PlatformSDL implementation.

This commit is contained in:
LuisAntonRebollo 2015-01-16 20:37:16 +01:00
parent 21d58bb191
commit aa35157eef
33 changed files with 3971 additions and 151 deletions

View file

@ -0,0 +1,35 @@
#ifndef PLATFORM_SDL_POPUPMENU_DATA_H
#define PLATFORM_SDL_POPUPMENU_DATA_H
#include "core/util/tDictionary.h"
class GuiMenuBar;
struct EventDescriptor;
class PopupMenu;
class MenuBar;
struct PlatformPopupMenuData
{
MenuBar *mMenuBar;
GuiMenuBar::Menu *mMenuGui;
static const U8 mCheckedBitmapIdx = 0;
static Map<GuiMenuBar::Menu*, PopupMenu*> mMenuMap;
PlatformPopupMenuData()
{
mMenuBar = NULL;
mMenuGui = NULL;
}
~PlatformPopupMenuData()
{
}
void insertAccelerator(EventDescriptor &desc, U32 id);
void removeAccelerator(U32 id);
void setAccelleratorEnabled(U32 id, bool enabled);
};
#endif //PLATFORM_SDL_POPUPMENU_DATA_H

View file

@ -0,0 +1,170 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "platform/menus/menuBar.h"
#include "platform/menus/popupMenu.h"
#include "gui/core/guiCanvas.h"
#include "windowManager/platformWindowMgr.h"
#include "core/util/safeDelete.h"
#include "windowManager/sdl/sdlWindow.h"
#include "gui/editor/guiMenuBar.h"
#include "platformSDL/menus/PlatformSDLPopupMenuData.h"
#ifdef TORQUE_SDL
//-----------------------------------------------------------------------------
// Platform Data
//-----------------------------------------------------------------------------
// class PlatformMenuBarData
// {
//
// };
Map<GuiMenuBar::Menu*, PopupMenu*> PlatformPopupMenuData::mMenuMap;
class GuiPlatformGenericMenuBar : public GuiMenuBar
{
typedef GuiMenuBar Parent;
public:
DECLARE_CONOBJECT(GuiPlatformGenericMenuBar);
virtual void menuItemSelected(Menu *menu, MenuItem *item)
{
AssertFatal(menu && item, "");
PopupMenu *popupMenu = PlatformPopupMenuData::mMenuMap[ menu ];
AssertFatal(popupMenu, "");
popupMenu->handleSelect( item->id );
Parent::menuItemSelected(menu, item);
}
protected:
/// menu id / item id
Map<CompoundKey<U32, U32>, String> mCmds;
};
IMPLEMENT_CONOBJECT(GuiPlatformGenericMenuBar);
//-----------------------------------------------------------------------------
// MenuBar Methods
//-----------------------------------------------------------------------------
void MenuBar::createPlatformPopupMenuData()
{
mData = NULL;
}
void MenuBar::deletePlatformPopupMenuData()
{
// SAFE_DELETE(mData);
}
//-----------------------------------------------------------------------------
GuiPlatformGenericMenuBar* _FindMenuBarCtrl()
{
GuiControl* control;
Sim::findObject("PlatformGenericMenubar", control);
AssertFatal(control, "");
if( !control )
return NULL;
GuiPlatformGenericMenuBar* menuBar;
menuBar = dynamic_cast<GuiPlatformGenericMenuBar*>( control->findObjectByInternalName( StringTable->insert("menubar"), true) );
AssertFatal(menuBar, "");
return menuBar;
}
void MenuBar::updateMenuBar(PopupMenu *popupMenu /* = NULL */)
{
//if(! isAttachedToCanvas())
// return;
if(!popupMenu)
return;
GuiPlatformGenericMenuBar* menuBarGui = _FindMenuBarCtrl();
popupMenu->mData->mMenuBar = this;
AssertFatal( dStrcmp( popupMenu->mData->mMenuGui->text, popupMenu->getBarTitle() ) == 0, "");
GuiMenuBar::Menu* menuGui = menuBarGui->findMenu( popupMenu->getBarTitle() );
if(!menuGui)
{
menuBarGui->addMenu( popupMenu->mData->mMenuGui );
menuGui = menuBarGui->findMenu( popupMenu->getBarTitle() );
}
PlatformPopupMenuData::mMenuMap[ menuGui ] = popupMenu;
}
//-----------------------------------------------------------------------------
void MenuBar::attachToCanvas(GuiCanvas *owner, S32 pos)
{
if(owner == NULL || isAttachedToCanvas())
return;
// This is set for popup menus in the onAttachToMenuBar() callback
mCanvas = owner;
PlatformWindowSDL *pWindow = dynamic_cast<PlatformWindowSDL*>(owner->getPlatformWindow());
if(pWindow == NULL)
return;
// Setup the native menu bar
GuiMenuBar *hWindowMenu = static_cast<GuiMenuBar*>( pWindow->getMenuHandle() );
if( hWindowMenu == NULL && !Journal::IsPlaying() )
hWindowMenu = _FindMenuBarCtrl();
if(hWindowMenu)
{
pWindow->setMenuHandle( hWindowMenu );
GuiControl *base = hWindowMenu->getParent();
while( base->getParent() )
{
base = base->getParent();
}
mCanvas->setMenuBar( base );
}
}
void MenuBar::removeFromCanvas()
{
_FindMenuBarCtrl()->clearMenus();
mCanvas->setMenuBar(NULL);
if(mCanvas == NULL || !isAttachedToCanvas())
return;
}
#endif

