1 | #include "ZydecoCommon.hpp" |
2 | #include "GLRenderObject.hpp" |
3 | #include "GLRenderObjectImGui.hpp" |
4 | #include "Mandelbrot.hpp" |
5 |
|
6 |
|
7 | GLRenderObjectImGui::GLRenderObjectImGui(MandelbrotSettings *p_settings): |
8 | GLRenderObject::GLRenderObject("", 10), m_pSettings(p_settings) |
9 | { |
10 | m_font = ImGui::GetIO().Fonts->AddFontFromFileTTF("/usr/share/fonts/FiraSans-Regular.ttf", 14); |
11 | ImGui_ImplOpenGL3_CreateFontsTexture(); |
12 | } |
13 |
|
14 | void GLRenderObjectImGui::Render() |
15 | { |
16 | if (!m_renderEnabled) { return; } |
17 |
|
18 | ImGuiIO& io = ImGui::GetIO(); |
19 |
|
20 | ImGui_ImplSDL2_NewFrame(); |
21 | ImGui_ImplOpenGL3_NewFrame(); |
22 |
|
23 | ImGui::NewFrame(); |
24 |
|
25 | auto mods = io.KeyMods; |
26 | auto ctrl = io.KeyCtrl; |
27 | auto alt = io.KeyAlt; |
28 | auto shift = io.KeyShift; |
29 |
|
30 | ImGui::StyleColorsClassic(); |
31 | ImGui::PushFont(m_font); |
32 |
|
33 | static bool show_demo_window = false; |
34 | static bool show_about_window = false; |
35 | static bool show_settings_window = true; |
36 | if (ImGui::BeginMainMenuBar()) |
37 | { |
38 | ImGui::MenuItem("Zydeco", nullptr, &show_demo_window, false); |
39 | if (ImGui::BeginMenu("Help")) |
40 | { |
41 | ImGui::MenuItem("ImGui Demo", nullptr, &show_demo_window, true); |
42 | ImGui::MenuItem("About", nullptr, &show_about_window, true); |
43 | ImGui::EndMenu(); |
44 | } |
45 | ImGui::MenuItem("Fractal Settings", nullptr, &show_settings_window, true); |
46 | ImGui::EndMainMenuBar(); |
47 | } |
48 |
|
49 | ImGui::DockSpaceOverViewport(ImGui::GetMainViewport(), ImGuiDockNodeFlags_PassthruCentralNode, nullptr); |
50 |
|
51 | if (show_demo_window) { ImGui::ShowDemoWindow(&show_demo_window); } |
52 | if (show_about_window) |
53 | { |
54 | ImGui::SetNextWindowSize({350, 120}); |
55 | if (ImGui::Begin("About", &show_about_window, ImGuiWindowFlags_Modal | ImGuiWindowFlags_NoCollapse |
56 | | ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoResize)) |
57 | { |
58 | ImGui::Text("Zydeco (c) 2023 Joshua Stockin"); |
59 | ImGui::Text("<https://joshstock.in> <josh@joshstock.in>"); |
60 | ImGui::Separator(); |
61 | ImGui::TextWrapped("Zydeco is an experimental project in C++, graphics programming with OpenGL, procedural generation, and world simulation."); |
62 | ImGui::End(); |
63 | } |
64 | } |
65 | if (show_settings_window) |
66 | { |
67 | ImGui::SetNextWindowSize({0, 0}); |
68 | if (ImGui::Begin("Fractal Settings", &show_settings_window, 0)) |
69 | { |
70 | ImGui::PushItemWidth(150); |
71 | if (ImGui::DragFloat("Re[z]", &m_pSettings->param_z, 0.0025, -6, 6)) { m_pSettings->restart = true; } |
72 | //if (ImGui::SliderInt("Max Iteration Count\n(Unscaled)", &m_pSettings->iteration_count, 0, 5000)) { m_pSettings->restart = true; } |
73 | if (ImGui::SliderInt("Iteration Step", &m_pSettings->iteration_step, 50, 1000)) { m_pSettings->restart = true; } |
74 | if (ImGui::DragFloat("Discard Threshold", &m_pSettings->discard_threshold, 0.01, 0.01, 16.)) { m_pSettings->restart = true; } |
75 | ImGui::DragFloat("Brightness", &m_pSettings->brightness, 0.1, 0.1, 100.0); |
76 | ImGui::PopItemWidth(); |
77 | if (ImGui::Checkbox("Enable Interlacing", (bool*)(&m_pSettings->do_interlacing))) { m_pSettings->restart = true; } |
78 | ImGui::Text("Zoom: %.6e\nX: %.6e\nY: %.6e\nIteration %i\nFirst Interlace %i\nInterlace Layer %i\nIteration Count (Scaled): %i", |
79 | m_pSettings->zoom, |
80 | m_pSettings->pos_x, |
81 | m_pSettings->pos_y, |
82 | m_pSettings->current_iteration, |
83 | m_pSettings->first_interlace, |
84 | m_pSettings->interlace_layer, |
85 | m_pSettings->adjusted_iteration_step); |
86 | if (ImGui::Button("Reset")) |
87 | { |
88 | m_pSettings->zoom = 2.0; |
89 | m_pSettings->pos_x = 0.0; |
90 | m_pSettings->pos_y = 0.0; |
91 |
|
92 | m_pSettings->first_interlace = 1; |
93 | m_pSettings->interlace_layer = 0; |
94 | m_pSettings->param_z = 0.0; |
95 | m_pSettings->brightness = 1.0; |
96 | m_pSettings->iteration_count = 100; |
97 | m_pSettings->iteration_step = 50; |
98 | m_pSettings->adjusted_iteration_step = 50; |
99 | m_pSettings->current_iteration = 0; |
100 | m_pSettings->discard_threshold = 4.; |
101 | } |
102 | ImGui::End(); |
103 | } |
104 | } |
105 |
|
106 | ImGui::PopFont(); |
107 |
|
108 | io.KeyMods = mods; |
109 | io.KeyCtrl = ctrl; |
110 | io.KeyAlt = alt; |
111 | io.KeyShift = shift; |
112 |
|
113 | ImGui::Render(); |
114 | ImGui::UpdatePlatformWindows(); |
115 |
|
116 | ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); |
117 | } |
118 |
|