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.Point;
26 import java.awt.Rectangle;
27 import java.awt.image.BufferedImage;
28 import java.util.Collection;
29 import java.util.HashSet;
49 import org.jetbrains.annotations.NotNull;
50 import org.jetbrains.annotations.Nullable;
118 private final Rectangle
tmpRec =
new Rectangle();
128 public void gridVisibleChanged(
final boolean gridVisible) {
133 public void lightVisibleChanged(
final boolean lightVisible) {
138 public void smoothingChanged(
final boolean smoothing) {
143 public void tileStretchingChanged(
final boolean tileStretching) {
148 public void doubleFacesChanged(
final boolean doubleFaces) {
153 public void alphaTypeChanged(
final int alphaType) {
158 public void editTypeChanged(
final int editType) {
163 public void autojoinChanged(
final boolean autojoin) {
176 public void mapSizeChanged(@NotNull
final Size2D newSize) {
182 final Collection<MapSquare<GameObject, MapArchObject, Archetype>> toRepaint =
new HashSet<>();
184 getSquaresToRepaint(mapSquare, toRepaint);
192 public void mapObjectsChanged(@NotNull
final Set<GameObject> gameObjects, @NotNull
final Set<GameObject> transientGameObjects) {
193 final Collection<MapSquare<GameObject, MapArchObject, Archetype>> toRepaint =
new HashSet<>();
194 addMapSquares(gameObjects, toRepaint);
195 addMapSquares(transientGameObjects, toRepaint);
209 if (!gameObject.isInContainer()) {
212 if (square != null) {
213 getSquaresToRepaint(square, toRepaint);
229 final Point point =
new Point();
230 for (
int dx = -1; dx <= 1; dx++) {
231 for (
int dy = -1; dy <= 1; dy++) {
232 mapSquare.getMapLocation(point, dx, dy);
239 toRepaint.add(mapSquare);
249 public void mapFileChanged(@Nullable
final MapFile oldMapFile) {
254 public void modifiedChanged() {
267 public void mapGridChanged(@NotNull
final MapGridEvent e) {
274 public void mapGridResized(@NotNull
final MapGridEvent e) {
291 super(mapModel, gameObjectParser);
295 mapSize = this.mapModel.getMapArchObject().getMapSize();
298 mapViewSettings.addMapViewSettingsListener(mapViewSettingsListener);
300 setToolTipText(
"dummy");
302 borderOffset.setLocation(borderSize, borderSize);
328 final BufferedImage bufImage =
new BufferedImage(viewWidth, viewHeight, BufferedImage.TYPE_INT_ARGB);
329 final Graphics graphics = bufImage.getGraphics();
331 graphics.setColor(Color.white);
332 graphics.fillRect(0, 0, viewWidth, viewHeight);
335 final Point storeOffset =
new Point(borderOffset);
337 borderOffset.setLocation(0, 0);
340 borderOffset.setLocation(storeOffset);
375 final Point pos = square.getMapLocation();
388 protected void paintComponent(@NotNull
final Graphics graphics,
final boolean isSnapshot,
final boolean checkClip) {
389 graphics.setColor(getBackground());
390 graphics.fillRect(0, 0, getWidth(), getHeight());
404 protected void paintSquareGrid(@NotNull
final Graphics graphics, @NotNull
final Point point) {
417 final int gridFlags = mapGrid.
getFlags(point.x, point.y);
428 private void paintMap(@NotNull
final Graphics graphics,
final boolean checkClip) {
429 for (tmpPoint.y = 0; tmpPoint.y < mapGrid.
getSize().
getHeight(); tmpPoint.y++) {
431 for (tmpPoint.x = 0; tmpPoint.x < mapGrid.
getSize().
getWidth(); tmpPoint.x++) {
447 for (tmpPoint.y = 0; tmpPoint.y < mapSize.
getHeight(); tmpPoint.y++) {
449 for (tmpPoint.x = 0; tmpPoint.x < mapSize.
getWidth(); tmpPoint.x++) {
467 final int mapWidth = tmpMapSize.
getWidth();
468 final int mapHeight = tmpMapSize.
getHeight();
469 for (
int x = 0; x <= mapWidth; x++) {
472 for (
int y = 0; y <= mapHeight; y++) {
480 final int x = point.x - borderOffset.x;
481 final int y = point.y - borderOffset.y;
482 if (x < 0 || y < 0) {
491 retPoint.setLocation(xm, ym);
519 setPreferredSize(forcedSize);
520 setMinimumSize(forcedSize);
529 protected abstract void updateSquare(@NotNull Point point);
535 protected abstract void updateSquares(@NotNull Rectangle rectangle);
547 return borderOffset.x;
555 return borderOffset.y;
This is the default renderer of a map.
MapSquare< G, A, R > getMapSquare()
A MapModel reflects the data of a map.
boolean isLight()
Returns whether this map square is affected by any light emitting game objects.
final MapViewSettingsListener mapViewSettingsListener
The MapViewSettingsListener attached to mapViewSettings.
Graphical User Interface of Gridarta.
Reading and writing of maps, handling of paths.
void paintSquareGrid(@NotNull final Graphics graphics, @NotNull final Point point)
Paints the grid for one square.
final MapModel< GameObject, MapArchObject, Archetype > mapModel
The MapModel to render.
This package contains the framework for validating maps.
int SQUARE_HEIGHT
The height of a square in pixels.
void resizeMapGrid()
Updates cached information to new map grid size.
void paintMap(@NotNull final Graphics graphics, final boolean checkClip)
Paints the whole map.
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 listeners listening on MapModel events.
boolean lightVisible
Whether the setting for lighted map squares is inverted.
Interface for classes that read or write GameObject instances.
boolean getSquareLocationAt(@NotNull final Point point, @NotNull final Point retPoint)
Returns the map location at the given point.
abstract void paintComponent(@NotNull Graphics g)
AbstractMethodOverridesConcreteMethod
int getFlags(final int x, final int y)
Returns the flags of a square.
Handles the Crossfire GameObjects.
void forceRepaint()
Repaint the view because some view parameters may have changed.
void removeMapGridListener(@NotNull final MapGridListener listener)
Removes a MapGridListener.
boolean isLightVisible()
Get the visibility of the light.
void paintSquare(@NotNull final MapSquare< GameObject, MapArchObject, Archetype > square)
Paints one square.
void paintMapSelection(@NotNull final Graphics graphics)
Paints the selection for the whole map.
void addMapModelListener(@NotNull MapModelListener< G, A, R > listener)
Register a map listener.
Size2D getSize()
Returns size of grid.
boolean isSmoothing()
Returns the smoothing setting.
static final long serialVersionUID
The serial version UID.
boolean isPointValid(@Nullable final Point pos)
Checks whether the given coordinate is within map bounds.
Base package of all Gridarta classes.
Abstract base class for classes implementing MapRenderer.
Reflects a game object (object on a map).
Interface for listeners listening to MapGridEvents.
boolean isGridVisible()
Get the visibility of the grid.
abstract void resizeBackBuffer(@NotNull Dimension size)
Resizes the backing buffer to the new grid size.
Paints overlays for map grids.
Implements Crossfire archetypes.
final MapGrid mapGrid
The MapGrid to render.
void addMapGridListener(@NotNull final MapGridListener listener)
Registers a MapGridListener.
void paintComponent(@NotNull final Graphics graphics, final boolean isSnapshot, final boolean checkClip)
Paints this component.
AbstractFlatMapRenderer(@NotNull final MapViewSettings mapViewSettings, @NotNull final MapModel< GameObject, MapArchObject, Archetype > mapModel, @NotNull final MapGrid mapGrid, final int borderSize, @NotNull final GridMapSquarePainter gridMapSquarePainter, @NotNull final GameObjectParser< GameObject, MapArchObject, Archetype > gameObjectParser)
Creates a new instance.
Interface for event listeners that are interested in changes on MapViewSettings.
void removeMapViewSettingsListener(@NotNull MapViewSettingsListener listener)
Unregister a MapViewSettingsListener.
Rectangle getSquareBounds(@NotNull final Point p)
Returns coordinates, length and width of map square.
Container for settings that affect the rendering of maps.
final MapModelListener< GameObject, MapArchObject, Archetype > mapModelListener
The MapModelListener to track changes in mapModel.
MapSquare< G, A, R > getMapSquare(@NotNull Point pos)
Get the square at a specified location.
BufferedImage getFullImage()
Returns an image of the entire map view.
GameObjects are the objects based on Archetypes found on maps.
final MapViewSettings mapViewSettings
The MapViewSettings instance to use.
int getWidth()
Returns the width of the area.
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.
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.
final Point borderOffset
The offset to map borders (32 for std.
final MapGridListener mapGridListener
The MapGridListener to track changes in mapGrid.
final GameObjectParser< G, A, R > gameObjectParser
The GameObjectParser for creating tooltip information or.
Base classes for rendering maps.
Main package of Gridarta4Crossfire, contains all classes specific to the Crossfire version of the Gri...
void removeMapModelListener(@NotNull MapModelListener< G, A, R > listener)
Unregister a map listener.
abstract void updateSquare(@NotNull Point point)
Callback function that is called when a square may have changed.
abstract void updateAll()
Callback function that is called when any square may have changed.
A getMapArchObject()
Returns the Map Arch Object with the meta information about the map.
abstract void updateSquares(@NotNull Rectangle rectangle)
Callback function that is called when multiple squares may have changed.
boolean isLightVisible()
Returns whether the setting for lighted map squares should be inverted.
int getBorderOffsetY()
Returns the y offset to map borders.
void init()
Finishes initialization of this instance.
An interface for classes that collect errors.
Size2D mapSize
The map size in squares.
int getHeight()
Returns the height of the area.
final GridMapSquarePainter gridMapSquarePainter
The GridMapSquarePainter to use.
void paintMapGrid(@NotNull final Graphics graphics)
Paints the grid of the whole map.
Rectangle getRecChange()
Returns a rectangle where the grid was changed.
The location of a map file with a map directory.
int SQUARE_WIDTH
The width of a square in pixels.
final Rectangle tmpRec
Temporary rectangle.
The class Size2D represents a 2d rectangular area.
This event is created by MapGrid.
final Point tmpPoint
Temporary point.