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 @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), };
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) {
175 if (!
mapModel.getMapArchObject().isPointValid(point)) {
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) {
233 final int w = backBuffer.getWidth();
234 final int h = backBuffer.getHeight();
235 g.drawImage(backBuffer, 0, 0, w, h, 0, 0, w, h,
null);
242 if (backBuffer !=
null && backBuffer.getWidth() == size.width && backBuffer.getHeight() == size.height) {
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);
275 if (square.isEmpty()) {
309 final Color color = g.getColor();
325 final ImageIcon img = node.getNormalImage();
352 if (backBuffer ==
null) {
353 if (
LOG.isDebugEnabled()) {
354 LOG.debug(
"lost back buffer");