View file

@ -0,0 +1,250 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifdef TORQUE_SDL
#include "platform/menus/popupMenu.h"
#include "platform/menus//menuBar.h"
#include "console/consoleTypes.h"
#include "gui/core/guiCanvas.h"
#include "core/util/safeDelete.h"
#include "sim/actionMap.h"
#include "platform/platformInput.h"
#include "windowManager/sdl/sdlWindow.h"
#include "gui/editor/guiMenuBar.h"
#include "platformSDL/menus/PlatformSDLPopupMenuData.h"
//////////////////////////////////////////////////////////////////////////
// Platform Menu Data
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
void PlatformPopupMenuData::insertAccelerator(EventDescriptor &desc, U32 id)
{
AssertFatal(0, "");
}
void PlatformPopupMenuData::removeAccelerator(U32 id)
{
AssertFatal(0, "");
}
void PlatformPopupMenuData::setAccelleratorEnabled( U32 id, bool enabled )
{
AssertFatal(0, "");
}
//////////////////////////////////////////////////////////////////////////
void PopupMenu::createPlatformPopupMenuData()
{
mData = new PlatformPopupMenuData;
}
void PopupMenu::deletePlatformPopupMenuData()
{
SAFE_DELETE(mData);
}
void PopupMenu::createPlatformMenu()
{
mData->mMenuGui = GuiMenuBar::sCreateMenu( getBarTitle(), getId() );
PlatformPopupMenuData::mMenuMap[ mData->mMenuGui ] = this;
}
//////////////////////////////////////////////////////////////////////////
// Public Methods
//////////////////////////////////////////////////////////////////////////
S32 PopupMenu::insertItem(S32 pos, const char *title, const char* accelerator, const char* cmd)
{
GuiMenuBar::MenuItem *item = GuiMenuBar::findMenuItem( mData->mMenuGui, title );
if(item)
{
setItem( pos, title, accelerator, cmd);
return pos;
}
item = GuiMenuBar::addMenuItem( mData->mMenuGui, title, pos, accelerator, -1, cmd );
item->submenuParentMenu = this->mData->mMenuGui;
return pos;
}
S32 PopupMenu::insertSubMenu(S32 pos, const char *title, PopupMenu *submenu)
{
GuiMenuBar::MenuItem *item = GuiMenuBar::addMenuItem( mData->mMenuGui, title, pos, "", -1, "" );
item->isSubmenu = true;
item->submenu = submenu->mData->mMenuGui;
item->submenuParentMenu = this->mData->mMenuGui;
return pos;
}
bool PopupMenu::setItem(S32 pos, const char *title, const char* accelerator, const char* cmd)
{
GuiMenuBar::MenuItem *item = NULL;
item = GuiMenuBar::findMenuItem( mData->mMenuGui, title );
if(item)
{
item->id = pos;
item->cmd = cmd;
if( accelerator && accelerator[0] )
item->accelerator = dStrdup( accelerator );
else
item->accelerator = NULL;
return true;
}
return false;
}
void PopupMenu::removeItem(S32 itemPos)
{
GuiMenuBar::MenuItem *item = GuiMenuBar::findMenuItem( mData->mMenuGui, String::ToString(itemPos) );
if(item)
{
GuiMenuBar::removeMenuItem( mData->mMenuGui, item);
}
}
//////////////////////////////////////////////////////////////////////////
void PopupMenu::enableItem( S32 pos, bool enable )
{
GuiMenuBar::MenuItem *item = NULL;
for( item = mData->mMenuGui->firstMenuItem; item; item = item->nextMenuItem )
{
if( item->id == pos)
item->enabled = enable;
}
}
void PopupMenu::checkItem(S32 pos, bool checked)
{
GuiMenuBar::MenuItem *item = NULL;
for( item = mData->mMenuGui->firstMenuItem; item; item = item->nextMenuItem )
if(item->id == pos)
break;
if( !item )
return;
if(checked && item->checkGroup != -1)
{
// first, uncheck everything in the group:
for( GuiMenuBar::MenuItem *itemWalk = mData->mMenuGui->firstMenuItem; itemWalk; itemWalk = itemWalk->nextMenuItem )
if( itemWalk->checkGroup == item->checkGroup && itemWalk->bitmapIndex == mData->mCheckedBitmapIdx )
itemWalk->bitmapIndex = -1;
}
item->bitmapIndex = checked ? mData->mCheckedBitmapIdx : -1;
}
void PopupMenu::checkRadioItem(S32 firstPos, S32 lastPos, S32 checkPos)
{
GuiMenuBar::MenuItem *item = NULL;
for( item = mData->mMenuGui->firstMenuItem; item; item = item->nextMenuItem )
{
if(item->id >= firstPos && item->id <= lastPos)
{
item->bitmapIndex = (item->id == checkPos) ? mData->mCheckedBitmapIdx : -1;
}
}
}
bool PopupMenu::isItemChecked(S32 pos)
{
GuiMenuBar::MenuItem *item = NULL;
for( item = mData->mMenuGui->firstMenuItem; item; item = item->nextMenuItem )
if(item->id == pos)
return item->bitmapIndex == mData->mCheckedBitmapIdx;
return false;
}
U32 PopupMenu::getItemCount()
{
int count = 0;
for( GuiMenuBar::MenuItem *item = mData->mMenuGui->firstMenuItem; item; item = item->nextMenuItem )
++count;
return count;
}
//////////////////////////////////////////////////////////////////////////
bool PopupMenu::canHandleID(U32 id)
{
return true;
}
bool PopupMenu::handleSelect(U32 command, const char *text /* = NULL */)
{
return dAtob(Con::executef(this, "onSelectItem", Con::getIntArg(command), text ? text : ""));
}
//////////////////////////////////////////////////////////////////////////
void PopupMenu::showPopup(GuiCanvas *owner, S32 x /* = -1 */, S32 y /* = -1 */)
{
if(owner == NULL || isAttachedToMenuBar())
return;
}
//////////////////////////////////////////////////////////////////////////
void PopupMenu::attachToMenuBar(GuiCanvas *owner, S32 pos, const char *title)
{
if(owner == NULL || isAttachedToMenuBar())
return;
}
// New version of above for use by MenuBar class. Do not use yet.
void PopupMenu::attachToMenuBar(GuiCanvas *owner, S32 pos)
{
if(owner == NULL || isAttachedToMenuBar())
return;
//mData->mMenuBar = owner->setMenuBar();
}
void PopupMenu::removeFromMenuBar()
{
if(isAttachedToMenuBar())
return;
}
S32 PopupMenu::getPosOnMenuBar()
{
return 0;
}
#endif

