drawtext_outline to fix unreadable infotips, tooltips fade in and out (more like old tpt)

This commit is contained in:
jacob1 2013-05-04 23:03:59 -04:00
parent 2d0ce60afe
commit 07486c9885
7 changed files with 51 additions and 14 deletions

View File

@ -225,6 +225,7 @@ public:
void Clear();
void Finalise();
//
int drawtext_outline(int x, int y, const char *s, int r, int g, int b, int a);
int drawtext(int x, int y, const char *s, int r, int g, int b, int a);
int drawtext(int x, int y, std::string s, int r, int g, int b, int a);
int drawchar(int x, int y, int c, int r, int g, int b, int a);

View File

@ -1,4 +1,16 @@
#include "../data/font.h"
int PIXELMETHODS_CLASS::drawtext_outline(int x, int y, const char *s, int r, int g, int b, int a)
{
drawtext(x-1, y-1, s, 0, 0, 0, 120);
drawtext(x+1, y+1, s, 0, 0, 0, 120);
drawtext(x-1, y+1, s, 0, 0, 0, 120);
drawtext(x+1, y-1, s, 0, 0, 0, 120);
return drawtext(x, y, s, r, g, b, a);
}
int PIXELMETHODS_CLASS::drawtext(int x, int y, const char *s, int r, int g, int b, int a)
{
bool invert = false;

View File

@ -1,5 +1,16 @@
#include "font.h"
int PIXELMETHODS_CLASS::drawtext_outline(int x, int y, const char *s, int r, int g, int b, int a)
{
drawtext(x-1, y-1, s, 0, 0, 0, 120);
drawtext(x+1, y+1, s, 0, 0, 0, 120);
drawtext(x-1, y+1, s, 0, 0, 0, 120);
drawtext(x+1, y-1, s, 0, 0, 0, 120);
return drawtext(x, y, s, r, g, b, a);
}
int PIXELMETHODS_CLASS::drawtext(int x, int y, const char *s, int r, int g, int b, int a)
{
if(!strlen(s))

View File

@ -112,6 +112,7 @@ public:
void draw_icon(int x, int y, Icon icon);
int drawtext_outline(int x, int y, const char *s, int r, int g, int b, int a);
int drawtext(int x, int y, const char *s, int r, int g, int b, int a);
int drawtext(int x, int y, std::string s, int r, int g, int b, int a);
int drawchar(int x, int y, int c, int r, int g, int b, int a);

View File

@ -1150,8 +1150,12 @@ void GameView::ToolTip(ui::Component * sender, ui::Point mousePosition, std::str
{
if(sender->Position.Y > Size.Y-17)
{
buttonTip = toolTip;
buttonTipShow = 120;
if (selectMode == PlaceSave || selectMode == SelectNone)
{
buttonTip = toolTip;
if (buttonTipShow < 120)
buttonTipShow += 3;
}
}
else if(sender->Position.X > Size.X-BARSIZE)// < Size.Y-(quickOptionButtons.size()+1)*16)
{
@ -1159,13 +1163,15 @@ void GameView::ToolTip(ui::Component * sender, ui::Point mousePosition, std::str
toolTipPosition = ui::Point(Size.X-27-Graphics::textwidth((char*)toolTip.c_str()), sender->Position.Y+3);
if(toolTipPosition.Y+10 > Size.Y-MENUSIZE)
toolTipPosition = ui::Point(Size.X-27-Graphics::textwidth((char*)toolTip.c_str()), Size.Y-MENUSIZE-10);
toolTipPresence = 120;
if (toolTipPresence < 120)
toolTipPresence += 3;
}
else
{
this->toolTip = toolTip;
toolTipPosition = ui::Point(Size.X-27-Graphics::textwidth((char*)toolTip.c_str()), Size.Y-MENUSIZE-10);
toolTipPresence = 160;
if (toolTipPresence < 160)
toolTipPresence += 3;
}
}
@ -1202,8 +1208,8 @@ void GameView::BeginStampSelection()
{
selectMode = SelectStamp;
selectPoint1 = ui::Point(-1, -1);
infoTip = "\x0F\xEF\xEF\x10Select an area to create a stamp";
infoTipPresence = 120;
buttonTip = "\x0F\xEF\xEF\x10Click-and-drag to specify an area to create a stamp (right click = cancel)";
buttonTipShow = 120;
}
void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt)
@ -1382,8 +1388,8 @@ void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
{
selectMode = SelectCopy;
selectPoint1 = ui::Point(-1, -1);
infoTip = "\x0F\xEF\xEF\x10Select an area to copy";
infoTipPresence = 120;
buttonTip = "\x0F\xEF\xEF\x10Click-and-drag to specify an area to copy (right click = cancel)";
buttonTipShow = 120;
}
break;
case 'x':
@ -1391,8 +1397,8 @@ void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
{
selectMode = SelectCut;
selectPoint1 = ui::Point(-1, -1);
infoTip = "\x0F\xEF\xEF\x10Select an area to cut";
infoTipPresence = 120;
buttonTip = "\x0F\xEF\xEF\x10Click-and-drag to specify an area to copy then cut (right click = cancel)";
buttonTipShow = 120;
}
break;
case 'v':
@ -1519,7 +1525,9 @@ void GameView::OnTick(float dt)
if(infoTipPresence<0)
infoTipPresence = 0;
}
if(buttonTipShow>0)
if (selectMode != PlaceSave && selectMode != SelectNone && buttonTipShow < 120)
buttonTipShow += 2;
else if(buttonTipShow>0)
{
buttonTipShow -= int(dt)>0?int(dt):1;
if(buttonTipShow<0)
@ -2110,7 +2118,7 @@ void GameView::OnDraw()
if(infoTipPresence)
{
int infoTipAlpha = (infoTipPresence>50?50:infoTipPresence)*5;
g->drawtext((XRES-Graphics::textwidth((char*)infoTip.c_str()))/2, (YRES/2)-2, (char*)infoTip.c_str(), 255, 255, 255, infoTipAlpha);
g->drawtext_outline((XRES-Graphics::textwidth((char*)infoTip.c_str()))/2, (YRES/2)-2, (char*)infoTip.c_str(), 255, 255, 255, infoTipAlpha);
}
if(toolTipPresence && toolTipPosition.X!=-1 && toolTipPosition.Y!=-1 && toolTip.length())
@ -2120,7 +2128,7 @@ void GameView::OnDraw()
if(buttonTipShow > 0)
{
g->drawtext(6, Size.Y-MENUSIZE-10, (char*)buttonTip.c_str(), 255, 255, 255, buttonTipShow>51?255:buttonTipShow*5);
g->drawtext(16, Size.Y-MENUSIZE-24, (char*)buttonTip.c_str(), 255, 255, 255, buttonTipShow>51?255:buttonTipShow*5);
}
//Introduction text

View File

@ -192,13 +192,16 @@ void Button::OnMouseEnter(int x, int y)
return;
if(actionCallback)
actionCallback->MouseEnterCallback(this);
}
void Button::OnMouseHover(int x, int y)
{
if(toolTip.length()>0 && GetParentWindow())
{
GetParentWindow()->ToolTip(this, ui::Point(x, y), toolTip);
}
}
void Button::OnMouseLeave(int x, int y)
{
isMouseInside = false;

View File

@ -32,6 +32,7 @@ public:
//virtual void OnMouseUp(int x, int y, unsigned int button);
virtual void OnMouseEnter(int x, int y);
virtual void OnMouseHover(int x, int y);
virtual void OnMouseLeave(int x, int y);
virtual void Draw(const Point& screenPos);