Skip to content

Commit

Permalink
Implemented tooltip element descriptor display in element search.
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertBScott authored and jacob1 committed Nov 23, 2017
1 parent b5bc4ad commit 4c3b4da
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
26 changes: 25 additions & 1 deletion src/gui/elementsearch/ElementSearchActivity.cpp
Expand Up @@ -30,7 +30,9 @@ ElementSearchActivity::ElementSearchActivity(GameController * gameController, st
shiftPressed(false),
ctrlPressed(false),
altPressed(false),
exit(false)
exit(false),
toolTip(""),
isToolTipFadingIn(false)
{
ui::Label * title = new ui::Label(ui::Point(4, 5), ui::Point(Size.X-8, 15), "Element Search");
title->SetTextColour(style::Colour::InformationTitle);
Expand Down Expand Up @@ -193,12 +195,28 @@ void ElementSearchActivity::OnDraw()
g->drawrect(Position.X, Position.Y, Size.X, Size.Y, 255, 255, 255, 255);

g->drawrect(Position.X+searchField->Position.X, Position.Y+searchField->Position.Y+searchField->Size.Y+8, searchField->Size.X, Size.Y-(searchField->Position.Y+searchField->Size.Y+8)-23, 255, 255, 255, 180);
if (toolTipPresence && toolTip.length())
{
g->drawtext(10, Size.Y+70, (char*)toolTip.c_str(), 255, 255, 255, toolTipPresence>51?255:toolTipPresence*5);
}
}

void ElementSearchActivity::OnTick(float dt)
{
if (exit)
Exit();
if (isToolTipFadingIn)
{
isToolTipFadingIn = false;
if (toolTipPresence < 120)
toolTipPresence += int(dt*2)>1?int(dt*2):2;
}
if (toolTipPresence>0)
{
toolTipPresence -= int(dt)>0?int(dt):1;
if (toolTipPresence<0)
toolTipPresence = 0;
}
}

void ElementSearchActivity::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt)
Expand Down Expand Up @@ -246,6 +264,12 @@ void ElementSearchActivity::OnKeyRelease(int key, Uint16 character, bool shift,
}
}

void ElementSearchActivity::ToolTip(ui::Point senderPosition, std::string toolTip)
{
this->toolTip = toolTip;
this->isToolTipFadingIn = true;
}

ElementSearchActivity::~ElementSearchActivity() {
}

6 changes: 5 additions & 1 deletion src/gui/elementsearch/ElementSearchActivity.h
Expand Up @@ -18,9 +18,12 @@ class ElementSearchActivity: public WindowActivity
std::vector<Tool*> tools;
ui::Textbox * searchField;
std::vector<ToolButton*> toolButtons;
std::string toolTip;
int toolTipPresence;
bool shiftPressed;
bool ctrlPressed;
bool altPressed;
bool isToolTipFadingIn;
void searchTools(std::string query);

public:
Expand All @@ -30,10 +33,11 @@ class ElementSearchActivity: public WindowActivity
ElementSearchActivity(GameController * gameController, std::vector<Tool*> tools);
void SetActiveTool(int selectionState, Tool * tool);
virtual ~ElementSearchActivity();
virtual void OnDraw();
virtual void OnTick(float dt);
virtual void OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt);
virtual void OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt);
virtual void OnDraw();
virtual void ToolTip(ui::Point senderPosition, std::string ToolTip);
};

#endif /* ELEMENTSEARCHACTIVITY_H_ */

0 comments on commit 4c3b4da

Please sign in to comment.