mirror of
https://github.com/libretro/scummvm.git
synced 2025-02-13 23:43:34 +00:00
Merge pull request #572 from lordhoto/sdl2-support
SDL: Add experimental support for SDL2
This commit is contained in:
commit
4d13d44f8a
1
AUTHORS
1
AUTHORS
@ -565,6 +565,7 @@ Other contributions
|
||||
Jeroen Janssen - Numerous readability and bugfix patches
|
||||
Keith Kaisershot - Several Pegasus Prime patches
|
||||
Andreas Karlsson - Initial port for SymbianOS
|
||||
Stefan Kristiansson - Initial work on SDL2 support
|
||||
Claudio Matsuoka - Daily Linux builds
|
||||
Thomas Mayer - PSP port contributions
|
||||
Sean Murray - ScummVM tools GUI application (GSoC 2007
|
||||
|
1
Makefile
1
Makefile
@ -91,6 +91,7 @@ ifeq "$(findstring config.mk,$(MAKEFILE_LIST))" "config.mk"
|
||||
LDFLAGS="$(SAVED_LDFLAGS)" CXX="$(SAVED_CXX)" \
|
||||
CXXFLAGS="$(SAVED_CXXFLAGS)" CPPFLAGS="$(SAVED_CPPFLAGS)" \
|
||||
ASFLAGS="$(SAVED_ASFLAGS)" WINDRESFLAGS="$(SAVED_WINDRESFLAGS)" \
|
||||
SDL_CONFIG="$(SAVED_SDL_CONFIG)" \
|
||||
$(srcdir)/configure $(SAVED_CONFIGFLAGS)
|
||||
else
|
||||
$(error You need to run $(srcdir)/configure before you can run make. Check $(srcdir)/configure --help for a list of parameters)
|
||||
|
@ -24,9 +24,12 @@
|
||||
|
||||
#if defined(SDL_BACKEND)
|
||||
|
||||
#include "common/textconsole.h"
|
||||
#include "backends/audiocd/sdl/sdl-audiocd.h"
|
||||
|
||||
#if !SDL_VERSION_ATLEAST(1, 3, 0)
|
||||
|
||||
#include "common/textconsole.h"
|
||||
|
||||
SdlAudioCDManager::SdlAudioCDManager()
|
||||
:
|
||||
_cdrom(0),
|
||||
@ -133,4 +136,6 @@ void SdlAudioCDManager::updateCD() {
|
||||
}
|
||||
}
|
||||
|
||||
#endif // !SDL_VERSION_ATLEAST(1, 3, 0)
|
||||
|
||||
#endif
|
||||
|
@ -27,6 +27,8 @@
|
||||
|
||||
#include "backends/platform/sdl/sdl-sys.h"
|
||||
|
||||
#if !SDL_VERSION_ATLEAST(1, 3, 0)
|
||||
|
||||
/**
|
||||
* The SDL audio cd manager. Implements real audio cd playback.
|
||||
*/
|
||||
@ -47,4 +49,6 @@ protected:
|
||||
uint32 _cdEndTime, _cdStopTime;
|
||||
};
|
||||
|
||||
#endif // !SDL_VERSION_ATLEAST(1, 3, 0)
|
||||
|
||||
#endif
|
||||
|
@ -63,8 +63,14 @@ SdlEventSource::SdlEventSource()
|
||||
|
||||
// Enable joystick
|
||||
if (SDL_NumJoysticks() > joystick_num) {
|
||||
debug("Using joystick: %s", SDL_JoystickName(joystick_num));
|
||||
_joystick = SDL_JoystickOpen(joystick_num);
|
||||
debug("Using joystick: %s",
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
SDL_JoystickName(_joystick)
|
||||
#else
|
||||
SDL_JoystickName(joystick_num)
|
||||
#endif
|
||||
);
|
||||
} else {
|
||||
warning("Invalid joystick: %d", joystick_num);
|
||||
}
|
||||
@ -76,21 +82,24 @@ SdlEventSource::~SdlEventSource() {
|
||||
SDL_JoystickClose(_joystick);
|
||||
}
|
||||
|
||||
int SdlEventSource::mapKey(SDLKey key, SDLMod mod, Uint16 unicode) {
|
||||
if (key >= SDLK_F1 && key <= SDLK_F9) {
|
||||
int SdlEventSource::mapKey(SDLKey sdlKey, SDLMod mod, Uint16 unicode) {
|
||||
Common::KeyCode key = SDLToOSystemKeycode(sdlKey);
|
||||
|
||||
if (key >= Common::KEYCODE_F1 && key <= Common::KEYCODE_F9) {
|
||||
return key - SDLK_F1 + Common::ASCII_F1;
|
||||
} else if (key >= SDLK_KP0 && key <= SDLK_KP9) {
|
||||
return key - SDLK_KP0 + '0';
|
||||
} else if (key >= SDLK_UP && key <= SDLK_PAGEDOWN) {
|
||||
} else if (key >= Common::KEYCODE_KP0 && key <= Common::KEYCODE_KP9) {
|
||||
return key - Common::KEYCODE_KP0 + '0';
|
||||
} else if (key >= Common::KEYCODE_UP && key <= Common::KEYCODE_PAGEDOWN) {
|
||||
return key;
|
||||
} else if (unicode) {
|
||||
return unicode;
|
||||
} else if (key >= 'a' && key <= 'z' && (mod & KMOD_SHIFT)) {
|
||||
return key & ~0x20;
|
||||
} else if (key >= SDLK_NUMLOCK && key <= SDLK_EURO) {
|
||||
} else if (key >= Common::KEYCODE_NUMLOCK && key <= Common::KEYCODE_EURO) {
|
||||
return 0;
|
||||
} else {
|
||||
return key;
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
||||
void SdlEventSource::processMouseEvent(Common::Event &event, int x, int y) {
|
||||
@ -173,7 +182,9 @@ void SdlEventSource::handleKbdMouse() {
|
||||
_km.y_down_count = 1;
|
||||
}
|
||||
|
||||
SDL_WarpMouse((Uint16)_km.x, (Uint16)_km.y);
|
||||
if (_graphicsManager) {
|
||||
_graphicsManager->getWindow()->warpMouseInWindow((Uint16)_km.x, (Uint16)_km.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -340,7 +351,9 @@ Common::KeyCode SdlEventSource::SDLToOSystemKeycode(const SDLKey key) {
|
||||
case SDLK_HELP: return Common::KEYCODE_HELP;
|
||||
case SDLK_PRINT: return Common::KEYCODE_PRINT;
|
||||
case SDLK_SYSREQ: return Common::KEYCODE_SYSREQ;
|
||||
#if !SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
case SDLK_BREAK: return Common::KEYCODE_BREAK;
|
||||
#endif
|
||||
case SDLK_MENU: return Common::KEYCODE_MENU;
|
||||
case SDLK_POWER: return Common::KEYCODE_POWER;
|
||||
case SDLK_UNDO: return Common::KEYCODE_UNDO;
|
||||
@ -387,24 +400,52 @@ bool SdlEventSource::dispatchSDLEvent(SDL_Event &ev, Common::Event &event) {
|
||||
case SDL_JOYAXISMOTION:
|
||||
return handleJoyAxisMotion(ev, event);
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
case SDL_MOUSEWHEEL: {
|
||||
Sint32 yDir = ev.wheel.y;
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 4)
|
||||
if (ev.wheel.direction == SDL_MOUSEWHEEL_FLIPPED) {
|
||||
yDir *= -1;
|
||||
}
|
||||
#endif
|
||||
// HACK: It seems we want the mouse coordinates supplied
|
||||
// with a mouse wheel event. However, SDL2 does not supply
|
||||
// these, thus we use whatever we got last time. It seems
|
||||
// these are always stored in _km.x, _km.y.
|
||||
processMouseEvent(event, _km.x, _km.y);
|
||||
if (yDir < 0) {
|
||||
event.type = Common::EVENT_WHEELDOWN;
|
||||
return true;
|
||||
} else if (yDir > 0) {
|
||||
event.type = Common::EVENT_WHEELUP;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
case SDL_WINDOWEVENT:
|
||||
switch (ev.window.event) {
|
||||
case SDL_WINDOWEVENT_EXPOSED:
|
||||
if (_graphicsManager)
|
||||
_graphicsManager->notifyVideoExpose();
|
||||
return false;
|
||||
|
||||
case SDL_WINDOWEVENT_RESIZED:
|
||||
return handleResizeEvent(event, ev.window.data1, ev.window.data2);
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
case SDL_VIDEOEXPOSE:
|
||||
if (_graphicsManager)
|
||||
_graphicsManager->notifyVideoExpose();
|
||||
return false;
|
||||
|
||||
case SDL_VIDEORESIZE:
|
||||
if (_graphicsManager) {
|
||||
_graphicsManager->notifyResize(ev.resize.w, ev.resize.h);
|
||||
|
||||
// If the screen changed, send an Common::EVENT_SCREEN_CHANGED
|
||||
int screenID = ((OSystem_SDL *)g_system)->getGraphicsManager()->getScreenChangeID();
|
||||
if (screenID != _lastScreenID) {
|
||||
_lastScreenID = screenID;
|
||||
event.type = Common::EVENT_SCREEN_CHANGED;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return handleResizeEvent(event, ev.resize.w, ev.resize.h);
|
||||
#endif
|
||||
|
||||
case SDL_QUIT:
|
||||
event.type = Common::EVENT_QUIT;
|
||||
@ -429,7 +470,9 @@ bool SdlEventSource::handleKeyDown(SDL_Event &ev, Common::Event &event) {
|
||||
|
||||
// Ctrl-m toggles mouse capture
|
||||
if (event.kbd.hasFlags(Common::KBD_CTRL) && ev.key.keysym.sym == 'm') {
|
||||
toggleMouseGrab();
|
||||
if (_graphicsManager) {
|
||||
_graphicsManager->getWindow()->toggleMouseGrab();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -472,7 +515,7 @@ bool SdlEventSource::handleKeyDown(SDL_Event &ev, Common::Event &event) {
|
||||
|
||||
event.type = Common::EVENT_KEYDOWN;
|
||||
event.kbd.keycode = SDLToOSystemKeycode(ev.key.keysym.sym);
|
||||
event.kbd.ascii = mapKey(ev.key.keysym.sym, (SDLMod)ev.key.keysym.mod, (Uint16)ev.key.keysym.unicode);
|
||||
event.kbd.ascii = mapKey(ev.key.keysym.sym, (SDLMod)ev.key.keysym.mod, obtainUnicode(ev.key.keysym));
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -516,7 +559,7 @@ bool SdlEventSource::handleKeyUp(SDL_Event &ev, Common::Event &event) {
|
||||
|
||||
event.type = Common::EVENT_KEYUP;
|
||||
event.kbd.keycode = SDLToOSystemKeycode(ev.key.keysym.sym);
|
||||
event.kbd.ascii = mapKey(ev.key.keysym.sym, (SDLMod)ev.key.keysym.mod, (Uint16)ev.key.keysym.unicode);
|
||||
event.kbd.ascii = mapKey(ev.key.keysym.sym, (SDLMod)ev.key.keysym.mod, 0);
|
||||
|
||||
// Ctrl-Alt-<key> will change the GFX mode
|
||||
SDLModToOSystemKeyFlags(mod, event);
|
||||
@ -752,13 +795,6 @@ bool SdlEventSource::remapKey(SDL_Event &ev, Common::Event &event) {
|
||||
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) {
|
||||
_km.x_max = x_max;
|
||||
_km.y_max = y_max;
|
||||
@ -766,4 +802,64 @@ void SdlEventSource::resetKeyboadEmulation(int16 x_max, int16 y_max) {
|
||||
_km.last_time = 0;
|
||||
}
|
||||
|
||||
bool SdlEventSource::handleResizeEvent(Common::Event &event, int w, int h) {
|
||||
if (_graphicsManager) {
|
||||
_graphicsManager->notifyResize(w, h);
|
||||
|
||||
// If the screen changed, send an Common::EVENT_SCREEN_CHANGED
|
||||
int screenID = ((OSystem_SDL *)g_system)->getGraphicsManager()->getScreenChangeID();
|
||||
if (screenID != _lastScreenID) {
|
||||
_lastScreenID = screenID;
|
||||
event.type = Common::EVENT_SCREEN_CHANGED;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
static uint32 convUTF8ToUTF32(const char *src) {
|
||||
uint32 utf32 = 0;
|
||||
|
||||
char *dst = SDL_iconv_string(
|
||||
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
|
||||
"UTF-32BE",
|
||||
#else
|
||||
"UTF-32LE",
|
||||
#endif
|
||||
"UTF-8", src, SDL_strlen(src) + 1);
|
||||
|
||||
if (dst) {
|
||||
utf32 = *((uint32 *)dst);
|
||||
SDL_free(dst);
|
||||
}
|
||||
|
||||
return utf32;
|
||||
}
|
||||
#endif
|
||||
|
||||
uint32 SdlEventSource::obtainUnicode(const SDL_keysym keySym) {
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
SDL_Event events[2];
|
||||
|
||||
// In SDL2, the unicode field has been removed from the keysym struct.
|
||||
// Instead a SDL_TEXTINPUT event is generated on key combinations that
|
||||
// generates unicode.
|
||||
// Here we peek into the event queue for the event to see if it exists.
|
||||
int n = SDL_PeepEvents(events, 2, SDL_PEEKEVENT, SDL_KEYDOWN, SDL_TEXTINPUT);
|
||||
// Make sure that the TEXTINPUT event belongs to this KEYDOWN
|
||||
// event and not another pending one.
|
||||
if (n > 0 && events[0].type == SDL_TEXTINPUT) {
|
||||
return convUTF8ToUTF32(events[0].text.text);
|
||||
} else if (n > 1 && events[0].type != SDL_KEYDOWN && events[1].type == SDL_TEXTINPUT) {
|
||||
return convUTF8ToUTF32(events[1].text.text);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
return keySym.unicode;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -49,11 +49,6 @@ public:
|
||||
*/
|
||||
virtual void resetKeyboadEmulation(int16 x_max, int16 y_max);
|
||||
|
||||
/**
|
||||
* Toggles mouse input grab
|
||||
*/
|
||||
virtual void toggleMouseGrab();
|
||||
|
||||
protected:
|
||||
/** @name Keyboard mouse emulation
|
||||
* Disabled by fingolfin 2004-12-18.
|
||||
@ -130,7 +125,7 @@ protected:
|
||||
/**
|
||||
* Maps the ASCII value of key
|
||||
*/
|
||||
virtual int mapKey(SDLKey key, SDLMod mod, Uint16 unicode);
|
||||
int mapKey(SDLKey key, SDLMod mod, Uint16 unicode);
|
||||
|
||||
/**
|
||||
* Configures the key modifiers flags status
|
||||
@ -141,6 +136,17 @@ protected:
|
||||
* Translates SDL key codes to OSystem key codes
|
||||
*/
|
||||
Common::KeyCode SDLToOSystemKeycode(const SDLKey key);
|
||||
|
||||
/**
|
||||
* Notify graphics manager of a resize request.
|
||||
*/
|
||||
bool handleResizeEvent(Common::Event &event, int w, int h);
|
||||
|
||||
/**
|
||||
* Extracts unicode information for the specific key sym.
|
||||
* May only be used for key down events.
|
||||
*/
|
||||
uint32 obtainUnicode(const SDL_keysym keySym);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -133,7 +133,9 @@ bool SymbianSdlEventSource::remapKey(SDL_Event &ev, Common::Event &event) {
|
||||
_currentZone = 0;
|
||||
event.type = Common::EVENT_MOUSEMOVE;
|
||||
processMouseEvent(event, _mouseXZone[_currentZone], _mouseYZone[_currentZone]);
|
||||
SDL_WarpMouse(event.mouse.x, event.mouse.y);
|
||||
if (_graphicsManager) {
|
||||
_graphicsManager->getWindow()->warpMouseInWindow(event.mouse.x, event.mouse.y);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -35,8 +35,8 @@ static const OSystem::GraphicsMode s_supportedGraphicsModes[] = {
|
||||
{0, 0, 0}
|
||||
};
|
||||
|
||||
DINGUXSdlGraphicsManager::DINGUXSdlGraphicsManager(SdlEventSource *boss)
|
||||
: SurfaceSdlGraphicsManager(boss) {
|
||||
DINGUXSdlGraphicsManager::DINGUXSdlGraphicsManager(SdlEventSource *boss, SdlWindow *window)
|
||||
: SurfaceSdlGraphicsManager(boss, window) {
|
||||
}
|
||||
|
||||
const OSystem::GraphicsMode *DINGUXSdlGraphicsManager::getSupportedGraphicsModes() const {
|
||||
@ -122,7 +122,7 @@ void DINGUXSdlGraphicsManager::initSize(uint w, uint h) {
|
||||
if (w > 320 || h > 240) {
|
||||
setGraphicsMode(GFX_HALF);
|
||||
setGraphicsModeIntern();
|
||||
_eventSource->toggleMouseGrab();
|
||||
_window->toggleMouseGrab();
|
||||
}
|
||||
|
||||
_transactionDetails.sizeChanged = true;
|
||||
|
@ -34,7 +34,7 @@ enum {
|
||||
|
||||
class DINGUXSdlGraphicsManager : public SurfaceSdlGraphicsManager {
|
||||
public:
|
||||
DINGUXSdlGraphicsManager(SdlEventSource *boss);
|
||||
DINGUXSdlGraphicsManager(SdlEventSource *boss, SdlWindow *window);
|
||||
|
||||
bool hasFeature(OSystem::Feature f);
|
||||
void setFeatureState(OSystem::Feature f, bool enable);
|
||||
|
@ -35,8 +35,8 @@ static const OSystem::GraphicsMode s_supportedGraphicsModes[] = {
|
||||
{0, 0, 0}
|
||||
};
|
||||
|
||||
GPHGraphicsManager::GPHGraphicsManager(SdlEventSource *sdlEventSource)
|
||||
: SurfaceSdlGraphicsManager(sdlEventSource) {
|
||||
GPHGraphicsManager::GPHGraphicsManager(SdlEventSource *sdlEventSource, SdlWindow *window)
|
||||
: SurfaceSdlGraphicsManager(sdlEventSource, window) {
|
||||
}
|
||||
|
||||
const OSystem::GraphicsMode *GPHGraphicsManager::getSupportedGraphicsModes() const {
|
||||
@ -141,7 +141,7 @@ void GPHGraphicsManager::initSize(uint w, uint h, const Graphics::PixelFormat *f
|
||||
if (w > 320 || h > 240) {
|
||||
setGraphicsMode(GFX_HALF);
|
||||
setGraphicsModeIntern();
|
||||
_eventSource->toggleMouseGrab();
|
||||
_window->toggleMouseGrab();
|
||||
}
|
||||
|
||||
_videoMode.overlayWidth = 320;
|
||||
|
@ -33,7 +33,7 @@ enum {
|
||||
|
||||
class GPHGraphicsManager : public SurfaceSdlGraphicsManager {
|
||||
public:
|
||||
GPHGraphicsManager(SdlEventSource *boss);
|
||||
GPHGraphicsManager(SdlEventSource *boss, SdlWindow *window);
|
||||
|
||||
bool hasFeature(OSystem::Feature f);
|
||||
void setFeatureState(OSystem::Feature f, bool enable);
|
||||
|
@ -45,8 +45,8 @@ static const OSystem::GraphicsMode s_supportedGraphicsModes[] = {
|
||||
{0, 0, 0}
|
||||
};
|
||||
|
||||
LinuxmotoSdlGraphicsManager::LinuxmotoSdlGraphicsManager(SdlEventSource *sdlEventSource)
|
||||
: SurfaceSdlGraphicsManager(sdlEventSource) {
|
||||
LinuxmotoSdlGraphicsManager::LinuxmotoSdlGraphicsManager(SdlEventSource *sdlEventSource, SdlWindow *window)
|
||||
: SurfaceSdlGraphicsManager(sdlEventSource, window) {
|
||||
}
|
||||
|
||||
const OSystem::GraphicsMode *LinuxmotoSdlGraphicsManager::getSupportedGraphicsModes() const {
|
||||
@ -134,7 +134,7 @@ void LinuxmotoSdlGraphicsManager::initSize(uint w, uint h) {
|
||||
if (w > 320 || h > 240) {
|
||||
setGraphicsMode(GFX_HALF);
|
||||
setGraphicsModeIntern();
|
||||
_eventSource->toggleMouseGrab();
|
||||
_window->toggleMouseGrab();
|
||||
}
|
||||
|
||||
_transactionDetails.sizeChanged = true;
|
||||
|
@ -27,7 +27,7 @@
|
||||
|
||||
class LinuxmotoSdlGraphicsManager : public SurfaceSdlGraphicsManager {
|
||||
public:
|
||||
LinuxmotoSdlGraphicsManager(SdlEventSource *sdlEventSource);
|
||||
LinuxmotoSdlGraphicsManager(SdlEventSource *sdlEventSource, SdlWindow *window);
|
||||
|
||||
virtual void initSize(uint w, uint h);
|
||||
virtual void setGraphicsModeIntern();
|
||||
|
@ -29,8 +29,8 @@
|
||||
#include "backends/events/maemosdl/maemosdl-events.h"
|
||||
#include "backends/graphics/maemosdl/maemosdl-graphics.h"
|
||||
|
||||
MaemoSdlGraphicsManager::MaemoSdlGraphicsManager(SdlEventSource *sdlEventSource)
|
||||
: SurfaceSdlGraphicsManager(sdlEventSource) {
|
||||
MaemoSdlGraphicsManager::MaemoSdlGraphicsManager(SdlEventSource *sdlEventSource, SdlWindow *window)
|
||||
: SurfaceSdlGraphicsManager(sdlEventSource, window) {
|
||||
}
|
||||
|
||||
bool MaemoSdlGraphicsManager::loadGFXMode() {
|
||||
|
@ -29,7 +29,7 @@
|
||||
|
||||
class MaemoSdlGraphicsManager : public SurfaceSdlGraphicsManager {
|
||||
public:
|
||||
MaemoSdlGraphicsManager(SdlEventSource *sdlEventSource);
|
||||
MaemoSdlGraphicsManager(SdlEventSource *sdlEventSource, SdlWindow *window);
|
||||
|
||||
protected:
|
||||
virtual bool loadGFXMode();
|
||||
|
@ -28,8 +28,13 @@
|
||||
#include "common/translation.h"
|
||||
#endif
|
||||
|
||||
OpenGLSdlGraphicsManager::OpenGLSdlGraphicsManager(uint desktopWidth, uint desktopHeight, SdlEventSource *eventSource)
|
||||
: SdlGraphicsManager(eventSource), _lastVideoModeLoad(0), _hwScreen(nullptr), _lastRequestedWidth(0), _lastRequestedHeight(0),
|
||||
OpenGLSdlGraphicsManager::OpenGLSdlGraphicsManager(uint desktopWidth, uint desktopHeight, SdlEventSource *eventSource, SdlWindow *window)
|
||||
: SdlGraphicsManager(eventSource, window), _lastRequestedHeight(0),
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
_glContext(),
|
||||
#else
|
||||
_lastVideoModeLoad(0), _hwScreen(nullptr),
|
||||
#endif
|
||||
_graphicsScale(2), _ignoreLoadVideoMode(false), _gotResize(false), _wantsFullScreen(false), _ignoreResizeEvents(0),
|
||||
_desiredFullscreenWidth(0), _desiredFullscreenHeight(0) {
|
||||
// Setup OpenGL attributes for SDL
|
||||
@ -40,6 +45,17 @@ OpenGLSdlGraphicsManager::OpenGLSdlGraphicsManager(uint desktopWidth, uint deskt
|
||||
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
||||
|
||||
// Retrieve a list of working fullscreen modes
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
const int numModes = SDL_GetNumDisplayModes(0);
|
||||
for (int i = 0; i < numModes; ++i) {
|
||||
SDL_DisplayMode mode;
|
||||
if (SDL_GetDisplayMode(0, i, &mode)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
_fullscreenVideoModes.push_back(VideoMode(mode.w, mode.h));
|
||||
}
|
||||
#else
|
||||
const SDL_Rect *const *availableModes = SDL_ListModes(NULL, SDL_OPENGL | SDL_FULLSCREEN);
|
||||
if (availableModes != (void *)-1) {
|
||||
for (;*availableModes; ++availableModes) {
|
||||
@ -47,9 +63,19 @@ OpenGLSdlGraphicsManager::OpenGLSdlGraphicsManager(uint desktopWidth, uint deskt
|
||||
|
||||
_fullscreenVideoModes.push_back(VideoMode(mode->w, mode->h));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// Sort the modes in ascending order.
|
||||
Common::sort(_fullscreenVideoModes.begin(), _fullscreenVideoModes.end());
|
||||
// Sort the modes in ascending order.
|
||||
Common::sort(_fullscreenVideoModes.begin(), _fullscreenVideoModes.end());
|
||||
|
||||
// Strip duplicates in video modes.
|
||||
for (uint i = 0; i + 1 < _fullscreenVideoModes.size();) {
|
||||
if (_fullscreenVideoModes[i] == _fullscreenVideoModes[i + 1]) {
|
||||
_fullscreenVideoModes.remove_at(i);
|
||||
} else {
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
// In case SDL is fine with every mode we will force the desktop mode.
|
||||
@ -108,7 +134,7 @@ void OpenGLSdlGraphicsManager::setFeatureState(OSystem::Feature f, bool enable)
|
||||
|
||||
case OSystem::kFeatureIconifyWindow:
|
||||
if (enable) {
|
||||
SDL_WM_IconifyWindow();
|
||||
_window->iconifyWindow();
|
||||
}
|
||||
break;
|
||||
|
||||
@ -120,11 +146,19 @@ void OpenGLSdlGraphicsManager::setFeatureState(OSystem::Feature f, bool enable)
|
||||
bool OpenGLSdlGraphicsManager::getFeatureState(OSystem::Feature f) {
|
||||
switch (f) {
|
||||
case OSystem::kFeatureFullscreenMode:
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
if (_window) {
|
||||
return (SDL_GetWindowFlags(_window->getSDLWindow()) & SDL_WINDOW_FULLSCREEN) != 0;
|
||||
} else {
|
||||
return _wantsFullScreen;
|
||||
}
|
||||
#else
|
||||
if (_hwScreen) {
|
||||
return (_hwScreen->flags & SDL_FULLSCREEN) != 0;
|
||||
} else {
|
||||
return _wantsFullScreen;
|
||||
}
|
||||
#endif
|
||||
|
||||
default:
|
||||
return OpenGLGraphicsManager::getFeatureState(f);
|
||||
@ -201,13 +235,20 @@ void OpenGLSdlGraphicsManager::updateScreen() {
|
||||
OpenGLGraphicsManager::updateScreen();
|
||||
|
||||
// Swap OpenGL buffers
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
SDL_GL_SwapWindow(_window->getSDLWindow());
|
||||
#else
|
||||
SDL_GL_SwapBuffers();
|
||||
#endif
|
||||
}
|
||||
|
||||
void OpenGLSdlGraphicsManager::notifyVideoExpose() {
|
||||
}
|
||||
|
||||
void OpenGLSdlGraphicsManager::notifyResize(const uint width, const uint height) {
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
setActualScreenSize(width, height);
|
||||
#else
|
||||
if (!_ignoreResizeEvents && _hwScreen && !(_hwScreen->flags & SDL_FULLSCREEN)) {
|
||||
// We save that we handled a resize event here. We need to know this
|
||||
// so we do not overwrite the users requested window size whenever we
|
||||
@ -218,6 +259,7 @@ void OpenGLSdlGraphicsManager::notifyResize(const uint width, const uint height)
|
||||
g_system->quit();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void OpenGLSdlGraphicsManager::transformMouseCoordinates(Common::Point &point) {
|
||||
@ -229,7 +271,7 @@ void OpenGLSdlGraphicsManager::notifyMousePos(Common::Point mouse) {
|
||||
}
|
||||
|
||||
void OpenGLSdlGraphicsManager::setInternalMousePosition(int x, int y) {
|
||||
SDL_WarpMouse(x, y);
|
||||
_window->warpMouseInWindow(x, y);
|
||||
}
|
||||
|
||||
bool OpenGLSdlGraphicsManager::loadVideoMode(uint requestedWidth, uint requestedHeight, const Graphics::PixelFormat &format) {
|
||||
@ -300,6 +342,58 @@ bool OpenGLSdlGraphicsManager::setupMode(uint width, uint height) {
|
||||
height = _desiredFullscreenHeight;
|
||||
}
|
||||
|
||||
// This is pretty confusing since RGBA8888 talks about the memory
|
||||
// layout here. This is a different logical layout depending on
|
||||
// whether we run on little endian or big endian. However, we can
|
||||
// only safely assume that RGBA8888 in memory layout is supported.
|
||||
// Thus, we chose this one.
|
||||
const Graphics::PixelFormat rgba8888 =
|
||||
#ifdef SCUMM_LITTLE_ENDIAN
|
||||
Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24);
|
||||
#else
|
||||
Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0);
|
||||
#endif
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
if (_glContext) {
|
||||
notifyContextDestroy();
|
||||
|
||||
SDL_GL_DeleteContext(_glContext);
|
||||
_glContext = nullptr;
|
||||
}
|
||||
|
||||
_window->destroyWindow();
|
||||
|
||||
uint32 flags = SDL_WINDOW_OPENGL;
|
||||
if (_wantsFullScreen) {
|
||||
flags |= SDL_WINDOW_FULLSCREEN;
|
||||
} else {
|
||||
flags |= SDL_WINDOW_RESIZABLE;
|
||||
}
|
||||
|
||||
if (!_window->createWindow(width, height, flags)) {
|
||||
// We treat fullscreen requests as a "hint" for now. This means in
|
||||
// case it is not available we simply ignore it.
|
||||
if (_wantsFullScreen) {
|
||||
_window->createWindow(width, height, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
|
||||
}
|
||||
|
||||
if (!_window->getSDLWindow()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
_glContext = SDL_GL_CreateContext(_window->getSDLWindow());
|
||||
if (!_glContext) {
|
||||
return false;
|
||||
}
|
||||
|
||||
notifyContextCreate(rgba8888, rgba8888);
|
||||
int actualWidth, actualHeight;
|
||||
getWindowDimensions(&actualWidth, &actualHeight);
|
||||
setActualScreenSize(actualWidth, actualHeight);
|
||||
return true;
|
||||
#else
|
||||
// WORKAROUND: Working around infamous SDL bugs when switching
|
||||
// resolutions too fast. This might cause the event system to supply
|
||||
// incorrect mouse position events otherwise.
|
||||
@ -341,17 +435,6 @@ bool OpenGLSdlGraphicsManager::setupMode(uint width, uint height) {
|
||||
_lastVideoModeLoad = SDL_GetTicks();
|
||||
|
||||
if (_hwScreen) {
|
||||
// This is pretty confusing since RGBA8888 talks about the memory
|
||||
// layout here. This is a different logical layout depending on
|
||||
// whether we run on little endian or big endian. However, we can
|
||||
// only safely assume that RGBA8888 in memory layout is supported.
|
||||
// Thus, we chose this one.
|
||||
const Graphics::PixelFormat rgba8888 =
|
||||
#ifdef SCUMM_LITTLE_ENDIAN
|
||||
Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24);
|
||||
#else
|
||||
Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0);
|
||||
#endif
|
||||
notifyContextCreate(rgba8888, rgba8888);
|
||||
setActualScreenSize(_hwScreen->w, _hwScreen->h);
|
||||
}
|
||||
@ -363,6 +446,21 @@ bool OpenGLSdlGraphicsManager::setupMode(uint width, uint height) {
|
||||
_ignoreResizeEvents = 10;
|
||||
|
||||
return _hwScreen != nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
void OpenGLSdlGraphicsManager::getWindowDimensions(int *width, int *height) {
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
SDL_GetWindowSize(_window->getSDLWindow(), width, height);
|
||||
#else
|
||||
if (width) {
|
||||
*width = _hwScreen->w;
|
||||
}
|
||||
|
||||
if (height) {
|
||||
*height = _hwScreen->h;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bool OpenGLSdlGraphicsManager::notifyEvent(const Common::Event &event) {
|
||||
@ -456,7 +554,9 @@ bool OpenGLSdlGraphicsManager::notifyEvent(const Common::Event &event) {
|
||||
// Calculate the next scaling setting. We approximate the
|
||||
// current scale setting in case the user resized the
|
||||
// window. Then we apply the direction change.
|
||||
_graphicsScale = MAX<int>(_hwScreen->w / _lastRequestedWidth, _hwScreen->h / _lastRequestedHeight);
|
||||
int windowWidth = 0, windowHeight = 0;
|
||||
getWindowDimensions(&windowWidth, &windowHeight);
|
||||
_graphicsScale = MAX<int>(windowWidth / _lastRequestedWidth, windowHeight / _lastRequestedHeight);
|
||||
_graphicsScale = MAX<int>(_graphicsScale + direction, 1);
|
||||
|
||||
// Since we overwrite a user resize here we reset its
|
||||
@ -472,7 +572,9 @@ bool OpenGLSdlGraphicsManager::notifyEvent(const Common::Event &event) {
|
||||
}
|
||||
|
||||
#ifdef USE_OSD
|
||||
const Common::String osdMsg = Common::String::format("Resolution: %dx%d", _hwScreen->w, _hwScreen->h);
|
||||
int windowWidth = 0, windowHeight = 0;
|
||||
getWindowDimensions(&windowWidth, &windowHeight);
|
||||
const Common::String osdMsg = Common::String::format("Resolution: %dx%d", windowWidth, windowHeight);
|
||||
displayMessageOnOSD(osdMsg.c_str());
|
||||
#endif
|
||||
|
||||
|
@ -32,7 +32,7 @@
|
||||
|
||||
class OpenGLSdlGraphicsManager : public OpenGL::OpenGLGraphicsManager, public SdlGraphicsManager, public Common::EventObserver {
|
||||
public:
|
||||
OpenGLSdlGraphicsManager(uint desktopWidth, uint desktopHeight, SdlEventSource *eventSource);
|
||||
OpenGLSdlGraphicsManager(uint desktopWidth, uint desktopHeight, SdlEventSource *eventSource, SdlWindow *window);
|
||||
virtual ~OpenGLSdlGraphicsManager();
|
||||
|
||||
// GraphicsManager API
|
||||
@ -68,8 +68,14 @@ protected:
|
||||
private:
|
||||
bool setupMode(uint width, uint height);
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
SDL_GLContext _glContext;
|
||||
#else
|
||||
uint32 _lastVideoModeLoad;
|
||||
SDL_Surface *_hwScreen;
|
||||
#endif
|
||||
|
||||
void getWindowDimensions(int *width, int *height);
|
||||
|
||||
uint _lastRequestedWidth;
|
||||
uint _lastRequestedHeight;
|
||||
|
@ -32,8 +32,8 @@
|
||||
|
||||
static SDL_Cursor *hiddenCursor;
|
||||
|
||||
OPGraphicsManager::OPGraphicsManager(SdlEventSource *sdlEventSource)
|
||||
: SurfaceSdlGraphicsManager(sdlEventSource) {
|
||||
OPGraphicsManager::OPGraphicsManager(SdlEventSource *sdlEventSource, SdlWindow *window)
|
||||
: SurfaceSdlGraphicsManager(sdlEventSource, window) {
|
||||
}
|
||||
|
||||
bool OPGraphicsManager::loadGFXMode() {
|
||||
|
@ -32,7 +32,7 @@ enum {
|
||||
|
||||
class OPGraphicsManager : public SurfaceSdlGraphicsManager {
|
||||
public:
|
||||
OPGraphicsManager(SdlEventSource *sdlEventSource);
|
||||
OPGraphicsManager(SdlEventSource *sdlEventSource, SdlWindow *window);
|
||||
|
||||
bool loadGFXMode();
|
||||
void unloadGFXMode();
|
||||
|
@ -28,8 +28,8 @@
|
||||
#include "backends/events/samsungtvsdl/samsungtvsdl-events.h"
|
||||
#include "backends/graphics/samsungtvsdl/samsungtvsdl-graphics.h"
|
||||
|
||||
SamsungTVSdlGraphicsManager::SamsungTVSdlGraphicsManager(SdlEventSource *sdlEventSource)
|
||||
: SurfaceSdlGraphicsManager(sdlEventSource) {
|
||||
SamsungTVSdlGraphicsManager::SamsungTVSdlGraphicsManager(SdlEventSource *sdlEventSource, SdlWindow *window)
|
||||
: SurfaceSdlGraphicsManager(sdlEventSource, window) {
|
||||
}
|
||||
|
||||
bool SamsungTVSdlGraphicsManager::hasFeature(OSystem::Feature f) {
|
||||
|
@ -29,7 +29,7 @@
|
||||
|
||||
class SamsungTVSdlGraphicsManager : public SurfaceSdlGraphicsManager {
|
||||
public:
|
||||
SamsungTVSdlGraphicsManager(SdlEventSource *sdlEventSource);
|
||||
SamsungTVSdlGraphicsManager(SdlEventSource *sdlEventSource, SdlWindow *window);
|
||||
|
||||
bool hasFeature(OSystem::Feature f);
|
||||
void setFeatureState(OSystem::Feature f, bool enable);
|
||||
|
@ -22,10 +22,12 @@
|
||||
|
||||
#include "backends/graphics/sdl/sdl-graphics.h"
|
||||
|
||||
#include "backends/platform/sdl/sdl-sys.h"
|
||||
#include "backends/events/sdl/sdl-events.h"
|
||||
#include "common/textconsole.h"
|
||||
|
||||
SdlGraphicsManager::SdlGraphicsManager(SdlEventSource *source)
|
||||
: _eventSource(source) {
|
||||
SdlGraphicsManager::SdlGraphicsManager(SdlEventSource *source, SdlWindow *window)
|
||||
: _eventSource(source), _window(window) {
|
||||
}
|
||||
|
||||
SdlGraphicsManager::~SdlGraphicsManager() {
|
||||
@ -38,3 +40,36 @@ void SdlGraphicsManager::activateManager() {
|
||||
void SdlGraphicsManager::deactivateManager() {
|
||||
_eventSource->setGraphicsManager(0);
|
||||
}
|
||||
|
||||
SdlGraphicsManager::State SdlGraphicsManager::getState() {
|
||||
State state;
|
||||
|
||||
state.screenWidth = getWidth();
|
||||
state.screenHeight = getHeight();
|
||||
state.aspectRatio = getFeatureState(OSystem::kFeatureAspectRatioCorrection);
|
||||
state.fullscreen = getFeatureState(OSystem::kFeatureFullscreenMode);
|
||||
state.cursorPalette = getFeatureState(OSystem::kFeatureCursorPalette);
|
||||
#ifdef USE_RGB_COLOR
|
||||
state.pixelFormat = getScreenFormat();
|
||||
#endif
|
||||
return state;
|
||||
}
|
||||
|
||||
bool SdlGraphicsManager::setState(const State &state) {
|
||||
beginGFXTransaction();
|
||||
#ifdef USE_RGB_COLOR
|
||||
initSize(state.screenWidth, state.screenHeight, &state.pixelFormat);
|
||||
#else
|
||||
initSize(state.screenWidth, state.screenHeight, 0);
|
||||
#endif
|
||||
setFeatureState(OSystem::kFeatureAspectRatioCorrection, state.aspectRatio);
|
||||
setFeatureState(OSystem::kFeatureFullscreenMode, state.fullscreen);
|
||||
setFeatureState(OSystem::kFeatureCursorPalette, state.cursorPalette);
|
||||
|
||||
if (endGFXTransaction() != OSystem::kTransactionSuccess) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,6 +24,7 @@
|
||||
#define BACKENDS_GRAPHICS_SDL_SDLGRAPHICS_H
|
||||
|
||||
#include "backends/graphics/graphics.h"
|
||||
#include "backends/platform/sdl/sdl-window.h"
|
||||
|
||||
#include "common/rect.h"
|
||||
|
||||
@ -36,7 +37,7 @@ class SdlEventSource;
|
||||
*/
|
||||
class SdlGraphicsManager : virtual public GraphicsManager {
|
||||
public:
|
||||
SdlGraphicsManager(SdlEventSource *source);
|
||||
SdlGraphicsManager(SdlEventSource *source, SdlWindow *window);
|
||||
virtual ~SdlGraphicsManager();
|
||||
|
||||
/**
|
||||
@ -91,8 +92,39 @@ public:
|
||||
*/
|
||||
virtual void notifyMousePos(Common::Point mouse) = 0;
|
||||
|
||||
/**
|
||||
* A (subset) of the graphic manager's state. This is used when switching
|
||||
* between different SDL graphic managers on runtime.
|
||||
*/
|
||||
struct State {
|
||||
int screenWidth, screenHeight;
|
||||
bool aspectRatio;
|
||||
bool fullscreen;
|
||||
bool cursorPalette;
|
||||
|
||||
#ifdef USE_RGB_COLOR
|
||||
Graphics::PixelFormat pixelFormat;
|
||||
#endif
|
||||
};
|
||||
|
||||
/**
|
||||
* Queries the current state of the graphic manager.
|
||||
*/
|
||||
State getState();
|
||||
|
||||
/**
|
||||
* Setup a basic state of the graphic manager.
|
||||
*/
|
||||
bool setState(const State &state);
|
||||
|
||||
/**
|
||||
* Queries the SDL window.
|
||||
*/
|
||||
SdlWindow *getWindow() const { return _window; }
|
||||
|
||||
protected:
|
||||
SdlEventSource *_eventSource;
|
||||
SdlWindow *_window;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -116,13 +116,17 @@ static AspectRatio getDesiredAspectRatio() {
|
||||
}
|
||||
#endif
|
||||
|
||||
SurfaceSdlGraphicsManager::SurfaceSdlGraphicsManager(SdlEventSource *sdlEventSource)
|
||||
SurfaceSdlGraphicsManager::SurfaceSdlGraphicsManager(SdlEventSource *sdlEventSource, SdlWindow *window)
|
||||
:
|
||||
SdlGraphicsManager(sdlEventSource),
|
||||
SdlGraphicsManager(sdlEventSource, window),
|
||||
#ifdef USE_OSD
|
||||
_osdSurface(0), _osdAlpha(SDL_ALPHA_TRANSPARENT), _osdFadeStartTime(0),
|
||||
#endif
|
||||
_hwscreen(0), _screen(0), _tmpscreen(0),
|
||||
_hwscreen(0),
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
_renderer(nullptr), _screenTexture(nullptr),
|
||||
#endif
|
||||
_screen(0), _tmpscreen(0),
|
||||
#ifdef USE_RGB_COLOR
|
||||
_screenFormat(Graphics::PixelFormat::createFormatCLUT8()),
|
||||
_cursorFormat(Graphics::PixelFormat::createFormatCLUT8()),
|
||||
@ -235,7 +239,7 @@ void SurfaceSdlGraphicsManager::setFeatureState(OSystem::Feature f, bool enable)
|
||||
break;
|
||||
case OSystem::kFeatureIconifyWindow:
|
||||
if (enable)
|
||||
SDL_WM_IconifyWindow();
|
||||
_window->iconifyWindow();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -681,12 +685,22 @@ static void fixupResolutionForAspectRatio(AspectRatio desiredAspectRatio, int &w
|
||||
const int w = width;
|
||||
const int h = height;
|
||||
|
||||
int bestW = 0, bestH = 0;
|
||||
uint bestMetric = (uint)-1; // Metric is wasted space
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
const int numModes = SDL_GetNumDisplayModes(0);
|
||||
SDL_DisplayMode modeData, *mode = &modeData;
|
||||
for (int i = 0; i < numModes; ++i) {
|
||||
if (SDL_GetDisplayMode(0, i, &modeData)) {
|
||||
continue;
|
||||
}
|
||||
#else
|
||||
SDL_Rect const* const*availableModes = SDL_ListModes(NULL, SDL_FULLSCREEN|SDL_SWSURFACE); //TODO : Maybe specify a pixel format
|
||||
assert(availableModes);
|
||||
|
||||
const SDL_Rect *bestMode = NULL;
|
||||
uint bestMetric = (uint)-1; // Metric is wasted space
|
||||
while (const SDL_Rect *mode = *availableModes++) {
|
||||
#endif
|
||||
if (mode->w < w)
|
||||
continue;
|
||||
if (mode->h < h)
|
||||
@ -699,15 +713,23 @@ static void fixupResolutionForAspectRatio(AspectRatio desiredAspectRatio, int &w
|
||||
continue;
|
||||
|
||||
bestMetric = metric;
|
||||
bestMode = mode;
|
||||
}
|
||||
bestW = mode->w;
|
||||
bestH = mode->h;
|
||||
|
||||
if (!bestMode) {
|
||||
// Make editors a bit more happy by having the same amount of closing as
|
||||
// opening curley braces.
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
}
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!bestW || !bestH) {
|
||||
warning("Unable to enforce the desired aspect ratio");
|
||||
return;
|
||||
}
|
||||
width = bestMode->w;
|
||||
height = bestMode->h;
|
||||
width = bestW;
|
||||
height = bestH;
|
||||
}
|
||||
|
||||
bool SurfaceSdlGraphicsManager::loadGFXMode() {
|
||||
@ -876,6 +898,10 @@ void SurfaceSdlGraphicsManager::unloadGFXMode() {
|
||||
_screen = NULL;
|
||||
}
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
deinitializeRenderer();
|
||||
#endif
|
||||
|
||||
if (_hwscreen) {
|
||||
SDL_FreeSurface(_hwscreen);
|
||||
_hwscreen = NULL;
|
||||
@ -1443,6 +1469,9 @@ void SurfaceSdlGraphicsManager::setPalette(const byte *colors, uint start, uint
|
||||
base[i].r = b[0];
|
||||
base[i].g = b[1];
|
||||
base[i].b = b[2];
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
base[i].a = 255;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (start < _paletteDirtyStart)
|
||||
@ -1481,6 +1510,9 @@ void SurfaceSdlGraphicsManager::setCursorPalette(const byte *colors, uint start,
|
||||
base[i].r = b[0];
|
||||
base[i].g = b[1];
|
||||
base[i].b = b[2];
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
base[i].a = 255;
|
||||
#endif
|
||||
}
|
||||
|
||||
_cursorPaletteDisabled = false;
|
||||
@ -1710,7 +1742,7 @@ void SurfaceSdlGraphicsManager::warpMouse(int x, int y) {
|
||||
int y1 = y;
|
||||
|
||||
// Don't change actual mouse position, when mouse is outside of our window (in case of windowed mode)
|
||||
if (!(SDL_GetAppState( ) & SDL_APPMOUSEFOCUS)) {
|
||||
if (!_window->hasMouseFocus()) {
|
||||
setMousePos(x, y); // but change game cursor position
|
||||
return;
|
||||
}
|
||||
@ -1720,9 +1752,9 @@ void SurfaceSdlGraphicsManager::warpMouse(int x, int y) {
|
||||
|
||||
if (_mouseCurState.x != x || _mouseCurState.y != y) {
|
||||
if (!_overlayVisible)
|
||||
SDL_WarpMouse(x * _videoMode.scaleFactor, y1 * _videoMode.scaleFactor);
|
||||
_window->warpMouseInWindow(x * _videoMode.scaleFactor, y1 * _videoMode.scaleFactor);
|
||||
else
|
||||
SDL_WarpMouse(x, y1);
|
||||
_window->warpMouseInWindow(x, y1);
|
||||
|
||||
// SDL_WarpMouse() generates a mouse movement event, so
|
||||
// setMousePos() would be called eventually. However, the
|
||||
@ -2317,4 +2349,52 @@ void SurfaceSdlGraphicsManager::notifyMousePos(Common::Point mouse) {
|
||||
setMousePos(mouse.x, mouse.y);
|
||||
}
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
void SurfaceSdlGraphicsManager::deinitializeRenderer() {
|
||||
SDL_DestroyTexture(_screenTexture);
|
||||
_screenTexture = nullptr;
|
||||
|
||||
SDL_DestroyRenderer(_renderer);
|
||||
_renderer = nullptr;
|
||||
|
||||
_window->destroyWindow();
|
||||
}
|
||||
|
||||
SDL_Surface *SurfaceSdlGraphicsManager::SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags) {
|
||||
deinitializeRenderer();
|
||||
|
||||
if (!_window->createWindow(width, height, (flags & SDL_FULLSCREEN) ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
_renderer = SDL_CreateRenderer(_window->getSDLWindow(), -1, 0);
|
||||
if (!_renderer) {
|
||||
deinitializeRenderer();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
_screenTexture = SDL_CreateTexture(_renderer, SDL_PIXELFORMAT_RGB565, SDL_TEXTUREACCESS_STREAMING, width, height);
|
||||
if (!_screenTexture) {
|
||||
deinitializeRenderer();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
SDL_Surface *screen = SDL_CreateRGBSurface(0, width, height, 16, 0xF800, 0x7E0, 0x1F, 0);
|
||||
if (!screen) {
|
||||
deinitializeRenderer();
|
||||
return nullptr;
|
||||
} else {
|
||||
return screen;
|
||||
}
|
||||
}
|
||||
|
||||
void SurfaceSdlGraphicsManager::SDL_UpdateRects(SDL_Surface *screen, int numrects, SDL_Rect *rects) {
|
||||
SDL_UpdateTexture(_screenTexture, nullptr, screen->pixels, screen->pitch);
|
||||
|
||||
SDL_RenderClear(_renderer);
|
||||
SDL_RenderCopy(_renderer, _screenTexture, NULL, NULL);
|
||||
SDL_RenderPresent(_renderer);
|
||||
}
|
||||
#endif // SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
|
||||
#endif
|
||||
|
@ -77,7 +77,7 @@ public:
|
||||
*/
|
||||
class SurfaceSdlGraphicsManager : public SdlGraphicsManager, public Common::EventObserver {
|
||||
public:
|
||||
SurfaceSdlGraphicsManager(SdlEventSource *sdlEventSource);
|
||||
SurfaceSdlGraphicsManager(SdlEventSource *sdlEventSource, SdlWindow *window);
|
||||
virtual ~SurfaceSdlGraphicsManager();
|
||||
|
||||
virtual void activateManager();
|
||||
@ -166,6 +166,17 @@ protected:
|
||||
/** Hardware screen */
|
||||
SDL_Surface *_hwscreen;
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
/* SDL2 features a different API for 2D graphics. We create a wrapper
|
||||
* around this API to keep the code paths as close as possible. */
|
||||
SDL_Renderer *_renderer;
|
||||
SDL_Texture *_screenTexture;
|
||||
void deinitializeRenderer();
|
||||
|
||||
SDL_Surface *SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags);
|
||||
void SDL_UpdateRects(SDL_Surface *screen, int numrects, SDL_Rect *rects);
|
||||
#endif
|
||||
|
||||
/** Unseen game screen */
|
||||
SDL_Surface *_screen;
|
||||
#ifdef USE_RGB_COLOR
|
||||
|
@ -27,8 +27,8 @@
|
||||
#include "backends/graphics/symbiansdl/symbiansdl-graphics.h"
|
||||
#include "backends/platform/symbian/src/SymbianActions.h"
|
||||
|
||||
SymbianSdlGraphicsManager::SymbianSdlGraphicsManager(SdlEventSource *sdlEventSource)
|
||||
: SurfaceSdlGraphicsManager(sdlEventSource) {
|
||||
SymbianSdlGraphicsManager::SymbianSdlGraphicsManager(SdlEventSource *sdlEventSource, SdlWindow *window)
|
||||
: SurfaceSdlGraphicsManager(sdlEventSource, window) {
|
||||
}
|
||||
|
||||
int SymbianSdlGraphicsManager::getDefaultGraphicsMode() const {
|
||||
|
@ -27,7 +27,7 @@
|
||||
|
||||
class SymbianSdlGraphicsManager : public SurfaceSdlGraphicsManager {
|
||||
public:
|
||||
SymbianSdlGraphicsManager(SdlEventSource *sdlEventSource);
|
||||
SymbianSdlGraphicsManager(SdlEventSource *sdlEventSource, SdlWindow *window);
|
||||
|
||||
public:
|
||||
virtual bool hasFeature(OSystem::Feature f);
|
||||
|
@ -42,8 +42,8 @@
|
||||
#include "backends/platform/wince/CEScaler.h"
|
||||
#include "backends/platform/wince/CEgui/ItemAction.h"
|
||||
|
||||
WINCESdlGraphicsManager::WINCESdlGraphicsManager(SdlEventSource *sdlEventSource)
|
||||
: SurfaceSdlGraphicsManager(sdlEventSource),
|
||||
WINCESdlGraphicsManager::WINCESdlGraphicsManager(SdlEventSource *sdlEventSource, SdlWindow *window)
|
||||
: SurfaceSdlGraphicsManager(sdlEventSource, window),
|
||||
_panelInitialized(false), _noDoubleTapRMB(false), _noDoubleTapPT(false),
|
||||
_toolbarHighDrawn(false), _newOrientation(0), _orientationLandscape(0),
|
||||
_panelVisible(true), _saveActiveToolbar(NAME_MAIN_PANEL), _panelStateForced(false),
|
||||
|
@ -41,7 +41,7 @@ extern bool _hasSmartphoneResolution;
|
||||
|
||||
class WINCESdlGraphicsManager : public SurfaceSdlGraphicsManager {
|
||||
public:
|
||||
WINCESdlGraphicsManager(SdlEventSource *sdlEventSource);
|
||||
WINCESdlGraphicsManager(SdlEventSource *sdlEventSource, SdlWindow *window);
|
||||
|
||||
const OSystem::GraphicsMode *getSupportedGraphicsModes() const;
|
||||
void initSize(uint w, uint h, const Graphics::PixelFormat *format = NULL);
|
||||
|
@ -57,10 +57,14 @@ void SdlMixerManager::init() {
|
||||
error("Could not initialize SDL: %s", SDL_GetError());
|
||||
}
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
const char *sdlDriverName = SDL_GetCurrentAudioDriver();
|
||||
#else
|
||||
const int maxNameLen = 20;
|
||||
char sdlDriverName[maxNameLen];
|
||||
sdlDriverName[0] = '\0';
|
||||
SDL_AudioDriverName(sdlDriverName, maxNameLen);
|
||||
#endif
|
||||
debug(1, "Using SDL Audio Driver \"%s\"", sdlDriverName);
|
||||
|
||||
// Get the desired audio specs
|
||||
|
@ -74,9 +74,11 @@ MODULE_OBJS += \
|
||||
|
||||
# SDL 1.3 removed audio CD support
|
||||
ifndef USE_SDL13
|
||||
ifndef USE_SDL2
|
||||
MODULE_OBJS += \
|
||||
audiocd/sdl/sdl-audiocd.o
|
||||
endif
|
||||
endif
|
||||
|
||||
ifdef USE_OPENGL
|
||||
MODULE_OBJS += \
|
||||
|
@ -33,7 +33,7 @@ void OSystem_SDL_Dingux::initBackend() {
|
||||
|
||||
// Create the graphics manager
|
||||
if (_graphicsManager == 0) {
|
||||
_graphicsManager = new DINGUXSdlGraphicsManager(_eventSource);
|
||||
_graphicsManager = new DINGUXSdlGraphicsManager(_eventSource, _window);
|
||||
}
|
||||
|
||||
// Call parent implementation of this method
|
||||
|
@ -159,7 +159,7 @@ void OSystem_GPH::initBackend() {
|
||||
|
||||
// Create the graphics manager
|
||||
if (_graphicsManager == 0) {
|
||||
_graphicsManager = new GPHGraphicsManager(_eventSource);
|
||||
_graphicsManager = new GPHGraphicsManager(_eventSource, _window);
|
||||
}
|
||||
|
||||
/* Pass to POSIX method to do the heavy lifting */
|
||||
|
@ -31,7 +31,7 @@ void OSystem_LINUXMOTO::initBackend() {
|
||||
_eventSource = new LinuxmotoSdlEventSource();
|
||||
|
||||
if (_graphicsManager == 0)
|
||||
_graphicsManager = new LinuxmotoSdlGraphicsManager(_eventSource);
|
||||
_graphicsManager = new LinuxmotoSdlGraphicsManager(_eventSource, _window);
|
||||
|
||||
// Call parent implementation of this method
|
||||
OSystem_POSIX::initBackend();
|
||||
|
@ -84,6 +84,15 @@ static void registerDefaultKeyBindings(Common::KeymapperDefaultBindings *_keymap
|
||||
}
|
||||
#endif
|
||||
|
||||
void OSystem_SDL_Maemo::init() {
|
||||
// Use an iconless window for Maemo
|
||||
// also N900 is hit by SDL_WM_SetIcon bug (window cannot receive input)
|
||||
// http://bugzilla.libsdl.org/show_bug.cgi?id=586
|
||||
_window = new SdlIconlessWindow();
|
||||
|
||||
OSystem_POSIX::init();
|
||||
}
|
||||
|
||||
void OSystem_SDL_Maemo::initBackend() {
|
||||
ConfMan.registerDefault("fullscreen", true);
|
||||
ConfMan.registerDefault("aspect_ratio", true);
|
||||
@ -93,7 +102,7 @@ void OSystem_SDL_Maemo::initBackend() {
|
||||
_eventSource = new MaemoSdlEventSource();
|
||||
|
||||
if (_graphicsManager == 0)
|
||||
_graphicsManager = new MaemoSdlGraphicsManager(_eventSource);
|
||||
_graphicsManager = new MaemoSdlGraphicsManager(_eventSource, _window);
|
||||
|
||||
if (_eventObserver == 0)
|
||||
_eventObserver = new MaemoSdlEventObserver((MaemoSdlEventSource *)_eventSource);
|
||||
@ -178,12 +187,6 @@ const Maemo::Model OSystem_SDL_Maemo::detectModel() {
|
||||
return *model;
|
||||
}
|
||||
|
||||
void OSystem_SDL_Maemo::setupIcon() {
|
||||
// no Maemo version needs setupIcon
|
||||
// also N900 is hit by SDL_WM_SetIcon bug (window cannot receive input)
|
||||
// http://bugzilla.libsdl.org/show_bug.cgi?id=586
|
||||
}
|
||||
|
||||
#ifdef ENABLE_KEYMAPPER
|
||||
static const Common::KeyTableEntry maemoKeys[] = {
|
||||
// Function keys
|
||||
|
@ -36,11 +36,11 @@ public:
|
||||
OSystem_SDL_Maemo();
|
||||
~OSystem_SDL_Maemo();
|
||||
|
||||
virtual void init();
|
||||
virtual void initBackend();
|
||||
virtual void quit();
|
||||
virtual void fatalError();
|
||||
virtual void setWindowCaption(const char *caption);
|
||||
virtual void setupIcon();
|
||||
#ifdef ENABLE_KEYMAPPER
|
||||
virtual Common::HardwareInputSet *getHardwareInputSet();
|
||||
virtual Common::Keymap *getGlobalKeymap();
|
||||
|
@ -147,7 +147,7 @@ void OSystem_OP::initBackend() {
|
||||
|
||||
// Create the graphics manager
|
||||
if (_graphicsManager == 0) {
|
||||
_graphicsManager = new OPGraphicsManager(_eventSource);
|
||||
_graphicsManager = new OPGraphicsManager(_eventSource, _window);
|
||||
}
|
||||
|
||||
/* Pass to POSIX method to do the heavy lifting */
|
||||
|
@ -40,7 +40,7 @@ void OSystem_SDL_SamsungTV::initBackend() {
|
||||
_eventSource = new SamsungTVSdlEventSource();
|
||||
|
||||
if (_graphicsManager == 0)
|
||||
_graphicsManager = new SamsungTVSdlGraphicsManager(_eventSource);
|
||||
_graphicsManager = new SamsungTVSdlGraphicsManager(_eventSource, _window);
|
||||
|
||||
// Call parent implementation of this method
|
||||
OSystem_POSIX::initBackend();
|
||||
|
@ -47,6 +47,9 @@ OSystem_MacOSX::OSystem_MacOSX()
|
||||
}
|
||||
|
||||
void OSystem_MacOSX::init() {
|
||||
// Use an iconless window on OS X, as we use a nicer external icon there.
|
||||
_window = new SdlIconlessWindow();
|
||||
|
||||
#if defined(USE_TASKBAR)
|
||||
// Initialize taskbar manager
|
||||
_taskbarManager = new MacOSXTaskbarManager();
|
||||
@ -101,8 +104,6 @@ void OSystem_MacOSX::addSysArchivesToSearchSet(Common::SearchSet &s, int priorit
|
||||
}
|
||||
}
|
||||
|
||||
void OSystem_MacOSX::setupIcon() {
|
||||
// Don't set icon on OS X, as we use a nicer external icon there.
|
||||
}
|
||||
|
||||
bool OSystem_MacOSX::hasFeature(Feature f) {
|
||||
|
@ -38,7 +38,6 @@ public:
|
||||
virtual void init();
|
||||
virtual void initBackend();
|
||||
virtual void addSysArchivesToSearchSet(Common::SearchSet &s, int priority = 0);
|
||||
virtual void setupIcon();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -1,7 +1,8 @@
|
||||
MODULE := backends/platform/sdl
|
||||
|
||||
MODULE_OBJS := \
|
||||
sdl.o
|
||||
sdl.o \
|
||||
sdl-window.o
|
||||
|
||||
ifdef POSIX
|
||||
MODULE_OBJS += \
|
||||
@ -19,6 +20,7 @@ endif
|
||||
ifdef WIN32
|
||||
MODULE_OBJS += \
|
||||
win32/win32-main.o \
|
||||
win32/win32-window.o \
|
||||
win32/win32.o
|
||||
endif
|
||||
|
||||
|
@ -52,12 +52,49 @@ typedef struct { int FAKE; } FAKE_FILE;
|
||||
#define strncasecmp FAKE_strncasecmp
|
||||
#endif
|
||||
|
||||
// HACK: SDL might include windows.h which defines its own ARRAYSIZE.
|
||||
// However, we want to use the version from common/util.h. Thus, we make sure
|
||||
// that we actually have this definition after including the SDL headers.
|
||||
#if defined(ARRAYSIZE) && defined(COMMON_UTIL_H)
|
||||
#define HACK_REDEFINE_ARRAYSIZE
|
||||
#undef ARRAYSIZE
|
||||
#endif
|
||||
|
||||
#if defined(__SYMBIAN32__)
|
||||
#include <esdl\SDL.h>
|
||||
#else
|
||||
#include <SDL.h>
|
||||
#endif
|
||||
|
||||
#include <SDL_syswm.h>
|
||||
// SDL_syswm.h will include windows.h on Win32. We need to undefine its
|
||||
// ARRAYSIZE definition because we supply our own.
|
||||
#undef ARRAYSIZE
|
||||
|
||||
#ifdef HACK_REDEFINE_ARRAYSIZE
|
||||
#undef HACK_REDEFINE_ARRAYSIZE
|
||||
#define ARRAYSIZE(x) ((int)(sizeof(x) / sizeof(x[0])))
|
||||
#endif
|
||||
|
||||
// In a moment of brilliance Xlib.h included by SDL_syswm.h #defines the
|
||||
// following names. In a moment of mental breakdown, which occured upon
|
||||
// gazing at Xlib.h, LordHoto decided to undefine them to prevent havoc.
|
||||
#ifdef Status
|
||||
#undef Status
|
||||
#endif
|
||||
|
||||
#ifdef Bool
|
||||
#undef Bool
|
||||
#endif
|
||||
|
||||
#ifdef True
|
||||
#undef True
|
||||
#endif
|
||||
|
||||
#ifdef False
|
||||
#undef False
|
||||
#endif
|
||||
|
||||
// Finally forbid FILE again (if it was forbidden to start with)
|
||||
#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_FILE)
|
||||
#undef FILE
|
||||
@ -74,5 +111,50 @@ typedef struct { int FAKE; } FAKE_FILE;
|
||||
#define strncasecmp FORBIDDEN_SYMBOL_REPLACEMENT
|
||||
#endif
|
||||
|
||||
// SDL 2 has major API changes. We redefine constants which got renamed to
|
||||
// ease the transition. This is sometimes dangerous because the values changed
|
||||
// too!
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
|
||||
// Type names which changed between SDL 1.2 and SDL 2.
|
||||
#define SDLKey SDL_Keycode
|
||||
#define SDLMod SDL_Keymod
|
||||
#define SDL_keysym SDL_Keysym
|
||||
|
||||
// Key code constants which got renamed.
|
||||
#define SDLK_SCROLLOCK SDLK_SCROLLLOCK
|
||||
#define SDLK_NUMLOCK SDLK_NUMLOCKCLEAR
|
||||
#define SDLK_LSUPER SDLK_LGUI
|
||||
#define SDLK_RSUPER SDLK_RGUI
|
||||
#define SDLK_PRINT SDLK_PRINTSCREEN
|
||||
#define SDLK_COMPOSE SDLK_APPLICATION
|
||||
#define SDLK_KP0 SDLK_KP_0
|
||||
#define SDLK_KP1 SDLK_KP_1
|
||||
#define SDLK_KP2 SDLK_KP_2
|
||||
#define SDLK_KP3 SDLK_KP_3
|
||||
#define SDLK_KP4 SDLK_KP_4
|
||||
#define SDLK_KP5 SDLK_KP_5
|
||||
#define SDLK_KP6 SDLK_KP_6
|
||||
#define SDLK_KP7 SDLK_KP_7
|
||||
#define SDLK_KP8 SDLK_KP_8
|
||||
#define SDLK_KP9 SDLK_KP_9
|
||||
|
||||
// Meta key constants which got renamed.
|
||||
#define KMOD_META KMOD_GUI
|
||||
|
||||
// SDL surface flags which got removed.
|
||||
#define SDL_SRCCOLORKEY 0
|
||||
#define SDL_SRCALPHA 0
|
||||
#define SDL_FULLSCREEN 0x40000000
|
||||
|
||||
// Compatibility implementations for removed functionality.
|
||||
int SDL_SetColors(SDL_Surface *surface, SDL_Color *colors, int firstcolor, int ncolors);
|
||||
int SDL_SetAlpha(SDL_Surface *surface, Uint32 flag, Uint8 alpha);
|
||||
|
||||
#define SDL_SetColorKey SDL_SetColorKey_replacement
|
||||
int SDL_SetColorKey_replacement(SDL_Surface *surface, Uint32 flag, Uint32 key);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
223
backends/platform/sdl/sdl-window.cpp
Normal file
223
backends/platform/sdl/sdl-window.cpp
Normal file
@ -0,0 +1,223 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
#define FORBIDDEN_SYMBOL_ALLOW_ALL
|
||||
|
||||
#include "backends/platform/sdl/sdl-window.h"
|
||||
|
||||
#include "common/textconsole.h"
|
||||
|
||||
#include "icons/scummvm.xpm"
|
||||
|
||||
SdlWindow::SdlWindow()
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
: _window(nullptr), _inputGrabState(false), _windowCaption("ScummVM")
|
||||
#endif
|
||||
{
|
||||
}
|
||||
|
||||
SdlWindow::~SdlWindow() {
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
destroyWindow();
|
||||
#endif
|
||||
}
|
||||
|
||||
void SdlWindow::setupIcon() {
|
||||
int x, y, w, h, ncols, nbytes, i;
|
||||
unsigned int rgba[256];
|
||||
unsigned int *icon;
|
||||
|
||||
if (sscanf(scummvm_icon[0], "%d %d %d %d", &w, &h, &ncols, &nbytes) != 4) {
|
||||
warning("Wrong format of scummvm_icon[0] (%s)", scummvm_icon[0]);
|
||||
|
||||
return;
|
||||
}
|
||||
if ((w > 512) || (h > 512) || (ncols > 255) || (nbytes > 1)) {
|
||||
warning("Could not load the built-in icon (%d %d %d %d)", w, h, ncols, nbytes);
|
||||
return;
|
||||
}
|
||||
icon = (unsigned int*)malloc(w*h*sizeof(unsigned int));
|
||||
if (!icon) {
|
||||
warning("Could not allocate temp storage for the built-in icon");
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < ncols; i++) {
|
||||
unsigned char code;
|
||||
char color[32];
|
||||
memset(color, 0, sizeof(color));
|
||||
unsigned int col;
|
||||
if (sscanf(scummvm_icon[1 + i], "%c c %s", &code, color) != 2) {
|
||||
warning("Wrong format of scummvm_icon[%d] (%s)", 1 + i, scummvm_icon[1 + i]);
|
||||
}
|
||||
if (!strcmp(color, "None"))
|
||||
col = 0x00000000;
|
||||
else if (!strcmp(color, "black"))
|
||||
col = 0xFF000000;
|
||||
else if (color[0] == '#') {
|
||||
if (sscanf(color + 1, "%06x", &col) != 1) {
|
||||
warning("Wrong format of color (%s)", color + 1);
|
||||
}
|
||||
col |= 0xFF000000;
|
||||
} else {
|
||||
warning("Could not load the built-in icon (%d %s - %s) ", code, color, scummvm_icon[1 + i]);
|
||||
free(icon);
|
||||
return;
|
||||
}
|
||||
|
||||
rgba[code] = col;
|
||||
}
|
||||
for (y = 0; y < h; y++) {
|
||||
const char *line = scummvm_icon[1 + ncols + y];
|
||||
for (x = 0; x < w; x++) {
|
||||
icon[x + w * y] = rgba[(int)line[x]];
|
||||
}
|
||||
}
|
||||
|
||||
SDL_Surface *sdl_surf = SDL_CreateRGBSurfaceFrom(icon, w, h, 32, w * 4, 0xFF0000, 0x00FF00, 0x0000FF, 0xFF000000);
|
||||
if (!sdl_surf) {
|
||||
warning("SDL_CreateRGBSurfaceFrom(icon) failed");
|
||||
}
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
if (_window) {
|
||||
SDL_SetWindowIcon(_window, sdl_surf);
|
||||
}
|
||||
#else
|
||||
SDL_WM_SetIcon(sdl_surf, NULL);
|
||||
#endif
|
||||
|
||||
SDL_FreeSurface(sdl_surf);
|
||||
free(icon);
|
||||
}
|
||||
|
||||
void SdlWindow::setWindowCaption(const Common::String &caption) {
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
_windowCaption = caption;
|
||||
if (_window) {
|
||||
SDL_SetWindowTitle(_window, caption.c_str());
|
||||
}
|
||||
#else
|
||||
SDL_WM_SetCaption(caption.c_str(), caption.c_str());
|
||||
#endif
|
||||
}
|
||||
|
||||
void SdlWindow::toggleMouseGrab() {
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
if (_window) {
|
||||
_inputGrabState = !(SDL_GetWindowGrab(_window) == SDL_TRUE);
|
||||
SDL_SetWindowGrab(_window, _inputGrabState ? SDL_TRUE : SDL_FALSE);
|
||||
}
|
||||
#else
|
||||
if (SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_OFF) {
|
||||
SDL_WM_GrabInput(SDL_GRAB_ON);
|
||||
} else {
|
||||
SDL_WM_GrabInput(SDL_GRAB_OFF);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bool SdlWindow::hasMouseFocus() const {
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
if (_window) {
|
||||
return (SDL_GetWindowFlags(_window) & SDL_WINDOW_MOUSE_FOCUS);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
return (SDL_GetAppState() & SDL_APPMOUSEFOCUS);
|
||||
#endif
|
||||
}
|
||||
|
||||
void SdlWindow::warpMouseInWindow(uint x, uint y) {
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
if (_window) {
|
||||
SDL_WarpMouseInWindow(_window, x, y);
|
||||
}
|
||||
#else
|
||||
SDL_WarpMouse(x, y);
|
||||
#endif
|
||||
}
|
||||
|
||||
void SdlWindow::iconifyWindow() {
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
if (_window) {
|
||||
SDL_MinimizeWindow(_window);
|
||||
}
|
||||
#else
|
||||
SDL_WM_IconifyWindow();
|
||||
#endif
|
||||
}
|
||||
|
||||
bool SdlWindow::getSDLWMInformation(SDL_SysWMinfo *info) const {
|
||||
SDL_VERSION(&info->version);
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
return SDL_GetWindowWMInfo(_window, info);
|
||||
#else
|
||||
return SDL_GetWMInfo(info);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
SDL_Surface *copySDLSurface(SDL_Surface *src) {
|
||||
const bool locked = SDL_MUSTLOCK(src) == SDL_TRUE;
|
||||
|
||||
if (locked) {
|
||||
if (SDL_LockSurface(src) != 0) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
SDL_Surface *res = SDL_CreateRGBSurfaceFrom(src->pixels,
|
||||
src->w, src->h, src->format->BitsPerPixel,
|
||||
src->pitch, src->format->Rmask, src->format->Gmask,
|
||||
src->format->Bmask, src->format->Amask);
|
||||
|
||||
if (locked) {
|
||||
SDL_UnlockSurface(src);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
bool SdlWindow::createWindow(int width, int height, uint32 flags) {
|
||||
destroyWindow();
|
||||
|
||||
if (_inputGrabState) {
|
||||
flags |= SDL_WINDOW_INPUT_GRABBED;
|
||||
}
|
||||
|
||||
_window = SDL_CreateWindow(_windowCaption.c_str(), SDL_WINDOWPOS_UNDEFINED,
|
||||
SDL_WINDOWPOS_UNDEFINED, width, height, flags);
|
||||
if (!_window) {
|
||||
return false;
|
||||
}
|
||||
setupIcon();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void SdlWindow::destroyWindow() {
|
||||
SDL_DestroyWindow(_window);
|
||||
_window = nullptr;
|
||||
}
|
||||
#endif
|
112
backends/platform/sdl/sdl-window.h
Normal file
112
backends/platform/sdl/sdl-window.h
Normal file
@ -0,0 +1,112 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef BACKENDS_PLATFORM_SDL_WINDOW_H
|
||||
#define BACKENDS_PLATFORM_SDL_WINDOW_H
|
||||
|
||||
#include "backends/platform/sdl/sdl-sys.h"
|
||||
|
||||
#include "common/str.h"
|
||||
|
||||
class SdlWindow {
|
||||
public:
|
||||
SdlWindow();
|
||||
virtual ~SdlWindow();
|
||||
|
||||
/**
|
||||
* Setup the window icon.
|
||||
*/
|
||||
virtual void setupIcon();
|
||||
|
||||
/**
|
||||
* Change the caption of the window.
|
||||
*
|
||||
* @param caption New window caption in UTF-8 encoding.
|
||||
*/
|
||||
void setWindowCaption(const Common::String &caption);
|
||||
|
||||
/**
|
||||
* 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();
|
||||
|
||||
/**
|
||||
* Query platform specific SDL window manager information.
|
||||
*
|
||||
* Since this is an SDL internal structure clients are responsible
|
||||
* for accessing it in a version safe manner.
|
||||
*/
|
||||
bool getSDLWMInformation(SDL_SysWMinfo *info) const;
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
public:
|
||||
/**
|
||||
* @return The window ScummVM has setup with SDL.
|
||||
*/
|
||||
SDL_Window *getSDLWindow() const { return _window; }
|
||||
|
||||
/**
|
||||
* Creates a new SDL window (and destroies the old one).
|
||||
*
|
||||
* @param width Width of the window.
|
||||
* @param height Height of the window.
|
||||
* @param flags SDL flags passed to SDL_CreateWindow
|
||||
* @return true on success, false otherwise
|
||||
*/
|
||||
bool createWindow(int width, int height, uint32 flags);
|
||||
|
||||
/**
|
||||
* Destroies the current SDL window.
|
||||
*/
|
||||
void destroyWindow();
|
||||
|
||||
protected:
|
||||
SDL_Window *_window;
|
||||
|
||||
private:
|
||||
bool _inputGrabState;
|
||||
Common::String _windowCaption;
|
||||
#endif
|
||||
};
|
||||
|
||||
class SdlIconlessWindow : public SdlWindow {
|
||||
public:
|
||||
virtual void setupIcon() {}
|
||||
};
|
||||
|
||||
#endif
|
@ -52,8 +52,6 @@
|
||||
#include "graphics/cursorman.h"
|
||||
#endif
|
||||
|
||||
#include "icons/scummvm.xpm"
|
||||
|
||||
#include <time.h> // for getTimeAndDate()
|
||||
|
||||
#ifdef USE_DETECTLANG
|
||||
@ -77,7 +75,8 @@ OSystem_SDL::OSystem_SDL()
|
||||
_initedSDL(false),
|
||||
_logger(0),
|
||||
_mixerManager(0),
|
||||
_eventSource(0) {
|
||||
_eventSource(0),
|
||||
_window(0) {
|
||||
|
||||
}
|
||||
|
||||
@ -95,6 +94,8 @@ OSystem_SDL::~OSystem_SDL() {
|
||||
}
|
||||
delete _graphicsManager;
|
||||
_graphicsManager = 0;
|
||||
delete _window;
|
||||
_window = 0;
|
||||
delete _eventManager;
|
||||
_eventManager = 0;
|
||||
delete _eventSource;
|
||||
@ -126,8 +127,10 @@ void OSystem_SDL::init() {
|
||||
// Initialize SDL
|
||||
initSDL();
|
||||
|
||||
#if !SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
// Enable unicode support if possible
|
||||
SDL_EnableUNICODE(1);
|
||||
#endif
|
||||
|
||||
// Disable OS cursor
|
||||
SDL_ShowCursor(SDL_DISABLE);
|
||||
@ -147,6 +150,9 @@ void OSystem_SDL::init() {
|
||||
if (_mutexManager == 0)
|
||||
_mutexManager = new SdlMutexManager();
|
||||
|
||||
if (_window == 0)
|
||||
_window = new SdlWindow();
|
||||
|
||||
#if defined(USE_TASKBAR)
|
||||
if (_taskbarManager == 0)
|
||||
_taskbarManager = new Common::TaskbarManager();
|
||||
@ -158,10 +164,14 @@ void OSystem_SDL::initBackend() {
|
||||
// Check if backend has not been initialized
|
||||
assert(!_inited);
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
const char *sdlDriverName = SDL_GetCurrentVideoDriver();
|
||||
#else
|
||||
const int maxNameLen = 20;
|
||||
char sdlDriverName[maxNameLen];
|
||||
sdlDriverName[0] = '\0';
|
||||
SDL_VideoDriverName(sdlDriverName, maxNameLen);
|
||||
#endif
|
||||
// Using printf rather than debug() here as debug()/logging
|
||||
// is not active by this point.
|
||||
debug(1, "Using SDL Video Driver \"%s\"", sdlDriverName);
|
||||
@ -172,6 +182,13 @@ void OSystem_SDL::initBackend() {
|
||||
_eventSource = new SdlEventSource();
|
||||
|
||||
#ifdef USE_OPENGL
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
SDL_DisplayMode displayMode;
|
||||
if (!SDL_GetDesktopDisplayMode(0, &displayMode)) {
|
||||
_desktopWidth = displayMode.w;
|
||||
_desktopHeight = displayMode.h;
|
||||
}
|
||||
#else
|
||||
// Query the desktop resolution. We simply hope nothing tried to change
|
||||
// the resolution so far.
|
||||
const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo();
|
||||
@ -179,6 +196,7 @@ void OSystem_SDL::initBackend() {
|
||||
_desktopWidth = videoInfo->current_w;
|
||||
_desktopHeight = videoInfo->current_h;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (_graphicsManager == 0) {
|
||||
@ -196,7 +214,7 @@ void OSystem_SDL::initBackend() {
|
||||
Common::String gfxMode(ConfMan.get("gfx_mode"));
|
||||
for (uint i = _firstGLMode; i < _graphicsModeIds.size(); ++i) {
|
||||
if (!scumm_stricmp(_graphicsModes[i].name, gfxMode.c_str())) {
|
||||
_graphicsManager = new OpenGLSdlGraphicsManager(_desktopWidth, _desktopHeight, _eventSource);
|
||||
_graphicsManager = new OpenGLSdlGraphicsManager(_desktopWidth, _desktopHeight, _eventSource, _window);
|
||||
_graphicsMode = i;
|
||||
break;
|
||||
}
|
||||
@ -205,7 +223,7 @@ void OSystem_SDL::initBackend() {
|
||||
#endif
|
||||
|
||||
if (_graphicsManager == 0) {
|
||||
_graphicsManager = new SurfaceSdlGraphicsManager(_eventSource);
|
||||
_graphicsManager = new SurfaceSdlGraphicsManager(_eventSource, _window);
|
||||
}
|
||||
}
|
||||
|
||||
@ -238,7 +256,7 @@ void OSystem_SDL::initBackend() {
|
||||
}
|
||||
|
||||
// Setup a custom program icon.
|
||||
setupIcon();
|
||||
_window->setupIcon();
|
||||
|
||||
_inited = true;
|
||||
|
||||
@ -314,7 +332,7 @@ void OSystem_SDL::setWindowCaption(const char *caption) {
|
||||
}
|
||||
}
|
||||
|
||||
SDL_WM_SetCaption(cap.c_str(), cap.c_str());
|
||||
_window->setWindowCaption(cap);
|
||||
}
|
||||
|
||||
void OSystem_SDL::quit() {
|
||||
@ -421,68 +439,6 @@ Common::String OSystem_SDL::getSystemLanguage() const {
|
||||
#endif // USE_DETECTLANG
|
||||
}
|
||||
|
||||
void OSystem_SDL::setupIcon() {
|
||||
int x, y, w, h, ncols, nbytes, i;
|
||||
unsigned int rgba[256];
|
||||
unsigned int *icon;
|
||||
|
||||
if (sscanf(scummvm_icon[0], "%d %d %d %d", &w, &h, &ncols, &nbytes) != 4) {
|
||||
warning("Wrong format of scummvm_icon[0] (%s)", scummvm_icon[0]);
|
||||
|
||||
return;
|
||||
}
|
||||
if ((w > 512) || (h > 512) || (ncols > 255) || (nbytes > 1)) {
|
||||
warning("Could not load the built-in icon (%d %d %d %d)", w, h, ncols, nbytes);
|
||||
return;
|
||||
}
|
||||
icon = (unsigned int*)malloc(w*h*sizeof(unsigned int));
|
||||
if (!icon) {
|
||||
warning("Could not allocate temp storage for the built-in icon");
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < ncols; i++) {
|
||||
unsigned char code;
|
||||
char color[32];
|
||||
memset(color, 0, sizeof(color));
|
||||
unsigned int col;
|
||||
if (sscanf(scummvm_icon[1 + i], "%c c %s", &code, color) != 2) {
|
||||
warning("Wrong format of scummvm_icon[%d] (%s)", 1 + i, scummvm_icon[1 + i]);
|
||||
}
|
||||
if (!strcmp(color, "None"))
|
||||
col = 0x00000000;
|
||||
else if (!strcmp(color, "black"))
|
||||
col = 0xFF000000;
|
||||
else if (color[0] == '#') {
|
||||
if (sscanf(color + 1, "%06x", &col) != 1) {
|
||||
warning("Wrong format of color (%s)", color + 1);
|
||||
}
|
||||
col |= 0xFF000000;
|
||||
} else {
|
||||
warning("Could not load the built-in icon (%d %s - %s) ", code, color, scummvm_icon[1 + i]);
|
||||
free(icon);
|
||||
return;
|
||||
}
|
||||
|
||||
rgba[code] = col;
|
||||
}
|
||||
for (y = 0; y < h; y++) {
|
||||
const char *line = scummvm_icon[1 + ncols + y];
|
||||
for (x = 0; x < w; x++) {
|
||||
icon[x + w * y] = rgba[(int)line[x]];
|
||||
}
|
||||
}
|
||||
|
||||
SDL_Surface *sdl_surf = SDL_CreateRGBSurfaceFrom(icon, w, h, 32, w * 4, 0xFF0000, 0x00FF00, 0x0000FF, 0xFF000000);
|
||||
if (!sdl_surf) {
|
||||
warning("SDL_CreateRGBSurfaceFrom(icon) failed");
|
||||
}
|
||||
SDL_WM_SetIcon(sdl_surf, NULL);
|
||||
SDL_FreeSurface(sdl_surf);
|
||||
free(icon);
|
||||
}
|
||||
|
||||
|
||||
uint32 OSystem_SDL::getMillis(bool skipRecord) {
|
||||
uint32 millis = SDL_GetTicks();
|
||||
|
||||
@ -572,14 +528,8 @@ bool OSystem_SDL::setGraphicsMode(int mode) {
|
||||
//
|
||||
// This is a probably temporary workaround to fix bugs like #3368143
|
||||
// "SDL/OpenGL: Crash when switching renderer backend".
|
||||
const int screenWidth = _graphicsManager->getWidth();
|
||||
const int screenHeight = _graphicsManager->getHeight();
|
||||
const bool arState = _graphicsManager->getFeatureState(kFeatureAspectRatioCorrection);
|
||||
const bool fullscreen = _graphicsManager->getFeatureState(kFeatureFullscreenMode);
|
||||
const bool cursorPalette = _graphicsManager->getFeatureState(kFeatureCursorPalette);
|
||||
#ifdef USE_RGB_COLOR
|
||||
const Graphics::PixelFormat pixelFormat = _graphicsManager->getScreenFormat();
|
||||
#endif
|
||||
SdlGraphicsManager *sdlGraphicsManager = dynamic_cast<SdlGraphicsManager *>(_graphicsManager);
|
||||
SdlGraphicsManager::State state = sdlGraphicsManager->getState();
|
||||
|
||||
bool switchedManager = false;
|
||||
|
||||
@ -587,16 +537,16 @@ bool OSystem_SDL::setGraphicsMode(int mode) {
|
||||
// manager, delete and create the new mode graphics manager
|
||||
if (_graphicsMode >= _firstGLMode && mode < _firstGLMode) {
|
||||
debug(1, "switching to plain SDL graphics");
|
||||
dynamic_cast<SdlGraphicsManager *>(_graphicsManager)->deactivateManager();
|
||||
sdlGraphicsManager->deactivateManager();
|
||||
delete _graphicsManager;
|
||||
_graphicsManager = new SurfaceSdlGraphicsManager(_eventSource);
|
||||
_graphicsManager = sdlGraphicsManager = new SurfaceSdlGraphicsManager(_eventSource, _window);
|
||||
|
||||
switchedManager = true;
|
||||
} else if (_graphicsMode < _firstGLMode && mode >= _firstGLMode) {
|
||||
debug(1, "switching to OpenGL graphics");
|
||||
dynamic_cast<SdlGraphicsManager *>(_graphicsManager)->deactivateManager();
|
||||
sdlGraphicsManager->deactivateManager();
|
||||
delete _graphicsManager;
|
||||
_graphicsManager = new OpenGLSdlGraphicsManager(_desktopWidth, _desktopHeight, _eventSource);
|
||||
_graphicsManager = sdlGraphicsManager = new OpenGLSdlGraphicsManager(_desktopWidth, _desktopHeight, _eventSource, _window);
|
||||
|
||||
switchedManager = true;
|
||||
}
|
||||
@ -604,24 +554,10 @@ bool OSystem_SDL::setGraphicsMode(int mode) {
|
||||
_graphicsMode = mode;
|
||||
|
||||
if (switchedManager) {
|
||||
dynamic_cast<SdlGraphicsManager *>(_graphicsManager)->activateManager();
|
||||
sdlGraphicsManager->activateManager();
|
||||
|
||||
_graphicsManager->beginGFXTransaction();
|
||||
#ifdef USE_RGB_COLOR
|
||||
_graphicsManager->initSize(screenWidth, screenHeight, &pixelFormat);
|
||||
#else
|
||||
_graphicsManager->initSize(screenWidth, screenHeight, 0);
|
||||
#endif
|
||||
_graphicsManager->setFeatureState(kFeatureAspectRatioCorrection, arState);
|
||||
_graphicsManager->setFeatureState(kFeatureFullscreenMode, fullscreen);
|
||||
_graphicsManager->setFeatureState(kFeatureCursorPalette, cursorPalette);
|
||||
|
||||
// Worst part about this right now, tell the cursor manager to
|
||||
// resetup the cursor + cursor palette if necessarily
|
||||
|
||||
// First we need to try to setup the old state on the new manager...
|
||||
if (_graphicsManager->endGFXTransaction() != kTransactionSuccess) {
|
||||
// Oh my god if this failed the client code might just explode.
|
||||
// This failing will probably have bad consequences...
|
||||
if (!sdlGraphicsManager->setState(state)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -630,7 +566,7 @@ bool OSystem_SDL::setGraphicsMode(int mode) {
|
||||
CursorMan.popCursor();
|
||||
|
||||
// Next setup cursor palette if needed
|
||||
if (cursorPalette) {
|
||||
if (_graphicsManager->getFeatureState(kFeatureCursorPalette)) {
|
||||
CursorMan.pushCursorPalette(0, 0, 0);
|
||||
CursorMan.popCursorPalette();
|
||||
}
|
||||
@ -660,7 +596,7 @@ void OSystem_SDL::setupGraphicsModes() {
|
||||
const OSystem::GraphicsMode *srcMode;
|
||||
int defaultMode;
|
||||
|
||||
GraphicsManager *manager = new SurfaceSdlGraphicsManager(_eventSource);
|
||||
GraphicsManager *manager = new SurfaceSdlGraphicsManager(_eventSource, _window);
|
||||
srcMode = manager->getSupportedGraphicsModes();
|
||||
defaultMode = manager->getDefaultGraphicsMode();
|
||||
while (srcMode->name) {
|
||||
@ -674,7 +610,7 @@ void OSystem_SDL::setupGraphicsModes() {
|
||||
assert(_defaultSDLMode != -1);
|
||||
|
||||
_firstGLMode = _graphicsModes.size();
|
||||
manager = new OpenGLSdlGraphicsManager(_desktopWidth, _desktopHeight, _eventSource);
|
||||
manager = new OpenGLSdlGraphicsManager(_desktopWidth, _desktopHeight, _eventSource, _window);
|
||||
srcMode = manager->getSupportedGraphicsModes();
|
||||
defaultMode = manager->getDefaultGraphicsMode();
|
||||
while (srcMode->name) {
|
||||
@ -702,5 +638,38 @@ void OSystem_SDL::setupGraphicsModes() {
|
||||
mode++;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
int SDL_SetColors(SDL_Surface *surface, SDL_Color *colors, int firstcolor, int ncolors) {
|
||||
if (surface->format->palette) {
|
||||
return !SDL_SetPaletteColors(surface->format->palette, colors, firstcolor, ncolors) ? 1 : 0;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int SDL_SetAlpha(SDL_Surface *surface, Uint32 flag, Uint8 alpha) {
|
||||
if (SDL_SetSurfaceAlphaMod(surface, alpha)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (alpha == 255 || !flag) {
|
||||
if (SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_NONE)) {
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
if (SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_BLEND)) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#undef SDL_SetColorKey
|
||||
int SDL_SetColorKey_replacement(SDL_Surface *surface, Uint32 flag, Uint32 key) {
|
||||
return SDL_SetColorKey(surface, SDL_TRUE, key) ? -1 : 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include "backends/mixer/sdl/sdl-mixer.h"
|
||||
#include "backends/events/sdl/sdl-events.h"
|
||||
#include "backends/log/log.h"
|
||||
#include "backends/platform/sdl/sdl-window.h"
|
||||
|
||||
#include "common/array.h"
|
||||
|
||||
@ -91,6 +92,11 @@ protected:
|
||||
*/
|
||||
SdlEventSource *_eventSource;
|
||||
|
||||
/**
|
||||
* The SDL output window.
|
||||
*/
|
||||
SdlWindow *_window;
|
||||
|
||||
virtual Common::EventSource *getDefaultEventSource() { return _eventSource; }
|
||||
|
||||
/**
|
||||
@ -98,11 +104,6 @@ protected:
|
||||
*/
|
||||
virtual void initSDL();
|
||||
|
||||
/**
|
||||
* Setup the window icon.
|
||||
*/
|
||||
virtual void setupIcon();
|
||||
|
||||
// Logging
|
||||
virtual Common::WriteStream *createLogFile() { return 0; }
|
||||
Backends::Log::Log *_logger;
|
||||
|
@ -40,7 +40,9 @@
|
||||
#include "base/main.h"
|
||||
|
||||
int __stdcall WinMain(HINSTANCE /*hInst*/, HINSTANCE /*hPrevInst*/, LPSTR /*lpCmdLine*/, int /*iShowCmd*/) {
|
||||
#if !SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
SDL_SetModuleHandle(GetModuleHandle(NULL));
|
||||
#endif
|
||||
return main(__argc, __argv);
|
||||
}
|
||||
|
||||
|
59
backends/platform/sdl/win32/win32-window.cpp
Normal file
59
backends/platform/sdl/win32/win32-window.cpp
Normal file
@ -0,0 +1,59 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
// Disable symbol overrides so that we can use system headers.
|
||||
#define FORBIDDEN_SYMBOL_ALLOW_ALL
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
#include "backends/platform/sdl/win32/win32-window.h"
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#undef ARRAYSIZE // winnt.h defines ARRAYSIZE, but we want our own one...
|
||||
|
||||
void SdlWindow_Win32::setupIcon() {
|
||||
HMODULE handle = GetModuleHandle(NULL);
|
||||
HICON ico = LoadIcon(handle, MAKEINTRESOURCE(1001 /* IDI_ICON */));
|
||||
if (ico) {
|
||||
SDL_SysWMinfo wminfo;
|
||||
if (getSDLWMInformation(&wminfo)) {
|
||||
// Replace the handle to the icon associated with the window class by our custom icon
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
SetClassLongPtr(wminfo.info.win.window, GCLP_HICON, (ULONG_PTR)ico);
|
||||
#else
|
||||
SetClassLongPtr(wminfo.window, GCLP_HICON, (ULONG_PTR)ico);
|
||||
#endif
|
||||
|
||||
// Since there wasn't any default icon, we can't use the return value from SetClassLong
|
||||
// to check for errors (it would be 0 in both cases: error or no previous value for the
|
||||
// icon handle). Instead we check for the last-error code value.
|
||||
if (GetLastError() == ERROR_SUCCESS)
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// If no icon has been set, fallback to default path
|
||||
SdlWindow::setupIcon();
|
||||
}
|
||||
|
||||
#endif
|
37
backends/platform/sdl/win32/win32-window.h
Normal file
37
backends/platform/sdl/win32/win32-window.h
Normal file
@ -0,0 +1,37 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef BACKENDS_PLATFORM_SDL_WIN32_WIN32_WINDOW_H
|
||||
#define BACKENDS_PLATFORM_SDL_WIN32_WIN32_WINDOW_H
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
#include "backends/platform/sdl/sdl-window.h"
|
||||
|
||||
class SdlWindow_Win32 : public SdlWindow {
|
||||
public:
|
||||
virtual void setupIcon();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
@ -35,9 +35,8 @@
|
||||
#include "common/error.h"
|
||||
#include "common/textconsole.h"
|
||||
|
||||
#include <SDL_syswm.h> // For setting the icon
|
||||
|
||||
#include "backends/platform/sdl/win32/win32.h"
|
||||
#include "backends/platform/sdl/win32/win32-window.h"
|
||||
#include "backends/saves/windows/windows-saves.h"
|
||||
#include "backends/fs/windows/windows-fs-factory.h"
|
||||
#include "backends/taskbar/win32/win32-taskbar.h"
|
||||
@ -50,9 +49,12 @@ void OSystem_Win32::init() {
|
||||
// Initialize File System Factory
|
||||
_fsFactory = new WindowsFilesystemFactory();
|
||||
|
||||
// Create Win32 specific window
|
||||
_window = new SdlWindow_Win32();
|
||||
|
||||
#if defined(USE_TASKBAR)
|
||||
// Initialize taskbar manager
|
||||
_taskbarManager = new Win32TaskbarManager();
|
||||
_taskbarManager = new Win32TaskbarManager(_window);
|
||||
#endif
|
||||
|
||||
// Invoke parent implementation of this method
|
||||
@ -126,28 +128,6 @@ bool OSystem_Win32::displayLogFile() {
|
||||
return false;
|
||||
}
|
||||
|
||||
void OSystem_Win32::setupIcon() {
|
||||
HMODULE handle = GetModuleHandle(NULL);
|
||||
HICON ico = LoadIcon(handle, MAKEINTRESOURCE(1001 /* IDI_ICON */));
|
||||
if (ico) {
|
||||
SDL_SysWMinfo wminfo;
|
||||
SDL_VERSION(&wminfo.version);
|
||||
if (SDL_GetWMInfo(&wminfo)) {
|
||||
// Replace the handle to the icon associated with the window class by our custom icon
|
||||
SetClassLongPtr(wminfo.window, GCLP_HICON, (ULONG_PTR)ico);
|
||||
|
||||
// Since there wasn't any default icon, we can't use the return value from SetClassLong
|
||||
// to check for errors (it would be 0 in both cases: error or no previous value for the
|
||||
// icon handle). Instead we check for the last-error code value.
|
||||
if (GetLastError() == ERROR_SUCCESS)
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// If no icon has been set, fallback to default path
|
||||
OSystem_SDL::setupIcon();
|
||||
}
|
||||
|
||||
Common::String OSystem_Win32::getDefaultConfigFileName() {
|
||||
char configFile[MAXPATHLEN];
|
||||
|
||||
|
@ -47,7 +47,6 @@ protected:
|
||||
*/
|
||||
Common::String _logFilePath;
|
||||
|
||||
virtual void setupIcon();
|
||||
virtual Common::String getDefaultConfigFileName();
|
||||
virtual Common::WriteStream *createLogFile();
|
||||
};
|
||||
|
@ -63,6 +63,8 @@ OSystem_SDL_Symbian::OSystem_SDL_Symbian()
|
||||
|
||||
void OSystem_SDL_Symbian::init() {
|
||||
_RFs = &CEikonEnv::Static()->FsSession();
|
||||
// Use iconless window: it uses the EScummVM.aif file for the icon.
|
||||
_window = new SdlIconlessWindow();
|
||||
_fsFactory = new SymbianFilesystemFactory();
|
||||
OSystem_SDL::init();
|
||||
}
|
||||
@ -109,7 +111,7 @@ void OSystem_SDL_Symbian::initBackend() {
|
||||
_mixerManager->init();
|
||||
}
|
||||
if (_graphicsManager == 0)
|
||||
_graphicsManager = new SymbianSdlGraphicsManager(_eventSource);
|
||||
_graphicsManager = new SymbianSdlGraphicsManager(_eventSource, _window);
|
||||
|
||||
// Call parent implementation of this method
|
||||
OSystem_SDL::initBackend();
|
||||
@ -171,10 +173,6 @@ Common::String OSystem_SDL_Symbian::getDefaultConfigFileName() {
|
||||
return configFile;
|
||||
}
|
||||
|
||||
void OSystem_SDL_Symbian::setupIcon() {
|
||||
// Don't for Symbian: it uses the EScummVM.aif file for the icon.
|
||||
}
|
||||
|
||||
RFs& OSystem_SDL_Symbian::FsSession() {
|
||||
return *_RFs;
|
||||
}
|
||||
|
@ -39,7 +39,6 @@ public:
|
||||
virtual void engineDone();
|
||||
virtual bool setGraphicsMode(const char *name);
|
||||
virtual Common::String getDefaultConfigFileName();
|
||||
virtual void setupIcon();
|
||||
|
||||
/**
|
||||
* Returns reference to File session
|
||||
|
@ -420,7 +420,7 @@ void OSystem_WINCE3::initBackend() {
|
||||
}
|
||||
|
||||
if (_graphicsManager == 0)
|
||||
_graphicsManager = new WINCESdlGraphicsManager(_eventSource);
|
||||
_graphicsManager = new WINCESdlGraphicsManager(_eventSource, _window);
|
||||
|
||||
((WINCESdlEventSource *)_eventSource)->init(dynamic_cast<WINCESdlGraphicsManager *>(_graphicsManager));
|
||||
|
||||
|
@ -48,9 +48,6 @@
|
||||
|
||||
#include <shlobj.h>
|
||||
|
||||
// For HWND
|
||||
#include <SDL_syswm.h>
|
||||
|
||||
#include "common/scummsys.h"
|
||||
|
||||
#include "backends/taskbar/win32/win32-taskbar.h"
|
||||
@ -62,7 +59,7 @@
|
||||
// System.Title property key, values taken from http://msdn.microsoft.com/en-us/library/bb787584.aspx
|
||||
const PROPERTYKEY PKEY_Title = { /* fmtid = */ { 0xF29F85E0, 0x4FF9, 0x1068, { 0xAB, 0x91, 0x08, 0x00, 0x2B, 0x27, 0xB3, 0xD9 } }, /* propID = */ 2 };
|
||||
|
||||
Win32TaskbarManager::Win32TaskbarManager() : _taskbar(NULL), _count(0), _icon(NULL) {
|
||||
Win32TaskbarManager::Win32TaskbarManager(SdlWindow *window) : _window(window), _taskbar(NULL), _count(0), _icon(NULL) {
|
||||
// Do nothing if not running on Windows 7 or later
|
||||
if (!isWin7OrLater())
|
||||
return;
|
||||
@ -408,12 +405,15 @@ LPWSTR Win32TaskbarManager::ansiToUnicode(const char *s) {
|
||||
|
||||
HWND Win32TaskbarManager::getHwnd() {
|
||||
SDL_SysWMinfo wmi;
|
||||
SDL_VERSION(&wmi.version);
|
||||
|
||||
if(!SDL_GetWMInfo(&wmi))
|
||||
if (_window->getSDLWMInformation(&wmi)) {
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
return wmi.info.win.window;
|
||||
#else
|
||||
return wmi.window;
|
||||
#endif
|
||||
} else {
|
||||
return NULL;
|
||||
|
||||
return wmi.window;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -25,6 +25,8 @@
|
||||
|
||||
#if defined(WIN32) && defined(USE_TASKBAR)
|
||||
|
||||
#include "backends/platform/sdl/sdl-window.h"
|
||||
|
||||
#include "common/str.h"
|
||||
#include "common/taskbar.h"
|
||||
|
||||
@ -32,7 +34,7 @@ struct ITaskbarList3;
|
||||
|
||||
class Win32TaskbarManager : public Common::TaskbarManager {
|
||||
public:
|
||||
Win32TaskbarManager();
|
||||
Win32TaskbarManager(SdlWindow *window);
|
||||
virtual ~Win32TaskbarManager();
|
||||
|
||||
virtual void setOverlayIcon(const Common::String &name, const Common::String &description);
|
||||
@ -44,6 +46,8 @@ public:
|
||||
virtual void clearError();
|
||||
|
||||
private:
|
||||
SdlWindow *_window;
|
||||
|
||||
ITaskbarList3 *_taskbar;
|
||||
|
||||
// Count handling
|
||||
|
7
configure
vendored
7
configure
vendored
@ -35,6 +35,7 @@ SAVED_CXXFLAGS=$CXXFLAGS
|
||||
SAVED_CPPFLAGS=$CPPFLAGS
|
||||
SAVED_ASFLAGS=$ASFLAGS
|
||||
SAVED_WINDRESFLAGS=$WINDRESFLAGS
|
||||
SAVED_SDL_CONFIG=$SDL_CONFIG
|
||||
|
||||
# Use environment vars if set
|
||||
CXXFLAGS="$CXXFLAGS $CPPFLAGS"
|
||||
@ -353,7 +354,7 @@ define_in_config_if_yes() {
|
||||
# TODO: small bit of code to test sdl usability
|
||||
find_sdlconfig() {
|
||||
echo_n "Looking for sdl-config... "
|
||||
sdlconfigs="$_sdlconfig:sdl-config:sdl11-config:sdl12-config"
|
||||
sdlconfigs="$SDL_CONFIG:$_sdlconfig:sdl-config:sdl11-config:sdl12-config"
|
||||
_sdlconfig=
|
||||
|
||||
IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="$SEPARATOR"
|
||||
@ -3069,6 +3070,9 @@ case $_backend in
|
||||
1.3.*)
|
||||
add_line_to_config_mk "USE_SDL13 = 1"
|
||||
;;
|
||||
2.0.*)
|
||||
add_line_to_config_mk "USE_SDL2 = 1"
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
@ -4581,6 +4585,7 @@ SAVED_CXXFLAGS := $SAVED_CXXFLAGS
|
||||
SAVED_CPPFLAGS := $SAVED_CPPFLAGS
|
||||
SAVED_ASFLAGS := $SAVED_ASFLAGS
|
||||
SAVED_WINDRESFLAGS := $SAVED_WINDRESFLAGS
|
||||
SAVED_SDL_CONFIG := $SAVED_SDL_CONFIG
|
||||
EOF
|
||||
|
||||
#
|
||||
|
@ -1133,6 +1133,7 @@ begin_credits("Credits");
|
||||
add_person("Jeroen Janssen", "japj", "Numerous readability and bugfix patches");
|
||||
add_person("Keith Kaisershot", "blitter", "Several Pegasus Prime patches");
|
||||
add_person("Andreas Karlsson", "Sprawl", "Initial port for SymbianOS");
|
||||
add_person("Stefan Kristiansson", "skristiansson", "Initial work on SDL2 support");
|
||||
add_person("Claudio Matsuoka", "", "Daily Linux builds");
|
||||
add_person("Thomas Mayer", "", "PSP port contributions");
|
||||
add_person("Sean Murray", "lightcast", "ScummVM tools GUI application (GSoC 2007 task)");
|
||||
|
@ -694,6 +694,8 @@ static const char *credits[] = {
|
||||
"C2""Several Pegasus Prime patches",
|
||||
"C0""Andreas Karlsson",
|
||||
"C2""Initial port for SymbianOS",
|
||||
"C0""Stefan Kristiansson",
|
||||
"C2""Initial work on SDL2 support",
|
||||
"C0""Claudio Matsuoka",
|
||||
"C2""Daily Linux builds",
|
||||
"C0""Thomas Mayer",
|
||||
|
Loading…
x
Reference in New Issue
Block a user