66#include < string>
77#include < iostream>
88
9+ #include < imgui.h>
10+ #include < imgui_stdlib.h>
11+
912#include < interactions/export.h>
1013
1114
@@ -17,15 +20,15 @@ const float DEBOUNCE_DELAY = 0.05f;
1720namespace UI {
1821 bool Button (const char * label, const ImVec2& size = ImVec2(0 , 0 )) {
1922 bool clicked = ImGui::Button (label, size);
20-
23+
2124 if (ImGui::IsItemHovered ()) {
2225 ImGui::SetMouseCursor (ImGuiMouseCursor_Hand);
2326 }
2427 return clicked;
2528 }
2629
2730 bool RadioButton (const char * label, const bool cond) {
28- bool clicked = ImGui::RadioButton (label,cond);
31+ bool clicked = ImGui::RadioButton (label, cond);
2932 if (ImGui::IsItemHovered ()) {
3033 ImGui::SetMouseCursor (ImGuiMouseCursor_Hand);
3134 }
@@ -48,56 +51,44 @@ namespace UI {
4851}
4952
5053
51- int input_text_callback (ImGuiInputTextCallbackData* data) {
52- if (data->EventFlag != ImGuiInputTextFlags_CallbackResize) {
53- return 0 ;
54- }
55- string* s = static_cast <string*>(data->UserData );
56- s->resize (data->BufTextLen );
57- data->Buf = static_cast <char *>(s->data ());
58- return 0 ;
59- }
60-
61-
62-
6354void render (FunctionState& state, unsigned int & op_tex, unsigned int & const_tex, Shader& interpreter_shader) {
64- try {
65- vector<TokenOperator> stack = parser::parse (state.expression );
66- vector<unsigned char > operator_stack;
67- vector<vec2> constant_stack;
68- get_stacks (stack, operator_stack, constant_stack);
69- unsigned int op_tbo_buf, const_tbo_buf;
70- populate_texture (op_tbo_buf, op_tex, operator_stack);
71- populate_texture (const_tbo_buf, const_tex, constant_stack);
72- state.error_message = " " ;
73- state.needs_reparse = false ;
74- }
75- catch (const std::runtime_error& e) {
76- state.error_message = e.what ();
77- state.needs_reparse = false ;
78- }
79- state.current_shader = &interpreter_shader;
80- state.is_interpreted = true ;
55+ try {
56+ vector<TokenOperator> stack = parser::parse (state.expression );
57+ vector<unsigned char > operator_stack;
58+ vector<vec2> constant_stack;
59+ get_stacks (stack, operator_stack, constant_stack);
60+ unsigned int op_tbo_buf, const_tbo_buf;
61+ populate_texture (op_tbo_buf, op_tex, operator_stack);
62+ populate_texture (const_tbo_buf, const_tex, constant_stack);
63+ state.error_message = " " ;
64+ state.needs_reparse = false ;
65+ }
66+ catch (const std::runtime_error& e) {
67+ state.error_message = e.what ();
68+ state.needs_reparse = false ;
69+ }
70+ state.current_shader = &interpreter_shader;
71+ state.is_interpreted = true ;
8172}
8273
8374void compile (FunctionState& state, CompilerShader& compiler_shader, unsigned int & op_tex, unsigned int & const_tex) {
84- try {
85- vector<TokenOperator> stack = parser::parse (state.expression );
75+ try {
76+ vector<TokenOperator> stack = parser::parse (state.expression );
8677 vector<unsigned char > operator_stack;
8778 vector<vec2> constant_stack;
8879 get_stacks (stack, operator_stack, constant_stack);
8980 unsigned int op_tbo_buf, const_tbo_buf;
9081 populate_texture (op_tbo_buf, op_tex, operator_stack);
9182 populate_texture (const_tbo_buf, const_tex, constant_stack);
92- const string& expression = stack_to_glsl_string (stack);
93- compiler_shader.compile (expression,state.is_3d );
94- }
95- catch (const std::runtime_error& e) {
96- state.error_message = e.what ();
97- state.needs_reparse = false ;
98- }
99- state.current_shader = &compiler_shader.shader ;
100- state.is_interpreted = false ;
83+ const string& expression = stack_to_glsl_string (stack);
84+ compiler_shader.compile (expression, state.is_3d );
85+ }
86+ catch (const std::runtime_error& e) {
87+ state.error_message = e.what ();
88+ state.needs_reparse = false ;
89+ }
90+ state.current_shader = &compiler_shader.shader ;
91+ state.is_interpreted = false ;
10192}
10293
10394
@@ -116,7 +107,7 @@ void render_inspector_overlay(const PickerResult& hover, ViewState& view_state)
116107 ImVec2 window_pos, window_pos_pivot;
117108 window_pos.x = work_pos.x + work_size.x - padding;
118109 window_pos.y = work_pos.y + work_size.y - padding;
119- window_pos_pivot = ImVec2 (1 .0f , 1 .0f );
110+ window_pos_pivot = ImVec2 (1 .0f , 1 .0f );
120111 ImGui::SetNextWindowPos (window_pos, ImGuiCond_Always, window_pos_pivot);
121112 }
122113 ImGui::SetNextWindowBgAlpha (0 .65f );
@@ -168,11 +159,8 @@ void render_and_update(FunctionState& state, ViewState& view_state, unsigned int
168159 static bool auto_reparse = true ;
169160
170161 bool pressed_enter = ImGui::InputText (" ##source" ,
171- static_cast <char *>(state.expression .data ()),
172- state.expression .capacity () + 1 ,
173- ImGuiInputTextFlags_CallbackResize | ImGuiInputTextFlags_EnterReturnsTrue,
174- input_text_callback,
175- &state.expression );
162+ &state.expression ,
163+ ImGuiInputTextFlags_EnterReturnsTrue);
176164
177165 bool typed = ImGui::IsItemEdited ();
178166
@@ -183,7 +171,7 @@ void render_and_update(FunctionState& state, ViewState& view_state, unsigned int
183171
184172 ImGui::SameLine ();
185173 if (UI::Button (" Compile" )) {
186- pressed_enter = true ;
174+ pressed_enter = true ;
187175 }
188176 if (ImGui::IsItemHovered ()) {
189177 ImGui::SetMouseCursor (ImGuiMouseCursor_Hand);
@@ -277,9 +265,9 @@ void render_and_update(FunctionState& state, ViewState& view_state, unsigned int
277265 " sin(z)*cos(10/z)"
278266 };
279267 static int current_preset = -1 ;
280- if (ImGui::Combo (" Choose" , & current_preset, presets, IM_ARRAYSIZE (presets))) {
268+ if (ImGui::Combo (" Choose" , ¤t_preset, presets, IM_ARRAYSIZE (presets))) {
281269 state.expression = string (presets[current_preset]);
282- state.needs_reparse = true ;
270+ state.needs_reparse = true ;
283271 }
284272 }
285273 if (UI::CollapsingHeader (" Export" )) {
@@ -310,7 +298,7 @@ void render_and_update(FunctionState& state, ViewState& view_state, unsigned int
310298 }
311299 if (view_state.show_export_success ) {
312300 ImGui::OpenPopup (" Export Successful!" );
313- view_state.show_export_success = false ;
301+ view_state.show_export_success = false ;
314302 }
315303
316304 ImVec2 center = ImGui::GetMainViewport ()->GetCenter ();
@@ -321,19 +309,19 @@ void render_and_update(FunctionState& state, ViewState& view_state, unsigned int
321309 ImGui::Spacing ();
322310 ImGui::Separator ();
323311 ImGui::Spacing ();
324- #ifndef __EMSCRIPTEN__
312+ #ifndef __EMSCRIPTEN__
325313 ImGui::TextDisabled (" Check the folder where your executable is located." );
326- #else
314+ #else
327315 ImGui::TextDisabled (" Check your browser's downloads folder." );
328- #endif
316+ #endif
329317 ImGui::Spacing ();
330-
318+
331319 ImGui::SetCursorPosX ((ImGui::GetWindowSize ().x - 120 .0f ) * 0 .5f );
332320 if (UI::Button (" Awesome" , ImVec2 (120 , 0 ))) {
333321 ImGui::CloseCurrentPopup ();
334322 }
335323 ImGui::SetItemDefaultFocus ();
336-
324+
337325 ImGui::EndPopup ();
338326 }
339327
0 commit comments