ScummVM API documentation
macwindowmanager.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 #ifndef GRAPHICS_MACGUI_MACWINDOWMANAGER_H
23 #define GRAPHICS_MACGUI_MACWINDOWMANAGER_H
24 
25 #include "common/hashmap.h"
26 #include "common/list.h"
27 #include "common/mutex.h"
28 #include "common/stack.h"
29 #include "common/events.h"
30 
31 #include "graphics/font.h"
32 #include "graphics/fontman.h"
33 #include "graphics/palette.h"
34 #include "graphics/macgui/macwindow.h"
35 #include "graphics/macgui/macmenu.h"
36 
37 #include "engines/engine.h"
38 
39 namespace Common {
40 class Archive;
41 }
42 
43 namespace Graphics {
44 
45 namespace MacGUIConstants {
46 enum {
47  kDesktopArc = 7
48 };
49 
50 enum {
51  kColorBlack = 0,
52  kColorGray80 = 1,
53  kColorGray88 = 2,
54  kColorGrayEE = 3,
55  kColorWhite = 4,
56  kColorGreen = 5,
57  kColorGreen2 = 6,
58  kColorCount
59 };
60 
61 enum {
62  kPatternSolid = 1,
63  kPatternStripes = 2,
64  kPatternCheckers = 3,
65  kPatternCheckers2 = 4,
66  kPatternLightGray = 5,
67  kPatternDarkGray = 6
68 };
69 
70 enum MacCursorType {
71  kMacCursorArrow,
72  kMacCursorBeam,
73  kMacCursorCrossHair,
74  kMacCursorCrossBar,
75  kMacCursorWatch,
76  kMacCursorCustom,
77  kMacCursorOff
78 };
79 
80 enum {
81  kWMModeNone = 0,
82  kWMModeNoDesktop = (1 << 0),
83  kWMModeAutohideMenu = (1 << 1),
84  kWMModalMenuMode = (1 << 2),
85  kWMModeForceBuiltinFonts = (1 << 3),
86  kWMModeUnicode = (1 << 4),
87  kWMModeManualDrawWidgets = (1 << 5),
88  kWMModeFullscreen = (1 << 6),
89  kWMModeButtonDialogStyle = (1 << 7),
90  kWMMode32bpp = (1 << 8),
91  kWMNoScummVMWallpaper = (1 << 9),
92  kWMModeWin95 = (1 << 10),
93  kWMModeForceMacFontsInWin95 = (1 << 11), // Enforce Mac font for languages which don't have glyphs in ms_sans_serif.ttf
94  kWMModeNoCursorOverride = (1 << 12),
95  kWMModeForceMacBorder = (1 << 13),
96  kWMModeForceMacFonts = (1 << 14), // Enforce Mac fonts even when there are viable TTF substitutions
97  kWMModeNoSystemRedraw = (1 << 15), // Skip g_system->copyRectToScreen (for 3D game backends)
98 };
99 
100 }
101 using namespace MacGUIConstants;
102 
103 class Cursor;
104 
105 class ManagedSurface;
106 
107 class MacCursor;
108 class MacMenu;
109 class MacTextWindow;
110 class MacWidget;
111 
112 class MacFont;
113 
114 class MacFontManager;
115 
116 typedef Common::Array<const byte *> MacPatterns;
117 
118 struct MacPlotData {
119  Graphics::ManagedSurface *surface;
121  MacPatterns *patterns;
122  uint fillType;
123  int fillOriginX;
124  int fillOriginY;
125  int thickness;
126  uint bgColor;
127  bool invert;
128 
129  MacPlotData(Graphics::ManagedSurface *s, Graphics::ManagedSurface *m, MacPatterns *p, uint f, int fx, int fy, int t, uint bg, bool inv = false) :
130  surface(s), mask(m), patterns(p), fillType(f), fillOriginX(fx), fillOriginY(fy), thickness(t), bgColor(bg), invert(inv) {
131  }
132 };
133 
134 struct ZoomBox {
135  Common::Rect start;
136  Common::Rect end;
138  int delay;
139  int step;
140  uint32 startTime;
141  uint32 nextTime;
142 };
143 
149 public:
150  MacWindowManager(uint32 mode = 0, MacPatterns *patterns = nullptr, Common::Language language = Common::UNK_LANG);
151  ~MacWindowManager();
152 
153  Primitives &getDrawPrimitives() const { return *_macDrawPrimitives; }
154  Primitives &getDrawInvertPrimitives() const;
155 
161  void setScreen(ManagedSurface *screen);
162 
168  void setScreen(int w, int h);
169 
170  int getWidth();
171 
172  int getHeight();
173 
182  MacWindow *addWindow(bool scrollable, bool resizable, bool editable);
183  MacTextWindow *addTextWindow(const MacFont *font, int fgcolor, int bgcolor, int maxWidth, TextAlign textAlignment, MacMenu *menu, int padding = 0);
184  MacTextWindow *addTextWindow(const Font *font, int fgcolor, int bgcolor, int maxWidth, TextAlign textAlignment, MacMenu *menu, int padding = 0);
185  void resizeScreen(int w, int h);
186 
192  void addWindowInitialized(MacWindow *macwindow);
197  int getLastId() { return _lastId; }
202  int getNextId() { return _lastId++; }
209  MacMenu *addMenu();
210  void addMenu(int id, MacMenu *menu);
211 
212  void removeMenu();
213  void activateMenu();
214 
215  void activateScreenCopy();
216  void disableScreenCopy();
217 
218  bool isMenuActive();
219  void setDesktopMode(uint32 mode);
220 
224  void setMenuHotzone(const Common::Rect &rect) { _menuHotzone = rect; }
225 
229  void setMenuDelay(int delay) { _menuDelay = delay; }
230 
235  void setActiveWindow(int id);
236 
237  int getActiveWindow() { return _activeWindow; }
238 
244  MacWindow *findWindowAtPoint(int16 x, int16 y);
249  MacWindow *findWindowAtPoint(Common::Point point);
250 
256  void removeWindow(MacWindow *target);
257 
262  void setFullRefresh(bool redraw) { _fullRefresh = redraw; }
263 
270  void draw();
271 
279  bool processEvent(Common::Event &event);
280 
287  if (id >= 0 && id < (int)_windows.size())
288  return _windows[id];
289  return nullptr;
290  }
291 
296  MacPatterns &getPatterns() { return _patterns; }
297 
303  void setActiveWidget(MacWidget *widget);
304 
311  void setLockedWidget(MacWidget *widget);
312 
318  void setBackgroundWindow(MacWindow *window);
319 
320  MacPatterns &getBuiltinPatterns() { return _builtinPatterns; }
321 
322  MacWidget *getActiveWidget() { return _activeWidget; }
323  MacWidget *getLockedWidget() { return _lockedWidget; }
324 
325  Common::Rect getScreenBounds() { return _screen ? _screen->getBounds() : _screenDims; }
326 
327  void clearWidgetRefs(MacWidget *widget);
328 
329  void printWMMode(int debuglevel = 0);
330 
331 private:
332  void replaceCursorType(MacCursorType type);
333 
334 public:
335  MacCursorType getCursorType() const;
336  static bool getBuiltInCursorData(MacCursorType type, const byte *&data, const byte *&palette,
337  const byte *&mask, int &w, int &h, int &hotspotX, int &hotspotY, int &transColor);
338 
339  void pushCursor(MacCursorType type, Cursor *cursor = nullptr);
340  void replaceCursor(MacCursorType type, Cursor *cursor = nullptr);
341 
342  void pushCustomCursor(const byte *data, int w, int h, int hx, int hy, int transcolor);
343  void replaceCustomCursor(const byte *data, int w, int h, int hx, int hy, int transcolor);
344  void pushCustomCursor(const Graphics::Cursor *cursor);
345  void popCursor();
346 
347  PauseToken pauseEngine();
348 
349  void setMode(uint32 mode);
350 
351  void setEngine(Engine *engine);
352  void setEngineRedrawCallback(void *engine, void (*redrawCallback)(void *engine));
353  void setEngineActivateMenuCallback(void *engine, void (*redrawCallback)(void *engine));
354 
355  void passPalette(const byte *palette, uint size);
356  template <typename T> void decomposeColor(uint32 color, byte &r, byte &g, byte &b);
357  uint32 findBestColor(byte cr, byte cg, byte cb);
358  uint32 findBestColor(uint32 color);
359  void setDesktopColor(byte, byte, byte);
360 
361  byte inverter(byte src);
362 
363  const byte *getPalette() { return _palette; }
364  uint getPaletteSize() { return _paletteSize; }
365 
366  void renderZoomBox(bool redraw = false);
367  void addZoomBox(ZoomBox *box);
368 
369  void removeMarked();
370 
371  void loadDataBundle();
372  void cleanupDataBundle();
373  void cleanupDesktopBmp();
374 
375  const BorderOffsets &getBorderOffsets(uint32 windowType);
376  Common::SeekableReadStream *getBorderFile(uint32 windowType, uint32 flags);
377  Common::SeekableReadStream *getFile(const Common::Path &filename);
378 
379  void setTextInClipboard(const Common::U32String &str);
385  Common::U32String getTextFromClipboard(const Common::U32String &format = Common::U32String(), int *size = nullptr);
386 
392  void clearHandlingWidgets();
393 
394  void setMenuItemCheckMark(MacMenuItem *menuItem, bool checkMark);
395  void setMenuItemEnabled(MacMenuItem *menuItem, bool enabled);
396  void setMenuItemName(MacMenuItem *menuItem, const Common::String &name);
397  void setMenuItemAction(MacMenuItem *menuItem, int actionId);
398 
399  bool getMenuItemCheckMark(MacMenuItem *menuItem);
400  bool getMenuItemEnabled(MacMenuItem *menuItem);
401  Common::String getMenuItemName(MacMenuItem *menuItem);
402  int getMenuItemAction(MacMenuItem *menuItem);
403  MacMenu *getMenu();
404  MacMenu *getMenu(int id);
405 
406  void sayText(const Common::U32String &text) const;
407  void setTTSEnabled(bool enabled);
408 
409 public:
410  MacFontManager *_fontMan;
411  uint32 _mode;
412  Common::Language _language;
413 
414  Common::Point _lastClickPos;
415  Common::Point _lastMousePos;
416  Common::Rect _menuHotzone;
417 
418  uint32 _menuTimer;
419  bool _mouseDown;
420 
421  uint32 _colorBlack, _colorGray80, _colorGray88, _colorGrayEE, _colorWhite, _colorGreen, _colorGreen2;
422 
423  MacWidget *_hoveredWidget;
424 
425  // we use it to indicate whether we are clicking the hilite-able widget.
426  // In list style button mode, we will highlight the subsequent buttons only when we've clicked the hilite-able button initially
427  bool _hilitingWidget;
428 
429 private:
430  void loadDesktop();
431  void drawDesktop();
432 
433  void removeFromStack(BaseMacWindow *target);
434  void removeFromWindowList(BaseMacWindow *target);
435 
436  void zoomBoxInner(Common::Rect &r, Graphics::MacPlotData &pd);
437  bool haveZoomBox() { return !_zoomBoxes.empty(); }
438 
439  void adjustDimensions(const Common::Rect &clip, const Common::Rect &dims, int &adjWidth, int &adjHeight);
440 
441 public:
442  Surface *_desktopBmp;
443  ManagedSurface *_desktop;
444  PixelFormat _pixelformat;
445 
446  ManagedSurface *_screen;
447  ManagedSurface *_screenCopy;
448  Common::Rect _screenDims;
449 
450 private:
451  Common::Mutex _mutex;
452  Common::List<BaseMacWindow *> _windowStack;
454 
455  Common::List<BaseMacWindow *> _windowsToRemove;
456  bool _needsRemoval;
457 
458  int _lastId;
459  int _activeWindow;
460 
461  bool _fullRefresh;
462 
463  bool _inEditableArea;
464 
465  Primitives *_macDrawPrimitives;
466  Primitives *_macDrawInvertPrimitives;
467 
468  MacPatterns _patterns;
469  MacPatterns _builtinPatterns;
470  byte *_palette;
471  uint _paletteSize;
472 
473  MacMenu *_menu;
474  uint32 _menuDelay;
475 
476  Engine *_engineP;
477  void *_engineR;
478  void (*_redrawEngineCallback)(void *engine);
479  void *_engineAM;
480  void (*_activateMenuCallback)(void *engine);
481 
482  MacCursorType _tempType = kMacCursorArrow;
483  Common::Stack<MacCursorType> _cursorTypeStack;
484  Cursor *_cursor = nullptr;
485 
486  MacWidget *_activeWidget;
487  MacWidget *_lockedWidget;
488  MacWindow *_backgroundWindow;
489 
490  PauseToken *_screenCopyPauseToken;
491 
492  Common::Array<ZoomBox *> _zoomBoxes;
493  Graphics::PaletteLookup _paletteLookup;
494  Common::HashMap<uint, uint> _invertColorHash;
495 
496  Common::Archive *_dataBundle;
497 
498  Common::U32String _clipboard;
499 
500  bool _ttsEnabled;
501 };
502 
503 const Common::U32String::value_type *readHex(uint16 *res, const Common::U32String::value_type *s, int len);
504 
505 } // End of namespace Graphics
506 
507 #endif
Definition: managed_surface.h:51
Definition: engine.h:105
Definition: str.h:59
Definition: font.h:83
TextAlign
Definition: font.h:48
Definition: surface.h:67
BaseMacWindow * getWindow(int id)
Definition: macwindowmanager.h:286
Definition: pixelformat.h:138
Definition: macfontmanager.h:152
Definition: macwindow.h:205
Definition: mactextwindow.h:30
Definition: macwindowmanager.h:134
MacPatterns & getPatterns()
Definition: macwindowmanager.h:296
Definition: palette.h:195
Definition: list.h:44
Definition: rect.h:524
Definition: path.h:52
void setMenuHotzone(const Common::Rect &rect)
Definition: macwindowmanager.h:224
Definition: stream.h:745
Definition: macwindowmanager.h:148
int getNextId()
Definition: macwindowmanager.h:202
Definition: archive.h:141
Definition: macwindowborder.h:57
Definition: primitives.h:29
Definition: hashmap.h:85
Definition: ustr.h:57
Definition: atari-cursor.h:35
Definition: cursor.h:42
Definition: events.h:210
Definition: algorithm.h:29
Definition: formatinfo.h:28
Definition: mutex.h:67
Definition: rect.h:144
Definition: macwidget.h:39
Definition: macmenu.h:94
Definition: macwindowmanager.h:118
Definition: macfontmanager.h:110
int getLastId()
Definition: macwindowmanager.h:197
Definition: macmenu.h:59
Definition: macwindow.h:80
Definition: engine.h:144
void setMenuDelay(int delay)
Definition: macwindowmanager.h:229
Language
Definition: language.h:45
void setFullRefresh(bool redraw)
Definition: macwindowmanager.h:262