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