16 #include "fmt/format.h"
18 #include "imgui/imgui_internal.h"
19 #include "imgui_stdlib.h"
21 #include "euph_generated_config.h"
46 ImGui::TextDisabled(ICON_MD_INFO);
54 if (ImGui::IsItemHovered())
56 ImGui::BeginTooltip();
57 ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f);
58 ImGui::TextUnformatted(desc);
59 ImGui::PopTextWrapPos();
69 ImGui::TextUnformatted(str.c_str());
85 const auto value_was_changed = ImGui::SliderFloat
98 return value_was_changed;
112 const auto value_was_changed = ImGui::DragFloat
118 if(value_was_changed)
124 return value_was_changed;
133 const auto c = ImGui::GetStyle().Colors[ImGuiCol_ButtonActive];
134 ImGui::PushStyleColor(ImGuiCol_Button, c);
135 const auto r = ImGui::Button(label, size);
136 ImGui::PopStyleColor(1);
142 return ImGui::Button(label, size);
149 return ImGui::ColorEdit3(name, &c->r);
155 return ImGui::ColorEdit4(name, &c->r);
162 const auto changed = ImGui::ColorEdit4(name, &cc.r);
176 #elif EU_ARCH_64 == 1
182 return reinterpret_cast<ImTextureID
>(id);
190 auto tex_w =
static_cast<float>(texture->
width);
191 auto tex_h =
static_cast<float>(texture->
height);
194 ImVec2 tex_screen_pos = ImGui::GetCursorScreenPos();
195 imgui_label(fmt::format(
"{:.0}x{:.0}", tex_w, tex_h));
198 ImVec2(tex_w, tex_h),
201 ImColor(255, 255, 255, 255),
202 ImColor(255, 255, 255, 128));
203 if(ImGui::IsItemHovered())
205 ImGui::BeginTooltip();
206 float focus_sz = 32.0f;
207 float focus_x = ImGui::GetMousePos().x - tex_screen_pos.x - focus_sz * 0.5f;
212 else if(focus_x > tex_w - focus_sz)
214 focus_x = tex_w - focus_sz;
216 float focus_y = ImGui::GetMousePos().y - tex_screen_pos.y
222 else if(focus_y > tex_h - focus_sz)
224 focus_y = tex_h - focus_sz;
226 imgui_label(fmt::format(
"Min: ({:.2f}, {:.2f})", focus_x, focus_y));
227 imgui_label(fmt::format(
"Max: ({:.2f}, {:.2f})", focus_x + focus_sz, focus_y + focus_sz));
228 ImVec2 uv0 = ImVec2((focus_x) / tex_w, (focus_y) / tex_h);
230 (focus_x + focus_sz) / tex_w, (focus_y + focus_sz) / tex_h);
236 ImColor(255, 255, 255, 255),
237 ImColor(255, 255, 255, 128));
248 const std::string& title,
253 const int corner_int =
static_cast<int>(corner);
255 const auto distance_x = a_distance;
256 const auto distance_y = a_distance_y > 0 ? a_distance_y : a_distance;
257 const auto size = ImGui::GetIO().DisplaySize;
259 ? ImVec2(size.x / 2, size.y / 2)
262 (corner_int & 1) != 0
263 ? size.x - distance_x
265 (corner_int & 2) != 0
266 ? size.y - distance_y
273 (corner_int & 1) != 0 ? 1.0f : 0.0f,
274 (corner_int & 2) != 0 ? 1.0f : 0.0f
276 ImGui::SetNextWindowPos(window_pos, ImGuiCond_Always, window_pos_pivot);
281 ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize
282 | ImGuiWindowFlags_AlwaysAutoResize
283 | ImGuiWindowFlags_NoMove
284 | ImGuiWindowFlags_NoSavedSettings);
294 ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * 0.5f);
301 ImGui::PopStyleVar();
310 if(ImGui::Selectable(label))
318 ImGui::TextUnformatted(label);
329 ImDrawList* draw_list,
330 const ImVec2& centre,
341 if((col & IM_COL32_A_MASK) == 0)
350 a_max + angle_offset,
353 draw_list->PathFillConvex(col);
367 constexpr
auto pi2 =
pi * 2;
368 constexpr
float angle_min =
pi * 0.75f;
369 constexpr
float angle_max =
pi * 2.25f;
370 constexpr
float angle_step = 20 * (
pi / 180);
371 constexpr
float size_outer = 20;
372 constexpr
float peg_max_end = size_outer;
373 constexpr
float peg_end = 19;
374 constexpr
float peg_start = 15;
375 constexpr
float knob_size = 15;
376 constexpr
float knob_mark_start = 15;
377 constexpr
float knob_mark_end = 8;
378 constexpr
int seg = 16;
380 ImGuiIO& io = ImGui::GetIO();
381 ImGuiStyle& imstyle = ImGui::GetStyle();
382 ImDrawList* draw_list = ImGui::GetWindowDrawList();
384 const ImVec2 start = ImGui::GetCursorScreenPos();
386 = ImVec2(start.x + size_outer, start.y + size_outer);
387 const float line_height = ImGui::GetTextLineHeight();
389 ImGui::InvisibleButton
395 size_outer * 2 + line_height + imstyle.ItemInnerSpacing.y
398 const bool is_active = ImGui::IsItemActive();
399 const bool is_hovered = ImGui::IsItemHovered();
401 const float t = (*p_value - v_min) / (v_max - v_min);
402 const float current_angle = angle_min + (angle_max - angle_min) * t;
405 bool value_changed =
false;
409 ImVec2 direct(io.MousePos.x -
center.x, io.MousePos.y -
center.y);
410 const float directl = sqrtf(direct.x * direct.x + direct.y * direct.y);
411 direct.x = direct.x / directl;
412 direct.y = direct.y / directl;
415 const auto acos = acosf(direct.x);
416 const auto ang = direct.y > 0 ? pi2 -
acos :
acos;
417 float input_angle = -ang;
419 const bool b = input_angle <
pi / 2;
425 const float input_angle_t
426 = (input_angle - angle_min) / (angle_max - angle_min);
428 if(is_active && (io.MouseDelta.x != 0.0f || io.MouseDelta.y != 0.0f))
430 *p_value = v_min + (v_max - v_min) * input_angle_t;
432 if(*p_value < v_min) { *p_value = v_min; }
433 if(*p_value > v_max) { *p_value = v_max; }
439 if(is_active && val != 0.0f)
441 float step = (v_max - v_min) / 200.0f;
442 *p_value += val * step;
443 if(*p_value < v_min) { *p_value = v_min; }
444 if(*p_value > v_max) { *p_value = v_max; }
446 value_changed =
true;
451 const auto label_color = ImGui::GetColorU32(ImGuiCol_Text);
452 const auto fill_color = ImGui::GetColorU32(ImGuiCol_FrameBg);
453 const auto knob_color = ImGui::GetColorU32(ImGuiCol_SliderGrab);
454 const auto indicator_color = ImGui::GetColorU32(ImGuiCol_Text);
455 const auto peg_color_off = ImGui::GetColorU32(ImGuiCol_TextDisabled);
456 const auto peg_color_on = ImGui::GetColorU32(ImGuiCol_Text);
457 const auto peg_color_max = ImGui::GetColorU32(ImGuiCol_Text);
460 const auto calculate_position = [=](
float ang,
float rad) -> ImVec2
462 return {
center.x + cosf(ang) * rad,
center.y + sinf(ang) * rad};
469 draw_list->AddCircleFilled(
center, size_outer, fill_color, seg);
476 for(
float angle = angle_min; angle <= marker_stop; angle += angle_step)
480 : angle <= current_angle ? peg_color_on : peg_color_off
482 draw_list->AddLine(calculate_position(angle, peg_start), calculate_position(angle, peg_end), c, 1.0f);
488 draw_list->AddLine(calculate_position(angle_max, peg_start), calculate_position(angle_max, peg_max_end), peg_color_max, 1.0f);
489 draw_list->AddLine(calculate_position(angle_min, peg_start), calculate_position(angle_min, peg_max_end), peg_color_max, 1.0f);
494 draw_list->AddLine(calculate_position(current_angle, knob_mark_start), calculate_position(current_angle, knob_mark_end), indicator_color, 2.0f);
497 ? is_active || is_hovered
502 const auto label_position = ImVec2 {start.x, start.y + size_outer * 2 + imstyle.ItemInnerSpacing.y / 4};
504 const auto value_to_str = [](
float f) -> std::string
506 std::stringstream ss;
507 ss << std::fixed << std::setprecision(3) << f;
513 const auto v = value_to_str(*p_value);
514 draw_list->AddText(label_position, label_color, v.c_str());
518 draw_list->AddText(label_position, label_color, label);
524 ImGui::SetNextWindowPos
529 start.y - line_height - imstyle.ItemInnerSpacing.y - imstyle.WindowPadding.y
532 ImGui::BeginTooltip();
533 const auto v = value_to_str(*p_value);
534 ImGui::Text(
"%s", v.c_str());
538 return value_changed;
544 ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(1, 1));
545 ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));
546 ImGui::PushStyleColor(ImGuiCol_ChildBg, background_color);
548 return ImGui::BeginChild
553 ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoMove
562 ImGui::PopStyleColor();
563 ImGui::PopStyleVar(2);
569 return ImGui::BeginCombo(label, preview);
575 return ImGui::Selectable(label, is_selected);
581 return ImGui::EndCombo();
bool imgui_angle_slider(const char *name, Angle *angle, const Angle &mindeg, const Angle &maxdeg)
bool imgui_selectable(const char *label, bool is_selected)
bool imgui_knob(const char *label, float *p_value, float v_min, float v_max, KnobStyle style)
void add_help_marker_for_previous_widget(const char *desc)
bool imgui_toggle_button(const char *label, bool down, const ImVec2 &size)
void add_circle_filled(ImDrawList *draw_list, const ImVec2 ¢re, float radius, ImU32 col, int num_segments, float angle_offset)
void imgui_label(const std::string &str)
bool begin_combo(const char *label, const char *preview)
bool begin_canvas_widget(const ImVec4 &background_color, const char *title)
@ knob_style_vis_display_value_on_hover
@ knob_style_vis_draw_background
@ knob_style_vis_value_as_tooltip
@ knob_style_vis_value_instead_of_name
@ knob_style_vis_markers_visible
@ knob_style_vis_off_marker_hidden
@ knob_style_vis_max_and_min_visible
bool begin_fixed_overlay(Corner corner, const std::string &title, float a_distance, float a_distance_y)
bool imgui_selectable_or_disabled(bool enabled, const char *label)
void imgui_image(render::Texture2 *texture)
ImTextureID c_texture_to_imgui(render::Texture2 *texture)
bool imgui_color_edit(const char *name, Rgb *c)
void add_help_text_for_previous_widget(const char *desc)
ImVec2 con(const vec2f &v)
Rgbai to_rgbai(const Rgba &c)
constexpr float c_int_to_float(int i)
Rgba to_rgba(const Rgbai &c)
constexpr float as_degrees() const
constexpr static Angle from_degrees(float degrees)