123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- /* GCSx
- ** TOOLTIP.CPP
- **
- ** Tooltip popups
- */
- /*****************************************************************************
- ** Copyright (C) 2003-2006 Janson
- **
- ** This program is free software; you can redistribute it and/or modify
- ** it under the terms of the GNU General Public License as published by
- ** the Free Software Foundation; either version 2 of the License, or
- ** (at your option) any later version.
- **
- ** This program is distributed in the hope that it will be useful,
- ** but WITHOUT ANY WARRANTY; without even the implied warranty of
- ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ** GNU General Public License for more details.
- **
- ** You should have received a copy of the GNU General Public License
- ** along with this program; if not, write to the Free Software
- ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
- *****************************************************************************/
- #include "all.h"
- ToolTip::ToolTip(const char* tText) : Window() { start_func
- assert(tText);
- text = tText;
- if (text.length() > MAX_LINELENGTH) text = text.substr(0, MAX_LINELENGTH);
-
- // Calculate size
- resize(fontWidth(text, FONT_TOOLTIP) + TOOLTIP_BORDER * 2 + TOOLTIP_PADDING_HORIZ * 2,
- fontHeight(FONT_TOOLTIP) + TOOLTIP_BORDER * 2 + TOOLTIP_PADDING_VERT * 2);
- }
- ToolTip::~ToolTip() { start_func
- }
- #ifndef NDEBUG
- const char* ToolTip::debugDump() const { start_func
- return text.c_str();
- }
- #endif
- void ToolTip::display(SDL_Surface* destSurface, Rect& toDisplay, const Rect& clipArea, int xOffset, int yOffset) { start_func
- assert(destSurface);
- if (visible) {
- // If dirty, redraw all
- if (dirty) {
- getRect(toDisplay);
- toDisplay.x += xOffset;
- toDisplay.y += yOffset;
- dirty = 0;
- intersectRects(toDisplay, clipArea);
- }
-
- // Anything to draw?
- if (toDisplay.w) {
- SDL_SetClipRect(destSurface, &toDisplay);
-
- xOffset += x;
- yOffset += y;
- SDL_FillRect(destSurface, &toDisplay, guiPacked[COLOR_TOOLTIP]);
- drawText(text, guiRGB[COLOR_TEXT], xOffset + TOOLTIP_BORDER + TOOLTIP_PADDING_HORIZ, yOffset + TOOLTIP_BORDER + TOOLTIP_PADDING_VERT, destSurface, FONT_TOOLTIP);
- drawHLine(xOffset, xOffset + width - 2, yOffset, guiPacked[COLOR_LIGHT1], destSurface);
- drawVLine(yOffset, yOffset + height - 2, xOffset, guiPacked[COLOR_LIGHT1], destSurface);
- drawVLine(yOffset + 1, yOffset + height - 1, xOffset + width - 1, guiPacked[COLOR_DARK1], destSurface);
- drawHLine(xOffset + 1, xOffset + width - 1, yOffset + height - 1, guiPacked[COLOR_DARK1], destSurface);
- }
- }
- }
- void ToolTip::popup(int xPos, int yPos) { start_func
- // Move as needed
- if (xPos + width > screenWidth) xPos = screenWidth - width;
- if (yPos + height > screenHeight) yPos = screenHeight - height;
- if (xPos < 0) xPos = 0;
- if (yPos < 0) yPos = 0;
- move(xPos, yPos);
- desktop->addWindow(this, 0);
- setDirty();
- }
- int ToolTip::event(int hasFocus, const SDL_Event* event) { start_func
- assert(event);
- return 0;
- }
- Window::WindowType ToolTip::windowType() const { start_func
- return WINDOW_TOOLTIP;
- }
- Window::WindowSort ToolTip::windowSort() const { start_func
- return WINDOWSORT_POPUP;
- }
- int ToolTip::refuseAll() const { start_func
- return 1;
- }
|