CCursorHandler.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #include "../stdafx.h"
  2. #include "CCursorHandler.h"
  3. #include "SDL.h"
  4. #include "SDL_Extensions.h"
  5. #include "CGameInfo.h"
  6. #include "../hch/CDefHandler.h"
  7. /*
  8. * CCursorHandler.cpp, part of VCMI engine
  9. *
  10. * Authors: listed in file AUTHORS in main folder
  11. *
  12. * License: GNU General Public License v2.0 or later
  13. * Full text of license available in license.txt file, in main folder
  14. *
  15. */
  16. extern SDL_Surface * screen;
  17. void CCursorHandler::initCursor()
  18. {
  19. mode = number = xpos = ypos = 0;
  20. help = CSDL_Ext::newSurface(32,32);
  21. cursors.push_back(CDefHandler::giveDef("CRADVNTR.DEF"));
  22. cursors.push_back(CDefHandler::giveDef("CRCOMBAT.DEF"));
  23. cursors.push_back(CDefHandler::giveDef("CRDEFLT.DEF"));
  24. cursors.push_back(CDefHandler::giveDef("CRSPELL.DEF"));
  25. SDL_ShowCursor(SDL_DISABLE);
  26. }
  27. void CCursorHandler::changeGraphic(const int & type, const int & no)
  28. {
  29. mode = type;
  30. number = no;
  31. }
  32. void CCursorHandler::cursorMove(const int & x, const int & y)
  33. {
  34. xpos = x;
  35. ypos = y;
  36. }
  37. void CCursorHandler::draw1()
  38. {
  39. if(!Show) return;
  40. int x = xpos, y = ypos;
  41. if((mode==1 && number!=6) || mode ==3)
  42. {
  43. x-=16;
  44. y-=16;
  45. // Properly align the melee attack cursors.
  46. if (mode == 1) {
  47. switch (number) {
  48. case 7: // Bottom left
  49. x -= 6;
  50. y += 16;
  51. break;
  52. case 8: // Left
  53. x -= 16;
  54. y += 11;
  55. break;
  56. case 9: // Top left
  57. x -= 6;
  58. y -= 6;
  59. break;
  60. case 10: // Top right
  61. x += 16;
  62. y -= 6;
  63. break;
  64. case 11: // Right
  65. x += 16;
  66. y += 11;
  67. break;
  68. case 12: // Bottom right
  69. x += 16;
  70. y += 16;
  71. break;
  72. }
  73. }
  74. }
  75. else if(mode==0 && number>0)
  76. {
  77. x-=12;
  78. y-=10;
  79. }
  80. SDL_BlitSurface(screen, &genRect(32,32,x,y), help, &genRect(32,32,0,0));
  81. blitAt(cursors[mode]->ourImages[number].bitmap,x,y);
  82. }
  83. void CCursorHandler::draw2()
  84. {
  85. if(!Show) return;
  86. int x = xpos, y = ypos;
  87. if((mode==1 && number!=6) || mode == 3)
  88. {
  89. x-=16;
  90. y-=16;
  91. }
  92. else if(mode==0 && number>0)
  93. {
  94. x-=12;
  95. y-=10;
  96. }
  97. blitAt(help,x,y);
  98. }