From 9df0077257b02a464ede9ceaf1152e03cfea69fc Mon Sep 17 00:00:00 2001 From: Simon Holmberg Date: Tue, 16 Oct 2012 13:22:24 +0200 Subject: [PATCH] More GUI stuff --- DepthsBelow/DepthsBelow/Core.cs | 17 +- DepthsBelow/DepthsBelow/DepthsBelow.csproj | 397 +++++++++--------- DepthsBelow/DepthsBelow/GUI/Button.cs | 27 +- DepthsBelow/DepthsBelow/GUI/Frame.cs | 20 +- DepthsBelow/DepthsBelow/GUI/Text.cs | 5 + DepthsBelow/DepthsBelow/Interface.cs | 40 ++ .../DepthsBelowContent/Arial.spritefont | 2 +- 7 files changed, 282 insertions(+), 226 deletions(-) create mode 100755 DepthsBelow/DepthsBelow/Interface.cs diff --git a/DepthsBelow/DepthsBelow/Core.cs b/DepthsBelow/DepthsBelow/Core.cs index 43b2f17..72f58cf 100755 --- a/DepthsBelow/DepthsBelow/Core.cs +++ b/DepthsBelow/DepthsBelow/Core.cs @@ -92,21 +92,8 @@ namespace DepthsBelow TestMonster.X = 12; TestMonster.Y = 4; - // Test GUI frames - var frame = new GUI.Button() - { - X = 100, - Width = 48, - Height = 23, - Texture = Content.Load("images/Enter"), - OnClick = delegate(Point clickPos) - { - Debug.WriteLine("That ugly button was clicked at (" + clickPos.X + "," + clickPos.Y + ")"); - } - }; - var text = new GUI.Text(Content.Load("Arial")); - text.Value = "Hello world!"; - frame.Add(text); + + //frame.Add(text); } /// diff --git a/DepthsBelow/DepthsBelow/DepthsBelow.csproj b/DepthsBelow/DepthsBelow/DepthsBelow.csproj index ad34875..f85399d 100644 --- a/DepthsBelow/DepthsBelow/DepthsBelow.csproj +++ b/DepthsBelow/DepthsBelow/DepthsBelow.csproj @@ -1,200 +1,201 @@ - - - - {94683C5B-052D-4143-96D8-35C67E831000} - {6D335F3A-9D43-41b4-9D22-F6F17C4BE596};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - Debug - x86 - WinExe - Properties - DepthsBelow - DepthsBelow - v4.0 - Client - v4.0 - Windows - HiDef - faa0577e-a03e-43cf-89c7-0a03f4c22717 - Game - Game.ico - GameThumbnail.png - false - publish\ - true - Disk - false - Foreground - 7 - Days - false - false - true - 1 - 1.0.0.%2a - false - true - true - - - true - full - false - bin\x86\Debug - DEBUG;TRACE;WINDOWS - prompt - 4 - true - false - x86 - false - - - pdbonly - true - bin\x86\Release - TRACE;WINDOWS - prompt - 4 - true - false - x86 - true - - - ECE66DEF071576E8D2F7D57232C0569623E3E2DF - - - DepthsBelow_TemporaryKey.pfx - - - true - - - true - - - - False - - - False - - - False - - - False - - - False - - - False - - - False - - - False - - - False - - - False - - - False - - - - False - - - False - - - False - - - False - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {CD3F949D-54AA-4D38-99DB-92905A375D84} - AStar - - - DepthsBelowContent %28Content%29 - Content - {433A77A2-DE52-4875-A4EF-232CF59C2DD3} - - - - - False - Microsoft .NET Framework 4 Client Profile %28x86 and x64%29 - true - - - False - .NET Framework 3.5 SP1 Client Profile - false - - - False - .NET Framework 3.5 SP1 - false - - - False - Windows Installer 3.1 - true - - - False - Microsoft XNA Framework Redistributable 4.0 - true - - - - - - - - + + + + {94683C5B-052D-4143-96D8-35C67E831000} + {6D335F3A-9D43-41b4-9D22-F6F17C4BE596};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + Debug + x86 + WinExe + Properties + DepthsBelow + DepthsBelow + v4.0 + Client + v4.0 + Windows + HiDef + faa0577e-a03e-43cf-89c7-0a03f4c22717 + Game + Game.ico + GameThumbnail.png + false + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 1 + 1.0.0.%2a + false + true + true + + + true + full + false + bin\x86\Debug + DEBUG;TRACE;WINDOWS + prompt + 4 + true + false + x86 + false + + + pdbonly + true + bin\x86\Release + TRACE;WINDOWS + prompt + 4 + true + false + x86 + true + + + ECE66DEF071576E8D2F7D57232C0569623E3E2DF + + + DepthsBelow_TemporaryKey.pfx + + + true + + + true + + + + False + + + False + + + False + + + False + + + False + + + False + + + False + + + False + + + False + + + False + + + False + + + + False + + + False + + + False + + + False + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {CD3F949D-54AA-4D38-99DB-92905A375D84} + AStar + + + DepthsBelowContent %28Content%29 + Content + {433A77A2-DE52-4875-A4EF-232CF59C2DD3} + + + + + False + Microsoft .NET Framework 4 Client Profile %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 Client Profile + false + + + False + .NET Framework 3.5 SP1 + false + + + False + Windows Installer 3.1 + true + + + False + Microsoft XNA Framework Redistributable 4.0 + true + + + + + + + + + --> \ No newline at end of file diff --git a/DepthsBelow/DepthsBelow/GUI/Button.cs b/DepthsBelow/DepthsBelow/GUI/Button.cs index 3ff27a7..4d2c23d 100755 --- a/DepthsBelow/DepthsBelow/GUI/Button.cs +++ b/DepthsBelow/DepthsBelow/GUI/Button.cs @@ -17,16 +17,23 @@ namespace DepthsBelow.GUI private MouseState lastMouseState; - public Button() - { - - } - /*public void OnClick(Point pos) { Debug.WriteLine(this + " was clicked at (" + pos.X + "," + pos.Y + ")"); }*/ + public Button() + : base() + { + + } + + public Button(Frame parent) + : this() + { + this.Parent = parent; + } + public override void Update(GameTime gameTime) { base.Update(gameTime); @@ -37,14 +44,14 @@ namespace DepthsBelow.GUI { // HACK: This should be handled globally somewhere else to prevent event bubbling if ( - ms.X >= Rectangle.Left - && ms.X < Rectangle.Right - && ms.Y >= Rectangle.Top - && ms.Y < Rectangle.Bottom) + ms.X >= AbsoluteRectangle.Left + && ms.X < AbsoluteRectangle.Right + && ms.Y >= AbsoluteRectangle.Top + && ms.Y < AbsoluteRectangle.Bottom) { if (OnClick != null) { - var clickPos = new Point(ms.X - Rectangle.X, ms.Y - Rectangle.Y); + var clickPos = new Point(ms.X - AbsoluteRectangle.X, ms.Y - AbsoluteRectangle.Y); OnClick(clickPos); } } diff --git a/DepthsBelow/DepthsBelow/GUI/Frame.cs b/DepthsBelow/DepthsBelow/GUI/Frame.cs index d27f30e..8f511fa 100755 --- a/DepthsBelow/DepthsBelow/GUI/Frame.cs +++ b/DepthsBelow/DepthsBelow/GUI/Frame.cs @@ -31,6 +31,16 @@ namespace DepthsBelow.GUI } public Rectangle Rectangle; + public Rectangle AbsoluteRectangle + { + get + { + if (Parent != null) + return new Rectangle(Parent.Rectangle.X + Rectangle.X, Parent.Rectangle.Y + Rectangle.Y, Rectangle.Width, Rectangle.Height); + else + return Rectangle; + } + } public Texture2D Texture; public Color Color; public bool Visible = true; @@ -49,6 +59,12 @@ namespace DepthsBelow.GUI GUIManager.Add(this); } + public Frame(Frame parentFrame) + : this() + { + this.Parent = parentFrame; + } + public void Add(Frame childFrame) { childFrame.Parent = this; @@ -79,9 +95,9 @@ namespace DepthsBelow.GUI public virtual void Draw(SpriteBatch spriteBatch) { if (Visible) - { + { if (Texture != null) - spriteBatch.Draw(Texture, Rectangle, Color); + spriteBatch.Draw(Texture, AbsoluteRectangle, Color); foreach (var child in Children) child.Draw(spriteBatch); diff --git a/DepthsBelow/DepthsBelow/GUI/Text.cs b/DepthsBelow/DepthsBelow/GUI/Text.cs index e62058c..897eb3f 100755 --- a/DepthsBelow/DepthsBelow/GUI/Text.cs +++ b/DepthsBelow/DepthsBelow/GUI/Text.cs @@ -20,6 +20,11 @@ namespace DepthsBelow.GUI this.Color = Color.Black; } + public Text(Frame parent, SpriteFont font) : this(font) + { + this.Parent = parent; + } + public override void Draw(SpriteBatch spriteBatch) { base.Draw(spriteBatch); diff --git a/DepthsBelow/DepthsBelow/Interface.cs b/DepthsBelow/DepthsBelow/Interface.cs new file mode 100755 index 0000000..6e93498 --- /dev/null +++ b/DepthsBelow/DepthsBelow/Interface.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Microsoft.Xna.Framework; +using System.Diagnostics; +using Microsoft.Xna.Framework.Graphics; + +namespace DepthsBelow +{ + class Interface + { + Core core; + + public Interface(Core core) + { + this.core = core; + + // Test GUI frames + var frame = new GUI.Frame() + { + Y = 100 + }; + + var button = new GUI.Button(frame) + { + Width = 48, + Height = 23, + Texture = core.Content.Load("images/Enter"), + OnClick = delegate(Point clickPos) + { + Debug.WriteLine("That ugly button was clicked at (" + clickPos.X + "," + clickPos.Y + ")"); + } + }; + + var text = new GUI.Text(frame, core.Content.Load("Arial")); + text.Value = "Hello world!"; + } + } +} diff --git a/DepthsBelow/DepthsBelowContent/Arial.spritefont b/DepthsBelow/DepthsBelowContent/Arial.spritefont index f3cb2cc..57a4b48 100755 --- a/DepthsBelow/DepthsBelowContent/Arial.spritefont +++ b/DepthsBelow/DepthsBelowContent/Arial.spritefont @@ -11,7 +11,7 @@ with. - Berlin Sans FB + Arial