4#include <imgui/imgui.h>
5#include <imgui/imgui_internal.h>
13struct preset_card_info
22const preset_card_info presets[] = {
26 "Basic lighting and minimal post-processing.\n"
27 "Best for low-end hardware or mobile targets.",
32 "Balanced lighting, soft shadows and post-processing.\n"
33 "Recommended for most projects.",
38 "Full Lighting, SSR, Bloom, Volumetric Clouds, Soft Shadows and Post-Processing.\n"
39 "Best for high-end desktop builds.",
44 "Full Lighting, SSIL, SSR, Bloom, TAA, Volumetric Clouds, Soft Shadows and Post-Processing.\n"
45 "Best for showcase builds. Requires a powerful GPU.",
56auto draw_preset_card(
const preset_card_info& info,
float card_width,
bool is_selected) -> card_action
58 auto result = card_action::none;
59 bool is_hovered =
false;
61 ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, 8.0f);
62 ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(20, 16));
63 ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 8.0f);
67 ImGui::PushStyleColor(ImGuiCol_ChildBg, ImGui::GetColorU32(ImGuiCol_ButtonActive, 0.25f));
71 ImGui::PushStyleColor(ImGuiCol_ChildBg, ImGui::GetColorU32(ImGuiCol_FrameBg, 0.6f));
74 ImVec2 card_size(card_width, 0);
75 if(ImGui::BeginChild(info.id, card_size,
76 ImGuiChildFlags_FrameStyle | ImGuiChildFlags_Borders | ImGuiChildFlags_AutoResizeY))
78 is_hovered = ImGui::IsWindowHovered();
80 ImDrawList* draw_list = ImGui::GetWindowDrawList();
81 ImVec2 p_min = ImGui::GetWindowPos();
82 ImVec2 p_max = ImVec2(p_min.x + ImGui::GetWindowSize().x, p_min.y + ImGui::GetWindowSize().y);
86 draw_list->AddRectFilled(p_min, p_max, ImGui::GetColorU32(ImGuiCol_ButtonHovered, 0.4f), 8.0f);
87 draw_list->AddRect(p_min, p_max, ImGui::GetColorU32(ImGuiCol_ButtonActive, 0.6f), 8.0f, 0, 2.0f);
91 draw_list->AddRect(p_min, p_max, ImGui::GetColorU32(ImGuiCol_ButtonActive, 0.6f), 8.0f, 0, 1.5f);
94 ImGui::SetCursorPos(ImVec2(ImGui::GetCursorPosX() + 4, ImGui::GetCursorPosY() + 2));
98 if(is_hovered || is_selected)
100 ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetColorU32(ImGuiCol_ButtonActive));
103 ImGui::Text(
"%s", info.icon);
104 ImGui::SameLine(0.0f, ImGui::GetStyle().ItemInnerSpacing.x);
107 ImGui::Text(
"%s", info.title);
109 if(is_hovered || is_selected)
111 ImGui::PopStyleColor();
117 ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetColorU32(ImGuiCol_TextDisabled, 0.9f));
118 ImGui::TextWrapped(
"%s", info.description);
119 ImGui::PopStyleColor();
125 ImGui::PopStyleColor();
126 ImGui::PopStyleVar(3);
128 if(is_hovered && ImGui::IsMouseDoubleClicked(0))
130 result = card_action::confirmed;
132 else if(is_hovered && ImGui::IsMouseClicked(0))
134 result = card_action::selected;
144 auto& inst = get_instance();
145 inst.callback_ = std::move(on_preset_selected);
146 inst.show_requested_ =
true;
147 inst.open_requested_ =
true;
153 return get_instance().show_requested_;
158 auto& inst = get_instance();
159 if(!inst.show_requested_)
164 auto callback = std::move(inst.callback_);
166 inst.show_requested_ =
false;
167 inst.open_requested_ =
false;
168 inst.selected_preset_ =
preset;
179 auto& inst = get_instance();
181 inst.show_requested_ =
false;
182 inst.open_requested_ =
false;
187 auto& inst = get_instance();
188 if(!inst.show_requested_)
195 ImGui::OpenPopup(
"Create Scene");
199 auto* viewport = ImGui::GetMainViewport();
200 ImGui::SetNextWindowPos(viewport->GetCenter(),
204 const float modal_width = viewport->Size.x * 0.3f;
205 ImGui::SetNextWindowSize(ImVec2(modal_width, 0), ImGuiCond_Always);
207 ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(24, 20));
208 ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 10.0f);
209 ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(12, 10));
211 if(!ImGui::BeginPopupModal(
"Create Scene",
nullptr,
212 ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoSavedSettings))
214 ImGui::PopStyleVar(3);
218 ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetColorU32(ImGuiCol_TextDisabled, 0.8f));
219 ImGui::TextWrapped(
"Choose a preset for your new scene.");
220 ImGui::PopStyleColor();
223 ImGui::PushStyleColor(ImGuiCol_Separator, ImVec4(0.25f, 0.25f, 0.25f, 1.0f));
225 ImGui::PopStyleColor();
229 ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 10.0f));
230 float card_width = ImGui::GetContentRegionAvail().x;
231 bool should_confirm =
false;
233 for(
const auto& p : presets)
235 bool is_selected = (p.preset == inst.selected_preset_);
236 auto action = draw_preset_card(p, card_width, is_selected);
237 if(action == card_action::confirmed)
239 inst.selected_preset_ = p.preset;
240 should_confirm =
true;
242 else if(action == card_action::selected)
244 inst.selected_preset_ = p.preset;
247 ImGui::PopStyleVar();
250 ImGui::PushStyleColor(ImGuiCol_Separator, ImVec4(0.25f, 0.25f, 0.25f, 1.0f));
252 ImGui::PopStyleColor();
256 float button_width = 100.0f;
257 float total_buttons_w = button_width * 2 + ImGui::GetStyle().ItemSpacing.x;
259 ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 6.0f);
261 ImGui::AlignedItem(1.0f, ImGui::GetContentRegionAvail().
x, total_buttons_w, [&]() ->
void
263 if(ImGui::Button(
"Create", ImVec2(button_width, 30)) || should_confirm)
267 inst.callback_(inst.selected_preset_);
269 ImGui::CloseCurrentPopup();
270 inst.show_requested_ =
false;
275 if(ImGui::Button(
"Cancel", ImVec2(button_width, 30)))
277 ImGui::CloseCurrentPopup();
278 inst.show_requested_ =
false;
282 ImGui::PopStyleVar();
285 ImGui::PopStyleVar(3);
Modal for selecting a scene preset when creating a new scene. Call ShowCreateSceneModal() to open; Re...
static void show(std::function< void(defaults::scene_preset)> on_preset_selected)
Request the create scene modal to open.
static void render()
Draw the modal. Call every frame from the main UI render loop.
static auto complete_if_pending(defaults::scene_preset preset) -> bool
static auto is_pending() -> bool
True when Show was requested and the user has not yet confirmed/cancelled.
static void cancel_if_pending()
Dismiss a pending create-scene modal without invoking the callback.
defaults::scene_preset preset
#define ICON_MDI_DIAMOND_STONE
#define ICON_MDI_LIGHTNING_BOLT_OUTLINE
void PushFont(Font::Enum _font)
void PopWindowFontScale()
void PushWindowFontScale(float scale)
scene_preset
Quality presets for new scene creation (low = less expensive, high = more expensive).