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 #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  bool handleMenu(int id, Common::String &name) override;
82 
83  void runAboutDialog() override;
84  bool runOpenDialog(int &saveSlotToHandle) override;
85  bool runSaveDialog(int &saveSlotToHandle, Common::String &saveName) override;
86  bool runOptionsDialog() override;
87  bool runIqPointsDialog();
88 
89 private:
90  int _verbGuiTop = 0;
91  Graphics::Surface _verbGuiSurface;
92 
93  bool _visible = false;
94 
95  bool _leftButtonIsPressed = false;
96  Common::Point _leftButtonPressed;
97  Common::Point _leftButtonHeld;
98 
99  int _timer = 0;
100 
101  bool updateVerbs(int delta);
102  void updateMouseHeldTimer(int delta);
103  void drawVerbs();
104 
105  void clearAboutDialog(MacDialogWindow *window);
106 
107  int getInventoryScrollOffset() const;
108  void setInventoryScrollOffset(int n) const;
109 
110  class Widget : public MacGuiObject {
111  private:
112  int _timer = 0;
113 
114  public:
115  static ScummEngine *_vm;
116  static MacIndy3Gui *_gui;
117  static Graphics::Surface *_surface;
118 
119  Widget(int x, int y, int width, int height);
120  virtual ~Widget() {}
121 
122  void setEnabled(bool enabled) {
123  if (enabled != _enabled)
124  setRedraw(true);
125  if (!_enabled)
126  _timer = 0;
127  _enabled = enabled;
128  }
129 
130  void setTimer(int t) { _timer = t; }
131  void clearTimer() { _timer = 0; }
132  bool hasTimer() const { return _timer > 0; }
133 
134  virtual void setRedraw(bool redraw) { _redraw = redraw; }
135 
136  virtual void reset();
137 
138  virtual bool handleEvent(Common::Event &event) = 0;
139  virtual bool handleMouseHeld(Common::Point &pressed, Common::Point &held) { return false; }
140  virtual void updateTimer(int delta);
141  virtual void timeOut() {}
142 
143  virtual void draw();
144  virtual void undraw();
145 
146  byte translateChar(byte c) const;
147 
148  // Primitives
149  void fill(Common::Rect r);
150  void drawBitmap(Common::Rect r, const uint16 *bitmap, byte color) const;
151  void drawShadowBox(Common::Rect r) const;
152  void drawShadowFrame(Common::Rect r, byte shadowColor, byte fillColor);
153 
154  void markScreenAsDirty(Common::Rect r) const;
155  };
156 
157  class VerbWidget : public Widget {
158  protected:
159  int _verbid = 0;
160  int _verbslot = -1;
161  bool _kill = false;
162 
163  public:
164  VerbWidget(int x, int y, int width, int height) : Widget(x, y, width, height) {}
165 
166  void setVerbid(int n) { _verbid = n; }
167  bool hasVerb() const { return _verbslot != -1; }
168  void threaten() { _kill = true; }
169  bool isDying() const { return _kill; }
170 
171  void reset();
172 
173  virtual void updateVerb(int verbslot);
174 
175  void draw();
176  void undraw();
177  };
178 
179  class Button : public VerbWidget {
180  private:
181  Common::String _text;
182 
183  public:
184  Button(int x, int y, int width, int height);
185 
186  bool handleEvent(Common::Event &event);
187 
188  void reset();
189  void timeOut();
190  void updateVerb(int verbslot);
191 
192  void draw();
193  };
194 
195  class Inventory : public VerbWidget {
196  private:
197  class ScrollBar : public Widget {
198  private:
199  int _invCount = 0;
200  int _invOffset = 0;
201 
202  public:
203  ScrollBar(int x, int y, int width, int height);
204 
205  void setInventoryParameters(int invCount, int invOffset);
206  void scroll(ScrollDirection dir);
207  int getHandlePosition();
208 
209  void reset();
210 
211  bool handleEvent(Common::Event &event);
212 
213  void draw();
214  };
215 
216  class ScrollButton : public Widget {
217  public:
218  ScrollDirection _direction;
219 
220  ScrollButton(int x, int y, int width, int height, ScrollDirection direction);
221 
222  bool handleEvent(Common::Event &event);
223  bool handleMouseHeld(Common::Point &pressed, Common::Point &held);
224  void timeOut();
225 
226  void draw();
227  };
228 
229  class Slot : public Widget {
230  private:
231  Common::String _name;
232  int _slot = -1;
233  int _obj = -1;
234 
235  public:
236  Slot(int slot, int x, int y, int width, int height);
237 
238  void clearName() { _name.clear(); }
239  bool hasName() const { return !_name.empty(); }
240 
241  void clearObject();
242  void setObject(int n);
243  int getObject() const { return _obj; }
244 
245  void reset();
246 
247  bool handleEvent(Common::Event &event);
248  void timeOut();
249 
250  void draw();
251  };
252 
253  Slot *_slots[6];
254  ScrollBar *_scrollBar;
255  ScrollButton *_scrollButtons[2];
256 
257  static const uint16 _upArrow[16];
258  static const uint16 _downArrow[16];
259 
260  public:
261  Inventory(int x, int y, int width, int height);
262  ~Inventory();
263 
264  void setRedraw(bool redraw);
265 
266  void reset();
267 
268  bool handleEvent(Common::Event &event);
269  bool handleMouseHeld(Common::Point &pressed, Common::Point &held);
270  void updateTimer(int delta);
271  void updateVerb(int verbslot);
272 
273  void draw();
274  };
275 
277  Common::Array<Common::Rect> _dirtyRects;
278 
279  bool isVerbGuiAllowed() const;
280 
281  void show();
282  void hide();
283 
284  void fill(Common::Rect r);
285 
286  void markScreenAsDirty(Common::Rect r);
287  void copyDirtyRectsToScreen();
288 };
289 
290 } // End of namespace Scumm
291 #endif
Definition: macgui_impl.h:55
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:518
Definition: hashmap.h:85
Definition: events.h:199
Definition: macgui_impl.h:580
Definition: rect.h:45
Definition: macgui_impl.h:237
Definition: actor.h:97
int16 w
Definition: surface.h:71
void fillRect(Common::Rect r, uint32 color)
Definition: actor.h:30