20 package net.sf.gridarta.var.crossfire.gui.map.renderer;
22 import java.awt.Color;
23 import java.awt.Dimension;
24 import java.awt.Graphics;
25 import java.awt.Image;
26 import java.awt.Point;
27 import java.awt.Rectangle;
28 import java.awt.image.BufferedImage;
29 import java.awt.image.RenderedImage;
30 import java.lang.ref.SoftReference;
31 import javax.swing.Icon;
32 import javax.swing.ImageIcon;
49 import org.apache.log4j.Category;
50 import org.apache.log4j.Logger;
51 import org.jetbrains.annotations.NotNull;
52 import org.jetbrains.annotations.Nullable;
89 private final Color[]
highLightMask = {
new Color(1.0f, 0.0f, 0.0f, 0.33f),
new Color(0.0f, 1.0f, 0.0f, 0.33f),
new Color(0.0f, 1.0f, 1.0f, 0.33f), };
102 private final Point
offset =
new Point();
156 public FlatMapRenderer(@NotNull
final MapViewSettings mapViewSettings, @NotNull
final FilterControl<GameObject, MapArchObject, Archetype> filterControl, @NotNull
final MapModel<GameObject, MapArchObject, Archetype> mapModel, @NotNull
final MapGrid mapGrid, @NotNull
final GridMapSquarePainter gridMapSquarePainter, @NotNull
final GameObjectParser<GameObject, MapArchObject, Archetype> gameObjectParser, @NotNull
final ResourceIcons resourceIcons, @NotNull
final SmoothingRenderer smoothingRenderer) {
157 super(mapViewSettings, mapModel, mapGrid, 32, gridMapSquarePainter, gameObjectParser);
164 this.filterControl.addConfigListener(filterConfigListener);
180 if (backBuffer == null) {
184 final Graphics g = backBuffer.getGraphics();
196 final Point point =
new Point();
198 for (point.x = rectangle.x - 1; point.x < rectangle.x + rectangle.width + 1; point.x++) {
199 for (point.y = rectangle.y - 1; point.y < rectangle.y + rectangle.height + 1; point.y++) {
204 for (point.x = rectangle.x; point.x < rectangle.x + rectangle.width; point.x++) {
205 for (point.y = rectangle.y; point.y < rectangle.y + rectangle.height; point.y++) {
215 if (backBuffer == null) {
219 final Graphics graphics = backBuffer.getGraphics();
230 if (backBuffer != null) {
231 final int w = backBuffer.getWidth();
232 final int h = backBuffer.getHeight();
233 g.drawImage(backBuffer, 0, 0, w, h, 0, 0, w, h, null);
242 if (backBuffer != null && backBuffer.getWidth() == size.width && backBuffer.getHeight() == size.height) {
246 backBufferRef = null;
248 if (LOG.isDebugEnabled()) {
249 LOG.debug(
"Creating a backbuffer of size " + size.width +
"x" + size.height +
".");
251 final BufferedImage newBackBuffer;
255 newBackBuffer =
new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_ARGB);
256 }
catch (
final OutOfMemoryError ignore) {
257 if (LOG.isDebugEnabled()) {
258 LOG.debug(
"out of memory creating new back buffer");
262 final Graphics g = newBackBuffer.getGraphics();
264 g.setColor(getBackground());
265 g.fillRect(0, 0, size.width, size.height);
269 backBufferRef =
new SoftReference<>(newBackBuffer);
275 if (square.isEmpty()) {
276 emptySquareIcon.paintIcon(
this, g, x, y);
296 smoothingRenderer.
paintSmooth(g, square.getMapLocation(), 1, layer + 1,
true, borderOffsetX, borderOffsetY);
309 final Color color = g.getColor();
310 g.setColor(highLightMask[i]);
325 final ImageIcon img = node.getNormalImage();
347 if (backBufferRef == null) {
351 final BufferedImage backBuffer = backBufferRef.get();
352 if (backBuffer == null) {
353 if (LOG.isDebugEnabled()) {
354 LOG.debug(
"lost back buffer");
356 backBufferRef = null;
This is the default renderer of a map.
static final long serialVersionUID
Serial Version UID.
A MapModel reflects the data of a map.
void updateSquares(@NotNull final Rectangle rectangle)
Graphical User Interface of Gridarta.
Reading and writing of maps, handling of paths.
static final String SMOOTHLEVEL
The name of the "smoothlevel" attribute.
void newSquare(@NotNull FilterState filterState)
void paintSquareGrid(@NotNull final Graphics graphics, @NotNull final Point point)
Paints the grid for one square.
int SQUARE_HEIGHT
The height of a square in pixels.
void paintSquareSelection(@NotNull final Graphics graphics, @NotNull final Point point)
Paints the selection for one square.
MapArchObject contains the specific meta data about a map that is stored in the map-arch, at the very beginning of the map file.
Handles the Crossfire variants of GameObjects and Archetypes.
Interface for classes that read or write GameObject instances.
boolean isEditType(int editType)
Get information on the current state of edit type.
final Color [] highLightMask
The colors for highlighting.
void resizeBackBuffer(@NotNull final Dimension size)
Handles the Crossfire GameObjects.
void forceRepaint()
Repaint the view because some view parameters may have changed.
Renderer for smoothed faces as used by Crossfire.
final Point offset
The offset for painting the map contents.
final Icon emptySquareIcon
The Icon for painting empty map squares.
boolean isSmoothing()
Returns the smoothing setting.
final FilterControl< GameObject, MapArchObject, Archetype > filterControl
The FilterControl for filtering painted game objects.
Base package of all Gridarta classes.
final MapModel< GameObject, MapArchObject, Archetype > mapModel
The MapModel to render.
Reflects a game object (object on a map).
void paintSquare(@NotNull final Graphics g, final int x, final int y, @NotNull final MapSquare< GameObject, MapArchObject, Archetype > square)
Paints overlays for map grids.
Implements Crossfire archetypes.
final MapGrid mapGrid
The MapGrid to render.
BufferedImage getBackBufferImage()
Get the back buffer image for the map.
Types of FilterConfig change types.
Container for settings that affect the rendering of maps.
MapSquare< G, A, R > getMapSquare(@NotNull Point pos)
Get the square at a specified location.
GameObjects are the objects based on Archetypes found on maps.
boolean canShow(@NotNull G gameObject)
SoftReference< BufferedImage > backBufferRef
The back buffer for this map.
boolean isHighlightedSquare(@NotNull FilterState filterState, int path)
int getBorderOffsetX()
Returns the x offset to map borders.
2D-Grid containing flags for selection, pre-selection, cursor, warnings and errors.
Defines common UI constants used in different dialogs and all used icon files.
The filter package contains the classes for Filters.
final FilterState filterState
The filter state instance for this map renderer.
A AbstractFlatMapRenderer to render map files.
final GameObjectParser< G, A, R > gameObjectParser
The GameObjectParser for creating tooltip information or.
Base classes for rendering maps.
void paintGameObject(@NotNull final Graphics g, final int x, final int y, @NotNull final net.sf.gridarta.model.gameobject.GameObject< GameObject, MapArchObject, Archetype > node)
Paints one game object.
Main package of Gridarta4Crossfire, contains all classes specific to the Crossfire version of the Gri...
static final String INVISIBLE
The name of the "invisible" attribute.
void objectInSquare(@NotNull FilterState filterState, @NotNull G gameObject)
FlatMapRenderer(@NotNull final MapViewSettings mapViewSettings, @NotNull final FilterControl< GameObject, MapArchObject, Archetype > filterControl, @NotNull final MapModel< GameObject, MapArchObject, Archetype > mapModel, @NotNull final MapGrid mapGrid, @NotNull final GridMapSquarePainter gridMapSquarePainter, @NotNull final GameObjectParser< GameObject, MapArchObject, Archetype > gameObjectParser, @NotNull final ResourceIcons resourceIcons, @NotNull final SmoothingRenderer smoothingRenderer)
Creates a new instance.
A getMapArchObject()
Returns the Map Arch Object with the meta information about the map.
final FilterConfigListener filterConfigListener
The FilterConfigListener attached to filterControl to repaint all after config changes.
static final Category LOG
The Logger for printing log messages.
int getBorderOffsetY()
Returns the y offset to map borders.
Creates ImageIcon instances from resources.
void init()
Finishes initialization of this instance.
void removeConfigListener(@NotNull FilterConfigListener listener)
Removes a FilterConfigListener to be notified about changes.
static final String SQUARE_EMPTY
final GridMapSquarePainter gridMapSquarePainter
The GridMapSquarePainter to use.
final MapViewSettings mapViewSettings
The map view settings instance.
Interface for filter configurations.
final SmoothingRenderer smoothingRenderer
The SmoothingRenderer for rendering smoothed faces.
int SQUARE_WIDTH
The width of a square in pixels.
void paintSmooth(@NotNull final Graphics graphics, @NotNull final Point pos, final int level, final int firstLayer, final boolean allLayers, final int borderOffsetX, final int borderOffsetY)
Draw the smoothing information at given position of map, for a given limit smoothlevel, at a given layer.
Interface for listeners interested in FilterConfig related changes.
void updateSquare(@NotNull final Point point)
void paintComponent(@NotNull final Graphics g)
The highlighted state while using a FilterControl instance.