2002-04-21 17:46:42 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
|
|
|
* Copyright (C) 2001 Ludvig Strigeus
|
|
|
|
* Copyright (C) 2001/2002 The ScummVM project
|
|
|
|
*
|
|
|
|
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* $Header$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2002-08-24 10:41:32 +00:00
|
|
|
#include "sdl-common.h"
|
2002-09-08 01:08:12 +00:00
|
|
|
#include "common/scaler.h"
|
2002-09-19 17:03:24 +00:00
|
|
|
#include "common/util.h"
|
2002-09-08 01:08:12 +00:00
|
|
|
#include "common/engine.h" // Only #included for error() and warning()
|
2001-11-05 19:21:49 +00:00
|
|
|
|
2002-08-24 10:41:32 +00:00
|
|
|
class OSystem_SDL_Normal : public OSystem_SDL_Common {
|
2002-04-12 21:26:59 +00:00
|
|
|
public:
|
2002-11-13 14:38:49 +00:00
|
|
|
OSystem_SDL_Normal();
|
2002-09-27 13:05:54 +00:00
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
// Set colors of the palette
|
|
|
|
void set_palette(const byte *colors, uint start, uint num);
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
// Update the dirty areas of the screen
|
|
|
|
void update_screen();
|
2002-03-09 13:48:02 +00:00
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
// Set a parameter
|
2002-05-04 09:55:10 +00:00
|
|
|
uint32 property(int param, Property *value);
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2002-09-19 16:06:51 +00:00
|
|
|
// Overlay
|
|
|
|
virtual void show_overlay();
|
|
|
|
virtual void hide_overlay();
|
|
|
|
virtual void clear_overlay();
|
|
|
|
virtual void grab_overlay(int16 *buf, int pitch);
|
|
|
|
virtual void copy_rect_overlay(const int16 *buf, int pitch, int x, int y, int w, int h);
|
|
|
|
|
2002-12-13 16:15:58 +00:00
|
|
|
// Methods that convert RBG to/from colors suitable for the overlay.
|
|
|
|
virtual int16 RBGToColor(uint8 r, uint8 g, uint8 b);
|
|
|
|
virtual void colorToRBG(int16 color, uint8 &r, uint8 &g, uint8 &b);
|
|
|
|
|
2002-08-24 10:41:32 +00:00
|
|
|
protected:
|
2002-09-19 16:06:51 +00:00
|
|
|
typedef void ScalerProc(uint8 *srcPtr, uint32 srcPitch, uint8 *deltaPtr,
|
|
|
|
uint8 *dstPtr, uint32 dstPitch, int width, int height);
|
|
|
|
|
2002-11-23 00:13:52 +00:00
|
|
|
SDL_Surface *_tmpscreen; // temporary screen (for scalers/overlay)
|
|
|
|
SDL_Surface *_hwscreen; // hardware screen
|
2002-09-19 16:06:51 +00:00
|
|
|
bool _overlay_visible;
|
2002-03-10 07:48:01 +00:00
|
|
|
|
2002-09-19 16:06:51 +00:00
|
|
|
ScalerProc *_scaler_proc;
|
|
|
|
|
2002-11-13 14:38:49 +00:00
|
|
|
int TMP_SCREEN_WIDTH;
|
|
|
|
|
2002-09-19 16:06:51 +00:00
|
|
|
virtual void draw_mouse();
|
|
|
|
virtual void undraw_mouse();
|
|
|
|
|
|
|
|
virtual void load_gfx_mode();
|
|
|
|
virtual void unload_gfx_mode();
|
2002-04-13 12:43:02 +00:00
|
|
|
void hotswap_gfx_mode();
|
2002-04-12 21:26:59 +00:00
|
|
|
};
|
2002-03-10 07:48:01 +00:00
|
|
|
|
2002-08-24 10:41:32 +00:00
|
|
|
OSystem_SDL_Common *OSystem_SDL_Common::create() {
|
|
|
|
return new OSystem_SDL_Normal();
|
2002-03-10 07:48:01 +00:00
|
|
|
}
|
|
|
|
|
2002-11-13 14:38:49 +00:00
|
|
|
OSystem_SDL_Normal::OSystem_SDL_Normal()
|
2002-11-23 00:13:52 +00:00
|
|
|
: _tmpscreen(0), _hwscreen(0), _overlay_visible(false),
|
2002-11-13 14:38:49 +00:00
|
|
|
_scaler_proc(0), TMP_SCREEN_WIDTH(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-08-24 10:41:32 +00:00
|
|
|
void OSystem_SDL_Normal::set_palette(const byte *colors, uint start, uint num) {
|
2002-04-12 21:26:59 +00:00
|
|
|
const byte *b = colors;
|
|
|
|
uint i;
|
2002-09-28 16:19:28 +00:00
|
|
|
SDL_Color *base = _currentPalette + start;
|
2002-09-19 16:06:51 +00:00
|
|
|
for(i = 0; i < num; i++) {
|
2002-06-14 04:31:17 +00:00
|
|
|
base[i].r = b[0];
|
|
|
|
base[i].g = b[1];
|
|
|
|
base[i].b = b[2];
|
|
|
|
b += 4;
|
2002-03-10 07:48:01 +00:00
|
|
|
}
|
|
|
|
|
2002-09-28 16:19:28 +00:00
|
|
|
if (start < _paletteDirtyStart)
|
|
|
|
_paletteDirtyStart = start;
|
2002-04-15 17:45:52 +00:00
|
|
|
|
2002-09-28 16:19:28 +00:00
|
|
|
if (start + num > _paletteDirtyEnd)
|
|
|
|
_paletteDirtyEnd = start + num;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
2002-03-10 07:48:01 +00:00
|
|
|
|
2002-09-19 16:06:51 +00:00
|
|
|
void OSystem_SDL_Normal::draw_mouse() {
|
|
|
|
if (!_overlay_visible) {
|
|
|
|
OSystem_SDL_Common::draw_mouse();
|
|
|
|
}
|
|
|
|
|
2002-09-28 16:19:28 +00:00
|
|
|
if (_mouseDrawn || !_mouseVisible)
|
2002-09-19 16:06:51 +00:00
|
|
|
return;
|
|
|
|
|
2002-11-13 14:38:49 +00:00
|
|
|
int x = _mouseCurState.x - _mouseHotspotX;
|
|
|
|
int y = _mouseCurState.y - _mouseHotspotY;
|
|
|
|
int w = _mouseCurState.w;
|
|
|
|
int h = _mouseCurState.h;
|
2002-09-19 16:06:51 +00:00
|
|
|
byte color;
|
2002-09-28 16:19:28 +00:00
|
|
|
byte *src = _mouseData; // Image representing the mouse
|
|
|
|
uint16 *bak = (uint16*)_mouseBackup; // Surface used to backup the area obscured by the mouse
|
2002-09-19 16:06:51 +00:00
|
|
|
uint16 *dst; // Surface we are drawing into
|
|
|
|
|
|
|
|
// clip the mouse rect, and addjust the src pointer accordingly
|
|
|
|
if (x < 0) {
|
|
|
|
w += x;
|
|
|
|
src -= x;
|
|
|
|
x = 0;
|
|
|
|
}
|
|
|
|
if (y < 0) {
|
|
|
|
h += y;
|
2002-11-13 14:38:49 +00:00
|
|
|
src -= y * _mouseCurState.w;
|
2002-09-19 16:06:51 +00:00
|
|
|
y = 0;
|
|
|
|
}
|
|
|
|
|
2002-09-28 16:19:28 +00:00
|
|
|
// Quick check to see if anything has to be drawn at all
|
|
|
|
if (w <= 0 || h <= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (w > _screenWidth - x)
|
|
|
|
w = _screenWidth - x;
|
|
|
|
if (h > _screenHeight - y)
|
|
|
|
h = _screenHeight - y;
|
2002-09-19 16:06:51 +00:00
|
|
|
|
|
|
|
// Store the bounding box so that undraw mouse can restore the area the
|
|
|
|
// mouse currently covers to its original content.
|
2002-11-13 14:38:49 +00:00
|
|
|
_mouseOldState.x = x;
|
|
|
|
_mouseOldState.y = y;
|
|
|
|
_mouseOldState.w = w;
|
|
|
|
_mouseOldState.h = h;
|
2002-09-19 16:06:51 +00:00
|
|
|
|
|
|
|
// Draw the mouse cursor; backup the covered area in "bak"
|
|
|
|
|
2002-11-23 00:13:52 +00:00
|
|
|
if (SDL_LockSurface(_tmpscreen) == -1)
|
2002-09-19 16:06:51 +00:00
|
|
|
error("SDL_LockSurface failed: %s.\n", SDL_GetError());
|
|
|
|
|
2002-10-21 22:25:52 +00:00
|
|
|
// Mark as dirty
|
|
|
|
add_dirty_rect(x, y, w, h);
|
|
|
|
|
2002-11-23 00:13:52 +00:00
|
|
|
dst = (uint16 *)_tmpscreen->pixels + (y+1) * TMP_SCREEN_WIDTH + (x+1);
|
2002-09-19 16:06:51 +00:00
|
|
|
while (h > 0) {
|
|
|
|
int width = w;
|
|
|
|
while (width > 0) {
|
|
|
|
*bak++ = *dst;
|
|
|
|
color = *src++;
|
|
|
|
if (color != 0xFF) // 0xFF = transparent, don't draw
|
2002-12-13 16:15:58 +00:00
|
|
|
*dst = RBGToColor(_currentPalette[color].r, _currentPalette[color].g, _currentPalette[color].b);
|
2002-09-19 16:06:51 +00:00
|
|
|
dst++;
|
|
|
|
width--;
|
|
|
|
}
|
2002-11-13 14:38:49 +00:00
|
|
|
src += _mouseCurState.w - w;
|
2002-09-19 16:06:51 +00:00
|
|
|
bak += MAX_MOUSE_W - w;
|
|
|
|
dst += TMP_SCREEN_WIDTH - w;
|
|
|
|
h--;
|
|
|
|
}
|
|
|
|
|
2002-11-23 00:13:52 +00:00
|
|
|
SDL_UnlockSurface(_tmpscreen);
|
2002-09-19 16:06:51 +00:00
|
|
|
|
|
|
|
// Finally, set the flag to indicate the mouse has been drawn
|
2002-09-28 16:19:28 +00:00
|
|
|
_mouseDrawn = true;
|
2002-09-19 16:06:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OSystem_SDL_Normal::undraw_mouse() {
|
|
|
|
if (!_overlay_visible) {
|
|
|
|
OSystem_SDL_Common::undraw_mouse();
|
|
|
|
}
|
|
|
|
|
2002-09-28 16:19:28 +00:00
|
|
|
if (!_mouseDrawn)
|
2002-09-19 16:06:51 +00:00
|
|
|
return;
|
2002-09-28 16:19:28 +00:00
|
|
|
_mouseDrawn = false;
|
2002-09-19 16:06:51 +00:00
|
|
|
|
2002-11-23 00:13:52 +00:00
|
|
|
if (SDL_LockSurface(_tmpscreen) == -1)
|
2002-09-28 16:19:28 +00:00
|
|
|
error("SDL_LockSurface failed: %s.\n", SDL_GetError());
|
|
|
|
|
|
|
|
uint16 *dst, *bak = (uint16 *)_mouseBackup;
|
2002-11-13 14:38:49 +00:00
|
|
|
const int old_mouse_x = _mouseOldState.x;
|
|
|
|
const int old_mouse_y = _mouseOldState.y;
|
|
|
|
const int old_mouse_w = _mouseOldState.w;
|
|
|
|
const int old_mouse_h = _mouseOldState.h;
|
2002-09-28 16:19:28 +00:00
|
|
|
int x, y;
|
2002-09-19 16:06:51 +00:00
|
|
|
|
|
|
|
// No need to do clipping here, since draw_mouse() did that already
|
|
|
|
|
2002-11-23 00:13:52 +00:00
|
|
|
dst = (uint16 *)_tmpscreen->pixels + (old_mouse_y+1) * TMP_SCREEN_WIDTH + (old_mouse_x+1);
|
2002-09-19 16:06:51 +00:00
|
|
|
for (y = 0; y < old_mouse_h; ++y, bak += MAX_MOUSE_W, dst += TMP_SCREEN_WIDTH) {
|
|
|
|
for (x = 0; x < old_mouse_w; ++x) {
|
|
|
|
dst[x] = bak[x];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-28 16:19:28 +00:00
|
|
|
add_dirty_rect(old_mouse_x, old_mouse_y, old_mouse_w, old_mouse_h);
|
2002-09-19 16:06:51 +00:00
|
|
|
|
2002-11-23 00:13:52 +00:00
|
|
|
SDL_UnlockSurface(_tmpscreen);
|
2002-09-19 16:06:51 +00:00
|
|
|
}
|
|
|
|
|
2002-08-24 10:41:32 +00:00
|
|
|
void OSystem_SDL_Normal::load_gfx_mode() {
|
2002-09-28 16:19:28 +00:00
|
|
|
_forceFull = true;
|
2002-10-14 11:02:27 +00:00
|
|
|
_mode_flags = DF_WANT_RECT_OPTIM | DF_UPDATE_EXPAND_1_PIXEL;
|
2002-04-13 12:43:02 +00:00
|
|
|
|
2002-11-23 00:13:52 +00:00
|
|
|
_tmpscreen = NULL;
|
2002-09-28 16:19:28 +00:00
|
|
|
TMP_SCREEN_WIDTH = (_screenWidth + 3);
|
2002-06-14 04:31:17 +00:00
|
|
|
|
2002-04-13 12:43:02 +00:00
|
|
|
switch(_mode) {
|
2002-04-12 21:26:59 +00:00
|
|
|
case GFX_2XSAI:
|
2002-09-28 16:19:28 +00:00
|
|
|
_scaleFactor = 2;
|
2002-09-19 16:06:51 +00:00
|
|
|
_scaler_proc = _2xSaI;
|
2002-04-13 04:39:04 +00:00
|
|
|
break;
|
2002-04-12 21:26:59 +00:00
|
|
|
case GFX_SUPER2XSAI:
|
2002-09-28 16:19:28 +00:00
|
|
|
_scaleFactor = 2;
|
2002-09-19 16:06:51 +00:00
|
|
|
_scaler_proc = Super2xSaI;
|
2002-04-13 04:39:04 +00:00
|
|
|
break;
|
2002-04-12 21:26:59 +00:00
|
|
|
case GFX_SUPEREAGLE:
|
2002-09-28 16:19:28 +00:00
|
|
|
_scaleFactor = 2;
|
2002-09-19 16:06:51 +00:00
|
|
|
_scaler_proc = SuperEagle;
|
2002-04-12 21:26:59 +00:00
|
|
|
break;
|
2002-04-24 07:42:29 +00:00
|
|
|
case GFX_ADVMAME2X:
|
2002-09-28 16:19:28 +00:00
|
|
|
_scaleFactor = 2;
|
2002-09-19 16:06:51 +00:00
|
|
|
_scaler_proc = AdvMame2x;
|
2002-04-24 07:42:29 +00:00
|
|
|
break;
|
2001-12-27 17:51:58 +00:00
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
case GFX_DOUBLESIZE:
|
2002-09-28 16:19:28 +00:00
|
|
|
_scaleFactor = 2;
|
2002-09-19 16:06:51 +00:00
|
|
|
_scaler_proc = Normal2x;
|
2002-04-12 21:26:59 +00:00
|
|
|
break;
|
2001-11-06 20:00:47 +00:00
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
case GFX_TRIPLESIZE:
|
2002-04-13 12:43:02 +00:00
|
|
|
if (_full_screen) {
|
|
|
|
warning("full screen in useless in triplesize mode, reverting to normal mode");
|
|
|
|
goto normal_mode;
|
|
|
|
}
|
2002-09-28 16:19:28 +00:00
|
|
|
_scaleFactor = 3;
|
2002-09-19 16:06:51 +00:00
|
|
|
_scaler_proc = Normal3x;
|
2002-04-13 12:43:02 +00:00
|
|
|
break;
|
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
case GFX_NORMAL:
|
2002-04-13 12:43:02 +00:00
|
|
|
normal_mode:;
|
2002-09-28 16:19:28 +00:00
|
|
|
_scaleFactor = 1;
|
2002-09-19 16:06:51 +00:00
|
|
|
_scaler_proc = Normal1x;
|
2002-04-12 21:26:59 +00:00
|
|
|
break;
|
2002-10-14 11:02:27 +00:00
|
|
|
default:
|
|
|
|
error("unknown gfx mode");
|
|
|
|
_scaleFactor = 1;
|
|
|
|
_scaler_proc = NULL;
|
2001-11-06 20:00:47 +00:00
|
|
|
}
|
2002-06-14 04:31:17 +00:00
|
|
|
|
2002-10-14 11:02:27 +00:00
|
|
|
//
|
|
|
|
// Create the surface that contains the 8 bit game data
|
|
|
|
//
|
2002-09-28 16:19:28 +00:00
|
|
|
_screen = SDL_CreateRGBSurface(SDL_SWSURFACE, _screenWidth, _screenHeight, 8, 0, 0, 0, 0);
|
|
|
|
if (_screen == NULL)
|
2002-10-14 11:02:27 +00:00
|
|
|
error("_screen failed");
|
2002-05-04 00:11:57 +00:00
|
|
|
|
2002-06-25 12:43:15 +00:00
|
|
|
|
2002-10-14 11:02:27 +00:00
|
|
|
//
|
|
|
|
// Create the surface that contains the scaled graphics in 16 bit mode
|
|
|
|
//
|
2002-11-23 00:13:52 +00:00
|
|
|
_hwscreen = SDL_SetVideoMode(_screenWidth * _scaleFactor, _screenHeight * _scaleFactor, 16,
|
2002-09-19 16:06:51 +00:00
|
|
|
_full_screen ? (SDL_FULLSCREEN|SDL_SWSURFACE) : SDL_SWSURFACE
|
|
|
|
);
|
2002-11-23 00:13:52 +00:00
|
|
|
if (_hwscreen == NULL)
|
|
|
|
error("_hwscreen failed");
|
2002-09-19 16:06:51 +00:00
|
|
|
|
2002-10-14 11:02:27 +00:00
|
|
|
//
|
|
|
|
// Create the surface used for the graphics in 16 bit before scaling, and also the overlay
|
|
|
|
//
|
|
|
|
|
|
|
|
// Distinguish 555 and 565 mode
|
2002-11-23 00:13:52 +00:00
|
|
|
if (_hwscreen->format->Rmask == 0x7C00)
|
2002-09-19 16:06:51 +00:00
|
|
|
Init_2xSaI(555);
|
|
|
|
else
|
|
|
|
Init_2xSaI(565);
|
2002-10-14 11:02:27 +00:00
|
|
|
|
|
|
|
// Need some extra bytes around when using 2xSaI
|
2002-11-23 00:13:52 +00:00
|
|
|
uint16 *tmp_screen = (uint16*)calloc(TMP_SCREEN_WIDTH*(_screenHeight+3), sizeof(uint16));
|
|
|
|
_tmpscreen = SDL_CreateRGBSurfaceFrom(tmp_screen,
|
2002-09-28 16:19:28 +00:00
|
|
|
TMP_SCREEN_WIDTH, _screenHeight + 3, 16, TMP_SCREEN_WIDTH*2,
|
2002-11-23 00:13:52 +00:00
|
|
|
_hwscreen->format->Rmask,
|
|
|
|
_hwscreen->format->Gmask,
|
|
|
|
_hwscreen->format->Bmask,
|
|
|
|
_hwscreen->format->Amask);
|
2002-09-19 16:06:51 +00:00
|
|
|
|
2002-11-23 00:13:52 +00:00
|
|
|
if (_tmpscreen == NULL)
|
|
|
|
error("_tmpscreen failed");
|
2002-09-19 16:06:51 +00:00
|
|
|
|
2002-06-25 12:43:15 +00:00
|
|
|
// keyboard cursor control, some other better place for it?
|
2002-09-28 16:19:28 +00:00
|
|
|
km.x_max = _screenWidth * _scaleFactor - 1;
|
|
|
|
km.y_max = _screenHeight * _scaleFactor - 1;
|
2002-07-16 11:09:28 +00:00
|
|
|
km.delay_time = 25;
|
|
|
|
km.last_time = 0;
|
2002-06-25 12:43:15 +00:00
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
2001-11-06 20:00:47 +00:00
|
|
|
|
2002-08-24 10:41:32 +00:00
|
|
|
void OSystem_SDL_Normal::unload_gfx_mode() {
|
2002-09-28 16:19:28 +00:00
|
|
|
if (_screen) {
|
|
|
|
SDL_FreeSurface(_screen);
|
|
|
|
_screen = NULL;
|
2002-08-24 10:41:32 +00:00
|
|
|
}
|
2001-11-06 20:00:47 +00:00
|
|
|
|
2002-11-23 00:13:52 +00:00
|
|
|
if (_hwscreen) {
|
|
|
|
SDL_FreeSurface(_hwscreen);
|
|
|
|
_hwscreen = NULL;
|
2002-08-24 10:41:32 +00:00
|
|
|
}
|
|
|
|
|
2002-11-23 00:13:52 +00:00
|
|
|
if (_tmpscreen) {
|
|
|
|
free(_tmpscreen->pixels);
|
|
|
|
SDL_FreeSurface(_tmpscreen);
|
|
|
|
_tmpscreen = NULL;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
2001-11-05 19:21:49 +00:00
|
|
|
}
|
|
|
|
|
2002-11-23 00:13:52 +00:00
|
|
|
void OSystem_SDL_Normal::hotswap_gfx_mode() {
|
|
|
|
|
|
|
|
|
|
|
|
// Keep around the old _screen & _tmpscreen so we can restore the screen data
|
|
|
|
// after the mode switch.
|
|
|
|
SDL_Surface *old_screen = _screen;
|
|
|
|
SDL_Surface *old_tmpscreen = _tmpscreen;
|
|
|
|
|
|
|
|
// Release the HW screen surface
|
|
|
|
SDL_FreeSurface(_hwscreen);
|
|
|
|
|
|
|
|
// Setup the new GFX mode
|
|
|
|
load_gfx_mode();
|
|
|
|
|
|
|
|
// reset palette
|
|
|
|
SDL_SetColors(_screen, _currentPalette, 0, 256);
|
|
|
|
|
|
|
|
// Restore old screen content
|
|
|
|
SDL_BlitSurface(old_screen, NULL, _screen, NULL);
|
|
|
|
SDL_BlitSurface(old_tmpscreen, NULL, _tmpscreen, NULL);
|
|
|
|
|
|
|
|
// Free the old surfaces
|
|
|
|
SDL_FreeSurface(old_screen);
|
|
|
|
free(old_tmpscreen->pixels);
|
|
|
|
SDL_FreeSurface(old_tmpscreen);
|
|
|
|
|
|
|
|
// Finally, blit everything to the screen
|
|
|
|
update_screen();
|
|
|
|
}
|
|
|
|
|
2002-08-24 10:41:32 +00:00
|
|
|
void OSystem_SDL_Normal::update_screen() {
|
2002-06-14 04:31:17 +00:00
|
|
|
|
2002-11-23 00:13:52 +00:00
|
|
|
assert(_hwscreen != NULL);
|
2002-09-29 18:19:57 +00:00
|
|
|
|
|
|
|
// If the shake position changed, fill the dirty area with blackness
|
|
|
|
if (_currentShakePos != _newShakePos) {
|
|
|
|
SDL_Rect blackrect = {0, 0, _screenWidth*_scaleFactor, _newShakePos*_scaleFactor};
|
2002-11-23 00:13:52 +00:00
|
|
|
SDL_FillRect(_hwscreen, &blackrect, 0);
|
2002-05-10 15:33:02 +00:00
|
|
|
|
2002-09-29 18:19:57 +00:00
|
|
|
_currentShakePos = _newShakePos;
|
|
|
|
|
|
|
|
_forceFull = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure the mouse is drawn, if it should be drawn.
|
2002-04-12 21:26:59 +00:00
|
|
|
draw_mouse();
|
|
|
|
|
2002-09-19 16:06:51 +00:00
|
|
|
// Check whether the palette was changed in the meantime and update the
|
|
|
|
// screen surface accordingly.
|
2002-09-28 16:19:28 +00:00
|
|
|
if (_paletteDirtyEnd != 0) {
|
|
|
|
SDL_SetColors(_screen, _currentPalette + _paletteDirtyStart,
|
|
|
|
_paletteDirtyStart,
|
|
|
|
_paletteDirtyEnd - _paletteDirtyStart);
|
2002-06-14 04:31:17 +00:00
|
|
|
|
2002-09-28 16:19:28 +00:00
|
|
|
_paletteDirtyEnd = 0;
|
2002-04-15 17:45:52 +00:00
|
|
|
|
2002-09-28 16:19:28 +00:00
|
|
|
_forceFull = true;
|
2002-04-15 17:45:52 +00:00
|
|
|
}
|
|
|
|
|
2002-09-19 16:06:51 +00:00
|
|
|
// Force a full redraw if requested
|
2002-09-28 16:19:28 +00:00
|
|
|
if (_forceFull) {
|
|
|
|
_num_dirty_rects = 1;
|
2002-05-04 00:11:57 +00:00
|
|
|
|
2002-09-27 13:05:54 +00:00
|
|
|
_dirty_rect_list[0].x = 0;
|
|
|
|
_dirty_rect_list[0].y = 0;
|
2002-09-28 16:19:28 +00:00
|
|
|
_dirty_rect_list[0].w = _screenWidth;
|
|
|
|
_dirty_rect_list[0].h = _screenHeight;
|
2002-05-04 00:11:57 +00:00
|
|
|
}
|
2002-04-15 17:45:52 +00:00
|
|
|
|
2002-09-19 16:06:51 +00:00
|
|
|
// Only draw anything if necessary
|
2002-09-28 16:19:28 +00:00
|
|
|
if (_num_dirty_rects > 0) {
|
2002-05-10 15:33:02 +00:00
|
|
|
|
|
|
|
SDL_Rect *r;
|
|
|
|
uint32 srcPitch, dstPitch;
|
2002-09-28 16:19:28 +00:00
|
|
|
SDL_Rect *last_rect = _dirty_rect_list + _num_dirty_rects;
|
2002-05-10 15:33:02 +00:00
|
|
|
|
2002-09-19 16:06:51 +00:00
|
|
|
// Convert appropriate parts of the 8bpp image into 16bpp
|
|
|
|
if (!_overlay_visible) {
|
2002-05-10 15:33:02 +00:00
|
|
|
SDL_Rect dst;
|
2002-09-28 16:19:28 +00:00
|
|
|
for(r = _dirty_rect_list; r != last_rect; ++r) {
|
2002-05-10 15:33:02 +00:00
|
|
|
dst = *r;
|
2002-09-19 16:06:51 +00:00
|
|
|
dst.x++; // Shift rect by one since 2xSai needs to acces the data around
|
|
|
|
dst.y++; // any pixel to scale it, and we want to avoid mem access crashes.
|
2002-11-23 00:13:52 +00:00
|
|
|
if (SDL_BlitSurface(_screen, r, _tmpscreen, &dst) != 0)
|
2002-05-10 15:33:02 +00:00
|
|
|
error("SDL_BlitSurface failed: %s", SDL_GetError());
|
2002-05-04 00:11:57 +00:00
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
2002-05-10 15:33:02 +00:00
|
|
|
|
2002-11-23 00:13:52 +00:00
|
|
|
SDL_LockSurface(_tmpscreen);
|
|
|
|
SDL_LockSurface(_hwscreen);
|
2002-05-10 15:33:02 +00:00
|
|
|
|
2002-11-23 00:13:52 +00:00
|
|
|
srcPitch = _tmpscreen->pitch;
|
|
|
|
dstPitch = _hwscreen->pitch;
|
2002-05-10 15:33:02 +00:00
|
|
|
|
2002-09-28 16:19:28 +00:00
|
|
|
for(r = _dirty_rect_list; r != last_rect; ++r) {
|
|
|
|
register int dst_y = r->y + _currentShakePos;
|
2002-09-19 16:06:51 +00:00
|
|
|
register int dst_h = 0;
|
2002-09-28 16:19:28 +00:00
|
|
|
if (dst_y < _screenHeight) {
|
2002-09-19 16:06:51 +00:00
|
|
|
dst_h = r->h;
|
2002-09-28 16:19:28 +00:00
|
|
|
if (dst_h > _screenHeight - dst_y)
|
|
|
|
dst_h = _screenHeight - dst_y;
|
2002-05-04 01:16:06 +00:00
|
|
|
|
2002-09-28 16:19:28 +00:00
|
|
|
dst_y *= _scaleFactor;
|
2002-05-04 01:16:06 +00:00
|
|
|
|
2002-11-23 00:13:52 +00:00
|
|
|
_scaler_proc((byte*)_tmpscreen->pixels + (r->x*2+2) + (r->y+1)*srcPitch, srcPitch, NULL,
|
|
|
|
(byte*)_hwscreen->pixels + r->x*2*_scaleFactor + dst_y*dstPitch, dstPitch, r->w, dst_h);
|
2002-05-04 00:11:57 +00:00
|
|
|
}
|
2002-09-19 16:06:51 +00:00
|
|
|
|
2002-09-28 16:19:28 +00:00
|
|
|
r->x *= _scaleFactor;
|
2002-09-19 16:06:51 +00:00
|
|
|
r->y = dst_y;
|
2002-09-28 16:19:28 +00:00
|
|
|
r->w *= _scaleFactor;
|
|
|
|
r->h = dst_h * _scaleFactor;
|
2002-05-10 15:33:02 +00:00
|
|
|
}
|
|
|
|
|
2002-11-23 00:13:52 +00:00
|
|
|
SDL_UnlockSurface(_tmpscreen);
|
|
|
|
SDL_UnlockSurface(_hwscreen);
|
2002-09-28 16:19:28 +00:00
|
|
|
|
2002-09-29 18:19:57 +00:00
|
|
|
// Readjust the dirty rect list in case we are doing a full update.
|
|
|
|
// This is necessary if shaking is active.
|
|
|
|
if (_forceFull) {
|
|
|
|
_dirty_rect_list[0].y = 0;
|
|
|
|
_dirty_rect_list[0].h = _screenHeight * _scaleFactor;
|
|
|
|
}
|
|
|
|
|
2002-09-28 16:19:28 +00:00
|
|
|
// Finally, blit all our changes to the screen
|
2002-11-23 00:13:52 +00:00
|
|
|
SDL_UpdateRects(_hwscreen, _num_dirty_rects, _dirty_rect_list);
|
2002-05-10 15:33:02 +00:00
|
|
|
}
|
2002-05-09 18:23:33 +00:00
|
|
|
|
2002-09-28 16:19:28 +00:00
|
|
|
_num_dirty_rects = 0;
|
|
|
|
_forceFull = false;
|
2002-03-17 13:00:11 +00:00
|
|
|
}
|
2001-11-11 16:54:45 +00:00
|
|
|
|
2002-08-24 10:41:32 +00:00
|
|
|
uint32 OSystem_SDL_Normal::property(int param, Property *value) {
|
2002-03-23 22:03:35 +00:00
|
|
|
|
2002-08-24 10:41:32 +00:00
|
|
|
if (param == PROP_TOGGLE_FULLSCREEN) {
|
2002-11-23 00:13:52 +00:00
|
|
|
assert(_hwscreen != 0);
|
2002-04-13 12:43:02 +00:00
|
|
|
_full_screen ^= true;
|
2002-12-08 14:08:51 +00:00
|
|
|
#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
|
2002-11-23 00:13:52 +00:00
|
|
|
if (!SDL_WM_ToggleFullScreen(_hwscreen)) {
|
2002-10-14 11:02:27 +00:00
|
|
|
// if ToggleFullScreen fails, achieve the same effect with hotswap gfx mode
|
2002-04-13 12:43:02 +00:00
|
|
|
hotswap_gfx_mode();
|
|
|
|
}
|
2002-12-08 14:08:51 +00:00
|
|
|
#endif
|
2002-04-13 12:43:02 +00:00
|
|
|
return 1;
|
2002-04-11 17:19:16 +00:00
|
|
|
}
|
2002-05-07 22:06:06 +00:00
|
|
|
|
2002-08-24 10:41:32 +00:00
|
|
|
return OSystem_SDL_Common::property(param, value);
|
2002-06-04 18:18:44 +00:00
|
|
|
}
|
2002-09-19 16:06:51 +00:00
|
|
|
|
2002-12-13 16:15:58 +00:00
|
|
|
int16 OSystem_SDL_Normal::RBGToColor(uint8 r, uint8 g, uint8 b)
|
|
|
|
{
|
|
|
|
return SDL_MapRGB(_tmpscreen->format, r, g, b);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OSystem_SDL_Normal::colorToRBG(int16 color, uint8 &r, uint8 &g, uint8 &b)
|
|
|
|
{
|
|
|
|
SDL_GetRGB(color, _tmpscreen->format, &r, &g, &b);
|
|
|
|
}
|
2002-09-19 16:06:51 +00:00
|
|
|
|
|
|
|
void OSystem_SDL_Normal::show_overlay()
|
|
|
|
{
|
|
|
|
// hide the mouse
|
|
|
|
undraw_mouse();
|
|
|
|
|
|
|
|
_overlay_visible = true;
|
|
|
|
clear_overlay();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OSystem_SDL_Normal::hide_overlay()
|
|
|
|
{
|
2002-09-28 16:19:28 +00:00
|
|
|
// hide the mouse
|
|
|
|
undraw_mouse();
|
|
|
|
|
2002-09-19 16:06:51 +00:00
|
|
|
_overlay_visible = false;
|
2002-09-28 16:19:28 +00:00
|
|
|
_forceFull = true;
|
2002-09-19 16:06:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OSystem_SDL_Normal::clear_overlay()
|
|
|
|
{
|
|
|
|
if (!_overlay_visible)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// hide the mouse
|
|
|
|
undraw_mouse();
|
|
|
|
|
|
|
|
// Clear the overlay by making the game screen "look through" everywhere.
|
|
|
|
SDL_Rect src, dst;
|
|
|
|
src.x = src.y = 0;
|
|
|
|
dst.x = dst.y = 1;
|
2002-09-28 16:19:28 +00:00
|
|
|
src.w = dst.w = _screenWidth;
|
|
|
|
src.h = dst.h = _screenHeight;
|
2002-11-23 00:13:52 +00:00
|
|
|
if (SDL_BlitSurface(_screen, &src, _tmpscreen, &dst) != 0)
|
2002-09-19 16:06:51 +00:00
|
|
|
error("SDL_BlitSurface failed: %s", SDL_GetError());
|
|
|
|
|
2002-09-28 16:19:28 +00:00
|
|
|
_forceFull = true;
|
2002-09-19 16:06:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OSystem_SDL_Normal::grab_overlay(int16 *buf, int pitch)
|
|
|
|
{
|
|
|
|
if (!_overlay_visible)
|
|
|
|
return;
|
|
|
|
|
2002-11-23 00:13:52 +00:00
|
|
|
if (_tmpscreen == NULL)
|
2002-09-19 16:06:51 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// hide the mouse
|
|
|
|
undraw_mouse();
|
|
|
|
|
2002-11-23 00:13:52 +00:00
|
|
|
if (SDL_LockSurface(_tmpscreen) == -1)
|
2002-09-19 16:06:51 +00:00
|
|
|
error("SDL_LockSurface failed: %s.\n", SDL_GetError());
|
|
|
|
|
2002-11-23 00:13:52 +00:00
|
|
|
int16 *src = (int16 *)_tmpscreen->pixels + TMP_SCREEN_WIDTH + 1;
|
2002-09-28 16:19:28 +00:00
|
|
|
int h = _screenHeight;
|
2002-09-19 16:06:51 +00:00
|
|
|
do {
|
2002-09-28 16:19:28 +00:00
|
|
|
memcpy(buf, src, _screenWidth*2);
|
2002-09-19 16:06:51 +00:00
|
|
|
src += TMP_SCREEN_WIDTH;
|
|
|
|
buf += pitch;
|
|
|
|
} while (--h);
|
|
|
|
|
2002-11-23 00:13:52 +00:00
|
|
|
SDL_UnlockSurface(_tmpscreen);
|
2002-09-19 16:06:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OSystem_SDL_Normal::copy_rect_overlay(const int16 *buf, int pitch, int x, int y, int w, int h)
|
|
|
|
{
|
|
|
|
if (!_overlay_visible)
|
|
|
|
return;
|
|
|
|
|
2002-11-23 00:13:52 +00:00
|
|
|
if (_tmpscreen == NULL)
|
2002-09-19 16:06:51 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Clip the coordinates
|
|
|
|
if (x < 0) { w+=x; buf-=x; x = 0; }
|
|
|
|
if (y < 0) { h+=y; buf-=y*pitch; y = 0; }
|
2002-09-28 16:19:28 +00:00
|
|
|
if (w > _screenWidth-x) { w = _screenWidth - x; }
|
|
|
|
if (h > _screenHeight-y) { h = _screenHeight - y; }
|
2002-09-19 16:06:51 +00:00
|
|
|
if (w <= 0 || h <= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Mark the modified region as dirty
|
|
|
|
cksum_valid = false;
|
|
|
|
add_dirty_rect(x, y, w, h);
|
|
|
|
|
|
|
|
/* FIXME: undraw mouse only if the draw rect intersects with the mouse rect */
|
|
|
|
undraw_mouse();
|
|
|
|
|
2002-11-23 00:13:52 +00:00
|
|
|
if (SDL_LockSurface(_tmpscreen) == -1)
|
2002-09-19 16:06:51 +00:00
|
|
|
error("SDL_LockSurface failed: %s.\n", SDL_GetError());
|
|
|
|
|
2002-11-23 00:13:52 +00:00
|
|
|
int16 *dst = (int16 *)_tmpscreen->pixels + (y+1) * TMP_SCREEN_WIDTH + (x+1);
|
2002-09-19 16:06:51 +00:00
|
|
|
do {
|
|
|
|
memcpy(dst, buf, w*2);
|
|
|
|
dst += TMP_SCREEN_WIDTH;
|
|
|
|
buf += pitch;
|
|
|
|
} while (--h);
|
|
|
|
|
2002-11-23 00:13:52 +00:00
|
|
|
SDL_UnlockSurface(_tmpscreen);
|
2002-09-19 16:06:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|