yaze 0.2.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
controller.cc
Go to the documentation of this file.
1#include "controller.h"
2
3#include <SDL.h>
4
5#include "absl/status/status.h"
6#include "app/core/window.h"
8#include "imgui/backends/imgui_impl_sdl2.h"
9#include "imgui/backends/imgui_impl_sdlrenderer2.h"
10#include "imgui/imgui.h"
11
12namespace yaze {
13namespace core {
14
15absl::Status Controller::OnEntry(std::string filename) {
16 RETURN_IF_ERROR(CreateWindow(window_, SDL_WINDOW_RESIZABLE));
17 editor_manager_.emulator().set_audio_buffer(window_.audio_buffer_.get());
18 editor_manager_.emulator().set_audio_device_id(window_.audio_device_);
19 editor_manager_.Initialize(filename);
20 active_ = true;
21 return absl::OkStatus();
22}
23
27
28absl::Status Controller::OnLoad() {
29 if (editor_manager_.quit() || !window_.active_) {
30 active_ = false;
31 return absl::OkStatus();
32 }
33
34#if TARGET_OS_IPHONE != 1
35 ImGui_ImplSDLRenderer2_NewFrame();
36 ImGui_ImplSDL2_NewFrame();
37 ImGui::NewFrame();
38
39 const ImGuiViewport *viewport = ImGui::GetMainViewport();
40 ImGui::SetNextWindowPos(viewport->WorkPos);
41 ImGui::SetNextWindowSize(viewport->WorkSize);
42 ImGui::SetNextWindowViewport(viewport->ID);
43
44 ImGuiWindowFlags window_flags =
45 ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDocking;
46 window_flags |= ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse |
47 ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove;
48 window_flags |=
49 ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus;
50
51 ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
52 ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
53 ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
54 ImGui::Begin("DockSpaceWindow", nullptr, window_flags);
55 ImGui::PopStyleVar(3);
56
57 // Create DockSpace
58 ImGuiID dockspace_id = ImGui::GetID("MyDockSpace");
59 ImGui::DockSpace(dockspace_id, ImVec2(0.0f, 0.0f),
60 ImGuiDockNodeFlags_PassthruCentralNode);
61
62 editor_manager_.DrawMenuBar(); // Draw the fixed menu bar at the top
63
64 ImGui::End();
65#endif
67 return absl::OkStatus();
68}
69
71 ImGui::Render();
72 SDL_RenderClear(Renderer::Get().renderer());
73 ImGui_ImplSDLRenderer2_RenderDrawData(ImGui::GetDrawData(),
74 Renderer::Get().renderer());
75 SDL_RenderPresent(Renderer::Get().renderer());
76}
77
79
80} // namespace core
81} // namespace yaze
absl::Status OnLoad()
Definition controller.cc:28
core::Window window_
Definition controller.h:40
void DoRender() const
Definition controller.cc:70
absl::Status OnEntry(std::string filename="")
Definition controller.cc:15
editor::EditorManager editor_manager_
Definition controller.h:41
static Renderer & Get()
Definition window.h:37
#define PRINT_IF_ERROR(expression)
Definition macro.h:25
#define RETURN_IF_ERROR(expression)
Definition macro.h:51
absl::Status ShutdownWindow(Window &window)
Definition window.cc:74
absl::Status CreateWindow(Window &window, int flags)
Definition window.cc:15
absl::Status HandleEvents(Window &window)
Definition window.cc:86
Main namespace for the application.
Definition controller.cc:12