-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFigureObject.pde
186 lines (161 loc) · 5.2 KB
/
FigureObject.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
private class FigureObject extends GameObject {
/*private float strokeWeight, strokeAlpha;
private color strokeColors;
private int strokeJoin, strokeCap;*/
private boolean canFill, canStroke;
private int mode = CORNER;
private int cornerNum = 4;
private FigureObject() {
canFill = true;
canStroke = false;
}
@Override
public FigureObject clone(){
FigureObject object = new FigureObject();
try {
object = (FigureObject)super.clone();
object.states = new HashMap<String, State>(this.states);
for(Entry<String, State> entry : object.states.entrySet()) {
object.addState(entry.getKey(), entry.getValue());
}
//object.colors = new Integer(this.colors);
//object.subStates = new ArrayList<State>(this.subStates);
} catch (Exception e){
e.printStackTrace();
}
return object;
}
//セッター&ゲッター
/*private void setStrokeWeight(float strokeWeight) {
this.strokeWeight = strokeWeight;
}
private float getStrokeWeight() {
return strokeWeight;
}
private void setStrokeColor(color strokeColors) {
this.strokeColors = strokeColors;
canStroke = true;
}
private color getStrokeColor() {
return strokeColors;
}
private void setStrokeAlpha(float strokeAlpha) {
this.strokeAlpha = strokeAlpha;
}
private float getStrokeAlpha() {
return strokeAlpha;
}
private void setStrokeJoin(int strokeJoin) {
this.strokeJoin = strokeJoin;
}
private int getStrokeJoin() {
return strokeJoin;
}
private void setStrokeCap() {
this.strokeCap = strokeCap;
}
private int getStrokeCap() {
return strokeCap;
}
private void setStroke(boolean canStroke) {
this.canStroke = canStroke;
}
private boolean canStroke() {
return canStroke;
}
private void setFill(boolean canFill) {
this.canFill = canFill;
}
private boolean canFill() {
return canFill;
}*/
private void setMode(int mode) {
this.mode = mode;
adjustParameter();
}
private void setCornerNum(int num) {
this.cornerNum = num;
}
@Override
protected void adjustParameter() {
if(isFreeRef) {
return;
}
// アンカー座標がテキストボックスの中心になるように設定をする
switch(mode) {
case CORNER:
posRX = posX + sizeX / 2.0f;
posRY = posY + sizeY / 2.0f;
break;
case CENTER:
posRX = posX;
posRY = posY;
break;
case CORNERS:
posRX = posX + (posX2 - posX/*size*/) / 2;
posRY = posY + (posY2 - posY/*size*/) / 2;
break;
}
}
// 実装メソッド
@Override
protected void concreteDraw() {
pushMatrix();
float realPosRX = posRX * DISPLAY_SCALE + WIDTH_MARGIN;
float realPosRY = posRY * DISPLAY_SCALE + HEIGHT_MARGIN;
translate(realPosRX, realPosRY);
rotate(radians(rotation));
translate(-realPosRX, -realPosRY);
if(canFill) {
fill(colors, alpha);
} else {
noFill();
}
if(canStroke) {
//stroke(strokeColors, strokeAlpha);
} else {
noStroke();
}
rectMode(mode);
ellipseMode(mode);
float diffX = (sizeX * (scale - 1.0f)) / 2.0f;
float diffY = (sizeY * (scale - 1.0f)) / 2.0f;
float realPosX, realPosY, realPosX2, realPosY2, realSizeX, realSizeY;
switch(mode) {
case CORNER:
realPosX = (posX - diffX) * DISPLAY_SCALE + WIDTH_MARGIN;
realPosY = (posY - diffY) * DISPLAY_SCALE + HEIGHT_MARGIN;
realSizeX = sizeX * scale * DISPLAY_SCALE;
realSizeY = sizeY * scale * DISPLAY_SCALE;
if(cornerNum == 4) {
rect(realPosX, realPosY, realSizeX, realSizeY);
} else {
ellipse(realPosX, realPosY, realSizeX, realSizeY);
}
break;
case CENTER:
realPosX = posX * DISPLAY_SCALE + WIDTH_MARGIN;
realPosY = posY * DISPLAY_SCALE + HEIGHT_MARGIN;
realSizeX = sizeX * scale * DISPLAY_SCALE;
realSizeY = sizeY * scale * DISPLAY_SCALE;
if(cornerNum == 4) {
rect(realPosX, realPosY, realSizeX, realSizeY);
} else {
ellipse(realPosX, realPosY, realSizeX, realSizeY);
}
break;
case CORNERS:
realPosX = (posX - diffX) * DISPLAY_SCALE + WIDTH_MARGIN;
realPosY = (posY - diffY) * DISPLAY_SCALE + HEIGHT_MARGIN;
realPosX2 = (posX2 + diffX) * DISPLAY_SCALE + WIDTH_MARGIN;
realPosY2 = (posY2 + diffY) * DISPLAY_SCALE + HEIGHT_MARGIN;
if(cornerNum == 4) {
rect(realPosX, realPosY, realPosX2, realPosY2);
} else {
ellipse(realPosX, realPosY, realPosX2, realPosY2);
}
break;
}
popMatrix();
}
}