From 07486c9885fdfde734c5f052a8c31e1af26acfeb Mon Sep 17 00:00:00 2001 From: jacob1 Date: Sat, 4 May 2013 23:03:59 -0400 Subject: [PATCH] drawtext_outline to fix unreadable infotips, tooltips fade in and out (more like old tpt) --- src/graphics/Graphics.h | 1 + src/graphics/OpenGLDrawMethods.inl | 12 +++++++++++ src/graphics/RasterDrawMethods.inl | 11 ++++++++++ src/graphics/Renderer.h | 1 + src/gui/game/GameView.cpp | 34 ++++++++++++++++++------------ src/gui/interface/Button.cpp | 5 ++++- src/gui/interface/Button.h | 1 + 7 files changed, 51 insertions(+), 14 deletions(-) diff --git a/src/graphics/Graphics.h b/src/graphics/Graphics.h index e2ed119c1..3a87bb665 100644 --- a/src/graphics/Graphics.h +++ b/src/graphics/Graphics.h @@ -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); diff --git a/src/graphics/OpenGLDrawMethods.inl b/src/graphics/OpenGLDrawMethods.inl index 1ecd6b10d..bfc338a77 100644 --- a/src/graphics/OpenGLDrawMethods.inl +++ b/src/graphics/OpenGLDrawMethods.inl @@ -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; diff --git a/src/graphics/RasterDrawMethods.inl b/src/graphics/RasterDrawMethods.inl index 527d249a2..b4de87554 100644 --- a/src/graphics/RasterDrawMethods.inl +++ b/src/graphics/RasterDrawMethods.inl @@ -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)) diff --git a/src/graphics/Renderer.h b/src/graphics/Renderer.h index 6328c1950..92510069e 100644 --- a/src/graphics/Renderer.h +++ b/src/graphics/Renderer.h @@ -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); diff --git a/src/gui/game/GameView.cpp b/src/gui/game/GameView.cpp index 27b7b8412..a21ec431b 100644 --- a/src/gui/game/GameView.cpp +++ b/src/gui/game/GameView.cpp @@ -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 diff --git a/src/gui/interface/Button.cpp b/src/gui/interface/Button.cpp index 3f08153d6..37ef22dba 100644 --- a/src/gui/interface/Button.cpp +++ b/src/gui/interface/Button.cpp @@ -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; diff --git a/src/gui/interface/Button.h b/src/gui/interface/Button.h index 05f466d4b..42b0b4495 100644 --- a/src/gui/interface/Button.h +++ b/src/gui/interface/Button.h @@ -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);