CCursorHandler.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 += 10;
  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. case 13: // Below
  73. x += 9;
  74. y += 16;
  75. break;
  76. case 14: // Above
  77. x += 9;
  78. y -= 15;
  79. break;
  80. }
  81. }
  82. }
  83. else if(mode==0 && number>0)
  84. {
  85. x-=12;
  86. y-=10;
  87. }
  88. SDL_BlitSurface(screen, &genRect(32,32,x,y), help, &genRect(32,32,0,0));
  89. blitAt(cursors[mode]->ourImages[number].bitmap,x,y);
  90. }
  91. void CCursorHandler::draw2()
  92. {
  93. if(!Show) return;
  94. int x = xpos, y = ypos;
  95. if((mode==1 && number!=6) || mode == 3)
  96. {
  97. x-=16;
  98. y-=16;
  99. }
  100. else if(mode==0 && number>0)
  101. {
  102. x-=12;
  103. y-=10;
  104. }
  105. blitAt(help,x,y);
  106. }