-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWRUtilities.h
250 lines (221 loc) · 6.98 KB
/
WRUtilities.h
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
/**
* Copyright © 2024 Piotr Domanski
* Licensed under the MIT license.
**/
#pragma once
#include <vector>
#include <cmath>
#include <limits>
#include <cstdio> // For sscanf()
#include <iostream>
#include <wx/wx.h>
#include <Windows.h>
namespace WinRuler
{
/**
* Ruler's position. It describes position of ruler's scale.
**/
typedef enum ERulerPosition
{
// Ruler's scale is on left side of the ruler.
rpLeft,
// Ruler's scale is on top side of the ruler.
rpTop,
// Ruler's scale is on right side of the ruler.
rpRight,
// Ruler's scale is on bottom side of the ruler.
rpBottom
} ERulerPosition;
/**
* Ruler's units of measurement types.
**/
typedef enum ERulerUnits
{
// Centimetres as unit of measurement.
ruCentimetres,
// Inches as unit of measurement.
ruInches,
// Picas as unit of measurement.
ruPicas,
// Pixels as unit of measurement.
ruPixels
} ERulerUnits;
/**
* Ruler's background type.
**/
typedef enum ERulerBackgroundType
{
// Solid colour as ruler's background.
btSolid,
// Gradient colour as ruler's background.
btGradient,
// Image as ruler's background.
btImage
} ERulerBackgroundType;
/*-------------------------------------------------------------------------
Mathematical routines.
-------------------------------------------------------------------------*/
/**
* Portable comparison function for double float numbers.
*
* @param a First double float number that will be compared.
* @param b Second double float number that will be compared.
*
* @return Returns true if a and b numbers are almost equal, false otherwise.
**/
bool AreSame(double a, double b, double epsilon = std::numeric_limits<double>::epsilon());
/*-------------------------------------------------------------------------
Unit of measurement conversion routines.
-------------------------------------------------------------------------*/
extern std::vector<wxSize> g_vPixelPerInch;
/**
* Sets new PixelPerInch value.
*
* @param NewValue New value that will be stored as current PixelPerInch
* value.
**/
void SetPixelPerInch(unsigned int DisplayNo, wxSize& NewPPIValue);
/**
* Gets PixelPerInch value.
*
* @return Returns current PixelPerInch value.
**/
wxSize& GetPixelPerInch(unsigned int DisplayNo);
/**
* Calculates conversion from inches to pixels (horizontal version).
*
* @param AInchDistance Inch distance that will be calculated to
* pixels.
*
* @return Returns result of inches to pixels calculation.
**/
int InchesToPixelsHorizontal(unsigned int DisplayNo, double AInchDistance);
/**
* Calculates conversion from inches to pixels (vertical version).
*
* @param AInchDistance Inch distance that will be calculated to
* pixels.
*
* @return Returns result of inches to pixels calculation.
**/
int InchesToPixelsVertical(unsigned int DisplayNo, double AInchDistance);
/**
* Calculates conversion from pixels to inches (horizontal version).
*
* @param APixelDistance Pixel distance that will be calculated to
* inches.
*
* @return Returns result of pixels to inches calculation.
**/
double PixelsToInchesHorizontal(unsigned int DisplayNo, int APixelDistance);
/**
* Calculates conversion from pixels to inches (vertical version).
*
* @param APixelDistance Pixel distance that will be calculated to
* inches.
*
* @return Returns result of pixels to inches calculation.
**/
double PixelsToInchesVertical(unsigned int DisplayNo, int APixelDistance);
/**
* Calculates conversion form centimetres to pixels (horizontal version).
*
* @param ACentimetreDistance Centimetre distans that will be calculated to
* pixels.
*
* @return Returns result of centimetres to pixels calculation.
**/
int CentimetresToPixelsHorizontal(unsigned int DisplayNo, double ACentimetreDistance);
/**
* Calculates conversion form centimetres to pixels (vertical version).
*
* @param ACentimetreDistance Centimetre distans that will be calculated to
* pixels.
*
* @return Returns result of centimetres to pixels calculation.
**/
int CentimetresToPixelsVertical(unsigned int DisplayNo, double ACentimetreDistance);
/**
* Calculates conversion from pixels to centimetres (horizontal version).
*
* @param APixelDistance Pixel distance that will be calculated to
* centimetres.
* @return Returns result of pixels to centimetres calculation.
**/
double PixelsToCentimetresHorizontal(unsigned int DisplayNo, int APixelDistance);
/**
* Calculates conversion from pixels to centimetres (vertical version).
*
* @param APixelDistance Pixel distance that will be calculated to
* centimetres.
* @return Returns result of pixels to centimetres calculation.
**/
double PixelsToCentimetresVertical(unsigned int DisplayNo, int APixelDistance);
/**
* Calculates conversion from picas to pixels (horizontal version).
*
* @param APicasDistance Picas distance that will be calculated to pixels.
*
* @return Returns result of picas to pixels calculation.
**/
int PicasToPixelsHorizontal(unsigned int DisplayNo, double APicasDistance);
/**
* Calculates conversion from picas to pixels (vertical version).
*
* @param APicasDistance Picas distance that will be calculated to pixels.
*
* @return Returns result of picas to pixels calculation.
**/
int PicasToPixelsVertical(unsigned int DisplayNo, double APicasDistance);
/**
* Calculates conversion from pixels to picas (horizontal version).
*
* @param APixelDistance Pixel distance that will be calculated to picas.
*
* @return Returns result of pixels to picas calculation.
**/
double PixelsToPicasHorizontal(unsigned int DisplayNo, int APixelDistance);
/**
* Calculates conversion from pixels to picas (vertical version).
*
* @param APixelDistance Pixel distance that will be calculated to picas.
*
* @return Returns result of pixels to picas calculation.
**/
double PixelsToPicasVertical(unsigned int DisplayNo, int APixelDistance);
/*-------------------------------------------------------------------------
Other helpful routines.
-------------------------------------------------------------------------*/
/**
* Performs retrival of two values from specially formated string "%d:%d".
*
* @param PositionString Reference to specially formated position
* string.
*
* @return Returns retrived values represented in wxPoint type format.
**/
wxPoint ParsePosition(const wxString& PositionString);
// Window information structure.
struct WindowInfo
{
// Window rect (position and size).
RECT Rect;
// Window handle.
HWND hwnd;
};
/**
* Callback function for EnumWindows.
*
* @param hwnd Window handle.
* @param lParam LPARAM instance.
*
* @return Returns TRUE if operation was successful.
**/
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam);
/**
* Returns vector of all visible windows.
*
* @return Returns vector of all visible windows.
**/
std::vector<WindowInfo> GetAllWindows();
}