aboutsummaryrefslogtreecommitdiff
path: root/backends/sdl
diff options
context:
space:
mode:
authorMax Horn2004-02-24 22:39:42 +0000
committerMax Horn2004-02-24 22:39:42 +0000
commitd158280425efac5f4ec72e00fb2b7389cdfb5a75 (patch)
treef1bdab69e381b2a28320fdeb30936482565e5099 /backends/sdl
parent70f910cbe19e9c7320a56fa48669f7a5e9df00e6 (diff)
downloadscummvm-rg350-d158280425efac5f4ec72e00fb2b7389cdfb5a75.tar.gz
scummvm-rg350-d158280425efac5f4ec72e00fb2b7389cdfb5a75.tar.bz2
scummvm-rg350-d158280425efac5f4ec72e00fb2b7389cdfb5a75.zip
the OSystem changes we discussed on the ML (note: renaming of the existing OSystem API is not yet finished); porters will have to fix their ports to get them to compile again
svn-id: r13036
Diffstat (limited to 'backends/sdl')
-rw-r--r--backends/sdl/sdl-common.cpp199
-rw-r--r--backends/sdl/sdl-common.h28
-rw-r--r--backends/sdl/sdl.cpp47
3 files changed, 162 insertions, 112 deletions
diff --git a/backends/sdl/sdl-common.cpp b/backends/sdl/sdl-common.cpp
index 3ecd5197e8..4e4d522f41 100644
--- a/backends/sdl/sdl-common.cpp
+++ b/backends/sdl/sdl-common.cpp
@@ -47,29 +47,23 @@
#define JOY_BUT_SPACE 4
#define JOY_BUT_F5 5
-OSystem *OSystem_SDL_create(int gfx_mode) {
- return OSystem_SDL_Common::create(gfx_mode);
+OSystem *OSystem_SDL_create() {
+ return OSystem_SDL_Common::create();
}
-OSystem *OSystem_SDL_Common::create(int gfx_mode) {
+OSystem *OSystem_SDL_Common::create() {
OSystem_SDL_Common *syst = OSystem_SDL_Common::create_intern();
- syst->init_intern(gfx_mode);
+ syst->init_intern();
return syst;
}
-void OSystem_SDL_Common::init_intern(int gfx_mode) {
+void OSystem_SDL_Common::init_intern() {
int joystick_num = ConfMan.getInt("joystick_num");
uint32 sdlFlags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER;
- cksum_valid = false;
- _mode = gfx_mode;
- _full_screen = ConfMan.getBool("fullscreen");
- _adjustAspectRatio = ConfMan.getBool("aspect_ratio");
- _mode_flags = 0;
-
if (joystick_num > -1)
sdlFlags |= SDL_INIT_JOYSTICK;
@@ -84,6 +78,13 @@ void OSystem_SDL_Common::init_intern(int gfx_mode) {
// Enable unicode support if possible
SDL_EnableUNICODE(1);
+ cksum_valid = false;
+ _mode = GFX_DOUBLESIZE;
+ _full_screen = ConfMan.getBool("fullscreen");
+ _adjustAspectRatio = ConfMan.getBool("aspect_ratio");
+ _mode_flags = 0;
+
+
#ifndef MACOSX // Don't set icon on OS X, as we use a nicer external icon there
// Setup the icon
setup_icon();
@@ -133,7 +134,7 @@ OSystem_SDL_Common::~OSystem_SDL_Common() {
SDL_Quit();
}
-void OSystem_SDL_Common::init_size(uint w, uint h) {
+void OSystem_SDL_Common::initSize(uint w, uint h) {
// Avoid redundant res changes
if ((int)w == _screenWidth && (int)h == _screenHeight)
return;
@@ -622,7 +623,7 @@ bool OSystem_SDL_Common::poll_event(Event *event) {
// Alt-Return toggles full screen mode
if (b == KBD_ALT && ev.key.keysym.sym == SDLK_RETURN) {
- property(PROP_TOGGLE_FULLSCREEN, NULL);
+ setFeatureState(kFeatureFullscreenMode, !_full_screen);
break;
}
@@ -654,7 +655,7 @@ bool OSystem_SDL_Common::poll_event(Event *event) {
#else
// Ctrl-m toggles mouse capture
if (b == KBD_CTRL && ev.key.keysym.sym == 'm') {
- property(PROP_TOGGLE_MOUSE_GRAB, NULL);
+ toggleMouseGrab();
break;
}
@@ -695,13 +696,11 @@ bool OSystem_SDL_Common::poll_event(Event *event) {
}
}
-
- Property prop;
int factor = _scaleFactor - 1;
// Ctrl-Alt-a toggles aspect ratio correction
if (ev.key.keysym.sym == 'a') {
- property(PROP_TOGGLE_ASPECT_RATIO, NULL);
+ setFeatureState(kFeatureAspectRatioCorrection, !_adjustAspectRatio);
break;
}
@@ -710,8 +709,7 @@ bool OSystem_SDL_Common::poll_event(Event *event) {
if (ev.key.keysym.sym == '=' || ev.key.keysym.sym == '+' || ev.key.keysym.sym == '-') {
factor += (ev.key.keysym.sym == '-' ? -1 : +1);
if (0 <= factor && factor < 4 && gfxModes[_scalerType][factor] >= 0) {
- prop.gfx_mode = gfxModes[_scalerType][factor];
- property(PROP_SET_GFX_MODE, &prop);
+ setGraphicsMode(gfxModes[_scalerType][factor]);
}
break;
}
@@ -725,8 +723,7 @@ bool OSystem_SDL_Common::poll_event(Event *event) {
assert(factor > 0);
factor--;
}
- prop.gfx_mode = gfxModes[_scalerType][factor];
- property(PROP_SET_GFX_MODE, &prop);
+ setGraphicsMode(gfxModes[_scalerType][factor]);
break;
}
}
@@ -1014,12 +1011,11 @@ bool OSystem_SDL_Common::poll_event(Event *event) {
return false;
}
-bool OSystem_SDL_Common::set_sound_proc(SoundProc proc, void *param, SoundFormat format) {
+bool OSystem_SDL_Common::setSoundCallback(SoundProc proc, void *param) {
SDL_AudioSpec desired;
memset(&desired, 0, sizeof(desired));
- /* only one format supported at the moment */
desired.freq = SAMPLES_PER_SEC;
desired.format = AUDIO_S16SYS;
desired.channels = 2;
@@ -1033,55 +1029,140 @@ bool OSystem_SDL_Common::set_sound_proc(SoundProc proc, void *param, SoundFormat
return true;
}
-void OSystem_SDL_Common::clear_sound_proc() {
+void OSystem_SDL_Common::clearSoundCallback() {
SDL_CloseAudio();
}
-uint32 OSystem_SDL_Common::property(int param, Property *value) {
- switch(param) {
+static const OSystem::GraphicsMode gfx_modes[] = {
+ {"1x", "Normal (no scaling)", GFX_NORMAL},
+ {"2x", "2x", GFX_DOUBLESIZE},
+ {"3x", "3x", GFX_TRIPLESIZE},
+ {"2xsai", "2xSAI", GFX_2XSAI},
+ {"super2xsai", "Super2xSAI", GFX_SUPER2XSAI},
+ {"supereagle", "SuperEagle", GFX_SUPEREAGLE},
+ {"advmame2x", "AdvMAME2x", GFX_ADVMAME2X},
+ {"advmame3x", "AdvMAME3x", GFX_ADVMAME3X},
+ {"hq2x", "HQ2x", GFX_HQ2X},
+ {"hq3x", "HQ3x", GFX_HQ3X},
+ {"tv2x", "TV2x", GFX_TV2X},
+ {"dotmatrix", "DotMatrix", GFX_DOTMATRIX},
+ {0, 0, 0}
+};
+
+const OSystem::GraphicsMode *OSystem_SDL_Common::getSupportedGraphicsModes() const {
+ return gfx_modes;
+}
- case PROP_WANT_RECT_OPTIM:
- _mode_flags |= DF_WANT_RECT_OPTIM;
- break;
+bool OSystem_SDL_Common::setGraphicsMode(int mode) {
+ Common::StackLock lock(_graphicsMutex, this);
- case PROP_GET_FULLSCREEN:
- return _full_screen;
+ // FIXME! HACK, hard coded threshold, not good
+ // Really should check the 'mode' against the list of supported
+ // modes, and then decide whether to accept it.
+ if (mode > 11)
+ return false;
- case PROP_GET_GFX_MODE:
- return _mode;
-
- case PROP_SET_WINDOW_CAPTION:
- SDL_WM_SetCaption(value->caption, value->caption);
- return 1;
-
- case PROP_OPEN_CD:
- if (SDL_InitSubSystem(SDL_INIT_CDROM) == -1)
- _cdrom = NULL;
- else {
- _cdrom = SDL_CDOpen(value->cd_num);
- // Did it open? Check if _cdrom is NULL
- if (!_cdrom) {
- warning("Couldn't open drive: %s", SDL_GetError());
- } else {
- cd_num_loops = 0;
- cd_stop_time = 0;
- cd_end_time = 0;
- }
+ _mode = mode;
+ hotswap_gfx_mode();
+ return true;
+}
+
+int OSystem_SDL_Common::getGraphicsMode() const {
+ return _mode;
+}
+
+
+void OSystem_SDL_Common::setWindowCaption(const char *caption) {
+ SDL_WM_SetCaption(caption, caption);
+}
+
+bool OSystem_SDL_Common::openCD(int drive) {
+ if (SDL_InitSubSystem(SDL_INIT_CDROM) == -1)
+ _cdrom = NULL;
+ else {
+ _cdrom = SDL_CDOpen(drive);
+ // Did it open? Check if _cdrom is NULL
+ if (!_cdrom) {
+ warning("Couldn't open drive: %s", SDL_GetError());
+ } else {
+ cd_num_loops = 0;
+ cd_stop_time = 0;
+ cd_end_time = 0;
}
- break;
+ }
+
+ return (_cdrom != NULL);
+}
+
+int OSystem_SDL_Common::getOutputSampleRate() const {
+ return SAMPLES_PER_SEC;
+}
- case PROP_GET_SAMPLE_RATE:
- return SAMPLES_PER_SEC;
- case PROP_TOGGLE_MOUSE_GRAB:
- if (SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_OFF)
- SDL_WM_GrabInput(SDL_GRAB_ON);
+bool OSystem_SDL_Common::hasFeature(Feature f) {
+ return
+ (f == kFeatureFullscreenMode) ||
+ (f == kFeatureAspectRatioCorrection) ||
+ (f == kFeatureAutoComputeDirtyRects);
+}
+
+void OSystem_SDL_Common::setFeatureState(Feature f, bool enable) {
+ Common::StackLock lock(_graphicsMutex, this);
+
+ switch (f) {
+ case kFeatureFullscreenMode:
+ if (_full_screen != enable) {
+ //assert(_hwscreen != 0);
+ _full_screen ^= true;
+#ifdef MACOSX
+ // On OS X, SDL_WM_ToggleFullScreen is currently not implemented. Worse,
+ // it still always returns -1. So we simply don't call it at all and
+ // use hotswap_gfx_mode() directly to switch to fullscreen mode.
+ hotswap_gfx_mode();
+#else
+ if (!SDL_WM_ToggleFullScreen(_hwscreen)) {
+ // if ToggleFullScreen fails, achieve the same effect with hotswap gfx mode
+ hotswap_gfx_mode();
+ }
+#endif
+ }
+ break;
+ case kFeatureAspectRatioCorrection:
+ if (_screenHeight == 200 && _adjustAspectRatio != enable) {
+ //assert(_hwscreen != 0);
+ _adjustAspectRatio ^= true;
+ hotswap_gfx_mode();
+ }
+ break;
+ case kFeatureAutoComputeDirtyRects:
+ if (enable)
+ _mode_flags |= DF_WANT_RECT_OPTIM;
else
- SDL_WM_GrabInput(SDL_GRAB_OFF);
+ _mode_flags &= ~DF_WANT_RECT_OPTIM;
+ break;
+ default:
break;
}
+}
- return 0;
+bool OSystem_SDL_Common::getFeatureState(Feature f) {
+ switch (f) {
+ case kFeatureFullscreenMode:
+ return _full_screen;
+ case kFeatureAspectRatioCorrection:
+ return _adjustAspectRatio;
+ case kFeatureAutoComputeDirtyRects:
+ return _mode_flags & DF_WANT_RECT_OPTIM;
+ default:
+ return false;
+ }
+}
+
+void OSystem_SDL_Common::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 OSystem_SDL_Common::quit() {
diff --git a/backends/sdl/sdl-common.h b/backends/sdl/sdl-common.h
index 3d47ca582e..cdd5b0c1de 100644
--- a/backends/sdl/sdl-common.h
+++ b/backends/sdl/sdl-common.h
@@ -33,7 +33,7 @@ class OSystem_SDL_Common : public OSystem {
public:
// Set the size of the video bitmap.
// Typically, 320x200
- void init_size(uint w, uint h);
+ void initSize(uint w, uint h);
// Set colors of the palette
void set_palette(const byte *colors, uint start, uint num);
@@ -72,9 +72,9 @@ public:
bool poll_event(Event *event);
// Set function that generates samples
- bool set_sound_proc(SoundProc proc, void *param, SoundFormat format);
+ bool setSoundCallback(SoundProc proc, void *param);
- void clear_sound_proc();
+ void clearSoundCallback();
// Poll CD status
// Returns true if cd audio is playing
@@ -92,8 +92,6 @@ public:
// Quit
void quit();
- // Set a parameter
- uint32 property(int param, Property *value);
// Add a callback timer
void set_timer(TimerProc callback, int timer);
@@ -117,7 +115,21 @@ public:
virtual int16 RGBToColor(uint8 r, uint8 g, uint8 b);
virtual void colorToRGB(int16 color, uint8 &r, uint8 &g, uint8 &b);
- static OSystem *create(int gfx_mode);
+
+ virtual const GraphicsMode *getSupportedGraphicsModes() const;
+ virtual bool setGraphicsMode(int mode);
+ virtual int getGraphicsMode() const;
+
+ virtual void setWindowCaption(const char *caption);
+ virtual bool openCD(int drive);
+ virtual int getOutputSampleRate() const;
+
+ virtual bool hasFeature(Feature f);
+ virtual void setFeatureState(Feature f, bool enable);
+ virtual bool getFeatureState(Feature f);
+
+
+ static OSystem *create();
protected:
OSystem_SDL_Common();
@@ -125,7 +137,7 @@ protected:
static OSystem_SDL_Common *create_intern();
- void init_intern(int gfx_mode);
+ void init_intern();
// unseen game screen
SDL_Surface *_screen;
@@ -218,10 +230,12 @@ protected:
/** Set the position of the virtual mouse cursor. */
void set_mouse_pos(int x, int y);
void fillMouseEvent(Event &event, int x, int y);
+ void toggleMouseGrab();
virtual void load_gfx_mode() = 0;
virtual void unload_gfx_mode() = 0;
+ virtual void hotswap_gfx_mode() = 0;
virtual bool save_screenshot(const char *filename) = 0;
diff --git a/backends/sdl/sdl.cpp b/backends/sdl/sdl.cpp
index 456ed2c5bf..384af1673c 100644
--- a/backends/sdl/sdl.cpp
+++ b/backends/sdl/sdl.cpp
@@ -31,9 +31,6 @@ public:
// Update the dirty areas of the screen
void update_screen();
- // Set a parameter
- uint32 property(int param, Property *value);
-
protected:
SDL_Surface *_hwscreen; // hardware screen
@@ -42,7 +39,7 @@ protected:
virtual void load_gfx_mode();
virtual void unload_gfx_mode();
virtual bool save_screenshot(const char *filename);
- void hotswap_gfx_mode();
+ virtual void hotswap_gfx_mode();
};
OSystem_SDL_Common *OSystem_SDL_Common::create_intern() {
@@ -363,48 +360,6 @@ void OSystem_SDL::update_screen() {
_forceFull = false;
}
-uint32 OSystem_SDL::property(int param, Property *value) {
-
- Common::StackLock lock(_graphicsMutex, this); // Lock the mutex until this function ends
-
- if (param == PROP_TOGGLE_FULLSCREEN) {
- assert(_hwscreen != 0);
- _full_screen ^= true;
-#ifdef MACOSX
- // On OS X, SDL_WM_ToggleFullScreen is currently not implemented. Worse,
- // it still always returns -1. So we simply don't call it at all and
- // use hotswap_gfx_mode() directly to switch to fullscreen mode.
- hotswap_gfx_mode();
-#else
- if (!SDL_WM_ToggleFullScreen(_hwscreen)) {
- // if ToggleFullScreen fails, achieve the same effect with hotswap gfx mode
- hotswap_gfx_mode();
- }
-#endif
- return 1;
- } else if (param == PROP_SET_GFX_MODE) {
- if (value->gfx_mode > 11) // FIXME! HACK, hard coded threshold, not good
- return 0;
-
- _mode = value->gfx_mode;
- hotswap_gfx_mode();
-
- return 1;
- } else if (param == PROP_TOGGLE_ASPECT_RATIO) {
- if (_screenHeight == 200) {
- assert(_hwscreen != 0);
- _adjustAspectRatio ^= true;
- hotswap_gfx_mode();
- }
- } else if (param == PROP_HAS_SCALER) {
- if (value->gfx_mode <= 11) // FIXME: Hardcoded
- return 1;
- return 0;
- }
-
- return OSystem_SDL_Common::property(param, value);
-}
-
bool OSystem_SDL::save_screenshot(const char *filename) {
assert(_hwscreen != NULL);