mirror of
https://github.com/AlexMacocian/MonoGame.Extended.git
synced 2026-07-26 00:45:20 +00:00
* started refactoring for gui windows * a bit more work on gui windows * fixed some bugs and broken build stuff * fixed some bugs in gui controls * a little code cleanup * got gui dialogs positioning and experimenting with named styles by type * apply control styles directly in the constructor of controls * got everything compiling again * all gui controls have skinnable constructors * rework uniform grid desired size calculations * turns out gui layouts are complicated * include pdb files in nuget packages * fixed a bug in find nearest glyph * custom control styling * added a range constructor overload that takes one value * rethinking control desired size behaviour * made particle emitters more editable at runtime * moved the auto trigger code to the particle effect instead of the emitters * tweaks * changed the particle modifer interface to an abstract base with an optional name * changed the particle modifer interface to an abstract base with an optional name * an attempt at creating a gui combo box * rolled back the nested control experiment * pretty good (but not perfect) combo boxes * tweaks * name property bindings on lists * removed and cleaned up the hacks from the gui combo box * minor combo box styling tweaks * minor bug fix in gui combo box * experiments with data binding * fixed a mistake on the texture region service interface * working on the ability to serialize particles * finished particle serialization * more robust range deserialization * added editor browable attributes * fixed some broken demos * made the particle modifiers editable at runtime * fixed some issues with particle serialization * fixed some issues with interpolators
108 lines
3.4 KiB
C#
108 lines
3.4 KiB
C#
using Microsoft.Xna.Framework;
|
|
using Microsoft.Xna.Framework.Input;
|
|
using MonoGame.Extended.Input.InputListeners;
|
|
using MonoGame.Extended.TextureAtlases;
|
|
|
|
namespace MonoGame.Extended.Gui.Controls
|
|
{
|
|
public class GuiComboBox : GuiItemsControl
|
|
{
|
|
public GuiComboBox()
|
|
: this(null)
|
|
{
|
|
}
|
|
|
|
public GuiComboBox(GuiSkin skin)
|
|
: base(skin)
|
|
{
|
|
}
|
|
|
|
public bool IsOpen { get; set; }
|
|
public TextureRegion2D DropDownRegion { get; set; }
|
|
public Color DropDownColor { get; set; } = Color.White;
|
|
|
|
public override void OnKeyPressed(IGuiContext context, KeyboardEventArgs args)
|
|
{
|
|
base.OnKeyPressed(context, args);
|
|
|
|
if (args.Key == Keys.Enter)
|
|
IsOpen = false;
|
|
}
|
|
|
|
public override void OnPointerDown(IGuiContext context, GuiPointerEventArgs args)
|
|
{
|
|
base.OnPointerDown(context, args);
|
|
|
|
IsOpen = !IsOpen;
|
|
}
|
|
|
|
protected override Rectangle GetContentRectangle(IGuiContext context)
|
|
{
|
|
return GetDropDownRectangle(context);
|
|
}
|
|
|
|
public override bool Contains(IGuiContext context, Point point)
|
|
{
|
|
return base.Contains(context, point) || IsOpen && GetContentRectangle(context).Contains(point);
|
|
}
|
|
|
|
protected override Size2 CalculateDesiredSize(IGuiContext context, Size2 availableSize)
|
|
{
|
|
var width = 0f;
|
|
var height = 0f;
|
|
|
|
foreach (var item in Items)
|
|
{
|
|
var itemSize = GetItemSize(context, availableSize, item);
|
|
|
|
if (itemSize.Width > width)
|
|
width = itemSize.Width;
|
|
|
|
if (itemSize.Height > height)
|
|
height = itemSize.Height;
|
|
}
|
|
|
|
return new Size2(width + ClipPadding.Size.Width, height + ClipPadding.Size.Height);
|
|
}
|
|
|
|
protected override void DrawBackground(IGuiContext context, IGuiRenderer renderer, float deltaSeconds)
|
|
{
|
|
base.DrawBackground(context, renderer, deltaSeconds);
|
|
|
|
if (IsOpen)
|
|
{
|
|
var dropDownRectangle = GetContentRectangle(context);
|
|
|
|
if (DropDownRegion != null)
|
|
renderer.DrawRegion(DropDownRegion, dropDownRectangle, DropDownColor);
|
|
else
|
|
renderer.FillRectangle(dropDownRectangle, DropDownColor);
|
|
}
|
|
}
|
|
|
|
protected override void DrawForeground(IGuiContext context, IGuiRenderer renderer, float deltaSeconds, TextInfo textInfo)
|
|
{
|
|
var selectedTextInfo = GetItemTextInfo(context, ClippingRectangle, SelectedItem, ClippingRectangle);
|
|
base.DrawForeground(context, renderer, deltaSeconds, selectedTextInfo);
|
|
|
|
if (IsOpen)
|
|
DrawItemList(context, renderer);
|
|
}
|
|
|
|
private Rectangle GetDropDownRectangle(IGuiContext context)
|
|
{
|
|
var dropDownRectangle = BoundingRectangle;
|
|
dropDownRectangle.Y = dropDownRectangle.Y + dropDownRectangle.Height;
|
|
var height = 0f;
|
|
|
|
foreach (var item in Items)
|
|
{
|
|
var itemSize = GetItemSize(context, new Size2(BoundingRectangle.Width, 100), item);
|
|
height += itemSize.Height;
|
|
}
|
|
|
|
dropDownRectangle.Height = (int)height;
|
|
return dropDownRectangle;
|
|
}
|
|
}
|
|
} |