-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
DevLoop.h
427 lines (382 loc) · 14.4 KB
/
DevLoop.h
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
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
#ifndef NDEBUG // if debug build then do this one
//#include "Luna.h"
#include "config.h"
//todo fix GUI button render needs its own receiver
//todo fix GUI instances into vector
enum GUI_ELEMENTS
{
MENU_QUIT = 200,
MENU_UNDO,
MENU_REDO,
MENU_CUT,
MENU_PASTE,
MENU_COPY,
MENU_DELETE,
MENU_LINECOUNT,
MENU_ENGLISH,
MENU_FRENCH,
};
// Declare a structure to hold some context for the event receiver so that it
// has it available inside its OnEvent() method.
#ifdef CODEEDITOR
struct SAppContext
{
IrrlichtDevice *device;
CGUIEditBoxIRB * codeEditor;
IGUIContextMenu * menu;
};
#endif
//
//class MyEventReceiver : public IEventReceiver
//{
//public:
// MyEventReceiver(SAppContext & context) : Context(context) { }
//
// virtual bool OnEvent(const SEvent& event)
// {
// if (event.EventType == EET_GUI_EVENT)
// {
// s32 id = event.GUIEvent.Caller->getID();
// IGUIEnvironment* env = Context.device->getGUIEnvironment();
//
// switch(event.GUIEvent.EventType)
// {
//
// case EGET_SCROLL_BAR_CHANGED:
// break;
//
// case EGET_BUTTON_CLICKED:
// break;
//
// case gui::EGET_MENU_ITEM_SELECTED:
// {
// IGUIContextMenu* menu = (IGUIContextMenu*)event.GUIEvent.Caller;
// s32 item = menu->getItemCommandId(menu->getSelectedItem());
// switch (item)
// {
// case MENU_QUIT:
// //Context.device->closeDevice();
// #ifdef PYTHON
// Python::bCodeEditor=3;
// #endif
// break;
// case MENU_UNDO:
// Context.codeEditor->undo();
// break;
// case MENU_REDO:
// Context.codeEditor->redo();
// break;
// case MENU_CUT:
// Context.codeEditor->cut();
// break;
// case MENU_COPY:
// Context.codeEditor->copy();
// break;
// case MENU_PASTE:
// Context.codeEditor->paste();
// break;
// case MENU_DELETE:
// Context.codeEditor->deleteText();
// break;
// case MENU_LINECOUNT:
// {
// bool visible = Context.codeEditor->isLineCountDisplayed();
// Context.codeEditor->setDisplayLineCount(!visible);
// }
// break;
// case MENU_ENGLISH:
// {
// // Change the text of the menu in English
// Context.menu->setItemText(0,L"File");
// Context.menu->setItemText(1,L"Edit");
// Context.menu->setItemText(2,L"Display");
//
// IGUIContextMenu * submenu;
// submenu = Context.menu->getSubMenu(0);
// submenu->setItemText(0,L"Quit");
//
// submenu = Context.menu->getSubMenu(1);
// submenu->setItemText(0,L"Cut");
// submenu->setItemText(1,L"Copy");
// submenu->setItemText(2,L"Paste");
// submenu->setItemText(3,L"Delete");
// submenu->setItemText(5,L"Undo");
// submenu->setItemText(6,L"Redo");
//
// submenu = Context.menu->getSubMenu(2);
// submenu->setItemText(0,L"Toggle linecount display");
// // Change the checked state of the language
// submenu->setItemChecked(1,true);
// submenu->setItemChecked(2,false);
//
// // Set the elements text of the codeEditor in english
// Context.codeEditor->setElementText(Context.codeEditor->CM_CUT,L"Cut");
// Context.codeEditor->setElementText(Context.codeEditor->CM_COPY,L"Copy");
// Context.codeEditor->setElementText(Context.codeEditor->CM_DELETE,L"Delete");
// Context.codeEditor->setElementText(Context.codeEditor->CM_PASTE,L"Paste");
// Context.codeEditor->setElementText(Context.codeEditor->CM_UNDO,L"Undo");
// Context.codeEditor->setElementText(Context.codeEditor->CM_REDO,L"Redo");
// Context.codeEditor->setElementText(Context.codeEditor->BT_LINECOUNT,
// L"Toggle linecount display");
//
//
// }
// break;
// case MENU_FRENCH:
// {
// // Change the text of the menus in French
// Context.menu->setItemText(0,L"Fichier");
//// Context.menu->setItemText(1,L"Édition");
// Context.menu->setItemText(2,L"Affichage");
//
// IGUIContextMenu * submenu;
// submenu = Context.menu->getSubMenu(0);
// submenu->setItemText(0,L"Quitter");
//
// submenu = Context.menu->getSubMenu(1);
// submenu->setItemText(0,L"Couper");
// submenu->setItemText(1,L"Copier");
// submenu->setItemText(2,L"Coller");
// submenu->setItemText(3,L"Effacer");
// submenu->setItemText(5,L"Annuler");
// submenu->setItemText(6,L"Refaire");
//
// submenu = Context.menu->getSubMenu(2);
// submenu->setItemText(0,L"Basculer affichage des lignes");
// // Change the checked state of the language
// submenu->setItemChecked(1,false);
// submenu->setItemChecked(2,true);
//
// // Set the elements text of the codeEditor in french
// Context.codeEditor->setElementText(Context.codeEditor->CM_CUT,L"Couper");
// Context.codeEditor->setElementText(Context.codeEditor->CM_COPY,L"Copier");
// Context.codeEditor->setElementText(Context.codeEditor->CM_DELETE,L"Effacer");
// Context.codeEditor->setElementText(Context.codeEditor->CM_PASTE,L"Coller");
// Context.codeEditor->setElementText(Context.codeEditor->CM_UNDO,L"Annuler");
// Context.codeEditor->setElementText(Context.codeEditor->CM_REDO,L"Refaire");
// Context.codeEditor->setElementText(Context.codeEditor->BT_LINECOUNT,
// L"Basculer affichage des lignes");
//
// }
// break;
//
// }
// break;
// }
//
//
// default:
// break;
// }
// }
//
// return false;
// }
//
//private:
// SAppContext & Context;
//
//};
//if ( !device->run() ) return 0;
// guienv->clear();
// smgr->clear();
// Init the Custom GUI
//#ifdef PYTHON
// //Python
// Python::registerIrrDevice(this,*device,m_cInGameEvents);
// Py_Initialize(); //Initialize Python
// //PythonMultithreading goes here when time comes
// // PyEval_InitThreads() ; // nb: creates and locks the GIL
// Python::init_irr(); //Initialize our module
// //Py_SetProgramName(), Py_SetPythonHome(), PyEval_InitThreads(), PyEval_ReleaseLock(), and PyEval_AcquireLock()
// //https://docs.python.org/2/c-api/init.html
// ///todo check for empty or missing files or impliment the using command
//#ifndef __EMSCRIPTEN__
// Python::ExecuteScript("./media/functions-list.pys"); // this is for testing
//#else
// Python::ExecuteScript("./functions-list.pys"); // this is for testing
//#endif
// //Python::PyIrr_LoadVehicle(m_cVehicle);
// //Python::PyIrr_addTerrain("1");
//
// // pyloader = "./APP/cowsynth/main.pys";
//#ifdef __EMSCRIPTEN__
//pyloader = "./media/main.pys";
//
// #else
// pyloader = "./RACING/racer/main.pys";
//#endif
//Python::bCodeEditor=3; // initial closed state
//
//#endif
//camera = smgr->addCameraSceneNodeFPS(0, 100, .1f, -1, keyMap, 8);
//smgr->addCameraSceneNodeFPS();
// u32 then = device->getTimer()->getTime();
// int lastFPS;
/**
/////////////////////////////////////
// DEVLOOP //////////////////
///////////////////////////////////
**/
// IGUIWindow* windows = guienv->addWindow(
// rect<s32>(100 , 100 , 800 , 800 ),
// false, // modal?
// L"Test window");
#ifdef CODEEDITOR
guienv->createSkin(EGST_WINDOWS_METALLIC);
IGUISkin* skin = guienv->getSkin();
skin->setColor(EGDC_HIGH_LIGHT ,video::SColor(192,222,237,243));
skin->setColor(EGDC_BUTTON_TEXT ,video::SColor(255,30,30,30));
skin->setColor(EGDC_HIGH_LIGHT_TEXT ,video::SColor(255,30,30,30));
skin->setColor(EGDC_3D_DARK_SHADOW ,video::SColor(255,56,56,56));
skin->setColor(EGDC_3D_SHADOW ,video::SColor(255,85,85,85));
skin->setColor(EGDC_3D_FACE ,video::SColor(255,170,170,170));
IGUIFont* font = guienv->getFont("../media/editor/fonts/arial10.xml");
if (font)
skin->setFont(font);
windows->setVisible(true);
device->setWindowCaption(L"Code editor example, using IRRlicht 1.7.2");
// Create the menus for the example with it default language (English)
IGUIContextMenu * menu = guienv->addMenu(0,-1);
menu->addItem(L"File",0,true,true);
menu->addItem(L"Edit",1,true,true);
menu->addItem(L"Display",2,true,true);
IGUIContextMenu * file_submenu;
file_submenu = menu->getSubMenu(0);
file_submenu->addItem(L"Quit",MENU_QUIT);
IGUIContextMenu * edit_submenu;
edit_submenu = menu->getSubMenu(1);
edit_submenu->addItem(L"Cut",MENU_CUT);
edit_submenu->addItem(L"Copy",MENU_COPY);
edit_submenu->addItem(L"Paste",MENU_PASTE);
edit_submenu->addItem(L"Delete",MENU_PASTE);
edit_submenu->addSeparator();
edit_submenu->addItem(L"Undo",MENU_UNDO);
edit_submenu->addItem(L"Redo",MENU_REDO);
IGUIContextMenu * display_submenu;
display_submenu = menu->getSubMenu(2);
display_submenu->addItem(L"Toggle linecount display",MENU_LINECOUNT,true,false,false,false);
display_submenu->addItem(L"English",MENU_ENGLISH,true,false,true,false);
// display_submenu->addItem(L"Français",MENU_FRENCH,true,false,false,false);
// Define the example text of the Code editor box
stringw exampletext = L"// Welcome to the code editor example\n//This example use the c++ style of code to highlight\n\nStrings:\"Here is some text\"\n";
exampletext += L"C++ Keywords: this, if, else, break, switch, case, while\n\n";
exampletext += L"custom keywords highlight: Hybrid, CuteAlien, Bitplane\n";
exampletext += L"custom group highlight 1: (Text is colored between the parenthesis)\n";
exampletext += L"custom group highlight 2: Feature(This is a demo of a feature and should work on multiple lines of text.)\n";
exampletext += L"custom group highlight 2: Feature(Single line text)\n";
exampletext += L"custom line highlight: remark: This line will be highlighted.";
// guienv->addImage(driver->getTexture( "media/irrlichtlogo.jpg"),
// position2d<int>(10,10));
// CGUIEditBoxIRB * codeEditor = new CGUIEditBoxIRB(exampletext.c_str(),true,true,guienv,guienv->getRootGUIElement(),-1,rect<s32>(20,60,600,400),device);
CGUIEditBoxIRB * codeEditor = new CGUIEditBoxIRB(exampletext.c_str(),true,true,guienv,windows,-1,rect<s32>(10,40,driver->getScreenSize().Width-20,driver->getScreenSize().Height-20),device);
////CGUIEditBoxIRB* codeEditor = new CGUIEditBoxIRB(exampletext.c_str(),
//// true,
//// true,
//// guienv,
//// -1,
//// 25,
//// //myRect(10,40,driver->getScreenSize().Width-220,driver->getScreenSize().Height-260),
//// rect<s32>(20,60,600,400),
//// device);
//
//
//codeEditor->FrameRect=rect<s32>(200,60,600,400);
// Recolor the background with pure white
codeEditor->setBackgroundColor(SColor(255,240,240,240));
// Recolor the linecount GUI element
codeEditor->setLineCountColors(SColor(255,32,32,32),SColor(200,64,120,180),SColor(255,200,200,224));
// Recolor the selection colors
codeEditor->setSelectionColors(SColor(180,0,96,64),SColor(255,255,255,255),SColor(180,0,128,96));
// Allow the code editor to use syntax highlighting based on C++ keywords
codeEditor->addCppKeywords();
// Allow the code editor to use syntax highlighting based on LUA keywords
//codeEditor->addLUAKeywords();
// Set the pointers so the event manager can manipulate their objects
SAppContext context;
context.device = device;
context.codeEditor = codeEditor;
//context.menu = menu;
// Then create the event receiver, giving it that context structure.
// MyEventReceiver receiver(context);
// And tell the device to use our custom event receiver.
// device->setEventReceiver(&receiver);
codeEditor->setEnabled(0);
codeEditor->setVisible(false);
menu->setVisible(false);
// windows->setVisible(false);
// windows->setVisible(true);
// windows->setVisible(false);
// IGUIWindow* windowss = guienv->addWindow(
// rect<s32>(1 , 1 ,222 , 222 ),
// false, // modal?
// L"mhm");
Python::bCodeEditor=0;
windows->setVisible(true);
codeEditor->setEnabled(true);
codeEditor->setVisible(true);
// menu->setVisible(true); // only seems to work when called from here
// menu->setEnabled(true);
windows->setVisible(true);
//device->setEventReceiver(&receiver);
device->getCursorControl()->setVisible(true);
device->setResizable(true);
#endif
device->getCursorControl()->setVisible(true);
// IrrAssimp assimp(smgr);
// IAnimatedMesh* mesh = assimp.getMesh("media/dwarf.x");
//// if (!mesh /*|| !meshNoAssimp*/)
//// {
//// device->drop();
//// return 1;
//// }
//
// IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );
// node->setAnimationSpeed(mesh->getAnimationSpeed());
//
//irr::core::string dir = "RACING/racer";
//irr::core::::string dir2 = "./" + dir2.c_str() + "/main.pys";
// printf("%s",dir2.c_str());
// char* convert = strdup(dir2.c_str());
//char* convert = const_cast<char*>(dir2.c_str());
// char * dir2 = "/RACING/racer/";
// char *dir ;
// strcat (dir, ".");
// strcat(dir, dir2);
// strcat(dir, "main.pys");
// puts (dir);
// char * loader = "./RACING/racer/main.pys";
//sidescroller texture
//node->getMaterial(0)->getTextureMatrix(0).setTextureTranslate(x, y)
// #ifdef __EMSCRIPTEN__
// emscripten_set_main_loop(main_loop,0,1);
//#else
//rendermain();
//
//#endif
#endif
/*
// // I'm just using a basic cube scene node for the glass pane, "scaled to flatness".
// ISceneNode* GlassPane = smgr->addCubeSceneNode();
// GlassPane->setScale(vector3df(100,150,1));
// GlassPane->setPosition(core::vector3df(0,0,0));
// GlassPane->setRotation(vector3df(0,60,0));
//
// // Here I make a RTT for the refraction, you can use a higher res one if you want,
// // I chose 512^2 for compatibility. I also load the normalmap.
// ITexture* RTTTex = driver->addRenderTargetTexture(dimension2du(512,512));
// ITexture* NormMap = driver->getTexture("shaders/glass-bubble/media/NormalMap.png");
//
// GlassPane->setMaterialTexture(0, RTTTex);
// GlassPane->setMaterialTexture(1, NormMap);
//
// io::path vshader = "shaders/glass-bubble/GlassV.glsl";
// io::path pshader = "shaders/glass-bubble/GlassP.glsl";
//
// video::IGPUProgrammingServices* gpu = driver->getGPUProgrammingServices();
//
// // I create the shader material for the glass pane.
// s32 GlassMat = gpu->addHighLevelShaderMaterialFromFiles(vshader,"main",EVST_VS_2_0,pshader,"main",EPST_PS_2_0,0);
//
// GlassPane->setMaterialType(E_MATERIAL_TYPE(GlassMat));
*/