/
StartEnd.sketchplugin
50 lines (40 loc) · 1.44 KB
/
StartEnd.sketchplugin
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Sketch Plugin: AEFlowchart - "Start/End" (ctrl shift s)
// Source: github.com/tadija/AEFlowchart
// Version: 1.0
@import 'AEFlowchart.js'
var stepName = "Start/End";
/* call AEFlowchart main function with custom name and shape function */
createStep(stepName, startEndShape);
/* draw start-end rounded rectangle shape for given label */
function startEndShape(label)
{
// create shape
var parentGroup = [label parentGroup];
var shape = [[MSRectangleShape alloc] init];
var shapeGroup = MSShapeGroup.shapeWithPath(shape);
[parentGroup addLayers:[shapeGroup]];
// set frame
var labelFrame = [label frame];
var shapeFrame = [shape frame];
[shapeFrame setWidth:[labelFrame width] + 40];
[shapeFrame setHeight:[labelFrame height] + 20];
[shapeFrame setMidX:[labelFrame midX]];
[shapeFrame setMidY:[labelFrame midY]];
[shapeGroup setFrame: shapeFrame];
// set style
styleType = "layerStyles";
if(doesStyleExist(stepName, shapeGroup, styleType) == false) {
// log(stepName + " style doesn't exist so create it");
createLayerStyle(stepName, shapeGroup, startEndColor, startEndInnerShadows)
}
// round corners (calculate pill radius)
var radius;
if ([shapeFrame width] >= [shapeFrame height]) {
radius = [shapeFrame height] / 2;
} else {
radius = [shapeFrame width] / 2;
}
var firstObject = [[shapeGroup layers] firstObject];
[firstObject setCornerRadiusFloat:Math.round(radius)];
return shapeGroup;
}