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