2 #include <msp/core/application.h>
3 #include <msp/core/systemerror.h>
5 #include "window_private.h"
11 LRESULT CALLBACK wndproc_(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
15 CREATESTRUCT *cs = reinterpret_cast<CREATESTRUCT *>(lparam);
16 SetWindowLong(hwnd, 0, reinterpret_cast<LONG>(cs->lpCreateParams));
20 Msp::Graphics::Window *wnd = reinterpret_cast<Msp::Graphics::Window *>(GetWindowLong(hwnd, 0));
21 Msp::Graphics::Window::Event ev;
25 if(wnd && wnd->event(ev))
29 return DefWindowProc(hwnd, msg, wparam, lparam);
37 void Window::platform_init()
39 static bool wndclass_created = false;
45 wndcl.cbSize = sizeof(WNDCLASSEX);
47 wndcl.lpfnWndProc = &wndproc_;
49 wndcl.cbWndExtra = sizeof(Window *);
50 wndcl.hInstance = reinterpret_cast<HINSTANCE>(Application::get_data());
52 wndcl.hCursor = LoadCursor(0, IDC_ARROW);
53 wndcl.hbrBackground = 0;
54 wndcl.lpszMenuName = 0;
55 wndcl.lpszClassName = "mspgui";
58 if(!RegisterClassEx(&wndcl))
59 throw system_error("RegisterClassEx");
61 wndclass_created = true;
65 SetRect(&rect, 0, 0, options.width, options.height);
67 int style = (options.fullscreen ? WS_POPUP : WS_OVERLAPPEDWINDOW);
68 if(!options.resizable)
69 style &= ~WS_THICKFRAME;
70 int exstyle = (options.fullscreen ? WS_EX_APPWINDOW : WS_EX_OVERLAPPEDWINDOW);
71 AdjustWindowRectEx(&rect, style, false, exstyle);
73 priv->window = CreateWindowEx(exstyle,
77 CW_USEDEFAULT, CW_USEDEFAULT,
78 rect.right-rect.left, rect.bottom-rect.top,
81 reinterpret_cast<HINSTANCE>(Application::get_data()),
84 throw system_error("CreateWindowEx");
87 void Window::platform_cleanup()
90 CloseWindow(priv->window);
93 void Window::set_title(const string &title)
95 SetWindowText(priv->window, title.c_str());
98 void Window::platform_reconfigure(bool fullscreen_changed)
101 SetRect(&rect, 0, 0, options.width, options.height);
103 int style = (options.fullscreen ? WS_POPUP : WS_OVERLAPPEDWINDOW);
104 if(!options.resizable)
105 style &= ~WS_THICKFRAME;
106 int exstyle = (options.fullscreen ? WS_EX_APPWINDOW : WS_EX_OVERLAPPEDWINDOW);
107 AdjustWindowRectEx(&rect, style, false, exstyle);
109 if(fullscreen_changed)
112 SetWindowLong(priv->window, GWL_EXSTYLE, exstyle);
113 SetWindowLong(priv->window, GWL_STYLE, style);
117 if(options.fullscreen)
118 SetWindowPos(priv->window, 0, 0, 0, rect.right-rect.left, rect.bottom-rect.top, SWP_NOZORDER);
120 SetWindowPos(priv->window, 0, 0, 0, rect.right-rect.left, rect.bottom-rect.top, SWP_NOMOVE|SWP_NOZORDER);
123 void Window::show_cursor(bool s)
128 void Window::warp_pointer(int, int)
132 void Window::platform_show()
134 ShowWindow(priv->window, SW_SHOWNORMAL);
137 void Window::platform_hide()
139 ShowWindow(priv->window, SW_HIDE);
142 bool Window::event(const Event &evnt)
156 signal_input_event.emit(evnt);
159 options.width = LOWORD(evnt.lparam);
160 options.height = HIWORD(evnt.lparam);
161 signal_resize.emit(options.width, options.height);
173 } // namespace Graphics