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");