-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWindow.hpp
More file actions
99 lines (83 loc) · 2.74 KB
/
Copy pathWindow.hpp
File metadata and controls
99 lines (83 loc) · 2.74 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
#pragma once
#include <windows.h>
#include <string>
#include <vector>
#include <cstdlib>
#include <cassert>
#include <cmath> // for ceil, floor
#include "Color.hpp"
#define PI 3.1415926535897932384626433832795
enum MENU_ITEM { LINE_DDA = 0, LINE_BRESENHAM, LINE_ANIMATE, OBJECT_CIRCLE, OBJECT_ELLIPSE, NUM_MENU_ITEMS };
// Prototypes
/**
* @brief Window procedure to handle messages sent to the window.
*
* @param hwnd Handle to the window.
* @param msg Message identifier.
* @param wParam Additional message information.
* @param lParam Additional message information.
* @return LRESULT Result of the message processing.
*/
LRESULT CALLBACK MyWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
bool IsMenuItemActive(const enum MENU_ITEM menuItem);
void ClearFirstPoint();
void SetFirstPoint(unsigned int x, unsigned int y);
void SetMenuItem(HMENU hMenu, MENU_ITEM menuItem, UINT check);
void SetMousePosStr(DWORD x, DWORD y);
int roundToInt(float n);
unsigned int roundToUInt(float n);
// Data used by the Window Procedure
namespace
{
HWND gHwnd;
std::vector<bool> menuChecked(NUM_MENU_ITEMS, false);
std::string gFirstPosStr;
std::string gFirstPosPrefix = " First Point: ";
std::string gMousePosStr;
std::string gPosPrefix = "(";
std::string gPosSeparator = ", ";
std::string gPosSuffix = ")";
} // namespace anon
namespace CGF
{
////////////////////////////////////////////////////////////////////////////////
/*!
@class Window
@brief Launches a window in the Win32 environment
*/
////////////////////////////////////////////////////////////////////////////////
class Window
{
public:
Window();
~Window();
bool Create(HINSTANCE hInstance, const std::string & windowName, const unsigned int width, const unsigned int height);
unsigned int Width() const;
unsigned int Height() const;
void SetPixel(const unsigned int x, const unsigned int y, const Color & color) const;
void ProcessMessages();
void Present();
bool Running() const;
private:
// Prevent copying
Window(const Window & rhs) = delete;
Window & operator=(const Window & rhs) = delete;
// Internal use
bool RegisterWndClass(HINSTANCE hInstance);
void UnregisterWndClass();
void CreateSecondaryBuffer(const unsigned int width, const unsigned int height);
unsigned int mWidth, mHeight;
bool mRunning;
// Main window
HWND mHwnd; // The window handle
HWND mHtoolbar; // The toolbar handle
HDC mHdc; // The device context of the window
HINSTANCE mWindowInstance; // The instance ID of the application
std::string mClassName;
// Secondary window
HBITMAP mBitmap;
HBITMAP mOldBitmap;
HDC mBitmapDC;
unsigned int * mSurface;
}; // class Window
} // namespace CGF