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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
|
using System;
using System.Xml.Serialization;
using System.ComponentModel;
using System.Diagnostics;
namespace Crow
{
[DefaultStyle("#Crow.Styles.Window.style")]
[DefaultTemplate("#Crow.Templates.Window.goml")]
public class Window : TemplatedContainer
{
enum Direction
{
None,
N,
S,
E,
W,
NW,
NE,
SW,
SE,
}
string _title;
string _icon;
bool _resizable;
Container _contentContainer;
Direction currentDirection = Direction.None;
#region CTOR
public Window () : base() {
}
#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
public override GraphicObject Content {
get {
return _contentContainer == null ? null : _contentContainer.Child;
}
set {
_contentContainer.SetChild(value);
}
}
[XmlAttributeAttribute()][DefaultValue("Window")]
public string Title {
get { return _title; }
set {
_title = value;
NotifyValueChanged ("Title", _title);
}
}
[XmlAttributeAttribute()][DefaultValue("#Crow.Images.Icons.tetra.png")]
public string Icon {
get { return _icon; }
set {
_icon = value;
NotifyValueChanged ("Icon", _icon);
}
}
[XmlAttributeAttribute()][DefaultValue(true)]
public bool Resizable {
get {
return _resizable;
}
set {
_resizable = value;
NotifyValueChanged ("Resizable", _resizable);
}
}
public override void onMouseMove (object sender, MouseMoveEventArgs e)
{
base.onMouseMove (sender, e);
Interface otkgw = Interface.CurrentInterface;
if (e.Mouse.IsButtonDown (MouseButton.Left)) {
if (!HasFocus)
return;
//otkgw.redrawClip.AddRectangle (this.ScreenCoordinates(this.Slot));
int currentLeft = this.Left;
int currentTop = this.Top;
if (currentLeft == 0)
currentLeft = this.Slot.Left;
if (currentTop == 0)
currentTop = this.Slot.Top;
switch (currentDirection) {
case Direction.None:
this.Left = currentLeft + e.XDelta;
this.Top = currentTop + e.YDelta;
break;
case Direction.N:
this.Top = currentTop + e.YDelta;
this.Height -= e.YDelta;
break;
case Direction.S:
this.Height += e.YDelta;
break;
case Direction.W:
this.Left = currentLeft + e.XDelta;
this.Width -= e.XDelta;
break;
case Direction.E:
this.Width += e.XDelta;
break;
case Direction.NW:
this.Left = currentLeft + e.XDelta;
this.Top = currentTop + e.YDelta;
this.Width -= e.XDelta;
this.Height -= e.YDelta;
break;
case Direction.NE:
this.Width += e.XDelta;
this.Top = currentTop + e.YDelta;
this.Height -= e.YDelta;
break;
case Direction.SW:
this.Left = currentLeft + e.XDelta;
this.Width -= e.XDelta;
this.Height += e.YDelta;
break;
case Direction.SE:
this.Width += e.XDelta;
this.Height += e.YDelta;
break;
}
return;
}
GraphicObject firstFocusableAncestor = otkgw.hoverWidget;
while (firstFocusableAncestor != this) {
if (firstFocusableAncestor == null)
return;
if (firstFocusableAncestor.Focusable)
return;
firstFocusableAncestor = firstFocusableAncestor.Parent as GraphicObject;
}
if (Resizable) {
Direction lastDir = currentDirection;
if (Math.Abs (e.Position.Y - this.Slot.Y) < Interface.BorderThreshold) {
if (Math.Abs (e.Position.X - this.Slot.X) < Interface.BorderThreshold)
currentDirection = Direction.NW;
else if (Math.Abs (e.Position.X - this.Slot.Right) < Interface.BorderThreshold)
currentDirection = Direction.NE;
else
currentDirection = Direction.N;
} else if (Math.Abs (e.Position.Y - this.Slot.Bottom) < Interface.BorderThreshold) {
if (Math.Abs (e.Position.X - this.Slot.X) < Interface.BorderThreshold)
currentDirection = Direction.SW;
else if (Math.Abs (e.Position.X - this.Slot.Right) < Interface.BorderThreshold)
currentDirection = Direction.SE;
else
currentDirection = Direction.S;
} else if (Math.Abs (e.Position.X - this.Slot.X) < Interface.BorderThreshold)
currentDirection = Direction.W;
else if (Math.Abs (e.Position.X - this.Slot.Right) < Interface.BorderThreshold)
currentDirection = Direction.E;
else
currentDirection = Direction.None;
if (currentDirection != lastDir) {
switch (currentDirection) {
case Direction.None:
otkgw.MouseCursor = XCursor.Default;
break;
case Direction.N:
otkgw.MouseCursor = XCursor.V;
break;
case Direction.S:
otkgw.MouseCursor = XCursor.V;
break;
case Direction.E:
otkgw.MouseCursor = XCursor.H;
break;
case Direction.W:
otkgw.MouseCursor = XCursor.H;
break;
case Direction.NW:
otkgw.MouseCursor = XCursor.NW;
break;
case Direction.NE:
otkgw.MouseCursor = XCursor.NE;
break;
case Direction.SW:
otkgw.MouseCursor = XCursor.SW;
break;
case Direction.SE:
otkgw.MouseCursor = XCursor.SE;
break;
}
}
}
}
public override void onMouseLeave (object sender, MouseMoveEventArgs e)
{
base.onMouseLeave (sender, e);
currentDirection = Direction.None;
Interface.CurrentInterface.MouseCursor = XCursor.Default;
}
protected override void loadTemplate(GraphicObject template = null)
{
base.loadTemplate (template);
_contentContainer = this.child.FindByName ("Content") as Container;
}
protected void butQuitPress (object sender, MouseButtonEventArgs e)
{
ILayoutable parent = (sender as GraphicObject).Parent;
while(!(parent is Window))
parent = parent.Parent;
Interface.CurrentInterface.DeleteWidget (parent as GraphicObject);
}
public override void ResolveBindings ()
{
base.ResolveBindings ();
if (Content != null)
Content.ResolveBindings ();
}
}
}
|