25
25
26
26
import org .eclipse .swt .SWT ;
27
27
import org .eclipse .swt .events .MouseEvent ;
28
+ import org .eclipse .swt .graphics .Color ;
28
29
import org .eclipse .swt .graphics .GC ;
29
30
import org .eclipse .swt .graphics .Transform ;
30
31
import org .eclipse .wb .swt .SWTResourceManager ;
31
32
32
33
import phasereditor .scene .core .ObjectModel ;
33
34
import phasereditor .scene .core .TileSpriteComponent ;
34
35
import phasereditor .scene .ui .editor .SceneEditor ;
36
+ import phasereditor .ui .PhaserEditorUI ;
35
37
36
38
/**
37
39
* @author arian
40
42
@ SuppressWarnings ("boxing" )
41
43
public class TilePositionElement extends RenderInteractiveElement {
42
44
45
+ private static final int BOX = 14 ;
43
46
private static final int ARROW_LENGTH = 80 ;
44
47
private int _globalX ;
45
48
private int _globalY ;
@@ -48,6 +51,7 @@ public class TilePositionElement extends RenderInteractiveElement {
48
51
private int _initialGlobalX ;
49
52
private boolean _changeX ;
50
53
private boolean _changeY ;
54
+ private boolean _hightlights ;
51
55
52
56
public TilePositionElement (SceneEditor editor , List <ObjectModel > models , boolean changeX , boolean changeY ) {
53
57
super (editor , models );
@@ -114,46 +118,59 @@ public void render(GC gc) {
114
118
globalAngle = globalAngle / size ;
115
119
116
120
if (_changeX && _changeY ) {
117
- gc .setBackground (SWTResourceManager .getColor (SWT .COLOR_BLACK ));
118
-
119
- fillRect (gc , globalX , _globalY , globalAngle , 12 );
120
-
121
- gc .setBackground (SWTResourceManager .getColor (SWT .COLOR_WHITE ));
122
- fillRect (gc , globalX , _globalY , globalAngle , 10 );
123
-
121
+ fillRect (gc , globalX , _globalY , globalAngle , BOX ,
122
+ SWTResourceManager .getColor (_hightlights ? SWT .COLOR_WHITE : SWT .COLOR_YELLOW ));
124
123
} else {
125
124
gc .setBackground (SWTResourceManager .getColor (SWT .COLOR_BLACK ));
126
125
gc .setForeground (SWTResourceManager .getColor (SWT .COLOR_BLACK ));
127
126
128
- fillRect (gc , globalX , _globalY , globalAngle , 12 );
129
-
130
- gc .setLineWidth (3 );
131
- gc .drawLine (centerGlobalX , centerGlobalY , globalX , globalY );
132
- gc .setLineWidth (1 );
133
-
134
- var color = SWTResourceManager .getColor (_changeX ? SWT .COLOR_RED : SWT .COLOR_GREEN );
127
+ var color = SWTResourceManager
128
+ .getColor (_hightlights ? SWT .COLOR_WHITE : (_changeX ? SWT .COLOR_RED : SWT .COLOR_GREEN ));
135
129
136
130
gc .setBackground (color );
137
131
gc .setForeground (color );
138
132
139
133
gc .drawLine (centerGlobalX , centerGlobalY , globalX , globalY );
140
134
141
- fillRect (gc , globalX , globalY , globalAngle , 10 );
135
+ fillArrow (gc , globalX , globalY , globalAngle + ( _changeY ? 90 : 0 ), BOX , color );
142
136
}
143
137
144
138
_globalX = globalX ;
145
139
_globalY = globalY ;
146
140
147
141
}
148
142
149
- private static void fillRect (GC gc , int globalX , int globalY , float globalAngle , int size ) {
143
+ private static void fillArrow (GC gc , int globalX , int globalY , float globalAngle , int size , Color color ) {
150
144
var tx = new Transform (gc .getDevice ());
151
145
152
146
tx .translate (globalX , globalY );
153
147
tx .rotate (globalAngle );
148
+ tx .translate (0 , -size / 2 );
154
149
gc .setTransform (tx );
155
150
151
+ gc .setBackground (color );
152
+ gc .setForeground (SWTResourceManager .getColor (SWT .COLOR_BLACK ));
153
+
154
+ gc .fillPolygon (new int [] { 0 , 0 , size , size / 2 , 0 , size });
155
+ gc .drawPolygon (new int [] { 0 , 0 , size , size / 2 , 0 , size });
156
+
157
+ gc .setTransform (null );
158
+
159
+ tx .dispose ();
160
+ }
161
+
162
+ private static void fillRect (GC gc , int globalX , int globalY , float globalAngle , int size , Color color ) {
163
+ var tx = new Transform (gc .getDevice ());
164
+
165
+ tx .translate (globalX , globalY );
166
+ tx .rotate (globalAngle );
167
+ gc .setTransform (tx );
168
+
169
+ gc .setBackground (color );
170
+ gc .setForeground (SWTResourceManager .getColor (SWT .COLOR_BLACK ));
171
+
156
172
gc .fillRectangle (-size / 2 , -size / 2 , size , size );
173
+ gc .drawRectangle (-size / 2 , -size / 2 , size , size );
157
174
158
175
gc .setTransform (null );
159
176
@@ -167,15 +184,11 @@ public boolean contains(int sceneX, int sceneY) {
167
184
return true ;
168
185
}
169
186
170
- boolean b = _globalX - 5 <= sceneX
171
-
172
- && _globalX + 5 >= sceneX
173
-
174
- && _globalY - 5 <= sceneY
187
+ var contains = PhaserEditorUI .distance (sceneX , sceneY , _globalX , _globalY ) <= BOX ;
175
188
176
- && _globalY + 5 >= sceneY ;
189
+ _hightlights = contains ;
177
190
178
- return b ;
191
+ return contains ;
179
192
}
180
193
181
194
@ Override
0 commit comments