Skip to content

Commit a530e1d

Browse files
committed
Fixed errors and modified Borderless() syntax
1 parent 5b3d7a1 commit a530e1d

File tree

4 files changed

+14
-19
lines changed

4 files changed

+14
-19
lines changed

Examples/Example_3D.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ static void Main(string[] args) {
3939
public override void Create() {
4040
Engine.SetPalette(Palettes.Pico8);
4141
Engine.SetBackground(0);
42-
Engine.Borderless(true);
42+
Engine.Borderless();
4343

4444
Console.Title = "3D Demo";
4545

Examples/Tetris.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ private static void Main(string[] args) {
3131
}
3232
public override void Create() {
3333
Engine.SetPalette(Palettes.Pico8);
34-
Engine.Borderless(true);
34+
Engine.Borderless();
3535
Console.Title = "Tetris";
3636
TargetFramerate = 16;
3737

Source/ConsoleEngine.cs

+10-16
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ public ConsoleEngine(int width, int height, int fontW, int fontH) {
4040

4141
Console.Title = "Untitled console application";
4242
Console.CursorVisible = false;
43+
44+
// sätter fönstret och bufferns storlek
45+
// buffern måste sättas efter fönsret, eftersom den aldrig får vara mindre än skärmen
46+
Console.SetWindowSize(width, height);
4347
Console.SetBufferSize(width, height);
4448

4549
ConsoleBuffer = new ConsoleBuffer(width, height);
@@ -56,12 +60,9 @@ public ConsoleEngine(int width, int height, int fontW, int fontH) {
5660
// Stänger av alla standard ConsoleInput metoder (Quick-edit etc)
5761
NativeMethods.SetConsoleMode(stdInputHandle, 0x0080);
5862

59-
// Sätter fontstorlek och tvingar Raster (Terminal)
63+
// Sätter fontstorlek och tvingar Raster (Terminal) / Consolas
6064
// Detta måste göras efter SetBufferSize, annars ger den en IOException
6165
ConsoleFont.SetFont(stdOutputHandle, (short)fontW, (short)fontH);
62-
// sätter storleken på fönstret, måste ske efter SetBufferSize för annars
63-
// blir fönstret 1 px större (?)
64-
Console.SetWindowSize(width, height);
6566
}
6667

6768
// Rita
@@ -104,13 +105,11 @@ public void DisplayBuffer() {
104105
ConsoleBuffer.Blit();
105106
}
106107

107-
/// <summary> Sets wheather the window should be borderless or not. </summary>
108-
/// <param name="b">True if intended to run borderless.</param>
109-
public void Borderless(bool b) {
110-
IsBorderless = b;
108+
/// <summary> Sets the window to borderless mode. </summary>
109+
public void Borderless() {
110+
IsBorderless = true;
111111

112112
int GWL_STYLE = -16; // hex konstant för stil-förändring
113-
int WS_DEFAULT = 0x00C00000; // vanlig
114113
int WS_BORDERLESS = 0x00080000; // helt borderless
115114

116115
NativeMethods.Rect rect = new NativeMethods.Rect();
@@ -125,13 +124,8 @@ public void Borderless(bool b) {
125124
(desktopRect.Right / 2) - ((WindowSize.X * FontSize.X) / 2),
126125
(desktopRect.Bottom / 2) - ((WindowSize.Y * FontSize.Y) / 2));
127126

128-
if (b == true) {
129-
NativeMethods.SetWindowLong(consoleHandle, GWL_STYLE, WS_BORDERLESS);
130-
NativeMethods.SetWindowPos(consoleHandle, -2, wPos.X, wPos.Y, rect.Right - 8, rect.Bottom - 8, 0x0040);
131-
} else {
132-
NativeMethods.SetWindowLong(consoleHandle, GWL_STYLE, WS_DEFAULT);
133-
NativeMethods.SetWindowPos(consoleHandle, -2, wPos.X, wPos.Y, rect.Right, rect.Bottom, 0x0040);
134-
}
127+
NativeMethods.SetWindowLong(consoleHandle, GWL_STYLE, WS_BORDERLESS);
128+
NativeMethods.SetWindowPos(consoleHandle, -2, wPos.X, wPos.Y, rect.Right - 8, rect.Bottom - 8, 0x0040);
135129

136130
NativeMethods.DrawMenuBar(consoleHandle);
137131
}

Source/ConsoleFont.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ internal static int SetFont(IntPtr h, short sizeX, short sizeY) {
1919
cfi.dwFontSize.Y = sizeY;
2020

2121
// sätter font till Terminal (Raster)
22-
cfi.FaceName = "Terminal";
22+
if (sizeX < 4 || sizeY < 4) cfi.FaceName = "Consolas";
23+
else cfi.FaceName = "Terminal";
2324

2425
NativeMethods.SetCurrentConsoleFontEx(h, false, ref cfi);
2526
return 0;

0 commit comments

Comments
 (0)