mirror of
https://github.com/AlexMacocian/MonoGame.Extended.git
synced 2026-07-24 03:56:31 +00:00
e962cec448
* mostly restored the tiled importer unit tests * code cleanup * code cleanup * almost got tiled maps serialization independent of the content pipeline * refactored the tiled map content importer so that tiled maps can be loaded at runtime * code cleanup * removed nuspec files * experimenting with an XML based GUI markup parser * a few more markup parser features * finally got a working open file dialog * experimenting with markup bindings * attached properties * working on the gui stuff again * working on a better textbox * multiline textboxing * new text box is really coming along * removed the content explorer experiment * restored the old gui demo back to the way it was before (for now)
82 lines
2.4 KiB
C#
82 lines
2.4 KiB
C#
using System.Collections.Generic;
|
|
using Microsoft.Xna.Framework;
|
|
|
|
namespace MonoGame.Extended.Gui.Controls
|
|
{
|
|
public class ContentControl : Control
|
|
{
|
|
private bool _contentChanged = true;
|
|
|
|
private object _content;
|
|
public object Content
|
|
{
|
|
get => _content;
|
|
set
|
|
{
|
|
if (_content != value)
|
|
{
|
|
_content = value;
|
|
_contentChanged = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
public override IEnumerable<Control> Children
|
|
{
|
|
get
|
|
{
|
|
if (Content is Control control)
|
|
yield return control;
|
|
}
|
|
}
|
|
|
|
public bool HasContent => Content == null;
|
|
|
|
public override void InvalidateMeasure()
|
|
{
|
|
base.InvalidateMeasure();
|
|
_contentChanged = true;
|
|
}
|
|
|
|
public override void Update(IGuiContext context, float deltaSeconds)
|
|
{
|
|
if (_content is Control control && _contentChanged)
|
|
{
|
|
control.Parent = this;
|
|
control.ActualSize = ContentRectangle.Size;
|
|
control.Position = new Point(Padding.Left, Padding.Top);
|
|
control.InvalidateMeasure();
|
|
_contentChanged = false;
|
|
}
|
|
}
|
|
|
|
public override void Draw(IGuiContext context, IGuiRenderer renderer, float deltaSeconds)
|
|
{
|
|
base.Draw(context, renderer, deltaSeconds);
|
|
|
|
if (Content is Control control)
|
|
{
|
|
control.Draw(context, renderer, deltaSeconds);
|
|
}
|
|
else
|
|
{
|
|
var text = Content?.ToString();
|
|
var textInfo = GetTextInfo(context, text, ContentRectangle, HorizontalTextAlignment, VerticalTextAlignment);
|
|
|
|
if (!string.IsNullOrWhiteSpace(textInfo.Text))
|
|
renderer.DrawText(textInfo.Font, textInfo.Text, textInfo.Position + TextOffset, textInfo.Color, textInfo.ClippingRectangle);
|
|
}
|
|
}
|
|
|
|
public override Size GetContentSize(IGuiContext context)
|
|
{
|
|
if (Content is Control control)
|
|
return control.CalculateActualSize(context);
|
|
|
|
var text = Content?.ToString();
|
|
var font = Font ?? context.DefaultFont;
|
|
return (Size)font.MeasureString(text ?? string.Empty);
|
|
}
|
|
}
|
|
|
|
} |