public static LabelControl AddLabel(this Screen screen, string text, UniScalar x, UniScalar y) { var r = CreateLabel(text, x, y); screen.Desktop.Children.Add(r); return(r); }
public PositionLayout Create(Control control) { UniScalar x, y; if (_horizontalAlignment == HorizontalAlignment.Left) { x = _padding.Left; } else if (_horizontalAlignment == HorizontalAlignment.Right) { x = new UniScalar(1.0f) - _width - _padding.Right; } else { x = new UniScalar(0.5f) - ((_width - _padding.Left - _padding.Right) / 2 + _padding.Left); } if (_verticalAlignment == VerticalAlignment.Top) { y = _padding.Top; } else if (_verticalAlignment == VerticalAlignment.Bottom) { y = new UniScalar(1.0f) - _height - _padding.Bottom; } else { y = new UniScalar(0.5f) - ((_height - _padding.Top - _padding.Bottom) / 2 + _padding.Top); } control.Coordinates = new UniRectangle(x, y, _width, _height); ParentComponent.Register(control); return(this); }
/// <summary> /// Adds the radio. /// </summary> /// <param name="screen">The screen.</param> /// <param name="text">The text.</param> /// <param name="x">The x.</param> /// <param name="y">The y.</param> /// <returns></returns> public static ChoiceControl AddRadio(this Screen screen, string text, UniScalar x, UniScalar y) { var r = CreateRadio(text, x, y); screen.Desktop.Children.Add(r); return(r); }
/// <summary> /// Calculates the unified coordinates a region needs to be placed at /// </summary> /// <param name="placementIndex"> /// Placement index indicating where in a frame the region will be located /// </param> /// <param name="width">Width of the region in pixels</param> /// <param name="lowBorderWidth"> /// Width of the border on the lower end of the coordinate range /// </param> /// <param name="highBorderWidth"> /// Width of the border on the higher end of the coordinate range /// </param> /// <param name="location"> /// Receives the target location of the region in unified coordinates /// </param> /// <param name="size"> /// Receives the size of the region in unified coordinates /// </param> private void calculateRegionPlacement( int placementIndex, int width, int lowBorderWidth, int highBorderWidth, ref UniScalar location, ref UniScalar size ) { switch (placementIndex) { case (-1): { // left or top int gapWidth = lowBorderWidth - width; location.Fraction = 0.0f; location.Offset = (float)gapWidth; size.Fraction = 0.0f; size.Offset = (float)width; break; } case (+1): { // right or bottom location.Fraction = 1.0f; location.Offset = -(float)highBorderWidth; size.Fraction = 0.0f; size.Offset = (float)width; break; } case (0): { // stretch location.Fraction = 0.0f; location.Offset = (float)lowBorderWidth; size.Fraction = 1.0f; size.Offset = -(float)(highBorderWidth + lowBorderWidth); break; } } }
public HorizontalLayout(Control parent, UniScalar verticalPosition, UniScalar height, int leftOffset = 0, int rightOffset = 0) { _verticalPosition = verticalPosition; _height = height; _leftOffset = leftOffset; _rightOffset = rightOffset; Parent = parent; }
/// <summary> /// Creates the button. /// </summary> /// <param name="text">The text.</param> /// <param name="x">The x.</param> /// <param name="y">The y.</param> /// <returns></returns> public static ButtonControl CreateButton(string text, UniScalar x, UniScalar y) { return(new ButtonControl { Bounds = { Size = new UniVector(120, 35), Location = new UniVector(x, y) }, Text = text }); }
/// <summary> /// Creates the label. /// </summary> /// <param name="text">The text.</param> /// <param name="x">The x.</param> /// <param name="y">The y.</param> /// <returns></returns> public static LabelControl CreateLabel(string text, UniScalar x, UniScalar y) { return(new LabelControl { Bounds = { Location = new UniVector(x, y) }, Text = text }); }
public PositionLayout(UiComponent parent, UniScalar width, UniScalar height, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment, Padding padding = null) : base(parent) { _width = width; _height = height; _horizontalAlignment = horizontalAlignment; _verticalAlignment = verticalAlignment; _padding = padding ?? new Padding(0); }
public Overlay(string title, int width, int height = -1) { Title = title; EnableDragging = false; X = new UniScalar(0, 0); Y = new UniScalar(0, 0); Width = width; Height = height; }
/// <summary> /// Creates the radio. /// </summary> /// <param name="text">The text.</param> /// <param name="x">The x.</param> /// <param name="y">The y.</param> /// <returns></returns> public static ChoiceControl CreateRadio(string text, UniScalar x, UniScalar y) { return(new ChoiceControl { Bounds = { Location = new UniVector(x, y), Size = new UniVector(120, 13), }, Text = text }); }
public void Create() { int count = _controls.Count; int controlsWidth = _controls.Sum(c => c.Width); int totalFixedWidth = controlsWidth + _leftOffset + _rightOffset; UniScalar blank = new UniScalar(1.0f/(count-1), -totalFixedWidth/(count-1)); UniScalar currentPosition = new UniScalar(_leftOffset); foreach (LayoutItem layoutItem in _controls) { layoutItem.Control.Coordinates = new UniRectangle(currentPosition, _verticalPosition, layoutItem.Width, _height); currentPosition += layoutItem.Width + blank; Parent.Register(layoutItem.Control); } }
/// <summary> /// Initializes a new instance of the <see cref="FieldControl"/> class. /// </summary> public FieldControl() { _bubbles = new BubbleField(Size, this); Bounds.Size = new UniVector(Bubble.Size * Size + 100, Bubble.Size * Size); var left = new UniScalar(1.0f, -80); _labelScore = Children.AddLabel("Score: 0", left, new UniScalar(0, 0)); _labelSelectedScore = Children.AddLabel("Selected: 0", left, new UniScalar(0, 15)); _rStandart = Children.AddRadio("Standart", left, new UniScalar(0, 30)); _rContinuous = Children.AddRadio("Continuous", left, new UniScalar(0, 45)); _rShifter = Children.AddRadio("Shifter", left, new UniScalar(0, 60)); _rMegaShifter = Children.AddRadio("Mega Shifter", left, new UniScalar(0, 75)); }
public void Create() { int count = _controls.Count; int controlsWidth = _controls.Sum(c => c.Width); int totalFixedWidth = controlsWidth + _leftOffset + _rightOffset; UniScalar blank = new UniScalar(1.0f / (count - 1), -totalFixedWidth / (count - 1)); UniScalar currentPosition = new UniScalar(_leftOffset); foreach (LayoutItem layoutItem in _controls) { layoutItem.Control.Coordinates = new UniRectangle(currentPosition, _verticalPosition, layoutItem.Width, _height); currentPosition += layoutItem.Width + blank; Parent.Register(layoutItem.Control); } }
private void ResizeTo(float x, float y) { var OldBounds = Bounds; var diffX = x - _grabX; var diffY = y - _grabY; var boundsX = Bounds.Size.X; var boundsY = Bounds.Size.Y; var locX = Bounds.Location.X; var locY = Bounds.Location.Y; if (_resizingSides.HasFlag(ResizingSides.Right)) { boundsX = new UniScalar(boundsX.Fraction, boundsX.Offset + diffX); } if (_resizingSides.HasFlag(ResizingSides.Left)) { boundsX = new UniScalar(boundsX.Fraction, boundsX.Offset - diffX); locX = new UniScalar(locX.Fraction, locX.Offset + diffX); } if (_resizingSides.HasFlag(ResizingSides.Bottom)) { boundsY = new UniScalar(boundsY.Fraction, boundsY.Offset + diffY); } if (_resizingSides.HasFlag(ResizingSides.Top)) { boundsY = new UniScalar(boundsY.Fraction, boundsY.Offset - diffY); locY = new UniScalar(locY.Fraction, locY.Offset + diffY); } Bounds = new UniRectangle(new UniVector(locX, locY), new UniVector(boundsX, boundsY)); if (GetAbsoluteBounds().Size.Width < 20 || GetAbsoluteBounds().Size.Height < 20) //Too Small { Bounds = OldBounds; } else { if (_resizingSides.HasFlag(ResizingSides.Right)) { _grabX = x; } if (_resizingSides.HasFlag(ResizingSides.Bottom)) { _grabY = y; } OnResize(OldBounds); } }
private void CreatePanel() { _panel = new Container(); _panel.Bounds.Location = new UniVector(Left, new UniScalar(0.0f, -30f)); _panel.Bounds.Size = new UniVector(200, 200); _screen.Desktop.Children.Add(_panel); var left = new UniScalar(0.0f, 0f); _radioEasy = _panel.Children.AddRadio("Easy", left, new UniScalar(0.0f, 0f)); _radioNormal = _panel.Children.AddRadio("Normal", left, new UniScalar(0.0f, 20f)); _radioHard = _panel.Children.AddRadio("Hard", left, new UniScalar(0.0f, 40f)); _radioEasy.Selected = true; // Button to open another "New Game" dialog var newGameButton = _panel.Children.AddButton("New Game", left, new UniScalar(0.0f, 60f)); newGameButton.Pressed += (sender, arguments) => _box.Controller.NewGame(Difficulty); }
public PositionLayout Create(Control control) { UniScalar x, y; if (_horizontalAlignment == HorizontalAlignment.Left) x = _padding.Left; else if(_horizontalAlignment == HorizontalAlignment.Right) x = new UniScalar(1.0f) - _width - _padding.Right; else x = new UniScalar(0.5f) - ((_width - _padding.Left - _padding.Right) / 2 + _padding.Left) ; if (_verticalAlignment == VerticalAlignment.Top) y = _padding.Top; else if (_verticalAlignment == VerticalAlignment.Bottom) y = new UniScalar(1.0f) - _height - _padding.Bottom; else y = new UniScalar(0.5f) - ((_height - _padding.Top - _padding.Bottom)/2 + _padding.Top); control.Coordinates = new UniRectangle(x, y, _width, _height); ParentComponent.Register(control); return this; }
/// <summary> /// Calculates the unified coordinates a region needs to be placed at /// </summary> /// <param name="placementIndex"> /// Placement index indicating where in a frame the region will be located /// </param> /// <param name="width">Width of the region in pixels</param> /// <param name="lowBorderWidth"> /// Width of the border on the lower end of the coordinate range /// </param> /// <param name="highBorderWidth"> /// Width of the border on the higher end of the coordinate range /// </param> /// <param name="location"> /// Receives the target location of the region in unified coordinates /// </param> /// <param name="size"> /// Receives the size of the region in unified coordinates /// </param> private void CalculateRegionPlacement( int placementIndex, int width, int lowBorderWidth, int highBorderWidth, ref UniScalar location, ref UniScalar size ) { switch (placementIndex) { case -1: { // left or top var gapWidth = lowBorderWidth - width; location.Fraction = 0.0f; location.Offset = gapWidth; size.Fraction = 0.0f; size.Offset = width; break; } case +1: { // right or bottom location.Fraction = 1.0f; location.Offset = -highBorderWidth; size.Fraction = 0.0f; size.Offset = width; break; } case 0: { // stretch location.Fraction = 0.0f; location.Offset = lowBorderWidth; size.Fraction = 1.0f; size.Offset = -(highBorderWidth + lowBorderWidth); break; } } }
public PositionLayout Right(UniScalar heigth, VerticalAlignment alignment, Padding padding) { return(Right(heigth, alignment, padding, new UniScalar(1.0f, -_padding.Left - _padding.Right) - _width)); }
/// <summary>Checks whether another instance is equal to this instance</summary> /// <param name="other">Other instance to compare to this instance</param> /// <returns>True if the other instance is equal to this instance</returns> public bool Equals(UniScalar other) { // For a struct, 'other' cannot be null return((Fraction == other.Fraction) && (Offset == other.Offset)); }
public PositionLayout Right(UniScalar heigth, VerticalAlignment alignment, Padding padding, UniScalar width) { return new PositionLayout(ParentComponent, width, heigth, HorizontalAlignment.Left, alignment, new Padding(padding.Left + _padding.Left + _padding.Right + _width.ToOffset(0), padding.Right, padding.Top, padding.Bottom)); }
public PositionLayout Right(UniScalar heigth, VerticalAlignment alignment, Padding padding) { return Right(heigth, alignment, padding, new UniScalar(1.0f, -_padding.Left - _padding.Right) - _width); }
/// <summary> /// Adds the label. /// </summary> /// <param name="screen">The screen.</param> /// <param name="text">The text.</param> /// <param name="x">The x.</param> /// <param name="y">The y.</param> /// <returns></returns> public static LabelControl AddLabel(this Collection <Control> screen, string text, UniScalar x, UniScalar y) { var r = CreateLabel(text, x, y); screen.Add(r); return(r); }
/// <summary> /// Adds the radio. /// </summary> /// <param name="screen">The screen.</param> /// <param name="text">The text.</param> /// <param name="x">The x.</param> /// <param name="y">The y.</param> /// <returns></returns> public static ChoiceControl AddRadio(this Collection <Control> screen, string text, UniScalar x, UniScalar y) { var r = CreateRadio(text, x, y); screen.Add(r); return(r); }
public PositionLayout Right(UniScalar heigth, VerticalAlignment alignment, Padding padding, UniScalar width) { return(new PositionLayout(ParentComponent, width, heigth, HorizontalAlignment.Left, alignment, new Padding(padding.Left + _padding.Left + _padding.Right + _width.ToOffset(0), padding.Right, padding.Top, padding.Bottom))); }
/// <summary> /// Adds the button. /// </summary> /// <param name="screen">The screen.</param> /// <param name="text">The text.</param> /// <param name="x">The x.</param> /// <param name="y">The y.</param> /// <returns></returns> public static ButtonControl AddButton(this Collection <Control> screen, string text, UniScalar x, UniScalar y) { var r = CreateButton(text, x, y); screen.Add(r); return(r); }