Skip to content

Commit 441908e

Browse files
committed
window mode
Optional /w parameter to launch as a normal bordered window. Example: HsvScreensaver.scr /w 640 360
1 parent f43d919 commit 441908e

File tree

4 files changed

+35
-17
lines changed

4 files changed

+35
-17
lines changed

Windows/C#/HsvScreensaver/AssemblyInfo.tt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ using System.Runtime.InteropServices;
3333
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
3434
// übernehmen, indem Sie "*" eingeben:
3535
// [assembly: AssemblyVersion("1.0.*")]
36-
[assembly: AssemblyVersion("0.4.6.<#= this.RevisionNumber #>")]
37-
[assembly: AssemblyFileVersion("0.4.6.<#= this.RevisionNumber #>")]
36+
[assembly: AssemblyVersion("0.5.0.<#= this.RevisionNumber #>")]
37+
[assembly: AssemblyFileVersion("0.5.0.<#= this.RevisionNumber #>")]
3838
<#+
3939
int RevisionNumber = (int)(DateTime.UtcNow - new DateTime(2016, 4, 19)).TotalDays;
4040
#>

Windows/C#/HsvScreensaver/Program.cs

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ static void Main(string[] args) {
1212
Application.EnableVisualStyles();
1313
Application.SetCompatibleTextRenderingDefault(false);
1414

15-
char cmd = getParam(args, 0, 's');
15+
char cmd = getCommand(args, 0, 's');
1616
if ( cmd == 'c' ) {
1717
Configure();
1818
}
@@ -26,6 +26,14 @@ static void Main(string[] args) {
2626
Show();
2727
#endif
2828
}
29+
else if ( cmd == 'w' ) {
30+
Settings.I.Windowed = true;
31+
Settings.I.Maximized = false;
32+
Settings.I.Fullscreen = false;
33+
int w = (int.TryParse(getParam(args, 1, ""), out w) ? w : int.MaxValue);
34+
int h = (int.TryParse(getParam(args, 2, ""), out h) ? h : int.MaxValue);
35+
Show(w, h);
36+
}
2937
else {
3038
Configure();
3139
}
@@ -41,27 +49,33 @@ private static void Preview(string[] args) {
4149
Application.Run(new PreviewForm(Ptr));
4250
}
4351

44-
public static void Show() {
52+
public static void Show(int width = int.MaxValue, int height = int.MaxValue) {
4553
// get resolution
46-
int left = int.MaxValue;
47-
int right = int.MinValue;
48-
int top = int.MaxValue;
54+
int left = int.MaxValue;
55+
int right = int.MinValue;
56+
int top = int.MaxValue;
4957
int bottom = int.MinValue;
5058
foreach ( Screen s in Screen.AllScreens ) {
51-
left = Math.Min(s.Bounds.Left, left);
52-
right = Math.Max(s.Bounds.Right, right);
53-
top = Math.Min(s.Bounds.Top, top);
59+
left = Math.Min(s.Bounds.Left, left);
60+
right = Math.Max(s.Bounds.Right, right);
61+
top = Math.Min(s.Bounds.Top, top);
5462
bottom = Math.Max(s.Bounds.Bottom, bottom);
5563
}
56-
Rectangle r = new Rectangle(left, top, right - left, bottom - top);
64+
width = Math.Min(width, right - left);
65+
height = Math.Min(height, bottom - top);
66+
Rectangle r = new Rectangle(left, top, width, height);
5767
using ( ScreensaverWindow scr = new ScreensaverWindow(r) ) {
5868
scr.Run();
5969
}
6070
}
6171

62-
private static char getParam(string[] args, int index, char _default) {
72+
private static string getParam(string[] args, int index, string _default) {
6373
if ( args.Length <= index || index < 0 ) { return _default; }
64-
return args[index].Trim().Substring(1, 1).ToLower()[0];
74+
return args[index].Trim();
75+
}
76+
77+
private static char getCommand(string[] args, int index, char _default) {
78+
return getParam(args, index, "/" + _default).Substring(1, 1).ToLower()[0];
6579
}
6680
}
6781
}

Windows/C#/HsvScreensaver/ScreensaverWindow.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,18 @@ class ScreensaverWindow : GameWindow {
1313
public ScreensaverWindow(Rectangle r)
1414
: base(r.Width, r.Height, GraphicsMode.Default, "HsvScreensaver", GameWindowFlags.FixedWindow) {
1515
// set up window
16-
WindowBorder = WindowBorder.Hidden;
16+
WindowBorder = (Settings.I.Windowed ? WindowBorder.Resizable : WindowBorder.Hidden);
1717
WindowState = (Settings.I.Fullscreen ? WindowState.Fullscreen : (Settings.I.Maximized ? WindowState.Maximized : WindowState.Normal));
1818
Location = r.Location;
1919
ClientRectangle = r;
2020

2121
VSync = (Settings.I.VSync ? VSyncMode.On : VSyncMode.Off);
2222

23-
CursorVisible = false;
24-
KeyDown += (sender, ev) => { Close(); };
25-
MouseDown += (sender, ev) => { Close(); };
23+
if ( ! Settings.I.Windowed ) {
24+
CursorVisible = false;
25+
KeyDown += (sender, ev) => { Close(); };
26+
MouseDown += (sender, ev) => { Close(); };
27+
}
2628

2729
gl = new ScreensaverGL();
2830
}

Windows/C#/HsvScreensaver/Settings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ public class Settings {
1212
private static Settings instance = null;
1313
[NonSerialized()]
1414
private static string settingsDir = null;
15+
[NonSerialized()]
16+
public bool Windowed = false;
1517
#endregion
1618

1719
#region serialized attributes

0 commit comments

Comments
 (0)