goat3d

changeset 61:fdece14403ff

max gui
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 31 Mar 2014 09:41:47 +0300
parents 0c3576325480
children 55571a390144
files exporters/maxgoat/maxgoat.rc exporters/maxgoat/maxgoat.vcxproj exporters/maxgoat/maxgoat.vcxproj.filters exporters/maxgoat/msglogo3d.bmp exporters/maxgoat/resource.h exporters/maxgoat/src/logger.cc exporters/maxgoat/src/logger.h exporters/maxgoat/src/maxgoat.cc exporters/maxgoat/src/minwin.cc exporters/maxgoat/src/minwin.h
diffstat 10 files changed, 210 insertions(+), 37 deletions(-) [+]
line diff
     1.1 Binary file exporters/maxgoat/maxgoat.rc has changed
     2.1 --- a/exporters/maxgoat/maxgoat.vcxproj	Sun Mar 30 08:53:33 2014 +0300
     2.2 +++ b/exporters/maxgoat/maxgoat.vcxproj	Mon Mar 31 09:41:47 2014 +0300
     2.3 @@ -100,7 +100,7 @@
     2.4        <Optimization>Disabled</Optimization>
     2.5        <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;MAXGOAT_EXPORTS;%(PreprocessorDefinitions);BUILD_MAXPLUGIN</PreprocessorDefinitions>
     2.6        <DisableSpecificWarnings>4996;4244</DisableSpecificWarnings>
     2.7 -      <AdditionalIncludeDirectories>$(SolutionDir)\src</AdditionalIncludeDirectories>
     2.8 +      <AdditionalIncludeDirectories>$(SolutionDir)\src;$(ProjectDir)</AdditionalIncludeDirectories>
     2.9      </ClCompile>
    2.10      <Link>
    2.11        <SubSystem>Windows</SubSystem>
    2.12 @@ -140,7 +140,7 @@
    2.13        <IntrinsicFunctions>true</IntrinsicFunctions>
    2.14        <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;MAXGOAT_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    2.15        <DisableSpecificWarnings>4996;4244</DisableSpecificWarnings>
    2.16 -      <AdditionalIncludeDirectories>$(SolutionDir)\src</AdditionalIncludeDirectories>
    2.17 +      <AdditionalIncludeDirectories>$(SolutionDir)\src;$(ProjectDir)</AdditionalIncludeDirectories>
    2.18      </ClCompile>
    2.19      <Link>
    2.20        <SubSystem>Windows</SubSystem>
    2.21 @@ -155,12 +155,22 @@
    2.22      </PostBuildEvent>
    2.23    </ItemDefinitionGroup>
    2.24    <ItemGroup>
    2.25 +    <ClCompile Include="src\logger.cc" />
    2.26      <ClCompile Include="src\maxgoat.cc" />
    2.27      <ClCompile Include="src\minwin.cc" />
    2.28    </ItemGroup>
    2.29    <ItemGroup>
    2.30 +    <ClInclude Include="resource.h" />
    2.31 +    <ClInclude Include="src\logger.h" />
    2.32      <ClInclude Include="src\minwin.h" />
    2.33    </ItemGroup>
    2.34 +  <ItemGroup>
    2.35 +    <ResourceCompile Include="maxgoat.rc" />
    2.36 +  </ItemGroup>
    2.37 +  <ItemGroup>
    2.38 +    <None Include="msglogo3d.bmp" />
    2.39 +    <None Include="msglogo3d.png" />
    2.40 +  </ItemGroup>
    2.41    <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
    2.42    <ImportGroup Label="ExtensionTargets">
    2.43    </ImportGroup>
     3.1 --- a/exporters/maxgoat/maxgoat.vcxproj.filters	Sun Mar 30 08:53:33 2014 +0300
     3.2 +++ b/exporters/maxgoat/maxgoat.vcxproj.filters	Mon Mar 31 09:41:47 2014 +0300
     3.3 @@ -13,10 +13,26 @@
     3.4      <ClCompile Include="src\minwin.cc">
     3.5        <Filter>src</Filter>
     3.6      </ClCompile>
     3.7 +    <ClCompile Include="src\logger.cc">
     3.8 +      <Filter>src</Filter>
     3.9 +    </ClCompile>
    3.10    </ItemGroup>
    3.11    <ItemGroup>
    3.12      <ClInclude Include="src\minwin.h">
    3.13        <Filter>src</Filter>
    3.14      </ClInclude>
    3.15 +    <ClInclude Include="src\logger.h">
    3.16 +      <Filter>src</Filter>
    3.17 +    </ClInclude>
    3.18 +    <ClInclude Include="resource.h">
    3.19 +      <Filter>src</Filter>
    3.20 +    </ClInclude>
    3.21 +  </ItemGroup>
    3.22 +  <ItemGroup>
    3.23 +    <ResourceCompile Include="maxgoat.rc" />
    3.24 +  </ItemGroup>
    3.25 +  <ItemGroup>
    3.26 +    <None Include="msglogo3d.png" />
    3.27 +    <None Include="msglogo3d.bmp" />
    3.28    </ItemGroup>
    3.29  </Project>
    3.30 \ No newline at end of file
     4.1 Binary file exporters/maxgoat/msglogo3d.bmp has changed
     5.1 Binary file exporters/maxgoat/resource.h has changed
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/exporters/maxgoat/src/logger.cc	Mon Mar 31 09:41:47 2014 +0300
     6.3 @@ -0,0 +1,31 @@
     6.4 +#include <stdio.h>
     6.5 +#include <stdarg.h>
     6.6 +#include "logger.h"
     6.7 +
     6.8 +static FILE *logfile;
     6.9 +
    6.10 +bool maxlog_open(const char *fname)
    6.11 +{
    6.12 +	if(!(logfile = fopen(fname, "wb"))) {
    6.13 +		return false;
    6.14 +	}
    6.15 +	setvbuf(logfile, 0, _IONBF, 0);
    6.16 +	return true;
    6.17 +}
    6.18 +
    6.19 +void maxlog_close()
    6.20 +{
    6.21 +	if(logfile) {
    6.22 +		fclose(logfile);
    6.23 +	}
    6.24 +}
    6.25 +
    6.26 +void maxlog(const char *fmt, ...)
    6.27 +{
    6.28 +	if(!logfile) return;
    6.29 +
    6.30 +	va_list ap;
    6.31 +	va_start(ap, fmt);
    6.32 +	vfprintf(logfile, fmt, ap);
    6.33 +	va_end(ap);
    6.34 +}
    6.35 \ No newline at end of file
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/exporters/maxgoat/src/logger.h	Mon Mar 31 09:41:47 2014 +0300
     7.3 @@ -0,0 +1,8 @@
     7.4 +#ifndef MAXLOGGER_H_
     7.5 +#define MAXLOGGER_H_
     7.6 +
     7.7 +bool maxlog_open(const char *fname);
     7.8 +void maxlog_close();
     7.9 +void maxlog(const char *fmt, ...);
    7.10 +
    7.11 +#endif	/* MAXLOGGER_H_ */
    7.12 \ No newline at end of file
     8.1 --- a/exporters/maxgoat/src/maxgoat.cc	Sun Mar 30 08:53:33 2014 +0300
     8.2 +++ b/exporters/maxgoat/src/maxgoat.cc	Mon Mar 31 09:41:47 2014 +0300
     8.3 @@ -15,6 +15,8 @@
     8.4  #include "goat3d.h"
     8.5  #include "minwin.h"
     8.6  #include "config.h"
     8.7 +#include "logger.h"
     8.8 +#include "resource.h"
     8.9  
    8.10  
    8.11  #pragma comment (lib, "core.lib")
    8.12 @@ -32,8 +34,7 @@
    8.13  #define VERSION(major, minor) \
    8.14  	((major) * 100 + ((minor) < 10 ? (minor) * 10 : (minor)))
    8.15  
    8.16 -static FILE *logfile;
    8.17 -static HINSTANCE hinst;
    8.18 +HINSTANCE hinst;
    8.19  
    8.20  class GoatExporter : public SceneExport {
    8.21  private:
    8.22 @@ -116,10 +117,45 @@
    8.23  	MessageBoxA(win, "Goat3D exporter plugin", "About this plugin", 0);
    8.24  }
    8.25  
    8.26 +static INT_PTR CALLBACK handle_dlg_events(HWND win, unsigned int msg, WPARAM wparam, LPARAM lparam)
    8.27 +{
    8.28 +	switch(msg) {
    8.29 +	case WM_INITDIALOG:
    8.30 +		CheckDlgButton(win, IDC_GOAT_NODES, 1);
    8.31 +		CheckDlgButton(win, IDC_GOAT_MESHES, 1);
    8.32 +		CheckDlgButton(win, IDC_GOAT_LIGHTS, 1);
    8.33 +		CheckDlgButton(win, IDC_GOAT_CAMERAS, 1);
    8.34 +		break;
    8.35 +
    8.36 +	case WM_COMMAND:
    8.37 +		switch(LOWORD(wparam)) {
    8.38 +		case IDOK:
    8.39 +			EndDialog(win, 1);
    8.40 +			break;
    8.41 +
    8.42 +		case IDCANCEL:
    8.43 +			EndDialog(win, 0);
    8.44 +			break;
    8.45 +
    8.46 +		default:
    8.47 +			return 0;
    8.48 +		}
    8.49 +		break;
    8.50 +
    8.51 +	default:
    8.52 +		return 0;
    8.53 +	}
    8.54 +
    8.55 +	return 1;
    8.56 +}
    8.57 +
    8.58  int GoatExporter::DoExport(const MCHAR *name, ExpInterface *eiface, Interface *iface,
    8.59  		BOOL non_interactive, DWORD opt)
    8.60  {
    8.61 -	mw_test();
    8.62 +	if(!DialogBox(hinst, MAKEINTRESOURCE(IDD_GOAT_SCE), 0, handle_dlg_events)) {
    8.63 +		maxlog("canceled!\n");
    8.64 +		return IMPEXP_CANCEL;
    8.65 +	}
    8.66  
    8.67  	mtlmap.clear();
    8.68  	nodemap.clear();
    8.69 @@ -127,9 +163,9 @@
    8.70  	char fname[512];
    8.71  	wcstombs(fname, name, sizeof fname - 1);
    8.72  
    8.73 -	fprintf(logfile, "Exporting Goat3D Scene (text) file: %s\n", fname);
    8.74 +	maxlog("Exporting Goat3D Scene (text) file: %s\n", fname);
    8.75  	if(!(igame = GetIGameInterface())) {
    8.76 -		fprintf(logfile, "failed to get the igame interface\n");
    8.77 +		maxlog("failed to get the igame interface\n");
    8.78  		return IMPEXP_FAIL;
    8.79  	}
    8.80  	IGameConversionManager *cm = GetConversionManager();
    8.81 @@ -451,18 +487,13 @@
    8.82  	SHGetFolderPathA(0, CSIDL_PERSONAL, 0, 0, path);
    8.83  	strcat(path, "/testexp.log");
    8.84  
    8.85 -	if((logfile = fopen(path, "w"))) {
    8.86 -		setvbuf(logfile, 0, _IONBF, 0);
    8.87 -	}
    8.88 +	maxlog_open(path);
    8.89  	return TRUE;
    8.90  }
    8.91  
    8.92  __declspec(dllexport) int LibShutdown()
    8.93  {
    8.94 -	if(logfile) {
    8.95 -		fclose(logfile);
    8.96 -		logfile = 0;
    8.97 -	}
    8.98 +	maxlog_close();
    8.99  	return TRUE;
   8.100  }
   8.101  
     9.1 --- a/exporters/maxgoat/src/minwin.cc	Sun Mar 30 08:53:33 2014 +0300
     9.2 +++ b/exporters/maxgoat/src/minwin.cc	Mon Mar 31 09:41:47 2014 +0300
     9.3 @@ -1,6 +1,7 @@
     9.4  #include <string.h>
     9.5  #include <windows.h>
     9.6  #include "minwin.h"
     9.7 +#include "logger.h"
     9.8  
     9.9  #define GOATSCE_WCLASS	"goatsce-window"
    9.10  
    9.11 @@ -14,48 +15,89 @@
    9.12  };
    9.13  
    9.14  static void init();
    9.15 +static MinWidget *createwin(MinWidget *parent, const char *cls, const char *name,
    9.16 +		unsigned int style, int x, int y, int xsz, int ysz);
    9.17  static LRESULT CALLBACK handle_msg(HWND win, unsigned int msg, WPARAM wparam, LPARAM lparam);
    9.18  
    9.19 +extern HINSTANCE hinst;	// defined in maxgoat.cc
    9.20 +
    9.21  void mw_set_callback(MinWidget *w, MWCallback func, void *cls)
    9.22  {
    9.23  	w->cbfunc = func;
    9.24  	w->cbcls = cls;
    9.25  }
    9.26  
    9.27 -MinWidget *mw_create_window(MinWidget *parent, const char *name)
    9.28 +MinWidget *mw_create_window(MinWidget *parent, const char *name, int x, int y, int xsz, int ysz)
    9.29  {
    9.30 -	MinWidget *w = new MinWidget;
    9.31 -	HINSTANCE inst = GetModuleHandle(0);
    9.32 +	unsigned int style = WS_OVERLAPPEDWINDOW | WS_VISIBLE;
    9.33 +	if(parent) {
    9.34 +		style |= WS_CHILD;
    9.35 +	}
    9.36  
    9.37 -	w->win = CreateWindowA(GOATSCE_WCLASS, "Goat3D Scene export options ...", WS_OVERLAPPED,
    9.38 -		CW_USEDEFAULT, CW_USEDEFAULT, 512, 400,	parent ? parent->win : 0, 0, inst, 0);
    9.39 -	ShowWindow(w->win, 1);
    9.40 +	maxlog("creating window: %s\n", name);
    9.41  
    9.42 +	MinWidget *w = createwin(parent, GOATSCE_WCLASS, name, style, x, y, xsz, ysz);
    9.43  	return w;
    9.44  }
    9.45  
    9.46  MinWidget *mw_create_button(MinWidget *parent, const char *text, int x, int y, int xsz, int ysz)
    9.47  {
    9.48 -	MinWidget *bn = new MinWidget;
    9.49 -	HINSTANCE inst = GetModuleHandle(0);
    9.50 +	unsigned int style = BS_PUSHBUTTON | WS_VISIBLE;
    9.51 +	if(parent) {
    9.52 +		style |= WS_CHILD;
    9.53 +	}
    9.54  
    9.55 -	bn->win = CreateWindowA("BUTTON", text, BS_PUSHBUTTON | BS_TEXT,
    9.56 -		x, y, xsz, ysz,	parent ? parent->win : 0, 0, inst, 0);
    9.57 -	ShowWindow(bn->win, 1);
    9.58 +	maxlog("creating button: %s\n", text);
    9.59  
    9.60 -	return bn;
    9.61 +	MinWidget *w = createwin(parent, "BUTTON", text, style, x, y, xsz, ysz);
    9.62 +	return w;
    9.63  }
    9.64  
    9.65 -MinWidget *mw_create_checkbox(MinWidget *parent, const char *text, int x, int y, int w, int h, bool checked)
    9.66 +MinWidget *mw_create_checkbox(MinWidget *parent, const char *text, int x, int y, int xsz, int ysz, bool checked)
    9.67  {
    9.68 -	return 0;
    9.69 +	unsigned int style = BS_CHECKBOX | WS_VISIBLE;
    9.70 +	if(parent) {
    9.71 +		style |= WS_CHILD;
    9.72 +	}
    9.73 +
    9.74 +	maxlog("creating checkbox: %s\n", text);
    9.75 +
    9.76 +	MinWidget *w = createwin(parent, "CHECKBOX", text, style, x, y, xsz, ysz);
    9.77 +	return w;
    9.78  }
    9.79  
    9.80 +static DWORD WINAPI gui_thread_func(void *cls);
    9.81  
    9.82  void mw_test()
    9.83  {
    9.84 -	MinWidget *win = mw_create_window(0, "test window!");
    9.85 -	MinWidget *bn = mw_create_button(win, "button!", 100, 100, 300, 80);
    9.86 +	init();
    9.87 +
    9.88 +	HANDLE thread = CreateThread(0, 0, gui_thread_func, 0, 0, 0);
    9.89 +	//WaitForSingleObject(thread, 5000);
    9.90 +}
    9.91 +
    9.92 +static DWORD WINAPI gui_thread_func(void *cls)
    9.93 +{
    9.94 +	MinWidget *win = mw_create_window(0, "test window!", -1, -1, 400, 400);
    9.95 +	MinWidget *bn_ok = mw_create_button(win, "Ok", 50, 100, 150, 40);
    9.96 +	MinWidget *bn_cancel = mw_create_button(win, "Cancel", 250, 100, 150, 40);
    9.97 +	MinWidget *ck_lights = mw_create_checkbox(win, "Export lights", 20, 20, 250, 40, true);
    9.98 +	MinWidget *ck_cameras = mw_create_checkbox(win, "Export cameras", 20, 60, 250, 40, true);
    9.99 +
   9.100 +	MSG msg;
   9.101 +	while(GetMessage(&msg, win->win, 0, 0)) {
   9.102 +		TranslateMessage(&msg);
   9.103 +		DispatchMessage(&msg);
   9.104 +	}
   9.105 +
   9.106 +	DestroyWindow(win->win);
   9.107 +	delete bn_ok;
   9.108 +	delete bn_cancel;
   9.109 +	delete ck_lights;
   9.110 +	delete ck_cameras;
   9.111 +	delete win;
   9.112 +
   9.113 +	return 0;
   9.114  }
   9.115  
   9.116  static void init()
   9.117 @@ -66,18 +108,53 @@
   9.118  	}
   9.119  	done_init = true;
   9.120  
   9.121 -	HINSTANCE hinst = GetModuleHandle(0);
   9.122 +	size_t sz = mbstowcs(0, GOATSCE_WCLASS, 0);
   9.123 +	wchar_t *cname = new wchar_t[sz + 1];
   9.124 +	mbstowcs(cname, GOATSCE_WCLASS, sz + 1);
   9.125  
   9.126 -	WNDCLASSA wc;
   9.127 +	WNDCLASS wc;
   9.128  	memset(&wc, 0, sizeof wc);
   9.129 -	wc.lpszClassName = GOATSCE_WCLASS;
   9.130 +	wc.lpszClassName = cname;
   9.131  	wc.hInstance = hinst;
   9.132  	wc.lpfnWndProc = handle_msg;
   9.133  	wc.style = CS_HREDRAW | CS_VREDRAW;
   9.134 +	wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
   9.135 +	wc.hCursor = LoadCursor(0, IDC_ARROW);
   9.136  
   9.137 -	RegisterClassA(&wc);
   9.138 +	RegisterClass(&wc);
   9.139  }
   9.140  
   9.141 +static MinWidget *createwin(MinWidget *parent, const char *cls, const char *name,
   9.142 +		unsigned int style, int x, int y, int xsz, int ysz)
   9.143 +{
   9.144 +	init();
   9.145 +
   9.146 +	MinWidget *w = new MinWidget;
   9.147 +
   9.148 +	size_t sz = mbstowcs(0, cls, 0);
   9.149 +	wchar_t *wcls = new wchar_t[sz + 1];
   9.150 +	mbstowcs(wcls, cls, sz + 1);
   9.151 +
   9.152 +	sz = mbstowcs(0, name, 0);
   9.153 +	wchar_t *wname = new wchar_t[sz + 1];
   9.154 +	mbstowcs(wname, name, sz + 1);
   9.155 +
   9.156 +	if(x <= 0) x = CW_USEDEFAULT;
   9.157 +	if(y <= 0) y = CW_USEDEFAULT;
   9.158 +
   9.159 +	w->win = CreateWindow(wcls, wname, style, x, y, xsz, ysz, parent ? parent->win : 0, 0, hinst, 0);
   9.160 +
   9.161 +	delete [] wcls;
   9.162 +	delete [] wname;
   9.163 +
   9.164 +	if(!w->win) {
   9.165 +		delete w;
   9.166 +		return 0;
   9.167 +	}
   9.168 +	return w;
   9.169 +}
   9.170 +
   9.171 +
   9.172  static LRESULT CALLBACK handle_msg(HWND win, unsigned int msg, WPARAM wparam, LPARAM lparam)
   9.173  {
   9.174  	switch(msg) {
    10.1 --- a/exporters/maxgoat/src/minwin.h	Sun Mar 30 08:53:33 2014 +0300
    10.2 +++ b/exporters/maxgoat/src/minwin.h	Mon Mar 31 09:41:47 2014 +0300
    10.3 @@ -6,9 +6,9 @@
    10.4  
    10.5  void mw_set_callback(MinWidget *w, MWCallback func, void *cls);
    10.6  
    10.7 -MinWidget *mw_create_window(MinWidget *parent, const char *name);
    10.8 -MinWidget *mw_create_button(MinWidget *parent, const char *text, int x, int y, int w, int h);
    10.9 -MinWidget *mw_create_checkbox(MinWidget *parent, const char *text, int x, int y, int w, int h, bool checked);
   10.10 +MinWidget *mw_create_window(MinWidget *parent, const char *name, int x, int y, int xsz, int ysz);
   10.11 +MinWidget *mw_create_button(MinWidget *parent, const char *text, int x, int y, int xsz, int ysz);
   10.12 +MinWidget *mw_create_checkbox(MinWidget *parent, const char *text, int x, int y, int xsz, int ysz, bool checked);
   10.13  
   10.14  void mw_test();
   10.15