From be216e5aad030c3d3bfa6a7c6c3620a10f6b737a Mon Sep 17 00:00:00 2001 From: Isaiah Odhner Date: Sat, 14 Dec 2019 23:11:30 -0500 Subject: [PATCH] Add action icon for Invert --- help/p_invert.png | Bin 0 -> 139 bytes src/functions.js | 5 ++++- src/image-manipulation.js | 18 +++++++++++------- 3 files changed, 15 insertions(+), 8 deletions(-) create mode 100755 help/p_invert.png diff --git a/help/p_invert.png b/help/p_invert.png new file mode 100755 index 0000000000000000000000000000000000000000..24acd070a36a628c4ad9b5745b67bce6fa38cc49 GIT binary patch literal 139 zcmeAS@N?(olHy`uVBq!ia0vp^d_c_2!3HG#TlXXZsUS}m#}JL+vzJbDG8l5O1S~g- zo_{XJNgzcj=YvT9LG_Q!lM { + apply_image_transformation({ + name: "Invert", + icon: get_icon_for_tool({help_icon: "p_invert.png"}), // HACK + }, (original_canvas, original_ctx, new_canvas, new_ctx) => { invert_rgb(original_ctx, new_ctx); }); } diff --git a/src/image-manipulation.js b/src/image-manipulation.js index b3d8069..9cdb8c4 100644 --- a/src/image-manipulation.js +++ b/src/image-manipulation.js @@ -393,7 +393,7 @@ function draw_noncontiguous_fill(ctx, x, y, fill_r, fill_g, fill_b, fill_a){ } } -function apply_image_transformation(action_name, fn){ +function apply_image_transformation(meta, fn){ // Apply an image transformation function to either the selection or the entire canvas const original_canvas = selection ? selection.source_canvas: canvas; @@ -406,13 +406,17 @@ function apply_image_transformation(action_name, fn){ if(selection){ undoable({ - name: `${action_name} Selection`, + name: `${meta.name} Selection`, + icon: meta.icon, soft: true, }, () => { selection.replace_source_canvas(new_canvas); }); }else{ - undoable({name: action_name}, () => { + undoable({ + name: meta.name, + icon: meta.icon, + }, () => { deselect(); cancel(); saved = false; @@ -425,7 +429,7 @@ function apply_image_transformation(action_name, fn){ } function flip_horizontal(){ - apply_image_transformation("Flip Horizontal", (original_canvas, original_ctx, new_canvas, new_ctx) => { + apply_image_transformation({name: "Flip Horizontal"}, (original_canvas, original_ctx, new_canvas, new_ctx) => { new_ctx.translate(new_canvas.width, 0); new_ctx.scale(-1, 1); new_ctx.drawImage(original_canvas, 0, 0); @@ -433,7 +437,7 @@ function flip_horizontal(){ } function flip_vertical(){ - apply_image_transformation("Flip Vertical", (original_canvas, original_ctx, new_canvas, new_ctx) => { + apply_image_transformation({name: "Flip Vertical"}, (original_canvas, original_ctx, new_canvas, new_ctx) => { new_ctx.translate(0, new_canvas.height); new_ctx.scale(1, -1); new_ctx.drawImage(original_canvas, 0, 0); @@ -441,7 +445,7 @@ function flip_vertical(){ } function rotate(angle){ - apply_image_transformation(`Rotate ${angle / TAU * 360} degrees`, (original_canvas, original_ctx, new_canvas, new_ctx) => { + apply_image_transformation({name: `Rotate ${angle / TAU * 360} degrees`}, (original_canvas, original_ctx, new_canvas, new_ctx) => { new_ctx.save(); switch(angle){ case TAU / 4: @@ -513,7 +517,7 @@ function rotate(angle){ } function stretch_and_skew(xscale, yscale, hsa, vsa){ - apply_image_transformation("Stretch/Skew", (original_canvas, original_ctx, new_canvas, new_ctx) => { + apply_image_transformation({name: "Stretch/Skew"}, (original_canvas, original_ctx, new_canvas, new_ctx) => { const w = original_canvas.width * xscale; const h = original_canvas.height * yscale;