more lowercase stuff
This commit is contained in:
1206
src/Application/Core/constants.h
Normal file
1206
src/Application/Core/constants.h
Normal file
File diff suppressed because it is too large
Load Diff
114
src/Application/Core/controller.cc
Normal file
114
src/Application/Core/controller.cc
Normal file
@@ -0,0 +1,114 @@
|
||||
#include "controller.h"
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <imgui/imgui.h>
|
||||
#include <imgui/imgui_internal.h>
|
||||
|
||||
#include "core/renderer.h"
|
||||
#include "core/window.h"
|
||||
#include "editor/editor.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace Application {
|
||||
namespace Core {
|
||||
|
||||
bool Controller::isActive() const { return active_; }
|
||||
|
||||
void Controller::onEntry() {
|
||||
window_.Create();
|
||||
renderer_.Create(window_.Get());
|
||||
ImGuiIO &io = ImGui::GetIO();
|
||||
io.KeyMap[ImGuiKey_Backspace] = SDL_GetScancodeFromKey(SDLK_BACKSPACE);
|
||||
io.KeyMap[ImGuiKey_Enter] = SDL_GetScancodeFromKey(SDLK_RETURN);
|
||||
io.KeyMap[ImGuiKey_UpArrow] = SDL_GetScancodeFromKey(SDLK_UP);
|
||||
io.KeyMap[ImGuiKey_DownArrow] = SDL_GetScancodeFromKey(SDLK_DOWN);
|
||||
io.KeyMap[ImGuiKey_Tab] = SDL_GetScancodeFromKey(SDLK_TAB);
|
||||
io.KeyMap[ImGuiKey_LeftCtrl] = SDL_GetScancodeFromKey(SDLK_LCTRL);
|
||||
active_ = true;
|
||||
}
|
||||
|
||||
void Controller::onInput() {
|
||||
int wheel = 0;
|
||||
SDL_Event event;
|
||||
ImGuiIO &io = ImGui::GetIO();
|
||||
|
||||
while (SDL_PollEvent(&event)) {
|
||||
switch (event.type) {
|
||||
case SDL_KEYDOWN:
|
||||
switch (event.key.keysym.sym) {
|
||||
case SDLK_UP:
|
||||
case SDLK_DOWN:
|
||||
case SDLK_RETURN:
|
||||
case SDLK_BACKSPACE:
|
||||
case SDLK_TAB:
|
||||
io.KeysDown[event.key.keysym.scancode] =
|
||||
(event.type == SDL_KEYDOWN);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_KEYUP: {
|
||||
int key = event.key.keysym.scancode;
|
||||
IM_ASSERT(key >= 0 && key < IM_ARRAYSIZE(io.KeysDown));
|
||||
io.KeysDown[key] = (event.type == SDL_KEYDOWN);
|
||||
io.KeyShift = ((SDL_GetModState() & KMOD_SHIFT) != 0);
|
||||
io.KeyCtrl = ((SDL_GetModState() & KMOD_CTRL) != 0);
|
||||
io.KeyAlt = ((SDL_GetModState() & KMOD_ALT) != 0);
|
||||
io.KeySuper = ((SDL_GetModState() & KMOD_GUI) != 0);
|
||||
break;
|
||||
}
|
||||
case SDL_WINDOWEVENT:
|
||||
switch (event.window.event) {
|
||||
case SDL_WINDOWEVENT_CLOSE:
|
||||
active_ = false;
|
||||
break;
|
||||
case SDL_WINDOWEVENT_SIZE_CHANGED:
|
||||
io.DisplaySize.x = static_cast<float>(event.window.data1);
|
||||
io.DisplaySize.y = static_cast<float>(event.window.data2);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case SDL_TEXTINPUT:
|
||||
io.AddInputCharactersUTF8(event.text.text);
|
||||
break;
|
||||
case SDL_MOUSEWHEEL:
|
||||
wheel = event.wheel.y;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int mouseX;
|
||||
int mouseY;
|
||||
const int buttons = SDL_GetMouseState(&mouseX, &mouseY);
|
||||
io.DeltaTime = 1.0f / 60.0f;
|
||||
io.MousePos = ImVec2(static_cast<float>(mouseX), static_cast<float>(mouseY));
|
||||
io.MouseDown[0] = buttons & SDL_BUTTON(SDL_BUTTON_LEFT);
|
||||
io.MouseDown[1] = buttons & SDL_BUTTON(SDL_BUTTON_RIGHT);
|
||||
io.MouseWheel = static_cast<float>(wheel);
|
||||
}
|
||||
|
||||
void Controller::onLoad() { editor_.UpdateScreen(); }
|
||||
|
||||
void Controller::doRender() {
|
||||
SDL_Delay(10);
|
||||
renderer_.Render();
|
||||
}
|
||||
|
||||
void Controller::onExit() {
|
||||
ImGui_ImplSDLRenderer_Shutdown();
|
||||
ImGui_ImplSDL2_Shutdown();
|
||||
ImGui::DestroyContext();
|
||||
window_.Destroy();
|
||||
renderer_.Destroy();
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
} // namespace Core
|
||||
} // namespace Application
|
||||
} // namespace yaze
|
||||
44
src/Application/Core/controller.h
Normal file
44
src/Application/Core/controller.h
Normal file
@@ -0,0 +1,44 @@
|
||||
#ifndef YAZE_APPLICATION_CORE_CONTROLLER_H
|
||||
#define YAZE_APPLICATION_CORE_CONTROLLER_H
|
||||
#define SDL_MAIN_HANDLED
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <imgui/imgui.h>
|
||||
#include <imgui/imgui_internal.h>
|
||||
|
||||
#include "core/renderer.h"
|
||||
#include "core/window.h"
|
||||
#include "editor/editor.h"
|
||||
|
||||
int main(int argc, char** argv);
|
||||
|
||||
namespace yaze {
|
||||
namespace Application {
|
||||
namespace Core {
|
||||
|
||||
class Controller {
|
||||
public:
|
||||
Controller() = default;
|
||||
|
||||
bool isActive() const;
|
||||
void onEntry();
|
||||
void onInput();
|
||||
void onLoad();
|
||||
void doRender();
|
||||
void onExit();
|
||||
|
||||
private:
|
||||
inline void quit() { active_ = false; }
|
||||
friend int ::main(int argc, char** argv);
|
||||
|
||||
bool active_;
|
||||
Window window_;
|
||||
Renderer renderer_;
|
||||
Editor::Editor editor_;
|
||||
};
|
||||
|
||||
} // namespace Core
|
||||
} // namespace Application
|
||||
} // namespace yaze
|
||||
|
||||
#endif // YAZE_APPLICATION_CORE_CONTROLLER_H
|
||||
77
src/Application/Core/renderer.cc
Normal file
77
src/Application/Core/renderer.cc
Normal file
@@ -0,0 +1,77 @@
|
||||
#include "Renderer.h"
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <imgui/backends/imgui_impl_sdl.h>
|
||||
#include <imgui/backends/imgui_impl_sdlrenderer.h>
|
||||
#include <imgui/imgui.h>
|
||||
|
||||
#include "graphics/icons.h"
|
||||
#include "graphics/style.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace Application {
|
||||
namespace Core {
|
||||
|
||||
void Renderer::Create(SDL_Window* window) {
|
||||
if (window == nullptr) {
|
||||
SDL_Log("SDL_CreateWindow: %s\n", SDL_GetError());
|
||||
SDL_Quit();
|
||||
} else {
|
||||
renderer = SDL_CreateRenderer(
|
||||
window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
|
||||
if (renderer == nullptr) {
|
||||
SDL_Log("SDL_CreateRenderer: %s\n", SDL_GetError());
|
||||
SDL_Quit();
|
||||
} else {
|
||||
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
|
||||
SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0x00);
|
||||
}
|
||||
}
|
||||
|
||||
// Create the ImGui and ImPlot contexts
|
||||
ImGui::CreateContext();
|
||||
|
||||
// Initialize ImGui for SDL
|
||||
ImGui_ImplSDL2_InitForSDLRenderer(window, renderer);
|
||||
ImGui_ImplSDLRenderer_Init(renderer);
|
||||
|
||||
// Load available fonts
|
||||
const ImGuiIO& io = ImGui::GetIO();
|
||||
io.Fonts->AddFontFromFileTTF("assets/Fonts/Karla-Regular.ttf", 14.0f);
|
||||
|
||||
// merge in icons from Google Material Design
|
||||
static const ImWchar icons_ranges[] = {ICON_MIN_MD, 0xf900, 0};
|
||||
ImFontConfig icons_config;
|
||||
icons_config.MergeMode = true;
|
||||
icons_config.GlyphOffset.y = 5.0f;
|
||||
icons_config.GlyphMinAdvanceX = 13.0f;
|
||||
icons_config.PixelSnapH = true;
|
||||
io.Fonts->AddFontFromFileTTF(FONT_ICON_FILE_NAME_MD, 18.0f, &icons_config,
|
||||
icons_ranges);
|
||||
io.Fonts->AddFontFromFileTTF("assets/Fonts/Roboto-Medium.ttf", 14.0f);
|
||||
io.Fonts->AddFontFromFileTTF("assets/Fonts/Cousine-Regular.ttf", 14.0f);
|
||||
io.Fonts->AddFontFromFileTTF("assets/Fonts/DroidSans.ttf", 16.0f);
|
||||
|
||||
// Set the default style
|
||||
Style::ColorsYaze();
|
||||
|
||||
// Build a new ImGui frame
|
||||
ImGui_ImplSDLRenderer_NewFrame();
|
||||
ImGui_ImplSDL2_NewFrame(window);
|
||||
}
|
||||
|
||||
void Renderer::Render() {
|
||||
SDL_RenderClear(renderer);
|
||||
ImGui::Render();
|
||||
ImGui_ImplSDLRenderer_RenderDrawData(ImGui::GetDrawData());
|
||||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
|
||||
void Renderer::Destroy() {
|
||||
SDL_DestroyRenderer(renderer);
|
||||
renderer = nullptr;
|
||||
}
|
||||
|
||||
} // namespace Core
|
||||
} // namespace Application
|
||||
} // namespace yaze
|
||||
29
src/Application/Core/renderer.h
Normal file
29
src/Application/Core/renderer.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifndef YAZE_APPLICATION_CORE_RENDERER_H
|
||||
#define YAZE_APPLICATION_CORE_RENDERER_H
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <imgui/backends/imgui_impl_sdl.h>
|
||||
#include <imgui/backends/imgui_impl_sdlrenderer.h>
|
||||
#include <imgui/imgui.h>
|
||||
|
||||
#include "graphics/icons.h"
|
||||
#include "graphics/style.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace Application {
|
||||
namespace Core {
|
||||
|
||||
static SDL_Renderer* renderer = nullptr;
|
||||
|
||||
class Renderer {
|
||||
public:
|
||||
void Create(SDL_Window* window);
|
||||
void Render();
|
||||
void Destroy();
|
||||
};
|
||||
|
||||
} // namespace Core
|
||||
} // namespace Application
|
||||
} // namespace yaze
|
||||
|
||||
#endif // YAZE_APPLICATION_CORE_RENDERER_H
|
||||
33
src/Application/Core/window.cc
Normal file
33
src/Application/Core/window.cc
Normal file
@@ -0,0 +1,33 @@
|
||||
#include "Window.h"
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
namespace yaze {
|
||||
namespace Application {
|
||||
namespace Core {
|
||||
|
||||
// TODO: pass in the size of the window as argument
|
||||
void Window::Create() {
|
||||
if (SDL_Init(SDL_INIT_EVERYTHING)) {
|
||||
SDL_Log("SDL_Init: %s\n", SDL_GetError());
|
||||
} else {
|
||||
window = SDL_CreateWindow("Yet Another Zelda3 Editor", // window title
|
||||
SDL_WINDOWPOS_UNDEFINED, // initial x position
|
||||
SDL_WINDOWPOS_UNDEFINED, // initial y position
|
||||
1200, // width, in pixels
|
||||
800, // height, in pixels
|
||||
SDL_WINDOW_RESIZABLE // window flags
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
SDL_Window* Window::Get() { return window; }
|
||||
|
||||
void Window::Destroy() {
|
||||
SDL_DestroyWindow(window);
|
||||
window = nullptr;
|
||||
}
|
||||
|
||||
} // namespace Core
|
||||
} // namespace Application
|
||||
} // namespace yaze
|
||||
24
src/Application/Core/window.h
Normal file
24
src/Application/Core/window.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#ifndef YAZE_APPLICATION_CORE_WINDOW_H
|
||||
#define YAZE_APPLICATION_CORE_WINDOW_H
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
namespace yaze {
|
||||
namespace Application {
|
||||
namespace Core {
|
||||
|
||||
class Window {
|
||||
public:
|
||||
void Create();
|
||||
void Destroy();
|
||||
SDL_Window* Get();
|
||||
|
||||
private:
|
||||
SDL_Window* window = nullptr;
|
||||
};
|
||||
|
||||
} // namespace Core
|
||||
} // namespace Application
|
||||
} // namespace yaze
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user