add a MainMenuBar and make Tile Picker and Demo Window hidden by default
use dockspace for positioning Tile Picker
This commit is contained in:
parent
dc7c424d7f
commit
002bbcd097
208
src/main.cpp
208
src/main.cpp
@ -1191,6 +1191,7 @@ int main(int argc, char **argv) {
|
||||
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
|
||||
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad;
|
||||
io.ConfigFlags |= ImGuiConfigFlags_IsSRGB;
|
||||
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
|
||||
|
||||
ImGui::StyleColorsDark();
|
||||
|
||||
@ -1208,8 +1209,10 @@ int main(int argc, char **argv) {
|
||||
};
|
||||
ImGui_ImplSDLGPU3_Init(&imgui_init_info);
|
||||
|
||||
bool show_demo_window = true;
|
||||
bool first_frame = true;
|
||||
bool show_demo_window = false;
|
||||
bool show_tile_picker = false;
|
||||
|
||||
|
||||
SDL_GetWindowSizeInPixels(window, &window_width, &window_height);
|
||||
|
||||
@ -1237,97 +1240,123 @@ int main(int argc, char **argv) {
|
||||
calendar_time.minute = real_mod(calendar_time.minute, 60);
|
||||
calendar_time.hour = real_mod(calendar_time.hour, 24);
|
||||
|
||||
ImGui::SetNextWindowPos(ImVec2(0, 0));
|
||||
ImGui::SetNextWindowSizeConstraints(ImVec2(0, window_height), ImVec2(window_width, window_height));
|
||||
ImGui::SetNextWindowSize(ImVec2(0.2 * window_width, window_height), ImGuiCond_FirstUseEver);
|
||||
if (ImGui::Begin("Tile Picker", NULL, ImGuiWindowFlags_NoFocusOnAppearing)) {
|
||||
if (SelectableTile("##tile", selected_tile == -1, NULL, 0, ImVec2(32, 32))) {
|
||||
selected_tile = -1;
|
||||
if (ImGui::BeginMainMenuBar()) {
|
||||
if (ImGui::BeginMenu("File")) {
|
||||
ImGui::MenuItem("Demo Window", NULL, &show_demo_window);
|
||||
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
|
||||
for (int i = 0; i < SDL_arraysize(tile_infos); i++) {
|
||||
ImGui::PushID(i);
|
||||
|
||||
ImVec2 uv0 = ImVec2(tile_infos[i].uv_min.x, tile_infos[i].uv_min.y);
|
||||
ImVec2 uv1 = ImVec2(tile_infos[i].uv_max.x, tile_infos[i].uv_max.y);
|
||||
|
||||
float available = ImGui::GetContentRegionAvail().x - ImGui::GetItemRectMax().x;
|
||||
if (available >= 32)
|
||||
ImGui::SameLine();
|
||||
|
||||
if (SelectableTile("##tile", selected_tile == i, &tile_atlas_texture_binding, i, ImVec2(32, 32), uv0, uv1, SDL_max(selected_rotation, 0)))
|
||||
selected_tile = i;
|
||||
|
||||
ImGui::PopID();
|
||||
if (ImGui::BeginMenu("Edit")) {
|
||||
ImGui::MenuItem("Tile Picker", NULL, &show_tile_picker);
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
|
||||
if (selected_tile != -1) {
|
||||
ImGui::Text("Rotation:");
|
||||
|
||||
ImVec2 uv0 = ImVec2(tile_infos[selected_tile].uv_min.x, tile_infos[selected_tile].uv_min.y);
|
||||
ImVec2 uv1 = ImVec2(tile_infos[selected_tile].uv_max.x, tile_infos[selected_tile].uv_max.y);
|
||||
|
||||
if (SelectableTile("##None", selected_rotation == 0, &tile_atlas_texture_binding, selected_tile, ImVec2(32, 32), uv0, uv1, 0))
|
||||
selected_rotation = 0;
|
||||
|
||||
if (ImGui::GetContentRegionAvail().x - ImGui::GetItemRectMax().x >= 32)
|
||||
ImGui::SameLine();
|
||||
|
||||
if (SelectableTile("##90", selected_rotation == 1, &tile_atlas_texture_binding, selected_tile, ImVec2(32, 32), uv0, uv1, 1))
|
||||
selected_rotation = 1;
|
||||
|
||||
if (ImGui::GetContentRegionAvail().x - ImGui::GetItemRectMax().x >= 32)
|
||||
ImGui::SameLine();
|
||||
|
||||
if (SelectableTile("##180", selected_rotation == 2, &tile_atlas_texture_binding, selected_tile, ImVec2(32, 32), uv0, uv1, 2))
|
||||
selected_rotation = 2;
|
||||
|
||||
if (ImGui::GetContentRegionAvail().x - ImGui::GetItemRectMax().x >= 32)
|
||||
ImGui::SameLine();
|
||||
|
||||
if (SelectableTile("##270", selected_rotation == 3, &tile_atlas_texture_binding, selected_tile, ImVec2(32, 32), uv0, uv1, 3))
|
||||
selected_rotation = 3;
|
||||
|
||||
if (ImGui::Selectable("Random", selected_rotation == -1))
|
||||
selected_rotation = -1;
|
||||
}
|
||||
|
||||
ImGui::DragFloat("fovy", &per_frame.fovy_degrees);
|
||||
ImGui::DragFloat("camera_distance", &per_frame.camera_distance, 0.25f, 1.0f, INFINITY);
|
||||
ImGui::DragFloat("camera_tilt", &per_frame.camera_tilt, 0.25f, 0.0f, 89.0f);
|
||||
|
||||
if (ImGui::Checkbox("MSAA", &enable_msaa)) {
|
||||
recreate_graphics_pipelines();
|
||||
if (msaa_texture) {
|
||||
SDL_ReleaseGPUTexture(device, msaa_texture);
|
||||
msaa_texture = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::DragScalarN("calendar_time", ImGuiDataType_S32, &calendar_time.hour, 3);
|
||||
imgui_time_picker("time_offset", &time_offset.hour);
|
||||
|
||||
ImGui::NewLine();
|
||||
imgui_time_picker("time0", time_tints_times[0]);
|
||||
imgui_time_picker("time1", time_tints_times[1]);
|
||||
imgui_time_picker("time2", time_tints_times[2]);
|
||||
imgui_time_picker("time3", time_tints_times[3]);
|
||||
|
||||
ImGui::NewLine();
|
||||
ImGui::ColorEdit3("time0_color", time_tints[0].E);
|
||||
ImGui::ColorEdit3("time1_color", time_tints[1].E);
|
||||
ImGui::ColorEdit3("time2_color", time_tints[2].E);
|
||||
ImGui::ColorEdit3("time3_color", time_tints[3].E);
|
||||
|
||||
if (selected_tile != -1 && ImGui::IsWindowFocused() && ImGui::IsKeyPressed(ImGuiKey_R, false)) {
|
||||
if (ImGui::IsKeyDown(ImGuiKey_LeftShift)) {
|
||||
selected_rotation = (selected_rotation - 1) & 3;
|
||||
} else {
|
||||
selected_rotation = (selected_rotation + 1) & 3;
|
||||
}
|
||||
}
|
||||
ImGui::EndMainMenuBar();
|
||||
}
|
||||
|
||||
ImGuiID main_viewport_dock = ImGui::GetID("main_viewport_dock");
|
||||
if (!ImGui::DockBuilderGetNode(main_viewport_dock)) {
|
||||
ImGui::DockBuilderAddNode (main_viewport_dock, (ImGuiDockNodeFlags)ImGuiDockNodeFlags_DockSpace | ImGuiDockNodeFlags_AutoHideTabBar | ImGuiDockNodeFlags_PassthruCentralNode | ImGuiDockNodeFlags_NoDockingOverCentralNode);
|
||||
ImGui::DockBuilderSetNodePos (main_viewport_dock, ImGui::GetMainViewport()->WorkPos);
|
||||
ImGui::DockBuilderSetNodeSize(main_viewport_dock, ImGui::GetMainViewport()->WorkSize);
|
||||
|
||||
ImGuiID left_dock = ImGui::DockBuilderSplitNode(main_viewport_dock, ImGuiDir_Left, 0.2f, NULL, NULL);
|
||||
ImGui::DockBuilderDockWindow("Tile Picker", left_dock);
|
||||
ImGui::DockBuilderFinish(main_viewport_dock);
|
||||
}
|
||||
ImGui::DockSpaceOverViewport(main_viewport_dock, ImGui::GetMainViewport(), ImGuiDockNodeFlags_AutoHideTabBar | ImGuiDockNodeFlags_PassthruCentralNode | ImGuiDockNodeFlags_NoDockingOverCentralNode);
|
||||
|
||||
if (show_tile_picker) {
|
||||
if (ImGui::Begin("Tile Picker", &show_tile_picker, ImGuiWindowFlags_NoFocusOnAppearing)) {
|
||||
if (SelectableTile("##tile", selected_tile == -1, NULL, 0, ImVec2(32, 32))) {
|
||||
selected_tile = -1;
|
||||
}
|
||||
|
||||
for (int i = 0; i < SDL_arraysize(tile_infos); i++) {
|
||||
ImGui::PushID(i);
|
||||
|
||||
ImVec2 uv0 = ImVec2(tile_infos[i].uv_min.x, tile_infos[i].uv_min.y);
|
||||
ImVec2 uv1 = ImVec2(tile_infos[i].uv_max.x, tile_infos[i].uv_max.y);
|
||||
|
||||
float available = ImGui::GetContentRegionAvail().x - ImGui::GetItemRectMax().x;
|
||||
if (available >= 32)
|
||||
ImGui::SameLine();
|
||||
|
||||
if (SelectableTile("##tile", selected_tile == i, &tile_atlas_texture_binding, i, ImVec2(32, 32), uv0, uv1, SDL_max(selected_rotation, 0)))
|
||||
selected_tile = i;
|
||||
|
||||
ImGui::PopID();
|
||||
}
|
||||
|
||||
if (selected_tile != -1) {
|
||||
ImGui::Text("Rotation:");
|
||||
|
||||
ImVec2 uv0 = ImVec2(tile_infos[selected_tile].uv_min.x, tile_infos[selected_tile].uv_min.y);
|
||||
ImVec2 uv1 = ImVec2(tile_infos[selected_tile].uv_max.x, tile_infos[selected_tile].uv_max.y);
|
||||
|
||||
if (SelectableTile("##None", selected_rotation == 0, &tile_atlas_texture_binding, selected_tile, ImVec2(32, 32), uv0, uv1, 0))
|
||||
selected_rotation = 0;
|
||||
|
||||
if (ImGui::GetContentRegionAvail().x - ImGui::GetItemRectMax().x >= 32)
|
||||
ImGui::SameLine();
|
||||
|
||||
if (SelectableTile("##90", selected_rotation == 1, &tile_atlas_texture_binding, selected_tile, ImVec2(32, 32), uv0, uv1, 1))
|
||||
selected_rotation = 1;
|
||||
|
||||
if (ImGui::GetContentRegionAvail().x - ImGui::GetItemRectMax().x >= 32)
|
||||
ImGui::SameLine();
|
||||
|
||||
if (SelectableTile("##180", selected_rotation == 2, &tile_atlas_texture_binding, selected_tile, ImVec2(32, 32), uv0, uv1, 2))
|
||||
selected_rotation = 2;
|
||||
|
||||
if (ImGui::GetContentRegionAvail().x - ImGui::GetItemRectMax().x >= 32)
|
||||
ImGui::SameLine();
|
||||
|
||||
if (SelectableTile("##270", selected_rotation == 3, &tile_atlas_texture_binding, selected_tile, ImVec2(32, 32), uv0, uv1, 3))
|
||||
selected_rotation = 3;
|
||||
|
||||
if (ImGui::Selectable("Random", selected_rotation == -1))
|
||||
selected_rotation = -1;
|
||||
}
|
||||
|
||||
ImGui::DragFloat("fovy", &per_frame.fovy_degrees);
|
||||
ImGui::DragFloat("camera_distance", &per_frame.camera_distance, 0.25f, 1.0f, INFINITY);
|
||||
ImGui::DragFloat("camera_tilt", &per_frame.camera_tilt, 0.25f, 0.0f, 89.0f);
|
||||
|
||||
if (ImGui::Checkbox("MSAA", &enable_msaa)) {
|
||||
recreate_graphics_pipelines();
|
||||
if (msaa_texture) {
|
||||
SDL_ReleaseGPUTexture(device, msaa_texture);
|
||||
msaa_texture = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::DragScalarN("calendar_time", ImGuiDataType_S32, &calendar_time.hour, 3);
|
||||
imgui_time_picker("time_offset", &time_offset.hour);
|
||||
|
||||
ImGui::NewLine();
|
||||
imgui_time_picker("time0", time_tints_times[0]);
|
||||
imgui_time_picker("time1", time_tints_times[1]);
|
||||
imgui_time_picker("time2", time_tints_times[2]);
|
||||
imgui_time_picker("time3", time_tints_times[3]);
|
||||
|
||||
ImGui::NewLine();
|
||||
ImGui::ColorEdit3("time0_color", time_tints[0].E);
|
||||
ImGui::ColorEdit3("time1_color", time_tints[1].E);
|
||||
ImGui::ColorEdit3("time2_color", time_tints[2].E);
|
||||
ImGui::ColorEdit3("time3_color", time_tints[3].E);
|
||||
|
||||
if (selected_tile != -1 && ImGui::IsWindowFocused() && ImGui::IsKeyPressed(ImGuiKey_R, false)) {
|
||||
if (ImGui::IsKeyDown(ImGuiKey_LeftShift)) {
|
||||
selected_rotation = (selected_rotation - 1) & 3;
|
||||
} else {
|
||||
selected_rotation = (selected_rotation + 1) & 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
ImGui::End();
|
||||
|
||||
if (show_demo_window)
|
||||
ImGui::ShowDemoWindow(&show_demo_window);
|
||||
@ -1680,5 +1709,10 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
FrameMark;
|
||||
}
|
||||
|
||||
ImGui_ImplSDLGPU3_Shutdown();
|
||||
ImGui_ImplSDL3_Shutdown();
|
||||
ImGui::DestroyContext();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user