1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
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;
registerForGraphicUpdate();
}
}
[XmlAttributeAttribute()][DefaultValue("droid,12")]
public Font Font {
get { return _font; }
set { _font = value; }
}
#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;
}
}
}
|