-
Notifications
You must be signed in to change notification settings - Fork 0
/
ObjHW.pde
131 lines (113 loc) · 3.41 KB
/
ObjHW.pde
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
class ObjHW {
//TODO: z buffer
ControlP5 aController;
PGraphics ptrScreen;
private PGraphics _backBuffer; //backbuffer a remonter dans objet controlleur (a creer?)
private int selectionWeight= 2;
private int contourWeight= 10;
public color objColor;
public boolean selected;
public ObjTemplate head;
public ObjTemplate queue;
public ObjLink aLink;
public ArrayList nodeList;
ObjHW(GUICtrl tGUICtrl) {
ptrScreen = tGUICtrl.screenBuf;
_backBuffer = tGUICtrl.backBuf;
aController = tGUICtrl.ctrlControlP5;
nodeList = new ArrayList();
head = new ObjCir(200,200,50, this, aController);
queue = new ObjArrow(200,200,40,this, aController);
nodeList.add(head);
aLink = new ObjLink(200,200,200,250,10);
objColor = color(255,220,0);
}
/*
* Private
*/
private void _drawObj(PGraphics aBuffer, int contourWeight, int typeBuffer) {
if (head.selected) {
head.center.x = mouseX;
head.center.y = mouseY;
aLink.processed = false;
}
if (queue.selected) {
queue.center.x = mouseX;
queue.center.y = mouseY;
aLink.processed = false;
}
aLink.psrc1.x = head.center.x;
aLink.psrc1.y = head.center.y;
aLink.psrc2.x = queue.center.x;
aLink.psrc2.y = queue.center.y;
aLink.drawIt(aBuffer, contourWeight, typeBuffer);
head.drawIt(aBuffer, contourWeight, typeBuffer);
queue.drawIt(aBuffer, contourWeight, typeBuffer);
}
private boolean _isSelectedBackBuffer(int x, int y) {
color res;
drawObjInBuffer();
res = _backBuffer.get(x, y);
//on parcourt la liste des composants
println("_isSelectedBackBuffer");
if ( color(head.id) == res ) {
head.selected = true;
println("head selected");
}
if ( color(queue.id) == res) {
queue.selected = true;
println("queue selected");
}
selected = queue.selected | head.selected;
return selected;
}
private void _drawSelection(PGraphics aBuffer) {
aBuffer.beginDraw();
aBuffer.fill(255,0,0);
_drawObj(aBuffer, contourWeight+selectionWeight, 0);
aBuffer.endDraw();
}
/*
* Public
*/
public boolean isSelected(int clickX, int clickY) {
return _isSelectedBackBuffer(mouseX, mouseY);
}
public void drawIt(PGraphics aBuffer, color aColor, int typeBuffer) {
aBuffer.beginDraw();
aBuffer.pushStyle();
aBuffer.noStroke();
aBuffer.fill(0);
_drawObj(aBuffer, contourWeight, typeBuffer);
aBuffer.fill(aColor);
_drawObj(aBuffer, 0, typeBuffer);
aBuffer.popStyle();
aBuffer.endDraw();
}
public void drawObj() {
if (selected) {
_drawSelection(ptrScreen);
}
drawIt(ptrScreen, objColor, 0);
}
public void drawObjInBuffer() {
drawIt(backBuffer, color(255) ,1);
}
public void setUnselected() {
head.selected = false;
queue.selected = false;
}
public void loadParametersUI() {
aController.controller("headRadius").setValue(head.getObjSize());
aController.controller("queueRadius").setValue(queue.getObjSize());
aController.controller("red").setValue(red(objColor));
aController.controller("green").setValue(green(objColor));
aController.controller("blue").setValue(blue(objColor));
}
public void xml(StringBuilder tStrXml) {
tStrXml.append("<objHW id='test'>");
head.toXml(tStrXml);
queue.toXml(tStrXml);
tStrXml.append("</objHW>");
}
}