Advertisement
Frumkin

Verbose ImGui

Mar 1st, 2024
659
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.60 KB | None | 0 0
  1. void UIManager::render(sf::RenderWindow& window, const sf::Vector2f complex, const sf::Sprite& sprite) {
  2.     inputs_changed = false;
  3.  
  4.     if (ImGui::Begin("Settings")) {
  5.         is_focused = ImGui::IsWindowFocused();
  6.  
  7.         bool fractal_configurations_inputs_changed = false;
  8.         if (ImGui::CollapsingHeader("Fractal Configurations", ImGuiTreeNodeFlags_DefaultOpen)) {
  9.             ImGui::Text("Iterations");
  10.             ImGui::SameLine();
  11.             int signed_iterations = static_cast<int>(settings.iterations);
  12.             const bool iterations_changed = ImGui::SliderInt("##iterations", &signed_iterations, FractalSettings::MINIMUM_ITERATIONS, FractalSettings::MAXIMUM_ITERATIONS);
  13.             if (iterations_changed) settings.iterations = static_cast<unsigned int>(signed_iterations);
  14.  
  15.             bool current_set_changed = false;
  16.             if (ImGui::BeginCombo("##set_type", stringify(settings.current_set).c_str())) {
  17.                 SetType previous = settings.current_set;
  18.                 for (std::size_t index = 0; index < static_cast<std::size_t>(SetType::COUNT); index += 1) {
  19.                     SetType type = static_cast<SetType>(index);
  20.                     const bool is_selected = type == settings.current_set;
  21.                     if (ImGui::Selectable(stringify(type).c_str(), is_selected)) {
  22.                         settings.current_set = type;
  23.                     }
  24.  
  25.                     if (is_selected) ImGui::SetItemDefaultFocus();
  26.                 }
  27.  
  28.                 ImGui::EndCombo();
  29.                 current_set_changed = previous != settings.current_set;
  30.             }
  31.  
  32.             bool input_changed_based_on_julia = false;
  33.             if (settings.current_set == SetType::JULIA) {
  34.                 ImGui::Text("Use Phoenix Complex");
  35.                 ImGui::SameLine();
  36.                 const bool use_phoenix_complex_changed = ImGui::Checkbox("##use_phoenix_complex", &settings.use_phoenix_complex);
  37.  
  38.                 ImGui::Text("Julia Complex");
  39.                 ImGui::SameLine();
  40.                 float julia_complex_floats[2] = { settings.julia_complex.x, settings.julia_complex.y };
  41.                 const bool julia_complex_changed = ImGui::SliderFloat2("##julia_complex", julia_complex_floats, FractalSettings::JULIA_COMPLEX_MINIMUM, FractalSettings::JULIA_COMPLEX_MAXIMUM);
  42.                 if (julia_complex_changed) settings.julia_complex = sf::Vector2f(julia_complex_floats[0], julia_complex_floats[1]);
  43.  
  44.                 bool phoenix_complex_changed = false;
  45.                 if (settings.use_phoenix_complex) {
  46.                     ImGui::Text("Phoenix Complex");
  47.                     ImGui::SameLine();
  48.                     float phoenix_complex_floats[2] = { settings.phoenix_complex.x, settings.phoenix_complex.y };
  49.                     phoenix_complex_changed = ImGui::SliderFloat2("##phoenix_complex", phoenix_complex_floats, FractalSettings::PHOENIX_COMPLEX_MINIMUM, FractalSettings::PHOENIX_COMPLEX_MAXIMUM);
  50.                     if (phoenix_complex_changed) settings.phoenix_complex = sf::Vector2f(phoenix_complex_floats[0], phoenix_complex_floats[1]);
  51.                 }
  52.  
  53.                 if (use_phoenix_complex_changed || julia_complex_changed || phoenix_complex_changed) input_changed_based_on_julia = true;
  54.             }
  55.  
  56.             if (iterations_changed || current_set_changed || input_changed_based_on_julia) fractal_configurations_inputs_changed = true;
  57.         }
  58.  
  59.         bool main_coloring_changed = false;
  60.         if (ImGui::CollapsingHeader("Coloring")) {
  61.             bool coloring_changed = false;
  62.             if (ImGui::BeginCombo("##coloring_type", stringify(settings.coloring).c_str())) {
  63.                 ColoringType previous = settings.coloring;
  64.                 for (std::size_t index = 0; index < static_cast<std::size_t>(ColoringType::COUNT); index += 1) {
  65.                     ColoringType type = static_cast<ColoringType>(index);
  66.                     const bool is_selected = type == settings.coloring;
  67.                     if (ImGui::Selectable(stringify(type).c_str(), is_selected)) {
  68.                         settings.coloring = type;
  69.                     }
  70.  
  71.                     if (is_selected) ImGui::SetItemDefaultFocus();
  72.                 }
  73.  
  74.                 ImGui::EndCombo();
  75.                 coloring_changed = previous != settings.coloring;
  76.             }
  77.  
  78.             ImGui::Text("Color Repeatings");
  79.             ImGui::SameLine();
  80.             int signed_color_repeatings = static_cast<int>(settings.color_repeatings);
  81.             const bool color_repeatings_changed = ImGui::SliderInt("##color_repeatings", &signed_color_repeatings, FractalSettings::MINIMUM_COLOR_REPEATINGS, FractalSettings::MAXIMUM_COLOR_REPEATINGS);
  82.             if (color_repeatings_changed) settings.color_repeatings = static_cast<unsigned int>(signed_color_repeatings);
  83.  
  84.             bool inputs_changed_based_on_coloring = false;
  85.             switch (settings.coloring) {
  86.                 case ColoringType::MIX: {
  87.                     ImGui::Text("First Color");
  88.                     ImGui::SameLine();
  89.                     float first_color_floats[3] = { settings.first_color.r / 255.0f, settings.first_color.g / 255.0f, settings.first_color.b / 255.0f };
  90.                     const bool first_color_changed = ImGui::ColorEdit3("##first_color", first_color_floats, ImGuiColorEditFlags_NoSidePreview | ImGuiColorEditFlags_PickerHueWheel);
  91.                     if (first_color_changed) settings.first_color = sf::Color(static_cast<sf::Uint8>(first_color_floats[0] * 255), static_cast<sf::Uint8>(first_color_floats[1] * 255), static_cast<sf::Uint8>(first_color_floats[2] * 255));
  92.  
  93.                     ImGui::Text("Second Color");
  94.                     ImGui::SameLine();
  95.                     float second_color_floats[3] = { settings.second_color.r / 255.0f, settings.second_color.g / 255.0f, settings.second_color.b / 255.0f };
  96.                     const bool second_color_changed = ImGui::ColorEdit3("##second_color", second_color_floats, ImGuiColorEditFlags_NoSidePreview | ImGuiColorEditFlags_PickerHueWheel);
  97.                     if (second_color_changed) settings.second_color = sf::Color(static_cast<sf::Uint8>(second_color_floats[0] * 255), static_cast<sf::Uint8>(second_color_floats[1] * 255), static_cast<sf::Uint8>(second_color_floats[2] * 255));
  98.  
  99.                     if (first_color_changed || second_color_changed) inputs_changed_based_on_coloring = true;
  100.                     break;
  101.                 }
  102.                 case ColoringType::RAINBOW: {
  103.                     ImGui::Text("Saturation");
  104.                     ImGui::SameLine();
  105.                     const bool saturation_changed = ImGui::SliderFloat("##saturation", &settings.rainbow_saturation, 0.0f, 1.0f);
  106.  
  107.                     ImGui::Text("Brightness");
  108.                     ImGui::SameLine();
  109.                     const bool brightness_changed = ImGui::SliderFloat("##brightness", &settings.rainbow_brightness, 0.0f, 1.0f);
  110.  
  111.                     if (saturation_changed || brightness_changed) inputs_changed_based_on_coloring = true;
  112.                     break;
  113.                 }
  114.             }
  115.  
  116.             if (coloring_changed || color_repeatings_changed || inputs_changed_based_on_coloring) main_coloring_changed = true;
  117.         }
  118.  
  119.         bool viewing_changed = false;
  120.         if (ImGui::CollapsingHeader("View")) {
  121.             ImGui::Text("Center: %g + %gi", complex.x, complex.y);
  122.  
  123.             ImGui::Text("Zoom Speed");
  124.             ImGui::SameLine();
  125.             const bool zoom_speed_changed = ImGui::SliderFloat("##zoom_speed", &settings.zoom_speed, FractalSettings::MINIMUM_ZOOM_SPEED, FractalSettings::MAXIMUM_ZOOM_SPEED);
  126.  
  127.             ImGui::Text("Pan Speed");
  128.             ImGui::SameLine();            
  129.             const bool pan_speed_changed = ImGui::SliderFloat("##pan_speed", &settings.pan_speed, FractalSettings::MINIMUM_PAN_SPEED, FractalSettings::MAXIMUM_PAN_SPEED);
  130.  
  131.             if (ImGui::Button("Save Image")) sprite.getTexture()->copyToImage().saveToFile(image_file_name);
  132.             ImGui::SameLine();
  133.  
  134.             std::array<char, 256> raw_image_file_name;
  135.             std::strcpy(raw_image_file_name.data(), image_file_name.c_str());
  136.             const bool image_file_name_changed = ImGui::InputText("##image_file_name", raw_image_file_name.data(), raw_image_file_name.size());
  137.             if (image_file_name_changed) image_file_name = raw_image_file_name.data();
  138.  
  139.             if (zoom_speed_changed || pan_speed_changed) viewing_changed = true;
  140.         }
  141.  
  142.         if (fractal_configurations_inputs_changed || viewing_changed || main_coloring_changed) inputs_changed = true;
  143.     }
  144.  
  145.     ImGui::End();
  146.     ImGui::SFML::Render(window);
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement