nuclear@60: #include nuclear@60: #include nuclear@60: #include "minwin.h" nuclear@61: #include "logger.h" nuclear@60: nuclear@60: #define GOATSCE_WCLASS "goatsce-window" nuclear@60: nuclear@60: struct MinWidget { nuclear@60: HWND win; nuclear@60: nuclear@60: MWCallback cbfunc; nuclear@60: void *cbcls; nuclear@60: nuclear@60: MinWidget() { win = 0; cbfunc = 0; cbcls = 0; } nuclear@60: }; nuclear@60: nuclear@60: static void init(); nuclear@61: static MinWidget *createwin(MinWidget *parent, const char *cls, const char *name, nuclear@61: unsigned int style, int x, int y, int xsz, int ysz); nuclear@60: static LRESULT CALLBACK handle_msg(HWND win, unsigned int msg, WPARAM wparam, LPARAM lparam); nuclear@60: nuclear@61: extern HINSTANCE hinst; // defined in maxgoat.cc nuclear@61: nuclear@60: void mw_set_callback(MinWidget *w, MWCallback func, void *cls) nuclear@60: { nuclear@60: w->cbfunc = func; nuclear@60: w->cbcls = cls; nuclear@60: } nuclear@60: nuclear@61: MinWidget *mw_create_window(MinWidget *parent, const char *name, int x, int y, int xsz, int ysz) nuclear@60: { nuclear@61: unsigned int style = WS_OVERLAPPEDWINDOW | WS_VISIBLE; nuclear@61: if(parent) { nuclear@61: style |= WS_CHILD; nuclear@61: } nuclear@60: nuclear@61: maxlog("creating window: %s\n", name); nuclear@60: nuclear@61: MinWidget *w = createwin(parent, GOATSCE_WCLASS, name, style, x, y, xsz, ysz); nuclear@60: return w; nuclear@60: } nuclear@60: nuclear@60: MinWidget *mw_create_button(MinWidget *parent, const char *text, int x, int y, int xsz, int ysz) nuclear@60: { nuclear@61: unsigned int style = BS_PUSHBUTTON | WS_VISIBLE; nuclear@61: if(parent) { nuclear@61: style |= WS_CHILD; nuclear@61: } nuclear@60: nuclear@61: maxlog("creating button: %s\n", text); nuclear@60: nuclear@61: MinWidget *w = createwin(parent, "BUTTON", text, style, x, y, xsz, ysz); nuclear@61: return w; nuclear@60: } nuclear@60: nuclear@61: MinWidget *mw_create_checkbox(MinWidget *parent, const char *text, int x, int y, int xsz, int ysz, bool checked) nuclear@60: { nuclear@61: unsigned int style = BS_CHECKBOX | WS_VISIBLE; nuclear@61: if(parent) { nuclear@61: style |= WS_CHILD; nuclear@61: } nuclear@61: nuclear@61: maxlog("creating checkbox: %s\n", text); nuclear@61: nuclear@61: MinWidget *w = createwin(parent, "CHECKBOX", text, style, x, y, xsz, ysz); nuclear@61: return w; nuclear@60: } nuclear@60: nuclear@61: static DWORD WINAPI gui_thread_func(void *cls); nuclear@60: nuclear@60: void mw_test() nuclear@60: { nuclear@61: init(); nuclear@61: nuclear@61: HANDLE thread = CreateThread(0, 0, gui_thread_func, 0, 0, 0); nuclear@61: //WaitForSingleObject(thread, 5000); nuclear@61: } nuclear@61: nuclear@61: static DWORD WINAPI gui_thread_func(void *cls) nuclear@61: { nuclear@61: MinWidget *win = mw_create_window(0, "test window!", -1, -1, 400, 400); nuclear@61: MinWidget *bn_ok = mw_create_button(win, "Ok", 50, 100, 150, 40); nuclear@61: MinWidget *bn_cancel = mw_create_button(win, "Cancel", 250, 100, 150, 40); nuclear@61: MinWidget *ck_lights = mw_create_checkbox(win, "Export lights", 20, 20, 250, 40, true); nuclear@61: MinWidget *ck_cameras = mw_create_checkbox(win, "Export cameras", 20, 60, 250, 40, true); nuclear@61: nuclear@61: MSG msg; nuclear@61: while(GetMessage(&msg, win->win, 0, 0)) { nuclear@61: TranslateMessage(&msg); nuclear@61: DispatchMessage(&msg); nuclear@61: } nuclear@61: nuclear@61: DestroyWindow(win->win); nuclear@61: delete bn_ok; nuclear@61: delete bn_cancel; nuclear@61: delete ck_lights; nuclear@61: delete ck_cameras; nuclear@61: delete win; nuclear@61: nuclear@61: return 0; nuclear@60: } nuclear@60: nuclear@60: static void init() nuclear@60: { nuclear@60: static bool done_init; nuclear@60: if(done_init) { nuclear@60: return; nuclear@60: } nuclear@60: done_init = true; nuclear@60: nuclear@61: size_t sz = mbstowcs(0, GOATSCE_WCLASS, 0); nuclear@61: wchar_t *cname = new wchar_t[sz + 1]; nuclear@61: mbstowcs(cname, GOATSCE_WCLASS, sz + 1); nuclear@60: nuclear@61: WNDCLASS wc; nuclear@60: memset(&wc, 0, sizeof wc); nuclear@61: wc.lpszClassName = cname; nuclear@60: wc.hInstance = hinst; nuclear@60: wc.lpfnWndProc = handle_msg; nuclear@60: wc.style = CS_HREDRAW | CS_VREDRAW; nuclear@61: wc.hbrBackground = (HBRUSH)COLOR_WINDOW; nuclear@61: wc.hCursor = LoadCursor(0, IDC_ARROW); nuclear@60: nuclear@61: RegisterClass(&wc); nuclear@60: } nuclear@60: nuclear@61: static MinWidget *createwin(MinWidget *parent, const char *cls, const char *name, nuclear@61: unsigned int style, int x, int y, int xsz, int ysz) nuclear@61: { nuclear@61: init(); nuclear@61: nuclear@61: MinWidget *w = new MinWidget; nuclear@61: nuclear@61: size_t sz = mbstowcs(0, cls, 0); nuclear@61: wchar_t *wcls = new wchar_t[sz + 1]; nuclear@61: mbstowcs(wcls, cls, sz + 1); nuclear@61: nuclear@61: sz = mbstowcs(0, name, 0); nuclear@61: wchar_t *wname = new wchar_t[sz + 1]; nuclear@61: mbstowcs(wname, name, sz + 1); nuclear@61: nuclear@61: if(x <= 0) x = CW_USEDEFAULT; nuclear@61: if(y <= 0) y = CW_USEDEFAULT; nuclear@61: nuclear@61: w->win = CreateWindow(wcls, wname, style, x, y, xsz, ysz, parent ? parent->win : 0, 0, hinst, 0); nuclear@61: nuclear@61: delete [] wcls; nuclear@61: delete [] wname; nuclear@61: nuclear@61: if(!w->win) { nuclear@61: delete w; nuclear@61: return 0; nuclear@61: } nuclear@61: return w; nuclear@61: } nuclear@61: nuclear@61: nuclear@60: static LRESULT CALLBACK handle_msg(HWND win, unsigned int msg, WPARAM wparam, LPARAM lparam) nuclear@60: { nuclear@60: switch(msg) { nuclear@60: case WM_CLOSE: nuclear@60: DestroyWindow(win); nuclear@60: break; nuclear@60: nuclear@60: default: nuclear@60: return DefWindowProc(win, msg, wparam, lparam); nuclear@60: } nuclear@60: nuclear@60: return 0; nuclear@60: }