From 9ccd25dd32a6fcebf19a44c368a5c40f630571e3 Mon Sep 17 00:00:00 2001 From: Marukyu Date: Fri, 14 Oct 2016 21:40:32 +0200 Subject: [PATCH] Improved readability of editor tooltip by adding translucent background --- src/Client/GUI2/Widget.cpp | 2 +- src/Client/System/NEWindow.cpp | 12 +++++++++++- src/Client/System/NEWindow.hpp | 2 ++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Client/GUI2/Widget.cpp b/src/Client/GUI2/Widget.cpp index 4d66cb0..a73a17a 100644 --- a/src/Client/GUI2/Widget.cpp +++ b/src/Client/GUI2/Widget.cpp @@ -396,7 +396,7 @@ void Widget::process(const WidgetEvents & events) myIsClicked = 0; // set mouse-over flag. mouse position is already pre-transformed. - bool mouseOver = events.mouseFocus && checkMouseover(events.mousePosition); + bool mouseOver = events.mouseFocus && checkMouseover(events.mousePosition) && isEnabled(); if (myIsMouseOver != mouseOver) { diff --git a/src/Client/System/NEWindow.cpp b/src/Client/System/NEWindow.cpp index 3276df8..034745b 100644 --- a/src/Client/System/NEWindow.cpp +++ b/src/Client/System/NEWindow.cpp @@ -179,8 +179,15 @@ void NEWindow::initPanels() tooltip = gui2::Text::make(); tooltip->setZPosition(10); - tooltip->setEnabled(false); + tooltip->setTextColor(sf::Color(255, 255, 255, 220)); add(tooltip); + + tooltipBackground = gui2::Gradient::make(); + tooltipBackground->setColorA(sf::Color(0, 0, 0, 150)); + tooltipBackground->setColorB(sf::Color(0, 0, 0, 150)); + tooltipBackground->setZPosition(9); + tooltipBackground->setEnabled(false); + add(tooltipBackground); } void NEWindow::initLevelPanel() @@ -336,6 +343,7 @@ void NEWindow::updateTilePanels() void NEWindow::updateTooltip() { float tooltipMargin = 10.f; + sf::Vector2f tooltipExpansion(3.f, 3.f); tooltip->setTextAlignment(gui2::Text::AlignBottomLeft); tooltip->setPosition(mainPanel->getSideSize(gui2::BorderPanel::Left) + tooltipMargin, getSize().y / getViewMultiplier() - tooltipMargin); @@ -354,6 +362,8 @@ void NEWindow::updateTooltip() } tooltip->setText(joinStrings(tooltips, "\n", true)); + tooltipBackground->setVisible(!tooltip->getText().empty()); + tooltipBackground->setRect(moveRect(expandRect(tooltip->getTextRect(), tooltipExpansion), tooltip->getPosition())); } void NEWindow::onProcessWindow(const gui2::WidgetEvents& events) diff --git a/src/Client/System/NEWindow.hpp b/src/Client/System/NEWindow.hpp index 9a84790..db466a4 100644 --- a/src/Client/System/NEWindow.hpp +++ b/src/Client/System/NEWindow.hpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -106,6 +107,7 @@ class NEWindow : public gui2::Window gui2::Ptr editor; gui2::Ptr tooltip; + gui2::Ptr tooltipBackground; std::vector floors, walls;