CCursorHandler.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. public:
  30. /// position of cursor
  31. int xpos, ypos;
  32. /// Current cursor
  33. ECursor::ECursorTypes type;
  34. size_t frame;
  35. /// inits cursorHandler - run only once, it's not memleak-proof (rev 1333)
  36. void initCursor();
  37. /// changes cursor graphic for type type (0 - adventure, 1 - combat, 2 - default, 3 - spellbook) and frame index (not used for type 3)
  38. void changeGraphic(ECursor::ECursorTypes type, int index);
  39. /**
  40. * Replaces the cursor with a custom image.
  41. *
  42. * @param image Image to replace cursor with or nullptr to use the normal
  43. * cursor. CursorHandler takes ownership of object
  44. */
  45. void dragAndDropCursor (CAnimImage * image);
  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. 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. };