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
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Threading;
using ShiftOS.Engine;
using static ShiftOS.Engine.SkinEngine;
namespace ShiftOS.Wpf
{
public static class ShiftOSSkin
{
public static Brush GetAppButtonHoverBrush(DependencyObject obj)
{
return (Brush)obj.GetValue(AppButtonHoverBrushProperty);
}
public static void SetAppButtonHoverBrush(DependencyObject obj, Brush value)
{
obj.SetValue(AppButtonHoverBrushProperty, value);
}
public static readonly DependencyProperty AppButtonHoverBrushProperty =
DependencyProperty.RegisterAttached(
"AppButtonHoverBrush",
typeof(Brush),
typeof(ShiftOSSkin),
new FrameworkPropertyMetadata(LoadedSkin.Menu_MenuItemSelected.CreateBrush()));
}
public static class Startup
{
private static Visibility getVisibility(string upg)
{
if (Shiftorium.UpgradeInstalled(upg))
{
return Visibility.Visible;
}
else
{
return Visibility.Collapsed;
}
}
public static void Upgrade(this Control ctrl, string upg)
{
ctrl.Visibility = getVisibility(upg);
}
public static void Upgrade(this UIElement ctrl, string upg)
{
ctrl.Visibility = getVisibility(upg);
}
static public void BringToFront(this UserControl pToMove, Canvas pParent)
{
int currentIndex = Canvas.GetZIndex(pToMove);
int zIndex = 0;
int maxZ = 0;
UserControl child;
for (int i = 0; i < pParent.Children.Count; i++)
{
if (pParent.Children[i] is UserControl &&
pParent.Children[i] != pToMove)
{
child = pParent.Children[i] as UserControl;
zIndex = Canvas.GetZIndex(child);
maxZ = Math.Max(maxZ, zIndex);
if (zIndex > currentIndex)
{
Canvas.SetZIndex(child, zIndex - 1);
}
}
}
Canvas.SetZIndex(pToMove, maxZ);
}
public static void SetTitle(this IShiftOSWindow win, string title)
{
foreach(var frm in AppearanceManager.OpenForms)
{
if(frm.ParentWindow == win)
{
frm.Text = title;
}
}
}
public static void InitiateEngine(System.IO.TextWriter writer)
{
OutOfBoxExperience.Init(new OOBE());
AppearanceManager.Initiate(new WpfWindowManager());
Infobox.Init(new WpfInfoboxFrontend());
FileSkimmerBackend.Init(new Applications.WpfFSFrontend());
if (writer != null)
{
Console.SetOut(writer);
}
SaveSystem.Begin(false);
AppearanceManager.OnExit += () =>
{
Environment.Exit(0);
};
}
public static void SetMouseOverStyle(this Control button, string style = "")
{
var bg = button.Background;
var fg = button.Foreground;
var border = button.BorderThickness;
var borderfg = button.BorderBrush;
button.MouseEnter += (o, a) =>
{
try
{
switch (style)
{
case "menuitem":
button.Background = LoadedSkin.Menu_MenuItemSelected.CreateBrush();
button.Foreground = LoadedSkin.Menu_SelectedTextColor.CreateBrush();
button.BorderBrush = LoadedSkin.Menu_MenuItemBorder.CreateBrush();
break;
}
}
catch { }
};
button.MouseLeave += (o, a) =>
{
try
{
button.Background = bg;
button.Foreground = fg;
button.BorderThickness = border;
button.BorderBrush = borderfg;
}
catch
{
}
};
}
public static void DestroyShiftOSEngine()
{
ServerManager.Disconnect();
}
public static TextBox ConsoleOut { get; set; }
public static SolidColorBrush CreateBrush(this System.Drawing.Color color)
{
return new SolidColorBrush(Color.FromArgb(color.A, color.R, color.G, color.B));
}
public struct Font
{
public FontFamily FontFamily { get; set; }
public double FontSize { get; set; }
public FontStyle FontStyle { get; set; }
public FontWeight FontWeight { get; set; }
}
private static Font createFont(System.Drawing.Font f)
{
var font = new Font();
font.FontFamily = new FontFamily(f.Name);
font.FontSize = f.Size;
switch (f.Style)
{
case System.Drawing.FontStyle.Bold:
font.FontWeight = FontWeights.Bold;
break;
case System.Drawing.FontStyle.Italic:
font.FontStyle = FontStyles.Oblique;
break;
default:
case System.Drawing.FontStyle.Regular:
font.FontStyle = FontStyles.Normal;
break;
}
return font;
}
public static void SetFont(this Control ctrl, System.Drawing.Font f)
{
var font = createFont(f);
ctrl.FontFamily = font.FontFamily;
ctrl.FontSize = PointsToPixels(font.FontSize);
ctrl.FontStyle = font.FontStyle;
ctrl.FontWeight = font.FontWeight;
}
private static double PointsToPixels(double points)
{
return points * (96.0 / 72.0);
}
public static void SetFont(this TextBlock ui, System.Drawing.Font f)
{
var font = createFont(f);
ui.FontFamily = font.FontFamily;
ui.FontSize = PointsToPixels(font.FontSize);
ui.FontStyle = font.FontStyle;
ui.FontWeight = font.FontWeight;
}
public static BitmapImage ToBitmapImage(this System.Drawing.Image img)
{
using(var str = new MemoryStream())
{
img.Save(str, System.Drawing.Imaging.ImageFormat.Png);
return ToBitmapImage(str.ToArray());
}
}
public static BitmapImage ToBitmapImage(this byte[] imgSource)
{
using(MemoryStream ms = new MemoryStream(imgSource))
{
var img = new BitmapImage();
img.BeginInit();
img.StreamSource = ms;
img.CacheOption = BitmapCacheOption.OnLoad;
img.EndInit();
return img;
}
}
}
public class WpfTerminalTextWriter : TextWriter
{
public override Encoding Encoding
{
get
{
return Encoding.Unicode;
}
}
public TextBox UnderlyingControl
{
get
{
return Startup.ConsoleOut;
}
}
public void select()
{
try
{
UnderlyingControl.Select(UnderlyingControl.Text.Length, 0);
UnderlyingControl.ScrollToEnd();
UnderlyingControl.Focus();
AppearanceManager.CurrentPosition = 1;
AppearanceManager.LastLength = UnderlyingControl.Text.Length - 1;
}
catch { }
}
public override void Write(char value)
{
try
{
UnderlyingControl.Dispatcher.Invoke(new Action(() =>
{
UnderlyingControl.AppendText(value.ToString());
select();
}));
}
catch { }
}
public override void WriteLine(string value)
{
try
{
UnderlyingControl.Dispatcher.Invoke(new Action(() =>
{
UnderlyingControl.AppendText(ShiftOS.Engine.Localization.Parse(value) + Environment.NewLine);
select();
}));
}
catch { }
}
public void SetLastText()
{
if (SaveSystem.CurrentSave != null)
{
if (!Shiftorium.UpgradeInstalled("window_manager"))
AppearanceManager.LastTerminalText = UnderlyingControl.Text;
}
}
public override void Write(string value)
{
try
{
UnderlyingControl.Dispatcher.Invoke(new Action(() =>
{
UnderlyingControl.AppendText(ShiftOS.Engine.Localization.Parse(value));
select();
}));
}
catch { }
}
}
}
|