From 75bdbe50aff36405a56422783c4ef84f951f4dc6 Mon Sep 17 00:00:00 2001 From: jpbruyere Date: Tue, 15 Sep 2015 11:30:06 +0200 Subject: [PATCH] Templated Groupbox --- GOLib.csproj | 3 +- Templates/Groupbox.goml | 10 ++ Tests/Interfaces/testBorder.goml | 7 ++ Tests/Interfaces/testGroupBox.goml | 9 ++ Tests/Interfaces/testWindow.goml | 4 +- src/GraphicObjects/Border.cs | 1 + src/GraphicObjects/GroupBox.cs | 153 ----------------------------- src/GraphicObjects/Groupbox.cs | 68 +++++++++++++ 8 files changed, 99 insertions(+), 156 deletions(-) create mode 100755 Templates/Groupbox.goml create mode 100755 Tests/Interfaces/testBorder.goml create mode 100755 Tests/Interfaces/testGroupBox.goml delete mode 100644 src/GraphicObjects/GroupBox.cs create mode 100644 src/GraphicObjects/Groupbox.cs diff --git a/GOLib.csproj b/GOLib.csproj index 4fac6677..8fcc21bb 100644 --- a/GOLib.csproj +++ b/GOLib.csproj @@ -64,7 +64,6 @@ - @@ -119,6 +118,7 @@ + @@ -197,6 +197,7 @@ + diff --git a/Templates/Groupbox.goml b/Templates/Groupbox.goml new file mode 100755 index 00000000..d804aab8 --- /dev/null +++ b/Templates/Groupbox.goml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/Tests/Interfaces/testBorder.goml b/Tests/Interfaces/testBorder.goml new file mode 100755 index 00000000..15ecba3a --- /dev/null +++ b/Tests/Interfaces/testBorder.goml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Tests/Interfaces/testGroupBox.goml b/Tests/Interfaces/testGroupBox.goml new file mode 100755 index 00000000..712a485f --- /dev/null +++ b/Tests/Interfaces/testGroupBox.goml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/Tests/Interfaces/testWindow.goml b/Tests/Interfaces/testWindow.goml index 1f5cf4e4..740cfc53 100755 --- a/Tests/Interfaces/testWindow.goml +++ b/Tests/Interfaces/testWindow.goml @@ -10,13 +10,13 @@ - + - + diff --git a/src/GraphicObjects/Border.cs b/src/GraphicObjects/Border.cs index 1bc2b729..84adfc0a 100644 --- a/src/GraphicObjects/Border.cs +++ b/src/GraphicObjects/Border.cs @@ -1,6 +1,7 @@ using System; using System.Xml.Serialization; using System.ComponentModel; +using System.Diagnostics; namespace go { diff --git a/src/GraphicObjects/GroupBox.cs b/src/GraphicObjects/GroupBox.cs deleted file mode 100644 index a9c3cc1c..00000000 --- a/src/GraphicObjects/GroupBox.cs +++ /dev/null @@ -1,153 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Text; -using System.Xml.Serialization; -using Cairo; - -namespace go -{ - - public class GroupBox : Border - { - #region CTOR - public GroupBox() : base (){ - } - public GroupBox(string _title = "GroupBox") - : base() - { - Text = _title; - } - #endregion - - #region private fields - string _title; - Font _font; - #endregion - - #region public properties - [XmlAttributeAttribute][DefaultValue("GroupBox")] - public string Text - { - get { return _title; } - set - { - _title = value; - NotifyValueChanged ("Text", _title); - registerForGraphicUpdate(); - } - } - #endregion - - Size titleSize { - get { -#if _WIN32 || _WIN64 - byte[] txt = System.Text.UTF8Encoding.UTF8.GetBytes(_title); -#endif - - Size s; - - using (ImageSurface img = new ImageSurface (Format.Argb32, 1, 1)) { - using (Context gr = new Context (img)) { - gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight); - gr.SetFontSize (Font.Size); - TextExtents te; -#if _WIN32 || _WIN64 - te = gr.TextExtents(txt); -#elif __linux__ - te = gr.TextExtents (Text); -#endif - FontExtents fe = gr.FontExtents; - s = new Size ((int)Math.Ceiling (te.XAdvance), (int)Math.Ceiling (fe.Height)); - } - } - return s;// +borderWidth; - } - } - - #region GraphicObject overrides - public override Rectangle ClientRectangle { - get { - Size ts = titleSize; - Rectangle cb = Slot.Size; - cb.Y = ts.Height; - cb.Height -= ts.Height; - cb.Inflate ( - Margin); - return cb; - } - } - protected override Size measureRawSize () - { - Size raw = base.measureRawSize (); - return raw > 0 ? raw + titleSize : raw; - } - protected override void onDraw (Context gr) - { - //base.onDraw (gr); - - byte[] txt = System.Text.UTF8Encoding.UTF8.GetBytes(Text); - Rectangle r = new Rectangle(Slot.Size); - if (BorderWidth > 0) - r.Inflate (-BorderWidth / 2); - - //gr.Rotate(Math.PI); - gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight); - gr.SetFontSize (Font.Size); - FontExtents fe = gr.FontExtents; - TextExtents te = gr.TextExtents(Text); - - gr.Antialias = Antialias.Subpixel; - gr.LineWidth = BorderWidth; - gr.Color = Background; - - - - Rectangle rTitle = r; - - int th = (int)Math.Ceiling(fe.Height / 2); - r.Y += th; - r.Height -= th; - - CairoHelpers.CairoRectangle (gr, r, CornerRadius); - gr.Fill(); - - const int titleGap = 5; - - if (BorderWidth > 0) - { - gr.Color = BorderColor; - - rTitle.X = r.X + titleGap; - rTitle.Width = (int)Math.Ceiling(te.XAdvance) + 2 * titleGap; - rTitle.Height = (int)Math.Ceiling(fe.Height); - gr.Save(); - gr.FillRule = FillRule.EvenOdd; - gr.Rectangle(new Rectangle(Slot.Size)); - gr.Rectangle(rTitle); - gr.Clip(); - - CairoHelpers.CairoRectangle (gr, r, CornerRadius); - - gr.Stroke(); - gr.Restore(); - } - - gr.MoveTo(rTitle.X + titleGap, rTitle.Y + (int)Math.Ceiling(fe.Height - fe.Descent)); - - #if _WIN32 || _WIN64 - gr.ShowText(txt); - #elif __linux__ - gr.ShowText(Text); - #endif - gr.Color = Foreground; - gr.Fill(); - } - #endregion - - public override string ToString() - { - return base.ToString() + ": " + this.Text; - } - } -} - diff --git a/src/GraphicObjects/Groupbox.cs b/src/GraphicObjects/Groupbox.cs new file mode 100644 index 00000000..60c2dd08 --- /dev/null +++ b/src/GraphicObjects/Groupbox.cs @@ -0,0 +1,68 @@ +using System; + + +using System.Collections.Generic; +using System.Linq; +using System.Text; +//using OpenTK.Graphics.OpenGL; + +using Cairo; + +using winColors = System.Drawing.Color; +using System.Diagnostics; +using System.Xml.Serialization; +using OpenTK.Input; +using System.ComponentModel; +using System.Xml; +using System.IO; + +namespace go +{ + [DefaultTemplate("#go.Templates.Groupbox.goml")] + public class Groupbox : TemplatedContainer + { + string title; + Container _contentContainer; + + #region CTOR + public Groupbox() : base(){} + #endregion + + #region Template overrides + public override GraphicObject Content { + get { + return _contentContainer == null ? null : _contentContainer.Child; + } + set { + _contentContainer.SetChild(value); + } + } + protected override void loadTemplate(GraphicObject template = null) + { + base.loadTemplate (template); + + _contentContainer = this.child.FindByName ("Content") as Container; + } + #endregion + + #region GraphicObject overrides + [XmlAttributeAttribute()][DefaultValue(true)]//overiden to get default to true + public override bool Focusable + { + get { return base.Focusable; } + set { base.Focusable = value; } + } + #endregion + + [XmlAttributeAttribute()][DefaultValue("Groupbox")] + public string Title { + get { return title; } + set { + if (title == value) + return; + title = value; + NotifyValueChanged ("Title", title); + } + } + } +} -- 2.47.3