gcsx_tooltip.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /* GCSx
  2. ** TOOLTIP.CPP
  3. **
  4. ** Tooltip popups
  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. ToolTip::ToolTip(const char* tText) : Window() { start_func
  25. assert(tText);
  26. text = tText;
  27. if (text.length() > MAX_LINELENGTH) text = text.substr(0, MAX_LINELENGTH);
  28. // Calculate size
  29. resize(fontWidth(text, FONT_TOOLTIP) + TOOLTIP_BORDER * 2 + TOOLTIP_PADDING_HORIZ * 2,
  30. fontHeight(FONT_TOOLTIP) + TOOLTIP_BORDER * 2 + TOOLTIP_PADDING_VERT * 2);
  31. }
  32. ToolTip::~ToolTip() { start_func
  33. }
  34. #ifndef NDEBUG
  35. const char* ToolTip::debugDump() const { start_func
  36. return text.c_str();
  37. }
  38. #endif
  39. void ToolTip::display(SDL_Surface* destSurface, Rect& toDisplay, const Rect& clipArea, int xOffset, int yOffset) { start_func
  40. assert(destSurface);
  41. if (visible) {
  42. // If dirty, redraw all
  43. if (dirty) {
  44. getRect(toDisplay);
  45. toDisplay.x += xOffset;
  46. toDisplay.y += yOffset;
  47. dirty = 0;
  48. intersectRects(toDisplay, clipArea);
  49. }
  50. // Anything to draw?
  51. if (toDisplay.w) {
  52. SDL_SetClipRect(destSurface, &toDisplay);
  53. xOffset += x;
  54. yOffset += y;
  55. SDL_FillRect(destSurface, &toDisplay, guiPacked[COLOR_TOOLTIP]);
  56. drawText(text, guiRGB[COLOR_TEXT], xOffset + TOOLTIP_BORDER + TOOLTIP_PADDING_HORIZ, yOffset + TOOLTIP_BORDER + TOOLTIP_PADDING_VERT, destSurface, FONT_TOOLTIP);
  57. drawHLine(xOffset, xOffset + width - 2, yOffset, guiPacked[COLOR_LIGHT1], destSurface);
  58. drawVLine(yOffset, yOffset + height - 2, xOffset, guiPacked[COLOR_LIGHT1], destSurface);
  59. drawVLine(yOffset + 1, yOffset + height - 1, xOffset + width - 1, guiPacked[COLOR_DARK1], destSurface);
  60. drawHLine(xOffset + 1, xOffset + width - 1, yOffset + height - 1, guiPacked[COLOR_DARK1], destSurface);
  61. }
  62. }
  63. }
  64. void ToolTip::popup(int xPos, int yPos) { start_func
  65. // Move as needed
  66. if (xPos + width > screenWidth) xPos = screenWidth - width;
  67. if (yPos + height > screenHeight) yPos = screenHeight - height;
  68. if (xPos < 0) xPos = 0;
  69. if (yPos < 0) yPos = 0;
  70. move(xPos, yPos);
  71. desktop->addWindow(this, 0);
  72. setDirty();
  73. }
  74. int ToolTip::event(int hasFocus, const SDL_Event* event) { start_func
  75. assert(event);
  76. return 0;
  77. }
  78. Window::WindowType ToolTip::windowType() const { start_func
  79. return WINDOW_TOOLTIP;
  80. }
  81. Window::WindowSort ToolTip::windowSort() const { start_func
  82. return WINDOWSORT_POPUP;
  83. }
  84. int ToolTip::refuseAll() const { start_func
  85. return 1;
  86. }