-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui.cpp
211 lines (174 loc) · 4.96 KB
/
ui.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#include "ui.h"
#include <string>
#include <sstream>
#include "addons/export3ds.h"
#include "addons/exportTexture.h"
#include "drawbmd.h"
#include "oglblock.h"
#include <iostream>
#ifdef _WIN32
#include <windows.h>
#undef min
#undef max
#include "textbox.h"
//TODO: this is ugly, do this somehow else
void loadFile(const std::string& name, bool merge = false);
extern HWND getHWnd(); //in simple_gl.cpp
#endif
#include "main.h"
#ifdef _WIN32
void unimplemented(const std::string& str)
{
MessageBox(getHWnd(), str.c_str(), "Unimplemeted:", MB_OK);
}
std::string getOpenFilename(const std::string& title = "Open",
const char* filter = "All Files\0*.*\0")
{
static bool s_isInitialized = false;
static OPENFILENAME s_openFileName;
static char buffer[MAX_PATH];
if(!s_isInitialized)
{
ZeroMemory(&s_openFileName, sizeof(s_openFileName));
s_openFileName.lStructSize = sizeof(s_openFileName);
s_openFileName.hwndOwner = getHWnd();
s_openFileName.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_EXPLORER;
s_openFileName.lpstrFile = buffer;
s_openFileName.nMaxFile = MAX_PATH;
s_openFileName.lpstrDefExt = "XXX"; //this way extensions are appended
s_isInitialized = true;
}
s_openFileName.lpstrTitle = title.c_str();
s_openFileName.lpstrFilter = filter;
if(GetOpenFileName(&s_openFileName))
{
return s_openFileName.lpstrFile;
}
else
return "";
}
std::string getSaveFilename(const std::string& title = "Save",
const char* filter = "All Files\0*.*\0")
{
static bool s_isInitialized = false;
static OPENFILENAME s_saveFileName;
static char buffer[MAX_PATH];
if(!s_isInitialized)
{
ZeroMemory(&s_saveFileName, sizeof(s_saveFileName));
s_saveFileName.lStructSize = sizeof(s_saveFileName);
s_saveFileName.hwndOwner = getHWnd();
s_saveFileName.Flags = OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY | OFN_EXPLORER;
s_saveFileName.lpstrFile = buffer;
s_saveFileName.nMaxFile = MAX_PATH;
s_saveFileName.lpstrDefExt = "XXX"; //this way extensions are appended
s_isInitialized = true;
}
s_saveFileName.lpstrTitle = title.c_str();
s_saveFileName.lpstrFilter = filter;
if(GetSaveFileName(&s_saveFileName))
{
return s_saveFileName.lpstrFile;
}
else
return "";
}
void menuFileOpenModel()
{
std::string name = getOpenFilename("Open model",
"BModel (*.bmd, *.bdl)\0*.bmd;*.bdl\0");
if(name != "")
loadFile(name);
}
void menuFileMergeModel()
{
std::string name = getOpenFilename("Merge model",
"BModel (*.bmd, *.bdl)\0*.bmd;*.bdl\0");
if(name != "")
loadFile(name, true);
}
void menuFileOpenAnimation()
{
std::string name = getOpenFilename("Open animation",
"All animations (*.bck, *.btp)\0*.bck;*.btp\0"
"Bone animation (*.bck)\0*.bck\0"
"Texture animation (*.btp)\0*.btp\0");
if(name != "")
loadFile(name);
}
void menuFileExportModel()
{
std::string name = getSaveFilename("Export model", "3ds files\0*.3ds\0");
if(name != "")
menuFileExportModel(name);
}
void menuFileExportTextures()
{
std::string filename = getSaveFilename("Enter textures basename",
"dds files\0*.dds\0tga files\0*.tga\0");
if(filename != "")
menuFileExportTextures(filename);
}
#endif
void menuFileExportModel(const std::string& filename)
{
if(g_models.back().bmd != NULL)
exportAs3ds(*g_models.back().bmd, filename);
else
warn("Failed to export %s, no model loaded", filename.c_str());
}
void menuFileExportTextures(const std::string& filename)
{
if(g_models.back().bmd != NULL)
{
std::string name, extension;
splitName(filename, name, extension);
std::transform(extension.begin(), extension.end(), extension.begin(),
tolower);
if(extension == "dds")
exportTextures(DDS, g_models.back().bmd->tex1, name);
else if(extension == "tga")
exportTextures(TGA, g_models.back().bmd->tex1, name);
else
warn("Failed to export textures, unknown extension \"%s\"",
extension.c_str());
}
else
warn("Failed to export textures to \"%s\", no model loaded",
filename.c_str());
}
void menuFileExportShaders()
{
if(g_models.back().oglBlock != NULL)
saveShaderStrings(*g_models.back().oglBlock, g_models.back().bmdFileName);
}
void menuFileReimportShaders()
{
if(g_models.back().oglBlock != NULL)
loadShaderStrings(*g_models.back().oglBlock, g_models.back().bmdFileName);
}
void menuFileRegenerateShaders()
{
if(g_models.back().oglBlock != NULL)
generateShaderStrings(*g_models.back().oglBlock,
g_models.back().bmd->mat3);
}
void menuDebugSectioninfo()
{
if(g_models.back().oglBlock != NULL) //model loaded?
{
FILE* f = fopen(g_models.back().bmdFileName.c_str(), "rb");
if(f != NULL)
{
std::ostringstream out;
writeBmdInfo(f, out);
fclose(f);
#ifdef _WIN32
TextBox(getHWnd(), out.str().c_str(), "Bmd sections",
MB_OK | TB_USEFIXEDFONT);
#else
std::cout << out.str();
#endif
}
}
}