dropped the gui prefix on most of the gui stuff

This commit is contained in:
Dylan Wilson
2018-03-05 22:06:57 +10:00
parent c9a4cf37a9
commit 0c8ccf5125
41 changed files with 314 additions and 317 deletions
@@ -7,21 +7,21 @@ using MonoGame.Extended.Gui.Controls;
namespace MonoGame.Extended.Gui
{
public class GuiControlStyle : IDictionary<string, object>
public class ControlStyle : IDictionary<string, object>
{
private readonly Dictionary<Guid, Dictionary<string, object>> _previousStates = new Dictionary<Guid, Dictionary<string, object>>();
public GuiControlStyle()
: this(typeof(GuiElement))
public ControlStyle()
: this(typeof(Element))
{
}
public GuiControlStyle(Type targetType)
public ControlStyle(Type targetType)
: this(targetType.FullName, targetType)
{
}
public GuiControlStyle(string name, Type targetType)
public ControlStyle(string name, Type targetType)
{
Name = name;
TargetType = targetType;
@@ -33,7 +33,7 @@ namespace MonoGame.Extended.Gui
private readonly Dictionary<string, object> _setters;
public void ApplyIf(GuiControl control, bool predicate)
public void ApplyIf(Control control, bool predicate)
{
if (predicate)
Apply(control);
@@ -41,7 +41,7 @@ namespace MonoGame.Extended.Gui
Revert(control);
}
public void Apply(GuiControl control)
public void Apply(Control control)
{
_previousStates[control.Id] = _setters
.ToDictionary(i => i.Key, i => TargetType.GetRuntimeProperty(i.Key)?.GetValue(control));
@@ -49,7 +49,7 @@ namespace MonoGame.Extended.Gui
ChangePropertyValues(control, _setters);
}
public void Revert(GuiControl control)
public void Revert(Control control)
{
if (_previousStates.ContainsKey(control.Id) && _previousStates[control.Id] != null)
ChangePropertyValues(control, _previousStates[control.Id]);
@@ -57,7 +57,7 @@ namespace MonoGame.Extended.Gui
_previousStates[control.Id] = null;
}
private static void ChangePropertyValues(GuiControl control, Dictionary<string, object> setters)
private static void ChangePropertyValues(Control control, Dictionary<string, object> setters)
{
var targetType = control.GetType();
@@ -4,9 +4,9 @@ using MonoGame.Extended.TextureAtlases;
namespace MonoGame.Extended.Gui.Controls
{
public class GuiButton : GuiControl
public class Button : Control
{
public GuiButton()
public Button()
{
}
@@ -46,8 +46,8 @@ namespace MonoGame.Extended.Gui.Controls
}
}
private GuiControlStyle _pressedStyle;
public GuiControlStyle PressedStyle
private ControlStyle _pressedStyle;
public ControlStyle PressedStyle
{
get { return _pressedStyle; }
set
@@ -62,7 +62,7 @@ namespace MonoGame.Extended.Gui.Controls
private bool _isPointerDown;
public override bool OnPointerDown(IGuiContext context, GuiPointerEventArgs args)
public override bool OnPointerDown(IGuiContext context, PointerEventArgs args)
{
if (IsEnabled)
{
@@ -72,7 +72,7 @@ namespace MonoGame.Extended.Gui.Controls
return base.OnPointerDown(context, args);
}
public override bool OnPointerUp(IGuiContext context, GuiPointerEventArgs args)
public override bool OnPointerUp(IGuiContext context, PointerEventArgs args)
{
_isPointerDown = false;
@@ -86,7 +86,7 @@ namespace MonoGame.Extended.Gui.Controls
return base.OnPointerUp(context, args);
}
public override bool OnPointerEnter(IGuiContext context, GuiPointerEventArgs args)
public override bool OnPointerEnter(IGuiContext context, PointerEventArgs args)
{
if (IsEnabled && _isPointerDown)
IsPressed = true;
@@ -94,7 +94,7 @@ namespace MonoGame.Extended.Gui.Controls
return base.OnPointerEnter(context, args);
}
public override bool OnPointerLeave(IGuiContext context, GuiPointerEventArgs args)
public override bool OnPointerLeave(IGuiContext context, PointerEventArgs args)
{
if (IsEnabled)
IsPressed = false;
@@ -2,9 +2,9 @@
namespace MonoGame.Extended.Gui.Controls
{
public class GuiCanvas : GuiLayoutControl
public class Canvas : LayoutControl
{
public GuiCanvas()
public Canvas()
{
}
@@ -3,9 +3,9 @@ using Microsoft.Xna.Framework;
namespace MonoGame.Extended.Gui.Controls
{
public class GuiCheckBox : GuiControl
public class CheckBox : Control
{
public GuiCheckBox()
public CheckBox()
{
}
@@ -27,8 +27,8 @@ namespace MonoGame.Extended.Gui.Controls
}
}
private GuiControlStyle _checkedStyle;
public GuiControlStyle CheckedStyle
private ControlStyle _checkedStyle;
public ControlStyle CheckedStyle
{
get { return _checkedStyle; }
set
@@ -41,7 +41,7 @@ namespace MonoGame.Extended.Gui.Controls
}
}
public override bool OnPointerUp(IGuiContext context, GuiPointerEventArgs args)
public override bool OnPointerUp(IGuiContext context, PointerEventArgs args)
{
if (IsFocused && BoundingRectangle.Contains(args.Position))
IsChecked = !IsChecked;
@@ -5,9 +5,9 @@ using MonoGame.Extended.TextureAtlases;
namespace MonoGame.Extended.Gui.Controls
{
public class GuiComboBox : GuiItemsControl
public class ComboBox : ItemsControl
{
public GuiComboBox()
public ComboBox()
{
}
@@ -23,7 +23,7 @@ namespace MonoGame.Extended.Gui.Controls
return base.OnKeyPressed(context, args);
}
public override bool OnPointerDown(IGuiContext context, GuiPointerEventArgs args)
public override bool OnPointerDown(IGuiContext context, PointerEventArgs args)
{
IsOpen = !IsOpen;
return base.OnPointerDown(context, args);
@@ -10,15 +10,15 @@ using System.Linq;
namespace MonoGame.Extended.Gui.Controls
{
public abstract class GuiControl : GuiElement<GuiControl>, IMovable, ISizable, IRectangular
public abstract class Control : Element<Control>, IMovable, ISizable, IRectangular
{
protected GuiControl()
protected Control()
{
Color = Color.White;
TextColor = Color.White;
IsEnabled = true;
IsVisible = true;
Controls = new GuiControlCollection(this)
Controls = new ControlCollection(this)
{
ItemAdded = x => UpdateRootIsLayoutRequired(),
ItemRemoved = x => UpdateRootIsLayoutRequired()
@@ -26,10 +26,10 @@ namespace MonoGame.Extended.Gui.Controls
Origin = Vector2.Zero;
}
private GuiSkin _skin;
private Skin _skin;
[EditorBrowsable(EditorBrowsableState.Never)]
public GuiSkin Skin
public Skin Skin
{
get { return _skin; }
set
@@ -71,7 +71,7 @@ namespace MonoGame.Extended.Gui.Controls
public BitmapFont Font { get; set; }
public Color TextColor { get; set; }
public Vector2 TextOffset { get; set; }
public GuiControlCollection Controls { get; }
public ControlCollection Controls { get; }
public HorizontalAlignment HorizontalAlignment { get; set; } = HorizontalAlignment.Centre;
public VerticalAlignment VerticalAlignment { get; set; } = VerticalAlignment.Centre;
public HorizontalAlignment HorizontalTextAlignment { get; set; } = HorizontalAlignment.Centre;
@@ -129,7 +129,7 @@ namespace MonoGame.Extended.Gui.Controls
var buttonSize = Size2.Empty;
var guiButton = this as GuiButton;
var guiButton = this as Button;
if (guiButton?.IconRegion != null)
{
buttonSize = guiButton.IconRegion.Size;
@@ -166,10 +166,10 @@ namespace MonoGame.Extended.Gui.Controls
}
public bool IsVisible { get; set; }
public GuiControlStyle HoverStyle { get; set; }
public ControlStyle HoverStyle { get; set; }
private GuiControlStyle _disabledStyle;
public GuiControlStyle DisabledStyle
private ControlStyle _disabledStyle;
public ControlStyle DisabledStyle
{
get { return _disabledStyle; }
set
@@ -187,11 +187,11 @@ namespace MonoGame.Extended.Gui.Controls
public virtual bool OnFocus(IGuiContext context) { return true; }
public virtual bool OnUnfocus(IGuiContext context) { return true; }
public virtual bool OnPointerDown(IGuiContext context, GuiPointerEventArgs args) { return true; }
public virtual bool OnPointerMove(IGuiContext context, GuiPointerEventArgs args) { return true; }
public virtual bool OnPointerUp(IGuiContext context, GuiPointerEventArgs args) { return true; }
public virtual bool OnPointerDown(IGuiContext context, PointerEventArgs args) { return true; }
public virtual bool OnPointerMove(IGuiContext context, PointerEventArgs args) { return true; }
public virtual bool OnPointerUp(IGuiContext context, PointerEventArgs args) { return true; }
public virtual bool OnPointerEnter(IGuiContext context, GuiPointerEventArgs args)
public virtual bool OnPointerEnter(IGuiContext context, PointerEventArgs args)
{
if (IsEnabled && !_isHovering)
{
@@ -201,7 +201,7 @@ namespace MonoGame.Extended.Gui.Controls
return true;
}
public virtual bool OnPointerLeave(IGuiContext context, GuiPointerEventArgs args)
public virtual bool OnPointerLeave(IGuiContext context, PointerEventArgs args)
{
if (IsEnabled && _isHovering)
{
@@ -222,19 +222,19 @@ namespace MonoGame.Extended.Gui.Controls
DrawForeground(context, renderer, deltaSeconds, GetTextInfo(context, CreateBoxText(Text, Font ?? context.DefaultFont, Width), BoundingRectangle, HorizontalTextAlignment, VerticalTextAlignment));
}
public bool HasParent(GuiControl control)
public bool HasParent(Control control)
{
return Parent != null && (Parent == control || Parent.HasParent(control));
}
protected List<T> FindControls<T>()
where T : GuiControl
where T : Control
{
return FindControls<T>(Controls);
}
protected List<T> FindControls<T>(GuiControlCollection controls)
where T : GuiControl
protected List<T> FindControls<T>(ControlCollection controls)
where T : Control
{
var results = new List<T>();
foreach (var control in controls)
@@ -249,7 +249,7 @@ namespace MonoGame.Extended.Gui.Controls
{
var font = Font ?? context.DefaultFont;
var textSize = font.GetStringRectangle(text ?? string.Empty, Vector2.Zero).Size;
var destinationRectangle = GuiLayoutHelper.AlignRectangle(horizontalAlignment, verticalAlignment, textSize, targetRectangle);
var destinationRectangle = LayoutHelper.AlignRectangle(horizontalAlignment, verticalAlignment, textSize, targetRectangle);
var textPosition = destinationRectangle.Location.ToVector2();
var textInfo = new TextInfo(text, font, textPosition, textSize, TextColor, clippingRectangle ?? ClippingRectangle);
return textInfo;
@@ -0,0 +1,15 @@
namespace MonoGame.Extended.Gui.Controls
{
public class ControlCollection : ElementCollection<Control, Control>
{
public ControlCollection()
: base(null)
{
}
public ControlCollection(Control parent)
: base(parent)
{
}
}
}
@@ -3,18 +3,18 @@ using MonoGame.Extended.TextureAtlases;
namespace MonoGame.Extended.Gui.Controls
{
public class GuiDialog : GuiLayoutControl
public class Dialog : LayoutControl
{
public GuiDialog()
public Dialog()
{
HorizontalAlignment = HorizontalAlignment.Centre;
VerticalAlignment = VerticalAlignment.Centre;
}
public Thickness Padding { get; set; }
public GuiScreen Owner { get; private set; }
public Screen Owner { get; private set; }
public void Show(GuiScreen owner)
public void Show(Screen owner)
{
Owner = owner;
Owner.Controls.Add(this);
@@ -27,7 +27,7 @@ namespace MonoGame.Extended.Gui.Controls
protected override Size2 CalculateDesiredSize(IGuiContext context, Size2 availableSize)
{
var sizes = Controls.Select(control => GuiLayoutHelper.GetSizeWithMargins(control, context, availableSize)).ToArray();
var sizes = Controls.Select(control => LayoutHelper.GetSizeWithMargins(control, context, availableSize)).ToArray();
var width = sizes.Max(s => s.Width);
var height = sizes.Max(s => s.Height);
return new Size2(width, height) + Padding.Size;
@@ -4,9 +4,9 @@ using Microsoft.Xna.Framework.Input;
namespace MonoGame.Extended.Gui.Controls
{
public class GuiForm : GuiStackPanel
public class Form : StackPanel
{
public GuiForm()
public Form()
{
}
@@ -14,7 +14,7 @@ namespace MonoGame.Extended.Gui.Controls
{
if (args.Key == Keys.Tab)
{
var controls = FindControls<GuiControl>();
var controls = FindControls<Control>();
var index = controls.IndexOf(context.FocusedControl);
if (index > -1)
{
@@ -27,7 +27,7 @@ namespace MonoGame.Extended.Gui.Controls
if (args.Key == Keys.Enter)
{
var controls = FindControls<GuiSubmit>();
var controls = FindControls<Submit>();
if (controls.Count > 0)
{
var submit = controls.FirstOrDefault();
@@ -1,15 +0,0 @@
namespace MonoGame.Extended.Gui.Controls
{
public class GuiControlCollection : GuiElementCollection<GuiControl, GuiControl>
{
public GuiControlCollection()
: base(null)
{
}
public GuiControlCollection(GuiControl parent)
: base(parent)
{
}
}
}
@@ -2,13 +2,13 @@
namespace MonoGame.Extended.Gui.Controls
{
public class GuiImage : GuiControl
public class Image : Control
{
public GuiImage()
public Image()
{
}
public GuiImage(TextureRegion2D image)
public Image(TextureRegion2D image)
{
BackgroundRegion = image;
}
@@ -7,9 +7,9 @@ using MonoGame.Extended.Input.InputListeners;
namespace MonoGame.Extended.Gui.Controls
{
public abstract class GuiItemsControl : GuiControl
public abstract class ItemsControl : Control
{
protected GuiItemsControl()
protected ItemsControl()
{
}
@@ -71,7 +71,7 @@ namespace MonoGame.Extended.Gui.Controls
SelectedIndex--;
}
public override bool OnPointerDown(IGuiContext context, GuiPointerEventArgs args)
public override bool OnPointerDown(IGuiContext context, PointerEventArgs args)
{
var contentRectangle = GetContentRectangle(context);
@@ -90,7 +90,7 @@ namespace MonoGame.Extended.Gui.Controls
return base.OnPointerDown(context, args);
}
protected virtual void OnItemClicked(IGuiContext context, GuiPointerEventArgs args) { }
protected virtual void OnItemClicked(IGuiContext context, PointerEventArgs args) { }
protected TextInfo GetItemTextInfo(IGuiContext context, Rectangle itemRectangle, object item, Rectangle? clippingRectangle)
{
@@ -1,12 +1,12 @@
namespace MonoGame.Extended.Gui.Controls
{
public class GuiLabel : GuiControl
public class Label : Control
{
public GuiLabel()
public Label()
{
}
public GuiLabel(string text = null)
public Label(string text = null)
{
Text = text ?? string.Empty;
}
@@ -3,9 +3,9 @@ using Microsoft.Xna.Framework;
namespace MonoGame.Extended.Gui.Controls
{
public abstract class GuiLayoutControl : GuiControl
public abstract class LayoutControl : Control
{
protected GuiLayoutControl()
protected LayoutControl()
{
HorizontalAlignment = HorizontalAlignment.Stretch;
VerticalAlignment = VerticalAlignment.Stretch;
@@ -19,9 +19,9 @@ namespace MonoGame.Extended.Gui.Controls
public abstract void Layout(IGuiContext context, RectangleF rectangle);
protected static void PlaceControl(IGuiContext context, GuiControl control, float x, float y, float width, float height)
protected static void PlaceControl(IGuiContext context, Control control, float x, float y, float width, float height)
{
GuiLayoutHelper.PlaceControl(context, control, x, y, width, height);
LayoutHelper.PlaceControl(context, control, x, y, width, height);
}
}
}
@@ -3,9 +3,9 @@ using Microsoft.Xna.Framework;
namespace MonoGame.Extended.Gui.Controls
{
public class GuiListBox : GuiItemsControl
public class ListBox : ItemsControl
{
public GuiListBox()
public ListBox()
{
}
@@ -4,9 +4,9 @@ using MonoGame.Extended.TextureAtlases;
namespace MonoGame.Extended.Gui.Controls
{
public class GuiProgressBar : GuiControl
public class ProgressBar : Control
{
public GuiProgressBar()
public ProgressBar()
{
}
@@ -2,15 +2,15 @@
namespace MonoGame.Extended.Gui.Controls
{
public class GuiStackPanel : GuiLayoutControl
public class StackPanel : LayoutControl
{
public GuiStackPanel()
public StackPanel()
{
HorizontalAlignment = HorizontalAlignment.Centre;
VerticalAlignment = VerticalAlignment.Centre;
}
public GuiOrientation Orientation { get; set; } = GuiOrientation.Vertical;
public Orientation Orientation { get; set; } = Orientation.Vertical;
public Thickness Padding { get; set; }
public int Spacing { get; set; } = 0;
@@ -21,15 +21,15 @@ namespace MonoGame.Extended.Gui.Controls
foreach (var control in Controls)
{
var desiredSize = GuiLayoutHelper.GetSizeWithMargins(control, context, availableSize);
var desiredSize = LayoutHelper.GetSizeWithMargins(control, context, availableSize);
switch (Orientation)
{
case GuiOrientation.Horizontal:
case Orientation.Horizontal:
width += desiredSize.Width;
height = desiredSize.Height > height ? desiredSize.Height : height;
break;
case GuiOrientation.Vertical:
case Orientation.Vertical:
width = desiredSize.Width > width ? desiredSize.Width : width;
height += desiredSize.Height;
break;
@@ -39,8 +39,8 @@ namespace MonoGame.Extended.Gui.Controls
}
width += Padding.Left + Padding.Right + (Orientation == GuiOrientation.Horizontal ? (Controls.Count - 1) * Spacing : 0);
height += Padding.Top + Padding.Bottom + (Orientation == GuiOrientation.Vertical ? (Controls.Count - 1) * Spacing : 0);
width += Padding.Left + Padding.Right + (Orientation == Orientation.Horizontal ? (Controls.Count - 1) * Spacing : 0);
height += Padding.Top + Padding.Bottom + (Orientation == Orientation.Vertical ? (Controls.Count - 1) * Spacing : 0);
return new Size2(width, height);
}
@@ -53,18 +53,18 @@ namespace MonoGame.Extended.Gui.Controls
foreach (var control in Controls)
{
var desiredSize = GuiLayoutHelper.GetSizeWithMargins(control, context, availableSize);
var desiredSize = LayoutHelper.GetSizeWithMargins(control, context, availableSize);
switch (Orientation)
{
case GuiOrientation.Vertical:
case Orientation.Vertical:
control.VerticalAlignment = VerticalAlignment.Top;
PlaceControl(context, control, 0f, y, Width, desiredSize.Height);
y += desiredSize.Height + Spacing;
availableSize.Height -= desiredSize.Height;
break;
case GuiOrientation.Horizontal:
case Orientation.Horizontal:
control.HorizontalAlignment = HorizontalAlignment.Left;
PlaceControl(context, control, x, 0f, desiredSize.Width, Height);
@@ -1,6 +1,6 @@
namespace MonoGame.Extended.Gui.Controls
{
public class GuiSubmit : GuiButton
public class Submit : Button
{
}
}
@@ -7,9 +7,9 @@ using MonoGame.Extended.BitmapFonts;
namespace MonoGame.Extended.Gui.Controls
{
public class GuiTextBox : GuiControl
public class TextBox : Control
{
public GuiTextBox(string text = null)
public TextBox(string text = null)
{
Text = text ?? string.Empty;
}
@@ -31,7 +31,7 @@ namespace MonoGame.Extended.Gui.Controls
return new Size2(Width + Padding.Left + Padding.Right, (Height <= 0.0f ? font.LineHeight + 2 : Height) + Padding.Top + Padding.Bottom);
}
public override bool OnPointerDown(IGuiContext context, GuiPointerEventArgs args)
public override bool OnPointerDown(IGuiContext context, PointerEventArgs args)
{
SelectionStart = FindNearestGlyphIndex(context, args.Position);
_isCaretVisible = true;
@@ -43,7 +43,7 @@ namespace MonoGame.Extended.Gui.Controls
return base.OnPointerDown(context, args);
}
public override bool OnPointerMove(IGuiContext context, GuiPointerEventArgs args)
public override bool OnPointerMove(IGuiContext context, PointerEventArgs args)
{
if (_startSelectionBox)
{
@@ -71,14 +71,14 @@ namespace MonoGame.Extended.Gui.Controls
return base.OnPointerMove(context, args);
}
public override bool OnPointerLeave(IGuiContext context, GuiPointerEventArgs args)
public override bool OnPointerLeave(IGuiContext context, PointerEventArgs args)
{
_startSelectionBox = false;
return base.OnPointerLeave(context, args);
}
public override bool OnPointerUp(IGuiContext context, GuiPointerEventArgs args)
public override bool OnPointerUp(IGuiContext context, PointerEventArgs args)
{
_startSelectionBox = false;
@@ -3,9 +3,9 @@ using System.Linq;
namespace MonoGame.Extended.Gui.Controls
{
public class GuiUniformGrid : GuiLayoutControl
public class UniformGrid : LayoutControl
{
public GuiUniformGrid()
public UniformGrid()
{
}
@@ -60,7 +60,7 @@ namespace MonoGame.Extended.Gui.Controls
var maxCellWidth = availableSize.Width / columns;
var maxCellHeight = availableSize.Height / rows;
var sizes = Controls
.Select(control => GuiLayoutHelper.GetSizeWithMargins(control, context, new Size2(maxCellWidth, maxCellHeight)))
.Select(control => LayoutHelper.GetSizeWithMargins(control, context, new Size2(maxCellWidth, maxCellHeight)))
.ToArray();
var maxControlWidth = sizes.Length == 0 ? 0 : sizes.Max(s => s.Width);
var maxControlHeight = sizes.Length == 0 ? 0 : sizes.Max(s => s.Height);
@@ -3,7 +3,7 @@ using MonoGame.Extended.TextureAtlases;
namespace MonoGame.Extended.Gui
{
public class GuiCursor
public class Cursor
{
public TextureRegion2D TextureRegion { get; set; }
public Color Color { get; set; } = Color.White;
@@ -21,7 +21,7 @@ namespace MonoGame.Extended.Gui
public string ViewProperty { get; }
}
public abstract class GuiElement
public abstract class Element
{
public string Name { get; set; }
public Vector2 Position { get; set; }
@@ -93,7 +93,7 @@ namespace MonoGame.Extended.Gui
public abstract void Draw(IGuiContext context, IGuiRenderer renderer, float deltaSeconds);
}
public abstract class GuiElement<TParent> : GuiElement, IRectangular
public abstract class Element<TParent> : Element, IRectangular
where TParent : IRectangular
{
[EditorBrowsable(EditorBrowsableState.Never)]
@@ -5,9 +5,9 @@ using MonoGame.Extended.Gui.Controls;
namespace MonoGame.Extended.Gui
{
public abstract class GuiElementCollection<TChild, TParent> : IList<TChild>
public abstract class ElementCollection<TChild, TParent> : IList<TChild>
where TParent : class, IRectangular
where TChild : GuiElement<TParent>
where TChild : Element<TParent>
{
private readonly TParent _parent;
private readonly List<TChild> _list = new List<TChild>();
@@ -15,7 +15,7 @@ namespace MonoGame.Extended.Gui
public Action<TChild> ItemAdded { get; set; }
public Action<TChild> ItemRemoved { get; set; }
protected GuiElementCollection(TParent parent)
protected ElementCollection(TParent parent)
{
_parent = parent;
}
@@ -67,7 +67,7 @@ namespace MonoGame.Extended.Gui
public int Count => _list.Count;
public bool IsReadOnly => ((ICollection<GuiControl>)_list).IsReadOnly;
public bool IsReadOnly => ((ICollection<Control>)_list).IsReadOnly;
public int IndexOf(TChild item)
{
@@ -1,4 +0,0 @@
namespace MonoGame.Extended.Gui
{
public enum GuiOrientation { Horizontal, Vertical }
}
@@ -1,10 +0,0 @@
namespace MonoGame.Extended.Gui
{
public class GuiScreenCollection : GuiElementCollection<GuiScreen, GuiSystem>
{
public GuiScreenCollection(GuiSystem parent)
: base(parent)
{
}
}
}
+26 -26
View File
@@ -12,9 +12,9 @@ namespace MonoGame.Extended.Gui
{
BitmapFont DefaultFont { get; }
Vector2 CursorPosition { get; }
GuiControl FocusedControl { get; }
Control FocusedControl { get; }
void SetFocus(GuiControl focusedControl);
void SetFocus(Control focusedControl);
}
public class GuiSystem : IGuiContext, IRectangular
@@ -25,23 +25,23 @@ namespace MonoGame.Extended.Gui
private readonly TouchListener _touchListener;
private readonly KeyboardListener _keyboardListener;
private GuiControl _preFocusedControl;
private Control _preFocusedControl;
public GuiSystem(ViewportAdapter viewportAdapter, IGuiRenderer renderer, GuiSkin defaultSkin)
public GuiSystem(ViewportAdapter viewportAdapter, IGuiRenderer renderer, Skin defaultSkin)
{
_viewportAdapter = viewportAdapter;
_renderer = renderer;
_mouseListener = new MouseListener(viewportAdapter);
_mouseListener.MouseDown += (s, e) => OnPointerDown(GuiPointerEventArgs.FromMouseArgs(e));
_mouseListener.MouseMoved += (s, e) => OnPointerMoved(GuiPointerEventArgs.FromMouseArgs(e));
_mouseListener.MouseUp += (s, e) => OnPointerUp(GuiPointerEventArgs.FromMouseArgs(e));
_mouseListener.MouseDown += (s, e) => OnPointerDown(PointerEventArgs.FromMouseArgs(e));
_mouseListener.MouseMoved += (s, e) => OnPointerMoved(PointerEventArgs.FromMouseArgs(e));
_mouseListener.MouseUp += (s, e) => OnPointerUp(PointerEventArgs.FromMouseArgs(e));
_mouseListener.MouseWheelMoved += (s, e) => FocusedControl?.OnScrolled(e.ScrollWheelDelta);
_touchListener = new TouchListener(viewportAdapter);
_touchListener.TouchStarted += (s, e) => OnPointerDown(GuiPointerEventArgs.FromTouchArgs(e));
_touchListener.TouchMoved += (s, e) => OnPointerMoved(GuiPointerEventArgs.FromTouchArgs(e));
_touchListener.TouchEnded += (s, e) => OnPointerUp(GuiPointerEventArgs.FromTouchArgs(e));
_touchListener.TouchStarted += (s, e) => OnPointerDown(PointerEventArgs.FromTouchArgs(e));
_touchListener.TouchMoved += (s, e) => OnPointerMoved(PointerEventArgs.FromTouchArgs(e));
_touchListener.TouchEnded += (s, e) => OnPointerUp(PointerEventArgs.FromTouchArgs(e));
_keyboardListener = new KeyboardListener();
_keyboardListener.KeyTyped += (sender, args) => PropagateDown(FocusedControl, x => x.OnKeyTyped(this, args));
@@ -50,11 +50,11 @@ namespace MonoGame.Extended.Gui
DefaultSkin = defaultSkin;
}
public GuiControl FocusedControl { get; private set; }
public GuiControl HoveredControl { get; private set; }
public Control FocusedControl { get; private set; }
public Control HoveredControl { get; private set; }
private GuiScreen _activeScreen;
public GuiScreen ActiveScreen
private Screen _activeScreen;
public Screen ActiveScreen
{
get { return _activeScreen; }
set
@@ -73,11 +73,11 @@ namespace MonoGame.Extended.Gui
public Vector2 CursorPosition { get; set; }
public GuiSkin DefaultSkin { get; }
public Skin DefaultSkin { get; }
public BitmapFont DefaultFont => DefaultSkin?.DefaultFont;
private void InitializeScreen(GuiScreen screen)
private void InitializeScreen(Screen screen)
{
screen.Layout(this, BoundingRectangle);
}
@@ -117,7 +117,7 @@ namespace MonoGame.Extended.Gui
_renderer.End();
}
private void DrawWindows(GuiWindowCollection windows, float deltaSeconds)
private void DrawWindows(WindowCollection windows, float deltaSeconds)
{
foreach (var window in windows)
{
@@ -126,7 +126,7 @@ namespace MonoGame.Extended.Gui
}
}
private void DrawChildren(GuiControlCollection controls, float deltaSeconds)
private void DrawChildren(ControlCollection controls, float deltaSeconds)
{
foreach (var control in controls.Where(c => c.IsVisible))
{
@@ -140,7 +140,7 @@ namespace MonoGame.Extended.Gui
DrawChildren(childControl.Controls, deltaSeconds);
}
private void OnPointerDown(GuiPointerEventArgs args)
private void OnPointerDown(PointerEventArgs args)
{
if (ActiveScreen == null || !ActiveScreen.IsVisible)
return;
@@ -149,7 +149,7 @@ namespace MonoGame.Extended.Gui
PropagateDown(HoveredControl, x => x.OnPointerDown(this, args));
}
private void OnPointerUp(GuiPointerEventArgs args)
private void OnPointerUp(PointerEventArgs args)
{
if (ActiveScreen == null || !ActiveScreen.IsVisible)
return;
@@ -165,7 +165,7 @@ namespace MonoGame.Extended.Gui
PropagateDown(HoveredControl, x => x.OnPointerUp(this, args));
}
private void OnPointerMoved(GuiPointerEventArgs args)
private void OnPointerMoved(PointerEventArgs args)
{
CursorPosition = args.Position.ToVector2();
@@ -188,7 +188,7 @@ namespace MonoGame.Extended.Gui
}
}
public void SetFocus(GuiControl focusedControl)
public void SetFocus(Control focusedControl)
{
if (FocusedControl != focusedControl)
{
@@ -214,7 +214,7 @@ namespace MonoGame.Extended.Gui
/// </summary>
/// <param name="control">The control we want to check against</param>
/// <param name="predicate">A function to check if the propagation should resume, if returns false it will continue down the tree.</param>
private static void PropagateDown(GuiControl control, Func<GuiControl, bool> predicate)
private static void PropagateDown(Control control, Func<Control, bool> predicate)
{
while(control != null && predicate(control))
{
@@ -222,7 +222,7 @@ namespace MonoGame.Extended.Gui
}
}
private GuiControl FindControlAtPoint(Point point)
private Control FindControlAtPoint(Point point)
{
if (ActiveScreen == null || !ActiveScreen.IsVisible)
return null;
@@ -230,9 +230,9 @@ namespace MonoGame.Extended.Gui
return FindControlAtPoint(ActiveScreen.Controls, point);
}
private GuiControl FindControlAtPoint(GuiControlCollection controls, Point point)
private Control FindControlAtPoint(ControlCollection controls, Point point)
{
var topMostControl = (GuiControl) null;
var topMostControl = (Control) null;
for (var i = controls.Count - 1; i >= 0; i--)
{
@@ -1,10 +0,0 @@
namespace MonoGame.Extended.Gui
{
public class GuiWindowCollection : GuiElementCollection<GuiWindow, GuiScreen>
{
public GuiWindowCollection(GuiScreen parent)
: base(parent)
{
}
}
}
@@ -7,14 +7,14 @@ namespace MonoGame.Extended.Gui
public enum HorizontalAlignment { Left, Right, Centre, Stretch }
public enum VerticalAlignment { Top, Bottom, Centre, Stretch }
public static class GuiLayoutHelper
public static class LayoutHelper
{
public static Size2 GetSizeWithMargins(GuiControl control, IGuiContext context, Size2 availableSize)
public static Size2 GetSizeWithMargins(Control control, IGuiContext context, Size2 availableSize)
{
return control.GetDesiredSize(context, availableSize) + control.Margin.Size;
}
public static void PlaceControl(IGuiContext context, GuiControl control, float x, float y, float width, float height)
public static void PlaceControl(IGuiContext context, Control control, float x, float y, float width, float height)
{
var rectangle = new Rectangle((int)x, (int)y, (int)width, (int)height);
var availableSize = new Size2(width, height);
@@ -24,11 +24,11 @@ namespace MonoGame.Extended.Gui
control.Position = new Vector2(control.Margin.Left + alignedRectangle.X, control.Margin.Top + alignedRectangle.Y);
control.Size = alignedRectangle.Size - control.Margin.Size;
var layoutControl = control as GuiLayoutControl;
var layoutControl = control as LayoutControl;
layoutControl?.Layout(context, new RectangleF(x, y, width, height));
}
public static void PlaceWindow(IGuiContext context, GuiWindow window, float x, float y, float width, float height)
public static void PlaceWindow(IGuiContext context, Window window, float x, float y, float width, float height)
{
var rectangle = new Rectangle((int)x, (int)y, (int)width, (int)height);
var availableSize = new Size2(width, height);
@@ -38,44 +38,44 @@
<DocumentationFile>bin\Release\MonoGame.Extended.Gui.XML</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Compile Include="Controls\GuiButton.cs" />
<Compile Include="Controls\GuiCanvas.cs" />
<Compile Include="Controls\GuiCheckBox.cs" />
<Compile Include="Controls\GuiComboBox.cs" />
<Compile Include="Controls\GuiControl.cs" />
<Compile Include="Controls\GuiControlCollection.cs" />
<Compile Include="Controls\GuiDialog.cs" />
<Compile Include="Controls\GuiForm.cs" />
<Compile Include="Controls\GuiImage.cs" />
<Compile Include="Controls\GuiItemsControl.cs" />
<Compile Include="Controls\GuiLabel.cs" />
<Compile Include="Controls\GuiLayoutControl.cs" />
<Compile Include="Controls\GuiListBox.cs" />
<Compile Include="Controls\GuiSubmit.cs" />
<Compile Include="Controls\GuiUniformGrid.cs" />
<Compile Include="GuiElement.cs" />
<Compile Include="GuiOrientation.cs" />
<Compile Include="Controls\GuiProgressBar.cs" />
<Compile Include="Controls\GuiTextBox.cs" />
<Compile Include="Controls\GuiStackPanel.cs" />
<Compile Include="GuiCursor.cs" />
<Compile Include="GuiElementCollection.cs" />
<Compile Include="GuiPointerEventArgs.cs" />
<Compile Include="GuiScreenCollection.cs" />
<Compile Include="Controls\Button.cs" />
<Compile Include="Controls\Canvas.cs" />
<Compile Include="Controls\CheckBox.cs" />
<Compile Include="Controls\ComboBox.cs" />
<Compile Include="Controls\Control.cs" />
<Compile Include="Controls\ControlCollection.cs" />
<Compile Include="Controls\Dialog.cs" />
<Compile Include="Controls\Form.cs" />
<Compile Include="Controls\Image.cs" />
<Compile Include="Controls\ItemsControl.cs" />
<Compile Include="Controls\Label.cs" />
<Compile Include="Controls\LayoutControl.cs" />
<Compile Include="Controls\ListBox.cs" />
<Compile Include="Controls\Submit.cs" />
<Compile Include="Controls\UniformGrid.cs" />
<Compile Include="Element.cs" />
<Compile Include="Orientation.cs" />
<Compile Include="Controls\ProgressBar.cs" />
<Compile Include="Controls\TextBox.cs" />
<Compile Include="Controls\StackPanel.cs" />
<Compile Include="Cursor.cs" />
<Compile Include="ElementCollection.cs" />
<Compile Include="PointerEventArgs.cs" />
<Compile Include="ScreenCollection.cs" />
<Compile Include="GuiSystem.cs" />
<Compile Include="GuiScreen.cs" />
<Compile Include="GuiSkin.cs" />
<Compile Include="Screen.cs" />
<Compile Include="Skin.cs" />
<Compile Include="GuiSpriteBatchRenderer.cs" />
<Compile Include="GuiControlStyle.cs" />
<Compile Include="GuiLayoutHelper.cs" />
<Compile Include="GuiWindow.cs" />
<Compile Include="GuiWindowCollection.cs" />
<Compile Include="ControlStyle.cs" />
<Compile Include="LayoutHelper.cs" />
<Compile Include="Window.cs" />
<Compile Include="WindowCollection.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Serialization\GuiAlignmentConverter.cs" />
<Compile Include="Serialization\GuiControlJsonConverter.cs" />
<Compile Include="Serialization\GuiControlStyleJsonConverter.cs" />
<Compile Include="Serialization\AlignmentConverter.cs" />
<Compile Include="Serialization\ControlJsonConverter.cs" />
<Compile Include="Serialization\ControlStyleJsonConverter.cs" />
<Compile Include="Serialization\GuiJsonSerializer.cs" />
<Compile Include="Serialization\GuiSkinJsonConverter.cs" />
<Compile Include="Serialization\SkinJsonConverter.cs" />
<Compile Include="Serialization\GuiTextureAtlasJsonConverter.cs" />
<Compile Include="Serialization\GuiNinePatchRegion2DJsonConverter.cs" />
<Compile Include="Serialization\GuiTextureRegionService.cs" />
@@ -0,0 +1,4 @@
namespace MonoGame.Extended.Gui
{
public enum Orientation { Horizontal, Vertical }
}
@@ -4,9 +4,9 @@ using MonoGame.Extended.Input.InputListeners;
namespace MonoGame.Extended.Gui
{
public class GuiPointerEventArgs : EventArgs
public class PointerEventArgs : EventArgs
{
private GuiPointerEventArgs()
private PointerEventArgs()
{
}
@@ -16,9 +16,9 @@ namespace MonoGame.Extended.Gui
public int ScrollWheelValue { get; private set; }
public TimeSpan Time { get; private set; }
public static GuiPointerEventArgs FromMouseArgs(MouseEventArgs args)
public static PointerEventArgs FromMouseArgs(MouseEventArgs args)
{
return new GuiPointerEventArgs
return new PointerEventArgs
{
Position = args.Position,
Button = args.Button,
@@ -28,9 +28,9 @@ namespace MonoGame.Extended.Gui
};
}
public static GuiPointerEventArgs FromTouchArgs(TouchEventArgs args)
public static PointerEventArgs FromTouchArgs(TouchEventArgs args)
{
return new GuiPointerEventArgs
return new PointerEventArgs
{
Position = args.Position,
Button = MouseButton.Left,
@@ -9,14 +9,14 @@ using Newtonsoft.Json;
namespace MonoGame.Extended.Gui
{
public class GuiScreenRoot : GuiControl { }
public class ScreenRoot : Control { }
public class GuiScreen : GuiElement<GuiSystem>, IDisposable
public class Screen : Element<GuiSystem>, IDisposable
{
public GuiScreen()
public Screen()
{
Controls = new GuiControlCollection { ItemAdded = c => _isLayoutRequired = true };
Windows = new GuiWindowCollection(this) { ItemAdded = w => _isLayoutRequired = true };
Controls = new ControlCollection { ItemAdded = c => _isLayoutRequired = true };
Windows = new WindowCollection(this) { ItemAdded = w => _isLayoutRequired = true };
}
public virtual void Dispose()
@@ -24,10 +24,10 @@ namespace MonoGame.Extended.Gui
}
[JsonProperty(Order = 1)]
public GuiControlCollection Controls { get; set; }
public ControlCollection Controls { get; set; }
[JsonIgnore]
public GuiWindowCollection Windows { get; }
public WindowCollection Windows { get; }
public new float Width { get; private set; }
public new float Height { get; private set; }
@@ -51,13 +51,13 @@ namespace MonoGame.Extended.Gui
}
public T FindControl<T>(string name)
where T : GuiControl
where T : Control
{
return FindControl<T>(Controls, name);
}
private static T FindControl<T>(GuiControlCollection controls, string name)
where T : GuiControl
private static T FindControl<T>(ControlCollection controls, string name)
where T : Control
{
foreach (var control in controls)
{
@@ -82,10 +82,10 @@ namespace MonoGame.Extended.Gui
Height = rectangle.Height;
foreach (var control in Controls)
GuiLayoutHelper.PlaceControl(context, control, rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
LayoutHelper.PlaceControl(context, control, rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
foreach (var window in Windows)
GuiLayoutHelper.PlaceWindow(context, window, rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
LayoutHelper.PlaceWindow(context, window, rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
_isLayoutRequired = false;
foreach (var control in Controls) control.IsLayoutRequired = false;
@@ -96,21 +96,21 @@ namespace MonoGame.Extended.Gui
renderer.DrawRectangle(BoundingRectangle, Color.Green);
}
public static GuiScreen FromStream(ContentManager contentManager, Stream stream, params Type[] customControlTypes)
public static Screen FromStream(ContentManager contentManager, Stream stream, params Type[] customControlTypes)
{
return FromStream<GuiScreen>(contentManager, stream, customControlTypes);
return FromStream<Screen>(contentManager, stream, customControlTypes);
}
public static TScreen FromStream<TScreen>(ContentManager contentManager, Stream stream, params Type[] customControlTypes)
where TScreen : GuiScreen
where TScreen : Screen
{
var skinService = new GuiSkinService();
var skinService = new SkinService();
var serializer = new GuiJsonSerializer(contentManager, customControlTypes)
{
Converters =
{
new GuiSkinJsonConverter(contentManager, skinService, customControlTypes),
new GuiControlJsonConverter(skinService, customControlTypes)
new SkinJsonConverter(contentManager, skinService, customControlTypes),
new ControlJsonConverter(skinService, customControlTypes)
}
};
@@ -122,16 +122,16 @@ namespace MonoGame.Extended.Gui
}
}
public static GuiScreen FromFile(ContentManager contentManager, string path, params Type[] customControlTypes)
public static Screen FromFile(ContentManager contentManager, string path, params Type[] customControlTypes)
{
using (var stream = TitleContainer.OpenStream(path))
{
return FromStream<GuiScreen>(contentManager, stream, customControlTypes);
return FromStream<Screen>(contentManager, stream, customControlTypes);
}
}
public static TScreen FromFile<TScreen>(ContentManager contentManager, string path, params Type[] customControlTypes)
where TScreen : GuiScreen
where TScreen : Screen
{
using (var stream = TitleContainer.OpenStream(path))
{
@@ -0,0 +1,10 @@
namespace MonoGame.Extended.Gui
{
public class ScreenCollection : ElementCollection<Screen, GuiSystem>
{
public ScreenCollection(GuiSystem parent)
: base(parent)
{
}
}
}
@@ -3,10 +3,7 @@ using Newtonsoft.Json;
namespace MonoGame.Extended.Gui.Serialization
{
/// <summary>
/// This converter handles the different spellings of Center.
/// </summary>
public class GuiAlignmentConverter : JsonConverter
public class AlignmentConverter : JsonConverter
{
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
@@ -4,16 +4,16 @@ using Newtonsoft.Json;
namespace MonoGame.Extended.Gui.Serialization
{
public class GuiControlJsonConverter : JsonConverter
public class ControlJsonConverter : JsonConverter
{
private readonly IGuiSkinService _guiSkinService;
private readonly GuiControlStyleJsonConverter _styleConverter;
private readonly ControlStyleJsonConverter _styleConverter;
private const string _styleProperty = "Style";
public GuiControlJsonConverter(IGuiSkinService guiSkinService, params Type[] customControlTypes)
public ControlJsonConverter(IGuiSkinService guiSkinService, params Type[] customControlTypes)
{
_guiSkinService = guiSkinService;
_styleConverter = new GuiControlStyleJsonConverter(customControlTypes);
_styleConverter = new ControlStyleJsonConverter(customControlTypes);
}
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
@@ -23,15 +23,15 @@ namespace MonoGame.Extended.Gui.Serialization
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
var skin = _guiSkinService.Skin;
var style = (GuiControlStyle) _styleConverter.ReadJson(reader, objectType, existingValue, serializer);
var style = (ControlStyle) _styleConverter.ReadJson(reader, objectType, existingValue, serializer);
var template = GetControlTemplate(style);
var control = skin.Create(style.TargetType, template);
object childControls;
if (style.TryGetValue(nameof(GuiControl.Controls), out childControls))
if (style.TryGetValue(nameof(Control.Controls), out childControls))
{
var controlCollection = childControls as GuiControlCollection;
var controlCollection = childControls as ControlCollection;
if (controlCollection != null)
{
@@ -46,10 +46,10 @@ namespace MonoGame.Extended.Gui.Serialization
public override bool CanConvert(Type objectType)
{
return objectType == typeof(GuiControl);
return objectType == typeof(Control);
}
private static string GetControlTemplate(GuiControlStyle style)
private static string GetControlTemplate(ControlStyle style)
{
object template;
@@ -9,26 +9,26 @@ using Newtonsoft.Json;
namespace MonoGame.Extended.Gui.Serialization
{
public class GuiControlStyleJsonConverter : JsonConverter
public class ControlStyleJsonConverter : JsonConverter
{
private readonly Dictionary<string, Type> _controlTypes;
private const string _typeProperty = "Type";
private const string _nameProperty = "Name";
public GuiControlStyleJsonConverter(params Type[] customControlTypes)
public ControlStyleJsonConverter(params Type[] customControlTypes)
{
_controlTypes = typeof(GuiControl)
_controlTypes = typeof(Control)
.GetTypeInfo()
.Assembly
.ExportedTypes
.Concat(customControlTypes)
.Where(t => t.GetTypeInfo().IsSubclassOf(typeof(GuiControl)))
.Where(t => t.GetTypeInfo().IsSubclassOf(typeof(Control)))
.ToDictionary(t => t.Name);
}
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var style = (GuiControlStyle)value;
var style = (ControlStyle)value;
var dictionary = new Dictionary<string, object> { [_typeProperty] = style.TargetType.Name };
foreach (var keyValuePair in style)
@@ -42,11 +42,11 @@ namespace MonoGame.Extended.Gui.Serialization
var dictionary = serializer.Deserialize<Dictionary<string, object>>(reader);
var name = dictionary.GetValueOrDefault(_nameProperty) as string;
var typeName = dictionary.GetValueOrDefault(_typeProperty) as string;
var targetType = typeName != null ? _controlTypes[typeName] : typeof(GuiControl);
var targetType = typeName != null ? _controlTypes[typeName] : typeof(Control);
var properties = targetType
.GetRuntimeProperties()
.ToDictionary(p => p.Name);
var style = new GuiControlStyle(name, targetType);
var style = new ControlStyle(name, targetType);
foreach (var keyValuePair in dictionary.Where(i => i.Key != _typeProperty))
{
@@ -77,7 +77,7 @@ namespace MonoGame.Extended.Gui.Serialization
public override bool CanConvert(Type objectType)
{
return objectType == typeof(GuiControlStyle);
return objectType == typeof(ControlStyle);
}
}
}
@@ -16,11 +16,11 @@ namespace MonoGame.Extended.Gui.Serialization
Converters.Add(new ColorJsonConverter());
Converters.Add(new ThicknessJsonConverter());
Converters.Add(new ContentManagerJsonConverter<BitmapFont>(contentManager, font => font.Name));
Converters.Add(new GuiControlStyleJsonConverter(customControlTypes));
Converters.Add(new ControlStyleJsonConverter(customControlTypes));
Converters.Add(new GuiTextureAtlasJsonConverter(contentManager, textureRegionService));
Converters.Add(new GuiNinePatchRegion2DJsonConverter(textureRegionService));
Converters.Add(new TextureRegion2DJsonConverter(textureRegionService));
Converters.Add(new GuiAlignmentConverter());
Converters.Add(new AlignmentConverter());
ContractResolver = new ShortNameJsonContractResolver();
Formatting = Formatting.Indented;
}
@@ -7,21 +7,21 @@ namespace MonoGame.Extended.Gui.Serialization
{
public interface IGuiSkinService
{
GuiSkin Skin { get; set; }
Skin Skin { get; set; }
}
public class GuiSkinService : IGuiSkinService
public class SkinService : IGuiSkinService
{
public GuiSkin Skin { get; set; }
public Skin Skin { get; set; }
}
public class GuiSkinJsonConverter : JsonConverter
public class SkinJsonConverter : JsonConverter
{
private readonly ContentManager _contentManager;
private readonly IGuiSkinService _skinService;
private readonly Type[] _customControlTypes;
public GuiSkinJsonConverter(ContentManager contentManager, IGuiSkinService skinService, params Type[] customControlTypes)
public SkinJsonConverter(ContentManager contentManager, IGuiSkinService skinService, params Type[] customControlTypes)
{
_contentManager = contentManager;
_skinService = skinService;
@@ -41,18 +41,18 @@ namespace MonoGame.Extended.Gui.Serialization
// TODO: Load this using the ContentManager instead.
using (var stream = TitleContainer.OpenStream(assetName))
{
var skin = GuiSkin.FromStream(_contentManager, stream, _customControlTypes);
var skin = Skin.FromStream(_contentManager, stream, _customControlTypes);
_skinService.Skin = skin;
return skin;
}
}
throw new InvalidOperationException($"{nameof(GuiSkinJsonConverter)} can only convert from a string");
throw new InvalidOperationException($"{nameof(SkinJsonConverter)} can only convert from a string");
}
public override bool CanConvert(Type objectType)
{
return objectType == typeof(GuiSkin);
return objectType == typeof(Skin);
}
}
}
@@ -14,14 +14,14 @@ using Newtonsoft.Json;
namespace MonoGame.Extended.Gui
{
public class GuiSkin
public class Skin
{
public GuiSkin()
public Skin()
{
TextureAtlases = new List<TextureAtlas>();
Fonts = new List<BitmapFont>();
NinePatches = new List<NinePatchRegion2D>();
Styles = new KeyedCollection<string, GuiControlStyle>(s => s.Name ?? s.TargetType.Name);
Styles = new KeyedCollection<string, ControlStyle>(s => s.Name ?? s.TargetType.Name);
}
[JsonProperty(Order = 0)]
@@ -40,19 +40,19 @@ namespace MonoGame.Extended.Gui
public BitmapFont DefaultFont => Fonts.FirstOrDefault();
[JsonProperty(Order = 5)]
public GuiCursor Cursor { get; set; }
public Cursor Cursor { get; set; }
[JsonProperty(Order = 6)]
public KeyedCollection<string, GuiControlStyle> Styles { get; private set; }
public KeyedCollection<string, ControlStyle> Styles { get; private set; }
public GuiControlStyle GetStyle(string name)
public ControlStyle GetStyle(string name)
{
return Styles[name];
}
public GuiControlStyle GetStyle(Type controlType)
public ControlStyle GetStyle(Type controlType)
{
GuiControlStyle controlStyle = null;
ControlStyle controlStyle = null;
while (controlStyle == null && controlType != null)
{
@@ -63,7 +63,7 @@ namespace MonoGame.Extended.Gui
return controlStyle;
}
public static GuiSkin FromFile(ContentManager contentManager, string path, params Type[] customControlTypes)
public static Skin FromFile(ContentManager contentManager, string path, params Type[] customControlTypes)
{
using (var stream = TitleContainer.OpenStream(path))
{
@@ -71,26 +71,26 @@ namespace MonoGame.Extended.Gui
}
}
public static GuiSkin FromStream(ContentManager contentManager, Stream stream, params Type[] customControlTypes)
public static Skin FromStream(ContentManager contentManager, Stream stream, params Type[] customControlTypes)
{
var skinSerializer = new GuiJsonSerializer(contentManager, customControlTypes);
using (var streamReader = new StreamReader(stream))
using (var jsonReader = new JsonTextReader(streamReader))
{
return skinSerializer.Deserialize<GuiSkin>(jsonReader);
return skinSerializer.Deserialize<Skin>(jsonReader);
}
}
public T Create<T>(string template, string name = null, string text = null)
where T : GuiControl, new()
where T : Control, new()
{
return Create<T>(template, Vector2.Zero, name, text);
}
public T Create<T>(string template, Vector2 position, string name = null, string text = null)
where T : GuiControl, new()
where T : Control, new()
{
var control = new T();
GetStyle(template).Apply(control);
@@ -101,7 +101,7 @@ namespace MonoGame.Extended.Gui
}
public T Create<T>(string template, Action<T> onCreate)
where T : GuiControl, new()
where T : Control, new()
{
var control = new T();
GetStyle(template).Apply(control);
@@ -109,9 +109,9 @@ namespace MonoGame.Extended.Gui
return control;
}
public GuiControl Create(Type type, string template)
public Control Create(Type type, string template)
{
var control = (GuiControl)Activator.CreateInstance(type);
var control = (Control)Activator.CreateInstance(type);
if (template != null)
GetStyle(template).Apply(control);
@@ -119,59 +119,59 @@ namespace MonoGame.Extended.Gui
return control;
}
public static GuiSkin FromDefault(BitmapFont font)
public static Skin FromDefault(BitmapFont font)
{
var skin = new GuiSkin
var skin = new Skin
{
Fonts = { font },
Styles =
{
new GuiControlStyle(typeof(GuiControl))
new ControlStyle(typeof(Control))
{
{nameof(GuiControl.Color), new Color(51, 51, 55)},
{nameof(GuiControl.BorderColor), new Color(67, 67, 70)},
{nameof(GuiControl.BorderThickness), 1},
{nameof(GuiControl.TextColor), new Color(241, 241, 241)},
{nameof(GuiStackPanel.Padding), new Thickness(5)}
{nameof(Control.Color), new Color(51, 51, 55)},
{nameof(Control.BorderColor), new Color(67, 67, 70)},
{nameof(Control.BorderThickness), 1},
{nameof(Control.TextColor), new Color(241, 241, 241)},
{nameof(StackPanel.Padding), new Thickness(5)}
},
new GuiControlStyle(typeof(GuiComboBox))
new ControlStyle(typeof(ComboBox))
{
{nameof(GuiControl.Color), new Color(51, 51, 55)},
{nameof(GuiControl.BorderColor), new Color(67, 67, 70)},
{nameof(GuiControl.BorderThickness), 1},
{nameof(GuiControl.TextColor), new Color(241, 241, 241)},
{nameof(GuiStackPanel.Padding), new Thickness(5)},
{nameof(GuiComboBox.DropDownColor) , new Color(51, 51, 55)}
{nameof(Control.Color), new Color(51, 51, 55)},
{nameof(Control.BorderColor), new Color(67, 67, 70)},
{nameof(Control.BorderThickness), 1},
{nameof(Control.TextColor), new Color(241, 241, 241)},
{nameof(StackPanel.Padding), new Thickness(5)},
{nameof(ComboBox.DropDownColor) , new Color(51, 51, 55)}
},
new GuiControlStyle(typeof(GuiLabel))
new ControlStyle(typeof(Label))
{
{nameof(GuiControl.Color), Color.Transparent},
{nameof(GuiControl.TextColor), Color.White}
{nameof(Control.Color), Color.Transparent},
{nameof(Control.TextColor), Color.White}
},
new GuiControlStyle(typeof(GuiTextBox))
new ControlStyle(typeof(TextBox))
{
{nameof(GuiControl.Color), Color.LightGray},
{nameof(GuiControl.TextColor), Color.Black},
{nameof(GuiControl.BorderColor), new Color(67, 67, 70)},
{nameof(Control.Color), Color.LightGray},
{nameof(Control.TextColor), Color.Black},
{nameof(Control.BorderColor), new Color(67, 67, 70)},
},
new GuiControlStyle(typeof(GuiButton))
new ControlStyle(typeof(Button))
{
{nameof(GuiControl.Color), new Color(51, 51, 55)},
{nameof(GuiControl.BorderColor), new Color(67, 67, 70)},
{nameof(GuiControl.BorderThickness), 1},
{nameof(GuiControl.TextColor), new Color(241, 241, 241)},
{nameof(Control.Color), new Color(51, 51, 55)},
{nameof(Control.BorderColor), new Color(67, 67, 70)},
{nameof(Control.BorderThickness), 1},
{nameof(Control.TextColor), new Color(241, 241, 241)},
{
nameof(GuiControl.HoverStyle),
new GuiControlStyle
nameof(Control.HoverStyle),
new ControlStyle
{
{nameof(GuiButton.Color), new Color(62, 62, 64)}
{nameof(Button.Color), new Color(62, 62, 64)}
}
},
{
nameof(GuiButton.PressedStyle),
new GuiControlStyle
nameof(Button.PressedStyle),
new ControlStyle
{
{nameof(GuiButton.Color), new Color(0, 122, 204)}
{nameof(Button.Color), new Color(0, 122, 204)}
}
}
}
@@ -4,14 +4,14 @@ using MonoGame.Extended.Gui.Controls;
namespace MonoGame.Extended.Gui
{
public class GuiWindow : GuiElement<GuiScreen>
public class Window : Element<Screen>
{
public GuiWindow(GuiScreen parent)
public Window(Screen parent)
{
Parent = parent;
}
public GuiControlCollection Controls { get; } = new GuiControlCollection();
public ControlCollection Controls { get; } = new ControlCollection();
public void Show()
{
@@ -36,7 +36,7 @@ namespace MonoGame.Extended.Gui
public void Layout(IGuiContext context, RectangleF rectangle)
{
foreach (var control in Controls)
GuiLayoutHelper.PlaceControl(context, control, rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
LayoutHelper.PlaceControl(context, control, rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
}
}
}
@@ -0,0 +1,10 @@
namespace MonoGame.Extended.Gui
{
public class WindowCollection : ElementCollection<Window, Screen>
{
public WindowCollection(Screen parent)
: base(parent)
{
}
}
}