ScummVM API documentation
dc.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #include "backends/base-backend.h"
23 #include <graphics/surface.h>
24 #include <graphics/paletteman.h>
25 #include <ronin/soundcommon.h>
26 #include "backends/timer/default/default-timer.h"
27 #include "backends/audiocd/default/default-audiocd.h"
28 #include "backends/fs/fs-factory.h"
29 #include "audio/mixer_intern.h"
30 #include "common/language.h"
31 #include "common/platform.h"
32 #ifdef DYNAMIC_MODULES
33 #include "backends/plugins/dynamic-plugin.h"
34 #endif
35 
36 #define NUM_BUFFERS 4
37 #define SOUND_BUFFER_SHIFT 3
38 
40 {
41  public:
42  virtual int key(int k, byte &shiftFlags) = 0;
43  virtual void mouse(int x, int y) = 0;
44  virtual ~Interactive() = 0;
45 };
46 inline Interactive::~Interactive() { }
47 
48 #include "softkbd.h"
49 
50 class DCHardware {
51  private:
52  static void dc_init_hardware();
53  protected:
54  DCHardware() { dc_init_hardware(); }
55 };
56 
58 public:
59  // Poll cdrom status
60  // Returns true if cd audio is playing
61  bool isPlaying() const override;
62 
63  // Play cdrom audio track
64  bool play(int track, int numLoops, int startFrame, int duration, bool onlyEmulate = false,
66 
67  // Stop cdrom audio track
68  void stop() override;
69 };
70 
72 #ifdef DYNAMIC_MODULES
73  , public FilePluginProvider
74 #endif
75  {
76 
77  public:
79 
80  virtual void initBackend();
81 
82  // Determine whether the backend supports the specified feature.
83  bool hasFeature(Feature f);
84 
85  // En-/disable the specified feature.
86  void setFeatureState(Feature f, bool enable);
87 
88  // Query the state of the specified feature.
89  bool getFeatureState(Feature f);
90 
91  // Set colors of the palette
92  PaletteManager *getPaletteManager() { return this; }
93 protected:
94  // PaletteManager API
95  void setPalette(const byte *colors, uint start, uint num);
96  void grabPalette(byte *colors, uint start, uint num) const;
97 
98 public:
99 
100  // Determine the pixel format currently in use for screen rendering.
101  Graphics::PixelFormat getScreenFormat() const;
102 
103  // Returns a list of all pixel formats supported by the backend.
104  Common::List<Graphics::PixelFormat> getSupportedFormats() const;
105 
106  // Set the size of the video bitmap.
107  // Typically, 320x200
108  void initSize(uint w, uint h, const Graphics::PixelFormat *format);
109  int16 getHeight() { return _screen_h; }
110  int16 getWidth() { return _screen_w; }
111 
112  // Draw a bitmap to screen.
113  // The screen will not be updated to reflect the new bitmap
114  void copyRectToScreen(const void *buf, int pitch, int x, int y, int w, int h);
115 
116  virtual Graphics::Surface *lockScreen();
117  virtual void unlockScreen();
118 
119  // Update the dirty areas of the screen
120  void updateScreen();
121 
122  // Either show or hide the mouse cursor
123  bool showMouse(bool visible);
124 
125  // Move ("warp") the mouse cursor to the specified position.
126  void warpMouse(int x, int y);
127 
128  // Set the bitmap that's used when drawing the cursor.
129  void setMouseCursor(const void *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, bool dontScale, const Graphics::PixelFormat *format, const byte *mask);
130 
131  // Replace the specified range of cursor the palette with new colors.
132  void setCursorPalette(const byte *colors, uint start, uint num);
133 
134  // Shaking is used in SCUMM. Set current shake position.
135  void setShakePos(int shake_x_pos, int shake_y_pos);
136 
137  // Get the number of milliseconds since the program was started.
138  uint32 getMillis(bool skipRecord = false);
139 
140  // Delay for a specified amount of milliseconds
141  void delayMillis(uint msecs);
142 
143  // Get the current time and date. Correspond to time()+localtime().
144  void getTimeAndDate(TimeDate &td, bool skipRecord = false) const;
145 
146  // Get the next event.
147  // Returns true if an event was retrieved.
148  bool pollEvent(Common::Event &event);
149 
150  // Quit
151  void quit();
152 
153  // Overlay
154  int16 getOverlayHeight();
155  int16 getOverlayWidth();
156  bool isOverlayVisible() const { return _overlay_visible; }
157  void showOverlay(bool inGUI);
158  void hideOverlay();
159  void clearOverlay();
160  void grabOverlay(Graphics::Surface &surface);
161  void copyRectToOverlay(const void *buf, int pitch, int x, int y, int w, int h);
162  virtual Graphics::PixelFormat getOverlayFormat() const { return Graphics::PixelFormat(2, 4, 4, 4, 4, 8, 4, 0, 12); }
163 
164  // Mutex handling
165  Common::MutexInternal *createMutex();
166 
167  // Set a window caption or any other comparable status display to the
168  // given value.
169  void setWindowCaption(const Common::U32String &caption);
170 
171  // Modulatized backend
172  Audio::Mixer *getMixer() { return _mixer; }
173 
174  // Extra SoftKbd support
175  void mouseToSoftKbd(int x, int y, int &rx, int &ry) const;
176 
177  // Filesystem
178  AbstractFSNode *makeRootFileNode() const override;
179  AbstractFSNode *makeCurrentDirectoryFileNode() const override;
180  AbstractFSNode *makeFileNodePath(const Common::String &path) const override;
181 
182  private:
183 
184  Audio::MixerImpl *_mixer;
185  SoftKeyboard _softkbd;
186 
187  int _ms_cur_x, _ms_cur_y, _ms_cur_w, _ms_cur_h, _ms_old_x, _ms_old_y;
188  int _ms_hotspot_x, _ms_hotspot_y, _ms_visible, _devpoll, _last_screen_refresh;
189  int _current_shake_x_pos, _current_shake_y_pos, _screen_w, _screen_h;
190  int _overlay_x, _overlay_y;
191  unsigned char *_ms_buf;
192  uint32 _ms_keycolor;
193  bool _overlay_visible, _overlay_dirty, _screen_dirty;
194  int _screen_buffer, _overlay_buffer, _mouse_buffer;
195  bool _aspect_stretch, _softkbd_on, _enable_cursor_palette;
196  bool _overlay_in_gui;
197  float _overlay_fade, _xscale, _yscale, _top_offset;
198  int _softkbd_motion;
199 
200  unsigned char *screen;
201  unsigned short *mouse;
202  unsigned short *overlay;
203  void *screen_tx[NUM_BUFFERS];
204  void *mouse_tx[NUM_BUFFERS];
205  void *ovl_tx[NUM_BUFFERS];
206  unsigned short palette[256], cursor_palette[256];
207 
208  Graphics::Surface _framebuffer;
209  int _screenFormat, _mouseFormat;
210 
211  int temp_sound_buffer[RING_BUFFER_SAMPLES>>SOUND_BUFFER_SHIFT];
212 
213  uint initSound();
214  void checkSound();
215 
216  void updateScreenTextures(void);
217  void updateScreenPolygons(void);
218  void maybeRefreshScreen(void);
219  void drawMouse(int xdraw, int ydraw, int w, int h,
220  unsigned char *buf, bool visible);
221 
222  void setScaling();
223 
224 
225  Common::SaveFileManager *createSavefileManager();
226 
227  Common::SeekableReadStream *createConfigReadStream();
228  Common::WriteStream *createConfigWriteStream();
229 
230  void logMessage(LogMessageType::Type type, const char *message);
231  Common::String getSystemLanguage() const;
232 
233 #ifdef DYNAMIC_MODULES
234  class DCPlugin;
235 
236  protected:
237  Plugin* createPlugin(const Common::FSNode &node) const;
238  bool isPluginFilename(const Common::FSNode &node) const;
239  void addCustomDirectories(Common::FSList &dirs) const;
240  public:
241  PluginList getPlugins();
242  private:
243  const char *pluginCustomDirectory;
244 #endif
245 };
246 
247 
248 extern int handleInput(struct mapledev *pad,
249  int &mouse_x, int &mouse_y,
250  byte &shiftFlags, Interactive *inter = NULL);
251 extern bool selectGame(char *&, char *&, char *&, Common::Language &, Common::Platform &, class Icon &);
252 #ifdef DYNAMIC_MODULES
253 extern bool selectPluginDir(Common::String &selection, const Common::FSNode &base);
254 #endif
Definition: mixer.h:65
Definition: system.h:106
Definition: str.h:59
Definition: surface.h:67
virtual Graphics::PixelFormat getOverlayFormat() const
Definition: dc.h:162
Definition: stream.h:77
Definition: dc.h:50
Definition: fs-factory.h:31
Definition: array.h:52
Definition: default-audiocd.h:35
Definition: pixelformat.h:138
PaletteManager * getPaletteManager()
Definition: dc.h:92
Feature
Definition: system.h:403
Definition: list.h:44
Definition: stream.h:745
Definition: plugins.h:145
Definition: softkbd.h:31
Type
Definition: log.h:33
Definition: mixer_intern.h:58
Definition: icon.h:25
SoundType
Definition: mixer.h:62
Definition: mixer.h:59
Definition: dc.h:57
Definition: ustr.h:57
Definition: events.h:199
Definition: fs.h:69
Definition: fs.h:57
Definition: base-backend.h:44
Definition: dc.h:39
Definition: savefile.h:142
int16 getWidth()
Definition: dc.h:110
bool isOverlayVisible() const
Definition: dc.h:156
Definition: mutex.h:40
Audio::Mixer * getMixer()
Definition: dc.h:172
Definition: paletteman.h:47
Definition: dc.h:71
Definition: abstract-fs.h:41
int16 getHeight()
Definition: dc.h:109
Platform
Definition: platform.h:46
Language
Definition: language.h:45