Skip to content

Commit

Permalink
new shapes: callout, cog, moon, tear
Browse files Browse the repository at this point in the history
  • Loading branch information
viliusle committed Jun 19, 2021
1 parent 6bb57b1 commit 1699063
Show file tree
Hide file tree
Showing 6 changed files with 597 additions and 5 deletions.
145 changes: 140 additions & 5 deletions images/test-collection.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"info": {
"width": 1000,
"height": 700,
"height": 750,
"about": "Image data with multi-layers. Can be opened using miniPaint - https://github.com/viliusle/miniPaint",
"date": "2021-01-02",
"version": "4.5.0",
"date": "2021-06-16",
"version": "4.7.1",
"layer_active": 1,
"guides": [
{ "x": null, "y": 400},
{ "x": null, "y": 600}
{ "x": null, "y": 600},
{ "x": null, "y": 650}
]
},
"layers": [
Expand Down Expand Up @@ -700,7 +701,7 @@
"y": 0,
"width": 1000,
"width_original": null,
"height": 700,
"height": 750,
"height_original": null,
"visible": true,
"is_vector": false,
Expand Down Expand Up @@ -1583,6 +1584,140 @@
"human",
"render"
]
},
{
"id": 43,
"parent_id": 0,
"name": "Cog #43",
"type": "cog",
"link": null,
"x": 50,
"y": 650,
"width": 77,
"width_original": null,
"height": 77,
"height_original": null,
"visible": true,
"is_vector": true,
"hide_selection_if_active": false,
"opacity": 100,
"order": 43,
"composition": "source-over",
"rotate": 0,
"data": null,
"params": {},
"status": null,
"color": null,
"filters": [],
"render_function": [
"cog",
"render"
]
},
{
"id": 44,
"parent_id": 0,
"name": "Tear #44",
"type": "tear",
"link": null,
"x": 140,
"y": 650,
"width": 61,
"width_original": null,
"height": 76.25,
"height_original": null,
"visible": true,
"is_vector": true,
"hide_selection_if_active": false,
"opacity": 100,
"order": 44,
"composition": "source-over",
"rotate": 0,
"data": null,
"params": {
"border_size": 4,
"border": true,
"fill": true,
"border_color": "#555555",
"fill_color": "#aaaaaa"
},
"status": null,
"color": null,
"filters": [],
"render_function": [
"tear",
"render"
]
},
{
"id": 45,
"parent_id": 0,
"name": "Moon #45",
"type": "moon",
"link": null,
"x": 220,
"y": 650,
"width": 58,
"width_original": null,
"height": 72.5,
"height_original": null,
"visible": true,
"is_vector": true,
"hide_selection_if_active": false,
"opacity": 100,
"order": 45,
"composition": "source-over",
"rotate": 0,
"data": null,
"params": {
"border_size": 4,
"border": true,
"fill": true,
"border_color": "#555555",
"fill_color": "#aaaaaa"
},
"status": null,
"color": null,
"filters": [],
"render_function": [
"moon",
"render"
]
},
{
"id": 46,
"parent_id": 0,
"name": "Callout #46",
"type": "callout",
"link": null,
"x": 300,
"y": 650,
"width": 81.60000000000001,
"width_original": null,
"height": 69,
"height_original": null,
"visible": true,
"is_vector": true,
"hide_selection_if_active": false,
"opacity": 100,
"order": 46,
"composition": "source-over",
"rotate": 0,
"data": null,
"params": {
"border_size": 4,
"border": true,
"fill": true,
"border_color": "#555555",
"fill_color": "#aaaaaa"
},
"status": null,
"color": null,
"filters": [],
"render_function": [
"callout",
"render"
]
}
],
"data": [
Expand Down
38 changes: 38 additions & 0 deletions src/js/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,44 @@ config.TOOLS = [
fill_color: '#aaaaaa',
},
},
{
name: 'tear',
visible: false,
attributes: {
border_size: 4,
border: false,
fill: true,
border_color: '#555555',
fill_color: '#aaaaaa',
},
},
{
name: 'cog',
visible: false,
attributes: {},
},
{
name: 'moon',
visible: false,
attributes: {
border_size: 4,
border: false,
fill: true,
border_color: '#555555',
fill_color: '#aaaaaa',
},
},
{
name: 'callout',
visible: false,
attributes: {
border_size: 4,
border: true,
fill: true,
border_color: '#555555',
fill_color: '#aaaaaa',
},
},
{
name: 'text',
on_update: 'on_params_update',
Expand Down
99 changes: 99 additions & 0 deletions src/js/tools/shapes/callout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import Base_tools_class from './../../core/base-tools.js';
import Base_layers_class from './../../core/base-layers.js';

class Callout_class extends Base_tools_class {

constructor(ctx) {
super();
this.Base_layers = new Base_layers_class();
this.ctx = ctx;
this.name = 'callout';
this.layer = {};
this.best_ratio = 1.3;
this.snap_line_info = {x: null, y: null};
}

load() {
this.default_events();
}

mousedown(e) {
this.shape_mousedown(e);
}

mousemove(e) {
this.shape_mousemove(e);
}

mouseup(e) {
this.shape_mouseup(e);
}

render_overlay(ctx){
var ctx = this.Base_layers.ctx;
this.render_overlay_parent(ctx);
}

demo(ctx, x, y, width, height) {
ctx.fillStyle = '#aaa';
ctx.strokeStyle = '#555';
ctx.lineWidth = 2;

var width_all = width + x * 2;
width = height * this.best_ratio;
x = (width_all - width) / 2;

ctx.save();
ctx.translate(x + width / 2, y + height / 2);
this.draw_shape(ctx, -width / 2, -height / 2, width, height);
ctx.restore();
}

render(ctx, layer) {
var params = layer.params;
var fill = params.fill;

ctx.save();

//set styles
ctx.strokeStyle = 'transparent';
ctx.fillStyle = 'transparent';
if(params.border)
ctx.strokeStyle = params.border_color;
if(params.fill)
ctx.fillStyle = params.fill_color;
ctx.lineWidth = params.border_size;

//draw with rotation support
ctx.translate(layer.x + layer.width / 2, layer.y + layer.height / 2);
ctx.rotate(layer.rotate * Math.PI / 180);
this.draw_shape(ctx, -layer.width / 2, -layer.height / 2, layer.width, layer.height);

ctx.restore();
}

draw_shape(ctx, x, y, width, height, coords) {
ctx.lineJoin = "round";

ctx.beginPath();

ctx.moveTo(x, y);
ctx.lineTo(x + width, y);
ctx.lineTo(x + width, y + height * 0.6);

ctx.lineTo(x + width / 2 + width / 10, y + height * 0.6);
ctx.lineTo(x + width / 8, y + height);
ctx.lineTo(x + width / 2 - width / 10, y + height * 0.6);

ctx.lineTo(x, y + height * 0.6);
ctx.lineTo(x, y);

ctx.closePath();

ctx.fill();
ctx.stroke();
}

}

export default Callout_class;
Loading

0 comments on commit 1699063

Please sign in to comment.