8#include "absl/status/status.h"
9#include "absl/strings/str_format.h"
14#include "imgui/backends/imgui_impl_sdl2.h"
15#include "imgui/backends/imgui_impl_sdlrenderer2.h"
16#include "imgui/imgui.h"
25 ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoCollapse |
26 ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_MenuBar |
27 ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoTitleBar;
33using ImGui::SetNextWindowPos;
34using ImGui::SetNextWindowSize;
37 const ImGuiIO &io = GetIO();
38 ImGui_ImplSDLRenderer2_NewFrame();
39 ImGui_ImplSDL2_NewFrame();
42 ImVec2 dimensions(io.DisplaySize.x, io.DisplaySize.y);
43 SetNextWindowSize(dimensions, ImGuiCond_Always);
54#if defined(__APPLE__) && defined(__MACH__)
55#if TARGET_IPHONE_SIMULATOR == 1 || TARGET_OS_IPHONE == 1
57#elif TARGET_OS_MAC == 1
62#elif defined(__linux__)
73 return absl::OkStatus();
79 ImGuiIO &io = ImGui::GetIO();
81 while (SDL_PollEvent(&event)) {
82 ImGui_ImplSDL2_ProcessEvent(&event);
86 ImGuiIO &io = ImGui::GetIO();
87 io.KeyShift = ((SDL_GetModState() & KMOD_SHIFT) != 0);
88 io.KeyCtrl = ((SDL_GetModState() & KMOD_CTRL) != 0);
89 io.KeyAlt = ((SDL_GetModState() & KMOD_ALT) != 0);
90 io.KeySuper = ((SDL_GetModState() & KMOD_GUI) != 0);
94 switch (event.window.event) {
95 case SDL_WINDOWEVENT_CLOSE:
98 case SDL_WINDOWEVENT_SIZE_CHANGED:
99 io.DisplaySize.x =
static_cast<float>(
event.window.data1);
100 io.DisplaySize.y =
static_cast<float>(
event.window.data2);
113 const int buttons = SDL_GetMouseState(&mouseX, &mouseY);
115 io.DeltaTime = 1.0f / 60.0f;
116 io.MousePos = ImVec2(
static_cast<float>(mouseX),
static_cast<float>(mouseY));
117 io.MouseDown[0] = buttons & SDL_BUTTON(SDL_BUTTON_LEFT);
118 io.MouseDown[1] = buttons & SDL_BUTTON(SDL_BUTTON_RIGHT);
119 io.MouseDown[2] = buttons & SDL_BUTTON(SDL_BUTTON_MIDDLE);
120 io.MouseWheel =
static_cast<float>(wheel);
127#if TARGET_OS_IPHONE != 1
133#if TARGET_OS_IPHONE != 1
138 return absl::OkStatus();
143 return absl::OkStatus();
149 ImGui_ImplSDLRenderer2_RenderDrawData(ImGui::GetDrawData(),
157 ImGui_ImplSDLRenderer2_Shutdown();
158 ImGui_ImplSDL2_Shutdown();
159 ImGui::DestroyContext();
164 auto sdl_flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER;
165 if (
flags()->kUseNewImGuiInput) {
166 sdl_flags |= SDL_INIT_GAMECONTROLLER;
169 if (SDL_Init(sdl_flags) != 0) {
170 return absl::InternalError(
171 absl::StrFormat(
"SDL_Init: %s\n", SDL_GetError()));
174 SDL_DisplayMode display_mode;
175 SDL_GetCurrentDisplayMode(0, &display_mode);
176 int screen_width = display_mode.w * 0.8;
177 int screen_height = display_mode.h * 0.8;
179 window_ = std::unique_ptr<SDL_Window, core::SDL_Deleter>(
180 SDL_CreateWindow(
"Yet Another Zelda3 Editor",
181 SDL_WINDOWPOS_UNDEFINED,
182 SDL_WINDOWPOS_UNDEFINED,
185 SDL_WINDOW_RESIZABLE),
188 return absl::InternalError(
189 absl::StrFormat(
"SDL_CreateWindow: %s\n", SDL_GetError()));
192 return absl::OkStatus();
200 IMGUI_CHECKVERSION();
201 ImGui::CreateContext();
203 ImGuiIO &io = ImGui::GetIO();
204 io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
205 if (
flags()->kUseNewImGuiInput) {
206 io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad;
210 ImGui_ImplSDL2_InitForSDLRenderer(
window_.get(),
220 ImGui_ImplSDLRenderer2_NewFrame();
221 ImGui_ImplSDL2_NewFrame();
223 return absl::OkStatus();
232 SDL_AudioSpec want, have;
233 SDL_memset(&want, 0,
sizeof(want));
235 want.format = AUDIO_S16;
238 want.callback = NULL;
239 audio_device_ = SDL_OpenAudioDevice(NULL, 0, &want, &have, 0);
241 return absl::InternalError(
242 absl::StrFormat(
"Failed to open audio: %s\n", SDL_GetError()));
249 return absl::OkStatus();
258 if (!std::filesystem::exists(config_directory)) {
259 if (!std::filesystem::create_directory(config_directory)) {
260 return absl::InternalError(absl::StrFormat(
261 "Failed to create config directory %s", config_directory));
266 std::string config_file = config_directory +
"yaze.cfg";
267 if (!std::filesystem::exists(config_file)) {
269 std::ofstream file(config_file);
270 if (!file.is_open()) {
271 return absl::InternalError(
272 absl::StrFormat(
"Failed to create config file %s", config_file));
277 return absl::OkStatus();
SDL_AudioDeviceID audio_device_
absl::Status CreateGuiContext()
editor::EditorManager editor_manager_
absl::Status LoadFontFamilies() const
absl::Status LoadAudioDevice()
std::shared_ptr< SDL_Window > window_
absl::Status OnTestLoad()
absl::Status OnEntry(std::string filename="")
absl::Status LoadConfigFiles()
editor::Editor * test_editor_
auto renderer() -> SDL_Renderer *
absl::Status CreateRenderer()
std::shared_ptr< int16_t > audio_buffer_
absl::Status CreateWindow()
absl::Status CreateRenderer(SDL_Window *window)
auto renderer() -> SDL_Renderer *
static Renderer & GetInstance()
void SetupScreen(std::string filename="")
auto emulator() -> emu::Emulator &
virtual absl::Status Update()=0
#define RETURN_IF_ERROR(expression)
constexpr ImGuiWindowFlags kMainEditorFlags
std::string GetConfigDirectory(Platform platform)
absl::Status LoadPackageFonts()
constexpr ImVec2 kZeroPos
Deleter for SDL_Window and SDL_Renderer.