From 73f5f958c78935a1214e9e0b2c6b16e8e74fdcbf Mon Sep 17 00:00:00 2001 From: Kieran Millar Date: Sun, 26 Nov 2017 22:43:10 +0000 Subject: [PATCH] Clickable buttons --- src/Editor/bar.cpp | 2 + src/Editor/canvas.cpp | 10 +++++ src/Editor/canvas.hpp | 2 + src/Editor/input.cpp | 85 ++++++++++++++++++++++--------------------- 4 files changed, 57 insertions(+), 42 deletions(-) diff --git a/src/Editor/bar.cpp b/src/Editor/bar.cpp index dfab37b..aa9821b 100644 --- a/src/Editor/bar.cpp +++ b/src/Editor/bar.cpp @@ -140,6 +140,8 @@ void Bar::moveScrollBar(int moveLocationInWindow) void Bar::changeType(int t) { + canvas_ptr->layerVisible[t] = true; + canvas_ptr->redraw = true; if (type == t) return; type = t; diff --git a/src/Editor/canvas.cpp b/src/Editor/canvas.cpp index c3291e3..983e253 100644 --- a/src/Editor/canvas.cpp +++ b/src/Editor/canvas.cpp @@ -334,4 +334,14 @@ void Canvas::draw_dashed_level_border(borderType type, int pos, int offset, bool y2 += 20; } } +} + +bool Canvas::toggleLayerVisibility(int type) +{ + if (layerVisible[type]) + layerVisible[type] = false; + else + layerVisible[type] = true; + redraw = true; + return true; } \ No newline at end of file diff --git a/src/Editor/canvas.hpp b/src/Editor/canvas.hpp index bdd3df9..9ae3801 100644 --- a/src/Editor/canvas.hpp +++ b/src/Editor/canvas.hpp @@ -69,6 +69,8 @@ class Canvas enum borderType { horizontal, vertical }; void draw_dashed_level_border(borderType type, int pos, int offset, bool highlight); + bool toggleLayerVisibility(int type); + Canvas(void) { /* nothing to do */ } }; diff --git a/src/Editor/input.cpp b/src/Editor/input.cpp index f1180cf..eef1d1b 100644 --- a/src/Editor/input.cpp +++ b/src/Editor/input.cpp @@ -216,6 +216,46 @@ void Editor_input::handleEvents(SDL_Event event) { holdingType = -1; holdingID = -1; + if (mouse_y_window > window_ptr->height - BAR_HEIGHT + 3 && mouse_y_window < window_ptr->height - BAR_HEIGHT + 35) + //first row of buttons + { + if (mouse_x_window > 3 && mouse_x_window < 35) + { + bar_ptr->changeType(PERM); + } + if (mouse_x_window > 39 && mouse_x_window < 71) + { + bar_ptr->changeType(TEMP); + } + if (mouse_x_window > 75 && mouse_x_window < 107) + { + bar_ptr->changeType(TOOL); + } + if (mouse_x_window > 111 && mouse_x_window < 143) + { + editor_ptr->save(level_ptr->level_id); + } + } + if (mouse_y_window > window_ptr->height - BAR_HEIGHT + 39 && mouse_y_window < window_ptr->height - BAR_HEIGHT + 71) + //second row of buttons + { + if (mouse_x_window > 3 && mouse_x_window < 35) + { + canvas_ptr->toggleLayerVisibility(PERM); + } + if (mouse_x_window > 39 && mouse_x_window < 71) + { + canvas_ptr->toggleLayerVisibility(TEMP); + } + if (mouse_x_window > 75 && mouse_x_window < 107) + { + canvas_ptr->toggleLayerVisibility(TOOL); + } + /*if (mouse_x_window > 111 && mouse_x_window < 143) + { + editor_ptr->save(level_ptr->level_id); + }*/ + } } else if (mouse_y_window < window_ptr->height - 16) // piece browser @@ -358,60 +398,21 @@ void Editor_input::handleEvents(SDL_Event event) { case SDLK_1: if (ctrl_down) - { - if (canvas_ptr->layerVisible[PERM]) - { - canvas_ptr->layerVisible[PERM] = false; - } - else - { - canvas_ptr->layerVisible[PERM] = true; - } - } + canvas_ptr->toggleLayerVisibility(PERM); else - { bar_ptr->changeType(PERM); - canvas_ptr->layerVisible[PERM] = true; - } - canvas_ptr->redraw = true; break; case SDLK_2: if (ctrl_down) - { - if (canvas_ptr->layerVisible[TEMP]) - { - canvas_ptr->layerVisible[TEMP] = false; - } - else - { - canvas_ptr->layerVisible[TEMP] = true; - } - } + canvas_ptr->toggleLayerVisibility(TEMP); else - { bar_ptr->changeType(TEMP); - canvas_ptr->layerVisible[TEMP] = true; - } - canvas_ptr->redraw = true; break; case SDLK_3: if (ctrl_down) - { - if (canvas_ptr->layerVisible[TOOL]) - { - canvas_ptr->layerVisible[TOOL] = false; - } - else - { - canvas_ptr->layerVisible[TOOL] = true; - } - } + canvas_ptr->toggleLayerVisibility(TOOL); else - { bar_ptr->changeType(TOOL); - canvas_ptr->layerVisible[TOOL] = true; - } - canvas_ptr->redraw = true; break; case SDLK_s: editor_ptr->save(level_ptr->level_id);