// ClassicalSharp copyright 2014-2016 UnknownShadow200 | Licensed under MIT
using System;
using System.Drawing;
using OpenTK.Input;
namespace ClassicalSharp.Gui.Widgets {
/// Represents an individual 2D gui component.
public abstract class Widget : GuiElement {
public Widget( Game game ) : base( game ) {
HorizontalAnchor = Anchor.LeftOrTop;
VerticalAnchor = Anchor.LeftOrTop;
}
/// Whether this widget is currently being moused over.
public bool Active;
/// Whether this widget is prevented from being interacted with.
public bool Disabled;
/// Invoked when this widget is clicked on. Can be null.
public ClickHandler OnClick;
/// Horizontal coordinate of top left corner in pixels.
public int X;
/// Vertical coordinate of top left corner in pixels.
public int Y;
/// Horizontal length of widget's bounds in pixels.
public int Width;
/// Vertical length of widget's bounds in pixels.
public int Height;
/// Specifies the horizontal reference point for when the widget is resized.
public Anchor HorizontalAnchor;
/// Specifies the vertical reference point for when the widget is resized.
public Anchor VerticalAnchor;
/// Horizontal offset from the reference point in pixels.
public int XOffset;
/// Vertical offset from the reference point in pixels.
public int YOffset;
/// Width and height of widget in pixels.
public Size Size { get { return new Size( Width, Height ); } }
/// Coordinate of top left corner of widget's bounds in pixels.
public Point TopLeft { get { return new Point( X, Y ); } }
/// Coordinate of bottom right corner of widget's bounds in pixels.
public Point BottomRight { get { return new Point( X + Width, Y + Height ); } }
/// Specifies the boundaries of the widget in pixels.
public Rectangle Bounds { get { return new Rectangle( X, Y, Width, Height ); } }
public virtual void CalculatePosition() {
X = CalcPos( HorizontalAnchor, XOffset, Width, game.Width );
Y = CalcPos( VerticalAnchor, YOffset, Height, game.Height );
}
}
}