View file

@ -0,0 +1,440 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "platform/platformInput.h"
#include "console/console.h"
#include "core/util/journal/process.h"
#include "windowManager/platformWindowMgr.h"
#include "sdlInput.h"
#include "platform/platformInput.h"
#include "SDL.h"
#ifdef LOG_INPUT
#include <time.h>
#include <stdarg.h>
#endif
// Static class variables:
InputManager* Input::smManager;
bool Input::smActive;
U8 Input::smModifierKeys;
bool Input::smLastKeyboardActivated;
bool Input::smLastMouseActivated;
bool Input::smLastJoystickActivated;
InputEvent Input::smInputEvent;
#ifdef LOG_INPUT
static HANDLE gInputLog;
#endif
static void fillAsciiTable() {}
//------------------------------------------------------------------------------
//
// This function gets the standard ASCII code corresponding to our key code
// and the existing modifier key state.
//
//------------------------------------------------------------------------------
struct AsciiData
{
struct KeyData
{
U16 ascii;
bool isDeadChar;
};
KeyData upper;
KeyData lower;
KeyData goofy;
};
#define NUM_KEYS ( KEY_OEM_102 + 1 )
#define KEY_FIRST KEY_ESCAPE
//------------------------------------------------------------------------------
void Input::init()
{
Con::printf( "Input Init:" );
destroy();
smActive = false;
smLastKeyboardActivated = true;
smLastMouseActivated = true;
smLastJoystickActivated = true;
SDL_InitSubSystem( SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | SDL_INIT_GAMECONTROLLER | SDL_INIT_EVENTS );
// Init the current modifier keys
setModifierKeys(0);
fillAsciiTable();
Con::printf( "" );
// Set ourselves to participate in per-frame processing.
Process::notify(Input::process, PROCESS_INPUT_ORDER);
}
//------------------------------------------------------------------------------
ConsoleFunction( isJoystickDetected, bool, 1, 1, "isJoystickDetected()" )
{
argc; argv;
return( SDL_NumJoysticks() > 0 );
}
//------------------------------------------------------------------------------
ConsoleFunction( getJoystickAxes, const char*, 2, 2, "getJoystickAxes( instance )" )
{
argc;
// TODO SDL
return( "" );
}
//------------------------------------------------------------------------------
U16 Input::getKeyCode( U16 asciiCode )
{
if( asciiCode > 255 )
return 0;
char c[2];
c[0]= asciiCode;
c[1] = NULL;
return KeyMapSDL::getTorqueScanCodeFromSDL( SDL_GetScancodeFromName( c ) );
}
//------------------------------------------------------------------------------
U16 Input::getAscii( U16 keyCode, KEY_STATE keyState )
{
if ( keyCode >= NUM_KEYS )
return 0;
U32 SDLKey = KeyMapSDL::getSDLScanCodeFromTorque( keyCode );
SDLKey = SDL_GetKeyFromScancode( (SDL_Scancode)SDLKey );
const char *text = SDL_GetKeyName( SDLKey );
if(text[1] != 0)
return 0;
U8 ret = text[0];
if( !dIsalpha(ret) )
return ret;
switch ( keyState )
{
case STATE_LOWER:
return dTolower( ret );
case STATE_UPPER:
return dToupper( ret );
case STATE_GOOFY:
return 0; // TODO SDL
default:
return(0);
}
}
//------------------------------------------------------------------------------
void Input::destroy()
{
Process::remove(Input::process);
SDL_QuitSubSystem( SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | SDL_INIT_GAMECONTROLLER );
}
//------------------------------------------------------------------------------
bool Input::enable()
{
if ( smManager && !smManager->isEnabled() )
return( smManager->enable() );
return( false );
}
//------------------------------------------------------------------------------
void Input::disable()
{
if ( smManager && smManager->isEnabled() )
smManager->disable();
}
//------------------------------------------------------------------------------
void Input::activate()
{
#ifdef UNICODE
//winState.imeHandle = ImmGetContext( getWin32WindowHandle() );
//ImmReleaseContext( getWin32WindowHandle(), winState.imeHandle );
#endif
if ( !Con::getBoolVariable( "$enableDirectInput" ) )
return;
if ( smManager && smManager->isEnabled() && !smActive )
{
Con::printf( "Activating Input..." );
smActive = true;
}
}
//------------------------------------------------------------------------------
void Input::deactivate()
{
if ( smManager && smManager->isEnabled() && smActive )
{
smActive = false;
Con::printf( "Input deactivated." );
}
}
//------------------------------------------------------------------------------
bool Input::isEnabled()
{
if ( smManager )
return smManager->isEnabled();
return false;
}
//------------------------------------------------------------------------------
bool Input::isActive()
{
return smActive;
}
//------------------------------------------------------------------------------
void Input::process()
{
if ( smManager && smManager->isEnabled() && smActive )
smManager->process();
}
//------------------------------------------------------------------------------
InputManager* Input::getManager()
{
return( smManager );
}
//-----------------------------------------------------------------------------
// Clipboard functions
const char* Platform::getClipboard()
{
//note - this function never returns NULL
return SDL_HasClipboardText() ? SDL_GetClipboardText() : "";
}
//-----------------------------------------------------------------------------
bool Platform::setClipboard(const char *text)
{
if (!text)
return false;
SDL_SetClipboardText(text);
return true;
}
namespace
{
const int TableSize = 256;
U32 SDL_T3D[256];
U32 T3D_SDL[256];
static bool _buildScanCode = true;
}
void mapScanCode(U32 sdl, U32 torque)
{
SDL_T3D[sdl] = torque;
T3D_SDL[torque] = sdl;
}
void buildScanCodeArray()
{
_buildScanCode = false;
for(int i = 0; i < TableSize; ++i)
{
SDL_T3D[i] = 0;
T3D_SDL[i] = 0;
}
// SDL, Torque
mapScanCode(SDL_SCANCODE_A, KEY_A);
mapScanCode(SDL_SCANCODE_B, KEY_B);
mapScanCode(SDL_SCANCODE_C, KEY_C);
mapScanCode(SDL_SCANCODE_D, KEY_D);
mapScanCode(SDL_SCANCODE_E, KEY_E);
mapScanCode(SDL_SCANCODE_F, KEY_F);
mapScanCode(SDL_SCANCODE_G, KEY_G);
mapScanCode(SDL_SCANCODE_H, KEY_H);
mapScanCode(SDL_SCANCODE_I, KEY_I);
mapScanCode(SDL_SCANCODE_J, KEY_J);
mapScanCode(SDL_SCANCODE_K, KEY_K);
mapScanCode(SDL_SCANCODE_L, KEY_L);
mapScanCode(SDL_SCANCODE_M, KEY_M);
mapScanCode(SDL_SCANCODE_N, KEY_N);
mapScanCode(SDL_SCANCODE_O, KEY_O);
mapScanCode(SDL_SCANCODE_P, KEY_P);
mapScanCode(SDL_SCANCODE_Q, KEY_Q);
mapScanCode(SDL_SCANCODE_R, KEY_R);
mapScanCode(SDL_SCANCODE_S, KEY_S);
mapScanCode(SDL_SCANCODE_T, KEY_T);
mapScanCode(SDL_SCANCODE_U, KEY_U);
mapScanCode(SDL_SCANCODE_V, KEY_V);
mapScanCode(SDL_SCANCODE_W, KEY_W);
mapScanCode(SDL_SCANCODE_X, KEY_X);
mapScanCode(SDL_SCANCODE_Y, KEY_Y);
mapScanCode(SDL_SCANCODE_Z, KEY_Z);
mapScanCode(SDL_SCANCODE_1, KEY_1);
mapScanCode(SDL_SCANCODE_2, KEY_2);
mapScanCode(SDL_SCANCODE_3, KEY_3);
mapScanCode(SDL_SCANCODE_4, KEY_4);
mapScanCode(SDL_SCANCODE_5, KEY_5);
mapScanCode(SDL_SCANCODE_6, KEY_6);
mapScanCode(SDL_SCANCODE_7, KEY_7);
mapScanCode(SDL_SCANCODE_8, KEY_8);
mapScanCode(SDL_SCANCODE_9, KEY_9);
mapScanCode(SDL_SCANCODE_0, KEY_0);
mapScanCode(SDL_SCANCODE_BACKSPACE, KEY_BACKSPACE);
mapScanCode(SDL_SCANCODE_TAB, KEY_TAB);
mapScanCode(SDL_SCANCODE_RETURN, KEY_RETURN);
mapScanCode(SDL_SCANCODE_LCTRL, KEY_CONTROL);
mapScanCode(SDL_SCANCODE_RCTRL, KEY_CONTROL);
mapScanCode(SDL_SCANCODE_LALT, KEY_ALT);
mapScanCode(SDL_SCANCODE_RALT, KEY_ALT);
mapScanCode(SDL_SCANCODE_LSHIFT, KEY_SHIFT);
mapScanCode(SDL_SCANCODE_RSHIFT, KEY_SHIFT);
mapScanCode(SDL_SCANCODE_PAUSE, KEY_PAUSE);
mapScanCode(SDL_SCANCODE_CAPSLOCK, KEY_CAPSLOCK);
mapScanCode(SDL_SCANCODE_ESCAPE, KEY_ESCAPE);
mapScanCode(SDL_SCANCODE_SPACE, KEY_SPACE);
mapScanCode(SDL_SCANCODE_PAGEDOWN, KEY_PAGE_DOWN);
mapScanCode(SDL_SCANCODE_PAGEUP, KEY_PAGE_UP);
mapScanCode(SDL_SCANCODE_END, KEY_END);
mapScanCode(SDL_SCANCODE_HOME, KEY_HOME);
mapScanCode(SDL_SCANCODE_LEFT, KEY_LEFT);
mapScanCode(SDL_SCANCODE_UP, KEY_UP);
mapScanCode(SDL_SCANCODE_RIGHT, KEY_RIGHT);
mapScanCode(SDL_SCANCODE_DOWN, KEY_DOWN);
mapScanCode(SDL_SCANCODE_PRINTSCREEN, KEY_PRINT);
mapScanCode(SDL_SCANCODE_INSERT, KEY_INSERT);
mapScanCode(SDL_SCANCODE_DELETE, KEY_DELETE);
mapScanCode(SDL_SCANCODE_HELP, KEY_HELP);
mapScanCode(SDL_SCANCODE_GRAVE, KEY_TILDE);
mapScanCode(SDL_SCANCODE_MINUS, KEY_MINUS);
mapScanCode(SDL_SCANCODE_EQUALS, KEY_EQUALS);
mapScanCode(SDL_SCANCODE_LEFTBRACKET, KEY_LBRACKET);
mapScanCode(SDL_SCANCODE_RIGHTBRACKET, KEY_RBRACKET);
mapScanCode(SDL_SCANCODE_BACKSLASH, KEY_BACKSLASH);
mapScanCode(SDL_SCANCODE_SEMICOLON, KEY_SEMICOLON);
mapScanCode(SDL_SCANCODE_APOSTROPHE, KEY_APOSTROPHE);
mapScanCode(SDL_SCANCODE_COMMA, KEY_COMMA);
mapScanCode(SDL_SCANCODE_PERIOD, KEY_PERIOD);
mapScanCode(SDL_SCANCODE_SLASH, KEY_SLASH);
mapScanCode(SDL_SCANCODE_KP_0, KEY_NUMPAD0);
mapScanCode(SDL_SCANCODE_KP_1, KEY_NUMPAD1);
mapScanCode(SDL_SCANCODE_KP_2, KEY_NUMPAD2);
mapScanCode(SDL_SCANCODE_KP_3, KEY_NUMPAD3);
mapScanCode(SDL_SCANCODE_KP_4, KEY_NUMPAD4);
mapScanCode(SDL_SCANCODE_KP_5, KEY_NUMPAD5);
mapScanCode(SDL_SCANCODE_KP_6, KEY_NUMPAD6);
mapScanCode(SDL_SCANCODE_KP_7, KEY_NUMPAD7);
mapScanCode(SDL_SCANCODE_KP_8, KEY_NUMPAD8);
mapScanCode(SDL_SCANCODE_KP_9, KEY_NUMPAD9);
mapScanCode(SDL_SCANCODE_KP_MULTIPLY, KEY_MULTIPLY);
mapScanCode(SDL_SCANCODE_KP_PLUS, KEY_ADD);
mapScanCode(SDL_SCANCODE_KP_EQUALS, KEY_SEPARATOR);
mapScanCode(SDL_SCANCODE_KP_MINUS, KEY_SUBTRACT);
mapScanCode(SDL_SCANCODE_KP_PERIOD, KEY_DECIMAL);
mapScanCode(SDL_SCANCODE_KP_DIVIDE, KEY_DIVIDE);
mapScanCode(SDL_SCANCODE_KP_ENTER, KEY_NUMPADENTER);
mapScanCode(SDL_SCANCODE_F1, KEY_F1);
mapScanCode(SDL_SCANCODE_F2, KEY_F2);
mapScanCode(SDL_SCANCODE_F3, KEY_F3);
mapScanCode(SDL_SCANCODE_F4, KEY_F4);
mapScanCode(SDL_SCANCODE_F5, KEY_F5);
mapScanCode(SDL_SCANCODE_F6, KEY_F6);
mapScanCode(SDL_SCANCODE_F7, KEY_F7);
mapScanCode(SDL_SCANCODE_F8, KEY_F8);
mapScanCode(SDL_SCANCODE_F9, KEY_F9);
mapScanCode(SDL_SCANCODE_F10, KEY_F10);
mapScanCode(SDL_SCANCODE_F11, KEY_F11);
mapScanCode(SDL_SCANCODE_F12, KEY_F12);
mapScanCode(SDL_SCANCODE_F13, KEY_F13);
mapScanCode(SDL_SCANCODE_F14, KEY_F14);
mapScanCode(SDL_SCANCODE_F15, KEY_F15);
mapScanCode(SDL_SCANCODE_F16, KEY_F16);
mapScanCode(SDL_SCANCODE_F17, KEY_F17);
mapScanCode(SDL_SCANCODE_F18, KEY_F18);
mapScanCode(SDL_SCANCODE_F19, KEY_F19);
mapScanCode(SDL_SCANCODE_F20, KEY_F20);
mapScanCode(SDL_SCANCODE_F21, KEY_F21);
mapScanCode(SDL_SCANCODE_F22, KEY_F22);
mapScanCode(SDL_SCANCODE_F23, KEY_F23);
mapScanCode(SDL_SCANCODE_F24, KEY_F24);
//mapScanCode(SDL_SCANCODE_LOCKINGNUMLOCK, KEY_NUMLOCK);
//mapScanCode(SDL_SCANCODE_LOCKINGSCROLLLOCK, KEY_SCROLLLOCK);
mapScanCode(SDL_SCANCODE_LCTRL, KEY_LCONTROL);
mapScanCode(SDL_SCANCODE_RCTRL, KEY_RCONTROL);
mapScanCode(SDL_SCANCODE_LALT, KEY_LALT);
mapScanCode(SDL_SCANCODE_RALT, KEY_RALT);
mapScanCode(SDL_SCANCODE_LSHIFT, KEY_LSHIFT);
mapScanCode(SDL_SCANCODE_RSHIFT, KEY_RSHIFT);
//mapScanCode(____, KEY_WIN_LWINDOW);
//mapScanCode(____, KEY_WIN_RWINDOW);
//mapScanCode(____, KEY_WIN_APPS);
//mapScanCode(____, KEY_OEM_102);
//mapScanCode(____, KEY_MAC_OPT);
//mapScanCode(____, KEY_MAC_LOPT);
//mapScanCode(____, KEY_MAC_ROPT);
//for(int i = 0; i < 48; ++i)
// mapScanCode(____, KEY_BUTTON0 + i );
//mapScanCode(____, KEY_ANYKEY);
}
U32 KeyMapSDL::getTorqueScanCodeFromSDL(U32 sdl)
{
if(_buildScanCode)
buildScanCodeArray();
return SDL_T3D[sdl];
}
U32 KeyMapSDL::getSDLScanCodeFromTorque(U32 torque)
{
if(_buildScanCode)
buildScanCodeArray();
return T3D_SDL[torque];
}

View file

@ -0,0 +1,13 @@
#ifndef SDL_INPUT_H
#define SDL_INPUT_H
#include "platform/types.h"
namespace KeyMapSDL
{
U32 getTorqueScanCodeFromSDL(U32 sdl);
U32 getSDLScanCodeFromTorque(U32 torque);
}
#endif

View file

@ -0,0 +1,162 @@
#include "windowManager/platformWindowMgr.h"
#include "windowManager/sdl/sdlWindow.h"
#include "SDL.h"
namespace
{
SDL_MessageBoxButtonData MBOkCancelData[2], MBRetryCancelData[2], MBSaveDontSaveData[2], MBSaveDontSaveCancelData[3], MBAlertAssetData[4];
bool needInitMsgBox = true;
void initMsgBox_ButtonData()
{
needInitMsgBox = false;
SDL_MessageBoxButtonData MBOkButton;
MBOkButton.text = "Ok";
MBOkButton.buttonid = MROk;
MBOkButton.flags = 0;
SDL_MessageBoxButtonData MBCancelButton;
MBCancelButton.text = "Cancel";
MBCancelButton.buttonid = MRCancel;
MBCancelButton.flags = 0;
SDL_MessageBoxButtonData MBRetryButton;
MBRetryButton.text = "Retry";
MBRetryButton.buttonid = MROk;
MBRetryButton.flags = 0;
SDL_MessageBoxButtonData MBSaveButton;
MBSaveButton.text = "Save";
MBSaveButton.buttonid = MROk;
MBSaveButton.flags = 0;
SDL_MessageBoxButtonData MBDontSaveButton;
MBDontSaveButton.text = "Don't Save";
MBDontSaveButton.buttonid = MRRetry;
MBDontSaveButton.flags = 0;
MBOkCancelData[0] = MBOkButton;
MBOkCancelData[1] = MBCancelButton;
MBRetryCancelData[0] = MBRetryButton;
MBRetryCancelData[1] = MBCancelButton;
MBSaveDontSaveData[0] = MBSaveButton;
MBSaveDontSaveData[1] = MBDontSaveButton;
MBSaveDontSaveCancelData[0] = MBSaveButton;
MBSaveDontSaveCancelData[1] = MBDontSaveButton;
MBSaveDontSaveCancelData[2] = MBRetryButton;
MBAlertAssetData[0].text = "Debug";
MBAlertAssetData[0].buttonid = Platform::ALERT_ASSERT_DEBUG;
MBAlertAssetData[0].flags = 0;
MBAlertAssetData[1].text = "Ignore";
MBAlertAssetData[1].buttonid = Platform::ALERT_ASSERT_IGNORE;
MBAlertAssetData[1].flags = 0;
MBAlertAssetData[2].text = "Ignore all";
MBAlertAssetData[2].buttonid = Platform::ALERT_ASSERT_IGNORE_ALL;
MBAlertAssetData[2].flags = 0;
MBAlertAssetData[3].text = "Exit";
MBAlertAssetData[3].buttonid = Platform::ALERT_ASSERT_EXIT;
MBAlertAssetData[3].flags = 0;
}
}
#ifdef TORQUE_SDL
S32 Platform::messageBox(const UTF8 *title, const UTF8 *message, MBButtons buttons, MBIcons icon)
{
if(needInitMsgBox)
initMsgBox_ButtonData();
SDL_Window *window = WindowManager->getFirstWindow() ? SDL_GetWindowFromID( WindowManager->getFirstWindow()->getWindowId() ) : NULL;
if(buttons == MBOk)
return SDL_ShowSimpleMessageBox(0, title, message, window );
SDL_MessageBoxData boxData;
boxData.title = title;
boxData.message = message;
boxData.window = window;
boxData.flags = 0;
boxData.colorScheme = NULL;
boxData.buttons = NULL;
boxData.numbuttons = 0;
int res = MBOk;
switch(buttons)
{
case MBOkCancel:
{
boxData.buttons = &MBOkCancelData[0];
boxData.numbuttons = 2;
break;
}
case MBRetryCancel:
{
boxData.buttons = &MBRetryCancelData[0];
boxData.numbuttons = 2;
break;
}
case MBSaveDontSave:
{
boxData.buttons = &MBSaveDontSaveData[0];
boxData.numbuttons = 2;
break;
}
case MBSaveDontSaveCancel:
{
boxData.buttons = &MBSaveDontSaveCancelData[0];
boxData.numbuttons = 3;
break;
}
case MBAlertAssert:
{
boxData.buttons = &MBAlertAssetData[0];
boxData.numbuttons = 4;
break;
}
default:
{
return MBOk;
}
}
SDL_ShowMessageBox(&boxData, &res);
return res;
}
//--------------------------------------
void Platform::AlertOK(const char *windowTitle, const char *message)
{
SDL_ShowCursor(1);
Platform::messageBox(windowTitle, message, MBOk );
}
//--------------------------------------
bool Platform::AlertOKCancel(const char *windowTitle, const char *message)
{
SDL_ShowCursor(1);
return MROk == Platform::messageBox(windowTitle, message, MBOkCancel );
}
//--------------------------------------
bool Platform::AlertRetry(const char *windowTitle, const char *message)
{
SDL_ShowCursor(1);
return MROk == Platform::messageBox(windowTitle, message, MBRetryCancel );
}
Platform::ALERT_ASSERT_RESULT Platform::AlertAssert(const char *windowTitle, const char *message)
{
SDL_ShowCursor(1);
return (Platform::ALERT_ASSERT_RESULT)Platform::messageBox(windowTitle, message, MBAlertAssert );
}
#endif

