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 | LRESULT CALLBACK
windowProc(HWND window, UINT message, WPARAM wParam, LPARAM lParam)
{
LRESULT result = 0;
switch(message)
{
case WM_ACTIVATEAPP:
{
} break;
case WM_CLOSE:
case WM_DESTROY:
case WM_QUIT:
{
GlobalRunning = false;
AnimateWindow(window, 200, AW_SLIDE|AW_VER_NEGATIVE|AW_HIDE);
PostQuitMessage(0);
} break;
case WM_SIZE:
{
int width = LOWORD(lParam);
int height = HIWORD(lParam);
resizeBackBuffer(&GlobalBackBuffer, width, height);
}break;
case WM_PAINT:
{
PAINTSTRUCT paint = {};
HDC deviceContext = BeginPaint(window, &paint);
int width = paint.rcPaint.right - paint.rcPaint.left;
int height = paint.rcPaint.bottom - paint.rcPaint.top;
blitBackBuffer(&GlobalBackBuffer, deviceContext, width, height);
EndPaint(window, &paint);
} break;
case WM_SYSKEYDOWN:
case WM_KEYDOWN:
{
char buffer[256];
sprintf(buffer, "Keydown: wParam(%d) lParam(%d)\n", wParam, lParam);
OutputDebugStringA(buffer);
} break;
default:
{
result = DefWindowProcA(window, message, wParam, lParam);
}
}
return result;
}
int CALLBACK
WinMain(HINSTANCE instance, HINSTANCE prevInstance, LPSTR commandLine, int showCommand)
{
WNDCLASS windowClass = {};
windowClass.style = CS_HREDRAW | CS_VREDRAW;
windowClass.lpfnWndProc = windowProc;
// windowClass.cbClsExtra = ;
// windowClass.cbWndExtra = ;
windowClass.hInstance = instance;
// windowClass.hIcon = ;
windowClass.hCursor = LoadCursor(0, IDC_ARROW);
windowClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
// windowClass.lpszMenuName = ;
windowClass.lpszClassName = "EditorWindowClass";
if(!RegisterClass(&windowClass))
{
int error = GetLastError();
invalidCodePath;
return -1;
}
HWND window = CreateWindowEx(0,
windowClass.lpszClassName,
"pixeleditor",
WS_OVERLAPPEDWINDOW|WS_VISIBLE,
CW_USEDEFAULT, CW_USEDEFAULT, 960, 540,
0,
0,
instance,
0);
if(!window)
{
int error = GetLastError();
invalidCodePath;
return -2;
}
RECT windowDim;
GetClientRect(window, &windowDim);
int windowWidth = windowDim.right - windowDim.left;
int windowHeight = windowDim.bottom - windowDim.top;
initOpenGL(window);
resizeBackBuffer(&GlobalBackBuffer, windowWidth, windowHeight);
editor_code editorCode = loadEditorCode();
editor_state editorState = {};
editor_memory editorMemory = {};
editorMemory.debugReadFile = debugReadFile;
editorMemory.debugWriteFile = debugWriteFile;
editorMemory.debugFreeFile = debugFreeFile;
// ShowWindow(window, SW_SHOW);
// Note: AnimateWindow Documentation
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms632669(v=vs.85).aspx
// AnimateWindow(window, 200, AW_SLIDE|AW_VER_POSITIVE|AW_ACTIVATE);
// TODO: Our window seems to appear black
// This will be hopefully a temporary fix .........
// ........... Never mind ... it still doesn't work.
// InvalidateRect(window, &windowDim, false);
GlobalRunning = true;
while(GlobalRunning)
{
MSG message;
while(PeekMessage(&message, 0, 0, 0, PM_REMOVE))
{
TranslateMessage(&message);
DispatchMessageA(&message);
}
if(editorCode.updateAndRender)
{
editor_backbuffer editorBackBuffer = {};
editorBackBuffer.memory = GlobalBackBuffer.memory;
editorBackBuffer.width = GlobalBackBuffer.width;
editorBackBuffer.height = GlobalBackBuffer.height;
editorCode.updateAndRender(&editorState, &editorBackBuffer, &editorMemory);
}
HDC deviceContext = GetDC(window);
blitBackBuffer(&GlobalBackBuffer, deviceContext, GlobalBackBuffer.width, GlobalBackBuffer.height);
ReleaseDC(window, deviceContext);
}
return 0;
}
|