Skip to content

Commit

Permalink
Improved readability of editor tooltip by adding translucent background
Browse files Browse the repository at this point in the history
  • Loading branch information
Marukyu committed Oct 14, 2016
1 parent fa3275c commit 9ccd25d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Client/GUI2/Widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
12 changes: 11 additions & 1 deletion src/Client/System/NEWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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);
Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/Client/System/NEWindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <Client/GUI2/Panels/BorderPanel.hpp>
#include <Client/GUI2/Panels/GridPanel.hpp>
#include <Client/GUI2/Widgets/Button.hpp>
#include <Client/GUI2/Widgets/Gradient.hpp>
#include <Client/GUI2/Widgets/MessageBox.hpp>
#include <Client/GUI2/Widgets/Text.hpp>
#include <Shared/Level/Tile.hpp>
Expand Down Expand Up @@ -106,6 +107,7 @@ class NEWindow : public gui2::Window
gui2::Ptr<Editor> editor;

gui2::Ptr<gui2::Text> tooltip;
gui2::Ptr<gui2::Gradient> tooltipBackground;

std::vector<Tile> floors, walls;

Expand Down

0 comments on commit 9ccd25d

Please sign in to comment.