ScummVM API documentation
system.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
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (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, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #ifndef COMMON_SYSTEM_H
24 #define COMMON_SYSTEM_H
25 
26 #include "common/scummsys.h"
27 #include "common/noncopyable.h"
28 #include "common/array.h" // For OSystem::getGlobalKeymaps()
29 #include "common/list.h" // For OSystem::getSupportedFormats()
30 #include "common/ustr.h"
31 #include "graphics/pixelformat.h"
32 #include "graphics/pixelbuffer.h"
33 #include "graphics/mode.h"
34 
35 namespace Audio {
36 class Mixer;
37 }
38 
39 namespace Graphics {
40 struct Surface;
41 }
42 
43 namespace Common {
44 class EventManager;
45 struct Rect;
46 class SaveFileManager;
47 class SearchSet;
48 class String;
49 #if defined(USE_TASKBAR)
50 class TaskbarManager;
51 #endif
52 #if defined(USE_UPDATES)
53 class UpdateManager;
54 #endif
55 #if defined(USE_TTS)
56 class TextToSpeechManager;
57 #endif
58 #if defined(USE_SYSDIALOGS)
59 class DialogManager;
60 #endif
61 class TimerManager;
62 class SeekableReadStream;
63 class WriteStream;
64 class HardwareInputSet;
65 class Keymap;
66 class KeymapperDefaultBindings;
67 class Encoding;
68 
69 typedef Array<Keymap *> KeymapArray;
70 }
71 
81 class AudioCDManager;
82 class FilesystemFactory;
83 class PaletteManager;
84 
96 struct TimeDate {
97  int tm_sec;
98  int tm_min;
99  int tm_hour;
100  int tm_mday;
101  int tm_mon;
102  int tm_year;
103  int tm_wday;
104 };
105 
106 namespace LogMessageType {
112 enum Type {
117 };
118 
119 } // End of namespace LogMessageType
120 
137 class OSystem : Common::NonCopyable {
138  friend class Common::Encoding;
139 protected:
140  OSystem();
141  virtual ~OSystem();
142 
143 protected:
172  AudioCDManager *_audiocdManager;
173 
181  Common::EventManager *_eventManager;
182 
188  Common::TimerManager *_timerManager;
189 
195  Common::SaveFileManager *_savefileManager;
196 
197 #if defined(USE_TASKBAR)
198 
203  Common::TaskbarManager *_taskbarManager;
204 #endif
205 
206 #if defined(USE_UPDATES)
207 
212  Common::UpdateManager *_updateManager;
213 #endif
214 
215 #if defined(USE_TTS)
216 
221  Common::TextToSpeechManager *_textToSpeechManager;
222 #endif
223 
224 #if defined(USE_SYSDIALOGS)
225 
230  Common::DialogManager *_dialogManager;
231 #endif
232 
242  FilesystemFactory *_fsFactory;
243 
248  Common::U32String _clipboard;
249 
255 private:
259  bool _backendInitialized;
260 
262 
263 public:
264 
268  void destroy();
269 
273  virtual void init() {}
274 
283  virtual void initBackend();
284 
291  bool backendInitialized() const { return _backendInitialized; }
292 
298  virtual void engineInit() { }
299 
305  virtual void engineDone() { }
306 
335  enum Feature {
341 
359 
365 
370 
377 
389 
398 
404 
410 
417 
428 
436 
449 
457 
462 
467 
472 
477 
482 
487 
493 
497  kFeatureNoQuit
498  };
499 
503  virtual bool hasFeature(Feature f) { return false; }
504 
511  virtual void setFeatureState(Feature f, bool enable) {}
512 
518  virtual bool getFeatureState(Feature f) { return false; }
519 
592  struct GraphicsMode {
599  const char *name;
605  const char *description;
612  int id;
613  };
614 
625  virtual const GraphicsMode *getSupportedGraphicsModes() const {
626  static const GraphicsMode noGraphicsModes[] = {{"NONE", "Normal", 0}, {nullptr, nullptr, 0 }};
627  return noGraphicsModes;
628  }
629 
638  virtual int getDefaultGraphicsMode() const { return 0; }
639 
641  kGfxModeNoFlags = 0,
642  kGfxModeRender3d = (1 << 0)
643  };
644 
658  virtual bool setGraphicsMode(int mode, uint flags = kGfxModeNoFlags) { return (mode == 0); }
659 
673  bool setGraphicsMode(const char *name);
674 
680  virtual int getGraphicsMode() const { return 0; }
681 
688  virtual void resetGraphicsScale() {}
689 
690 #ifdef USE_RGB_COLOR
691 
698  virtual Graphics::PixelFormat getScreenFormat() const = 0;
699 
723  virtual Common::List<Graphics::PixelFormat> getSupportedFormats() const = 0;
724 #else
725  inline Graphics::PixelFormat getScreenFormat() const {
726  return Graphics::PixelFormat::createFormatCLUT8();
727  };
728 
729  inline Common::List<Graphics::PixelFormat> getSupportedFormats() const {
730  Common::List<Graphics::PixelFormat> list;
731  list.push_back(Graphics::PixelFormat::createFormatCLUT8());
732  return list;
733  };
734 #endif
735 
742  virtual Common::Array<uint> getSupportedAntiAliasingLevels() const {
743  return Common::Array<uint>();
744  }
745 
756  virtual const GraphicsMode *getSupportedShaders() const {
757  static const OSystem::GraphicsMode no_shader[2] = {{"NONE", "Normal (no shader)", 0}, {nullptr, nullptr, 0}};
758  return no_shader;
759  }
760 
771  virtual int getDefaultShader() const { return 0; }
772 
782  virtual bool setShader(int id) { return false; }
783 
798  bool setShader(const char *name);
799 
805  virtual int getShader() const { return 0; }
806 
816  virtual const GraphicsMode *getSupportedStretchModes() const {
817  static const GraphicsMode noStretchModes[] = {{"NONE", "Normal", 0}, {nullptr, nullptr, 0 }};
818  return noStretchModes;
819  }
820 
830  virtual int getDefaultStretchMode() const { return 0; }
831 
841  virtual bool setStretchMode(int mode) { return false; }
842 
857  bool setStretchMode(const char *name);
858 
864  virtual int getStretchMode() const { return 0; }
865 
866 
895  virtual void initSize(uint width, uint height, const Graphics::PixelFormat *format = nullptr) = 0;
896 
907  virtual void initSizeHint(const Graphics::ModeList &modes) {}
908 
923  virtual int getScreenChangeID() const { return 0; }
924 
943  virtual void beginGFXTransaction() {}
944 
955  kTransactionSuccess = 0,
956  kTransactionAspectRatioFailed = (1 << 0),
957  kTransactionFullscreenFailed = (1 << 1),
958  kTransactionModeSwitchFailed = (1 << 2),
959  kTransactionSizeChangeFailed = (1 << 3),
960  kTransactionFormatNotSupported = (1 << 4),
961  kTransactionFilteringFailed = (1 << 5),
962  kTransactionStretchModeSwitchFailed = (1 << 6)
963  };
964 
973  virtual TransactionError endGFXTransaction() { return kTransactionSuccess; }
974 
982  virtual int16 getHeight() = 0;
983 
991  virtual int16 getWidth() = 0;
992 
998  virtual PaletteManager *getPaletteManager() = 0;
999 
1027  virtual void copyRectToScreen(const void *buf, int pitch, int x, int y, int w, int h) = 0;
1028 
1047  virtual Graphics::Surface *lockScreen() = 0;
1048 
1053  virtual void unlockScreen() = 0;
1054 
1058  virtual void fillScreen(uint32 col) = 0;
1059 
1069  virtual void updateScreen() = 0;
1070 
1088  virtual void setShakePos(int shakeXOffset, int shakeYOffset) = 0;
1089 
1104  virtual void setFocusRectangle(const Common::Rect& rect) {}
1105 
1114  virtual void clearFocusRectangle() {}
1115 
1121  virtual void saveScreenshot() {}
1122 
1148  virtual void showOverlay() = 0;
1149 
1151  virtual void hideOverlay() = 0;
1152 
1154  virtual bool isOverlayVisible() const = 0;
1155 
1161  virtual Graphics::PixelFormat getOverlayFormat() const = 0;
1162 
1173  virtual void clearOverlay() = 0;
1174 
1180  virtual void grabOverlay(void *buf, int pitch) = 0;
1181 
1197  virtual void copyRectToOverlay(const void *buf, int pitch, int x, int y, int w, int h) = 0;
1198 
1204  virtual int16 getOverlayHeight() = 0;
1205 
1211  virtual int16 getOverlayWidth() = 0;
1212 
1239  virtual bool showMouse(bool visible) = 0;
1240 
1245  virtual bool lockMouse(bool lock) { return false; }
1246 
1254  virtual void warpMouse(int x, int y) = 0;
1255 
1271  virtual void setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale = false, const Graphics::PixelFormat *format = nullptr) = 0;
1272 
1284  virtual void setCursorPalette(const byte *colors, uint start, uint num) {}
1285 
1302  virtual uint32 getMillis(bool skipRecord = false) = 0;
1303 
1305  virtual void delayMillis(uint msecs) = 0;
1306 
1313  virtual void getTimeAndDate(TimeDate &t) const = 0;
1314 
1320  virtual Common::TimerManager *getTimerManager();
1321 
1327  inline Common::EventManager *getEventManager() {
1328  return _eventManager;
1329  }
1330 
1338  virtual Common::HardwareInputSet *getHardwareInputSet() { return nullptr; }
1339 
1349  virtual Common::KeymapArray getGlobalKeymaps() { return Common::KeymapArray(); }
1350 
1358  virtual Common::KeymapperDefaultBindings *getKeymapperDefaultBindings() { return nullptr; }
1359 
1382  typedef struct OpaqueMutex *MutexRef;
1383 
1389  virtual MutexRef createMutex() = 0;
1390 
1401  virtual void lockMutex(MutexRef mutex) = 0;
1402 
1408  virtual void unlockMutex(MutexRef mutex) = 0;
1409 
1419  virtual void deleteMutex(MutexRef mutex) = 0;
1420 
1435  virtual Audio::Mixer *getMixer() = 0;
1436 
1451  inline AudioCDManager *getAudioCDManager() {
1452  return _audiocdManager;
1453  }
1454 
1465  virtual void quit() = 0;
1466 
1472  virtual void fatalError();
1473 
1484  virtual void setWindowCaption(const char *caption) {}
1485 
1502  virtual void displayMessageOnOSD(const Common::U32String &msg) = 0;
1503 
1521  virtual void displayActivityIconOnOSD(const Graphics::Surface *icon) = 0;
1535  virtual Common::SaveFileManager *getSavefileManager();
1536 
1537 #if defined(USE_TASKBAR)
1538 
1544  virtual Common::TaskbarManager *getTaskbarManager() {
1545  return _taskbarManager;
1546  }
1547 #endif
1548 
1549 #if defined(USE_UPDATES)
1550 
1556  virtual Common::UpdateManager *getUpdateManager() {
1557  return _updateManager;
1558  }
1559 #endif
1560 
1561 #if defined(USE_TTS)
1562 
1567  virtual Common::TextToSpeechManager *getTextToSpeechManager() {
1568  return _textToSpeechManager;
1569  }
1570 #endif
1571 
1572 #if defined(USE_SYSDIALOGS)
1573 
1578  virtual Common::DialogManager *getDialogManager() {
1579  return _dialogManager;
1580  }
1581 #endif
1582 
1588  virtual FilesystemFactory *getFilesystemFactory();
1605  virtual void addSysArchivesToSearchSet(Common::SearchSet &s, int priority = 0) {}
1606 
1613  virtual Common::SeekableReadStream *createConfigReadStream();
1614 
1623  virtual Common::WriteStream *createConfigWriteStream();
1624 
1631  virtual Common::String getDefaultConfigFileName();
1632 
1645  virtual void logMessage(LogMessageType::Type type, const char *message) = 0;
1646 
1672  virtual bool displayLogFile() { return false; }
1673 
1683  virtual bool hasTextInClipboard() { return !_clipboard.empty(); }
1684 
1694  virtual Common::U32String getTextFromClipboard() { return _clipboard; }
1695 
1705  virtual bool setTextInClipboard(const Common::U32String &text) { _clipboard = text; return true; }
1706 
1719  virtual bool openUrl(const Common::String &url) {return false; }
1720 
1737  virtual Common::String getSystemLanguage() const;
1738 
1744  virtual bool isConnectionLimited();
1745 
1746 
1747 protected:
1748 
1762  virtual char *convertEncoding(const char *to, const char *from, const char *string, size_t length) { return nullptr; }
1764 };
1765 
1766 
1768 extern OSystem *g_system;
1769 
1772 #endif
virtual int getShader() const
Definition: system.h:805
virtual const GraphicsMode * getSupportedShaders() const
Definition: system.h:756
virtual Common::KeymapArray getGlobalKeymaps()
Definition: system.h:1349
GfxModeFlags
Definition: system.h:640
int tm_hour
Definition: system.h:99
virtual Common::UpdateManager * getUpdateManager()
Definition: system.h:1556
Definition: system.h:96
virtual Common::HardwareInputSet * getHardwareInputSet()
Definition: system.h:1338
int id
Definition: system.h:612
virtual bool lockMouse(bool lock)
Definition: system.h:1245
int tm_mday
Definition: system.h:100
Definition: system.h:466
virtual void setFocusRectangle(const Common::Rect &rect)
Definition: system.h:1104
Definition: stream.h:76
virtual void saveScreenshot()
Definition: system.h:1121
Common::UpdateManager * _updateManager
Definition: system.h:212
virtual Common::Array< uint > getSupportedAntiAliasingLevels() const
Definition: system.h:742
virtual int getGraphicsMode() const
Definition: system.h:680
const char * name
Definition: system.h:599
Definition: system.h:592
int tm_min
Definition: system.h:98
virtual const GraphicsMode * getSupportedStretchModes() const
Definition: system.h:816
Feature
Definition: system.h:335
virtual void addSysArchivesToSearchSet(Common::SearchSet &s, int priority=0)
Definition: system.h:1605
Common::TimerManager * _timerManager
Definition: system.h:188
Definition: system.h:113
Definition: system.h:461
Common::TextToSpeechManager * _textToSpeechManager
Definition: system.h:221
virtual TransactionError endGFXTransaction()
Definition: system.h:973
Definition: system.h:481
virtual void engineInit()
Definition: system.h:298
Definition: system.h:448
virtual int getDefaultGraphicsMode() const
Definition: system.h:638
Definition: stream.h:655
Definition: system.h:369
Definition: system.h:364
Common::TaskbarManager * _taskbarManager
Definition: system.h:203
OSystem * g_system
Definition: system.h:476
virtual void resetGraphicsScale()
Definition: system.h:688
virtual Common::DialogManager * getDialogManager()
Definition: system.h:1578
virtual bool setShader(int id)
Definition: system.h:782
Type
Definition: system.h:112
virtual void initSizeHint(const Graphics::ModeList &modes)
Definition: system.h:907
Definition: system.h:116
int tm_wday
Definition: system.h:103
virtual void setWindowCaption(const char *caption)
Definition: system.h:1484
Definition: system.h:435
Common::DialogManager * _dialogManager
Definition: system.h:230
Common::U32String _clipboard
Definition: system.h:248
AudioCDManager * getAudioCDManager()
Definition: system.h:1451
virtual void setCursorPalette(const byte *colors, uint start, uint num)
Definition: system.h:1284
virtual void engineDone()
Definition: system.h:305
virtual char * convertEncoding(const char *to, const char *from, const char *string, size_t length)
Definition: system.h:1762
virtual bool openUrl(const Common::String &url)
Definition: system.h:1719
virtual bool hasTextInClipboard()
Definition: system.h:1683
virtual bool setTextInClipboard(const Common::U32String &text)
Definition: system.h:1705
TransactionError
Definition: system.h:954
virtual int getDefaultShader() const
Definition: system.h:771
virtual bool setGraphicsMode(int mode, uint flags=kGfxModeNoFlags)
Definition: system.h:658
int tm_sec
Definition: system.h:97
virtual bool setStretchMode(int mode)
Definition: system.h:841
Definition: system.h:43
Definition: system.h:39
Definition: system.h:456
virtual bool hasFeature(Feature f)
Definition: system.h:503
Definition: system.h:115
const char * description
Definition: system.h:605
Definition: system.h:403
virtual Common::KeymapperDefaultBindings * getKeymapperDefaultBindings()
Definition: system.h:1358
Common::SaveFileManager * _savefileManager
Definition: system.h:195
virtual int getScreenChangeID() const
Definition: system.h:923
Definition: system.h:409
virtual bool displayLogFile()
Definition: system.h:1672
Definition: system.h:376
int tm_year
Definition: system.h:102
Definition: system.h:340
virtual void init()
Definition: system.h:273
Common::EventManager * getEventManager()
Definition: system.h:1327
Definition: system.h:106
Common::EventManager * _eventManager
Definition: system.h:181
Definition: system.h:486
int tm_mon
Definition: system.h:101
virtual Common::TaskbarManager * getTaskbarManager()
Definition: system.h:1544
virtual int getStretchMode() const
Definition: system.h:864
virtual void beginGFXTransaction()
Definition: system.h:943
virtual Common::TextToSpeechManager * getTextToSpeechManager()
Definition: system.h:1567
Definition: system.h:114
virtual Common::U32String getTextFromClipboard()
Definition: system.h:1694
Definition: system.h:492
bool backendInitialized() const
Definition: system.h:291
virtual void clearFocusRectangle()
Definition: system.h:1114
Definition: system.h:137
virtual const GraphicsMode * getSupportedGraphicsModes() const
Definition: system.h:625
virtual void setFeatureState(Feature f, bool enable)
Definition: system.h:511
FilesystemFactory * _fsFactory
Definition: system.h:242
AudioCDManager * _audiocdManager
Definition: system.h:172
Definition: system.h:416
bool _dummyUnused
Definition: system.h:253
Definition: system.h:35
virtual int getDefaultStretchMode() const
Definition: system.h:830
Definition: system.h:388
virtual bool getFeatureState(Feature f)
Definition: system.h:518