Refactor Controller: Replace SetupScreen with Initialize and clean up unused code

This commit is contained in:
scawful
2024-12-31 11:46:39 -05:00
parent 33dc1983bc
commit bac4660bac
2 changed files with 46 additions and 67 deletions

View File

@@ -18,37 +18,6 @@
namespace yaze { namespace yaze {
namespace core { namespace core {
namespace {
constexpr ImGuiWindowFlags kMainEditorFlags =
ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoCollapse |
ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_MenuBar |
ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoTitleBar;
using ImGui::Begin;
using ImGui::End;
using ImGui::GetIO;
using ImGui::NewFrame;
using ImGui::SetNextWindowPos;
using ImGui::SetNextWindowSize;
void NewMasterFrame() {
const ImGuiIO &io = GetIO();
ImGui_ImplSDLRenderer2_NewFrame();
ImGui_ImplSDL2_NewFrame();
NewFrame();
SetNextWindowPos(gui::kZeroPos);
ImVec2 dimensions(io.DisplaySize.x, io.DisplaySize.y);
SetNextWindowSize(dimensions, ImGuiCond_Always);
if (!Begin("##YazeMain", nullptr, kMainEditorFlags)) {
End();
return;
}
}
} // namespace
absl::Status Controller::OnEntry(std::string filename) { absl::Status Controller::OnEntry(std::string filename) {
#if defined(__APPLE__) && defined(__MACH__) #if defined(__APPLE__) && defined(__MACH__)
#if TARGET_IPHONE_SIMULATOR == 1 || TARGET_OS_IPHONE == 1 #if TARGET_IPHONE_SIMULATOR == 1 || TARGET_OS_IPHONE == 1
@@ -67,7 +36,7 @@ absl::Status Controller::OnEntry(std::string filename) {
RETURN_IF_ERROR(CreateRenderer()) RETURN_IF_ERROR(CreateRenderer())
RETURN_IF_ERROR(CreateGuiContext()) RETURN_IF_ERROR(CreateGuiContext())
RETURN_IF_ERROR(LoadAudioDevice()) RETURN_IF_ERROR(LoadAudioDevice())
editor_manager_.SetupScreen(filename); editor_manager_.Initialize(filename);
active_ = true; active_ = true;
return absl::OkStatus(); return absl::OkStatus();
} }
@@ -124,15 +93,26 @@ absl::Status Controller::OnLoad() {
active_ = false; active_ = false;
} }
#if TARGET_OS_IPHONE != 1 #if TARGET_OS_IPHONE != 1
if (platform_ != Platform::kiOS) { constexpr ImGuiWindowFlags kMainEditorFlags =
NewMasterFrame(); ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoCollapse |
ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_MenuBar |
ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoTitleBar;
const ImGuiIO &io = ImGui::GetIO();
ImGui_ImplSDLRenderer2_NewFrame();
ImGui_ImplSDL2_NewFrame();
ImGui::NewFrame();
ImGui::SetNextWindowPos(gui::kZeroPos);
ImVec2 dimensions(io.DisplaySize.x, io.DisplaySize.y);
ImGui::SetNextWindowSize(dimensions, ImGuiCond_Always);
if (!ImGui::Begin("##YazeMain", nullptr, kMainEditorFlags)) {
ImGui::End();
} }
#endif #endif
RETURN_IF_ERROR(editor_manager_.Update()); RETURN_IF_ERROR(editor_manager_.Update());
#if TARGET_OS_IPHONE != 1 #if TARGET_OS_IPHONE != 1
if (platform_ != Platform::kiOS) { ImGui::End();
End();
}
#endif #endif
return absl::OkStatus(); return absl::OkStatus();
} }
@@ -277,5 +257,4 @@ absl::Status Controller::LoadConfigFiles() {
} }
} // namespace core } // namespace core
} // namespace yaze } // namespace yaze

View File

@@ -44,7 +44,7 @@ class Controller : public ExperimentFlags {
absl::Status LoadConfigFiles(); absl::Status LoadConfigFiles();
void SetupScreen(std::string filename = "") { void SetupScreen(std::string filename = "") {
editor_manager_.SetupScreen(filename); editor_manager_.Initialize(filename);
} }
auto editor_manager() -> editor::EditorManager & { return editor_manager_; } auto editor_manager() -> editor::EditorManager & { return editor_manager_; }
auto renderer() -> SDL_Renderer * { auto renderer() -> SDL_Renderer * {