Skip to content

Commit 220f2bf

Browse files
authored
Merge pull request #39 from exomia/development
feature ui
2 parents 913465d + 8a1b926 commit 220f2bf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+3165
-993
lines changed

examples/Exomia.Framework.Example.Canvas/Exomia.Framework.Example.Canvas.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<LangVersion>8.0</LangVersion>
77
<Nullable>enable</Nullable>
88
<NullableReferenceTypes>true</NullableReferenceTypes>
9+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
910
</PropertyGroup>
1011

1112
<PropertyGroup>
@@ -45,7 +46,7 @@
4546
<AssemblyName>$(MSBuildProjectName).$(Platform)</AssemblyName>
4647
<PackageId>$(MSBuildProjectName).$(Platform)</PackageId>
4748
</PropertyGroup>
48-
49+
4950
<ItemGroup>
5051
<ProjectReference Include="..\..\src\Exomia.Framework\Exomia.Framework.csproj" />
5152
</ItemGroup>

examples/Exomia.Framework.Example.Canvas/MyGame.cs

Lines changed: 153 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,16 @@
88

99
#endregion
1010

11+
using System;
1112
using Exomia.Framework.Components;
1213
using Exomia.Framework.Game;
1314
using Exomia.Framework.Graphics;
15+
using Exomia.Framework.Input;
1416
using Exomia.Framework.Mathematics;
1517
using Exomia.Framework.Resources;
18+
using Exomia.Framework.UI;
19+
using Exomia.Framework.UI.Brushes;
20+
using Exomia.Framework.UI.Controls;
1621
using SharpDX;
1722

1823
namespace Exomia.Framework.Example.Canvas
@@ -81,9 +86,9 @@ public MyGame()
8186
protected override void OnInitializeGameGraphicsParameters(ref GameGraphicsParameters parameters)
8287
{
8388
parameters.IsMouseVisible = true;
84-
parameters.Width = 1600;
85-
parameters.Height = 1024;
86-
parameters.EnableMultiSampling = true;
89+
parameters.Width = 1920;
90+
parameters.Height = 1080;
91+
parameters.EnableMultiSampling = false;
8792
parameters.MultiSampleCount = MultiSampleCount.MsaaX8;
8893
}
8994

@@ -95,33 +100,157 @@ protected override void OnInitialize()
95100
_spriteBatch = ToDispose(new SpriteBatch(GraphicsDevice));
96101
_canvas = ToDispose(new Graphics.Canvas(GraphicsDevice));
97102

