Varying borders for button, exit dropdown menu with Esc or outside click, fixes #100
This commit is contained in:
parent
d5e57e04d0
commit
db519a7036
@ -30,6 +30,7 @@ namespace ui
|
|||||||
BorderDisabled(100, 100, 100),
|
BorderDisabled(100, 100, 100),
|
||||||
|
|
||||||
Margin(1, 4),
|
Margin(1, 4),
|
||||||
|
Border(1),
|
||||||
|
|
||||||
icon(NoIcon),
|
icon(NoIcon),
|
||||||
|
|
||||||
|
@ -49,6 +49,8 @@ namespace ui
|
|||||||
|
|
||||||
ui::Border Margin;
|
ui::Border Margin;
|
||||||
|
|
||||||
|
ui::Border Border;
|
||||||
|
|
||||||
Icon icon;
|
Icon icon;
|
||||||
|
|
||||||
VideoBuffer * GetTexture();
|
VideoBuffer * GetTexture();
|
||||||
|
@ -41,9 +41,14 @@ namespace ui
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline bool operator == (const int& v) const
|
||||||
|
{
|
||||||
|
return (Top == v && Right == v && Bottom == v && Left == v);
|
||||||
|
}
|
||||||
|
|
||||||
inline bool operator == (const Border& v) const
|
inline bool operator == (const Border& v) const
|
||||||
{
|
{
|
||||||
return (Top == v.Top || Right == v.Right || Bottom == v.Bottom || Left == v.Left);
|
return (Top == v.Top && Right == v.Right && Bottom == v.Bottom && Left == v.Left);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool operator != (const Border& v) const
|
inline bool operator != (const Border& v) const
|
||||||
|
@ -121,7 +121,19 @@ void Button::Draw(const Point& screenPos)
|
|||||||
|
|
||||||
bgColour = Appearance.BackgroundInactive;
|
bgColour = Appearance.BackgroundInactive;
|
||||||
g->fillrect(Position.X+1, Position.Y+1, Size.X-2, Size.Y-2, backgroundColour.Red, backgroundColour.Green, backgroundColour.Blue, backgroundColour.Alpha);
|
g->fillrect(Position.X+1, Position.Y+1, Size.X-2, Size.Y-2, backgroundColour.Red, backgroundColour.Green, backgroundColour.Blue, backgroundColour.Alpha);
|
||||||
|
if(Appearance.Border == 1)
|
||||||
g->drawrect(Position.X, Position.Y, Size.X, Size.Y, borderColour.Red, borderColour.Green, borderColour.Blue, borderColour.Alpha);
|
g->drawrect(Position.X, Position.Y, Size.X, Size.Y, borderColour.Red, borderColour.Green, borderColour.Blue, borderColour.Alpha);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(Appearance.Border.Top)
|
||||||
|
g->draw_line(Position.X, Position.Y, Position.X+Size.X-1, Position.Y, borderColour.Red, borderColour.Green, borderColour.Blue, borderColour.Alpha);
|
||||||
|
if(Appearance.Border.Bottom)
|
||||||
|
g->draw_line(Position.X, Position.Y+Size.Y-1, Position.X+Size.X-1, Position.Y+Size.Y-1, borderColour.Red, borderColour.Green, borderColour.Blue, borderColour.Alpha);
|
||||||
|
if(Appearance.Border.Left)
|
||||||
|
g->draw_line(Position.X, Position.Y, Position.X, Position.Y+Size.Y-1, borderColour.Red, borderColour.Green, borderColour.Blue, borderColour.Alpha);
|
||||||
|
if(Appearance.Border.Right)
|
||||||
|
g->draw_line(Position.X+Size.X-1, Position.Y, Position.X+Size.X-1, Position.Y+Size.Y-1, borderColour.Red, borderColour.Green, borderColour.Blue, borderColour.Alpha);
|
||||||
|
}
|
||||||
g->drawtext(Position.X+textPosition.X, Position.Y+textPosition.Y, buttonDisplayText, textColour.Red, textColour.Green, textColour.Blue, textColour.Alpha);
|
g->drawtext(Position.X+textPosition.X, Position.Y+textPosition.Y, buttonDisplayText, textColour.Red, textColour.Green, textColour.Blue, textColour.Alpha);
|
||||||
|
|
||||||
bool iconInvert = (backgroundColour.Blue + (3*backgroundColour.Green) + (2*backgroundColour.Red))>544?true:false;
|
bool iconInvert = (backgroundColour.Blue + (3*backgroundColour.Green) + (2*backgroundColour.Red))>544?true:false;
|
||||||
|
@ -43,16 +43,17 @@ public:
|
|||||||
{
|
{
|
||||||
Button * tempButton = new Button(Point(1, currentY), Point(Size.X-2, 16), dropDown->options[i].first);
|
Button * tempButton = new Button(Point(1, currentY), Point(Size.X-2, 16), dropDown->options[i].first);
|
||||||
tempButton->Appearance = appearance;
|
tempButton->Appearance = appearance;
|
||||||
|
if(i)
|
||||||
|
tempButton->Appearance.Border = ui::Border(0, 1, 1, 1);
|
||||||
tempButton->SetActionCallback(new ItemSelectedAction(this, dropDown->options[i].first));
|
tempButton->SetActionCallback(new ItemSelectedAction(this, dropDown->options[i].first));
|
||||||
AddComponent(tempButton);
|
AddComponent(tempButton);
|
||||||
currentY += 15;
|
currentY += 16;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
virtual void OnDraw()
|
virtual void OnDraw()
|
||||||
{
|
{
|
||||||
Graphics * g = ui::Engine::Ref().g;
|
Graphics * g = ui::Engine::Ref().g;
|
||||||
g->fillrect(Position.X, Position.Y, Size.X, Size.Y, 100, 100, 100, 255);
|
g->clearrect(Position.X, Position.Y, Size.X, Size.Y);
|
||||||
g->drawrect(Position.X, Position.Y, Size.X, Size.Y, appearance.BackgroundInactive.Red, appearance.BackgroundInactive.Green, appearance.BackgroundInactive.Blue, appearance.BackgroundInactive.Alpha);
|
|
||||||
}
|
}
|
||||||
void setOption(std::string option)
|
void setOption(std::string option)
|
||||||
{
|
{
|
||||||
@ -68,6 +69,10 @@ public:
|
|||||||
dropDown->callback->OptionChanged(dropDown, dropDown->options[optionIndex]);
|
dropDown->callback->OptionChanged(dropDown, dropDown->options[optionIndex]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
virtual void OnTryExit(ExitMethod method)
|
||||||
|
{
|
||||||
|
SelfDestruct();
|
||||||
|
}
|
||||||
virtual ~DropDownWindow() {}
|
virtual ~DropDownWindow() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -95,23 +100,39 @@ void DropDown::Draw(const Point& screenPos)
|
|||||||
}
|
}
|
||||||
Graphics * g = ui::Engine::Ref().g;
|
Graphics * g = ui::Engine::Ref().g;
|
||||||
Point Position = screenPos;
|
Point Position = screenPos;
|
||||||
if(isMouseInside)
|
|
||||||
|
ui::Colour textColour = Appearance.TextInactive;
|
||||||
|
ui::Colour borderColour = Appearance.BorderInactive;
|
||||||
|
ui::Colour backgroundColour = Appearance.BackgroundInactive;
|
||||||
|
|
||||||
|
if (isMouseInside)
|
||||||
{
|
{
|
||||||
g->fillrect(Position.X-1, Position.Y-1, Size.X+2, Size.Y+2, Appearance.BackgroundActive.Red, Appearance.BackgroundActive.Green, Appearance.BackgroundActive.Blue, 255);
|
textColour = Appearance.TextHover;
|
||||||
g->drawrect(Position.X, Position.Y, Size.X, Size.Y, Appearance.BorderActive.Red, Appearance.BorderActive.Green, Appearance.BorderActive.Blue, 255);
|
borderColour = Appearance.BorderHover;
|
||||||
if(optionIndex!=-1)
|
backgroundColour = Appearance.BackgroundHover;
|
||||||
g->drawtext(Position.X+textPosition.X, Position.Y+textPosition.Y, options[optionIndex].first, Appearance.TextActive.Red, Appearance.TextActive.Green, Appearance.TextActive.Blue, 255);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
g->fillrect(Position.X, Position.Y, Size.X, Size.Y, Appearance.BackgroundInactive.Red, Appearance.BackgroundInactive.Green, Appearance.BackgroundInactive.Blue, 255);
|
textColour = Appearance.TextInactive;
|
||||||
g->drawrect(Position.X, Position.Y, Size.X, Size.Y, Appearance.BorderInactive.Red, Appearance.BorderInactive.Green, Appearance.BorderInactive.Blue, 255);
|
borderColour = Appearance.BorderInactive;
|
||||||
if(optionIndex!=-1)
|
backgroundColour = Appearance.BackgroundInactive;
|
||||||
g->drawtext(Position.X+textPosition.X, Position.Y+textPosition.Y, options[optionIndex].first, Appearance.TextInactive.Red, Appearance.TextInactive.Green, Appearance.TextInactive.Blue, 255);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g->fillrect(Position.X-1, Position.Y-1, Size.X+2, Size.Y+2, backgroundColour.Red, backgroundColour.Green, backgroundColour.Blue, backgroundColour.Alpha);
|
||||||
|
g->drawrect(Position.X, Position.Y, Size.X, Size.Y, borderColour.Red, borderColour.Green, borderColour.Blue, borderColour.Alpha);
|
||||||
|
if(optionIndex!=-1)
|
||||||
|
g->drawtext(Position.X+textPosition.X, Position.Y+textPosition.Y, options[optionIndex].first, textColour.Red, textColour.Green, textColour.Blue, textColour.Alpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DropDown::OnMouseEnter(int x, int y)
|
||||||
|
{
|
||||||
|
isMouseInside = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DropDown::OnMouseLeave(int x, int y)
|
||||||
|
{
|
||||||
|
isMouseInside = false;
|
||||||
|
}
|
||||||
std::pair<std::string, int> DropDown::GetOption()
|
std::pair<std::string, int> DropDown::GetOption()
|
||||||
{
|
{
|
||||||
if(optionIndex!=-1)
|
if(optionIndex!=-1)
|
||||||
|
@ -39,6 +39,8 @@ public:
|
|||||||
void SetActionCallback(DropDownAction * action) { callback = action;}
|
void SetActionCallback(DropDownAction * action) { callback = action;}
|
||||||
virtual void Draw(const Point& screenPos);
|
virtual void Draw(const Point& screenPos);
|
||||||
virtual void OnMouseClick(int x, int y, unsigned int button);
|
virtual void OnMouseClick(int x, int y, unsigned int button);
|
||||||
|
virtual void OnMouseEnter(int x, int y);
|
||||||
|
virtual void OnMouseLeave(int x, int y);
|
||||||
virtual ~DropDown();
|
virtual ~DropDown();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user