diff options
| -rw-r--r-- | backends/sdl/sdl-common.cpp | 48 | ||||
| -rw-r--r-- | backends/sdl/sdl-common.h | 15 | ||||
| -rw-r--r-- | backends/sdl/sdl_gl.cpp | 41 | 
3 files changed, 57 insertions, 47 deletions
| diff --git a/backends/sdl/sdl-common.cpp b/backends/sdl/sdl-common.cpp index 90f1cfe45a..d74a4a2ede 100644 --- a/backends/sdl/sdl-common.cpp +++ b/backends/sdl/sdl-common.cpp @@ -529,6 +529,30 @@ static int mapKey(SDLKey key, SDLMod mod, Uint16 unicode)  	return key;  } +void OSystem_SDL_Common::fillMouseEvent(Event &event, int x, int y) { +	event.mouse.x = x; +	event.mouse.y = y; +	 +	// FIXME: HACK HACK HACK. This works around an odd problem in the OpenGL +	// variant of the SDL backend, where the mouse y coordinates are reversed. +	// Since the OpenGL variants is quite hackish anyway, we have to hard code +	// here a screen height of 480). +	if (_mode_flags & DF_REVERSE_Y) +		event.mouse.y = 480 - event.mouse.y; +	 +	// Update the "keyboard mouse" coords +	km.x = event.mouse.x; +	km.y = event.mouse.y; + +	// Adjust for the screen scaling +	event.mouse.x /= _scaleFactor; +	event.mouse.y /= _scaleFactor; + +	// Optionally perform aspect ratio adjusting +	if (_adjustAspectRatio) +		event.mouse.y = aspect2Real(event.mouse.y); +} +  bool OSystem_SDL_Common::poll_event(Event *event) {  	SDL_Event ev;  	int axis; @@ -722,14 +746,7 @@ bool OSystem_SDL_Common::poll_event(Event *event) {  		case SDL_MOUSEMOTION:  			event->event_code = EVENT_MOUSEMOVE; -			km.x = event->mouse.x = ev.motion.x; -			km.y = event->mouse.y = ev.motion.y; - -			event->mouse.x /= _scaleFactor; -			event->mouse.y /= _scaleFactor; - -			if (_adjustAspectRatio) -				event->mouse.y = aspect2Real(event->mouse.y); +			fillMouseEvent(*event, ev.motion.x, ev.motion.y);  			set_mouse_pos(event->mouse.x, event->mouse.y);  			return true; @@ -747,13 +764,8 @@ bool OSystem_SDL_Common::poll_event(Event *event) {  #endif  			else  				break; -			km.x = event->mouse.x = ev.button.x; -			km.y = event->mouse.y = ev.button.y; -			event->mouse.x /= _scaleFactor; -			event->mouse.y /= _scaleFactor; -			if (_adjustAspectRatio) -				event->mouse.y = aspect2Real(event->mouse.y); +			fillMouseEvent(*event, ev.button.x, ev.button.y);  			return true; @@ -764,13 +776,7 @@ bool OSystem_SDL_Common::poll_event(Event *event) {  				event->event_code = EVENT_RBUTTONUP;  			else  				break; -			event->mouse.x = ev.button.x; -			event->mouse.y = ev.button.y; -			event->mouse.x /= _scaleFactor; -			event->mouse.y /= _scaleFactor; - -			if (_adjustAspectRatio) -				event->mouse.y = aspect2Real(event->mouse.y); +			fillMouseEvent(*event, ev.button.x, ev.button.y);  			return true; diff --git a/backends/sdl/sdl-common.h b/backends/sdl/sdl-common.h index 439e52124b..a36ea2dbff 100644 --- a/backends/sdl/sdl-common.h +++ b/backends/sdl/sdl-common.h @@ -149,7 +149,8 @@ protected:  	enum {  		DF_WANT_RECT_OPTIM			= 1 << 0, -		DF_UPDATE_EXPAND_1_PIXEL	= 1 << 3 +		DF_UPDATE_EXPAND_1_PIXEL	= 1 << 1, +		DF_REVERSE_Y				= 1 << 2  	};  	bool _forceFull; // Force full redraw on next update_screen @@ -185,9 +186,7 @@ protected:  		MousePos() : x(0), y(0), w(0), h(0) {}  	}; -	// joystick -	SDL_Joystick *_joystick; - +	// mouse  	bool _mouseVisible;  	bool _mouseDrawn;  	const byte *_mouseData; @@ -197,6 +196,9 @@ protected:  	int16 _mouseHotspotX;  	int16 _mouseHotspotY; +	// joystick +	SDL_Joystick *_joystick; +  	// Shake mode  	int _currentShakePos;  	int _newShakePos; @@ -213,20 +215,21 @@ protected:  	void add_dirty_rgn_auto(const byte *buf);  	void mk_checksums(const byte *buf); -	static void fill_sound(void *userdata, Uint8 * stream, int len); -	  	void add_dirty_rect(int x, int y, int w, int h);  	virtual void draw_mouse();  	virtual void undraw_mouse();  	/** Set the position of the virtual mouse cursor. */  	void set_mouse_pos(int x, int y); +	void fillMouseEvent(Event &event, int x, int y);  	virtual void load_gfx_mode() = 0;  	virtual void unload_gfx_mode() = 0;  	virtual bool save_screenshot(const char *filename) = 0; +	 +	virtual int effectiveScreenHeight() { return (_adjustAspectRatio ? 240 : _screenHeight) * _scaleFactor; }  	void setup_icon();  	void kbd_mouse(); diff --git a/backends/sdl/sdl_gl.cpp b/backends/sdl/sdl_gl.cpp index 35c398ead5..33dbd76dd2 100644 --- a/backends/sdl/sdl_gl.cpp +++ b/backends/sdl/sdl_gl.cpp @@ -102,8 +102,23 @@ void OSystem_SDL_OpenGL::load_gfx_mode() {  	switch(_mode) {  	case GFX_BILINEAR:  		_usingOpenGL = true; +		_mode_flags |= DF_REVERSE_Y;  		_mode = GFX_NORMAL;  		break; + +	case GFX_NORMAL: +		_scaleFactor = 1; +		_scaler_proc = Normal1x; +		break; +	case GFX_DOUBLESIZE: +		_scaleFactor = 2; +		_scaler_proc = Normal2x; +		break; +	case GFX_TRIPLESIZE: +		_scaleFactor = 3; +		_scaler_proc = Normal3x; +		break; +  	case GFX_2XSAI:  		_scaleFactor = 2;  		_scaler_proc = _2xSaI; @@ -132,31 +147,16 @@ void OSystem_SDL_OpenGL::load_gfx_mode() {  		_scaleFactor = 2;  		_scaler_proc = DotMatrix;  		break; -	case GFX_DOUBLESIZE: -		_scaleFactor = 2; -		_scaler_proc = Normal2x; -		break; -	case GFX_TRIPLESIZE: -		_scaleFactor = 3; -		_scaler_proc = Normal3x; -		break; - -	case GFX_NORMAL: -		_scaleFactor = 1; //_usingOpenGL ? 2 : 1; -		_scaler_proc = Normal1x; -		break;  	default:  		error("unknown gfx mode %d", _mode); -		_mode = GFX_NORMAL; -		_scaleFactor = 1; -		_scaler_proc = Normal1x;  	} - +	  	if (_mode != GFX_NORMAL) { -	  _usingOpenGL = false; +		_usingOpenGL = false; +		_mode_flags &= ~DF_REVERSE_Y;  	} -   +  	//  	// Create the surface that contains the 8 bit game data  	// @@ -630,11 +630,11 @@ uint32 OSystem_SDL_OpenGL::property(int param, Property *value) {  		}  	} else if (param == PROP_SET_GFX_MODE) { -  		if (value->gfx_mode > 10) { // OpenGL modes  			if (!_usingOpenGL) {  				_usingOpenGL = true;  				_mode = GFX_NORMAL; +				_mode_flags |= DF_REVERSE_Y;  				_scaleFactor = 1;  				_scaler_proc = Normal1x;  				hotswap_gfx_mode(); @@ -655,6 +655,7 @@ uint32 OSystem_SDL_OpenGL::property(int param, Property *value) {  				if (_usingOpenGL) {  					_glBilinearFilter = false;  					_usingOpenGL = false; +					_mode_flags &= ~DF_REVERSE_Y;  				}  				hotswap_gfx_mode(); | 
