Skip to content

Commit

Permalink
move tooltip defaults to control.cpp, fix padding, fix border stacking
Browse files Browse the repository at this point in the history
  • Loading branch information
FranciscoDA committed Mar 7, 2019
1 parent 42b30ef commit 1af6d7a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
26 changes: 17 additions & 9 deletions forms/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@ Control::Control(bool takesFocus)
: mouseInside(false), mouseDepressed(false), resolvedLocation(0, 0), Visible(true),
Name("Control"), Location(0, 0), Size(0, 0), SelectionSize(0, 0),
BackgroundColour(0, 0, 0, 0), takesFocus(takesFocus), showBounds(false), Enabled(true),
canCopy(true), funcPreRender(nullptr)
canCopy(true), funcPreRender(nullptr),
// Tooltip defaults
ToolTipBackground{128, 128, 128}, ToolTipBorders{
{1, {0, 0, 0}}, {1, {255, 255, 255}}, {1, {0, 0, 0, 0}}}
{
// Tooltip defaults
ToolTipBackground = {128, 128, 128};
ToolTipBorders = {{1, {0, 0, 0}}, {1, {255, 255, 255}}};
ToolTipPadding = 1;
}

Control::~Control() { unloadResources(); }
Expand Down Expand Up @@ -302,7 +301,7 @@ void Control::eventOccured(Event *e)

sp<Image> textImage = ToolTipFont->getString(ToolTipText);

unsigned totalBorder = ToolTipPadding;
unsigned totalBorder = 0;
for (const auto &b : ToolTipBorders)
totalBorder += b.first;

Expand All @@ -315,8 +314,9 @@ void Control::eventOccured(Event *e)
int i = 0;
for (const auto &b : ToolTipBorders)
{
fw().renderer->drawRect(
{i, i}, surface->size - Vec2<unsigned int>{i * 2, i * 2}, b.second);
fw().renderer->drawRect({i, i},
surface->size - Vec2<unsigned int>{i * 2, i * 2},
b.second, b.first);
i += b.first;
}
fw().renderer->draw(textImage, {totalBorder, totalBorder});
Expand Down Expand Up @@ -732,6 +732,7 @@ void Control::configureSelfFromXml(pugi::xml_node *node)
else
ToolTipBackground = Colour::FromHtmlName(backgroundString);
}
size_t numDefaultBorders = ToolTipBorders.size();
for (auto child2 = child.first_child(); child2; child2 = child2.next_sibling())
{
UString child2Name = child2.name();
Expand All @@ -743,9 +744,17 @@ void Control::configureSelfFromXml(pugi::xml_node *node)
borderColour = Colour::FromHex(borderColourStr);
else
borderColour = Colour::FromHtmlName(borderColourStr);
borderColour.a = child2.attribute("alpha").as_uint(255);
ToolTipBorders.emplace_back(child2.attribute("width").as_uint(1), borderColour);
}
}
if (numDefaultBorders != ToolTipBorders.size())
{
// this means that the xml file has specified what border styles to use
// we have to remove the default borders so the new ones don't stack over them
ToolTipBorders.erase(ToolTipBorders.begin(),
ToolTipBorders.begin() + numDefaultBorders);
}
}
}

Expand Down Expand Up @@ -1009,7 +1018,6 @@ void Control::copyControlData(sp<Control> CopyOf)
CopyOf->ToolTipFont = this->ToolTipFont;
CopyOf->ToolTipBackground = this->ToolTipBackground;
CopyOf->ToolTipBorders = this->ToolTipBorders;
CopyOf->ToolTipPadding = this->ToolTipPadding;

for (auto &c : Controls)
{
Expand Down
5 changes: 2 additions & 3 deletions forms/control.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,8 @@ class Control : public std::enable_shared_from_this<Control>
UString ToolTipText;
sp<BitmapFont> ToolTipFont;
// transparent background by default
Colour ToolTipBackground = {0, 0, 0, 0};
std::list<std::pair<unsigned int, Colour>> ToolTipBorders;
unsigned int ToolTipPadding = 0;
Colour ToolTipBackground;
std::vector<std::pair<unsigned int, Colour>> ToolTipBorders;

bool canCopy;
wp<Control> lastCopiedTo;
Expand Down

0 comments on commit 1af6d7a

Please sign in to comment.