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 };
98 
99 }
100 using namespace MacGUIConstants;
101 
102 class Cursor;
103 
104 class ManagedSurface;
105 
106 class MacCursor;
107 class MacMenu;
108 class MacTextWindow;
109 class MacWidget;
110 
111 class MacFont;
112 
113 class MacFontManager;
114 
115 typedef Common::Array<const byte *> MacPatterns;
116 
117 struct MacPlotData {
118  Graphics::ManagedSurface *surface;
120  MacPatterns *patterns;
121  uint fillType;
122  int fillOriginX;
123  int fillOriginY;
124  int thickness;
125  uint bgColor;
126  bool invert;
127 
128  MacPlotData(Graphics::ManagedSurface *s, Graphics::ManagedSurface *m, MacPatterns *p, uint f, int fx, int fy, int t, uint bg, bool inv = false) :
129  surface(s), mask(m), patterns(p), fillType(f), fillOriginX(fx), fillOriginY(fy), thickness(t), bgColor(bg), invert(inv) {
130  }
131 };
132 
133 struct ZoomBox {
134  Common::Rect start;
135  Common::Rect end;
137  int delay;
138  int step;
139  uint32 startTime;
140  uint32 nextTime;
141 };
142 
148 public:
149  MacWindowManager(uint32 mode = 0, MacPatterns *patterns = nullptr, Common::Language language = Common::UNK_LANG);
150  ~MacWindowManager();
151 
152  Primitives &getDrawPrimitives() const { return *_macDrawPrimitives; }
153  Primitives &getDrawInvertPrimitives() const;
154 
160  void setScreen(ManagedSurface *screen);
161 
167  void setScreen(int w, int h);
168 
169  int getWidth();
170 
171  int getHeight();
172 
181  MacWindow *addWindow(bool scrollable, bool resizable, bool editable);
182  MacTextWindow *addTextWindow(const MacFont *font, int fgcolor, int bgcolor, int maxWidth, TextAlign textAlignment, MacMenu *menu, int padding = 0);
183  MacTextWindow *addTextWindow(const Font *font, int fgcolor, int bgcolor, int maxWidth, TextAlign textAlignment, MacMenu *menu, int padding = 0);
184  void resizeScreen(int w, int h);
185 
191  void addWindowInitialized(MacWindow *macwindow);
196  int getLastId() { return _lastId; }
201  int getNextId() { return _lastId++; }
208  MacMenu *addMenu();
209  void addMenu(int id, MacMenu *menu);
210 
211  void removeMenu();
212  void activateMenu();
213 
214  void activateScreenCopy();
215  void disableScreenCopy();
216 
217  bool isMenuActive();
218  void setDesktopMode(uint32 mode);
219 
223  void setMenuHotzone(const Common::Rect &rect) { _menuHotzone = rect; }
224 
228  void setMenuDelay(int delay) { _menuDelay = delay; }
229 
234  void setActiveWindow(int id);
235 
236  int getActiveWindow() { return _activeWindow; }
237 
243  MacWindow *findWindowAtPoint(int16 x, int16 y);
248  MacWindow *findWindowAtPoint(Common::Point point);
249 
255  void removeWindow(MacWindow *target);
256 
261  void setFullRefresh(bool redraw) { _fullRefresh = redraw; }
262 
269  void draw();
270 
278  bool processEvent(Common::Event &event);
279 
286  if (id >= 0 && id < (int)_windows.size())
287  return _windows[id];
288  return nullptr;
289  }
290 
295  MacPatterns &getPatterns() { return _patterns; }
296 
302  void setActiveWidget(MacWidget *widget);
303 
310  void setLockedWidget(MacWidget *widget);
311 
317  void setBackgroundWindow(MacWindow *window);
318 
319  MacPatterns &getBuiltinPatterns() { return _builtinPatterns; }
320 
321  MacWidget *getActiveWidget() { return _activeWidget; }
322  MacWidget *getLockedWidget() { return _lockedWidget; }
323 
324  Common::Rect getScreenBounds() { return _screen ? _screen->getBounds() : _screenDims; }
325 
326  void clearWidgetRefs(MacWidget *widget);
327 
328  void printWMMode(int debuglevel = 0);
329 
330 private:
331  void replaceCursorType(MacCursorType type);
332 
333 public:
334  MacCursorType getCursorType() const;
335 
336  void pushCursor(MacCursorType type, Cursor *cursor = nullptr);
337  void replaceCursor(MacCursorType type, Cursor *cursor = nullptr);
338 
339  void pushCustomCursor(const byte *data, int w, int h, int hx, int hy, int transcolor);
340  void replaceCustomCursor(const byte *data, int w, int h, int hx, int hy, int transcolor);
341  void pushCustomCursor(const Graphics::Cursor *cursor);
342  void popCursor();
343 
344  PauseToken pauseEngine();
345 
346  void setMode(uint32 mode);
347 
348  void setEngine(Engine *engine);
349  void setEngineRedrawCallback(void *engine, void (*redrawCallback)(void *engine));
350  void setEngineActivateMenuCallback(void *engine, void (*redrawCallback)(void *engine));
351 
352  void passPalette(const byte *palette, uint size);
353  template <typename T> void decomposeColor(uint32 color, byte &r, byte &g, byte &b);
354  uint32 findBestColor(byte cr, byte cg, byte cb);
355  uint32 findBestColor(uint32 color);
356  void setDesktopColor(byte, byte, byte);
357 
358  byte inverter(byte src);
359 
360  const byte *getPalette() { return _palette; }
361  uint getPaletteSize() { return _paletteSize; }
362 
363  void renderZoomBox(bool redraw = false);
364  void addZoomBox(ZoomBox *box);
365 
366  void removeMarked();
367 
368  void loadDataBundle();
369  void cleanupDataBundle();
370  void cleanupDesktopBmp();
371 
372  const BorderOffsets &getBorderOffsets(uint32 windowType);
373  Common::SeekableReadStream *getBorderFile(uint32 windowType, uint32 flags);
374  Common::SeekableReadStream *getFile(const Common::Path &filename);
375 
376  void setTextInClipboard(const Common::U32String &str);
382  Common::U32String getTextFromClipboard(const Common::U32String &format = Common::U32String(), int *size = nullptr);
383 
389  void clearHandlingWidgets();
390 
391  void setMenuItemCheckMark(MacMenuItem *menuItem, bool checkMark);
392  void setMenuItemEnabled(MacMenuItem *menuItem, bool enabled);
393  void setMenuItemName(MacMenuItem *menuItem, const Common::String &name);
394  void setMenuItemAction(MacMenuItem *menuItem, int actionId);
395 
396  bool getMenuItemCheckMark(MacMenuItem *menuItem);
397  bool getMenuItemEnabled(MacMenuItem *menuItem);
398  Common::String getMenuItemName(MacMenuItem *menuItem);
399  int getMenuItemAction(MacMenuItem *menuItem);
400  MacMenu *getMenu();
401  MacMenu *getMenu(int id);
402 
403  void sayText(const Common::U32String &text) const;
404  void setTTSEnabled(bool enabled);
405 
406 public:
407  MacFontManager *_fontMan;
408  uint32 _mode;
409  Common::Language _language;
410 
411  Common::Point _lastClickPos;
412  Common::Point _lastMousePos;
413  Common::Rect _menuHotzone;
414 
415  uint32 _menuTimer;
416  bool _mouseDown;
417 
418  uint32 _colorBlack, _colorGray80, _colorGray88, _colorGrayEE, _colorWhite, _colorGreen, _colorGreen2;
419 
420  MacWidget *_hoveredWidget;
421 
422  // we use it to indicate whether we are clicking the hilite-able widget.
423  // In list style button mode, we will highlight the subsequent buttons only when we've clicked the hilite-able button initially
424  bool _hilitingWidget;
425 
426 private:
427  void loadDesktop();
428  void drawDesktop();
429 
430  void removeFromStack(BaseMacWindow *target);
431  void removeFromWindowList(BaseMacWindow *target);
432 
433  void zoomBoxInner(Common::Rect &r, Graphics::MacPlotData &pd);
434  bool haveZoomBox() { return !_zoomBoxes.empty(); }
435 
436  void adjustDimensions(const Common::Rect &clip, const Common::Rect &dims, int &adjWidth, int &adjHeight);
437 
438 public:
439  Surface *_desktopBmp;
440  ManagedSurface *_desktop;
441  PixelFormat _pixelformat;
442 
443  ManagedSurface *_screen;
444  ManagedSurface *_screenCopy;
445  Common::Rect _screenDims;
446 
447 private:
448  Common::Mutex _mutex;
449  Common::List<BaseMacWindow *> _windowStack;
451 
452  Common::List<BaseMacWindow *> _windowsToRemove;
453  bool _needsRemoval;
454 
455  int _lastId;
456  int _activeWindow;
457 
458  bool _fullRefresh;
459 
460  bool _inEditableArea;
461 
462  Primitives *_macDrawPrimitives;
463  Primitives *_macDrawInvertPrimitives;
464 
465  MacPatterns _patterns;
466  MacPatterns _builtinPatterns;
467  byte *_palette;
468  uint _paletteSize;
469 
470  MacMenu *_menu;
471  uint32 _menuDelay;
472 
473  Engine *_engineP;
474  void *_engineR;
475  void (*_redrawEngineCallback)(void *engine);
476  void *_engineAM;
477  void (*_activateMenuCallback)(void *engine);
478 
479  MacCursorType _tempType = kMacCursorArrow;
480  Common::Stack<MacCursorType> _cursorTypeStack;
481  Cursor *_cursor = nullptr;
482 
483  MacWidget *_activeWidget;
484  MacWidget *_lockedWidget;
485  MacWindow *_backgroundWindow;
486 
487  PauseToken *_screenCopyPauseToken;
488 
489  Common::Array<ZoomBox *> _zoomBoxes;
490  Graphics::PaletteLookup _paletteLookup;
491  Common::HashMap<uint, uint> _invertColorHash;
492 
493  Common::Archive *_dataBundle;
494 
495  Common::U32String _clipboard;
496 
497  bool _ttsEnabled;
498 };
499 
500 const Common::U32String::value_type *readHex(uint16 *res, const Common::U32String::value_type *s, int len);
501 
502 } // End of namespace Graphics
503 
504 #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:285
Definition: pixelformat.h:138
Definition: macfontmanager.h:148
Definition: macwindow.h:203
Definition: mactextwindow.h:30
Definition: macwindowmanager.h:133
MacPatterns & getPatterns()
Definition: macwindowmanager.h:295
Definition: palette.h:189
Definition: list.h:44
Definition: rect.h:524
Definition: path.h:52
void setMenuHotzone(const Common::Rect &rect)
Definition: macwindowmanager.h:223
Definition: stream.h:745
Definition: macwindowmanager.h:147
int getNextId()
Definition: macwindowmanager.h:201
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:117
Definition: macfontmanager.h:106
int getLastId()
Definition: macwindowmanager.h:196
Definition: macmenu.h:59
Definition: macwindow.h:78
Definition: engine.h:144
void setMenuDelay(int delay)
Definition: macwindowmanager.h:228
Language
Definition: language.h:45
void setFullRefresh(bool redraw)
Definition: macwindowmanager.h:261