CCursorHandler.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #pragma once
  2. class CAnimImage;
  3. struct SDL_Surface;
  4. /*
  5. * CCursorhandler.h, part of VCMI engine
  6. *
  7. * Authors: listed in file AUTHORS in main folder
  8. *
  9. * License: GNU General Public License v2.0 or later
  10. * Full text of license available in license.txt file, in main folder
  11. *
  12. */
  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
  24. {
  25. SDL_Surface * help;
  26. CAnimImage * currentCursor;
  27. CAnimImage * dndObject; //if set, overrides currentCursor
  28. bool showing;
  29. /// Draw cursor preserving original image below cursor
  30. void drawWithScreenRestore();
  31. /// Restore original image below cursor
  32. void drawRestored();
  33. /// Simple draw cursor
  34. void draw(SDL_Surface *to);
  35. public:
  36. /// position of cursor
  37. int xpos, ypos;
  38. /// Current cursor
  39. ECursor::ECursorTypes type;
  40. size_t frame;
  41. /// inits cursorHandler - run only once, it's not memleak-proof (rev 1333)
  42. void initCursor();
  43. /// changes cursor graphic for type type (0 - adventure, 1 - combat, 2 - default, 3 - spellbook) and frame index (not used for type 3)
  44. void changeGraphic(ECursor::ECursorTypes type, int index);
  45. /**
  46. * Replaces the cursor with a custom image.
  47. *
  48. * @param image Image to replace cursor with or nullptr to use the normal
  49. * cursor. CursorHandler takes ownership of object
  50. */
  51. void dragAndDropCursor (CAnimImage * image);
  52. void render();
  53. void shiftPos( int &x, int &y );
  54. void hide() { showing=0; };
  55. void show() { showing=1; };
  56. /// change cursor's positions to (x, y)
  57. void cursorMove(const int & x, const int & y);
  58. /// Move cursor to screen center
  59. void centerCursor();
  60. ~CCursorHandler();
  61. };