gcsx_mouse.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /* GCSx
  2. ** MOUSE.CPP
  3. **
  4. ** Basic mouse display
  5. */
  6. /*****************************************************************************
  7. ** Copyright (C) 2003-2006 Janson
  8. **
  9. ** This program is free software; you can redistribute it and/or modify
  10. ** it under the terms of the GNU General Public License as published by
  11. ** the Free Software Foundation; either version 2 of the License, or
  12. ** (at your option) any later version.
  13. **
  14. ** This program is distributed in the hope that it will be useful,
  15. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. ** GNU General Public License for more details.
  18. **
  19. ** You should have received a copy of the GNU General Public License
  20. ** along with this program; if not, write to the Free Software
  21. ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
  22. *****************************************************************************/
  23. #include "all.h"
  24. MousePointer::MousePointer(const char* filename, int x, int y) { start_func
  25. assert(filename);
  26. assert(x >= 0);
  27. assert(y >= 0);
  28. original = SDL_LoadBMP(filename);
  29. if (original == NULL) {
  30. fatalCrash(0, "Error loading mouse cursor %s: %s", filename, SDL_GetError());
  31. }
  32. SDL_SetColorKey(original, SDL_SRCCOLORKEY, SDL_MapRGB(original->format, 255, 0, 0));
  33. converted = NULL;
  34. hotX = x;
  35. hotY = y;
  36. tex = NULL;
  37. texNum = 0;
  38. }
  39. MousePointer::~MousePointer() { start_func
  40. if (original) SDL_FreeSurface(original);
  41. if (converted) SDL_FreeSurface(converted);
  42. }
  43. int MousePointer::xSize() const { start_func
  44. assert(original);
  45. return original->w;
  46. }
  47. int MousePointer::ySize() const { start_func
  48. assert(original);
  49. return original->h;
  50. }
  51. int MousePointer::tooltipYOffset() const { start_func
  52. assert(original);
  53. return original->h - hotY;
  54. }
  55. void MousePointer::convertFor(SDL_Surface* screen) { start_func
  56. assert(screen);
  57. if (converted) SDL_FreeSurface(converted);
  58. converted = NULL;
  59. converted = SDL_ConvertSurface(original, screen->format, screen->flags);
  60. tex = NULL;
  61. }
  62. void MousePointer::convertGL(TextureMap* texmap, int gNum, int xSize, int ySize) { start_func
  63. assert(texmap);
  64. SDL_Surface* temp = createSurface32(xSize, ySize);
  65. SDL_Rect sourceRect;
  66. sourceRect.x = 0;
  67. sourceRect.y = 0;
  68. sourceRect.w = original->w;
  69. sourceRect.h = original->h;
  70. SDL_Rect destRect = sourceRect;
  71. if (SDL_BlitSurface(original, &sourceRect, temp, &destRect)) {
  72. fatalCrash(0, "SDL Blit error: %s", SDL_GetError());
  73. }
  74. texmap->store(gNum, temp);
  75. SDL_FreeSurface(temp);
  76. tex = texmap;
  77. texNum = gNum;
  78. }
  79. void MousePointer::textureAt(int x, int y) const { start_func
  80. if (tex) tex->draw(texNum, x - hotX, y - hotY);
  81. }
  82. void MousePointer::displayAt(int x, int y, SDL_Surface* save, SDL_Rect* storeRect) { start_func
  83. assert((converted) || (original));
  84. if (save) blit(x - hotX, y - hotY, getScreen(), 0, 0, save, save->w, save->h);
  85. SDL_Rect sourceRect;
  86. sourceRect.x = 0;
  87. sourceRect.y = 0;
  88. storeRect->x = x - hotX;
  89. storeRect->y = y - hotY;
  90. if (converted) {
  91. sourceRect.w = converted->w;
  92. sourceRect.h = converted->h;
  93. if (SDL_BlitSurface(converted, &sourceRect, getScreen(), storeRect)) {
  94. fatalCrash(0, "SDL Blit error: %s", SDL_GetError());
  95. }
  96. }
  97. else {
  98. sourceRect.w = original->w;
  99. sourceRect.h = original->h;
  100. if (SDL_BlitSurface(original, &sourceRect, getScreen(), storeRect)) {
  101. fatalCrash(0, "SDL Blit error: %s", SDL_GetError());
  102. }
  103. }
  104. }
  105. void MousePointer::unDisplay(int x, int y, SDL_Surface* saved, SDL_Rect* storeRect) const { start_func
  106. if (saved) {
  107. SDL_Rect sourceRect;
  108. sourceRect.x = 0;
  109. sourceRect.y = 0;
  110. sourceRect.w = saved->w;
  111. sourceRect.h = saved->h;
  112. storeRect->x = x - hotX;
  113. storeRect->y = y - hotY;
  114. if (SDL_BlitSurface(saved, &sourceRect, getScreen(), storeRect)) {
  115. fatalCrash(0, "SDL Blit error: %s", SDL_GetError());
  116. }
  117. }
  118. }