98-
/*
99-
* TODO: Add your initialization logic here
100-
*/
103+
var uiManager = Add(new UiManager("uiManager") { Visible = true, DrawOrder = 1 });
104+
105+
var container = new Container
106+
{
107+
Enabled = true,
108+
Visible = true,
109+
BackgroundBrush = new SolidColorBrush(Color.Orange),
110+
ClientRectangle = new RectangleF(50, 700, 400, 400)
111+
};
112+
container.MouseEntered += (Control sender, in MouseEventArgs args) =>
113+
{
114+
Console.WriteLine("entered...");
115+
};
116+
container.MouseLeaved += (Control sender, in MouseEventArgs args) =>
117+
{
118+
Console.WriteLine("leaved...");
119+
};
120+
121+
_texture = Content.Load<Texture>("logo1.jpg");
122+
123+
var container2 = new Container
124+
{
125+
Enabled = true,
126+
Visible = true,
127+
BackgroundBrush = new TextureBrush(_texture),
128+
ClientRectangle = new RectangleF(50, 50, 500, 75)
129+
};
130+
container2.MouseEntered += (Control sender, in MouseEventArgs args) =>
131+
{
132+
Console.WriteLine("2 entered...");
133+
};
134+
container2.MouseLeaved += (Control sender, in MouseEventArgs args) =>
135+
{
136+
Console.WriteLine("2 leaved...");
137+
};
138+
container.Add(container2);
139+
uiManager.Add(container);
140+
141+
_spriteFont1_12Px = Content.Load<SpriteFont>(Fonts.ARIAL_12_PX, true);
142+
_spriteFont1_24Px = Content.Load<SpriteFont>(Fonts.ARIAL_24_PX, true);
143+
144+
var label1 = new Label(_spriteFont1_24Px, "Hello there!")
145+
{
146+
Enabled = true,
147+
Visible = true,
148+
BackgroundBrush = new BorderBrush(Color.BlueViolet),
149+
ClientRectangle = new RectangleF(320, 300, 200, 50),
150+
TextAlignment = TextAlignment.MiddleCenter
151+
};
152+
label1.MouseEntered += (Control sender, in MouseEventArgs args) =>
153+
{
154+
label1.Text = "entered...";
155+
};
156+
label1.MouseLeaved += (Control sender, in MouseEventArgs args) =>
157+
{
158+
label1.Text = "leaved...";
159+
};
160+
container.Add(label1);
161+
162+
var button1 = new Button(_spriteFont1_24Px, "click me!")
163+
{
164+
Enabled = true,
165+
Visible = true,
166+
BackgroundBrush = new SolidColorBrush(Color.Yellow),
167+
ClientRectangle = new RectangleF(900, 900, 400, 80),
168+
TextAlignment = TextAlignment.MiddleCenter
169+
};
170+
button1.MouseEntered += (Control sender, in MouseEventArgs args) =>
171+
{
172+
button1.Text = "entered...";
173+
};
174+
button1.MouseLeaved += (Control sender, in MouseEventArgs args) =>
175+
{
176+
button1.Text = "leaved...";
177+
};
178+
button1.MouseClick += (Control sender, in MouseEventArgs args, ref EventAction action) =>
179+
{
180+
button1.Text = "clicked...";
181+
};
182+
button1.GotFocus += (Control sender) =>
183+
{
184+
button1.Text = "got focus...";
185+
};
186+
button1.LostFocus += (Control sender) =>
187+
{
188+
button1.Text = "lost focus...";
189+
};
190+
uiManager.Add(button1);
191+
192+
var checkbox1 = new Checkbox
193+
{
194+
Enabled = true,
195+
Visible = true,
196+
BackgroundBrush = new SolidColorBrush(Color.Yellow),
197+
CheckedBrush = new SolidColorBrush(Color.Blue),
198+
ClientRectangle = new RectangleF(380, 0, 40, 40),
199+
Padding = new Padding(5)
200+
};
201+
container.Add(checkbox1);
202+
203+
var progressbar1 = new Progressbar
204+
{
205+
Enabled = true,
206+
Visible = true,
207+
BackgroundBrush = new BorderBrush(Color.Yellow),
208+
BarBrush = new SolidColorBrush(Color.Blue),
209+
ClientRectangle = new RectangleF(300, 180, 200, 50),
210+
Padding = new Padding(10, 5),
211+
Value = 0.13f
212+
};
213+
progressbar1.MouseEntered += (Control sender, in MouseEventArgs args) =>
214+
{
215+
progressbar1.Value += 0.05f;
216+
};
217+
container.Add(progressbar1);
218+
219+
var slider1 = new Slider
220+
{
221+
Enabled = true,
222+
Visible = true,
223+
SliderTrackBrush = new SolidColorBrush(Color.Gray),
224+
SliderCaretBrush = new SolidColorBrush(Color.DarkGray),
225+
ClientRectangle = new RectangleF(300, 250, 200, 50),
226+
Padding = new Padding(20, 5),
227+
Value = 0
228+
};
229+
container.Add(slider1);
230+
231+
var label2 = new Label(_spriteFont1_24Px, "0")
232+
{
233+
Enabled = true,
234+
Visible = true,
235+
ClientRectangle = new RectangleF(555, 950, 200, 50),
236+
TextAlignment = TextAlignment.MiddleLeft
237+
};
238+
slider1.ValueChanged += slider => { label2.Text = slider.Value.ToString(); };
239+
uiManager.Add(label2);
101240
}
102241

103242
/// <inheritdoc />
104243
/// OnLoadContent will be called once per game and is the place to load all of your content.
105244
protected override void OnLoadContent()
106245
{
107-
/*
108-
* TODO: use base.Content to load your game content here
109-
*/
110-
111-
_texture = Content.Load<Texture>("logo1.jpg");
112246
_texture2 = Content.Load<Texture>("logo2.png");
113-
114-
_spriteFont1_12Px = Content.Load<SpriteFont>(Fonts.ARIAL_12_PX, true);
115-
_spriteFont1_24Px = Content.Load<SpriteFont>(Fonts.ARIAL_24_PX, true);
116247
}
117248

118249
/// <inheritdoc />
119250
/// OnUnloadContent will be called once per game and is the place to unload all content
120251
protected override void OnUnloadContent()
121252
{
122-
/*
123-
* TODO: Unload any non ContentManager content here
124-
*/
253+
Content.Unload<Texture>("logo2.png");
125254
}
126255

127256
/// <inheritdoc />
@@ -140,7 +269,6 @@ protected override void Update(GameTime gameTime)
140269
protected override void Draw(GameTime gameTime)
141270
{
142271
GraphicsDevice.Clear(Color.CornflowerBlue);
143-
144272
_canvas.Begin(rasterizerState: GraphicsDevice.RasterizerStates.CullBackDepthClipOffMultiSampleOn);
145273

146274
k += gameTime.DeltaTimeS / 2;
@@ -159,11 +287,11 @@ protected override void Draw(GameTime gameTime)
159287
_canvas.DrawFillRectangle(new RectangleF(200, 200, 100, 50), Color.Yellow, k, new Vector2(200, 200), 1.0f);
160288
_canvas.DrawRectangle(new RectangleF(200, 200, 100, 50), Color.Green, 5.0f, k, new Vector2(200, 200), 1.0f);
161289

162-
_canvas.DrawLine(new Line2(300, 400, 345, 400), Color.Red, 5.0f, 1.0f, 0, Vector2.Zero);
163-
_canvas.DrawLine(new Line2(400, 400, 450, 450), Color.Red, 5.0f, 1.0f, k, new Vector2(425, 425));
290+
_canvas.DrawLine(new Line2(300, 400, 345, 400), Color.Red, 5.0f, 0, Vector2.Zero, 1.0f);
291+
_canvas.DrawLine(new Line2(400, 400, 450, 450), Color.Red, 5.0f, k, new Vector2(425, 425), 1.0f);
164292

165-
_canvas.DrawLine(new Line2(300, 450, 345, 450), Color.Yellow, 5.0f, 1.0f, 0, Vector2.Zero);
166-
_canvas.DrawLine(new Line2(400, 450, 450, 400), Color.Yellow, 5.0f, 1.0f, k, new Vector2(425, 425));
293+
_canvas.DrawLine(new Line2(300, 450, 345, 450), Color.Yellow, 5.0f, 0, Vector2.Zero, 1.0f);
294+
_canvas.DrawLine(new Line2(400, 450, 450, 400), Color.Yellow, 5.0f, k, new Vector2(425, 425), 1.0f);
167295

168296
_canvas.DrawFillPolygon(polyA, Color.Red, 0.0f, Vector2.Zero, 1.0f);
169297
_canvas.DrawPolygon(polyA, Color.Green, 5.0f, 0.0f, Vector2.Zero, 1.0f);
@@ -271,7 +399,9 @@ protected override void Draw(GameTime gameTime)
271399
_canvas.Draw(_texture2, new RectangleF(1350, 50, 200, 200), Color.White);
272400

273401
_canvas.DrawText(_spriteFont1_12Px, "This is the canvas example.", new Vector2(450, 50), Color.Black, 0);
274-
_canvas.DrawText(_spriteFont1_24Px, "This is the canvas example.", new Vector2(450, 65), Color.Black, k, new Vector2(450, 65), 1.0f, TextureEffects.None);
402+
_canvas.DrawText(
403+
_spriteFont1_24Px, "This is the canvas example.", new Vector2(450, 65), Color.Black, k,
404+
new Vector2(450, 65), 1.0f, TextureEffects.None);
275405

276406
_canvas.End();
277407

examples/Exomia.Framework.Example.Canvas/Program.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#endregion
1010

11+
using System;
12+
1113
namespace Exomia.Framework.Example.Canvas
1214
{
1315
/// <summary>

examples/Exomia.Framework.Example.JumpAndRun/Exomia.Framework.Example.JumpAndRun.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040
</PropertyGroup>
4141

4242
<ItemGroup>
43-
<PackageReference Include="Exomia.Framework" Version="1.4.1" />
44-
<PackageReference Include="Exomia.ECS" Version="1.5.3-debug.1" />
43+
<PackageReference Include="Exomia.Framework" Version="1.*" />
44+
<PackageReference Include="Exomia.ECS" Version="1.*" />
4545
</ItemGroup>
4646

4747
<ItemGroup>

examples/Exomia.Framework.Example.JumpAndRun/Scenes/GameScene.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ protected override void OnLoadContent(IServiceRegistry registry)
170170
});
171171
}
172172

173-
private bool OnKeyDown(int keyValue, KeyModifier modifiers)
173+
private EventAction OnKeyDown(int keyValue, KeyModifier modifiers)
174174
{
175175
switch (keyValue)
176176
{
@@ -182,10 +182,10 @@ private bool OnKeyDown(int keyValue, KeyModifier modifiers)
182182
break;
183183
}
184184

185-
return false;
185+
return EventAction.Continue;
186186
}
187187

188-
private bool OnKeyUp(int keyValue, KeyModifier modifiers)
188+
private EventAction OnKeyUp(int keyValue, KeyModifier modifiers)
189189
{
190190
switch (keyValue)
191191
{
@@ -199,7 +199,7 @@ private bool OnKeyUp(int keyValue, KeyModifier modifiers)
199199
_inputComponent.Right = false;
200200
break;
201201
}
202-
return false;
202+
return EventAction.Continue;
203203
}
204204
}
205205
}

src/Exomia.Framework/Activator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public static TDelegate GetCreator<TDelegate>()
8484
where TDelegate : Delegate
8585
{
8686
Type dType = typeof(TDelegate);
87-
return (TDelegate)Convert.ChangeType(GetCreator(dType), dType);
87+
return (TDelegate)System.Convert.ChangeType(GetCreator(dType), dType);
8888
}
8989

9090
/// <summary>

src/Exomia.Framework/Buffers/CircularBuffer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public T this[int index]
101101
/// Thrown when one or more arguments have unsupported or
102102
/// illegal values.
103103
/// </exception>
104-
public CircularBuffer(int capacity = 1024, T[] items = null!)
104+
public CircularBuffer(int capacity = 1024, T[]? items = null)
105105
{
106106
if (capacity < 1)
107107
{

0 commit comments

Comments
 (0)