MCPcopy
hub / github.com/viliusle/miniPaint / fill

Method fill

src/js/tools/fill.js:53–133  ·  view source on GitHub ↗
(mouse)

Source from the content-addressed store, hash-verified

51 }
52
53 async fill(mouse) {
54 var params = this.getParams();
55
56 if(this.working == true){
57 return;
58 }
59
60 if (config.layer.type != 'image' && config.layer.type !== null) {
61 alertify.error('This layer must contain an image. Please convert it to raster to apply this tool.');
62 return;
63 }
64 if (config.layer.is_vector == true) {
65 alertify.error('Layer is vector, convert it to raster to apply this tool.');
66 return;
67 }
68 if (config.ALPHA == 0) {
69 alertify.error('Color alpha value can not be zero.');
70 return;
71 }
72
73 //get canvas from layer
74 var canvas = document.createElement('canvas');
75 var ctx = canvas.getContext("2d");
76 if (config.layer.type !== null) {
77 canvas.width = config.layer.width_original;
78 canvas.height = config.layer.height_original;
79 ctx.drawImage(config.layer.link, 0, 0);
80 }
81 else {
82 canvas.width = config.WIDTH;
83 canvas.height = config.HEIGHT;
84 }
85
86 var mouse_x = Math.round(mouse.x) - config.layer.x;
87 var mouse_y = Math.round(mouse.y) - config.layer.y;
88
89 //adapt to origin size
90 mouse_x = this.adaptSize(mouse_x, 'width');
91 mouse_y = this.adaptSize(mouse_y, 'height');
92
93 //convert float coords to integers
94 mouse_x = Math.round(mouse_x);
95 mouse_y = Math.round(mouse_y);
96
97 var color_to = this.Helper.hexToRgb(config.COLOR);
98 color_to.a = config.ALPHA;
99
100 //change
101 this.working = true;
102 this.fill_general(ctx, config.WIDTH, config.HEIGHT,
103 mouse_x, mouse_y, color_to, params.power, params.anti_aliasing, params.contiguous);
104
105 if (config.layer.type != null) {
106 //update
107 app.State.do_action(
108 new app.Actions.Bundle_action('fill_tool', 'Fill Tool', [
109 new app.Actions.Update_layer_image_action(canvas)
110 ])

Callers 15

mousedownMethod · 0.95
fill_generalMethod · 0.80
renderMethod · 0.80
render_stabilizedMethod · 0.80
magic_erase_generalMethod · 0.80
renderMethod · 0.80
erase_generalMethod · 0.80
roundRectMethod · 0.80
draw_shapeMethod · 0.80
draw_shapeMethod · 0.80
draw_shapeMethod · 0.80
draw_shapeMethod · 0.80

Calls 5

fill_generalMethod · 0.95
getParamsMethod · 0.80
adaptSizeMethod · 0.80
hexToRgbMethod · 0.80
do_actionMethod · 0.80

Tested by

no test coverage detected