mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-29 19:00:33 +02:00
drawtext_outline to fix unreadable infotips, tooltips fade in and out (more like old tpt)
This commit is contained in:
@@ -225,6 +225,7 @@ public:
|
|||||||
void Clear();
|
void Clear();
|
||||||
void Finalise();
|
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, 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 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);
|
int drawchar(int x, int y, int c, int r, int g, int b, int a);
|
||||||
|
@@ -1,4 +1,16 @@
|
|||||||
#include "../data/font.h"
|
#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)
|
int PIXELMETHODS_CLASS::drawtext(int x, int y, const char *s, int r, int g, int b, int a)
|
||||||
{
|
{
|
||||||
bool invert = false;
|
bool invert = false;
|
||||||
|
@@ -1,5 +1,16 @@
|
|||||||
#include "font.h"
|
#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)
|
int PIXELMETHODS_CLASS::drawtext(int x, int y, const char *s, int r, int g, int b, int a)
|
||||||
{
|
{
|
||||||
if(!strlen(s))
|
if(!strlen(s))
|
||||||
|
@@ -112,6 +112,7 @@ public:
|
|||||||
|
|
||||||
void draw_icon(int x, int y, Icon icon);
|
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, 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 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);
|
int drawchar(int x, int y, int c, int r, int g, int b, int a);
|
||||||
|
@@ -1149,9 +1149,13 @@ void GameView::ExitPrompt()
|
|||||||
void GameView::ToolTip(ui::Component * sender, ui::Point mousePosition, std::string toolTip)
|
void GameView::ToolTip(ui::Component * sender, ui::Point mousePosition, std::string toolTip)
|
||||||
{
|
{
|
||||||
if(sender->Position.Y > Size.Y-17)
|
if(sender->Position.Y > Size.Y-17)
|
||||||
|
{
|
||||||
|
if (selectMode == PlaceSave || selectMode == SelectNone)
|
||||||
{
|
{
|
||||||
buttonTip = toolTip;
|
buttonTip = toolTip;
|
||||||
buttonTipShow = 120;
|
if (buttonTipShow < 120)
|
||||||
|
buttonTipShow += 3;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if(sender->Position.X > Size.X-BARSIZE)// < Size.Y-(quickOptionButtons.size()+1)*16)
|
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);
|
toolTipPosition = ui::Point(Size.X-27-Graphics::textwidth((char*)toolTip.c_str()), sender->Position.Y+3);
|
||||||
if(toolTipPosition.Y+10 > Size.Y-MENUSIZE)
|
if(toolTipPosition.Y+10 > Size.Y-MENUSIZE)
|
||||||
toolTipPosition = ui::Point(Size.X-27-Graphics::textwidth((char*)toolTip.c_str()), Size.Y-MENUSIZE-10);
|
toolTipPosition = ui::Point(Size.X-27-Graphics::textwidth((char*)toolTip.c_str()), Size.Y-MENUSIZE-10);
|
||||||
toolTipPresence = 120;
|
if (toolTipPresence < 120)
|
||||||
|
toolTipPresence += 3;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this->toolTip = toolTip;
|
this->toolTip = toolTip;
|
||||||
toolTipPosition = ui::Point(Size.X-27-Graphics::textwidth((char*)toolTip.c_str()), Size.Y-MENUSIZE-10);
|
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;
|
selectMode = SelectStamp;
|
||||||
selectPoint1 = ui::Point(-1, -1);
|
selectPoint1 = ui::Point(-1, -1);
|
||||||
infoTip = "\x0F\xEF\xEF\x10Select an area to create a stamp";
|
buttonTip = "\x0F\xEF\xEF\x10Click-and-drag to specify an area to create a stamp (right click = cancel)";
|
||||||
infoTipPresence = 120;
|
buttonTipShow = 120;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt)
|
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;
|
selectMode = SelectCopy;
|
||||||
selectPoint1 = ui::Point(-1, -1);
|
selectPoint1 = ui::Point(-1, -1);
|
||||||
infoTip = "\x0F\xEF\xEF\x10Select an area to copy";
|
buttonTip = "\x0F\xEF\xEF\x10Click-and-drag to specify an area to copy (right click = cancel)";
|
||||||
infoTipPresence = 120;
|
buttonTipShow = 120;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'x':
|
case 'x':
|
||||||
@@ -1391,8 +1397,8 @@ void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
|
|||||||
{
|
{
|
||||||
selectMode = SelectCut;
|
selectMode = SelectCut;
|
||||||
selectPoint1 = ui::Point(-1, -1);
|
selectPoint1 = ui::Point(-1, -1);
|
||||||
infoTip = "\x0F\xEF\xEF\x10Select an area to cut";
|
buttonTip = "\x0F\xEF\xEF\x10Click-and-drag to specify an area to copy then cut (right click = cancel)";
|
||||||
infoTipPresence = 120;
|
buttonTipShow = 120;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'v':
|
case 'v':
|
||||||
@@ -1519,7 +1525,9 @@ void GameView::OnTick(float dt)
|
|||||||
if(infoTipPresence<0)
|
if(infoTipPresence<0)
|
||||||
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;
|
buttonTipShow -= int(dt)>0?int(dt):1;
|
||||||
if(buttonTipShow<0)
|
if(buttonTipShow<0)
|
||||||
@@ -2110,7 +2118,7 @@ void GameView::OnDraw()
|
|||||||
if(infoTipPresence)
|
if(infoTipPresence)
|
||||||
{
|
{
|
||||||
int infoTipAlpha = (infoTipPresence>50?50:infoTipPresence)*5;
|
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())
|
if(toolTipPresence && toolTipPosition.X!=-1 && toolTipPosition.Y!=-1 && toolTip.length())
|
||||||
@@ -2120,7 +2128,7 @@ void GameView::OnDraw()
|
|||||||
|
|
||||||
if(buttonTipShow > 0)
|
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
|
//Introduction text
|
||||||
|
@@ -192,13 +192,16 @@ void Button::OnMouseEnter(int x, int y)
|
|||||||
return;
|
return;
|
||||||
if(actionCallback)
|
if(actionCallback)
|
||||||
actionCallback->MouseEnterCallback(this);
|
actionCallback->MouseEnterCallback(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Button::OnMouseHover(int x, int y)
|
||||||
|
{
|
||||||
if(toolTip.length()>0 && GetParentWindow())
|
if(toolTip.length()>0 && GetParentWindow())
|
||||||
{
|
{
|
||||||
GetParentWindow()->ToolTip(this, ui::Point(x, y), toolTip);
|
GetParentWindow()->ToolTip(this, ui::Point(x, y), toolTip);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Button::OnMouseLeave(int x, int y)
|
void Button::OnMouseLeave(int x, int y)
|
||||||
{
|
{
|
||||||
isMouseInside = false;
|
isMouseInside = false;
|
||||||
|
@@ -32,6 +32,7 @@ public:
|
|||||||
//virtual void OnMouseUp(int x, int y, unsigned int button);
|
//virtual void OnMouseUp(int x, int y, unsigned int button);
|
||||||
|
|
||||||
virtual void OnMouseEnter(int x, int y);
|
virtual void OnMouseEnter(int x, int y);
|
||||||
|
virtual void OnMouseHover(int x, int y);
|
||||||
virtual void OnMouseLeave(int x, int y);
|
virtual void OnMouseLeave(int x, int y);
|
||||||
|
|
||||||
virtual void Draw(const Point& screenPos);
|
virtual void Draw(const Point& screenPos);
|
||||||
|
Reference in New Issue
Block a user