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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
|
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ShiftOS.Engine;
using ShiftOS.Frontend.GraphicsSubsystem;
using static ShiftOS.Engine.SkinEngine;
namespace ShiftOS.Frontend.Desktop
{
public class WindowManager : Engine.WindowManager
{
public override void Close(IShiftOSWindow win)
{
var brdr = RunningBorders.FirstOrDefault(x => x.ParentWindow == win);
if (brdr != null)
{
brdr.Close();
win = null;
}
}
private List<WindowBorder> RunningBorders = new List<WindowBorder>();
public override void InvokeAction(Action act)
{
act?.Invoke();
}
public override void Maximize(IWindowBorder border)
{
throw new NotImplementedException();
}
public override void Minimize(IWindowBorder border)
{
throw new NotImplementedException();
}
public override void SetTitle(IShiftOSWindow win, string title)
{
var brdr = RunningBorders.FirstOrDefault(x => x.ParentWindow == win);
if (brdr != null)
brdr.Text = title;
}
public override void SetupDialog(IShiftOSWindow win)
{
var wb = new WindowBorder();
wb.Width = (win as GUI.Control).Width + LoadedSkin.LeftBorderWidth + LoadedSkin.RightBorderWidth;
wb.Height = (win as GUI.Control).Height + LoadedSkin.TitlebarHeight + LoadedSkin.BottomBorderWidth;
wb.ParentWindow = win;
wb.IsDialog = true;
UIManager.AddTopLevel(wb);
RunningBorders.Add(wb);
win.OnLoad();
win.OnUpgrade();
win.OnSkinLoad();
}
public override void SetupWindow(IShiftOSWindow win)
{
if (!Shiftorium.UpgradeAttributesUnlocked(win.GetType()))
{
Console.WriteLine("Application not found on system.");
return;
}
var wb = new WindowBorder();
wb.Width = (win as GUI.Control).Width + LoadedSkin.LeftBorderWidth + LoadedSkin.RightBorderWidth;
wb.Height = (win as GUI.Control).Height + LoadedSkin.TitlebarHeight + LoadedSkin.BottomBorderWidth;
wb.ParentWindow = win;
wb.IsDialog = true;
UIManager.AddTopLevel(wb);
AppearanceManager.OpenForms.Add(wb);
RunningBorders.Add(wb);
win.OnLoad();
win.OnUpgrade();
win.OnSkinLoad();
}
}
public class WindowBorder : GUI.Control, IWindowBorder
{
private string _text = "ShiftOS window";
private GUI.Control _hostedwindow = null;
public WindowBorder()
{
X = 720;
Y = 480;
}
public IShiftOSWindow ParentWindow
{
get
{
return (IShiftOSWindow)_hostedwindow;
}
set
{
_hostedwindow = (GUI.Control)value;
ClearControls();
AddControl(_hostedwindow);
Width = (LoadedSkin.LeftBorderWidth*2) + _hostedwindow.Width + LoadedSkin.RightBorderWidth;
Height = LoadedSkin.BottomBorderWidth + _hostedwindow.Height + (LoadedSkin.TitlebarHeight*2);
}
}
public bool IsDialog { get; set; }
public string Text
{
get
{
return _text;
}
set
{
_text = value;
}
}
public void Close()
{
Visible = false;
UIManager.StopHandling(this);
}
private int lastmousex, lastmousey = 0;
protected override void OnLayout()
{
if (moving)
{
var screenpoint = PointToScreen(MouseX, MouseY);
this.X = lastmousex + screenpoint.X;
this.Y = lastmousey + screenpoint.Y;
}
int titlebarheight = Shiftorium.UpgradeInstalled("wm_titlebar") ? LoadedSkin.TitlebarHeight : 0;
int borderleft = Shiftorium.UpgradeInstalled("window_borders") ? LoadedSkin.LeftBorderWidth : 0;
int borderright = Shiftorium.UpgradeInstalled("window_borders") ? LoadedSkin.RightBorderWidth : 0;
int borderbottom = Shiftorium.UpgradeInstalled("window_borders") ? LoadedSkin.BottomBorderWidth : 0;
_hostedwindow.X = borderleft;
_hostedwindow.Y = titlebarheight;
}
private bool moving = false;
public override void MouseStateChanged()
{
if (Shiftorium.UpgradeInstalled("wm_titlebar"))
{
if (Shiftorium.UpgradeInstalled("close_button"))
{
var closebuttonsize = LoadedSkin.CloseButtonSize;
var closebuttonloc = LoadedSkin.CloseButtonFromSide;
if (LoadedSkin.TitleButtonPosition == 0)
closebuttonloc = new Point(Width - closebuttonsize.Width - closebuttonloc.X, closebuttonloc.Y);
if(MouseX > closebuttonloc.X && MouseY > closebuttonloc.Y && MouseX < closebuttonloc.X + closebuttonsize.Width && MouseY < closebuttonloc.Y + closebuttonsize.Height)
{
Close();
}
}
if (Shiftorium.UpgradeInstalled("minimize_button"))
{
var closebuttonsize = LoadedSkin.MinimizeButtonSize;
var closebuttonloc = LoadedSkin.MinimizeButtonFromSide;
if (LoadedSkin.TitleButtonPosition == 0)
closebuttonloc = new Point(Width - closebuttonsize.Width - closebuttonloc.X, closebuttonloc.Y);
if (MouseX > closebuttonloc.X && MouseY > closebuttonloc.Y && MouseX < closebuttonloc.X + closebuttonsize.Width && MouseY < closebuttonloc.Y + closebuttonsize.Height)
{
if (IsFocusedControl || ContainsFocusedControl)
UIManager.FocusedControl = null;
Visible = false;
}
}
if (Shiftorium.UpgradeInstalled("maximize_button"))
{
var closebuttonsize = LoadedSkin.MaximizeButtonSize;
var closebuttonloc = LoadedSkin.MaximizeButtonFromSide;
if (LoadedSkin.TitleButtonPosition == 0)
closebuttonloc = new Point(Width - closebuttonsize.Width - closebuttonloc.X, closebuttonloc.Y);
if (MouseX > closebuttonloc.X && MouseY > closebuttonloc.Y && MouseX < closebuttonloc.X + closebuttonsize.Width && MouseY < closebuttonloc.Y + closebuttonsize.Height)
{
AppearanceManager.Maximize(this);
}
}
if (MouseY < LoadedSkin.TitlebarHeight)
{
var screenpoint = PointToScreen(MouseX, MouseY);
lastmousex = this.X - screenpoint.X;
lastmousey = this.Y - screenpoint.Y;
moving = MouseLeftDown;
CaptureMouse = moving;
}
}
}
protected override void OnPaint(Graphics gfx)
{
int titleheight = LoadedSkin.TitlebarHeight;
int leftborderwidth = LoadedSkin.LeftBorderWidth;
int rightborderwidth = LoadedSkin.RightBorderWidth;
int bottomborderwidth = LoadedSkin.BottomBorderWidth;
if (Shiftorium.UpgradeInstalled("wm_titlebar"))
{
var titlebarcolor = LoadedSkin.TitleBackgroundColor;
var titlefont = LoadedSkin.TitleFont;
var titletextcolor = LoadedSkin.TitleTextColor;
var titletextleft = LoadedSkin.TitleTextLeft;
bool titletextcentered = LoadedSkin.TitleTextCentered;
var titlebarbg = GetImage("titlebar");
var titlebarlayout = GetImageLayout("titlebar");
var drawcorners = LoadedSkin.ShowTitleCorners;
int titlebarleft = 0;
int titlebarwidth = Width;
if (drawcorners)
{
//set titleleft to the first corner width
titlebarleft = LoadedSkin.TitleLeftCornerWidth;
titlebarwidth -= titlebarleft;
titlebarwidth -= LoadedSkin.TitleRightCornerWidth;
//Let's get the left and right images.
var leftimage = GetImage("titlebarleft");
var rightimage = GetImage("titlebarright");
//and the colors
var leftcolor = LoadedSkin.TitleLeftCornerBackground;
var rightcolor = LoadedSkin.TitleRightCornerBackground;
//and the layouts...
var leftlayout = GetImageLayout("titlebarleft");
var rightlayout = GetImageLayout("titlebarright");
//and the widths
var leftwidth = LoadedSkin.TitleLeftCornerWidth;
var rightwidth = LoadedSkin.TitleRightCornerWidth;
//draw left corner
if(leftimage != null)
{
var resized = ResizeImage(leftimage, leftwidth, titleheight);
gfx.DrawImage(resized, 0, 0);
}
else
{
gfx.FillRectangle(new SolidBrush(leftcolor), new Rectangle(0, 0, leftwidth, titleheight));
}
//draw right corner
if (rightimage != null)
{
var resized = ResizeImage(rightimage, rightwidth, titleheight);
gfx.DrawImage(resized, titlebarleft+titlebarwidth, 0);
}
else
{
gfx.FillRectangle(new SolidBrush(rightcolor), new Rectangle(titlebarleft+titlebarwidth, 0, rightwidth, titleheight));
}
}
if (titlebarbg == null)
{
//draw the title bg
gfx.FillRectangle(new SolidBrush(titlebarcolor), new Rectangle(titlebarleft, 0, titlebarwidth, titleheight));
}
else
{
var resized = ResizeImage(titlebarbg, titlebarwidth, titleheight);
gfx.DrawImage(resized, titlebarleft, 0);
}
//Now we draw the title text.
var textMeasure = gfx.MeasureString(_text, titlefont);
PointF textloc;
if (titletextcentered)
textloc = new PointF((titlebarwidth - textMeasure.Width) / 2,
titletextleft.Y);
else
textloc = new PointF(titlebarleft + titletextleft.X, titletextleft.Y);
gfx.DrawString(_text, titlefont, new SolidBrush(titletextcolor), textloc);
var tbuttonpos = LoadedSkin.TitleButtonPosition;
//Draw close button
if(Shiftorium.UpgradeInstalled("close_button"))
{
var closebuttoncolor = LoadedSkin.CloseButtonColor;
var closebuttonsize = LoadedSkin.CloseButtonSize;
var closebuttonright = LoadedSkin.CloseButtonFromSide;
if (LoadedSkin.TitleButtonPosition == 0)
closebuttonright = new Point(Width - closebuttonsize.Width - closebuttonright.X, closebuttonright.Y);
gfx.FillRectangle(new SolidBrush(closebuttoncolor), new Rectangle(closebuttonright, closebuttonsize));
}
//Draw maximize button
if (Shiftorium.UpgradeInstalled("maximize_button"))
{
var closebuttoncolor = LoadedSkin.MaximizeButtonColor;
var closebuttonsize = LoadedSkin.MaximizeButtonSize;
var closebuttonright = LoadedSkin.MaximizeButtonFromSide;
if (LoadedSkin.TitleButtonPosition == 0)
closebuttonright = new Point(Width - closebuttonsize.Width - closebuttonright.X, closebuttonright.Y);
gfx.FillRectangle(new SolidBrush(closebuttoncolor), new Rectangle(closebuttonright, closebuttonsize));
}
//Draw minimize button
if (Shiftorium.UpgradeInstalled("minimize_button"))
{
var closebuttoncolor = LoadedSkin.MinimizeButtonColor;
var closebuttonsize = LoadedSkin.MinimizeButtonSize;
var closebuttonright = LoadedSkin.MinimizeButtonFromSide;
if (LoadedSkin.TitleButtonPosition == 0)
closebuttonright = new Point(Width - closebuttonsize.Width - closebuttonright.X, closebuttonright.Y);
gfx.FillRectangle(new SolidBrush(closebuttoncolor), new Rectangle(closebuttonright, closebuttonsize));
}
}
else
{
//Set the titleheight to 0.
titleheight = 0;
}
if (Shiftorium.UpgradeInstalled("window_borders"))
{
//Some variables we'll need...
int bottomlocy = Height - LoadedSkin.BottomBorderWidth;
int bottomlocx = leftborderwidth;
int bottomwidth = Width - bottomlocx - rightborderwidth;
int brightlocx = Width - rightborderwidth;
var borderleftcolor = (ContainsFocusedControl || IsFocusedControl) ? LoadedSkin.BorderLeftBackground : LoadedSkin.BorderInactiveLeftBackground;
var borderrightcolor = (ContainsFocusedControl || IsFocusedControl) ? LoadedSkin.BorderRightBackground : LoadedSkin.BorderInactiveRightBackground;
var borderbottomcolor = (ContainsFocusedControl || IsFocusedControl) ? LoadedSkin.BorderBottomBackground : LoadedSkin.BorderInactiveBottomBackground;
var borderbleftcolor = (ContainsFocusedControl || IsFocusedControl) ? LoadedSkin.BorderBottomLeftBackground : LoadedSkin.BorderInactiveBottomLeftBackground;
var borderbrightcolor = (ContainsFocusedControl || IsFocusedControl) ? LoadedSkin.BorderBottomRightBackground : LoadedSkin.BorderInactiveBottomRightBackground;
//draw border corners
//BOTTOM LEFT
gfx.FillRectangle(new SolidBrush(borderbleftcolor), new Rectangle(0, bottomlocy, leftborderwidth, bottomborderwidth));
//BOTTOM RIGHT
gfx.FillRectangle(new SolidBrush(borderbrightcolor), new Rectangle(brightlocx, bottomlocy, rightborderwidth, bottomborderwidth));
//BOTTOM
gfx.FillRectangle(new SolidBrush(borderbottomcolor), new Rectangle(bottomlocx, bottomlocy, bottomwidth, bottomborderwidth));
//LEFT
gfx.FillRectangle(new SolidBrush(borderleftcolor), new Rectangle(0, titleheight, leftborderwidth, Height - titleheight - bottomborderwidth));
//RIGHT
gfx.FillRectangle(new SolidBrush(borderrightcolor), new Rectangle(brightlocx, titleheight, rightborderwidth, Height - titleheight - bottomborderwidth));
}
//So here's what we're gonna do now.
//Now that we have a titlebar and window borders...
//We're going to composite the hosted window
//and draw it to the remaining area.
//Painting of the canvas is done by the Paint() method.
}
}
}
|