66#include < string>
77#include < iostream>
88
9+
910using string = std::string;
1011using glm::vec2;
1112
@@ -43,9 +44,15 @@ void render(FunctionState& state, unsigned int& op_tex, unsigned int& const_tex,
4344 state.is_interpreted = true ;
4445}
4546
46- void compile (FunctionState& state, CompilerShader& compiler_shader) {
47+ void compile (FunctionState& state, CompilerShader& compiler_shader, unsigned int & op_tex, unsigned int & const_tex ) {
4748 try {
4849 vector<TokenOperator> stack = parser::parse (state.expression );
50+ vector<unsigned char > operator_stack;
51+ vector<vec2> constant_stack;
52+ get_stacks (stack, operator_stack, constant_stack);
53+ unsigned int op_tbo_buf, const_tbo_buf;
54+ populate_texture (op_tbo_buf, op_tex, operator_stack);
55+ populate_texture (const_tbo_buf, const_tex, constant_stack);
4956 const string& expression = stack_to_glsl_string (stack);
5057 compiler_shader.compile (expression,state.is_3d );
5158 }
@@ -57,13 +64,56 @@ void compile(FunctionState& state, CompilerShader& compiler_shader) {
5764 state.is_interpreted = false ;
5865}
5966
60- void change_3d_mode (ViewState& view_state) {
6167
68+ void render_inspector_overlay (const PickerResult& hover, ViewState& view_state) {
69+ const float padding = 10 .0f ;
70+ const ImVec2 offset = ImVec2 (15 .0f , 15 .0f );
71+ const ImGuiViewport* viewport = ImGui::GetMainViewport ();
72+ ImVec2 work_pos = viewport->WorkPos ;
73+ ImVec2 work_size = viewport->WorkSize ;
74+
75+ if (view_state.inspector_follows_mouse ) {
76+ const ImVec2 mouse_pos = ImGui::GetMousePos ();
77+ ImGui::SetNextWindowPos (ImVec2 (offset.x + mouse_pos.x , offset.y + mouse_pos.y ), ImGuiCond_Always);
78+ }
79+ else {
80+ ImVec2 window_pos, window_pos_pivot;
81+ window_pos.x = work_pos.x + work_size.x - padding;
82+ window_pos.y = work_pos.y + work_size.y - padding;
83+ window_pos_pivot = ImVec2 (1 .0f , 1 .0f );
84+ ImGui::SetNextWindowPos (window_pos, ImGuiCond_Always, window_pos_pivot);
85+ }
86+ ImGui::SetNextWindowBgAlpha (0 .65f );
87+
88+ ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoDecoration |
89+ ImGuiWindowFlags_AlwaysAutoResize |
90+ ImGuiWindowFlags_NoSavedSettings |
91+ ImGuiWindowFlags_NoFocusOnAppearing |
92+ ImGuiWindowFlags_NoNav |
93+ ImGuiWindowFlags_NoInputs;
94+ if (ImGui::Begin (" Inspector" , nullptr , window_flags)) {
95+ ImGui::Text (" Coordinate (z)" );
96+ ImGui::Separator ();
97+ ImGui::Text (" %.3f %s %.3fi" ,
98+ hover.coordinate .x ,
99+ (hover.coordinate .y >= 0 ? " +" : " -" ),
100+ std::abs (hover.coordinate .y ));
101+
102+ ImGui::Spacing ();
103+
104+ ImGui::Text (" Value f(z)" );
105+ ImGui::Separator ();
106+ ImGui::Text (" %.3f %s %.3fi" ,
107+ hover.value .x ,
108+ (hover.value .y >= 0 ? " +" : " -" ),
109+ std::abs (hover.value .y ));
110+ }
111+ ImGui::End ();
62112}
63113
64114
65- void render_and_update (FunctionState& state, ViewState& view_state, unsigned int & op_tex, unsigned int & const_tex, Shader& interpreter_shader, CompilerShader& compiler_shader, bool & should_switch ) {
66- ImGui::Begin (" Function Control " , nullptr , ImGuiWindowFlags_AlwaysAutoResize);
115+ void render_and_update (FunctionState& state, ViewState& view_state, unsigned int & op_tex, unsigned int & const_tex, Shader& interpreter_shader, CompilerShader& compiler_shader) {
116+ ImGui::Begin (" Function Editor " , nullptr , ImGuiWindowFlags_AlwaysAutoResize);
67117 ImGui::SameLine ();
68118 if (state.is_interpreted ) {
69119 ImGui::TextColored (ImVec4 (1 .0f , 0 .8f , 0 .0f , 1 .0f ), " [ INTERPRETED ]" );
@@ -104,7 +154,7 @@ void render_and_update(FunctionState& state, ViewState& view_state, unsigned int
104154 const bool debounced = time_dif > DEBOUNCE_DELAY ;
105155
106156 if (pressed_enter) {
107- compile (state, compiler_shader);
157+ compile (state, compiler_shader, op_tex, const_tex );
108158 }
109159 if (state.needs_reparse && debounced && !pressed_enter) {
110160 render (state, op_tex, const_tex, interpreter_shader);
@@ -131,6 +181,13 @@ void render_and_update(FunctionState& state, ViewState& view_state, unsigned int
131181 if (ImGui::RadioButton (" 3D Surface" , state.is_3d )) {
132182 view_state.is_3d = true ;
133183 }
184+ ImGui::Checkbox (" Show Value Inspector" , &view_state.show_inspector );
185+
186+ if (view_state.show_inspector ) {
187+ ImGui::Indent ();
188+ ImGui::Checkbox (" Follow Mouse" , &view_state.inspector_follows_mouse );
189+ ImGui::Unindent ();
190+ }
134191 }
135192
136193 if (ImGui::CollapsingHeader (" 3D Keybinds" )) {
0 commit comments