ScummVM API documentation
button.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  * Based on the original sources
22  * Faery Tale II -- The Halls of the Dead
23  * (c) 1993-1996 The Wyrmkeep Entertainment Co.
24  */
25 
26 #ifndef SAGA2_BUTTON_H
27 #define SAGA2_BUTTON_H
28 
29 #include "saga2/panel.h"
30 #include "saga2/cmisc.h"
31 #include "saga2/floating.h"
32 #include "saga2/idtypes.h"
33 
34 //#include "saga2/sprite.h"
35 
36 namespace Saga2 {
37 
38 struct Sprite;
39 class hResContext;
40 
41 /* ======================================================================= *
42  Misc. Structs and classes
43  * ======================================================================= */
44 
46  uint8 dlPen;
47  uint8 urPen;
48  uint8 inPen;
49  uint8 dlHilitePen;
50  uint8 urHilitePen;
51  uint8 inHilitePen;
52 };
53 
54 struct textPallete {
55  uint8 dlPen;
56  uint8 urPen;
57  uint8 inPen;
58  uint8 dlHilitePen;
59  uint8 urHilitePen;
60  uint8 inHilitePen;
61 
62  // default constructor
63  textPallete() {
64  dlPen = urPen = inPen = dlHilitePen = urHilitePen = inHilitePen = 0;
65  }
66 
67  textPallete(uint8 dlP, uint8 urP, uint8 inP, uint8 dlHP, uint8 urHP, uint8 inHP) {
68  set(dlP, urP, inP, dlHP, urHP, inHP);
69  }
70 
72  dlPen = pal.dlPen;
73  urPen = pal.urPen;
74  inPen = pal.inPen;
75  dlHilitePen = pal.dlHilitePen;
76  urHilitePen = pal.urHilitePen;
77  inHilitePen = pal.inHilitePen;
78  }
79 
80  void set(uint8 dlP, uint8 urP, uint8 inP, uint8 dlHP, uint8 urHP, uint8 inHP) {
81  dlPen = dlP;
82  urPen = urP;
83  inPen = inP;
84  dlHilitePen = dlHP;
85  urHilitePen = urHP;
86  inHilitePen = inHP;
87  }
88 };
89 
90 class GameObject;
91 
92 /* ======================================================================= *
93  Compressed image class
94  * ======================================================================= */
95 
96 class GfxCompImage : public gControl {
97 private:
98 
99  // number of image pointer allocated
100  uint16 _numPtrAlloc;
101  bool _internalAlloc;
102 
103 protected:
104  void **_compImages; // double pointer(s) the compressed image(s)
105  uint16 _currentImage; // current image index
106  uint16 _max, _min; // min max of the index
107  textPallete _textPal; // contains info about coloring for multi-depth text rendering
108  gFont *_textFont; // pointer to font for this button
109 
110 protected:
111  virtual void *getCurrentCompImage(); // get the current image
112 
113  void init();
114 
115 public:
116 
117  enum controlValue {
118  kEnter = (1 << 0),
119  kLeave = (1 << 1)
120  };
121 
122  GfxCompImage(gPanelList &, const Rect16 &, void *, uint16, AppFunc *cmd = NULL);
123 
124  GfxCompImage(gPanelList &, const Rect16 &, void *, const char *,
125  textPallete &, uint16, AppFunc *cmd = NULL);
126 
127  GfxCompImage(gPanelList &, const Rect16 &, void **, int16, int16,
128  uint16, AppFunc *cmd = NULL);
129 
130  GfxCompImage(gPanelList &, const Rect16 &, void **, int16, int16,
131  const char *, textPallete &, uint16, AppFunc *cmd = NULL);
132 
133  GfxCompImage(gPanelList &list,
134  const Rect16 &box,
135  uint32 contextID,
136  char a, char b, char c,
137  uint16 resNum,
138  uint16 numButtons,
139  uint16 ident,
140  AppFunc *cmd);
141 
142  GfxCompImage(gPanelList &, const StaticRect &, void **, int16, int16,
143  const char *, textPallete &, uint16, AppFunc *cmd = NULL);
144 
145  ~GfxCompImage();
146 
147  void pointerMove(gPanelMessage &msg);
148  void enable(bool);
149  void invalidate(Rect16 *unused = nullptr); // invalidates the drawing
150  int16 getCurrent() {
151  return _currentImage;
152  }
153  int16 getMin() {
154  return _min;
155  }
156  int16 getMax() {
157  return _max;
158  }
159  void setCurrent(uint16 val) {
160  _currentImage = clamp(_min, val, _max);
161  }
162  void setExtent(const Rect16 &rect);
163  void select(uint16 val);
164  void select(uint16 val, const Rect16 &rect);
165  void setImages(void **images);
166  void setImage(void *image);
167 
168  void draw(); // redraw the panel.
169  virtual void drawClipped(gPort &,
170  const Point16 &,
171  const Rect16 &);
172 };
173 
174 class GfxSpriteImage : public GfxCompImage {
175 private:
176 
177  // Color set to draw the object.
178  ColorTable _objColors;
179 
180 protected:
181  Sprite *_sprPtr;
182 
183 public:
184  // this one takes a sprite pointer
185  GfxSpriteImage(gPanelList &, const Rect16 &, GameObject *, char,
186  uint16, AppFunc *cmd = NULL);
187 
188 
189  void drawClipped(gPort &,
190  const Point16 &,
191  const Rect16 &);
192 };
193 
194 /* ======================================================================= *
195  Compressed image button
196  * ======================================================================= */
197 
198 class GfxCompButton : public GfxCompImage {
199 protected:
200  void *_forImage; // pointer to forground compress image data
201  void *_resImage; // pointer to resessed compressed image data
202  void *_dimImage; // pointer to dimmed commpressed image data
203  Rect16 _extent; // area that image covers
204  bool _dimmed; // duh dim bit
205  bool _internalAlloc; // set if memory allocated in class
206 
207 public:
208 
209  GfxCompButton(gPanelList &, const Rect16 &, hResContext *, hResID res1, hResID res2,
210  uint16, AppFunc *cmd = NULL);
211 
212  GfxCompButton(gPanelList &, const Rect16 &, hResID contextID, hResID res1, hResID res2,
213  uint16, AppFunc *cmd = NULL);
214 
215  GfxCompButton(gPanelList &, const Rect16 &, hResContext *, char, char, char, int16, int16,
216  uint16, AppFunc *cmd = NULL);
217 
218  GfxCompButton(gPanelList &, const Rect16 &, hResID, char, char, char, int16, int16,
219  uint16, AppFunc *cmd = NULL);
220 
221  GfxCompButton(gPanelList &, const Rect16 &, hResContext *, uint32 resID, int8, int8,
222  uint16, AppFunc *cmd = NULL);
223 
224  GfxCompButton(gPanelList &, const Rect16 &, hResID, uint32, int8, int8,
225  uint16, AppFunc *cmd = NULL);
226 
227  GfxCompButton(gPanelList &, const Rect16 &, hResContext *, int16,
228  uint16, AppFunc *cmd = NULL);
229 
230  GfxCompButton(gPanelList &, const Rect16 &, void **, int16,
231  uint16, AppFunc *cmd = NULL);
232 
233  GfxCompButton(gPanelList &, const Rect16 &, void **, int16,
234  const char *, textPallete &, uint16, AppFunc *cmd = NULL);
235 
236  GfxCompButton(gPanelList &, const Rect16 &, void **, int16, void *, bool,
237  uint16, AppFunc *cmd = NULL);
238 
239  GfxCompButton(gPanelList &, const Rect16 &, void *,
240  uint16, AppFunc *cmd = NULL);
241 
242  GfxCompButton(gPanelList &, const StaticRect &, void **, int16,
243  const char *, textPallete &, uint16, AppFunc *cmd = NULL);
244 
245  GfxCompButton(gPanelList &, const Rect16 &, AppFunc *cmd = NULL);
246 
247  ~GfxCompButton();
248 
249 
250  bool activate(gEventType why); // activate the control
251  void deactivate();
252 
253  void enable(bool);
254  void invalidate(Rect16 *unused = nullptr); // invalidates the drawing
255  // area for this button
256  void draw(); // redraw the panel.
257  void dim(bool);
258  void setForImage(void *image) {
259  if (image) _forImage = image;
260  }
261  void setResImage(void *image) {
262  if (image) _resImage = image;
263  }
264 
265 private:
266  void loadImages(hResContext *con, hResID res1, hResID res2);
267  void loadImages(uint32 contextID, hResID res1, hResID res2);
268 
269 protected:
270  void pointerMove(gPanelMessage &msg);
271  bool pointerHit(gPanelMessage &msg);
272  void pointerDrag(gPanelMessage &msg);
273  void pointerRelease(gPanelMessage &msg);
274  virtual void *getCurrentCompImage();
275 };
276 
277 /************************************************************************
278 * GfxOwnerSelCompButton -- like a GfxCompButton but does not chage the *
279 * selector bit *
280 ************************************************************************/
281 
283 public:
284 
285  GfxOwnerSelCompButton(gPanelList &, const Rect16 &, void **, int16,
286  uint16, AppFunc *cmd = NULL);
287 
288  //protected:
289  bool activate(gEventType why); // activate the control
290  bool pointerHit(gPanelMessage &msg);
291  void select(uint16 val);
292 };
293 
294 /************************************************************************
295 * GfxMultCompButton -- like GfxCompButton but does any number of images *
296 ************************************************************************/
297 
299 private:
300  bool _response; // tells whether to display an image when hit.
301 
302 protected:
303  void **_images;
304  Rect16 _extent;
305  int16 _current;
306  int16 _min;
307  int16 _max;
308 
309 
310 public:
311  GfxMultCompButton(gPanelList &, const Rect16 &, hResContext *, char, char, char, int16, int16, int16,
312  uint16, AppFunc *cmd = NULL);
313 
314  GfxMultCompButton(gPanelList &, const Rect16 &, void **, int16, int16,
315  uint16, AppFunc *cmd = NULL);
316 
317  GfxMultCompButton(gPanelList &, const Rect16 &, void **,
318  int16, int16, bool,
319  uint16, AppFunc *cmd = NULL);
320 
322 
323  int16 getCurrent() {
324  return _current;
325  }
326  int16 getMin() {
327  return _min;
328  }
329  int16 getMax() {
330  return _max;
331  }
332  void setCurrent(int16 val) {
333  _current = clamp(_min, val, _max);
334  }
335  void setImages(void **newImages) {
336  if (_images && newImages)
337  _images = newImages;
338  }
339  void setResponse(bool resp) {
340  _response = resp;
341  }
342 
343 protected:
344  bool activate(gEventType why); // activate the control
345  bool pointerHit(gPanelMessage &msg);
346  virtual void *getCurrentCompImage();
347 };
348 
349 
350 /* ===================================================================== *
351  GfxSlider class
352  * ===================================================================== */
353 
354 class GfxSlider : public GfxMultCompButton {
355 protected:
356  Rect16 _imageRect;
357  int16 _slValMin;
358  int16 _slValMax;
359  int16 _slCurrent;
360  int16 _imagePosX;
361 
362 public:
363  GfxSlider(gPanelList &, const Rect16 &, const Rect16 &, int16, int16,
364  void **, int16, int16,
365  uint16, AppFunc *cmd = NULL);
366 
367 private:
368  bool activate(gEventType why);
369  void deactivate();
370  bool pointerHit(gPanelMessage &msg);
371  void pointerMove(gPanelMessage &msg);
372  void pointerRelease(gPanelMessage &);
373  void pointerDrag(gPanelMessage &msg);
374  void updateSliderIndexes(Point16 &pos);
375  void drawClipped(gPort &port,
376  const Point16 &offset,
377  const Rect16 &r);
378 
379 public:
380  void setSliderCurrent(int16 val) {
381  _slCurrent = val;
382  }
383  int16 getSliderCurrent() {
384  return _slCurrent;
385  }
386  int16 getSliderLenVal();
387  virtual void *getCurrentCompImage();
388  void draw();
389 };
390 
391 
392 /* ===================================================================== *
393  Misc functions
394  * ===================================================================== */
395 
396 void drawCompressedImageToMap(gPixelMap &map, void *image);
397 
398 void writePlaqText(gPort &port,
399  const Rect16 &r,
400  gFont *font,
401  int16 textPos,
402  textPallete &pal,
403  bool hiLite,
404  const char *msg, ...);
405 
406 
407 void writePlaqTextPos(gPort &port,
408  const Point16 &pos,
409  gFont *font,
410  int16 textPos,
411  textPallete &pal,
412  bool hiLite,
413  const char *msg, ...);
414 
415 } // end of namespace Saga2
416 
417 #endif
Definition: button.h:54
Definition: button.h:354
Definition: actor.h:32
Definition: gdraw.h:56
Definition: gdraw.h:178
Definition: button.h:198
Definition: button.h:298
Definition: sprite.h:42
Definition: rect.h:282
Definition: hresmgr.h:98
Definition: button.h:282
Definition: rect.h:42
Definition: panel.h:255
Definition: objects.h:118
Definition: panel.h:218
Definition: button.h:45
Definition: gdraw.h:111
Definition: button.h:174
Definition: button.h:96
Definition: rect.h:290
Definition: panel.h:406