Skip to content

Commit

Permalink
Clickable buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
kieranmillar committed Nov 26, 2017
1 parent a05e144 commit 73f5f95
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 42 deletions.
2 changes: 2 additions & 0 deletions src/Editor/bar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions src/Editor/canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 2 additions & 0 deletions src/Editor/canvas.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 */ }

};
Expand Down
85 changes: 43 additions & 42 deletions src/Editor/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 73f5f95

Please sign in to comment.