CCursorHandler.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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
  16. {
  17. ADVENTURE,
  18. COMBAT,
  19. DEFAULT,
  20. SPELLBOOK
  21. };
  22. enum EBattleCursors
  23. {
  24. COMBAT_BLOCKED,
  25. COMBAT_MOVE,
  26. COMBAT_FLY,
  27. COMBAT_SHOOT,
  28. COMBAT_HERO,
  29. COMBAT_QUERY,
  30. COMBAT_POINTER,
  31. //various attack frames
  32. COMBAT_SHOOT_PENALTY = 15,
  33. COMBAT_SHOOT_CATAPULT,
  34. COMBAT_HEAL,
  35. COMBAT_SACRIFICE,
  36. COMBAT_TELEPORT
  37. };
  38. }
  39. /// handles mouse cursor
  40. class CCursorHandler
  41. {
  42. SDL_Surface * help;
  43. CAnimImage * currentCursor;
  44. CAnimImage * dndObject; //if set, overrides currentCursor
  45. bool showing;
  46. /// Draw cursor preserving original image below cursor
  47. void drawWithScreenRestore();
  48. /// Restore original image below cursor
  49. void drawRestored();
  50. /// Simple draw cursor
  51. void draw(SDL_Surface * to);
  52. public:
  53. /// position of cursor
  54. int xpos, ypos;
  55. /// Current cursor
  56. ECursor::ECursorTypes type;
  57. size_t frame;
  58. /// inits cursorHandler - run only once, it's not memleak-proof (rev 1333)
  59. void initCursor();
  60. /// changes cursor graphic for type type (0 - adventure, 1 - combat, 2 - default, 3 - spellbook) and frame index (not used for type 3)
  61. void changeGraphic(ECursor::ECursorTypes type, int index);
  62. /**
  63. * Replaces the cursor with a custom image.
  64. *
  65. * @param image Image to replace cursor with or nullptr to use the normal
  66. * cursor. CursorHandler takes ownership of object
  67. */
  68. void dragAndDropCursor(CAnimImage * image);
  69. void render();
  70. void shiftPos(int & x, int & y);
  71. void hide() { showing = 0; };
  72. void show() { showing = 1; };
  73. /// change cursor's positions to (x, y)
  74. void cursorMove(const int & x, const int & y);
  75. /// Move cursor to screen center
  76. void centerCursor();
  77. ~CCursorHandler();
  78. };