ScummVM API documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
macgui_indy3.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 SCUMM_MACGUI_MACGUI_INDY3_H
23 #define SCUMM_MACGUI_MACGUI_INDY3_H
24 
25 #include "common/events.h"
26 #include "common/rect.h"
27 #include "common/str.h"
28 
29 #include "graphics/surface.h"
30 
31 #include "scumm/macgui/macgui_colors.h"
32 
33 namespace Scumm {
34 
35 class MacGuiImpl;
36 
37 class MacIndy3Gui : public MacGuiImpl {
38 public:
39  enum ScrollDirection {
40  kScrollUp,
41  kScrollDown
42  };
43 
44  MacIndy3Gui(ScummEngine *vm, const Common::Path &resourceFile);
45  ~MacIndy3Gui();
46 
47  const Common::String name() const override { return "Indy"; }
48  int getNumColors() const override { return 16; }
49 
50  Graphics::Surface _textArea;
51 
52  const Graphics::Font *getFontByScummId(int32 id) override;
53 
54  void setupCursor(int &width, int &height, int &hotspotX, int &hotspotY, int &animate) override;
55 
56  Graphics::Surface *textArea() override { return &_textArea; }
57  void clearTextArea() override { _textArea.fillRect(Common::Rect(_textArea.w, _textArea.h), kBlack); }
58  void initTextAreaForActor(Actor *a, byte color) override;
59  void printCharToTextArea(int chr, int x, int y, int color) override;
60 
61  // There is a distinction between the GUI being allowed and being
62  // active. Allowed means that it's allowed to draw verbs, but not that
63  // it necessarily is. Active means that there are verbs on screen. From
64  // the outside, only the latter is relevant.
65  //
66  // One case where this makes a difference is when boxing with the
67  // coach. During the "10 minutes later" sign, the GUI is active but
68  // it's not drawing verbs, so the SCUMM engine is allowed to draw in
69  // the verb area to clear the power meters and text.
70 
71  bool isVerbGuiActive() const override;
72 
73  void reset() override;
74  void resetAfterLoad() override;
75  void update(int delta) override;
76  bool handleEvent(Common::Event event) override;
77 
78 protected:
79  bool getFontParams(FontId fontId, int &id, int &size, int &slant) const override;
80 
81  void updateMenus() override;
82  bool handleMenu(int id, Common::String &name) override;
83 
84  void runAboutDialog() override;
85  bool runOpenDialog(int &saveSlotToHandle) override;
86  bool runSaveDialog(int &saveSlotToHandle, Common::String &saveName) override;
87  bool runOptionsDialog() override;
88  bool runIqPointsDialog();
89 
90 private:
91  int _verbGuiTop = 0;
92  Graphics::Surface _verbGuiSurface;
93 
94  bool _visible = false;
95 
96  bool _leftButtonIsPressed = false;
97  Common::Point _leftButtonPressed;
98  Common::Point _leftButtonHeld;
99 
100  int _timer = 0;
101 
102  bool updateVerbs(int delta);
103  void updateMouseHeldTimer(int delta);
104  void drawVerbs();
105 
106  void clearAboutDialog(MacDialogWindow *window);
107 
108  int getInventoryScrollOffset() const;
109  void setInventoryScrollOffset(int n) const;
110 
111  class Widget : public MacGuiObject {
112  private:
113  int _timer = 0;
114 
115  public:
116  static ScummEngine *_vm;
117  static MacIndy3Gui *_gui;
118  static Graphics::Surface *_surface;
119 
120  Widget(int x, int y, int width, int height);
121  virtual ~Widget() {}
122 
123  void setEnabled(bool enabled) {
124  if (enabled != _enabled)
125  setRedraw(true);
126  if (!_enabled)
127  _timer = 0;
128  _enabled = enabled;
129  }
130 
131  void setTimer(int t) { _timer = t; }
132  void clearTimer() { _timer = 0; }
133  bool hasTimer() const { return _timer > 0; }
134 
135  virtual void setRedraw(bool redraw) { _redraw = redraw; }
136 
137  virtual void reset();
138 
139  virtual bool handleEvent(Common::Event &event) = 0;
140  virtual bool handleMouseHeld(Common::Point &pressed, Common::Point &held) { return false; }
141  virtual void updateTimer(int delta);
142  virtual void timeOut() {}
143 
144  virtual void draw();
145  virtual void undraw();
146 
147  byte translateChar(byte c) const;
148 
149  // Primitives
150  void fill(Common::Rect r);
151  void drawBitmap(Common::Rect r, const uint16 *bitmap, byte color) const;
152  void drawShadowBox(Common::Rect r) const;
153  void drawShadowFrame(Common::Rect r, byte shadowColor, byte fillColor);
154 
155  void markScreenAsDirty(Common::Rect r) const;
156  };
157 
158  class VerbWidget : public Widget {
159  protected:
160  int _verbid = 0;
161  int _verbslot = -1;
162  bool _kill = false;
163 
164  public:
165  VerbWidget(int x, int y, int width, int height) : Widget(x, y, width, height) {}
166 
167  void setVerbid(int n) { _verbid = n; }
168  bool hasVerb() const { return _verbslot != -1; }
169  void threaten() { _kill = true; }
170  bool isDying() const { return _kill; }
171 
172  void reset() override;
173 
174  virtual void updateVerb(int verbslot);
175 
176  void draw() override;
177  void undraw() override;
178  };
179 
180  class Button : public VerbWidget {
181  private:
182  Common::String _text;
183 
184  public:
185  Button(int x, int y, int width, int height);
186 
187  bool handleEvent(Common::Event &event) override;
188 
189  void reset() override;
190  void timeOut() override;
191  void updateVerb(int verbslot) override;
192 
193  void draw() override;
194  };
195 
196  class Inventory : public VerbWidget {
197  private:
198  class ScrollBar : public Widget {
199  private:
200  int _invCount = 0;
201  int _invOffset = 0;
202 
203  public:
204  ScrollBar(int x, int y, int width, int height);
205 
206  void setInventoryParameters(int invCount, int invOffset);
207  void scroll(ScrollDirection dir);
208  int getHandlePosition();
209 
210  void reset() override;
211 
212  bool handleEvent(Common::Event &event) override;
213 
214  void draw() override;
215  };
216 
217  class ScrollButton : public Widget {
218  public:
219  ScrollDirection _direction;
220 
221  ScrollButton(int x, int y, int width, int height, ScrollDirection direction);
222 
223  bool handleEvent(Common::Event &event) override;
224  bool handleMouseHeld(Common::Point &pressed, Common::Point &held) override;
225  void timeOut() override;
226 
227  void draw() override;
228  };
229 
230  class Slot : public Widget {
231  private:
232  Common::String _name;
233  int _slot = -1;
234  int _obj = -1;
235 
236  public:
237  Slot(int slot, int x, int y, int width, int height);
238 
239  void clearName() { _name.clear(); }
240  bool hasName() const { return !_name.empty(); }
241 
242  void clearObject();
243  void setObject(int n);
244  int getObject() const { return _obj; }
245 
246  void reset() override;
247 
248  bool handleEvent(Common::Event &event) override;
249  void timeOut() override;
250 
251  void draw() override;
252  };
253 
254  Slot *_slots[6];
255  ScrollBar *_scrollBar;
256  ScrollButton *_scrollButtons[2];
257 
258  static const uint16 _upArrow[16];
259  static const uint16 _downArrow[16];
260 
261  public:
262  Inventory(int x, int y, int width, int height);
263  ~Inventory();
264 
265  void setRedraw(bool redraw) override;
266 
267  void reset() override;
268 
269  bool handleEvent(Common::Event &event) override;
270  bool handleMouseHeld(Common::Point &pressed, Common::Point &held) override;
271  void updateTimer(int delta) override;
272  void updateVerb(int verbslot) override;
273 
274  void draw() override;
275  };
276 
278  Common::Array<Common::Rect> _dirtyRects;
279 
280  bool isVerbGuiAllowed() const;
281 
282  void show();
283  void hide();
284 
285  void fill(Common::Rect r);
286 
287  void markScreenAsDirty(Common::Rect r);
288  void copyDirtyRectsToScreen();
289 };
290 
291 } // End of namespace Scumm
292 #endif
Definition: macgui_impl.h:52
Definition: str.h:59
Definition: font.h:83
Definition: surface.h:67
int16 h
Definition: surface.h:76
Definition: rect.h:144
Definition: path.h:52
Definition: macgui_indy3.h:37
Definition: scumm.h:504
Definition: hashmap.h:85
Definition: events.h:199
Definition: macgui_impl.h:655
Definition: rect.h:45
Definition: macgui_impl.h:249
Definition: actor.h:97
int16 w
Definition: surface.h:71
void fillRect(Common::Rect r, uint32 color)
Definition: actor.h:30