mattercontrol/CustomWidgets/ClickWidget.cs

66 lines
1.3 KiB
C#
Raw Normal View History

2015-04-08 15:20:10 -07:00
using MatterHackers.Agg;
2014-01-29 19:09:30 -08:00
using MatterHackers.Agg.UI;
using MatterHackers.Agg.VertexSource;
2015-04-08 15:20:10 -07:00
using System;
using System.Collections.Generic;
2014-01-29 19:09:30 -08:00
namespace MatterHackers.MatterControl
{
2015-04-08 15:20:10 -07:00
// A clickable GuiWidget
public class ClickWidget : GuiWidget
{
private int borderWidth = 0;
public ClickWidget()
2015-04-08 15:20:10 -07:00
{
this.BorderColor = Color.Black;
2015-04-08 15:20:10 -07:00
}
public int BorderWidth
2015-04-08 15:20:10 -07:00
{
get { return borderWidth; }
2015-04-08 15:20:10 -07:00
set
{
this.borderWidth = value;
2015-04-08 15:20:10 -07:00
this.Invalidate();
}
}
public event EventHandler Click;
public bool GetChildClicks = false;
2015-04-08 15:20:10 -07:00
override public void OnMouseUp(MouseEventArgs mouseEvent)
{
if (PositionWithinLocalBounds(mouseEvent.X, mouseEvent.Y))
2015-04-08 15:20:10 -07:00
{
if (Click != null && (GetChildClicks || this.MouseCaptured))
{
UiThread.RunOnIdle(() => Click(this, mouseEvent));
}
2015-04-08 15:20:10 -07:00
}
base.OnMouseUp(mouseEvent);
}
public override void OnDraw(Graphics2D graphics2D)
{
RectangleDouble borderRectangle = LocalBounds;
if (BorderWidth > 0)
{
if (BorderWidth == 1)
{
graphics2D.Rectangle(borderRectangle, BorderColor);
}
else
{
RoundedRect rectBorder = new RoundedRect(borderRectangle, 0);
graphics2D.Render(new Stroke(rectBorder, BorderWidth), BorderColor);
}
}
base.OnDraw(graphics2D);
}
}
}