1 package org.catacomb.graph.gui;
2
3 import org.catacomb.be.Direction;
4 import org.catacomb.be.Placement;
5 import org.catacomb.be.Position;
6 import org.catacomb.datalish.*;
7 import org.catacomb.interlish.content.Polypoint;
8
9
10 public class SpriteMoviePainter implements MoviePaintInstructor {
11
12 SpriteAnimation movie;
13
14 int lastPainted;
15
16 int frameToPaint;
17
18
19 public SpriteMoviePainter() {
20
21 }
22
23 public SpriteMoviePainter(SpriteAnimation san) {
24 super();
25 setMovie(san);
26 }
27
28
29 public void setMovie(SpriteAnimation sa) {
30 movie = sa;
31 }
32
33
34 public void setFrame(int ifr) {
35 frameToPaint = ifr;
36 }
37
38 public void advanceToFrame(int ifr) {
39 frameToPaint = ifr;
40 if (frameToPaint > lastPainted) {
41 for (int i = lastPainted+1; i <= frameToPaint; i++) {
42 SceneConfig scene = movie.getSceneConfig(i);
43
44 SpriteEvents sevs = scene.getEvents();
45 if (sevs != null) {
46 sevs.perform();
47 }
48 }
49 }
50 }
51
52
53 public int getNFrames() {
54 int ret = 0;
55 if (movie != null) {
56 ret = movie.getNPoint();
57 }
58 return ret;
59 }
60
61 public boolean antialias() {
62 return false;
63 }
64
65 public void instruct(Painter p) {
66
67 if (movie != null) {
68 SceneConfig scene = movie.getSceneConfig(frameToPaint);
69 SpritePlacement[] spa = scene.getPlacements();;
70 SpriteStore spriteStore = movie.getSpriteStore();
71 for (SpritePlacement sp : spa) {
72 String sid = sp.getID();
73 Placement pmt = sp.getPlacement();
74 SpriteData sdat = spriteStore.getSprite(sid);
75
76 paintSprite(p, sdat, pmt);
77
78
79 }
80 lastPainted = frameToPaint;
81 }
82 }
83
84
85 private void paintSprite(Painter p, SpriteData sdat, Placement pmt) {
86 Position pos = pmt.getPosition();
87 Direction dir = pmt.getDirection();
88 for (SpritePart sp : sdat.getParts()) {
89 Polypoint pl = new Polypoint(sp.copyXpts(), sp.copyYpts());
90 pl.rotate(dir);
91 pl.translate(pos);
92
93
94 double[] xd = pl.getXPts();
95 double[] yd = pl.getYPts();
96
97 if (sp.open()) {
98 p.setColor(sp.getLineColor());
99 p.drawPolyline(xd, yd);
100
101 } else if (sp.closed()) {
102 p.setColor(sp.getLineColor());
103 p.drawPolygon(xd, yd);
104
105 } else {
106 p.setColor(sp.getFillColor());
107 p.fillPolygon(xd, yd);
108 p.setColor(sp.getLineColor());
109 p.drawPolygon(xd, yd);
110 }
111 }
112
113 for (SpriteMarker sm : sdat.getMarkers()) {
114 p.setColorWhite();
115 Position mpos = sm.getPosition().copy();
116 mpos.rotateTo(dir);
117 mpos.shift(pos);
118 p.fillCenteredOval(mpos, 2);
119 }
120 }
121
122
123 public Box getLimitBox() {
124 Box b = null;
125 if (movie != null) {
126 b = movie.getBox();
127 SpriteStore spriteStore = movie.getSpriteStore();
128 SceneConfig scene = movie.getSceneConfig(0);
129 if (scene != null) {
130 SpritePlacement[] spa = scene.getPlacements();
131 if (spa != null) {
132 for (SpritePlacement sp : spa) {
133 String sid = sp.getID();
134 SpriteData sdat = spriteStore.getSprite(sid);
135 sdat.pushBox(b);
136 }
137 }
138 }
139 }
140 return b;
141 }
142
143 public String getFrameDescription(int ifr) {
144 return movie.getFrameDescription(ifr);
145 }
146
147
148
149
150 }