add a .xpm file as background / first TEST /

- add a special cat image in background
- now ready for a pixel art phase ...
- very quick&dirty implementation of xpm parser...

- xpm generated with gimp using posterize. Thanks gimp !
This commit is contained in:
philippe lhardy
2020-12-13 22:44:09 +01:00
parent 56585712c8
commit 338dc3dd6b
4 changed files with 1218 additions and 4 deletions

View File

@@ -11,6 +11,7 @@ import org.artisanlogiciel.graphics.SvgWriter;
import org.artisanlogiciel.osm.OsmReader;
import org.artisanlogiciel.osm.convert.OsmToDrawing;
import org.artisanlogiciel.util.UTF8Control;
import org.artisanlogiciel.xpm.Xpm;
import javax.imageio.ImageIO;
import javax.swing.*;
@@ -87,6 +88,16 @@ implements StatusListener
private MazeComponent createMazeComponent(LabyModel model, int W, int H) {
MazeCellParameters cp = new MazeCellParameters(model.getWidth(), model.getHeight(), W, H, 3, 3);
MazeComponent comp = new MazeComponent(model, cp, this);
Xpm xpm = new Xpm();
// HARDCODED FOR FIRST TEST FIXME !!!
try {
xpm.parse(new FileInputStream("lab/titou20.xpm"));
comp.setXpm(xpm);
}
catch(Exception e)
{
System.err.println("Hardcoded background to fix");
}
return comp;
}

View File

@@ -5,6 +5,7 @@ import org.artisanlogiciel.games.maze.solve.DirectionPosition;
import org.artisanlogiciel.games.maze.solve.MazeResolutionListener;
import org.artisanlogiciel.graphics.Drawing;
import org.artisanlogiciel.graphics.DrawingLine;
import org.artisanlogiciel.xpm.Xpm;
import javax.swing.*;
import java.awt.*;
@@ -36,6 +37,9 @@ public class MazeComponent
int gX = -1;
int gY = -1;
// use a background
Xpm xpm = null;
Date lastDrag = null;
// FIXME HARCDODED delay after which a draging to draw a continous line is ended, a new line will then start.
long dragTimeout = 200;
@@ -63,6 +67,11 @@ public class MazeComponent
this.goal = goal;
}
}
public void setXpm(Xpm xpm)
{
this.xpm = xpm;
}
// for a given (x,y) pixel return cell position.
// if rightmost position of view not (0,0) this is not working.
Position getPosition(int x, int y) {
@@ -319,18 +328,22 @@ public class MazeComponent
int aX = pX;
int aY = pY;
// draw background
for (; pY < mY; pY++) {
for (pX = 0; pX < mX; pX++) {
walls = map.getWalls(pX, pY);
g.setColor(colorMap.background);
if ( xpm != null ) {
int cX = ( pX < xpm.getWidth()) ? pX : xpm.getWidth() - 1;
int cY = ( pY < xpm.getHeight()) ? pY : xpm.getHeight() - 1;
g.setColor(xpm.getColor(cX,cY));
}
else {
g.setColor(colorMap.background);
}
cp.drawBackground(g, pX, pY, walls);
}
}
pX = aX;
pY = aY;
// draw all walls within clip bounds horiz first then lines