-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWindow.cpp
More file actions
718 lines (636 loc) · 24.2 KB
/
Copy pathWindow.cpp
File metadata and controls
718 lines (636 loc) · 24.2 KB
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
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
#include "Window.hpp"
#include "Line2D.hpp"
#include "Point2D.hpp"
#include "Vector2D.hpp"
#include "resource.h"
#include "Shapes/Box2D.hpp"
#include "Shapes/Circle.hpp"
#include "Shapes/Ellipse.hpp"
#include <commctrl.h> // Required for TBBUTTON and toolbar functions
// Functions defined in Main.cpp
extern void AddLine2D(CGF::Line2D & line);
extern void AddBox2D(CGF::Box2D & box);
extern void AddCircle(CGF::Circle & circle);
extern void AddEllipse(CGF::Ellipse & ellipse);
extern void SetPreviousPoint(unsigned int x, unsigned int y);
extern void ClearLine2D();
extern void ClearBox2D();
extern void ClearCircle();
extern void ClearEllipse();
extern void ClearPreviousPoint();
namespace CGF
{
////////////////////////////////////////////////////////////////////////////////
/*!
@brief Window default constructor
*/
////////////////////////////////////////////////////////////////////////////////
Window::Window() : mWidth(0), mHeight(0), mRunning(false),
mHwnd(0), mHdc(0), mWindowInstance(0), mClassName("WndClass"),
mBitmap(0), mOldBitmap(0), mBitmapDC(0), mSurface(0)
{}
////////////////////////////////////////////////////////////////////////////////
/*!
@brief Window destructor
*/
////////////////////////////////////////////////////////////////////////////////
Window::~Window()
{
// Get rid of the secondary window
mBitmap = (HBITMAP)::SelectObject(mBitmapDC, mOldBitmap);
::DeleteObject(mBitmap);
::ReleaseDC(NULL, mBitmapDC);
// Destroy the toolbar
::DestroyWindow(mHtoolbar);
// Get rid of the main window
UnregisterWndClass();
::ReleaseDC(mHwnd, mHdc);
// Destroy the main window
::DestroyWindow(mHwnd);
mHwnd = 0;
gHwnd = 0; // Get rid of the global window handle reference
mHdc = 0;
mRunning = false;
}
////////////////////////////////////////////////////////////////////////////////
/*!
@brief Returns the width of the Window
@return Width of the Window
*/
////////////////////////////////////////////////////////////////////////////////
unsigned int Window::Width() const
{
return mWidth;
}
////////////////////////////////////////////////////////////////////////////////
/*!
@brief Returns the height of the Window
@return Height of the Window
*/
////////////////////////////////////////////////////////////////////////////////
unsigned int Window::Height() const
{
return mHeight;
}
////////////////////////////////////////////////////////////////////////////////
/*!
@brief Returns the status of the Window (running or not running)
@return true if the Window is runing, false if not
*/
////////////////////////////////////////////////////////////////////////////////
bool Window::Running() const
{
return mRunning;
}
////////////////////////////////////////////////////////////////////////////////
/*!
@brief Registers the WNDCLASS with Windows
@param hInstance
Windows window instance
@return true for success, false for error
*/
////////////////////////////////////////////////////////////////////////////////
bool Window::RegisterWndClass(HINSTANCE hInstance)
{
WNDCLASS wc;
// fill out the window style structure...mostly default options
wc.style = CS_DBLCLKS;
wc.lpfnWndProc = MyWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = NULL;
wc.hCursor = LoadCursor(NULL, IDC_CROSS);
wc.hbrBackground = (HBRUSH)::GetStockObject(WHITE_BRUSH);//(HBRUSH)(COLOR_WINDOW + 1);
wc.lpszMenuName = NULL;
wc.lpszClassName = mClassName.c_str();
if (!::RegisterClass(&wc))
return false;
return true;
}
////////////////////////////////////////////////////////////////////////////////
/*!
@brief Un-registers the WNDCLASS with Windows
*/
////////////////////////////////////////////////////////////////////////////////
void Window::UnregisterWndClass()
{
::UnregisterClass(mClassName.c_str(), mWindowInstance);
}
////////////////////////////////////////////////////////////////////////////////
/*!
@brief Creates the Window
@param hInstance
Windows window instance
@param windowName
The name of the window
@param width
Width of the Window
@param height
Height of the Window
@return true if the Window creation was successful, false if not
@par This must be called to complete initialization of the Window object
*/
////////////////////////////////////////////////////////////////////////////////
bool Window::Create(HINSTANCE hInstance, const std::string & windowName, const unsigned int width, const unsigned int height)
{
if(!RegisterWndClass(hInstance))
return false;
HMENU hMenu = ::LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU1));
SetMenuItem(hMenu, LINE_DDA, MF_CHECKED);
mHwnd = ::CreateWindow(mClassName.c_str(), // Window class name
windowName.c_str(), // Window text (title)
WS_OVERLAPPEDWINDOW, // Window style
CW_USEDEFAULT, // Let Windows decide
CW_USEDEFAULT, // Let Windows decide
width, // Window size x
height, // Window size y
NULL, // No parent window
hMenu, // App's menu
hInstance, // App's HINSTANCE
NULL); // No data to WM_CREATE
if(NULL == mHwnd)
return false;
gHwnd = mHwnd; // Store the window handle globally
mHdc = ::GetDC(mHwnd);
::ShowWindow(mHwnd, SW_SHOWNORMAL);
// Define the array of TBBUTTON structures
TBBUTTON tbButtons[] = {
{ MAKELONG(0, 0), ID_PRIMITIVE_LINE, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, (INT_PTR)L"Line" },
{ MAKELONG(1, 0), ID_PRIMITIVE_VECTOR, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, (INT_PTR)L"Vector" },
{ MAKELONG(2, 0), ID_SHAPE_TRIANGLE, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, (INT_PTR)L"Triangle" },
{ MAKELONG(3, 0), ID_SHAPE_RECTANGLE, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, (INT_PTR)L"Rectangle" },
{ MAKELONG(4, 0), ID_SHAPE_CIRCLE, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, (INT_PTR)L"Circle" },
{ MAKELONG(5, 0), ID_SHAPE_ELLIPSE, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, (INT_PTR)L"Ellipse" }
};
INITCOMMONCONTROLSEX icex;
icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
icex.dwICC = ICC_BAR_CLASSES; // Load toolbar and rebar controls
InitCommonControlsEx(&icex);
mHtoolbar = CreateToolbarEx(
mHwnd, // Handle to the parent window
WS_CHILD | WS_VISIBLE, // Toolbar styles
IDR_TOOLBAR1, // Toolbar resource ID
7, // Number of buttons
hInstance, // Handle to the application instance
IDB_TOOLBAR, // Bitmap resource ID
tbButtons, // Array of TBBUTTON structures
sizeof(tbButtons) / sizeof(TBBUTTON),
16, 16, // Width and height of buttons
16, 16, // Width and height of bitmaps
sizeof(TBBUTTON) // Size of a TBBUTTON structure
);
::ShowWindow(mHtoolbar, SW_SHOW);
mRunning = true;
mWidth = width;
mHeight = height;
mWindowInstance = hInstance;
// Create the secondary buffer
CreateSecondaryBuffer(width, height);
memset(mSurface, 0xFF, sizeof(int) * Width() * Height()); // Set the back surface to white
return true;
}
////////////////////////////////////////////////////////////////////////////////
/*!
@brief Creates a secondary rendering buffer
@param width
Width of the secondary buffer
@param height
Height of the secondary buffer
*/
////////////////////////////////////////////////////////////////////////////////
void Window::CreateSecondaryBuffer(const unsigned int width, const unsigned int height)
{
BITMAPINFOHEADER bmpinfo;
bmpinfo.biBitCount = 32;
bmpinfo.biClrImportant = 0;
bmpinfo.biClrUsed = 0;
bmpinfo.biCompression = BI_RGB;
bmpinfo.biHeight = height;
bmpinfo.biPlanes = 1;
bmpinfo.biSize = sizeof(BITMAPINFOHEADER);
bmpinfo.biSizeImage = 0;
bmpinfo.biWidth = width;
bmpinfo.biXPelsPerMeter = 0;
bmpinfo.biYPelsPerMeter = 0;
HDC tmpDC = ::CreateDC("Display", 0, 0, 0);
mBitmapDC = ::CreateCompatibleDC(tmpDC);
// if mBitmapDC is null, something very bad hapened
mBitmap = ::CreateDIBSection(mBitmapDC, (BITMAPINFO *)&bmpinfo, DIB_RGB_COLORS, (void **)&mSurface, NULL, NULL);
mOldBitmap = (HBITMAP)SelectObject(mBitmapDC, mBitmap);
::DeleteDC(tmpDC);
}
////////////////////////////////////////////////////////////////////////////////
/*!
@brief Swaps the primary and secondary buffer by blitting to the primary surface
@par Has a side effect of clearing the screen after blitting
*/
////////////////////////////////////////////////////////////////////////////////
void Window::Present()
{
RECT rect;
GetClientRect(gHwnd, &rect);
SetTextColor(mBitmapDC, RGB(0, 0, 0));
DrawText(mBitmapDC, gFirstPosStr.c_str(), -1, &rect, DT_BOTTOM | DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
DrawText(mBitmapDC, gMousePosStr.c_str(), -1, &rect, DT_BOTTOM | DT_CENTER | DT_SINGLELINE | DT_NOCLIP);
BitBlt(mHdc, 0, 0, Width(), Height(), mBitmapDC, 0, 0, SRCCOPY);
memset(mSurface, 0xFF, sizeof(int) * Width() * Height());
}
////////////////////////////////////////////////////////////////////////////////
/*!
@brief Sets a pixel on the back buffer surface
@param x
X coordinate of the pixel
@param y
Y coordinate of the pixel
@param color
Color of the pixel
*/
////////////////////////////////////////////////////////////////////////////////
void Window::SetPixel(const unsigned int x, const unsigned int y, const Color & color) const
{
if( (x < Width() && x > 0) && (y < Height() && y > 0) )
{
unsigned int fnlcolor = 0;
fnlcolor = color.GetR() << 16;
fnlcolor = (color.GetG() << 8) | fnlcolor;
fnlcolor = color.GetB() | fnlcolor;
// Note: y is flipped b/c Windows stores bitmaps upside down
*(mSurface + ((Height() - y) * Width()) + x) = fnlcolor;
}
}
////////////////////////////////////////////////////////////////////////////////
/*!
@brief Processes messages from Windows
@par Sets the internal running state to false if a close message is
in the queue.
*/
////////////////////////////////////////////////////////////////////////////////
void Window::ProcessMessages()
{
MSG msg;
if(::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
// Signal that the window should be terminated on a quit message
if(WM_QUIT == msg.message)
mRunning = false;
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
}
} // namespace CGF
////////////////////////////////////////////////////////////////////////////////
/*!
@brief Checks if a menu item is active
@param menuItem
The menu item to check for
@return true if the menu item is set to active, false if not
*/
////////////////////////////////////////////////////////////////////////////////
bool IsMenuItemActive(const enum MENU_ITEM menuItem)
{
// Check if the specified menu was set
return menuChecked[menuItem];
}
void ClearFirstPoint()
{
ClearPreviousPoint();
gFirstPosStr.clear();
}
void SetFirstPoint(unsigned int x, unsigned int y)
{
SetPreviousPoint(x, y);
gFirstPosStr = gFirstPosPrefix + gPosPrefix + std::to_string(x) + gPosSeparator + std::to_string(y) + gPosSuffix;
}
////////////////////////////////////////////////////////////////////////////////
/*!
@brief Sets a menu item in a menu to active or inactive (checked or unchecked)
@param hMenu
The menu
@param menuItem
The menu item to check for
@param check
The state of the menu item
*/
////////////////////////////////////////////////////////////////////////////////
void SetMenuItem(HMENU hMenu, MENU_ITEM menuItem, UINT check)
{
menuChecked[menuItem] = (check == MF_CHECKED);
switch (menuItem)
{
case LINE_DDA:
CheckMenuItem(hMenu, ID_LINE_DRAW_DDA, check);
break;
case LINE_BRESENHAM:
CheckMenuItem(hMenu, ID_LINE_DRAW_BRESENHAM, check);
break;
case LINE_ANIMATE:
CheckMenuItem(hMenu, ID_LINE_ANIMATE, check);
break;
case OBJECT_CIRCLE:
CheckMenuItem(hMenu, ID_SHAPE_CIRCLE, check);
break;
case OBJECT_ELLIPSE:
CheckMenuItem(hMenu, ID_SHAPE_ELLIPSE, check);
break;
default:
throw std::exception("Invalid menu item");
}
}
void SetMousePosStr(DWORD x, DWORD y)
{
gMousePosStr = gPosPrefix + std::to_string(x) + gPosSeparator + std::to_string(y) + gPosSuffix;
}
////////////////////////////////////////////////////////////////////////////////
/*!
@brief Window Procedure
@param hwnd
Window handle
@param msg
Incoming message
@param wParam
Message data
@param lParam
Message data
@return Result of the callback
*/
////////////////////////////////////////////////////////////////////////////////
LRESULT CALLBACK MyWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
// Required for constructing a polyline ...
static int firstTime = 1;
static CGF::Point2D firstPoint;
static CGF::Point2D majorAxis;
static CGF::Point2D minorAxis;
PAINTSTRUCT ps;
// Check the message type
switch (msg)
{
// Re-sizing the window
case WM_SIZING:
{
// Prevent window re-sizing
// @bug -- Using this technique causes the window to collapse
/*RECT * newArea = reinterpret_cast<RECT *>(lParam);
RECT clientArea;
::GetClientRect(gHwnd, &clientArea);
clientArea.right += 8; // pixel border
clientArea.bottom += 34;
if(newArea)
*newArea = clientArea;
*/
return TRUE;
}
// Handle the mousemove message
case WM_MOUSEMOVE:
SetMousePosStr(LOWORD(lParam), HIWORD(lParam));
return 0;
// Handle left mouse button clicks
// Left mouse button clicks in active region of window
// create a polyline ...
case WM_LBUTTONDOWN:
{
// Add the point to the point list
unsigned int x = LOWORD(lParam);
unsigned int y = HIWORD(lParam);
if (IsMenuItemActive(LINE_DDA) || IsMenuItemActive(LINE_BRESENHAM))
{
if (firstTime)
{
firstPoint = CGF::Point2D(x, y);
SetFirstPoint(x, y);
firstTime = 0;
}
else
{
CGF::Point2D secondPoint(x, y);
// Create a polyline whose start point is defined by firstPoint and
// end point is defined by second point and default color is black
CGF::Line2D l(firstPoint, secondPoint, CGF::Color(0,0,0,255));
// Add line to list
AddLine2D(l);
// A line also defines an animated box object whose default width and height
// are both 40 and whose initial center is the start point of the line.
// The box bounces between the first and second points with a default
// green fill color.
extern CGF::Color grnClr; // defined in Main.cpp
AddBox2D(CGF::Box2D (40, 40, firstPoint, secondPoint, 300, grnClr));
firstPoint = secondPoint;
SetFirstPoint(x, y);
}
}
else if (IsMenuItemActive(OBJECT_CIRCLE))
{
if (firstTime) // first point, set the center point
{
firstPoint = CGF::Point2D(x, y);
SetFirstPoint(x, y);
firstTime = 0;
}
else // second point, set the radius
{
CGF::Point2D secondPoint(x, y);
float radius = CGF::Vector2D(firstPoint, secondPoint).magnitude();
// Create a circle with the first point as the center and the distance to the second point as the radius
CGF::Circle c(firstPoint, radius);
// Add circle to list
AddCircle(c);
firstTime = 1;
ClearFirstPoint();
}
}
else if (IsMenuItemActive(OBJECT_ELLIPSE))
{
if (firstTime == 1)
{
// Set the center point
firstPoint = CGF::Point2D(x, y);
SetFirstPoint(x, y);
firstTime = 2;
}
else if (firstTime == 2)
{
// Set the major axis
majorAxis = CGF::Point2D(x, y);
firstTime = 3;
}
else if (firstTime == 3)
{
// Set the minor axis
minorAxis = CGF::Point2D(x, y);
// Create an ellipse with the first point as the center and the distance to the second point as the major axis
CGF::Ellipse e(firstPoint, majorAxis, minorAxis);
// Add ellipse to list
AddEllipse(e);
firstTime = 1;
ClearFirstPoint();
}
}
return 0;
}
// Handle the keydown message
case WM_KEYDOWN:
{
// The keycode is specified by the wParam
switch(wParam)
{
// Windows does not define symbols for these keys.
// Use the 'C' key to clear the line list.
// 'C' is 0x43
case 0x43: // 'C' key
{
ClearLine2D();
ClearBox2D();
ClearCircle();
ClearEllipse();
ClearFirstPoint();
firstTime = 1;
break;
}
}
return 0;
}
// Handle messages from the Menu bar
case WM_COMMAND:
{
// Get a handle to the menu
HMENU hMenu = ::GetMenu(gHwnd);
switch(LOWORD(wParam))
{
case ID_LINE_DRAW_DDA:
{
if (IsMenuItemActive(LINE_DDA))
{
SetMenuItem(hMenu, LINE_DDA, MF_UNCHECKED);
}
else
{
SetMenuItem(hMenu, LINE_DDA, MF_CHECKED);
SetMenuItem(hMenu, LINE_BRESENHAM, MF_UNCHECKED);
SetMenuItem(hMenu, OBJECT_CIRCLE, MF_UNCHECKED);
SetMenuItem(hMenu, OBJECT_ELLIPSE, MF_UNCHECKED);
}
break;
}
case ID_LINE_DRAW_BRESENHAM:
{
if (IsMenuItemActive(LINE_BRESENHAM))
{
SetMenuItem(hMenu, LINE_BRESENHAM, MF_UNCHECKED);
}
else
{
SetMenuItem(hMenu, LINE_BRESENHAM, MF_CHECKED);
SetMenuItem(hMenu, LINE_DDA, MF_UNCHECKED);
SetMenuItem(hMenu, OBJECT_CIRCLE, MF_UNCHECKED);
SetMenuItem(hMenu, OBJECT_ELLIPSE, MF_UNCHECKED);
}
break;
}
case ID_LINE_ANIMATE:
{
// Toggle the Animate menu item
if (IsMenuItemActive(LINE_ANIMATE))
{
SetMenuItem(hMenu, LINE_ANIMATE, MF_UNCHECKED);
}
else
{
SetMenuItem(hMenu, LINE_ANIMATE, MF_CHECKED);
SetMenuItem(hMenu, OBJECT_CIRCLE, MF_UNCHECKED);
SetMenuItem(hMenu, OBJECT_ELLIPSE, MF_UNCHECKED);
}
break;
}
case ID_SHAPE_CIRCLE:
{
// Toggle the Circle menu item
if (IsMenuItemActive(OBJECT_CIRCLE))
{
SetMenuItem(hMenu, OBJECT_CIRCLE, MF_UNCHECKED);
}
else
{
ClearFirstPoint();
firstTime = 1;
SetMenuItem(hMenu, LINE_DDA, MF_UNCHECKED);
SetMenuItem(hMenu, LINE_BRESENHAM, MF_UNCHECKED);
SetMenuItem(hMenu, LINE_ANIMATE, MF_UNCHECKED);
SetMenuItem(hMenu, OBJECT_CIRCLE, MF_CHECKED);
SetMenuItem(hMenu, OBJECT_ELLIPSE, MF_UNCHECKED);
}
break;
}
case ID_SHAPE_ELLIPSE:
{
// Toggle the Ellipse menu item
if (IsMenuItemActive(OBJECT_ELLIPSE))
{
SetMenuItem(hMenu, OBJECT_ELLIPSE, MF_UNCHECKED);
}
else
{
ClearFirstPoint();
firstTime = 1;
SetMenuItem(hMenu, LINE_DDA, MF_UNCHECKED);
SetMenuItem(hMenu, LINE_BRESENHAM, MF_UNCHECKED);
SetMenuItem(hMenu, LINE_ANIMATE, MF_UNCHECKED);
SetMenuItem(hMenu, OBJECT_ELLIPSE, MF_CHECKED);
SetMenuItem(hMenu, OBJECT_CIRCLE, MF_UNCHECKED);
}
break;
}
case ID_HELP_ABOUT:
{
// Simple about box - modal
MessageBox(gHwnd, "Developer :: Willow Hayward", "Computer Graphics Framework", MB_OK);
break;
}
}
return 0;
}
// Paint message
case WM_PAINT:
{
BeginPaint(hwnd, &ps);
EndPaint(hwnd, &ps);
return 0;
}
// Destroy message
case WM_DESTROY:
return 0;
// Close message
case WM_CLOSE:
PostQuitMessage(0);
return 0;
// Default handling
default:
break;
}
// Dispatch any unhandled messages
return DefWindowProc(hwnd, msg, wParam, lParam);
}
////////////////////////////////////////////////////////////////////////////////
/*!
@brief floating point rounding operation
@param n
the float
@return the integer that the float is closest to
*/
////////////////////////////////////////////////////////////////////////////////
int roundToInt(float n)
{
return (int) (n < 0.0F ? ceil(n - 0.5F) : floor(n + 0.5F));
}
////////////////////////////////////////////////////////////////////////////////
/*!
@brief floating point rounding operation
@param n
the float
@return the absolute value of the integer that the float is closest to
*/
////////////////////////////////////////////////////////////////////////////////
unsigned int roundToUInt(float n)
{
return (unsigned int) abs(roundToInt(n));
}