 |
Gridarta Editor
|
Go to the documentation of this file.
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;
47 import org.apache.log4j.Category;
48 import org.apache.log4j.Logger;
49 import org.jetbrains.annotations.NotNull;
50 import org.jetbrains.annotations.Nullable;
87 private final Color @NotNull []
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), };
100 private final Point
offset =
new Point();
147 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) {
166 if (!
mapModel.getMapArchObject().isPointValid(point)) {
171 if (backBuffer ==
null) {
175 final Graphics g = backBuffer.getGraphics();
187 final Point point =
new Point();
189 for (point.x = rectangle.x - 1; point.x < rectangle.x + rectangle.width + 1; point.x++) {
190 for (point.y = rectangle.y - 1; point.y < rectangle.y + rectangle.height + 1; point.y++) {
195 for (point.x = rectangle.x; point.x < rectangle.x + rectangle.width; point.x++) {
196 for (point.y = rectangle.y; point.y < rectangle.y + rectangle.height; point.y++) {
206 if (backBuffer ==
null) {
210 final Graphics graphics = backBuffer.getGraphics();
221 if (backBuffer ==
null) {
224 final int w = backBuffer.getWidth();
225 final int h = backBuffer.getHeight();
226 g.drawImage(backBuffer, 0, 0, w, h, 0, 0, w, h,
null);
233 if (backBuffer !=
null && backBuffer.getWidth() == size.width && backBuffer.getHeight() == size.height) {
239 if (
LOG.isDebugEnabled()) {
240 LOG.debug(
"Creating a backbuffer of size " + size.width +
"x" + size.height +
".");
242 final BufferedImage newBackBuffer;
246 newBackBuffer =
new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_ARGB);
247 }
catch (
final OutOfMemoryError ignore) {
248 if (
LOG.isDebugEnabled()) {
249 LOG.debug(
"out of memory creating new back buffer");
253 final Graphics g = newBackBuffer.getGraphics();
255 g.setColor(getBackground());
256 g.fillRect(0, 0, size.width, size.height);
266 if (square.isEmpty()) {
300 final Color color = g.getColor();
316 final ImageIcon img = node.getNormalImage();
343 if (backBuffer ==
null) {
344 if (
LOG.isDebugEnabled()) {
345 LOG.debug(
"lost back buffer");
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.
A MapModel reflects the data of a map.
boolean isSmoothing()
Returns the smoothing setting.
int getBorderOffsetX()
Returns the x offset to map borders.
final SmoothingRenderer smoothingRenderer
The SmoothingRenderer for rendering smoothed faces.
A AbstractFlatMapRenderer to render map files.
Base package of all Gridarta classes.
The highlighted state while using a FilterControl instance.
void paintSquare(@NotNull final Graphics g, final int x, final int y, @NotNull final MapSquare< GameObject, MapArchObject, Archetype > square)
Paints one square.
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.
SoftReference< BufferedImage > backBufferRef
The back buffer for this map.
static final String SQUARE_EMPTY
Reflects a game object (object on a map).
Container for settings that affect the rendering of maps.
final GridMapSquarePainter gridMapSquarePainter
The GridMapSquarePainter to use.
This is the default renderer of a map.
Paints overlays for map grids.
Interface for listeners interested in FilterConfig related changes.
Graphical User Interface of Gridarta.
final GameObjectParser< G, A, R > gameObjectParser
The GameObjectParser for creating tooltip information or.
Defines common UI constants used in different dialogs and all used icon files.
void closeNotify()
Must be called when this renderer is not used anymore.
GameObjects are the objects based on Archetypes found on maps.
Implements Crossfire archetypes.
MapArchObject contains the specific meta data about a map that is stored in the map-arch,...
final MapGrid mapGrid
The MapGrid to render.
void paintComponent(@NotNull final Graphics g)
@noinspection AbstractMethodOverridesConcreteMethod
final Icon emptySquareIcon
The Icon for painting empty map squares.
Main package of Gridarta4Crossfire, contains all classes specific to the Crossfire version of the Gri...
final FilterControl< GameObject, MapArchObject, Archetype > filterControl
The FilterControl for filtering painted game objects.
void updateSquare(@NotNull final Point point)
Callback function that is called when a square may have changed.
boolean isEditType(int editType)
Get information on the current state of edit type.
void forceRepaint()
Repaint the view because some view parameters may have changed.
int SQUARE_WIDTH
The width of a square in pixels.
void updateAll()
Callback function that is called when any square may have changed.
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,...
final Color[] highLightMask
The colors for highlighting.
Reading and writing of maps, handling of paths.
static final String SMOOTHLEVEL
The name of the "smoothlevel" attribute.
static final Category LOG
The Logger for printing log messages.
final MapModel< GameObject, MapArchObject, Archetype > mapModel
The MapModel to render.
2D-Grid containing flags for selection, pre-selection, cursor, warnings and errors.
static final String INVISIBLE
The name of the "invisible" attribute.
final MapViewSettings mapViewSettings
The map view settings instance.
void resizeBackBuffer(@NotNull final Dimension size)
Resizes the backing buffer to the new grid size.
Renderer for smoothed faces as used by Crossfire.
Base classes for rendering maps.
Handles the Crossfire variants of GameObjects and Archetypes.
void paintSquareSelection(@NotNull final Graphics graphics, @NotNull final Point point)
Paints the selection for one square.
Handles the Crossfire GameObjects.
void updateSquares(@NotNull final Rectangle rectangle)
Callback function that is called when multiple squares may have changed.
Creates ImageIcon instances from resources.
void init()
Finishes initialization of this instance.
BufferedImage getBackBufferImage()
Get the back buffer image for the map.
Interface for classes that read or write GameObject instances.
final Point offset
The offset for painting the map contents.
static final long serialVersionUID
Serial Version UID.
final FilterConfigListener filterConfigListener
The FilterConfigListener attached to filterControl to repaint all after config changes.
final FilterState filterState
The filter state instance for this map renderer.
int getBorderOffsetY()
Returns the y offset to map borders.
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.