2002-08-24 10:41:32 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
2004-02-29 00:49:40 +00:00
|
|
|
* Copyright (C) 2001 Ludvig Strigeus
|
2004-01-06 12:45:34 +00:00
|
|
|
* Copyright (C) 2001-2004 The ScummVM project
|
2002-08-24 10:41:32 +00:00
|
|
|
*
|
|
|
|
* 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$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SDL_COMMON_H
|
|
|
|
#define SDL_COMMON_H
|
|
|
|
|
2003-08-01 12:21:04 +00:00
|
|
|
#include "common/stdafx.h"
|
|
|
|
#include "common/scummsys.h"
|
2004-02-27 19:35:51 +00:00
|
|
|
#include "common/scaler.h"
|
2003-08-01 12:21:04 +00:00
|
|
|
#include "common/system.h"
|
2003-07-31 12:33:33 +00:00
|
|
|
#include "backends/intern.h"
|
2002-08-24 10:41:32 +00:00
|
|
|
|
|
|
|
#include <SDL.h>
|
|
|
|
|
2004-03-13 14:19:15 +00:00
|
|
|
// Uncomment this to enable the 'on screen display' code.
|
|
|
|
#define USE_OSD 1
|
|
|
|
|
2004-02-29 00:49:40 +00:00
|
|
|
class OSystem_SDL : public OSystem {
|
2002-08-24 10:41:32 +00:00
|
|
|
public:
|
2004-02-29 00:49:40 +00:00
|
|
|
OSystem_SDL();
|
|
|
|
virtual ~OSystem_SDL();
|
|
|
|
|
2002-08-24 10:41:32 +00:00
|
|
|
// Set the size of the video bitmap.
|
|
|
|
// Typically, 320x200
|
2004-02-24 22:39:42 +00:00
|
|
|
void initSize(uint w, uint h);
|
2002-08-24 10:41:32 +00:00
|
|
|
|
2003-07-02 15:08:46 +00:00
|
|
|
// Set colors of the palette
|
2004-02-28 12:58:13 +00:00
|
|
|
void setPalette(const byte *colors, uint start, uint num);
|
2003-07-02 15:08:46 +00:00
|
|
|
|
2002-08-24 10:41:32 +00:00
|
|
|
// Draw a bitmap to screen.
|
|
|
|
// The screen will not be updated to reflect the new bitmap
|
2003-10-04 00:12:30 +00:00
|
|
|
void copy_rect(const byte *src, int pitch, int x, int y, int w, int h);
|
2002-08-24 10:41:32 +00:00
|
|
|
|
2002-09-09 05:56:11 +00:00
|
|
|
void move_screen(int dx, int dy, int height);
|
|
|
|
|
2002-08-24 10:41:32 +00:00
|
|
|
// Update the dirty areas of the screen
|
2004-02-28 12:58:13 +00:00
|
|
|
void updateScreen();
|
2002-08-24 10:41:32 +00:00
|
|
|
|
|
|
|
// Either show or hide the mouse cursor
|
|
|
|
bool show_mouse(bool visible);
|
|
|
|
|
2003-01-09 08:07:13 +00:00
|
|
|
// Warp the mouse cursor. Where set_mouse_pos() only informs the
|
|
|
|
// backend of the mouse cursor's current position, this function
|
|
|
|
// actually moves the cursor to the specified position.
|
|
|
|
void warp_mouse(int x, int y);
|
2003-03-06 18:30:44 +00:00
|
|
|
|
2002-08-24 10:41:32 +00:00
|
|
|
// Set the bitmap that's used when drawing the cursor.
|
|
|
|
void set_mouse_cursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y);
|
2003-03-06 18:30:44 +00:00
|
|
|
|
2002-08-24 10:41:32 +00:00
|
|
|
// Shaking is used in SCUMM. Set current shake position.
|
|
|
|
void set_shake_pos(int shake_pos);
|
2003-03-06 18:30:44 +00:00
|
|
|
|
2002-08-24 10:41:32 +00:00
|
|
|
// Get the number of milliseconds since the program was started.
|
|
|
|
uint32 get_msecs();
|
2003-03-06 18:30:44 +00:00
|
|
|
|
2002-08-24 10:41:32 +00:00
|
|
|
// Delay for a specified amount of milliseconds
|
|
|
|
void delay_msecs(uint msecs);
|
2003-03-06 18:30:44 +00:00
|
|
|
|
2002-08-24 10:41:32 +00:00
|
|
|
// Get the next event.
|
|
|
|
// Returns true if an event was retrieved.
|
|
|
|
bool poll_event(Event *event);
|
2003-03-06 18:30:44 +00:00
|
|
|
|
2002-08-24 10:41:32 +00:00
|
|
|
// Set function that generates samples
|
2004-02-24 22:39:42 +00:00
|
|
|
bool setSoundCallback(SoundProc proc, void *param);
|
2003-06-09 01:19:25 +00:00
|
|
|
|
2004-02-24 22:39:42 +00:00
|
|
|
void clearSoundCallback();
|
2003-03-06 18:30:44 +00:00
|
|
|
|
2002-09-28 16:19:28 +00:00
|
|
|
// Poll CD status
|
2002-08-24 10:41:32 +00:00
|
|
|
// Returns true if cd audio is playing
|
|
|
|
bool poll_cdrom();
|
|
|
|
|
2002-09-28 16:19:28 +00:00
|
|
|
// Play CD audio track
|
2003-07-22 20:36:43 +00:00
|
|
|
void play_cdrom(int track, int num_loops, int start_frame, int duration);
|
2002-08-24 10:41:32 +00:00
|
|
|
|
2002-09-28 16:19:28 +00:00
|
|
|
// Stop CD audio track
|
2002-08-24 10:41:32 +00:00
|
|
|
void stop_cdrom();
|
|
|
|
|
2002-09-28 16:19:28 +00:00
|
|
|
// Update CD audio status
|
2002-08-24 10:41:32 +00:00
|
|
|
void update_cdrom();
|
|
|
|
|
|
|
|
// Quit
|
|
|
|
void quit();
|
|
|
|
|
|
|
|
|
|
|
|
// Add a callback timer
|
2004-03-15 01:18:47 +00:00
|
|
|
void setTimerCallback(TimerProc callback, int timer);
|
2002-08-24 10:41:32 +00:00
|
|
|
|
|
|
|
// Mutex handling
|
2004-02-28 12:58:13 +00:00
|
|
|
MutexRef createMutex();
|
|
|
|
void lockMutex(MutexRef mutex);
|
|
|
|
void unlockMutex(MutexRef mutex);
|
|
|
|
void deleteMutex(MutexRef mutex);
|
2002-08-24 10:41:32 +00:00
|
|
|
|
2002-12-13 17:27:28 +00:00
|
|
|
// Overlay
|
|
|
|
virtual void show_overlay();
|
|
|
|
virtual void hide_overlay();
|
|
|
|
virtual void clear_overlay();
|
2004-03-13 14:19:15 +00:00
|
|
|
virtual void grab_overlay(OverlayColor *buf, int pitch);
|
|
|
|
virtual void copy_rect_overlay(const OverlayColor *buf, int pitch, int x, int y, int w, int h);
|
2004-03-15 00:45:45 +00:00
|
|
|
virtual int16 getHeight();
|
|
|
|
virtual int16 getWidth();
|
2002-12-13 17:27:28 +00:00
|
|
|
|
2003-03-08 06:53:32 +00:00
|
|
|
// Methods that convert RGB to/from colors suitable for the overlay.
|
2004-03-13 14:19:15 +00:00
|
|
|
virtual OverlayColor RGBToColor(uint8 r, uint8 g, uint8 b);
|
|
|
|
virtual void colorToRGB(OverlayColor color, uint8 &r, uint8 &g, uint8 &b);
|
2002-12-13 17:27:28 +00:00
|
|
|
|
2004-02-24 22:39:42 +00:00
|
|
|
|
|
|
|
virtual const GraphicsMode *getSupportedGraphicsModes() const;
|
2004-03-15 00:45:45 +00:00
|
|
|
virtual int getDefaultGraphicsMode() const;
|
2004-02-24 22:39:42 +00:00
|
|
|
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);
|
|
|
|
|
2002-08-24 10:41:32 +00:00
|
|
|
protected:
|
2004-02-24 22:39:42 +00:00
|
|
|
void init_intern();
|
2003-05-14 19:44:41 +00:00
|
|
|
|
2004-03-13 14:19:15 +00:00
|
|
|
#ifdef USE_OSD
|
|
|
|
SDL_Surface *_osdSurface;
|
|
|
|
Uint8 _osdAlpha; // Transparency level of the OSD
|
|
|
|
uint32 _osdFadeStartTime; // When to start the fade out
|
|
|
|
enum {
|
|
|
|
kOSDFadeOutDelay = 2 * 1000, // Delay before the OSD is faded out (in milliseconds)
|
|
|
|
kOSDFadeOutDuration = 500, // Duration of the OSD fade out (in milliseconds)
|
|
|
|
kOSDColorKey = 1,
|
|
|
|
kOSDInitialAlpha = 80 // Initial alpha level, in percent
|
|
|
|
};
|
|
|
|
|
|
|
|
void displayMessageOnOSD(const char *msg);
|
|
|
|
#endif
|
|
|
|
|
2004-02-29 00:49:40 +00:00
|
|
|
// hardware screen
|
|
|
|
SDL_Surface *_hwscreen;
|
|
|
|
|
2002-09-28 16:19:28 +00:00
|
|
|
// unseen game screen
|
|
|
|
SDL_Surface *_screen;
|
|
|
|
int _screenWidth, _screenHeight;
|
|
|
|
|
2002-12-13 17:21:23 +00:00
|
|
|
// temporary screen (for scalers/overlay)
|
|
|
|
SDL_Surface *_tmpscreen;
|
|
|
|
bool _overlayVisible;
|
|
|
|
|
2002-09-28 16:19:28 +00:00
|
|
|
// CD Audio
|
|
|
|
SDL_CD *_cdrom;
|
2003-07-22 20:38:01 +00:00
|
|
|
int cd_track, cd_num_loops, cd_start_frame, cd_duration;
|
2004-03-01 01:44:36 +00:00
|
|
|
Uint32 cd_end_time, cd_stop_time;
|
2002-08-24 10:41:32 +00:00
|
|
|
|
|
|
|
enum {
|
|
|
|
DF_WANT_RECT_OPTIM = 1 << 0,
|
2003-10-04 23:49:04 +00:00
|
|
|
DF_UPDATE_EXPAND_1_PIXEL = 1 << 1
|
2002-08-24 10:41:32 +00:00
|
|
|
};
|
|
|
|
|
2004-02-28 12:58:13 +00:00
|
|
|
bool _forceFull; // Force full redraw on next updateScreen
|
2004-02-27 19:35:51 +00:00
|
|
|
ScalerProc *_scaler_proc;
|
2002-09-28 16:19:28 +00:00
|
|
|
int _scaleFactor;
|
2002-08-24 10:41:32 +00:00
|
|
|
int _mode;
|
|
|
|
bool _full_screen;
|
|
|
|
uint32 _mode_flags;
|
2003-09-06 20:21:54 +00:00
|
|
|
bool _modeChanged;
|
2002-08-24 10:41:32 +00:00
|
|
|
|
2003-10-05 14:41:30 +00:00
|
|
|
/** True if aspect ratio correction is enabled. */
|
|
|
|
bool _adjustAspectRatio;
|
|
|
|
|
2002-08-24 10:41:32 +00:00
|
|
|
enum {
|
|
|
|
NUM_DIRTY_RECT = 100,
|
|
|
|
|
2002-12-25 12:53:47 +00:00
|
|
|
MAX_MOUSE_W = 80,
|
|
|
|
MAX_MOUSE_H = 80,
|
2002-08-24 10:41:32 +00:00
|
|
|
MAX_SCALING = 3
|
|
|
|
};
|
|
|
|
|
2002-09-28 16:19:28 +00:00
|
|
|
// Dirty rect managment
|
2003-10-05 14:41:30 +00:00
|
|
|
SDL_Rect _dirty_rect_list[NUM_DIRTY_RECT];
|
2002-09-28 16:19:28 +00:00
|
|
|
int _num_dirty_rects;
|
2002-09-27 13:05:54 +00:00
|
|
|
uint32 *_dirty_checksums;
|
2002-09-28 16:19:28 +00:00
|
|
|
bool cksum_valid;
|
|
|
|
int CKSUM_NUM;
|
2002-08-24 10:41:32 +00:00
|
|
|
|
2002-09-28 16:19:28 +00:00
|
|
|
// Keyboard mouse emulation
|
2002-08-24 10:41:32 +00:00
|
|
|
struct KbdMouse {
|
|
|
|
int16 x, y, x_vel, y_vel, x_max, y_max, x_down_count, y_down_count;
|
|
|
|
uint32 last_time, delay_time, x_down_time, y_down_time;
|
|
|
|
} km;
|
|
|
|
|
|
|
|
struct MousePos {
|
|
|
|
int16 x, y, w, h;
|
2002-11-13 14:38:49 +00:00
|
|
|
MousePos() : x(0), y(0), w(0), h(0) {}
|
2002-08-24 10:41:32 +00:00
|
|
|
};
|
|
|
|
|
2003-09-14 12:52:38 +00:00
|
|
|
// mouse
|
2002-09-28 16:19:28 +00:00
|
|
|
bool _mouseVisible;
|
|
|
|
bool _mouseDrawn;
|
2003-05-21 16:59:51 +00:00
|
|
|
const byte *_mouseData;
|
2002-09-28 16:19:28 +00:00
|
|
|
byte *_mouseBackup;
|
2002-11-13 14:38:49 +00:00
|
|
|
MousePos _mouseCurState;
|
2002-09-28 16:19:28 +00:00
|
|
|
int16 _mouseHotspotX;
|
|
|
|
int16 _mouseHotspotY;
|
2002-08-24 10:41:32 +00:00
|
|
|
|
2003-09-14 12:52:38 +00:00
|
|
|
// joystick
|
|
|
|
SDL_Joystick *_joystick;
|
|
|
|
|
2002-09-28 16:19:28 +00:00
|
|
|
// Shake mode
|
|
|
|
int _currentShakePos;
|
|
|
|
int _newShakePos;
|
|
|
|
|
|
|
|
// Palette data
|
|
|
|
SDL_Color *_currentPalette;
|
|
|
|
uint _paletteDirtyStart, _paletteDirtyEnd;
|
2003-04-30 19:11:33 +00:00
|
|
|
|
2004-02-28 12:58:13 +00:00
|
|
|
/**
|
|
|
|
* Mutex which prevents multiple threads from interfering with each other
|
|
|
|
* when accessing the screen.
|
|
|
|
*/
|
2003-07-05 15:17:46 +00:00
|
|
|
MutexRef _graphicsMutex;
|
2002-08-24 10:41:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
void add_dirty_rgn_auto(const byte *buf);
|
|
|
|
void mk_checksums(const byte *buf);
|
|
|
|
|
2004-02-29 00:49:40 +00:00
|
|
|
void add_dirty_rect(int x, int y, int w, int h);
|
2002-08-24 10:41:32 +00:00
|
|
|
|
2004-02-29 00:49:40 +00:00
|
|
|
void draw_mouse();
|
|
|
|
void undraw_mouse();
|
2003-09-11 23:53:38 +00:00
|
|
|
/** Set the position of the virtual mouse cursor. */
|
|
|
|
void set_mouse_pos(int x, int y);
|
2003-09-14 12:52:38 +00:00
|
|
|
void fillMouseEvent(Event &event, int x, int y);
|
2004-02-24 22:39:42 +00:00
|
|
|
void toggleMouseGrab();
|
2003-09-11 23:53:38 +00:00
|
|
|
|
2002-08-24 10:41:32 +00:00
|
|
|
|
2004-02-29 00:49:40 +00:00
|
|
|
void internUpdateScreen();
|
2004-02-27 19:35:51 +00:00
|
|
|
|
2004-02-29 00:49:40 +00:00
|
|
|
void load_gfx_mode();
|
|
|
|
void unload_gfx_mode();
|
|
|
|
void hotswap_gfx_mode();
|
2004-02-25 09:53:36 +00:00
|
|
|
|
2004-02-29 00:49:40 +00:00
|
|
|
void setFullscreenMode(bool enable);
|
2002-08-24 10:41:32 +00:00
|
|
|
|
2004-02-29 00:49:40 +00:00
|
|
|
bool save_screenshot(const char *filename);
|
2003-09-14 12:52:38 +00:00
|
|
|
|
2004-02-29 00:49:40 +00:00
|
|
|
int effectiveScreenHeight() { return (_adjustAspectRatio ? 240 : _screenHeight) * _scaleFactor; }
|
2003-08-22 07:40:40 +00:00
|
|
|
|
2002-08-24 10:41:32 +00:00
|
|
|
void setup_icon();
|
|
|
|
void kbd_mouse();
|
2003-10-01 10:47:19 +00:00
|
|
|
void init_joystick(int joystick_num) { _joystick = SDL_JoystickOpen(joystick_num); }
|
2002-08-24 10:41:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|