20 package net.sf.gridarta.gui.map.renderer;
22 import java.awt.Color;
23 import java.awt.Graphics;
24 import java.awt.Graphics2D;
25 import java.awt.Point;
26 import java.awt.Rectangle;
27 import java.awt.image.BufferedImage;
35 import org.jetbrains.annotations.NotNull;
70 private final Point
origin =
new Point();
78 super(mapModel, null);
89 final Rectangle rec =
new Rectangle(0, 0, mapSize.
getWidth(), mapSize.
getHeight());
90 final Point pos =
new Point();
91 final Point endPos = rec.getLocation();
92 endPos.translate(rec.width, rec.height);
93 for (pos.y = rec.y; pos.y < endPos.y; pos.y++) {
94 int xStart = origin.x - (pos.y - rec.x + 1) * isoMapSquareInfo.
getXLen2();
95 int yStart = origin.y + (pos.y + rec.x) * isoMapSquareInfo.
getYLen2();
96 for (pos.x = rec.x; pos.x < endPos.x; pos.x++) {
97 if (graphics.hitClip(xStart, yStart - isoMapSquareInfo.
getYLen() * 4, isoMapSquareInfo.
getXLen(), isoMapSquareInfo.
getYLen() * 5)) {
104 for (
final G node : square) {
105 paint(graphics, xStart, yStart, node);
109 xStart += isoMapSquareInfo.
getXLen2();
110 yStart += isoMapSquareInfo.
getYLen2();
122 protected abstract void paint(@NotNull Graphics2D graphics2D,
int xStart,
int yStart, @NotNull G gameObject);
135 throw new IllegalStateException();
145 final int viewWidth = sum * isoMapSquareInfo.
getXLen2();
146 final int viewHeight = sum * isoMapSquareInfo.
getYLen2();
149 final BufferedImage image =
new BufferedImage(viewWidth, viewHeight, BufferedImage.TYPE_INT_ARGB);
150 final Graphics2D graphics = image.createGraphics();
151 graphics.setColor(BACKGROUND_COLOR);
152 graphics.fillRect(0, 0, viewWidth, viewHeight);
161 throw new IllegalStateException();
172 throw new IllegalStateException();
A MapModel reflects the data of a map.
Rectangle getSquareBounds(@NotNull final Point p)
void paintComponent(@NotNull final Graphics g)
boolean isEmpty()
Check whether this square is empty.
static final long serialVersionUID
The serial version UID.
final IsoMapSquareInfo isoMapSquareInfo
The IsoMapSquareInfo to use.
int getYLen2()
Returns the vertical center of a square.
Base class for classes that contain GameObjects as children in the sense of containment.
int getYLen()
Returns the vertical size of a square.
static final Color BACKGROUND_COLOR
The background Color for created images.
Base package of all Gridarta classes.
Abstract base class for classes implementing MapRenderer.
Reflects a game object (object on a map).
boolean getSquareLocationAt(@NotNull final Point point, @NotNull final Point retPoint)
void calculateOrigin()
The origin which is located in the NORTH_WEST-corner of the map is calculated.
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.
int getWidth()
Returns the width of the area.
final Point origin
The origin is the point in the north-west corner.
void paintComponent2(@NotNull final Graphics2D graphics)
Paints this component.
Provides information about isometric map squares.
BufferedImage getFullImage()
A getMapArchObject()
Returns the Map Arch Object with the meta information about the map.
abstract void paint(@NotNull Graphics2D graphics2D, int xStart, int yStart, @NotNull G gameObject)
Paints a single GameObject.
int getXLen2()
Returns the horizontal center of a square.
AbstractSimpleIsoMapRenderer(@NotNull final MapModel< G, A, R > mapModel, @NotNull final IsoMapSquareInfo isoMapSquareInfo)
Creates a new instance.
int getHeight()
Returns the height of the area.
Abstract base class for ISO MapRenderers.
final MapModel< G, A, R > mapModel
The MapModel to render.
int getXLen()
Returns the horizontal size of a square.
Interface for MapArchObjects.
The class Size2D represents a 2d rectangular area.