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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
|
/*
* RenderView.cpp
*
* Created on: Jan 23, 2012
* Author: Simon
*/
#include "simulation/ElementGraphics.h"
#include "graphics/Graphics.h"
#include "graphics/Renderer.h"
#include "RenderView.h"
class RenderView::RenderModeAction: public ui::CheckboxAction
{
RenderView * v;
public:
unsigned int renderMode;
RenderModeAction(RenderView * v_, unsigned int renderMode_)
{
v = v_;
renderMode = renderMode_;
}
virtual void ActionCallback(ui::Checkbox * sender)
{
if(sender->GetChecked())
v->c->SetRenderMode(renderMode);
else
v->c->UnsetRenderMode(renderMode);
}
};
class RenderView::DisplayModeAction: public ui::CheckboxAction
{
RenderView * v;
public:
unsigned int displayMode;
DisplayModeAction(RenderView * v_, unsigned int displayMode_)
{
v = v_;
displayMode = displayMode_;
}
virtual void ActionCallback(ui::Checkbox * sender)
{
if(sender->GetChecked())
v->c->SetDisplayMode(displayMode);
else
v->c->UnsetDisplayMode(displayMode);
}
};
class RenderView::ColourModeAction: public ui::CheckboxAction
{
RenderView * v;
public:
unsigned int colourMode;
ColourModeAction(RenderView * v_, unsigned int colourMode_)
{
v = v_;
colourMode = colourMode_;
}
virtual void ActionCallback(ui::Checkbox * sender)
{
if(sender->GetChecked())
v->c->SetColourMode(colourMode);
else
v->c->SetColourMode(0);
}
};
class RenderView::RenderPresetAction: public ui::ButtonAction
{
RenderView * v;
public:
int renderPreset;
RenderPresetAction(RenderView * v_, int renderPreset_)
{
v = v_;
renderPreset = renderPreset_;
}
virtual void ActionCallback(ui::Button * sender)
{
v->c->LoadRenderPreset(renderPreset);
}
};
RenderView::RenderView():
ui::Window(ui::Point(0, 0), ui::Point(XRES, YRES+MENUSIZE)),
toolTip(""),
toolTipPresence(0),
ren(NULL)
{
ui::Button * presetButton;
int presetButtonOffset = 375;
int checkboxOffset = 1;
int cSpace = 32;
int sSpace = 38;
presetButton = new ui::Button(ui::Point(presetButtonOffset+200, YRES+6), ui::Point(30, 13), "", "Velocity display mode preset");
presetButton->SetIcon(IconVelocity);
presetButton->SetActionCallback(new RenderPresetAction(this, 1));
AddComponent(presetButton);
presetButton = new ui::Button(ui::Point(presetButtonOffset+200, YRES+6+18), ui::Point(30, 13), "", "Pressure display mode preset");
presetButton->SetIcon(IconPressure);
presetButton->SetActionCallback(new RenderPresetAction(this, 2));
AddComponent(presetButton);
presetButton = new ui::Button(ui::Point(presetButtonOffset+161, YRES+6), ui::Point(30, 13), "", "Persistent display mode preset");
presetButton->SetIcon(IconPersistant);
presetButton->SetActionCallback(new RenderPresetAction(this, 3));
AddComponent(presetButton);
presetButton = new ui::Button(ui::Point(presetButtonOffset+161, YRES+6+18), ui::Point(30, 13), "", "Fire display mode preset");
presetButton->SetIcon(IconFire);
presetButton->SetActionCallback(new RenderPresetAction(this, 4));
AddComponent(presetButton);
presetButton = new ui::Button(ui::Point(presetButtonOffset+122, YRES+6), ui::Point(30, 13), "", "Blob display mode preset");
presetButton->SetIcon(IconBlob);
presetButton->SetActionCallback(new RenderPresetAction(this, 5));
AddComponent(presetButton);
presetButton = new ui::Button(ui::Point(presetButtonOffset+122, YRES+6+18), ui::Point(30, 13), "", "Heat display mode preset");
presetButton->SetIcon(IconHeat);
presetButton->SetActionCallback(new RenderPresetAction(this, 6));
AddComponent(presetButton);
presetButton = new ui::Button(ui::Point(presetButtonOffset+83, YRES+6), ui::Point(30, 13), "", "Fancy display mode preset");
presetButton->SetIcon(IconBlur);
presetButton->SetActionCallback(new RenderPresetAction(this, 7));
AddComponent(presetButton);
presetButton = new ui::Button(ui::Point(presetButtonOffset+83, YRES+6+18), ui::Point(30, 13), "", "Nothing display mode preset");
presetButton->SetIcon(IconBasic);
presetButton->SetActionCallback(new RenderPresetAction(this, 8));
AddComponent(presetButton);
presetButton = new ui::Button(ui::Point(presetButtonOffset+44, YRES+6), ui::Point(30, 13), "", "Heat gradient display mode preset");
presetButton->SetIcon(IconGradient);
presetButton->SetActionCallback(new RenderPresetAction(this, 9));
AddComponent(presetButton);
presetButton = new ui::Button(ui::Point(presetButtonOffset+44, YRES+6+18), ui::Point(30, 13), "", "Alternative Velocity display mode preset");
presetButton->SetIcon(IconAltAir);
presetButton->SetActionCallback(new RenderPresetAction(this, 0));
AddComponent(presetButton);
presetButton = new ui::Button(ui::Point(presetButtonOffset+5, YRES+6), ui::Point(30, 13), "", "Life display mode preset");
presetButton->SetIcon(IconLife);
presetButton->SetActionCallback(new RenderPresetAction(this, 10));
AddComponent(presetButton);
ui::Checkbox * tCheckbox;
tCheckbox = new ui::Checkbox(ui::Point(checkboxOffset, YRES+4), ui::Point(30, 16), "Effects", "Adds Special flare effects to some elements");
renderModes.push_back(tCheckbox);
tCheckbox->SetIcon(IconEffect);
tCheckbox->SetActionCallback(new RenderModeAction(this, RENDER_EFFE));
AddComponent(tCheckbox);
tCheckbox = new ui::Checkbox(ui::Point(checkboxOffset, YRES+4+18), ui::Point(30, 16), "Fire", "Fire effect for gasses");
renderModes.push_back(tCheckbox);
tCheckbox->SetIcon(IconFire);
tCheckbox->SetActionCallback(new RenderModeAction(this, RENDER_FIRE));
AddComponent(tCheckbox);
checkboxOffset += cSpace;
tCheckbox = new ui::Checkbox(ui::Point(checkboxOffset, YRES+4), ui::Point(30, 16), "Glow", "Glow effect on some elements");
renderModes.push_back(tCheckbox);
tCheckbox->SetIcon(IconGlow);
tCheckbox->SetActionCallback(new RenderModeAction(this, RENDER_GLOW));
AddComponent(tCheckbox);
tCheckbox = new ui::Checkbox(ui::Point(checkboxOffset, YRES+4+18), ui::Point(30, 16), "Blur", "Blur effect for liquids");
renderModes.push_back(tCheckbox);
tCheckbox->SetIcon(IconBlur);
tCheckbox->SetActionCallback(new RenderModeAction(this, RENDER_BLUR));
AddComponent(tCheckbox);
checkboxOffset += cSpace;
tCheckbox = new ui::Checkbox(ui::Point(checkboxOffset, YRES+4), ui::Point(30, 16), "Blob", "Makes everything be drawn like a blob");
renderModes.push_back(tCheckbox);
tCheckbox->SetIcon(IconBlob);
tCheckbox->SetActionCallback(new RenderModeAction(this, RENDER_BLOB));
AddComponent(tCheckbox);
tCheckbox = new ui::Checkbox(ui::Point(checkboxOffset, YRES+4+18), ui::Point(30, 16), "Point", "Basic rendering, without this, most things will be invisible");
renderModes.push_back(tCheckbox);
tCheckbox->SetIcon(IconBasic);
tCheckbox->SetActionCallback(new RenderModeAction(this, RENDER_BASC));
AddComponent(tCheckbox);
checkboxOffset += sSpace;
line1 = checkboxOffset-5;
tCheckbox = new ui::Checkbox(ui::Point(checkboxOffset, YRES+4), ui::Point(30, 16), "Alt. Air", "Displays pressure as red and blue, and velocity as white");
displayModes.push_back(tCheckbox);
tCheckbox->SetIcon(IconAltAir);
tCheckbox->SetActionCallback(new DisplayModeAction(this, DISPLAY_AIRC));
AddComponent(tCheckbox);
tCheckbox = new ui::Checkbox(ui::Point(checkboxOffset, YRES+4+18), ui::Point(30, 16), "Pressure", "Displays pressure, red is positive and blue is negative");
displayModes.push_back(tCheckbox);
tCheckbox->SetIcon(IconPressure);
tCheckbox->SetActionCallback(new DisplayModeAction(this, DISPLAY_AIRP));
AddComponent(tCheckbox);
checkboxOffset += cSpace;
tCheckbox = new ui::Checkbox(ui::Point(checkboxOffset, YRES+4), ui::Point(30, 16), "Velocity", "Displays velocity and positive pressure: up/down adds blue, right/left adds red, still pressure adds green");
displayModes.push_back(tCheckbox);
tCheckbox->SetIcon(IconVelocity);
tCheckbox->SetActionCallback(new DisplayModeAction(this, DISPLAY_AIRV));
AddComponent(tCheckbox);
tCheckbox = new ui::Checkbox(ui::Point(checkboxOffset, YRES+4+18), ui::Point(30, 16), "Air-heat", "Displays the temperature of the air like heat display does");
displayModes.push_back(tCheckbox);
tCheckbox->SetIcon(IconHeat);
tCheckbox->SetActionCallback(new DisplayModeAction(this, DISPLAY_AIRH));
AddComponent(tCheckbox);
/*tCheckbox = new ui::Checkbox(ui::Point(216, YRES+4), ui::Point(30, 16), "Air", "");
displayModes.push_back(tCheckbox);
tCheckbox->SetIcon(IconAltAir);
tCheckbox->SetActionCallback(new DisplayModeAction(this, DISPLAY_AIR));
AddComponent(tCheckbox);*/
checkboxOffset += sSpace;
line2 = checkboxOffset-5;
tCheckbox = new ui::Checkbox(ui::Point(checkboxOffset, YRES+4+18), ui::Point(30, 16), "Warp", "Gravity lensing, Newtonian Gravity bends light with this on");
displayModes.push_back(tCheckbox);
tCheckbox->SetIcon(IconWarp);
tCheckbox->SetActionCallback(new DisplayModeAction(this, DISPLAY_WARP));
AddComponent(tCheckbox);
#ifdef OGLR
tCheckbox = new ui::Checkbox(ui::Point(checkboxOffset, YRES+4), ui::Point(30, 16), "Effect", "I don't know what this does..."); //I would remove the whole checkbox, but then there's a large empty space
#else
tCheckbox = new ui::Checkbox(ui::Point(checkboxOffset, YRES+4), ui::Point(30, 16), "Effect", "Does nothing");
#endif
displayModes.push_back(tCheckbox);
tCheckbox->SetIcon(IconEffect);
tCheckbox->SetActionCallback(new DisplayModeAction(this, DISPLAY_EFFE));
AddComponent(tCheckbox);
checkboxOffset += cSpace;
tCheckbox = new ui::Checkbox(ui::Point(checkboxOffset, YRES+4), ui::Point(30, 16), "Persistent", "Element paths persist on the screen for a while");
displayModes.push_back(tCheckbox);
tCheckbox->SetIcon(IconPersistant);
tCheckbox->SetActionCallback(new DisplayModeAction(this, DISPLAY_PERS));
AddComponent(tCheckbox);
checkboxOffset += sSpace;
line3 = checkboxOffset-5;
tCheckbox = new ui::Checkbox(ui::Point(checkboxOffset, YRES+4), ui::Point(30, 16), "Heat", "Displays temperatures of the elements, dark blue is coldest, pink is hottest");
colourModes.push_back(tCheckbox);
tCheckbox->SetIcon(IconHeat);
tCheckbox->SetActionCallback(new ColourModeAction(this, COLOUR_HEAT));
AddComponent(tCheckbox);
tCheckbox = new ui::Checkbox(ui::Point(checkboxOffset, YRES+4+18), ui::Point(30, 16), "Life", "Displays the life value of elements in greyscale gradients");
colourModes.push_back(tCheckbox);
tCheckbox->SetIcon(IconLife);
tCheckbox->SetActionCallback(new ColourModeAction(this, COLOUR_LIFE));
AddComponent(tCheckbox);
checkboxOffset += cSpace;
tCheckbox = new ui::Checkbox(ui::Point(checkboxOffset, YRES+4+18), ui::Point(30, 16), "H-Gradient", "Changes colors of elements slightly to show heat diffusing through them");
colourModes.push_back(tCheckbox);
tCheckbox->SetIcon(IconGradient);
tCheckbox->SetActionCallback(new ColourModeAction(this, COLOUR_GRAD));
AddComponent(tCheckbox);
tCheckbox = new ui::Checkbox(ui::Point(checkboxOffset, YRES+4), ui::Point(30, 16), "Basic", "No special effects at all for anything, overrides all other options and deco");
colourModes.push_back(tCheckbox);
tCheckbox->SetIcon(IconBasic);
tCheckbox->SetActionCallback(new ColourModeAction(this, COLOUR_BASC));
AddComponent(tCheckbox);
checkboxOffset += sSpace;
line4 = checkboxOffset-5;
}
void RenderView::OnMouseDown(int x, int y, unsigned button)
{
if(x > XRES || y < YRES)
c->Exit();
}
void RenderView::NotifyRendererChanged(RenderModel * sender)
{
ren = sender->GetRenderer();
}
void RenderView::NotifyRenderChanged(RenderModel * sender)
{
for(int i = 0; i < renderModes.size(); i++)
{
if(renderModes[i]->GetActionCallback())
{
//Compares bitmasks at the moment, this means that "Point" is always on when other options that depend on it are, this might confuse some users, TODO: get the full list and compare that?
RenderModeAction * action = (RenderModeAction *)(renderModes[i]->GetActionCallback());
if(action->renderMode == (sender->GetRenderMode() & action->renderMode))
{
renderModes[i]->SetChecked(true);
}
else
{
renderModes[i]->SetChecked(false);
}
}
}
}
void RenderView::NotifyDisplayChanged(RenderModel * sender)
{
for(int i = 0; i < displayModes.size(); i++)
{
if(displayModes[i]->GetActionCallback())
{
DisplayModeAction * action = (DisplayModeAction *)(displayModes[i]->GetActionCallback());
if(action->displayMode == (sender->GetDisplayMode() & action->displayMode))
{
displayModes[i]->SetChecked(true);
}
else
{
displayModes[i]->SetChecked(false);
}
}
}
}
void RenderView::NotifyColourChanged(RenderModel * sender)
{
for(int i = 0; i < colourModes.size(); i++)
{
if(colourModes[i]->GetActionCallback())
{
ColourModeAction * action = (ColourModeAction *)(colourModes[i]->GetActionCallback());
if(action->colourMode == sender->GetColourMode())
{
colourModes[i]->SetChecked(true);
}
else
{
colourModes[i]->SetChecked(false);
}
}
}
}
void RenderView::OnDraw()
{
Graphics * g = ui::Engine::Ref().g;
g->clearrect(-1, -1, XRES+BARSIZE+1, YRES+MENUSIZE+1);
if(ren)
{
ren->clearScreen(1.0f);
ren->RenderBegin();
ren->RenderEnd();
}
g->draw_line(0, YRES, XRES-1, YRES, 200, 200, 200, 255);
g->draw_line(line1, YRES, line1, YRES+MENUSIZE, 200, 200, 200, 255);
g->draw_line(line2, YRES, line2, YRES+MENUSIZE, 200, 200, 200, 255);
g->draw_line(line3, YRES, line3, YRES+MENUSIZE, 200, 200, 200, 255);
g->draw_line(line4, YRES, line4, YRES+MENUSIZE, 200, 200, 200, 255);
g->draw_line(XRES, 0, XRES, YRES+MENUSIZE, 255, 255, 255, 255);
if(toolTipPresence && toolTip.length())
{
g->drawtext(6, Size.Y-MENUSIZE-12, (char*)toolTip.c_str(), 255, 255, 255, toolTipPresence>51?255:toolTipPresence*5);
}
}
void RenderView::OnTick(float dt)
{
if(toolTipPresence>0)
{
toolTipPresence -= int(dt)>0?int(dt):1;
if(toolTipPresence<0)
toolTipPresence = 0;
}
}
void RenderView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt)
{
if (shift && key == '1')
c->LoadRenderPreset(10);
else if(key >= '0' && key <= '9')
{
c->LoadRenderPreset(key-'0');
}
}
void RenderView::ToolTip(ui::Component * sender, ui::Point mousePosition, std::string toolTip)
{
this->toolTip = toolTip;
toolTipPresence = 500;
}
RenderView::~RenderView() {
// TODO Auto-generated destructor stub
}
|