1#define GF_EXPOSE_DRAW_PLATFORM
26LRESULT CALLBACK gf_draw_platform_proc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
32 BeginPaint(hWnd, &ps);
37 GetClientRect(hWnd, &rect);
40 draw->
width = rect.right - rect.left;
41 draw->
height = rect.bottom - rect.top;
46 if(draw->
input != NULL) {
53 if(draw->
input != NULL) {
54 if(msg == WM_LBUTTONDOWN) {
65 if(draw->
input != NULL) {
66 if(msg == WM_MBUTTONDOWN) {
77 if(draw->
input != NULL) {
78 if(msg == WM_RBUTTONDOWN) {
94 return DefWindowProc(hWnd, msg, wp, lp);
104 while(PeekMessage(&msg, draw->
platform->window, 0, 0, PM_NOREMOVE)) {
105 if(GetMessage(&msg, draw->
platform->window, 0, 0)) {
106 TranslateMessage(&msg);
107 DispatchMessage(&msg);
128 memset(platform, 0,
sizeof(*platform));
129 platform->engine = engine;
131 platform->instance = (HINSTANCE)GetModuleHandle(NULL);
132 if(platform->instance == NULL) {
138 wc.cbSize =
sizeof(wc);
139 wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
140 wc.lpfnWndProc = gf_draw_platform_proc;
143 wc.hInstance = platform->instance;
144 wc.hIcon = LoadIcon(platform->instance,
"GAME");
145 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
146 wc.hbrBackground = NULL;
147 wc.lpszMenuName = NULL;
148 wc.lpszClassName =
"goldfish";
149 wc.hIconSm = LoadIcon(platform->instance,
"GAME");
150 if(!RegisterClassEx(&wc)) {
156 platform->window = CreateWindow(
"goldfish", draw->
title, (WS_OVERLAPPEDWINDOW), draw->
x, draw->
y, draw->
width, draw->
height, NULL, 0, platform->instance, NULL);
157 if(platform->window == NULL) {
163 SetWindowLongPtr(platform->window, GWLP_USERDATA, (LONG_PTR)draw);
165 platform->dc = GetDC(platform->window);
169 style = (DWORD)GetWindowLongPtr(platform->window, GWL_STYLE);
170 AdjustWindowRect(&rect, style, FALSE);
171 SetWindowPos(platform->window, NULL, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, SWP_NOMOVE);
173 ShowWindow(platform->window, SW_NORMAL);
174 UpdateWindow(platform->window);
180 if(platform->dc != NULL) {
181 ReleaseDC(platform->window, platform->dc);
183 if(platform->window != NULL) {
184 DestroyWindow(platform->window);
186 gf_log_function(platform->engine,
"Destroyed platform-dependent part of drawing driver",
"");
void gf_draw_frame(gf_draw_t *draw)
Draw frame (common part)
void gf_draw_reshape(gf_draw_t *draw)
Do stuffs required on resizing window.
void gf_draw_driver_before(gf_draw_t *draw)
Called before gf_draw_frame.
void gf_draw_driver_after(gf_draw_t *draw)
Called after gf_draw_frame.
#define gf_log_function(engine, fmt,...)
Output log with line number and function name.
Required headers before anything.
gf_input_t * input
Input interface.
char title[128]
Window title.
int close
1 if it was requested to be closed, otherwise 0
gf_draw_platform_t * platform
Platform-dependent part of drawing driver.
int width
Width of window.
int height
Height of window.