diff options
| author | jpbruyere <jp.bruyere@hotmail.com> | 2015-09-15 11:30:06 +0200 |
|---|---|---|
| committer | jpbruyere <jp.bruyere@hotmail.com> | 2015-09-15 11:30:06 +0200 |
| commit | 75bdbe50aff36405a56422783c4ef84f951f4dc6 (patch) | |
| tree | 1528a6f8c5705bc849001d21c4e75aa8fa95be2a /src | |
| parent | 8d543b42826995b35fdf8416e3a19fb4d3a0aa11 (diff) | |
Templated Groupbox
Diffstat (limited to 'src')
| -rw-r--r-- | src/GraphicObjects/Border.cs | 1 | ||||
| -rw-r--r-- | src/GraphicObjects/GroupBox.cs | 153 | ||||
| -rw-r--r-- | src/GraphicObjects/Groupbox.cs | 68 |
3 files changed, 69 insertions, 153 deletions
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);
+ }
+ }
+ }
+}
|