Add a bit more functionality to the controls
This commit is contained in:
parent
5557039364
commit
a40f22ff73
7 changed files with 164 additions and 6 deletions
|
|
@ -30,7 +30,12 @@ void PushButton::OnPaintFrame(Canvas* canvas)
|
|||
double w = GetFrameGeometry().width;
|
||||
double h = GetFrameGeometry().height;
|
||||
Colorf bordercolor = Colorf::fromRgba8(100, 100, 100);
|
||||
canvas->fillRect(Rect::xywh(0.0, 0.0, w, h), Colorf::fromRgba8(68, 68, 68));
|
||||
Colorf buttoncolor = Colorf::fromRgba8(68, 68, 68);
|
||||
if (buttonDown)
|
||||
buttoncolor = Colorf::fromRgba8(88, 88, 88);
|
||||
else if (hot)
|
||||
buttoncolor = Colorf::fromRgba8(78, 78, 78);
|
||||
canvas->fillRect(Rect::xywh(0.0, 0.0, w, h), buttoncolor);
|
||||
canvas->fillRect(Rect::xywh(0.0, 0.0, w, 1.0), bordercolor);
|
||||
canvas->fillRect(Rect::xywh(0.0, h - 1.0, w, 1.0), bordercolor);
|
||||
canvas->fillRect(Rect::xywh(0.0, 0.0, 1.0, h - 0.0), bordercolor);
|
||||
|
|
@ -42,3 +47,63 @@ void PushButton::OnPaint(Canvas* canvas)
|
|||
Rect box = canvas->measureText(text);
|
||||
canvas->drawText(Point((GetWidth() - box.width) * 0.5, GetHeight() - 5.0), Colorf::fromRgba8(255, 255, 255), text);
|
||||
}
|
||||
|
||||
void PushButton::OnMouseMove(const Point& pos)
|
||||
{
|
||||
if (!hot)
|
||||
{
|
||||
hot = true;
|
||||
Update();
|
||||
}
|
||||
}
|
||||
|
||||
void PushButton::OnMouseDown(const Point& pos, int key)
|
||||
{
|
||||
SetFocus();
|
||||
buttonDown = true;
|
||||
Update();
|
||||
}
|
||||
|
||||
void PushButton::OnMouseUp(const Point& pos, int key)
|
||||
{
|
||||
if (buttonDown)
|
||||
{
|
||||
buttonDown = false;
|
||||
hot = false;
|
||||
Repaint();
|
||||
Click();
|
||||
}
|
||||
}
|
||||
|
||||
void PushButton::OnMouseLeave()
|
||||
{
|
||||
hot = false;
|
||||
buttonDown = false;
|
||||
Update();
|
||||
}
|
||||
|
||||
void PushButton::OnKeyDown(EInputKey key)
|
||||
{
|
||||
if (key == IK_Space || key == IK_Enter)
|
||||
{
|
||||
buttonDown = true;
|
||||
Update();
|
||||
}
|
||||
}
|
||||
|
||||
void PushButton::OnKeyUp(EInputKey key)
|
||||
{
|
||||
if (key == IK_Space || key == IK_Enter)
|
||||
{
|
||||
buttonDown = false;
|
||||
hot = false;
|
||||
Repaint();
|
||||
Click();
|
||||
}
|
||||
}
|
||||
|
||||
void PushButton::Click()
|
||||
{
|
||||
if (OnClick)
|
||||
OnClick();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue