From 79c94ad0042ca7ed129d492441d1d28d15d8e14a Mon Sep 17 00:00:00 2001 From: Kai Date: Wed, 26 Jun 2019 01:19:02 +0900 Subject: [PATCH 1/3] =?UTF-8?q?Button=E4=BD=9C=E6=88=90=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- EngineGL.Tests/Exec/GamrExecTest.cs | 11 ++++++++++ EngineGL/EngineGL.csproj | 1 + EngineGL/Event/LifeCycle/ClickEventArgs.cs | 7 ++++++ EngineGL/Impl/UI/Button.cs | 25 +++++++++++++++++----- 4 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 EngineGL/Event/LifeCycle/ClickEventArgs.cs diff --git a/EngineGL.Tests/Exec/GamrExecTest.cs b/EngineGL.Tests/Exec/GamrExecTest.cs index a30f89a..9f8b911 100644 --- a/EngineGL.Tests/Exec/GamrExecTest.cs +++ b/EngineGL.Tests/Exec/GamrExecTest.cs @@ -10,6 +10,8 @@ using EngineGL.Impl.DrawableComponents.Shape3D; using EngineGL.Impl.Objects; using EngineGL.Impl.Resource; +using EngineGL.Impl.UI; +using EngineGL.Structs.Drawing; using EngineGL.Structs.Math; using EngineGL.Tests.Exec.TestComponents; using EngineGL.Utils; @@ -174,6 +176,15 @@ private Scene GetInitScene() }); scene.AddObject(g8); + GameObject g9 = new GameObject(); + g9.SetBounds(new Vec3(5, 5, 0)) + .SetPosition(new Vec3(-3, -2, 0)); + g9.AddComponent(new Button() + { + Colour = Color4.Red + }); + scene.AddObject(g9); + IAudio audio = ResourceManager.LoadWave("Sounds/Mixdown2.wav"); audio.SetLoop(true); audio.Play(); diff --git a/EngineGL/EngineGL.csproj b/EngineGL/EngineGL.csproj index 258f8ba..65b5009 100644 --- a/EngineGL/EngineGL.csproj +++ b/EngineGL/EngineGL.csproj @@ -103,6 +103,7 @@ + diff --git a/EngineGL/Event/LifeCycle/ClickEventArgs.cs b/EngineGL/Event/LifeCycle/ClickEventArgs.cs new file mode 100644 index 0000000..8abfde6 --- /dev/null +++ b/EngineGL/Event/LifeCycle/ClickEventArgs.cs @@ -0,0 +1,7 @@ +namespace EngineGL.Event.LifeCycle +{ + public class ClickEventArgs + { + + } +} \ No newline at end of file diff --git a/EngineGL/Impl/UI/Button.cs b/EngineGL/Impl/UI/Button.cs index 6cbacc2..703be6d 100644 --- a/EngineGL/Impl/UI/Button.cs +++ b/EngineGL/Impl/UI/Button.cs @@ -1,23 +1,38 @@ using System.Drawing; +using EngineGL.GraphicAdapter; +using EngineGL.GraphicAdapter.Interface; using EngineGL.Structs.Drawing; +using EngineGL.Impl.DrawableComponents; +using EngineGL.Structs.Math; namespace EngineGL.Impl.UI { - public class Button : Element + public class Button : DrawableComponent { public string Text { get; set; } - public Colour4 BackColor { get; set; } public Font Font { get; set; } public int FontSize { get; set; } - public Colour4 FontColor { get; set; } + public Color FontColor { get; set; } public int Width { get; set; } public int Height { get; set; } - public Button() + public Button() : base(GraphicAdapterFactory.OpenGL2.CreateQuads()) { } - public void Click() + public override void OnVertexWrite(double deltaTime, IVertexHandler vertexHandler) + { + base.OnVertexWrite(deltaTime, vertexHandler); + vertexHandler.SetVertces3(new Vec3[] + { + new Vec3(-GameObject.Transform.Bounds.X / 2, -GameObject.Transform.Bounds.Y / 2), + new Vec3(GameObject.Transform.Bounds.X / 2, -GameObject.Transform.Bounds.Y / 2), + new Vec3(GameObject.Transform.Bounds.X / 2, GameObject.Transform.Bounds.Y / 2), + new Vec3(-GameObject.Transform.Bounds.X / 2, GameObject.Transform.Bounds.Y / 2), + }); + } + + public void OnClick() { } } From a96980bc68b43ed0d1804b1f69c8e9c8981afc8f Mon Sep 17 00:00:00 2001 From: Kai Date: Wed, 26 Jun 2019 02:04:41 +0900 Subject: [PATCH 2/3] =?UTF-8?q?Click=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- EngineGL/Core/LifeCycle/IClickable.cs | 17 +++++++++++++++++ EngineGL/EngineGL.csproj | 1 + EngineGL/Event/LifeCycle/ClickEventArgs.cs | 14 ++++++++++++-- EngineGL/Impl/UI/Button.cs | 4 ++-- 4 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 EngineGL/Core/LifeCycle/IClickable.cs diff --git a/EngineGL/Core/LifeCycle/IClickable.cs b/EngineGL/Core/LifeCycle/IClickable.cs new file mode 100644 index 0000000..242b28e --- /dev/null +++ b/EngineGL/Core/LifeCycle/IClickable.cs @@ -0,0 +1,17 @@ +using System; +using EngineGL.Event.LifeCycle; +using EngineGL.Structs.Drawing; + +namespace EngineGL.Core.LifeCycle +{ + public interface IClickable + { + event EventHandler Draw; + + /// + /// オブジェクトを描画するメソッド + /// + /// ゲームのフレーム更新間隔時間 + void OnClick(); + } +} \ No newline at end of file diff --git a/EngineGL/EngineGL.csproj b/EngineGL/EngineGL.csproj index 65b5009..80ff0c1 100644 --- a/EngineGL/EngineGL.csproj +++ b/EngineGL/EngineGL.csproj @@ -96,6 +96,7 @@ + diff --git a/EngineGL/Event/LifeCycle/ClickEventArgs.cs b/EngineGL/Event/LifeCycle/ClickEventArgs.cs index 8abfde6..95d56f0 100644 --- a/EngineGL/Event/LifeCycle/ClickEventArgs.cs +++ b/EngineGL/Event/LifeCycle/ClickEventArgs.cs @@ -1,7 +1,17 @@ +using System; +using EngineGL.Core.LifeCycle; +using OpenTK.Graphics.OpenGL; +using OpenTK.Input; + namespace EngineGL.Event.LifeCycle { - public class ClickEventArgs + public class ClickEventArgs : EventArgs { - + public IClickable ClickTarget { get; } + + public ClickEventArgs(IClickable clickable) + { + ClickTarget = clickable; + } } } \ No newline at end of file diff --git a/EngineGL/Impl/UI/Button.cs b/EngineGL/Impl/UI/Button.cs index 703be6d..491191e 100644 --- a/EngineGL/Impl/UI/Button.cs +++ b/EngineGL/Impl/UI/Button.cs @@ -1,7 +1,6 @@ using System.Drawing; using EngineGL.GraphicAdapter; using EngineGL.GraphicAdapter.Interface; -using EngineGL.Structs.Drawing; using EngineGL.Impl.DrawableComponents; using EngineGL.Structs.Math; @@ -32,8 +31,9 @@ public override void OnVertexWrite(double deltaTime, IVertexHandler vertexHandle }); } - public void OnClick() + public override void OnClick() { + } } } \ No newline at end of file From 754b772c9375c602aafc3413bb2b703c266ab6c3 Mon Sep 17 00:00:00 2001 From: Kai Date: Wed, 26 Jun 2019 07:57:12 +0900 Subject: [PATCH 3/3] =?UTF-8?q?Click=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- EngineGL/Core/LifeCycle/IClickable.cs | 2 +- EngineGL/Impl/UI/Button.cs | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/EngineGL/Core/LifeCycle/IClickable.cs b/EngineGL/Core/LifeCycle/IClickable.cs index 242b28e..9b0fa8e 100644 --- a/EngineGL/Core/LifeCycle/IClickable.cs +++ b/EngineGL/Core/LifeCycle/IClickable.cs @@ -6,7 +6,7 @@ namespace EngineGL.Core.LifeCycle { public interface IClickable { - event EventHandler Draw; + event EventHandler Click; /// /// オブジェクトを描画するメソッド diff --git a/EngineGL/Impl/UI/Button.cs b/EngineGL/Impl/UI/Button.cs index 491191e..f0c9809 100644 --- a/EngineGL/Impl/UI/Button.cs +++ b/EngineGL/Impl/UI/Button.cs @@ -1,12 +1,16 @@ +using System; using System.Drawing; +using EngineGL.Core.LifeCycle; +using EngineGL.Event.LifeCycle; using EngineGL.GraphicAdapter; using EngineGL.GraphicAdapter.Interface; using EngineGL.Impl.DrawableComponents; +using EngineGL.Structs.Drawing; using EngineGL.Structs.Math; namespace EngineGL.Impl.UI { - public class Button : DrawableComponent + public class Button : DrawableComponent, IClickable { public string Text { get; set; } public Font Font { get; set; } @@ -14,6 +18,7 @@ public class Button : DrawableComponent public Color FontColor { get; set; } public int Width { get; set; } public int Height { get; set; } + public event EventHandler Click; public Button() : base(GraphicAdapterFactory.OpenGL2.CreateQuads()) { @@ -31,9 +36,9 @@ public override void OnVertexWrite(double deltaTime, IVertexHandler vertexHandle }); } - public override void OnClick() + public void OnClick() { - + Colour = Color.Blue; } } } \ No newline at end of file