diff --git a/Source/Demos/Demo.NuclexGui/Content/Content.mgcb b/Source/Demos/Demo.NuclexGui/Content/Content.mgcb index 7daae778..366e1d4e 100644 --- a/Source/Demos/Demo.NuclexGui/Content/Content.mgcb +++ b/Source/Demos/Demo.NuclexGui/Content/Content.mgcb @@ -52,3 +52,31 @@ /processorParam:TextureFormat=Compressed /build:TitleFont.spritefont +#begin Fonts/Heading1.spritefont +/importer:FontDescriptionImporter +/processor:FontDescriptionProcessor +/processorParam:PremultiplyAlpha=True +/processorParam:TextureFormat=Compressed +/build:Fonts/Heading1.spritefont + +#begin Fonts/Heading2.spritefont +/importer:FontDescriptionImporter +/processor:FontDescriptionProcessor +/processorParam:PremultiplyAlpha=True +/processorParam:TextureFormat=Compressed +/build:Fonts/Heading2.spritefont + +#begin Fonts/Heading3.spritefont +/importer:FontDescriptionImporter +/processor:FontDescriptionProcessor +/processorParam:PremultiplyAlpha=True +/processorParam:TextureFormat=Compressed +/build:Fonts/Heading3.spritefont + +#begin Fonts/Title.spritefont +/importer:FontDescriptionImporter +/processor:FontDescriptionProcessor +/processorParam:PremultiplyAlpha=True +/processorParam:TextureFormat=Compressed +/build:Fonts/Title.spritefont + diff --git a/Source/Demos/Demo.NuclexGui/Content/Fonts/Heading1.spritefont b/Source/Demos/Demo.NuclexGui/Content/Fonts/Heading1.spritefont new file mode 100644 index 00000000..5b854bd9 --- /dev/null +++ b/Source/Demos/Demo.NuclexGui/Content/Fonts/Heading1.spritefont @@ -0,0 +1,60 @@ + + + + + + + Corbel + + + 16 + + + 0 + + + true + + + + + + ? + + + + + + ~ + + + + diff --git a/Source/Demos/Demo.NuclexGui/Content/Fonts/Heading2.spritefont b/Source/Demos/Demo.NuclexGui/Content/Fonts/Heading2.spritefont new file mode 100644 index 00000000..562b8eaf --- /dev/null +++ b/Source/Demos/Demo.NuclexGui/Content/Fonts/Heading2.spritefont @@ -0,0 +1,60 @@ + + + + + + + Corbel + + + 13 + + + 0 + + + true + + + + + + ? + + + + + + ~ + + + + diff --git a/Source/Demos/Demo.NuclexGui/Content/Fonts/Heading3.spritefont b/Source/Demos/Demo.NuclexGui/Content/Fonts/Heading3.spritefont new file mode 100644 index 00000000..df6b506a --- /dev/null +++ b/Source/Demos/Demo.NuclexGui/Content/Fonts/Heading3.spritefont @@ -0,0 +1,60 @@ + + + + + + + Corbel + + + 12 + + + 0 + + + true + + + + + + ? + + + + + + ~ + + + + diff --git a/Source/Demos/Demo.NuclexGui/Content/Fonts/Title.spritefont b/Source/Demos/Demo.NuclexGui/Content/Fonts/Title.spritefont new file mode 100644 index 00000000..b9289591 --- /dev/null +++ b/Source/Demos/Demo.NuclexGui/Content/Fonts/Title.spritefont @@ -0,0 +1,60 @@ + + + + + + + Corbel + + + 28 + + + 0 + + + true + + + + + + ? + + + + + + ~ + + + + diff --git a/Source/Demos/Demo.NuclexGui/Demo.NuclexGui.csproj b/Source/Demos/Demo.NuclexGui/Demo.NuclexGui.csproj index 9e884695..428e7e0b 100644 --- a/Source/Demos/Demo.NuclexGui/Demo.NuclexGui.csproj +++ b/Source/Demos/Demo.NuclexGui/Demo.NuclexGui.csproj @@ -95,6 +95,10 @@ + + + + @@ -132,4 +136,4 @@ --> - + \ No newline at end of file diff --git a/Source/Demos/Demo.NuclexGui/Game1.cs b/Source/Demos/Demo.NuclexGui/Game1.cs index db0c8428..d13fbf67 100644 --- a/Source/Demos/Demo.NuclexGui/Game1.cs +++ b/Source/Demos/Demo.NuclexGui/Game1.cs @@ -1,4 +1,5 @@ -using System.Linq; +using System; +using System.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; @@ -7,6 +8,7 @@ using MonoGame.Extended.Input.InputListeners; using MonoGame.Extended.Sprites; using MonoGame.Extended.ViewportAdapters; using MonoGame.Extended.NuclexGui; +using MonoGame.Extended.NuclexGui.Controls; using MonoGame.Extended.NuclexGui.Controls.Desktop; namespace Demo.NuclexGui @@ -65,14 +67,90 @@ namespace Demo.NuclexGui Bounds = new UniRectangle(new UniScalar(20), new UniScalar(80), new UniScalar(120), new UniScalar(50)), Text = "Open Window" }; + var button3 = new GuiButtonControl() + { + Name = "button3", + Bounds = new UniRectangle(new UniScalar(20), new UniScalar(140), new UniScalar(120), new UniScalar(50)), + Text = "Show Labels", + }; // Attach relevant events button.Pressed += Button_Pressed; button2.Pressed += Button2_Pressed; + button3.Pressed += Button3_Pressed; // And finally, attach controls to the parent control. In this case, desktop screen. _gui.Screen.Desktop.Children.Add(button); _gui.Screen.Desktop.Children.Add(button2); + _gui.Screen.Desktop.Children.Add(button3); + } + + private void Button3_Pressed(object sender, EventArgs e) + { + if (_gui.Screen.Desktop.Children.Any(i => i.Name == "window")) + return; + + var window = new GuiWindowControl + { + Name = "window", + Bounds = new UniRectangle(new UniVector(new UniScalar(0.5f, -100), new UniScalar(0.5f, -60)), new UniVector(new UniScalar(200), new UniScalar(160))), + Title = "Labels with Styles", + EnableDragging = true + }; + + var labelTitle = new GuiLabelControl + { + Name = "label-title", + Bounds = new UniRectangle(new UniScalar(10), new UniScalar(45), new UniScalar(10), new UniScalar(10)), + Text = "Title", + Style = "label-title" + }; + var label1 = new GuiLabelControl + { + Name = "label1", + Bounds = new UniRectangle(new UniScalar(0.0f, 10), new UniScalar(0.0f, 70), new UniScalar(10), new UniScalar(10)), + Text = "Heading 1", + Style = "label-h1", + }; + var label2 = new GuiLabelControl + { + Name = "label2", + Bounds = new UniRectangle(new UniScalar(0.0f, 10), new UniScalar(0.0f, 90), new UniScalar(10), new UniScalar(10)), + Text = "Heading 2", + Style = "label-h2", + }; + var label3 = new GuiLabelControl + { + Name = "label3", + Bounds = new UniRectangle(new UniScalar(0.0f, 10), new UniScalar(0.0f, 105), new UniScalar(10), new UniScalar(10)), + Text = "Heading 3", + Style = "label-h3" + }; + + var button1 = new GuiButtonControl + { + Name = "confirm", + Bounds = new UniRectangle(new UniScalar(0.0f, 10), new UniScalar(1.0f, -40), new UniScalar(0f, 80), new UniScalar(0f, 30)), + Text = "Confirm" + }; + var button2 = new GuiButtonControl + { + Name = "cancel", + Bounds = new UniRectangle(new UniScalar(1.0f, -90), new UniScalar(1.0f, -40), new UniScalar(0f, 80), new UniScalar(0f, 30)), + Text = "Cancel" + }; + + button1.Pressed += DialogueConfirm_Pressed; + button2.Pressed += DialogueCancel_Pressed; + + window.Children.Add(labelTitle); + window.Children.Add(label1); + window.Children.Add(label2); + window.Children.Add(label3); + window.Children.Add(button1); + window.Children.Add(button2); + + _gui.Screen.Desktop.Children.Add(window); } private void Button2_Pressed(object sender, System.EventArgs e) diff --git a/Source/MonoGame.Extended.NuclexGui/Controls/GuiLabelControl.cs b/Source/MonoGame.Extended.NuclexGui/Controls/GuiLabelControl.cs index eb67ff61..d287e493 100644 --- a/Source/MonoGame.Extended.NuclexGui/Controls/GuiLabelControl.cs +++ b/Source/MonoGame.Extended.NuclexGui/Controls/GuiLabelControl.cs @@ -6,6 +6,19 @@ /// Text to be rendered in the control's frame public string Text; + /// + /// Gets or sets the style to be used with this label when drawing. + /// + /// + /// + /// If you are using the FlatGuiVisualizer, this style + /// corresponds to the 'Frames' used in + /// + /// The style can be customized in the skin's json file. + /// + /// + public string Style { get; set; } + /// Initializes a new label control with an empty string public GuiLabelControl() : this(string.Empty) { diff --git a/Source/MonoGame.Extended.NuclexGui/Resources/Skins/SuaveSkin.json b/Source/MonoGame.Extended.NuclexGui/Resources/Skins/SuaveSkin.json index c3936ce4..47ef2f87 100644 --- a/Source/MonoGame.Extended.NuclexGui/Resources/Skins/SuaveSkin.json +++ b/Source/MonoGame.Extended.NuclexGui/Resources/Skins/SuaveSkin.json @@ -9,6 +9,22 @@ { "name": "default", "contentPath": "DefaultFont" + }, + { + "name": "heading1", + "contentPath": "Fonts/Heading1" + }, + { + "name": "heading2", + "contentPath": "Fonts/Heading2" + }, + { + "name": "heading3", + "contentPath": "Fonts/Heading3" + }, + { + "name": "label-title", + "contentPath": "Fonts/Title" } ], "bitmap": [ @@ -133,6 +149,54 @@ } ] }, + { + "name": "label-h1", + "text": [ + { + "font": "heading1", + "hplacement": "left", + "vplacement": "center", + "yoffset": 0, + "color": "#3F3F3F" + } + ] + }, + { + "name": "label-h2", + "text": [ + { + "font": "heading2", + "hplacement": "left", + "vplacement": "center", + "yoffset": 0, + "color": "#3F3F3F" + } + ] + }, + { + "name": "label-h3", + "text": [ + { + "font": "heading3", + "hplacement": "left", + "vplacement": "center", + "yoffset": 0, + "color": "#3F3F3F" + } + ] + }, + { + "name": "label-title", + "text": [ + { + "font": "label-title", + "hplacement": "left", + "vplacement": "center", + "yoffset": 0, + "color": "#3F3F3F" + } + ] + }, { "name": "progress", "region": [ diff --git a/Source/MonoGame.Extended.NuclexGui/Visuals/Flat/Renderers/FlatLabelControlRenderer.cs b/Source/MonoGame.Extended.NuclexGui/Visuals/Flat/Renderers/FlatLabelControlRenderer.cs index 22042376..9e99f4bc 100644 --- a/Source/MonoGame.Extended.NuclexGui/Visuals/Flat/Renderers/FlatLabelControlRenderer.cs +++ b/Source/MonoGame.Extended.NuclexGui/Visuals/Flat/Renderers/FlatLabelControlRenderer.cs @@ -1,4 +1,5 @@ -using MonoGame.Extended.NuclexGui.Controls; +using System; +using MonoGame.Extended.NuclexGui.Controls; namespace MonoGame.Extended.NuclexGui.Visuals.Flat.Renderers { @@ -14,7 +15,10 @@ namespace MonoGame.Extended.NuclexGui.Visuals.Flat.Renderers /// public void Render(GuiLabelControl control, IFlatGuiGraphics graphics) { - graphics.DrawString("label", control.GetAbsoluteBounds(), control.Text); + var frameName = "label"; + if (control.Style != null) frameName = control.Style; + + graphics.DrawString(frameName, control.GetAbsoluteBounds(), control.Text); } } } \ No newline at end of file diff --git a/Source/MonoGame.Extended.sln b/Source/MonoGame.Extended.sln index 04670910..94e65d6e 100644 --- a/Source/MonoGame.Extended.sln +++ b/Source/MonoGame.Extended.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26430.12 +VisualStudioVersion = 15.0.27130.2010 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MonoGame.Extended", "MonoGame.Extended\MonoGame.Extended.csproj", "{41724C52-3D50-45BB-81EB-3C8A247EAFD1}" EndProject @@ -107,6 +107,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sandbox", "Tests\Sandbox\Sa {28CD24BD-432C-4987-9E9D-65CFCF120EA0} = {28CD24BD-432C-4987-9E9D-65CFCF120EA0} EndProjectSection EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MonoGame.Extended.Entities.Tests", "Tests\MonoGame.Extended.Entities.Tests\MonoGame.Extended.Entities.Tests.csproj", "{5B993DD9-A9B8-434C-B444-F1CFFB947F79}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -323,6 +325,14 @@ Global {9A920A4D-3794-4AB4-9A76-3C19407A1C5F}.Release|Any CPU.Build.0 = Release|Any CPU {9A920A4D-3794-4AB4-9A76-3C19407A1C5F}.Release|x86.ActiveCfg = Release|Any CPU {9A920A4D-3794-4AB4-9A76-3C19407A1C5F}.Release|x86.Build.0 = Release|Any CPU + {5B993DD9-A9B8-434C-B444-F1CFFB947F79}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5B993DD9-A9B8-434C-B444-F1CFFB947F79}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5B993DD9-A9B8-434C-B444-F1CFFB947F79}.Debug|x86.ActiveCfg = Debug|Any CPU + {5B993DD9-A9B8-434C-B444-F1CFFB947F79}.Debug|x86.Build.0 = Debug|Any CPU + {5B993DD9-A9B8-434C-B444-F1CFFB947F79}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5B993DD9-A9B8-434C-B444-F1CFFB947F79}.Release|Any CPU.Build.0 = Release|Any CPU + {5B993DD9-A9B8-434C-B444-F1CFFB947F79}.Release|x86.ActiveCfg = Release|Any CPU + {5B993DD9-A9B8-434C-B444-F1CFFB947F79}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -342,5 +352,9 @@ Global {57C47653-BC51-43BA-98F4-1D0EEE78782D} = {932F8931-4A8D-4205-BFCF-98E794207786} {BDAEDFAF-2EDA-4BCA-9675-3625456FAB78} = {932F8931-4A8D-4205-BFCF-98E794207786} {9A920A4D-3794-4AB4-9A76-3C19407A1C5F} = {E5A148A1-DE7B-4D17-ABE8-831B9673B863} + {5B993DD9-A9B8-434C-B444-F1CFFB947F79} = {E5A148A1-DE7B-4D17-ABE8-831B9673B863} + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {8ED5A62D-25EC-4331-9F99-BDD1E10C02A0} EndGlobalSection EndGlobal diff --git a/Source/Tests/MonoGame.Extended.Entities.Tests/EntityTemplateTests.cs b/Source/Tests/MonoGame.Extended.Entities.Tests/EntityTemplateTests.cs new file mode 100644 index 00000000..9d49b2e8 --- /dev/null +++ b/Source/Tests/MonoGame.Extended.Entities.Tests/EntityTemplateTests.cs @@ -0,0 +1,54 @@ +using System; +using Microsoft.Xna.Framework; +using MonoGame.Extended.Entities; +using MonoGame.Extended.Gui.Tests.Implementation; +using NUnit.Framework; + +namespace MonoGame.Extended.Gui.Tests +{ + [TestFixture] + public class EntityTemplateTests + { + [Test] + public void ECS_CreateEntityFromTemplate_Basic_Test() + { + // Seems to work with null. + var ecs = new EntityComponentSystem(null); + ecs.Scan(typeof(EntityTemplateBasic).Assembly); + var manager = ecs.EntityManager; + Entity entity = null; + try + { + entity = manager.CreateEntityFromTemplate(EntityTemplateBasic.Name); + } + catch (Exception e) + { + Assert.Fail("Failed to create entity from template.\n" + e.StackTrace); + } + + Assert.NotNull(entity); + Assert.NotNull(entity.Get()); + } + + [Test] + public void ECS_CreateEntityFromTemplate_UsingManager_Test() + { + // Seems to work with null. + var ecs = new EntityComponentSystem(null); + ecs.Scan(typeof(EntityTemplateUsingManager).Assembly); + var manager = ecs.EntityManager; + Entity entity = null; + try + { + entity = manager.CreateEntityFromTemplate(EntityTemplateUsingManager.Name); + } + catch (Exception e) + { + Assert.Fail("Failed to create entity from template.\n" + e.StackTrace); + } + + Assert.NotNull(entity); + Assert.NotNull(entity.Get()); + } + } +} \ No newline at end of file diff --git a/Source/Tests/MonoGame.Extended.Entities.Tests/Implementation/EntityComponentBasic.cs b/Source/Tests/MonoGame.Extended.Entities.Tests/Implementation/EntityComponentBasic.cs new file mode 100644 index 00000000..3161781c --- /dev/null +++ b/Source/Tests/MonoGame.Extended.Entities.Tests/Implementation/EntityComponentBasic.cs @@ -0,0 +1,10 @@ +using MonoGame.Extended.Entities; + +namespace MonoGame.Extended.Gui.Tests.Implementation +{ + [EntityComponent] + public class EntityComponentBasic : TransformComponent2D + { + public int Number { get; set; } + } +} \ No newline at end of file diff --git a/Source/Tests/MonoGame.Extended.Entities.Tests/Implementation/EntityTemplateBasic.cs b/Source/Tests/MonoGame.Extended.Entities.Tests/Implementation/EntityTemplateBasic.cs new file mode 100644 index 00000000..a4d7bfe6 --- /dev/null +++ b/Source/Tests/MonoGame.Extended.Entities.Tests/Implementation/EntityTemplateBasic.cs @@ -0,0 +1,15 @@ +using MonoGame.Extended.Entities; + +namespace MonoGame.Extended.Gui.Tests.Implementation +{ + [EntityTemplate(Name)] + public class EntityTemplateBasic : EntityTemplate + { + public const string Name = nameof(EntityTemplateBasic); + + protected override void Build(Entity entity) + { + entity.Attach(); + } + } +} \ No newline at end of file diff --git a/Source/Tests/MonoGame.Extended.Entities.Tests/Implementation/EntityTemplateUsingManager.cs b/Source/Tests/MonoGame.Extended.Entities.Tests/Implementation/EntityTemplateUsingManager.cs new file mode 100644 index 00000000..260345e1 --- /dev/null +++ b/Source/Tests/MonoGame.Extended.Entities.Tests/Implementation/EntityTemplateUsingManager.cs @@ -0,0 +1,16 @@ +using MonoGame.Extended.Entities; + +namespace MonoGame.Extended.Gui.Tests.Implementation +{ + [EntityTemplate(Name)] + public class EntityTemplateUsingManager : EntityTemplate + { + public const string Name = nameof(EntityTemplateUsingManager); + + protected override void Build(Entity entity) + { + var num = Manager.EntityManager.TotalEntitiesCount; + entity.Attach(c => c.Number = num); + } + } +} \ No newline at end of file diff --git a/Source/Tests/MonoGame.Extended.Entities.Tests/Implementation/README.md b/Source/Tests/MonoGame.Extended.Entities.Tests/Implementation/README.md new file mode 100644 index 00000000..d5356ff1 --- /dev/null +++ b/Source/Tests/MonoGame.Extended.Entities.Tests/Implementation/README.md @@ -0,0 +1,5 @@ + +# Implementation + +This folder is for making a testable implementation using the ECS library. +This implementation is used in the unit tests in this project. \ No newline at end of file diff --git a/Source/Tests/MonoGame.Extended.Entities.Tests/MonoGame.Extended.Entities.Tests.csproj b/Source/Tests/MonoGame.Extended.Entities.Tests/MonoGame.Extended.Entities.Tests.csproj new file mode 100644 index 00000000..b0e1f265 --- /dev/null +++ b/Source/Tests/MonoGame.Extended.Entities.Tests/MonoGame.Extended.Entities.Tests.csproj @@ -0,0 +1,79 @@ + + + + + Debug + AnyCPU + {5B993DD9-A9B8-434C-B444-F1CFFB947F79} + Library + Properties + MonoGame.Extended.Gui.Tests + MonoGame.Extended.Gui.Tests + v4.5.2 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\..\packages\MonoGame.Framework.WindowsDX.3.6.0.1625\lib\net40\MonoGame.Framework.dll + True + + + ..\..\packages\NSubstitute.1.10.0.0\lib\net45\NSubstitute.dll + True + + + ..\..\packages\NUnit.2.6.4\lib\nunit.framework.dll + True + + + + + + + + + + + + + + + + + + + + + + + + {35fd1f05-af04-469a-b37a-f9b36c34401c} + MonoGame.Extended.Entities + + + + + \ No newline at end of file diff --git a/Source/Tests/MonoGame.Extended.Entities.Tests/Properties/AssemblyInfo.cs b/Source/Tests/MonoGame.Extended.Entities.Tests/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..07a0c3c0 --- /dev/null +++ b/Source/Tests/MonoGame.Extended.Entities.Tests/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("MonoGame.Extended.Entities.Tests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("MonoGame.Extended.Entities.Tests")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("EFE3C251-67A7-4BBF-A4B8-A7659F460920")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Source/Tests/MonoGame.Extended.Entities.Tests/packages.config b/Source/Tests/MonoGame.Extended.Entities.Tests/packages.config new file mode 100644 index 00000000..fa95cfc0 --- /dev/null +++ b/Source/Tests/MonoGame.Extended.Entities.Tests/packages.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file