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