2007-01-15 12:09:25 -08:00
|
|
|
/*
|
|
|
|
This file is part of Warzone 2100.
|
|
|
|
Copyright (C) 1999-2004 Eidos Interactive
|
2011-02-25 09:45:27 -08:00
|
|
|
Copyright (C) 2005-2011 Warzone 2100 Project
|
2007-01-15 12:09:25 -08:00
|
|
|
|
|
|
|
Warzone 2100 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.
|
|
|
|
|
|
|
|
Warzone 2100 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 Warzone 2100; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
2008-03-21 08:40:23 -07:00
|
|
|
/** @file
|
|
|
|
* The tool tip display system.
|
2007-06-28 10:47:08 -07:00
|
|
|
*/
|
|
|
|
|
2006-06-02 12:34:58 -07:00
|
|
|
#include "lib/framework/frame.h"
|
|
|
|
#include "lib/framework/frameint.h"
|
2007-06-28 10:47:08 -07:00
|
|
|
#include "widget.h"
|
|
|
|
#include "widgint.h"
|
|
|
|
#include "tip.h"
|
2006-06-02 12:34:58 -07:00
|
|
|
// FIXME Direct iVis implementation include!
|
2010-12-31 13:37:14 -08:00
|
|
|
#include "lib/ivis_opengl/pieblitfunc.h"
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
/* Time delay before showing the tool tip */
|
|
|
|
#define TIP_PAUSE 200
|
|
|
|
|
|
|
|
/* How long to display the tool tip */
|
|
|
|
#define TIP_TIME 4000
|
|
|
|
|
|
|
|
/* Size of border around tip text */
|
|
|
|
#define TIP_HGAP 6
|
|
|
|
#define TIP_VGAP 3
|
|
|
|
|
|
|
|
|
|
|
|
/* The tool tip state */
|
|
|
|
static enum _tip_state
|
|
|
|
{
|
|
|
|
TIP_NONE, // No tip, and no button hilited
|
|
|
|
TIP_WAIT, // A button is hilited, but not yet ready to show the tip
|
|
|
|
TIP_ACTIVE, // A tip is being displayed
|
|
|
|
} tipState;
|
|
|
|
|
|
|
|
|
|
|
|
static SDWORD startTime; // When the tip was created
|
|
|
|
static SDWORD mx,my; // Last mouse coords
|
|
|
|
static SDWORD wx,wy,ww,wh; // Position and size of button to place tip by
|
|
|
|
static SDWORD tx,ty,tw,th; // Position and size of the tip box
|
|
|
|
static SDWORD fx,fy; // Position of the text
|
2007-04-09 07:41:22 -07:00
|
|
|
static const char *pTip; // Tip text
|
2007-12-09 08:09:23 -08:00
|
|
|
static PIELIGHT *pColours; // The colours for the tool tip
|
2007-06-28 10:47:08 -07:00
|
|
|
static WIDGET *psWidget; // The button the tip is for
|
2008-03-23 11:12:23 -07:00
|
|
|
static enum iV_fonts FontID = font_regular; // ID for the Ivis Font.
|
2007-12-09 08:09:23 -08:00
|
|
|
static PIELIGHT TipColour;
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
/* Initialise the tool tip module */
|
|
|
|
void tipInitialise(void)
|
|
|
|
{
|
|
|
|
tipState = TIP_NONE;
|
2007-12-09 08:09:23 -08:00
|
|
|
TipColour = WZCOL_WHITE;
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set the global toop tip text colour.
|
2008-04-20 10:17:50 -07:00
|
|
|
void widgSetTipColour(PIELIGHT colour)
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
2007-12-09 08:09:23 -08:00
|
|
|
TipColour = colour;
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Setup a tool tip.
|
|
|
|
* The tip module will then wait until the correct points to
|
|
|
|
* display and then remove the tool tip.
|
|
|
|
* i.e. The tip will not be displayed immediately.
|
|
|
|
* Calling this while another tip is being displayed will restart
|
|
|
|
* the tip system.
|
|
|
|
* psSource is the widget that started the tip.
|
|
|
|
* x,y,width,height - specify the position of the button to place the
|
|
|
|
* tip by.
|
|
|
|
*/
|
2008-03-23 11:12:23 -07:00
|
|
|
void tipStart(WIDGET *psSource, const char *pNewTip, enum iV_fonts NewFontID,
|
2007-12-09 08:09:23 -08:00
|
|
|
PIELIGHT *pNewColours, SDWORD x, SDWORD y, UDWORD width, UDWORD height)
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
2007-04-03 06:20:41 -07:00
|
|
|
ASSERT( psSource != NULL,
|
2006-08-23 05:58:48 -07:00
|
|
|
"tipStart: Invalid widget pointer" );
|
2007-04-03 06:20:41 -07:00
|
|
|
// ASSERT( pNewTip != NULL,
|
2006-08-23 05:58:48 -07:00
|
|
|
// "tipStart: Invalid tip pointer" );
|
2007-04-03 06:20:41 -07:00
|
|
|
ASSERT( pNewColours != NULL,
|
2006-08-23 05:58:48 -07:00
|
|
|
"tipStart: Invalid colours pointer" );
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
tipState = TIP_WAIT;
|
2006-08-27 12:09:35 -07:00
|
|
|
startTime = SDL_GetTicks();
|
2007-06-28 10:47:08 -07:00
|
|
|
mx = mouseX();
|
|
|
|
my = mouseY();
|
|
|
|
wx = x; wy = y;
|
|
|
|
ww = width; wh = height;
|
|
|
|
pTip = pNewTip;
|
|
|
|
psWidget = psSource;
|
|
|
|
FontID = NewFontID;
|
|
|
|
pColours = pNewColours;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Stop a tool tip (e.g. if the hilite is lost on a button).
|
|
|
|
* psSource should be the same as the widget that started the tip.
|
|
|
|
*/
|
|
|
|
void tipStop(WIDGET *psSource)
|
|
|
|
{
|
2007-04-03 06:20:41 -07:00
|
|
|
ASSERT( psSource != NULL,
|
2006-08-23 05:58:48 -07:00
|
|
|
"tipStop: Invalid widget pointer" );
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
if (tipState != TIP_NONE && psSource == psWidget)
|
|
|
|
{
|
|
|
|
tipState = TIP_NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define RIGHTBORDER (0)
|
|
|
|
#define BOTTOMBORDER (0)
|
|
|
|
|
|
|
|
|
|
|
|
/* Update and possibly display the tip */
|
|
|
|
void tipDisplay(void)
|
|
|
|
{
|
|
|
|
SDWORD newMX,newMY;
|
|
|
|
SDWORD currTime;
|
|
|
|
SDWORD fw, topGap;
|
|
|
|
// UDWORD time;
|
|
|
|
|
|
|
|
switch (tipState)
|
|
|
|
{
|
|
|
|
case TIP_WAIT:
|
|
|
|
/* See if the tip has to be shown */
|
|
|
|
newMX = mouseX();
|
|
|
|
newMY = mouseY();
|
2006-08-27 12:09:35 -07:00
|
|
|
currTime = SDL_GetTicks();
|
2007-06-28 10:47:08 -07:00
|
|
|
if (newMX == mx &&
|
|
|
|
newMY == my &&
|
|
|
|
(currTime - startTime > TIP_PAUSE))
|
|
|
|
{
|
|
|
|
/* Activate the tip */
|
|
|
|
tipState = TIP_ACTIVE;
|
|
|
|
|
|
|
|
/* Calculate the size of the tip box */
|
|
|
|
topGap = TIP_VGAP;
|
|
|
|
iV_SetFont(FontID);
|
|
|
|
|
|
|
|
fw = iV_GetTextWidth(pTip);
|
|
|
|
tw = fw + TIP_HGAP*2;
|
|
|
|
th = topGap*2 + iV_GetTextLineSize()+iV_GetTextBelowBase();
|
|
|
|
|
|
|
|
/* Position the tip box */
|
|
|
|
tx = wx + (ww >> 1);
|
|
|
|
ty = wy + wh + TIP_VGAP;
|
|
|
|
|
|
|
|
/* Check the box is on screen */
|
|
|
|
if (tx < 0)
|
|
|
|
{
|
|
|
|
tx = 0;
|
|
|
|
}
|
|
|
|
if (tx + tw >= (SDWORD)screenWidth-RIGHTBORDER)
|
|
|
|
{
|
|
|
|
tx = screenWidth-RIGHTBORDER - tw - 1;
|
|
|
|
}
|
|
|
|
if (ty < 0)
|
|
|
|
{
|
|
|
|
ty = 0;
|
|
|
|
}
|
|
|
|
if (ty + th >= (SDWORD)screenHeight-BOTTOMBORDER)
|
|
|
|
{
|
|
|
|
/* Position the tip above the button */
|
|
|
|
ty = wy - th - TIP_VGAP;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Position the text */
|
|
|
|
fx = tx + TIP_HGAP;
|
|
|
|
|
|
|
|
fy = ty + (th - iV_GetTextLineSize())/2 - iV_GetTextAboveBase();
|
|
|
|
|
|
|
|
|
|
|
|
/* Note the time */
|
2006-08-27 12:09:35 -07:00
|
|
|
startTime = SDL_GetTicks();
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
else if (newMX != mx ||
|
|
|
|
newMY != my ||
|
|
|
|
mousePressed(MOUSE_LMB))
|
|
|
|
{
|
|
|
|
mx = newMX;
|
|
|
|
my = newMY;
|
|
|
|
startTime = currTime;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TIP_ACTIVE:
|
|
|
|
/* See if the tip still needs to be displayed */
|
|
|
|
// time = GetTickCount();
|
|
|
|
// if (mousePressed(MOUSE_LMB) ||
|
|
|
|
// ((time - startTime) > TIP_TIME))
|
|
|
|
// {
|
|
|
|
// tipState = TIP_NONE;
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
/* Draw the tool tip */
|
2007-12-09 08:09:23 -08:00
|
|
|
pie_BoxFill(tx,ty, tx+tw, ty+th, pColours[WCOL_TIPBKGRND]);
|
2007-11-26 13:04:42 -08:00
|
|
|
iV_Box(tx,ty, tx+tw-1, ty+th-1, pColours[WCOL_LIGHT]);
|
|
|
|
iV_Line(tx+1, ty+th-2, tx+1, ty+1, pColours[WCOL_DARK]);
|
|
|
|
iV_Line(tx+2, ty+1, tx+tw-2, ty+1, pColours[WCOL_DARK]);
|
|
|
|
iV_Line(tx, ty+th, tx+tw, ty+th, pColours[WCOL_DARK]);
|
|
|
|
iV_Line(tx+tw,ty+th-1, tx+tw, ty, pColours[WCOL_DARK]);
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
iV_SetFont(FontID);
|
2007-12-09 08:09:23 -08:00
|
|
|
iV_SetTextColour(TipColour);
|
2007-06-28 10:47:08 -07:00
|
|
|
iV_DrawText(pTip,fx,fy);
|
|
|
|
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|