From a3eb81cc6b70c03fb40ac4dcd140d5f3ad241ceb Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Tue, 15 Oct 2024 12:17:21 +0200 Subject: move file loading command + try GUI file loading (still broken) --- View.cpp | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) (limited to 'View.cpp') diff --git a/View.cpp b/View.cpp index c53ad8f..998356f 100644 --- a/View.cpp +++ b/View.cpp @@ -31,8 +31,14 @@ void View::work() { continue; } if (e.type == SDL_EVENT_KEY_DOWN) { - this->ev_keydown(e.key); - continue; + if (e.key.repeat) continue; + this->controller.ev_keydown(static_cast(e.key.scancode)); + } + if (e.type == SDL_EVENT_MOUSE_BUTTON_DOWN) { + this->controller.ev_mousedown(static_cast(e.button.button)); + } + if (e.type == SDL_EVENT_MOUSE_MOTION) { + this->controller.ev_mousemove(e.motion.x, e.motion.y); } } @@ -44,11 +50,6 @@ void View::work() { this->window_deinit(); } -void View::ev_keydown(SDL_KeyboardEvent ev) { - if (ev.repeat) return; - this->controller.keypress(static_cast(ev.scancode)); -} - void View::window_init() { SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS); this->window = SDL_CreateWindow( @@ -102,22 +103,21 @@ void View::draw_rect(Rectangle r, Color c) { } typedef struct { - bool open; - vector out; -} dialog_file_tmp_data; -vector View::dialog_file() { - dialog_file_tmp_data data = { - .open = true, - .out = {}, - }; - SDL_DialogFileCallback callback = [](void * userdata, const char * const * files, int) -> void { - dialog_file_tmp_data * data = static_cast(userdata); + void (* callback)(std::vector files, void* data); + void * data; +} tmp_data; +void View::dialog_file(void(*callback)(std::vector files, void* data), void* data) { + tmp_data * temp = new tmp_data({ + .callback = callback, + .data = data, + }); + SDL_ShowOpenFileDialog([](void * userdata, const char * const * files, int) -> void { + tmp_data * temp = static_cast(userdata); + vector out = {}; for (; *files != NULL; files++) - data->out.push_back(std::string(*files)); - data->open = false; - }; - SDL_ShowOpenFileDialog(callback, &data, this->window, NULL, 0, NULL, true); - while (data.open); - return data.out; + out.push_back(string(*files)); + (*temp->callback)(out, temp->data); + delete temp; + }, temp, this->window, NULL, 0, NULL, true); } -- cgit v1.2.3