GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
GameApi_gui.cc
Go to the documentation of this file.
1
2#include "GameApi_h.hh"
3#include "GameApi_gui.hh"
4#include "GameApi_cmd.hh"
5#include "Tasks.hh"
6
7#ifdef WINDOWS
8#include <direct.h>
9#endif
10
11#ifdef LINUX
12#include <unistd.h>
13#endif
14
15
16
17#ifdef EMSCRIPTEN
18#include <emscripten.h>
19#endif
20
21IMPORT extern bool g_transparent;
22
23IMPORT extern int g_event_screen_x;
24IMPORT extern int g_event_screen_y;
25
26#if defined(ARM) || defined(RASPI)
27#ifdef FIRST_PART
28//int strlen(const char *ptr) { const char *p = ptr; while(*p) { p++; } return p-ptr;}
29size_t strlen(const char *);
30#else
31size_t strlen(const char *);
32#endif
33#endif
34int ret_type_count(std::string return_type);
35
36std::string unique_id_apiitem();
37std::vector<GameApiItem*> all_functions(GameApi::EveryApi &ev);
38std::vector<GameApiItem*> polydistfield_functions();
39std::vector<GameApiItem*> waveform_functions();
40std::vector<GameApiItem*> blocker_functions(GameApi::EveryApi &ev);
41std::vector<GameApiItem*> textureapi_functions();
42std::vector<GameApiItem*> volumeapi_functions();
43std::vector<GameApiItem*> floatvolumeapi_functions();
44std::vector<GameApiItem*> colorvolumeapi_functions();
45std::vector<GameApiItem*> vectorapi_functions();
46std::vector<GameApiItem*> pointapi_functions();
47std::vector<GameApiItem*> fontapi_functions();
48std::vector<GameApiItem*> moveapi_functions();
49std::vector<GameApiItem*> polygonapi_functions();
50std::vector<GameApiItem*> shadermoduleapi_functions();
51std::vector<GameApiItem*> shaderapi_functions();
52std::vector<GameApiItem*> framebuffermoduleapi_functions();
53std::vector<GameApiItem*> textureapi_functions();
54std::vector<GameApiItem*> booleanopsapi_functions();
55std::vector<GameApiItem*> polygonapi_functions1();
56std::vector<GameApiItem*> polygonapi_functions2();
57std::vector<GameApiItem*> linesapi_functions();
58std::vector<GameApiItem*> pointsapi_functions();
59std::vector<GameApiItem*> floatbitmapapi_functions();
60std::vector<GameApiItem*> boolbitmapapi_functions();
61std::vector<GameApiItem*> bitmapapi_functions();
62
63extern int async_pending_count;
64
65
67{
68public:
70};
71
72
73const float keypress_rot_speed = 6.0;
74
75
77{
78public:
79 TimedWidget2(GameApi::EveryApi &ev, GuiWidget *next, float time) : GuiWidgetForward(ev, { next } ), time(time)
80 {
81 old_time = ev.mainloop_api.get_time();
82 }
83 void update(Point2d mouse_pos, int button, int ch, int type, int mouse_wheel_y)
84 {
85 GuiWidgetForward::update(mouse_pos, button, ch, type, mouse_wheel_y);
86 float current_time = ev.mainloop_api.get_time();
87 float delta = current_time - old_time;
88 if (delta > time && vec.size()>0)
89 {
90 vec.erase(vec.begin());
91 }
92 }
94 {
95 vec[0]->set_size(v);
96 }
97private:
98 float old_time;
99 float time;
100};
102{
103public:
104 TimedWidget(GameApi::EveryApi &ev, GuiWidget *next, GameApi::W (*timed_func)(void*), void*data, GuiWidgetForward *insert_wid, float start_duration, float duration, float dx) : GuiWidgetForward(ev, {next}), next(next), timed_func(timed_func),data(data), insert_wid(insert_wid), start_duration(start_duration), duration(duration),dx(dx)
105 {
106 uid = unique_id();
107 state = 0;
108 Point2d p = { -666.0, -666.0 };
109 update(p, -1,-1, -1,0);
110 Point2d p2 = { 0.0, 0.0 };
111 set_pos(p2);
112 }
113 ~TimedWidget() { delete m_tm; }
114 void update(Point2d mouse_pos, int button, int ch, int type, int mouse_wheel_y)
115 {
116 GuiWidgetForward::update(mouse_pos, button, ch, type,mouse_wheel_y);
117 Point2d pos = vec[0]->get_pos();
118 Vector2d sz = vec[0]->get_size();
119 if (state==0 && mouse_pos.x>pos.x && mouse_pos.x<pos.x+sz.dx &&
120 mouse_pos.y>pos.y && mouse_pos.y<pos.y+sz.dy)
121 {
122 state=1;
123 state1_time = ev.mainloop_api.get_time();
124 }
125 float current_time = ev.mainloop_api.get_time();
126 if (state==1 && current_time-state1_time > start_duration)
127 {
128 state=2;
129 state2_time = ev.mainloop_api.get_time();
130 // this only works with tooltips
131 Point2d p = next->get_pos();
132 Vector2d ps = next->get_size();
133 Point2d pos = { float(p.x+ps.dx-dx), float(p.y+0.0) };
134 if (!timed)
135 {
136 GameApi::W t = timed_func(data);
137 timed = find_widget(ev.get_env(),t);
138 }
139 timed->set_pos(pos);
140
141
142 GuiWidget *tm = new TimedWidget2(ev, timed, duration);
143 tm->set_id(uid);
144 delete m_tm;
145 m_tm = tm;
146 insert_wid->vec.push_back(tm);
147 index = insert_wid->vec.size()-1;
148 }
149 if (state==2 && (current_time-state2_time > duration||
150 !(mouse_pos.x>pos.x && mouse_pos.x<pos.x+sz.dx &&
151 mouse_pos.y>pos.y && mouse_pos.y<pos.y+sz.dy))
152 )
153 {
154 state=3;
155 int s = insert_wid->vec.size();
156 for(int i=0;i<s;i++)
157 {
158 GuiWidget* w = insert_wid->vec[i];
159 std::string id = w->get_id();
160 if (id==uid)
161 {
162 insert_wid->vec.erase(insert_wid->vec.begin()+i);
163 break;
164 }
165 }
166 }
167 if (state==3 && (
168 !(mouse_pos.x>pos.x && mouse_pos.x<pos.x+sz.dx &&
169 mouse_pos.y>pos.y && mouse_pos.y<pos.y+sz.dy))
170 ) {
171 state=0;
172 }
173
174 }
176 {
177 vec[0]->set_size(v);
178 }
179private:
180 std::string uid;
181 GuiWidget *next=0;
182 GuiWidget *timed=0;
183 GameApi::W (*timed_func)(void*);
184 void *data=0;
185 GuiWidgetForward *insert_wid=0;
186 float start_duration=0.0;
187 float duration=0.0;
188 int state=0;
189 float state1_time=0.0;
190 float state2_time=0.0;
191 int index=0;
192 float dx=0.0;
193 GuiWidget *m_tm=0;
194};
195
196#ifndef EMSCRIPTEN
197
199{
200public:
201 DynamicTextGuiWidget(GameApi::Env &e, GameApi::EveryApi &ev, GameApi::GuiApi &gui, std::string need_letters, std::string *dyn_text, void (*fptr)(void*, float mouse_x, float mouse_y, int button, int ch, int type, int mouse_wheel_y), void *user_ptr, GameApi::FtA atlas, GameApi::BM atlas_bm, int x_gap) : GuiWidgetForward(ev,std::vector<GuiWidget*>()), e(e), ev(ev), gui(gui), need_letters(need_letters), dyn_text(dyn_text), fptr(fptr), user_ptr(user_ptr), atlas(atlas), atlas_bm(atlas_bm), x_gap(x_gap) {
202 check_letters(need_letters);
203 }
204 void add_letter(int ch)
205 {
206 std::string s;
207 s+=char(ch);
208 GameApi::W w = gui.text(s, atlas, atlas_bm, 0);
209 letter_widgets[ch]=w;
210 letter_widgets2.push_back(w);
211 letter_chars2.push_back(ch);
212 GuiWidget *ww = find_widget(e,w);
213 Point2d p; p.x = 0; p.y = 0;
214 ww->update(p,-1,-1,-1,0);
215 }
216 void update(Point2d mouse, int button, int ch, int type, int mouse_wheel_y)
217 {
218 fptr(user_ptr, mouse.x, mouse.y, button, ch, type, mouse_wheel_y);
219 int s = letter_widgets2.size();
220 for(int i=0;i<s;i++)
221 {
222 GameApi::W w = letter_widgets2[i];
223 GuiWidget *ww = find_widget(e,w);
224 ww->update(mouse,button,ch,type,mouse_wheel_y);
225 }
226 }
227 void check_letters(std::string ss)
228 {
229 int s = ss.size();
230 int pos = 0;
231 for(int i=0;i<s;i++)
232 {
233 char ch = ss[i];
234 int ch2 = (int)ch;
235 if (letter_widgets.find(ch2)==letter_widgets.end())
236 {
237 add_letter(ch2);
238 }
239 }
240 }
241 void render()
242 {
243 std::string ss = *dyn_text;
244 check_letters(ss);
245 int s = ss.size();
246 int pos = 0;
247 for(int i=0;i<s;i++)
248 {
249 char ch = ss[i];
250 int ch2 = (int)ch;
251 render_w(pos,letter_widgets[ch2],ch2);
252 GuiWidget *wid = find_widget(e,letter_widgets[ch2]);
253
254 pos+=wid->get_size().dx+x_gap;
255 }
256 }
257 int calc_top(char ch2)
258 {
260 FontAtlasGlyphInfo ii = info->char_map[ch2];
261 int top = ii.top;
262 return top;
263 }
265 {
266 int s = need_letters.size();
267 int min_delta=0;
268 for(int i=0;i<s;i++)
269 {
270 int delta = calc_top(need_letters[i]);
271 if (delta<min_delta) min_delta=delta;
272 }
273 return -min_delta;
274 }
275 int calc_one_top(char ch)
276 {
278 FontAtlasGlyphInfo ii = info->char_map[ch];
279 int top = ii.y;
280 return top;
281 }
283 {
284 int s = letter_widgets2.size();
285 int max_height=0;
286 for(int i=0;i<s;i++)
287 {
288 GameApi::W w = letter_widgets2[i];
289 GuiWidget *ww = find_widget(e,w);
290 if (ww->get_size().dy-calc_top(letter_chars2[i])>max_height) max_height=ww->get_size().dy-calc_top(letter_chars2[i]);
291 }
292 return max_height;
293 }
295 {
296 char ch = letter_chars2[0];
298 FontAtlasGlyphInfo ii = info->char_map[ch];
299 return ii.sy;
300 }
301 void render_w(int p, GameApi::W w, char ch2)
302 {
303 GuiWidget *ww = find_widget(e,w);
304 Point2d pp;
305 pp.x = pos.x+p;
306 pp.y = pos.y +calc_one_height() /*+calc_all_top()*/ /*+calc_one_top(ch2)*/ /*+calc_top(ch2)*/ /*+calc_all_height()*/ -ww->get_size().dy-1;
307 ww->set_pos(pp /*pos.x + p,pos.y*/);
308 ww->render();
309 }
310
311private:
314 GameApi::GuiApi &gui;
315 std::string need_letters;
316 std::string *dyn_text;
317 std::map<int, GameApi::W> letter_widgets;
318 std::vector<GameApi::W> letter_widgets2;
319 std::string letter_chars2;
320 GameApi::FtA atlas;
321 GameApi::BM atlas_bm;
322 void (*fptr)(void*, float mouse_x, float mouse_y, int button, int ch, int type, int mouse_wheel_y);
323 void *user_ptr;
324 int x_gap;
325};
326
327#ifndef EMSCRIPTEN
328std::string g_searchstring="@";
329#endif
330
332{
333public:
334 MousePositionTweakForEditors(GameApi::EveryApi &ev, GuiWidget *inner, GuiWidget *outer, GuiWidget *outerouter) : ev(ev), GuiWidgetForward(ev, { outer }), inner(inner), outer(outer), outerouter(outerouter) {
335 Point2d p = { -666.0, -666.0 };
336 update(p, -1,-1, -1,0);
337 Point2d p2 = { 0.0, 0.0 };
338 set_pos(p2);
339 }
341 {
343 Point2d p = { pos.x, pos.y };
344 outer->set_pos(p);
345 }
346 void set_size(Vector2d size_p)
347 {
349 outer->set_size(outer->get_size());
350 size = outer->get_size();
351 }
353 {
354 if (p.x >= outer->get_pos().x && p.x < outer->get_pos().x + outer->get_size().dx)
355 {
356 if (p.y >= outer->get_pos().y && p.y < outer->get_pos().y + outer->get_size().dy)
357 {
358 done = true;
359 return inner->get_pos() + Vector2d(inner->get_size().dx/2,inner->get_size().dy/2);
360 }
361 }
362 return p;
363 }
364 void update(Point2d mouse, int button, int ch, int type, int mouse_wheel_y)
365 {
366 bool b = false;
367 GuiWidgetForward::update(get_mouse_tweak(mouse,b),button,ch,type,mouse_wheel_y);
368 if (b) {
369 // activate editor
370 outerouter->update(get_mouse_tweak(mouse,b),0,-1,1025,mouse_wheel_y);
371 }
372 size = Vector2d(outer->get_size().dx,outer->get_size().dy);
373 }
374 virtual Point2d get_pos() const { return GuiWidgetForward::get_pos(); }
375 virtual Vector2d get_size() const { return GuiWidgetForward::get_size(); } // -4 is because of margins uppeprivate:
376 int chosen_item() const { return outerouter->chosen_item(); }
377 void render()
378 {
380 }
383
384private:
386 GuiWidget *inner;
387 GuiWidget *outer;
388 GuiWidget *outerouter;
389};
391{
392 GuiWidget *in = find_widget(e,inner);
393 GuiWidget *out = find_widget(e,outer);
394 GuiWidget *outout = find_widget(e,outerouter);
395 return add_widget(e, new MousePositionTweakForEditors(ev,in,out,outout));
396}
397
398#ifndef EMSCRIPTEN
400{
401public:
402 HideWidgetIfArrayEmpty(GameApi::Env &env, GameApi::EveryApi &ev, GuiWidget *w2, std::vector<GuiWidget*> items, GameApi::W *redraw_w) : GuiWidgetForward(ev, { w2 }), env(env), ev(ev), w(w2), items(items), redraw_w(redraw_w)
403 {
404 Point2d p = { -666.0, -666.0 };
405 update(p, -1,-1, -1,0);
406 Point2d p2 = { 0.0, 0.0 };
407 set_pos(p2);
408 }
410 {
412 Point2d p = { pos.x, pos.y };
413 w->set_pos(p);
414 }
415 void set_size(Vector2d size_p)
416 {
418 w->set_size(w->get_size());
419 size = w->get_size(); //size_p;
420 }
422
423 bool is_visible2() const
424 {
425 int s = items.size();
426 bool show = false;
427 for(int i=0;i<s;i++)
428 {
429 Vector2d sz = items[i]->get_size();
430 if (sz.dy > 10.0)
431 {
432 show=true;
433 }
434 }
435 return show;
436 }
437 void update(Point2d mouse, int button, int ch, int type, int mouse_wheel_y)
438 {
439 //GuiWidgetForward::update(mouse,button,ch,type,mouse_wheel_y);
440
441 int s = items.size();
442 for(int i=0;i<s;i++)
443 {
444 items[i]->update(mouse,button,ch,type,mouse_wheel_y);
445 }
446
447 if (is_visible2()) {
448 GuiWidgetForward::update(mouse,button,ch,type,mouse_wheel_y);
449 }
450 if (is_visible2())
451 {
452 size = Vector2d(w->get_size().dx,w->get_size().dy);
453 //w->show();
454 }
455 else
456 {
457 size = Vector2d(0.0,-5.0);
458 //w->hide();
459 }
460
461 if ((redraw_w && !inside_redraw) && ( button==-1 && ch==-1 && type==-1 ) ) {
462 inside_redraw= true;
463 GuiWidget *ww = find_widget(env,*redraw_w);
464
465 Point2d p = { -666.0, -666.0 };
466 ww->update(p, -1,-1, -1,1);
467 /*
468 Point2d p2 = { ww->get_pos().x, ww->get_pos().y };
469 ww->set_pos(p2);
470 Vector2d s2 = { ww->get_size().dx, ww->get_size().dy };
471 ww->set_size(s2);
472 */
473 ww->update(mouse,button,ch,type,mouse_wheel_y);
474
475 /*
476 Point2d a_p = { -666.0, -666.0 };
477 ww->update(a_p, -1,-1, -1,0);
478 Point2d a_p2 = { ww->get_pos().x, ww->get_pos().y };
479 ww->set_pos(a_p2);
480 Vector2d a_s2 = { ww->get_size().dx, ww->get_size().dy };
481 ww->set_size(a_s2);
482
483 ww->update(mouse,button,ch,type,mouse_wheel_y);
484 */
485 inside_redraw=false;
486 }
487
488 }
489 virtual Point2d get_pos() const { return GuiWidgetForward::get_pos(); }
490 virtual Vector2d get_size() const { if (is_visible2()) return GuiWidgetForward::get_size(); else return Vector2d(0.0,-5.0); } // -4 is because of margins upper in the scene.
491 int chosen_item() const { return w->chosen_item(); }
492 void render()
493 {
494 if (is_visible2()) {
495 //w->show();
497 } else
498 {
499 //w->hide();
500 }
501 }
504
505 bool content_changed() const
506 {
507 //return GuiWidgetForward::content_changed();
508 bool b = is_currently_visible != is_visible2();
509 is_currently_visible = is_visible2();
511 }
512
513private:
516 GuiWidget *w;
517 std::vector<GuiWidget*> items;
518 mutable bool is_currently_visible=false;
519 static bool inside_redraw;
520 GameApi::W *redraw_w=0;
521};
522
523bool HideWidgetIfArrayEmpty::inside_redraw=false;
524#endif
525
526#ifndef EMSCRIPTEN
528{
529public:
530 HideNonSearchableGuiWidget(GameApi::Env &env, GameApi::EveryApi &ev, GuiWidget *w2, std::string label, GameApi::W *redraw_w) : GuiWidgetForward(ev, { w2 }), env(env), ev(ev), w(w2), label(label), redraw_w(redraw_w) {
531 Point2d p = { -666.0, -666.0 };
532 update(p, -1,-1, -1,0);
533 Point2d p2 = { 0.0, 0.0 };
534 set_pos(p2);
535
536
537 }
539 {
541 w->set_pos(pos);
542 }
543 void set_size(Vector2d size_p)
544 {
546 w->set_size(w->get_size());
547 size = w->get_size(); //size_p;
548 /*
549 if (!inside_redraw && redraw_w) {
550 inside_redraw=true;
551 GuiWidget *ww = find_widget(env,*redraw_w);
552 ww->set_pos(ww->get_pos());
553 ww->set_size(ww->get_size());
554 inside_redraw=false;
555 ww->render();
556 }
557 */
558 }
559 void update(Point2d mouse, int button, int ch, int type, int mouse_wheel_y)
560 {
561 if (is_visible2()|| (ch==-1&&button==-1&&type==-1)) // check if visible or if going to be made visible by search panel change
562 w->update(mouse,button,ch,type,mouse_wheel_y);
563 if (is_visible2())
564 {
565 size = w->get_size();
566 }
567 else
568 {
569 size = Vector2d(0.0,-2.0);
570 }
571 /*
572 if ((redraw_w && !inside_redraw) && ( button==-1 && ch==-1 && type==-1)) {
573 inside_redraw= true;
574 GuiWidget *ww = find_widget(env,*redraw_w);
575
576 Point2d p = { -666.0, -666.0 };
577 ww->update(p, -1,-1, -1,1);
578 Point2d p2 = { ww->get_pos().x, ww->get_pos().y };
579 ww->set_pos(p2);
580 Vector2d s2 = { ww->get_size().dx, ww->get_size().dy };
581 ww->set_size(s2);
582
583 ww->update(mouse,button,ch,type,mouse_wheel_y);
584
585
586 Point2d a_p = { -666.0, -666.0 };
587 ww->update(a_p, -1,-1, -1,0);
588 Point2d a_p2 = { ww->get_pos().x, ww->get_pos().y };
589 ww->set_pos(a_p2);
590 Vector2d a_s2 = { ww->get_size().dx, ww->get_size().dy };
591 ww->set_size(a_s2);
592
593 ww->update(mouse,button,ch,type,mouse_wheel_y);
594
595 inside_redraw=false;
596 }
597 */
598 }
599 virtual Point2d get_pos() const { return pos; }
600 virtual Vector2d get_size() const { if (is_visible2()) return size; /*w->get_size();*/ else return Vector2d(0.0,-2.0); } // -4 is because of margins upper in the scene.
601 //bool is_visible() const { return is_visible2() && GuiWidgetForward::is_visible(); }
602
603 bool is_visible2() const
604 {
605
606 std::string searchstring = g_searchstring;
607 //std::cout << "searchstring:" << searchstring << std::endl;
608 if (g_searchstring.size()==0||g_searchstring=="@") {
609 //if (g_searchstring.size()==0 || g_searchstring[0]!='@') g_searchstring="@";
610 return true;
611 }
612 //if (g_searchstring.size()>0 && g_searchstring[0]!='@') g_searchstring="@";
613 if (searchstring.size()>0 && searchstring[0]=='@') searchstring=searchstring.substr(1,searchstring.size()-1);
614 int s = label.size();
615 int s2 = searchstring.size();
616 for(int i=0;i<s-s2+1;i++)
617 {
618 bool found = true;
619 for(int j=0;j<s2;j++)
620 {
621 if (label[i+j]!=searchstring[j]) found=false;
622 }
623 if (found) return true;
624 }
625 return false;
626 }
627
628 void render()
629 {
630 if (is_visible2())
631 w->render();
632 }
634 { return 0; }
635 bool content_changed() const
636 {
637 bool b = is_currently_visible != is_visible2();
638 is_currently_visible = is_visible2();
640 }
641private:
644 GuiWidget *w;
645 std::string label;
646 mutable bool is_currently_visible = false;
647 GameApi::W *redraw_w=0;
648 static bool inside_redraw;
649};
650
651bool HideNonSearchableGuiWidget::inside_redraw = false;
652#endif
653
655{
656public:
657 AltGuiWidget(GameApi::EveryApi &ev, std::vector<GuiWidget*> vec, int *choose) : GuiWidgetForward(ev,vec), ev(ev), vec(vec), choose(choose) { }
658 void update(Point2d mouse, int button, int ch, int type, int mouse_wheel_y)
659 {
660 int s = vec.size();
661 for(int i=0;i<s;i++) {
662 vec[i]->update(mouse,button,ch,type,mouse_wheel_y);
663 }
664 }
666 {
668 int s = vec.size();
669 for(int i=0;i<s;i++) {
670 vec[i]->set_size(v);
671 }
672 }
673 void render()
674 {
675 int cho = *choose;
676 if (cho>=0&&cho<vec.size())
677 vec[cho]->render();
678 }
680 { return 0; }
681private:
683 std::vector<GuiWidget*> vec;
684 int *choose;
685};
686
687
689{
690public:
691 OverlapGuiWidget(GameApi::EveryApi &ev, std::vector<GuiWidget*> vec) : GuiWidgetForward(ev,vec), ev(ev), vec(vec) { }
692 void update(Point2d mouse, int button, int ch, int type, int mouse_wheel_y)
693 {
694 int s = vec.size();
695 for(int i=0;i<s;i++) {
696 vec[i]->update(mouse,button,ch,type,mouse_wheel_y);
697 }
698 }
699 void render()
700 {
701 int s = vec.size();
702 for(int i=0;i<s;i++)
703 vec[i]->render();
704 }
706 { return 0; }
709 int s = vec.size();
710 for(int i=0;i<s;i++) {
711 vec[i]->set_size(v);
712 }
713 }
714private:
716 std::vector<GuiWidget*> vec;
717};
718
719IMPORT extern ConversionTableInterface *g_conv_table;
720
721
722std::map<std::string, int> shared_text;
723
724#ifndef EMSCRIPTEN
726{
727public:
728 TextGuiWidgetAtlas(GameApi::EveryApi &ev, std::string label, GameApi::FtA atlas, GameApi::BM atlas_bm, GameApi::SH sh, int x_gap) : GuiWidgetForward(ev, std::vector<GuiWidget*>()), label(label), atlas(atlas), atlas_bm(atlas_bm), sh(sh), x_gap(x_gap) { firsttime = true;
729 //std::cout << "TextGuiWidgetAtlas: " << atlas.id << " " << atlas_bm.id << std::endl;
730 Point2d p = { -666.0, -666.0 };
731 update(p, -1,-1, -1,0);
732 Point2d p2 = { 0.0, 0.0 };
733 set_pos(p2);
734 sh = ev.shader_api.texture_shader(true);
735 }
736 void update(Point2d mouse, int button, int ch, int type, int mouse_wheel_y)
737 {
738 if (firsttime)
739 {
740 std::string display_label = label;
741
742 display_label = g_conv_table->convert_labels_to_chars(display_label);
743
744 int c = get_current_block();
746 rendered_bitmap = ev.font_api.font_string_from_atlas(ev, atlas, atlas_bm, display_label.c_str(), x_gap*1.2);
747
748 //GameApi::CBM sca = ev.cont_bitmap_api.from_bitmap(rendered_bitmap, 1.0, 1.0);
749 //int sx = ev.bitmap_api.size_x(rendered_bitmap);
750 //int sy = ev.bitmap_api.size_y(rendered_bitmap);
751 //scaled_bitmap = ev.cont_bitmap_api.sample(sca, sx/2, sy/2);
752
753 int sx = ev.bitmap_api.size_x(rendered_bitmap);
754 int sy = ev.bitmap_api.size_y(rendered_bitmap);
755 //GameApi::BM scaled_bitmap0 = ev.bitmap_api.simple_blur(rendered_bitmap, 1.0, 0.25, 0.25, 0.25, 0.25); //
756 scaled_bitmap = rendered_bitmap; //ev.bitmap_api.scale_bitmap(ev,scaled_bitmap0, int(float(sx-2)/8.0),int(float(sy-2)/8.0));
757 std::stringstream ss;
758 ss << sx << " " << sy;
759 std::string key = label + ss.str();
760 std::map<std::string,int>::iterator i = shared_text.find(key);
761 if (i!=shared_text.end())
762 {
763
764 rendered_bitmap_va.id = (*i).second;
765 } else {
766 rendered_bitmap_va = ev.sprite_api.create_vertex_array(scaled_bitmap,false,true); // progress=false, textrender=true
767 shared_text[key]=rendered_bitmap_va.id;
768 }
770 firsttime = false;
771 }
772 size.dx = ev.bitmap_api.size_x(scaled_bitmap);
773 size.dy = ev.bitmap_api.size_y(scaled_bitmap);
774 }
775
776 void render()
777 {
778 if (is_visible())
779 if (!firsttime)
780 {
781 Point2d p = get_pos();
782 OpenglLowApi *ogl = g_low->ogl;
783 //ogl->glAlphaFunc(Low_GL_LESS, 0.9);
784 //ogl->glEnable(Low_GL_ALPHA_TEST);
785 ev.shader_api.use(sh);
786 ev.shader_api.set_var(sh, "in_MV", ev.matrix_api.trans(p.x,p.y,0.0));
787 ev.sprite_api.render_sprite_vertex_array(rendered_bitmap_va);
788 //ogl->glDisable(Low_GL_ALPHA_TEST);
789 }
790 }
792 {
793 return rendered_bitmap.id;
794 }
795private:
796 bool firsttime;
797 std::string label;
798 GameApi::FtA atlas;
799 GameApi::BM atlas_bm;
800 GameApi::SH sh;
801 GameApi::BM rendered_bitmap;
802 GameApi::BM scaled_bitmap;
803 GameApi::VA rendered_bitmap_va;
804 int x_gap;
805};
806#endif
807#endif
808
809template<class T>
811{
812public:
813 EditorGuiWidget(GameApi::EveryApi &ev, std::string allowed_chars, T &target_m, GameApi::Ft font, GameApi::SH sh) : GuiWidgetForward(ev, std::vector<GuiWidget*>()), allowed_chars(allowed_chars), target(target_m), font(font), sh(sh) { firsttime = true; active=false;
814 Point2d p = { -666.0, -666.0 };
815 update(p, -1,-1, -1,0);
816 Point2d p2 = { 0.0, 0.0 };
817 set_pos(p2);
818 }
819 void update(Point2d mouse, int button, int ch, int type, int mouse_wheel_y)
820 {
821 bool changed = false;
822 Point2d pos = get_pos();
823 Vector2d sz = get_size();
824 if (button == 0 && type==1025 && mouse.x>=pos.x && mouse.x < pos.x+sz.dx
825 && mouse.y>=pos.y && mouse.y<pos.y+sz.dy)
826 {
827 active = true;
828 }
829 else if (button==0)
830 {
831 active = false;
832
833 }
834
835 if (firsttime)
836 {
837 std::stringstream ss;
838 ss << target;
839 label = ss.str();
840 }
841
842 if (active)
843 {
844 int s = allowed_chars.size();
845 for(int i=0;i<s;i++)
846 {
847 if (allowed_chars[i]==ch)
848 {
849 label.push_back(ch);
850 changed = true;
851 }
852 }
853 if (ch==8 && label.size()>0)
854 {
855 label.erase(label.begin()+(label.size()-1));
856 changed = true;
857 }
858 }
859
860 // note, spaces are not allowed.
861 if (active) {
862 //std::cout << "EDITOR UPDATES: " << label << std::endl;
863 std::stringstream ss2(label);
864 ss2 >> target;
865 //std::cout << "EDITOR UPDATES2: " << target << std::endl;
866 }
867
868 if (firsttime || changed)
869 {
870 rendered_bitmap = ev.font_api.font_string(font, label.c_str(), 2);
871 rendered_bitmap_va = ev.sprite_api.create_vertex_array(rendered_bitmap);
872 firsttime = false;
873 }
874 size.dx = ev.bitmap_api.size_x(rendered_bitmap);
875 size.dy = ev.bitmap_api.size_y(rendered_bitmap);
876 }
877 void render()
878 {
879 if (is_visible())
880 if (!firsttime)
881 {
882 Point2d p = get_pos();
883 ev.shader_api.set_var(sh, "in_MV", ev.matrix_api.trans(p.x+0.5,p.y+0.5,0.0));
884 ev.sprite_api.render_sprite_vertex_array(rendered_bitmap_va);
885 }
886 }
888 {
889 return rendered_bitmap.id;
890 }
891private:
892 bool firsttime;
893 std::string allowed_chars;
894 T &target;
895 std::string label;
896 std::string oldlabel;
897 GameApi::Ft font;
898 GameApi::SH sh;
899 GameApi::BM rendered_bitmap;
900 GameApi::VA rendered_bitmap_va;
901 bool active;
902};
903
904std::string FloatExprEval(std::string s);
905std::string StringExprEval(std::string s);
906std::string IntExprEval(std::string s);
907
908template<class T>
909class Conv {
910public:
911 static void set(T &target, std::string s, bool allow_expr, std::string &expr) { std::stringstream ss(s); ss >> target; expr=s; }
912 static void get(const T &target, std::string &s, bool allow_expr, std::string &expr) { std::stringstream ss; ss << target; s=ss.str(); }
913 static std::string error(const std::string &target, const std::string &dd) { return "Drag & Drop not allowed for the type!"; }
914};
915template<>
916class Conv<std::string>
917{
918public:
919 static void set(std::string &target, std::string s, bool allow_expr, std::string &expr) { if (allow_expr) { expr=s; s=StringExprEval(expr); } else { s=StringExprEval(s); } target = s; }
920 static void get(const std::string &target, std::string &s, bool allow_expr, std::string &expr) { if (allow_expr && expr!="" && expr!="@") s= expr; else s= target; /*expr=target;*/ }
921 static std::string error(const std::string &target, const std::string &dd_ext) {
922 std::string filename = target;
923 std::string ext = filename.size()<4?"@":filename.substr(filename.size()-3);
924
925 return std::string("Drag & Drop not allowed for the extension .") + ext + ", since required: ." + dd_ext + "!"; }
926};
927template<>
928class Conv<float>
929{
930public:
931 static void set(float &target, std::string s, bool allow_expr, std::string &expr) { if (allow_expr) { expr = s; s=FloatExprEval(expr); } else s = FloatExprEval(s); std::stringstream ss(s); ss >> target; }
932 static void get(const float &target, std::string &s, bool allow_expr, std::string &expr) { std::stringstream ss; if (allow_expr && expr!="" && expr!="@") ss << expr; else ss << target; s=ss.str(); }
933 static std::string error(const std::string &target, const std::string &dd) { return "Drag & Drop not allowed for the type float!"; }
934};
935
936template<>
937class Conv<int>
938{
939public:
940 static void set(int &target, std::string s, bool allow_expr, std::string &expr) { if (allow_expr) { expr = s; s=IntExprEval(expr); } else s = IntExprEval(s); std::stringstream ss(s); ss >> target; }
941 static void get(const int &target, std::string &s, bool allow_expr, std::string &expr) { std::stringstream ss; if (allow_expr && expr!="" && expr!="@") ss << expr; else ss << target; s=ss.str(); }
942 static std::string error(const std::string &target, const std::string &dd) { return "Drag & Drop not allowed for the type int!"; }
943};
944
945template<class T>
947{
948public:
949 MultilineEditor(GameApi::EveryApi &ev, std::string allowed_chars, T &target_m, GameApi::FI font, GameApi::SH sh, int x_gap, int line_height) : GuiWidgetForward(ev, std::vector<GuiWidget*>()), allowed_chars(allowed_chars), target(target_m), font(font), sh(sh), x_gap(x_gap), line_height(line_height) {
950 firsttime = true; active=false;
951 Point2d p = { -666.0, -666.0 };
952 update(p, -1, -1, -1, 0);
953 Point2d p2 = { 0.0, 0.0 };
954 set_pos(p2);
955 shift=false;
956 }
957 void update(Point2d mouse, int button, int ch, int type, int mouse_wheel_y)
958 {
959 bool changed = false;
960 Point2d pos = get_pos();
961 Vector2d sz = get_size();
962 if (button == 0 && type==1025 && mouse.x>=pos.x && mouse.x < pos.x+sz.dx
963 && mouse.y>=pos.y && mouse.y<pos.y+sz.dy)
964 {
965 active = true;
966 }
967 else if (button==0 && type==1025)
968 {
969 active = false;
970 }
971 //std::cout << type << " " << ch << std::endl;
972 if (type==768 && (ch==1073742049||ch==1073742053)) { shift=true; std::cout << "Shift1" << std::endl; }
973 if (type==769 && (ch==1073742049||ch==1073742053)) { shift=false; std::cout << "Shift2" << std::endl; }
974
975 if (firsttime)
976 {
977 std::string tmp;
978 Conv<T>::get(target, label, false, tmp);
979 }
980#ifdef EMSCRIPTEN
981 if (ch>=4 && ch<=29) { ch = ch - 4; ch=ch+'a'; }
982 if (ch==39) ch='0';
983 if (ch>=30 && ch<=38) { ch = ch-30; ch=ch+'1'; }
984#endif
985 if (ch==13) { ch='\n'; }
986 if (shift) {
987#ifdef EMSCRIPTEN
988 const char *chars1 = "";
989 const char *chars2 = "";
990#else
991 const char *chars1 = "§1234567890+',.-abcdefghijklmnopqrstuvwxyz";
992 const char *chars2 = "œ!\"#€%&/()=?*;:_ABCDEFGHIJKLMNOPQRSTUVWXYZ";
993#endif
994 int s = strlen(chars1);
995 for(int i=0;i<s;i++)
996 {
997 if (ch == chars1[i]) ch=chars2[i];
998 }
999 if (ch==45) ch='_';
1000 }
1001 if (active && type==768)
1002 {
1003 int s = allowed_chars.size();
1004 for(int i=0;i<s;i++)
1005 {
1006 if (allowed_chars[i]==ch)
1007 {
1008 label.push_back(ch);
1009 changed = true;
1010 }
1011 }
1012 if ((ch==8 ||ch==42) && label.size()>0)
1013 {
1014 label.erase(label.begin()+(label.size()-1));
1015 changed = true;
1016 }
1017 }
1018
1019 // note, spaces are not allowed.
1020 if (active) {
1021 std::string tmp;
1022 Conv<T>::set(target, label,false,tmp);
1023 }
1024
1025 if (firsttime || changed)
1026 {
1027 rendered_bitmap = ev.font_api.draw_text_string(font, label, x_gap, line_height);
1028 //int sx = ev.bitmap_api.size_x(rendered_bitmap);
1029 //int sy = ev.bitmap_api.size_y(rendered_bitmap);
1030 //GameApi::CBM cbm = ev.cont_bitmap_api.from_bitmap(rendered_bitmap, 1.0,1.0);
1031 scaled_bitmap = rendered_bitmap; //ev.cont_bitmap_api.sample(cbm, sx/2, sy/2);
1032 rendered_bitmap_va = ev.sprite_api.create_vertex_array(scaled_bitmap);
1033 firsttime = false;
1034 }
1035 size.dx = ev.bitmap_api.size_x(scaled_bitmap);
1036 size.dy = ev.bitmap_api.size_y(scaled_bitmap);
1037 }
1038
1039 void render()
1040 {
1041 if (is_visible())
1042 if (!firsttime)
1043 {
1044 Point2d p = get_pos();
1045 ev.shader_api.set_var(sh, "in_MV", ev.matrix_api.trans(p.x+0.5,p.y+0.5,0.0));
1046 ev.sprite_api.render_sprite_vertex_array(rendered_bitmap_va);
1047
1048 }
1049 }
1050private:
1051 bool firsttime;
1052 std::string allowed_chars;
1053 T &target;
1054 std::string label;
1055 GameApi::FI font;
1056 GameApi::SH sh;
1057 GameApi::BM rendered_bitmap;
1058 GameApi::BM scaled_bitmap;
1059 GameApi::VA rendered_bitmap_va;
1060 bool active;
1061 int x_gap;
1062 int line_height;
1063 bool shift;
1064};
1065
1066
1069
1070std::string g_temp44;
1071
1073
1074
1075int find_str(std::string val, std::string repl);
1076
1077
1078
1079bool is_allowed(std::string chars, char ch)
1080{
1081 int s = chars.size();
1082 for(int i=0;i<s;i++) if (ch==chars[i]) return true;
1083 return false;
1084}
1085
1086#ifndef EMSCRIPTEN
1087
1088IMPORT extern GameApi::PAT gameapi_temp_dir;
1089
1090std::string GetContentInstallDir(bool b);
1091
1092
1093template<class T>
1095{
1096public:
1097 EditorGuiWidgetAtlas(GameApi::Env &env, GameApi::EveryApi &ev, std::string allowed_chars, T &target_m, GameApi::FtA atlas, GameApi::BM atlas_bm, GameApi::SH sh, int x_gap, bool allow_expr=false, std::string &expr = g_temp44, int non_editable=0, GameApi::W *redraw_w=0) : env(env), GuiWidgetForward(ev, std::vector<GuiWidget*>()), allowed_chars(allowed_chars), target(target_m), atlas(atlas), atlas_bm(atlas_bm), sh(sh), x_gap(x_gap), allow_expr(allow_expr), expr(expr),non_editable(non_editable),redraw_w(redraw_w) { firsttime = true; active=false;
1098 Point2d p = { -666.0, -666.0 };
1099 update(p, -1,-1, -1,0);
1100 Point2d p2 = { 0.0, 0.0 };
1101 set_pos(p2);
1102 shift=false;
1103 ctrl=false;
1104 altgr=false;
1105 sh = ev.shader_api.texture_shader(true);
1106 }
1107 void update(Point2d mouse, int button, int ch, int type, int mouse_wheel_y)
1108 {
1109 //std::cout << "button=" << button << " ch=" << ch << " type=" << std::hex << type << " wheel_y=" << mouse_wheel_y << std::endl;
1110 if (inside_redraw) return;
1111 bool changed = false;
1112 Point2d pos = get_pos();
1113 Vector2d sz = get_size();
1114
1115 //std::cout << "ATTEMPT DRAGDROP: " << g_dragdrop_enabled << " " << button << " " << type << std::endl;
1116
1117 //std::cout << "Attempt active:" << button << type << std::endl;
1118 if (button == 0 && type==1025 && mouse.x>=pos.x && mouse.x < pos.x+sz.dx
1119 && mouse.y>=pos.y && mouse.y<pos.y+sz.dy)
1120 {
1121 //std::cout << "active=true" << std::endl;
1122 active = true;
1123 }
1124 else if (button==0 && type==1025)
1125 {
1126 //std::cout << "active=false" << std::endl;
1127 active = false;
1128 }
1129
1130
1131 static int state=0;
1132 if (button==0 && type==1024) state=1;
1133 if (button!=0 && type==1024) state=0;
1134 if (g_dragdrop_enabled && state==1 && button==-1 && type==1026 && mouse.x>=pos.x && mouse.x < pos.x+sz.dx
1135 && mouse.y>=pos.y && mouse.y<pos.y+sz.dy)
1136 {
1137 g_dragdrop_enabled=false;
1138 g_reload_edit_dialog = true;
1139 std::string filename = g_dragdrop_filename;
1140
1141
1142 std::string ext = filename.size()<4?"@":filename.substr(filename.size()-3);
1143 if (drag_drop_ext == ext
1144 ||((ext==".ds"||ext=="obj")&&(drag_drop_ext==".ds"||drag_drop_ext=="obj"))
1145 ||((ext=="jpg"||ext=="png"||ext=="peg")&&(drag_drop_ext=="jpg"||drag_drop_ext=="png"||drag_drop_ext=="peg"))
1146
1147 ) {
1148 label="@" + filename;
1149 changed=true;
1150 active=true;
1151 } else {
1152 std::string err = Conv<T>::error(ext,drag_drop_ext);
1153 std::cout << err << std::endl;
1154 }
1155 //std::cout << "DRAGDROP" << std::endl;
1156 }
1157
1158
1159 //std::cout << type << " " << ch << std::endl;
1160 bool shiftactiveevent=false;
1161 if (type==768 && (ch==1073742049||ch==1073742053)) { shift=true; shiftactiveevent=true;}
1162 if (type==769 && (ch==1073742049||ch==1073742053)) { shift=false; }
1163 if (type==768 && (ch==1073742048||ch==1073742052)) { ctrl = true; }
1164 if (type==769 && (ch==1073742048||ch==1073742052)) { ctrl = false; }
1165 if (type==768 && (ch==1073742054)) { altgr=true; }
1166 if (type==769 && (ch==1073742054)) { altgr=false; }
1167
1168
1169 if (firsttime)
1170 {
1171 Conv<T>::get(target, label, allow_expr, expr);
1172
1173 if (find_str(label,"$(tempdir)") != -1) {
1174 std::cout << "Note: $(tempdir) is the same as " << g_path_handler->use_path(env,gameapi_temp_dir,g_path_handler->situ(PathHandler::EDragDropInfoMessage)) << std::endl;
1175 }
1176 {
1177 int l1,l2;
1178 if ((l1=find_str(label,"$(instdir)")) != -1 ||
1179 (l2=find_str(label,"$(INSTDIR)")) != -1)
1180 {
1181 std::string chosen;
1182 if (l1!=-1) chosen="$(instdir)";
1183 if (l2!=-1) chosen="$(INSTDIR)";
1184 std::string cd2 = GetContentInstallDir(false);
1185 std::cout << "Note: " << chosen << " is the same as " << cd2 << std::endl;
1186
1187
1188
1189 }
1190
1191 }
1192 {
1193 int l1=-1,l2=-1,l3=-1,l4=-1;
1194 if ((l1=find_str(label,"%CD%")) != -1
1195 ||(l2= find_str(label,"%cd")) != -1
1196 ||(l3=find_str(label,"$(pwd)")) != -1
1197 ||(l4=find_str(label, "$(PWD)")) != -1)
1198 {
1199 std::string chosen="";
1200 if (l1!=-1) chosen="%CD%";
1201 if (l2!=-1) chosen="%cd%";
1202 if (l3!=-1) chosen="$(pwd)";
1203 if (l4!=-1) chosen="$(PWD)";
1204
1205#ifdef WINDOWS
1206
1207 char buffer3[MAX_PATH];
1208 if (_getcwd(buffer3,sizeof(buffer3))) {
1209 std::string cd = buffer3;
1210#endif
1211#ifdef LINUX
1212 char buffer3[PATH_MAX];
1213 buffer3[0]=0;
1214 getcwd(buffer3, PATH_MAX);
1215 if (1)
1216 {
1217 std::string cd = buffer3;
1218
1219#endif
1220
1221 std::cout << "Note: " << chosen << " is the same as " << cd << std::endl;
1222 }
1223 }
1224 }
1225
1226
1227
1228 std::string ext = label.size()<4?"$":label.substr(label.size()-3);
1229 drag_drop_ext = ext;
1230
1231
1232
1233 //std::stringstream ss;
1234 //ss << target;
1235 //label = target; //ss.str();
1236 }
1237#ifdef EMSCRIPTEN
1238 if (ch>=4 && ch<=29) { ch = ch - 4; ch=ch+'a'; }
1239 if (ch==39) ch='0';
1240 if (ch>=30 && ch<=38) { ch = ch-30; ch=ch+'1'; }
1241#endif
1242 // finnish åöä
1243 if (ch==229) { ch='\xE5'; }
1244 if (ch==246) { ch='\xF6'; }
1245 if (ch==228) { ch='\xE4'; }
1246
1247 if (ch==13) { ch='\n'; }
1248 if (altgr && ch=='4') { ch='$'; }
1249 if (ctrl && ch=='s') { ch=0; }
1250 if (active && ctrl && type==768 && ch==118) // ctrl-v
1251 {
1252 char *buf = g_low->sdl->SDL_GetClipboardText();
1253 std::string buf2 = buf;
1254 int s = buf2.size();
1255 std::string buf3;
1256 for(int i=0;i<s;i++) {
1257 int s2 = allowed_chars.size();
1258 bool insert = false;
1259 for(int j=0;j<s2;j++) {
1260 if (allowed_chars[j]==buf2[i]) { insert=true; break; }
1261 }
1262 if (insert) buf3.push_back(buf2[i]);
1263 }
1264
1265 label = buf3;
1266 changed=true;
1267 }
1268 if (active && ctrl && type==768 && ch==99) {
1269 g_low->sdl->SDL_SetClipboardText(label.c_str());
1270 changed=true;
1271 }
1272 if (active && ctrl) ch=0;
1273 //std::cout << "PART1:" << (int)ch << "==" << (char)ch << std::endl;
1274 if (shift) {
1275#ifdef EMSCRIPTEN
1276 const unsigned char *chars1 = (unsigned char*)"";
1277 const unsigned char *chars2 = (unsigned char*)"";
1278#else
1279 const unsigned char *chars1 = (unsigned char*)"abcdefghijklmnopqrstuvwxyz\xE5\xE4\xF6 13567890+',.-";
1280 const unsigned char *chars2 = (unsigned char*)"ABCDEFGHIJKLMNOPQRSTUVWXYZ\xC5\xC4\xD6 !#%&/()=?*;:_";
1281#endif
1282 int s = strlen((const char*)chars1);
1283 for(int i=0;i<s;i++)
1284 {
1285 if ((((unsigned int)ch)&0xff) == (((unsigned int)(chars1[i]))&0xff)) { ch=(int)(((unsigned int)(chars2[i]))&0xff);
1286 }
1287
1288 }
1289 if (ch==45) ch='_';
1290 //ch = std::toupper(ch);
1291 }
1292 //std::cout << "PART2:" << (int)ch << "==" << (char)ch << std::endl;
1293
1294 if (altgr) {
1295#ifdef EMSCRIPTEN
1296 const unsigned char *chars1 = (unsigned char*)"";
1297 const unsigned char *chars2 = (unsigned char*)"";
1298#else
1299 const unsigned char *chars1 = (unsigned char*)"024789+'3";
1300 const unsigned char *chars2 = (unsigned char*)"}@${[]\\¸£";
1301#endif
1302 int s = strlen((const char*)chars1);
1303 for(int i=0;i<s;i++)
1304 {
1305 if (ch == chars1[i]) {
1306 ch=(unsigned char)(chars2[i]);
1307 break;
1308 }
1309 }
1310 }
1311 //std::cout << "PART3:" << (int)ch << "==" << (char)ch << std::endl;
1312 bool done = false;
1313 if (active && is_allowed(allowed_chars,ch) && type==768)
1314 {
1315 done = g_conv_table->insert_label_to_string(&label,ch);
1316 }
1317 if (done) changed=true;
1318 if (!done)
1319 if (active && type==768 && !changed && !shiftactiveevent)
1320 {
1321 int s = allowed_chars.size();
1322 for(int i=0;i<s;i++)
1323 {
1324 if ((int((unsigned int)allowed_chars[i])&0xff)==(ch&0xff))
1325 {
1326 label.push_back(ch);
1327 changed = true;
1328 break;
1329 }
1330 }
1331 if (!changed) {
1332 if ((ch==8 ||ch==42) && label.size()>non_editable)
1333 {
1334 if (label.size()>4 && label.size()>non_editable+4) {
1335 int loc = g_conv_table->find_last_location(label);
1336 if (loc!=-1 && loc==label.size()-5)
1337 {
1338 label.erase(label.begin()+(label.size()-1));
1339 label.erase(label.begin()+(label.size()-1));
1340 label.erase(label.begin()+(label.size()-1));
1341 label.erase(label.begin()+(label.size()-1));
1342 label.erase(label.begin()+(label.size()-1));
1343 changed=true;
1344 }
1345 else {
1346 label.erase(label.begin()+(label.size()-1));
1347 changed = true;
1348 }
1349
1350 } else {
1351 label.erase(label.begin()+(label.size()-1));
1352 changed = true;
1353 }
1354 }
1355 }
1356 }
1357 // note, spaces are not allowed.
1358 if (active) {
1359 //std::cout << "EDITOR UPDATES: " << label << std::endl;
1360 //std::cout << "EDITOR UPDATES0: " << allow_expr << "::"<< expr << std::endl;
1361 //std::stringstream ss2(label);
1362 //ss2 >> target;
1363 Conv<T>::set(target, label, allow_expr, expr);
1364 //std::cout << "EDITOR UPDATES2: " << target << std::endl;
1365 }
1366
1367 if (firsttime || changed||externally_set)
1368 {
1369 externally_set=false;
1370 std::string display_label = label;
1371
1372 display_label = g_conv_table->convert_labels_to_chars(display_label);
1373
1374 rendered_bitmap = ev.font_api.font_string_from_atlas(ev, atlas, atlas_bm, non_editable>0?(std::string("[ ") + std::string(display_label.substr(1,display_label.size()-1))+std::string(" ]")).c_str():display_label.c_str(), x_gap*1.2);
1375 //int sx = ev.bitmap_api.size_x(rendered_bitmap);
1376 //int sy = ev.bitmap_api.size_y(rendered_bitmap);
1377 //GameApi::CBM cbm = ev.cont_bitmap_api.from_bitmap(rendered_bitmap, 1.0,1.0);
1378 scaled_bitmap = rendered_bitmap; //ev.cont_bitmap_api.sample(cbm, sx/2, sy/2);
1379 rendered_bitmap_va = ev.sprite_api.create_vertex_array(scaled_bitmap,false,true); // progres=false, textrender=true
1380 firsttime = false;
1381
1382 if (redraw_w && !inside_redraw) {
1383 inside_redraw= true;
1384 GuiWidget *ww = find_widget(env,*redraw_w);
1385
1386 Point2d p = { -666.0, -666.0 };
1387 ww->update(p, -1,-1, -1,1);
1388 //Point2d p2 = { ww->get_pos().x, ww->get_pos().y };
1389 //ww->set_pos(p2);
1390 //Vector2d s2 = { ww->get_size().dx, ww->get_size().dy };
1391 //ww->set_size(s2);
1392
1393 ww->update(mouse,button,ch,type,mouse_wheel_y);
1394 //ww->render();
1395
1396 //Point2d a_p = { -666.0, -666.0 };
1397 //ww->update(a_p, -1,-1, -1,0);
1398 //Point2d a_p2 = { ww->get_pos().x, ww->get_pos().y };
1399 //ww->set_pos(a_p2);
1400 //Vector2d a_s2 = { ww->get_size().dx, ww->get_size().dy };
1401 //ww->set_size(a_s2);
1402
1403 //ww->update(mouse,button,ch,type,mouse_wheel_y);
1404 //ww->render();
1405
1406 inside_redraw=false;
1407 }
1408 }
1409 size.dx = ev.bitmap_api.size_x(scaled_bitmap);
1410 size.dy = ev.bitmap_api.size_y(scaled_bitmap);
1411 }
1412 void render()
1413 {
1414 if (inside_redraw) return;
1415 if (is_visible())
1416 if (!firsttime)
1417 {
1418 Point2d p = get_pos();
1419 ev.shader_api.set_var(sh, "in_MV", ev.matrix_api.trans(p.x+0.5,p.y+0.5,0.0));
1420 //glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE);
1421 ev.sprite_api.render_sprite_vertex_array(rendered_bitmap_va);
1422 //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1423
1424 if (redraw_w && !inside_redraw) {
1425 inside_redraw= true;
1426 GuiWidget *ww = find_widget(env,*redraw_w);
1427 ww->render();
1428 inside_redraw=false;
1429 }
1430
1431
1432 }
1433 }
1435 {
1436 return rendered_bitmap.id;
1437 }
1438 void set_value(std::string value) {
1439 if (non_editable!=0) {
1440 label = "@" + value;
1441 expr="@" + value;
1442 } else {
1443 label = value;
1444 expr=value;
1445 }
1446 Conv<T>::set(target, label,allow_expr,expr);
1447 externally_set=true;
1448 }
1449private:
1450 GameApi::Env &env;
1451 bool firsttime;
1452 std::string allowed_chars;
1453 T &target;
1454 std::string &expr;
1455 bool allow_expr;
1456 std::string label;
1457 GameApi::FtA atlas;
1458 GameApi::BM atlas_bm;
1459 GameApi::SH sh;
1460 GameApi::BM rendered_bitmap;
1461 GameApi::BM scaled_bitmap;
1462 GameApi::VA rendered_bitmap_va;
1463 bool active=false;
1464 int x_gap;
1465 bool shift=false;
1466 bool ctrl=false;
1467 bool altgr=false;
1468 bool externally_set=false;
1469 std::string drag_drop_ext;
1470 int non_editable=0;
1471 GameApi::W *redraw_w=0;
1472 bool inside_redraw=false;
1473};
1474#endif
1475
1476
1477
1478class PolyGuiWidget : public GuiWidgetForward
1479{
1480public:
1481 PolyGuiWidget(GameApi::EveryApi &ev, GameApi::P p, GameApi::SH sh, GameApi::SH old_sh, int sx, int sy, int screen_x, int screen_y) : GuiWidgetForward(ev, { }), sh(sh), old_sh(old_sh), p(p), obj(ev, p, sh),sx(sx),sy(sy), screen_x(screen_x), screen_y(screen_y) { firsttime = true;
1482 Point2d p3 = {-666.0, -666.0 };
1483 update(p3, -1,-1,-1,0);
1484 Point2d p2 = { 0.0,0.0 };
1485 set_pos(p2);
1486 rot_y = 0.0;
1487 left=false; right=false;
1488 }
1489 ~PolyGuiWidget() { /*std::cout << "PolyGuiWidget destructor" << std::endl;*/ }
1490 void update(Point2d mouse, int button, int ch, int type, int mouse_wheel_y)
1491 {
1492#ifdef EMSCRIPTEN
1493 if (ch>=4 && ch<=29) { ch = ch - 4; ch=ch+'a'; }
1494 if (ch==39) ch='0';
1495 if (ch>=30 && ch<=38) { ch = ch-30; ch=ch+'1'; }
1496#endif
1497
1498 if (ch=='a' && type==0x300)
1499 {
1500 left = true;
1501 }
1502 if (ch=='a' && type==0x301)
1503 {
1504 left = false;
1505 }
1506 if (ch=='d' && type==0x300)
1507 {
1508 right=true;
1509 }
1510 if (ch=='d' && type==0x301)
1511 {
1512 right=false;
1513 }
1514
1515 if (firsttime)
1516 {
1517 obj.prepare();
1518 firsttime = false;
1519 }
1520 size.dx = sx;
1521 size.dy = sy;
1522 }
1523 void render()
1524 {
1525 OpenglLowApi *ogl = g_low->ogl;
1526
1527 if (is_visible()) {
1528 if (left)
1529 {
1530 rot_y+=1.0*3.14159*2.0/360.0*ev.mainloop_api.get_delta_time()*keypress_rot_speed;
1531 obj.set_rotation_y(rot_y);
1532 }
1533 if (right)
1534 {
1535 rot_y-=1.0*3.14159*2.0/360.0*ev.mainloop_api.get_delta_time()*keypress_rot_speed;
1536 obj.set_rotation_y(rot_y);
1537 }
1538 if (!firsttime)
1539 {
1540 Point2d pos = get_pos();
1541 Vector2d sz = get_size();
1542 float scale_x = 1.0;
1543 float scale_y = 1.0;
1544 if (g_event_screen_y!=-1) {
1545 scale_x = float(g_event_screen_x)/float(screen_x);
1546 scale_y = float(g_event_screen_y)/float(screen_y);
1547 }
1548 ogl->glViewport(pos.x*scale_x, screen_y*scale_y-pos.y*scale_y-sz.dy*scale_y, sz.dx*scale_x, sz.dy*scale_y);
1549 ev.shader_api.use(sh);
1550 ev.mainloop_api.switch_to_3d(true, sh, screen_x, screen_y);
1551
1552 if (!g_transparent) {
1554 g_low->ogl->glScissor(pos.x, screen_y-pos.y-sz.dy, sz.dx,sz.dy);
1555 ev.mainloop_api.clear_3d(0xff000000);
1557
1558 }
1559
1562 obj.render();
1564 ev.mainloop_api.switch_to_3d(false, sh, screen_x, screen_y);
1565 ogl->glViewport(0,0,screen_x*scale_x, screen_y*scale_y);
1566 ev.shader_api.use(old_sh);
1568 }
1569 }
1570private:
1571 GameApi::SH sh;
1572 GameApi::SH old_sh;
1573 GameApi::P p;
1574 GameApi::PolygonObj obj;
1575 bool firsttime;
1576 int sx,sy;
1577 int screen_x, screen_y;
1578 float rot_y;
1579 bool left,right;
1580};
1581
1582class VAGuiWidget : public GuiWidgetForward
1583{
1584public:
1585 VAGuiWidget(GameApi::EveryApi &ev, GameApi::VA p, GameApi::SH sh, GameApi::SH old_sh, int sx, int sy, int screen_x, int screen_y) : GuiWidgetForward(ev, { }), sh(sh), old_sh(old_sh), p(p),sx(sx),sy(sy), screen_x(screen_x), screen_y(screen_y) { firsttime = true;
1586 Point2d p3 = {-666.0, -666.0 };
1587 update(p3, -1,-1,-1,0);
1588 Point2d p2 = { 0.0,0.0 };
1589 set_pos(p2);
1590 rot_y = 0.0;
1591 mat = ev.matrix_api.identity();
1592 left=false; right=false;
1593 }
1594 void update(Point2d mouse, int button, int ch, int type, int mouse_wheel_y)
1595 {
1596#ifdef EMSCRIPTEN
1597 if (ch>=4 && ch<=29) { ch = ch - 4; ch=ch+'a'; }
1598 if (ch==39) ch='0';
1599 if (ch>=30 && ch<=38) { ch = ch-30; ch=ch+'1'; }
1600#endif
1601
1602 if (ch=='a' && type==0x300)
1603 {
1604 left = true;
1605 }
1606 if (ch=='a' && type==0x301)
1607 {
1608 left = false;
1609 }
1610 if (ch=='d' && type==0x300)
1612 right = true;
1613 }
1614 if (ch=='d' && type==0x301)
1615 {
1616 right=false;
1617 }
1618
1619 if (firsttime)
1620 {
1621 //obj.prepare();
1622 firsttime = false;
1623 }
1624 size.dx = sx;
1625 size.dy = sy;
1626 }
1627 void render()
1628 {
1629 OpenglLowApi *ogl = g_low->ogl;
1630 if (is_visible())
1631 {
1632 if (left)
1633 {
1634 rot_y+=1.0*3.14159*2.0/360.0*ev.mainloop_api.get_delta_time()*keypress_rot_speed;
1635 //obj.set_rotation_y(rot_y);
1636 mat = ev.matrix_api.yrot(rot_y);
1637 }
1638 if (right)
1639 {
1640 rot_y-=1.0*3.14159*2.0/360.0*ev.mainloop_api.get_delta_time()*keypress_rot_speed;
1641 //obj.set_rotation_y(rot_y);
1642 mat = ev.matrix_api.yrot(rot_y);
1643 }
1644 if (!firsttime)
1645 {
1646 Point2d pos = get_pos();
1647 Vector2d sz = get_size();
1648 float scale_x = 1.0;
1649 float scale_y = 1.0;
1650 if (g_event_screen_y!=-1) {
1651 scale_x = float(g_event_screen_x)/float(screen_x);
1652 scale_y = float(g_event_screen_y)/float(screen_y);
1653 }
1654 ogl->glViewport(pos.x*scale_x, screen_y*scale_y-pos.y*scale_y-sz.dy*scale_y, sz.dx*scale_x, sz.dy*scale_y);
1655 ev.shader_api.use(sh);
1656 ev.mainloop_api.switch_to_3d(true, sh, screen_x, screen_y);
1657
1658 if (!g_transparent) {
1660 g_low->ogl->glScissor(pos.x, screen_y-pos.y-sz.dy, sz.dx,sz.dy);
1661 ev.mainloop_api.clear_3d(0xff000000);
1663
1664 }
1665
1667 //obj.render();
1668 ev.shader_api.set_var(sh, "in_MV", mat);
1669 ev.polygon_api.render_vertex_array(p);
1671 ev.mainloop_api.switch_to_3d(false, sh, screen_x, screen_y);
1672 ogl->glViewport(0,0,screen_x*scale_x, screen_y*scale_y);
1673 ev.shader_api.use(old_sh);
1674 }
1675 }
1676 }
1677private:
1678 GameApi::SH sh;
1679 GameApi::SH old_sh;
1680 GameApi::VA p;
1681 GameApi::M mat;
1682 //GameApi::PolygonObj obj;
1683 bool firsttime;
1684 int sx,sy;
1685 int screen_x, screen_y;
1686 float rot_y;
1687 bool left,right;
1688};
1689
1690extern bool g_is_quake;
1691
1692bool g_inside_ml_widget;
1694extern bool g_inside_mesh_display;
1695
1696
1698{
1699public:
1701 vec.push_back(i);
1702 }
1704 vec2.push_back(i);
1705 }
1706 void execute(int i) {
1707 int sz = vec.size();
1708 if (i>=0 && i<sz && vec[i])
1709 vec[i]->HeavyPrepare();
1710 }
1711 void first_frame(int i) {
1712 int sz = vec2.size();
1713 if (i>=0 && i<sz && vec2[i])
1714 vec2[i]->FirstFrame();
1715 }
1716
1717 int count(int i) const
1718 {
1719 int sz = vec.size();
1720 if (i>=0 && i<sz && vec[i])
1721 return vec[i]->NumBlocks();
1722 return 1;
1723 }
1724public:
1725 std::vector<CollectInterface*> vec;
1726 std::vector<CollectInterface*> vec2;
1727 //int count=0;
1728};
1729
1730extern int g_time_id;
1731
1732extern std::vector<GameApi::TF> g_tf_instances;
1733
1734
1735class MLGuiWidget : public GuiWidgetForward
1736{
1737public:
1738 MLGuiWidget(GameApi::Env &env, GameApi::EveryApi &ev, GameApi::ML p, GameApi::SH sh, GameApi::SH sh2,GameApi::SH sh_2d, GameApi::SH sh_arr, GameApi::SH old_sh, int sx, int sy, int screen_x, int screen_y) : GuiWidgetForward(ev, { }), env(env), sh(sh), sh2(sh2), sh_2d(sh_2d), sh_arr(sh_arr), old_sh(old_sh), p(p),sx(sx),sy(sy), screen_x(screen_x), screen_y(screen_y) { firsttime = true;
1739 Point2d p3 = {-666.0, -666.0 };
1740 update(p3, -1,-1,-1,0);
1741 Point2d p2 = { 0.0,0.0 };
1742 set_pos(p2);
1743 rot_y = 0.0;
1744 mat = ev.matrix_api.identity();
1745 e.cursor_pos = ev.point_api.point(0.0,0.0,0.0);
1746 e.type = -1;
1747 e.ch = -1;
1748 e.button = -1;
1749 left=false; right=false;
1750 keys_enabled=true;
1751 g_is_quake = false;
1752 firsttime2=true;
1753 g_inside_ml_widget=true;
1754 }
1755 ~MLGuiWidget() { g_inside_ml_widget=false; }
1756 void update(Point2d mouse, int button, int ch, int type, int mouse_wheel_y)
1757 {
1758 if (firsttime)
1759 {
1760 ev.mainloop_api.reset_time();
1761 }
1762 if (type==0x300 || type==0x301 ||type==Low_SDL_JOYAXISMOTION || type==Low_SDL_JOYBALLMOTION)
1763 {
1764
1765 //std::cout << "update: " << type << " " << ch << " " << button << std::endl;
1766 e.type = type;
1767 e.ch = ch;
1768 e.button = button;
1769 e.cursor_pos = ev.point_api.point(mouse.x,mouse.y,0.0);
1770
1771 // TODO, JOYSTICK AXIS AND BALL EVENTS? (needs changes to widget? :)
1772
1773 static Low_SDL_Joystick *joy1 = g_low->sdl->SDL_JoystickOpen(0);
1774 unsigned int but1 = g_low->sdl->SDL_JoystickGetButton(joy1, 0);
1775 unsigned int but2 = g_low->sdl->SDL_JoystickGetButton(joy1, 1);
1776 unsigned int but3 = g_low->sdl->SDL_JoystickGetButton(joy1, 2);
1777 unsigned int but4 = g_low->sdl->SDL_JoystickGetButton(joy1, 3);
1778 e.joy0_button0 = but1==1;
1779 e.joy0_button1 = but2==1;
1780 e.joy0_button2 = but3==1;
1781 e.joy0_button3 = but4==1;
1782
1783 // TODO
1784 e.joy1_button0 = false;
1785 e.joy1_button1 = false;
1786 e.joy1_button2 = false;
1787 e.joy1_button3 = false;
1788
1789 e.joy0_current_axis = -1;
1790 e.joy0_axis0 = 0;
1791 e.joy0_axis1 = 0;
1792 e.joy0_axis2 = 0;
1793 e.joy0_axis3 = 0;
1794 e.joy0_axis4 = 0;
1795 e.joy1_current_axis = -1;
1796 e.joy1_axis0 = 0;
1797 e.joy1_axis1 = 0;
1798 e.joy1_axis2 = 0;
1799 e.joy1_axis3 = 0;
1800 e.joy1_axis4 = 0;
1801
1802
1803 e.joy0_ball0 = 0;
1804 e.joy0_ball1 = 0;
1805 e.joy1_ball0 = 0;
1806 e.joy1_ball1 = 0;
1807 // END OF TODO
1808 }
1809 if (!firsttime)
1810 {
1811 g_inside_mesh_display = true;
1812 ev.mainloop_api.event_ml(p, e);
1814 }
1815
1816#ifdef EMSCRIPTEN
1817 if (ch>=4 && ch<=29) { ch = ch - 4; ch=ch+'a'; }
1818 if (ch==39) ch='0';
1819 if (ch>=30 && ch<=38) { ch = ch-30; ch=ch+'1'; }
1820#endif
1821 if (ch=='p' && type==0x300)
1822 {
1823 keys_enabled = false;
1824 }
1825 if (ch=='o' && type==0x300)
1826 {
1827 keys_enabled = true;
1828 }
1829
1830
1831 if (keys_enabled && !g_is_quake){
1832 if (ch=='a' && type==0x300)
1833 {
1834 left=true;
1835 }
1836 if (ch=='a' && type==0x301)
1837 {
1838 left=false;
1839 }
1840 if (ch=='d' && type==0x300)
1841 {
1842 right=true;
1843 }
1844 if (ch=='d' && type==0x301)
1845 {
1846 right=false;
1847 }
1848 }
1849 if (firsttime)
1850 {
1851 //obj.prepare();
1852 firsttime = false;
1853 }
1854 size.dx = sx;
1855 size.dy = sy;
1856 }
1857 void render()
1858 {
1860 OpenglLowApi *ogl = g_low->ogl;
1861 if (is_visible())
1862 {
1863
1864 if (firsttime2) {
1865 // firsttime
1866 MainLoopItem *item = find_main_loop(env, p);
1867 if (ev.polygon_api.ready_to_prepare(p)) {
1868 // COLLECT LOGIC (STILL UNSTABLE)
1869 /*
1870 CollectInterfaceImpl2 *vis = new CollectInterfaceImpl2;
1871 item->Collect(*vis);
1872 int s = vis->vec.size();
1873 for(int i=0;i<s;i++)
1874 {
1875 vis->execute(s);
1876 }
1877 */
1878 // COLLECT LOGIC
1879
1881 //std::cout << "MLGuiWidget calling ML prepapre" << std::endl;
1882 item->Prepare();
1884 //std::cout << "MLGuiWidget finished ML prepapre" << std::endl;
1885 firsttime2 = false;
1886 }
1887 }
1888
1889 if (!firsttime2) {
1890 if (left)
1891 {
1892 rot_y+=1.0*3.14159*2.0/360.0*ev.mainloop_api.get_delta_time()*keypress_rot_speed;
1893 //obj.set_rotation_y(rot_y);
1894 mat = ev.matrix_api.yrot(rot_y);
1895 }
1896 if (right)
1897 {
1898 rot_y-=1.0*3.14159*2.0/360.0*ev.mainloop_api.get_delta_time()*keypress_rot_speed;
1899 //obj.set_rotation_y(rot_y);
1900 mat = ev.matrix_api.yrot(rot_y);
1901 }
1902 if (!firsttime)
1903 {
1904 Point2d pos = get_pos();
1905 Vector2d sz = get_size();
1906 float scale_x = 1.0;
1907 float scale_y = 1.0;
1908 if (g_event_screen_y!=-1) {
1909 scale_x = float(g_event_screen_x)/float(screen_x);
1910 scale_y = float(g_event_screen_y)/float(screen_y);
1911 }
1912 ogl->glViewport(pos.x*scale_x, screen_y*scale_y-pos.y*scale_y-sz.dy*scale_y, sz.dx*scale_x, sz.dy*scale_y);
1913 int c_x = ev.mainloop_api.get_corner_x();
1914 int c_y = ev.mainloop_api.get_corner_y();
1915 int c_sx = ev.mainloop_api.get_screen_rect_sx();
1916 int c_sy = ev.mainloop_api.get_screen_rect_sy();
1917 ev.mainloop_api.set_corner(pos.x, pos.y, sz.dx,sz.dy);
1918 ev.shader_api.use(sh);
1919 ev.mainloop_api.switch_to_3d(true, sh, screen_x, screen_y);
1920 ev.shader_api.use(sh2);
1921 ev.mainloop_api.switch_to_3d(true, sh2, screen_x, screen_y);
1922 ev.shader_api.use(sh_2d);
1923 ev.mainloop_api.switch_to_3d(false, sh_2d, screen_x, screen_y);
1924 ev.shader_api.use(sh_arr);
1925 ev.mainloop_api.switch_to_3d(true, sh_arr, screen_x, screen_y);
1927 //obj.render();
1928 ev.shader_api.use(sh);
1929 ev.shader_api.set_var(sh, "in_MV", mat);
1930 ev.shader_api.use(sh2);
1931 ev.shader_api.set_var(sh2, "in_MV", mat);
1932 ev.shader_api.use(sh_2d);
1933 ev.shader_api.set_var(sh_2d, "in_MV", mat);
1934 ev.shader_api.use(sh_arr);
1935 ev.shader_api.set_var(sh_arr, "in_MV", mat);
1936 ev.shader_api.use(sh);
1937 GameApi::M in_T = ev.mainloop_api.in_T(ev, true);
1938 GameApi::M in_N = ev.mainloop_api.in_N(ev, true);
1939 //e.inMV = find_matrix(env, mat);
1940 if (!g_transparent) {
1942 g_low->ogl->glScissor(pos.x*scale_x, (screen_y-pos.y-sz.dy)*scale_y, sz.dx*scale_x,sz.dy*scale_y);
1943 ev.mainloop_api.clear_3d(0xff000000);
1945
1946 }
1948 //std::cout << "MLGUIWiget::Execute_ml" << std::endl;
1949 ev.mainloop_api.execute_ml(ev,p, sh, sh2, sh2, sh_arr,mat, in_T, in_N, sz.dx, sz.dy);
1950 //std::cout << "MLGUIWiget::finished Execute_ml" << std::endl;
1952 e.type = -1;
1953 e.ch = -1;
1954 e.button = -1;
1955
1956 //ev.polygon_api.render_vertex_array(p);
1958 ev.shader_api.use(sh);
1959 ev.mainloop_api.switch_to_3d(false, sh, screen_x, screen_y);
1960 ev.shader_api.use(sh2);
1961 ev.mainloop_api.switch_to_3d(false, sh2, screen_x, screen_y);
1962 ev.shader_api.use(sh_arr);
1963 ev.mainloop_api.switch_to_3d(false, sh_arr, screen_x, screen_y);
1964 ev.shader_api.use(sh_2d);
1965 ev.mainloop_api.switch_to_3d(false, sh_2d, screen_x, screen_y);
1966 ev.mainloop_api.set_corner(c_x,c_y,c_sx,c_sy);
1967 ogl->glViewport(0,0,screen_x*scale_x, screen_y*scale_y);
1968 ev.shader_api.use(old_sh);
1969 }
1970 }
1971 }
1972 g_time_id++;
1973 }
1974private:
1975 GameApi::Env &env;
1976 GameApi::SH sh;
1977 GameApi::SH sh2;
1978 GameApi::SH sh_2d;
1979 GameApi::SH sh_arr;
1980 GameApi::SH old_sh;
1981 GameApi::ML p;
1982 GameApi::M mat;
1983 GameApi::MainLoopApi::Event e;
1984 //GameApi::PolygonObj obj;
1985 bool keys_enabled;
1986 bool firsttime;
1987 int sx,sy;
1988 int screen_x, screen_y;
1989 float rot_y;
1990 bool left,right;
1991 bool firsttime2;
1992};
1993
1994
1995
1996class ShaderPlaneGuiWidget : public GuiWidgetForward
1997{
1998public:
1999 ShaderPlaneGuiWidget(GameApi::EveryApi &ev, GameApi::SFO p, GameApi::SH sh, int sx, int sy, int screen_x, int screen_y) : GuiWidgetForward(ev, { }), sh(sh), p(p),sx(sx),sy(sy),screen_x(screen_x), screen_y(screen_y) { firsttime = true;
2000 Point2d p3 = {-666.0, -666.0 };
2001 update(p3, -1,-1,-1,0);
2002 Point2d p2 = { 0.0,0.0 };
2003 set_pos(p2);
2004 rot_y = 0.0;
2005 time = ev.mainloop_api.get_time();
2006 left=false; right=false;
2007
2008 }
2009 GameApi::V func(int face, int point, GameApi::EveryApi &ev)
2010 {
2011 switch(point)
2012 {
2013 case 0: return ev.vector_api.vector(0.0,0.0,0.0);
2014 case 1: return ev.vector_api.vector(1.0,0.0,0.0);
2015 case 2: return ev.vector_api.vector(1.0,1.0,0.0);
2016 case 3: return ev.vector_api.vector(0.0,1.0,0.0);
2017 };
2018 return ev.vector_api.vector(0.0,0.0,0.0);
2019 }
2020
2021 GameApi::PT func2(int face, int point, GameApi::EveryApi &ev)
2022 {
2023 switch(point)
2024 {
2025 case 0: return ev.point_api.point(0.0,1.0,0.0);
2026 case 1: return ev.point_api.point(1.0,1.0,0.0);
2027 case 2: return ev.point_api.point(1.0,0.0,0.0);
2028 case 3: return ev.point_api.point(0.0,0.0,0.0);
2029 };
2030 return ev.point_api.point(0.0,0.0,0.0);
2031 }
2032
2033
2034 void update(Point2d mouse, int button, int ch, int type, int mouse_wheel_y)
2035 {
2036
2037#ifdef EMSCRIPTEN
2038 if (ch>=4 && ch<=29) { ch = ch - 4; ch=ch+'a'; }
2039 if (ch==39) ch='0';
2040 if (ch>=30 && ch<=38) { ch = ch-30; ch=ch+'1'; }
2041#endif
2042
2043 if (ch=='a' && type==0x300)
2044 {
2045 left = true;
2046 }
2047 if (ch=='a' && type==0x301)
2048 {
2049 left = false;
2050 }
2051 if (ch=='d' && type==0x300)
2052 {
2053 right=true;
2054 }
2055 if (ch=='d' && type==0x301)
2056 {
2057 right=false;
2058 }
2059
2060
2061 using std::placeholders::_1;
2062 using std::placeholders::_2;
2063 if (firsttime)
2064 {
2065 GameApi::SFO render = ev.sh_api.render(p);
2066 sh2 = ev.shader_api.get_normal_shader("screen", "screen", "", "", "", false, render);
2067 ev.mainloop_api.init(sh2, screen_x, screen_y);
2068 ev.mainloop_api.alpha(true);
2069 GameApi::P poly_0 = ev.polygon_api.quad_z(0.0, sx,
2070 0.0, sy,
2071 0.0);
2072 GameApi::P poly_1 = ev.polygon_api.normal_function(poly_0, std::bind(&ShaderPlaneGuiWidget::func, this, _1, _2, std::ref(ev)));
2073 GameApi::P poly_2 = ev.polygon_api.texcoord_function(poly_1, std::bind(&ShaderPlaneGuiWidget::func2, this, _1, _2, std::ref(ev)));
2074 obj = new GameApi::PolygonObj(ev, poly_2, sh2);
2075
2076 obj->prepare();
2077 firsttime = false;
2078 }
2079 size.dx = sx;
2080 size.dy = sy;
2081 }
2082 void render()
2083 {
2084 if (is_visible())
2085 {
2086 if (left)
2087 {
2088 rot_y+=1.0*3.14159*2.0/360.0*ev.mainloop_api.get_delta_time()*keypress_rot_speed;
2089 }
2090 if (right)
2091 {
2092 rot_y-=1.0*3.14159*2.0/360.0*ev.mainloop_api.get_delta_time()*keypress_rot_speed;
2093 }
2094 if (!firsttime)
2095 {
2096 float f = (ev.mainloop_api.get_time()-time)/1000.0;
2097 ev.shader_api.use(sh2);
2098 ev.shader_api.set_var(sh2, "roty", rot_y);
2099 ev.shader_api.set_var(sh2, "time", f);
2100 Point2d pos = get_pos();
2101 //Vector2d sz = get_size();
2102 obj->set_pos(pos.x, pos.y, 0.0);
2103 obj->render();
2104 ev.shader_api.use(sh);
2105 }
2106 }
2107 }
2108private:
2109 GameApi::SH sh;
2110 GameApi::SH sh2;
2111 GameApi::SFO p;
2112 GameApi::PolygonObj *obj;
2113 bool firsttime;
2114 int sx,sy;
2115 int screen_x, screen_y;
2116 float rot_y;
2117 float time;
2118 float left,right;
2119};
2120
2121class OneItemFaceCollection : public FaceCollection
2122{
2123public:
2124 virtual std::string name() const { return "OneItemFaceCollection"; }
2125 virtual void Prepare() { }
2126 virtual void HeavyPrepare() { }
2127 virtual void Collect(CollectVisitor &vis) { }
2128 virtual int NumFaces() const { return 1; }
2129 virtual int NumPoints(int face) const { return 1; }
2130 virtual Point FacePoint(int face, int point) const { return Point(0.0,0.0,0.0); }
2131 virtual Vector PointNormal(int face, int point) const { return Vector(0.0,0.0,0.0); }
2132 virtual float Attrib(int face, int point, int id) const { return 0.0; }
2133 virtual int AttribI(int face, int point, int id) const { return 0; }
2134 virtual unsigned int Color(int face, int point) const { return 0xffffffff; }
2135 virtual Point2d TexCoord(int face, int point) const { Point2d p; p.x = 0.0; p.y = 0.0; return p; }
2136
2137};
2139{
2140 return add_polygon2(e,new OneItemFaceCollection,1);
2141}
2142
2143
2144class PTSGuiWidget : public GuiWidgetForward
2145{
2146public:
2147 PTSGuiWidget(GameApi::Env &e, GameApi::EveryApi &ev, GameApi::PTS p, GameApi::SH sh, GameApi::SH old_sh, int sx, int sy, int screen_x, int screen_y) : GuiWidgetForward(ev, { }), sh(sh), old_sh(old_sh), p(p), obj(ev, p, sh,one(e),1.0f),sx(sx),sy(sy), screen_x(screen_x), screen_y(screen_y) { firsttime = true;
2148 Point2d p3 = {-666.0, -666.0 };
2149 update(p3, -1,-1,-1,0);
2150 Point2d p2 = { 0.0,0.0 };
2151 set_pos(p2);
2152 rot_y = 0.0;
2153 left=false; right=false;
2154 }
2155 void update(Point2d mouse, int button, int ch, int type, int mouse_wheel_y)
2156 {
2157#ifdef EMSCRIPTEN
2158 if (ch>=4 && ch<=29) { ch = ch - 4; ch=ch+'a'; }
2159 if (ch==39) ch='0';
2160 if (ch>=30 && ch<=38) { ch = ch-30; ch=ch+'1'; }
2161#endif
2162 if (ch=='a' && type==0x300)
2163 {
2164 left=true;
2165 }
2166 if (ch=='a' && type==0x301)
2167 {
2168 left=false;
2169 }
2170 if (ch=='d' && type==0x300)
2171 {
2172 right=true;
2173 }
2174 if (ch=='d' && type==0x301)
2175 {
2176 right=false;
2177 }
2178
2179 if (firsttime)
2180 {
2181 obj.prepare();
2182 firsttime = false;
2183 }
2184 size.dx = sx;
2185 size.dy = sy;
2186 }
2187 void render()
2188 {
2189 OpenglLowApi *ogl = g_low->ogl;
2190 if (is_visible())
2191 {
2192 if (left)
2193 {
2194 rot_y+=1.0*3.14159*2.0/360.0*ev.mainloop_api.get_delta_time()*keypress_rot_speed;
2195 obj.set_rotation_matrix(ev.matrix_api.yrot(rot_y));
2196 }
2197 if (right)
2198 {
2199 rot_y-=1.0*3.14159*2.0/360.0*ev.mainloop_api.get_delta_time()*keypress_rot_speed;
2200 obj.set_rotation_matrix(ev.matrix_api.yrot(rot_y));
2201 }
2202 if (!firsttime)
2203 {
2204 Point2d pos = get_pos();
2205 Vector2d sz = get_size();
2206
2207 float scale_x = 1.0;
2208 float scale_y = 1.0;
2209 if (g_event_screen_y!=-1) {
2210 scale_x = float(g_event_screen_x)/float(screen_x);
2211 scale_y = float(g_event_screen_y)/float(screen_y);
2212 }
2213
2214 ogl->glViewport(pos.x*scale_x, screen_y*scale_y-pos.y*scale_y-sz.dy*scale_y, sz.dx*scale_x, sz.dy*scale_y);
2215 ev.shader_api.use(sh);
2216 ev.mainloop_api.switch_to_3d(true, sh, screen_x, screen_y);
2217
2218 if (!g_transparent) {
2220 g_low->ogl->glScissor(pos.x, screen_y-pos.y-sz.dy, sz.dx,sz.dy);
2221 ev.mainloop_api.clear_3d(0xff000000);
2223
2224 }
2225
2226
2228 //glPointSize(5.0);
2229 //ev.mainloop_api.clear_3d();
2230 obj.render();
2232 ev.mainloop_api.switch_to_3d(false, sh, screen_x, screen_y);
2233 ogl->glViewport(0,0,screen_x*scale_x, screen_y*scale_y);
2234 ev.shader_api.use(old_sh);
2235 }
2236 }
2237 }
2238private:
2239 GameApi::SH sh;
2240 GameApi::SH old_sh;
2241 GameApi::PTS p;
2242 GameApi::PointsObj obj;
2243 bool firsttime;
2244 int sx,sy;
2245 int screen_x, screen_y;
2246 float rot_y;
2247 bool left,right;
2248};
2249
2250
2251class LinesGuiWidget : public GuiWidgetForward
2252{
2253public:
2254 LinesGuiWidget(GameApi::EveryApi &ev, GameApi::LI p, GameApi::SH sh, GameApi::SH old_sh, int sx, int sy, int screen_x, int screen_y) : GuiWidgetForward(ev, { }), sh(sh), old_sh(old_sh), p(p), obj(ev, p, sh),sx(sx),sy(sy), screen_x(screen_x), screen_y(screen_y) { firsttime = true;
2255 Point2d p3 = {-666.0, -666.0 };
2256 update(p3, -1,-1,-1,0);
2257 Point2d p2 = { 0.0,0.0 };
2258 set_pos(p2);
2259 rot_y = 0.0;
2260 left = false;
2261 right=false;
2262 }
2263 void update(Point2d mouse, int button, int ch, int type, int mouse_wheel_y)
2264 {
2265#ifdef EMSCRIPTEN
2266 if (ch>=4 && ch<=29) { ch = ch - 4; ch=ch+'a'; }
2267 if (ch==39) ch='0';
2268 if (ch>=30 && ch<=38) { ch = ch-30; ch=ch+'1'; }
2269#endif
2270 if (ch=='a' && type==0x300)
2271 {
2272 left=true;
2273 }
2274 if (ch=='d' && type==0x300)
2275 {
2276 right=true;
2277 }
2278 if (ch=='a' && type==0x301)
2279 {
2280 left=false;
2281 }
2282 if (ch=='d' && type==0x301)
2283 {
2284 right=false;
2285 }
2286
2287 if (firsttime)
2288 {
2289 obj.prepare();
2290 firsttime = false;
2291 }
2292 size.dx = sx;
2293 size.dy = sy;
2294 }
2295 void render()
2296 {
2297 OpenglLowApi *ogl = g_low->ogl;
2298 if (is_visible())
2299 {
2300 if (left)
2301 {
2302 rot_y+=1.0*3.14159*2.0/360.0*ev.mainloop_api.get_delta_time()*keypress_rot_speed;
2303 obj.set_rotation_matrix(ev.matrix_api.yrot(rot_y));
2304 }
2305 if (right)
2306 {
2307 rot_y-=1.0*3.14159*2.0/360.0*ev.mainloop_api.get_delta_time()*keypress_rot_speed;
2308 obj.set_rotation_matrix(ev.matrix_api.yrot(rot_y));
2309 }
2310 if (!firsttime)
2311 {
2312 Point2d pos = get_pos();
2313 Vector2d sz = get_size();
2314 float scale_x = 1.0;
2315 float scale_y = 1.0;
2316 if (g_event_screen_y!=-1) {
2317 scale_x = float(g_event_screen_x)/float(screen_x);
2318 scale_y = float(g_event_screen_y)/float(screen_y);
2319 }
2320
2321 ogl->glViewport(pos.x*scale_x, screen_y*scale_y-pos.y*scale_y-sz.dy*scale_y, sz.dx*scale_x, sz.dy*scale_y);
2322 ev.shader_api.use(sh);
2323 ev.mainloop_api.switch_to_3d(true, sh, screen_x, screen_y);
2324 if (!g_transparent) {
2326 g_low->ogl->glScissor(pos.x, screen_y-pos.y-sz.dy, sz.dx,sz.dy);
2327 ev.mainloop_api.clear_3d(0xff000000);
2329
2330 }
2331
2333 obj.render();
2335 ev.mainloop_api.switch_to_3d(false, sh, screen_x, screen_y);
2336 ogl->glViewport(0,0,screen_x*scale_x, screen_y*scale_y);
2337 ev.shader_api.use(old_sh);
2338 }
2339 }
2340 }
2341private:
2342 GameApi::SH sh;
2343 GameApi::SH old_sh;
2344 GameApi::LI p;
2345 GameApi::LinesObj obj;
2346 bool firsttime;
2347 int sx,sy;
2348 int screen_x, screen_y;
2349 float rot_y;
2350 bool left,right;
2351};
2352
2353class BoundingBoxWidget : public GuiWidgetForward
2354{
2355public:
2356 BoundingBoxWidget(GuiWidget *next) : GuiWidgetForward(ev, std::vector<GuiWidget*>{next}), next(next) {
2357 Point2d p = { -666.0, -666.0 };
2358 update(p, -1,-1, -1,0);
2359 Point2d p2 = { 0.0, 0.0 };
2360 set_pos(p2);
2361 }
2362 void set_size(Vector2d v) {
2364 next->set_size(v);
2365 }
2366 void update(Point2d mouse, int button, int ch, int type, int mouse_wheel_y)
2367 {
2368 if (mouse.x<pos.x) return;
2369 if (mouse.y<pos.y) return;
2370 if (mouse.x>pos.x+size.dx) return;
2371 if (mouse.y>pos.y+size.dy) return;
2372 next->update(mouse,button,ch,type,mouse_wheel_y);
2373 }
2374private:
2375 GuiWidget *next;
2376};
2378{
2379 GuiWidget *ww = find_widget(e,w);
2380 return add_widget(e, new BoundingBoxWidget(ww));
2381}
2382
2383extern bool g_inside_icon_display;
2384
2385class IconGuiWidget : public GuiWidgetForward
2386{
2387public:
2388 IconGuiWidget(GameApi::EveryApi &ev, GameApi::BM bm, GameApi::SH sh) : GuiWidgetForward(ev, std::vector<GuiWidget*>()), sh(sh), bm(bm) { firsttime=true;
2389 Point2d p = { -666.0, -666.0 };
2390 update(p, -1,-1, -1,0);
2391 Point2d p2 = { 0.0, 0.0 };
2392 set_pos(p2);
2393 if (ev.bitmap_api.ready_to_prepare(bm)) {
2395 ev.bitmap_api.prepare(bm);
2397 }
2398 }
2399 void update(Point2d mouse, int button, int ch, int type, int mouse_wheel_y)
2400 {
2401 //std::cout << "Update" << std::endl;
2402 //std::cout << "Update Ready to Prepare" << std::endl;
2403 #if 1
2404 if (firsttime) {
2405 if (ev.bitmap_api.ready_to_prepare(bm)) {
2406 //std::cout << "ACTUAL PREPARE" << std::endl;
2408 ev.bitmap_api.prepare(bm);
2410 }
2411 }
2412 size.dx = ev.bitmap_api.size_x(bm);
2413 size.dy = ev.bitmap_api.size_y(bm);
2414 if (firsttime)
2415 {
2416 if (ev.bitmap_api.ready_to_prepare(bm)) {
2418 bm_va = ev.sprite_api.create_vertex_array(bm);
2420 //ev.sprite_api.clear_arrays(bm_va);
2421 firsttime = false;
2422 }
2423 }
2424 #endif
2425 }
2426 void render()
2427 {
2428 //std::cout << "Render" << std::endl;
2429 if (firsttime && ev.bitmap_api.ready_to_prepare(bm)) {
2430 //std::cout << "REUPDATE" << std::endl;
2431 Point2d p;
2432 p.x=0.0f; p.y=0.0f;
2433 update(p,-1,-1,0,0);
2434 }
2435
2436 #if 1
2437 if (is_visible())
2438 {
2439 if (!firsttime)
2440 {
2441 Point2d p = get_pos();
2442 ev.shader_api.use(sh);
2443 ev.shader_api.set_var(sh, "color_mix", 1.0f);
2444 ev.shader_api.set_var(sh, "in_MV", ev.matrix_api.trans(p.x+0.5,p.y+0.5,0.0));
2446 ev.sprite_api.render_sprite_vertex_array(bm_va);
2448
2449 }
2450 }
2451 #endif
2452 }
2453 int render_to_bitmap()
2454 {
2455 return bm.id;
2456 }
2457private:
2458 bool firsttime;
2459 GameApi::SH sh;
2460 GameApi::BM bm;
2461 GameApi::VA bm_va;
2462 //static std::map<int, int> arrs;
2463};
2464
2465#ifndef EMSCRIPTEN
2466//std::map<int, int> shared_sprites;
2467//int find_shared_sprites(int key) {
2468// std::map<int,int>::iterator it = shared_sprites.find(key);
2469// if (it!=shared_sprites.end()) return (*it).second;
2470// return -1;
2471//}
2472#if 1
2473struct A { int key; int value; };
2474std::vector<A> shared_sprites;
2475int find_shared_sprites(int key) {
2476 int s = shared_sprites.size();
2477 for(int i=0;i<s;i++) { if (shared_sprites[i].key==key) return i; }
2478 return -1;
2479}
2480#endif
2481class IconGuiWidgetShared : public GuiWidgetForward
2482{
2483public:
2484 IconGuiWidgetShared(GameApi::Env &env, GameApi::EveryApi &ev, GameApi::BM bm, GameApi::SH sh, int key) : GuiWidgetForward(ev, std::vector<GuiWidget*>()), env(env), ev(ev), sh(sh), bm(bm), key(key) { firsttime=true;
2485 Point2d p = { -666.0, -666.0 };
2486 update(p, -1,-1, -1,0);
2487 Point2d p2 = { 0.0, 0.0 };
2488 set_pos(p2);
2489 //ev.bitmap_api.prepare(bm);
2490 }
2491 void update(Point2d mouse, int button, int ch, int type, int mouse_wheel_y)
2492 {
2493 #if 1
2494 size.dx = ev.bitmap_api.size_x(bm);
2495 size.dy = ev.bitmap_api.size_y(bm);
2496 if (firsttime)
2497 {
2498 int c = get_current_block();
2500
2501 //std::map<int,int>::iterator i = shared_sprites.find(key);
2502 int index = find_shared_sprites(key);
2503 if (index!=-1) {
2504 bm_va.id = shared_sprites[index].value;
2505 RenderVertexArray *r = find_vertex_array_render(env, bm_va);
2506 if (!r) {
2507 GameApi::BM scaled = ev.bitmap_api.scale_bitmap(ev,bm, 100,100);
2508 bm_va = ev.sprite_api.create_vertex_array(scaled);
2509 A a;
2510 a.key = key;
2511 a.value = bm_va.id;
2512 shared_sprites.push_back(a);
2513 //std::cout << "shared_sprites " << shared_sprites.size() << " " << bm_va.id << std::endl;
2514 //shared_sprites[key] = bm_va.id;
2515 }
2516 } else {
2517 GameApi::BM scaled = ev.bitmap_api.scale_bitmap(ev,bm, 100,100);
2518 bm_va = ev.sprite_api.create_vertex_array(scaled);
2519 A a;
2520 a.key = key;
2521 a.value = bm_va.id;
2522 shared_sprites.push_back(a);
2523 // std::cout << "shared_sprites2 " << shared_sprites.size() << " " << bm_va.id << std::endl;
2524 //shared_sprites[key] = bm_va.id;
2525 //shared_sprites[a.key] = a.value;
2526 // shared_sprites[key] = bm_va.id;
2527 }
2529 firsttime = false;
2530 }
2531 #endif
2532 }
2533 void render()
2534 {
2535 #if 1
2536 if (is_visible())
2537 {
2538 if (!firsttime)
2539 {
2540 Point2d p = get_pos();
2541 GameApi::M m = ev.matrix_api.trans(p.x+0.5,p.y+0.5,0.0);
2542 GameApi::M ms = ev.matrix_api.scale(size.dx/100.0, size.dy/100.0, 1.0);
2543 GameApi::M mc = ev.matrix_api.mult(ms,m);
2544 ev.shader_api.use(sh);
2545 ev.shader_api.set_var(sh, "color_mix", 1.0f);
2546 ev.shader_api.set_var(sh, "in_MV", mc);
2547 ev.sprite_api.render_sprite_vertex_array(bm_va);
2548 //ev.shader_api.use(sh);
2549 }
2550 }
2551 #endif
2552 }
2553 int render_to_bitmap()
2554 {
2555 return bm.id;
2556 }
2557private:
2558 GameApi::Env &env;
2559 GameApi::EveryApi &ev;
2560 bool firsttime;
2561 GameApi::SH sh;
2562 GameApi::BM bm;
2563 GameApi::VA bm_va;
2564 //static std::map<int, int> arrs;
2565 int key;
2566};
2567
2568
2569class IconGuiWidgetSharedNoScale : public GuiWidgetForward
2570{
2571public:
2572 IconGuiWidgetSharedNoScale(GameApi::Env &env, GameApi::EveryApi &ev, GameApi::BM bm, GameApi::SH sh, int key) : GuiWidgetForward(ev, std::vector<GuiWidget*>()), env(env), ev(ev), sh(sh), bm(bm), key(key) { firsttime=true;
2573 Point2d p = { -666.0, -666.0 };
2574 update(p, -1,-1, -1,0);
2575 Point2d p2 = { 0.0, 0.0 };
2576 set_pos(p2);
2577 //ev.bitmap_api.prepare(bm);
2578 }
2579 void update(Point2d mouse, int button, int ch, int type, int mouse_wheel_y)
2580 {
2581 #if 1
2582 //BitmapHandle *handle = find_bitmap(env, bm);
2583 //::Bitmap<Color> *b2 = find_color_bitmap(handle);
2584 //b2->Prepare();
2585 size.dx = 400; //ev.bitmap_api.size_x(bm);
2586 size.dy = 200; //ev.bitmap_api.size_y(bm);
2587 if (firsttime)
2588 {
2589 int c = get_current_block();
2591
2592 //std::map<int,int>::iterator i = shared_sprites.find(key);
2593 int index = find_shared_sprites(key);
2594 if (index!=-1) {
2595 bm_va.id = shared_sprites[index].value;
2596 RenderVertexArray *r = find_vertex_array_render(env, bm_va);
2597 if (!r) {
2598 GameApi::BM scaled = ev.bitmap_api.scale_bitmap(ev,bm, 400,200);
2599 bm_va = ev.sprite_api.create_vertex_array(scaled);
2600 A a;
2601 a.key = key;
2602 a.value = bm_va.id;
2603 shared_sprites.push_back(a);
2604 //std::cout << "shared_sprites " << shared_sprites.size() << " " << bm_va.id << std::endl;
2605 //shared_sprites[key] = bm_va.id;
2606 }
2607 } else {
2608 GameApi::BM scaled = ev.bitmap_api.scale_bitmap(ev,bm, 400,200);
2609 bm_va = ev.sprite_api.create_vertex_array(scaled);
2610 A a;
2611 a.key = key;
2612 a.value = bm_va.id;
2613 shared_sprites.push_back(a);
2614 // std::cout << "shared_sprites2 " << shared_sprites.size() << " " << bm_va.id << std::endl;
2615 //shared_sprites[key] = bm_va.id;
2616 //shared_sprites[a.key] = a.value;
2617 // shared_sprites[key] = bm_va.id;
2618 }
2620 firsttime = false;
2621 }
2622 #endif
2623 }
2624 void render()
2625 {
2626 #if 1
2627 if (is_visible())
2628 {
2629 if (!firsttime)
2630 {
2631 Point2d p = get_pos();
2632 GameApi::M m = ev.matrix_api.trans(p.x+0.5,p.y+0.5,0.0);
2633 GameApi::M ms = ev.matrix_api.scale(size.dx/100.0, size.dy/100.0, 1.0);
2634 GameApi::M mc = ev.matrix_api.mult(ms,m);
2635 ev.shader_api.use(sh);
2636 ev.shader_api.set_var(sh, "color_mix", 1.0f);
2637 ev.shader_api.set_var(sh, "in_MV", mc);
2638 ev.sprite_api.render_sprite_vertex_array(bm_va);
2639 ev.shader_api.use(sh);
2640 }
2641 }
2642 #endif
2643 }
2644 int render_to_bitmap()
2645 {
2646 return bm.id;
2647 }
2648private:
2649 GameApi::Env &env;
2650 GameApi::EveryApi &ev;
2651 bool firsttime;
2652 GameApi::SH sh;
2653 GameApi::BM bm;
2654 GameApi::VA bm_va;
2655 //static std::map<int, int> arrs;
2656 int key;
2657};
2658
2659#endif
2660
2661
2662int ELayoutEmpty = 66666;
2663
2664struct LayoutGuiWidget_WH { };
2665struct LayoutGuiWidget_lt { };
2666struct LayoutGuiWidget_rb { };
2667
2668class LayoutGuiWidget : public GuiWidgetForward
2669{
2670public:
2671 LayoutGuiWidget(GameApi::EveryApi &ev, GuiWidget *w, int l, int t, int W, int H, int r, int b) : GuiWidgetForward(ev, { w }), l(l), t(t), W(W), H(H), r(r), b(b)
2672 {
2673 c_l = l;
2674 c_t = t;
2675 c_W = W;
2676 c_H = H;
2677 c_r = r;
2678 c_b = b;
2679
2680
2681 Point2d p = { -666.0, -666.0 };
2682 update(p, -1, -1, -1,0);
2683 Point2d p2 = { 0.0, 0.0 };
2684 set_pos(p2);
2685 }
2686 LayoutGuiWidget(LayoutGuiWidget_WH type, GameApi::EveryApi &ev, GuiWidget *w, int l, int t, int W, int H, int r, int b, int (*fptr_W)(void *), int (*fptr_H)(void *), void *ctx1, void *ctx2) : GuiWidgetForward(ev, { w }), l(l), t(t), W(W), H(H), r(r), b(b), fptr_x(fptr_W), fptr_y(fptr_H), ctx1(ctx1), ctx2(ctx2)
2687 {
2688 c_l = l;
2689 c_t = t;
2690 c_W = W;
2691 c_H = H;
2692 c_r = r;
2693 c_b = b;
2694
2695 is_dynamic_WH=true;
2696 Point2d p = { -666.0, -666.0 };
2697 update(p, -1, -1, -1,0);
2698 Point2d p2 = { 0.0, 0.0 };
2699 set_pos(p2);
2700 }
2701 LayoutGuiWidget(LayoutGuiWidget_lt type, GameApi::EveryApi &ev, GuiWidget *w, int l, int t, int W, int H, int r, int b, int (*fptr_l)(void *), int (*fptr_t)(void *), void *ctx1, void *ctx2) : GuiWidgetForward(ev, { w }), l(l), t(t), W(W), H(H), r(r), b(b), fptr_x(fptr_l), fptr_y(fptr_t), ctx1(ctx1), ctx2(ctx2)
2702 {
2703 c_l = l;
2704 c_t = t;
2705 c_W = W;
2706 c_H = H;
2707 c_r = r;
2708 c_b = b;
2709
2710
2711 is_dynamic_lt=true;
2712 Point2d p = { -666.0, -666.0 };
2713 update(p, -1, -1, -1,0);
2714 Point2d p2 = { 0.0, 0.0 };
2715 set_pos(p2);
2716 }
2717 LayoutGuiWidget(LayoutGuiWidget_rb type, GameApi::EveryApi &ev, GuiWidget *w, int l, int t, int W, int H, int r, int b, int (*fptr_r)(void *), int (*fptr_b)(void *), void *ctx1, void *ctx2) : GuiWidgetForward(ev, { w }), l(l), t(t), W(W), H(H), r(r), b(b), fptr_x(fptr_r), fptr_y(fptr_b), ctx1(ctx1), ctx2(ctx2)
2718 {
2719 c_l = l;
2720 c_t = t;
2721 c_W = W;
2722 c_H = H;
2723 c_r = r;
2724 c_b = b;
2725
2726 is_dynamic_rb=true;
2727 Point2d p = { -666.0, -666.0 };
2728 update(p, -1, -1, -1,0);
2729 Point2d p2 = { 0.0, 0.0 };
2730 set_pos(p2);
2731 }
2732 void do_layout(Vector2d size_p)
2733 {
2734 c_l = l;
2735 c_t = t;
2736 c_W = W;
2737 c_H = H;
2738 c_r = r;
2739 c_b = b;
2740
2741
2742 if (l!=ELayoutEmpty && W!=ELayoutEmpty && r!=ELayoutEmpty) { assert(l+W+r==size_p.dx); }
2743 if (t!=ELayoutEmpty && H!=ELayoutEmpty && b!=ELayoutEmpty) { assert(t+H+b==size_p.dy); }
2744
2745
2746 if (is_dynamic_WH) {
2747 if (l==ELayoutEmpty && W==ELayoutEmpty) { c_W=fptr_x(ctx1); c_l=size_p.dx-c_W-r; }
2748 if (t==ELayoutEmpty && H==ELayoutEmpty) { c_H=fptr_y(ctx2); c_t=size_p.dy-c_H-b; }
2749 if (r==ELayoutEmpty && W==ELayoutEmpty) { c_W=fptr_x(ctx1); c_r=size_p.dx-c_W-l; }
2750 if (b==ELayoutEmpty && H==ELayoutEmpty) { c_H=fptr_y(ctx2); c_b=size_p.dy-c_H-t; }
2751 }
2752 if (is_dynamic_lt) {
2753 if (l==ELayoutEmpty && W==ELayoutEmpty) { c_l=fptr_x(ctx1); c_W=size_p.dx-c_l-r; }
2754 if (t==ELayoutEmpty && H==ELayoutEmpty) { c_t=fptr_y(ctx2); c_H=size_p.dy-c_t-b; }
2755 if (r==ELayoutEmpty && l==ELayoutEmpty) { c_l=fptr_x(ctx1); c_r=size_p.dx-W-c_l; }
2756 if (b==ELayoutEmpty && t==ELayoutEmpty) { c_t=fptr_y(ctx2); c_b=size_p.dy-H-c_t; }
2757 }
2758 if (is_dynamic_rb) {
2759 if (l==ELayoutEmpty && r==ELayoutEmpty) { c_r=fptr_x(ctx1); c_l=size_p.dx-W-c_r; }
2760 if (t==ELayoutEmpty && b==ELayoutEmpty) { c_b=fptr_y(ctx2); c_t=size_p.dy-H-c_b; }
2761 if (r==ELayoutEmpty && W==ELayoutEmpty) { c_r=fptr_x(ctx1); c_W=size_p.dx-c_r-l; }
2762 if (b==ELayoutEmpty && H==ELayoutEmpty) { c_b=fptr_y(ctx2); c_H=size_p.dy-c_b-t; }
2763 }
2764
2765
2766 // normal layoututils equation solving
2767 if (l==ELayoutEmpty) { c_l = size_p.dx - W - r; }
2768 if (t==ELayoutEmpty) { c_t = size_p.dy - H - b; }
2769 if (W==ELayoutEmpty) { c_W = size_p.dx - l - r; }
2770 if (H==ELayoutEmpty) { c_H = size_p.dy - t - b; }
2771 if (r==ELayoutEmpty) { c_r = size_p.dx - l - W; }
2772 if (b==ELayoutEmpty) { c_b = size_p.dy - t - H; }
2773 }
2774 void set_size(Vector2d size_p)
2775 {
2776 // two layoutempty's.
2777 do_layout(size_p);
2779 Vector2d delta = { float(c_l+c_r), float(c_t+c_b) };
2780 vec[0]->set_size(size_p + (- delta));
2781
2782 Vector2d v = vec[0]->get_size();
2783 Vector2d vv = { float(c_l+c_r), float(c_t+c_b) };
2784 Vector2d vvv = v+vv;
2785 size = vvv;
2786 }
2787 void set_pos(Point2d p)
2788 {
2790 do_layout(size);
2791 Vector2d v = { float(c_l), float(c_t) };
2792 vec[0]->set_pos(p+v);
2793 }
2794 void update(Point2d mouse, int button, int ch, int type, int mouse_wheel_y)
2795 {
2796 GuiWidgetForward::update(mouse,button,ch, type, mouse_wheel_y);
2797 Vector2d v = vec[0]->get_size();
2798 Vector2d vv = { float(c_l+c_r), float(c_t+c_b) };
2799 Vector2d vvv = v+vv;
2800 size = vvv;
2801
2802 set_pos(get_pos());
2803 set_size(get_size());
2804 }
2805 int chosen_item() const
2806 {
2807 int val = vec[0]->chosen_item();
2808 return val;
2809 }
2810
2811private:
2812 int l,t,W,H,r,b;
2813 int c_l,c_t,c_W,c_H,c_r,c_b;
2814 bool is_dynamic_WH=false;
2815 bool is_dynamic_lt=false;
2816 bool is_dynamic_rb=false;
2817 int (*fptr_x)(void *);
2818 int (*fptr_y)(void *);
2819 void *ctx1;
2820 void *ctx2;
2821};
2822
2823
2824//std::map<int,int> IconGuiWidget::arrs;
2825class MarginGuiWidget : public GuiWidgetForward
2826{
2827public:
2828 MarginGuiWidget(GameApi::EveryApi &ev, GuiWidget *w, int l, int t, int r, int b) : GuiWidgetForward(ev, { w }), l(l), t(t), r(r), b(b)
2829 {
2830 Point2d p = { -666.0, -666.0 };
2831 update(p, -1, -1, -1,0);
2832 Point2d p2 = { 0.0, 0.0 };
2833 set_pos(p2);
2834 }
2835 void set_size(Vector2d size_p)
2836 {
2838 Vector2d delta = { float(l+r), float(t+b) };
2839 vec[0]->set_size(size_p + (- delta));
2840
2841 Vector2d v = vec[0]->get_size();
2842 Vector2d vv = { float(l+r), float(t+b) };
2843 Vector2d vvv = v+vv;
2844 size = vvv;
2845 }
2846 void set_pos(Point2d p)
2847 {
2849 Vector2d v = { float(l), float(t) };
2850 vec[0]->set_pos(p+v);
2851 }
2852 void update(Point2d mouse, int button, int ch, int type, int mouse_wheel_y)
2853 {
2854 GuiWidgetForward::update(mouse,button,ch, type, mouse_wheel_y);
2855 Vector2d v = vec[0]->get_size();
2856 Vector2d vv = { float(l+r), float(t+b) };
2857 Vector2d vvv = v+vv;
2858 size = vvv;
2859
2860 set_pos(get_pos());
2861 set_size(get_size());
2862 }
2863 int chosen_item() const
2864 {
2865 int val = vec[0]->chosen_item();
2866 return val;
2867 }
2868
2869private:
2870 int l,t,r,b;
2871};
2872class SizeGuiWidget : public GuiWidgetForward
2873{
2874public:
2875 SizeGuiWidget(GameApi::EveryApi &ev, GuiWidget *w, int sx, int sy) : GuiWidgetForward(ev, { w }), sx(sx), sy(sy)
2876 {
2877 Point2d p = { -666.0, -666.0 };
2878 update(p, -1, -1, -1,0);
2879 Point2d p2 = { 0.0, 0.0 };
2880 set_pos(p2);
2881 }
2882 void set_size(Vector2d size)
2883 {
2885 Vector2d delta = { float(sx), float(sy) };
2886 vec[0]->set_size(delta);
2887 }
2888 void set_pos(Point2d p)
2889 {
2891 //Vector2d v = { float(l), float(t) };
2892 //Vector2d vs = vec[0]->get_size();
2893 vec[0]->set_pos(p);
2894 }
2895 void update(Point2d mouse, int button, int ch, int type, int mouse_wheel_y)
2896 {
2897 GuiWidgetForward::update(mouse,button,ch, type, mouse_wheel_y);
2898 //
2899 Vector2d vv = { float(sx), float(sy) };
2900 Vector2d vvv = vv;
2901 size = vvv;
2902 }
2903 int chosen_item() const
2904 {
2905 int val = vec[0]->chosen_item();
2906 return val;
2907 }
2908
2909private:
2910 int sx,sy;
2911};
2912
2913class LayerGuiWidget : public GuiWidgetForward
2914{
2915public:
2916 LayerGuiWidget(GameApi::EveryApi &ev, GuiWidget *w1, GuiWidget *w2) : GuiWidgetForward(ev, { w1, w2 })
2917 {
2918 Point2d p = { -666.0, -666.0 };
2919 update(p, -1,-1, -1,0);
2920 Point2d p2 = { 0.0, 0.0 };
2921 set_pos(p2);
2922 }
2923 void set_pos(Point2d pos)
2924 {
2926 vec[0]->set_pos(pos);
2927 vec[1]->set_pos(pos);
2928 }
2929 void set_size(Vector2d size)
2930 {
2932 vec[0]->set_size(size);
2933 vec[1]->set_size(size);
2934 }
2935 void update(Point2d mouse_pos, int button, int ch, int type, int mouse_wheel_y)
2936 {
2937 GuiWidgetForward::update(mouse_pos, button,ch, type, mouse_wheel_y);
2938 Vector2d v1 = vec[0]->get_size();
2939 Vector2d v2 = vec[1]->get_size();
2940 Vector2d mx = { std::max(v1.dx, v2.dx), std::max(v1.dy,v2.dy) };
2941 size = mx;
2942 }
2943 void render() {
2944 vec[0]->render();
2945 vec[1]->render();
2946 }
2947 int chosen_item() const
2948 {
2949 int val = vec[0]->chosen_item();
2950 if (val != -1) return val;
2951 return vec[1]->chosen_item();
2952 }
2953};
2954class ArrayXWidget : public GuiWidgetForward
2955{
2956public:
2957 ArrayXWidget(GameApi::EveryApi &ev, std::vector<GuiWidget*> vec, int x_gap) : GuiWidgetForward(ev, vec), x_gap(x_gap)
2958 {
2959 Point2d pos = { -666.0, -666.0 };
2960 update(pos, -1,-1, -1,0);
2961 Point2d p2 = { 0.0, 0.0 };
2962 set_pos(p2);
2963 }
2964 void set_pos(Point2d pos)
2965 {
2967 int s = vec.size();
2968 float delta = 0;
2969 for(int i=0;i<s;i++)
2970 {
2971 GuiWidget *w = vec[i];
2972 Point2d p = { pos.x + delta, pos.y };
2973 w->set_pos(p);
2974 delta += w->get_size().dx + x_gap;
2975 }
2976 }
2977 void set_size(Vector2d size)
2978 {
2980 int s = vec.size();
2981 float delta = 0;
2982 for(int i=0;i<s;i++) {
2983 vec[i]->set_size(vec[i]->get_size());
2984 }
2985
2986 }
2987 void update(Point2d mouse, int button, int ch, int type, int mouse_wheel_y)
2988 {
2989 GuiWidgetForward::update(mouse,button,ch, type, mouse_wheel_y);
2990 int s = vec.size();
2991 float sz = 0;
2992 float sz_max = 0;
2993 for(int i=0;i<s; i++)
2994 {
2995 sz += vec[i]->get_size().dx + x_gap;
2996 sz_max = std::max(sz_max, vec[i]->get_size().dy);
2997 }
2998 size.dx = sz;
2999 size.dy = sz_max;
3000 set_pos(get_pos());
3001 }
3002 void render()
3003 {
3004 if (is_visible())
3005 {
3007 }
3008 }
3009private:
3010 int x_gap;
3011};
3012
3013class ArrayYWidget : public GuiWidgetForward
3014{
3015public:
3016 ArrayYWidget(GameApi::EveryApi &ev, std::vector<GuiWidget*> vec, int y_gap, bool heavy) : GuiWidgetForward(ev, vec), y_gap(y_gap),heavy(heavy)
3017 {
3018 Point2d pos = { -666.0, -666.0 };
3019 update(pos, -1,-1, -1,0);
3020 Point2d p2 = { 0.0, 0.0 };
3021 set_pos(p2);
3022 }
3023
3024 virtual Point2d get_pos() const { return old_pos; }
3025 virtual Vector2d get_size() const
3026 {
3027 return size;
3028 }
3029
3030 void set_pos(Point2d pos)
3031 {
3032 old_pos = pos;
3034
3035 // Calculate whole size
3036 int s2 = vec.size();
3037 float sz = 0;
3038 float sz_max = 0;
3039 for(int i=0;i<s2; i++)
3040 {
3041 sz += vec[i]->get_size().dy + y_gap;
3042 sz_max = std::max(sz_max, vec[i]->get_size().dx);
3043 }
3044 size.dx = sz_max;
3045 size.dy = sz;
3046
3047 // set child sizes
3048 int s3 = vec.size();
3049 for(int i=0;i<s3;i++)
3050 {
3051 vec[i]->set_size(vec[i]->get_size());
3052 }
3053
3054 // calculate positions
3055 int s = vec.size();
3056 float delta = 0;
3057 for(int i=0;i<s;i++)
3058 {
3059 GuiWidget *w = vec[i];
3060 Point2d p = { pos.x, pos.y +delta};
3061 //std::cout << i << " :: " << delta << std::endl;
3062 w->set_pos(p);
3063 delta += w->get_size().dy + y_gap;
3064 }
3065 }
3066 void set_size(Vector2d size_p)
3067 {
3069 int s = vec.size();
3070 float sz = 0;
3071 float sz_max = 0;
3072 for(int i=0;i<s; i++)
3073 {
3074 sz += vec[i]->get_size().dy + y_gap;
3075 sz_max = std::max(sz_max, vec[i]->get_size().dx);
3076 }
3077 size.dx = sz_max;
3078 size.dy = sz;
3079
3080 int s2 = vec.size();
3081 for(int i=0;i<s2;i++)
3082 {
3083 vec[i]->set_size(vec[i]->get_size());
3084 }
3085
3086
3087
3088 if (!inside) {
3089 inside=true;
3090 set_pos(old_pos);
3091 inside=false;
3092 }
3093
3094
3095 //set_pos(old_pos);
3096 }
3097 void update(Point2d mouse, int button, int ch, int type, int mouse_wheel_y)
3098 {
3099 int s = vec.size();
3100 float sz = 0;
3101 float sz_max = 0;
3102 for(int i=0;i<s; i++)
3103 {
3104 sz += vec[i]->get_size().dy + y_gap;
3105 sz_max = std::max(sz_max, vec[i]->get_size().dx);
3106 }
3107 size.dx = sz_max;
3108 size.dy = sz;
3109
3110
3111 static bool recursion_stopper = false;
3112 if (button==-1&& ch==-1 && type==-1 && heavy && !recursion_stopper) {
3113 recursion_stopper=true;
3114 int s2 = vec.size();
3115 Point2d pp;
3116 Vector2d sz1;
3117 for(int i=0;i<s2;i++)
3118 {
3119 GuiWidget *w = vec[i];
3120 Point2d pos = w->get_pos();
3121 Vector2d sz = w->get_size();
3122 Point2d pos2 = pos + sz*0.5;
3123 pp = pos2;
3124 sz1=sz;
3125 GuiWidgetForward::update(pos2,button,ch,type,mouse_wheel_y);
3126 }
3127 GuiWidgetForward::update(Point2d(pp.x,pp.y+sz1.dy*3),button,ch,type,mouse_wheel_y);
3128 recursion_stopper=false;
3129 }
3130 GuiWidgetForward::update(mouse,button,ch, type, mouse_wheel_y);
3131
3132
3133
3134
3135 selected_item = -1;
3136
3137 for(int j=0;j<s;j++)
3138 {
3139 GuiWidget *w = vec[j];
3140 Point2d pos = w->get_pos();
3141 Vector2d size = w->get_size();
3142 if (mouse.x>=pos.x && mouse.x<pos.x+size.dx &&
3143 mouse.y>=pos.y && mouse.y<pos.y+size.dy)
3144 {
3145 selected_item = j;
3146 }
3147 }
3148
3149 if (!inside) {
3150 inside=true;
3151 set_pos(old_pos);
3152 inside=false;
3153 }
3154
3155
3156 }
3157 int chosen_item() const { return selected_item; }
3158 void render()
3159 {
3160 if (is_visible())
3161 {
3163 }
3164 }
3165private:
3166 int y_gap;
3167 int selected_item;
3168 Point2d old_pos = { 0.0,0.0 };
3169 bool inside=false;
3170 bool heavy=false;
3171};
3172
3173int highlight_bitmap = -1;
3174int highlight_border = -1;
3175class HighlightGuiWidget : public GuiWidgetForward
3176{
3177public:
3178 HighlightGuiWidget(GameApi::EveryApi &ev, GameApi::SH sh, int sx, int sy) : GuiWidgetForward(ev, std::vector<GuiWidget*>()), sh(sh), enabled(false), oldenabled(false), c_changed(false) {
3179 firsttime=true;
3180 size.dx = sx;
3181 size.dy = sy;
3182 Point2d p = { -666.0, -666.0 };
3183 update(p, -1,-1,-1,0);
3184 }
3185 void update(Point2d mouse, int button,int ch, int type, int mouse_wheel_y)
3186 {
3187 Point2d p = get_pos();
3188 Vector2d s = get_size();
3189 if (mouse.x >= p.x && mouse.x < p.x+s.dx && mouse.y>=p.y && mouse.y< p.y+s.dy)
3190 {
3191 //std::cout << "Enabled: " << mouse.x << " " << mouse.y << std::endl;
3192 //std::cout << p.x << " " << p.y << " " << s.dx << " " << s.dy << std::endl;
3193 enabled = true;
3194 }
3195 else
3196 {
3197 enabled = false;
3198 }
3199 if (enabled!=oldenabled)
3200 {
3201 c_changed = true;
3202 oldenabled = enabled;
3203 }
3204 if (firsttime)
3205 {
3206 if (highlight_bitmap != -1)
3207 {
3208 empty_bm_va.id = highlight_bitmap;
3209 bm_va.id = highlight_border;
3210 }
3211 else {
3212 Vector2d v;
3213 v.dx = 100;
3214 v.dy = 100;
3215 GameApi::BB bg = ev.bool_bitmap_api.bb_empty(v.dx, v.dy);
3216 GameApi::BB bb_1 = ev.bool_bitmap_api.rectangle(bg, 0.0,0.0, 2.0, (float)v.dy);
3217 GameApi::BB bb_2 = ev.bool_bitmap_api.rectangle(bb_1, 0.0,0.0, (float)v.dx, 2.0);
3218 GameApi::BB bb_3 = ev.bool_bitmap_api.rectangle(bb_2, v.dx-2.0,0.0, 2.0, v.dy);
3219 GameApi::BB bb_4 = ev.bool_bitmap_api.rectangle(bb_3, 0.0, v.dy-2, v.dx, 2.0);
3220 bm = ev.bool_bitmap_api.to_bitmap(bb_4, 255,255,255,255, 0,0,0,0);
3221 bm_va = ev.sprite_api.create_vertex_array(bm);
3222 empty_bm = ev.bool_bitmap_api.to_bitmap(bg, 255,255,255,255, 0,0,0,0);
3223 empty_bm_va = ev.sprite_api.create_vertex_array(empty_bm);
3224 highlight_bitmap = empty_bm_va.id;
3225 highlight_border = bm_va.id;
3226 }
3227 firsttime = false;
3228 }
3229 }
3230 void render()
3231 {
3232 if (is_visible())
3233 {
3234 if (!firsttime && enabled)
3235 {
3236 Vector2d v = get_size();
3237 Point2d p = get_pos();
3238 GameApi::M m = ev.matrix_api.trans(p.x+0.5, p.y+0.5, 0.0);
3239 GameApi::M ms = ev.matrix_api.scale(v.dx/100.0, v.dy/100.0, 1.0);
3240 GameApi::M mc = ev.matrix_api.mult(ms,m);
3241 ev.shader_api.set_var(sh, "in_MV", mc);
3242 ev.sprite_api.render_sprite_vertex_array(bm_va);
3243 }
3244 }
3245 }
3246 int render_to_bitmap()
3247 {
3248 if (enabled)
3249 return bm.id;
3250 else
3251 return empty_bm.id;
3252 }
3253 bool content_changed() const
3254 {
3255 return c_changed;
3256 }
3257 void clear_content_changed() { c_changed = false; }
3258private:
3259 GameApi::BM bm;
3260 GameApi::BM empty_bm;
3261 GameApi::VA bm_va;
3262 GameApi::VA empty_bm_va;
3263 GameApi::SH sh;
3264 bool firsttime=true;
3265 bool enabled = true;
3266 bool oldenabled;
3267 bool c_changed;
3268};
3269
3270
3271bool WidgetCompare(GuiWidget *w1, GuiWidget *w2)
3272{
3273 //std::cout << std::hex << (long)w1 << " ";
3274 //std::cout << std::hex << (long)w2 << std::endl;;
3275 float p1 = w1->get_pos().y;
3276 float p2 = w2->get_pos().y;
3277 if (fabs(p2-p1)<0.0001) return w1<w2;
3278 return p1<p2;
3279
3280}
3281
3282
3283class Highlight2GuiWidget : public GuiWidgetForward
3284{
3285public:
3286 Highlight2GuiWidget(GameApi::EveryApi &ev, GuiWidget *wid, GameApi::SH sh) : GuiWidgetForward(ev, {wid} ), sh(sh), enabled(false), oldenabled(false), c_changed(false) {
3287 firsttime=true;
3288 changed=false;
3289 Point2d p = { -666.0, -666.0 };
3290 update(p, -1, -1, -1,0);
3291 }
3292 void update(Point2d mouse, int button,int ch, int type, int mouse_wheel_y)
3293 {
3294 GuiWidgetForward::update(mouse, button,ch, type, mouse_wheel_y);
3295 Point2d p = get_pos();
3296 Vector2d s = get_size();
3297 if (mouse.x >= p.x && mouse.x < p.x+s.dx && mouse.y>=p.y && mouse.y< p.y+s.dy)
3298 {
3299 enabled = true;
3300 }
3301 else
3302 {
3303 enabled = false;
3304 }
3305 if (enabled!=oldenabled)
3306 {
3307 c_changed = true;
3308 oldenabled = enabled;
3309 }
3310 oldsize = size;
3311 size = vec[0]->get_size();
3312
3313 if (size.dx != oldsize.dx ||size.dy!=oldsize.dy)
3314 {
3315
3316 changed = true;
3317 }
3318
3319 if ((firsttime ||changed) && enabled)
3320 {
3321 Vector2d v = get_size();
3322 GameApi::BB bg = ev.bool_bitmap_api.bb_empty(v.dx, v.dy);
3323 GameApi::BB bb_1 = ev.bool_bitmap_api.rectangle(bg, 0.0,0.0, 2.0, (float)v.dy);
3324 GameApi::BB bb_2 = ev.bool_bitmap_api.rectangle(bb_1, 0.0,0.0, (float)v.dx, 2.0);
3325 GameApi::BB bb_3 = ev.bool_bitmap_api.rectangle(bb_2, v.dx-2.0,0.0, 2.0, v.dy);
3326 GameApi::BB bb_4 = ev.bool_bitmap_api.rectangle(bb_3, 0.0, v.dy-2, v.dx, 2.0);
3327 bm = ev.bool_bitmap_api.to_bitmap(bb_4, 255,255,255,255, 0,0,0,0);
3328 bm_va = ev.sprite_api.create_vertex_array(bm);
3329 empty_bm = ev.bool_bitmap_api.to_bitmap(bg, 255,255,255,255, 0,0,0,0);
3330 empty_bm_va = ev.sprite_api.create_vertex_array(empty_bm);
3331 firsttime = false;
3332 changed = false;
3333 }
3334 }
3335 void render()
3336 {
3337 if (is_visible())
3338 {
3340 if (!firsttime && enabled)
3341 {
3342 Point2d p = get_pos();
3343 ev.shader_api.set_var(sh, "in_MV", ev.matrix_api.trans(p.x+0.5, p.y+0.5, 0.0));
3344 ev.sprite_api.render_sprite_vertex_array(bm_va);
3345 }
3346 }
3347 }
3348 int render_to_bitmap()
3349 {
3350 if (enabled)
3351 return bm.id;
3352 else
3353 return empty_bm.id;
3354 }
3355 bool content_changed() const
3356 {
3357 return c_changed;
3358 }
3359 void clear_content_changed() { c_changed = false; }
3360private:
3361 GameApi::BM bm;
3362 GameApi::BM empty_bm;
3363 GameApi::VA bm_va;
3364 GameApi::VA empty_bm_va;
3365 GameApi::SH sh;
3366 bool firsttime;
3367 bool changed;
3368 bool enabled;
3369 bool oldenabled;
3370 bool c_changed;
3371 Vector2d oldsize;
3372};
3373
3374class LineWidget : public GuiWidgetForward
3375{
3376public:
3377 LineWidget(GameApi::EveryApi &ev, GameApi::SH sh, GuiWidget *t1, int delta_x, int delta_y,
3378 GuiWidget *t2, int delta2_x, int delta2_y, GameApi::SH sh2)
3379 : GuiWidgetForward(ev, { } ), sh(sh), t1(t1), delta_x(delta_x), delta_y(delta_y),
3380 t2(t2), delta2_x(delta2_x), delta2_y(delta2_y),sh2(sh2) { firsttime = true;
3381 Point2d p = t1->get_pos();
3382 p.x += delta_x;
3383 p.y += delta_y;
3384 Point2d p2 = t2->get_pos();
3385 p2.x += delta2_x;
3386 p2.y += delta2_y;
3387 Point2d pp = { std::min(p.x,p2.x), std::min(p.y,p2.y) };
3388 Point2d pp2 = { std::max(p.x,p2.x), std::max(p.y,p2.y) };
3389 Vector2d sz = pp2-pp;
3390 pos = pp;
3391 size = sz;
3392 Vector2d d = { 0.0, 0.0 };
3393 delta_vec = d;
3394 }
3395 void set_pos(Point2d p2)
3396 {
3397 //Point2d p = pos;
3399 //delta_vec = p2 - p + delta_vec;
3400 Point2d p = { -666.0, -666.0 };
3401 update(p, -1, -1, -1,0);
3402
3403 }
3404 GameApi::PT line_func(int linenum, bool id)
3405 {
3406 if (id==false) {
3407 Point2d pos = t1->get_pos();
3408 pos.x += delta_x;
3409 pos.y += delta_y;
3410 pos+=delta_vec;
3411 return ev.point_api.point(pos.x, pos.y, 0.0);
3412 } else {
3413 Point2d pos = t2->get_pos();
3414 pos.x += delta2_x;
3415 pos.y += delta2_y;
3416 pos+=delta_vec;
3417 return ev.point_api.point(pos.x, pos.y, 0.0);
3418 }
3419 return ev.point_api.point(0.0,0.0,0.0);
3420 }
3421 GameApi::P line_to_poly(int i, float sx, float sy, float sz, float ex, float ey, float ez, unsigned int scolor, unsigned int ecolor)
3422 {
3423 //std::cout << sx << " " << sy << " " << sz << ":" << ex << " " << ey << " " << ez << std::endl;
3424 GameApi::PT p1 = ev.point_api.point(sx-2,sy,0.0);
3425 GameApi::PT p2 = ev.point_api.point(sx,sy+2,0.0);
3426 GameApi::PT p3 = ev.point_api.point(ex+2,ey,0.0);
3427 GameApi::PT p4 = ev.point_api.point(ex,ey+2,0.0);
3428 GameApi:: P poly = ev.polygon_api.quad(p1,p2,p3,p4);
3429 //GameApi::P poly = ev.polygon_api.quad_z(sx,ex,sy,ey,0.0);
3430 return ev.polygon_api.color(poly, 0xffffffff);
3431 }
3432 void update(Point2d mouse_pos, int button, int ch, int type, int mouse_wheel_y)
3433 {
3434 using std::placeholders::_1;
3435 using std::placeholders::_2;
3436 using std::placeholders::_3;
3437 using std::placeholders::_4;
3438 using std::placeholders::_5;
3439 using std::placeholders::_6;
3440 using std::placeholders::_7;
3441 using std::placeholders::_8;
3442 using std::placeholders::_9;
3443 if (firsttime)
3444 {
3445 line = ev.lines_api.function([this](int a,bool b){ return line_func(a,b); }, 1);
3446 line = ev.lines_api.change_color(line, 0xffffffff);
3447 line_2 = ev.polygon_api.from_lines(line, [this](int a,float b,float c,float d,float e,float f,float g,unsigned int h,unsigned int i) { return line_to_poly(a,b,c,d,e,f,g,h,i); });
3448 line_3 = ev.polygon_api.create_vertex_array(line_2, true);
3449 //line_p = ev.lines_api.prepare(line);
3450 firsttime = false;
3451 }
3452 else
3453 {
3454
3455 if (old_t1_pos.x != t1->get_pos().x ||old_t2_pos.x != t2->get_pos().x
3456 ||old_t1_pos.y != t1->get_pos().y || old_t2_pos.y != t2->get_pos().y)
3457 {
3458 line = ev.lines_api.function([this](int a,bool b){ return line_func(a,b); }, 1);
3459 line = ev.lines_api.change_color(line, 0xffffffff);
3460 line_2 = ev.polygon_api.from_lines(line, [this](int a,float b,float c,float d,float e,float f,float g,unsigned int h,unsigned int i) { return line_to_poly(a,b,c,d,e,f,g,h,i); });
3461
3462
3463 ev.polygon_api.update_vertex_array_no_memory(line_3, line_2);
3464 }
3465 //ev.lines_api.update(line_p, line);
3466 }
3467 old_t1_pos = t1->get_pos();
3468 old_t2_pos = t2->get_pos();
3469
3470
3471 Point2d p = t1->get_pos();
3472 p.x += delta_x;
3473 p.y += delta_y;
3474 p+=delta_vec;
3475 Point2d p2 = t2->get_pos();
3476 p2.x += delta2_x;
3477 p2.y += delta2_y;
3478 p2+=delta_vec;
3479 Point2d pp = { std::min(p.x,p2.x), std::min(p.y,p2.y) };
3480 Point2d pp2 = { std::max(p.x,p2.x), std::max(p.y,p2.y) };
3481 Vector2d sz = pp2-pp;
3482 pos = pp;
3483 size = sz;
3484
3485
3486 }
3487 void render()
3488 {
3489 if (is_visible())
3490 {
3491 if (!firsttime)
3492 {
3493 ev.shader_api.use(sh);
3494 ev.shader_api.set_var(sh, "in_MV", ev.matrix_api.identity());
3495 //ev.lines_api.render(line_p);
3496 ev.polygon_api.render_vertex_array(line_3);
3497 ev.shader_api.use(sh2);
3498 }
3499 }
3500 }
3501private:
3502 GameApi::SH sh;
3503 bool firsttime;
3504 GuiWidget *t1;
3505 int delta_x, delta_y;
3506 GuiWidget *t2;
3507 int delta2_x, delta2_y;
3508 GameApi::LI line;
3509 GameApi::P line_2;
3510 GameApi::VA line_3;
3511 //GameApi::LLA line_p;
3512 Point2d old_t1_pos;
3513 Point2d old_t2_pos;
3514 GameApi::SH sh2;
3515 Vector2d delta_vec;
3516};
3517
3518class LineWidget2 : public GuiWidgetForward
3519{
3520public:
3521 LineWidget2(GameApi::Env &env, GameApi::EveryApi &ev, GameApi::SH sh, GuiWidget *t1, int delta_x, int delta_y,
3522 GuiWidget *t2, int delta2_x, int delta2_y, GameApi::SH sh2)
3523 : GuiWidgetForward(ev, { } ), env(env), sh(sh), t1(t1), delta_x(delta_x), delta_y(delta_y),
3524 t2(t2), delta2_x(delta2_x), delta2_y(delta2_y),sh2(sh2) { firsttime = true;
3525 Point2d p = t1->get_pos();
3526 p.x += delta_x;
3527 p.y += delta_y;
3528 Point2d p2 = t2->get_pos();
3529 p2.x += delta2_x;
3530 p2.y += delta2_y;
3531 Point2d pp = { std::min(p.x,p2.x), std::min(p.y,p2.y) };
3532 Point2d pp2 = { std::max(p.x,p2.x), std::max(p.y,p2.y) };
3533 Vector2d sz = pp2-pp;
3534 pos = pp;
3535 size = sz;
3536 Vector2d d = { 0.0, 0.0 };
3537 delta_vec = d;
3538}
3539 void set_pos(Point2d p2)
3540 {
3541 //Point2d p = pos;
3543 //delta_vec = p2 - p + delta_vec;
3544 Point2d p = { -666.0, -666.0 };
3545 update(p, -1, -1, -1,0);
3546
3547 }
3548 GameApi::PT line_func(int linenum, bool id)
3549 {
3550 if (id)
3551 return ev.point_api.point(100.0,0.0,0.0);
3552 return ev.point_api.point(0.0,0.0,0.0);
3553 }
3554 GameApi::P line_to_poly(int i, float sx, float sy, float sz, float ex, float ey, float ez, unsigned int scolor, unsigned int ecolor)
3555 {
3556 //std::cout << sx << " " << sy << " " << sz << ":" << ex << " " << ey << " " << ez << std::endl;
3557 int width = 200;
3558 GameApi::PT p1 = ev.point_api.point(sx,sy,0.0);
3559 GameApi::PT p2 = ev.point_api.point(sx,sy+width,0.0);
3560 GameApi::PT p3 = ev.point_api.point(ex,ey,0.0);
3561 GameApi::PT p4 = ev.point_api.point(ex,ey+width,0.0);
3562 GameApi:: P poly = ev.polygon_api.quad(p1,p2,p3,p4);
3563 //GameApi::P poly = ev.polygon_api.quad_z(sx,ex,sy,ey,0.0);
3564 return ev.polygon_api.color(poly, 0xffffffff);
3565 }
3566 void update(Point2d mouse_pos, int button, int ch, int type, int mouse_wheel_y)
3567 {
3568 using std::placeholders::_1;
3569 using std::placeholders::_2;
3570 using std::placeholders::_3;
3571 using std::placeholders::_4;
3572 using std::placeholders::_5;
3573 using std::placeholders::_6;
3574 using std::placeholders::_7;
3575 using std::placeholders::_8;
3576 using std::placeholders::_9;
3577 if (firsttime)
3578 {
3579 line = ev.lines_api.function([this](int a,bool b){ return line_func(a,b); }, 1);
3580 line = ev.lines_api.change_color(line, 0xffffffff);
3581 line_2 = ev.polygon_api.from_lines(line, [this](int a,float b,float c,float d,float e,float f,float g,unsigned int h,unsigned int i) { return line_to_poly(a,b,c,d,e,f,g,h,i); });
3582 line_3 = ev.polygon_api.create_vertex_array(line_2, true);
3583 //line_p = ev.lines_api.prepare(line);
3584 firsttime = false;
3585 }
3586 else
3587 {
3588#if 0
3589 if (old_t1_pos.x != t1->get_pos().x ||old_t2_pos.x != t2->get_pos().x
3590 ||old_t1_pos.y != t1->get_pos().y || old_t2_pos.y != t2->get_pos().y)
3591 {
3592 line = ev.lines_api.function([this](int a,bool b){ return line_func(a,b); }, 1);
3593 line = ev.lines_api.change_color(line, 0xffffffff);
3594 line_2 = ev.polygon_api.from_lines(line, [this](int a,float b,float c,float d,float e,float f,float g,unsigned int h,unsigned int i) { return line_to_poly(a,b,c,d,e,f,g,h,i); });
3595
3596
3597 ev.polygon_api.update_vertex_array_no_memory(line_3, line_2);
3598 }
3599 //ev.lines_api.update(line_p, line);
3600#endif
3601 }
3602 old_t1_pos = t1->get_pos();
3603 old_t2_pos = t2->get_pos();
3604
3605
3606 Point2d p = t1->get_pos();
3607 p.x += delta_x;
3608 p.y += delta_y;
3609 p+=delta_vec;
3610 Point2d p2 = t2->get_pos();
3611 p2.x += delta2_x;
3612 p2.y += delta2_y;
3613 p2+=delta_vec;
3614 Point2d pp = { std::min(p.x,p2.x), std::min(p.y,p2.y) };
3615 Point2d pp2 = { std::max(p.x,p2.x), std::max(p.y,p2.y) };
3616 Vector2d sz = pp2-pp;
3617 pos = pp;
3618 size = sz;
3619
3620
3621 }
3622 void render()
3623 {
3624 if (is_visible())
3625 {
3626 if (!firsttime)
3627 {
3628 ev.shader_api.use(sh);
3629 Point2d p = t1->get_pos();
3630 p.x += delta_x;
3631 p.y += delta_y;
3632 p+=delta_vec;
3633 Point2d p2 = t2->get_pos();
3634 p2.x += delta2_x;
3635 p2.y += delta2_y;
3636 p2+=delta_vec;
3637 LineProperties prop(Point(p.x,p.y,0.0), Point(p2.x,p2.y,0.0));
3638 Matrix m0 = Matrix::Scale(1.0/100.0, 1.0/100.0,1.0);
3639 Matrix m1 = prop.translate_to_p1();
3640 Matrix m2 = prop.rotate_z_from_p1_in_2d();
3641 Matrix m3 = prop.scale_length_in_2d();
3642 Matrix mm = m0*m3*m2*m1;
3643 GameApi::M mm2 = add_matrix2(env, mm);
3644 ev.shader_api.set_var(sh, "in_MV", mm2);
3645 //ev.lines_api.render(line_p);
3646 ev.polygon_api.render_vertex_array(line_3);
3647 ev.shader_api.use(sh2);
3648 }
3649 }
3650 }
3651private:
3652 GameApi::Env &env;
3653 GameApi::SH sh;
3654 bool firsttime;
3655 GuiWidget *t1;
3656 int delta_x, delta_y;
3657 GuiWidget *t2;
3658 int delta2_x, delta2_y;
3659 GameApi::LI line;
3660 GameApi::P line_2;
3661 GameApi::VA line_3;
3662 //GameApi::LLA line_p;
3663 Point2d old_t1_pos;
3664 Point2d old_t2_pos;
3665 GameApi::SH sh2;
3666 Vector2d delta_vec;
3667};
3668
3669EXPORT GameApi::W GameApi::GuiApi::timed_visibility(W orig, W (*timed_widget_func)(void*), void*data, W insert, float start_duration, float duration, float dx)
3670{
3671 GuiWidget *o = find_widget(e,orig);
3672 //GuiWidget *t = find_widget(e,timed_widget);
3673 GuiWidget *i = find_widget(e, insert);
3674#ifdef EMSCRIPTEN
3675 GuiWidgetForward *ii = static_cast<GuiWidgetForward*>(i);
3676#else
3677 GuiWidgetForward *ii = dynamic_cast<GuiWidgetForward*>(i);
3678#endif
3679 return add_widget(e, new TimedWidget(ev, o, timed_widget_func,data, ii, start_duration, duration, dx));
3680}
3681
3683{
3684 return add_widget(e, new EmptyWidget(ev));
3685}
3686
3687struct ToolTipData
3688{
3689 GameApi::GuiApi *api;
3690 GameApi::W orig;
3691 GameApi::W insert;
3692 std::string label;
3693 GameApi::FtA atlas;
3694 GameApi::BM atlas_bm;
3695 int x_gap;
3696 float dx;
3697};
3698
3699GameApi::W tooltip_func(void *data)
3700{
3701 ToolTipData *dt = (ToolTipData*)data;
3702 GameApi::W w = dt->api->text(dt->label, dt->atlas, dt->atlas_bm, dt->x_gap);
3703 GameApi::W w1 = dt->api->margin(w, 5,5,5,5);
3704 GameApi::W w2 = dt->api->button(dt->api->size_x(w1),dt->api->size_y(w1), c_tooltip_button, c_tooltip_button2 /*0xff888888, c_dialog_1_2*/);
3705 GameApi::W w3 = dt->api->layer(w2,w1);
3706 float p_x = dt->api->pos_x(dt->orig) + dt->api->size_x(dt->orig) + 10.0;
3707 float p_y = dt->api->pos_y(dt->orig) + 10.0;
3708 dt->api->set_pos(w3, p_x, p_y);
3709 return w3;
3710}
3711
3712GameApi::W GameApi::GuiApi::tooltip(W orig, W insert, std::string label, FtA atlas, BM atlas_bm, int x_gap, float dx)
3713{
3714 ToolTipData *dt = new ToolTipData;
3715 dt->api = this;
3716 dt->orig = orig;
3717 dt->insert = insert;
3718 dt->label = label;
3719 dt->atlas = atlas;
3720 dt->atlas_bm = atlas_bm;
3721 dt->x_gap = x_gap;
3722 dt->dx = dx;
3723
3724 W w4 = timed_visibility(orig, tooltip_func, (void*)dt, insert, 0.3, 400.0, dx);
3725 return w4;
3726}
3728 W target2, int delta2_x, int delta2_y, SH sh, SH old_sh)
3729{
3730 GuiWidget *t1 = find_widget(e, target1);
3731 GuiWidget *t2 = find_widget(e, target2);
3732 return add_widget(e, new LineWidget2(e,ev, sh, t1, delta_x, delta_y,
3733 t2, delta2_x, delta2_y, old_sh));
3734}
3736{
3737 return add_widget(e, new CanvasWidget(ev, sx, sy));
3738}
3740{
3741 GuiWidget *w = find_widget(e, canvas);
3742 if (!w) {
3743 {
3744 // std::cout << "ERROR: find_canvas_item failed to find canvas!" << std::endl;
3745 GameApi::W wx;
3746 wx.id = -1;
3747 return wx;
3748 }
3749 }
3750#ifndef EMSCRIPTEN
3751 CanvasWidget *ww = dynamic_cast<CanvasWidget*>(w);
3752#else
3753 CanvasWidget *ww = static_cast<CanvasWidget*>(w);
3754#endif
3755 GuiWidget *item = ww->find_widget(id);
3756 if (!item)
3757 {
3758 // std::cout << "ERROR: find_canvas_item failed to find widget from canvas!" << std::endl;
3759 GameApi::W wx;
3760 wx.id = -1;
3761 return wx;
3762 }
3764 int s = env->widgets.size();
3765 for(int i=0;i<s;i++)
3766 {
3767 GuiWidget *w = env->widgets[i];
3768 if (w==item) { GameApi::W w; w.id = i; return w; }
3769 }
3770 //std::cout << "ERROR: find_canvas_item failed to find widget!" << std::endl;
3771 GameApi::W wx;
3772 wx.id = -1;
3773 return wx;
3774
3775}
3777{
3778 GuiWidget *canvas_1 = find_widget(e, canvas);
3779#ifdef EMSCRIPTEN
3780 CanvasWidget *canvas_2 = static_cast<CanvasWidget*>(canvas_1);
3781#else
3782 CanvasWidget *canvas_2 = dynamic_cast<CanvasWidget*>(canvas_1);
3783#endif
3784 if (!canvas_2) return -1;
3785 GuiWidget *item_1 = find_widget(e, item);
3786 canvas_2->push_back(item_1, x, y);
3787 return canvas_2->count()-1;
3788}
3790{
3791 GuiWidget *canvas_1 = find_widget(e, canvas);
3792#ifdef EMSCRIPTEN
3793 CanvasWidget *canvas_2 = static_cast<CanvasWidget*>(canvas_1);
3794#else
3795 CanvasWidget *canvas_2 = dynamic_cast<CanvasWidget*>(canvas_1);
3796#endif
3797 if (!canvas_2) return;
3798 canvas_2->del(id);
3799}
3801{
3802 GuiWidget *canvas_1 = find_widget(e, canvas);
3803#ifdef EMSCRIPTEN
3804 CanvasWidget *canvas_2 = static_cast<CanvasWidget*>(canvas_1);
3805#else
3806 CanvasWidget *canvas_2 = dynamic_cast<CanvasWidget*>(canvas_1);
3807#endif
3808 if (!canvas_2) return -1;
3809 GuiWidget *item_1 = find_widget(e, item);
3810 return canvas_2->find_index(item_1);
3811}
3812EXPORT GameApi::W GameApi::GuiApi::list_item_title(int sx, std::string label, FtA atlas, BM atlas_bm)
3813{
3814 W node_t = text(label, atlas, atlas_bm);
3815 W node_t0 = margin(node_t, 5,5,5,5);
3816 //std::cout << "List Item title height: " << size_y(node_t0) << std::endl;
3817 W node_0 = button(sx, size_y(node_t0), c_list_item_title, c_list_item_title2 /*0xff884422, 0xff442211*/);
3818 W node_1 = layer(node_0, node_t0);
3819 W node_2 = highlight(node_1);
3820 return node_2;
3821 }
3822
3823EXPORT GameApi::W GameApi::GuiApi::list_item_opened(int sx, std::string label, FtA atlas, BM atlas_bm, std::vector<std::string> subitems, std::vector<std::string> subitems_tooltip, FtA atlas2, BM atlas_bm2, W insert, bool hide, W *redraw_w, std::vector<std::string> subitems_funcname)
3824{
3825 W title = list_item_title(sx, label, atlas, atlas_bm);
3826 std::vector<W> vec;
3827 vec.push_back(title);
3828 int s = subitems.size();
3829 std::vector<W> w_vec;
3830 for(int i=0;i<s;i++)
3831 {
3832 W txt_3;
3833 //if (!hide) {
3834 std::string label = subitems[i];
3835 std::string toolt = label + "::" + subitems_tooltip[i];
3836 std::string label2;
3837 if (!hide) {
3838 int s2 = label.size();
3839 for(int j=0;j<s2;j++) {
3840 label2+=label[j];
3841 GameApi::BM txt_0=ev.font_api.font_string_from_atlas(ev,atlas2,atlas_bm2,label2,3*1.2);
3842 int sz = ev.bitmap_api.size_x(txt_0);
3843 if (sz>sx) break;
3844 }
3845 if (label2 != label) {
3846 if (label2.size()>2) label2=label2.substr(0,label2.size()-2);
3847 label2+="..";
3848 }
3849 } else { label2=label; }
3850 W txt_0 = text(label2, atlas2, atlas_bm2);
3851 W txt_1 = margin(txt_0, 5, 2, sx-5-size_x(txt_0), 2);
3852 W txt_2 = highlight(size_x(txt_1), size_y(txt_1));
3853 W txt_21 = tooltip(txt_2, insert, toolt, atlas2, atlas_bm2, 2, 40.0);
3854 txt_3 = layer(txt_1, txt_21);
3855 W txt_4 = hide_nonsearchable(txt_3,label+"::"+subitems_funcname[i],redraw_w);
3856 vec.push_back(txt_4);
3857 w_vec.push_back(txt_4);
3858 }
3859 W array = array_y(vec /*&vec[0], vec.size()*/,2,true); // this needs heavy=true
3860 W array_2 = margin(array, 1,1,1,1);
3861 if (hide) array_2 = title;
3862 W array_3 = hide_if_array_empty(array_2,w_vec,redraw_w);
3863 return array_3;
3864}
3865
3867
3870
3871class WindowMoveWidget : public GuiWidgetForward
3872{
3873public:
3874 WindowMoveWidget(GameApi::EveryApi &ev, GuiWidget *wid, int area_x, int area_y, int area_width, int area_height) : GuiWidgetForward(ev, { wid } ), area_x(area_x), area_y(area_y), area_width(area_width), area_height(area_height) { move_ongoing = false;
3875 Point2d p = { -666.0, -666.0 };
3876 update(p, -1, -1, -1, 0);
3877 }
3878 void update(Point2d mouse, int button, int ch, int type, int mouse_wheel_y)
3879 {
3880 GuiWidgetForward::update(mouse,button,ch, type, mouse_wheel_y);
3881 if (!move_ongoing && button==0 && type==1025 && mouse.x >= pos.x+area_x && mouse.x < pos.x+area_x+area_width &&
3882 mouse.y >= pos.y+area_y && mouse.y < pos.y+area_y+area_height)
3883 {
3884 move_ongoing = true;
3885 old_mouse = mouse;
3886 int px = g_window_pos_x;
3887 int py = g_window_pos_y;
3888 //g_low->sdl->SDL_GetWindowPosition(sdl_window, &px, &py);
3889 // std::cout << "GOT WINDOW POS:" << px << " " << py << std::endl;
3890 Point2d p = { float(px), float(py) };
3891 old_pos = p;
3892 }
3893 if (move_ongoing) {
3894 Vector2d delta = mouse - old_mouse;
3895 Point2d p = old_pos + delta;
3896 //g_low->sdl->SDL_SetWindowPosition(sdl_window, p.x, p.y);
3897 g_window_pos_x = p.x;
3898 g_window_pos_y = p.y;
3899 //std::cout << "Set WINDOW POS:" << p.x << " " << p.y << std::endl;
3900 }
3901 if (move_ongoing && button==-1)
3902 {
3903 move_ongoing = false;
3904 }
3905 size = vec[0]->get_size();
3906 }
3907 int chosen_item() const { return vec[0]->chosen_item(); }
3908private:
3909 int area_x, area_y;
3910 int area_width, area_height;
3911 bool move_ongoing;
3912 Point2d old_pos;
3913 Point2d old_mouse;
3914};
3915
3916class MouseMoveWidget : public GuiWidgetForward
3917{
3918public:
3919 MouseMoveWidget(GameApi::EveryApi &ev, GuiWidget *wid, int area_x, int area_y, int area_width, int area_height) : GuiWidgetForward(ev, { wid } ), area_x(area_x), area_y(area_y), area_width(area_width), area_height(area_height) { move_ongoing = false;
3920 Point2d p = { -666.0, -666.0 };
3921 update(p, -1, -1, -1,0);
3922 }
3923 void update(Point2d mouse, int button, int ch, int type, int mouse_wheel_y)
3924 {
3925 GuiWidgetForward::update(mouse,button,ch, type, mouse_wheel_y);
3926 if (!move_ongoing && button==0 && type==1025 && mouse.x >= pos.x+area_x && mouse.x < pos.x+area_x+area_width &&
3927 mouse.y >= pos.y+area_y && mouse.y < pos.y+area_y+area_height)
3928 {
3929 move_ongoing = true;
3930 old_mouse = mouse;
3931 old_pos = pos;
3932 }
3933 if (move_ongoing) {
3934 Vector2d delta = mouse - old_mouse;
3935 Point2d p = old_pos + delta;
3936 set_pos(p);
3937 }
3938 if (move_ongoing && button==-1)
3939 {
3940 move_ongoing = false;
3941 //if (fptr_enabled) fptr(data);
3942 }
3943 size = vec[0]->get_size();
3944 }
3945 void set_cb(void (*p_fptr)(void*),void* p_data) { /*fptr_enabled=true; fptr=p_fptr; data=p_data;*/ }
3946 int chosen_item() const { return vec[0]->chosen_item(); }
3947private:
3948 int area_x, area_y;
3949 int area_width, area_height;
3950 bool move_ongoing;
3951 Point2d old_pos;
3952 Point2d old_mouse;
3953 bool fptr_enabled;
3954 //void (*fptr)(void*);
3955 //void *data;
3956};
3957void set_mouse_move_cb(GuiWidget *w, void (*fptr)(void*), void*data)
3958{
3959 MouseMoveWidget *w2 = (MouseMoveWidget*)w;
3960 w2->set_cb(fptr,data);
3961}
3962
3963
3964class RectangleWidget : public GuiWidgetForward
3965{
3966public:
3967 RectangleWidget() = delete;
3968 RectangleWidget(GameApi::EveryApi &ev, GameApi::SH sh, int start_x, int end_x, int start_y, int end_y, unsigned int color) : GuiWidgetForward(ev, { } ), sh(sh), start_x(start_x), end_x(end_x), start_y(start_y), end_y(end_y), color(color) {
3969 firsttime = true;
3970 Point2d p = { -666.0, -666.0 };
3971 update(p, -1, -1, -1,0);
3972 }
3973 void update(Point2d mouse, int button, int ch, int type, int mouse_wheel_y)
3974 {
3975 GuiWidgetForward::update(mouse,button,ch, type, mouse_wheel_y);
3976 Vector2d sz = { float(end_x-start_x), float(end_y-start_y) };
3977 size = sz;
3978 if (firsttime)
3979 {
3980 sx = size.dx;
3981 sy = size.dy;
3982 GameApi::BB b = ev.bool_bitmap_api.bb_empty(sx,sy);
3983 GameApi::BB b1 = ev.bool_bitmap_api.rectangle(b, 0.0, 0.0, float(sx),float(sy));
3984 Color c(color);
3985 bg = ev.bool_bitmap_api.to_bitmap(b1, c.r,c.g,c.b,c.alpha,0,0,0,0);
3986 bg_va = ev.sprite_api.create_vertex_array(bg);
3987 firsttime = false;
3988 }
3989
3990 }
3991 void render() {
3992 if (is_visible())
3993 {
3994 if (!firsttime)
3995 {
3996 Point2d p = get_pos();
3997 ev.shader_api.set_var(sh, "in_MV", ev.matrix_api.trans(p.x, p.y, 0.0));
3998 ev.sprite_api.render_sprite_vertex_array(bg_va);
3999 }
4000 }
4001
4002 }
4003private:
4004 int sx,sy;
4005 GameApi::SH sh;
4006 GameApi::BM bg;
4007 GameApi::VA bg_va;
4008 int start_x, end_x;
4009 int start_y, end_y;
4010 bool firsttime;
4011 unsigned int color;
4012};
4013
4014EXPORT GameApi::W GameApi::GuiApi::rectangle(int start_x, int end_x, int start_y, int end_y, unsigned int color)
4015{
4016 return add_widget(e, new RectangleWidget(ev,sh,start_x, end_x, start_y, end_y, color));
4017}
4018
4019class ClickAreaWidget : public GuiWidgetForward
4020{
4021public:
4022 ClickAreaWidget(GameApi::EveryApi &ev, GuiWidget *wid, int area_x, int area_y, int area_width, int area_height, int button_id2) : GuiWidgetForward(ev, { wid } ), area_x(area_x), area_y(area_y), area_width(area_width), area_height(area_height) { done=false;
4023 selected = false;
4024 button_id = button_id2;
4025 Point2d p = { -666.0, -666.0 };
4026 update(p, -1, -1, -1,0);
4027 }
4028 void update(Point2d mouse, int button, int ch, int type, int mouse_wheel_y)
4029 {
4030 GuiWidgetForward::update(mouse,button,ch, type, mouse_wheel_y);
4031
4032 if (done) selected=false;
4033 if (button==-1) {done = false; }
4034
4035 //std::cout << "Update!" << std::endl;
4036 //std::cout << button << " " << type << " " << mouse << " " << pos << " " << area_x << " " << area_y << " " << area_width << " " << area_height << std::endl;
4037 if (!done && button==button_id && type==1025 && mouse.x >= pos.x+area_x && mouse.x < pos.x+area_x+area_width &&
4038 mouse.y >= pos.y+area_y && mouse.y < pos.y+area_y+area_height)
4039 {
4040 //std::cout << "Selected: true" << std::endl;
4041 selected = true;
4042 done = true;
4043 }
4044 size = vec[0]->get_size();
4045 }
4046 int chosen_item() const { if (selected) { selected=false; return 0; } else return -1; }
4047private:
4048 int area_x, area_y;
4049 int area_width, area_height;
4050 mutable bool selected;
4051 bool done;
4052 int button_id;
4053};
4054
4055class KeyAreaWidget : public GuiWidgetForward
4056{
4057public:
4058 KeyAreaWidget(GameApi::EveryApi &ev, GuiWidget *wid, int area_x, int area_y, int area_width, int area_height, int key) : GuiWidgetForward(ev, { wid } ), area_x(area_x), area_y(area_y), area_width(area_width), area_height(area_height),key(key) { done=false;
4059 Point2d p = { -666.0, -666.0 };
4060 update(p, -1, -1, -1,0);
4061 selected=false;
4062 }
4063 void update(Point2d mouse, int button, int ch, int type, int mouse_wheel_y)
4064 {
4065 GuiWidgetForward::update(mouse,button,ch, type, mouse_wheel_y);
4066
4067 if (done) {selected=false; }
4068 if (ch==-1) {done = false; }
4069
4070 //std::cout << "Update!" << std::endl;
4071 //std::cout << button << " " << mouse << " " << pos << " " << area_x << " " << area_y << " " << area_width << " " << area_height << std::endl;
4072 if (!done && ch==key && type==768 && mouse.x >= pos.x+area_x && mouse.x < pos.x+area_x+area_width &&
4073 mouse.y >= pos.y+area_y && mouse.y < pos.y+area_y+area_height)
4074 {
4075 //std::cout << "Selected: true" << std::endl;
4076 selected = true;
4077 done = true;
4078 }
4079 size = vec[0]->get_size();
4080 }
4081 int chosen_item() const { if (selected) return 0; else return -1; }
4082private:
4083 int area_x, area_y;
4084 int area_width, area_height;
4085 bool selected;
4086 bool done;
4087 int key;
4088};
4089
4090
4091EXPORT GameApi::W GameApi::GuiApi::click_area(W widget, int area_x, int area_y, int area_width, int area_height, int button_id)
4092{
4093 GuiWidget *wid = find_widget(e, widget);
4094 return add_widget(e, new ClickAreaWidget(ev, wid, area_x, area_y, area_width, area_height,button_id));
4095
4096}
4097EXPORT GameApi::W GameApi::GuiApi::key_area(W widget, int area_x, int area_y, int area_width, int area_height, int key)
4098{
4099 GuiWidget *wid = find_widget(e, widget);
4100 return add_widget(e, new KeyAreaWidget(ev, wid, area_x, area_y, area_width, area_height, key));
4101
4102}
4103
4104EXPORT GameApi::W GameApi::GuiApi::mouse_move(W widget, int area_x, int area_y, int area_width, int area_height)
4105{
4106 GuiWidget *wid = find_widget(e, widget);
4107 return add_widget(e, new MouseMoveWidget(ev, wid, area_x, area_y, area_width, area_height));
4108}
4109
4110EXPORT GameApi::W GameApi::GuiApi::window_move(W widget, int area_x, int area_y, int area_width, int area_height)
4111{
4112 GuiWidget *wid = find_widget(e, widget);
4113 return add_widget(e, new WindowMoveWidget(ev, wid, area_x, area_y, area_width, area_height));
4114}
4115
4116int ret_type_count(std::string return_type)
4117{
4118 //if (return_type.size()>1&&return_type[0]=='[') return 1; // filter out array rturns
4119 int s = return_type.size();
4120 int count = 1;
4121 int level = 0;
4122 for(int i=0;i<s;i++) {
4123 if (return_type[i]=='[') level++;
4124 if (return_type[i]==']') level--;
4125 if (return_type[i]==',' && level==0) count++;
4126 }
4127 return count;
4128}
4129std::string ret_type_index(std::string return_type, int index)
4130{
4131 int s = return_type.size();
4132 int count = 0;
4133 int beg = 0;
4134 std::string label;
4135 int i=0;
4136 int level = 0;
4137 for(;i<s;i++) {
4138 if (return_type[i]=='[') level++;
4139 if (return_type[i]==']') level--;
4140 if (return_type[i]==',' && level==0) {
4141 label = return_type.substr(beg,i-beg);
4142 if (count==index) return label;
4143 count++;
4144 beg = i+1;
4145 }
4146 }
4147 label = return_type.substr(beg,i-beg);
4148 return label;
4149}
4150
4151
4152EXPORT GameApi::W GameApi::GuiApi::license_item(std::string filename, std::string &license_url, std::string &author_name, FtA atlas, BM atlas_bm, FtA atlas2, BM atlas_bm2)
4153{
4154 W label = text(filename, atlas2,atlas_bm2);
4155 W author_label = text("Author:", atlas, atlas_bm);
4156 static std::string expr;
4157 static W redraw_w = empty();
4158 W author_edit = string_editor("abcdefghijklmnopqrstuvwxyz\xE5\xE4\xF6 ABCDEFGHIJKLMNOPQRSTUVWXYZ\xC5\xC4\xD6 1234567890-_*^@£$!#¤%&/()=? ", author_name, expr, atlas, atlas_bm,0,0,&redraw_w);
4159 W arr_x[] = { author_label, author_edit };
4160 W author_x = array_x(&arr_x[0], 2, 0);
4161 W author_marg = margin(author_x,5,0,0,0);
4162 W license_label = text("License:", atlas, atlas_bm);
4163 static std::string expr2;
4164 W edit = url_editor(license_url, atlas, atlas_bm, 3, expr2);
4165 W arr_x2[] = { license_label, edit };
4166 W license_x = array_x(&arr_x2[0],2,0);
4167 W marg = margin(license_x,5,0,0,0);
4168 std::vector<W> arr0;
4169 arr0.push_back(label);
4170 arr0.push_back(author_marg);
4171 arr0.push_back(marg);
4172 W arr = array_y(arr0 /*&arr0[0],3*/, 3);
4173 return arr;
4174}
4175
4176
4177EXPORT GameApi::W GameApi::GuiApi::asset_item(EveryApi &ev, std::string jpg_url, std::string jpg_display_name, FtA atlas, BM atlas_bm)
4178{
4179 W label = text(jpg_display_name, atlas,atlas_bm);
4180 W label_margin = margin(label, 120, 15, 15, 15);
4181 BM bm = ev.bitmap_api.loadbitmapfromurl(jpg_url);
4182 BM bm2 = ev.bitmap_api.scale_bitmap(ev, bm, 30, 30);
4183 W icon_contents = icon(bm2);
4184 W icon_margin = margin(icon_contents, 15,5,120+15,5);
4185 std::vector<W> vec;
4186 vec.push_back(label_margin);
4187 vec.push_back(icon_margin);
4188 W over = overlap(ev,vec);
4189 return over;
4190}
4191
4192EXPORT GameApi::W GameApi::GuiApi::asset_dialog(EveryApi &ev, std::vector<std::string> jpg_urls, std::vector<std::string> jpg_display_names,W &select_button, W &cancel_button, FtA atlas, BM atlas_bm)
4193{
4194 int s = std::min(jpg_urls.size(),jpg_display_names.size());
4195 std::vector<W> vec;
4196 for(int i=0;i<s;i++)
4197 {
4198 W item = asset_item(ev,jpg_urls[i], jpg_display_names[i],atlas, atlas_bm);
4199 vec.push_back(item);
4200 }
4201 W arr = array_y(vec /*&vec[0], vec.size()*/, 3);
4202 W cnvs = canvas(800,size_y(arr));
4203 W area = scroll_area2(cnvs, 800,400, 900);
4204 W cnv_item = canvas_item(cnvs, arr, 0,0);
4205 W scrollbar = scrollbar_y(15,400,size_y(arr));
4206 //scroll_bar = scrollbar;
4207 //canvas2 = cnvs;
4208 //canvas_area2=area;
4209
4210 std::vector<W> xx;
4211 xx.push_back(area);
4212 xx.push_back(scrollbar);
4213 W arr_xx = array_x(&xx[0],2,2);
4214
4215 int my = 45;
4216 int my2 = 10;
4217 int mx = 10;
4218
4219 W marg = margin(arr_xx, mx,my,mx,my2);
4220
4221 W bm_4 = marg;
4222
4223 W but_1 = text("Select", atlas, atlas_bm);
4224 W but_2 = center_align(but_1, size_x(bm_4)/2);
4225 W but_3 = center_y(but_2, 60.0);
4226 W but_4 = button(size_x(but_3), size_y(but_3), c_dialog_button_1, c_dialog_button_2);
4227 W but_41 = highlight(but_4);
4228 W but_5 = layer(but_41, but_3);
4229 W but_6 = click_area(but_5, 0,0,size_x(but_5), size_y(but_5),0);
4230 select_button = but_6;
4231
4232 W code_1 = text("Cancel", atlas, atlas_bm);
4233 W code_2 = center_align(code_1, size_x(bm_4)/2);
4234 W code_3 = center_y(code_2, 60.0);
4235 W code_4 = button(size_x(code_3), size_y(code_3), c_dialog_button_1, c_dialog_button_2);
4236 W code_41 = highlight(code_4);
4237 W code_5 = layer(code_41, code_3);
4238 W code_6 = click_area(code_5, 0,0,size_x(code_5), size_y(code_5),0);
4239 cancel_button = code_6;
4240
4241 W arr_x[] = { code_6, but_6 };
4242 W arr_x2 = array_x(&arr_x[0], 2, 0);
4243
4244 std::vector<W> arr_y = { bm_4, arr_x2 };
4245 W arr_2 = array_y(arr_y /*&arr_y[0],2*/,0);
4246
4247 W rect = window_decoration2(size_x(arr_xx)+2*mx,size_y(arr_xx)+my2,"Select asset to use", atlas, atlas_bm,false);
4248 W lay = layer(rect,arr_2);
4249
4250 W arr_3 = mouse_move(lay, 0,0,size_x(arr_xx), 35);
4251
4252 return arr_3;
4253
4254}
4255
4256EXPORT GameApi::W GameApi::GuiApi::license_dialog(std::vector<std::string> filename, std::vector<std::string> &license_url, std::vector<std::string> &author_name, FtA atlas, BM atlas_bm, FtA atlas2, BM atlas_bm2,FtA atlas3, BM atlas_bm3, W &next_button, W &cancel_button, W &canvas2, W &canvas_area2, W &scroll_bar)
4257{
4258 int s = std::min(filename.size(),license_url.size());
4259 std::vector<W> vec;
4260 for(int i=0;i<s;i++)
4261 {
4262 W item = license_item(filename[i],license_url[i],author_name[i], atlas, atlas_bm,atlas3, atlas_bm3);
4263 vec.push_back(item);
4264 }
4265 W arr = array_y(vec /*&vec[0], vec.size()*/, 3);
4266 W cnvs = canvas(800,size_y(arr));
4267 W area = scroll_area2(cnvs, 800,400, 900);
4268 W cnv_item = canvas_item(cnvs, arr, 0,0);
4269 W scrollbar = scrollbar_y(15,400,size_y(arr));
4270 scroll_bar = scrollbar;
4271 canvas2 = cnvs;
4272 canvas_area2=area;
4273
4274 std::vector<W> xx;
4275 xx.push_back(area);
4276 xx.push_back(scrollbar);
4277 W arr_xx = array_x(&xx[0],2,2);
4278
4279 int my = 45;
4280 int my2 = 10;
4281 int mx = 10;
4282
4283 W marg = margin(arr_xx, mx,my,mx,my2);
4284
4285 W bm_4 = marg;
4286
4287 W but_1 = text("Next->", atlas3, atlas_bm3);
4288 W but_2 = center_align(but_1, size_x(bm_4)/2);
4289 W but_3 = center_y(but_2, 60.0);
4290 W but_4 = button(size_x(but_3), size_y(but_3), c_dialog_button_1, c_dialog_button_2);
4291
4292 //W insert = empty();
4293 W but_41 = highlight(but_4);
4294 W but_5 = layer(but_41, but_3);
4295 //W but_40 = tooltip(but_5,but_5,"Fill in license information first/all assets need to be licensed.",atlas,atlas_bm,2,0.0);
4296 //W but_400 = layer(but_5,but_40);
4297 W but_6 = click_area(but_5, 0,0,size_x(but_5), size_y(but_5),0);
4298 next_button = but_6;
4299
4300 W code_1 = text("Cancel", atlas3, atlas_bm3);
4301 W code_2 = center_align(code_1, size_x(bm_4)/2);
4302 W code_3 = center_y(code_2, 60.0);
4303 W code_4 = button(size_x(code_3), size_y(code_3), c_dialog_button_1, c_dialog_button_2);
4304 W code_41 = highlight(code_4);
4305 W code_5 = layer(code_41, code_3);
4306 W code_6 = click_area(code_5, 0,0,size_x(code_5), size_y(code_5),0);
4307 cancel_button = code_6;
4308
4309 W arr_x[] = { code_6, but_6 };
4310 W arr_x2 = array_x(&arr_x[0], 2, 0);
4311
4312 std::vector<W> arr_y = { bm_4, arr_x2 };
4313 W arr_2 = array_y(arr_y /*&arr_y[0],2*/,0);
4314
4315 W rect = window_decoration2(size_x(arr_xx)+2*mx,size_y(arr_xx)+my2,"Setup license files for assets", atlas2, atlas_bm2,false);
4316 W lay = layer(rect,arr_2);
4317
4318 W arr_3 = mouse_move(lay, 0,0,size_x(arr_xx), 35);
4319
4320 return arr_3;
4321}
4322
4323
4324int progress_lock=0;
4325
4326EXPORT GameApi::W GameApi::GuiApi::progress_dialog(int sx, int sy, FtA atlas, BM atlas_bm, std::vector<std::string> vec, int val, int max)
4327{
4328 std::vector<std::string> prog;
4329 std::vector<std::string> rest;
4330
4331 int s2 = vec.size();
4332 for(int i=0;i<s2;i++)
4333 {
4334 if (vec[i].size()>19) {
4335 std::string r = vec[i].substr(18);
4336 //std::cout << "'" << r << "'" << std::endl;
4337 if (r!=" loading assets" && r!=" collect") {
4338 prog.push_back(vec[i].substr(0,18));
4339 rest.push_back(vec[i].substr(18));
4340 }
4341 }
4342 }
4343
4344 int restcount = 0;
4345 while(rest.size()<3) { restcount++; rest.push_back("Caaaaaaaaaaaaaaaaaaaa"); }
4346
4347
4348
4349 //std::cout << "Progress:" << prog << " " << rest << std::endl;
4350
4351 int s3 = std::max(0,int(rest.size()));
4352 int start = std::max(s3-3,0);
4353
4354
4355 for(int ii=start;ii<s3;ii++)
4356 {
4357 // std::cout << ii << "::" << rest[ii] << std::endl;
4358 int pos = -1;
4359 int s = rest[ii].size();
4360 for(int i=0;i<s;i++)
4361 {
4362 if (rest[ii][i]=='.') pos=i;
4363 }
4364
4365
4366 int restsize = rest[ii].size()-pos;
4367 if (pos!=-1 && pos >25-restsize)
4368 {
4369 std::string start = rest[ii].substr(0,25-restsize);
4370 std::string rest2 = rest[ii].substr(pos);
4371 rest[ii] = start+rest2;
4372 }
4373 }
4374
4375 /*
4376 BB I3=ev.bool_bitmap_api.bb_empty(300,30);
4377 BB I4=ev.bool_bitmap_api.rectangle(I3,0,0,300*val/max,30);
4378 BM I5=ev.bool_bitmap_api.to_bitmap(I4,255,255,255,255,0,0,0,0);
4379 */
4380BB I1=ev.bool_bitmap_api.bb_empty(310,40);
4381BB I2=ev.bool_bitmap_api.rectangle(I1,0,0,310,2);
4382BB I3=ev.bool_bitmap_api.rectangle(I2,0,0,2,40);
4383BB I4=ev.bool_bitmap_api.rectangle(I3,0,38,310,2);
4384BB I5=ev.bool_bitmap_api.rectangle(I4,308,0,2,40);
4385BM I6=ev.bool_bitmap_api.to_bitmap(I5,255,255,255,255,0,0,0,0);
4386BB I7=ev.bool_bitmap_api.bb_empty(300,30);
4387//std::cout << "Progress: " << rest << " :: " << val << " " << max << std::endl;
4388 BB I8=ev.bool_bitmap_api.rectangle(I7,0,0,300*val/max,30);
4389BM I9=ev.bool_bitmap_api.to_bitmap(I8,255,255,255,255,0,0,0,0);
4390BM I10=ev.bitmap_api.blitbitmap(I6,I9,5,5);
4391
4392
4393
4394 BM bm = I10;
4395 //W txt_0 = text(prog, atlas, atlas_bm);
4396 W txt_0 = icon(bm);
4397 std::vector<W> arr;
4398 arr.push_back(txt_0);
4399 int ssy = 20;
4400 //for(int ii=start;ii<s3;ii++) {
4401 GameApi::W w = text("Loading assets.." /*rest[ii]*/, atlas, atlas_bm);
4402 w = margin(w,0,(ssy-size_y(w))/2,0,(ssy-size_y(w))/2);
4403 arr.push_back(w);
4404 //}
4405 //W arr[2] = { txt_0, txt_1 };
4406 W array_0 = array_y(arr /*&arr[0], arr.size()*/, 5);
4407 //W array_0b = array_y(&arr[0], arr.size()-restcount, 5);
4408
4409 W array_1 = margin(array_0, (sx-size_x(array_0))/2, (sy-size_y(array_0))/2, (sx-size_x(array_0))/2, (sy-size_y(array_0))/2);
4410
4411 //W rect = highlight(400,200);
4412
4413 //vec2.push_back(txt_1);
4414
4415 //W array_0 = array_y(&vec2[0], vec2.size(), 5);
4416 //W array_1 = margin(array_0, 5,5,5,5);
4417 W rect = button(sx,sy,c_dialog_1, c_dialog_1_2);
4418
4419 //BM bm = ev.bitmap_api.loadbitmap("progress_v1.ppm");
4420 //progress_lock = 1;
4421 //W pic = icon_shared_noscale(bm,0x7777);
4422 //progress_lock = 0;
4423 //set_size(pic,sx,sy);
4424 //W txt_3 = layer(rect, pic);
4425 W txt_4 = layer(rect, array_1);
4426
4427 return txt_4;
4428}
4430
4431
4432IMPORT void update_progress_dialog_cb_impl(volatile GameApi::W &w, int x,int y, GameApi::FtA f, GameApi::BM b, std::vector<std::string> v, int val, int max, int process)
4433{
4434 g_everyapi_gui->update_progress_dialog(w,x,y,f,b,v,val,max,process);
4435}
4436
4437extern float g_progress_bar_mult_builder;
4438void GameApi::GuiApi::update_progress_dialog(volatile W &w, int sx, int sy, FtA atlas, BM atlas_bm, std::vector<std::string> vec, int val, int max,int process)
4439{
4440 //std::cout << "PROGRESS:" << val << " " << max << std::endl;
4441 //if (progress_lock) return;
4442 static int g_id = -1;
4443 if (g_id!=-1) clear_block(g_id);
4444 g_id = add_block();
4445 int old = get_current_block();
4446 set_current_block(g_id);
4447
4448
4449 GameApi::W ww = progress_dialog(sx,sy,atlas,atlas_bm, vec, g_progress_bar_mult_builder*val, max);
4450 w = ww;
4451 set_current_block(old);
4452}
4453
4454EXPORT GameApi::W GameApi::GuiApi::canvas_item_gameapi_node(int sx, int sy, std::string label, std::vector<std::string> param_types, std::vector<std::string> param_tooltip, std::string return_type, FtA atlas, BM atlas_bm, std::vector<W *> connect_click, std::string uid, std::vector<W> &params, std::string symbol, std::string comment)
4455{
4456 std::vector<W> vec;
4457 int s = param_types.size();
4458 int max_width = 0;
4459 for(int i=0;i<s;i++)
4460 {
4461 std::string p = param_types[i];
4462 std::string tt = param_tooltip[i];
4463 W txt_0 = text(p, atlas, atlas_bm);
4464 W txt_1 = margin(txt_0, 5,5,5,5);
4465 W txt_11 = tooltip(txt_1, txt_1, tt, atlas, atlas_bm, 2, 0.0);
4466 int width = size_x(txt_1);
4467 if (max_width<width) max_width = width;
4468 W txt_2 = button(size_x(txt_1), size_y(txt_1), c_canvas_item,c_canvas_item2 /*0xff888888, 0xff666666*/);
4469 W txt_3 = layer(txt_2, txt_11);
4470 W txt_4 = click_area(txt_3, 0.0,0.0,size_x(txt_3), size_y(txt_3),0);
4471
4472 std::stringstream ii;
4473 ii << i;
4474 std::string param_uid = uid + " " + ii.str();
4475
4476 set_id(txt_4, param_uid);
4477 params.push_back(txt_4);
4478 vec.push_back(txt_4);
4479 }
4480
4481 W node_2 = text(label, atlas,atlas_bm);
4482 W node_2a = text(symbol, atlas,atlas_bm);
4483 //float wd = size_x(node_2) + size_x(node_2a) + 5;
4484 //if (max_width<wd) max_width = wd;
4485
4486 //W insert = text(comment,atlas,atlas_bm);
4487 W node_2b = tooltip(node_2a, node_2a, comment, atlas, atlas_bm,2,0.0);
4488 W node_2bb = layer(node_2a, node_2b);
4489 std::vector<W> arr = { node_2, node_2bb };
4490 W node_2c = array_x(&arr[0],arr.size(),5);
4491 W node_22 = margin(node_2c, 5,5,5,5);
4492
4493 W array = array_y(vec /*&vec[0], vec.size()*/, 5);
4494 int ssy = std::max(sy, size_y(array)+size_y(node_22)+5);
4495 int ssy0 = std::max(sy-size_y(node_22), size_y(array));
4496 int ssy2 = ssy0 - size_y(array);
4497
4498
4499 int rs = ret_type_count(return_type);
4500 // std::cout << "RET TYPE" << return_type << "=" << rs << std::endl;
4501 std::vector<W> vec_ret;
4502 int ret_sx=0;
4503 for(int j=0;j<rs;j++) {
4504 std::string ret_type = ret_type_index(return_type,j);
4505 W txt_0 = text(ret_type, atlas,atlas_bm);
4506 W txt_1 = margin(txt_0, 5,5,5,5);
4507
4508 int max_width2 = size_x(txt_1);
4509 W txt_11 = highlight(txt_1);
4510 W txt_111 = click_area(txt_11, 0.0, 0.0, size_x(txt_11), size_y(txt_11),0);
4511 set_id(txt_111, uid);
4512 set_index(txt_111,j);
4513 set_size2(txt_111,rs);
4514 *(connect_click[j]) = txt_111;
4515 //std::cout << "txt_111 id=" << j << " " << txt_111.id << std::endl;
4516 W txt_2 = button(size_x(txt_1), size_y(txt_1), c_canvas_item_text_button, c_canvas_item_text_button2 /*0xff330033, 0xff880088*/);
4517 W txt_3 = layer(txt_2, txt_111);
4518
4519 ret_sx = std::max(size_x(txt_3),ret_sx);
4520
4521 vec_ret.push_back(txt_3);
4522 }
4523 for(int j=0;j<rs;j++)
4524 {
4525 vec_ret[j] = margin(vec_ret[j], ret_sx-size_x(vec_ret[j]),0.0, 0.0, 0.0);
4526 }
4527 int max_width2 = ret_sx;
4528 W array_ret = array_y(vec_ret /*&vec_ret[0], vec_ret.size()*/, 5);
4529 int ret_sy = size_y(array_ret);
4530
4531 W array_1 = margin(array, 0, size_y(node_22) + ssy2/2+2, 0, ssy2/2-size_y(node_22)-2);
4532
4533
4534 ssy = std::max(ssy, size_y(array_ret)+size_y(node_22)+5);
4535 ssy0 = std::max(ssy0, size_y(array_ret));
4536 ssy2 = ssy0 - std::max(size_y(array), size_y(array_ret));
4537
4538
4539
4540 int ssx_0 = std::max(sx, max_width+4+20+4+max_width2);
4541 int ssx = std::max(ssx_0,size_x(node_22));
4542 W node_0 = button(ssx,ssy, c_canvas_item_node_0, c_canvas_item_node_0_2 /*0xffff8844, 0xff884422*/);
4543 W node_1 = button(ssx,size_y(node_22), c_canvas_item_node_1, c_canvas_item_node_1_2 /*0xff884422, 0xff442211*/);
4544 W node_12 = highlight(node_1);
4545
4546 int sy0 = std::max(sy, std::max(size_y(array),size_y(array_ret))+size_y(node_22)+5);
4547 //W txt_4 = margin(txt_3, ssx-size_x(txt_3), size_y(node_22)+((sy0-size_y(node_22))-size_y(txt_3))/2, 0,((sy0-size_y(node_22))-size_y(txt_3))/2-size_y(node_22));
4548 W txt_4 = margin(array_ret, ssx-ret_sx, size_y(node_22)+((sy0-size_y(node_22))-ret_sy)/2, 0, ((sy0-size_y(node_22))-ret_sy)/2-size_y(node_22));
4549
4550
4551
4552 W l_0 = layer(node_0, node_12);
4553 W l_1 = layer(l_0, node_22);
4554 W l_2 = layer(l_1, array_1);
4555 W l_3 = layer(l_2, txt_4);
4556 //W l_4 = bounding_box(l_3);
4557 return l_3;
4558}
4559/*
4560EXPORT GameApi::W GameApi::GuiApi::dynamic_text(std::string need_letters, std::string *dyn_text, void (*fptr)(void *, float mouse_x, float mouse_y, int button, int ch, int type, int mouse_wheel_y), void *user_ptr, GameApi::FtA atlas, GameApi::BM atlas_bm)
4561{
4562#ifndef EMSCRIPTEN
4563 return add_widget(e, new DynamicTextGuiWidget(e,ev,*this, need_letters, dyn_text, fptr, user_ptr, atlas, atlas_bm));
4564#else
4565 GameApi::W w;
4566 w.id = 0;
4567 return w;
4568#endif
4569}
4570*/
4572{
4573#ifndef EMSCRIPTEN
4574 std::vector<GuiWidget*> vec2;
4575 int s = vec.size();
4576 for(int i=0;i<s;i++)
4577 {
4578 GuiWidget *ww = find_widget(e,vec[i]);
4579 vec2.push_back(ww);
4580 }
4581 return add_widget(e, new OverlapGuiWidget(ev,vec2));
4582#else
4583 GameApi::W w;
4584 w.id = 0;
4585 return w;
4586#endif
4587}
4588
4589
4590EXPORT GameApi::W GameApi::GuiApi::search_panel(int sx, FtA atlas, BM atlas_bm, int x_gap, W *redraw_w)
4591{
4592#ifndef EMSCRIPTEN
4593 static std::string expr = "@";
4594 W editor_t = string_editor("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_@", g_searchstring, expr, atlas,atlas_bm,x_gap,1,redraw_w,false);
4595 W node_t0 = margin(editor_t, 5,5,5,5);
4596 W node_0 = size(node_t0,sx,size_y(node_t0));
4597 //W node_0 = button(sx, size_y(node_t0), c_list_item_title, c_list_item_title2);
4598 //W node_1 = layer(node_0, node_t0);
4599 W node_2 = highlight(node_0);
4600 W node_3 = editor_mouse_tweak(editor_t,node_2,node_2);
4601 return node_3;
4602#endif
4603}
4604
4606{
4607#ifndef EMSCRIPTEN
4608 GuiWidget *ww = find_widget(e,w);
4609 return add_widget(e, new HideNonSearchableGuiWidget(e,ev,ww,label,redraw_w));
4610#endif
4611}
4612EXPORT GameApi::W GameApi::GuiApi::hide_if_array_empty(W w, std::vector<W> items, W *redraw_w)
4613{
4614#ifndef EMSCRIPTEN
4615 GuiWidget *ww = find_widget(e,w);
4616 std::vector<GuiWidget*> items2;
4617 int s = items.size();
4618 for(int i=0;i<s;i++)
4619 {
4620 items2.push_back(find_widget(e,items[i]));
4621 }
4622 return add_widget(e,new HideWidgetIfArrayEmpty(e,ev,ww,items2,redraw_w));
4623#endif
4624}
4625
4626EXPORT GameApi::W GameApi::GuiApi::alt(std::vector<W> vec, int *choose)
4627{
4628#ifndef EMSCRIPTEN
4629 std::vector<GuiWidget*> vec2;
4630 int s = vec.size();
4631 for(int i=0;i<s;i++)
4632 {
4633 GuiWidget *ww = find_widget(e,vec[i]);
4634 vec2.push_back(ww);
4635 }
4636 return add_widget(e, new AltGuiWidget(ev,vec2,choose));
4637#else
4638 GameApi::W w;
4639 w.id = 0;
4640 return w;
4641#endif
4642
4643 }
4644
4645
4646EXPORT GameApi::W GameApi::GuiApi::dynamic_text(std::string need_letters, std::string *dyn_text, void (*fptr)(void*,float mouse_x, float mouse_y, int button, int ch, int type, int mouse_wheel_y), void *user_ptr, GameApi::FtA atlas, GameApi::BM atlas_bm, int x_gap)
4647{
4648#ifndef EMSCRIPTEN
4649 return add_widget(e, new DynamicTextGuiWidget(e,ev,*this, need_letters,dyn_text,fptr,user_ptr,atlas,atlas_bm,x_gap));
4650#else
4651 GameApi::W w;
4652 w.id = 0;
4653 return w;
4654#endif
4655}
4656
4657
4658EXPORT GameApi::W GameApi::GuiApi::text(std::string label, FtA atlas, BM atlas_bm, int x_gap)
4659{
4660#ifndef EMSCRIPTEN
4661 return add_widget(e, new TextGuiWidgetAtlas(ev, label, atlas, atlas_bm, sh, x_gap));
4662#else
4663 GameApi::W w;
4664 w.id = 0;
4665 return w;
4666#endif
4667
4668}
4669
4671{
4672 return add_widget(e, new IconGuiWidget(ev, bm,sh));
4673}
4675{
4676#ifndef EMSCRIPTEN
4677 return add_widget(e, new IconGuiWidgetSharedNoScale(e,ev, bm, sh, key));
4678#else
4679 W w;
4680 w.id = 0;
4681 return w;
4682#endif
4683
4684}
4686{
4687#ifndef EMSCRIPTEN
4688 return add_widget(e, new IconGuiWidgetShared(e,ev, bm, sh, key));
4689#else
4690 W w;
4691 w.id = 0;
4692 return w;
4693#endif
4694}
4695EXPORT GameApi::W GameApi::GuiApi::poly(P p, SH sh2, int sx, int sy, int screen_size_x, int screen_size_y)
4696{
4697 return add_widget(e, new PolyGuiWidget(ev, p, sh2, sh, sx,sy, screen_size_x, screen_size_y));
4698}
4699EXPORT GameApi::W GameApi::GuiApi::va(VA p, SH sh2, int sx, int sy, int screen_size_x, int screen_size_y)
4700{
4701 return add_widget(e, new VAGuiWidget(ev, p, sh2, sh, sx,sy, screen_size_x, screen_size_y));
4702}
4703
4704std::vector<GameApi::TF> g_tf_instances;
4705
4706EXPORT GameApi::W GameApi::GuiApi::ml(ML p, SH sh2, SH sh3, SH sh_2d, SH sh_arr, int sx, int sy, int screen_size_x, int screen_size_y)
4707{
4708 int s = g_tf_instances.size();
4709 for(int i=0;i<s;i++)
4710 {
4711 p = ev.mainloop_api.async_gltf(p,g_tf_instances[i]);
4712 }
4713 g_tf_instances.clear();
4714
4715 return add_widget(e, new MLGuiWidget(e, ev, p, sh2, sh3, sh_2d, sh_arr, sh, sx,sy, screen_size_x, screen_size_y));
4716}
4717EXPORT GameApi::W GameApi::GuiApi::shader_plane(SFO p, int sx, int sy, int screen_x, int screen_y)
4718{
4719 return add_widget(e, new ShaderPlaneGuiWidget(ev, p, sh, sx,sy,screen_x, screen_y));
4720}
4721
4722EXPORT GameApi::W GameApi::GuiApi::lines(LI p, SH sh2, int sx, int sy, int screen_size_x, int screen_size_y)
4723{
4724 return add_widget(e, new LinesGuiWidget(ev, p, sh2, sh, sx,sy, screen_size_x, screen_size_y));
4725}
4726EXPORT GameApi::W GameApi::GuiApi::pts(PTS p, SH sh2, int sx, int sy, int screen_size_x, int screen_size_y)
4727{
4728 return add_widget(e, new PTSGuiWidget(e,ev, p, sh2, sh, sx,sy, screen_size_x, screen_size_y));
4729}
4730
4731EXPORT GameApi::W GameApi::GuiApi::string_editor(std::string allowed_chars, std::string &target, std::string &expr, FtA atlas, BM atlas_bm, int x_gap, int non_editable_char_count, W *redraw_w, bool allow_expr)
4732{
4733#ifndef EMSCRIPTEN
4734 W e1 = add_widget(e, new EditorGuiWidgetAtlas<std::string>(e,ev, allowed_chars, target, atlas, atlas_bm, sh, x_gap, allow_expr, expr,non_editable_char_count,redraw_w));
4735 W w1 = margin(e1,8,4,8,4);
4736 W e2 = highlight(w1);
4737 return e2;
4738#endif
4739}
4740EXPORT GameApi::W GameApi::GuiApi::multiline_string_editor(std::string allowed_chars, std::string &target, FI font, int x_gap, int line_height)
4741{
4742 W e1 = add_widget(e, new MultilineEditor<std::string>(ev, allowed_chars, target, font, sh, x_gap, line_height));
4743 W w1 = margin(e1,8,4,8,4);
4744 W e2 = highlight(w1);
4745 return e2;
4746}
4747
4748EXPORT GameApi::W GameApi::GuiApi::float_editor(float &target, std::string &expr, FtA atlas, BM atlas_bm, int x_gap, int noneditnum)
4749{
4750#ifndef EMSCRIPTEN
4751 std::string allowed_chars = "0123456789.-+*/%@";
4752 static W ww = empty();
4753 W w = add_widget(e, new EditorGuiWidgetAtlas<float>(e,ev,allowed_chars, target, atlas, atlas_bm, sh, x_gap,true, expr,noneditnum ,&ww));
4754 W w1 = margin(w,8,4,8,4);
4755 W w2 = highlight(w1);
4756 return w2;
4757#endif
4758}
4759EXPORT GameApi::W GameApi::GuiApi::url_editor(std::string &target, FtA atlas, BM atlas_bm, int x_gap, std::string &expr, int noneditnum)
4760{
4761#ifdef EMSCRIPTEN
4762 std::string allowed_chars="";
4763#else
4764 std::string allowed_chars = "0123456789.-abcdefghijklmnopqrstuvwxyz\xE5\xE4\xF6 246ABCDEFGHIJKLMNOPQRSTUVWXYZ\xC5\xC4\xD6~!\"#€%&/()=?+\\*^.,-<>|§œ;:_$@";
4765#endif
4766
4767#ifndef EMSCRIPTEN
4768 static W ww = empty();
4769 W w = add_widget(e, new EditorGuiWidgetAtlas<std::string>(e,ev,allowed_chars, target, atlas, atlas_bm, sh, x_gap,true,expr,noneditnum,&ww));
4770 W w1 = margin(w,8,4,8,4);
4771 W w2 = highlight(w1);
4772 return w2;
4773#endif
4774}
4775
4776std::vector<std::string> parse_array(std::string s);
4777std::vector<std::string> parse_enum_type(std::string type)
4778{
4779 if (type.size()>2) {
4780 if (type[0]=='{' && type[type.size()-1]=='}')
4781 {
4782 std::string rest = type.substr(1,type.size()-2);
4783 return parse_array(rest);
4784 }
4785 }
4786 return std::vector<std::string>();
4787}
4788
4789std::map<int, int> enum_map;
4790IMPORT bool file_exists(std::string filename);
4791 //std::string g_enum_type;
4792
4793EXPORT GameApi::W GameApi::GuiApi::enum_editor(EveryApi &ev, W &click_widget, int &target, FtA atlas, BM atlas_bm, int x_gap, std::string type, std::string &expr, int noneditnum)
4794{
4795 //g_enum_type = type;
4796 std::vector<std::string> arr = parse_enum_type(type);
4797 if (target<0||target>=arr.size()) { GameApi::W w; w.id = -1; return w; }
4798
4799 //std::stringstream ss;
4800 //ss << target << " (" << arr[target] << ")";
4801
4802 // W w = text(ss.str(),atlas,atlas_bm,x_gap);
4803 //static std::string expr;
4804 W w = int_editor(target, expr, atlas, atlas_bm, x_gap,noneditnum);
4805 //W w2 = button(30,30,c_tooltip_button,c_tooltip_button2);
4806 std::string filename;
4807 if (file_exists("./arrow.ppm")) {
4808 filename="arrow.ppm";
4809 } else {
4810 filename="/usr/share/arrow.ppm";
4811 }
4812 BM bm = ev.bitmap_api.loadbitmap(filename);
4813 W w2 = icon(bm);
4814 W w3 = highlight(w2);
4815 W click = click_area(w3, 0,0,30,30, 0);
4816 enum_map[click.id]=w.id;
4817 click_widget = click;
4818 std::stringstream ss;
4819 ss << &target;
4820 set_id(click_widget,ss.str());
4821 W layer2 = click;
4822 std::vector<W> vec = { w, layer2 };
4823 W arr2 = array_x(&vec[0],vec.size(), 5);
4824 return arr2;
4825}
4826static bool enum_clicked=false;
4829IMPORT bool enum_editor_callback(GameApi::Env &env,GameApi::GuiApi &gui, GameApi::W click_widget, std::string type, int mouse_x, int mouse_y, GameApi::FtA atlas, GameApi::BM atlas_bm, int x_gap, std::vector<GameApi::W> &areas, int button, int type2)
4830{
4831 //g_enum_type=type;
4832 //std::cout << "enum: " << button << " " << type2 << std::endl;
4833 if (enum_clicked==true){
4834 //std::cout << "enum_clicked=true" << std::endl;
4835 if (button==0&&type2==1025) {
4836 //std::cout << "close popup" << std::endl;
4837 enum_clicked=false;
4838 enum_popup.id = 0;
4839 }
4840 return true;
4841 }
4842 GuiWidget *p = find_widget(env,click_widget);
4843 if (gui.chosen_item(click_widget) &&button==0 && type2==1025 && !enum_clicked && mouse_x>=p->get_pos().x && mouse_x<=p->get_pos().x+p->get_size().dx && mouse_y>=p->get_pos().y && mouse_y<=p->get_pos().y+p->get_size().dy)
4844 {
4845 //std::cout << "Chosen" << std::endl;
4846 Point2d pp; pp.x = 0.0; pp.y = 0.0;
4847 p->update(pp,0,-1,-1,-1);
4848 enum_clicked=true;
4849 std::vector<std::string> arr = parse_enum_type(type);
4850 int s = arr.size();
4851 for(int i=0;i<s;i++) {
4852 std::stringstream ss;
4853 ss << i << ":" << arr[i];
4854 arr[i]=ss.str();
4855 }
4856 areas=std::vector<GameApi::W>();
4857 GameApi::W w = gui.popup_menu(mouse_x, mouse_y, arr, atlas, atlas_bm,areas);
4858 enum_popup = w;
4859 enum_click = click_widget;
4860 return true;
4861 }
4862 return false;
4863}
4865{
4866 if (enum_clicked && enum_popup.id!=0) {
4867 gui.render(enum_popup);
4868 }
4869}
4870IMPORT void enum_editor_handle_event(GameApi::GuiApi &gui, std::vector<GameApi::W> vec, int button)
4871{
4872 int s = vec.size();
4873 for(int i=0;i<s;i++) {
4874 GameApi::W w = vec[i];
4875 if (w.id==0) continue;
4876 std::string val = gui.get_id(w);
4877 if (val!="") {
4878 /*
4879 std::stringstream ss(val);
4880 unsigned long ptr;
4881 char ch1,ch2;
4882 ss >> ch1 >> ch2 >> std::hex >> ptr;
4883 int *ptr2 = (int*)ptr;
4884 *ptr2 = i;*/
4885 }
4886 }
4887}
4888extern std::map<int,int> int_editor_map;
4890{
4891#ifndef EMSCRIPTEN
4893 std::string val = w->get_id();
4894 if (val!="") {
4895 std::stringstream ss(val);
4896 unsigned long ptr;
4897 char ch1,ch2;
4898 ss >> ch1 >> ch2 >> std::hex >> ptr;
4899 int *ptr2 = (int*)ptr;
4900 *ptr2 = value;
4902 editor.id = enum_map[enum_click.id];
4903 GameApi::W editor2;
4904 editor2.id = int_editor_map[editor.id];
4906 //std::vector<std::string> arr = parse_enum_type(g_enum_type);
4907 std::stringstream ss2;
4908 //if (value>=0 && value<arr.size()) {
4909 // ss2 << value << " " << arr[value];
4910 //} else {
4911 ss2 << value;
4912 //}
4913 ed->set_value(ss2.str());
4914 Point2d pp; pp.x = 0.0; pp.y = 0.0;
4915 ed->update(pp,-1,-1,-1,-1);
4916 //std::cout << "SetValue: " << val << "::" << value << std::endl;
4917 }
4918#endif
4919}
4920
4921std::map<int, int> int_editor_map;
4922
4923EXPORT GameApi::W GameApi::GuiApi::int_editor(int &target, std::string &expr, FtA atlas, BM atlas_bm, int x_gap, int noneditnum)
4924{
4925#ifndef EMSCRIPTEN
4926 std::string allowed_chars = "0123456789-&%";
4927 static W ww = empty();
4928 W w = add_widget(e, new EditorGuiWidgetAtlas<int>(e,ev, allowed_chars, target, atlas, atlas_bm, sh, x_gap,true,expr,noneditnum,&ww));
4929 W w1 = margin(w,8,4,8,4);
4930 W w2 = highlight(w1);
4931 int_editor_map[w2.id]=w.id;
4932 return w2;
4933#endif
4934}
4935
4936EXPORT GameApi::W GameApi::GuiApi::long_editor(long &target, FtA atlas, BM atlas_bm, int x_gap, int noneditnum, std::string &expr)
4937{
4938#ifndef EMSCRIPTEN
4939 std::string allowed_chars = "0123456789-";
4940 //static std::string expr;
4941 static W ww = empty();
4942 //GuiWidget *ww2 = find_widget(e,ww);
4943 W w = add_widget(e, new EditorGuiWidgetAtlas<long>(e,ev, allowed_chars, target, atlas, atlas_bm, sh, x_gap,false,expr,noneditnum,&ww));
4944 W w1 = margin(w,8,4,8,4);
4945 W w2 = highlight(w1);
4946 return w2;
4947#endif
4948}
4949
4950
4951EXPORT GameApi::W GameApi::GuiApi::color_editor(std::string &col, FtA atlas, BM atlas_bm, int x_gap, int noneditnum, std::string &expr)
4952{
4953 std::string allowed_chars = "0123456789abcdef";
4954 //static std::string expr;
4955 static W redraw_w = empty();
4956 W edit = string_editor(allowed_chars, col, expr, atlas, atlas_bm, x_gap,noneditnum,&redraw_w);
4957 //W w1 = margin(edit,8,4,8,4);
4958 //W edit2 = highlight(w1); // not needed since string editor already have these.
4959 return edit;
4960}
4961EXPORT GameApi::W GameApi::GuiApi::copy_paste_dialog(SH sh, W &close_button,FI font, FtA atlas, BM atlas_bm, std::string &edit)
4962{
4963#ifdef EMSCRIPTEN
4964 std::string allowed_chars= "";
4965#else
4966 std::string allowed_chars= "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!\"#€%&/()=?\\|<>,.-;:_^~*'åöäÅÖÄ+";
4967#endif
4968 W w = multiline_string_editor( allowed_chars, edit, font, 5, 30);
4969
4970 W bm_2 = margin(w, 10,10,10,10);
4971 W bm_3 = button(size_x(bm_2), size_y(bm_2), c_dialog_1, c_dialog_1_2);
4972 W bm_4 = layer(bm_3, bm_2);
4973
4974 W but_1 = text("Close", atlas, atlas_bm);
4975 W but_2 = center_align(but_1, size_x(bm_4));
4976 W but_3 = center_y(but_2, 60.0);
4977 W but_4 = button(size_x(but_3), size_y(but_3), c_dialog_button_1, c_dialog_button_2);
4978 W but_41 = highlight(but_4);
4979 W but_5 = layer(but_41, but_3);
4980 W but_6 = click_area(but_5, 0,0,size_x(but_5), size_y(but_5),0);
4981 close_button = but_6;
4982
4983 //W code_1 = text("CodeGen", atlas, atlas_bm);
4984 //W code_2 = center_align(code_1, size_x(bm_4));
4985 //W code_3 = center_y(code_2, 60.0);
4986 //W code_4 = button(size_x(code_3), size_y(code_3), c_dialog_button_1, c_dialog_button_2);
4987 //W code_41 = highlight(code_4);
4988 //W code_5 = layer(code_41, code_3);
4989 //W code_6 = click_area(code_5, 0,0,size_x(code_5), size_y(code_5),0);
4990 //codegen_button = code_6;
4991
4992
4993 std::vector<W> arr = { bm_4, but_6 };
4994 W arr_2 = array_y(arr /*&arr[0], 2*/, 0);
4995
4996 W arr_3 = mouse_move(arr_2, 0,0, size_x(arr_2), size_y(arr_2));
4997 return arr_3;
4998
4999}
5000
5001
5002EXPORT GameApi::W GameApi::GuiApi::directory_view(std::vector<std::string> dir_items, int &selection, std::vector<W> &clicks, FtA atlas, BM atlas_bm)
5003{
5004 int s = dir_items.size();
5005 std::vector<W> vec;
5006 for(int i=0;i<s;i++)
5007 {
5008 W txt = text(dir_items[i], atlas, atlas_bm);
5009 W txt2 = highlight(txt);
5010 W txt_click = click_area(txt2, 0,0,size_x(txt2),size_y(txt2),0);
5011 clicks.push_back(txt_click);
5012 vec.push_back(txt_click);
5013 }
5014 W arr = array_y(vec /*&vec[0], vec.size()*/, 8);
5015 return arr;
5016}
5017
5019{
5020 GameApi::W w; return w;
5021}
5022
5023
5024
5025EXPORT GameApi::W GameApi::GuiApi::download_bar(GameApi::EveryApi &ev, std::vector<std::string> titles, std::vector<W> &close_button, std::vector<W> &buttons, FtA atlas, BM atlas_bm, int active_tab, std::vector<float> progress)
5026{
5027
5028 if (titles.size()==0)
5029 {
5030 std::vector<W> vert;
5031 W arr_combine = array_y(vert /*&vert[0], vert.size()*/, 6);
5032 return arr_combine;
5033 }
5034 int s = titles.size();
5035 std::vector<W> horiz_bar;
5036 for(int i=0;i<s;i++)
5037 {
5038 W txt = text(titles[i], atlas, atlas_bm);
5039 W txt2 = margin(txt,10,10,10,10);
5040 W txt3 = highlight(txt2);
5041 W txt_click = click_area(txt3, 0,0,size_x(txt3),size_y(txt3),0);
5042 buttons.push_back(txt_click);
5043
5044 W close_button2 = text("x", atlas, atlas_bm);
5045 W close_button21 = margin(close_button2,2,2,2,25);
5046 W close_button3 = highlight(close_button21);
5047 W close_click = click_area(close_button3,0,0,size_x(close_button3),size_y(close_button3),0);
5048 close_button.push_back(close_click);
5049 std::vector<W> horiz_tab;
5050 horiz_tab.push_back(txt_click);
5051 horiz_tab.push_back(close_click);
5052 W arr_tab = array_x(&horiz_tab[0], horiz_tab.size(), 3);
5053
5054
5055 float percentage = 0.0;
5056 if (progress[i]>0.0)
5057 {
5058 percentage = progress[i];
5059 }
5060 W perc_button = button(size_x(arr_tab)*percentage,size_y(arr_tab),i==active_tab?0xff00ff00:0xff008800, i==active_tab?0xff00ff00:0xff008800);
5061 //W back_button = button(size_x(arr_tab),size_y(arr_tab),i==active_tab?c_dialog_button_1:c_canvas_item, i==active_tab?c_dialog_button_2:c_canvas_item2);
5062 W tab_button = button(size_x(arr_tab),size_y(arr_tab),i==active_tab?0xff004400:0xff002200, i==active_tab?0xff004400:0xff002200);
5063 W back_layer = layer(tab_button, perc_button);
5064 W tab_layer = layer(back_layer, arr_tab);
5065
5066 horiz_bar.push_back(tab_layer);
5067 }
5068
5069 W arr_top = array_x(&horiz_bar[0], horiz_bar.size(), 3);
5070 std::vector<W> vert;
5071 vert.push_back(arr_top);
5072
5073 W arr_combine = array_y(vert /*&vert[0], vert.size()*/, 6);
5074 W comb_but = button(ev.mainloop_api.get_screen_width(), size_y(arr_combine),0xff228822, 0xff081108);
5075 W comb_layer = layer(comb_but,arr_combine);
5076
5077
5078 W arr_top2 = margin(comb_layer, 0,ev.mainloop_api.get_screen_height()-size_y(comb_layer),0,0);
5079 return arr_top2;
5080}
5081
5082EXPORT GameApi::W GameApi::GuiApi::navi_bar(GameApi::EveryApi &ev, std::vector<std::string> titles, W &back_button, W &forward_button, W &save_button, std::string &url, W &url_button, std::vector<W> &close_button, std::vector<W> &tab_change_button, W &new_tab_button, std::vector<std::string> bookmark_labels, std::vector<std::string> bookmark_urls, FtA atlas, BM atlas_bm, int &active_tab)
5083{
5084 // tabs and close buttons
5085 int s = titles.size();
5086 std::vector<W> horiz_bar;
5087 for(int i=0;i<s;i++)
5088 {
5089 W txt = text(titles[i], atlas, atlas_bm);
5090 W txt2 = margin(txt,10,10,10,10);
5091 W txt3 = highlight(txt2);
5092 W txt_click = click_area(txt3, 0,0,size_x(txt3),size_y(txt3),0);
5093 tab_change_button.push_back(txt_click);
5094 W close_button2 = text("x", atlas, atlas_bm);
5095 W close_button21 = margin(close_button2,2,2,2,25);
5096 W close_button3 = highlight(close_button21);
5097 W close_click = click_area(close_button3,0,0,size_x(close_button3),size_y(close_button3),0);
5098 close_button.push_back(close_click);
5099 std::vector<W> horiz_tab;
5100 horiz_tab.push_back(txt_click);
5101 horiz_tab.push_back(close_click);
5102 W arr_tab = array_x(&horiz_tab[0], horiz_tab.size(), 3);
5103 W tab_button = button(size_x(arr_tab),size_y(arr_tab),i==active_tab?c_dialog_button_1:c_canvas_item, i==active_tab?c_dialog_button_2:c_canvas_item2);
5104 W tab_layer = layer(tab_button, arr_tab);
5105 horiz_bar.push_back(tab_layer);
5106 }
5107 W new_tab_button2 = text("+", atlas, atlas_bm);
5108 W new_tab_button3 = margin(new_tab_button2,10,10,10,10);
5109 W new_tab_button4 = highlight(new_tab_button3);
5110 W new_tab_click = click_area(new_tab_button4, 0,0,size_x(new_tab_button4), size_y(new_tab_button4),0);
5111 new_tab_button = new_tab_click;
5112 horiz_bar.push_back(new_tab_click);
5113
5114 W arr_top = array_x(&horiz_bar[0], horiz_bar.size(), 3);
5115
5116 //return arr_top;
5117
5118#if 0
5119 // back, forward, refresh, url_bar
5120 std::vector<W> horiz_bar2;
5121 W back_button2 = text("<-", atlas, atlas_bm);
5122 W back_button3 = margin(back_button2,10,15,10,15);
5123 W back_button31 = highlight(back_button3);
5124 W back_button4 = button(size_x(back_button31),size_y(back_button31),c_dialog_button_1, c_dialog_button_2 /*c_canvas_item, c_canvas_item2*/);
5125 W back_layer = layer(back_button4, back_button31);
5126
5127 W back_click = click_area(back_layer, 0,0, size_x(back_layer), size_y(back_layer),0);
5128 back_button = back_click;
5129 W forward_button2 = text("->", atlas, atlas_bm);
5130 W forward_button3 = margin(forward_button2,10,15,10,15);
5131 W forward_button31 = highlight(forward_button3);
5132 W forward_button4 = button(size_x(forward_button31),size_y(forward_button31),c_dialog_button_1,c_dialog_button_2 /*c_canvas_item, c_canvas_item2*/);
5133 W forward_layer = layer(forward_button4, forward_button31);
5134
5135
5136 W forward_click = click_area(forward_layer, 0,0,size_x(forward_layer), size_y(forward_layer), 0);
5137 forward_button = forward_click;
5138
5139 W save_button2 = text("[]", atlas, atlas_bm);
5140 W save_button3 = margin(save_button2,10,10,10,10);
5141 W save_button31 = highlight(save_button3);
5142 W save_button4 = button(size_x(save_button31),size_y(save_button31),c_dialog_button_1,c_dialog_button_2 /*c_canvas_item, c_canvas_item2*/);
5143 W save_layer = layer(save_button4, save_button31);
5144
5145 W save_click = click_area(save_layer, 0,0,size_x(save_layer),size_y(save_layer),0);
5146
5147 static std::string expr;
5148 W url_bar = url_editor(url, atlas, atlas_bm, 3,expr);
5149 W url_bar2 = center_y(url_bar, 20+5+20-2-2-1);
5150 W url_bar21 = size(url_bar2, 630,20+5+20-2-2-1);
5151 W url_bar3 = margin(url_bar21,30,0,0,0);
5152 W url_bar31 = highlight(url_bar3);
5153 W url_bar4 = button(size_x(url_bar31),size_y(url_bar31),c_dialog_button_1,c_dialog_button_2 /*c_canvas_item, c_canvas_item2*/);
5154 W url_bar_layer = layer(url_bar4, url_bar31);
5155
5156
5157 horiz_bar2.push_back(back_click);
5158 horiz_bar2.push_back(forward_click);
5159 horiz_bar2.push_back(save_click);
5160 horiz_bar2.push_back(url_bar_layer);
5161 W arr_middle = array_x(&horiz_bar2[0], horiz_bar2.size(), 6);
5162#endif
5163 // bookmarks
5164 std::vector<W> vert;
5165 vert.push_back(arr_top);
5166 //vert.push_back(arr_middle);
5167 // vert.push_back(arr_bottom);
5168 W arr_combine = array_y(vert /*&vert[0], vert.size()*/, 6);
5169 W comb_but = button(ev.mainloop_api.get_screen_width(), size_y(arr_combine),0xff228822, 0xff081108);
5170 W comb_layer = layer(comb_but,arr_combine);
5171 return comb_layer;
5172
5173}
5174
5175EXPORT GameApi::W GameApi::GuiApi::polygon_dialog(P p, SH sh, int screen_size_x, int screen_size_y, W &close_button, FtA atlas, BM atlas_bm, W &codegen_button, W &collect_button, W &mem)
5176{
5177 int w = 800;
5178 int h = 600;
5179 /*
5180 if (g_event_screen_y!=-1) {
5181 float scale_x = float(g_event_screen_x)/float(screen_size_x);
5182 float scale_y = float(g_event_screen_y)/float(screen_size_y);
5183 w*=scale_x;
5184 h*=scale_y;
5185 }*/
5186 W bm_1 = poly(p, sh, w,h, screen_size_x,screen_size_y);
5187 mem = bm_1;
5188 W bm_2 = margin(bm_1, 10,10,10,10);
5189 W bm_3 = button(size_x(bm_2), size_y(bm_2), c_dialog_1, c_dialog_1_2);
5190 W bm_4 = layer(bm_3, bm_2);
5191
5192 W but_1 = text("Close", atlas, atlas_bm);
5193 W but_2 = center_align(but_1, size_x(bm_4)/3);
5194 W but_3 = center_y(but_2, 60.0);
5195 W but_4 = button(size_x(but_3), size_y(but_3), c_dialog_button_1, c_dialog_button_2);
5196 W but_41 = highlight(but_4);
5197 W but_5 = layer(but_41, but_3);
5198 W but_6 = click_area(but_5, 0,0,size_x(but_5), size_y(but_5),0);
5199 close_button = but_6;
5200
5201 W code_1 = text("CodeGen", atlas, atlas_bm);
5202 W code_2 = center_align(code_1, size_x(bm_4)/3);
5203 W code_3 = center_y(code_2, 60.0);
5204 W code_4 = button(size_x(code_3), size_y(code_3), c_dialog_button_1, c_dialog_button_2);
5205 W code_41 = highlight(code_4);
5206 W code_5 = layer(code_41, code_3);
5207 W code_6 = click_area(code_5, 0,0,size_x(code_5), size_y(code_5),0);
5208 codegen_button = code_6;
5209
5210 W coll_1 = text("Edit", atlas, atlas_bm);
5211 W coll_2 = center_align(coll_1, size_x(bm_4)/3);
5212 W coll_3 = center_y(coll_2, 60.0);
5213 W coll_4 = button(size_x(coll_3), size_y(coll_3), c_dialog_button_1, c_dialog_button_2);
5214 W coll_41 = highlight(coll_4);
5215 W coll_5 = layer(coll_41, coll_3);
5216 W coll_6 = click_area(coll_5, 0,0,size_x(coll_5), size_y(coll_5),0);
5217 collect_button = coll_6;
5218
5219
5220 W arr_x[] = { code_6, coll_6, but_6 };
5221 W arr_x2 = array_x(&arr_x[0], 3, 0);
5222
5223 //W popup = popup_box("Popup", { "Test1", "Test2", "Test3" }, atlas, atlas_bm);
5224
5225 std::vector<W> arr = { bm_4, arr_x2 };
5226 W arr_2 = array_y(arr /*&arr[0], 2*/, 0);
5227
5228 W arr_3 = mouse_move(arr_2, 0,0, size_x(arr_2), size_y(arr_2));
5229 return arr_3;
5230}
5231
5232EXPORT GameApi::W GameApi::GuiApi::va_dialog(VA p, SH sh, int screen_size_x, int screen_size_y, W &close_button, FtA atlas, BM atlas_bm, W &codegen_button, W &collect_button)
5233{
5234 int w = 800;
5235 int h = 600;
5236 /*
5237 if (g_event_screen_y!=-1) {
5238 float scale_x = float(g_event_screen_x)/float(screen_size_x);
5239 float scale_y = float(g_event_screen_y)/float(screen_size_y);
5240 w*=scale_x;
5241 h*=scale_y;
5242 }
5243 */
5244 W bm_1 = va(p, sh, w,h, screen_size_x,screen_size_y);
5245 W bm_2 = margin(bm_1, 10,10,10,10);
5246 W bm_3 = button(size_x(bm_2), size_y(bm_2), c_dialog_1, c_dialog_1_2);
5247 W bm_4 = layer(bm_3, bm_2);
5248
5249 W but_1 = text("Close", atlas, atlas_bm);
5250 W but_2 = center_align(but_1, size_x(bm_4));
5251 W but_3 = center_y(but_2, 60.0);
5252 W but_4 = button(size_x(but_3), size_y(but_3), c_dialog_button_1, c_dialog_button_2);
5253 W but_41 = highlight(but_4);
5254 W but_5 = layer(but_41, but_3);
5255 W but_6 = click_area(but_5, 0,0,size_x(but_5), size_y(but_5),0);
5256 close_button = but_6;
5257
5258 W code_1 = text("CodeGen", atlas, atlas_bm);
5259 W code_2 = center_align(code_1, size_x(bm_4));
5260 W code_3 = center_y(code_2, 60.0);
5261 W code_4 = button(size_x(code_3), size_y(code_3), c_dialog_button_1, c_dialog_button_2);
5262 W code_41 = highlight(code_4);
5263 W code_5 = layer(code_41, code_3);
5264 W code_6 = click_area(code_5, 0,0,size_x(code_5), size_y(code_5),0);
5265 codegen_button = code_6;
5266
5267
5268 std::vector<W> arr = { bm_4, code_6, but_6 };
5269 W arr_2 = array_y(arr /*&arr[0], 3*/, 0);
5270
5271 W arr_3 = mouse_move(arr_2, 0,0, size_x(arr_2), size_y(arr_2));
5272 return arr_3;
5273}
5274
5275EXPORT GameApi::W GameApi::GuiApi::ml_dialog(ML p, SH sh, SH sh2, SH sh_2d, SH sh_arr, int screen_size_x, int screen_size_y, W &close_button, FtA atlas, BM atlas_bm, W &codegen_button, W &collect_button)
5276{
5277 int w = 800;
5278 int h = 600;
5279 /*
5280 if (g_event_screen_y!=-1) {
5281 float scale_x = float(g_event_screen_x)/float(screen_size_x);
5282 float scale_y = float(g_event_screen_y)/float(screen_size_y);
5283 w*=scale_x;
5284 h*=scale_y;
5285 }
5286 */
5287
5288 W bm_1 = ml(p, sh, sh2, sh_2d, sh_arr, w,h, screen_size_x,screen_size_y);
5289 W bm_2 = margin(bm_1, 10,10,10,10);
5290 W bm_3 = button(size_x(bm_2), size_y(bm_2), c_dialog_1, c_dialog_1_2);
5291 W bm_4 = layer(bm_3, bm_2);
5292
5293 W but_1 = text("Close", atlas, atlas_bm);
5294 W but_2 = center_align(but_1, size_x(bm_4));
5295 W but_3 = center_y(but_2, 60.0);
5296 W but_4 = button(size_x(but_3), size_y(but_3), c_dialog_button_1, c_dialog_button_2);
5297 W but_41 = highlight(but_4);
5298 W but_5 = layer(but_41, but_3);
5299 W but_6 = click_area(but_5, 0,0,size_x(but_5), size_y(but_5),0);
5300 close_button = but_6;
5301
5302 W code_1 = text("CodeGen", atlas, atlas_bm);
5303 W code_2 = center_align(code_1, size_x(bm_4));
5304 W code_3 = center_y(code_2, 60.0);
5305 W code_4 = button(size_x(code_3), size_y(code_3), c_dialog_button_1, c_dialog_button_2);
5306 W code_41 = highlight(code_4);
5307 W code_5 = layer(code_41, code_3);
5308 W code_6 = click_area(code_5, 0,0,size_x(code_5), size_y(code_5),0);
5309 codegen_button = code_6;
5310
5311
5312 std::vector<W> arr = { bm_4, code_6, but_6 };
5313 W arr_2 = array_y(arr /*&arr[0], 3*/, 0);
5314
5315 W arr_3 = mouse_move(arr_2, 0,0, size_x(arr_2), size_y(arr_2));
5316 return arr_3;
5317}
5318
5319
5320
5321
5322EXPORT GameApi::W GameApi::GuiApi::shader_dialog(SFO p, W &close_button, FtA atlas, BM atlas_bm, int screen_x, int screen_y, W &codegen_button, W &collect_button)
5323{
5324 int w = 800;
5325 int h = 600;
5326 /*
5327 if (g_event_screen_y!=-1) {
5328 float scale_x = float(g_event_screen_x)/float(screen_x);
5329 float scale_y = float(g_event_screen_y)/float(screen_y);
5330 w*=scale_x;
5331 h*=scale_y;
5332 }
5333 */
5334
5335 W bm_1 = shader_plane(p, w,h*h/w, screen_x, screen_y);
5336 W bm_2 = margin(bm_1, 10,10,10,10);
5337 W bm_3 = button(size_x(bm_2), size_y(bm_2), c_dialog_1, c_dialog_1_2);
5338 W bm_4 = layer(bm_3, bm_2);
5339
5340 W but_1 = text("Close", atlas, atlas_bm);
5341 W but_2 = center_align(but_1, size_x(bm_4));
5342 W but_3 = center_y(but_2, 60.0);
5343 W but_4 = button(size_x(but_3), size_y(but_3), c_dialog_button_1, c_dialog_button_2);
5344 W but_41 = highlight(but_4);
5345 W but_5 = layer(but_41, but_3);
5346 W but_6 = click_area(but_5, 0,0,size_x(but_5), size_y(but_5),0);
5347 close_button = but_6;
5348
5349 W code_1 = text("CodeGen", atlas, atlas_bm);
5350 W code_2 = center_align(code_1, size_x(bm_4));
5351 W code_3 = center_y(code_2, 60.0);
5352 W code_4 = button(size_x(code_3), size_y(code_3), c_dialog_button_1, c_dialog_button_2);
5353 W code_41 = highlight(code_4);
5354 W code_5 = layer(code_41, code_3);
5355 W code_6 = click_area(code_5, 0,0,size_x(code_5), size_y(code_5),0);
5356 codegen_button = code_6;
5357
5358
5359 std::vector<W> arr = { bm_4, code_6, but_6 };
5360 W arr_2 = array_y(arr /*&arr[0], 3*/, 0);
5361
5362 W arr_3 = mouse_move(arr_2, 0,0, size_x(arr_2), size_y(arr_2));
5363 return arr_3;
5364}
5365
5366EXPORT GameApi::W GameApi::GuiApi::window_decoration(int sx, int sy, std::string label, FtA atlas, BM atlas_bm)
5367{
5368 return window_decoration2(sx,sy,label,atlas,atlas_bm,true);
5369}
5370
5371EXPORT GameApi::W GameApi::GuiApi::window_decoration2(int sx, int sy, std::string label, FtA atlas, BM atlas_bm, bool move)
5372{ // wayland only
5373 int w = sx;
5374 int h = sy;
5375 W contents = rectangle(0,w,0,h,0xff000000);
5376
5377 W txt = text(label, atlas, atlas_bm,3);
5378 W txt_1 = margin(txt, 5,7,5,5);
5379 W but_1 = button(w+10,35, 0xff888888, 0xff222222);
5380 W but_2 = margin(but_1,0,0,0,0);
5381 W but_3 = move?window_move(but_2,0,0,w+10,30):but_2;
5382 W lay_2 = layer(but_3,txt_1);
5383
5384 W mrg = margin(contents, 5,5+30,5,5);
5385 W lay_1 = layer(mrg,lay_2);
5386
5387
5388 W left = button(5,h+5,0xff888888,0xff222222);
5389 W right = button(5,h+5,0xff888888,0xff222222);
5390 W l_margin = margin(left,0,30,0,0);
5391 W r_margin = margin(right,w-4,30,0,0);
5392
5393 W bottom = button(w+10, 5, 0xff888888,0xff222222);
5394 W b_margin = margin(bottom, 0, h+5+30, 0,0);
5395
5396 W lay_3 = layer(l_margin, r_margin);
5397 W lay_4 = layer(lay_3,b_margin);
5398 W lay_6 = layer(lay_4,lay_1);
5399
5400 return lay_6;
5401
5402}
5403
5404EXPORT GameApi::W GameApi::GuiApi::lines_dialog(LI p, SH sh, int screen_size_x, int screen_size_y, W &close_button, FtA atlas, BM atlas_bm, W &codegen_button, W& collect_button)
5405{
5406 int w = 800;
5407 int h = 600;
5408 /*
5409 if (g_event_screen_y!=-1) {
5410 float scale_x = float(g_event_screen_x)/float(screen_size_x);
5411 float scale_y = float(g_event_screen_y)/float(screen_size_y);
5412 w*=scale_x;
5413 h*=scale_y;
5414 }
5415 */
5416 W bm_1 = lines(p, sh, w,h, screen_size_x,screen_size_y);
5417 W bm_2 = margin(bm_1, 10,10,10,10);
5418 W bm_3 = button(size_x(bm_2), size_y(bm_2), c_dialog_1, c_dialog_1_2);
5419 W bm_4 = layer(bm_3, bm_2);
5420
5421 W but_1 = text("Close", atlas, atlas_bm);
5422 W but_2 = center_align(but_1, size_x(bm_4));
5423 W but_3 = center_y(but_2, 60.0);
5424 W but_4 = button(size_x(but_3), size_y(but_3), c_dialog_button_1, c_dialog_button_2);
5425 W but_41 = highlight(but_4);
5426 W but_5 = layer(but_41, but_3);
5427 W but_6 = click_area(but_5, 0,0,size_x(but_5), size_y(but_5),0);
5428 close_button = but_6;
5429
5430 W code_1 = text("CodeGen", atlas, atlas_bm);
5431 W code_2 = center_align(code_1, size_x(bm_4));
5432 W code_3 = center_y(code_2, 60.0);
5433 W code_4 = button(size_x(code_3), size_y(code_3), c_dialog_button_1, c_dialog_button_2);
5434 W code_41 = highlight(code_4);
5435 W code_5 = layer(code_41, code_3);
5436 W code_6 = click_area(code_5, 0,0,size_x(code_5), size_y(code_5),0);
5437 codegen_button = code_6;
5438
5439
5440 std::vector<W> arr = { bm_4, code_6, but_6 };
5441 W arr_2 = array_y(arr /*&arr[0], 3*/, 0);
5442
5443 W arr_3 = mouse_move(arr_2, 0,0, size_x(arr_2), size_y(arr_2));
5444 return arr_3;
5445}
5446
5447EXPORT GameApi::W GameApi::GuiApi::pts_dialog(PTS p, SH sh, int screen_size_x, int screen_size_y, W &close_button, FtA atlas, BM atlas_bm, W &codegen_button, W &collect_button)
5448{
5449 int w = 800;
5450 int h = 600;
5451 /*
5452 if (g_event_screen_y!=-1) {
5453 float scale_x = float(g_event_screen_x)/float(screen_size_x);
5454 float scale_y = float(g_event_screen_y)/float(screen_size_y);
5455 w*=scale_x;
5456 h*=scale_y;
5457 }
5458 */
5459 W bm_1 = pts(p, sh, w,h, screen_size_x,screen_size_y);
5460 W bm_2 = margin(bm_1, 10,10,10,10);
5461 W bm_3 = button(size_x(bm_2), size_y(bm_2), c_dialog_1, c_dialog_1_2);
5462 W bm_4 = layer(bm_3, bm_2);
5463
5464 W but_1 = text("Close", atlas, atlas_bm);
5465 W but_2 = center_align(but_1, size_x(bm_4));
5466 W but_3 = center_y(but_2, 60.0);
5467 W but_4 = button(size_x(but_3), size_y(but_3), c_dialog_button_1, c_dialog_button_2);
5468 W but_41 = highlight(but_4);
5469 W but_5 = layer(but_41, but_3);
5470 W but_6 = click_area(but_5, 0,0,size_x(but_5), size_y(but_5),0);
5471 close_button = but_6;
5472
5473 W code_1 = text("CodeGen", atlas, atlas_bm);
5474 W code_2 = center_align(code_1, size_x(bm_4));
5475 W code_3 = center_y(code_2, 60.0);
5476 W code_4 = button(size_x(code_3), size_y(code_3), c_dialog_button_1, c_dialog_button_2);
5477 W code_41 = highlight(code_4);
5478 W code_5 = layer(code_41, code_3);
5479 W code_6 = click_area(code_5, 0,0,size_x(code_5), size_y(code_5),0);
5480 codegen_button = code_6;
5481
5482
5483 std::vector<W> arr = { bm_4, code_6, but_6 };
5484 W arr_2 = array_y(arr /*&arr[0], 3*/, 0);
5485
5486 W arr_3 = mouse_move(arr_2, 0,0, size_x(arr_2), size_y(arr_2));
5487 return arr_3;
5488}
5489
5490
5491
5492struct UserData
5493{
5494 GameApi::Env *e;
5495 GameApi::BM bm;
5496 GameApi::W bm_1;
5497 float sx;
5498 float sy;
5499 std::string s;
5500};
5501
5502void user_fptr(void *user_data, float mouse_x, float mouse_y, int button, int ch, int type, int mouse_wheel_y)
5503{
5504 UserData *dt = (UserData*)user_data;
5505
5506 GuiWidget *w = find_widget(*dt->e, dt->bm_1);
5507 Point2d pos = w->get_pos();
5508 float xx = mouse_x-pos.x;
5509 float yy = mouse_y-pos.y;
5510 xx/=dt->sx;
5511 yy/=dt->sy;
5512 BitmapHandle *handle = find_bitmap(*dt->e, dt->bm);
5513 ::Bitmap<Color> *b2 = find_color_bitmap(handle);
5514 int ssx = b2->SizeX();
5515 int ssy = b2->SizeY();
5516 xx*=ssx;
5517 yy*=ssy;
5518 std::stringstream ss;
5519 if (xx<0 ||xx>=ssx || yy<0 ||yy>=ssy)
5520 ss << " X:() Y:()";
5521 else
5522 ss << " X:" << int(xx) << " Y:" << int(yy);
5523 dt->s = ss.str();
5524}
5525
5526EXPORT GameApi::W GameApi::GuiApi::bitmap_dialog(BM bm, W &close_button, FtA atlas, BM atlas_bm, W &codegen_button, W&collect_button, FtA atlas_tiny, BM atlas_tiny_bm)
5527{
5528 OpenglLowApi *ogl = g_low->ogl;
5530 if (ev.bitmap_api.ready_to_prepare(bm))
5531 ev.bitmap_api.prepare(bm);
5532 float sx = float(ev.bitmap_api.size_x(bm));
5533 float sy = float(ev.bitmap_api.size_y(bm));
5534 if (sx>sy) {
5535 float change = 400.0/sx;
5536 sx *= change;
5537 sy *= change;
5538 } else {
5539 float change = 400.0/sy;
5540 sx *= change;
5541 sy *= change;
5542 }
5543
5544 CBM cbm = ev.cont_bitmap_api.from_bitmap(bm, 1.0,1.0);
5545 BM cbm_2 = ev.cont_bitmap_api.sample(cbm, int(sx),int(sy));
5546
5547 W bm_1 = icon(cbm_2);
5548 W bm_2 = margin(bm_1, 10,10,10,10);
5549 W bm_3 = button(size_x(bm_2), size_y(bm_2), c_dialog_1, c_dialog_1_2);
5550 W bm_4 = layer(bm_3, bm_2);
5551
5552 std::stringstream ss;
5553 ss << "SX:" << ev.bitmap_api.size_x(bm) << " SY:" << ev.bitmap_api.size_y(bm);
5554
5555 UserData *dt = new UserData;
5556 dt->e = &e;
5557 dt->bm = bm;
5558 dt->bm_1 = bm_1;
5559 dt->sx = sx;
5560 dt->sy = sy;
5561
5562
5563 W sztext = text(ss.str(), atlas_tiny, atlas_tiny_bm);
5564 W mousepoint = dynamic_text("0123456789/XY: ", &dt->s, user_fptr, (void*)dt, atlas_tiny, atlas_tiny_bm, 3);
5565 W arr5[] = { sztext, mousepoint};
5566 W arr_52 = array_x(&arr5[0], 2, 0);
5567
5568 W but_1 = text("Close", atlas, atlas_bm);
5569 W but_2 = center_align(but_1, size_x(bm_4));
5570 W but_3 = center_y(but_2, 60.0);
5571 W but_4 = button(size_x(but_3), size_y(but_3), c_dialog_button_1, c_dialog_button_2);
5572 W but_41 = highlight(but_4);
5573 W but_5 = layer(but_41, but_3);
5574 W but_6 = click_area(but_5, 0,0,size_x(but_5), size_y(but_5),0);
5575 close_button = but_6;
5576
5577 W code_1 = text("CodeGen", atlas, atlas_bm);
5578 W code_2 = center_align(code_1, size_x(bm_4));
5579 W code_3 = center_y(code_2, 60.0);
5580 W code_4 = button(size_x(code_3), size_y(code_3), c_dialog_button_1, c_dialog_button_2);
5581 W code_41 = highlight(code_4);
5582 W code_5 = layer(code_41, code_3);
5583 W code_6 = click_area(code_5, 0,0,size_x(code_5), size_y(code_5),0);
5584 codegen_button = code_6;
5585
5586 std::vector<W> arr = { bm_4, arr_52, code_6, but_6 };
5587 W arr_2 = array_y(arr /*&arr[0], 4*/, 0);
5588
5589 W arr_3 = mouse_move(arr_2, 0,0, size_x(arr_2), size_y(arr_2));
5590 return arr_3;
5591}
5592
5593EXPORT GameApi::W GameApi::GuiApi::edit_dialog(EveryApi &ev, const std::vector<std::string> &labels, const std::vector<GameApi::GuiApi::EditTypes*> &vec, FtA atlas, BM atlas_bm, const std::vector<std::string> &types, W &cancel_but, W &ok_but, FtA atlas_tiny, BM atlas_tiny_bm, std::vector<W> &vec3)
5594{
5595 assert(vec.size()==labels.size());
5596 assert(labels.size()==types.size());
5597 std::vector<W> vec2;
5598 std::vector<W> vec2_ed;
5599 std::vector<W> vec2_lab;
5600 int s = vec.size();
5601 //std::cout << "edit_dialog: " << s << std::endl;
5602 int size_x1 = 0;
5603 //std::vector<W> vec2;
5604 for(int j=0;j<s;j++)
5605 {
5606 std::string label = labels[j];
5607 W lab = text(label, atlas,atlas_bm, 8);
5608 int s = size_x(lab);
5609 if (size_x1 < s) size_x1 = s;
5610 GameApi::W w; w.id = 0;
5611 vec3.push_back(w);
5612 }
5613 int max_width=0;
5614 int max_width_lab=0;
5615 for(int i=0;i<s;i++)
5616 {
5617 EditTypes *target = vec[i];
5618 //std::cout << "edit_dialog" << i << " " << target << " " << target->i_value << std::endl;
5619 std::string type = types[i];
5620 std::string label = labels[i];
5621 W lab = text(label, atlas,atlas_bm, 8);
5622 W lab_2 = right_align(lab, size_x1);
5623 W edit = generic_editor(ev,*target, atlas, atlas_bm, type, 2, atlas_tiny, atlas_tiny_bm, size_y(lab),vec3[i]);
5624 max_width = std::max(max_width,size_x(lab)+size_x(edit));
5625 max_width_lab=std::max(max_width_lab,size_x(lab));
5626
5627 W array2[] = { lab_2, edit };
5628 W array3 = array_x(&array2[0], 2, 5);
5629 //max_width = std::max(max_width,size_x(array3));
5630 vec2.push_back(array3);
5631 vec2_ed.push_back(edit);
5632 vec2_lab.push_back(lab_2);
5633 }
5634 int extra_margin = 50;
5635 int button_width = std::max(max_width/2+30+extra_margin*2/2,350);
5636 bool is_empty = false;
5637 if (vec2.size()==0)
5638 {
5639 is_empty=true;
5640 W lab0 = text("", atlas, atlas_bm, 8);
5641 W lab = text("(No data)", atlas, atlas_bm, 8);
5642 W lab_2 = center_align(lab, button_width*2);
5643 vec2.push_back(lab0);
5644 vec2.push_back(lab_2);
5645 vec2.push_back(lab0);
5646 }
5647
5648 // This still breaks more than it fixes.
5649 W array = array_y(vec2 /*&vec2[0], vec2.size()*/, is_empty?35:35-30-15);
5650 for(int i=0;i<s;i++)
5651 {
5652 W array4 = margin(vec2[i],extra_margin+size_x1-size_x(vec2_lab[i]),15,max_width-size_x(vec2[i])-(size_x1-size_x(vec2_lab[i])-extra_margin)+extra_margin,15);
5653
5654 vec2[i] = editor_mouse_tweak(vec2_ed[i],array4,array);
5655 }
5656 W array_0 = array_y(vec2 /*&vec2[0],vec2.size()*/,is_empty?35:35-30-15);
5657 W array_1 = margin(array_0, 10,10,10,10);
5658 W array_1a = center_align(array_1, button_width*2);
5659 W array_2 = button(button_width*2, size_y(array_1), c_dialog_1, c_dialog_1_2 /*0xff884422, 0xff442211*/);
5660 W array_3 = layer(array_2, array_1a);
5661
5662
5663 W cancel_button = button(button_width,50, c_dialog_button_1, c_dialog_button_1 /*0xff884422, 0xff442211*/);
5664 W cancel_button_1 = text("Cancel", atlas,atlas_bm, 4);
5665 W cancel_button_11 = center_align(cancel_button_1, button_width);
5666 W cancel_button_111 = center_y(cancel_button_11, 50);
5667 W cancel_button_2 = layer(cancel_button, cancel_button_111);
5668 W cancel_button_3 = highlight(size_x(cancel_button_2), size_y(cancel_button_2));
5669 W cancel_button_4 = layer(cancel_button_2, cancel_button_3);
5670 W cancel_area = click_area(cancel_button_4, 0,0,button_width,50,0);
5671 cancel_but = cancel_area;
5672 W ok_button = button(button_width,50, c_dialog_button_1, c_dialog_button_1/*0xff884422, 0xff442211*/);
5673 W ok_button_1 = text("Ok", atlas,atlas_bm, 4);
5674 W ok_button_11 = center_align(ok_button_1, button_width);
5675 W ok_button_111 = center_y(ok_button_11, 50);
5676 W ok_button_2 = layer(ok_button, ok_button_111);
5677 W ok_button_3 = highlight(size_x(ok_button_2), size_y(ok_button_2));
5678 W ok_button_4 = layer(ok_button_2, ok_button_3);
5679 W ok_area = click_area(ok_button_4, 0,0,button_width,50,0);
5680 ok_but = ok_area;
5681 W button_array[] = { cancel_area, ok_area };
5682 W button_arr = array_x(&button_array[0], 2, 0);
5683 std::vector<W> combine_array = { array_3, button_arr };
5684 W combine_arr = array_y(combine_array /*&combine_array[0], 2*/, 0);
5685 W combine_move = mouse_move(combine_arr, 0,0,size_x(combine_arr), size_y(combine_arr));
5686 return combine_move;
5687}
5688
5689
5690class RightAlignWidget : public GuiWidgetForward
5691{
5692public:
5693 RightAlignWidget(GameApi::EveryApi &ev, GuiWidget *wid, int sx) : GuiWidgetForward(ev, { wid }), sx(sx) {
5694 Point2d p = { -666.0, -666.0 };
5695 update(p, -1, -1, -1,0);
5696
5697 }
5698 void set_pos(Point2d pos)
5699 {
5701 Vector2d size = vec[0]->get_size();
5702 Point2d p = { pos.x + sx - size.dx, pos.y };
5703 vec[0]->set_pos(p);
5704 }
5705 void update(Point2d mouse_pos, int button, int ch, int type, int mouse_wheel_y)
5706 {
5707 GuiWidgetForward::update(mouse_pos, button, ch, type, mouse_wheel_y);
5708 set_pos(get_pos());
5709 size.dx = sx;
5710 size.dy = vec[0]->get_size().dy;
5711 }
5712private:
5713 int sx;
5714};
5715class LeftAlignWidget : public GuiWidgetForward
5716{
5717public:
5718 LeftAlignWidget(GameApi::EveryApi &ev, GuiWidget *wid, int sx) : GuiWidgetForward(ev, { wid }), sx(sx) {
5719 Point2d p = { -666.0, -666.0 };
5720 update(p, -1, -1, -1,0);
5721
5722 }
5723 void set_pos(Point2d pos)
5724 {
5726 //Vector2d size = vec[0]->get_size();
5727 Point2d p = { pos.x, pos.y };
5728 vec[0]->set_pos(p);
5729 }
5730 void update(Point2d mouse_pos, int button, int ch, int type, int mouse_wheel_y)
5731 {
5732 GuiWidgetForward::update(mouse_pos, button, ch, type, mouse_wheel_y);
5733 set_pos(get_pos());
5734 size.dx = sx;
5735 size.dy = vec[0]->get_size().dy;
5736 }
5737private:
5738 int sx;
5739};
5740class CenterAlignWidget : public GuiWidgetForward
5741{
5742public:
5743 CenterAlignWidget(GameApi::EveryApi &ev, GuiWidget *wid, int sx) : GuiWidgetForward(ev, { wid }), sx(sx) {
5744 Point2d p = { -666.0, -666.0 };
5745 update(p, -1, -1, -1,0);
5746
5747 }
5748 void set_pos(Point2d pos)
5749 {
5751 Vector2d size = vec[0]->get_size();
5752 Point2d p = { pos.x + (sx - size.dx)/2, pos.y };
5753 vec[0]->set_pos(p);
5754 }
5755 void update(Point2d mouse_pos, int button, int ch, int type, int mouse_wheel_y)
5756 {
5757 GuiWidgetForward::update(mouse_pos, button, ch, type, mouse_wheel_y);
5758 set_pos(get_pos());
5759 size.dx = sx;
5760 size.dy = vec[0]->get_size().dy;
5761 }
5762private:
5763 int sx;
5764};
5765
5766class CenterYWidget : public GuiWidgetForward
5767{
5768public:
5769 CenterYWidget(GameApi::EveryApi &ev, GuiWidget *wid, int sy) : GuiWidgetForward(ev, { wid }), sy(sy) {
5770 Point2d p = { -666.0, -666.0 };
5771 update(p, -1, -1, -1,0);
5772
5773 }
5774 void set_pos(Point2d pos)
5775 {
5777 Vector2d size = vec[0]->get_size();
5778 Point2d p = { pos.x, pos.y + (sy-size.dy)/2};
5779 vec[0]->set_pos(p);
5780 }
5781 void update(Point2d mouse_pos, int button, int ch, int type, int mouse_wheel_y)
5782 {
5783 GuiWidgetForward::update(mouse_pos, button, ch, type, mouse_wheel_y);
5784 set_pos(get_pos());
5785 size.dx = vec[0]->get_size().dx;
5786 size.dy = sy;
5787 }
5788private:
5789 int sy;
5790};
5791
5792
5794{
5795 GuiWidget *wid = find_widget(e, item);
5796 return add_widget(e, new RightAlignWidget(ev, wid, sx));
5797}
5799{
5800 GuiWidget *wid = find_widget(e, item);
5801 return add_widget(e, new LeftAlignWidget(ev, wid, sx));
5802}
5804{
5805 GuiWidget *wid = find_widget(e, item);
5806 return add_widget(e, new CenterAlignWidget(ev, wid, sx));
5807}
5809{
5810 GuiWidget *wid = find_widget(e, item);
5811 return add_widget(e, new CenterYWidget(ev, wid, sy));
5812}
5813std::string FloatExprEval(std::string s);
5814
5815bool is_enum(std::string type)
5816{
5817 if (type.size()>2 && type[0]=='{' && type[type.size()-1]=='}')
5818 {
5819 return true;
5820 }
5821 return false;
5822}
5823
5824EXPORT void GameApi::GuiApi::string_to_generic(EditTypes &target, std::string type, const std::string &source, const std::string &expr)
5825{
5826 target.expr = expr;
5827
5828 //std::cout << "Source: " << source << std::endl;
5829
5830 //std::cout << "string_to_generic" << type << std::endl;
5831 if (type=="EveryApi&")
5832 {
5833 } else
5834 if (type=="long")
5835 {
5836 std::stringstream ss(source);
5837 if (ss >> target.l_value) {
5838 target.expr = "@" + expr;
5839 //std::cout << "Dest: " << target.i_value << std::endl;
5840 } else { std::cout << "StringStream failed" << std::endl; }
5841
5842 } else
5843 if (type=="int"||is_enum(type))
5844 {
5845 std::stringstream ss(source);
5846 target.expr = "@" + expr;
5847 if (ss >> target.i_value) {
5848 //std::cout << "Dest: " << target.i_value << std::endl;
5849 } else { std::cout << "StringStream failed" << std::endl; }
5850
5851 } else
5852 if (type=="unsigned int")
5853 {
5854 target.color = "@" + source;
5855 target.expr = "@" + expr;
5856 } else
5857 if (type=="std::string")
5858 {
5859 target.s = source;
5860 target.expr = "@" + expr;
5861 } else
5862 if (type=="float")
5863 {
5864 //std::string source2 = FloatExprEval(source);
5865 std::stringstream ss(source);
5866 ss >> target.f_value;
5867 target.expr = "@" + expr;
5868 } else
5869 if (type=="bool")
5870 {
5871 target.expr = "@" + expr;
5872 target.s = "@" + source;
5873 } else
5874 if (type=="PT")
5875 {
5876 std::stringstream ss(source);
5877 char c;
5878 ss >> c;
5879 ss >> target.f_x;
5880 ss >> c;
5881 ss >> target.f_y;
5882 ss >> c;
5883 ss >> target.f_z;
5884 ss >> c;
5885 } else
5886 {
5887 std::cout << "Unknown type at string_to_generic" << std::endl;
5888 }
5889}
5890EXPORT void GameApi::GuiApi::generic_to_string(const EditTypes &source, std::string type, std::string &target, std::string &expr)
5891{
5892 expr = source.expr;
5893
5894 //std::cout << "generic_to_string" << type << std::endl;
5895 if (type=="EveryApi&")
5896 {
5897 target="ev";
5898 } else
5899 if (type=="long")
5900 {
5901 long val = source.l_value;
5902 //std::cout << "Source2: " << val << std::endl;
5903 std::stringstream ss;
5904 ss << val;
5905 target = ss.str();
5906 if (source.expr.size()>0 && source.expr[0]=='@')
5907 expr = source.expr.substr(1,source.expr.size()-1);
5908 else
5909 expr = source.expr;
5910
5911 } else
5912 if (type=="int"||is_enum(type))
5913 {
5914 int val = source.i_value;
5915 //std::cout << "Source2: " << val << std::endl;
5916 std::stringstream ss;
5917 ss << val;
5918 target = ss.str();
5919 if (source.expr.size()>0 && source.expr[0]=='@')
5920 expr = source.expr.substr(1,source.expr.size()-1);
5921 else
5922 expr = source.expr;
5923 //std::cout << "Dest2: " << target << std::endl;
5924 } else
5925 if (type=="unsigned int")
5926 {
5927 std::string s = source.color.size()>0 && source.color[0]=='@' ? source.color.substr(1,source.color.size()-1) : source.color;
5928 target = s;
5929 if (source.expr.size()>0 && source.expr[0]=='@')
5930 expr = source.expr.substr(1,source.expr.size()-1);
5931 else
5932 expr = source.expr;
5933 } else
5934 if (type=="std::string")
5935 {
5936 std::string s = source.s;
5937 target = s;
5938 if (source.expr.size()>0 && source.expr[0]=='@')
5939 expr = source.expr.substr(1,source.expr.size()-1);
5940 else
5941 expr = source.expr;
5942 } else
5943 if (type=="bool")
5944 {
5945 std::string s = source.s;
5946 if (source.expr.size()>0 && source.expr[0]=='@')
5947 expr = source.expr.substr(1,source.expr.size()-1);
5948 else
5949 expr = source.expr;
5950 if (s.size()>0 && s[0]=='@')
5951 target = s.substr(1,s.size()-1);
5952 else
5953 target = s;
5954 } else
5955 if (type=="float")
5956 {
5957 float f = source.f_value;
5958 std::stringstream ss;
5959 ss << f;
5960 target = ss.str();
5961 if (source.expr.size()>0 && source.expr[0]=='@')
5962 expr = source.expr.substr(1,source.expr.size()-1);
5963 else
5964 expr = source.expr;
5965 } else
5966 if (type=="PT")
5967 {
5968 float x = source.f_x;
5969 float y = source.f_y;
5970 float z = source.f_z;
5971 std::stringstream ss;
5972 ss << "(" << x << "," << y << "," << z << ")";
5973 target = ss.str();
5974 } else
5975 {
5976 target = "";
5977 std::cout << "Unknown type at generic_to_string: " << type << std::endl;
5978 }
5979}
5980
5981EXPORT GameApi::W GameApi::GuiApi::generic_editor(EveryApi&ev,EditTypes &target, FtA atlas, BM atlas_bm, std::string type, int x_gap, FtA atlas_tiny, BM atlas_tiny_bm, int sy, W &click_target)
5982{
5983 //std::cout << "Generic editor: " << type << std::endl;
5984 if (type=="EveryApi&")
5985 {
5986 W edit = empty();
5987 return edit;
5988 }
5989 if (type=="long")
5990 {
5991 W edit = long_editor(target.l_value, atlas, atlas_bm, x_gap,1, target.expr);
5992 return edit;
5993 }
5994 if (is_enum(type))
5995 {
5996 //W click_target;
5997 W edit = enum_editor(ev,click_target, target.i_value, atlas, atlas_bm, x_gap, type,target.expr,1);
5998 return edit;
5999 }
6000 if (type=="int")
6001 {
6002 //std::cout << "Generic editor << " << target.i_value << std::endl;
6003 W edit = int_editor(target.i_value, target.expr, atlas, atlas_bm, x_gap,1);
6004 return edit;
6005 }
6006 if (type=="unsigned int")
6007 {
6008 W edit = color_editor(target.color, atlas, atlas_bm, x_gap,1,target.expr);
6009 return edit;
6010 }
6011 if (type=="std::string" || type=="bool")
6012 {
6013 if (target.s.size()>4 && (target.s.substr(0,4)=="http" ||target.s.substr(0,4)=="file"))
6014 {
6015 // used to be atlas_tiny => atlas
6016 W edit = url_editor(target.s, atlas_tiny, atlas_tiny_bm, x_gap,target.expr,1);
6017 W edit_2 = margin(edit, 0, sy-size_y(edit), 0, 0);
6018 return edit_2;
6019 }
6020 else
6021 {
6022 if (type=="bool") {
6023 std::string allowed = "0123456789abcdefghijklmnopqrstuvwxyz/.ABCDEFGHIJKLMNOPQRSTUVWXYZ*()-#+/*!\"€%&?\n,:_@";
6024 static W redraw_w = empty();
6025 W edit = string_editor(allowed, target.s, target.expr, atlas, atlas_bm, x_gap,1,&redraw_w);
6026 W edit_2 = margin(edit, 0, sy-size_y(edit), 0, 0);
6027 return edit_2;
6028
6029 } else {
6030 std::string allowed = "0123456789abcdefghijklmnopqrstuvwxyz\xE5\xE4\xF6/.ABCDEFGHIJKLMNOPQRSTUVWXYZ\xC5\xC4\xD6*()-#+/*!\"€%&?\n,:_@ |?;[]{}";
6031 static W redraw_w = empty();
6032 W edit = string_editor(allowed, target.s, target.expr, atlas_tiny, atlas_tiny_bm, x_gap,1,&redraw_w);
6033 W edit_2 = margin(edit, 0, sy-size_y(edit), 0, 0);
6034 return edit_2;
6035 }
6036 }
6037 }
6038 if (type=="float")
6039 {
6040 W edit = float_editor(target.f_value, target.expr, atlas, atlas_bm, x_gap,1);
6041 return edit;
6042 }
6043 if (type=="PT")
6044 {
6045 W edit = point_editor(target.f_x, target.f_y, target.f_z, atlas, atlas_bm, x_gap);
6046 return edit;
6047 }
6048 std::cout << "TYPE ERROR: " << type << std::endl;
6049 W dummy = button(30,30, 0xffffffff, c_dialog_1);
6050 return dummy;
6051}
6052
6053
6054EXPORT GameApi::W GameApi::GuiApi::point_editor(float &x, float &y, float &z, FtA atlas, BM atlas_bm, int x_gap)
6055{
6056 static std::string expr;
6057 W l0 = text("(",atlas, atlas_bm);
6058 W x_edit = float_editor(x, expr, atlas, atlas_bm, x_gap);
6059 W x_edit_2 = highlight(x_edit);
6060 W l1 = text(";",atlas, atlas_bm);
6061 W y_edit = float_editor(y, expr,atlas, atlas_bm, x_gap);
6062 W y_edit_2 = highlight(y_edit);
6063 W l2 = text(";",atlas,atlas_bm);
6064 W z_edit = float_editor(z, expr,atlas,atlas_bm, x_gap);
6065 W z_edit_2 = highlight(z_edit);
6066 W l3 = text(")",atlas,atlas_bm);
6067 W array[] = { l0, x_edit_2, l1, y_edit_2, l2, z_edit_2, l3 };
6068 return array_x(&array[0], 7, 2);
6069}
6070
6072{
6073 return add_widget(e, new HighlightGuiWidget(ev, sh, sx,sy));
6074}
6076{
6077 GuiWidget *w = find_widget(e, wid);
6078 return add_widget(e, new Highlight2GuiWidget(ev, w, sh));
6079}
6080EXPORT GameApi::W GameApi::GuiApi::layout(W w, int l, int t, int W, int H, int r, int b)
6081{
6082 GuiWidget *ww = find_widget(e, w);
6083 return add_widget(e, new LayoutGuiWidget(ev, ww, l, t, W,H,r, b));
6084}
6085EXPORT GameApi::W GameApi::GuiApi::layout_lt(W w, int l, int t, int W, int H, int r, int b, int (*fptr_l)(void *), int (*fptr_t)(void *), void *ctx, void *ctx2)
6086{
6087 GuiWidget *ww = find_widget(e, w);
6088 return add_widget(e, new LayoutGuiWidget(LayoutGuiWidget_lt(), ev, ww, l, t, W,H,r, b,fptr_l,fptr_t,ctx,ctx2));
6089}
6090EXPORT GameApi::W GameApi::GuiApi::layout_wh(W w, int l, int t, int W, int H, int r, int b, int (*fptr_W)(void *), int (*fptr_H)(void *), void *ctx, void *ctx2)
6091{
6092 GuiWidget *ww = find_widget(e, w);
6093 return add_widget(e, new LayoutGuiWidget(LayoutGuiWidget_WH(), ev, ww, l, t, W,H,r, b,fptr_W,fptr_H,ctx,ctx2));
6094}
6095EXPORT GameApi::W GameApi::GuiApi::layout_rb(W w, int l, int t, int W, int H, int r, int b, int (*fptr_r)(void *), int (*fptr_b)(void *), void *ctx, void *ctx2)
6096{
6097 GuiWidget *ww = find_widget(e, w);
6098 return add_widget(e, new LayoutGuiWidget(LayoutGuiWidget_rb(), ev, ww, l, t, W,H,r, b,fptr_r,fptr_b,ctx,ctx2));
6099}
6100
6101int fptr_empty(void *) { return 0; }
6102struct Empty2 { int W; };
6103int fptr_empty2(void *ctx) { Empty2 *e = (Empty2*)ctx; return e->W; }
6104EXPORT GameApi::W GameApi::GuiApi::layout_lh(W w, int l, int t, int W, int H, int r, int b, int (*fptr_l)(void*), int (*fptr_H)(void*), void *ctx, void *ctx2)
6105{
6106 Empty2 e;
6107 e.W = W;
6108 GameApi::W w0 = layout_lt(w,l,0,W,ELayoutEmpty,r,0,fptr_l, fptr_empty, ctx, 0);
6109 GameApi::W w1 = layout_wh(w0,0,t,ELayoutEmpty,H,0,b, fptr_empty2, fptr_H, (void*)&e,ctx2);
6110 return w1;
6111}
6112
6113EXPORT GameApi::W GameApi::GuiApi::margin(W w, int l, int t, int r, int b)
6114{
6115 GuiWidget *ww = find_widget(e, w);
6116 return add_widget(e, new MarginGuiWidget(ev, ww, l, t, r, b));
6117}
6119{
6120 GuiWidget *ww = find_widget(e, w);
6121 return add_widget(e, new SizeGuiWidget(ev, ww, sx,sy));
6122}
6124{
6125 GuiWidget *ww1 = find_widget(e, w1);
6126 GuiWidget *ww2 = find_widget(e, w2);
6127 return add_widget(e, new LayerGuiWidget(ev, ww1, ww2));
6128}
6130{
6131 int s = size;
6132 std::vector<GuiWidget*> vec;
6133 for(int i=0;i<s;i++)
6134 {
6135 vec.push_back(find_widget(e, arr[i]));
6136 }
6137 return add_widget(e, new ArrayXWidget(ev, vec, x_gap));
6138}
6139EXPORT GameApi::W GameApi::GuiApi::array_y(std::vector<W> arr, int y_gap, bool heavy)
6140{
6141 int s = arr.size();
6142 std::vector<GuiWidget*> vec;
6143 for(int i=0;i<s;i++)
6144 {
6145 vec.push_back(find_widget(e, arr[i]));
6146 }
6147 return add_widget(e, new ArrayYWidget(ev, vec, y_gap,heavy));
6148}
6149
6150EXPORT GameApi::W GameApi::GuiApi::main_menu(std::vector<std::string> labels, FtA atlas, BM atlas_bm)
6151{
6152 int s = labels.size();
6153 std::vector<W> vec;
6154 for(int i=0;i<s;i++)
6155 {
6156 std::string s = labels[i];
6157 W txt_1 = text(s, atlas, atlas_bm);
6158 W txt_2 = margin(txt_1, 5,5,5,5);
6159 W txt_3 = highlight(size_x(txt_2), size_y(txt_2));
6160 W txt_4 = layer(txt_2, txt_3);
6161 vec.push_back(txt_4);
6162 }
6163 W w = array_x(&vec[0], vec.size(), 20);
6164 //PT pt1 = ev.point_api.point(0.0,0.0,0.0);
6165 //PT pt2 = ev.point_api.point(0.0, size_y(w), 0.0);
6166 //W w3 = gradient(size_x(w), size_y(w), pt1, pt2, 0xffffaa88, 0xffff8844);
6167 W w3 = button(size_x(w), size_y(w), c_list_item_title, c_list_item_title2 /*0xffff8844, 0xff884422*/);
6168
6169 W w4 = layer(w3,w);
6170 W w5 = margin(w4, 2,2,2,2);
6171
6172 return w5;
6173}
6174
6175
6176class ScrollBarY : public GuiWidgetForward
6177{
6178public:
6179 ScrollBarY(GameApi::EveryApi &ev, GameApi::SH sh, int sx, int sy, int area_y) : GuiWidgetForward(ev, std::vector<GuiWidget*>()), sh(sh), sx(sx), sy(sy), area_y(area_y) { firsttime=true; current_pos = 0.0; following = false; old_area_y = area_y; changed=false; }
6180 float clamp(float val, float start, float end)
6181 {
6182 if (val<start) val=start;
6183 if (val>end) val=end;
6184 return val;
6185 }
6186 void update(Point2d mouse, int button, int ch, int type, int mouse_wheel_y)
6187 {
6188 Point2d p = get_pos();
6189 float size_y = float(sy)/float(area_y)*float(sy-2-2-2-2);
6190 float pos_y = current_pos * (float(sy) - clamp(float(sy)/float(area_y),0.0,1.0)*float(sy-2-2-2-2));
6191 if (button==0 && type == 1025 && !following && mouse.x>=p.x+2+2 && mouse.x<p.x+sx-2-2 && mouse.y>=p.y+pos_y+2+2 && mouse.y<p.y+pos_y+2+2+size_y)
6192 {
6193 following = true;
6194 start_pos = mouse;
6195 }
6196 if (button==0 && following)
6197 { // moving this to render() doesnt help since it needs mouse position
6198 float delta = mouse.y - start_pos.y;
6199 current_pos = current_pos + delta/float(sy-2-2-2-2);
6200
6201 if (current_pos < 0.0) current_pos = 0.0;
6202 if (current_pos > 1.0) current_pos = 1.0;
6203
6204 start_pos = mouse;
6205 }
6206
6207 if (button==-1)
6208 {
6209 following = false;
6210 }
6211 if (firsttime || changed)
6212 {
6213 if (firsttime)
6214 {
6215 GameApi::BB b = ev.bool_bitmap_api.bb_empty(sx,sy);
6216 GameApi::BB b1 = ev.bool_bitmap_api.rectangle(b, 0.0, 0.0, float(sx), 2.0);
6217 GameApi::BB b2 = ev.bool_bitmap_api.rectangle(b1, 0.0, 0.0, 2.0, float(sy));
6218 GameApi::BB b3 = ev.bool_bitmap_api.rectangle(b2, float(sx)-2.0, 0.0, 2.0, float(sy));
6219 GameApi::BB b4 = ev.bool_bitmap_api.rectangle(b3, 0.0, float(sy)-2.0, float(sx), 2.0);
6220 bg = ev.bool_bitmap_api.to_bitmap(b4, 255,255,255,255, 0,0,0,0);
6221
6222 bg_va = ev.sprite_api.create_vertex_array(bg);
6223 GameApi::BB k = ev.bool_bitmap_api.bb_empty(sx-2-2-2-2, clamp(float(sy)/float(area_y),0.0,1.0)*float(sy-2-2-2-2));
6224 GameApi::BB k2 = ev.bool_bitmap_api.rectangle(k, 0.0, 0.0, float(sx-2-2-2-2), clamp(float(sy)/float(area_y),0.0,1.0)*float(sy-2-2-2-2));
6225 thumb = ev.bool_bitmap_api.to_bitmap(k2, 255,255,255,255, 0,0,0,0);
6226 thumb_va = ev.sprite_api.create_vertex_array(thumb);
6227 }
6228
6229 firsttime = false;
6230 changed=false;
6231 old_area_y = area_y;
6232 }
6233 }
6234 void render()
6235 {
6236 if (is_visible())
6237 {
6238 if (!firsttime)
6239 {
6240 Point2d p = get_pos();
6241 ev.shader_api.set_var(sh, "in_MV", ev.matrix_api.trans(p.x, p.y, 0.0));
6242 ev.sprite_api.render_sprite_vertex_array(bg_va);
6243
6244 float pos_y = current_pos * (float(sy) - clamp(float(sy)/float(area_y),0.0,1.0)*float(sy));
6245 ev.shader_api.set_var(sh, "in_MV", ev.matrix_api.trans(p.x+2+2+0.5, p.y+pos_y+2+2+0.5, 0.0));
6246 ev.sprite_api.render_sprite_vertex_array(thumb_va);
6247 }
6248 }
6249 }
6250 float dynamic_param(int id) const
6251 {
6252 if (id==0) { return current_pos; }
6253 return 0.0;
6254 }
6255 void set_dynamic_param(int id, float val)
6256 {
6257 if (id==0) {
6258 area_y = int(val);
6259 if (area_y!=old_area_y)
6260 {
6261 changed=true;
6262 }
6263 }
6264 }
6265private:
6266 GameApi::SH sh;
6267 GameApi::BM bg;
6268 GameApi::VA bg_va;
6269 GameApi::BM thumb;
6270 GameApi::VA thumb_va;
6271 float current_pos;
6272 int sx,sy,area_y;
6273 bool firsttime;
6274 bool following;
6275 Point2d start_pos;
6276 int old_area_y;
6277 bool changed;
6278 bool button_pressed;
6279};
6280
6281class ScrollBarX : public GuiWidgetForward
6282{
6283public:
6284 ScrollBarX(GameApi::EveryApi &ev, GameApi::SH sh, int sx, int sy, int area_x) : GuiWidgetForward(ev, std::vector<GuiWidget*>()), sh(sh), sx(sx), sy(sy), area_x(area_x) { firsttime=true; current_pos = 0.0; following = false; changed=false; old_area_x = area_x; }
6285 void update(Point2d mouse, int button, int ch, int type, int mouse_wheel_y)
6286 {
6287 Point2d p = get_pos();
6288 float size_x = float(sx)/float(area_x)*float(sx-2-2-2-2);
6289 float pos_x = current_pos * (float(sx) - float(sx)/float(area_x)*float(sx-2-2-2-2));
6290 if (button==0 && type==1025 && !following && mouse.y>=p.y+2+2 && mouse.y<p.y+sy-2-2 && mouse.x>=p.x+pos_x+2+2 && mouse.x<p.x+pos_x+2+2+size_x)
6291 {
6292 following = true;
6293 start_pos = mouse;
6294 }
6295 if (button==0 && following)
6296 {
6297 float delta = mouse.x - start_pos.x;
6298 current_pos = current_pos + delta/float(sx-2-2-2-2);
6299
6300 if (current_pos < 0.0) current_pos = 0.0;
6301 if (current_pos > 1.0) current_pos = 1.0;
6302
6303 start_pos = mouse;
6304 }
6305 if (button==-1)
6306 {
6307 following = false;
6308 }
6309
6310 if (firsttime ||changed)
6311 {
6312 if (firsttime)
6313 {
6314 GameApi::BB b = ev.bool_bitmap_api.bb_empty(sx,sy);
6315 GameApi::BB b1 = ev.bool_bitmap_api.rectangle(b, 0.0, 0.0, float(sx), 2.0);
6316 GameApi::BB b2 = ev.bool_bitmap_api.rectangle(b1, 0.0, 0.0, 2.0, float(sy));
6317 GameApi::BB b3 = ev.bool_bitmap_api.rectangle(b2, float(sx)-2.0, 0.0, 2.0, float(sy));
6318 GameApi::BB b4 = ev.bool_bitmap_api.rectangle(b3, 0.0, float(sy)-2.0, float(sx), 2.0);
6319 bg = ev.bool_bitmap_api.to_bitmap(b4, 255,255,255,255, 0,0,0,0);
6320
6321 bg_va = ev.sprite_api.create_vertex_array(bg);
6322 GameApi::BB k = ev.bool_bitmap_api.bb_empty(float(sx)/float(area_x)*float(sx-2-2-2-2), sy-2-2-2-2);
6323 GameApi::BB k2 = ev.bool_bitmap_api.rectangle(k, 0.0, 0.0, float(sx)/float(area_x)*float(sx-2-2-2-2), float(sy-2-2-2-2));
6324 thumb = ev.bool_bitmap_api.to_bitmap(k2, 255,255,255,255, 0,0,0,0);
6325 thumb_va = ev.sprite_api.create_vertex_array(thumb);
6326 }
6327
6328 firsttime = false;
6329 changed=false;
6330 old_area_x = area_x;
6331 }
6332 }
6333 void render()
6334 {
6335 if (is_visible())
6336 {
6337 if (!firsttime)
6338 {
6339 Point2d p = get_pos();
6340 ev.shader_api.set_var(sh, "in_MV", ev.matrix_api.trans(p.x, p.y, 0.0));
6341 ev.sprite_api.render_sprite_vertex_array(bg_va);
6342
6343 float pos_x = current_pos * (float(sx) - float(sx)/float(area_x)*float(sx));
6344 ev.shader_api.set_var(sh, "in_MV", ev.matrix_api.trans(p.x+pos_x+2+2+0.5, p.y+2+2+0.5, 0.0));
6345 ev.sprite_api.render_sprite_vertex_array(thumb_va);
6346 }
6347 }
6348 }
6349 float dynamic_param(int id) const
6350 {
6351 if (id==0) { return current_pos; }
6352 return 0.0;
6353 }
6354 void set_dynamic_param(int id, float val)
6355 {
6356 if (id==0) {
6357 area_x = int(val);
6358 if (old_area_x != area_x)
6359 {
6360 changed=true;
6361 }
6362 }
6363 }
6364private:
6365 GameApi::SH sh;
6366 GameApi::BM bg;
6367 GameApi::VA bg_va;
6368 GameApi::BM thumb;
6369 GameApi::VA thumb_va;
6370 float current_pos;
6371 int sx,sy,area_x;
6372 bool firsttime;
6373 bool following;
6374 Point2d start_pos;
6375 int old_area_x;
6376 bool changed;
6377};
6378
6379float wave_transfer(float val, float start_range, std::function<float(float)> f, float time)
6380{
6381 val += start_range;
6382 float v = f(val+time);
6383 return v;
6384}
6385class WaveformWidget : public GuiWidget
6386{
6387public:
6388 WaveformWidget(GameApi::EveryApi &ev, GameApi::SH sh, std::function<float (float)> f, float start_range, float end_range, float min_value, float max_value, int sx, int sy, unsigned int true_color, unsigned int false_color) : ev(ev), sh(sh), f(f), start_range(start_range), end_range(end_range), min_value(min_value), max_value(max_value), sx(sx), sy(sy), true_color(true_color), false_color(false_color)
6389 {
6390 firsttime = true;
6391 Point2d p = { -666.0, -666.0 };
6392 update(p, -1,-1, -1,0);
6393 Point2d p2 = { 0.0, 0.0 };
6394 set_pos(p2);
6395 time = 0.0;
6396 }
6397 bool is_visible() const { return true; }
6398 Point2d get_pos() const { return pos; }
6399 Vector2d get_size() const { return size; }
6400 void set_pos(Point2d pos_p) { pos = pos_p; }
6401 void set_size(Vector2d vec_p) { size = vec_p; }
6402 void update(Point2d mouse_pos, int button,int ch, int type, int mouse_wheel_y)
6403 {
6404 if (firsttime)
6405 {
6406 GameApi::WV wave = ev.waveform_api.function(std::bind(&wave_transfer, GameApi::_1, start_range, f, std::ref(time)), end_range-start_range, min_value, max_value);
6407 wave_bm = ev.waveform_api.waveform_bitmap(wave, sx, sy, true_color, false_color);
6408 wave_bm_va = ev.sprite_api.create_vertex_array(wave_bm);
6409 firsttime = false;
6410 } else {
6411 time+=0.05;
6412 ev.sprite_api.update_vertex_array(wave_bm_va, wave_bm);
6413 }
6414 Vector2d s = { float(sx), float(sy) };
6415 size = s;
6416 }
6417 void render()
6418 {
6419 if (is_visible())
6420 {
6421 if (!firsttime)
6422 {
6423 Point2d pos = get_pos();
6424 ev.shader_api.set_var(sh, "in_MV", ev.matrix_api.trans(pos.x+0.5, pos.y+0.5, 0.0));
6425 ev.sprite_api.render_sprite_vertex_array(wave_bm_va);
6426 }
6427 }
6428 }
6429 int render_to_bitmap()
6430 {
6431 return wave_bm.id;
6432 }
6433 void select_item(int item) { }
6434 int chosen_item() const { return -1; }
6435 float dynamic_param(int id) const { return 0.0; }
6436 void set_dynamic_param(int id, float val) { }
6437 int child_count() const { return 0; }
6438 GuiWidget *child(int num) const { return 0; }
6439 bool content_changed() const { return true; }
6440 void clear_content_changed() { }
6441private:
6442 bool firsttime;
6443 GameApi::BM wave_bm;
6444 GameApi::VA wave_bm_va;
6445 Point2d pos;
6446 Vector2d size;
6447 GameApi::EveryApi &ev;
6448 GameApi::SH sh;
6449 std::function<float (float)> f;
6450 float start_range, end_range;
6451 float min_value, max_value;
6452 int sx, sy;
6453 unsigned int true_color, false_color;
6454 float time;
6455};
6458
6459extern const char *g_videodriver;
6460class ScrollAreaWidget : public GuiWidgetForward
6461{
6462public:
6463 ScrollAreaWidget(GameApi::EveryApi &ev, GameApi::SH sh, GuiWidget *orig, int sx, int sy, int screen_y,bool disable_wheel) : GuiWidgetForward(ev, { orig }), sh(sh), orig(orig), sx(sx), sy(sy), screen_y(screen_y), disable_wheel(disable_wheel) { firsttime = true; Vector2d v = { float(sx),float(sy)}; size = v; top=0.0; left=0.0;
6464 mouse_wheel_move=0.0;
6465}
6466 void set_pos(Point2d pos)
6467 {
6469 Vector2d sz = vec[0]->get_size();
6470 Point2d pos2 = { pos.x-left*(sz.dx-size.dx), pos.y-top*(sz.dy-size.dy)+mouse_wheel_move };
6471 vec[0]->set_pos(pos2);
6472 }
6473 void set_size(Vector2d sz)
6474 {
6476 size = sz;
6477 sx=(int)sz.dx;
6478 sy=(int)sz.dy;
6479 }
6480 void update(Point2d mouse_pos, int button, int ch, int type, int mouse_wheel_y)
6481 {
6482 Point2d mouse = mouse_pos;
6483 static bool is_inside=false;
6484 if (mouse.x>=pos.x-80 && mouse.x<pos.x+size.dx+80 &&
6485 mouse.y>=pos.y-80 && mouse.y<pos.y+size.dy+80)
6486 {
6487 //Vector2d sz = vec[0]->get_size();
6488 //mouse.x -= left*(sz.dx-size.dx);
6489 //mouse.y -= top*(sz.dy-size.dy);
6490 orig->update(mouse, button,ch, type, mouse_wheel_y);
6491 is_inside=true;
6492 }
6493 else
6494 {
6495 if (is_inside) {
6496
6497 Point2d mouse = {-666.0, -666.0 };
6498 orig->update(mouse, button,ch, type, mouse_wheel_y);
6499 }
6500 is_inside=false;
6501 }
6502 if (!disable_wheel && type==1027 && mouse.x>pos.x && mouse.x<pos.x+size.dx &&
6503 mouse.y>pos.y && mouse.y<pos.y+size.dy)
6504 { // mouse wheel
6505 //std::cout << "Mouse wheel" << mouse_wheel_y << std::endl;
6506 mouse_wheel_move+=mouse_wheel_y*80.0;
6507 Point2d pos = get_pos();
6508 Vector2d sz = vec[0]->get_size();
6509 Point2d pos2 = { pos.x-left*(sz.dx-size.dx), pos.y-top*(sz.dy-size.dy)+mouse_wheel_move };
6510 vec[0]->set_pos(pos2);
6511
6512 }
6513 }
6514 void render()
6515 {
6516 OpenglLowApi *ogl = g_low->ogl;
6517 if (is_visible())
6518 {
6520 if (g_event_screen_y!=-1) {
6521 float scale_x = float(g_event_screen_x)/float(ev.mainloop_api.get_screen_width());
6522 float scale_y = float(g_event_screen_y)/float(ev.mainloop_api.get_screen_height());
6523 //if (g_videodriver && std::string(g_videodriver)=="wayland") {
6524 // scale_x*=1.6;
6525 // }
6526
6527 //std::cout << g_event_screen_x << " / " << ev.mainloop_api.get_screen_width() << std::endl;
6528 //std::cout << g_event_screen_y << " / " << ev.mainloop_api.get_screen_height() << std::endl;
6529 //std::cout << "SCISSOR SIZE: " << size.dx << " " << size.dy << " " << scale_x << " " << scale_y << std::endl;
6530 ogl->glScissor(pos.x*scale_x, g_event_screen_y-pos.y*scale_y-size.dy*scale_y, (size.dx)*scale_x, size.dy*scale_y);
6531 } else {
6532 ogl->glScissor(pos.x, (screen_y-pos.y-size.dy), size.dx, size.dy);
6533 }
6534 //std::cout << "g_resize_event;:" << g_resize_event_sx << " " << g_resize_event_sy << std::endl;
6535 //std::cout << "g_event_screen:" << g_event_screen_x << " " << g_event_screen_y << std::endl;
6536 //std::cout<< "scrollarea:" << pos.x << " " << size.dx << std::endl;
6537 vec[0]->render();
6539 }
6540 }
6541
6542 int chosen_item() const { return orig->chosen_item(); }
6543 void set_dynamic_param(int id, float val)
6544 {
6545 switch(id) {
6546 case 0: left = val; break;
6547 case 1: top = val; break;
6548 }
6549 Point2d pos = get_pos();
6550 Vector2d sz = vec[0]->get_size();
6551 Point2d pos2 = { pos.x-left*(sz.dx-size.dx), pos.y-top*(sz.dy-size.dy)+mouse_wheel_move };
6552 //std::cout << "dyn: " << left << " " << top << std::endl;
6553 vec[0]->set_pos(pos2);
6554 }
6555private:
6556 bool firsttime;
6557 GameApi::SH sh;
6558 GameApi::BM area_bm;
6559 GameApi::VA area_bm_va;
6560 GuiWidget *orig;
6561 int sx,sy;
6562 float top, left;
6563 float mouse_wheel_move;
6564 int screen_y;
6565 bool disable_wheel;
6566};
6567class OrElemGuiWidget : public GuiWidget
6568{
6569public:
6570 OrElemGuiWidget(GameApi::Env &env, GameApi::W (*fptr1)(void*), GameApi::W (*fptr2)(void*), void*data)
6571 : env(env), b(false), fptr1(fptr1), fptr2(fptr2),data(data)
6572 {
6573
6574 isVisible=true;
6575 }
6576 virtual bool is_visible() const { return isVisible; }
6577virtual Point2d get_pos() const { check(); if (b) return w1->get_pos(); else return w2->get_pos(); }
6578virtual Vector2d get_size() const { check(); if (b) return w1->get_size(); else return w2->get_size(); }
6579virtual void set_pos(Point2d pos) { check(); if (b) w1->set_pos(pos); else w2->set_pos(pos); }
6580virtual void set_size(Vector2d size) { check(); if (b) w1->set_size(size); else w2->set_size(size); }
6581virtual void update(Point2d mouse_pos, int button, int ch, int type, int mouse_wheel_y) { check(); if (b) w1->update(mouse_pos, button,ch,type,mouse_wheel_y); else w2->update(mouse_pos, button,ch,type,mouse_wheel_y); }
6582virtual void render() { if (is_visible()) { check(); if (b) w1->render(); else w2->render();} }
6583virtual int render_to_bitmap() { check(); if (b) return w1->render_to_bitmap(); else return w2->render_to_bitmap(); }
6584 virtual void select_item(int item) { check(); if (item==0) b=true; if (item==1) b=false; update(Point2d(-666.0,-666.0), -1,-1,-1,0); set_size(get_size()); }
6585virtual int chosen_item() const { check(); if (b) return w1->chosen_item(); else return w2->chosen_item(); }
6586virtual float dynamic_param(int id) const { check(); if (b) return w1->dynamic_param(id); else return w2->dynamic_param(id); }
6587virtual void set_dynamic_param(int id, float val) { check(); if (b) w1->set_dynamic_param(id, val); else w2->set_dynamic_param(id, val); }
6588virtual int child_count() const { check(); if (b) { return w1->child_count(); } else { return w2->child_count(); } }
6589virtual bool content_changed() const { check(); if (b) { return w1->content_changed(); } else { return w2->content_changed(); } }
6590virtual void clear_content_changed() { check(); if (b) { w1->clear_content_changed(); } else { w2->clear_content_changed(); } }
6591 virtual GuiWidget *child(int num) const
6592 {
6593 if (b) { return w1->child(num); }
6594 else { return w2->child(num); }
6595 }
6596void check() const
6597{
6598 if (b) {
6599 if (!w1) {
6600 GameApi::W w = fptr1(data);
6601 w1 = find_widget(env, w);
6602 }
6603 }
6604 if (!b) {
6605 if (!w2) {
6606 GameApi::W w = fptr2(data);
6607 w2 = find_widget(env,w);
6608 }
6609 }
6610}
6611private:
6612 GameApi::Env &env;
6613 bool b;
6614 mutable GuiWidget *w1=0;
6615 mutable GuiWidget *w2=0;
6616 GameApi::W (*fptr1)(void*);
6617 GameApi::W (*fptr2)(void*);
6618 void *data;
6619 bool isVisible;
6620};
6621EXPORT GameApi::W GameApi::GuiApi::gradient(int sx, int sy, PT pos_1, PT pos_2, unsigned int color_1, unsigned int color_2)
6622{
6623 //color_2 = color_1;
6624 BM bm = ev.bitmap_api.gradient_y(/*pos_1, pos_2,*/ color_1, color_2, sx, sy);
6625 int key = color_1+color_2;
6626 return icon_shared(bm,key);
6627}
6628
6629struct ButtonCacheItem
6630{
6631 int sx;
6632 int sy;
6633 unsigned int color_1;
6634 unsigned int color_2;
6635 GameApi::BM bm;
6636};
6637std::vector<ButtonCacheItem*> button_cache;
6638ButtonCacheItem* find_from_button_cache(int sx, int sy, unsigned int color_1, unsigned int color_2)
6639{
6640 int s = button_cache.size();
6641 for(int i=0;i<s;i++)
6642 {
6643 ButtonCacheItem *item = button_cache[i];
6644 if (sx==item->sx && sy==item->sy && color_1 == item->color_1 && color_2==item->color_2) return item;
6645 }
6646 return 0;
6647}
6648
6649
6650EXPORT GameApi::W GameApi::GuiApi::button(int sx, int sy, unsigned int color_1, unsigned int color_2)
6651{
6652 //color_2 = color_1;
6653
6654 ButtonCacheItem *item = find_from_button_cache(sx,sy,color_1,color_2);
6655 GameApi::BM res;
6656 if (!item)
6657 {
6658 int c = get_current_block();
6659 set_current_block(-2); // dont take ownership of this
6660
6661 PT pt1 = ev.point_api.point(0.0, 0.0, 0.0);
6662 PT pt2 = ev.point_api.point(0.0, sy, 0.0);
6663 BM w = ev.bitmap_api.gradient_y(/*pt1, pt2,*/ color_1, color_2, sx,sy);
6664 unsigned int color_1L = color_1;
6665 unsigned int color_2L = color_2;
6666#if 1
6667 unsigned char *ptr = (unsigned char *)&color_1L;
6668 unsigned char *ptr2 = (unsigned char *)&color_2L;
6669 ptr[0] = (unsigned char) (float(ptr[0])*0.8);
6670 ptr[1] = (unsigned char) (float(ptr[1])*0.8);
6671 ptr[2] = (unsigned char) (float(ptr[2])*0.8);
6672 ptr[3] = (unsigned char) (float(ptr[3])*0.8);
6673 ptr2[0] = (unsigned char) (float(ptr2[0])*0.8);
6674 ptr2[1] = (unsigned char) (float(ptr2[1])*0.8);
6675 ptr2[2] = (unsigned char) (float(ptr2[2])*0.8);
6676 ptr2[3] = (unsigned char) (float(ptr2[3])*0.8);
6677#endif
6678 BM w2 = ev.bitmap_api.gradient_y(/*pt1, pt2,*/ color_1L, color_2L,sx,sy);
6679
6680 unsigned int color_1D = color_1;
6681 unsigned int color_2D = color_2;
6682#if 1
6683 unsigned char *ptrD = (unsigned char*)&color_1D;
6684 unsigned char *ptr2D = (unsigned char*)&color_2D;
6685 ptrD[0] = (unsigned char) (float(ptrD[0])*0.6);
6686 ptrD[1] = (unsigned char) (float(ptrD[1])*0.6);
6687 ptrD[2] = (unsigned char) (float(ptrD[2])*0.6);
6688 ptrD[3] = (unsigned char) (float(ptrD[3])*0.6);
6689 ptr2D[0] = (unsigned char) (float(ptr2D[0])*0.6);
6690 ptr2D[1] = (unsigned char) (float(ptr2D[1])*0.6);
6691 ptr2D[2] = (unsigned char) (float(ptr2D[2])*0.6);
6692 ptr2D[3] = (unsigned char) (float(ptr2D[3])*0.6);
6693#endif
6694 BM w3 = ev.bitmap_api.gradient_y(/*pt1, pt2,*/ color_1D, color_2D,sx,sy);
6695
6696 BB mask_0 = ev.bool_bitmap_api.bb_empty(sx,sy);
6697 BB mask_0a = ev.bool_bitmap_api.rectangle(mask_0, 0.0, 0.0, float(sx), 2.0);
6698 BB mask_0b = ev.bool_bitmap_api.rectangle(mask_0a, 0.0, 0.0, 2.0, float(sy));
6699 BB mask_1 = mask_0b;
6700
6701 BB mask__0 = ev.bool_bitmap_api.bb_empty(sx,sy);
6702 BB mask__0a = ev.bool_bitmap_api.rectangle(mask__0, float(sx-2), 0.0, 2.0, sy);
6703 BB mask__0b = ev.bool_bitmap_api.rectangle(mask__0a, 0.0, float(sy-2), float(sx), 2.0);
6704 BB mask_2 = mask__0b;
6705
6706 BM w4 = ev.bitmap_api.blitbitmap_bb(w2, w, 0, 0, mask_1);
6707 BM w5 = ev.bitmap_api.blitbitmap_bb(w4, w3, 0, 0, mask_2);
6709
6710 ButtonCacheItem *item2 = new ButtonCacheItem;
6711 item2->sx=sx;
6712 item2->sy=sy;
6713 item2->color_1 = color_1;
6714 item2->color_2 = color_2;
6715 item2->bm = w5;
6716 button_cache.push_back(item2);
6717 res = w5;
6718 }
6719 else
6720 {
6721 res = item->bm;
6722 }
6723
6724 int key = sx+sy+color_1+color_2;
6725 return icon_shared(res,key);
6726}
6727EXPORT GameApi::W GameApi::GuiApi::or_elem(W (*w1_func)(void*), W (*w2_func)(void*), void*data)
6728{
6729 //GuiWidget *ww1 = find_widget(e, w1);
6730 //GuiWidget *ww2 = find_widget(e, w2);
6731 return add_widget(e, new OrElemGuiWidget(e,w1_func,w2_func,data));
6732}
6734{
6735 return add_widget(e, new ScrollBarY(ev,sh, sx,sy,area_y));
6736}
6738{
6739 return add_widget(e, new ScrollBarX(ev,sh, sx,sy,area_x));
6740}
6741EXPORT GameApi::W GameApi::GuiApi::scroll_area(W orig, int sx, int sy, int screen_y)
6742{
6743 GuiWidget *orig_1 = find_widget(e, orig);
6744 return add_widget(e, new ScrollAreaWidget(ev, sh, orig_1, sx,sy, screen_y,false));
6745}
6746EXPORT GameApi::W GameApi::GuiApi::scroll_area2(W orig, int sx, int sy, int screen_y)
6747{
6748 GuiWidget *orig_1 = find_widget(e, orig);
6749 return add_widget(e, new ScrollAreaWidget(ev, sh, orig_1, sx,sy, screen_y,true));
6750}
6751#if 0
6752EXPORT GameApi::W GameApi::GuiApi::canvas_scroll_area(int sx, int sy, int screen_x, int screen_y)
6753{
6754}
6755#endif
6756EXPORT GameApi::W GameApi::GuiApi::waveform(std::function<float (float)> f, float start_range, float end_range, float min_value, float max_value, int sx, int sy, unsigned int true_color, unsigned int false_color)
6757{
6758 return add_widget(e, new WaveformWidget(ev, sh, f, start_range, end_range, min_value, max_value, sx, sy, true_color, false_color));
6759}
6760EXPORT GameApi::W GameApi::GuiApi::menu(W main_menu, int menu_id, std::vector<std::string> labels, FtA atlas, BM atlas_bm)
6761{
6763 int s = w->child(0)->child(1)->child_count();
6764 if (menu_id<0 || menu_id>=s) { std::cout << "ERROR: Wrong menu id" << menu_id << " " << s << std::endl; exit(0); }
6765 GuiWidget *ww = w->child(0)->child(1)->child(menu_id);
6766 Point2d pos = ww->get_pos();
6767 Vector2d size = ww->get_size();
6768
6769 int ss = labels.size();
6770 std::vector<W> vec;
6771 for(int i=0;i<ss;i++) {
6772 std::string s = labels[i];
6773 W txt_1 = text(s, atlas, atlas_bm);
6774 W txt_2 = margin(txt_1, 2,2,2,2);
6775 W txt_3 = highlight(size_x(txt_2), size_y(txt_2));
6776 W txt_4 = layer(txt_2, txt_3);
6777 vec.push_back(txt_4);
6778 }
6779 W w2 = array_y(vec /*&vec[0], vec.size()*/, 2);
6780 W w22 = margin(w2, 4,4,4,4);
6781 //PT pt1 = ev.point_api.point(0.0,0.0,0.0);
6782 //PT pt2 = ev.point_api.point(0.0, size_y(w2), 0.0);
6783 W w3 = button(size_x(w22), size_y(w22), c_list_item_title, c_list_item_title2 /*0xffff8844, 0xff884422*/);
6784 //gradient(size_x(w2), size_y(w2), pt1, pt2, 0xffff8844, 0xff884422);
6785 W w4 = layer(w3,w22);
6786 set_pos(w4, pos.x, pos.y+size.dy);
6787 return w4;
6788}
6789
6790EXPORT GameApi::W GameApi::GuiApi::popup_menu(int x, int y, std::vector<std::string> labels, FtA atlas, BM atlas_bm, std::vector<W> &areas)
6791{
6792 int ss = labels.size();
6793 std::vector<W> vec;
6794 for(int i=0;i<ss;i++) {
6795 std::string s = labels[i];
6796 W txt_1 = text(s, atlas, atlas_bm);
6797 W txt_2 = margin(txt_1, 2,2,2,2);
6798 W txt_3 = highlight(size_x(txt_2), size_y(txt_2));
6799 W txt_4 = layer(txt_2, txt_3);
6800 W txt_5 = click_area(txt_4, 0.0, 0.0, size_x(txt_4), size_y(txt_4),0);
6801 std::stringstream ss;
6802 ss << i;
6803 std::string id = ss.str();
6804 set_id(txt_5, id);
6805 vec.push_back(txt_5);
6806 areas.push_back(txt_5);
6807 }
6808
6809 W w2 = array_y(vec /*&vec[0], vec.size()*/, 2);
6810 W w22 = margin(w2, 4,4,4,4);
6811 W w3 = button(size_x(w22), size_y(w22), c_list_item_title, c_list_item_title2 /*0xffff8844, 0xff884422*/);
6812 W w4 = layer(w3,w22);
6813 set_pos(w4, x, y);
6814 return w4;
6815}
6816
6818{
6819 GameApi::BM bg = ev.bitmap_api.newbitmap(size.dx, size.dy, 0x0000000000);
6820 int s = vec.size();
6821 for(int i=0;i<s;i++)
6822 {
6823 GuiWidget *w = vec[i];
6824 int bm_id = w->render_to_bitmap();
6825 GameApi::BM bm_id_1;
6826 bm_id_1.id = bm_id;
6827 Point2d p = w->get_pos();
6828 p-=pos;
6829 GameApi::FB fb = ev.float_bitmap_api.from_alpha(bm_id_1);
6830 GameApi::BB bb3 = ev.bool_bitmap_api.from_float_bitmap(fb, 0.1, 1.2);
6831 bg = ev.bitmap_api.blitbitmap_bb(bg, bm_id_1, (int)p.x, (int)p.y, bb3);
6832 }
6833 return bg.id;
6834}
6836{
6837 GuiWidget *ww = find_widget(e, w);
6838 return int(ww->get_pos().x);
6839}
6841{
6842 GuiWidget *ww = find_widget(e, w);
6843 return int(ww->get_pos().y);
6844}
6846 {
6847 GuiWidget *ww = find_widget(e, w);
6848 return ww->get_size().dx;
6849 }
6851 {
6852 GuiWidget *ww = find_widget(e, w);
6853 return ww->get_size().dy;
6854 }
6855EXPORT void GameApi::GuiApi::set_pos(W w, float px, float py)
6856{
6857 Point2d p = { px, py };
6858 GuiWidget *ww = find_widget(e, w);
6859 if (ww) {
6860 ww->set_pos(p);
6861 }
6862}
6863EXPORT void GameApi::GuiApi::set_size(W w, float sx, float sy)
6864{
6865 Vector2d v = { sx, sy };
6866 GuiWidget *ww = find_widget(e, w);
6867 ww->set_size(v);
6868}
6869EXPORT void GameApi::GuiApi::update(W w, PT mouse, int button,int ch, int type, int mouse_wheel_y)
6870{
6871 GuiWidget *ww = find_widget(e, w);
6872 if (ww) {
6873 Point *pt = find_point(e, mouse);
6874
6875 Point2d pt2 = { pt?pt->x:0.0f, pt?pt->y:0.0f };
6876 ww->update(pt2, button,ch, type, mouse_wheel_y);
6877 }
6878}
6880{
6881 //std::cout << "GuiApi::render" << w.id << std::endl;
6882 GuiWidget *ww = find_widget(e, w);
6883 if (ww)
6884 ww->render();
6885}
6887{
6888 GuiWidget *ww = find_widget(e, w);
6889 if (!ww) { return -1; }
6890 return ww->chosen_item();
6891}
6893{
6894 GuiWidget *ww = find_widget(e, w);
6895 ww->select_item(item);
6896}
6898{
6899 //std::cout << "GuiApi::dynamic_param" << w.id << std::endl;
6900 GuiWidget *ww = find_widget(e, w);
6901 if (!ww) { return 0.0; }
6902 return ww->dynamic_param(id);
6903}
6905{
6906 GuiWidget *ww = find_widget(e, w);
6907#ifdef EMSCRIPTEN
6908 GuiWidgetForward *ww2 = static_cast<GuiWidgetForward*>(ww);
6909#else
6910 GuiWidgetForward *ww2 = dynamic_cast<GuiWidgetForward*>(ww);
6911#endif
6912 return ww2->vec.size();
6913}
6915{
6916 GuiWidget *ww = find_widget(e, w);
6917#ifdef EMSCRIPTEN
6918 GuiWidgetForward *ww2 = static_cast<GuiWidgetForward*>(ww);
6919#else
6920 GuiWidgetForward *ww2 = dynamic_cast<GuiWidgetForward*>(ww);
6921#endif
6922 if (ww2)
6923 {
6924 GuiWidget *child = ww2->vec[i];
6925
6927 int s = env->widgets.size();
6928 for(int i=0;i<s;i++)
6929 {
6930 GuiWidget *w = env->widgets[i];
6931 if (child==w) {
6932 GameApi::W wid;
6933 wid.id = i;
6934 return wid;
6935 }
6936 }
6937 }
6938 GameApi::W wid;
6939 wid.id = -1;
6940 return wid;
6941}
6943{
6944 GuiWidget *ww = find_widget(e, w);
6945 ww->set_dynamic_param(id, val);
6946}
6948{
6949 GuiWidget *ww = find_widget(e,w);
6950 return ww->get_id();
6951}
6953{
6954 GuiWidget *ww = find_widget(e,w);
6955 return ww->get_index();
6956}
6958{
6959 GuiWidget *ww = find_widget(e,w);
6960 return ww->get_size2();
6961}
6963{
6964 GuiWidget *ww = find_widget(e, w);
6965 ww->set_size2(sz);
6966}
6968{
6969 GuiWidget *ww = find_widget(e, w);
6970 ww->set_index(j);
6971}
6972EXPORT void GameApi::GuiApi::set_id(W w, std::string id)
6973{
6974 GuiWidget *ww = find_widget(e, w);
6975 ww->set_id(id);
6976}
6977
6978
6979int to_int(std::string s);
6980
6981
6982
6983class GameApiEditNode_float_coord : public GameApi::EditNode
6984{
6985public:
6986 GameApiEditNode_float_coord(int count, std::string param_type, std::string param_value, std::string param_name) : source(0), mode(0), count(count), param_type(param_type), param_value(param_value), param_name(param_name) { move=false; mod=false; source=0; mode=0; }
6987 void SetSource(int i) { source=i; }
6988 void SetMode(int i) { mode=i; }
6989 void CurrentPos(Point &p) const
6990 {
6991 if (param_type=="float") {
6992 std::stringstream ss(param_value);
6993 if (mode==1) { ss >> p.x; }
6994 if (mode==2) { ss >> p.y; }
6995 if (mode==3) { ss >> p.z; }
6996 }
6997 }
6998 void HandleMouseMove(int x, int y)
6999 {
7000 mod=false;
7001 if (source==1) { res = x; mod = true;}
7002 if (source==2) { res = y; mod = true; }
7003 if (mod && move && param_type=="float") {
7004 std::stringstream ss;
7005 ss << res;
7006 param_value = ss.str();
7007 }
7008 }
7009 // type==0 no event
7010 // type==1 mouse down
7011 // type==2 mouse up
7012 void HandleMousePress(int type) {
7013 if (type==1) { move=true; }
7014 if (type==2) { move=false; }
7015 }
7016 std::string GetValue() const { return param_value; }
7017private:
7018 int source; // 0=no source, 1=mouse_x, 2=mouse_y
7019 int mode; // 0=no edit, 1=edit_x, 2=edit_y, 3=edit_z
7020 int count;
7021 std::string param_type;
7022 std::string param_value;
7023 std::string param_name;
7024 int res;
7025 bool mod;
7026 bool move;
7027};
7028
7029#if 0
7030int GameApi::collect_counter(int mode)
7031{
7032 static int count=0;
7033 if (mode==0) { count=0; }
7034 if (mode==1) { count++; }
7035 return count;
7036}
7037#endif
7038#if 0
7039std::vector<GameApi::EditNode*> collectnodes(std::string name, std::vector<std::string> param_type, std::vector<std::string> param_names, std::vector<std::string> params, std::vector<std::string> param_name)
7040{
7041 int s=param_type.size();
7042 std::cout << "Params: " << s << std::endl;
7043 for(int i=0;i<s;i++)
7044 {
7046 std::cout << count << " " << name << ":" << param_type[i] << " " << param_names[i] << ": " << param_name[i] << std::endl;
7047 }
7048 return std::vector<GameApi::EditNode*>();
7049}
7050#endif
7051
7052template<class T>
7053int template_get_id(T t) { return t.id; }
7054int template_get_id(GameApi::ARR a) { return 0; }
7055
7056void funccall_1(std::vector<std::string> &s, GameApi::ExecuteEnv &e, std::vector<std::string> param_name);
7057
7058
7059
7060int find_char(const std::string &line, int start_char, char ch, bool braces=true)
7061{
7062 int s = line.size();
7063 int level=0;
7064 for(int i=start_char;i<s;i++)
7065 {
7066 if (braces && (line[i]=='(' ||line[i]=='{')) { level++; }
7067
7068 if (line[i]==ch && level==0) return i;
7069 if (braces && ((line[i]==')' ||line[i]=='}') && level>0)) { level--; }
7070 }
7071 return -1;
7072}
7073int find_one(std::string line, int start_char, std::string chars, bool braces=true)
7074{
7075 int s = line.size();
7076 int level=0;
7077 for(int i=start_char;i<s;i++)
7078 {
7079 if (braces && (line[i]=='('||line[i]=='{')) { level++; }
7080 int ss = chars.size();
7081 bool found = false;
7082 for(int j=0;j<ss;j++)
7083 {
7084 if (line[i]==chars[j])
7085 {
7086 if (level==0) {
7087 found = true;
7088 }
7089 }
7090 }
7091 if (braces && ((line[i]==')'||line[i]=='}') && level>0)) { level--; }
7092 if (found) { return i; }
7093 }
7094 return -1;
7095}
7096int extend_until(std::string line, int start_char, std::string chars)
7097{
7098 int s = line.size();
7099 for(int i=start_char;i<s;i++)
7100 {
7101 int ss = chars.size();
7102 bool b = false;
7103 for(int j=0;j<ss;j++)
7104 if (line[i]==chars[j]) { b=true; }
7105 if (b) continue;
7106 return i;
7107 }
7108 return -1;
7109}
7110class GameApiItem;
7111struct CodeGenLine {
7112 std::string return_type;
7113 std::string label_num;
7114 std::string api_name;
7115 std::string func_name;
7116 std::vector<std::string> params;
7117 std::vector<std::string> param_names;
7118 std::vector<std::string> params_linkage;
7119 std::vector<int> j; // -1 = check array
7120 GameApiItem *item;
7121 int x,y;
7122};
7123void CodeGenLineErrorCheck(CodeGenLine &line, std::vector<GameApiItem*> functions)
7124{
7125 int s = functions.size();
7126 bool found = false;
7127 for(int i=0;i<s;i++)
7128 {
7129 GameApiItem *item = functions[i];
7130 if (item->ApiName(0) == line.api_name && item->FuncName(0)==line.func_name)
7131 {
7132 found = true;
7133 if (item->ParamCount(0) != int(line.params.size()))
7134 {
7135 //std::cout << "ERROR: Param arity problem" << std::endl;
7136 //std::cout << "Trying to fix" << std::endl;
7137 int s = item->ParamCount(0) - line.params.size();
7138 int old_size = line.params.size();
7139 if (s>0)
7140 for(int j=0;j<s;j++) {
7141 line.params.push_back(item->ParamDefault(0,old_size + j));
7142 }
7143
7144#if 0
7145 std::cout << item->ParamCount(0)<< "!=" << line.params.size() << " -- " << item->ApiName(0) << "::" << item->FuncName(0) << "(";
7146 int ss = item->ParamCount(0);
7147 for(int ii=0;ii<ss;ii++)
7148 {
7149 std::cout << item->ParamType(0,ii);
7150 if (ii!=ss-1) std::cout << " ";
7151 }
7152 std::cout << ");" << std::endl;
7153 int ss2 = line.params.size();
7154 std::cout << line.api_name << "::" << line.func_name << "(";
7155 for(int j=0;j<ss2;j++)
7156 {
7157 std::cout << line.params[j];
7158 if (j!=ss2-1) std::cout << " ";
7159 }
7160 std::cout << ");" << std::endl;
7161#endif
7162 }
7163 }
7164 }
7165 if (!found) {
7166 std::cout << "ERROR: function not found! " << std::endl;
7167 int ss2 = line.params.size();
7168 std::cout << line.api_name << "::" << line.func_name << "(";
7169 for(int j=0;j<ss2;j++)
7170 {
7171 std::cout << line.params[j];
7172 if (j!=ss2-1) std::cout << " ";
7173 }
7174 std::cout << ");" << std::endl;
7175 }
7176}
7177template<class T>
7178std::ostream &operator<<(std::ostream &o, const std::vector<T> &v)
7179{
7180 int s = v.size();
7181 for(int i=0;i<s;i++)
7182 {
7183 o << v[i];
7184 if (i!=s-1) { o << ","; }
7185 }
7186 return o;
7187}
7188
7189std::string find_param_name(GameApi::EveryApi &ev, std::string api_name, std::string func_name, int ii)
7190{
7191 //static std::vector<GameApiItem*> lst = all_functions(ev);
7192
7193 std::vector<GameApiItem*> &lst = g_all_functions_service->get_all_functions(ev);
7194int s = lst.size();
7195 for(int i=0;i<s;i++)
7196 {
7197 if (api_name == lst[i]->ApiName(0) && func_name==lst[i]->FuncName(0))
7198 {
7199 //std::cout << "PARAM_NAME:" << lst[i]->ParamName(0,ii) << std::endl;
7200 return lst[i]->ParamName(0,ii);
7201 }
7202 }
7203 std::cout << "find_param_name failed for" << api_name << " " << func_name << std::endl;
7204 return "@";
7205}
7206
7207
7208CodeGenLine parse_codegen_line(GameApi::EveryApi &ev, std::string line)
7209{
7210 //std::cout << "Parse:" << line << std::endl;
7211
7212 CodeGenLine error = { "@", "@", "@", "@", { } };
7213 int first_space = find_char(line, 0, ' ');
7214 if (first_space==-1) { std::cout << "parse_codegen_line: first space error: " << std::endl; return error; }
7215 std::string return_type = line.substr(0,first_space);
7216 if (line[first_space+1]!='I') { std::cout << "parse_codegen_line: I error:" << std::endl; return error; }
7217 int num_end_iterator = extend_until(line, first_space+2, "0123456789");
7218 if (num_end_iterator==-1) { std::cout << "parse_codegen_line: 012345689:" << std::endl; return error; }
7219 std::string num = line.substr(first_space+2, num_end_iterator-first_space-2);
7220 if (line[num_end_iterator]!='=') { std::cout << "parse_codegen_line: '=' error:" << std::endl; return error; }
7221 if (line[num_end_iterator+1]!='e') { std::cout << "parse_codegen_line: 'e' error:" << std::endl; return error; }
7222 if (line[num_end_iterator+2]!='v') { std::cout << "parse_codegen_line: 'v' error:" << std::endl; return error; }
7223 if (line[num_end_iterator+3]!='.') { std::cout << "parse_codegen_line: '.' error:" << std::endl; return error; }
7224 int end = find_char(line, num_end_iterator+4, '.');
7225 if (end==-1) { std::cout << "parse_codegen_line2: '.' error:" << std::endl; return error; }
7226 std::string api_name = line.substr(num_end_iterator+4, end-num_end_iterator-4);
7227 int end2 = find_char(line,end+1,'(',false);
7228 if (end2==-1) { std::cout << "parse_codegen_line2: '(' error:" << std::endl; return error; }
7229 std::string func_name = line.substr(end+1, end2-end-1);
7230 std::vector<std::string> params;
7231 std::vector<std::string> param_names;
7232 int ii=0;
7233 while(1) {
7234 int end3 = find_one(line, end2+1, "),");
7235 if (end3==-1) { std::cout << "parse_codegen_line2: '),' error:" << std::endl; return error; }
7236 if (end3==end2+1 && line[end3]==')') { break; } // empty array
7237 std::string p = line.substr(end2+1,end3-end2-1);
7238 if (p.size()>0 && p[0]=='"' && p[p.size()-1]=='"')
7239 {
7240 p=p.substr(1,p.size()-2);
7241 }
7242 params.push_back(p);
7243 param_names.push_back(find_param_name(ev,api_name,func_name,ii));
7244 end2 = end3;
7245 if (line[end3]==')') { break; }
7246 ii++;
7247 }
7248 int x=-1;
7249 int y=-1;
7250 if (line[end2]!=')') end2++;
7251 if (line[end2]==')' &&
7252 line[end2+1]==';' &&
7253 line[end2+2]==' ' &&
7254 line[end2+3]=='/' &&
7255 line[end2+4]=='/' &&
7256 line[end2+5]==' ')
7257 {
7258 int end4 = find_one(line,end2+6,",\n\0");
7259 if (end4!=-1) {
7260 std::string sx = line.substr(end2+6,end4-end2-6);
7261 std::string sy = line.substr(end4+1,line.size()-end4-1);
7262 std::stringstream ssx(sx);
7263 ssx >> x;
7264 std::stringstream ssy(sy);
7265 ssy >> y;
7266 }
7267 }
7268
7269 CodeGenLine line2;
7270 line2.return_type = return_type;
7271 line2.label_num = "I" + num;
7272 line2.api_name = api_name;
7273 line2.func_name = func_name;
7274 line2.params = params;
7275 line2.param_names = param_names;
7276 line2.x = x;
7277 line2.y = y;
7278
7279 //std::cout << "CodeGenLine: " << line2.api_name << " " << line2.func_name << " " << line2.params << std::endl;
7280 return line2;
7281}
7282int find_str(std::string val, std::string repl);
7283
7284GameApiParam convert_param(GameApi::EveryApi &ev, const std::vector<CodeGenLine> &lines, const std::vector<GameApiLine> &lines2, std::string api_name, std::string func_name, int i, std::string param, int j)
7285{
7286 std::vector<GameApiItem*> &funcs = g_all_functions_service->get_all_functions(ev);
7287 //static std::vector<GameApiItem*> funcs = all_functions(ev);
7288
7289 int s = funcs.size();
7290 std::string param_name;
7291 for(int ii=0;ii<s;ii++)
7292 {
7293 GameApiItem *item = funcs[ii];
7294 if (item->ApiName(0)==api_name && item->FuncName(0)==func_name)
7295 {
7296 param_name=item->ParamName(0,i);
7297 break;
7298 }
7299 }
7300 if (param_name=="") std::cout << "Warning: " << api_name << "::" << func_name << " param " << i << " name not found." << std::endl;
7301
7302 int s2 = lines.size();
7303 const CodeGenLine *res_line=0;
7304 const GameApiLine *res_line2=0;
7305 for(int i2=0;i2<s2;i2++)
7306 {
7307 const CodeGenLine &line = lines[i2];
7308 if (param==line.label_num)
7309 {
7310 res_line = &lines[i2];
7311 res_line2 = &lines2[i2];
7312 }
7313 }
7314
7315
7316 GameApiParam res;
7317 res.param_name = param_name;
7318 res.value = res_line?res_line2->uid:param;
7319
7320 int p0 = find_str(param,"[");
7321 int p1 = find_str(param,"]");
7322 if (p0!=-1 && p1!=-1)
7323 { // multiple returns
7324 std::string label = param.substr(0,p0);
7325 std::string index = param.substr(p0+1,p1-p0-1);
7326 int index2 =0;
7327
7328 std::stringstream ss(index);
7329 ss >> index2;
7330 std::string res_param="";
7331
7332 int s2 = lines.size();
7333 const CodeGenLine *res_line=0;
7334 const GameApiLine *res_line2=0;
7335 for(int i2=0;i2<s2;i2++)
7336 {
7337 const CodeGenLine &line = lines[i2];
7338 if (label==line.label_num)
7339 {
7340 res_line = &lines[i2];
7341 res_line2 = &lines2[i2];
7342 res_param = res_line2->uid;
7343 }
7344 }
7345
7346 res.value = res_param;
7347 j=index2;
7348 }
7349
7350
7351 int pos = find_str(param,"std::vector<");
7352 int posA = find_str(param,"std::vector&lt;");
7353 if (pos!=-1 || posA!=-1)
7354 {
7355 int delta = 13;
7356 if (posA!=-1) delta=16;
7357 int pos0 = find_str(param,">");
7358 int pos0b = find_str(param,"&gt;");
7359 if (pos0==-1) pos0=pos0b;
7360 std::string type = param.substr(pos+delta,pos0-pos-delta);
7361
7362
7363 std::string res_param = "[";
7364 // if (delta==15) res_param="std::vector&lt;" + type + "&gt;{";
7365 int pos1 = find_str(param,"{");
7366 int pos2 = find_str(param,"}");
7367 std::string arr_params = param.substr(pos1+1,(pos2-1)-pos1);
7368 int pp = 0;
7369 std::string rest = arr_params;
7370 //std::cout << "ARR PARAMS:" << arr_params << std::endl;
7371
7372 while((pp=find_str(rest,","))!=-1)
7373 {
7374 std::string param = rest.substr(0,pp);
7375 //std::cout << "PARAM:" << param << std::endl;
7376
7377 int s2 = lines.size();
7378 const CodeGenLine *res_line=0;
7379 const GameApiLine *res_line2=0;
7380 for(int i2=0;i2<s2;i2++)
7381 {
7382 const CodeGenLine &line = lines[i2];
7383 if (param==line.label_num)
7384 {
7385 res_line = &lines[i2];
7386 res_line2 = &lines2[i2];
7387 res_param += res_line2->uid + ",";
7388 }
7389 }
7390 rest = rest.substr(pp+1);
7391 }
7392 std::string param = rest;
7393 //std::cout << "PARAM:" << param << std::endl;
7394 int s2 = lines.size();
7395 const CodeGenLine *res_line=0;
7396 const GameApiLine *res_line2=0;
7397 for(int i2=0;i2<s2;i2++)
7398 {
7399 const CodeGenLine &line = lines[i2];
7400 if (param==line.label_num)
7401 {
7402 res_line = &lines[i2];
7403 res_line2 = &lines2[i2];
7404 res_param += res_line2->uid;
7405 }
7406 }
7407 res_param+="]";
7408 //std::cout << "RESVALUE:" << res_param << std::endl;
7409 res.value = res_param;
7410 }
7411
7412
7413
7414 res.is_array = res_line && res_line->return_type.size()>0 && res_line->return_type[0]=='[' && res_line->return_type[res_line->return_type.size()-1]==']' ? true : false;
7415 res.array_return_target = res.is_array ? const_cast<GameApiLine*>(res_line2) : 0; // GameApiLine
7416 res.j = j;
7417 return res;
7418}
7419
7420struct CodeGenVectors {
7421 std::vector<std::string> params;
7422 std::vector<int> j;
7423};
7424
7425
7426GameApiLine convert_line(GameApi::EveryApi &ev, std::vector<CodeGenLine> &lines, std::vector<GameApiLine> &lines2, const std::vector<CodeGenVectors> &vecs, CodeGenLine l, int i)
7427{
7428 static int uid = 3333;
7429 uid++;
7430
7431 std::stringstream ss; ss << "uid" << uid;
7432
7433 int pos = lines2.size();
7434 int pos_x = pos % 6;
7435 int pos_y = pos / 6;
7436 //std::cout << "POS:" << pos << " " << pos_x << " " << pos_y << std::endl;
7437
7438
7439
7440 float start_x = 200.0;
7441 float start_y = 200.0;
7442
7443 float delta_x = 200.0;
7444 float delta_y = 200.0;
7445
7446 std::vector<GameApiItem*> &funcs = g_all_functions_service->get_all_functions(ev);
7447 //static std::vector<GameApiItem*> funcs = all_functions(ev);
7448 int s2 = funcs.size();
7449 std::string module_name = "";
7450 GameApiItem *res_item = 0;
7451 for(int k=0;k<s2;k++)
7452 {
7453 GameApiItem *item = funcs[k];
7454 if (item->ApiName(0)==l.api_name && item->FuncName(0)==l.func_name)
7455 {
7456 module_name = item->Name(0);
7457 res_item = item;
7458 break;
7459 }
7460 }
7461
7462
7463 GameApiLine res;
7464 res.x = l.x != -1 ? l.x : start_x + pos_x*delta_x;
7465 res.y = l.y != -1 ? l.y : start_y + pos_y*delta_y;
7466 res.module_name = module_name;
7467 res.uid = ss.str();
7468 res.j = i<vecs.size()&&vecs[i].j.size()>0?vecs[i].j[0]:0;
7469 res.sz = i<vecs.size()?vecs[i].j.size():1;
7470 res.array_return = l.return_type.size()>0 && l.return_type[0]=='[' && l.return_type[l.return_type.size()-1]==']';
7471
7472 int s = std::max(int(l.params.size()),res_item->ParamCount(0));
7473 for(int i=0;i<s;i++)
7474 {
7475 if (i>=l.params.size())
7476 {
7477 std::string param = res_item->ParamDefault(0,i);
7478 int j = l.j[i];
7479 res.params.push_back(convert_param(ev,lines,lines2,l.api_name,l.func_name,i,param,j));
7480 }
7481 else {
7482 std::string param = l.params[i];
7483 //std::string link = l.params_linkage[i];
7484 int j = l.j[i];
7485
7486 res.params.push_back(convert_param(ev,lines,lines2,l.api_name,l.func_name,i,param,j));
7487 }
7488 }
7489 return res;
7490}
7491
7492std::vector<GameApiLine> convert_script(GameApi::EveryApi &ev, std::string script);
7493
7494GameApiFunction convert_lines_to_functions(std::vector<GameApiLine> lines)
7495{
7496 GameApiFunction res;
7497 res.function_name = "test";
7498 res.param_names = std::vector<std::string>();
7499 res.param_types = std::vector<std::string>();
7500 res.lines = lines;
7501 return res;
7502}
7503GameApiModule convert_function_to_module(GameApiFunction f)
7504{
7505 GameApiModule m;
7506 m.funcs.push_back(f);
7507 return m;
7508}
7509
7510void save_gameapi(const GameApiModule &mod, std::string filename);
7511
7512void save_mod_txt_from_script_file(GameApi::EveryApi &ev, std::string input_script_filename, std::string output_mod_txt_filename)
7513{
7514 std::ifstream input(input_script_filename);
7515 std::stringstream buffer;
7516 buffer << input.rdbuf();
7517 std::string script = buffer.str();
7518 std::vector<GameApiLine> lines = convert_script(ev,script);
7519 GameApiFunction f = convert_lines_to_functions(lines);
7520 GameApiModule m = convert_function_to_module(f);
7521 save_gameapi(m,output_mod_txt_filename);
7522}
7523
7524GameApiModule load_gameapi(GameApi::EveryApi &ev, std::string filename);
7525
7526bool line_match(const GameApiLine &l1, const GameApiLine &l2)
7527{
7528 if (l1.module_name==l2.module_name)
7529 {
7530 int s1 = l1.params.size();
7531 int s2 = l2.params.size();
7532 if (s1==s2)
7533 {
7534 bool match=true;
7535 for(int k=0;k<s1;k++)
7536 {
7537 if (l1.params[k].value.size()>3 && l1.params[k].value[0]=='u' && l1.params[k].value[1]=='i' && l1.params[k].value[2]=='d')
7538 {
7539 if (l1.params[k].value != l2.params[k].value) match=false;
7540 }
7541 if (l2.params[k].value.size()>3 && l2.params[k].value[0]=='u' && l2.params[k].value[1]=='i' && l2.params[k].value[2]=='d')
7542 {
7543 if (l1.params[k].value != l2.params[k].value) match=false;
7544 }
7545 }
7546 return match;
7547 }
7548 }
7549 return false;
7550}
7551
7552
7553void transfer_x_y_from_old_mod_txt_to_new_one(GameApi::EveryApi &ev,
7554 std::string old_mod_filename,
7555 GameApiModule &mod)
7556{
7557 GameApiModule mod0 = load_gameapi(ev,old_mod_filename);
7558 GameApiFunction &f0 = mod0.funcs[0];
7559 GameApiFunction &f1 = mod.funcs[0];
7560 int s = f1.lines.size();
7561 int cursor = 0;
7562 for(int i=0;i<s;i++)
7563 {
7564 GameApiLine &l1 = f1.lines[i];
7565 GameApiLine &l2 = f0.lines[cursor];
7566 bool match = line_match(l1,l2);
7567 if (match) {
7568 l1.x = l2.x;
7569 l1.y = l2.y;
7570 cursor++;
7571 continue;
7572 }
7573 int diff = 1;
7574 repeat:
7575 {
7576 bool done = false;
7577 if (cursor+diff<f0.lines.size()) {
7578 GameApiLine &l2d = f0.lines[cursor+diff];
7579 bool match1 = line_match(l1,l2d);
7580 if (match1)
7581 {
7582 l1.x = l2d.x;
7583 l1.y = l2d.y;
7584 cursor+=diff;
7585 continue;
7586 }
7587 done = true;
7588 }
7589 if (i+diff<f1.lines.size()) {
7590 GameApiLine &l1d = f1.lines[i+diff];
7591 bool match2 = line_match(l1d,l2);
7592 if (match2)
7593 {
7594 l1d.x = l2.x;
7595 l1d.y = l2.y;
7596 i+=diff-1;
7597 continue;
7598 }
7599 done = true;
7600 }
7601 if (!done) continue;
7602 }
7603 // no match found...
7604 diff++;
7605 goto repeat;
7606
7607 }
7608}
7609
7610IMPORT void save_mod_txt_from_script_file2(GameApi::EveryApi &ev, std::string input_script_filename, std::string output_mod_txt_filename)
7611{
7612 if (!file_exists(output_mod_txt_filename)) {
7613 std::ifstream input(input_script_filename);
7614 std::stringstream buffer;
7615 buffer << input.rdbuf();
7616 std::string script = buffer.str();
7617 std::vector<GameApiLine> lines = convert_script(ev,script);
7618 GameApiFunction f = convert_lines_to_functions(lines);
7619 GameApiModule m = convert_function_to_module(f);
7620 save_gameapi(m,output_mod_txt_filename);
7621 } else {
7622 std::ifstream input(input_script_filename);
7623 std::stringstream buffer;
7624 buffer << input.rdbuf();
7625 std::string script = buffer.str();
7626 std::vector<GameApiLine> lines = convert_script(ev,script);
7627 GameApiFunction f = convert_lines_to_functions(lines);
7628 GameApiModule m = convert_function_to_module(f);
7629
7630 transfer_x_y_from_old_mod_txt_to_new_one(ev,
7631 output_mod_txt_filename,
7632 m);
7633 save_gameapi(m,output_mod_txt_filename);
7634 }
7635}
7636
7637
7638
7639
7640std::string striphomepage(std::string url);
7641
7642std::map<std::string, std::vector<unsigned char>*> load_url_buffers;
7643void onerror_cb(unsigned int tmp, void *arg, int, const char*)
7644{
7645 std::cout << "ERROR: onerror_cb" << std::endl;
7646 char *url = (char*)arg;
7647 std::string url_str(url);
7648 std::string url_only(striphomepage(url_str));
7649
7650 load_url_buffers[url_only] = (std::vector<unsigned char>*)-1;
7652 std::cout << "async_pending_count dec (onerror_cb) -->" << async_pending_count << std::endl;
7653}
7654std::string stripprefix(std::string s);
7655void ProgressBar(int num, int val, int max, std::string label);
7656void onprogress_cb(unsigned int tmp, void *, int, int) { }
7657void onload_cb(unsigned int tmp, void *arg, void *data, unsigned int datasize)
7658{
7659 std::vector<unsigned char> buffer;
7660 unsigned char *dataptr = (unsigned char*)data;
7661 int dt = datasize;
7662 for(int i=0;i<dt;i++) { buffer.push_back(dataptr[i]); }
7663
7664 char *url = (char*)arg;
7665 std::string url_str(url);
7666 std::string url_only(striphomepage(url_str));
7667 //std::cout << "url loading complete! " << url_only << std::endl;
7668
7669 load_url_buffers[url_only] = new std::vector<unsigned char>(buffer);
7671 std::cout << "async_pending_count dec (onlosd_cb) -->" << async_pending_count << std::endl;
7672 { // progressbar
7673 std::string url_plain(stripprefix(url_only));
7674 int s = url_plain.size();
7675 int sum=0;
7676 for(int i=0;i<s;i++) sum+=int(url_plain[i]);
7677 sum = sum % 1000;
7678 ProgressBar(sum,15,15,url_plain);
7679 }
7680
7681}
7682
7683#if 0
7684ASyncData async_data[] = {
7685 { "font_api", "newfont", 0 },
7686 { "font_api", "load_font", 0 },
7687 { "mainloop_api", "load_song", 2 },
7688#ifndef HAS_POPEN
7689 { "polygon_api", "p_url", 1 },
7690#endif
7691 { "polygon_api", "p_url_mtl", 1 },
7692#ifndef HAS_POPEN
7693 { "polygon_api", "p_mtl", 1 },
7694#endif
7695 { "polygon_api", "p_mtl", 2 },
7696#ifndef HAS_POPEN
7697 { "polygon_api", "p_mtl2", 1 },
7698#endif
7699 { "polygon_api", "p_mtl2", 2 },
7700 { "mainloop_api", "fps_display", 2 },
7701 { "mainloop_api", "score_display", 2 },
7702 { "mainloop_api", "time_display", 2 },
7703 //{ "mainloop_api", "load_P_script", 1 },
7704 //{ "mainloop_api", "load_P_script_array", 1 },
7705 //{ "mainloop_api", "load_ML_script", 1 },
7706 //{ "mainloop_api", "load_MN_script", 1 },
7707 //{ "mainloop_api", "load_MT_script", 1 },
7708 //{ "mainloop_api", "load_ML_script_array", 1 },
7709 //{ "mainloop_api", "load_BM_script", 1 },
7710 //{ "mainloop_api", "load_BM_script_array", 1 },
7711 { "polygon_api", "p_ds_url", 1 },
7712 { "bitmap_api", "intbitmap_loader", 0 },
7713 { "mainloop_api", "restart_screen", 2 },
7714 { "tracker_api", "play_wave_via_keypress", 2 },
7715 { "mainloop_api", "playback_keypresses", 1 },
7716 { "bitmap_api", "world_from_bitmap3", 2 },
7717 //{ "bitmap_api", "chai_bm", 0 }
7718 { "mainloop_api", "state_int_fetcher", 0 },
7719 { "mainloop_api", "state_speed_movement", 1 },
7720 // Note, this is function name, not user interface name.
7721 { "low_frame_api", "low_sprite_array", 1 },
7722 { "low_frame_api", "low_build_world", 1 },
7723 { "low_frame_api", "low_enemy_draw", 1 },
7724 { "low_frame_api", "low_enemy_draw2", 1 },
7725 { "polygon_api", "stl_load", 0 },
7726 { "font_api", "load_font_dump", 0 },
7727 { "polygon_api", "load_scene", 1 },
7728 //{ "polygon_api", "gltf_load", 2 },
7729 //{ "polygon_api", "gltf_load_bitmap", 2 },
7730 //{ "materials_api", "gltf_material", 2 },
7731 //{ "materials_api", "gltf_material_manual", 2 },
7732 //{ "materials_api", "gltf_material_env", 2 },
7733 { "polygon_api", "bar_chart", 1 },
7734 { "polygon_api", "bar_chart2", 1 },
7735 { "polygon_api", "piechart_full", 4 },
7736 //{ "mainloop_api", "gltf_mesh", 2 },
7737 //{ "mainloop_api", "gltf_mesh_all", 2 },
7738 //{ "mainloop_api", "gltf_mesh_all_env", 2 },
7739 //{ "mainloop_api", "gltf_node", 2 },
7740 //{ "mainloop_api", "gltf_scene", 2 },
7741 //{ "mainloop_api", "gltf_anim", 2 },
7742 //{ "mainloop_api", "gltf_anim2", 2 },
7743 //{ "mainloop_api", "gltf_skeleton", 2 },
7744 { "mainloop_api", "matrix_range_check", 3 },
7745 { "font_api", "draw_text_large", 2 },
7746 { "bitmap_api", "loadbitmapfromurl", 0},
7747 { "mainloop_api", "parse_areatype", 1},
7748 { "mainloop_api", "create_landscape", 1},
7749 { "mainloop_api", "bind_obj_type", 1},
7750 { "mainloop_api", "read_obj_pos", 0},
7751 { "polygon_api", "mesh_anim", 6},
7752 { "materials_api", "many_texture_id_material", 1},
7753 { "bitmap_api", "script_bitmap", 0},
7754 { "points_api", "ply_pts", 0 },
7755 { "points_api", "ply_faces", 0 },
7756 { "mainloop_api", "memmap_window2", 1 },
7757 { "mainloop_api", "memmap_window3", 1 },
7758 { "mainloop_api", "memmap_window3", 2 },
7759 { "mainloop_api", "memmap_window3", 3 },
7760 { "mainloop_api", "memmap_window3", 4 },
7761 { "mainloop_api", "memmap_window3", 5 },
7762 { "mainloop_api", "memmap_window3", 6 },
7763 { "polygon_api", "ske_anim", 4 },
7764 { "polygon_api", "ske_anim2", 4 },
7765 { "lines_api", "li_url", 0 },
7766 //{ "mainloop_api", "gltf_anim_skeleton", 2},
7767 //{ "polygon_api", "gltf_split_faces2", 2},
7768 //{ "mainloop_api", "gltf_anim4", 2},
7769 //{ "mainloop_api", "gltf_scene_anim", 2},
7770 { "mainloop_api", "async_url", 0},
7771 //{ "materials_api", "gltf_anim_material", 2},
7772 //{ "materials_api", "gltf_anim_material2", 2},
7773 { "mainloop_api", "tunnel_tree", 3},
7774 //{ "mainloop_api", "async_gltf", 2},
7775 { "materials_api", "gltf_material_from_file", 1},
7776 { "mainloop_api", "gltf_loadKK", 1},
7777 { "mainloop_api", "gltf_loadKK2", 0},
7778 { "mainloop_api", "html_url", 0 },
7779 { "mainloop_api", "gltf_load_sketchfab_zip", 0 },
7780 { "mainloop_api", "game", 3 },
7781 { "mainloop_api", "game", 4 },
7782 { "mainloop_api", "game", 5 },
7783 { "mainloop_api", "game", 6 },
7784 { "matrices_api", "render_ms_files", 3 },
7785 { "matrices_api", "render_ms_files2", 3 },
7786 { "voxel_api", "voxel_from_bitmaps", 1 },
7787 { "points_api", "load_points", 0 },
7788 { "bitmap_api", "debug_number", 4},
7789 { "bitmap_api", "video_source", 0},
7790 { "mainloop_api", "load_ML_script3",1},
7791 { "voxel_api", "vox_voxel", 1},
7792 { "voxel_api", "vox_voxel2", 1},
7793 { "voxel_api", "vox_voxel3", 1},
7794 { "voxel_api", "vox_cubes", 1},
7795 { "voxel_api", "vox_ml", 1},
7796 { "voxel_api", "vox_bind_ml",1},
7797 { "voxel_api", "vox_ml2", 1},
7798 { "voxel_api", "vox_bind_ml2",1},
7799 { "voxel_api", "lod_vox", 1},
7800 { "texture_api", "videofile_txid_generic", 3},
7801 { "mainloop_api", "AI_modified", 2},
7802 { "mainloop_api", "AI_generated", 2}
7803};
7804
7805
7806IMPORT ASyncData *g_async_ptr = &async_data[0];
7807IMPORT int g_async_count = sizeof(async_data)/sizeof(ASyncData);
7808
7809#endif
7810
7811
7812ASyncData async_data2[] = {
7813 { "polygon_api", "p_mtl", 1 },
7814 { "polygon_api", "p_mtl2", 1 },
7815 { "polygon_api", "p_url", 1 }
7816};
7817IMPORT ASyncData *g_async_ptr2 = &async_data2[0];
7818IMPORT int g_async_count2 = sizeof(async_data2)/sizeof(ASyncData);
7819
7820
7821
7822std::vector<std::string> g_async_loaded_urls;
7823bool is_async_loaded_urls_in_vec(std::string url)
7824{
7825 int s= g_async_loaded_urls.size();
7826 for(int i=0;i<s;i++) {
7827 if (g_async_loaded_urls[i]==url) return true;
7828 }
7829 return false;
7830}
7831struct ASyncCallback { void (*fptr)(void*); void *data; };
7832ASyncCallback *rem_async_cb(std::string url);
7833
7834#if 0
7835struct del_map
7836{
7837 void del_url(std::string url)
7838 {
7839 //std::vector<unsigned char>* v = load_url_buffers_async[url];
7840 //delete v;
7841 //load_url_buffers_async[url] = 0;
7842 }
7843 ~del_map() {
7844 //std::map<std::string,std::vector<unsigned char>*>::iterator i = load_url_buffers_async.begin();
7845 //for(;i!=load_url_buffers_async.end();i++)
7846 // {
7847 // std::pair<std::string,std::vector<unsigned char>*> p = *i;
7848 // std::cout << std::hex << (long)p.second << "::" << p.first << std::endl;
7849 // delete p.second;
7850 // }
7851 }
7852 std::map<std::string, std::vector<unsigned char>* > load_url_buffers_async;
7853};
7854extern del_map g_del_map;
7855#endif
7856
7857class FetchInBlocks;
7858
7859
7861
7862
7863//extern std::map<std::string, std::vector<unsigned char>* > load_url_buffers_async;
7864
7865void async_cb(void *data)
7866{
7867 //ASyncCallback *cb = (ASyncCallback*)data;
7868
7869}
7870std::vector<ASyncCallback*> g_async_vec;
7871std::vector<std::string> g_async_vec2;
7872
7874{
7875 int s = g_async_vec.size();
7876 for(int i=0;i<s;i++) {
7877 ASyncCallback *cb = g_async_vec[i];
7878 std::string url = g_async_vec2[i];
7879
7880 if (cb && g_del_map.async_find(std::string("load_url.php?url=") + url) && g_del_map.async_get2(std::string("load_url.php?url=") + url) != 0) {
7881 //std::cout << "Callback: " << url << std::endl;
7882 (*cb->fptr)(cb->data);
7883 g_async_vec[i] =0 ;
7884 }
7885 }
7886 //g_async_vec.clear();
7887}
7888
7889
7890
7891std::vector<std::string> g_extra_async_urls;
7892
7893bool is_in_vec(std::string url)
7894{
7895 int s = g_extra_async_urls.size();
7896 for(int i=0;i<s;i++) { if (g_extra_async_urls[i]==url) return true; }
7897 return false;
7898}
7899IMPORT std::vector<std::string> g_registered_urls;
7900bool is_in_registered(std::string url)
7901{
7902 int s = g_registered_urls.size();
7903 for(int i=0;i<s;i++) if (g_registered_urls[i]==url) return true;
7904 return false;
7905}
7906class RegisterUrl : public MainLoopItem
7907{
7908public:
7909 RegisterUrl(std::string url, MainLoopItem *next) : next(next) {
7910 g_registered_urls.push_back(url);
7911 }
7912 void Collect(CollectVisitor &vis) { next->Collect(vis); }
7913 void HeavyPrepare() { }
7914 virtual void Prepare() { next->Prepare(); }
7915 virtual void execute(MainLoopEnv &e) { next->execute(e); }
7916 virtual void handle_event(MainLoopEvent &e) { next->handle_event(e); }
7917 virtual std::vector<int> shader_id() { return next->shader_id(); }
7918
7919private:
7920 MainLoopItem *next;
7921};
7923{
7924 MainLoopItem *item = find_main_loop(e, ml);
7925 return add_main_loop(e, new RegisterUrl(url, item));
7926}
7927extern int g_async_load_count;
7928
7929/*
7930 std::string str_tolower(std::string s)
7931 {
7932 std::transform(s.begin(),s.end(),s.begin(), [](unsigned char c) { return std::tolower(c); } );
7933 return s;
7934 }
7935*/
7936std::string str_tolower(std::string s);
7937
7938void LoadUrls_async(GameApi::Env &e, const CodeGenLine &line, std::string homepage)
7939{
7940 //int s = sizeof(async_data)/sizeof(ASyncData);
7941 //for(int i=0;i<s;i++)
7942 // {
7943 //ASyncData &dt = async_data[i];
7944 //if (line.api_name == dt.api_name && line.func_name == dt.func_name)
7945 int s = line.param_names.size();
7946 for(int ii=0;ii<s;ii++)
7947 {
7948 //std::cout << "LoadUrls_async:" << line.param_names[ii] << std::endl;
7949 if (find_str(str_tolower(line.param_names[ii]),"url")!=-1)
7950 {
7952 int param_num = ii; //dt.param_num;
7953 std::string url = line.params[param_num];
7954
7955 //std::cout << "URL:" << url << std::endl;
7956
7957 if (!is_async_loaded_urls_in_vec(url)) {
7958 //std::cout << "LoadUrls_async Loading " << url << std::endl;
7959 //if (!g_cached_serv->is_cached(url)) {
7960 e.async_load_url(url,homepage);
7961 //}
7962 g_async_loaded_urls.push_back(url);
7963 } else {
7964 //std::cout << "LoadUrls_async Pushing " << url << std::endl;
7965
7966 ASyncCallback *cb = rem_async_cb(std::string("load_url.php?url=")+url);
7967 g_async_vec.push_back(cb);
7968 g_async_vec2.push_back(url);
7969
7970 }
7971 }
7972 }
7973}
7974IMPORT void InstallProgress(int num, std::string label, int max=15);
7975
7976void LoadUrls(const CodeGenLine &line, std::string homepage)
7977{
7978 return;
7979 //if (line.api_name!="bitmap_api" || line.func_name!="loadbitmapfromurl")
7980 // return;
7981#if 0
7982#ifdef EMSCRIPTEN
7983
7984 std::string url = line.params[0];
7985 std::cout << "loading url: " << url << std::endl;
7986
7987 // progress bar
7988 int s = url.size();
7989 int sum=0;
7990 for(int i=0;i<s;i++) sum+=int(url[i]);
7991 sum = sum % 1000;
7992 InstallProgress(sum,url);
7993
7994
7995 std::string url2 = "load_url.php";
7996 std::string urlend = "url=" + url + "&homepage=" + homepage;
7997 url = "load_url.php?url=" + url + "&homepage=" + homepage;
7998
7999 char *buf2 = new char[url2.size()+1];
8000 std::copy(url2.begin(), url2.end(), buf2);
8001 buf2[url2.size()]=0;
8002
8003 char *buf3 = new char[url.size()+1];
8004 std::copy(url.begin(), url.end(), buf3);
8005 buf3[url.size()]=0;
8006
8008 std::cout << "async_pending_count inc (LoadUrls) -->" << async_pending_count << std::endl;
8009
8010 LoadData *ld = new LoadData;
8011 ld->buf2 = buf2;
8012 ld->buf3 = buf3;
8013 ld->url = oldurl;
8014 ld->url3 = url3;
8015 emscripten_idb_async_exists("gameapi", oldurl.c_str(), (void*)ld, &idb_exists2, &idb_error2);
8016 //emscripten_async_wget_data(buf2, (void*)buf2 , &onload_cb, &onerror_cb);
8017 emscripten_async_wget2_data(buf2, "POST", urlend.c_str(), (void*)buf3, 1, &onload_cb, &onerror_cb, &onprogress_cb);
8018#endif
8019#endif
8020}
8021extern bool g_concurrent_download;
8022
8023void LoadUrls_codegen(GameApi::Env &env, std::vector<CodeGenLine> vec, std::string homepage)
8024{
8025 int s2 = vec.size();
8026 for(int i=0;i<s2;i++) {
8027 CodeGenLine l = vec[i];
8028 if (l.func_name=="concurrent_download") { g_concurrent_download=true; }
8029 }
8030
8031 int s = vec.size();
8032 for(int i=0;i<s;i++) {
8033 CodeGenLine l = vec[i];
8034 LoadUrls(l, homepage);
8035 LoadUrls_async(env,l, homepage);
8036 }
8037}
8038
8039struct FunctionSpec
8040{
8041 bool is_function;
8042 std::string name;
8043 std::vector<std::string> param_names;
8044};
8045
8046struct FunctionCallSpec
8047{
8048 bool is_function_call;
8049 std::string return_type;
8050 std::string label_num;
8051 std::string func_name;
8052 std::vector<std::string> params;
8053};
8054
8055FunctionCallSpec is_funccall(int lineno, std::string line)
8056{
8057 FunctionCallSpec spec;
8058 spec.is_function_call = false;
8059 int first_space = find_char(line,0,' ');
8060 if (first_space==-1) { return spec; }
8061 std::string return_type = line.substr(0,first_space);
8062 if (line[first_space+1]!='I') { return spec; }
8063 int num_end_iterator = extend_until(line,first_space+2,"0123456789");
8064 if (num_end_iterator==-1) { return spec; }
8065 std::string num = line.substr(first_space+2,num_end_iterator-first_space-2);
8066 if (line[num_end_iterator]!='=') { return spec; }
8067 if (line[num_end_iterator+1]=='e' && line[num_end_iterator+2]=='v' && line[num_end_iterator+3]=='.') { return spec; }
8068 int brace_pos = find_char(line,num_end_iterator+1,'(');
8069 if (brace_pos==-1) return spec;
8070 std::string func_name = line.substr(num_end_iterator+1,brace_pos-num_end_iterator-1);
8071 int pos = brace_pos+1;
8072 int close_brace_pos = find_char(line,pos,')');
8073 int comma_pos = find_char(line,pos,',');
8074 std::vector<std::string> params;
8075 while(close_brace_pos!=-1 && comma_pos!=-1) {
8076 int next_pos = comma_pos!=-1 ? comma_pos : close_brace_pos;
8077 std::string param = line.substr(pos,next_pos-pos);
8078 params.push_back(param);
8079
8080 pos = next_pos+1;
8081 close_brace_pos = find_char(line,pos,')');
8082 comma_pos = find_char(line,pos,',');
8083 }
8084 spec.is_function_call=true;
8085 spec.func_name = func_name;
8086 spec.params = params;
8087 return spec;
8088}
8089
8090
8091FunctionSpec is_line_function(int lineno, std::string line)
8092{
8093 std::stringstream ss;
8094 std::string name;
8095 char ch1;
8096 int pos = extend_until(line,0," \t");
8097 if (pos!=-1) {
8098 std::string str = line.substr(pos,8);
8099 if (str!="function") { FunctionSpec spec; spec.is_function=false; return spec; }
8100 } else { FunctionSpec spec; spec.is_function=false; return spec; }
8101 int pos2 = find_one(line,pos,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", false);
8102 if (pos2==-1) { FunctionSpec spec; spec.is_function=false; return spec; }
8103 name = line.substr(pos,pos2-pos);
8104 std::cout << "Function name:" << name << std::endl;
8105 char ch=line[pos2];
8106 if (ch!='(') { FunctionSpec spec; spec.is_function=false; return spec; }
8107 std::vector<std::string> param_names;
8108 int pos3;
8109 for(;;)
8110 {
8111 pos3 = extend_until(line,pos2+1,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
8112 if (pos3==-1) break;
8113 std::string param_name = line.substr(pos2+1,pos3-pos2-1);
8114 param_names.push_back(param_name);
8115 if (line[pos3]==')') break;
8116 if (line[pos3]!=',') { std::cout << "Line: " << lineno << " parse error at '" << line[pos3] << "'!" << std::endl; FunctionSpec spec; spec.is_function=false; return spec; }
8117 pos2 = pos3;
8118 }
8119 int pos4 = extend_until(line,pos3+1," \t");
8120 if (pos4!=-1) {
8121 char ch2 = line[pos4];
8122 if (ch2 != '{') { std::cout << "Line: " << lineno << " parse error at '" << ch2 << "'!" << std::endl; FunctionSpec spec; spec.is_function=false; return spec; }
8123 }
8124
8125 FunctionSpec spec;
8126 spec.is_function = true;
8127 spec.name = name;
8128 spec.param_names = param_names;
8129 return spec;
8130}
8131bool is_line_function_end(std::string line)
8132{
8133 int pos = extend_until(line,0," \t");
8134 int ch = line[pos];
8135 return ch=='}';
8136}
8137
8138struct FunctionImpl4
8139{
8140 std::string name;
8141 std::vector<std::string> param_names;
8142 std::vector<CodeGenLine> impl;
8143};
8144
8145
8146std::vector<CodeGenLine> parse_codegen(GameApi::Env &env, GameApi::EveryApi &ev, std::string text, int &error_line_num, std::vector<FunctionImpl4> &functions)
8147{
8148 int idx = 0;
8149 int old_idx = 0;
8150 int line_num = 0;
8151 error_line_num = 0;
8152 std::vector<std::vector<CodeGenLine> > linestack;
8153 std::vector<FunctionImpl4> stack;
8154 std::vector<CodeGenLine> vec;
8155 std::vector<GameApiItem*> &funcs = g_all_functions_service->get_all_functions(ev);
8156
8157 // static std::vector<GameApiItem*> funcs = all_functions(ev);
8158 std::string homepage = ev.mainloop_api.get_homepage_url();
8159 while((idx=find_char(text, idx, '\n'))!= -1)
8160 {
8161 std::string line = text.substr(old_idx, idx-old_idx-1);
8162 //std::cout << "Line:" << line << std::endl;
8163
8164 FunctionSpec s = is_line_function(line_num,line);
8165 if (s.is_function) {
8166 FunctionImpl4 impl;
8167 impl.name = s.name;
8168 impl.param_names = s.param_names;
8169 stack.push_back(impl);
8170 linestack.push_back(vec);
8171 vec.clear();
8172 }
8173 bool sb = is_line_function_end(line);
8174 if (sb && stack.size()==0) { std::cout << "ERROR: function nesting problem!" << std::endl; error_line_num = line_num; return vec; }
8175 if (sb && stack.size()>0)
8176 {
8177 FunctionImpl4 impl = stack[stack.size()-1];
8178 stack.pop_back();
8179 impl.impl = vec;
8180 vec = linestack[linestack.size()-1];
8181 linestack.pop_back();
8182 functions.push_back(impl);
8183 }
8184 FunctionCallSpec call = is_funccall(line_num,line);
8185 if (call.is_function_call)
8186 {
8187 CodeGenLine line2;
8188 line2.return_type = call.return_type;
8189 line2.label_num = call.label_num;
8190 line2.api_name = "@";
8191 line2.func_name = call.func_name;
8192 line2.params = call.params;
8193 vec.push_back(line2);
8194 line_num++;
8195 old_idx = idx+1;
8196 idx++;
8197 continue;
8198 }
8199
8200 if (line.size()<10) {
8201 line_num++;
8202 old_idx = idx+1;
8203 idx++;
8204 continue;
8205 }
8206 CodeGenLine l = parse_codegen_line(ev,line);
8207 CodeGenLineErrorCheck(l, funcs);
8208 if (l.return_type=="@") {
8209 std::cout << "ERROR:" << line << std::endl;
8210 error_line_num = line_num; return vec; }
8211 //LoadUrls(l, homepage);
8212 //LoadUrls_async(env,l, homepage);
8213 vec.push_back(l);
8214 line_num++;
8215#if 1
8216 if (line_num > 1800) {
8217 // quick exit if line_num is larger than 400, for line number misuse.
8218 std::cout << "Number of lines in CodeGen is limited to 1800 lines" << std::endl;
8219 exit(0);
8220 }
8221#endif
8222 old_idx = idx+1;
8223 idx++;
8224 }
8225 return vec;
8226}
8227
8228
8229std::pair<std::string, int> parse_multiple_return(std::string param)
8230{
8231 int s = param.size();
8232 int start = s;
8233 int end = s;
8234 for(int i=0;i<s;i++) {
8235 if (param[i]=='[') {
8236 start = i;
8237 }
8238 if (param[i]==']') {
8239 end = i;
8240 }
8241 }
8242 if (start==s || end==s) return std::make_pair(param,0);
8243 std::string res = param.substr(0,start);
8244 std::string index = param.substr(start+1,end-start-1);
8245 std::stringstream ss(index);
8246 int ii = 0;
8247 ss >> ii;
8248 //std::cout << "ParseMultipleReturn: " << res << " " << ii << std::endl;
8249 return std::make_pair(res,ii);
8250}
8251
8252void add_params_linkage(std::vector<CodeGenLine> &lines, std::vector<CodeGenVectors> &vectors, bool &error, std::map<std::string, int> env_map)
8253{
8254 error = false;
8255 // create line_map
8256 std::map<std::string, int> line_map;
8257 int s = lines.size();
8258 for(int i=0;i<s;i++)
8259 {
8260 CodeGenLine l = lines[i];
8261 line_map[l.label_num] = i;
8262 //std::cout << "Map: " << l.label_num << "=" << i << std::endl;
8263 }
8264
8265 // iterate all parameters
8266 int s2 = lines.size();
8267 for(int i=0;i<s2;i++)
8268 {
8269 CodeGenLine l = lines[i];
8270 int ss = l.params.size();
8271 for(int j=0;j<ss;j++)
8272 {
8273 std::string param_value = l.params[j];
8274 std::string param_linkage = "";
8275 // TODO std::vector types
8276 std::pair<std::string,int> pp = parse_multiple_return(param_value);
8277 int jj=0;
8278 if (pp.first.size()>0 && pp.first[0]=='I' && line_map.find(pp.first)!=line_map.end())
8279 {
8280 int linkage = line_map[pp.first];
8281 //if (!linkage) { std::cout << "Param not found (multiple return)! " << pp.first << std::endl; }
8282 //std::cout << "LINKAGE1" << linkage << std::endl;
8283 std::stringstream ss;
8284 ss << linkage;
8285 param_linkage = ss.str();
8286 jj = pp.second;
8287 } else if (pp.first[0]=='I') {
8288 std::cout << "Param not found (multiple return+find failed)" << pp.first << std::endl;
8289 std::cout << l.return_type << " " << l.api_name << "::" << l.func_name << std::endl;
8290 }
8291 if (param_value.size()>strlen("std::vector<"))
8292 {
8293 //std::cout << "Check Array" << param_value << std::endl;
8294 std::string substr = param_value.substr(0,strlen("std::vector<"));
8295 if (substr=="std::vector<")
8296 { // array
8297 //std::cout << "Is Array" << param_value << std::endl;
8298 int pos = find_char(param_value, 13, '>');
8299 if (pos==-1) { error = true; return; }
8300 std::string type = param_value.substr(13,pos);
8301 if (param_value[pos+1]!='{') { error=true; return; }
8302 CodeGenVectors vec;
8303 pos+=2;
8304 while(1) {
8305 int pos2 = find_one(param_value, pos, ",}");
8306 if (pos2==pos+1) break;
8307 if (pos2==-1) { std::cout << "Error=true" << std::endl; std::cout << l.return_type << " " << l.api_name << "::" << l.func_name << std::endl; error=true; return; }
8308 std::string param = param_value.substr(pos,pos2-pos);
8309 //std::cout << "ArrParam: " << param << std::endl;
8310
8311 std::pair<std::string,int> pp2 = parse_multiple_return(param);
8312
8313 std::string param_linkage = "";
8314 if (pp2.first.size()>0 && pp2.first[0]=='I')
8315 {
8316 int linkage = line_map[pp2.first];
8317 std::map<std::string,int>::iterator ii2 = line_map.find(pp2.first);
8318 if (ii2==line_map.end()) {
8319 std::map<std::string,int>::iterator ii=line_map.begin();
8320 for(;ii!=line_map.end();ii++) { std::pair<std::string,int> p=*ii; std::cout << "LINE MAP CONTAINS: (" << p.first << " " << p.second << ")" << std::endl; }
8321 std::cout << "ERROR: Param not found! (multiple return)'" << pp2.first << "'"<< std::endl; std::cout << l.return_type << " " << l.api_name << "::" << l.func_name << std::endl; }
8322 /* THAT !linkage test was broken */
8323 std::stringstream ss;
8324 ss << linkage;
8325 param_linkage = ss.str();
8326 } else if (pp2.first.size()>0 && pp2.first[0]=='E')
8327 {
8328 int linkage = env_map[pp2.first];
8329 if (!linkage) { std::cout << "ERROR: E not found! " << pp2.first << std::endl; std::cout << l.return_type << " " << l.api_name << "::" << l.func_name << std::endl; }
8330 //std::cout << "LINKAGE2" << linkage << std::endl;
8331 std::stringstream ss;
8332 ss << linkage;
8333 param_linkage = std::string("E") + ss.str();
8334 } else {
8335 param_linkage = param;
8336 }
8337 vec.params.push_back(param_linkage);
8338 vec.j.push_back(pp.second);
8339 pos = pos2+1;
8340 if (param_value[pos2]=='}') break;
8341 }
8342 vectors.push_back(vec);
8343 //std::cout << "LINKAGE3" << vectors.size()-1 << std::endl;
8344 std::stringstream ss;
8345 ss << vectors.size()-1;
8346 param_linkage = std::string("%") + ss.str();
8347 jj = -1;
8348 }
8349 }
8350 lines[i].params_linkage.push_back(param_linkage);
8351 lines[i].j.push_back(jj);
8352 }
8353
8354 }
8355}
8356
8357std::vector<GameApiLine> convert_script(GameApi::EveryApi &ev, std::string script)
8358{
8359 std::stringstream ss(script);
8360 std::string line;
8361 std::vector<CodeGenLine> lines;
8362 std::vector<GameApiLine> lines2;
8363 while(std::getline(ss,line))
8364 {
8365 CodeGenLine l = parse_codegen_line(ev,line);
8366 lines.push_back(l);
8367 }
8368 std::vector<CodeGenVectors> vecs;
8369 bool error=false;
8370 std::map<std::string,int> env_map;
8371 add_params_linkage(lines,vecs,error,env_map);
8372 if (error) { return std::vector<GameApiLine>(); }
8373 int s = lines.size();
8374 for(int i=0;i<s;i++)
8375 {
8376 GameApiLine l2 = convert_line(ev,lines,lines2,vecs,lines[i], i);
8377 lines2.push_back(l2);
8378 }
8379 return lines2;
8380}
8381
8382
8383void link_api_items(std::vector<CodeGenLine> &vec, std::vector<GameApiItem*> functions)
8384{
8385 int s = vec.size();
8386 for(int i=0;i<s;i++)
8387 {
8388 CodeGenLine &line = vec[i];
8389 int ss = functions.size();
8390 bool found = false;
8391 for(int j=0;j<ss;j++)
8392 {
8393 GameApiItem* item = functions[j];
8394 //std::cout << "Compare: " << line.func_name << " " << item->FuncName(0) << std::endl;
8395 //std::cout << "Compare2: " << line.api_name << " " << item->ApiName(0) << std::endl;
8396 if (line.func_name == item->FuncName(0) &&
8397 line.api_name == item->ApiName(0))
8398 {
8399 line.item = item;
8400 found=true; break;
8401 }
8402 }
8403 if (found==false) { std::cout << "NOT FOUND: " << line.api_name << " " << line.func_name<< std::endl; }
8404 }
8405}
8406
8407
8408bool is_num(std::string s)
8409{
8410 int ss = s.size();
8411 for(int i=0;i<ss;i++)
8412 {
8413 if (s[i]<'0' || s[i]>'9') return false;
8414 }
8415 return true;
8416}
8417
8418
8419bool has_envparams_markers(std::string s);
8420
8421std::vector<int> execute_api(GameApi::Env &ee, GameApi::EveryApi &ev, const std::vector<CodeGenLine> &vec, std::vector<CodeGenVectors> &vecvec, int /*line_num*/, GameApi::ExecuteEnv &e)
8422{
8423 std::vector<std::string> res_vec;
8424 int s2 = vec.size();
8425 int jj = 0;
8426 for(int ij=0;ij<s2;ij++)
8427 {
8428 CodeGenLine l = vec[ij];
8429
8430 int s = l.params_linkage.size();
8431 std::vector<std::string> params = l.params;
8432 for(int i=0;i<s;i++)
8433 {
8434 std::string link = l.params_linkage[i];
8435 int jj = l.j[i];
8436 if (link.size()>0 && link[0]=='E')
8437 {
8438 std::string sub = link.substr(1);
8439 std::stringstream ss(sub);
8440 int idx = 0;
8441 ss >> idx;
8442 int val = e.env[idx];
8443 std::stringstream ss2;
8444 ss2 << val;
8445 params[i] = ss2.str();
8446 }
8447 else if (link.size()>0 && link[0]=='%')
8448 {
8449 int j = i;
8450 std::string sub = link.substr(1);
8451 std::stringstream ss(sub);
8452 int idx = 0;
8453 ss >> idx;
8454 int s = vecvec[idx].params.size();
8455 //std::cout << "PARAMS_SIZE:" << s << std::endl;
8456 std::vector<std::string> params2;
8457 for(int i=0;i<s;i++)
8458 {
8459 std::string link = vecvec[idx].params[i];
8460 int jj = vecvec[idx].j[i];
8461 if (is_num(link)) {
8462 std::stringstream ss(link);
8463 int num;
8464 ss >> num;
8465 //std::stringstream ss2;
8466 //ss2 << jj;
8467 std::string val = res_vec[num];
8468 std::stringstream ss2(val);
8469 std::string val2;
8470 std::vector<std::string> vec;
8471 while(ss2>>val2) {
8472 //std::cout << "execute_api: " << val2 << std::endl;
8473 vec.push_back(val2);
8474 }
8475 //std::cout << "PARAM vec[jj]=" << jj << " " << vec[jj] << std::endl;
8476 params2.push_back( vec[jj] );
8477 } else {
8478 params2.push_back(link);
8479 }
8480 }
8481 std::string res = "[";
8482 for(int i=0;i<s;i++)
8483 {
8484 if (i!=0) { res+=","; }
8485 std::string p = params2[i];
8486 res+=p;
8487 }
8488 res+="]";
8489 params[j] = res;
8490 }
8491 else if (link!="")
8492 {
8493 std::stringstream ss(link);
8494 int num;
8495 ss >> num;
8496 //std::stringstream ss2;
8497 //ss2 << jj;
8498
8499 std::string val = num>=0&&num<res_vec.size()?res_vec[num]:"";
8500 std::stringstream ss2(val);
8501 std::string val2;
8502 std::vector<std::string> vec;
8503 while(ss2>>val2) { vec.push_back(val2); }
8504
8505 //std::cout << "LINK: " << jj << " " << vec[jj] << std::endl;
8506 if (jj>=0 && jj<vec.size())
8507 params[i] = vec[jj];
8508 else
8509 { params[i] = ""; std::cout << "ERROR: vec[jj] access outside bounds! (gameapi_gui.cc) jj=" << jj << " and i=" << i << std::endl;
8510 std::cout << l.api_name << "::" << l.func_name << std::endl;
8511 }
8512 }
8513 }
8514
8515
8516
8517
8518 //std::cout << "Execute: " << params << std::endl;
8519 std::stringstream sk3;
8520 std::string ret_type = l.item->ReturnType(0);
8521 int count = ret_type_count(ret_type);
8522 std::string res;
8523 int val = l.item->Execute(sk3, ee,ev, params, e,-1);
8524 if (count>1) {
8525 GameApi::ARR arr;
8526 arr.id = val;
8527 ArrayType *t = find_array(ee,arr);
8528 for(int jj=0;jj<count;jj++)
8529 {
8530 int val2 = t->vec[jj];
8531 std::stringstream ss2;
8532 ss2 << val2;
8533 //std::cout << "Return type id=" << val2 << std::endl;
8534 res+=ss2.str();
8535 if (jj!=count-1) res+=" ";
8536 }
8537 } else { std::stringstream ss; ss << val; res=ss.str(); }
8538 res_vec.push_back(res);
8539 }
8540 std::string s = res_vec[res_vec.size()-1];
8541 std::stringstream ss(s);
8542 int val = -1;
8543 std::vector<int> res_vec2;
8544 while(ss >> val) { res_vec2.push_back(val); }
8545 return res_vec2;
8546
8547}
8548
8549
8550std::string ToString(int num)
8551{
8552 std::stringstream ss;
8553 ss << num;
8554 return ss.str();
8555}
8556extern int g_async_load_count;
8558{
8560 int error_line_num = 0;
8561 std::vector<FunctionImpl4> funcs;
8562 std::vector<CodeGenLine> vec = parse_codegen(env, ev, text, error_line_num,funcs);
8563 if (vec.size()==0) {
8564 return std::make_pair(-1,std::string("Error at line ") + ToString(error_line_num));
8565 }
8566 std::vector<CodeGenVectors> vecvec;
8567 std::map<std::string, int> envmap = e.envmap;
8568 bool err2 = false;
8569 add_params_linkage(vec,vecvec,err2, envmap);
8570 if (err2) { return std::make_pair(-1, std::string("Error at params_linkage")); }
8571 std::vector<GameApiItem*> &functions = g_all_functions_service->get_all_functions(ev);
8572 //static std::vector<GameApiItem*> functions = all_functions(ev);
8573 link_api_items(vec, functions);
8574 std::vector<int> val = execute_api(env, ev, vec, vecvec, vec.size()-1, e);
8575 std::string homepage = ev.mainloop_api.get_homepage_url();
8576 LoadUrls_codegen(env,vec,homepage);
8577 CodeGenLine last = vec[vec.size()-1];
8578 if (last.return_type=="BLK") return std::make_pair(val[0],"OK");
8579 return std::make_pair(val[0],last.return_type);
8580 //if (last.return_type=="RUN") {
8581 // return std::make_pair(val,"RUN");
8582 //}
8583
8584 // return std::make_pair(val, "OK");
8585}
8586
8587template<class T>
8588class CodeGenBuilderValue : public BuilderValue<T>
8589{
8590public:
8591 CodeGenBuilderValue(GameApi::Env &env, GameApi::EveryApi &ev, std::string text, GameApi::ExecuteEnv &e) : env(env), ev(ev), text(text),e(e) { }
8592 T get() const
8593 {
8594 std::pair<int, std::string> p = execute_codegen(env, ev, text, e);
8595 T t;
8596 t.id = p.first;
8597 return t;
8598 }
8599private:
8600 GameApi::Env &env;
8601 GameApi::EveryApi &ev;
8602 std::string text;
8603 GameApi::ExecuteEnv &e;
8604};
8605std::pair<std::string,std::string> CodeGen_1(GameApi::EveryApi &ev, std::vector<std::string> params, std::vector<std::string> param_names, std::vector<std::string> param_type, std::string return_type, std::string api_name, std::string func_name,int j);
8606
8607
8608
8609#if USE_CHAISCRIPT
8610#define CHAISCRIPT_NO_THREADS
8613#endif
8614
8615
8616
8617DelApiItemF g_api_item_deleter;
8619
8620
8621std::vector<GameApiItem*> append_vectors(std::vector<GameApiItem*> vec1, std::vector<GameApiItem*> vec2);
8622
8623std::vector<GameApiItem*> append_vectors(std::vector<GameApiItem*> vec1, std::vector<GameApiItem*> vec2)
8624{
8625 int s = vec2.size();
8626 for(int i=0;i<s;i++)
8627 {
8628 vec1.push_back(vec2[i]);
8629 }
8630 return vec1;
8631}
8632
8633
8634
8635
8636
8637EXPORT std::vector<GameApiItem*> global_functions;
8638std::vector<GameApiItem*> all_functions(GameApi::EveryApi &ev)
8639{
8640 std::vector<GameApiItem*> v1 = bitmapapi_functions();
8641 std::vector<GameApiItem*> v2 = polygonapi_functions();
8642 std::vector<GameApiItem*> v3 = boolbitmapapi_functions();
8643 std::vector<GameApiItem*> v4 = floatbitmapapi_functions();
8644 std::vector<GameApiItem*> v5 = shadermoduleapi_functions();
8645 std::vector<GameApiItem*> v51 = shaderapi_functions();
8646 std::vector<GameApiItem*> v6 = linesapi_functions();
8647 std::vector<GameApiItem*> v7 = pointsapi_functions();
8648 std::vector<GameApiItem*> v8 = pointapi_functions();
8649 std::vector<GameApiItem*> v9 = vectorapi_functions();
8650 std::vector<GameApiItem*> va = volumeapi_functions();
8651 std::vector<GameApiItem*> vb = floatvolumeapi_functions();
8652 std::vector<GameApiItem*> vc = colorvolumeapi_functions();
8653 std::vector<GameApiItem*> vd = fontapi_functions();
8654 std::vector<GameApiItem*> ve = textureapi_functions();
8655 std::vector<GameApiItem*> vf = booleanopsapi_functions();
8656 std::vector<GameApiItem*> vg = global_functions;
8657 std::vector<GameApiItem*> vh = moveapi_functions();
8658 std::vector<GameApiItem*> vi = polydistfield_functions();
8659 std::vector<GameApiItem*> vj = waveform_functions();
8660 std::vector<GameApiItem*> vk = blocker_functions(ev);
8661 std::vector<GameApiItem*> vl = framebuffermoduleapi_functions();
8662
8663 std::vector<GameApiItem*> a1 = append_vectors(v1,v2);
8664 std::vector<GameApiItem*> a2 = append_vectors(v3,v4);
8665 std::vector<GameApiItem*> a3 = append_vectors(a1,a2);
8666 std::vector<GameApiItem*> a4 = append_vectors(a3, v5);
8667 std::vector<GameApiItem*> a5 = append_vectors(a4, v6);
8668 std::vector<GameApiItem*> a51 = append_vectors(a5, v51);
8669 std::vector<GameApiItem*> a6 = append_vectors(a51, v7);
8670 std::vector<GameApiItem*> a7 = append_vectors(a6, v8);
8671 std::vector<GameApiItem*> a8 = append_vectors(a7, v9);
8672 std::vector<GameApiItem*> a9 = append_vectors(a8, va);
8673 std::vector<GameApiItem*> aa = append_vectors(a9, vb);
8674 std::vector<GameApiItem*> ab = append_vectors(aa, vc);
8675 std::vector<GameApiItem*> ac = append_vectors(ab, vd);
8676 std::vector<GameApiItem*> ad = append_vectors(ac, ve);
8677 std::vector<GameApiItem*> ae = append_vectors(ad, vf);
8678 std::vector<GameApiItem*> af = append_vectors(ae, vg);
8679 std::vector<GameApiItem*> ag = append_vectors(af, vh);
8680 std::vector<GameApiItem*> ah = append_vectors(ag, vi);
8681 std::vector<GameApiItem*> ai = append_vectors(ah, vj);
8682 std::vector<GameApiItem*> aj = append_vectors(ai, vk);
8683 std::vector<GameApiItem*> ak = append_vectors(aj, vl);
8684 return ak;
8685}
8687{
8688 std::vector<GameApiItem*> funcs = bitmapapi_functions();
8689 GameApiItem *item = funcs[i];
8690 std::string name = item->Name(0);
8691 return name;
8692}
8694{
8695 std::vector<GameApiItem*> funcs = waveform_functions();
8696 GameApiItem *item = funcs[i];
8697 std::string name = item->Name(0);
8698 return name;
8699}
8701{
8702 std::vector<GameApiItem*> funcs = blocker_functions(ev);
8703 GameApiItem *item = funcs[i];
8704 std::string name = item->Name(0);
8705 return name;
8706}
8707
8709{
8710 std::vector<GameApiItem*> funcs = textureapi_functions();
8711 GameApiItem *item = funcs[i];
8712 std::string name = item->Name(0);
8713 return name;
8714}
8715
8717{
8718 std::vector<GameApiItem*> funcs = fontapi_functions();
8719 GameApiItem *item = funcs[i];
8720 std::string name = item->Name(0);
8721 return name;
8722}
8723
8725{
8726 std::vector<GameApiItem*> funcs = shadermoduleapi_functions();
8727 GameApiItem *item = funcs[i];
8728 std::string name = item->Name(0);
8729 return name;
8730}
8732{
8733 std::vector<GameApiItem*> funcs = shaderapi_functions();
8734 GameApiItem *item = funcs[i];
8735 std::string name = item->Name(0);
8736 return name;
8737}
8739{
8740 std::vector<GameApiItem*> funcs = framebuffermoduleapi_functions();
8741 GameApiItem *item = funcs[i];
8742 std::string name = item->Name(0);
8743 return name;
8744}
8746{
8747 std::vector<GameApiItem*> funcs = pointsapi_functions();
8748 GameApiItem *item = funcs[i];
8749 std::string name = item->Name(0);
8750 return name;
8751}
8753{
8754 std::vector<GameApiItem*> funcs = linesapi_functions();
8755 GameApiItem *item = funcs[i];
8756 std::string name = item->Name(0);
8757 return name;
8758}
8759
8761{
8762 std::vector<GameApiItem*> funcs = polygonapi_functions();
8763 GameApiItem *item = funcs[i];
8764 std::string name = item->Name(0);
8765 return name;
8766}
8768{
8769 std::vector<GameApiItem*> funcs = polydistfield_functions();
8770 GameApiItem *item = funcs[i];
8771 std::string name = item->Name(0);
8772 return name;
8773}
8775{
8776 std::vector<GameApiItem*> funcs = volumeapi_functions();
8777 GameApiItem *item = funcs[i];
8778 std::string name = item->Name(0);
8779 return name;
8780}
8782{
8783 std::vector<GameApiItem*> funcs = floatvolumeapi_functions();
8784 GameApiItem *item = funcs[i];
8785 std::string name = item->Name(0);
8786 return name;
8787}
8788
8790{
8791 std::vector<GameApiItem*> funcs = colorvolumeapi_functions();
8792 GameApiItem *item = funcs[i];
8793 std::string name = item->Name(0);
8794 return name;
8795}
8796
8797
8799{
8800 std::vector<GameApiItem*> funcs = boolbitmapapi_functions();
8801 GameApiItem *item = funcs[i];
8802 std::string name = item->Name(0);
8803 return name;
8804}
8806{
8807 std::vector<GameApiItem*> funcs = floatbitmapapi_functions();
8808 GameApiItem *item = funcs[i];
8809 std::string name = item->Name(0);
8810 return name;
8811}
8813{
8814 std::vector<GameApiItem*> funcs = pointapi_functions();
8815 GameApiItem *item = funcs[i];
8816 std::string name = item->Name(0);
8817 return name;
8818}
8820{
8821 std::vector<GameApiItem*> funcs = vectorapi_functions();
8822 GameApiItem *item = funcs[i];
8823 std::string name = item->Name(0);
8824 return name;
8825}
8826
8828{
8829 std::vector<GameApiItem*> funcs = booleanopsapi_functions();
8830 GameApiItem *item = funcs[i];
8831 std::string name = item->Name(0);
8832 return name;
8833}
8835{
8836 std::vector<GameApiItem*> funcs = moveapi_functions();
8837 GameApiItem *item = funcs[i];
8838 std::string name = item->Name(0);
8839 return name;
8840}
8841
8842struct FunctionsData
8843{
8844 GameApi::GuiApi *gui;
8845 std::string label;
8846 GameApi::FtA atlas;
8847 GameApi::BM atlas_bm;
8848 std::vector<std::string> vec2;
8849 std::vector<std::string> vec2_0;
8850 std::vector<std::string> vec3;
8851 GameApi::FtA atlas2;
8852 GameApi::BM atlas_bm2;
8853 GameApi::W insert;
8854 GameApi::W *outer;
8855};
8856
8857GameApi::W w1_func(void* ptr)
8858{
8859 FunctionsData *dt = (FunctionsData*)ptr;
8860 GameApi::W w = dt->gui->list_item_opened(130-5, dt->label, dt->atlas, dt->atlas_bm, dt->vec2, dt->vec3, dt->atlas2, dt->atlas_bm2, dt->insert,false,dt->outer, dt->vec2_0);
8861 return w;
8862}
8863GameApi::W w2_func(void *ptr)
8864{
8865 FunctionsData *dt = (FunctionsData*)ptr;
8866 //GameApi::W w2 = dt->gui->list_item_title(140-5, dt->label, dt->atlas, dt->atlas_bm);
8867 GameApi::W e = dt->gui->empty();
8868 GameApi::W w = dt->gui->list_item_opened(130-5, dt->label, dt->atlas, dt->atlas_bm, dt->vec2, dt->vec3, dt->atlas2, dt->atlas_bm2, e,true, dt->outer, dt->vec2_0);
8869 return w;
8870}
8871//#define DISPLAY_NUM 1
8872
8873EXPORT GameApi::W functions_widget(GameApi::GuiApi &gui, std::string label, std::vector<GameApiItem*> vec, GameApi::FtA atlas, GameApi::BM atlas_bm, GameApi::FtA atlas2, GameApi::BM atlas_bm2, GameApi::W insert, GameApi::W *outer)
8874{
8875 std::vector<std::string> vec2;
8876 std::vector<std::string> vec2_0;
8877 std::vector<std::string> vec3;
8878 int s = vec.size();
8879 for(int i=0;i<s;i++)
8880 {
8881 GameApiItem *item = vec[i];
8882 vec2.push_back(item->Name(0));
8883 vec2_0.push_back(item->FuncName(0));
8884 int sp = item->ParamCount(0);
8885 std::string typestr = "(";
8886 for(int j=0;j<sp;j++)
8887 {
8888 std::string type = item->ParamType(0, j);
8889
8890 if (type.size()<=4 && type.size()>0 && type[0]>='A' && type[0]<='Z')
8891 {
8892 if (typestr.size()!=1)
8893 typestr+=",";
8894 typestr+=type;
8895 }
8896 if (type.size()>2 && type[0]=='[' && type[type.size()-1]==']')
8897 {
8898 if (type[1]=='[' && type[type.size()-2]==']') type = type.substr(1, type.size()-2);
8899
8900 if (typestr.size()!=1)
8901 typestr+=",";
8902 typestr+= type;
8903 }
8904 }
8905 typestr+=")->";
8906 typestr+=item->ReturnType(0);
8907 vec3.push_back(typestr);
8908 }
8909 FunctionsData *dt = new FunctionsData;
8910 dt->gui = &gui;
8911 std::string num = "";
8912#ifdef DISPLAY_NUM
8913 std::stringstream ss; ss << s; num = ss.str() + " ";
8914#endif
8915 dt->label = num + label;
8916 dt->atlas = atlas;
8917 dt->atlas_bm = atlas_bm;
8918 dt->vec2 = vec2;
8919 dt->vec2_0 = vec2_0;
8920 dt->vec3 = vec3;
8921 dt->atlas2 = atlas2;
8922 dt->atlas_bm2 = atlas_bm2;
8923 dt->insert = insert;
8924 dt->outer = outer;
8925 //GameApi::W w = gui.list_item_opened(140-5, label, atlas, atlas_bm, vec2, vec3, atlas2, atlas_bm2, insert);
8926 //GameApi::W w2 = gui.list_item_title(140-5, label, atlas, atlas_bm);
8927 GameApi::W or_elem = gui.or_elem(w1_func,w2_func,(void*)dt);
8928 return or_elem;
8929}
8930
8931
8932
8933EXPORT GameApi::W GameApi::GuiApi::bitmapapi_functions_list_item(FtA atlas1, BM atlas_bm1, FtA atlas2, BM atlas_bm2, W insert, W *outer)
8934{
8935 return functions_widget(*this, "BitmapApi", bitmapapi_functions(), atlas1, atlas_bm1, atlas2, atlas_bm2, insert, outer);
8936}
8937EXPORT GameApi::W GameApi::GuiApi::waveformapi_functions_list_item(FtA atlas1, BM atlas_bm1, FtA atlas2, BM atlas_bm2, W insert, W *outer)
8938{
8939 return functions_widget(*this, "WaveformApi", waveform_functions(), atlas1, atlas_bm1, atlas2, atlas_bm2, insert,outer);
8940}
8941EXPORT GameApi::W GameApi::GuiApi::blockerapi_functions_list_item(GameApi::EveryApi &ev, FtA atlas1, BM atlas_bm1, FtA atlas2, BM atlas_bm2, W insert, W *outer)
8942{
8943 return functions_widget(*this, "MainLoopApi", blocker_functions(ev), atlas1, atlas_bm1, atlas2, atlas_bm2, insert, outer);
8944}
8945
8946EXPORT GameApi::W GameApi::GuiApi::textureapi_functions_list_item(FtA atlas1, BM atlas_bm1, FtA atlas2, BM atlas_bm2, W insert, W *outer)
8947{
8948 return functions_widget(*this, "TextureApi", textureapi_functions(), atlas1, atlas_bm1, atlas2, atlas_bm2, insert,outer);
8949}
8950
8951EXPORT GameApi::W GameApi::GuiApi::booleanopsapi_functions_list_item(FtA atlas1, BM atlas_bm1, FtA atlas2, BM atlas_bm2, W insert, W *outer)
8952{
8953 return functions_widget(*this, "BooleanOps", booleanopsapi_functions(), atlas1, atlas_bm1, atlas2, atlas_bm2, insert,outer);
8954}
8955
8956EXPORT GameApi::W GameApi::GuiApi::moveapi_functions_list_item(FtA atlas1, BM atlas_bm1, FtA atlas2, BM atlas_bm2, W insert, W *outer)
8957{
8958 return functions_widget(*this, "MoveApi", moveapi_functions(), atlas1, atlas_bm1, atlas2, atlas_bm2, insert,outer);
8959}
8960
8961
8962
8963EXPORT GameApi::W GameApi::GuiApi::fontapi_functions_list_item(FtA atlas1, BM atlas_bm1, FtA atlas2, BM atlas_bm2, W insert, W *outer)
8964{
8965 return functions_widget(*this, "FontApi", fontapi_functions(), atlas1, atlas_bm1, atlas2, atlas_bm2, insert,outer);
8966}
8967
8968EXPORT GameApi::W GameApi::GuiApi::volumeapi_functions_list_item(FtA atlas1, BM atlas_bm1, FtA atlas2, BM atlas_bm2, W insert, W *outer)
8969{
8970 return functions_widget(*this, "VolumeApi", volumeapi_functions(), atlas1, atlas_bm1, atlas2, atlas_bm2, insert,outer);
8971}
8972EXPORT GameApi::W GameApi::GuiApi::floatvolumeapi_functions_list_item(FtA atlas1, BM atlas_bm1, FtA atlas2, BM atlas_bm2, W insert, W *outer)
8973{
8974 return functions_widget(*this, "FloatSceneApi", floatvolumeapi_functions(), atlas1, atlas_bm1, atlas2, atlas_bm2, insert,outer);
8975}
8976EXPORT GameApi::W GameApi::GuiApi::colorvolumeapi_functions_list_item(FtA atlas1, BM atlas_bm1, FtA atlas2, BM atlas_bm2, W insert, W *outer)
8977{
8978 return functions_widget(*this, "CVolumeApi", colorvolumeapi_functions(), atlas1, atlas_bm1, atlas2, atlas_bm2, insert,outer);
8979}
8980
8981
8982EXPORT GameApi::W GameApi::GuiApi::shadermoduleapi_functions_list_item(FtA atlas1, BM atlas_bm1, FtA atlas2, BM atlas_bm2, W insert, W *outer)
8983{
8984 return functions_widget(*this, "MaterialsApi", shadermoduleapi_functions(), atlas1, atlas_bm1, atlas2, atlas_bm2, insert,outer);
8985}
8986EXPORT GameApi::W GameApi::GuiApi::shaderapi_functions_list_item(FtA atlas1, BM atlas_bm1, FtA atlas2, BM atlas_bm2, W insert, W *outer)
8987{
8988 return functions_widget(*this, "ShaderApi", shaderapi_functions(), atlas1, atlas_bm1, atlas2, atlas_bm2, insert,outer);
8989}
8990EXPORT GameApi::W GameApi::GuiApi::framebuffermoduleapi_functions_list_item(FtA atlas1, BM atlas_bm1, FtA atlas2, BM atlas_bm2, W insert, W *outer)
8991{
8992 return functions_widget(*this, "FrameBufApi", framebuffermoduleapi_functions(), atlas1, atlas_bm1, atlas2, atlas_bm2, insert,outer);
8993}
8994EXPORT GameApi::W GameApi::GuiApi::linesapi_functions_list_item(FtA atlas1, BM atlas_bm1, FtA atlas2, BM atlas_bm2, W insert, W *outer)
8995{
8996 return functions_widget(*this, "LinesApi", linesapi_functions(), atlas1, atlas_bm1, atlas2, atlas_bm2, insert,outer);
8997}
8998EXPORT GameApi::W GameApi::GuiApi::pointsapi_functions_list_item(FtA atlas1, BM atlas_bm1, FtA atlas2, BM atlas_bm2, W insert, W *outer)
8999{
9000 return functions_widget(*this, "PointsApi", pointsapi_functions(), atlas1, atlas_bm1, atlas2, atlas_bm2, insert,outer);
9001}
9002EXPORT GameApi::W GameApi::GuiApi::pointapi_functions_list_item(FtA atlas1, BM atlas_bm1, FtA atlas2, BM atlas_bm2, W insert, W *outer)
9003{
9004 return functions_widget(*this, "PointApi", pointapi_functions(), atlas1, atlas_bm1, atlas2, atlas_bm2, insert,outer);
9005}
9006EXPORT GameApi::W GameApi::GuiApi::vectorapi_functions_list_item(FtA atlas1, BM atlas_bm1, FtA atlas2, BM atlas_bm2, W insert, W *outer)
9007{
9008 return functions_widget(*this, "VectorApi", vectorapi_functions(), atlas1, atlas_bm1, atlas2, atlas_bm2, insert, outer);
9009}
9010
9011EXPORT GameApi::W GameApi::GuiApi::boolbitmapapi_functions_list_item(FtA atlas1, BM atlas_bm1, FtA atlas2, BM atlas_bm2, W insert, W *outer)
9012{
9013 return functions_widget(*this, "BoolBitmap", boolbitmapapi_functions(), atlas1, atlas_bm1, atlas2, atlas_bm2, insert, outer);
9014}
9015EXPORT GameApi::W GameApi::GuiApi::floatbitmapapi_functions_list_item(FtA atlas1, BM atlas_bm1, FtA atlas2, BM atlas_bm2, W insert, W *outer)
9016{
9017 return functions_widget(*this, "FloatBitmap", floatbitmapapi_functions(), atlas1, atlas_bm1, atlas2, atlas_bm2, insert, outer);
9018}
9019
9020EXPORT GameApi::W GameApi::GuiApi::polygonapi_functions_list_item(FtA atlas1, BM atlas_bm1, FtA atlas2, BM atlas_bm2, W insert, W *outer)
9021{
9022 return functions_widget(*this, "PolygonApi", polygonapi_functions(), atlas1, atlas_bm1, atlas2, atlas_bm2, insert, outer);
9023}
9024EXPORT GameApi::W GameApi::GuiApi::polygondistapi_functions_list_item(FtA atlas1, BM atlas_bm1, FtA atlas2, BM atlas_bm2, W insert, W *outer)
9025{
9026 return functions_widget(*this, "PolyDistApi", polydistfield_functions(), atlas1, atlas_bm1, atlas2, atlas_bm2, insert, outer);
9027}
9028
9029class InsertWidget : public GuiWidgetForward
9030{
9031public:
9032 InsertWidget(GameApi::EveryApi &ev,GuiWidget *w, std::function<void(int,int)> f) : GuiWidgetForward(ev, { w }), f(f) { activated = true; state=false; }
9033 void activate() { activated = true; }
9034 void deactivate() { activated = false; }
9035 void update(Point2d mouse_pos, int button,int ch, int type, int mouse_wheel_y)
9036 {
9037 GuiWidgetForward::update(mouse_pos, button,ch, type, mouse_wheel_y);
9038 if (activated)
9039 {
9040 set_pos(mouse_pos);
9041
9042 if (!state && button==-1)
9043 {
9044 state=true;
9045 }
9046 if (button==0 && type==1025 && state)
9047 {
9048 f(int(mouse_pos.x), int(mouse_pos.y));
9049 state = false;
9050 }
9051 }
9052 }
9053 void render()
9054 {
9055 if (is_visible())
9056 {
9057 if (activated)
9058 {
9059 vec[0]->render();
9060 }
9061 }
9062 }
9063private:
9064 bool activated;
9065 bool state;
9066 std::function<void(int,int)> f;
9067};
9068
9069EXPORT GameApi::W GameApi::GuiApi::insert_widget(W item, std::function<void(int,int)> f)
9070{
9071 GuiWidget *w = find_widget(e, item);
9072 return add_widget(e, new InsertWidget(ev,w,f));
9073}
9074
9076{
9077 GuiWidget *ww = new EmptyWidget(ev);
9078 add_update_widget(e, w, ww);
9079}
9080
9081std::vector<std::pair<std::string,std::string> > GameApi::GuiApi::get_functions_mapping(GameApi::EveryApi &ev)
9082{
9083 std::vector<std::pair<std::string,std::string> > vec;
9084
9085 std::vector<GameApiItem*> &funcs = g_all_functions_service->get_all_functions(ev);
9086 //static std::vector<GameApiItem*> funcs = all_functions(ev);
9087 int s = funcs.size();
9088 for(int i=0;i<s;i++)
9089 {
9090 GameApiItem *i2 = funcs[i];
9091 std::string apiname = i2->ApiName(0);
9092 std::string funcname = i2->FuncName(0);
9093 std::string name = i2->Name(0);
9094 vec.push_back(std::make_pair(apiname + "." + funcname,name));
9095 }
9096 return vec;
9097}
9098
9099
9100
9101
9102int find_float_ch(std::string s, char ch) {
9103 int ss = s.size();
9104 int level = 0;
9105 for(int i=0;i<ss;i++)
9106 {
9107 if (s[i]=='(') level++;
9108 if (s[i]==')') level--;
9109 if (level==0 && s[i]==ch) return i;
9110 }
9111 return -1;
9112}
9113
9114std::vector<std::string> g_float_eval_env;
9115std::vector<std::string> g_int_eval_env;
9116std::vector<std::string> g_string_eval_env;
9117
9118std::string IntExprEval(std::string s)
9119{
9120 if (s.size()>0 && s[0]=='@') return StringExprEval(s.substr(1,s.size()-1));
9121 //std::cout << "IntExprEval:" << s << std::endl;
9122 if (s.size()>0 && s[0]==' ') return IntExprEval(s.substr(1,s.size()-1));
9123 if (s.size()>0 && s[s.size()-1]==' ') return IntExprEval(s.substr(0,s.size()-1));
9124
9125 if (s.size()==2 && s[0]=='&' && s[1]>='1' && s[1]<='5')
9126 {
9127 int val = s[1]-'1';
9128 std::string v = g_int_eval_env.size()>val?g_int_eval_env[val]:"";
9129 //std::cout << "IntExprEval(ret):" << IntExprEval(v) << std::endl;
9130 return IntExprEval(v);
9131 }
9132 //std::cout << "IntExprEval(ret2):" << s << std::endl;
9133 // TODO, we want proper int expressions here?
9134 return s;
9135}
9136std::string StringExprEval(std::string s)
9137{
9138 if (s.size()>0 && s[0]=='@') return StringExprEval(s.substr(1,s.size()-1));
9139 if (s.size()==2 && s[0]=='$' && s[1]>='1' && s[1]<='5')
9140 {
9141 int val = s[1]-'1';
9142 std::string v = g_string_eval_env.size()>val?g_string_eval_env[val]:"";
9143 return StringExprEval(v);
9144 }
9145 return s;
9146}
9147
9148std::string FloatExprEval(std::string s)
9149{
9150 //std::cout << "FloatExprEval: " << s << std::endl;
9151 if (s.size()>0 && s[0]=='@') return FloatExprEval(s.substr(1,s.size()-1));
9152 if (s.size()>0 && s[0]==' ') return FloatExprEval(s.substr(1,s.size()-1));
9153 if (s.size()>0 && s[s.size()-1]==' ') return FloatExprEval(s.substr(0,s.size()-1));
9154 if (s.size()>0 && s[0]=='-') {
9155 std::string s2 = FloatExprEval(s.substr(1));
9156 std::stringstream ss(s2);
9157 float val;
9158 ss >> val;
9159 val = - val;
9160 std::stringstream ss2;
9161 ss2 << val;
9162 return ss2.str();
9163 }
9164
9165 if (s.size()>2 && s[0]=='(' && s[s.size()-1]==')')
9166 {
9167 return FloatExprEval(s.substr(1,s.size()-2));
9168 }
9169 int vala = find_float_ch(s, '+');
9170 if (vala!=-1) {
9171 std::string start = s.substr(0,vala);
9172 std::string end = s.substr(vala+1);
9173 std::string res1 = FloatExprEval(start);
9174 std::string res2 = FloatExprEval(end);
9175 std::stringstream ss(res1);
9176 std::stringstream ss2(res2);
9177 float val1=0.0, val2=0.0;
9178 ss >> val1;
9179 ss2 >> val2;
9180 std::stringstream res;
9181 res << val1+val2;
9182 //std::cout << "FloatExprEval(result): " << res.str() << std::endl;
9183
9184 return res.str();
9185 }
9186 int valb = find_float_ch(s, '-');
9187 if (valb!=-1) {
9188 std::string start = s.substr(0,valb);
9189 std::string end = s.substr(valb+1);
9190 std::string res1 = FloatExprEval(start);
9191 std::string res2 = FloatExprEval(end);
9192 std::stringstream ss(res1);
9193 std::stringstream ss2(res2);
9194 float val1=0.0, val2=0.0;
9195 ss >> val1;
9196 ss2 >> val2;
9197 std::stringstream res;
9198 res << val1-val2;
9199 //std::cout << "FloatExprEval(result): " << res.str() << std::endl;
9200 return res.str();
9201 }
9202
9203 int valc = find_float_ch(s, '*');
9204 if (valc!=-1) {
9205 std::string start = s.substr(0,valc);
9206 std::string end = s.substr(valc+1);
9207 std::string res1 = FloatExprEval(start);
9208 std::string res2 = FloatExprEval(end);
9209 std::stringstream ss(res1);
9210 std::stringstream ss2(res2);
9211 float val1=0.0, val2=0.0;
9212 ss >> val1;
9213 ss2 >> val2;
9214 std::stringstream res;
9215 res << val1*val2;
9216 //std::cout << "FloatExprEval(result): " << res.str() << std::endl;
9217 return res.str();
9218 }
9219
9220 int vald = find_float_ch(s, '/');
9221 if (vald!=-1) {
9222 std::string start = s.substr(0,vald);
9223 std::string end = s.substr(vald+1);
9224 std::string res1 = FloatExprEval(start);
9225 std::string res2 = FloatExprEval(end);
9226 std::stringstream ss(res1);
9227 std::stringstream ss2(res2);
9228 float val1=0.0, val2=0.0;
9229 ss >> val1;
9230 ss2 >> val2;
9231 std::stringstream res;
9232 res << val1/val2;
9233 //std::cout << "FloatExprEval(result): " << res.str() << std::endl;
9234 return res.str();
9235 }
9236
9237 if (s.size()==2 && s[0]=='%' && s[1]>='1' && s[1]<='5')
9238 {
9239 int val = s[1]-'1';
9240 std::string v = g_float_eval_env.size()>val?g_float_eval_env[val]:"";
9241 return FloatExprEval(v);
9242 }
9243 //std::cout << "FloatExprEval(result): " << s << std::endl;
9244 return s;
9245
9246}
9247struct CharConv { std::string repl; std::string ch_str; char ch; };
9248
9249class ConversionTable : public ConversionTableInterface {
9250public:
9251 static int find_str_pos(std::string val, int pos, std::string repl)
9252 {
9253 int s = val.size()-repl.size()+1;
9254 for(int i=pos;i<s;i++)
9255 {
9256 int s2 = repl.size();
9257 bool found = true;
9258 for(int j=0;j<s2;j++)
9259 {
9260 if (val[i+j]!=repl[j]) { found=false; break; }
9261 }
9262 if (found) return i;
9263 }
9264 return -1;
9265 }
9266
9267 static std::string replace_str3(std::string val, std::string repl, std::string subst)
9268 {
9269 while(1) {
9270 int pos = find_str(val, repl);
9271 if (pos==-1) return val;
9272 val = val.replace(pos,repl.size(),subst);
9273 }
9274 return val;
9275 }
9276
9277
9278 int get_size() const { return conv_table.size(); }
9279 std::string get_label(int i) const { return conv_table[i].repl; }
9280 virtual std::string get_str_ch(int i) const { return conv_table[i].ch_str; }
9281 virtual char get_ch(int i) const { return conv_table[i].ch; }
9282
9283 virtual std::string convert_labels_to_chars(std::string str) const
9284 {
9285 int s7 = get_size();
9286 for(int i=0;i<s7;i++)
9287 {
9288 str = replace_str3(str, get_label(i), get_str_ch(i));
9289 }
9290 return str;
9291 }
9292 virtual int find_last_location(std::string str) const
9293 {
9294 int pos = 0;
9295 int pos2 = -1;
9296 int loc = -1;
9297 while(1) {
9298 int s = get_size();
9299 bool found=false;
9300 for(int i=0;i<s;i++) {
9301 //std::cout << "pos=" << pos << std::endl;
9302 int res = find_str_pos(str,pos,get_label(i));
9303 //std::cout << "Result:" << res << std::endl;
9304 if (res!=-1) { pos2=std::max(pos2,res); found=true; }
9305 }
9306 if (!found) break; else loc=pos2;
9307 pos = pos2 + 1;
9308 }
9309 return loc;
9310 }
9311
9312 virtual bool insert_label_to_string(std::string *str, char ch) const
9313 {
9314 bool done = false;
9315 int s8 = get_size();
9316 for(int i=0;i<s8;i++)
9317 {
9318 if (ch==get_ch(i))
9319 {
9320 std::string label = get_label(i);
9321 int s9=label.size();
9322 for(int j=0;j<s9;j++)
9323 {
9324 str->push_back(label[j]);
9325 }
9326 done = true;
9327 }
9328 }
9329 return done;
9330 }
9331private:
9332 std::vector<CharConv> conv_table = {
9333 { "{032}", " ",' ' },
9334 { "{063}", "?",'?' },
9335 { "{035}", "#",'#' },
9336 //{ "{058}", ":",':' }, // messes up with urls.
9337 { "{059}", ";",';' },
9338 { "{124}", "|",'|' },
9339 { "{123}", "{",'{' },
9340 { "{125}", "}",'}' },
9341 { "{091}", "[",'[' },
9342 { "{093}", "]",']' },
9343 { "{044}", ",",',' },
9344 { "{034}", "\"",'"' }
9345 };
9346};
9347ConversionTable g_conv_table_impl;
9349
9350
9351struct KeyData
9352{
9353 int key;
9354 int sdl_scancode;
9355 const char *normal;
9356 const char *shift;
9357 const char *altgr;
9358};
9359std::string g_current_language = "fi";
9360
9361
9362
9363
9364std::vector<KeyData> finnish_scancodes =
9365{
9366 // number row (physical positions)
9367 { 0, 30, "1", "!", "" }, // SDL_SCANCODE_1
9368 { 1, 31, "2", "\"", "@" }, // SDL_SCANCODE_2
9369 { 2, 32, "3", "#", "£" }, // SDL_SCANCODE_3
9370 { 3, 33, "4", "$", "¤" }, // SDL_SCANCODE_4
9371 { 4, 34, "5", "%", "€" }, // SDL_SCANCODE_5
9372 { 5, 35, "6", "&", "" }, // SDL_SCANCODE_6
9373 { 6, 36, "7", "/", "{" }, // SDL_SCANCODE_7
9374 { 7, 37, "8", "(", "[" }, // SDL_SCANCODE_8
9375 { 8, 38, "9", ")", "]" }, // SDL_SCANCODE_9
9376 { 9, 39, "0", "=", "}" }, // SDL_SCANCODE_0
9377
9378 // punctuation row
9379 { 10, 45, "+", "?", "\\" }, // SDL_SCANCODE_MINUS (Finnish position)
9380 { 11, 46, "´", "`", "" }, // SDL_SCANCODE_EQUALS (dead key in FI layout)
9381
9382 // QWERTY top row
9383 { 12, 4, "q", "Q", "" }, // SDL_SCANCODE_A (actually physical A-row starts here)
9384 { 13, 5, "w", "W", "" }, // SDL_SCANCODE_B
9385 { 14, 6, "e", "E", "€" }, // SDL_SCANCODE_C
9386 { 15, 7, "r", "R", "" }, // SDL_SCANCODE_D
9387 { 16, 8, "t", "T", "" }, // SDL_SCANCODE_E
9388 { 17, 9, "y", "Y", "" }, // SDL_SCANCODE_F
9389 { 18, 10, "u", "U", "" }, // SDL_SCANCODE_G
9390 { 19, 11, "i", "I", "" }, // SDL_SCANCODE_H
9391 { 20, 12, "o", "O", "" }, // SDL_SCANCODE_I
9392 { 21, 13, "p", "P", "" }, // SDL_SCANCODE_J
9393
9394 // Finnish letters (important part)
9395 { 22, 14, "\xE5", "\xC5", "" }, // SDL_SCANCODE_K = åÅ
9396 { 23, 15, "\xF6", "\xD6", "" }, // SDL_SCANCODE_L = öÖ
9397 { 24, 16, "\xE4", "\xC4", "" }, // SDL_SCANCODE_M = äÄ
9398
9399 // middle row
9400 { 25, 17, "a", "A", "" },
9401 { 26, 18, "s", "S", "" },
9402 { 27, 19, "d", "D", "" },
9403 { 28, 20, "f", "F", "" },
9404 { 29, 21, "g", "G", "" },
9405 { 30, 22, "h", "H", "" },
9406 { 31, 23, "j", "J", "" },
9407 { 32, 24, "k", "K", "" },
9408 { 33, 25, "l", "L", "" },
9409
9410 // bottom row
9411 { 34, 26, "z", "Z", "" },
9412 { 35, 27, "x", "X", "" },
9413 { 36, 28, "c", "C", "" },
9414 { 37, 29, "v", "V", "" },
9415 { 38, 30, "b", "B", "" },
9416 { 39, 31, "n", "N", "" },
9417 { 40, 32, "m", "M", "" },
9418
9419 // punctuation
9420 { 41, 44, ",", ";", "" }, // comma
9421 { 42, 45, ".", ":", "" }, // period
9422 { 43, 46, "-", "_", "" }, // slash area depending layout
9423};
9424
9425
9426
9427std::vector<KeyData> us_scancodes =
9428{
9429 // number row
9430 { 0, 30, "1", "!", "" }, // SDL_SCANCODE_1
9431 { 1, 31, "2", "@", "" }, // SDL_SCANCODE_2
9432 { 2, 32, "3", "#", "" }, // SDL_SCANCODE_3
9433 { 3, 33, "4", "$", "" }, // SDL_SCANCODE_4
9434 { 4, 34, "5", "%", "" }, // SDL_SCANCODE_5
9435 { 5, 35, "6", "^", "" }, // SDL_SCANCODE_6
9436 { 6, 36, "7", "&", "" }, // SDL_SCANCODE_7
9437 { 7, 37, "8", "*", "" }, // SDL_SCANCODE_8
9438 { 8, 38, "9", "(", "" }, // SDL_SCANCODE_9
9439 { 9, 39, "0", ")", "" }, // SDL_SCANCODE_0
9440
9441 // punctuation row
9442 { 10, 45, "-", "_", "" }, // SDL_SCANCODE_MINUS
9443 { 11, 46, "=", "+", "" }, // SDL_SCANCODE_EQUALS
9444
9445 { 12, 47, "[", "{", "" }, // SDL_SCANCODE_LEFTBRACKET
9446 { 13, 48, "]", "}", "" }, // SDL_SCANCODE_RIGHTBRACKET
9447 { 14, 49, "\\", "|", "" }, // SDL_SCANCODE_BACKSLASH
9448
9449 { 15, 51, ";", ":", "" }, // SDL_SCANCODE_SEMICOLON
9450 { 16, 52, "'", "\"", "" }, // SDL_SCANCODE_APOSTROPHE
9451 { 17, 53, "`", "~", "" }, // SDL_SCANCODE_GRAVE
9452
9453 { 18, 54, ",", "<", "" }, // SDL_SCANCODE_COMMA
9454 { 19, 55, ".", ">", "" }, // SDL_SCANCODE_PERIOD
9455 { 20, 56, "/", "?", "" }, // SDL_SCANCODE_SLASH
9456
9457 // QWERTY row
9458 { 21, 4, "a", "A", "" },
9459 { 22, 5, "b", "B", "" },
9460 { 23, 6, "c", "C", "" },
9461 { 24, 7, "d", "D", "" },
9462 { 25, 8, "e", "E", "" },
9463 { 26, 9, "f", "F", "" },
9464 { 27, 10, "g", "G", "" },
9465 { 28, 11, "h", "H", "" },
9466 { 29, 12, "i", "I", "" },
9467 { 30, 13, "j", "J", "" },
9468 { 31, 14, "k", "K", "" },
9469 { 32, 15, "l", "L", "" },
9470
9471 { 33, 16, "m", "M", "" },
9472 { 34, 17, "n", "N", "" },
9473 { 35, 18, "o", "O", "" },
9474 { 36, 19, "p", "P", "" },
9475 { 37, 20, "q", "Q", "" },
9476 { 38, 21, "r", "R", "" },
9477 { 39, 22, "s", "S", "" },
9478 { 40, 23, "t", "T", "" },
9479 { 41, 24, "u", "U", "" },
9480 { 42, 25, "v", "V", "" },
9481 { 43, 26, "w", "W", "" },
9482 { 44, 27, "x", "X", "" },
9483 { 45, 28, "y", "Y", "" },
9484 { 46, 29, "z", "Z", "" },
9485};
9486
9487
9488
9489std::vector<KeyData> german_scancodes =
9490{
9491 // number row (DE layout differences!)
9492 { 0, 30, "1", "!", "" }, // SDL_SCANCODE_1
9493 { 1, 31, "2", "\"", "²" }, // SDL_SCANCODE_2
9494 { 2, 32, "3", "§", "³" }, // SDL_SCANCODE_3
9495 { 3, 33, "4", "$", "" }, // SDL_SCANCODE_4
9496 { 4, 34, "5", "%", "" }, // SDL_SCANCODE_5
9497 { 5, 35, "6", "&", "" }, // SDL_SCANCODE_6
9498 { 6, 36, "7", "/", "{" }, // SDL_SCANCODE_7
9499 { 7, 37, "8", "(", "[" }, // SDL_SCANCODE_8
9500 { 8, 38, "9", ")", "]" }, // SDL_SCANCODE_9
9501 { 9, 39, "0", "=", "}" }, // SDL_SCANCODE_0
9502
9503 // punctuation row (DE layout)
9504 { 10, 45, "ß", "?", "\\" }, // SDL_SCANCODE_MINUS
9505 { 11, 46, "´", "`", "" }, // SDL_SCANCODE_EQUALS (dead key)
9506
9507 { 12, 47, "ü", "Ü", "" }, // SDL_SCANCODE_LEFTBRACKET
9508 { 13, 48, "+", "*", "~" }, // SDL_SCANCODE_RIGHTBRACKET
9509 { 14, 49, "#", "'", "" }, // SDL_SCANCODE_BACKSLASH
9510
9511 { 15, 51, "ö", "Ö", "" }, // SDL_SCANCODE_SEMICOLON
9512 { 16, 52, "ä", "Ä", "" }, // SDL_SCANCODE_APOSTROPHE
9513 { 17, 53, "^", "°", "" }, // SDL_SCANCODE_GRAVE
9514
9515 { 18, 54, ",", ";", "" }, // SDL_SCANCODE_COMMA
9516 { 19, 55, ".", ":", "" }, // SDL_SCANCODE_PERIOD
9517 { 20, 56, "-", "_", "" }, // SDL_SCANCODE_SLASH
9518
9519 // QWERTZ letter row
9520 { 21, 4, "a", "A", "" },
9521 { 22, 5, "b", "B", "" },
9522 { 23, 6, "c", "C", "" },
9523 { 24, 7, "d", "D", "" },
9524 { 25, 8, "e", "E", "€" },
9525 { 26, 9, "f", "F", "" },
9526 { 27, 10, "g", "G", "" },
9527 { 28, 11, "h", "H", "" },
9528 { 29, 12, "i", "I", "" },
9529 { 30, 13, "j", "J", "" },
9530 { 31, 14, "k", "K", "" },
9531 { 32, 15, "l", "L", "" },
9532
9533 { 33, 16, "m", "M", "" },
9534 { 34, 17, "n", "N", "" },
9535 { 35, 18, "o", "O", "" },
9536 { 36, 19, "p", "P", "" },
9537 { 37, 20, "q", "Q", "@" },
9538 { 38, 21, "r", "R", "" },
9539 { 39, 22, "s", "S", "" },
9540 { 40, 23, "t", "T", "" },
9541 { 41, 24, "u", "U", "" },
9542 { 42, 25, "v", "V", "" },
9543 { 43, 26, "w", "W", "" },
9544 { 44, 27, "x", "X", "" },
9545 { 45, 28, "z", "Z", "" }, // NOTE: swapped y/z in QWERTZ
9546 { 46, 29, "y", "Y", "" },
9547};
9548
9549
9550std::vector<KeyData> choose_keydata()
9551{
9552 if (g_current_language=="fi") return finnish_scancodes;
9553 if (g_current_language=="us") return us_scancodes;
9554 if (g_current_language=="ge") return german_scancodes;
9555 std::cout << "Warning: " << g_current_language << " language not available at choose_keydata()." << std::endl;
9556 return finnish_scancodes;
9557}
char chars[]
Definition test.cpp:102
struct Envi env
P func(int c, EveryApi &ev)
Definition test.cpp:59
Env e
Definition Common.cc:2
EveryApi ev(e)
LowApi * g_low
Definition GameApi_low.cc:1684
Point2d pt(const FT_Vector *v)
Definition FreeType2.cc:459
void rectangle(Matrix m, float x, float y, FaceStore &s)
Definition Functions.cc:66
std::vector< GameApi::TF > g_tf_instances
Definition GameApi_gui.cc:4704
std::string str_tolower(std::string s)
Definition GameApi_pl.cc:18195
std::vector< GameApiItem * > all_functions(GameApi::EveryApi &ev)
Definition GameApi_gui.cc:8638
IMPORT ConversionTableInterface * g_conv_table
Definition GameApi_fnt.cc:614
std::string GetContentInstallDir(bool b)
float g_progress_bar_mult_builder
Definition GameApi.cc:45922
IMPORT AllFunctionsServiceInterface * g_all_functions_service
Definition GameApi.cc:46279
bool g_is_quake
Definition GameApi.cc:25263
std::string ch_str(std::vector< std::string > vec, int i)
Definition GameApi.cc:30160
int g_time_id
Definition GameApi_gltf.cc:14949
void call_all_mlguiwidget_cbs()
Definition GameApi.cc:18259
bool g_inside_icon_display
Definition GameApi.cc:30625
std::string find_param_name(GameApi::EveryApi &ev, std::string api_name, std::string func_name, int ii)
Definition GameApi_gui.cc:7189
std::string convert_script(std::string script)
Definition GameApi.cc:27532
bool g_inside_mesh_display
Definition GameApi.cc:30626
void LoadUrls_async_cbs()
Definition GameApi_gui.cc:7873
#define EXPORT
Definition GameApi.hh:334
int ELayoutEmpty
Definition GameApi_gui.cc:2662
#define IMPORT
Definition GameApi.hh:332
void clear_block(int id)
Definition GameApi_dep_add_find.cc:114
int add_block()
Definition GameApi_dep_add_find.cc:33
void set_current_block(int id)
Definition GameApi_dep_add_find.cc:65
int get_current_block()
Definition GameApi_dep_add_find.cc:110
std::string stripprefix(std::string s)
Definition GameApi_dep_env.cc:2555
std::map< std::string, std::vector< unsigned char > * > load_url_buffers
Definition GameApi_gui.cc:7642
void funccall_1(std::vector< std::string > &s, GameApi::ExecuteEnv &e, std::vector< std::string > param_name)
Definition GameApi_cmd.cc:87
MACRO2(GameApi::LI, ev.lines_api.from_polygon(ev.polygon_api.p_empty())) MACRO2(GameApi std::pair< std::string, std::string > CodeGen_1(GameApi::EveryApi &ev, std::vector< std::string > params, std::vector< std::string > param_names, std::vector< std::string > param_type, std::vector< std::string > param_exprs, std::string return_type, std::string api_name, std::string func_name, int j)
Definition GameApi_cmd.cc:45
int ret_type_count(std::string s)
Definition GameApi_gui.cc:4116
DelApiItemF g_api_item_deleter
Definition GameApi_gui.cc:8618
std::string FloatExprEval(std::string s)
Definition GameApi_gui.cc:9148
int find_float_ch(std::string s, char ch)
Definition GameApi_gui.cc:9102
std::vector< GameApiItem * > boolbitmapapi_functions()
Definition GameApi_cmd_bbitmap.cc:5
std::vector< GameApiItem * > bitmapapi_functions()
Definition GameApi_cmd_bitmap.cc:5
std::vector< GameApiItem * > booleanopsapi_functions()
Definition GameApi_cmd_booleanops.cc:6
std::vector< GameApiItem * > colorvolumeapi_functions()
Definition GameApi_cmd_cvolume.cc:5
std::vector< GameApiItem * > floatbitmapapi_functions()
Definition GameApi_cmd_fbitmap.cc:5
std::vector< GameApiItem * > fontapi_functions()
Definition GameApi_cmd_font.cc:5
std::vector< GameApiItem * > framebuffermoduleapi_functions()
Definition GameApi_cmd_framebuffer.cc:5
std::vector< GameApiItem * > vectorapi_functions()
Definition GameApi_cmd_vector.cc:5
std::vector< GameApiItem * > volumeapi_functions()
Definition GameApi_cmd_volume.cc:30
std::vector< GameApiItem * > textureapi_functions()
Definition GameApi_cmd_texture.cc:30
std::vector< GameApiItem * > polydistfield_functions()
Definition GameApi_cmd_pdfield.cc:4
std::vector< GameApiItem * > floatvolumeapi_functions()
Definition GameApi_cmd_fvolume.cc:29
std::vector< GameApiItem * > pointsapi_functions()
Definition GameApi_cmd_points.cc:4
std::vector< GameApiItem * > polygonapi_functions()
Definition GameApi_cmd_polygon.cc:8
std::vector< GameApiItem * > waveform_functions()
Definition GameApi_cmd_waveform.cc:5
std::vector< GameApiItem * > shadermoduleapi_functions()
Definition GameApi_cmd_material.cc:7
std::vector< GameApiItem * > linesapi_functions()
Definition GameApi_cmd_lines.cc:4
std::vector< GameApiItem * > moveapi_functions()
Definition GameApi_cmd_move.cc:5
std::vector< GameApiItem * > blocker_functions(GameApi::EveryApi &ev)
Definition GameApi_cmd_mainloop.cc:4
std::vector< GameApiItem * > pointapi_functions()
Definition GameApi_cmd_point.cc:4
std::vector< GameApiItem * > shaderapi_functions()
Definition GameApi_cmd_shader.cc:6
GameApi::P add_polygon2(GameApi::Env &e, FaceCollection *coll, int size=1)
Definition GameApi_dep_add_find.cc:1219
GameApi::M add_matrix2(GameApi::Env &e, Matrix mm)
Definition GameApi_dep_add_find.cc:1232
RenderVertexArray * find_vertex_array_render(GameApi::Env &e, GameApi::VA p)
Definition GameApi_dep_add_find.cc:2616
GameApi::W add_widget(GameApi::Env &e, GuiWidget *w)
Definition GameApi_dep_add_find.cc:818
GuiWidget * find_widget(GameApi::Env &e, GameApi::W w)
Definition GameApi_dep_add_find.cc:2082
Point * find_point(GameApi::Env &e, GameApi::PT p)
Definition GameApi_dep_add_find.cc:2784
BitmapHandle * find_bitmap(GameApi::Env &e, GameApi::BM b)
Definition GameApi_dep_add_find.cc:2456
FontAtlasInfo * find_font_atlas(GameApi::Env &e, GameApi::FtA ft)
Definition GameApi_dep_add_find.cc:2072
Bitmap< Color > * find_color_bitmap(BitmapHandle *handle, int bbm_choose)
Definition GameApi_dep_add_find.cc:2686
GameApi::ML add_main_loop(GameApi::Env &e, MainLoopItem *item)
Definition GameApi_dep_add_find.cc:797
void add_update_widget(GameApi::Env &e, GameApi::W widget, GuiWidget *w)
Definition GameApi_dep_add_find.cc:1096
MainLoopItem * find_main_loop(GameApi::Env &e, GameApi::ML ml)
Definition GameApi_dep_add_find.cc:2062
ASyncCallback * rem_async_cb(std::string url)
Definition GameApi_dep_env.cc:2507
void * process(void *ptr)
Definition GameApi_dep_env.cc:2773
del_map_interface & g_del_map
Definition GameApi_dep_env.cc:302
IMPORT std::string striphomepage(std::string url)
Definition GameApi_dep_env.cc:4365
int g_async_load_count
Definition GameApi_dep_env.cc:4090
int find_char(std::string expr, char c)
Definition GameApi_ex.cc:393
bool is_in_registered(std::string url)
Definition GameApi_gui.cc:7900
bool g_concurrent_download
Definition GameApi_gltf.cc:2008
IMPORT GameApi::PAT gameapi_temp_dir
Definition GameApi.cc:171
std::vector< GameApiItem * > fontapi_functions()
Definition GameApi_cmd_font.cc:5
std::map< std::string, int > shared_text
Definition GameApi_gui.cc:722
std::vector< GameApiItem * > polygonapi_functions1()
Definition GameApi_cmd_polygon.cc:15
std::vector< GameApiItem * > vectorapi_functions()
Definition GameApi_cmd_vector.cc:5
int ret_type_count(std::string return_type)
Definition GameApi_gui.cc:4116
std::vector< GameApiItem * > framebuffermoduleapi_functions()
Definition GameApi_cmd_framebuffer.cc:5
std::vector< GameApiItem * > volumeapi_functions()
Definition GameApi_cmd_volume.cc:30
std::vector< GameApiItem * > all_functions(GameApi::EveryApi &ev)
Definition GameApi_gui.cc:8638
bool done
Definition GameApi_gui.cc:1629
std::vector< GameApiItem * > colorvolumeapi_functions()
Definition GameApi_cmd_cvolume.cc:5
bool is_allowed(std::string chars, char ch)
Definition GameApi_gui.cc:1079
std::vector< GameApiItem * > bitmapapi_functions()
Definition GameApi_cmd_bitmap.cc:5
size dy
Definition GameApi_gui.cc:1727
const float keypress_rot_speed
Definition GameApi_gui.cc:73
std::vector< GameApiItem * > textureapi_functions()
Definition GameApi_cmd_texture.cc:30
std::string StringExprEval(std::string s)
Definition GameApi_gui.cc:9136
void set_value(std::string value)
Definition GameApi_gui.cc:1438
std::vector< GameApiItem * > polydistfield_functions()
Definition GameApi_cmd_pdfield.cc:4
IMPORT bool g_reload_edit_dialog
Definition GameApi_gui.cc:1072
std::string IntExprEval(std::string s)
Definition GameApi_gui.cc:9118
std::vector< GameApiItem * > floatvolumeapi_functions()
Definition GameApi_cmd_fvolume.cc:29
std::vector< GameApiItem * > pointsapi_functions()
Definition GameApi_cmd_points.cc:4
int render_to_bitmap()
Definition GameApi_gui.cc:1434
std::vector< GameApiItem * > floatbitmapapi_functions()
Definition GameApi_cmd_fbitmap.cc:5
std::vector< GameApiItem * > polygonapi_functions()
Definition GameApi_cmd_polygon.cc:8
std::vector< GameApiItem * > booleanopsapi_functions()
Definition GameApi_cmd_booleanops.cc:6
std::string g_searchstring
Definition GameApi_gui.cc:328
IMPORT ConversionTableInterface * g_conv_table
Definition GameApi_gui.cc:9348
std::vector< GameApiItem * > waveform_functions()
Definition GameApi_cmd_waveform.cc:5
std::vector< GameApiItem * > shadermoduleapi_functions()
Definition GameApi_cmd_material.cc:7
IMPORT std::string g_dragdrop_filename
Definition GameApi_gui.cc:1068
std::vector< GameApiItem * > shaderapi_functions()
Definition GameApi_cmd_shader.cc:6
EditorGuiWidgetAtlas GuiWidgetForward render()
Definition GameApi_gui.cc:1412
void update(Point2d mouse, int button, int ch, int type, int mouse_wheel_y)
Definition GameApi_gui.cc:1424
std::vector< GameApiItem * > linesapi_functions()
Definition GameApi_cmd_lines.cc:4
std::vector< GameApiItem * > moveapi_functions()
Definition GameApi_cmd_move.cc:5
std::vector< GameApiItem * > blocker_functions(GameApi::EveryApi &ev)
Definition GameApi_cmd_mainloop.cc:4
std::string unique_id_apiitem()
Definition accel.cc:42
IMPORT bool g_dragdrop_enabled
Definition GameApi_gui.cc:1067
std::vector< GameApiItem * > polygonapi_functions2()
Definition GameApi_cmd_polygon2.cc:5
std::vector< GameApiItem * > boolbitmapapi_functions()
Definition GameApi_cmd_bbitmap.cc:5
std::string g_temp44
Definition GameApi_gui.cc:1070
std::vector< GameApiItem * > pointapi_functions()
Definition GameApi_cmd_point.cc:4
const unsigned int c_canvas_item_text_button2
Definition GameApi_gui.hh:14
const unsigned int c_tooltip_button
Definition GameApi_gui.hh:7
const unsigned int c_canvas_item_node_1_2
Definition GameApi_gui.hh:18
const unsigned int c_dialog_button_1
Definition GameApi_gui.hh:21
const unsigned int c_canvas_item_text_button
Definition GameApi_gui.hh:13
const unsigned int c_list_item_title2
Definition GameApi_gui.hh:10
const unsigned int c_canvas_item_node_1
Definition GameApi_gui.hh:17
const unsigned int c_canvas_item
Definition GameApi_gui.hh:11
const unsigned int c_tooltip_button2
Definition GameApi_gui.hh:8
const unsigned int c_dialog_button_2
Definition GameApi_gui.hh:22
const unsigned int c_canvas_item_node_0_2
Definition GameApi_gui.hh:16
const unsigned int c_dialog_1_2
Definition GameApi_gui.hh:20
const unsigned int c_list_item_title
Definition GameApi_gui.hh:9
const unsigned int c_dialog_1
Definition GameApi_gui.hh:19
const unsigned int c_canvas_item_node_0
Definition GameApi_gui.hh:15
const unsigned int c_canvas_item2
Definition GameApi_gui.hh:12
std::string unique_id()
Definition GameApi_shm.cc:50
#define Low_SDL_JOYAXISMOTION
Definition GameApi_low.hh:585
@ Low_GL_DEPTH_TEST
Definition GameApi_low.hh:61
@ Low_GL_SCISSOR_TEST
Definition GameApi_low.hh:104
#define Low_SDL_JOYBALLMOTION
Definition GameApi_low.hh:586
bool g_inside_ml_widget
Definition GameApi_gui.cc:1692
float arg(Complex z)
Definition GameApi_pl.cc:31413
std::vector< Item * > functions()
Definition accel.cc:335
std::string api_name()
Definition accel.cc:318
PML or_elem(PML p1, PML p2)
Definition accel.cc:820
unsigned int color_1(int pointnum, PT pos)
Definition test.cpp:7
std::ostream & operator<<(std::ostream &, Catch_global_namespace_dummy)
Object call(Vector t_params) const
Calls the function with the given set of parameters and returns the value;.
void info(std::string info)
Definition check.cc:24
void error(std::string err, std::string fail_reason)
Definition check.cc:18
int value
Definition GameApi_gui.cc:2473
A()=default
int key
Definition GameApi_gui.cc:2473
virtual std::vector< GameApiItem * > & get_all_functions(GameApi::EveryApi &ev)=0
Definition GameApi_gui.cc:655
void update(Point2d mouse, int button, int ch, int type, int mouse_wheel_y)
Definition GameApi_gui.cc:658
int render_to_bitmap()
Definition GameApi_gui.cc:679
AltGuiWidget(GameApi::EveryApi &ev, std::vector< GuiWidget * > vec, int *choose)
Definition GameApi_gui.cc:657
void render()
Definition GameApi_gui.cc:673
void set_size(Vector2d v)
Definition GameApi_gui.cc:665
Definition GraphI.hh:826
virtual int SizeY() const =0
virtual int SizeX() const =0
Definition GraphI.hh:2215
Definition GameApi_gui.hh:297
GuiWidget * find_widget(int i) const
Definition GameApi_gui.hh:314
int push_back(GuiWidget *widget, int x, int y)
Definition GameApi_gui.hh:326
int find_index(GuiWidget *w)
Definition GameApi_gui.hh:305
int count() const
Definition GameApi_gui.hh:304
void del(int id)
Definition GameApi_gui.hh:335
Definition GameApi_fbo.cc:158
void first_frame(int i)
Definition GameApi_gui.cc:1711
std::vector< CollectInterface * > vec
Definition GameApi_fbo.cc:185
int count(int i) const
Definition GameApi_gui.cc:1717
void register_first_frame(CollectInterface *i)
Definition GameApi_gui.cc:1703
std::vector< CollectInterface * > vec2
Definition GameApi_fbo.cc:186
void register_obj(CollectInterface *i)
Definition GameApi_gui.cc:1700
void execute(int i)
Definition GameApi_gui.cc:1706
Definition GraphI.hh:612
Definition GraphI.hh:622
static void set(float &target, std::string s, bool allow_expr, std::string &expr)
Definition GameApi_gui.cc:931
static std::string error(const std::string &target, const std::string &dd)
Definition GameApi_gui.cc:933
static void get(const float &target, std::string &s, bool allow_expr, std::string &expr)
Definition GameApi_gui.cc:932
static std::string error(const std::string &target, const std::string &dd)
Definition GameApi_gui.cc:942
static void get(const int &target, std::string &s, bool allow_expr, std::string &expr)
Definition GameApi_gui.cc:941
static void set(int &target, std::string s, bool allow_expr, std::string &expr)
Definition GameApi_gui.cc:940
static std::string error(const std::string &target, const std::string &dd_ext)
Definition GameApi_gui.cc:921
static void get(const std::string &target, std::string &s, bool allow_expr, std::string &expr)
Definition GameApi_gui.cc:920
static void set(std::string &target, std::string s, bool allow_expr, std::string &expr)
Definition GameApi_gui.cc:919
Definition GameApi_gui.cc:909
static std::string error(const std::string &target, const std::string &dd)
Definition GameApi_gui.cc:913
static void set(T &target, std::string s, bool allow_expr, std::string &expr)
Definition GameApi_gui.cc:911
static void get(const T &target, std::string &s, bool allow_expr, std::string &expr)
Definition GameApi_gui.cc:912
Definition GraphI.hh:191
virtual std::string convert_labels_to_chars(std::string str) const =0
Definition GameApi_gui.cc:199
int calc_top(char ch2)
Definition GameApi_gui.cc:257
void check_letters(std::string ss)
Definition GameApi_gui.cc:227
int calc_one_height()
Definition GameApi_gui.cc:294
int calc_all_height()
Definition GameApi_gui.cc:282
void render_w(int p, GameApi::W w, char ch2)
Definition GameApi_gui.cc:301
DynamicTextGuiWidget(GameApi::Env &e, GameApi::EveryApi &ev, GameApi::GuiApi &gui, std::string need_letters, std::string *dyn_text, void(*fptr)(void *, float mouse_x, float mouse_y, int button, int ch, int type, int mouse_wheel_y), void *user_ptr, GameApi::FtA atlas, GameApi::BM atlas_bm, int x_gap)
Definition GameApi_gui.cc:201
void update(Point2d mouse, int button, int ch, int type, int mouse_wheel_y)
Definition GameApi_gui.cc:216
void render()
Definition GameApi_gui.cc:241
int calc_one_top(char ch)
Definition GameApi_gui.cc:275
void add_letter(int ch)
Definition GameApi_gui.cc:204
int calc_all_top()
Definition GameApi_gui.cc:264
Definition GameApi_gui.cc:1095
bool done
Definition GameApi_gui.cc:1312
EditorGuiWidgetAtlas(GameApi::Env &env, GameApi::EveryApi &ev, std::string allowed_chars, T &target_m, GameApi::FtA atlas, GameApi::BM atlas_bm, GameApi::SH sh, int x_gap, bool allow_expr=false, std::string &expr=g_temp44, int non_editable=0, GameApi::W *redraw_w=0)
Definition GameApi_gui.cc:1097
void update(Point2d mouse, int button, int ch, int type, int mouse_wheel_y)
Definition GameApi_gui.cc:1107
void render()
Definition GameApi_gui.cc:877
EditorGuiWidget(GameApi::EveryApi &ev, std::string allowed_chars, T &target_m, GameApi::Ft font, GameApi::SH sh)
Definition GameApi_gui.cc:813
int render_to_bitmap()
Definition GameApi_gui.cc:887
void update(Point2d mouse, int button, int ch, int type, int mouse_wheel_y)
Definition GameApi_gui.cc:819
Definition GameApi_gui.cc:67
EmptyWidget(GameApi::EveryApi &ev)
Definition GameApi_gui.cc:69
Definition test.cpp:376
virtual std::string Name(int i) const =0
virtual std::string ApiName(int i) const =0
virtual int ParamCount(int i) const =0
virtual std::string ReturnType(int i) const =0
virtual std::string ParamDefault(int i, int p) const =0
virtual std::string ParamName(int i, int p) const =0
virtual std::string FuncName(int i) const =0
virtual std::string ParamType(int i, int p) const =0
virtual int Execute(GameApi::Env &ee, GameApi::EveryApi &ev, std::vector< std::string > params, GameApi::ExecuteEnv &e, int j)=0
Definition GraphI.hh:2078
Definition GameApi.hh:362
Definition GameApi.hh:2254
IMPORT W generic_editor(EveryApi &ev, EditTypes &target, FtA atlas, BM atlas_bm, std::string type, int x_gap, FtA atlas_tiny, BM atlas_tiny_bm, int sy, W &click_target)
Definition GameApi_gui.cc:5981
IMPORT W colorvolumeapi_functions_list_item(FtA font1, BM font1_bm, FtA font2, BM font2_bm, W insert, W *outer)
Definition GameApi_gui.cc:8976
IMPORT W bounding_box(W w)
Definition GameApi_gui.cc:2377
IMPORT W or_elem(W(*w1_func)(void *), W(*w2_func)(void *), void *data)
Definition GameApi_gui.cc:6727
IMPORT std::string boolbitmapapi_functions_item_label(int i)
Definition GameApi_gui.cc:8798
IMPORT int size_x(W w)
Definition GameApi_gui.cc:6845
IMPORT W multiline_string_editor(std::string allowed_chars, std::string &target, FI font, int x_gap, int line_height)
Definition GameApi_gui.cc:4740
IMPORT W ml(ML p, SH sh, SH sh2, SH sh_2d, SH sh_arr, int sx, int sy, int screen_size_x, int screen_size_y)
Definition GameApi_gui.cc:4706
IMPORT int pos_y(W w)
Definition GameApi_gui.cc:6840
IMPORT std::string textureapi_functions_item_label(int i)
Definition GameApi_gui.cc:8708
IMPORT std::string fontapi_functions_item_label(int i)
Definition GameApi_gui.cc:8716
IMPORT W pts_dialog(PTS p, SH sh, int screen_size_x, int screen_size_y, W &close_button, FtA atlas, BM atlas_bm, W &codegen_button, W &collect_button)
Definition GameApi_gui.cc:5447
IMPORT W layout_lh(W item, int left, int top, int width, int height, int right, int bottom, int(*fptr_l)(void *), int(*fptr_H)(void *), void *ctx1, void *ctx2)
Definition GameApi_gui.cc:6104
IMPORT std::string linesapi_functions_item_label(int i)
Definition GameApi_gui.cc:8752
IMPORT W floatvolumeapi_functions_list_item(FtA font1, BM font1_bm, FtA font2, BM font2_bm, W insert, W *outer)
Definition GameApi_gui.cc:8972
IMPORT void set_dynamic_param(W w, int id, float val)
Definition GameApi_gui.cc:6942
IMPORT W canvas(int sx, int sy)
Definition GameApi_gui.cc:3735
IMPORT W directory_view(std::vector< std::string > dir_items, int &selection, std::vector< W > &clicks, FtA atlas, BM atlas_bm)
Definition GameApi_gui.cc:5002
IMPORT W floatbitmapapi_functions_list_item(FtA font1, BM font1_bm, FtA font2, BM font2_bm, W insert, W *outer)
Definition GameApi_gui.cc:9015
IMPORT int get_size2(W w)
Definition GameApi_gui.cc:6957
IMPORT W overlap(EveryApi &ev, std::vector< W > vec)
Definition GameApi_gui.cc:4571
IMPORT W array_y(std::vector< W > arr, int y_gap, bool heavy=false)
Definition GameApi_gui.cc:6139
IMPORT W license_item(std::string filename, std::string &license_url, std::string &author, FtA atlas, BM atlas_bm, FtA atlas2, BM atlas_bm2)
Definition GameApi_gui.cc:4152
IMPORT W list_item_opened(int sx, std::string label, FtA atlas, BM atlas_bm, std::vector< std::string > subitems, std::vector< std::string > subitems_tooltip, FtA atlas2, BM atlas_bm2, W insert, bool hide, W *redraw_w, std::vector< std::string > subitems_funcname)
Definition GameApi_gui.cc:3823
IMPORT W fontapi_functions_list_item(FtA font1, BM font1_bm, FtA font2, BM font2_bm, W insert, W *outer)
Definition GameApi_gui.cc:8963
IMPORT W line(W target1, int delta_x, int delta_y, W target2, int delta2_x, int delta2_y, SH sh, SH old_sh)
Definition GameApi_gui.cc:3727
IMPORT W bitmapapi_functions_list_item(FtA font1, BM font1_bm, FtA font2, BM font2_bm, W insert, W *outer)
Definition GameApi_gui.cc:8933
IMPORT W linesapi_functions_list_item(FtA font1, BM font1_bm, FtA font2, BM font2_bm, W insert, W *outer)
Definition GameApi_gui.cc:8994
IMPORT W gradient(int sx, int sy, PT pos_1, PT pos_2, unsigned int colot_1, unsigned int color_2)
Definition GameApi_gui.cc:6621
IMPORT W polygon_dialog(P p, SH sh, int screen_size_x, int screen_size_y, W &close_button, FtA atlas, BM atlas_bm, W &codegen_button, W &collect_button, W &mem)
Definition GameApi_gui.cc:5175
IMPORT void set_index(W w, int j)
Definition GameApi_gui.cc:6967
IMPORT W download_bar(GameApi::EveryApi &ev, std::vector< std::string > titles, std::vector< W > &close_button, std::vector< W > &buttons, FtA atlas, BM atlas_bm, int active_tab, std::vector< float > progress)
Definition GameApi_gui.cc:5025
IMPORT int size_y(W w)
Definition GameApi_gui.cc:6850
IMPORT W hide_nonsearchable(W w, std::string label, W *redraw_w)
Definition GameApi_gui.cc:4605
IMPORT W boolbitmapapi_functions_list_item(FtA font1, BM font1_bm, FtA font2, BM font2_bm, W insert, W *outer)
Definition GameApi_gui.cc:9011
IMPORT W lines_dialog(LI p, SH sh, int screen_size_x, int screen_size_y, W &close_button, FtA atlas, BM atlas_bm, W &codegen_button, W &collect_button)
Definition GameApi_gui.cc:5404
IMPORT std::string pointapi_functions_item_label(int i)
Definition GameApi_gui.cc:8812
IMPORT W blockerapi_functions_list_item(GameApi::EveryApi &ev, FtA font1, BM font1_bm, FtA font2, BM font2_bm, W insert, W *outer)
Definition GameApi_gui.cc:8941
IMPORT W moveapi_functions_list_item(FtA font1, BM font1_bm, FtA font2, BM font2_bm, W insert, W *outer)
Definition GameApi_gui.cc:8956
IMPORT W progress_dialog(int sx, int sy, FtA atlas, BM atlas_bm, std::vector< std::string > vec, int val, int max)
Definition GameApi_gui.cc:4326
IMPORT W framebuffermoduleapi_functions_list_item(FtA font1, BM font1_bm, FtA font2, BM font2_bm, W insert, W *outer)
Definition GameApi_gui.cc:8990
IMPORT int pos_x(W w)
Definition GameApi_gui.cc:6835
IMPORT W booleanopsapi_functions_list_item(FtA font1, BM font1_bm, FtA font2, BM font2_bm, W insert, W *outer)
Definition GameApi_gui.cc:8951
IMPORT W icon_shared_noscale(BM bitmap, int key)
Definition GameApi_gui.cc:4674
IMPORT W layer(W w1, W w2)
Definition GameApi_gui.cc:6123
IMPORT W navi_bar(EveryApi &ev, std::vector< std::string > titles, W &back_button, W &forward_button, W &save_button, std::string &url, W &url_button, std::vector< W > &close_button, std::vector< W > &tab_change_button, W &new_tab_button, std::vector< std::string > bookmark_labels, std::vector< std::string > bookmark_urls, FtA atlas, BM atlas_bm, int &active_tab)
Definition GameApi_gui.cc:5082
IMPORT W insert_widget(W item, std::function< void(int, int)> f)
Definition GameApi_gui.cc:9069
IMPORT W layout_wh(W item, int left, int top, int width, int height, int right, int bottom, int(*fptr_W)(void *), int(*fptr_H)(void *), void *ctx1, void *ctx2)
Definition GameApi_gui.cc:6090
IMPORT W window_decoration(int sx, int sy, std::string label, FtA atlas, BM atlas_bm)
Definition GameApi_gui.cc:5366
IMPORT W vectorapi_functions_list_item(FtA font1, BM font1_bm, FtA font2, BM font2_bm, W insert, W *outer)
Definition GameApi_gui.cc:9006
IMPORT std::string colorvolumeapi_functions_item_label(int i)
Definition GameApi_gui.cc:8789
IMPORT std::string polygonapi_functions_item_label(int i)
Definition GameApi_gui.cc:8760
IMPORT W va_dialog(VA p, SH sh, int screen_size_x, int screen_size_y, W &close_button, FtA atlas, BM atlas_bm, W &codegen_button, W &collect_button)
Definition GameApi_gui.cc:5232
IMPORT void update_progress_dialog(volatile W &w, int sx, int sy, FtA atlas, BM atlas_bm, std::vector< std::string > vec, int val, int max, int process)
Definition GameApi_gui.cc:4438
IMPORT W shadermoduleapi_functions_list_item(FtA font1, BM font1_bm, FtA font2, BM font2_bm, W insert, W *outer)
Definition GameApi_gui.cc:8982
IMPORT W point_editor(float &x, float &y, float &z, FtA atlas, BM atlas_bm, int x_gap)
Definition GameApi_gui.cc:6054
IMPORT void set_pos(W w, float px, float py)
Definition GameApi_gui.cc:6855
IMPORT W scrollbar_x(int sx, int sy, int area_x)
Definition GameApi_gui.cc:6737
IMPORT W scrollbar_y(int sx, int sy, int area_y)
Definition GameApi_gui.cc:6733
IMPORT std::string framebuffermoduleapi_functions_item_label(int i)
Definition GameApi_gui.cc:8738
IMPORT std::string vectorapi_functions_item_label(int i)
Definition GameApi_gui.cc:8819
IMPORT W timed_visibility(W orig, W(*timed_widget_func)(void *), void *data, W insert, float start_duration, float duration, float dx)
Definition GameApi_gui.cc:3669
IMPORT W layout(W item, int left, int top, int width, int height, int right, int bottom)
Definition GameApi_gui.cc:6080
IMPORT int get_index(W w)
Definition GameApi_gui.cc:6952
IMPORT W alt(std::vector< W > vec, int *choose)
Definition GameApi_gui.cc:4626
IMPORT W right_align(W item, int sx)
Definition GameApi_gui.cc:5793
IMPORT W va(VA p, SH sh, int sx, int sy, int screen_size_x, int screen_size_y)
Definition GameApi_gui.cc:4699
IMPORT W pointapi_functions_list_item(FtA font1, BM font1_bm, FtA font2, BM font2_bm, W insert, W *outer)
Definition GameApi_gui.cc:9002
IMPORT W int_editor(int &target, std::string &target_expr, FtA atlas, BM atlas_bm, int x_gap, int noneditnum=0)
Definition GameApi_gui.cc:4923
IMPORT W copy_paste_dialog(SH sh, W &close_button, FI font, FtA atlas, BM atlas_bm, std::string &edit)
Definition GameApi_gui.cc:4961
IMPORT std::string bitmapapi_functions_item_label(int i)
Definition GameApi_gui.cc:8686
IMPORT void render(W w)
Definition GameApi_gui.cc:6879
IMPORT W polygonapi_functions_list_item(FtA font1, BM font1_bm, FtA font2, BM font2_bm, W insert, W *outer)
Definition GameApi_gui.cc:9020
IMPORT void set_size2(W w, int sz)
Definition GameApi_gui.cc:6962
IMPORT W editor_mouse_tweak(W inner, W outer, W outerouter)
Definition GameApi_gui.cc:390
IMPORT W tooltip(W orig, W insert, std::string label, FtA atlas, BM atlas_bm, int x_gap=2, float dx=40.0)
Definition GameApi_gui.cc:3712
IMPORT std::string get_id(W w)
Definition GameApi_gui.cc:6947
IMPORT float dynamic_param(W w, int id)
Definition GameApi_gui.cc:6897
IMPORT std::string pointsapi_functions_item_label(int i)
Definition GameApi_gui.cc:8745
IMPORT W waveform(std::function< float(float)> f, float start_range, float end_range, float min_value, float max_value, int sx, int sy, unsigned int true_color, unsigned int false_color)
Definition GameApi_gui.cc:6756
IMPORT W window_move(W widget, int area_x, int area_y, int area_width, int area_height)
Definition GameApi_gui.cc:4110
IMPORT W scroll_area2(W orig, int sx, int sy, int screen_y)
Definition GameApi_gui.cc:6746
IMPORT W asset_view(std::string url_or_filename)
Definition GameApi_gui.cc:5018
IMPORT void select_item(W w, int item)
Definition GameApi_gui.cc:6892
IMPORT W shader_plane(SFO p, int sx, int sy, int screen_size_x, int screen_size_y)
Definition GameApi_gui.cc:4717
IMPORT W scroll_area(W orig, int sx, int sy, int screen_y)
Definition GameApi_gui.cc:6741
IMPORT std::vector< std::pair< std::string, std::string > > get_functions_mapping(GameApi::EveryApi &ev)
Definition GameApi_gui.cc:9081
IMPORT W dynamic_text(std::string need_letters, std::string *dyn_text, void(*fptr)(void *, float mouse_x, float mouse_y, int button, int ch, int type, int mouse_wheel_y), void *user_ptr, GameApi::FtA atlas, GameApi::BM atlas_bm, int x_gap)
Definition GameApi_gui.cc:4646
IMPORT std::string shaderapi_functions_item_label(int i)
Definition GameApi_gui.cc:8731
IMPORT W rectangle(int start_x, int end_x, int start_y, int end_y, unsigned int color)
Definition GameApi_gui.cc:4014
IMPORT W lines(LI p, SH sh, int sx, int sy, int screen_size_x, int screen_size_y)
Definition GameApi_gui.cc:4722
IMPORT std::string booleanopsapi_functions_item_label(int i)
Definition GameApi_gui.cc:8827
IMPORT W main_menu(std::vector< std::string > labels, FtA atlas, BM atlas_bm)
Definition GameApi_gui.cc:6150
IMPORT W waveformapi_functions_list_item(FtA font1, BM font1_bm, FtA font2, BM font2_bm, W insert, W *outer)
Definition GameApi_gui.cc:8937
IMPORT W list_item_title(int sx, std::string label, FtA atlas, BM atlas_bm)
Definition GameApi_gui.cc:3812
IMPORT int canvas_item_index(W canvas, W item)
Definition GameApi_gui.cc:3800
IMPORT W icon_shared(BM bitmap, int key)
Definition GameApi_gui.cc:4685
IMPORT W polygondistapi_functions_list_item(FtA font1, BM font1_bm, FtA font2, BM font2_bm, W insert, W *outer)
Definition GameApi_gui.cc:9024
IMPORT W search_panel(int sx, FtA atlas, BM atlas_bm, int x_gap, W *redraw_w)
Definition GameApi_gui.cc:4590
IMPORT int num_childs(W w)
Definition GameApi_gui.cc:6904
IMPORT W pts(PTS p, SH sh, int sx, int sy, int screen_size_x, int screen_size_y)
Definition GameApi_gui.cc:4726
IMPORT W long_editor(long &target, FtA atlas, BM atlas_bm, int x_gap, int noneditnum, std::string &expr)
Definition GameApi_gui.cc:4936
IMPORT std::string volumeapi_functions_item_label(int i)
Definition GameApi_gui.cc:8774
IMPORT W popup_menu(int x, int y, std::vector< std::string > labels, FtA atlas, BM atlas_bm, std::vector< W > &areas)
Definition GameApi_gui.cc:6790
IMPORT void update(W w, PT mouse_cursor_pos, int button, int ch, int type, int mouse_wheel_y)
Definition GameApi_gui.cc:6869
IMPORT W size(W item, int sx, int sy)
Definition GameApi_gui.cc:6118
IMPORT std::string blockerapi_functions_item_label(GameApi::EveryApi &ev, int i)
Definition GameApi_gui.cc:8700
IMPORT W volumeapi_functions_list_item(FtA font1, BM font1_bm, FtA font2, BM font2_bm, W insert, W *outer)
Definition GameApi_gui.cc:8968
IMPORT W mouse_move(W widget, int area_x, int area_y, int area_width, int area_height)
Definition GameApi_gui.cc:4104
IMPORT W array_x(W *arr, int size, int x_gap)
Definition GameApi_gui.cc:6129
IMPORT W shaderapi_functions_list_item(FtA font1, BM font1_bm, FtA font2, BM font2_bm, W insert, W *outer)
Definition GameApi_gui.cc:8986
IMPORT W shader_dialog(SFO p, W &close_button, FtA atlas, BM atlas_bm, int screen_size_x, int screen_size_y, W &codegen_button, W &collect_button)
Definition GameApi_gui.cc:5322
IMPORT W margin(W item, int left, int top, int right, int bottom)
Definition GameApi_gui.cc:6113
IMPORT W asset_item(EveryApi &ev, std::string jpg_url, std::string jpg_display_name, FtA atlas, BM atlas_bm)
Definition GameApi_gui.cc:4177
IMPORT std::string floatbitmapapi_functions_item_label(int i)
Definition GameApi_gui.cc:8805
IMPORT W text(std::string label, FtA atlas, BM atlas_bm, int x_gap=3)
Definition GameApi_gui.cc:4658
IMPORT W center_y(W item, int sy)
Definition GameApi_gui.cc:5808
IMPORT W edit_dialog(const std::vector< std::string > &labels, const std::vector< EditTypes * > &vec, Ft font, const std::vector< std::string > &types, W &cancel_button, W &ok_button)
IMPORT int canvas_item(W canvas, W item, int x, int y)
Definition GameApi_gui.cc:3776
IMPORT void set_size(W ow, float sx, float sy)
Definition GameApi_gui.cc:6863
IMPORT W license_dialog(std::vector< std::string > filename, std::vector< std::string > &license_url, std::vector< std::string > &author_names, FtA atlas, BM atlas_bm, FtA atlas2, BM atlas_bm2, FtA atlas3, BM atlas_bm3, W &next_button, W &cancel_button, W &canvas2, W &canvas_area, W &scroll_bar)
Definition GameApi_gui.cc:4256
IMPORT W window_decoration2(int sx, int sy, std::string label, FtA atlas, BM atlas_bm, bool move)
Definition GameApi_gui.cc:5371
IMPORT W button(int sx, int sy, unsigned int color_1, unsigned int color_2)
Definition GameApi_gui.cc:6650
IMPORT W asset_dialog(EveryApi &ev, std::vector< std::string > jpg_urls, std::vector< std::string > jpg_display_names, W &select_button, W &cancel_button, FtA atlas, BM atlas_bm)
Definition GameApi_gui.cc:4192
IMPORT W hide_if_array_empty(W w, std::vector< W > items, W *redraw_w)
Definition GameApi_gui.cc:4612
IMPORT W bitmap_dialog(BM bm, W &close_button, FtA atlas, BM atlas_bm, W &codegen_button, W &collect_button, FtA atlas_tiny, BM atlas_tiny_bm)
Definition GameApi_gui.cc:5526
IMPORT void delete_widget(W w)
Definition GameApi_gui.cc:9075
IMPORT W canvas_item_gameapi_node(int sx, int sy, std::string label, std::vector< std::string > param_types, std::vector< std::string > param_tooltips, std::string return_type, FtA atlas, BM atlas_bm, std::vector< W * > connect_click, std::string uid, std::vector< W > &params, std::string symbol, std::string comment)
Definition GameApi_gui.cc:4454
IMPORT std::string floatvolumeapi_functions_item_label(int i)
Definition GameApi_gui.cc:8781
IMPORT W center_align(W item, int sx)
Definition GameApi_gui.cc:5803
IMPORT W poly(P p, SH sh, int sx, int sy, int screen_size_x, int screen_size_y)
Definition GameApi_gui.cc:4695
IMPORT W menu(W main_menu, int menu_id, std::vector< std::string > labels, FtA atlas, BM atlas_bm)
Definition GameApi_gui.cc:6760
IMPORT void set_id(W w, std::string id)
Definition GameApi_gui.cc:6972
IMPORT W icon(BM bitmap)
Definition GameApi_gui.cc:4670
IMPORT std::string waveformapi_functions_item_label(int i)
Definition GameApi_gui.cc:8693
IMPORT W pointsapi_functions_list_item(FtA font1, BM font1_bm, FtA font2, BM font2_bm, W insert, W *outer)
Definition GameApi_gui.cc:8998
IMPORT W get_child(W w, int i)
Definition GameApi_gui.cc:6914
IMPORT W key_area(W widget, int area_x, int area_y, int area_width, int area_height, int key)
Definition GameApi_gui.cc:4097
IMPORT W click_area(W widget, int area_x, int area_y, int area_width, int area_height, int button_id)
Definition GameApi_gui.cc:4091
IMPORT W layout_rb(W item, int left, int top, int width, int height, int right, int bottom, int(*fptr_r)(void *), int(*fptr_b)(void *), void *ctx1, void *ctx2)
Definition GameApi_gui.cc:6095
IMPORT W textureapi_functions_list_item(FtA font1, BM font1_bm, FtA font2, BM font2_bm, W insert, W *outer)
Definition GameApi_gui.cc:8946
IMPORT std::string polygondistapi_functions_item_label(int i)
Definition GameApi_gui.cc:8767
IMPORT std::string moveapi_functions_item_label(int i)
Definition GameApi_gui.cc:8834
IMPORT W empty()
Definition GameApi_gui.cc:3682
IMPORT void generic_to_string(const EditTypes &source, std::string type, std::string &target, std::string &expr)
Definition GameApi_gui.cc:5890
IMPORT W float_editor(float &target, std::string &target_expr, FtA atlas, BM atlas_bm, int x_gap, int noneditnum=0)
Definition GameApi_gui.cc:4748
IMPORT W highlight(int sx, int sy)
Definition GameApi_gui.cc:6071
IMPORT std::string shadermoduleapi_functions_item_label(int i)
Definition GameApi_gui.cc:8724
IMPORT void string_to_generic(EditTypes &target, std::string type, const std::string &source, const std::string &expr)
Definition GameApi_gui.cc:5824
IMPORT W color_editor(std::string &col, FtA atlas, BM atlas_bm, int x_gap, int noneditnum, std::string &expr)
Definition GameApi_gui.cc:4951
IMPORT W layout_lt(W item, int left, int top, int width, int height, int right, int bottom, int(*fptr_l)(void *), int(*fptr_t)(void *), void *ctx1, void *ctx2)
Definition GameApi_gui.cc:6085
IMPORT W find_canvas_item(W canvas, std::string id)
Definition GameApi_gui.cc:3739
IMPORT W string_editor(std::string allowed_chars, std::string &target, std::string &target_expr, FtA atlas, BM atlas_bm, int x_gap, int non_editable, W *redraw_w, bool allow_expr=true)
Definition GameApi_gui.cc:4731
IMPORT W left_align(W item, int sx)
Definition GameApi_gui.cc:5798
IMPORT int chosen_item(W w)
Definition GameApi_gui.cc:6886
IMPORT W url_editor(std::string &target, FtA atlas, BM atlas_bm, int x_gap, std::string &expr, int noneditnum=0)
Definition GameApi_gui.cc:4759
IMPORT W ml_dialog(ML p, SH sh, SH sh2, SH sh_2d, SH sh_arr, int screen_size_x, int screen_size_y, W &close_button, FtA atlas, BM atlas_bm, W &codegen_button, W &collect_button)
Definition GameApi_gui.cc:5275
IMPORT W enum_editor(EveryApi &ev, W &click_target, int &target, FtA atlas, BM atlas_bm, int x_gap, std::string type, std::string &expr, int noneditnum=0)
Definition GameApi_gui.cc:4793
IMPORT void del_canvas_item(W canvas, int id)
Definition GameApi_gui.cc:3789
IMPORT ML async_url(std::string url, ML ml)
Definition GameApi_gui.cc:7922
Definition GameApi_gui.hh:57
virtual void render()
Definition GameApi_gui.hh:176
virtual Point2d get_pos() const
Definition GameApi_gui.hh:97
virtual void set_size(Vector2d size_p)
Definition GameApi_gui.hh:118
virtual Vector2d get_size() const
Definition GameApi_gui.hh:98
virtual int render_to_bitmap()
Definition GameApi_gui.cc:6817
int firsttime
Definition GameApi_gui.hh:269
virtual bool is_visible() const
Definition GameApi_gui.hh:93
void show()
Definition GameApi_gui.hh:84
virtual void set_pos(Point2d new_pos)
Definition GameApi_gui.hh:99
GameApi::EveryApi & ev
Definition GameApi_gui.hh:265
std::vector< GuiWidget * > vec
Definition GameApi_gui.hh:273
GuiWidgetForward(GameApi::EveryApi &ev, std::vector< GuiWidget * > vec)
Definition GameApi_gui.hh:59
Point2d pos
Definition GameApi_gui.hh:266
Vector2d size
Definition GameApi_gui.hh:267
virtual void update(Point2d mouse_pos, int button, int ch, int type, int mouse_wheel_y)
Definition GameApi_gui.hh:124
virtual bool content_changed() const
Definition GameApi_gui.hh:222
Definition GraphI.hh:1296
virtual void update(Point2d mouse_pos, int button, int ch, int type, int mouse_wheel_y)=0
virtual float dynamic_param(int id) const =0
virtual void set_size(Vector2d size)=0
virtual void select_item(int item)=0
virtual int chosen_item() const =0
GuiWidget()
Definition GraphI.hh:1298
void set_size2(int sz)
Definition GraphI.hh:1304
void set_id(std::string id_m)
Definition GraphI.hh:1300
void set_index(int j)
Definition GraphI.hh:1302
virtual Vector2d get_size() const =0
virtual Point2d get_pos() const =0
int get_index() const
Definition GraphI.hh:1303
virtual void render()=0
virtual GuiWidget * child(int num) const =0
std::string get_id() const
Definition GraphI.hh:1301
virtual void set_pos(Point2d pos)=0
virtual void set_dynamic_param(int id, float val)=0
int get_size2() const
Definition GraphI.hh:1305
Definition GameApi_gui.cc:528
bool is_visible2() const
Definition GameApi_gui.cc:603
virtual Point2d get_pos() const
Definition GameApi_gui.cc:599
void set_pos(Point2d pos)
Definition GameApi_gui.cc:538
int render_to_bitmap()
Definition GameApi_gui.cc:633
bool content_changed() const
Definition GameApi_gui.cc:635
HideNonSearchableGuiWidget(GameApi::Env &env, GameApi::EveryApi &ev, GuiWidget *w2, std::string label, GameApi::W *redraw_w)
Definition GameApi_gui.cc:530
void render()
Definition GameApi_gui.cc:628
virtual Vector2d get_size() const
Definition GameApi_gui.cc:600
void set_size(Vector2d size_p)
Definition GameApi_gui.cc:543
void update(Point2d mouse, int button, int ch, int type, int mouse_wheel_y)
Definition GameApi_gui.cc:559
Definition GameApi_gui.cc:400
virtual Vector2d get_size() const
Definition GameApi_gui.cc:490
HideWidgetIfArrayEmpty(GameApi::Env &env, GameApi::EveryApi &ev, GuiWidget *w2, std::vector< GuiWidget * > items, GameApi::W *redraw_w)
Definition GameApi_gui.cc:402
void update(Point2d mouse, int button, int ch, int type, int mouse_wheel_y)
Definition GameApi_gui.cc:437
virtual Point2d get_pos() const
Definition GameApi_gui.cc:489
bool is_visible2() const
Definition GameApi_gui.cc:423
bool is_visible() const
Definition GameApi_gui.cc:421
void set_size(Vector2d size_p)
Definition GameApi_gui.cc:415
void set_pos(Point2d pos)
Definition GameApi_gui.cc:409
bool content_changed() const
Definition GameApi_gui.cc:505
void render()
Definition GameApi_gui.cc:492
int chosen_item() const
Definition GameApi_gui.cc:491
int render_to_bitmap()
Definition GameApi_gui.cc:502
Definition GraphI.hh:1615
virtual void Prepare()=0
virtual void Collect(CollectVisitor &vis)=0
virtual std::vector< int > shader_id()
Definition GraphI.hh:1625
virtual void handle_event(MainLoopEvent &e)=0
virtual void execute(MainLoopEnv &e)=0
static Matrix Scale(float x, float y, float z)
Definition VectorTools.cc:556
Definition GameApi_gui.cc:332
MousePositionTweakForEditors(GameApi::EveryApi &ev, GuiWidget *inner, GuiWidget *outer, GuiWidget *outerouter)
Definition GameApi_gui.cc:334
int chosen_item() const
Definition GameApi_gui.cc:376
Point2d get_mouse_tweak(Point2d p, bool &done)
Definition GameApi_gui.cc:352
virtual Vector2d get_size() const
Definition GameApi_gui.cc:375
virtual Point2d get_pos() const
Definition GameApi_gui.cc:374
void render()
Definition GameApi_gui.cc:377
void set_pos(Point2d pos)
Definition GameApi_gui.cc:340
void update(Point2d mouse, int button, int ch, int type, int mouse_wheel_y)
Definition GameApi_gui.cc:364
void set_size(Vector2d size_p)
Definition GameApi_gui.cc:346
int render_to_bitmap()
Definition GameApi_gui.cc:381
Definition GameApi_gui.cc:947
void update(Point2d mouse, int button, int ch, int type, int mouse_wheel_y)
Definition GameApi_gui.cc:957
void render()
Definition GameApi_gui.cc:1039
MultilineEditor(GameApi::EveryApi &ev, std::string allowed_chars, T &target_m, GameApi::FI font, GameApi::SH sh, int x_gap, int line_height)
Definition GameApi_gui.cc:949
Definition GameApi_low.hh:299
virtual void glEnable(int val)=0
virtual void glViewport(int x, int y, unsigned int w, unsigned int h)=0
virtual void glDisable(int val)=0
virtual void glScissor(float x, float y, float w, float h)=0
Definition GameApi_gui.cc:689
int render_to_bitmap()
Definition GameApi_gui.cc:705
void render()
Definition GameApi_gui.cc:699
OverlapGuiWidget(GameApi::EveryApi &ev, std::vector< GuiWidget * > vec)
Definition GameApi_gui.cc:691
void set_size(Vector2d v)
Definition GameApi_gui.cc:707
void update(Point2d mouse, int button, int ch, int type, int mouse_wheel_y)
Definition GameApi_gui.cc:692
@ EDragDropInfoMessage
Definition test.cpp:180
virtual Low_SDL_Joystick * SDL_JoystickOpen(int i)=0
virtual unsigned int SDL_JoystickGetButton(Low_SDL_Joystick *joy, int i)=0
Definition GameApi_gui.cc:726
TextGuiWidgetAtlas(GameApi::EveryApi &ev, std::string label, GameApi::FtA atlas, GameApi::BM atlas_bm, GameApi::SH sh, int x_gap)
Definition GameApi_gui.cc:728
int render_to_bitmap()
Definition GameApi_gui.cc:791
void update(Point2d mouse, int button, int ch, int type, int mouse_wheel_y)
Definition GameApi_gui.cc:736
void render()
Definition GameApi_gui.cc:776
Definition GameApi_gui.cc:77
TimedWidget2(GameApi::EveryApi &ev, GuiWidget *next, float time)
Definition GameApi_gui.cc:79
void update(Point2d mouse_pos, int button, int ch, int type, int mouse_wheel_y)
Definition GameApi_gui.cc:83
void set_size(Vector2d v)
Definition GameApi_gui.cc:93
Definition GameApi_gui.cc:102
void update(Point2d mouse_pos, int button, int ch, int type, int mouse_wheel_y)
Definition GameApi_gui.cc:114
~TimedWidget()
Definition GameApi_gui.cc:113
TimedWidget(GameApi::EveryApi &ev, GuiWidget *next, GameApi::W(*timed_func)(void *), void *data, GuiWidgetForward *insert_wid, float start_duration, float duration, float dx)
Definition GameApi_gui.cc:104
void set_size(Vector2d v)
Definition GameApi_gui.cc:175
IMPORT int g_event_screen_y
Definition GameApi.cc:18167
IMPORT Low_SDL_Window * sdl_window
Definition GameApi.cc:38469
IMPORT bool g_transparent
Definition GameApi_gui.cc:1693
IMPORT int g_event_screen_x
Definition GameApi.cc:18166
int find_str(std::string val, std::string repl)
Definition GameApi.cc:26716
IMPORT GameApi::PAT gameapi_temp_dir
Definition test.cpp:4591
bool g_dragdrop_enabled
Definition GameApi_gui.cc:1067
IMPORT void enum_set_value(GameApi::Env &e, GameApi::W enum_click, int value)
Definition GameApi_gui.cc:4889
W functions_widget(GameApi::GuiApi &gui, std::string label, std::vector< GameApiItem * > vec, GameApi::FtA atlas, GameApi::BM atlas_bm, GameApi::FtA atlas2, GameApi::BM atlas_bm2, GameApi::W insert)
IMPORT PathHandler * g_path_handler
Definition GameApi_dep_env.cc:6102
GameApi::W enum_click
Definition GameApi_gui.cc:4828
int async_pending_count
Definition GameApi.cc:18142
ASyncData * g_async_ptr2
Definition GameApi_gui.cc:7817
std::vector< std::string > g_registered_urls
Definition GameApi_gui.cc:7899
std::string g_dragdrop_filename
Definition GameApi_gui.cc:1068
IMPORT ArrayType * find_array(GameApi::Env &e, GameApi::ARR arr)
Definition GameApi_dep_add_find.cc:1924
int g_window_pos_y
Definition GameApi_gui.cc:3869
IMPORT void ProgressBar(int num, int val, int max, std::string label)
Definition GameApi_dep_env.cc:4198
void save_mod_txt_from_script_file2(GameApi::EveryApi &ev, std::string input_script_filename, std::string output_mod_txt_filename)
Definition GameApi_gui.cc:7610
IMPORT void InstallProgress(int num, std::string label, int max=15)
Definition GameApi_dep_env.cc:3971
int g_window_pos_x
Definition GameApi_gui.cc:3868
const char * g_videodriver
Definition Main.cc:2092
IMPORT void enum_editor_handle_event(GameApi::GuiApi &gui, std::vector< GameApi::W > vec, int button)
Definition GameApi_gui.cc:4870
GameApi::GuiApi * g_everyapi_gui
Definition GameApi_dep_env.cc:4174
GameApi::W enum_popup
Definition GameApi_gui.cc:4827
IMPORT bool file_exists(std::string s)
Definition GameApi_dep_env.cc:4387
std::vector< GameApiItem * > global_functions
Definition GameApi_gui.cc:8637
int g_async_count2
Definition GameApi_gui.cc:7818
IMPORT bool g_reload_edit_dialog
Definition test.cpp:79
IMPORT bool enum_editor_callback(GameApi::Env &env, GameApi::GuiApi &gui, GameApi::W click_widget, std::string type, int mouse_x, int mouse_y, GameApi::FtA atlas, GameApi::BM atlas_bm, int x_gap, std::vector< GameApi::W > &areas, int button, int type2)
Definition GameApi_gui.cc:4829
void update_progress_dialog_cb_impl(volatile GameApi::W &w, int x, int y, GameApi::FtA f, GameApi::BM b, std::vector< std::string >, int val, int max, int process)
Definition GameApi_gui.cc:4432
IMPORT void enum_editor_draw(GameApi::EveryApi &ev, GameApi::GuiApi &gui)
Definition GameApi_gui.cc:4864
let delta_y
Definition gameapi_example.php:63
let delta_x
Definition gameapi_example.php:62
background color
Definition gameapi_example.php:46
PT func2(int face, int point, EveryApi &ev)
Definition test.cpp:27
exit
Definition mesh_ai_bm.php:3
left margin
Definition mesh_preview.php:76
d
Definition meshpage.php:3895
iVBORw0KGgoAAAANSUhEUgAAANcAAAB5CAMAAACdtUQZAAAA51BMVEX</div ></div >< div style="padding: 0px 0px; width: 1324px;">< div style="height: 400px; width: 1324px;"></div >< div itemscope itemtype="https: </div><div itemscope itemtype="https:</div >< div itemscope itemtype="https: </div></div><p><div style="padding:0px 0px;width:1324px;"><div></div><div itemscope itemtype="https:< ul >< li >< b > Application name
8AkrcAgqgAs9wqQ0ey2tkAo8gAuuQfeI4hPUH09fXHy8z4+fng4uNKXF/Lz9BzfoAcgpkQMTUAKjAbOT4Qr9AXhJ8Rl7ktMCwTosA...
Definition meshpage.php:1610
lazy data
Definition meshpage.php:1583
str
Definition meshpage.php:1778
n< br > font size
Definition meshpage.php:3536
url
Definition meshpage.php:1781
not_this_one end(...)
Numeric sum(Range c)
Returns the sum total of the values in the Range c.
int collect_counter(int mode)
IMPORT std::pair< int, std::string > execute_codegen(Env &e2, EveryApi &ev, std::string text, ExecuteEnv &e)
Definition GameApi_gui.cc:8557
size_t count(const T &t_target, const typename T::key_type &t_key)
Definition bootstrap_stl.hpp:104
void insert(T &t_target, const T &t_other)
Definition bootstrap_stl.hpp:110
auto child_count(const eval::AST_Node_Impl< T > &node)
Definition chaiscript_optimizer.hpp:60
auto get(const nlohmann::detail::iteration_proxy_value< IteratorType > &i) -> decltype(i.key())
Definition json.hpp:1781
STL namespace.
double f(const std::string &, double, bool) noexcept
Definition profile_cpp_calls_2.cpp:4
Definition GameApi_dep_env.cc:2495
void(* fptr)(void *)
Definition GameApi_dep_env.cc:2495
void * data
Definition GameApi_dep_env.cc:2495
Definition test.cpp:815
std::vector< int > vec
Definition test.cpp:84
Definition Parser.hh:8
Definition GameApi_cmd.hh:41
Definition GameApi_h.hh:672
::EnvImpl * Environment(GameApi::Env *e)
Definition GameApi_h.hh:848
Definition GameApi_h.hh:615
int sy
Definition GameApi_h.hh:616
int y
Definition GameApi_h.hh:618
int top
Definition GameApi_h.hh:619
Definition GameApi_h.hh:626
Definition GraphI.hh:1409
std::vector< std::string > param_names
Definition GraphI.hh:1411
std::string function_name
Definition GraphI.hh:1410
std::vector< std::string > param_types
Definition GraphI.hh:1412
std::vector< GameApiLine > lines
Definition GraphI.hh:1413
std::string uid
Definition GraphI.hh:1401
std::vector< GameApiParam > params
Definition GraphI.hh:1405
int y
Definition GraphI.hh:1399
int x
Definition GraphI.hh:1399
std::string module_name
Definition GraphI.hh:1400
int sz
Definition GraphI.hh:1403
int j
Definition GraphI.hh:1402
bool array_return
Definition GraphI.hh:1404
Definition GraphI.hh:1417
std::vector< GameApiFunction > funcs
Definition GraphI.hh:1418
std::string param_name
Definition test.cpp:368
bool is_array
Definition test.cpp:370
GameApiLine * array_return_target
Definition test.cpp:371
std::string value
Definition test.cpp:369
int j
Definition GraphI.hh:1346
int id
Definition GameApi.hh:112
Definition Common.hh:74
Definition Common.hh:71
int id
Definition Common.hh:71
Definition Common.hh:76
Definition GameApi.hh:4664
Definition GameApi.hh:301
Definition Common.hh:75
Definition Common.hh:39
Definition Common.hh:155
Definition Common.hh:97
Definition GameApi.hh:2373
float f_value
Definition GameApi.hh:2376
std::string s
Definition GameApi.hh:2379
int i_value
Definition GameApi.hh:2374
float f_z
Definition GameApi.hh:2377
float f_x
Definition GameApi.hh:2377
std::string color
Definition GameApi.hh:2378
float f_y
Definition GameApi.hh:2377
std::string expr
Definition GameApi.hh:2380
long l_value
Definition GameApi.hh:2375
Definition Common.hh:21
Definition Common.hh:140
Definition Common.hh:156
Definition Common.hh:144
Definition Common.hh:79
Definition Common.hh:86
Definition Common.hh:152
Definition Common.hh:92
Definition Common.hh:124
Definition Common.hh:153
int id
Definition Common.hh:153
std::string url
Definition GameApi_dep_env.cc:3025
std::string url3
Definition GameApi_dep_env.cc:3026
char * buf3
Definition GameApi_dep_env.cc:3028
char * buf2
Definition GameApi_dep_env.cc:3027
OpenglLowApi * ogl
Definition GameApi_low.hh:814
SDLLowApi * sdl
Definition GameApi_low.hh:819
Definition GameApi_low.hh:680
Definition VectorTools.hh:910
float x
Definition VectorTools.hh:911
float y
Definition VectorTools.hh:911
Definition Parser.cc:60
float x
Definition Parser.cc:60
float y
Definition Parser.cc:60
float z
Definition Parser.cc:60
Definition GameApi.h:42
int id
Definition GameApi.h:42
Definition VectorTools.hh:972
float dy
Definition VectorTools.hh:973
float dx
Definition VectorTools.hh:973
Definition GameApi.h:89
int to_int(TestEnum t)
Definition test_module.cpp:73
W link(std::string url, std::string str, int size_x, int size_y, int font_size, unsigned int font_colour, int align)
Definition ui.cc:731
W empty()
Definition ui.cc:634
W center_y(W item, int sy)
Definition ui.cc:947
W editor(std::string name, std::string value, std::string placeholder, int size_x, int size_y, int font_size, unsigned int font_colour, int align)
Definition ui.cc:1148
W layer(std::vector< W > v)
Definition ui.cc:737
W right_align(W item, int sx)
Definition ui.cc:935
W center_align(W item, int sx)
Definition ui.cc:941
W hide(W widget)
Definition ui.cc:954
W max_width(W w1, int width)
get_label( $arr)
Definition user.php:289
num
Definition view.php:2821
P line_func(int i, float sx, float sy, float sz, float ex, float ey, float ez, unsigned int scolor, unsigned int ecolor, EveryApi &ev)
Definition test.cpp:87