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);
}
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) {
ImGuiIO &io = ImGui::GetIO();
switch (event.key.keysym.sym) {
@@ -81,9 +96,9 @@ void HandleMouseMovement(int &wheel) {
} // 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(CreateRenderer())
RETURN_IF_ERROR(CreateGuiContext())
@@ -93,7 +108,7 @@ absl::Status Controller::onEntry() {
return absl::OkStatus();
}
void Controller::onInput() {
void Controller::OnInput() {
int wheel = 0;
SDL_Event event;
ImGuiIO &io = ImGui::GetIO();
@@ -133,16 +148,16 @@ void Controller::onInput() {
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());
ImGui::Render();
ImGui_ImplSDLRenderer2_RenderDrawData(ImGui::GetDrawData());
SDL_RenderPresent(renderer_.get());
}
void Controller::onExit() const {
void Controller::OnExit() const {
ImGui_ImplSDLRenderer2_Shutdown();
ImGui_ImplSDL2_Shutdown();
ImGui::DestroyContext();

View File

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

View File

@@ -1,7 +1,7 @@
#include "assembly_editor.h"
#include "core/constants.h"
#include "app/gui/widgets.h"
#include "core/constants.h"
namespace yaze {
namespace app {
@@ -12,7 +12,7 @@ AssemblyEditor::AssemblyEditor() {
text_editor_.SetPalette(TextEditor::GetDarkPalette());
}
void AssemblyEditor::Update(bool &is_loaded) {
void AssemblyEditor::Update(bool& is_loaded) {
ImGui::Begin("Assembly Editor", &is_loaded);
MENU_BAR()
DrawFileMenu();
@@ -32,8 +32,6 @@ void AssemblyEditor::Update(bool &is_loaded) {
ImGui::End();
}
void AssemblyEditor::InlineUpdate() {
ChangeActiveFile("assets/asm/template_song.asm");
auto cpos = text_editor_.GetCursorPosition();
@@ -48,7 +46,7 @@ void AssemblyEditor::InlineUpdate() {
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;
}

View File

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

View File

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