diff --git a/Engine/source/app/mainLoop.cpp b/Engine/source/app/mainLoop.cpp index 2819d153d..7fa747b93 100644 --- a/Engine/source/app/mainLoop.cpp +++ b/Engine/source/app/mainLoop.cpp @@ -460,7 +460,7 @@ bool StandardMainLoop::handleCommandLine( S32 argc, const char **argv ) #endif success = str.open(defaultScriptName, Torque::FS::File::Read); -#if defined( TORQUE_DEBUG ) && defined (TORQUE_TOOLS) && !defined( _XBOX ) +#if defined( TORQUE_DEBUG ) && defined (TORQUE_TOOLS) && !defined(TORQUE_DEDICATED) && !defined( _XBOX ) if (!success) { OpenFileDialog ofd; diff --git a/Engine/source/gfx/gl/sdl/gfxGLDevice.sdl.cpp b/Engine/source/gfx/gl/sdl/gfxGLDevice.sdl.cpp index b2e9aaba5..10e18deb4 100644 --- a/Engine/source/gfx/gl/sdl/gfxGLDevice.sdl.cpp +++ b/Engine/source/gfx/gl/sdl/gfxGLDevice.sdl.cpp @@ -19,7 +19,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. //----------------------------------------------------------------------------- -#if defined( TORQUE_SDL ) +#if defined( TORQUE_SDL ) && !defined( TORQUE_DEDICATED ) #include "gfx/gfxCubemap.h" #include "gfx/screenshot.h" diff --git a/Engine/source/platformSDL/menus/PlatformSDLPopupMenuData.h b/Engine/source/platformSDL/menus/PlatformSDLPopupMenuData.h new file mode 100644 index 000000000..4911f5c10 --- /dev/null +++ b/Engine/source/platformSDL/menus/PlatformSDLPopupMenuData.h @@ -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 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 \ No newline at end of file diff --git a/Engine/source/platformSDL/menus/menuBarSDL.cpp b/Engine/source/platformSDL/menus/menuBarSDL.cpp new file mode 100644 index 000000000..3139b743c --- /dev/null +++ b/Engine/source/platformSDL/menus/menuBarSDL.cpp @@ -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 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, 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( 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(owner->getPlatformWindow()); + if(pWindow == NULL) + return; + + // Setup the native menu bar + GuiMenuBar *hWindowMenu = static_cast( 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 diff --git a/Engine/source/platformSDL/menus/popupMenuSDL.cpp b/Engine/source/platformSDL/menus/popupMenuSDL.cpp new file mode 100644 index 000000000..c9d283de5 --- /dev/null +++ b/Engine/source/platformSDL/menus/popupMenuSDL.cpp @@ -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 diff --git a/Engine/source/platformSDL/sdlInput.cpp b/Engine/source/platformSDL/sdlInput.cpp new file mode 100644 index 000000000..97c57d5b9 --- /dev/null +++ b/Engine/source/platformSDL/sdlInput.cpp @@ -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 +#include +#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]; +} \ No newline at end of file diff --git a/Engine/source/platformSDL/sdlInput.h b/Engine/source/platformSDL/sdlInput.h new file mode 100644 index 000000000..acb5115da --- /dev/null +++ b/Engine/source/platformSDL/sdlInput.h @@ -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 diff --git a/Engine/source/platformSDL/sdlMsgBox.cpp b/Engine/source/platformSDL/sdlMsgBox.cpp new file mode 100644 index 000000000..6bb5b0bda --- /dev/null +++ b/Engine/source/platformSDL/sdlMsgBox.cpp @@ -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 \ No newline at end of file diff --git a/Engine/source/platformSDL/sdlPlatformGL.cpp b/Engine/source/platformSDL/sdlPlatformGL.cpp new file mode 100644 index 000000000..6562f2c80 --- /dev/null +++ b/Engine/source/platformSDL/sdlPlatformGL.cpp @@ -0,0 +1,84 @@ +#include +#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(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(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); + } + +} diff --git a/Engine/source/platformX86UNIX/x86UNIXPlatform.cpp b/Engine/source/platformX86UNIX/x86UNIXPlatform.cpp new file mode 100644 index 000000000..0f10d1eb4 --- /dev/null +++ b/Engine/source/platformX86UNIX/x86UNIXPlatform.cpp @@ -0,0 +1,12 @@ +#include "platform/platform.h" + +bool Platform::openWebBrowser( const char* webAddress ) +{ + return false; // TODO LINUX +} + +#ifdef TORQUE_DEDICATED +// XA: New class for the unix unicode font +class PlatformFont; +PlatformFont *createPlatformFont(const char *name, dsize_t size, U32 charset /* = TGE_ANSI_CHARSET */) { return NULL; } +#endif diff --git a/Engine/source/platformX86UNIX/x86UNIXStub.dedicated.cpp b/Engine/source/platformX86UNIX/x86UNIXStub.dedicated.cpp deleted file mode 100644 index a0fcc9ec6..000000000 --- a/Engine/source/platformX86UNIX/x86UNIXStub.dedicated.cpp +++ /dev/null @@ -1,145 +0,0 @@ -//----------------------------------------------------------------------------- -// 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 "platformX86UNIX/x86UNIXFont.h" -#include "platform/nativeDialogs/fileDialog.h" - -#if 0 -// declare stub functions -#define GL_FUNCTION(fn_return, fn_name, fn_args, fn_value) fn_return stub_##fn_name fn_args{ fn_value } -#include "platform/GLCoreFunc.h" -#include "platform/GLExtFunc.h" -#include "platform/GLUFunc.h" -#undef GL_FUNCTION - -// point gl function pointers at stub functions -#define GL_FUNCTION(fn_return,fn_name,fn_args, fn_value) fn_return (*fn_name)fn_args = stub_##fn_name; -#include "platform/GLCoreFunc.h" -#include "platform/GLExtFunc.h" -#include "platform/GLUFunc.h" -#undef GL_FUNCTION - -GLState gGLState; -bool gOpenGLDisablePT = false; -bool gOpenGLDisableCVA = false; -bool gOpenGLDisableTEC = false; -bool gOpenGLDisableARBMT = false; -bool gOpenGLDisableFC = false; -bool gOpenGLDisableTCompress = false; -bool gOpenGLNoEnvColor = false; -float gOpenGLGammaCorrection = 0.5; -bool gOpenGLNoDrawArraysAlpha = false; - -// AL stubs -//#include -//#include -//#define INITGUID -//#include - -// Define the OpenAL and Extension Stub functions -#define AL_FUNCTION(fn_return, fn_name, fn_args, fn_value) fn_return stub_##fn_name fn_args{ fn_value } -#include -#include -#include -#undef AL_FUNCTION -#include "platform/platformInput.h" - -// Declare the OpenAL and Extension Function pointers -// And initialize them to the stub functions -#define AL_FUNCTION(fn_return,fn_name,fn_args, fn_value) fn_return (*fn_name)fn_args = stub_##fn_name; -#include -#include -#include -#undef AL_FUNCTION - -namespace Audio -{ -bool OpenALDLLInit() { return false; } -void OpenALDLLShutdown() {} -} -#endif - -// Platform Stubs - -bool Platform::excludeOtherInstances(const char*) { return true; } - -// clipboard -const char* Platform::getClipboard() { return ""; } -bool Platform::setClipboard(const char *text) { return false; } - -// fs -void Platform::openFolder(const char *path) { } -void Platform::openFile(const char *path) { } - -// window -bool Platform::displaySplashWindow(String path) { return false; } -bool Platform::closeSplashWindow() { return false; } - -// font -PlatformFont *createPlatformFont(const char *name, U32 size, U32 charset) { return NULL; } -bool x86UNIXFont::create(const char *name, U32 size, U32 charset) { return false; } - -// web -bool Platform::openWebBrowser(const char *) { return false; } - -// messagebox -void Platform::AlertOK(const char *, const char *) {} -bool Platform::AlertOKCancel(const char *, const char *) { return false; } -S32 Platform::messageBox(char const*, char const*, MBButtons, MBIcons) { return 0; } -bool Platform::AlertRetry(char const*, char const*) { return false ; } -Platform::ALERT_ASSERT_RESULT Platform::AlertAssert(const char *windowTitle, const char *message) { return ALERT_ASSERT_EXIT; } - -// file dialog -IMPLEMENT_CONOBJECT(FileDialog); -FileDialog::FileDialog() {} -FileDialog::~FileDialog() {} -bool FileDialog::Execute() { return false; } -void FileDialog::initPersistFields() { Parent::initPersistFields(); } - -class FileDialogOpaqueData {}; - -FileDialogData::FileDialogData() {} -FileDialogData::~FileDialogData() {} - -IMPLEMENT_CONOBJECT(OpenFileDialog); -OpenFileDialog::OpenFileDialog() {} -OpenFileDialog::~OpenFileDialog() {} -void OpenFileDialog::initPersistFields() { Parent::initPersistFields(); } - -// Input stubs -void Input::init() {} -void Input::destroy() {} -bool Input::enable() { return false; } -void Input::disable() {} -void Input::activate() {} -void Input::deactivate() {} -U16 Input::getAscii( U16 keyCode, KEY_STATE keyState ) { return 0; } -U16 Input::getKeyCode( U16 asciiCode ) { return 0; } -bool Input::isEnabled() { return false; } -bool Input::isActive() { return false; } -void Input::process() {} -InputManager* Input::getManager() { return NULL; } -InputEvent Input::smInputEvent; -U8 Input::smModifierKeys; - -bool OpenGLInit() { return false; } diff --git a/Engine/source/windowManager/sdl/sdlCursorController.cpp b/Engine/source/windowManager/sdl/sdlCursorController.cpp new file mode 100644 index 000000000..dca1f04be --- /dev/null +++ b/Engine/source/windowManager/sdl/sdlCursorController.cpp @@ -0,0 +1,116 @@ +//----------------------------------------------------------------------------- +// 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 "core/strings/unicode.h" +#include "math/mMath.h" +#include "windowManager/sdl/sdlWindow.h" +#include "windowManager/sdl/sdlWindowMgr.h" +#include "windowManager/sdl/sdlCursorController.h" +#include "platform/platformInput.h" + +#include "SDL.h" + +static struct { U32 id; SDL_SystemCursor resourceID; SDL_Cursor *cursor;} sgCursorShapeMap[]= +{ + { PlatformCursorController::curArrow, SDL_SYSTEM_CURSOR_ARROW , NULL }, + { PlatformCursorController::curWait, SDL_SYSTEM_CURSOR_WAIT, NULL }, + { PlatformCursorController::curPlus, SDL_SYSTEM_CURSOR_CROSSHAIR, NULL }, + { PlatformCursorController::curResizeVert, SDL_SYSTEM_CURSOR_SIZEWE, NULL }, + { PlatformCursorController::curResizeHorz, SDL_SYSTEM_CURSOR_SIZENS, NULL }, + { PlatformCursorController::curResizeAll, SDL_SYSTEM_CURSOR_SIZEALL, NULL }, + { PlatformCursorController::curIBeam, SDL_SYSTEM_CURSOR_IBEAM, NULL }, + { PlatformCursorController::curResizeNESW, SDL_SYSTEM_CURSOR_SIZENESW, NULL }, + { PlatformCursorController::curResizeNWSE, SDL_SYSTEM_CURSOR_SIZENWSE, NULL }, + { PlatformCursorController::curHand, SDL_SYSTEM_CURSOR_HAND, NULL }, + { 0, SDL_SYSTEM_CURSOR_NO, NULL }, +}; + + +U32 PlatformCursorControllerSDL::getDoubleClickTime() +{ + // TODO SDL + return 500; +} +S32 PlatformCursorControllerSDL::getDoubleClickWidth() +{ + // TODO SDL + return 32; +} +S32 PlatformCursorControllerSDL::getDoubleClickHeight() +{ + // TODO SDL + return 32; +} + +void PlatformCursorControllerSDL::setCursorPosition( S32 x, S32 y ) +{ + if( PlatformWindowManager::get() && PlatformWindowManager::get()->getFirstWindow() ) + { + AssertFatal( dynamic_cast( PlatformWindowManager::get()->getFirstWindow() ), ""); + PlatformWindowSDL *window = static_cast( PlatformWindowManager::get()->getFirstWindow() ); + SDL_WarpMouseInWindow(window->getSDLWindow(), x, y); + } +} + +void PlatformCursorControllerSDL::getCursorPosition( Point2I &point ) +{ + SDL_GetMouseState( &point.x, &point.y ); +} + +void PlatformCursorControllerSDL::setCursorVisible( bool visible ) +{ + SDL_ShowCursor( visible ); +} + +bool PlatformCursorControllerSDL::isCursorVisible() +{ + return SDL_ShowCursor( -1 );; +} + +void PlatformCursorControllerSDL::setCursorShape(U32 cursorID) +{ + SDL_Cursor* cursor = NULL; + + for(S32 i = 0; sgCursorShapeMap[i].resourceID != SDL_SYSTEM_CURSOR_NO; ++i) + { + if(cursorID == sgCursorShapeMap[i].id) + { + if( !sgCursorShapeMap[i].cursor ) + sgCursorShapeMap[i].cursor = SDL_CreateSystemCursor( sgCursorShapeMap[i].resourceID ); + + cursor = sgCursorShapeMap[i].cursor; + break; + } + } + + if( !cursor ) + return; + + SDL_SetCursor(cursor); +} + + +void PlatformCursorControllerSDL::setCursorShape( const UTF8 *fileName, bool reload ) +{ + // TODO SDL + AssertWarn(0, "PlatformCursorControllerSDL::setCursorShape - Not implemented"); +} diff --git a/Engine/source/windowManager/sdl/sdlCursorController.h b/Engine/source/windowManager/sdl/sdlCursorController.h new file mode 100644 index 000000000..423be28b5 --- /dev/null +++ b/Engine/source/windowManager/sdl/sdlCursorController.h @@ -0,0 +1,51 @@ +//----------------------------------------------------------------------------- +// 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. +//----------------------------------------------------------------------------- + +#ifndef _SDL_CURSORCONTROLLER_H_ +#define _SDL_CURSORCONTROLLER_H_ + +#include "windowManager/platformCursorController.h" + +class PlatformCursorControllerSDL : public PlatformCursorController +{ +public: + PlatformCursorControllerSDL( PlatformWindow *owner ) : + PlatformCursorController( owner ) + { + pushCursor( PlatformCursorController::curArrow ); + }; + + virtual void setCursorPosition( S32 x, S32 y ); + virtual void getCursorPosition( Point2I &point ); + virtual void setCursorVisible( bool visible ); + virtual bool isCursorVisible(); + + void setCursorShape( U32 cursorID ); + void setCursorShape( const UTF8 *fileName, bool reload ); + + U32 getDoubleClickTime(); + S32 getDoubleClickWidth(); + S32 getDoubleClickHeight(); +}; + + +#endif diff --git a/Engine/source/windowManager/dedicated/dedicatedWindowStub.cpp b/Engine/source/windowManager/sdl/sdlSplashScreen.cpp similarity index 88% rename from Engine/source/windowManager/dedicated/dedicatedWindowStub.cpp rename to Engine/source/windowManager/sdl/sdlSplashScreen.cpp index 51149ff3a..974d0baeb 100644 --- a/Engine/source/windowManager/dedicated/dedicatedWindowStub.cpp +++ b/Engine/source/windowManager/sdl/sdlSplashScreen.cpp @@ -20,10 +20,15 @@ // IN THE SOFTWARE. //----------------------------------------------------------------------------- -#include "windowManager/dedicated/dedicatedWindowStub.h" +#include "platform/platform.h" +#include "console/console.h" - -PlatformWindowManager *CreatePlatformWindowManager() +bool Platform::displaySplashWindow( String path ) { - return new DedicatedWindowMgr; + if(path.isEmpty()) + return false; + + return true; } + + diff --git a/Engine/source/windowManager/sdl/sdlWindow.cpp b/Engine/source/windowManager/sdl/sdlWindow.cpp new file mode 100644 index 000000000..9046a7651 --- /dev/null +++ b/Engine/source/windowManager/sdl/sdlWindow.cpp @@ -0,0 +1,597 @@ +//----------------------------------------------------------------------------- +// 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 "math/mMath.h" +#include "gfx/gfxStructs.h" + +#include "windowManager/sdl/sdlWindow.h" +#include "windowManager/sdl/sdlWindowMgr.h" +#include "windowManager/sdl/sdlCursorController.h" +#include "platformSDL/sdlInput.h" +#include "platform/menus/popupMenu.h" +#include "platform/platformInput.h" + +#include "gfx/gfxDevice.h" + +#ifdef TORQUE_OS_LINUX +#define SDL_VIDEO_DRIVER_X11 // TODO SDL +#endif + +#include "SDL.h" +#include "SDL_syswm.h" + +#define SCREENSAVER_QUERY_DENY 0 // Disable screensaver + +#ifndef IDI_ICON1 +#define IDI_ICON1 107 +#endif + +namespace +{ + U32 getTorqueModFromSDL(U16 mod) + { + U32 ret = 0; + + if(mod & KMOD_LSHIFT) + ret |= IM_LSHIFT; + + if(mod & KMOD_RSHIFT) + ret |= IM_RSHIFT; + + if(mod & KMOD_LCTRL) + ret |= IM_LCTRL; + + if(mod & KMOD_RCTRL) + ret |= IM_RCTRL; + + if(mod & KMOD_LALT) + ret |= IM_LALT; + + if(mod & KMOD_RALT) + ret |= IM_RALT; + + return ret; + } +} + +PlatformWindowSDL::PlatformWindowSDL(): +mShouldLockMouse(false), +mMouseLocked(false), +mOwningManager(NULL), +mNextWindow(NULL), +mWindowHandle(NULL), +mOldParent(NULL), +mTarget(NULL), +mDevice(NULL), +mSuppressReset(false), +mMenuHandle(NULL), +mPosition(0,0) +{ + mCursorController = new PlatformCursorControllerSDL( this ); + + mVideoMode.bitDepth = 32; + mVideoMode.fullScreen = false; + mVideoMode.refreshRate = 60; + mVideoMode.resolution.set(800,600); +} + +PlatformWindowSDL::~PlatformWindowSDL() +{ + // delete our sdl handle.. + SDL_DestroyWindow(mWindowHandle); + + // unlink ourselves from the window list... + AssertFatal(mOwningManager, "PlatformWindowSDL::~PlatformWindowSDL - orphan window, cannot unlink!"); + mOwningManager->unlinkWindow(this); +} + +GFXDevice * PlatformWindowSDL::getGFXDevice() +{ + return mDevice; +} + +GFXWindowTarget * PlatformWindowSDL::getGFXTarget() +{ + return mTarget; +} + +const GFXVideoMode & PlatformWindowSDL::getVideoMode() +{ + return mVideoMode; +} + +void* PlatformWindowSDL::getSystemWindow(const WindowSystem system) +{ + SDL_SysWMinfo info; + SDL_VERSION(&info.version); + SDL_GetWindowWMInfo(mWindowHandle,&info); + +#ifdef TORQUE_OS_WIN32 + if( system == WindowSystem_Windows && info.subsystem == SDL_SYSWM_WINDOWS) + return info.info.win.window; +#endif + +#if defined(TORQUE_OS_LINUX) + if( system == WindowSystem_X11 && info.subsystem == SDL_SYSWM_X11) + return (void*)info.info.x11.window; +#endif + + AssertFatal(0, ""); + return NULL; +} + +void PlatformWindowSDL::setVideoMode( const GFXVideoMode &mode ) +{ + mVideoMode = mode; + mSuppressReset = true; + + // Set our window to have the right style based on the mode + if(mode.fullScreen && !Platform::getWebDeployment() && !mOffscreenRender) + { + setSize(mode.resolution); + + SDL_SetWindowFullscreen( mWindowHandle, SDL_WINDOW_FULLSCREEN); + + // When switching to Fullscreen, reset device after setting style + if(mTarget.isValid()) + mTarget->resetMode(); + } + else + { + // Reset device *first*, so that when we call setSize() and let it + // access the monitor settings, it won't end up with our fullscreen + // geometry that is just about to change. + + if(mTarget.isValid()) + mTarget->resetMode(); + + if (!mOffscreenRender) + { + SDL_SetWindowFullscreen( mWindowHandle, 0); + } + + setSize(mode.resolution); + centerWindow(); + } + + mSuppressReset = false; +} + +bool PlatformWindowSDL::clearFullscreen() +{ + return true; +} + +bool PlatformWindowSDL::isFullscreen() +{ + U32 flags = SDL_GetWindowFlags( mWindowHandle ); + if( flags & SDL_WINDOW_FULLSCREEN || flags & SDL_WINDOW_FULLSCREEN_DESKTOP ) + return true; + + return false; +} + +void PlatformWindowSDL::_setFullscreen(const bool fullscreen) +{ + if( isFullscreen() ) + return; + + if(fullscreen && !mOffscreenRender) + { + Con::printf("PlatformWindowSDL::setFullscreen (full) enter"); + SDL_SetWindowFullscreen( mWindowHandle, SDL_WINDOW_FULLSCREEN); + } + else + { + Con::printf("PlatformWindowSDL::setFullscreen (windowed) enter"); + if (!mOffscreenRender) + { + SDL_SetWindowFullscreen( mWindowHandle, SDL_WINDOW_FULLSCREEN_DESKTOP); + } + + setSize(mVideoMode.resolution); + + } + Con::printf("PlatformWindowSDL::setFullscreen exit"); +} + +bool PlatformWindowSDL::setCaption( const char *cap ) +{ + SDL_SetWindowTitle(mWindowHandle, cap); + return true; +} + +const char * PlatformWindowSDL::getCaption() +{ + return StringTable->insert( SDL_GetWindowTitle(mWindowHandle) ); +} + +void PlatformWindowSDL::setFocus() +{ + SDL_SetWindowGrab( mWindowHandle, SDL_TRUE ); +} + +void PlatformWindowSDL::setClientExtent( const Point2I newExtent ) +{ + Point2I oldExtent = getClientExtent(); + if (oldExtent == newExtent) + return; + + SDL_SetWindowSize(mWindowHandle, newExtent.x, newExtent.y); +} + +const Point2I PlatformWindowSDL::getClientExtent() +{ + // Fetch Client Rect from Windows + Point2I size; + SDL_GetWindowSize(mWindowHandle, &size.x, &size.y); + + return size; +} + +void PlatformWindowSDL::setBounds( const RectI &newBounds ) +{ + // TODO SDL +} + +const RectI PlatformWindowSDL::getBounds() const +{ + // TODO SDL + return RectI(0, 0, 0, 0); +} + +void PlatformWindowSDL::setPosition( const Point2I newPosition ) +{ + SDL_SetWindowPosition( mWindowHandle, newPosition.x, newPosition.y ); +} + +const Point2I PlatformWindowSDL::getPosition() +{ + Point2I position; + SDL_GetWindowPosition( mWindowHandle, &position.x, &position.y ); + + // Return position + return position; +} + +Point2I PlatformWindowSDL::clientToScreen( const Point2I& pos ) +{ + Point2I position; + SDL_GetWindowPosition( mWindowHandle, &position.x, &position.y ); + return pos + position; +} + +Point2I PlatformWindowSDL::screenToClient( const Point2I& pos ) +{ + Point2I position; + SDL_GetWindowPosition( mWindowHandle, &position.x, &position.y ); + return pos - position; +} + +void PlatformWindowSDL::centerWindow() +{ + int sizeX, sizeY; + SDL_GetWindowSize(mWindowHandle, &sizeX, &sizeY); + + SDL_DisplayMode mode; + SDL_GetDesktopDisplayMode(0, &mode); + + U32 posX = (mode.w/2) - (sizeX/2); + U32 posY = (mode.h/2) - (sizeY/2); + + SDL_SetWindowPosition( mWindowHandle, posX, posY); +} + +bool PlatformWindowSDL::setSize( const Point2I &newSize ) +{ + SDL_SetWindowSize(mWindowHandle, newSize.x, newSize.y); + + // Let GFX get an update about the new resolution + if (mTarget.isValid()) + mTarget->resetMode(); + + return true; +} + +bool PlatformWindowSDL::isOpen() +{ + return mWindowHandle; +} + +bool PlatformWindowSDL::isVisible() +{ + // Is the window open and visible, ie. not minimized? + if(!mWindowHandle) + return false; + + if (mOffscreenRender) + return true; + + U32 flags = SDL_GetWindowFlags( mWindowHandle ); + if( flags & SDL_WINDOW_SHOWN) + return true; + + return false; +} + +bool PlatformWindowSDL::isFocused() +{ + if (mOffscreenRender) + return true; + + U32 flags = SDL_GetWindowFlags( mWindowHandle ); + if( flags & SDL_WINDOW_INPUT_FOCUS || flags & SDL_WINDOW_INPUT_GRABBED || flags & SDL_WINDOW_MOUSE_FOCUS ) + return true; + + return true; +} + +bool PlatformWindowSDL::isMinimized() +{ + if (mOffscreenRender) + return false; + + U32 flags = SDL_GetWindowFlags( mWindowHandle ); + if( flags & SDL_WINDOW_MINIMIZED) + return true; + + return false; +} + +bool PlatformWindowSDL::isMaximized() +{ + if (mOffscreenRender) + return true; + + U32 flags = SDL_GetWindowFlags( mWindowHandle ); + if( flags & SDL_WINDOW_MAXIMIZED) + return true; + + return false; +} + +WindowId PlatformWindowSDL::getWindowId() +{ + return mWindowId; +} + +void PlatformWindowSDL::minimize() +{ + if (mOffscreenRender) + return; + + SDL_MinimizeWindow( mWindowHandle ); +} + +void PlatformWindowSDL::maximize() +{ + if (mOffscreenRender) + return; + + SDL_MaximizeWindow( mWindowHandle ); +} + +void PlatformWindowSDL::restore() +{ + if (mOffscreenRender) + return; + + SDL_RestoreWindow( mWindowHandle ); +} + +void PlatformWindowSDL::hide() +{ + if (mOffscreenRender) + return; + + SDL_HideWindow( mWindowHandle ); +} + +void PlatformWindowSDL::show() +{ + if (mOffscreenRender) + return; + + SDL_ShowWindow( mWindowHandle ); +} + +void PlatformWindowSDL::close() +{ + delete this; +} + +void PlatformWindowSDL::defaultRender() +{ + // TODO SDL +} + +void PlatformWindowSDL::_triggerMouseLocationNotify(const SDL_Event& evt) +{ + if(!mMouseLocked) + mouseEvent.trigger(getWindowId(), 0, evt.motion.x, evt.motion.y, false); + else + mouseEvent.trigger(getWindowId(), 0, evt.motion.xrel, evt.motion.yrel, true); +} + +void PlatformWindowSDL::_triggerMouseButtonNotify(const SDL_Event& event) +{ + S32 action = (event.type == SDL_MOUSEBUTTONDOWN) ? SI_MAKE : SI_BREAK; + S32 button = -1; + + switch (event.button.button) + { + case SDL_BUTTON_LEFT: + button = 0; + break; + case SDL_BUTTON_RIGHT: + button = 1; + break; + case SDL_BUTTON_MIDDLE: + button = 2; + break; + default: + return; + } + + U32 mod = getTorqueModFromSDL( SDL_GetModState() ); + buttonEvent.trigger(getWindowId(), mod, action, button ); +} + +void PlatformWindowSDL::_triggerKeyNotify(const SDL_Event& evt) +{ + U32 inputAction = IA_MAKE; + SDL_Keysym tKey = evt.key.keysym; + + if(evt.type == SDL_KEYUP) + { + inputAction = IA_BREAK; + } + + if(evt.key.repeat) + { + inputAction = IA_REPEAT; + } + + U32 torqueModifiers = getTorqueModFromSDL(evt.key.keysym.mod); + U32 torqueKey = KeyMapSDL::getTorqueScanCodeFromSDL(tKey.scancode); + if(tKey.scancode) + { + keyEvent.trigger(getWindowId(), torqueModifiers, inputAction, torqueKey); + //Con::printf("Key %d : %d", tKey.sym, inputAction); + } + + // stop SDL_TEXTINPUT event when unwanted + if( inputAction == IA_MAKE && getKeyboardTranslation() && shouldNotTranslate( torqueModifiers, torqueKey ) ) + SDL_StopTextInput(); + else + SDL_StartTextInput(); +} + +void PlatformWindowSDL::_triggerTextNotify(const SDL_Event& evt) +{ + U32 mod = getTorqueModFromSDL( SDL_GetModState() ); + + if( !evt.text.text[1] ) // get a char + { + U16 wchar = evt.text.text[0]; + charEvent.trigger(getWindowId(), mod, wchar ); + //Con::printf("Char: %c", wchar); + return; + } + else // get a wchar string + { + const U32 len = strlen(evt.text.text); + U16 wchar[16] = {}; + dMemcpy(wchar, evt.text.text, sizeof(char)*len); + + for(int i = 0; i < 16; ++i) + { + if( !wchar[i] ) + return; + + charEvent.trigger(getWindowId(), mod, wchar[i] ); + } + } +} + +void PlatformWindowSDL::_processSDLEvent(SDL_Event &evt) +{ + switch(evt.type) + { + case SDL_KEYDOWN: + case SDL_KEYUP: + { + _triggerKeyNotify(evt); + break; + } + + case SDL_TEXTINPUT: + { + _triggerTextNotify(evt); + break; + } + + case SDL_MOUSEMOTION: + { + _triggerMouseLocationNotify(evt); + break; + } + + case SDL_MOUSEBUTTONDOWN: + case SDL_MOUSEBUTTONUP: + { + appEvent.trigger(getWindowId(), GainFocus); + _triggerMouseButtonNotify(evt); + + break; + } + + case SDL_WINDOWEVENT: + { + switch( evt.window.event ) + { + case SDL_WINDOWEVENT_MAXIMIZED: + case SDL_WINDOWEVENT_RESIZED: + { + int width, height; + SDL_GetWindowSize( mWindowHandle, &width, &height ); + mVideoMode.resolution.set( width, height ); + getGFXTarget()->resetMode(); + break; + } + + default: + break; + } + } + } + +} + +//----------------------------------------------------------------------------- +// Mouse Locking +//----------------------------------------------------------------------------- + +void PlatformWindowSDL::setMouseLocked( bool enable ) +{ + if (mOffscreenRender) + return; + + mMouseLocked = enable; + + SDL_SetWindowGrab( mWindowHandle, SDL_bool(enable) ); + SDL_SetRelativeMouseMode( SDL_bool(enable) ); +} + +const UTF16 *PlatformWindowSDL::getWindowClassName() +{ + // TODO SDL + static String str("WindowClassName"); + return str.utf16(); +} + +const UTF16 *PlatformWindowSDL::getCurtainWindowClassName() +{ + // TODO SDL + static String str("CurtainWindowClassName"); + return str.utf16(); +} diff --git a/Engine/source/windowManager/sdl/sdlWindow.h b/Engine/source/windowManager/sdl/sdlWindow.h new file mode 100644 index 000000000..5c809da07 --- /dev/null +++ b/Engine/source/windowManager/sdl/sdlWindow.h @@ -0,0 +1,184 @@ +//----------------------------------------------------------------------------- +// 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. +//----------------------------------------------------------------------------- + +#ifndef _WINDOWMANAGER_SDL_WINDOW_ +#define _WINDOWMANAGER_SDL_WINDOW_ + +#include "windowManager/platformWindowMgr.h" +#include "gfx/gfxTarget.h" +#include "gfx/gfxStructs.h" +#include "sim/actionMap.h" + +class PlatformWindowManagerSDL; +struct SDL_Window; +union SDL_Event; + +/// Implementation of a window on SDL. +class PlatformWindowSDL : public PlatformWindow +{ + friend class PlatformWindowManagerSDL; + +private: + + /// @name Active window list + /// + /// Items used to track window instances. + /// + /// @{ + + /// Which manager created us? + PlatformWindowManagerSDL *mOwningManager; + + /// Which window comes next in list? + PlatformWindowSDL *mNextWindow; + + /// @} + + /// @name Window Information + /// + /// @{ + + /// Our SDL window. + SDL_Window *mWindowHandle; + + /// Our former Parent + SDL_Window *mOldParent; + + /// The GFX device that we're tied to. + GFXDevice *mDevice; + + /// Reference to the render target allocated on this window. + GFXWindowTargetRef mTarget; + + /// Our current size/resolution/fullscreen status. + GFXVideoMode mVideoMode; + + /// Our position on the desktop. + Point2I mPosition; + + /// Is the mouse locked to this window? + bool mMouseLocked; + + /// Determines whether this window should lock the mouse when it has an opportunity + bool mShouldLockMouse; + + /// When set, we don't trigger device resets due to sizing events. + bool mSuppressReset; + + /// Menu associated with this window. This is a passive property of the window and is not required to be used at all. + void* mMenuHandle; + + /// @} + + void _processSDLEvent(SDL_Event &evt); + void _triggerMouseLocationNotify(const SDL_Event& evt); + void _triggerMouseButtonNotify(const SDL_Event& event); + void _triggerKeyNotify(const SDL_Event& event); + void _triggerTextNotify(const SDL_Event& event); + +public: + PlatformWindowSDL(); + ~PlatformWindowSDL(); + + virtual void* getSystemWindow(const WindowSystem system); + + void* &getMenuHandle() + { + return mMenuHandle; + } + + void setMenuHandle( void* menuHandle ) + { + mMenuHandle = menuHandle; + } + + virtual GFXDevice *getGFXDevice(); + virtual GFXWindowTarget *getGFXTarget(); + + virtual void setVideoMode(const GFXVideoMode &mode); + virtual const GFXVideoMode &getVideoMode(); + virtual bool clearFullscreen(); + virtual bool isFullscreen(); + virtual void _setFullscreen(const bool fullscreen); + + virtual bool setCaption(const char *cap); + virtual const char *getCaption(); + + // Window Client Area Extent + virtual void setClientExtent( const Point2I newExtent ); + virtual const Point2I getClientExtent(); + + // Window Bounds + virtual void setBounds(const RectI &newBounds); + virtual const RectI getBounds() const; + + // Window Position + virtual void setPosition( const Point2I newPosition ); + virtual const Point2I getPosition(); + virtual void centerWindow(); + virtual bool setSize(const Point2I &newSize); + + // Coordinate space conversion. + virtual Point2I clientToScreen( const Point2I& pos ); + virtual Point2I screenToClient( const Point2I& pos ); + + virtual bool isOpen(); + virtual bool isVisible(); + virtual bool isFocused(); + virtual bool isMinimized(); + virtual bool isMaximized(); + + virtual void minimize(); + virtual void maximize(); + virtual void hide(); + virtual void show(); + virtual void close(); + virtual void restore(); + virtual void setFocus(); + + virtual void setMouseLocked(bool enable); + virtual bool isMouseLocked() const { return mMouseLocked; }; + virtual bool shouldLockMouse() const { return mShouldLockMouse; }; + + virtual WindowId getWindowId(); + + SDL_Window* getSDLWindow() const { return mWindowHandle; } + + virtual PlatformWindow * getNextWindow() const + { + return mNextWindow; + } + + /// Provide a simple GDI-based render for when the game is not rendering. + virtual void defaultRender(); + + /// Return the class name for the windows we create with this class. + static const UTF16 *getWindowClassName(); + + /// Return the class name for the curtain window class. + static const UTF16 *getCurtainWindowClassName(); + + /// Return the platform specific object needed to create or attach an + /// accelerated graohics drawing context on or to the window + virtual void* getPlatformDrawable() const { return mWindowHandle; } +}; +#endif diff --git a/Engine/source/windowManager/sdl/sdlWindowMgr.cpp b/Engine/source/windowManager/sdl/sdlWindowMgr.cpp new file mode 100644 index 000000000..788981dac --- /dev/null +++ b/Engine/source/windowManager/sdl/sdlWindowMgr.cpp @@ -0,0 +1,369 @@ +//----------------------------------------------------------------------------- +// 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 "windowManager/sdl/sdlWindowMgr.h" +#include "gfx/gfxDevice.h" +#include "core/util/journal/process.h" +#include "core/strings/unicode.h" + +#include "SDL.h" + +// ------------------------------------------------------------------------ + +void sdl_CloseSplashWindow(void* hinst); + +#ifdef TORQUE_SDL + +PlatformWindowManager * CreatePlatformWindowManager() +{ + return new PlatformWindowManagerSDL(); +} + +#endif + +// ------------------------------------------------------------------------ + +PlatformWindowManagerSDL::PlatformWindowManagerSDL() +{ + // Register in the process list. + mOnProcessSignalSlot.setDelegate( this, &PlatformWindowManagerSDL::_process ); + Process::notify( mOnProcessSignalSlot, PROCESS_INPUT_ORDER ); + + // Init our list of allocated windows. + mWindowListHead = NULL; + + // By default, we have no parent window. + mParentWindow = NULL; + + mCurtainWindow = NULL; + + mDisplayWindow = true; + mOffscreenRender = false; + + buildMonitorsList(); +} + +PlatformWindowManagerSDL::~PlatformWindowManagerSDL() +{ + // Kill all our windows first. + while(mWindowListHead) + // The destructors update the list, so this works just fine. + delete mWindowListHead; +} + +RectI PlatformWindowManagerSDL::getPrimaryDesktopArea() +{ + // TODO SDL + AssertFatal(0, ""); + return RectI(0,0,0,0); +} + +Point2I PlatformWindowManagerSDL::getDesktopResolution() +{ + SDL_DisplayMode mode; + SDL_GetDesktopDisplayMode(0, &mode); + + // Return Resolution + return Point2I(mode.w, mode.h); +} + +S32 PlatformWindowManagerSDL::getDesktopBitDepth() +{ + // Return Bits per Pixel + SDL_DisplayMode mode; + SDL_GetDesktopDisplayMode(0, &mode); + int bbp; + unsigned int r,g,b,a; + SDL_PixelFormatEnumToMasks(mode.format, &bbp, &r, &g, &b, &a); + return bbp; +} + +void PlatformWindowManagerSDL::buildMonitorsList() +{ + // TODO SDL +} + +S32 PlatformWindowManagerSDL::findFirstMatchingMonitor(const char* name) +{ + /// TODO SDL + AssertFatal(0, ""); + + return 0; +} + +U32 PlatformWindowManagerSDL::getMonitorCount() +{ + // TODO SDL + AssertFatal(0, ""); + return 1; +} + +const char* PlatformWindowManagerSDL::getMonitorName(U32 index) +{ + // TODO SDL + AssertFatal(0, ""); + + return "Monitor"; +} + +RectI PlatformWindowManagerSDL::getMonitorRect(U32 index) +{ + // TODO SDL + AssertFatal(0, ""); + + return RectI(0, 0, 0,0 ); +} + +void PlatformWindowManagerSDL::getMonitorRegions(Vector ®ions) +{ + // TODO SDL + AssertFatal(0, ""); +} + +void PlatformWindowManagerSDL::getWindows(VectorPtr &windows) +{ + PlatformWindowSDL *win = mWindowListHead; + while(win) + { + windows.push_back(win); + win = win->mNextWindow; + } +} + +PlatformWindow *PlatformWindowManagerSDL::createWindow(GFXDevice *device, const GFXVideoMode &mode) +{ + // Do the allocation. + PlatformWindowSDL *window = new PlatformWindowSDL(); + U32 windowFlags = /*SDL_WINDOW_SHOWN |*/ SDL_WINDOW_RESIZABLE; + + if(GFX->getAdapterType() == OpenGL) + windowFlags |= SDL_WINDOW_OPENGL; + + window->mWindowHandle = SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, mode.resolution.x, mode.resolution.y, windowFlags ); + window->mWindowId = SDL_GetWindowID( window->mWindowHandle ); + window->mOwningManager = this; + mWindowMap[ window->mWindowId ] = window; + + if(device) + { + window->mDevice = device; + window->mTarget = device->allocWindowTarget(window); + AssertISV(window->mTarget, "PlatformWindowManagerSDL::createWindow - failed to get a window target back from the device."); + } + else + { + Con::warnf("PlatformWindowManagerSDL::createWindow - created a window with no device!"); + } + + linkWindow(window); + + return window; +} + + +void PlatformWindowManagerSDL::setParentWindow(void* newParent) +{ + +} + +void* PlatformWindowManagerSDL::getParentWindow() +{ + return NULL; +} + +void PlatformWindowManagerSDL::_process() +{ + SDL_Event evt; + while( SDL_PollEvent(&evt) ) + { + switch(evt.type) + { + case SDL_QUIT: + { + PlatformWindowSDL *window = static_cast( getFirstWindow() ); + if(window) + window->appEvent.trigger( window->getWindowId(), WindowClose ); + break; + } + + case SDL_KEYDOWN: + case SDL_KEYUP: + { + PlatformWindowSDL *window = mWindowMap[evt.key.windowID]; + if(window) + window->_processSDLEvent(evt); + break; + } + + case SDL_MOUSEMOTION: + { + PlatformWindowSDL *window = mWindowMap[evt.motion.windowID]; + if(window) + window->_processSDLEvent(evt); + break; + } + + case SDL_MOUSEBUTTONDOWN: + case SDL_MOUSEBUTTONUP: + { + PlatformWindowSDL *window = mWindowMap[evt.button.windowID]; + if(window) + window->_processSDLEvent(evt); + break; + } + + case SDL_TEXTINPUT: + { + PlatformWindowSDL *window = mWindowMap[evt.text.windowID]; + if(window) + window->_processSDLEvent(evt); + break; + } + + case SDL_WINDOWEVENT: + { + PlatformWindowSDL *window = mWindowMap[evt.window.windowID]; + if(window) + window->_processSDLEvent(evt); + break; + } + + default: + { + //Con::printf("Event: %d", evt.type); + } + } + } + +} + +PlatformWindow * PlatformWindowManagerSDL::getWindowById( WindowId id ) +{ + // Walk the list and find the matching id, if any. + PlatformWindowSDL *win = mWindowListHead; + while(win) + { + if(win->getWindowId() == id) + return win; + + win = win->mNextWindow; + } + + return NULL; +} + +PlatformWindow * PlatformWindowManagerSDL::getFirstWindow() +{ + return mWindowListHead != NULL ? mWindowListHead : NULL; +} + +PlatformWindow* PlatformWindowManagerSDL::getFocusedWindow() +{ + PlatformWindowSDL* window = mWindowListHead; + while( window ) + { + if( window->isFocused() ) + return window; + + window = window->mNextWindow; + } + + return NULL; +} + +void PlatformWindowManagerSDL::linkWindow( PlatformWindowSDL *w ) +{ + w->mNextWindow = mWindowListHead; + mWindowListHead = w; +} + +void PlatformWindowManagerSDL::unlinkWindow( PlatformWindowSDL *w ) +{ + PlatformWindowSDL **walk = &mWindowListHead; + while(*walk) + { + if(*walk != w) + { + // Advance to next item in list. + walk = &(*walk)->mNextWindow; + continue; + } + + // Got a match - unlink and return. + *walk = (*walk)->mNextWindow; + return; + } +} + +void PlatformWindowManagerSDL::_processCmdLineArgs( const S32 argc, const char **argv ) +{ + // TODO SDL +} + +void PlatformWindowManagerSDL::lowerCurtain() +{ + if(mCurtainWindow) + return; + + // TODO SDL +} + +void PlatformWindowManagerSDL::raiseCurtain() +{ + if(!mCurtainWindow) + return; + + // TODO SDL +} + +bool Platform::closeSplashWindow() +{ + return true; +} + +void Platform::openFolder(const char* path ) +{ + AssertFatal(0, "Not Implemented"); +} + +void Platform::openFile(const char* path ) +{ + AssertFatal(0, "Not Implemented"); +} + +//------------------------------------------------------------------------------ + +namespace GL +{ + void gglPerformBinds(); +} + +void InitWindowingSystem() +{ + +} + +AFTER_MODULE_INIT(gfx) +{ + int res = SDL_Init( SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | SDL_INIT_GAMECONTROLLER | SDL_INIT_EVENTS | SDL_INIT_NOPARACHUTE ); + AssertFatal(res != -1, "SDL init error"); +} diff --git a/Engine/source/windowManager/sdl/sdlWindowMgr.h b/Engine/source/windowManager/sdl/sdlWindowMgr.h new file mode 100644 index 000000000..52f2c7ea1 --- /dev/null +++ b/Engine/source/windowManager/sdl/sdlWindowMgr.h @@ -0,0 +1,105 @@ +//----------------------------------------------------------------------------- +// 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. +//----------------------------------------------------------------------------- + +#ifndef _WINDOWMANAGER_SDL_WINDOWMANAGER_ +#define _WINDOWMANAGER_SDL_WINDOWMANAGER_ + +#include "math/mMath.h" +#include "gfx/gfxStructs.h" +#include "windowManager/sdl/sdlWindow.h" +#include "core/util/tVector.h" + +struct SDL_Window; +class FileDialog; // TODO SDL REMOVE + +/// SDL2 implementation of the window manager interface. +class PlatformWindowManagerSDL : public PlatformWindowManager +{ + friend class PlatformWindowSDL; + friend class FileDialog; // TODO SDL REMOVE + + virtual void _processCmdLineArgs(const S32 argc, const char **argv); + + /// Link the specified window into the window list. + void linkWindow(PlatformWindowSDL *w); + + /// Remove specified window from the window list. + void unlinkWindow(PlatformWindowSDL *w); + + /// Callback for the process list. + void _process(); + + /// List of allocated windows. + PlatformWindowSDL *mWindowListHead; + + /// Parent window, used in window setup in web plugin scenarios. + SDL_Window *mParentWindow; + + /// This is set as part of the canvas being shown, and flags that the windows should render as normal from now on. + // Basically a flag that lets the window manager know that we've handled the splash screen, and to operate as normal. + bool mDisplayWindow; + + /// set via command line -offscreen option, controls whether rendering/input + // is intended for offscreen rendering + bool mOffscreenRender; + + /// If a curtain window is present, then will be stored here. + SDL_Window *mCurtainWindow; + + Map mWindowMap; + + SignalSlot mOnProcessSignalSlot; + +public: + PlatformWindowManagerSDL(); + ~PlatformWindowManagerSDL(); + + virtual RectI getPrimaryDesktopArea(); + virtual S32 getDesktopBitDepth(); + virtual Point2I getDesktopResolution(); + + /// Build out the monitors list. + virtual void buildMonitorsList(); + + virtual S32 findFirstMatchingMonitor(const char* name); + virtual U32 getMonitorCount(); + virtual const char* getMonitorName(U32 index); + virtual RectI getMonitorRect(U32 index); + + virtual void getMonitorRegions(Vector ®ions); + virtual PlatformWindow *createWindow(GFXDevice *device, const GFXVideoMode &mode); + virtual void getWindows(VectorPtr &windows); + + virtual void setParentWindow(void* newParent); + virtual void* getParentWindow(); + + virtual PlatformWindow *getWindowById(WindowId id); + virtual PlatformWindow *getFirstWindow(); + virtual PlatformWindow* getFocusedWindow(); + + virtual void lowerCurtain(); + virtual void raiseCurtain(); + + virtual void setDisplayWindow(bool set) { mDisplayWindow = set; } +}; + +#endif \ No newline at end of file diff --git a/Templates/Empty/game/core/scripts/gui/FileDialog.cs b/Templates/Empty/game/core/scripts/gui/FileDialog.cs new file mode 100644 index 000000000..c5e693a80 --- /dev/null +++ b/Templates/Empty/game/core/scripts/gui/FileDialog.cs @@ -0,0 +1,308 @@ +exec("./FileDialog.gui"); + +function PlatformFileDialog::buildFilters(%this) +{ + %str = strreplace( %this.data.filters, "|", "\t"); + %this.filterCount = getFieldCount( %str ) / 2; + //echo( "Filter count: " @ %str ); + for( %i = 0; %i < %this.filterCount; %i++ ) + { + %this.filterName[%i] = GetField( %str, (%i*2) + 0 ); + %this.filter[%i] = strreplace( GetField( %str, (%i*2) + 1 ), ";", "\t"); + //echo( "Filter: " @ %this.filterName[%i] @ " - " @ %this.filter[%i]); + } +} + +function PlatformFileDialog::handleFlags(%this, %flags) +{ + %this.FDS_OPEN = false; + %this.FDS_SAVE = false; + %this.FDS_OVERWRITEPROMPT = false; + %this.FDS_MUSTEXIST = false; + %this.FDS_BROWSEFOLDER = false; + + %flagCount = getFieldCount( %flags ); + + //echo( "flag count: " @ %flagCount ); + + for( %i = 0; %i < %flagCount; %i++ ) + { + %flag = GetField( %flags, %i ); + //echo(%flag); + if( %flag $= "FDS_OPEN" ) + { + %this.FDS_OPEN = true; + %this-->Button.setText( "OPEN" ); + %this-->Button.command = "PlatformFileDialog.tryFile();"; + %this-->window.text = "Select file to OPEN"; + } + else if( %flag $= "FDS_SAVE" ) + { + %this.FDS_SAVE = true; + %this-->Button.setText( "SAVE" ); + %this-->Button.command = "PlatformFileDialog.tryFile();"; + %this-->window.text = "Select file to Save"; + } + else if( %flag $= "FDS_OVERWRITEPROMPT" ) + { + %this.FDS_OVERWRITEPROMPT = true; + } + else if( %flag $= "FDS_MUSTEXIST" ) + { + %this.FDS_MUSTEXIST = true; + } + else if( %flag $= "FDS_BROWSEFOLDER" ) + { + %this.FDS_BROWSEFOLDER = true; + %this-->window.text = "Select folder to OPEN"; + } + } +} + +function OpenPlatformFileDialog(%data, %flags) +{ + PlatformFileDialog.searchDir = ""; + PlatformFileDialog-->fileNameEdit.setText( "" ); + PlatformFileDialog.data = %data; + PlatformFileDialog.data.finished = 0; + + PlatformFileDialog.handleFlags( %flags ); + + if( !isObject(PlatformFileDialog.freeItemSet) ) + { + PlatformFileDialog.freeItemSet = new SimGroup(); + } + + PlatformFileDialog.buildFilters(); + + Canvas.pushDialog(PlatformFileDialog); +} + +function PlatformFileDialog::changeDir( %this, %newDir ) +{ + %this.searchDir = %newDir; + %this.update(); +} + +function PlatformFileDialog::navigateUp( %this ) +{ + //echo( "PlatformFileDialog::navigateUp " @ %this.searchDir ); + if( %this.searchDir !$= "" ) + { + %str = strreplace( %this.searchDir, "/", "\t"); + %count = getFieldCount( %str ); + + if ( %count == 0 ) + return; + + if ( %count == 1 ) + %address = ""; + else + %address = getFields( %str, 0, %count - 2 ); + + %newDir = strreplace( %address, "\t", "/" ); + + if( %newDir !$= "" ) + %newDir = %newDir @ "/"; + + %this.changeDir( %newDir ); + + } +} + +function PlatformFileDialog::cancel( %this ) +{ + %this.data.files[0] = ""; + %this.data.fileCount = 0; + %this.data.finished = 1; + + Canvas.popDialog(%this); +} + +function FileDialogItem::onClick( %this ) +{ + PlatformFileDialog-->fileNameEdit.setText( "" ); + + if( %this.isDir && %this.FDS_BROWSEFOLDER) + { + PlatformFileDialog-->fileNameEdit.setText( %this.text ); + } + else if( !%this.isDir && !%this.FDS_BROWSEFOLDER ) + { + PlatformFileDialog-->fileNameEdit.setText( %this.text ); + } +} + +function FileDialogItem::onDoubleClick( %this ) +{ + PlatformFileDialog-->fileNameEdit.setText( "" ); + + if( %this.isDir ) + { + PlatformFileDialog.changeDir( PlatformFileDialog.searchDir @ %this.text @ "/" ); + } +} + +function PlatformFileDialog::tryFile( %this ) +{ + %file = %this-->fileNameEdit.getText(); + if( %file $= "" ) + return; + + if( %this.FDS_OVERWRITEPROMPT ) + { + %callback = "PlatformFileDialog.onFile( \"" @ %file @ "\" );"; + MessageBoxOKCancel("Confirm overwrite", "Confirm overwrite", %callback, ""); + return; + } + + %this.onFile( %file ); +} + +function PlatformFileDialog::onFile( %this, %file ) +{ + %this.data.files[0] = ""; + %this.data.fileCount = 0; + + if( %file !$= "" ) + { + %file = %this.searchDir @ %file; + %this.data.fileCount = 1; + } + + if( %this.FDS_BROWSEFOLDER && !isDirectory( %file ) ) + { + echo("Select a directory"); + return; + } + else if( !%this.FDS_BROWSEFOLDER && !isFile( %file ) ) + { + echo("Select a file"); + return; + } + + if( %this.FDS_MUSTEXIST ) + { + if( !isFile( %file ) && !isDirectory( %file ) ) + { + echo("Target must exist: " @ %file ); + return; + } + } + + %this.data.finished = 1; + %this.data.files[0] = %file; + + Canvas.popDialog(%this); + + %this-->fileNameEdit.setText( "" ); +} + +function PlatformFileDialog::clear( %this ) +{ + %itemArray = %this-->itemArray; + + while( %itemArray.getCount() ) + { + %item = %itemArray.getObject( 0 ); + %this.freeItem( %item ); + } +} + +function PlatformFileDialog::getNewItem( %this ) +{ + if( %this.freeItemSet.getCount() ) + %item = %this.freeItemSet.getObject( 0 ); + + if( isObject(%item) ) + { + %this.freeItemSet.remove( %item ); + } + else + { + //create new + %item = new GuiIconButtonCtrl(); + %item.className = "FileDialogItem"; + %item.profile = "ToolsGuiIconButtonProfile"; + %item.textLocation = "left"; + %item.iconLocation = "left"; + %item.iconBitmap = ""; + %item.text = ""; + } + + return %item; +} + +function PlatformFileDialog::freeItem( %this, %item ) +{ + %this-->itemArray.remove( %item ); + + //clear + %item.setText( "" ); + %item.iconBitmap = ""; + %item.textMargin = 0; + %item.textLocation = "left"; + %item.iconLocation = "left"; + %item.resetState(); + + PlatformFileDialog.freeItemSet.add( %item ); +} + +function PlatformFileDialog::addDir( %this, %dir ) +{ + //echo( "Dir: " @ %dir ); + %item = %this.getNewItem(); + %item.setText( %dir ); + %item.isDir = true; + %item.iconBitmap = "core/art/gui/images/folder"; + %item.textLocation = "left"; + %item.iconLocation = "left"; + %item.textMargin = 24; + %this-->itemArray.add( %item ); +} + +function PlatformFileDialog::addFile( %this, %file ) +{ + //echo( "File: " @ %file ); + %item = %this.getNewItem(); + %item.text = strreplace( %file, %this.searchDir, "" ); + %item.isDir = false; + %this-->itemArray.add( %item ); +} + +function PlatformFileDialog::onWake( %this ) +{ + %this.update(); +} + +function PlatformFileDialog::onSleep( %this ) +{ + %this.data.finished = 1; +} + +function PlatformFileDialog::update( %this ) +{ + %this.clear(); + + %this-->popUpMenu.text = %this.searchDir; + + // dirs + %dirList = getDirectoryList( %this.searchDir, 0 ); + %wordCount = getFieldCount( %dirList ); + for( %i = 0; %i < %wordCount; %i++ ) + { + %dirItem = GetField( %dirList, %i ); + %this.addDir( %dirItem ); + } + + //files + %pattern = %this.filter[0]; + //echo( %pattern ); + %file = findFirstFileMultiExpr( %this.searchDir @ %pattern, false); + + while( %file !$= "" ) + { + %this.addFile( %file ); + %file = findNextFileMultiExpr( %pattern ); + } +} \ No newline at end of file diff --git a/Templates/Empty/game/core/scripts/gui/FileDialog.gui b/Templates/Empty/game/core/scripts/gui/FileDialog.gui new file mode 100644 index 000000000..e855636f0 --- /dev/null +++ b/Templates/Empty/game/core/scripts/gui/FileDialog.gui @@ -0,0 +1,293 @@ +//--- OBJECT WRITE BEGIN --- +%guiContent = new GuiControl(PlatformFileDialog) { + position = "0 0"; + extent = "1024 768"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "GuiDefaultProfile"; + visible = "1"; + active = "1"; + tooltipProfile = "GuiToolTipProfile"; + hovertime = "1000"; + isContainer = "1"; + canSave = "1"; + canSaveDynamicFields = "1"; + + new GuiWindowCtrl() { + text = ""; + resizeWidth = "1"; + resizeHeight = "1"; + canMove = "1"; + canClose = "1"; + canMinimize = "1"; + canMaximize = "1"; + canCollapse = "0"; + closeCommand = "PlatformFileDialog.cancel();"; + edgeSnap = "1"; + margin = "0 0 0 0"; + padding = "0 0 0 0"; + anchorTop = "1"; + anchorBottom = "0"; + anchorLeft = "1"; + anchorRight = "0"; + position = "135 113"; + extent = "727 623"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "GuiWindowProfile"; + visible = "1"; + active = "1"; + tooltipProfile = "GuiToolTipProfile"; + hovertime = "1000"; + isContainer = "1"; + internalName = "window"; + canSave = "1"; + canSaveDynamicFields = "0"; + + new GuiControl() { + position = "2 16"; + extent = "717 37"; + minExtent = "8 2"; + horizSizing = "width"; + vertSizing = "bottom"; + profile = "ToolsGuiDefaultProfile"; + visible = "1"; + active = "1"; + tooltipProfile = "ToolsGuiToolTipProfile"; + hovertime = "1000"; + isContainer = "1"; + canSave = "1"; + canSaveDynamicFields = "0"; + + new GuiBitmapButtonCtrl() { + bitmap = "tools/gui/images/folderUp"; + bitmapMode = "Stretched"; + autoFitExtents = "0"; + useModifiers = "0"; + useStates = "1"; + groupNum = "0"; + buttonType = "PushButton"; + useMouseEvents = "0"; + position = "9 9"; + extent = "20 19"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "ToolsGuiButtonProfile"; + visible = "1"; + active = "1"; + command = "PlatformFileDialog.navigateUp();"; + tooltipProfile = "ToolsGuiToolTipProfile"; + hovertime = "1000"; + isContainer = "0"; + internalName = "folderUpButton"; + canSave = "1"; + canSaveDynamicFields = "0"; + }; + new GuiPopUpMenuCtrl() { + maxPopupHeight = "200"; + sbUsesNAColor = "0"; + reverseTextList = "0"; + bitmapBounds = "16 16"; + maxLength = "1024"; + margin = "0 0 0 0"; + padding = "0 0 0 0"; + anchorTop = "1"; + anchorBottom = "0"; + anchorLeft = "1"; + anchorRight = "0"; + position = "36 9"; + extent = "666 18"; + minExtent = "8 2"; + horizSizing = "width"; + vertSizing = "bottom"; + profile = "ToolsGuiPopUpMenuProfile"; + visible = "1"; + active = "1"; + tooltipProfile = "ToolsGuiToolTipProfile"; + hovertime = "1000"; + isContainer = "0"; + internalName = "PopupMenu"; + canSave = "1"; + canSaveDynamicFields = "0"; + }; + }; + new GuiScrollCtrl() { + willFirstRespond = "1"; + hScrollBar = "dynamic"; + vScrollBar = "alwaysOff"; + lockHorizScroll = "0"; + lockVertScroll = "1"; + constantThumbHeight = "0"; + childMargin = "0 0"; + mouseWheelScrollSpeed = "-1"; + docking = "None"; + margin = "0 0 0 0"; + padding = "0 0 0 0"; + anchorTop = "0"; + anchorBottom = "1"; + anchorLeft = "1"; + anchorRight = "0"; + position = "7 64"; + extent = "712 509"; + minExtent = "8 2"; + horizSizing = "width"; + vertSizing = "height"; + profile = "GuiScrollProfile"; + visible = "1"; + active = "1"; + tooltipProfile = "ToolsGuiToolTipProfile"; + hovertime = "1000"; + isContainer = "1"; + canSave = "1"; + canSaveDynamicFields = "0"; + + new GuiDynamicCtrlArrayControl() { + colCount = "1"; + colSize = "64"; + rowCount = "1"; + rowSize = "258"; + rowSpacing = "4"; + colSpacing = "4"; + frozen = "0"; + autoCellSize = "1"; + fillRowFirst = "0"; + dynamicSize = "1"; + padding = "0 0 0 0"; + position = "1 1"; + extent = "666 507"; + minExtent = "8 2"; + horizSizing = "width"; + vertSizing = "height"; + profile = "ToolsGuiTransparentProfile"; + visible = "1"; + active = "1"; + tooltipProfile = "ToolsGuiToolTipProfile"; + hovertime = "1000"; + isContainer = "1"; + internalName = "itemArray"; + canSave = "1"; + canSaveDynamicFields = "0"; + }; + }; + new GuiContainer() { + docking = "Bottom"; + margin = "0 0 0 0"; + padding = "0 0 0 0"; + anchorTop = "0"; + anchorBottom = "1"; + anchorLeft = "1"; + anchorRight = "1"; + position = "1 583"; + extent = "725 37"; + minExtent = "8 2"; + horizSizing = "width"; + vertSizing = "bottom"; + profile = "GuiDefaultProfile"; + visible = "1"; + active = "1"; + tooltipProfile = "GuiToolTipProfile"; + hovertime = "1000"; + isContainer = "1"; + canSave = "1"; + canSaveDynamicFields = "0"; + + new GuiTextCtrl() { + text = "File Name"; + maxLength = "1024"; + margin = "0 0 0 0"; + padding = "0 0 0 0"; + anchorTop = "1"; + anchorBottom = "0"; + anchorLeft = "1"; + anchorRight = "0"; + position = "10 -1"; + extent = "51 30"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "GuiTextProfile"; + visible = "1"; + active = "1"; + tooltipProfile = "GuiToolTipProfile"; + hovertime = "1000"; + isContainer = "1"; + canSave = "1"; + canSaveDynamicFields = "0"; + }; + new GuiTextEditCtrl() { + historySize = "0"; + tabComplete = "0"; + sinkAllKeyEvents = "0"; + password = "0"; + passwordMask = "*"; + maxLength = "1024"; + margin = "0 0 0 0"; + padding = "0 0 0 0"; + anchorTop = "1"; + anchorBottom = "0"; + anchorLeft = "1"; + anchorRight = "0"; + position = "58 5"; + extent = "561 18"; + minExtent = "8 2"; + horizSizing = "width"; + vertSizing = "bottom"; + profile = "GuiTextEditProfile"; + visible = "1"; + active = "1"; + tooltipProfile = "GuiToolTipProfile"; + hovertime = "1000"; + isContainer = "1"; + internalName = "fileNameEdit"; + canSave = "1"; + canSaveDynamicFields = "0"; + }; + new GuiContainer() { + docking = "Right"; + margin = "0 0 0 0"; + padding = "0 0 0 0"; + anchorTop = "0"; + anchorBottom = "0"; + anchorLeft = "0"; + anchorRight = "0"; + position = "630 0"; + extent = "95 37"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "GuiDefaultProfile"; + visible = "1"; + active = "1"; + tooltipProfile = "GuiToolTipProfile"; + hovertime = "1000"; + isContainer = "1"; + canSave = "1"; + canSaveDynamicFields = "0"; + + new GuiButtonCtrl() { + groupNum = "-1"; + buttonType = "PushButton"; + useMouseEvents = "1"; + position = "6 1"; + extent = "81 24"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "GuiButtonProfile"; + visible = "1"; + active = "1"; + tooltipProfile = "GuiToolTipProfile"; + hovertime = "1000"; + isContainer = "0"; + internalName = "Button"; + canSave = "1"; + canSaveDynamicFields = "0"; + }; + }; + }; + }; +}; +//--- OBJECT WRITE END --- diff --git a/Templates/Empty/game/shaders/common/lighting/shadowMap/shadowMapIO.h b/Templates/Empty/game/shaders/common/lighting/shadowMap/shadowMapIO.h new file mode 100644 index 000000000..84ef6b6a8 --- /dev/null +++ b/Templates/Empty/game/shaders/common/lighting/shadowMap/shadowMapIO.h @@ -0,0 +1,50 @@ +//----------------------------------------------------------------------------- +// 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. +//----------------------------------------------------------------------------- + +//#define SM_Fmt_R8G8B8A8 + +#define pkDepthBitShft 65536.0 +#define pkDepthChanMax 256.0 +#define bias -0.5/255.0 +#define coeff 0.9999991 +//#define coeff 1.0 + +float4 encodeShadowMap( float depth ) +{ +#if defined(SM_Fmt_R8G8B8A8) + return frac( float4(1.0, 255.0, 65025.0, 160581375.0) * depth ) + bias; + + //float4 packedValue = frac((depth / coeff) * float4(16777216.0, 65536.0, 256.0, 1.0)); + //return (packedValue - packedValue.xxyz * float4(0, 1.0 / 256, 1.0 / 256, 1.0 / 256)); +#else + return depth; +#endif +} + +float decodeShadowMap( float4 smSample ) +{ +#if defined(SM_Fmt_R8G8B8A8) + return dot( smSample, float4(1.0, 1/255.0, 1/65025.0, 1/160581375.0) ); +#else + return smSample.x; +#endif +} diff --git a/Templates/Empty/game/tools/gui/guiPlatformGenericMenubar.ed.cs b/Templates/Empty/game/tools/gui/guiPlatformGenericMenubar.ed.cs new file mode 100644 index 000000000..327a50205 --- /dev/null +++ b/Templates/Empty/game/tools/gui/guiPlatformGenericMenubar.ed.cs @@ -0,0 +1 @@ +exec("./guiPlatformGenericMenubar.ed.gui"); \ No newline at end of file diff --git a/Templates/Empty/game/tools/gui/guiPlatformGenericMenubar.ed.gui b/Templates/Empty/game/tools/gui/guiPlatformGenericMenubar.ed.gui new file mode 100644 index 000000000..03e21afc4 --- /dev/null +++ b/Templates/Empty/game/tools/gui/guiPlatformGenericMenubar.ed.gui @@ -0,0 +1,14 @@ +//--- OBJECT WRITE BEGIN --- +%guiContent = new GuiControl(PlatformGenericMenubar) { + profile = "GuiModelessDialogProfile"; + + new GuiPlatformGenericMenuBar() + { + internalName = "menubar"; + extent = "1024 32"; + minExtent = "320 32"; + horizSizing = "width"; + profile = "GuiMenuBarProfile"; + }; +}; +//--- OBJECT WRITE END --- \ No newline at end of file diff --git a/Templates/Empty/game/tools/gui/images/checkbox-menubar.png b/Templates/Empty/game/tools/gui/images/checkbox-menubar.png new file mode 100644 index 000000000..a3314baff Binary files /dev/null and b/Templates/Empty/game/tools/gui/images/checkbox-menubar.png differ diff --git a/Templates/Full/game/core/scripts/gui/FileDialog.cs b/Templates/Full/game/core/scripts/gui/FileDialog.cs new file mode 100644 index 000000000..c5e693a80 --- /dev/null +++ b/Templates/Full/game/core/scripts/gui/FileDialog.cs @@ -0,0 +1,308 @@ +exec("./FileDialog.gui"); + +function PlatformFileDialog::buildFilters(%this) +{ + %str = strreplace( %this.data.filters, "|", "\t"); + %this.filterCount = getFieldCount( %str ) / 2; + //echo( "Filter count: " @ %str ); + for( %i = 0; %i < %this.filterCount; %i++ ) + { + %this.filterName[%i] = GetField( %str, (%i*2) + 0 ); + %this.filter[%i] = strreplace( GetField( %str, (%i*2) + 1 ), ";", "\t"); + //echo( "Filter: " @ %this.filterName[%i] @ " - " @ %this.filter[%i]); + } +} + +function PlatformFileDialog::handleFlags(%this, %flags) +{ + %this.FDS_OPEN = false; + %this.FDS_SAVE = false; + %this.FDS_OVERWRITEPROMPT = false; + %this.FDS_MUSTEXIST = false; + %this.FDS_BROWSEFOLDER = false; + + %flagCount = getFieldCount( %flags ); + + //echo( "flag count: " @ %flagCount ); + + for( %i = 0; %i < %flagCount; %i++ ) + { + %flag = GetField( %flags, %i ); + //echo(%flag); + if( %flag $= "FDS_OPEN" ) + { + %this.FDS_OPEN = true; + %this-->Button.setText( "OPEN" ); + %this-->Button.command = "PlatformFileDialog.tryFile();"; + %this-->window.text = "Select file to OPEN"; + } + else if( %flag $= "FDS_SAVE" ) + { + %this.FDS_SAVE = true; + %this-->Button.setText( "SAVE" ); + %this-->Button.command = "PlatformFileDialog.tryFile();"; + %this-->window.text = "Select file to Save"; + } + else if( %flag $= "FDS_OVERWRITEPROMPT" ) + { + %this.FDS_OVERWRITEPROMPT = true; + } + else if( %flag $= "FDS_MUSTEXIST" ) + { + %this.FDS_MUSTEXIST = true; + } + else if( %flag $= "FDS_BROWSEFOLDER" ) + { + %this.FDS_BROWSEFOLDER = true; + %this-->window.text = "Select folder to OPEN"; + } + } +} + +function OpenPlatformFileDialog(%data, %flags) +{ + PlatformFileDialog.searchDir = ""; + PlatformFileDialog-->fileNameEdit.setText( "" ); + PlatformFileDialog.data = %data; + PlatformFileDialog.data.finished = 0; + + PlatformFileDialog.handleFlags( %flags ); + + if( !isObject(PlatformFileDialog.freeItemSet) ) + { + PlatformFileDialog.freeItemSet = new SimGroup(); + } + + PlatformFileDialog.buildFilters(); + + Canvas.pushDialog(PlatformFileDialog); +} + +function PlatformFileDialog::changeDir( %this, %newDir ) +{ + %this.searchDir = %newDir; + %this.update(); +} + +function PlatformFileDialog::navigateUp( %this ) +{ + //echo( "PlatformFileDialog::navigateUp " @ %this.searchDir ); + if( %this.searchDir !$= "" ) + { + %str = strreplace( %this.searchDir, "/", "\t"); + %count = getFieldCount( %str ); + + if ( %count == 0 ) + return; + + if ( %count == 1 ) + %address = ""; + else + %address = getFields( %str, 0, %count - 2 ); + + %newDir = strreplace( %address, "\t", "/" ); + + if( %newDir !$= "" ) + %newDir = %newDir @ "/"; + + %this.changeDir( %newDir ); + + } +} + +function PlatformFileDialog::cancel( %this ) +{ + %this.data.files[0] = ""; + %this.data.fileCount = 0; + %this.data.finished = 1; + + Canvas.popDialog(%this); +} + +function FileDialogItem::onClick( %this ) +{ + PlatformFileDialog-->fileNameEdit.setText( "" ); + + if( %this.isDir && %this.FDS_BROWSEFOLDER) + { + PlatformFileDialog-->fileNameEdit.setText( %this.text ); + } + else if( !%this.isDir && !%this.FDS_BROWSEFOLDER ) + { + PlatformFileDialog-->fileNameEdit.setText( %this.text ); + } +} + +function FileDialogItem::onDoubleClick( %this ) +{ + PlatformFileDialog-->fileNameEdit.setText( "" ); + + if( %this.isDir ) + { + PlatformFileDialog.changeDir( PlatformFileDialog.searchDir @ %this.text @ "/" ); + } +} + +function PlatformFileDialog::tryFile( %this ) +{ + %file = %this-->fileNameEdit.getText(); + if( %file $= "" ) + return; + + if( %this.FDS_OVERWRITEPROMPT ) + { + %callback = "PlatformFileDialog.onFile( \"" @ %file @ "\" );"; + MessageBoxOKCancel("Confirm overwrite", "Confirm overwrite", %callback, ""); + return; + } + + %this.onFile( %file ); +} + +function PlatformFileDialog::onFile( %this, %file ) +{ + %this.data.files[0] = ""; + %this.data.fileCount = 0; + + if( %file !$= "" ) + { + %file = %this.searchDir @ %file; + %this.data.fileCount = 1; + } + + if( %this.FDS_BROWSEFOLDER && !isDirectory( %file ) ) + { + echo("Select a directory"); + return; + } + else if( !%this.FDS_BROWSEFOLDER && !isFile( %file ) ) + { + echo("Select a file"); + return; + } + + if( %this.FDS_MUSTEXIST ) + { + if( !isFile( %file ) && !isDirectory( %file ) ) + { + echo("Target must exist: " @ %file ); + return; + } + } + + %this.data.finished = 1; + %this.data.files[0] = %file; + + Canvas.popDialog(%this); + + %this-->fileNameEdit.setText( "" ); +} + +function PlatformFileDialog::clear( %this ) +{ + %itemArray = %this-->itemArray; + + while( %itemArray.getCount() ) + { + %item = %itemArray.getObject( 0 ); + %this.freeItem( %item ); + } +} + +function PlatformFileDialog::getNewItem( %this ) +{ + if( %this.freeItemSet.getCount() ) + %item = %this.freeItemSet.getObject( 0 ); + + if( isObject(%item) ) + { + %this.freeItemSet.remove( %item ); + } + else + { + //create new + %item = new GuiIconButtonCtrl(); + %item.className = "FileDialogItem"; + %item.profile = "ToolsGuiIconButtonProfile"; + %item.textLocation = "left"; + %item.iconLocation = "left"; + %item.iconBitmap = ""; + %item.text = ""; + } + + return %item; +} + +function PlatformFileDialog::freeItem( %this, %item ) +{ + %this-->itemArray.remove( %item ); + + //clear + %item.setText( "" ); + %item.iconBitmap = ""; + %item.textMargin = 0; + %item.textLocation = "left"; + %item.iconLocation = "left"; + %item.resetState(); + + PlatformFileDialog.freeItemSet.add( %item ); +} + +function PlatformFileDialog::addDir( %this, %dir ) +{ + //echo( "Dir: " @ %dir ); + %item = %this.getNewItem(); + %item.setText( %dir ); + %item.isDir = true; + %item.iconBitmap = "core/art/gui/images/folder"; + %item.textLocation = "left"; + %item.iconLocation = "left"; + %item.textMargin = 24; + %this-->itemArray.add( %item ); +} + +function PlatformFileDialog::addFile( %this, %file ) +{ + //echo( "File: " @ %file ); + %item = %this.getNewItem(); + %item.text = strreplace( %file, %this.searchDir, "" ); + %item.isDir = false; + %this-->itemArray.add( %item ); +} + +function PlatformFileDialog::onWake( %this ) +{ + %this.update(); +} + +function PlatformFileDialog::onSleep( %this ) +{ + %this.data.finished = 1; +} + +function PlatformFileDialog::update( %this ) +{ + %this.clear(); + + %this-->popUpMenu.text = %this.searchDir; + + // dirs + %dirList = getDirectoryList( %this.searchDir, 0 ); + %wordCount = getFieldCount( %dirList ); + for( %i = 0; %i < %wordCount; %i++ ) + { + %dirItem = GetField( %dirList, %i ); + %this.addDir( %dirItem ); + } + + //files + %pattern = %this.filter[0]; + //echo( %pattern ); + %file = findFirstFileMultiExpr( %this.searchDir @ %pattern, false); + + while( %file !$= "" ) + { + %this.addFile( %file ); + %file = findNextFileMultiExpr( %pattern ); + } +} \ No newline at end of file diff --git a/Templates/Full/game/core/scripts/gui/FileDialog.gui b/Templates/Full/game/core/scripts/gui/FileDialog.gui new file mode 100644 index 000000000..e855636f0 --- /dev/null +++ b/Templates/Full/game/core/scripts/gui/FileDialog.gui @@ -0,0 +1,293 @@ +//--- OBJECT WRITE BEGIN --- +%guiContent = new GuiControl(PlatformFileDialog) { + position = "0 0"; + extent = "1024 768"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "GuiDefaultProfile"; + visible = "1"; + active = "1"; + tooltipProfile = "GuiToolTipProfile"; + hovertime = "1000"; + isContainer = "1"; + canSave = "1"; + canSaveDynamicFields = "1"; + + new GuiWindowCtrl() { + text = ""; + resizeWidth = "1"; + resizeHeight = "1"; + canMove = "1"; + canClose = "1"; + canMinimize = "1"; + canMaximize = "1"; + canCollapse = "0"; + closeCommand = "PlatformFileDialog.cancel();"; + edgeSnap = "1"; + margin = "0 0 0 0"; + padding = "0 0 0 0"; + anchorTop = "1"; + anchorBottom = "0"; + anchorLeft = "1"; + anchorRight = "0"; + position = "135 113"; + extent = "727 623"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "GuiWindowProfile"; + visible = "1"; + active = "1"; + tooltipProfile = "GuiToolTipProfile"; + hovertime = "1000"; + isContainer = "1"; + internalName = "window"; + canSave = "1"; + canSaveDynamicFields = "0"; + + new GuiControl() { + position = "2 16"; + extent = "717 37"; + minExtent = "8 2"; + horizSizing = "width"; + vertSizing = "bottom"; + profile = "ToolsGuiDefaultProfile"; + visible = "1"; + active = "1"; + tooltipProfile = "ToolsGuiToolTipProfile"; + hovertime = "1000"; + isContainer = "1"; + canSave = "1"; + canSaveDynamicFields = "0"; + + new GuiBitmapButtonCtrl() { + bitmap = "tools/gui/images/folderUp"; + bitmapMode = "Stretched"; + autoFitExtents = "0"; + useModifiers = "0"; + useStates = "1"; + groupNum = "0"; + buttonType = "PushButton"; + useMouseEvents = "0"; + position = "9 9"; + extent = "20 19"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "ToolsGuiButtonProfile"; + visible = "1"; + active = "1"; + command = "PlatformFileDialog.navigateUp();"; + tooltipProfile = "ToolsGuiToolTipProfile"; + hovertime = "1000"; + isContainer = "0"; + internalName = "folderUpButton"; + canSave = "1"; + canSaveDynamicFields = "0"; + }; + new GuiPopUpMenuCtrl() { + maxPopupHeight = "200"; + sbUsesNAColor = "0"; + reverseTextList = "0"; + bitmapBounds = "16 16"; + maxLength = "1024"; + margin = "0 0 0 0"; + padding = "0 0 0 0"; + anchorTop = "1"; + anchorBottom = "0"; + anchorLeft = "1"; + anchorRight = "0"; + position = "36 9"; + extent = "666 18"; + minExtent = "8 2"; + horizSizing = "width"; + vertSizing = "bottom"; + profile = "ToolsGuiPopUpMenuProfile"; + visible = "1"; + active = "1"; + tooltipProfile = "ToolsGuiToolTipProfile"; + hovertime = "1000"; + isContainer = "0"; + internalName = "PopupMenu"; + canSave = "1"; + canSaveDynamicFields = "0"; + }; + }; + new GuiScrollCtrl() { + willFirstRespond = "1"; + hScrollBar = "dynamic"; + vScrollBar = "alwaysOff"; + lockHorizScroll = "0"; + lockVertScroll = "1"; + constantThumbHeight = "0"; + childMargin = "0 0"; + mouseWheelScrollSpeed = "-1"; + docking = "None"; + margin = "0 0 0 0"; + padding = "0 0 0 0"; + anchorTop = "0"; + anchorBottom = "1"; + anchorLeft = "1"; + anchorRight = "0"; + position = "7 64"; + extent = "712 509"; + minExtent = "8 2"; + horizSizing = "width"; + vertSizing = "height"; + profile = "GuiScrollProfile"; + visible = "1"; + active = "1"; + tooltipProfile = "ToolsGuiToolTipProfile"; + hovertime = "1000"; + isContainer = "1"; + canSave = "1"; + canSaveDynamicFields = "0"; + + new GuiDynamicCtrlArrayControl() { + colCount = "1"; + colSize = "64"; + rowCount = "1"; + rowSize = "258"; + rowSpacing = "4"; + colSpacing = "4"; + frozen = "0"; + autoCellSize = "1"; + fillRowFirst = "0"; + dynamicSize = "1"; + padding = "0 0 0 0"; + position = "1 1"; + extent = "666 507"; + minExtent = "8 2"; + horizSizing = "width"; + vertSizing = "height"; + profile = "ToolsGuiTransparentProfile"; + visible = "1"; + active = "1"; + tooltipProfile = "ToolsGuiToolTipProfile"; + hovertime = "1000"; + isContainer = "1"; + internalName = "itemArray"; + canSave = "1"; + canSaveDynamicFields = "0"; + }; + }; + new GuiContainer() { + docking = "Bottom"; + margin = "0 0 0 0"; + padding = "0 0 0 0"; + anchorTop = "0"; + anchorBottom = "1"; + anchorLeft = "1"; + anchorRight = "1"; + position = "1 583"; + extent = "725 37"; + minExtent = "8 2"; + horizSizing = "width"; + vertSizing = "bottom"; + profile = "GuiDefaultProfile"; + visible = "1"; + active = "1"; + tooltipProfile = "GuiToolTipProfile"; + hovertime = "1000"; + isContainer = "1"; + canSave = "1"; + canSaveDynamicFields = "0"; + + new GuiTextCtrl() { + text = "File Name"; + maxLength = "1024"; + margin = "0 0 0 0"; + padding = "0 0 0 0"; + anchorTop = "1"; + anchorBottom = "0"; + anchorLeft = "1"; + anchorRight = "0"; + position = "10 -1"; + extent = "51 30"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "GuiTextProfile"; + visible = "1"; + active = "1"; + tooltipProfile = "GuiToolTipProfile"; + hovertime = "1000"; + isContainer = "1"; + canSave = "1"; + canSaveDynamicFields = "0"; + }; + new GuiTextEditCtrl() { + historySize = "0"; + tabComplete = "0"; + sinkAllKeyEvents = "0"; + password = "0"; + passwordMask = "*"; + maxLength = "1024"; + margin = "0 0 0 0"; + padding = "0 0 0 0"; + anchorTop = "1"; + anchorBottom = "0"; + anchorLeft = "1"; + anchorRight = "0"; + position = "58 5"; + extent = "561 18"; + minExtent = "8 2"; + horizSizing = "width"; + vertSizing = "bottom"; + profile = "GuiTextEditProfile"; + visible = "1"; + active = "1"; + tooltipProfile = "GuiToolTipProfile"; + hovertime = "1000"; + isContainer = "1"; + internalName = "fileNameEdit"; + canSave = "1"; + canSaveDynamicFields = "0"; + }; + new GuiContainer() { + docking = "Right"; + margin = "0 0 0 0"; + padding = "0 0 0 0"; + anchorTop = "0"; + anchorBottom = "0"; + anchorLeft = "0"; + anchorRight = "0"; + position = "630 0"; + extent = "95 37"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "GuiDefaultProfile"; + visible = "1"; + active = "1"; + tooltipProfile = "GuiToolTipProfile"; + hovertime = "1000"; + isContainer = "1"; + canSave = "1"; + canSaveDynamicFields = "0"; + + new GuiButtonCtrl() { + groupNum = "-1"; + buttonType = "PushButton"; + useMouseEvents = "1"; + position = "6 1"; + extent = "81 24"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "GuiButtonProfile"; + visible = "1"; + active = "1"; + tooltipProfile = "GuiToolTipProfile"; + hovertime = "1000"; + isContainer = "0"; + internalName = "Button"; + canSave = "1"; + canSaveDynamicFields = "0"; + }; + }; + }; + }; +}; +//--- OBJECT WRITE END --- diff --git a/Templates/Full/game/shaders/.gitignore b/Templates/Full/game/shaders/.gitignore new file mode 100644 index 000000000..5baa4d384 --- /dev/null +++ b/Templates/Full/game/shaders/.gitignore @@ -0,0 +1 @@ +/procedural/ diff --git a/Templates/Full/game/shaders/common/lighting/shadowMap/shadowMapIO.h b/Templates/Full/game/shaders/common/lighting/shadowMap/shadowMapIO.h new file mode 100644 index 000000000..84ef6b6a8 --- /dev/null +++ b/Templates/Full/game/shaders/common/lighting/shadowMap/shadowMapIO.h @@ -0,0 +1,50 @@ +//----------------------------------------------------------------------------- +// 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. +//----------------------------------------------------------------------------- + +//#define SM_Fmt_R8G8B8A8 + +#define pkDepthBitShft 65536.0 +#define pkDepthChanMax 256.0 +#define bias -0.5/255.0 +#define coeff 0.9999991 +//#define coeff 1.0 + +float4 encodeShadowMap( float depth ) +{ +#if defined(SM_Fmt_R8G8B8A8) + return frac( float4(1.0, 255.0, 65025.0, 160581375.0) * depth ) + bias; + + //float4 packedValue = frac((depth / coeff) * float4(16777216.0, 65536.0, 256.0, 1.0)); + //return (packedValue - packedValue.xxyz * float4(0, 1.0 / 256, 1.0 / 256, 1.0 / 256)); +#else + return depth; +#endif +} + +float decodeShadowMap( float4 smSample ) +{ +#if defined(SM_Fmt_R8G8B8A8) + return dot( smSample, float4(1.0, 1/255.0, 1/65025.0, 1/160581375.0) ); +#else + return smSample.x; +#endif +} diff --git a/Templates/Full/game/tools/gui/guiPlatformGenericMenubar.ed.cs b/Templates/Full/game/tools/gui/guiPlatformGenericMenubar.ed.cs new file mode 100644 index 000000000..327a50205 --- /dev/null +++ b/Templates/Full/game/tools/gui/guiPlatformGenericMenubar.ed.cs @@ -0,0 +1 @@ +exec("./guiPlatformGenericMenubar.ed.gui"); \ No newline at end of file diff --git a/Templates/Full/game/tools/gui/guiPlatformGenericMenubar.ed.gui b/Templates/Full/game/tools/gui/guiPlatformGenericMenubar.ed.gui new file mode 100644 index 000000000..03e21afc4 --- /dev/null +++ b/Templates/Full/game/tools/gui/guiPlatformGenericMenubar.ed.gui @@ -0,0 +1,14 @@ +//--- OBJECT WRITE BEGIN --- +%guiContent = new GuiControl(PlatformGenericMenubar) { + profile = "GuiModelessDialogProfile"; + + new GuiPlatformGenericMenuBar() + { + internalName = "menubar"; + extent = "1024 32"; + minExtent = "320 32"; + horizSizing = "width"; + profile = "GuiMenuBarProfile"; + }; +}; +//--- OBJECT WRITE END --- \ No newline at end of file diff --git a/Templates/Full/game/tools/gui/images/checkbox-menubar.png b/Templates/Full/game/tools/gui/images/checkbox-menubar.png new file mode 100644 index 000000000..a3314baff Binary files /dev/null and b/Templates/Full/game/tools/gui/images/checkbox-menubar.png differ diff --git a/Templates/Full/game/tools/settings.xml b/Templates/Full/game/tools/settings.xml new file mode 100644 index 000000000..4c86bb29e --- /dev/null +++ b/Templates/Full/game/tools/settings.xml @@ -0,0 +1,2 @@ + + diff --git a/Tools/CMake/torque3d.cmake b/Tools/CMake/torque3d.cmake index 0440f0c7b..7eb69c36e 100644 --- a/Tools/CMake/torque3d.cmake +++ b/Tools/CMake/torque3d.cmake @@ -58,6 +58,12 @@ option(TORQUE_HIFI "HIFI? support" OFF) mark_as_advanced(TORQUE_HIFI) option(TORQUE_EXTENDED_MOVE "Extended move support" OFF) mark_as_advanced(TORQUE_EXTENDED_MOVE) +if(WIN32) + option(TORQUE_SDL "Use SDL for window and input" OFF) + mark_as_advanced(TORQUE_SDL) +else() + set(TORQUE_SDL ON) # we need sdl to work on Linux/Mac +endif() if(WIN32) option(TORQUE_OPENGL "Allow OpenGL render" OFF) #mark_as_advanced(TORQUE_OPENGL) @@ -338,6 +344,30 @@ else() addPath("${srcDir}/T3D/gameBase/std") endif() +if(TORQUE_SDL) + addPathRec("${srcDir}/windowManager/sdl") + addPathRec("${srcDir}/platformSDL") + + if(TORQUE_OPENGL) + addPathRec("${srcDir}/gfx/gl/sdl") + endif() + + if(UNIX) + set(CMAKE_SIZEOF_VOID_P 4) #force 32 bit + set(ENV{CFLAGS} "-m32 -g -O3") + if("${TORQUE_ADDITIONAL_LINKER_FLAGS}" STREQUAL "") + set(ENV{LDFLAGS} "-m32") + else() + set(ENV{LDFLAGS} "-m32 ${TORQUE_ADDITIONAL_LINKER_FLAGS}") + endif() + endif() + + #override and hide SDL2 cache variables + set(SDL_SHARED ON CACHE INTERNAL "" FORCE) + set(SDL_STATIC OFF CACHE INTERNAL "" FORCE) + add_subdirectory( ${libDir}/sdl ${CMAKE_CURRENT_BINARY_DIR}/sdl2) +endif() + if(TORQUE_TESTING) include( "modules/module_testing.cmake" ) endif() @@ -564,6 +594,13 @@ if(TORQUE_OPENGL) addDef(GLEW_STATIC) endif() endif() + +if(TORQUE_SDL) + addDef(TORQUE_SDL) + addInclude(${libDir}/sdl/include) + addLib(SDL2) +endif() + ############################################################################### # Include Paths ###############################################################################