5
5
import cz .hartrik .sg2 .brush .jfx .JFXControls ;
6
6
import cz .hartrik .sg2 .brush .manage .BrushManager ;
7
7
import cz .hartrik .sg2 .engine .EngineSyncTools ;
8
- import cz .hartrik .sg2 .engine .JFXEngine ;
9
8
import cz .hartrik .sg2 .tool .Draggable ;
10
9
import cz .hartrik .sg2 .tool .Fillable ;
11
10
import cz .hartrik .sg2 .tool .Tool ;
12
11
import cz .hartrik .sg2 .world .BrushInserter ;
13
12
import cz .hartrik .sg2 .world .ElementArea ;
14
13
import cz .hartrik .sg2 .world .element .Air ;
15
14
import java .util .function .Supplier ;
15
+ import java .util .logging .Logger ;
16
16
import javafx .scene .canvas .Canvas ;
17
17
import javafx .scene .input .MouseButton ;
18
18
import javafx .scene .input .MouseEvent ;
19
19
20
20
/**
21
21
* Kromě základního kreslení myší umožňuje ještě podržením shift, ctrl, alt...
22
22
*
23
- * @version 2015-03-21
23
+ * @version 2017-08-12
24
24
* @author Patrik Harag
25
25
*/
26
26
public class MouseControllerExt extends MouseControllerPick {
27
27
28
- protected final CanvasWithCursor fxCanvas ;
28
+ private static final Logger LOGGER = Logger . getLogger ( MouseControllerExt . class . getName ()) ;
29
29
30
- protected boolean shiftEvent ;
31
- protected boolean ctrlEvent ;
32
- protected boolean altEvent ;
30
+ private final CanvasWithCursor fxCanvas ;
31
+
32
+ private boolean shiftEvent ;
33
+ private boolean ctrlEvent ;
34
+ private boolean altEvent ;
33
35
34
36
public MouseControllerExt (Canvas canvas , JFXControls controls ,
35
- Supplier <JFXEngine <?>> engineSupplier ,
36
37
Supplier <ElementArea > areaSupplier ,
37
38
Supplier <EngineSyncTools <?>> syncTools ,
38
39
BrushManager brushManager , CanvasWithCursor fxCanvas ) {
39
40
40
- super (canvas , controls , engineSupplier , areaSupplier , syncTools ,
41
- brushManager );
41
+ super (canvas , controls , areaSupplier , syncTools , brushManager );
42
42
43
43
this .fxCanvas = fxCanvas ;
44
44
}
@@ -68,14 +68,16 @@ protected void onMouseReleased(MouseEvent event) {
68
68
apply ((int ) event .getX (), (int ) event .getY (), event .getButton (), false );
69
69
shiftEvent = false ;
70
70
ctrlEvent = false ;
71
+
71
72
} else {
72
73
super .onMouseReleased (event );
73
74
}
74
75
}
75
76
76
77
@ Override
77
78
protected void onMouseDragged (MouseEvent event ) {
78
- if (!shiftEvent && !ctrlEvent ) super .onMouseDragged (event );
79
+ if (!shiftEvent && !ctrlEvent )
80
+ super .onMouseDragged (event );
79
81
}
80
82
81
83
// ostatní metody
@@ -90,21 +92,26 @@ else if (ctrlEvent)
90
92
super .apply (x , y , button , drag );
91
93
}
92
94
93
- protected void shiftEvent (int x , int y , MouseButton button ) {
94
- Draggable draggable = ((Draggable ) controls .getTool (button ));
95
- Brush brush = controls .getBrush (button );
96
- BrushInserter <?> inserter = getInserter (brush );
97
-
98
- draggable .stroke (x , y , lastX , lastY , inserter );
95
+ private void shiftEvent (int x , int y , MouseButton button ) {
96
+ final Tool tool = controls .getTool (button );
97
+ final Brush brush = controls .getBrush (button );
98
+ final int lastX = this .lastX ;
99
+ final int lastY = this .lastY ;
100
+
101
+ if (tool instanceof Draggable ) {
102
+ syncTools .get ().synchronize (() -> {
103
+ BrushInserter <?> inserter = getInserter (brush );
104
+ ((Draggable ) tool ).stroke (x , y , lastX , lastY , inserter );
105
+ inserter .finalizeInsertion ();
106
+ });
107
+ } else {
108
+ LOGGER .warning ("Stroke is not supported" );
109
+ }
99
110
100
- inserter .finalizeInsertion ();
101
111
setDefaultCursor ();
102
112
}
103
113
104
- protected void ctrlEvent (int x , int y , MouseButton button ) {
105
- Fillable fillable = ((Fillable ) controls .getTool (button ));
106
- Brush brush = controls .getBrush (button );
107
- BrushInserter <?> inserter = getInserter (brush );
114
+ private void ctrlEvent (int x , int y , MouseButton button ) {
108
115
109
116
final int startX = Math .min (x , lastX );
110
117
final int startY = Math .min (y , lastY );
@@ -113,33 +120,41 @@ protected void ctrlEvent(int x, int y, MouseButton button) {
113
120
final int height = Math .abs (y - lastY );
114
121
115
122
if (width != 0 && height != 0 ) {
116
- fillable .apply (startX , startY , width , height , inserter );
117
- inserter .finalizeInsertion ();
123
+ final Tool tool = controls .getTool (button );
124
+ final Brush brush = controls .getBrush (button );
125
+
126
+ if (tool instanceof Fillable ) {
127
+ syncTools .get ().synchronize (() -> {
128
+ BrushInserter <?> inserter = getInserter (brush );
129
+ ((Fillable ) tool ).apply (startX , startY , width , height , inserter );
130
+ inserter .finalizeInsertion ();
131
+ });
132
+ } else {
133
+ LOGGER .warning ("Fill is not supported" );
134
+ }
118
135
}
119
136
120
137
setDefaultCursor ();
121
138
}
122
139
123
- protected void altEvent (int x , int y , MouseButton button ) {}
124
-
125
- protected void setDefaultCursor () {
140
+ private void setDefaultCursor () {
126
141
fxCanvas .removeCursor ();
127
142
Tool tool = controls .getTool (MouseButton .PRIMARY );
128
143
if (tool instanceof Cursorable )
129
144
fxCanvas .setCursor (((Cursorable ) tool ).createCursor (fxCanvas ));
130
145
}
131
146
132
- protected boolean isSupportedForDrag (MouseButton button ) {
147
+ private boolean isSupportedForDrag (MouseButton button ) {
133
148
return (button == MouseButton .PRIMARY || button == MouseButton .SECONDARY )
134
149
&& controls .getTool (button ) instanceof Draggable ;
135
150
}
136
151
137
- protected boolean isSupportedForFill (MouseButton button ) {
152
+ private boolean isSupportedForFill (MouseButton button ) {
138
153
return (button == MouseButton .PRIMARY || button == MouseButton .SECONDARY )
139
154
&& controls .getTool (button ) instanceof Fillable ;
140
155
}
141
156
142
- protected void savePos (MouseEvent event ) {
157
+ private void savePos (MouseEvent event ) {
143
158
lastX = (int ) event .getX ();
144
159
lastY = (int ) event .getY ();
145
160
}
0 commit comments