SDL: Refactor WM specific functionality into SdlGraphicsManager.
This commit is contained in:
parent
4e1ffc9434
commit
3a2db0135d
10 changed files with 88 additions and 26 deletions
|
@ -173,7 +173,9 @@ void SdlEventSource::handleKbdMouse() {
|
||||||
_km.y_down_count = 1;
|
_km.y_down_count = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_WarpMouse((Uint16)_km.x, (Uint16)_km.y);
|
if (_graphicsManager) {
|
||||||
|
_graphicsManager->warpMouseInWindow((Uint16)_km.x, (Uint16)_km.y);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -429,7 +431,9 @@ bool SdlEventSource::handleKeyDown(SDL_Event &ev, Common::Event &event) {
|
||||||
|
|
||||||
// Ctrl-m toggles mouse capture
|
// Ctrl-m toggles mouse capture
|
||||||
if (event.kbd.hasFlags(Common::KBD_CTRL) && ev.key.keysym.sym == 'm') {
|
if (event.kbd.hasFlags(Common::KBD_CTRL) && ev.key.keysym.sym == 'm') {
|
||||||
toggleMouseGrab();
|
if (_graphicsManager) {
|
||||||
|
_graphicsManager->toggleMouseGrab();
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -752,13 +756,6 @@ bool SdlEventSource::remapKey(SDL_Event &ev, Common::Event &event) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SdlEventSource::toggleMouseGrab() {
|
|
||||||
if (SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_OFF)
|
|
||||||
SDL_WM_GrabInput(SDL_GRAB_ON);
|
|
||||||
else
|
|
||||||
SDL_WM_GrabInput(SDL_GRAB_OFF);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SdlEventSource::resetKeyboadEmulation(int16 x_max, int16 y_max) {
|
void SdlEventSource::resetKeyboadEmulation(int16 x_max, int16 y_max) {
|
||||||
_km.x_max = x_max;
|
_km.x_max = x_max;
|
||||||
_km.y_max = y_max;
|
_km.y_max = y_max;
|
||||||
|
|
|
@ -49,11 +49,6 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual void resetKeyboadEmulation(int16 x_max, int16 y_max);
|
virtual void resetKeyboadEmulation(int16 x_max, int16 y_max);
|
||||||
|
|
||||||
/**
|
|
||||||
* Toggles mouse input grab
|
|
||||||
*/
|
|
||||||
virtual void toggleMouseGrab();
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/** @name Keyboard mouse emulation
|
/** @name Keyboard mouse emulation
|
||||||
* Disabled by fingolfin 2004-12-18.
|
* Disabled by fingolfin 2004-12-18.
|
||||||
|
|
|
@ -133,7 +133,9 @@ bool SymbianSdlEventSource::remapKey(SDL_Event &ev, Common::Event &event) {
|
||||||
_currentZone = 0;
|
_currentZone = 0;
|
||||||
event.type = Common::EVENT_MOUSEMOVE;
|
event.type = Common::EVENT_MOUSEMOVE;
|
||||||
processMouseEvent(event, _mouseXZone[_currentZone], _mouseYZone[_currentZone]);
|
processMouseEvent(event, _mouseXZone[_currentZone], _mouseYZone[_currentZone]);
|
||||||
SDL_WarpMouse(event.mouse.x, event.mouse.y);
|
if (_graphicsManager) {
|
||||||
|
_graphicsManager->warpMouseInWindow(event.mouse.x, event.mouse.y);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -122,7 +122,7 @@ void DINGUXSdlGraphicsManager::initSize(uint w, uint h) {
|
||||||
if (w > 320 || h > 240) {
|
if (w > 320 || h > 240) {
|
||||||
setGraphicsMode(GFX_HALF);
|
setGraphicsMode(GFX_HALF);
|
||||||
setGraphicsModeIntern();
|
setGraphicsModeIntern();
|
||||||
_eventSource->toggleMouseGrab();
|
toggleMouseGrab();
|
||||||
}
|
}
|
||||||
|
|
||||||
_transactionDetails.sizeChanged = true;
|
_transactionDetails.sizeChanged = true;
|
||||||
|
|
|
@ -134,7 +134,7 @@ void LinuxmotoSdlGraphicsManager::initSize(uint w, uint h) {
|
||||||
if (w > 320 || h > 240) {
|
if (w > 320 || h > 240) {
|
||||||
setGraphicsMode(GFX_HALF);
|
setGraphicsMode(GFX_HALF);
|
||||||
setGraphicsModeIntern();
|
setGraphicsModeIntern();
|
||||||
_eventSource->toggleMouseGrab();
|
toggleMouseGrab();
|
||||||
}
|
}
|
||||||
|
|
||||||
_transactionDetails.sizeChanged = true;
|
_transactionDetails.sizeChanged = true;
|
||||||
|
|
|
@ -108,7 +108,7 @@ void OpenGLSdlGraphicsManager::setFeatureState(OSystem::Feature f, bool enable)
|
||||||
|
|
||||||
case OSystem::kFeatureIconifyWindow:
|
case OSystem::kFeatureIconifyWindow:
|
||||||
if (enable) {
|
if (enable) {
|
||||||
SDL_WM_IconifyWindow();
|
iconifyWindow();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -229,7 +229,7 @@ void OpenGLSdlGraphicsManager::notifyMousePos(Common::Point mouse) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenGLSdlGraphicsManager::setInternalMousePosition(int x, int y) {
|
void OpenGLSdlGraphicsManager::setInternalMousePosition(int x, int y) {
|
||||||
SDL_WarpMouse(x, y);
|
warpMouseInWindow(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OpenGLSdlGraphicsManager::loadVideoMode(uint requestedWidth, uint requestedHeight, const Graphics::PixelFormat &format) {
|
bool OpenGLSdlGraphicsManager::loadVideoMode(uint requestedWidth, uint requestedHeight, const Graphics::PixelFormat &format) {
|
||||||
|
|
|
@ -22,7 +22,9 @@
|
||||||
|
|
||||||
#include "backends/graphics/sdl/sdl-graphics.h"
|
#include "backends/graphics/sdl/sdl-graphics.h"
|
||||||
|
|
||||||
|
#include "backends/platform/sdl/sdl-sys.h"
|
||||||
#include "backends/events/sdl/sdl-events.h"
|
#include "backends/events/sdl/sdl-events.h"
|
||||||
|
#include "common/textconsole.h"
|
||||||
|
|
||||||
SdlGraphicsManager::SdlGraphicsManager(SdlEventSource *source)
|
SdlGraphicsManager::SdlGraphicsManager(SdlEventSource *source)
|
||||||
: _eventSource(source) {
|
: _eventSource(source) {
|
||||||
|
@ -38,3 +40,32 @@ void SdlGraphicsManager::activateManager() {
|
||||||
void SdlGraphicsManager::deactivateManager() {
|
void SdlGraphicsManager::deactivateManager() {
|
||||||
_eventSource->setGraphicsManager(0);
|
_eventSource->setGraphicsManager(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SdlGraphicsManager::setWindowCaption(const Common::String &caption) {
|
||||||
|
SDL_WM_SetCaption(caption.c_str(), caption.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
void SdlGraphicsManager::setWindowIcon(SDL_Surface *icon) {
|
||||||
|
SDL_WM_SetIcon(icon, NULL);
|
||||||
|
SDL_FreeSurface(icon);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SdlGraphicsManager::toggleMouseGrab() {
|
||||||
|
if (SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_OFF) {
|
||||||
|
SDL_WM_GrabInput(SDL_GRAB_ON);
|
||||||
|
} else {
|
||||||
|
SDL_WM_GrabInput(SDL_GRAB_OFF);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SdlGraphicsManager::hasMouseFocus() const {
|
||||||
|
return (SDL_GetAppState() & SDL_APPMOUSEFOCUS);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SdlGraphicsManager::warpMouseInWindow(uint x, uint y) {
|
||||||
|
SDL_WarpMouse(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SdlGraphicsManager::iconifyWindow() {
|
||||||
|
SDL_WM_IconifyWindow();
|
||||||
|
}
|
||||||
|
|
|
@ -25,7 +25,9 @@
|
||||||
|
|
||||||
#include "backends/graphics/graphics.h"
|
#include "backends/graphics/graphics.h"
|
||||||
|
|
||||||
|
#include "backends/platform/sdl/sdl-sys.h"
|
||||||
#include "common/rect.h"
|
#include "common/rect.h"
|
||||||
|
#include "common/str.h"
|
||||||
|
|
||||||
class SdlEventSource;
|
class SdlEventSource;
|
||||||
|
|
||||||
|
@ -91,6 +93,42 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual void notifyMousePos(Common::Point mouse) = 0;
|
virtual void notifyMousePos(Common::Point mouse) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change the caption of the window.
|
||||||
|
*
|
||||||
|
* @param caption New window caption in UTF-8 encoding.
|
||||||
|
*/
|
||||||
|
void setWindowCaption(const Common::String &caption);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attach an icon to the window.
|
||||||
|
*
|
||||||
|
* @param icon The surface to use as icon. SdlGraphicsManager takes
|
||||||
|
* ownership over it.
|
||||||
|
*/
|
||||||
|
void setWindowIcon(SDL_Surface *icon);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Toggle mouse grab state. This decides whether the cursor can leave the
|
||||||
|
* window or not.
|
||||||
|
*/
|
||||||
|
void toggleMouseGrab();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether the application has mouse focus.
|
||||||
|
*/
|
||||||
|
bool hasMouseFocus() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Warp the mouse to the specified position in window coordinates.
|
||||||
|
*/
|
||||||
|
void warpMouseInWindow(uint x, uint y);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Iconifies the window.
|
||||||
|
*/
|
||||||
|
void iconifyWindow();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
SdlEventSource *_eventSource;
|
SdlEventSource *_eventSource;
|
||||||
};
|
};
|
||||||
|
|
|
@ -235,7 +235,7 @@ void SurfaceSdlGraphicsManager::setFeatureState(OSystem::Feature f, bool enable)
|
||||||
break;
|
break;
|
||||||
case OSystem::kFeatureIconifyWindow:
|
case OSystem::kFeatureIconifyWindow:
|
||||||
if (enable)
|
if (enable)
|
||||||
SDL_WM_IconifyWindow();
|
iconifyWindow();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -1710,7 +1710,7 @@ void SurfaceSdlGraphicsManager::warpMouse(int x, int y) {
|
||||||
int y1 = y;
|
int y1 = y;
|
||||||
|
|
||||||
// Don't change actual mouse position, when mouse is outside of our window (in case of windowed mode)
|
// Don't change actual mouse position, when mouse is outside of our window (in case of windowed mode)
|
||||||
if (!(SDL_GetAppState( ) & SDL_APPMOUSEFOCUS)) {
|
if (!hasMouseFocus()) {
|
||||||
setMousePos(x, y); // but change game cursor position
|
setMousePos(x, y); // but change game cursor position
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1720,9 +1720,9 @@ void SurfaceSdlGraphicsManager::warpMouse(int x, int y) {
|
||||||
|
|
||||||
if (_mouseCurState.x != x || _mouseCurState.y != y) {
|
if (_mouseCurState.x != x || _mouseCurState.y != y) {
|
||||||
if (!_overlayVisible)
|
if (!_overlayVisible)
|
||||||
SDL_WarpMouse(x * _videoMode.scaleFactor, y1 * _videoMode.scaleFactor);
|
warpMouseInWindow(x * _videoMode.scaleFactor, y1 * _videoMode.scaleFactor);
|
||||||
else
|
else
|
||||||
SDL_WarpMouse(x, y1);
|
warpMouseInWindow(x, y1);
|
||||||
|
|
||||||
// SDL_WarpMouse() generates a mouse movement event, so
|
// SDL_WarpMouse() generates a mouse movement event, so
|
||||||
// setMousePos() would be called eventually. However, the
|
// setMousePos() would be called eventually. However, the
|
||||||
|
|
|
@ -314,7 +314,7 @@ void OSystem_SDL::setWindowCaption(const char *caption) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_WM_SetCaption(cap.c_str(), cap.c_str());
|
dynamic_cast<SdlGraphicsManager *>(_graphicsManager)->setWindowCaption(cap);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OSystem_SDL::quit() {
|
void OSystem_SDL::quit() {
|
||||||
|
@ -477,8 +477,7 @@ void OSystem_SDL::setupIcon() {
|
||||||
if (!sdl_surf) {
|
if (!sdl_surf) {
|
||||||
warning("SDL_CreateRGBSurfaceFrom(icon) failed");
|
warning("SDL_CreateRGBSurfaceFrom(icon) failed");
|
||||||
}
|
}
|
||||||
SDL_WM_SetIcon(sdl_surf, NULL);
|
dynamic_cast<SdlGraphicsManager *>(_graphicsManager)->setWindowIcon(sdl_surf);
|
||||||
SDL_FreeSurface(sdl_surf);
|
|
||||||
free(icon);
|
free(icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue