mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-26 14:49:10 -04:00
Better comments for launcher widgets.
This commit is contained in:
parent
f6dbfc6062
commit
4c8e5078e0
@ -22,16 +22,16 @@ namespace ClassicalSharp.Gui {
|
||||
/// <summary> Invoked when this widget is clicked on. Can be null. </summary>
|
||||
public ClickHandler OnClick;
|
||||
|
||||
/// <summary> Horizontal coordinate of top left corner in window space. </summary>
|
||||
/// <summary> Horizontal coordinate of top left corner in pixels. </summary>
|
||||
public int X;
|
||||
|
||||
/// <summary> Vertical coordinate of top left corner in window space. </summary>
|
||||
/// <summary> Vertical coordinate of top left corner in pixels. </summary>
|
||||
public int Y;
|
||||
|
||||
/// <summary> Horizontal length of widget's bounds in window space. </summary>
|
||||
/// <summary> Horizontal length of widget's bounds in pixels. </summary>
|
||||
public int Width;
|
||||
|
||||
/// <summary> Vertical length of widget's bounds in window space. </summary>
|
||||
/// <summary> Vertical length of widget's bounds in pixels. </summary>
|
||||
public int Height;
|
||||
|
||||
/// <summary> Specifies the horizontal reference point for when the widget is resized. </summary>
|
||||
@ -40,25 +40,25 @@ namespace ClassicalSharp.Gui {
|
||||
/// <summary> Specifies the vertical reference point for when the widget is resized. </summary>
|
||||
public Anchor VerticalAnchor;
|
||||
|
||||
/// <summary> Horizontal offset from the reference point in window space. </summary>
|
||||
/// <summary> Horizontal offset from the reference point in pixels. </summary>
|
||||
public int XOffset = 0;
|
||||
|
||||
/// <summary> Vertical offset from the reference point in window space. </summary>
|
||||
/// <summary> Vertical offset from the reference point in pixels. </summary>
|
||||
public int YOffset = 0;
|
||||
|
||||
/// <summary> Width and height of widget in window space. </summary>
|
||||
/// <summary> Width and height of widget in pixels. </summary>
|
||||
public Size Size { get { return new Size( Width, Height ); } }
|
||||
|
||||
/// <summary> Coordinate of top left corner of widget's bounds in window space. </summary>
|
||||
/// <summary> Coordinate of top left corner of widget's bounds in pixels. </summary>
|
||||
public Point TopLeft { get { return new Point( X, Y ); } }
|
||||
|
||||
/// <summary> Coordinate of bottom right corner of widget's bounds in window space. </summary>
|
||||
/// <summary> Coordinate of bottom right corner of widget's bounds in pixels. </summary>
|
||||
public Point BottomRight { get { return new Point( X + Width, Y + Height ); } }
|
||||
|
||||
/// <summary> Specifies the boundaries of the widget in window space. </summary>
|
||||
/// <summary> Specifies the boundaries of the widget in pixels. </summary>
|
||||
public Rectangle Bounds { get { return new Rectangle( X, Y, Width, Height ); } }
|
||||
|
||||
/// <summary> Moves the widget to the specified window space coordinates. </summary>
|
||||
/// <summary> Moves the widget to the specified pixel coordinates. </summary>
|
||||
public virtual void MoveTo( int newX, int newY ) {
|
||||
X = newX; Y = newY;
|
||||
}
|
||||
|
@ -122,7 +122,8 @@ namespace Launcher.Gui.Widgets {
|
||||
|
||||
public void SetDrawData( IDrawer2D drawer, Font font, Font titleFont,
|
||||
Anchor horAnchor, Anchor verAnchor, int x, int y ) {
|
||||
CalculateOffset( x, y, horAnchor, verAnchor );
|
||||
SetAnchors( horAnchor, verAnchor ).SetOffsets( x, y )
|
||||
.CalculatePosition();
|
||||
view.SetDrawData( drawer, font, titleFont );
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,8 @@ namespace Launcher.Gui.Widgets {
|
||||
}
|
||||
|
||||
public void SetDrawData( IDrawer2D drawer, Anchor horAnchor, Anchor verAnchor, int x, int y ) {
|
||||
CalculateOffset( x, y, horAnchor, verAnchor );
|
||||
SetAnchors( horAnchor, verAnchor ).SetOffsets( x, y )
|
||||
.CalculatePosition();
|
||||
}
|
||||
|
||||
public override void Redraw( IDrawer2D drawer ) {
|
||||
|
@ -19,7 +19,8 @@ namespace Launcher.Gui.Widgets {
|
||||
public void SetDrawData( IDrawer2D drawer, string text, Font font, Anchor horAnchor,
|
||||
Anchor verAnchor, int width, int height, int x, int y ) {
|
||||
Width = width; Height = height;
|
||||
CalculateOffset( x, y, horAnchor, verAnchor );
|
||||
SetAnchors( horAnchor, verAnchor ).SetOffsets( x, y )
|
||||
.CalculatePosition();
|
||||
this.font = font;
|
||||
|
||||
Text = text;
|
||||
|
@ -43,7 +43,8 @@ namespace Launcher.Gui.Widgets {
|
||||
Anchor horAnchor, Anchor verAnchor, int width, int height, int x, int y ) {
|
||||
ButtonWidth = width; ButtonHeight = height;
|
||||
Width = width; Height = height;
|
||||
CalculateOffset( x, y, horAnchor, verAnchor );
|
||||
SetAnchors( horAnchor, verAnchor ).SetOffsets( x, y )
|
||||
.CalculatePosition();
|
||||
|
||||
Text = text;
|
||||
if( Password ) text = new String( '*', text.Length );
|
||||
|
@ -19,7 +19,8 @@ namespace Launcher.Gui.Widgets {
|
||||
Size size = drawer.MeasureSize( ref args );
|
||||
Width = size.Width; Height = size.Height;
|
||||
|
||||
CalculateOffset( x, y, horAnchor, verAnchor );
|
||||
SetAnchors( horAnchor, verAnchor ).SetOffsets( x, y )
|
||||
.CalculatePosition();
|
||||
Text = text;
|
||||
this.font = font;
|
||||
}
|
||||
|
@ -4,28 +4,66 @@ using ClassicalSharp;
|
||||
|
||||
namespace Launcher.Gui.Widgets {
|
||||
|
||||
/// <summary> Represents a graphical element/control. </summary>
|
||||
public abstract class LauncherWidget {
|
||||
|
||||
public int X, Y, Width, Height;
|
||||
public LauncherWindow Window;
|
||||
public Action<int, int> OnClick;
|
||||
|
||||
/// <summary> The text associated with this widget. </summary>
|
||||
public string Text;
|
||||
|
||||
/// <summary> Specifies the horizontal reference point for when the widget is resized. </summary>
|
||||
public Anchor HorizontalAnchor;
|
||||
|
||||
/// <summary> Specifies the vertical reference point for when the widget is resized. </summary>
|
||||
public Anchor VerticalAnchor;
|
||||
|
||||
/// <summary> Horizontal offset from the reference point in pixels. </summary>
|
||||
public int XOffset = 0;
|
||||
|
||||
/// <summary> Vertical offset from the reference point in pixels. </summary>
|
||||
public int YOffset = 0;
|
||||
|
||||
|
||||
public LauncherWidget( LauncherWindow window ) {
|
||||
Window = window;
|
||||
}
|
||||
|
||||
protected void CalculateOffset( int x, int y, Anchor horAnchor, Anchor verAnchor ) {
|
||||
if( horAnchor == Anchor.LeftOrTop ) X = x;
|
||||
else if( horAnchor == Anchor.Centre ) X = x + Window.Width / 2 - Width / 2;
|
||||
else if( horAnchor == Anchor.BottomOrRight ) X = x + Window.Width - Width;
|
||||
|
||||
if( verAnchor == Anchor.LeftOrTop ) Y = y;
|
||||
else if( verAnchor == Anchor.Centre ) Y = y + Window.Height / 2 - Height / 2;
|
||||
else if( verAnchor == Anchor.BottomOrRight ) Y = y + Window.Height - Height;
|
||||
}
|
||||
|
||||
/// <summary> Redraws the contents of this widget. </summary>
|
||||
public abstract void Redraw( IDrawer2D drawer );
|
||||
|
||||
/// <summary> Sets the reference points for when this widget is resized. </summary>
|
||||
public LauncherWidget SetAnchors( Anchor horAnchor, Anchor verAnchor ) {
|
||||
HorizontalAnchor = horAnchor;
|
||||
VerticalAnchor = verAnchor;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary> Sets the offsets from the reference points (anchors) in pixels. </summary>
|
||||
public LauncherWidget SetOffsets( int xOffset, int yOffset ) {
|
||||
XOffset = xOffset;
|
||||
YOffset = yOffset;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary> Calculates the position of this widget in the window,
|
||||
/// based on its anchor points and offset from the anchor points. </summary>
|
||||
public LauncherWidget CalculatePosition() {
|
||||
X = CalcPos( HorizontalAnchor, XOffset, Width, Window.Width );
|
||||
Y = CalcPos( VerticalAnchor, YOffset, Height, Window.Height );
|
||||
return this;
|
||||
}
|
||||
|
||||
static int CalcPos( Anchor anchor, int offset, int size, int axisLen ) {
|
||||
if( anchor == Anchor.LeftOrTop )
|
||||
return offset;
|
||||
if( anchor == Anchor.Centre )
|
||||
return offset + axisLen / 2 - size / 2;
|
||||
if( anchor == Anchor.BottomOrRight )
|
||||
return offset + axisLen - size;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user