CCursorHandler.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * CCursorHandler.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. class CAnimImage;
  12. struct SDL_Surface;
  13. namespace ECursor
  14. {
  15. enum ECursorTypes { ADVENTURE, COMBAT, DEFAULT, SPELLBOOK };
  16. enum EBattleCursors { COMBAT_BLOCKED, COMBAT_MOVE, COMBAT_FLY, COMBAT_SHOOT,
  17. COMBAT_HERO, COMBAT_QUERY, COMBAT_POINTER,
  18. //various attack frames
  19. COMBAT_SHOOT_PENALTY = 15, COMBAT_SHOOT_CATAPULT, COMBAT_HEAL,
  20. COMBAT_SACRIFICE, COMBAT_TELEPORT};
  21. }
  22. /// handles mouse cursor
  23. class CCursorHandler final
  24. {
  25. SDL_Surface * help;
  26. CAnimImage * currentCursor;
  27. std::unique_ptr<CAnimImage> dndObject; //if set, overrides currentCursor
  28. std::array<std::unique_ptr<CAnimImage>, 4> cursors;
  29. bool showing;
  30. /// Draw cursor preserving original image below cursor
  31. void drawWithScreenRestore();
  32. /// Restore original image below cursor
  33. void drawRestored();
  34. public:
  35. /// position of cursor
  36. int xpos, ypos;
  37. /// Current cursor
  38. ECursor::ECursorTypes type;
  39. size_t frame;
  40. /// inits cursorHandler - run only once, it's not memleak-proof (rev 1333)
  41. void initCursor();
  42. /// changes cursor graphic for type type (0 - adventure, 1 - combat, 2 - default, 3 - spellbook) and frame index (not used for type 3)
  43. void changeGraphic(ECursor::ECursorTypes type, int index);
  44. /**
  45. * Replaces the cursor with a custom image.
  46. *
  47. * @param image Image to replace cursor with or nullptr to use the normal
  48. * cursor. CursorHandler takes ownership of object
  49. */
  50. void dragAndDropCursor (std::unique_ptr<CAnimImage> image);
  51. void render();
  52. void shiftPos( int &x, int &y );
  53. void hide() { showing=0; };
  54. void show() { showing=1; };
  55. /// change cursor's positions to (x, y)
  56. void cursorMove(const int & x, const int & y);
  57. /// Move cursor to screen center
  58. void centerCursor();
  59. CCursorHandler();
  60. ~CCursorHandler();
  61. };