Gridarta Editor
GridMapSquarePainter.java
Go to the documentation of this file.
1 /*
2  * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3  * Copyright (C) 2000-2023 The Gridarta Developers.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 package net.sf.gridarta.gui.map.renderer;
21 
22 import java.awt.Graphics;
23 import java.awt.Image;
24 import java.awt.image.ImageObserver;
27 import org.jetbrains.annotations.NotNull;
28 
34 public class GridMapSquarePainter {
35 
39  private final Image selImg;
40 
44  private final Image selImgNorth;
45 
49  private final Image selImgEast;
50 
54  private final Image selImgSouth;
55 
59  private final Image selImgWest;
60 
64  private final Image preSelImg;
65 
69  private final Image cursorImg;
70 
74  private final Image warningSquareImg;
75 
80  private final Image lightSquare;
81 
86  public GridMapSquarePainter(@NotNull final ResourceIcons resourceIcons) {
87  selImg = resourceIcons.getResourceIcon(ResourceIcons.SQUARE_SELECTED_SQUARE).getImage();
88  selImgNorth = resourceIcons.getResourceIcon(ResourceIcons.SQUARE_SELECTED_SQUARE_NORTH).getImage();
89  selImgEast = resourceIcons.getResourceIcon(ResourceIcons.SQUARE_SELECTED_SQUARE_EAST).getImage();
90  selImgSouth = resourceIcons.getResourceIcon(ResourceIcons.SQUARE_SELECTED_SQUARE_SOUTH).getImage();
91  selImgWest = resourceIcons.getResourceIcon(ResourceIcons.SQUARE_SELECTED_SQUARE_WEST).getImage();
92  preSelImg = resourceIcons.getResourceIcon(ResourceIcons.SQUARE_PRE_SELECTED_SQUARE).getImage();
93  cursorImg = resourceIcons.getResourceIcon(ResourceIcons.SQUARE_CURSOR).getImage();
94  warningSquareImg = resourceIcons.getWarningSquareIcon().getImage();
95  lightSquare = resourceIcons.getLightSquareIcon().getImage();
96  }
97 
108  public void paint(@NotNull final Graphics graphics, final int gridFlags, final boolean light, final int x, final int y, @NotNull final ImageObserver imageObserver) {
109  if ((gridFlags & MapGrid.GRID_FLAG_SELECTION) != 0) {
110  graphics.drawImage(selImg, x, y, imageObserver);
111  }
112  if ((gridFlags & MapGrid.GRID_FLAG_SELECTION_NORTH) != 0) {
113  graphics.drawImage(selImgNorth, x, y, imageObserver);
114  }
115  if ((gridFlags & MapGrid.GRID_FLAG_SELECTION_EAST) != 0) {
116  graphics.drawImage(selImgEast, x, y, imageObserver);
117  }
118  if ((gridFlags & MapGrid.GRID_FLAG_SELECTION_SOUTH) != 0) {
119  graphics.drawImage(selImgSouth, x, y, imageObserver);
120  }
121  if ((gridFlags & MapGrid.GRID_FLAG_SELECTION_WEST) != 0) {
122  graphics.drawImage(selImgWest, x, y, imageObserver);
123  }
124  if ((gridFlags & MapGrid.GRID_FLAG_SELECTING) != 0) {
125  graphics.drawImage(preSelImg, x, y, imageObserver);
126  }
127  if ((gridFlags & MapGrid.GRID_FLAG_CURSOR) != 0) {
128  graphics.drawImage(cursorImg, x, y, imageObserver);
129  }
130  if ((gridFlags & MapGrid.GRID_FLAG_ERROR) != 0) {
131  graphics.drawImage(warningSquareImg, x, y, imageObserver);
132  }
133  if (light) {
134  graphics.drawImage(lightSquare, x, y, imageObserver);
135  }
136  }
137 
138 }
net.sf.gridarta.utils.ResourceIcons.SQUARE_PRE_SELECTED_SQUARE
static final String SQUARE_PRE_SELECTED_SQUARE
Definition: ResourceIcons.java:74
net.sf.gridarta.gui.map.renderer.GridMapSquarePainter.GridMapSquarePainter
GridMapSquarePainter(@NotNull final ResourceIcons resourceIcons)
Creates a new instance.
Definition: GridMapSquarePainter.java:86
net.sf.gridarta
Base package of all Gridarta classes.
net.sf.gridarta.utils.ResourceIcons.SQUARE_SELECTED_SQUARE_EAST
static final String SQUARE_SELECTED_SQUARE_EAST
Definition: ResourceIcons.java:65
net.sf.gridarta.model.mapgrid.MapGrid.GRID_FLAG_SELECTION
static final int GRID_FLAG_SELECTION
Selection - marks all selected squares.
Definition: MapGrid.java:98
net.sf
net.sf.gridarta.model.mapgrid.MapGrid.GRID_FLAG_SELECTION_EAST
static final int GRID_FLAG_SELECTION_EAST
Selection - is set for squares at the east edge of the selected area.
Definition: MapGrid.java:144
net.sf.gridarta.gui.map.renderer.GridMapSquarePainter.preSelImg
final Image preSelImg
The overlay Image for MapGrid#GRID_FLAG_SELECTING.
Definition: GridMapSquarePainter.java:64
net.sf.gridarta.gui.map.renderer.GridMapSquarePainter.selImgEast
final Image selImgEast
The overlay Image for MapGrid#GRID_FLAG_SELECTION_EAST.
Definition: GridMapSquarePainter.java:49
net.sf.gridarta.gui.map.renderer.GridMapSquarePainter.selImgSouth
final Image selImgSouth
The overlay Image for MapGrid#GRID_FLAG_SELECTION_SOUTH.
Definition: GridMapSquarePainter.java:54
net.sf.gridarta.utils.ResourceIcons.SQUARE_SELECTED_SQUARE_WEST
static final String SQUARE_SELECTED_SQUARE_WEST
Definition: ResourceIcons.java:71
net.sf.gridarta.gui.map.renderer.GridMapSquarePainter.paint
void paint(@NotNull final Graphics graphics, final int gridFlags, final boolean light, final int x, final int y, @NotNull final ImageObserver imageObserver)
Paints overlay images for one grid square.
Definition: GridMapSquarePainter.java:108
net.sf.gridarta.gui.map.renderer.GridMapSquarePainter
Paints overlays for map grids.
Definition: GridMapSquarePainter.java:34
net.sf.gridarta.gui.map.renderer.GridMapSquarePainter.selImgNorth
final Image selImgNorth
The overlay Image for MapGrid#GRID_FLAG_SELECTION_NORTH.
Definition: GridMapSquarePainter.java:44
net.sf.gridarta.model.mapgrid.MapGrid.GRID_FLAG_SELECTION_SOUTH
static final int GRID_FLAG_SELECTION_SOUTH
Selection - is set for squares at the south edge of the selected area.
Definition: MapGrid.java:149
net.sf.gridarta.utils.ResourceIcons.SQUARE_SELECTED_SQUARE_SOUTH
static final String SQUARE_SELECTED_SQUARE_SOUTH
Definition: ResourceIcons.java:68
net
net.sf.gridarta.model.mapgrid.MapGrid.GRID_FLAG_SELECTION_WEST
static final int GRID_FLAG_SELECTION_WEST
Selection - is set for squares at the west edge of the selected area.
Definition: MapGrid.java:154
net.sf.gridarta.model.mapgrid.MapGrid.GRID_FLAG_ERROR
static final int GRID_FLAG_ERROR
Flag to highlight as error.
Definition: MapGrid.java:118
net.sf.gridarta.gui.map.renderer.GridMapSquarePainter.selImgWest
final Image selImgWest
The overlay Image for MapGrid#GRID_FLAG_SELECTION_WEST.
Definition: GridMapSquarePainter.java:59
net.sf.gridarta.gui.map.renderer.GridMapSquarePainter.cursorImg
final Image cursorImg
The overlay Image for MapGrid#GRID_FLAG_CURSOR.
Definition: GridMapSquarePainter.java:69
net.sf.gridarta.model.mapgrid.MapGrid.GRID_FLAG_CURSOR
static final int GRID_FLAG_CURSOR
Flag to highlight cursor position.
Definition: MapGrid.java:134
net.sf.gridarta.utils.ResourceIcons.SQUARE_CURSOR
static final String SQUARE_CURSOR
Definition: ResourceIcons.java:77
net.sf.gridarta.gui.map.renderer.GridMapSquarePainter.warningSquareImg
final Image warningSquareImg
The overlay Image for MapGrid#GRID_FLAG_ERROR.
Definition: GridMapSquarePainter.java:74
net.sf.gridarta.model.mapgrid.MapGrid
2D-Grid containing flags for selection, pre-selection, cursor, warnings and errors.
Definition: MapGrid.java:46
net.sf.gridarta.model.mapgrid
Definition: MapGrid.java:20
net.sf.gridarta.model
net.sf.gridarta.utils.ResourceIcons.SQUARE_SELECTED_SQUARE_NORTH
static final String SQUARE_SELECTED_SQUARE_NORTH
Definition: ResourceIcons.java:62
net.sf.gridarta.gui.map.renderer.GridMapSquarePainter.lightSquare
final Image lightSquare
The overlay Image for map squares that are affected by light emitting game objects.
Definition: GridMapSquarePainter.java:80
net.sf.gridarta.model.mapgrid.MapGrid.GRID_FLAG_SELECTION_NORTH
static final int GRID_FLAG_SELECTION_NORTH
Selection - is set for squares at the north edge of the selected area.
Definition: MapGrid.java:139
net.sf.gridarta.utils.ResourceIcons
Creates ImageIcon instances from resources.
Definition: ResourceIcons.java:46
net.sf.gridarta.gui.map.renderer.GridMapSquarePainter.selImg
final Image selImg
The overlay Image for MapGrid#GRID_FLAG_SELECTION.
Definition: GridMapSquarePainter.java:39
net.sf.gridarta.utils
Definition: ActionBuilderUtils.java:20
net.sf.gridarta.model.mapgrid.MapGrid.GRID_FLAG_SELECTING
static final int GRID_FLAG_SELECTING
Pre-selection - used to preselect squares.
Definition: MapGrid.java:103
net.sf.gridarta.utils.ResourceIcons.SQUARE_SELECTED_SQUARE
static final String SQUARE_SELECTED_SQUARE
Definition: ResourceIcons.java:59