Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Clean Layer command #121

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/bindings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/bindings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/canvas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ namespace layer
}
return layer;
}

Layer*
get_by_id(Layer* root_layer, i32 id)
{
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 13 additions & 5 deletions src/gui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/localization.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 2 additions & 0 deletions src/localization.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions src/milton.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions src/milton.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down