-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathselectfuncs.js
101 lines (84 loc) · 2.61 KB
/
selectfuncs.js
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// --------------------------------
//
// State select/deselect functions
//
// --------------------------------
function stateClick(state)
{
deselectAll();
selectObject(state);
refreshToolbars();
}
function deselectAll()
{
var i;
refreshConnections();
for(i=0; i<g.selected.length; i++) deselectObject(g.selected[i--]);
deselectConnection();
refreshToolbars();
}
function deselectObject(state)
{
// remove from selection array
var i;
for(i=0; i<g.selected.length; i++) if (g.selected[i].id==state.id) g.selected.splice(i--,1);
state.attr({"stroke":'#666', 'stroke-width':1});
destroySelectors();
refreshToolbars();
}
function selectConnection(con)
{
if (con)
{
deselectAll();
refreshConnection(getConnectionsIndex(con),'red');
g.selectedCon=con;
con.toFront();
if (con.arrowend) con.arrowend.toFront();
if (con.text) con.text.toFront();
}
refreshToolbars();
}
function deselectConnection(con)
{
if (!con) con=g.selectedCon;
if (con) refreshConnection(getConnectionsIndex(con));
refreshToolbars();
g.selectedCon=false;
}
function isSelected(state)
{
var i, isSelected = false;
for(i=0; i<g.selected.length; i++) if (g.selected[i].id==state.id) isSelected=true;
return isSelected;
}
function selectObject(state)
{
if (!isSelected(state)) // add to array
{
state.attr({"stroke":"#6599FF", 'stroke-width': 2});
state.selXpos=state.attr("x");
state.selYpos=state.attr("y");
g.selected.push(state);
}
if (g.selected.length==1 && state.fwprop.type!='final')
{
if (!stateIsNote(state) && !stateIsNoteDot(state))
{
if (!g.connector) g.connector=paper.rect(0,0,10,10,5).transform("t0.5,0.5")
g.connector.attr({stroke:"#39f", fill: "#b9d5f1", cursor: "move"});
g.connector.drag(connectordragmove,connectordragstart,connectordragend);
g.connector.parent=state;
}
if (state.fwprop.type=='state' || stateIsNote(state))
{
if (!g.enlarger) g.enlarger=paper.path("M0,0L10,0L10,-10M0,0L10,-10M4,0L10,-6");
g.enlarger.attr({"stroke-width":2, stroke:"#6599ff", fill: "#fff", cursor: "nw-resize"});
g.enlarger.drag(enlargerdragmove,enlargerdragstart,enlargerdragend);
g.enlarger.parent=state;
}
refreshState(state);
}
else
destroySelectors();
}