-
Notifications
You must be signed in to change notification settings - Fork 0
/
modelerui.fl
318 lines (291 loc) · 9.81 KB
/
modelerui.fl
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
# data file for the Fltk User Interface Designer (fluid)
version 1.0107
header_name {.h}
code_name {.cxx}
class ModelerUserInterface {open
} {
Function {ModelerUserInterface()} {open
} {
Fl_Window m_controlsWindow {
label {CSE457 Modeler}
callback {ModelerUserInterface* pUI = (ModelerUserInterface*)(o->user_data());
if(Fl::e_number == FL_CLOSE) {
pUI->m_controlsWindow->hide();
pUI->m_modelerWindow->hide();
}} open
xywh {467 443 395 326} type Double when 0 hide resizable
} {
Fl_Menu_Bar m_controlsMenuBar {open
xywh {0 0 395 25}
} {
Submenu {} {
label File open
xywh {0 0 100 20}
} {
MenuItem {} {
label {Save Raytracer File}
callback {const char *filename = fileDialog(Fl_Native_File_Chooser::BROWSE_SAVE_FILE,
"RAY File (*.ray)\\t*.ray",
"Save Raytracer File");
if(!filename)
return;
if(openRayFile(filename) == false) {
fl_alert("Error opening file.");
}
else {
m_modelerView->draw();
closeRayFile();
}} selected
xywh {0 0 100 20}
code0 {\#include "modelerview.h"}
code2 {\#include <FL/Fl_Message.H>}
}
MenuItem {} {
label {Save Image}
callback {const char* filename = fileDialog(Fl_Native_File_Chooser::BROWSE_SAVE_FILE,
"PNG Image File (*.png)\\t*.png\\nJPEG Image File (*.jpg)\\t*.jpg",
"Save Image");
if(!filename)
return;
int x = m_modelerView->x();
int y = m_modelerView->y();
int w = m_modelerView->w();
int h = m_modelerView->h();
m_modelerWindow->show();
m_modelerView->make_current();
m_modelerView->draw();
unsigned char *imageBuffer = new unsigned char[3*w*h];
// Tell openGL to read from the front buffer when capturing
// out paint strokes
glReadBuffer(GL_BACK);
glPixelStorei( GL_PACK_ALIGNMENT, 1 );
glPixelStorei( GL_PACK_ROW_LENGTH, w );
glReadPixels( 0, 0, w, h,
GL_RGB, GL_UNSIGNED_BYTE,
imageBuffer );
std::string strFileName = filename;
int fileType = m_nativeChooser->filter_value(); //0: PNG, 1: JPG
\#ifdef SAMPLE_SOLUTION
//maybe add something to tack on the right file extension if the user didn't use an appropriate filename for this image type
\#endif
int quality = 95;
if(fileType == 1) {
Dialog2 x(0,0,0,0,"ok");
quality = x.getValue();
}
save(filename, imageBuffer, w, h, fileType == 0 ? ".png" : ".jpg", quality);
delete [] imageBuffer;}
xywh {10 10 100 20} divider
code0 {\#include "modelerview.h"}
code1 {\#include <FL/Fl_Native_File_Chooser.H>}
code2 {\#include "dialog.h"}
code3 {\#include "imageio.h"}
}
MenuItem {} {
label {Open Position File}
callback {const char *filename = fileDialog(Fl_Native_File_Chooser::BROWSE_FILE,
"Position File (*.pos)\\t*.pos",
"Open Position File");
if(!filename)
return;
std::ifstream ifs( filename );
if( !ifs ) {
std::cerr << "Error: couldn't read position file " << filename << std::endl;
return;
}
float elevation, azimuth, dolly, twist, x, y, z;
ifs >> elevation >> azimuth >> dolly >> twist >> x >> y >> z;
m_modelerView->m_camera->setElevation( elevation);
m_modelerView->m_camera->setAzimuth( azimuth );
m_modelerView->m_camera->setDolly( dolly );
m_modelerView->m_camera->setTwist( twist );
m_modelerView->m_camera->setLookAt( Vec3f(x, y, z) );
unsigned int controlNum;
float value;
while( ifs >> controlNum >> value ) {
if( controlNum >= ModelerApplication::Instance()->GetNumControls() ) {
break;
}
ModelerApplication::Instance()->SetControlValue(controlNum, value);
}
m_modelerView->redraw();}
xywh {0 0 100 20}
code0 {\#include <iostream>}
code1 {\#include <fstream>}
code2 {\#include "camera.h"}
}
MenuItem {} {
label {Save Position File}
callback {const char *filename = fileDialog(Fl_Native_File_Chooser::BROWSE_SAVE_FILE,
"Position File (*.pos)\\t*.pos",
"Save Position File");
if(!filename)
return;
FILE* posFile = NULL;
fopen_s(&posFile, filename, "w");
if(!posFile) {
fl_alert("Save failed!");
return;
}
float elevation, azimuth, dolly, twist;
Vec3f lookAt;
elevation = m_modelerView->m_camera->getElevation();
dolly = m_modelerView->m_camera->getDolly();
azimuth = m_modelerView->m_camera->getAzimuth();
twist = m_modelerView->m_camera->getTwist();
lookAt = m_modelerView->m_camera->getLookAt();
fprintf(posFile, "%f %f %f %f %f %f %f\\n", elevation, azimuth, dolly, twist, lookAt[0], lookAt[1], lookAt[2]);
double value;
for(unsigned int i = 0; i < ModelerApplication::Instance()->GetNumControls(); i++) {
value = ModelerApplication::Instance()->GetControlValue(i);
fprintf(posFile, "%d %f\\n", i, value);
}
fclose(posFile);}
xywh {0 0 100 20} divider
}
MenuItem {} {
label Exit
callback {m_controlsWindow->hide();
m_modelerWindow->hide();}
xywh {10 10 100 20}
}
}
Submenu {} {
label View open
xywh {0 0 100 20}
code0 {\#include "modelerdraw.h"}
} {
MenuItem {} {
label Normal
callback {setDrawMode(NORMAL);
m_modelerView->redraw();}
xywh {0 0 100 20} type Radio value 1
}
MenuItem {} {
label {Flat Shaded}
callback {setDrawMode(FLATSHADE);
m_modelerView->redraw();}
xywh {0 0 100 20} type Radio
}
MenuItem {} {
label Wireframe
callback {setDrawMode(WIREFRAME);
m_modelerView->redraw();}
xywh {10 10 100 20} type Radio divider
}
MenuItem {} {
label {High Quality}
callback {setQuality(HIGH);
m_modelerView->redraw();}
xywh {0 0 100 20} type Radio
}
MenuItem {} {
label {Medium Quality}
callback {setQuality(MEDIUM);
m_modelerView->redraw();}
xywh {10 10 100 20} type Radio value 1
}
MenuItem {} {
label {Low Quality}
callback {setQuality(LOW);
m_modelerView->redraw();}
xywh {20 20 100 20} type Radio
}
MenuItem {} {
label {Poor Quality}
callback {setQuality(POOR);
m_modelerView->redraw();}
xywh {30 30 100 20} type Radio
}
}
Submenu {} {
label Animate open
xywh {0 0 100 20}
} {
MenuItem m_controlsAnimOnMenu {
label Enable
callback {ModelerApplication::Instance()->m_animating = (m_controlsAnimOnMenu->value() == 0) ? false : true;}
xywh {0 0 100 20} type Toggle
}
}
}
Fl_Browser m_controlsBrowser {
label Controls
callback {for (int i=0; i<ModelerApplication::Instance()->m_numControls; i++) {
if (m_controlsBrowser->selected(i+1))
ModelerApplication::Instance()->ShowControl(i);
else
ModelerApplication::Instance()->HideControl(i);
}}
xywh {0 25 140 300} type Multi textsize 10 resizable
}
Fl_Scroll m_controlsScroll {open
xywh {145 25 250 300} type VERTICAL_ALWAYS when 1
} {
Fl_Pack m_controlsPack {open
xywh {145 25 225 300}
code0 {\#include "modelerapp.h"}
} {}
}
}
Fl_Window m_modelerWindow {
label Model
callback {ModelerUserInterface* pUI = (ModelerUserInterface*)(o->user_data());
if(Fl::e_number == FL_CLOSE) {
pUI->m_controlsWindow->hide();
pUI->m_modelerWindow->hide();
}} open
xywh {481 95 340 296} type Double when 0 hide resizable
} {
Fl_Box m_modelerView {
label ModelerView
xywh {0 0 340 295} resizable
code0 {\#include "modelerview.h"}
class ModelerView
}
}
code {m_nativeChooser = NULL;} {}
}
Function {show()} {open
} {
code {m_controlsWindow->show();
m_modelerWindow->show();
m_modelerView->show();} {}
}
Function {fileDialog(Fl_Native_File_Chooser::Type dialogType, const char* filter, const char* title=NULL)} {open private return_type {const char*}
} {
code {//------------------------------------------------------------------------
// This displays a modal file chooser with a native look-and-feel.
// The available dialog types are:
// BROWSE_DIRECTORY - Open a single directory
// BROWSE_FILE - Open a single file
// BROWSE_MULTI_DIRECTORY - Open directories, allowing the user to
// select more than one at a time
// BROWSE_MULTI_FILE - Open files, allowing the user to select
// more than one at a time
// BROWSE_SAVE_DIRECTORY - Save a directory
// BROWSE_SAVE_FILE - Save a file
//
// The filter limits the displayed files. See cb_load_image for an example.
// title is optional, use NULL for the OS default title.
// The return value is the filepath.
//------------------------------------------------------------------------
if(!m_nativeChooser)
m_nativeChooser = new Fl_Native_File_Chooser(dialogType);
else
m_nativeChooser->type(dialogType);
m_nativeChooser->filter(filter);
m_nativeChooser->title(title);
int ret = m_nativeChooser->show();
if(ret == -1 || ret == 1) {
//error or cancel respectively
return NULL;
}
return m_nativeChooser->filename();} {}
}
decl {Fl_Native_File_Chooser* m_nativeChooser;} {}
Function {~ModelerUserInterface()} {open
} {
code {if(m_nativeChooser) delete m_nativeChooser;} {}
}
}