20 package net.sf.gridarta.gui.misc;
22 import java.awt.Point;
23 import java.awt.Rectangle;
24 import java.util.Collection;
25 import java.util.LinkedList;
26 import java.util.List;
38 import org.jetbrains.annotations.NotNull;
39 import org.jetbrains.annotations.Nullable;
116 if (selRec == null) {
120 assert mapGrid != null;
126 assert selRec != null;
127 if (selRec.x + dx < 0) {
131 assert selRec != null;
132 if (selRec.x + selRec.width + dx > size.
getWidth()) {
138 assert selRec != null;
139 if (selRec.y + dy < 0) {
143 assert selRec != null;
144 if (selRec.y + selRec.height + dy > size.
getHeight()) {
159 final Point pos =
new Point();
166 for (
int x = selRec.x; x < selRec.x + selRec.width; x++) {
169 shift(pos, selRec.height);
174 for (
int y = selRec.y; y < selRec.y + selRec.height; y++) {
175 pos.x = selRec.x + selRec.width - 1;
177 shift(pos, selRec.width);
182 for (
int x = selRec.x; x < selRec.x + selRec.width; x++) {
184 pos.y = selRec.y + selRec.height - 1;
185 shift(pos, selRec.height);
190 for (
int y = selRec.y; y < selRec.y + selRec.height; y++) {
193 shift(pos, selRec.width);
198 for (
int x = selRec.x; x < selRec.x + selRec.width; x++) {
201 shift(pos, Math.min(x - selRec.x + 1, selRec.height));
203 for (
int y = selRec.y + 1; y < selRec.y + selRec.height; y++) {
204 pos.x = selRec.x + selRec.width - 1;
206 shift(pos, Math.min(selRec.y + selRec.height - y, selRec.width));
211 for (
int x = selRec.x; x < selRec.x + selRec.width; x++) {
213 pos.y = selRec.y + selRec.height - 1;
214 shift(pos, Math.min(x - selRec.x + 1, selRec.height));
216 for (
int y = selRec.y + selRec.height - 2; y >= selRec.y; y--) {
217 pos.x = selRec.x + selRec.width - 1;
219 shift(pos, Math.min(y - selRec.y + 1, selRec.width));
224 for (
int y = selRec.y; y < selRec.y + selRec.height; y++) {
227 shift(pos, Math.min(y - selRec.y + 1, selRec.width));
229 for (
int x = selRec.x + 1; x < selRec.x + selRec.width; x++) {
231 pos.y = selRec.y + selRec.height - 1;
232 shift(pos, Math.min(selRec.x + selRec.width - x, selRec.height));
237 for (
int y = selRec.y + selRec.height - 1; y >= selRec.y; y--) {
240 shift(pos, Math.min(selRec.y + selRec.height - y, selRec.width));
242 for (
int x = selRec.x + 1; x < selRec.x + selRec.width; x++) {
245 shift(pos, Math.min(selRec.x + selRec.width - x, selRec.height));
250 throw new IllegalArgumentException();
271 private void shift(
final Point pos,
final int len) {
272 final Collection<G> startGameObjects =
new LinkedList<>();
273 final List<GameObject<G, A, R>> gameObjectsToDelete =
new LinkedList<>();
274 final Collection<G> gameObjectsToInsert =
new LinkedList<>();
275 final Point prevPos =
new Point(pos.x + dx, pos.y + dy);
276 final Point startPos =
new Point();
277 assert mapGrid != null;
279 assert !startSelection;
280 boolean isStart =
true;
281 for (
int i = 0; i < len; i++) {
282 assert mapGrid != null;
284 assert mapGrid != null;
286 gameObjectsToInsert.clear();
290 startPos.setLocation(prevPos);
292 assert startGameObjects.isEmpty();
293 for (
final G gameObject : mapModel.
getMapSquare(prevPos)) {
294 if (gameObject.isHead() && !gameObject.isInContainer() && mapViewSettings.
isEditType(gameObject)) {
295 startGameObjects.add(gameObject);
296 gameObjectsToDelete.add(gameObject);
302 if (gameObject.isHead() && !gameObject.isInContainer() && mapViewSettings.
isEditType(gameObject)) {
303 gameObjectsToInsert.add(gameObject);
304 gameObjectsToDelete.add(gameObject);
313 gameObjectsToInsert.addAll(startGameObjects);
314 startGameObjects.clear();
320 while (!gameObjectsToDelete.isEmpty()) {
321 gameObjectsToDelete.remove(0).remove();
324 prevPos.setLocation(pos);
332 assert startGameObjects.isEmpty();
333 assert mapGrid != null;
344 private void insertAllAndClear(@NotNull
final Collection<G> gameObjects, @NotNull
final Point point) {
345 for (
final G gameObject : gameObjects) {
346 assert gameObject.isHead() && !gameObject.isInContainer() && mapViewSettings.
isEditType(gameObject);
final MapView< G, A, R > mapView
The map view to operate on.
void shift(final Point pos, final int len)
Shift one row.
Rectangle getSelectedRec()
Returns the smallest rectangle containing selection.
A MapModel reflects the data of a map.
Graphical User Interface of Gridarta.
void endTransaction()
End a transaction.
final InsertionModeSet< G, A, R > insertionModeSet
The InsertionModeSet to use.
MapGrid getMapGrid()
Returns the MapGrid of this view.
boolean isEditType(int editType)
Get information on the current state of edit type.
int getFlags(final int x, final int y)
Returns the flags of a square.
MapGrid mapGrid
The map grid to operate on.
void insertAllAndClear(@NotNull final Collection< G > gameObjects, @NotNull final Point point)
Inserts a collection of GameObjects into the map and clears the list.
Size2D getSize()
Returns size of grid.
G insertBaseObject(@NotNull BaseObject< G, A, R, ?> baseObject, @NotNull Point pos, boolean allowMany, boolean join, @NotNull InsertionMode< G, A, R > insertionMode)
Inserts a BaseObject to a map.
boolean canShift(@NotNull final Direction dir)
Check whether shifting is possible.
Base package of all Gridarta classes.
Reflects a game object (object on a map).
Container for settings that affect the rendering of maps.
MapSquare< G, A, R > getMapSquare(@NotNull Point pos)
Get the square at a specified location.
InsertionMode< G, A, R > getTopmostInsertionMode()
Returns the "topmost" insertion mode.
GameObjects are the objects based on Archetypes found on maps.
int getWidth()
Returns the width of the area.
2D-Grid containing flags for selection, pre-selection, cursor, warnings and errors.
Rectangle selRec
The selection rectangle to operate on.
Base classes for rendering maps.
void beginTransaction()
Starts a new transaction.
void select(@NotNull final Point pos, @NotNull final SelectionMode selectionMode)
Selects or deselects a single square.
void endTransaction()
Ends a transaction.
A map view consists of a map grid and a map cursor, and is attached to a map control.
ShiftProcessor(@NotNull final MapViewSettings mapViewSettings, @NotNull final MapView< G, A, R > mapView, @NotNull final MapModel< G, A, R > mapModel, @NotNull final InsertionModeSet< G, A, R > insertionModeSet)
Create a new instance.
void shift(@NotNull final Direction dir)
Shift the map contents by one square.
ADD
All squares that are preselected get selected.
final MapViewSettings mapViewSettings
The map view settings instance.
Modes that describe how squares get selected.
static final int GRID_FLAG_SELECTION
Selection - marks all selected squares.
SUB
All squares that are preselected get unselected.
void beginTransaction(@NotNull String name)
Starts a new transaction.
int getHeight()
Returns the height of the area.
int dx
The x offset to shift.
final MapModel< G, A, R > mapModel
The map model to operate on.
Interface for MapArchObjects.
Performs a "shift" operation in a map: shift all selected squares into the given direction.
int dy
The y offset to shift.
The class Size2D represents a 2d rectangular area.