View file

@ -0,0 +1,84 @@
#include <SDL.h>
#include "windowManager/sdl/sdlWindow.h"
#include "console/console.h"
namespace PlatformGL
{
void init()
{
static bool inited = false;
if(inited)
return;
inited = true;
const U32 majorOGL = 4;
const U32 minorOGL = 2;
U32 debugFlag = 0;
#ifdef TORQUE_DEBUG
debugFlag |= SDL_GL_CONTEXT_DEBUG_FLAG;
#endif
#if 0 // cause problem with glew, no extension load
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, majorOGL);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, minorOGL);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
#endif
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, debugFlag);
SDL_ClearError();
}
void* CreateContextGL( PlatformWindow *window )
{
init();
PlatformWindowSDL* windowSdl = dynamic_cast<PlatformWindowSDL*>(window);
AssertFatal(windowSdl, "");
if( !windowSdl )
return NULL;
SDL_ClearError();
SDL_GLContext ctx = SDL_GL_CreateContext( windowSdl->getSDLWindow() );
if( !ctx )
{
const char *err = SDL_GetError();
Con::printf( err );
AssertFatal(0, err );
}
return ctx;
}
void MakeCurrentGL( PlatformWindow *window, void *glContext )
{
PlatformWindowSDL* windowSdl = dynamic_cast<PlatformWindowSDL*>(window);
AssertFatal( windowSdl && glContext, "" );
SDL_ClearError();
SDL_GL_MakeCurrent( windowSdl->getSDLWindow(), glContext );
const char *err = SDL_GetError();
if( err && err[0] )
{
Con::printf( err );
AssertFatal(0, err );
}
}
void setVSync(const int i)
{
if( i == 1 || i == -1 )
{
int ret = SDL_GL_SetSwapInterval(-1);
if( ret == -1)
SDL_GL_SetSwapInterval(1);
}
else
SDL_GL_SetSwapInterval(0);
}
}