|
1 |
| -// The MIT License (MIT) |
2 |
| -// |
3 |
| -// Copyright (c) 2015, 2016 Arian Fornaris |
4 |
| -// |
5 |
| -// Permission is hereby granted, free of charge, to any person obtaining a |
6 |
| -// copy of this software and associated documentation files (the |
7 |
| -// "Software"), to deal in the Software without restriction, including |
8 |
| -// without limitation the rights to use, copy, modify, merge, publish, |
9 |
| -// distribute, sublicense, and/or sell copies of the Software, and to permit |
10 |
| -// persons to whom the Software is furnished to do so, subject to the |
11 |
| -// following conditions: The above copyright notice and this permission |
12 |
| -// notice shall be included in all copies or substantial portions of the |
13 |
| -// Software. |
14 |
| -// |
15 |
| -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
16 |
| -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
17 |
| -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN |
18 |
| -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
19 |
| -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
20 |
| -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE |
21 |
| -// USE OR OTHER DEALINGS IN THE SOFTWARE. |
22 |
| -package phasereditor.canvas.ui.editors.behaviors; |
23 |
| - |
24 |
| -import java.util.ArrayList; |
25 |
| -import java.util.HashSet; |
26 |
| -import java.util.List; |
27 |
| -import java.util.Set; |
28 |
| - |
29 |
| -import javafx.scene.Node; |
30 |
| -import javafx.scene.layout.Pane; |
31 |
| -import phasereditor.canvas.ui.editors.ObjectCanvas; |
32 |
| -import phasereditor.canvas.ui.editors.edithandlers.AnchorHandlerNode; |
33 |
| -import phasereditor.canvas.ui.editors.edithandlers.AngleHandlerNode; |
34 |
| -import phasereditor.canvas.ui.editors.edithandlers.ArcadeHighlightCircleBodyHandlerNode; |
35 |
| -import phasereditor.canvas.ui.editors.edithandlers.ArcadeHighlightRectBodyHandlerNode; |
36 |
| -import phasereditor.canvas.ui.editors.edithandlers.ArcadeMoveBodyHandlerNode; |
37 |
| -import phasereditor.canvas.ui.editors.edithandlers.ArcadeResizeCircleBodyHandlerNode; |
38 |
| -import phasereditor.canvas.ui.editors.edithandlers.ArcadeResizeRectBodyHandlerNode; |
39 |
| -import phasereditor.canvas.ui.editors.edithandlers.Axis; |
40 |
| -import phasereditor.canvas.ui.editors.edithandlers.IEditHandlerNode; |
41 |
| -import phasereditor.canvas.ui.editors.edithandlers.PivotHandlerNode; |
42 |
| -import phasereditor.canvas.ui.editors.edithandlers.ScaleHandlerNode; |
43 |
| -import phasereditor.canvas.ui.editors.edithandlers.TileHandlerNode; |
44 |
| -import phasereditor.canvas.ui.shapes.IObjectNode; |
45 |
| -import phasereditor.canvas.ui.shapes.ISpriteNode; |
46 |
| - |
47 |
| -/** |
48 |
| - * @author arian |
49 |
| - * |
50 |
| - */ |
51 |
| -public class HandlerBehavior { |
52 |
| - private ObjectCanvas _canvas; |
53 |
| - private Pane _pane; |
54 |
| - |
55 |
| - public HandlerBehavior(ObjectCanvas canvas) { |
56 |
| - super(); |
57 |
| - _canvas = canvas; |
58 |
| - _pane = _canvas.getHandlerPane(); |
59 |
| - } |
60 |
| - |
61 |
| - public void editScale(IObjectNode object) { |
62 |
| - clear(); |
63 |
| - |
64 |
| - for (Axis axis : new Axis[] { Axis.RIG, Axis.BOT, Axis.BOT_RIG }) { |
65 |
| - add(new ScaleHandlerNode(object, axis)); |
66 |
| - } |
67 |
| - |
68 |
| - update(); |
69 |
| - } |
70 |
| - |
71 |
| - public void editTile(IObjectNode object) { |
72 |
| - clear(); |
73 |
| - |
74 |
| - for (Axis axis : Axis.values()) { |
75 |
| - if (axis == Axis.CENTER) { |
76 |
| - continue; |
77 |
| - } |
78 |
| - add(new TileHandlerNode(object, axis)); |
79 |
| - } |
80 |
| - |
81 |
| - update(); |
82 |
| - } |
83 |
| - |
84 |
| - public void editArcadeRectBody(ISpriteNode object) { |
85 |
| - clear(); |
86 |
| - |
87 |
| - add(new ArcadeHighlightRectBodyHandlerNode(object)); |
88 |
| - |
89 |
| - for (Axis axis : Axis.values()) { |
90 |
| - if (axis == Axis.CENTER) { |
91 |
| - continue; |
92 |
| - } |
93 |
| - |
94 |
| - add(new ArcadeResizeRectBodyHandlerNode(object, axis)); |
95 |
| - } |
96 |
| - |
97 |
| - add(new ArcadeMoveBodyHandlerNode(object)); |
98 |
| - |
99 |
| - update(); |
100 |
| - } |
101 |
| - |
102 |
| - public void editArcadeCircleBody(ISpriteNode sprite) { |
103 |
| - clear(); |
104 |
| - |
105 |
| - add(new ArcadeHighlightCircleBodyHandlerNode(sprite)); |
106 |
| - add(new ArcadeMoveBodyHandlerNode(sprite)); |
107 |
| - add(new ArcadeResizeCircleBodyHandlerNode(sprite)); |
108 |
| - |
109 |
| - update(); |
110 |
| - } |
111 |
| - |
112 |
| - public void editAngle(IObjectNode object) { |
113 |
| - clear(); |
114 |
| - |
115 |
| - add(new AngleHandlerNode(object, Axis.TOP_LEF)); |
116 |
| - add(new AngleHandlerNode(object, Axis.TOP_RIG)); |
117 |
| - add(new AngleHandlerNode(object, Axis.BOT_LEF)); |
118 |
| - add(new AngleHandlerNode(object, Axis.BOT_RIG)); |
119 |
| - |
120 |
| - if (object instanceof ISpriteNode) { |
121 |
| - ISpriteNode sprite = (ISpriteNode) object; |
122 |
| - add(new AnchorHandlerNode(sprite)); |
123 |
| - } else { |
124 |
| - add(new PivotHandlerNode(object)); |
125 |
| - } |
126 |
| - |
127 |
| - update(); |
128 |
| - } |
129 |
| - |
130 |
| - public void editAnchor(ISpriteNode object) { |
131 |
| - clear(); |
132 |
| - |
133 |
| - add(new AnchorHandlerNode(object)); |
134 |
| - |
135 |
| - update(); |
136 |
| - } |
137 |
| - |
138 |
| - public void editPivot(IObjectNode object) { |
139 |
| - clear(); |
140 |
| - |
141 |
| - add(new PivotHandlerNode(object)); |
142 |
| - |
143 |
| - update(); |
144 |
| - } |
145 |
| - |
146 |
| - private void add(Node node) { |
147 |
| - _pane.getChildren().add(node); |
148 |
| - } |
149 |
| - |
150 |
| - public void clear() { |
151 |
| - _pane.getChildren().clear(); |
152 |
| - } |
153 |
| - |
154 |
| - public void update() { |
155 |
| - |
156 |
| - List<Node> del = new ArrayList<>(); |
157 |
| - |
158 |
| - _pane.getChildren().forEach(n -> { |
159 |
| - if (!((IEditHandlerNode) n).isValid()) { |
160 |
| - del.add(n); |
161 |
| - } |
162 |
| - }); |
163 |
| - |
164 |
| - _pane.getChildren().removeAll(del); |
165 |
| - |
166 |
| - _pane.getChildren().forEach(n -> { |
167 |
| - ((IEditHandlerNode) n).updateHandler(); |
168 |
| - }); |
169 |
| - } |
170 |
| - |
171 |
| - public void clearNotSelected() { |
172 |
| - @SuppressWarnings("unchecked") |
173 |
| - Set<IObjectNode> set = new HashSet<>(_canvas.getSelectionBehavior().getSelection().toList()); |
174 |
| - new ArrayList<>(_pane.getChildren()).forEach(n -> { |
175 |
| - IObjectNode obj = ((IEditHandlerNode) n).getObject(); |
176 |
| - if (!set.contains(obj)) { |
177 |
| - _pane.getChildren().remove(n); |
178 |
| - } |
179 |
| - }); |
180 |
| - } |
181 |
| - |
182 |
| - public boolean isEditing() { |
183 |
| - return !_pane.getChildren().isEmpty(); |
184 |
| - } |
185 |
| -} |
| 1 | +// The MIT License (MIT) |
| 2 | +// |
| 3 | +// Copyright (c) 2015, 2016 Arian Fornaris |
| 4 | +// |
| 5 | +// Permission is hereby granted, free of charge, to any person obtaining a |
| 6 | +// copy of this software and associated documentation files (the |
| 7 | +// "Software"), to deal in the Software without restriction, including |
| 8 | +// without limitation the rights to use, copy, modify, merge, publish, |
| 9 | +// distribute, sublicense, and/or sell copies of the Software, and to permit |
| 10 | +// persons to whom the Software is furnished to do so, subject to the |
| 11 | +// following conditions: The above copyright notice and this permission |
| 12 | +// notice shall be included in all copies or substantial portions of the |
| 13 | +// Software. |
| 14 | +// |
| 15 | +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 16 | +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 17 | +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN |
| 18 | +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
| 19 | +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 20 | +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE |
| 21 | +// USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 22 | +package phasereditor.canvas.ui.editors.behaviors; |
| 23 | + |
| 24 | +import java.util.ArrayList; |
| 25 | +import java.util.Arrays; |
| 26 | +import java.util.HashSet; |
| 27 | +import java.util.List; |
| 28 | +import java.util.Set; |
| 29 | + |
| 30 | +import javafx.scene.Node; |
| 31 | +import javafx.scene.layout.Pane; |
| 32 | +import phasereditor.canvas.ui.editors.ObjectCanvas; |
| 33 | +import phasereditor.canvas.ui.editors.edithandlers.AnchorHandlerNode; |
| 34 | +import phasereditor.canvas.ui.editors.edithandlers.AngleHandlerNode; |
| 35 | +import phasereditor.canvas.ui.editors.edithandlers.ArcadeHighlightCircleBodyHandlerNode; |
| 36 | +import phasereditor.canvas.ui.editors.edithandlers.ArcadeHighlightRectBodyHandlerNode; |
| 37 | +import phasereditor.canvas.ui.editors.edithandlers.ArcadeMoveBodyHandlerNode; |
| 38 | +import phasereditor.canvas.ui.editors.edithandlers.ArcadeResizeCircleBodyHandlerNode; |
| 39 | +import phasereditor.canvas.ui.editors.edithandlers.ArcadeResizeRectBodyHandlerNode; |
| 40 | +import phasereditor.canvas.ui.editors.edithandlers.Axis; |
| 41 | +import phasereditor.canvas.ui.editors.edithandlers.IEditHandlerNode; |
| 42 | +import phasereditor.canvas.ui.editors.edithandlers.PivotHandlerNode; |
| 43 | +import phasereditor.canvas.ui.editors.edithandlers.ScaleHandlerNode; |
| 44 | +import phasereditor.canvas.ui.editors.edithandlers.TileHandlerNode; |
| 45 | +import phasereditor.canvas.ui.shapes.IObjectNode; |
| 46 | +import phasereditor.canvas.ui.shapes.ISpriteNode; |
| 47 | + |
| 48 | +/** |
| 49 | + * @author arian |
| 50 | + * |
| 51 | + */ |
| 52 | +public class HandlerBehavior { |
| 53 | + private ObjectCanvas _canvas; |
| 54 | + private Pane _pane; |
| 55 | + |
| 56 | + public HandlerBehavior(ObjectCanvas canvas) { |
| 57 | + super(); |
| 58 | + _canvas = canvas; |
| 59 | + _pane = _canvas.getHandlerPane(); |
| 60 | + } |
| 61 | + |
| 62 | + public void editScale(IObjectNode object) { |
| 63 | + clear(); |
| 64 | + |
| 65 | + Arrays.stream(Axis.values()).filter(a -> a != Axis.CENTER) |
| 66 | + .forEach(axis -> add(new ScaleHandlerNode(object, axis))); |
| 67 | + |
| 68 | + update(); |
| 69 | + } |
| 70 | + |
| 71 | + public void editTile(IObjectNode object) { |
| 72 | + clear(); |
| 73 | + |
| 74 | + for (Axis axis : Axis.values()) { |
| 75 | + if (axis == Axis.CENTER) { |
| 76 | + continue; |
| 77 | + } |
| 78 | + add(new TileHandlerNode(object, axis)); |
| 79 | + } |
| 80 | + |
| 81 | + update(); |
| 82 | + } |
| 83 | + |
| 84 | + public void editArcadeRectBody(ISpriteNode object) { |
| 85 | + clear(); |
| 86 | + |
| 87 | + add(new ArcadeHighlightRectBodyHandlerNode(object)); |
| 88 | + |
| 89 | + for (Axis axis : Axis.values()) { |
| 90 | + if (axis == Axis.CENTER) { |
| 91 | + continue; |
| 92 | + } |
| 93 | + |
| 94 | + add(new ArcadeResizeRectBodyHandlerNode(object, axis)); |
| 95 | + } |
| 96 | + |
| 97 | + add(new ArcadeMoveBodyHandlerNode(object)); |
| 98 | + |
| 99 | + update(); |
| 100 | + } |
| 101 | + |
| 102 | + public void editArcadeCircleBody(ISpriteNode sprite) { |
| 103 | + clear(); |
| 104 | + |
| 105 | + add(new ArcadeHighlightCircleBodyHandlerNode(sprite)); |
| 106 | + add(new ArcadeMoveBodyHandlerNode(sprite)); |
| 107 | + add(new ArcadeResizeCircleBodyHandlerNode(sprite)); |
| 108 | + |
| 109 | + update(); |
| 110 | + } |
| 111 | + |
| 112 | + public void editAngle(IObjectNode object) { |
| 113 | + clear(); |
| 114 | + |
| 115 | + add(new AngleHandlerNode(object, Axis.TOP_LEF)); |
| 116 | + add(new AngleHandlerNode(object, Axis.TOP_RIG)); |
| 117 | + add(new AngleHandlerNode(object, Axis.BOT_LEF)); |
| 118 | + add(new AngleHandlerNode(object, Axis.BOT_RIG)); |
| 119 | + |
| 120 | + if (object instanceof ISpriteNode) { |
| 121 | + ISpriteNode sprite = (ISpriteNode) object; |
| 122 | + add(new AnchorHandlerNode(sprite)); |
| 123 | + } else { |
| 124 | + add(new PivotHandlerNode(object)); |
| 125 | + } |
| 126 | + |
| 127 | + update(); |
| 128 | + } |
| 129 | + |
| 130 | + public void editAnchor(ISpriteNode object) { |
| 131 | + clear(); |
| 132 | + |
| 133 | + add(new AnchorHandlerNode(object)); |
| 134 | + |
| 135 | + update(); |
| 136 | + } |
| 137 | + |
| 138 | + public void editPivot(IObjectNode object) { |
| 139 | + clear(); |
| 140 | + |
| 141 | + add(new PivotHandlerNode(object)); |
| 142 | + |
| 143 | + update(); |
| 144 | + } |
| 145 | + |
| 146 | + private void add(Node node) { |
| 147 | + _pane.getChildren().add(node); |
| 148 | + } |
| 149 | + |
| 150 | + public void clear() { |
| 151 | + _pane.getChildren().clear(); |
| 152 | + } |
| 153 | + |
| 154 | + public void update() { |
| 155 | + |
| 156 | + List<Node> del = new ArrayList<>(); |
| 157 | + |
| 158 | + _pane.getChildren().forEach(n -> { |
| 159 | + if (!((IEditHandlerNode) n).isValid()) { |
| 160 | + del.add(n); |
| 161 | + } |
| 162 | + }); |
| 163 | + |
| 164 | + _pane.getChildren().removeAll(del); |
| 165 | + |
| 166 | + _pane.getChildren().forEach(n -> { |
| 167 | + ((IEditHandlerNode) n).updateHandler(); |
| 168 | + }); |
| 169 | + } |
| 170 | + |
| 171 | + public void clearNotSelected() { |
| 172 | + @SuppressWarnings("unchecked") |
| 173 | + Set<IObjectNode> set = new HashSet<>(_canvas.getSelectionBehavior().getSelection().toList()); |
| 174 | + new ArrayList<>(_pane.getChildren()).forEach(n -> { |
| 175 | + IObjectNode obj = ((IEditHandlerNode) n).getObject(); |
| 176 | + if (!set.contains(obj)) { |
| 177 | + _pane.getChildren().remove(n); |
| 178 | + } |
| 179 | + }); |
| 180 | + } |
| 181 | + |
| 182 | + public boolean isEditing() { |
| 183 | + return !_pane.getChildren().isEmpty(); |
| 184 | + } |
| 185 | +} |
0 commit comments