From defc363c2d6b1ecb25dc3fe04475391f8a2a36c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82?= Date: Sun, 26 May 2019 15:01:19 +0200 Subject: [PATCH] Add Clean Layer command --- src/bindings.cc | 4 ++++ src/bindings.h | 1 + src/canvas.cc | 7 +++++++ src/canvas.h | 1 + src/gui.cc | 18 +++++++++++++----- src/localization.cc | 1 + src/localization.h | 2 ++ src/milton.cc | 5 +++++ src/milton.h | 1 + 9 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/bindings.cc b/src/bindings.cc index 7488e7c6..84c269f4 100644 --- a/src/bindings.cc +++ b/src/bindings.cc @@ -64,6 +64,7 @@ set_default_bindings(MiltonBindings* bs) binding(bs, Modifier_CTRL, 'n', Action_NEW); binding(bs, Modifier_CTRL, 'o', Action_OPEN); binding(bs, (ModifierFlags)(Modifier_CTRL | Modifier_SHIFT), 's', Action_SAVE_AS); + binding(bs, Modifier_CTRL, 'c', Action_WIPE_LAYER); binding(bs, Modifier_NONE, 'm', Action_TOGGLE_MENU); binding(bs, Modifier_NONE, 'e', Action_MODE_ERASER); @@ -252,6 +253,9 @@ binding_dispatch_action(BindableAction a, MiltonInput* input, Milton* milton, v2 case ActionRelease_PEEK_OUT: { peek_out_trigger_stop(milton); } break; + case Action_WIPE_LAYER: { + milton_wipe_layer(milton); + } break; #if MILTON_DEBUG case Action_TOGGLE_DEBUG_WINDOW: { milton->viz_window_visible = !milton->viz_window_visible; diff --git a/src/bindings.h b/src/bindings.h index 59f0c35f..fb2b8947 100644 --- a/src/bindings.h +++ b/src/bindings.h @@ -39,6 +39,7 @@ enum BindableAction Action_SET_BRUSH_ALPHA_100, Action_HELP, Action_PEEK_OUT, + Action_WIPE_LAYER, #if MILTON_ENABLE_PROFILING // Debug bindings diff --git a/src/canvas.cc b/src/canvas.cc index ef613bf9..cbdd8096 100644 --- a/src/canvas.cc +++ b/src/canvas.cc @@ -108,6 +108,7 @@ namespace layer } return layer; } + Layer* get_by_id(Layer* root_layer, i32 id) { @@ -141,6 +142,12 @@ namespace layer return result; } + void + layer_wipe(Layer* layer) + { + StrokeList* strokes = &(layer->strokes); + reset(strokes); + } void layer_toggle_visibility(Layer* layer) diff --git a/src/canvas.h b/src/canvas.h index 9c9cff5f..ff6e8a03 100644 --- a/src/canvas.h +++ b/src/canvas.h @@ -105,6 +105,7 @@ namespace layer { void layer_toggle_visibility (Layer* layer); b32 layer_has_blur_effect (Layer* layer); Stroke* layer_push_stroke (Layer* layer, Stroke stroke); + void layer_wipe(Layer* layer); i32 number_of_layers (Layer* root); void free_layers (Layer* root); i64 count_strokes (Layer* root); diff --git a/src/gui.cc b/src/gui.cc index 3772f5ee..9c7f9887 100644 --- a/src/gui.cc +++ b/src/gui.cc @@ -25,10 +25,12 @@ gui_layer_window(MiltonInput* input, PlatformState* platform, Milton* milton, f3 // Layer window ImGui::SetNextWindowPos(ImVec2(ui_scale*10, ui_scale*20 + (float)pbounds.bottom + brush_window_height ), ImGuiSetCond_FirstUseEver); - ImGui::SetNextWindowSize(ImVec2(ui_scale*300, ui_scale*220), ImGuiSetCond_FirstUseEver); + ImGui::SetNextWindowSize(ImVec2(ui_scale*400, ui_scale*220), ImGuiSetCond_FirstUseEver); + if ( ImGui::Begin(loc(TXT_layers)) ) { CanvasView* view = milton->view; - // left + + // Layers window. ImGui::BeginChild("left pane", ImVec2(150, 0), true); Layer* layer = milton->canvas->root_layer; @@ -48,16 +50,22 @@ gui_layer_window(MiltonInput* input, PlatformState* platform, Milton* milton, f3 layer = layer->prev; } ImGui::EndChild(); + ImGui::SameLine(); ImGui::BeginGroup(); ImGui::BeginChild("item view", ImVec2(0, 25)); + // New layer button. if ( ImGui::Button(loc(TXT_new_layer)) ) { milton_new_layer(milton); } ImGui::SameLine(); - - // Layer effects + // Wipe layer. + if ( ImGui::Button(loc(TXT_wipe_layer)) ) { + milton_wipe_layer(milton); + } + ImGui::SameLine(); + // Layer effects button. if ( canvas ) { Layer* working_layer = canvas->working_layer; Arena* canvas_arena = &canvas->arena; @@ -141,8 +149,8 @@ gui_layer_window(MiltonInput* input, PlatformState* platform, Milton* milton, f3 } } - ImGui::Separator(); ImGui::EndChild(); + ImGui::Separator(); ImGui::BeginChild("buttons"); static b32 is_renaming = false; diff --git a/src/localization.cc b/src/localization.cc index b34b61f0..347e5525 100644 --- a/src/localization.cc +++ b/src/localization.cc @@ -59,6 +59,7 @@ init_localization() EN(TXT_toggle_gui_visibility, "Toggle GUI Visibility"); EN(TXT_layers, "Layers"); EN(TXT_new_layer, "New Layer"); + EN(TXT_wipe_layer, "Clean layer"); EN(TXT_rename, "Rename"); EN(TXT_move, "Move"); EN(TXT_move_canvas, "Move canvas"); diff --git a/src/localization.h b/src/localization.h index bacf58ae..760db0e8 100644 --- a/src/localization.h +++ b/src/localization.h @@ -44,6 +44,7 @@ enum Texts TXT_switch_to_primitive, TXT_help_me, TXT_new_layer, + TXT_wipe_layer, TXT_rename, TXT_move, TXT_move_canvas, @@ -115,6 +116,7 @@ enum Texts TXT_Action_SET_BRUSH_ALPHA_100, TXT_Action_HELP, TXT_Action_PEEK_OUT, + TXT_Action_WIPE_LAYER, #if MILTON_ENABLE_PROFILING TXT_Action_TOGGLE_DEBUG_WINDOW, diff --git a/src/milton.cc b/src/milton.cc index 0f43fe73..f004e171 100644 --- a/src/milton.cc +++ b/src/milton.cc @@ -861,6 +861,11 @@ milton_set_working_layer(Milton* milton, Layer* layer) milton->view->working_layer_id = layer->id; } +void milton_wipe_layer(Milton* milton) +{ + layer::layer_wipe(milton->canvas->working_layer); +} + void milton_delete_working_layer(Milton* milton) { diff --git a/src/milton.h b/src/milton.h index 381262c5..7028230f 100644 --- a/src/milton.h +++ b/src/milton.h @@ -294,6 +294,7 @@ void milton_new_layer_with_id(Milton* milton, i32 new_id); void milton_set_working_layer(Milton* milton, Layer* layer); void milton_delete_working_layer(Milton* milton); void milton_set_background_color(Milton* milton, v3f background_color); +void milton_wipe_layer(Milton* milton); // Set the center of the zoom void milton_set_zoom_at_point(Milton* milton, v2i zoom_center);