This repository has been archived by the owner on May 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pallete.cs
83 lines (77 loc) · 2.13 KB
/
Pallete.cs
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
using System;
using System.Runtime.InteropServices;
namespace Engine;
public class Pallete {
public static int SetColor(int consoleColor, Color targetColor) {
return SetColor(consoleColor, targetColor.R, targetColor.G, targetColor.B);
}
private static int SetColor(int color, uint r, uint g, uint b) {
Kernel32.CONSOLE_SCREEN_BUFFER_INFO_EX csbe = new Kernel32.CONSOLE_SCREEN_BUFFER_INFO_EX();
csbe.cbSize = Marshal.SizeOf(csbe);
IntPtr hConsoleOutput = Kernel32.GetStdHandle(-11);
if (hConsoleOutput == new IntPtr(-1)) {
return Marshal.GetLastWin32Error();
}
bool brc = Kernel32.GetConsoleScreenBufferInfoEx(hConsoleOutput, ref csbe);
if (!brc) {
return Marshal.GetLastWin32Error();
}
switch (color) {
case 0:
csbe.black = new Kernel32.ColorRef(r, g, b);
break;
case 1:
csbe.darkBlue = new Kernel32.ColorRef(r, g, b);
break;
case 2:
csbe.darkGreen = new Kernel32.ColorRef(r, g, b);
break;
case 3:
csbe.darkCyan = new Kernel32.ColorRef(r, g, b);
break;
case 4:
csbe.darkRed = new Kernel32.ColorRef(r, g, b);
break;
case 5:
csbe.darkMagenta = new Kernel32.ColorRef(r, g, b);
break;
case 6:
csbe.darkYellow = new Kernel32.ColorRef(r, g, b);
break;
case 7:
csbe.gray = new Kernel32.ColorRef(r, g, b);
break;
case 8:
csbe.darkGray = new Kernel32.ColorRef(r, g, b);
break;
case 9:
csbe.blue = new Kernel32.ColorRef(r, g, b);
break;
case 10:
csbe.green = new Kernel32.ColorRef(r, g, b);
break;
case 11:
csbe.cyan = new Kernel32.ColorRef(r, g, b);
break;
case 12:
csbe.red = new Kernel32.ColorRef(r, g, b);
break;
case 13:
csbe.magenta = new Kernel32.ColorRef(r, g, b);
break;
case 14:
csbe.yellow = new Kernel32.ColorRef(r, g, b);
break;
case 15:
csbe.white = new Kernel32.ColorRef(r, g, b);
break;
}
++csbe.srWindow.Bottom;
++csbe.srWindow.Right;
brc = Kernel32.SetConsoleScreenBufferInfoEx(hConsoleOutput, ref csbe);
if (!brc) {
return Marshal.GetLastWin32Error();
}
return 0;
}
}