Skip to content
Draft

Ui #75

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions EngineGL.Tests/Exec/GamrExecTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
17 changes: 17 additions & 0 deletions EngineGL/Core/LifeCycle/IClickable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using EngineGL.Event.LifeCycle;
using EngineGL.Structs.Drawing;

namespace EngineGL.Core.LifeCycle
{
public interface IClickable
{
event EventHandler<ClickEventArgs> Click;

/// <summary>
/// オブジェクトを描画するメソッド
/// </summary>
/// <param name="deltaTime">ゲームのフレーム更新間隔時間</param>
void OnClick();
}
}
2 changes: 2 additions & 0 deletions EngineGL/EngineGL.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,15 @@
<Compile Include="Core\INameable.cs" />
<Compile Include="Core\IObject.cs" />
<Compile Include="Core\IScene.cs" />
<Compile Include="Core\LifeCycle\IClickable.cs" />
<Compile Include="Core\LifeCycle\IDestroyable.cs" />
<Compile Include="Core\LifeCycle\IDrawable.cs" />
<Compile Include="Core\LifeCycle\IGuiRenderable.cs" />
<Compile Include="Core\LifeCycle\Initialzeable.cs" />
<Compile Include="Core\LifeCycle\IUpdateable.cs" />
<Compile Include="Core\Resource\IAudio.cs" />
<Compile Include="Core\Resource\ITexture.cs" />
<Compile Include="Event\LifeCycle\ClickEventArgs.cs" />
<Compile Include="GraphicAdapter\GraphicAdapterFactory.cs" />
<Compile Include="GraphicAdapter\Impl\OpenGL2\GraphicAdapter.cs" />
<Compile Include="GraphicAdapter\Impl\OpenGL2\PreprocessVertexHandler.cs" />
Expand Down
17 changes: 17 additions & 0 deletions EngineGL/Event/LifeCycle/ClickEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using EngineGL.Core.LifeCycle;
using OpenTK.Graphics.OpenGL;
using OpenTK.Input;

namespace EngineGL.Event.LifeCycle
{
public class ClickEventArgs : EventArgs
{
public IClickable ClickTarget { get; }

public ClickEventArgs(IClickable clickable)
{
ClickTarget = clickable;
}
}
}
30 changes: 25 additions & 5 deletions EngineGL/Impl/UI/Button.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,44 @@
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 : Element
public class Button : DrawableComponent, IClickable
{
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 event EventHandler<ClickEventArgs> Click;

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()
{
Colour = Color.Blue;
}
}
}