CCursorHandler.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 CIntObject;
  12. class CAnimImage;
  13. struct SDL_Surface;
  14. struct SDL_Texture;
  15. namespace ECursor
  16. {
  17. enum ECursorTypes {
  18. ADVENTURE, // set of various cursors for adventure map
  19. COMBAT, // set of various cursors for combat
  20. DEFAULT, // default arror and hourglass cursors
  21. SPELLBOOK // animated cursor for spellcasting
  22. };
  23. enum EBattleCursors {
  24. COMBAT_BLOCKED = 0,
  25. COMBAT_MOVE = 1,
  26. COMBAT_FLY = 2,
  27. COMBAT_SHOOT = 3,
  28. COMBAT_HERO = 4,
  29. COMBAT_QUERY = 5,
  30. COMBAT_POINTER = 6,
  31. COMBAT_HIT_NORTHEAST = 7,
  32. COMBAT_HIT_EAST = 8,
  33. COMBAT_HIT_SOUTHEAST = 9,
  34. COMBAT_HIT_SOUTHWEST = 10,
  35. COMBAT_HIT_WEST = 11,
  36. COMBAT_HIT_NORTHWEST = 12,
  37. COMBAT_HIT_NORTH = 13,
  38. COMBAT_HIT_SOUTH = 14,
  39. COMBAT_SHOOT_PENALTY = 15,
  40. COMBAT_SHOOT_CATAPULT = 16,
  41. COMBAT_HEAL = 17,
  42. COMBAT_SACRIFICE = 18,
  43. COMBAT_TELEPORT = 19
  44. };
  45. }
  46. /// handles mouse cursor
  47. class CCursorHandler final
  48. {
  49. bool needUpdate;
  50. SDL_Texture * cursorLayer;
  51. SDL_Surface * buffer;
  52. CAnimImage * currentCursor;
  53. std::unique_ptr<CAnimImage> dndObject; //if set, overrides currentCursor
  54. std::array<std::unique_ptr<CAnimImage>, 4> cursors;
  55. bool showing;
  56. void clearBuffer();
  57. void updateBuffer(CIntObject * payload);
  58. void replaceBuffer(CIntObject * payload);
  59. void shiftPos( int &x, int &y );
  60. void updateTexture();
  61. public:
  62. /// position of cursor
  63. int xpos, ypos;
  64. /// Current cursor
  65. ECursor::ECursorTypes type;
  66. size_t frame;
  67. /// inits cursorHandler - run only once, it's not memleak-proof (rev 1333)
  68. void initCursor();
  69. /// changes cursor graphic for type type (0 - adventure, 1 - combat, 2 - default, 3 - spellbook) and frame index (not used for type 3)
  70. void changeGraphic(ECursor::ECursorTypes type, int index);
  71. /**
  72. * Replaces the cursor with a custom image.
  73. *
  74. * @param image Image to replace cursor with or nullptr to use the normal
  75. * cursor. CursorHandler takes ownership of object
  76. */
  77. void dragAndDropCursor (std::unique_ptr<CAnimImage> image);
  78. void render();
  79. void hide() { showing=false; };
  80. void show() { showing=true; };
  81. /// change cursor's positions to (x, y)
  82. void cursorMove(const int & x, const int & y);
  83. /// Move cursor to screen center
  84. void centerCursor();
  85. CCursorHandler();
  86. ~CCursorHandler();
  87. };