-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapplication.h
412 lines (329 loc) · 9.49 KB
/
application.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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
#ifndef APPLICATION_H
#define APPLICATION_H
#include "GT_Color.h"
#include "GT_Window.h"
#include "GT_Input.h"
#include "GT_Font.h"
#include "resource.h"
#include <vector>
const int kMaxChars = 256;
const int kGTFontVersionNum = 2; // **NOTE** If you change this, make sure to update kAboutText
const int kCustomColorNum = 16;
const int kClearImgColor = ARGB(128,0,0,0);
const int k1PixelKernelSize = 3 * 3;
const int k1PixKernelX[k1PixelKernelSize] = { -1, 0, 1,
-1, 0, 1,
-1, 0, 1, };
const int k1PixKernelY[k1PixelKernelSize] = { -1, -1, -1,
0, 0, 0,
1, 1, 1, };
const int k2PixelKernelSize = 5 * 5;
const int k2PixKernelX[k2PixelKernelSize] = { 0, -1, 0, 1, 0,
-2, -1, 0, 1, 2,
-2, -1, 0, 1, 2
-2, -1, 0, 1, 2,
0, -1, 0, 1, 0 };
const int k2PixKernelY[k2PixelKernelSize] = { 0, -2, -2, -2, 0,
-1, -1, -1, -1, -1,
0, 0, 0, 0, 0,
1, 1, 1, 1, 1,
0, 2, 2, 2, 0 };
const int k4PixKernelSize = 9 * 9;
const int k4PixKernelX[k4PixKernelSize] = { 0, 0, -2, -1, 0, 1, 2, 0, 0,
0, -3, -2, -1, 0, 1, 2, 3, 0,
-4, -3, -2, -1, 0, 1, 2, 3, 4,
-4, -3, -2, -1, 0, 1, 2, 3, 4,
-4, -3, -2, -1, 0, 1, 2, 3, 4,
-4, -3, -2, -1, 0, 1, 2, 3, 4,
-4, -3, -2, -1, 0, 1, 2, 3, 4,
0, -3, -2, -1, 0, 1, 2, 3, 0,
0, 0, -2, -1, 0, 1, 2, 0, 0 };
const int k4PixKernelY[k4PixKernelSize] = { 0, 0, -4, -4, -4, -4, -4, 0, 0,
0, -3, -3, -3, -3, -3, -3, -3, 0,
-2, -2, -2, -2, -2, -2, -2, -2, -2,
-1, -1, -1, -1, -1, -1, -1, -1, -1,
0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 1, 1, 1, 1, 1, 1, 1, 1,
2, 2, 2, 2, 2, 2, 2, 2, 2,
0, 3, 3, 3, 3, 3, 3, 3, 0,
0, 0, 4, 4, 4, 4, 4, 0, 0 };
class CAppFont : public CFont
{
public:
CAppFont() { mOrigFont = NULL; }
bool init()
{
mImg = new CImage;
if (mImg != NULL)
{
return mImg->init(128,128,4);
}
return false;
}
bool setFont(HFONT f)
{
if(f)
{
if(mOrigFont == NULL)
{
mOrigFont = (HFONT)SelectObject(mImg->getDC(), f);
if(!mOrigFont)
return false;
}
else
{
SelectObject(mImg->getDC(), f);
}
}
// Set text color
if(SetTextColor(mImg->getDC(), RGB(255, 255, 255)) == CLR_INVALID)
return false;
SetBkColor(mImg->getDC(), RGB(255, 255, 255));
// Set the background mode to transparent
if(!SetBkMode(mImg->getDC(), TRANSPARENT))
return false;
return true;
}
void renderOutline(int outlineSize, int outlineARGB, int bgARGB)
{
if(!mImg)
return;
assert(outlineARGB != bgARGB);
int kernelSize = 0;
const int *kernelX = NULL;
const int *kernelY = NULL;
switch(outlineSize)
{
case 1:
{
kernelSize = k1PixelKernelSize;
kernelX = k1PixKernelX;
kernelY = k1PixKernelY;
}
break;
case 2:
{
kernelSize = k2PixelKernelSize;
kernelX = k2PixKernelX;
kernelY = k2PixKernelY;
}
break;
case 4:
{
kernelSize = k4PixKernelSize;
kernelX = k4PixKernelX;
kernelY = k4PixKernelY;
}
break;
}
for(int y = 0; y < mImg->getHeight(); ++y)
{
for(int x = 0; x < mImg->getWidth(); ++x)
{
int pixel = mImg->getPixel(x,y);
if(pixel != bgARGB)
{
for(int k = 0; k < kernelSize; ++k)
{
int xxx = x + kernelX[k];
int yyy = y + kernelY[k];
int pix = mImg->getPixel(xxx,yyy);
if (pix == 0)
continue; // Out of bounds
if ((GET_R(pix) == 255) && (GET_G(pix) == 255) && (GET_B(pix) == 255))
continue; // Skip true letter pixels
if (pix == outlineARGB)
continue; // Skip outline color
mPoints.push_back(PT(xxx, yyy));
}
}
}
}
while(mPoints.empty() == false)
{
PT p = mPoints.back();
mImg->setPixel(p.x, p.y, outlineARGB);
mPoints.pop_back();
}
}
virtual ~CAppFont()
{
if(mOrigFont && mImg) // Put back original
{
SelectObject(mImg->getDC(), mOrigFont);
}
}
private:
class PT
{
public:
PT(int X, int Y) : x(X), y(Y) {}
int x;
int y;
};
HFONT mOrigFont;
std::vector<PT> mPoints;
};
class CApp : public CWindow
{
public:
CApp();
virtual bool init(HINSTANCE hinstance, const SWinInfo &winInfo);
virtual LRESULT wndProc(UINT msg, WPARAM wparam, LPARAM lparam);
void update();
void draw();
// Upper left corner of where to start drawing from
void drawDebugBoxes(int x, int y);
virtual ~CApp();
protected:
//SFont mCharUVSet[kMaxChars];
CHOOSEFONT mChooseFont;
LOGFONT mLogFont;
CAppFont mFont;
COLORREF mCustomColors[kCustomColorNum]; // Used by color picker
CColor mColorKey;
CColor mOutline;
HICON mIcon;
HMENU mMenu;
HFONT mCurWin32Font;
int mSizeFlag;
int mAliasFlag;
int mCharUVSetFlag;
int mCaseFlag;
int mColorKeyFlag;
int mOutlineFlag;
int mOutlineWidFlag;
int mOutlineSize; // Number of pixels to outline by
bool mRedraw; // Set to true when we need to redraw, false otherwise
wchar_t *mCustomSet; // A custom set of characters to be rendered
int mCustomSetCharCount; // Number of characters in the custom set
wchar_t mASCIISet[kMaxChars];
void zeroVars()
{
memset(&mChooseFont, 0, sizeof(CHOOSEFONT));
memset(&mLogFont, 0, sizeof(LOGFONT));
memset(mCustomColors, 0, sizeof(COLORREF) * kCustomColorNum);
mColorKey.set((uchar)0,0,0,0);
mOutline.set((uchar)0,0,0,0);
mIcon = NULL;
mMenu = NULL;
mCurWin32Font = NULL;
mSizeFlag = mAliasFlag = mCharUVSetFlag = mCaseFlag = mColorKeyFlag = mOutlineFlag = 0;
mOutlineSize = 0;
mRedraw = true;
mCustomSet = NULL;
mCustomSetCharCount = 0;
for(int i = 0; i < kMaxChars; ++i)
{
mASCIISet[i] = (wchar_t)i;
}
}
bool getSaveFileName(OPENFILENAME *ofn, const char *filtetText,
const char *filterExt, char *fileName);
bool getLoadFileName(OPENFILENAME *ofn, const char *filtetText,
const char *filterExt, char *fileName);
bool saveGTFT();
bool loadCustomCharSet();
bool chooseFont();
bool setFont(LOGFONT *f);
bool setupTexture();
bool antiAliasTexture();
bool colorKeyTexture();
bool renderFont();
bool renderLetters(); // Helper function to render each letter of chosen set
bool testLetter(int c); // Returns true if 'c' is in range of chosen ASCII set, false otherwise
bool testCase(int c); // Return true if 'c' is in range of chosen case set
void setMenuItemSize(int which); // Checks "which" size menu item
void setMenuItemAlias(int which); // Checks "which" anti-alias menu item
void setMenuItemChar(int which); // Check "which" character menu item
void setMenuItemCase(int which); // Check "which" case menu item
void setMenuItemColorKey(int which); // Check "which" color key menu item
void setMenuItemOutline(int which); // Check "which" outline menu item
void setMenuItemOutlineWidth(int which); // Check "which" outline width menu item
bool loadResources(HINSTANCE hinst); // Loads menu and icon
void calcLinearImgSize(int &wid, int &hgt);
void pickColor(int flag); // Uses color picker to a color determined by "flag"
void displayError(const char *err); // Display error messages
};
extern CApp *gApp;
#endif
/*
int last = outlineARGB;
// Check horizontal pixels
for(int y = 0; y < mImg->getHeight(); ++y)
{
for(int x = 0; x < mImg->getWidth(); ++x)
{
int pixel = mImg->getPixel(x,y);
// Check behind
if((pixel != bgARGB) && (pixel != outlineARGB) && (last == bgARGB))
{
int xxx = x - outlineSize;
int count = outlineSize;
if(xxx < 0)
{
count += xxx;
xxx = 0;
}
for(; count; xxx++, count--)
{
if(mImg->getPixel(xxx, y) == bgARGB)
mImg->setPixel(xxx, y, outlineARGB);
}
}
// Check in front
else if((pixel == bgARGB) && (last != bgARGB) && (last != outlineARGB))
{
int xxx = x;
int count = outlineSize;
if(xxx + count >= mImg->getWidth())
count = (xxx + count) - mImg->getWidth();
for(; count; xxx++, count--)
{
if(mImg->getPixel(xxx, y) == bgARGB)
mImg->setPixel(xxx, y, outlineARGB);
}
}
last = pixel;
}
}
last = outlineARGB;
// Check vertical pixels
for(int x = 0; x < mImg->getWidth(); ++x)
{
for(int y = 0; y < mImg->getHeight(); ++y)
{
int pixel = mImg->getPixel(x,y);
// Check behind
if((pixel != bgARGB) && (pixel != outlineARGB) && (last == bgARGB))
{
int yyy = y - outlineSize;
int count = outlineSize;
if(yyy < 0)
{
count += yyy;
yyy = 0;
}
for(; count; yyy++, count--)
{
if(mImg->getPixel(x, yyy) == bgARGB)
mImg->setPixel(x, yyy, outlineARGB);
}
}
// Check in front
else if((pixel == bgARGB) && (last != bgARGB) && (last != outlineARGB))
{
int yyy = y;
int count = outlineSize;
if(yyy + count >= mImg->getWidth())
count = (yyy + count) - mImg->getWidth();
for(; count; yyy++, count--)
{
if(mImg->getPixel(x, yyy) == bgARGB)
mImg->setPixel(x, yyy, outlineARGB);
}
}
last = pixel;
}
}
*/