Add ClipboardData to Controller, housekeeping

This commit is contained in:
scawful
2023-07-31 21:26:18 -04:00
parent 2bf6c5c773
commit bc4a90fc76
5 changed files with 37 additions and 24 deletions

View File

@@ -32,6 +32,21 @@ void InitializeKeymap() {
io.KeyMap[ImGuiKey_LeftCtrl] = SDL_GetScancodeFromKey(SDLK_LCTRL); io.KeyMap[ImGuiKey_LeftCtrl] = SDL_GetScancodeFromKey(SDLK_LCTRL);
} }
void ImGui_ImplSDL2_SetClipboardText(void *user_data, const char *text) {
SDL_SetClipboardText(text);
}
const char *ImGui_ImplSDL2_GetClipboardText(void *user_data) {
return SDL_GetClipboardText();
}
void InitializeClipboard() {
ImGuiIO &io = ImGui::GetIO();
io.SetClipboardTextFn = ImGui_ImplSDL2_SetClipboardText;
io.GetClipboardTextFn = ImGui_ImplSDL2_GetClipboardText;
io.ClipboardUserData = nullptr;
}
void HandleKeyDown(SDL_Event &event) { void HandleKeyDown(SDL_Event &event) {
ImGuiIO &io = ImGui::GetIO(); ImGuiIO &io = ImGui::GetIO();
switch (event.key.keysym.sym) { switch (event.key.keysym.sym) {
@@ -81,9 +96,9 @@ void HandleMouseMovement(int &wheel) {
} // namespace } // namespace
bool Controller::isActive() const { return active_; } bool Controller::IsActive() const { return active_; }
absl::Status Controller::onEntry() { absl::Status Controller::OnEntry() {
RETURN_IF_ERROR(CreateWindow()) RETURN_IF_ERROR(CreateWindow())
RETURN_IF_ERROR(CreateRenderer()) RETURN_IF_ERROR(CreateRenderer())
RETURN_IF_ERROR(CreateGuiContext()) RETURN_IF_ERROR(CreateGuiContext())
@@ -93,7 +108,7 @@ absl::Status Controller::onEntry() {
return absl::OkStatus(); return absl::OkStatus();
} }
void Controller::onInput() { void Controller::OnInput() {
int wheel = 0; int wheel = 0;
SDL_Event event; SDL_Event event;
ImGuiIO &io = ImGui::GetIO(); ImGuiIO &io = ImGui::GetIO();
@@ -133,16 +148,16 @@ void Controller::onInput() {
HandleMouseMovement(wheel); HandleMouseMovement(wheel);
} }
void Controller::onLoad() { master_editor_.UpdateScreen(); } void Controller::OnLoad() { master_editor_.UpdateScreen(); }
void Controller::doRender() const { void Controller::DoRender() const {
SDL_RenderClear(renderer_.get()); SDL_RenderClear(renderer_.get());
ImGui::Render(); ImGui::Render();
ImGui_ImplSDLRenderer2_RenderDrawData(ImGui::GetDrawData()); ImGui_ImplSDLRenderer2_RenderDrawData(ImGui::GetDrawData());
SDL_RenderPresent(renderer_.get()); SDL_RenderPresent(renderer_.get());
} }
void Controller::onExit() const { void Controller::OnExit() const {
ImGui_ImplSDLRenderer2_Shutdown(); ImGui_ImplSDLRenderer2_Shutdown();
ImGui_ImplSDL2_Shutdown(); ImGui_ImplSDL2_Shutdown();
ImGui::DestroyContext(); ImGui::DestroyContext();

View File

@@ -22,12 +22,12 @@ namespace core {
class Controller { class Controller {
public: public:
bool isActive() const; bool IsActive() const;
absl::Status onEntry(); absl::Status OnEntry();
void onInput(); void OnInput();
void onLoad(); void OnLoad();
void doRender() const; void DoRender() const;
void onExit() const; void OnExit() const;
private: private:
struct sdl_deleter { struct sdl_deleter {

View File

@@ -1,7 +1,7 @@
#include "assembly_editor.h" #include "assembly_editor.h"
#include "core/constants.h"
#include "app/gui/widgets.h" #include "app/gui/widgets.h"
#include "core/constants.h"
namespace yaze { namespace yaze {
namespace app { namespace app {
@@ -12,7 +12,7 @@ AssemblyEditor::AssemblyEditor() {
text_editor_.SetPalette(TextEditor::GetDarkPalette()); text_editor_.SetPalette(TextEditor::GetDarkPalette());
} }
void AssemblyEditor::Update(bool &is_loaded) { void AssemblyEditor::Update(bool& is_loaded) {
ImGui::Begin("Assembly Editor", &is_loaded); ImGui::Begin("Assembly Editor", &is_loaded);
MENU_BAR() MENU_BAR()
DrawFileMenu(); DrawFileMenu();
@@ -32,8 +32,6 @@ void AssemblyEditor::Update(bool &is_loaded) {
ImGui::End(); ImGui::End();
} }
void AssemblyEditor::InlineUpdate() { void AssemblyEditor::InlineUpdate() {
ChangeActiveFile("assets/asm/template_song.asm"); ChangeActiveFile("assets/asm/template_song.asm");
auto cpos = text_editor_.GetCursorPosition(); auto cpos = text_editor_.GetCursorPosition();
@@ -48,7 +46,7 @@ void AssemblyEditor::InlineUpdate() {
text_editor_.Render("##asm_editor", ImVec2(0, 0)); text_editor_.Render("##asm_editor", ImVec2(0, 0));
} }
void AssemblyEditor::ChangeActiveFile(const std::string& filename) { void AssemblyEditor::ChangeActiveFile(const std::string_view& filename) {
current_file_ = filename; current_file_ = filename;
} }

View File

@@ -18,7 +18,7 @@ class AssemblyEditor {
void Update(bool &is_loaded); void Update(bool &is_loaded);
void InlineUpdate(); void InlineUpdate();
void ChangeActiveFile(const std::string &); void ChangeActiveFile(const std::string_view &);
private: private:
void DrawFileMenu(); void DrawFileMenu();

View File

@@ -14,18 +14,18 @@ int main(int argc, char** argv) {
yaze::app::core::Controller controller; yaze::app::core::Controller controller;
auto entry_status = controller.onEntry(); auto entry_status = controller.OnEntry();
if (!entry_status.ok()) { if (!entry_status.ok()) {
// TODO(@scawful): log the specific error // TODO(@scawful): log the specific error
return EXIT_FAILURE; return EXIT_FAILURE;
} }
while (controller.isActive()) { while (controller.IsActive()) {
controller.onInput(); controller.OnInput();
controller.onLoad(); controller.OnLoad();
controller.doRender(); controller.DoRender();
} }
controller.onExit(); controller.OnExit();
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }