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 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (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, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 * 22 * Based on the original sources 23 * Faery Tale II -- The Halls of the Dead 24 * (c) 1993-1996 The Wyrmkeep Entertainment Co. 25 */ 26 27 #ifndef SAGA2_BUTTON_H 28 #define SAGA2_BUTTON_H 29 30 #include "saga2/panel.h" 31 #include "saga2/cmisc.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 45 struct StaticTextPallete { 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 textPalletetextPallete63 textPallete() { 64 dlPen = urPen = inPen = dlHilitePen = urHilitePen = inHilitePen = 0; 65 } 66 textPalletetextPallete67 textPallete(uint8 dlP, uint8 urP, uint8 inP, uint8 dlHP, uint8 urHP, uint8 inHP) { 68 set(dlP, urP, inP, dlHP, urHP, inHP); 69 } 70 textPalletetextPallete71 textPallete(StaticTextPallete pal) { 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 settextPallete80 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(void); // get the current image 112 113 void init(void); 114 115 public: 116 117 enum controlValue { 118 enter = (1 << 0), 119 leave = (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(void); 146 147 void pointerMove(gPanelMessage &msg); 148 void enable(bool); 149 void invalidate(Rect16 *unused = nullptr); // invalidates the drawing getCurrent(void)150 int16 getCurrent(void) { 151 return _currentImage; 152 } getMin(void)153 int16 getMin(void) { 154 return _min; 155 } getMax(void)156 int16 getMax(void) { 157 return _max; 158 } setCurrent(uint16 val)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(void); // 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(void); 248 249 250 bool activate(gEventType why); // activate the control 251 void deactivate(void); 252 253 void enable(bool); 254 void invalidate(Rect16 *unused = nullptr); // invalidates the drawing 255 // area for this button 256 void draw(void); // redraw the panel. 257 void dim(bool); setForImage(void * image)258 void setForImage(void *image) { 259 if (image) _forImage = image; 260 } setResImage(void * image)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(void); 275 }; 276 277 /************************************************************************ 278 * GfxOwnerSelCompButton -- like a GfxCompButton but does not chage the * 279 * selector bit * 280 ************************************************************************/ 281 282 class GfxOwnerSelCompButton : public GfxCompButton { 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 298 class GfxMultCompButton : public GfxCompButton { 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 321 ~GfxMultCompButton(void); 322 getCurrent(void)323 int16 getCurrent(void) { 324 return _current; 325 } getMin(void)326 int16 getMin(void) { 327 return _min; 328 } getMax(void)329 int16 getMax(void) { 330 return _max; 331 } setCurrent(int16 val)332 void setCurrent(int16 val) { 333 _current = clamp(_min, val, _max); 334 } setImages(void ** newImages)335 void setImages(void **newImages) { 336 if (_images && newImages) 337 _images = newImages; 338 } setResponse(bool resp)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(void); 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(void); 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: setSliderCurrent(int16 val)380 void setSliderCurrent(int16 val) { 381 _slCurrent = val; 382 } getSliderCurrent(void)383 int16 getSliderCurrent(void) { 384 return _slCurrent; 385 } 386 int16 getSliderLenVal(void); 387 virtual void *getCurrentCompImage(void); 388 void draw(void); 389 }; 390 391 392 /* ===================================================================== * 393 Misc functions 394 * ===================================================================== */ 395 // duplicate declaration in floating.h 396 397 void drawCompressedImage(gPort &port, const Point16 pos, void *image); 398 void drawCompressedImageGhosted(gPort &port, const Point16 pos, void *image); 399 void drawCompressedImageToMap(gPixelMap &map, void *image); 400 401 void writePlaqText(gPort &port, 402 const Rect16 &r, 403 gFont *font, 404 int16 textPos, 405 textPallete &pal, 406 bool hiLite, 407 const char *msg, ...); 408 409 410 void writePlaqTextPos(gPort &port, 411 const Point16 &pos, 412 gFont *font, 413 int16 textPos, 414 textPallete &pal, 415 bool hiLite, 416 const char *msg, ...); 417 418 } // end of namespace Saga2 419 420 #endif 421