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 23 #ifndef TITANIC_PET_GLYPHS_H 24 #define TITANIC_PET_GLYPHS_H 25 26 #include "common/keyboard.h" 27 #include "titanic/core/list.h" 28 #include "titanic/messages/mouse_messages.h" 29 #include "titanic/pet_control/pet_gfx_element.h" 30 #include "titanic/support/rect.h" 31 32 namespace Titanic { 33 34 #define TOTAL_GLYPHS 7 35 36 class CPetGlyphs; 37 class CPetSection; 38 class CTextControl; 39 40 enum GlyphActionMode { ACTION_REMOVE = 0, ACTION_REMOVED = 1, ACTION_CHANGE = 2 }; 41 42 enum GlyphFlag { GFLAG_1 = 1, GFLAG_2 = 2, GFLAG_4 = 4, GFLAG_8 = 8, GFLAG_16 = 16 }; 43 44 class CGlyphAction { 45 protected: 46 GlyphActionMode _mode; 47 public: CGlyphAction()48 CGlyphAction() : _mode(ACTION_REMOVED) {} CGlyphAction(GlyphActionMode mode)49 CGlyphAction(GlyphActionMode mode) : _mode(mode) {} 50 getMode()51 GlyphActionMode getMode() const { return _mode; } 52 }; 53 54 class CPetGlyph : public ListItem { 55 protected: 56 /** 57 * Get the overall pet section owner 58 */ 59 CPetSection *getPetSection() const; 60 public: 61 CPetGfxElement _element; 62 CPetGlyphs *_owner; 63 public: CPetGlyph()64 CPetGlyph() : ListItem(), _owner(nullptr) {} 65 66 /** 67 * Setup the glyph 68 */ 69 virtual bool setup(CPetControl *petControl, CPetGlyphs *owner); 70 71 /** 72 * Reset the glyph 73 */ reset()74 virtual bool reset() { return false; } 75 76 /** 77 * Called when the PET area is entered 78 */ enter()79 virtual void enter() {} 80 81 /** 82 * Called when the PET area is left 83 */ leave()84 virtual void leave() {} 85 86 /** 87 * Draw the glyph at a specified position 88 */ 89 virtual void drawAt(CScreenManager *screenManager, const Point &pt, bool isHighlighted); 90 91 /** 92 * Handles any secondary drawing of the glyph 93 */ draw2(CScreenManager * screenManager)94 virtual void draw2(CScreenManager *screenManager) {} 95 96 /** 97 * Updates the tooltip being shown for the glyph 98 */ 99 virtual void updateTooltip(); 100 101 /** 102 * Get the bounds for the glyph 103 */ getBounds()104 virtual Rect getBounds() const { return Rect(); } 105 106 /** 107 * Called for mouse button down messages 108 */ MouseButtonDownMsg(const Point & pt)109 virtual bool MouseButtonDownMsg(const Point &pt) { return false; } 110 111 /** 112 * Called when mouse drag starts 113 */ MouseDragStartMsg(CMouseDragStartMsg * msg)114 virtual bool MouseDragStartMsg(CMouseDragStartMsg *msg) { return false; } 115 116 /** 117 * Called during mouse drags 118 */ MouseDragMoveMsg(CMouseDragMoveMsg * msg)119 virtual bool MouseDragMoveMsg(CMouseDragMoveMsg *msg) { return false; } 120 121 /** 122 * Called when mouse drag ends 123 */ MouseDragEndMsg(CMouseDragEndMsg * msg)124 virtual bool MouseDragEndMsg(CMouseDragEndMsg *msg) { return false; } 125 126 /** 127 * Handles mouse button up messages 128 */ MouseButtonUpMsg(const Point & pt)129 virtual bool MouseButtonUpMsg(const Point &pt) { return false; } 130 131 /** 132 * Handles mouse double-click messages 133 */ MouseDoubleClickMsg(const CMouseDoubleClickMsg * msg)134 virtual bool MouseDoubleClickMsg(const CMouseDoubleClickMsg *msg) { return false; } 135 136 /** 137 * Handles keypresses 138 */ KeyCharMsg(int key)139 virtual bool KeyCharMsg(int key) { return false; } 140 141 /** 142 * Handles keypresses 143 */ VirtualKeyCharMsg(CVirtualKeyCharMsg * msg)144 virtual bool VirtualKeyCharMsg(CVirtualKeyCharMsg *msg) { return false; } 145 146 /** 147 * Unhighlight any currently highlighted element 148 */ unhighlightCurrent()149 virtual void unhighlightCurrent() {} 150 151 /** 152 * Highlight any currently highlighted element 153 */ highlightCurrent(const Point & pt)154 virtual void highlightCurrent(const Point &pt) {} 155 156 /** 157 * Glyph has been shifted to be first visible one 158 */ glyphFocused(const Point & topLeft,bool flag)159 virtual void glyphFocused(const Point &topLeft, bool flag) {} 160 161 /** 162 * Selects a glyph 163 */ selectGlyph(const Point & topLeft,const Point & pt)164 virtual void selectGlyph(const Point &topLeft, const Point &pt) {} 165 166 /** 167 * Called when a glyph drag starts 168 */ dragGlyph(const Point & topLeft,CMouseDragStartMsg * msg)169 virtual bool dragGlyph(const Point &topLeft, CMouseDragStartMsg *msg) { return false; } 170 171 /** 172 * Returns true if the glyph's bounds, shifted to a given position, 173 * will contain the specified point 174 */ 175 virtual bool contains(const Point &delta, const Point &pt); 176 177 /** 178 * Returns the tooltip text for when the glyph is selected 179 */ getTooltip(CTextControl * text)180 virtual void getTooltip(CTextControl *text) {} 181 182 /** 183 * Saves the data for the glyph 184 */ saveGlyph(SimpleFile * file,int indent)185 virtual void saveGlyph(SimpleFile *file, int indent) {} 186 proc33(CPetGlyph * glyph)187 virtual bool proc33(CPetGlyph *glyph) { return true; } 188 189 /** 190 * Return whether the glyph is currently valid 191 */ isValid()192 virtual bool isValid() const { return true; } 193 194 /** 195 * Called on a highlighted item when PET area is entered 196 */ enterHighlighted()197 virtual bool enterHighlighted() { return false; } 198 199 /** 200 * Called on a highlighted item when PET area is left 201 */ leaveHighlighted()202 virtual void leaveHighlighted() {} 203 204 /** 205 * Returns the object associated with the glyph 206 */ getObjectAt()207 virtual CGameObject *getObjectAt() { return nullptr; } 208 209 /** 210 * Does a processing action on the glyph 211 */ doAction(CGlyphAction * action)212 virtual bool doAction(CGlyphAction *action) { return true; } 213 214 /** 215 * Translate the glyph's position 216 */ translate(const Point & pt)217 void translate(const Point &pt) { _element.translate(pt.x, pt.y); } 218 219 /** 220 * Translate the glyph's position back 221 */ translateBack(const Point & pt)222 void translateBack(const Point &pt) { _element.translate(-pt.x, -pt.y); } 223 224 /** 225 * Get the parent RealLife area 226 */ getOwner()227 CPetGlyphs *getOwner() { return _owner; } 228 229 /** 230 * Get the PET control 231 */ 232 CPetControl *getPetControl() const; 233 234 /** 235 * Sets new name and default bounds for glyph 236 */ 237 void setName(const CString &name, CPetControl *petControl); 238 239 /** 240 * Returns true if the specified glyph is the currently highlighted one 241 */ 242 bool isHighlighted() const; 243 }; 244 245 class CPetGlyphs : public List<CPetGlyph> { 246 private: 247 /** 248 * Get a position for the glyph 249 */ 250 Point getPosition(int index) const; 251 252 /** 253 * Get a rect for the glyph 254 */ 255 Rect getRect(int index) const; 256 257 /** 258 * Returns the on-screen index for the highlight to be shown at 259 */ 260 int getHighlightedIndex(int index) const; 261 262 /** 263 * Returns the index of a glyph given the visible on-screen glyph number 264 */ 265 int getItemIndex(int index) const; 266 267 /** 268 * Set the item index 269 */ 270 void setSelectedIndex(int index); 271 272 /** 273 * Return a specified glyph 274 */ 275 CPetGlyph *getGlyph(int index) const; 276 277 /** 278 * Set the first visible glyph index 279 */ 280 void setFirstVisible(int index); 281 282 /** 283 * Make the PET dirty 284 */ 285 void makePetDirty(); 286 287 /** 288 * Returns true if all the glyphs are in a valid state 289 */ 290 bool areItemsValid() const; 291 protected: 292 int _firstVisibleIndex; 293 int _totalGlyphs; 294 int _numVisibleGlyphs; 295 int _highlightIndex; 296 int _field1C; 297 int _flags; 298 CPetGlyph *_dragGlyph; 299 CPetSection *_owner; 300 CPetGfxElement _selection; 301 CPetGfxElement _scrollLeft; 302 CPetGfxElement _scrollRight; 303 protected: 304 /** 305 * Change the currently selected glyph 306 */ 307 void changeHighlight(int index); 308 public: 309 CPetGlyphs(); 310 311 /** 312 * Set the number of visible glyphs 313 */ 314 void setNumVisible(int total); 315 316 /** 317 * Clears the glyph list 318 */ 319 void clear(); 320 321 322 /** 323 * The visual dimensions for the control and it's components 324 */ 325 virtual void setup(int numVisible, CPetSection *owner); 326 327 /** 328 * Set up the control 329 */ 330 virtual void reset(); 331 332 /** 333 * Called when PET area is entered 334 */ 335 virtual void enter(); 336 337 /** 338 * Called when PET area is left 339 */ 340 virtual void leave(); 341 setFlags(int flags)342 void setFlags(int flags) { _flags = flags; } 343 344 /** 345 * Draw the control 346 */ 347 void draw(CScreenManager *screenManager); 348 349 /** 350 * Highlight a specific glyph by indexe 351 */ 352 void highlight(int index); 353 354 /** 355 * Highlight a specific glyph 356 */ 357 void highlight(const CPetGlyph *glyph); 358 359 /** 360 * Get the owning section for the glyphs 361 */ getOwner()362 CPetSection *getOwner() const { return _owner; } 363 364 /** 365 * Get the PET control 366 */ 367 CPetControl *getPetControl() const; 368 369 /** 370 * Mouse button down message 371 */ 372 bool MouseButtonDownMsg(const Point &pt); 373 374 /** 375 * Mouse button up message 376 */ 377 bool MouseButtonUpMsg(const Point &pt); 378 379 /** 380 * Mouse double click message 381 */ MouseDoubleClickMsg(const Point & pt)382 bool MouseDoubleClickMsg(const Point &pt) { return true; } 383 384 /** 385 * Mouse drag start messagge 386 */ 387 bool MouseDragStartMsg(CMouseDragStartMsg *msg); 388 389 /** 390 * Mouse drag move message 391 */ 392 bool MouseDragMoveMsg(CMouseDragMoveMsg *msg); 393 394 /** 395 * Mouse drag end message 396 */ 397 bool MouseDragEndMsg(CMouseDragEndMsg *msg); 398 399 /** 400 * Key character message 401 */ 402 bool KeyCharMsg(int key); 403 404 /** 405 * Virtual key message 406 */ 407 bool VirtualKeyCharMsg(CVirtualKeyCharMsg *msg); 408 409 /** 410 * When the PET section is entered, passes onto the highlighted 411 * glyph, if any 412 */ 413 bool enterHighlighted(); 414 415 /** 416 * When the PET section is left, passes onto the highlighted 417 * glyph, if any 418 */ 419 void leaveHighlighted(); 420 421 /** 422 * Called when a dragging operation starts 423 */ 424 void startDragging(CPetGlyph *glyph, CMouseDragStartMsg *msg); 425 426 /** 427 * Called when a dragging operation ends 428 */ 429 void endDragging(); 430 431 /** 432 * Reset the highlight 433 */ resetHighlight()434 void resetHighlight() { changeHighlight(-1); } 435 436 bool highlighted14(); 437 438 /** 439 * Returns the index of the specified glyph in the lsit 440 */ 441 int indexOf(const CPetGlyph *glyph) const; 442 443 /** 444 * Resets the scrolling of the glyphs list back to the start 445 */ scrollToStart()446 void scrollToStart() { _firstVisibleIndex = 0; } 447 448 /** 449 * Scrolls the glyphs to the left 450 */ 451 void scrollLeft(); 452 453 /** 454 * Scrolls the glyphs to the right 455 */ 456 void scrollRight(); 457 458 /** 459 * Increment the currently selected index 460 */ 461 void incSelection(); 462 463 /** 464 * Decrement the currently selected index 465 */ 466 void decSelection(); 467 468 /** 469 * Returns the object associated the glyph under the specified position 470 */ 471 CGameObject *getObjectAt(const Point &pt) const; 472 473 /** 474 * Returns true if the specified glyph is the currently highlighted one 475 */ 476 bool isGlyphHighlighted(const CPetGlyph *glyph) const; 477 478 /** 479 * Returns the highlighted index, if any 480 */ getHighlightIndex()481 int getHighlightIndex() const { return _highlightIndex; } 482 483 /** 484 * Get the top-left position of the currently highlighted glyph 485 */ 486 Point getHighlightedGlyphPos() const; 487 488 /** 489 * Removes any glyphs from the list that no longer have any images 490 * associated with them 491 */ 492 void removeInvalid(); 493 }; 494 495 } // End of namespace Titanic 496 497 #endif /* TITANIC_PET_GLYPHS_H */ 498