CCursorHandler.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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(40,40);
  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. shiftPos(x, y);
  42. SDL_BlitSurface(screen, &genRect(40,40,x,y), help, &genRect(40,40,0,0));
  43. blitAt(cursors[mode]->ourImages[number].bitmap,x,y);
  44. }
  45. void CCursorHandler::draw2()
  46. {
  47. if(!Show) return;
  48. int x = xpos, y = ypos;
  49. shiftPos(x, y);
  50. blitAt(help,x,y);
  51. }
  52. void CCursorHandler::shiftPos( int &x, int &y )
  53. {
  54. if((mode==1 && number!=6) || mode ==3)
  55. {
  56. x-=16;
  57. y-=16;
  58. // Properly align the melee attack cursors.
  59. if (mode == 1)
  60. {
  61. switch (number)
  62. {
  63. case 7: // Bottom left
  64. x -= 6;
  65. y += 16;
  66. break;
  67. case 8: // Left
  68. x -= 16;
  69. y += 10;
  70. break;
  71. case 9: // Top left
  72. x -= 6;
  73. y -= 6;
  74. break;
  75. case 10: // Top right
  76. x += 16;
  77. y -= 6;
  78. break;
  79. case 11: // Right
  80. x += 16;
  81. y += 11;
  82. break;
  83. case 12: // Bottom right
  84. x += 16;
  85. y += 16;
  86. break;
  87. case 13: // Below
  88. x += 9;
  89. y += 16;
  90. break;
  91. case 14: // Above
  92. x += 9;
  93. y -= 15;
  94. break;
  95. }
  96. }
  97. }
  98. else if(mode==0)
  99. {
  100. if(number == 0); //to exclude
  101. else if(number == 2)
  102. {
  103. x -= 12;
  104. y -= 10;
  105. }
  106. else if(number == 3)
  107. {
  108. x -= 12;
  109. y -= 12;
  110. }
  111. else if(number < 27)
  112. {
  113. int hlpNum = (number - 4)%6;
  114. if(hlpNum == 0)
  115. {
  116. x -= 15;
  117. y -= 13;
  118. }
  119. else if(hlpNum == 1)
  120. {
  121. x -= 13;
  122. y -= 13;
  123. }
  124. else if(hlpNum == 2)
  125. {
  126. x -= 20;
  127. y -= 20;
  128. }
  129. else if(hlpNum == 3)
  130. {
  131. x -= 13;
  132. y -= 16;
  133. }
  134. else if(hlpNum == 4)
  135. {
  136. x -= 8;
  137. y -= 9;
  138. }
  139. else if(hlpNum == 5)
  140. {
  141. x -= 14;
  142. y -= 16;
  143. }
  144. }
  145. else if(number < 31)
  146. {
  147. x -= 20;
  148. y -= 20;
  149. }
  150. }
  151. }