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
#![allow(non_snake_case)]
use crate::co;
use crate::funcs::{LOBYTE, LOWORD};
#[repr(transparent)]
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub struct ATOM(pub(crate) u16);
impl std::fmt::Display for ATOM {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
#[repr(transparent)]
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub struct COLORREF(pub(crate) u32);
impl From<co::CLR> for COLORREF {
fn from(v: co::CLR) -> Self {
Self(v.0)
}
}
impl std::fmt::Display for COLORREF {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "R {}, G {}, B {}",
self.GetRValue(), self.GetGValue(), self.GetBValue())
}
}
impl COLORREF {
pub const fn new(red: u8, green: u8, blue: u8) -> COLORREF {
Self(red as u32 | ((green as u32) << 8) | ((blue as u32) << 16))
}
pub fn new_array<const N: usize>(rgbs: &[(u8, u8, u8); N]) -> [COLORREF; N] {
let mut arr = [Self::new(0, 0, 0); N];
for (i, rgb) in rgbs.iter().enumerate() {
arr[i] = Self::new(rgb.0, rgb.1, rgb.2);
}
arr
}
pub const fn GetRValue(self) -> u8 {
LOBYTE(LOWORD(self.0))
}
pub const fn GetGValue(self) -> u8 {
LOBYTE(LOWORD(self.0 >> 8))
}
pub const fn GetBValue(self) -> u8 {
LOBYTE(LOWORD(self.0 >> 16))
}
}
#[repr(transparent)]
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub struct LANGID(pub(crate) u16);
impl From<LANGID> for u16 {
fn from(v: LANGID) -> Self {
v.0
}
}
impl LANGID {
pub const SYSTEM_DEFAULT: Self = Self::new(co::LANG::NEUTRAL, co::SUBLANG::SYS_DEFAULT);
pub const USER_DEFAULT: Self = Self::new(co::LANG::NEUTRAL, co::SUBLANG::DEFAULT);
pub const fn new(lang: co::LANG, sublang: co::SUBLANG) -> LANGID {
Self((sublang.0 << 10) | lang.0)
}
pub const fn primary_lang_id(self) -> co::LANG {
co::LANG(self.0 & 0x3ff)
}
pub const fn sub_lang_id(self) -> co::SUBLANG {
co::SUBLANG(self.0 >> 10)
}
}
#[repr(transparent)]
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub struct LCID(pub(crate) u32);
impl LCID {
pub const SYSTEM_DEFAULT: Self = Self::new(LANGID::SYSTEM_DEFAULT, co::SORT::DEFAULT);
pub const USER_DEFAULT: Self = Self::new(LANGID::USER_DEFAULT, co::SORT::DEFAULT);
pub const fn new(lang_id: LANGID, sort_id: co::SORT) -> LCID {
Self(((sort_id.0 as u32) << 16) | lang_id.0 as u32)
}
pub const fn lang_id(self) -> LANGID {
LANGID(self.0 as _)
}
pub const fn sort_id(self) -> co::SORT {
co::SORT(((self.0 >> 16) & 0xf) as _)
}
}