goat3d

diff exporters/maxgoat/src/minwin.cc @ 61:fdece14403ff

max gui
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 31 Mar 2014 09:41:47 +0300
parents 0c3576325480
children
line diff
     1.1 --- a/exporters/maxgoat/src/minwin.cc	Sun Mar 30 08:53:33 2014 +0300
     1.2 +++ b/exporters/maxgoat/src/minwin.cc	Mon Mar 31 09:41:47 2014 +0300
     1.3 @@ -1,6 +1,7 @@
     1.4  #include <string.h>
     1.5  #include <windows.h>
     1.6  #include "minwin.h"
     1.7 +#include "logger.h"
     1.8  
     1.9  #define GOATSCE_WCLASS	"goatsce-window"
    1.10  
    1.11 @@ -14,48 +15,89 @@
    1.12  };
    1.13  
    1.14  static void init();
    1.15 +static MinWidget *createwin(MinWidget *parent, const char *cls, const char *name,
    1.16 +		unsigned int style, int x, int y, int xsz, int ysz);
    1.17  static LRESULT CALLBACK handle_msg(HWND win, unsigned int msg, WPARAM wparam, LPARAM lparam);
    1.18  
    1.19 +extern HINSTANCE hinst;	// defined in maxgoat.cc
    1.20 +
    1.21  void mw_set_callback(MinWidget *w, MWCallback func, void *cls)
    1.22  {
    1.23  	w->cbfunc = func;
    1.24  	w->cbcls = cls;
    1.25  }
    1.26  
    1.27 -MinWidget *mw_create_window(MinWidget *parent, const char *name)
    1.28 +MinWidget *mw_create_window(MinWidget *parent, const char *name, int x, int y, int xsz, int ysz)
    1.29  {
    1.30 -	MinWidget *w = new MinWidget;
    1.31 -	HINSTANCE inst = GetModuleHandle(0);
    1.32 +	unsigned int style = WS_OVERLAPPEDWINDOW | WS_VISIBLE;
    1.33 +	if(parent) {
    1.34 +		style |= WS_CHILD;
    1.35 +	}
    1.36  
    1.37 -	w->win = CreateWindowA(GOATSCE_WCLASS, "Goat3D Scene export options ...", WS_OVERLAPPED,
    1.38 -		CW_USEDEFAULT, CW_USEDEFAULT, 512, 400,	parent ? parent->win : 0, 0, inst, 0);
    1.39 -	ShowWindow(w->win, 1);
    1.40 +	maxlog("creating window: %s\n", name);
    1.41  
    1.42 +	MinWidget *w = createwin(parent, GOATSCE_WCLASS, name, style, x, y, xsz, ysz);
    1.43  	return w;
    1.44  }
    1.45  
    1.46  MinWidget *mw_create_button(MinWidget *parent, const char *text, int x, int y, int xsz, int ysz)
    1.47  {
    1.48 -	MinWidget *bn = new MinWidget;
    1.49 -	HINSTANCE inst = GetModuleHandle(0);
    1.50 +	unsigned int style = BS_PUSHBUTTON | WS_VISIBLE;
    1.51 +	if(parent) {
    1.52 +		style |= WS_CHILD;
    1.53 +	}
    1.54  
    1.55 -	bn->win = CreateWindowA("BUTTON", text, BS_PUSHBUTTON | BS_TEXT,
    1.56 -		x, y, xsz, ysz,	parent ? parent->win : 0, 0, inst, 0);
    1.57 -	ShowWindow(bn->win, 1);
    1.58 +	maxlog("creating button: %s\n", text);
    1.59  
    1.60 -	return bn;
    1.61 +	MinWidget *w = createwin(parent, "BUTTON", text, style, x, y, xsz, ysz);
    1.62 +	return w;
    1.63  }
    1.64  
    1.65 -MinWidget *mw_create_checkbox(MinWidget *parent, const char *text, int x, int y, int w, int h, bool checked)
    1.66 +MinWidget *mw_create_checkbox(MinWidget *parent, const char *text, int x, int y, int xsz, int ysz, bool checked)
    1.67  {
    1.68 -	return 0;
    1.69 +	unsigned int style = BS_CHECKBOX | WS_VISIBLE;
    1.70 +	if(parent) {
    1.71 +		style |= WS_CHILD;
    1.72 +	}
    1.73 +
    1.74 +	maxlog("creating checkbox: %s\n", text);
    1.75 +
    1.76 +	MinWidget *w = createwin(parent, "CHECKBOX", text, style, x, y, xsz, ysz);
    1.77 +	return w;
    1.78  }
    1.79  
    1.80 +static DWORD WINAPI gui_thread_func(void *cls);
    1.81  
    1.82  void mw_test()
    1.83  {
    1.84 -	MinWidget *win = mw_create_window(0, "test window!");
    1.85 -	MinWidget *bn = mw_create_button(win, "button!", 100, 100, 300, 80);
    1.86 +	init();
    1.87 +
    1.88 +	HANDLE thread = CreateThread(0, 0, gui_thread_func, 0, 0, 0);
    1.89 +	//WaitForSingleObject(thread, 5000);
    1.90 +}
    1.91 +
    1.92 +static DWORD WINAPI gui_thread_func(void *cls)
    1.93 +{
    1.94 +	MinWidget *win = mw_create_window(0, "test window!", -1, -1, 400, 400);
    1.95 +	MinWidget *bn_ok = mw_create_button(win, "Ok", 50, 100, 150, 40);
    1.96 +	MinWidget *bn_cancel = mw_create_button(win, "Cancel", 250, 100, 150, 40);
    1.97 +	MinWidget *ck_lights = mw_create_checkbox(win, "Export lights", 20, 20, 250, 40, true);
    1.98 +	MinWidget *ck_cameras = mw_create_checkbox(win, "Export cameras", 20, 60, 250, 40, true);
    1.99 +
   1.100 +	MSG msg;
   1.101 +	while(GetMessage(&msg, win->win, 0, 0)) {
   1.102 +		TranslateMessage(&msg);
   1.103 +		DispatchMessage(&msg);
   1.104 +	}
   1.105 +
   1.106 +	DestroyWindow(win->win);
   1.107 +	delete bn_ok;
   1.108 +	delete bn_cancel;
   1.109 +	delete ck_lights;
   1.110 +	delete ck_cameras;
   1.111 +	delete win;
   1.112 +
   1.113 +	return 0;
   1.114  }
   1.115  
   1.116  static void init()
   1.117 @@ -66,18 +108,53 @@
   1.118  	}
   1.119  	done_init = true;
   1.120  
   1.121 -	HINSTANCE hinst = GetModuleHandle(0);
   1.122 +	size_t sz = mbstowcs(0, GOATSCE_WCLASS, 0);
   1.123 +	wchar_t *cname = new wchar_t[sz + 1];
   1.124 +	mbstowcs(cname, GOATSCE_WCLASS, sz + 1);
   1.125  
   1.126 -	WNDCLASSA wc;
   1.127 +	WNDCLASS wc;
   1.128  	memset(&wc, 0, sizeof wc);
   1.129 -	wc.lpszClassName = GOATSCE_WCLASS;
   1.130 +	wc.lpszClassName = cname;
   1.131  	wc.hInstance = hinst;
   1.132  	wc.lpfnWndProc = handle_msg;
   1.133  	wc.style = CS_HREDRAW | CS_VREDRAW;
   1.134 +	wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
   1.135 +	wc.hCursor = LoadCursor(0, IDC_ARROW);
   1.136  
   1.137 -	RegisterClassA(&wc);
   1.138 +	RegisterClass(&wc);
   1.139  }
   1.140  
   1.141 +static MinWidget *createwin(MinWidget *parent, const char *cls, const char *name,
   1.142 +		unsigned int style, int x, int y, int xsz, int ysz)
   1.143 +{
   1.144 +	init();
   1.145 +
   1.146 +	MinWidget *w = new MinWidget;
   1.147 +
   1.148 +	size_t sz = mbstowcs(0, cls, 0);
   1.149 +	wchar_t *wcls = new wchar_t[sz + 1];
   1.150 +	mbstowcs(wcls, cls, sz + 1);
   1.151 +
   1.152 +	sz = mbstowcs(0, name, 0);
   1.153 +	wchar_t *wname = new wchar_t[sz + 1];
   1.154 +	mbstowcs(wname, name, sz + 1);
   1.155 +
   1.156 +	if(x <= 0) x = CW_USEDEFAULT;
   1.157 +	if(y <= 0) y = CW_USEDEFAULT;
   1.158 +
   1.159 +	w->win = CreateWindow(wcls, wname, style, x, y, xsz, ysz, parent ? parent->win : 0, 0, hinst, 0);
   1.160 +
   1.161 +	delete [] wcls;
   1.162 +	delete [] wname;
   1.163 +
   1.164 +	if(!w->win) {
   1.165 +		delete w;
   1.166 +		return 0;
   1.167 +	}
   1.168 +	return w;
   1.169 +}
   1.170 +
   1.171 +
   1.172  static LRESULT CALLBACK handle_msg(HWND win, unsigned int msg, WPARAM wparam, LPARAM lparam)
   1.173  {
   1.174  	switch(msg) {