mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-03-03 20:40:35 +00:00
PlatformSDL implementation.
This commit is contained in:
parent
21d58bb191
commit
aa35157eef
33 changed files with 3971 additions and 151 deletions
116
Engine/source/windowManager/sdl/sdlCursorController.cpp
Normal file
116
Engine/source/windowManager/sdl/sdlCursorController.cpp
Normal file
|
|
@ -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<PlatformWindowSDL*>( PlatformWindowManager::get()->getFirstWindow() ), "");
|
||||
PlatformWindowSDL *window = static_cast<PlatformWindowSDL*>( 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");
|
||||
}
|
||||
51
Engine/source/windowManager/sdl/sdlCursorController.h
Normal file
51
Engine/source/windowManager/sdl/sdlCursorController.h
Normal file
|
|
@ -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
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
597
Engine/source/windowManager/sdl/sdlWindow.cpp
Normal file
597
Engine/source/windowManager/sdl/sdlWindow.cpp
Normal file
|
|
@ -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();
|
||||
}
|
||||
184
Engine/source/windowManager/sdl/sdlWindow.h
Normal file
184
Engine/source/windowManager/sdl/sdlWindow.h
Normal file
|
|
@ -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
|
||||
369
Engine/source/windowManager/sdl/sdlWindowMgr.cpp
Normal file
369
Engine/source/windowManager/sdl/sdlWindowMgr.cpp
Normal file
|
|
@ -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<RectI> ®ions)
|
||||
{
|
||||
// TODO SDL
|
||||
AssertFatal(0, "");
|
||||
}
|
||||
|
||||
void PlatformWindowManagerSDL::getWindows(VectorPtr<PlatformWindow*> &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<PlatformWindowSDL*>( 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");
|
||||
}
|
||||
105
Engine/source/windowManager/sdl/sdlWindowMgr.h
Normal file
105
Engine/source/windowManager/sdl/sdlWindowMgr.h
Normal file
|
|
@ -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<U32, PlatformWindowSDL*> mWindowMap;
|
||||
|
||||
SignalSlot<void()> 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<RectI> ®ions);
|
||||
virtual PlatformWindow *createWindow(GFXDevice *device, const GFXVideoMode &mode);
|
||||
virtual void getWindows(VectorPtr<PlatformWindow*> &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
|
||||
Loading…
Add table
Add a link
Reference in a new issue