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
|
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.Apps;
using ShiftOS.Frontend.GraphicsSubsystem;
using static ShiftOS.Engine.SkinEngine;
namespace ShiftOS.Frontend.Desktop
{
public class Desktop : GUI.Control, IDesktop
{
bool alOpen = false;
int alX = 0;
int alY = 0;
public Desktop()
{
SaveSystem.GameReady += () =>
{
Show();
SetupDesktop();
};
MouseMove += (loc) =>
{
if(alOpen == true)
{
if(loc.X >= alX && loc.Y >= alY)
{
int height = LauncherItems[0].Height * LauncherItems.Count;
int width = LauncherItems[0].Width;
if(loc.X <= alX + width && loc.Y <= alY + height)
{
foreach(var item in LauncherItems)
{
if(loc.X >= alX && loc.Y >= alY + item.Y && loc.X <= alX + width && loc.Y <= alY + item.Y + item.Height)
{
alSelectedItem = LauncherItems.IndexOf(item);
Invalidate();
return;
}
}
}
else
{
alSelectedItem = -1;
Invalidate();
return;
}
}
}
};
}
public string DesktopName
{
get
{
return "ShiftOS MonoGame Desktop";
}
}
private int alSelectedItem = -1;
public void Close()
{
UIManager.StopHandling(this);
}
public Size GetSize()
{
return UIManager.Viewport;
}
public void HideAppLauncher()
{
alOpen = false;
Invalidate();
}
public void InvokeOnWorkerThread(Action act)
{
UIManager.CrossThreadOperations.Enqueue(act);
}
public void KillWindow(IWindowBorder border)
{
}
public void MaximizeWindow(IWindowBorder brdr)
{
}
public void MinimizeWindow(IWindowBorder brdr)
{
}
public void OpenAppLauncher(Point loc)
{
alX = loc.X;
alY = loc.Y;
alOpen = true;
alSelectedItem = -1;
Invalidate();
}
public void PopulateAppLauncher(LauncherItem[] items)
{
int y = 0;
int height = 0;
int[] widths = new int[items.Length];
using(var gfx = System.Drawing.Graphics.FromImage(new System.Drawing.Bitmap(1, 1)))
{
LauncherItems.Clear();
for(int i = 0; i < items.Length; i++)
{
string name = Localization.Parse(items[i].DisplayData.Name);
var measure = gfx.SmartMeasureString(name, LoadedSkin.MainFont);
if (height < (int)measure.Height)
height = (int)measure.Height;
widths[i] = 120 + (int)measure.Width;
}
int width = widths.Max();
foreach(var aitem in items)
{
var item = new AppLauncherItem
{
Data = aitem,
X = 0,
Y = y,
Height = height,
Width = width
};
LauncherItems.Add(item);
y += item.Height;
}
}
Invalidate();
}
public void PopulatePanelButtons()
{
PanelButtons.Clear();
foreach(var win in AppearanceManager.OpenForms)
{
var border = win as WindowBorder;
var pbtn = new PanelButtonData();
pbtn.Title = border.Text;
pbtn.Window = border;
PanelButtons.Add(pbtn);
}
Invalidate();
}
public void PushNotification(string app, string title, string message)
{
}
public void RestoreWindow(IWindowBorder brdr)
{
}
public void SetupDesktop()
{
Invalidate();
}
public void Show()
{
UIManager.AddTopLevel(this);
Visible = true;
Invalidate();
}
public void ShowWindow(IWindowBorder border)
{
}
private string dateTimeString = "";
protected override void OnLayout()
{
SendToBack();
X = 0;
Y = 0;
Width = GetSize().Width;
Height = GetSize().Height;
var now = DateTime.Now.TimeOfDay;
var newDateTimeString = $"{now.Hours}:{now.Minutes}:{now.Seconds}";
if(newDateTimeString != dateTimeString)
{
dateTimeString = newDateTimeString;
Invalidate();
}
}
private List<PanelButtonData> PanelButtons = new List<PanelButtonData>();
private List<AppLauncherItem> LauncherItems = new List<AppLauncherItem>();
public override void MouseStateChanged()
{
//This statement closes the app launcher. If we do this after opening it, we can't open it at all as it instantly closes.
if (alOpen == true && MouseLeftDown == true)
{
alOpen = false;
Invalidate();
return;
}
var al_left = LoadedSkin.AppLauncherFromLeft;
var al_size = LoadedSkin.AppLauncherHolderSize;
if(MouseX >= al_left.X && MouseY >= al_left.Y && MouseX <= al_left.X + al_size.Width && MouseY <= al_left.Y + al_size.Height)
{
if(alOpen == false && MouseLeftDown == true)
{
alX = 0;
if(LoadedSkin.DesktopPanelPosition == 0)
{
alY = LoadedSkin.DesktopPanelHeight;
}
else
{
alY = (Height - LoadedSkin.DesktopPanelHeight) - (LauncherItems[0].Height * LauncherItems.Count);
}
alOpen = true;
Invalidate();
}
}
}
protected override void OnPaint(GraphicsContext gfx)
{
//Let's get data for the desktop panel.
//We need the width and the height and the position.
int dp_height = LoadedSkin.DesktopPanelHeight;
int dp_position = (LoadedSkin.DesktopPanelPosition == 0) ? 0 : Height - dp_height;
int dp_width = Width;
//Alright, now we need to know if we should draw using a texture or a color
if (UIManager.SkinTextures.ContainsKey("desktoppanel"))
{
//Draw with the texture
gfx.DrawRectangle(0, dp_position, dp_width, dp_height, UIManager.SkinTextures["desktoppanel"]);
}
else
{
//draw with a color
var color = UIManager.SkinTextures["DesktopPanelColor"];
gfx.DrawRectangle(0, dp_position, dp_width, dp_height, color);
}
//Alright, now App Launcher.
var al_left = LoadedSkin.AppLauncherFromLeft;
var holderSize = LoadedSkin.AppLauncherHolderSize;
if (UIManager.SkinTextures.ContainsKey("applauncher"))
{
gfx.DrawRectangle(al_left.X, dp_position + al_left.Y, holderSize.Width, holderSize.Height, UIManager.SkinTextures["applauncher"]);
}
var altextmeasure = gfx.MeasureString(LoadedSkin.AppLauncherText, LoadedSkin.AppLauncherFont);
int altextx = (holderSize.Width - (int)altextmeasure.X) / 2;
int altexty = (holderSize.Height - (int)altextmeasure.Y) / 2;
gfx.DrawString(LoadedSkin.AppLauncherText, altextx, altexty, LoadedSkin.AppLauncherTextColor.ToMonoColor(), LoadedSkin.AppLauncherFont);
//Panel clock.
var panelClockRight = LoadedSkin.DesktopPanelClockFromRight;
var panelClockTextColor = LoadedSkin.DesktopPanelClockColor.ToMonoColor();
var measure = gfx.MeasureString(dateTimeString, LoadedSkin.DesktopPanelClockFont);
int panelclockleft = Width - (int)measure.X;
int panelclockwidth = Width - panelclockleft;
if (UIManager.SkinTextures.ContainsKey("panelclockbg"))
{
//draw the background using panelclock texture
gfx.DrawRectangle(panelclockleft, dp_position, panelclockwidth, dp_height, UIManager.SkinTextures["panelclockbg"]);
}
else
{
//draw using the bg color
var pcBGColor = UIManager.SkinTextures["DesktopPanelClockBackgroundColor"];
gfx.DrawRectangle(panelclockleft, dp_position, panelclockwidth, dp_height, pcBGColor);
}
int text_left = (panelclockwidth - (int)measure.X) / 2;
int text_top = (dp_height - (int)measure.Y) / 2;
//draw string
gfx.DrawString(dateTimeString, panelclockleft + text_left, dp_position + text_top, panelClockTextColor, LoadedSkin.DesktopPanelClockFont);
int initialGap = LoadedSkin.PanelButtonHolderFromLeft;
int offset = initialGap;
foreach(var pbtn in PanelButtons)
{
offset += LoadedSkin.PanelButtonFromLeft.X;
int pbtnfromtop = LoadedSkin.PanelButtonFromTop;
int pbtnwidth = LoadedSkin.PanelButtonSize.Width;
int pbtnheight = LoadedSkin.PanelButtonSize.Height;
//Draw panel button background...
if (UIManager.SkinTextures.ContainsKey("panelbutton"))
{
gfx.DrawRectangle(offset, dp_position + pbtnfromtop, pbtnwidth, pbtnheight, UIManager.SkinTextures["panelbutton"]);
}
else
{
gfx.DrawRectangle(offset, dp_position + pbtnfromtop, pbtnwidth, pbtnheight, UIManager.SkinTextures["PanelButtonColor"]);
}
//now we draw the text
gfx.DrawString(pbtn.Title, offset + 2, dp_position + pbtnfromtop + 2, LoadedSkin.PanelButtonTextColor.ToMonoColor(), LoadedSkin.PanelButtonFont);
offset += LoadedSkin.PanelButtonSize.Width;
}
if (alOpen)
{
int height = LauncherItems[0].Height * LauncherItems.Count;
int width = LauncherItems[0].Width;
gfx.DrawRectangle(alX, alY, width, height, UIManager.SkinTextures["Menu_ToolStripDropDownBackground"]);
foreach(var item in LauncherItems)
{
if(LauncherItems.IndexOf(item) == alSelectedItem)
{
gfx.DrawRectangle(alX, alY + item.Y, item.Width, item.Y, UIManager.SkinTextures["Menu_MenuItemSelected"]);
}
gfx.DrawString(Localization.Parse(item.Data.DisplayData.Name), alX + 20, alY + item.Y, LoadedSkin.Menu_TextColor.ToMonoColor(), LoadedSkin.MainFont);
}
}
}
}
public class PanelButtonData
{
public string Title { get; set; }
public WindowBorder Window { get; set; }
public bool IsActive
{
get
{
return Window.IsFocusedControl || Window.ContainsFocusedControl;
}
}
}
public class AppLauncherItem
{
public Engine.LauncherItem Data { get; set; }
public int X { get; set; }
public int Y { get; set; }
public int Width { get; set; }
public int Height { get; set; }
}
}
|