Varying borders for button, exit dropdown menu with Esc or outside click, fixes #100

This commit is contained in:
Simon Robertshaw 2012-08-14 14:22:41 +01:00
parent d5e57e04d0
commit db519a7036
6 changed files with 57 additions and 14 deletions

View File

@ -30,6 +30,7 @@ namespace ui
BorderDisabled(100, 100, 100),
Margin(1, 4),
Border(1),
icon(NoIcon),

View File

@ -49,6 +49,8 @@ namespace ui
ui::Border Margin;
ui::Border Border;
Icon icon;
VideoBuffer * GetTexture();

View File

@ -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
{
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

View File

@ -121,7 +121,19 @@ void Button::Draw(const Point& screenPos)
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);
if(Appearance.Border == 1)
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);
bool iconInvert = (backgroundColour.Blue + (3*backgroundColour.Green) + (2*backgroundColour.Red))>544?true:false;

View File

@ -43,16 +43,17 @@ public:
{
Button * tempButton = new Button(Point(1, currentY), Point(Size.X-2, 16), dropDown->options[i].first);
tempButton->Appearance = appearance;
if(i)
tempButton->Appearance.Border = ui::Border(0, 1, 1, 1);
tempButton->SetActionCallback(new ItemSelectedAction(this, dropDown->options[i].first));
AddComponent(tempButton);
currentY += 15;
currentY += 16;
}
}
virtual void OnDraw()
{
Graphics * g = ui::Engine::Ref().g;
g->fillrect(Position.X, Position.Y, Size.X, Size.Y, 100, 100, 100, 255);
g->drawrect(Position.X, Position.Y, Size.X, Size.Y, appearance.BackgroundInactive.Red, appearance.BackgroundInactive.Green, appearance.BackgroundInactive.Blue, appearance.BackgroundInactive.Alpha);
g->clearrect(Position.X, Position.Y, Size.X, Size.Y);
}
void setOption(std::string option)
{
@ -68,6 +69,10 @@ public:
dropDown->callback->OptionChanged(dropDown, dropDown->options[optionIndex]);
}
}
virtual void OnTryExit(ExitMethod method)
{
SelfDestruct();
}
virtual ~DropDownWindow() {}
};
@ -95,23 +100,39 @@ void DropDown::Draw(const Point& screenPos)
}
Graphics * g = ui::Engine::Ref().g;
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);
g->drawrect(Position.X, Position.Y, Size.X, Size.Y, Appearance.BorderActive.Red, Appearance.BorderActive.Green, Appearance.BorderActive.Blue, 255);
if(optionIndex!=-1)
g->drawtext(Position.X+textPosition.X, Position.Y+textPosition.Y, options[optionIndex].first, Appearance.TextActive.Red, Appearance.TextActive.Green, Appearance.TextActive.Blue, 255);
textColour = Appearance.TextHover;
borderColour = Appearance.BorderHover;
backgroundColour = Appearance.BackgroundHover;
}
else
{
g->fillrect(Position.X, Position.Y, Size.X, Size.Y, Appearance.BackgroundInactive.Red, Appearance.BackgroundInactive.Green, Appearance.BackgroundInactive.Blue, 255);
g->drawrect(Position.X, Position.Y, Size.X, Size.Y, Appearance.BorderInactive.Red, Appearance.BorderInactive.Green, Appearance.BorderInactive.Blue, 255);
if(optionIndex!=-1)
g->drawtext(Position.X+textPosition.X, Position.Y+textPosition.Y, options[optionIndex].first, Appearance.TextInactive.Red, Appearance.TextInactive.Green, Appearance.TextInactive.Blue, 255);
textColour = Appearance.TextInactive;
borderColour = Appearance.BorderInactive;
backgroundColour = 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->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()
{
if(optionIndex!=-1)

View File

@ -39,6 +39,8 @@ public:
void SetActionCallback(DropDownAction * action) { callback = action;}
virtual void Draw(const Point& screenPos);
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();
};