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

Method mousedown

src/js/tools/pencil.js:57–102  ·  view source on GitHub ↗
(e)

Source from the content-addressed store, hash-verified

55 }
56
57 mousedown(e) {
58 var mouse = this.get_mouse_info(e);
59 if (mouse.click_valid == false)
60 return;
61
62 var params_hash = this.get_params_hash();
63 var opacity = Math.round(config.ALPHA / 255 * 100);
64
65 if (config.layer.type != this.name || params_hash != this.params_hash) {
66 //register new object - current layer is not ours or params changed
67 this.layer = {
68 type: this.name,
69 data: [],
70 opacity: opacity,
71 params: this.clone(this.getParams()),
72 status: 'draft',
73 render_function: [this.name, 'render'],
74 x: 0,
75 y: 0,
76 width: config.WIDTH,
77 height: config.HEIGHT,
78 hide_selection_if_active: true,
79 rotate: null,
80 is_vector: true,
81 color: config.COLOR
82 };
83 app.State.do_action(
84 new app.Actions.Bundle_action('new_pencil_layer', 'New Pencil Layer', [
85 new app.Actions.Insert_layer_action(this.layer)
86 ])
87 );
88 this.params_hash = params_hash;
89 }
90 else {
91 //continue adding layer data, just register break
92 const new_data = JSON.parse(JSON.stringify(config.layer.data));
93 new_data.push(null);
94 app.State.do_action(
95 new app.Actions.Bundle_action('update_pencil_layer', 'Update Pencil Layer', [
96 new app.Actions.Update_layer_action(config.layer.id, {
97 data: new_data
98 })
99 ])
100 );
101 }
102 }
103
104 mousemove(e) {
105 var mouse = this.get_mouse_info(e);

Callers

nothing calls this directly

Calls 5

get_mouse_infoMethod · 0.80
get_params_hashMethod · 0.80
cloneMethod · 0.80
getParamsMethod · 0.80
do_actionMethod · 0.80

Tested by

no test coverage detected