diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-15 12:17:21 +0200 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-15 12:17:21 +0200 |
commit | a3eb81cc6b70c03fb40ac4dcd140d5f3ad241ceb (patch) | |
tree | 9d116014f1bb7ff40dab5dbd73a3cb887ef43311 /View.cpp | |
parent | 28ed8918eaf62969f507fc678b4ac31f195bf257 (diff) |
move file loading command + try GUI file loading (still broken)
Diffstat (limited to 'View.cpp')
-rw-r--r-- | View.cpp | 46 |
1 files changed, 23 insertions, 23 deletions
@@ -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<KeyboardCode>(e.key.scancode)); + } + if (e.type == SDL_EVENT_MOUSE_BUTTON_DOWN) { + this->controller.ev_mousedown(static_cast<MouseCode>(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<Scancode>(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<string> out; -} dialog_file_tmp_data; -vector<string> 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<dialog_file_tmp_data*>(userdata); + void (* callback)(std::vector<std::string> files, void* data); + void * data; +} tmp_data; +void View::dialog_file(void(*callback)(std::vector<std::string> 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<tmp_data*>(userdata); + vector<string> 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); } |