1 // 2 // Description: 3 // SWFShape Class 4 // 5 // Authors: 6 // Jonathan Shore <jshore@e-shuppan.com> 7 // Based on php wrapper developed by <dave@opaque.net> 8 // 9 // Copyright: 10 // Copyright 2001 E-Publishing Group Inc. Permission is granted to use or 11 // modify this code provided that the original copyright notice is included. 12 // 13 // This software is distributed with no warranty of liability, merchantability, 14 // or fitness for a specific purpose. 15 // 16 17 18 19 20 21 22 // 23 // SWFShape Class 24 // general polygon / poly-curve region 25 // 26 // Notes 27 // - building block for flash objects 28 // 29 public class SWFShape extends SWFObject implements SWFShapeI { 30 31 public final static float PI = 3.1415926f; 32 33 // public methods 34 SWFShape(int handle)35 public SWFShape (int handle) 36 throws SWFException 37 { 38 super (handle); 39 this.lwidth = 1; 40 this.color = SWFColor.identity(); 41 } 42 SWFShape()43 public SWFShape () 44 throws SWFException 45 { 46 setHandle (nNew()); 47 this.lwidth = 1; 48 this.color = SWFColor.identity(); 49 } 50 getPenX()51 public float getPenX() 52 { 53 return nGetPenX(handle); 54 } 55 getPenY()56 public float getPenY() 57 { 58 return nGetPenY(handle); 59 } 60 movePen(float x, float y)61 public void movePen (float x, float y) 62 { nMovePen (handle, x, y); } movePenTo(float x, float y)63 public void movePenTo (float x, float y) 64 { nMovePenTo (handle, x, y); } 65 66 drawLine(float x, float y)67 public void drawLine (float x, float y) 68 { nDrawLine (handle, x, y); } drawLineTo(float x, float y)69 public void drawLineTo (float x, float y) 70 { nDrawLineTo (handle, x, y); } drawLineToRelative(float dx, float dy)71 public void drawLineToRelative (float dx, float dy) 72 { nDrawLineToRelative (handle, dx, dy); } 73 74 drawCurve(float bx, float by, float cx, float cy)75 public void drawCurve (float bx, float by, float cx, float cy) 76 { nDrawCurve (handle, bx, by, cx, cy); } drawCurveTo(float bx, float by, float cx, float cy)77 public void drawCurveTo (float bx, float by, float cx, float cy) 78 { nDrawCurveTo (handle, bx, by, cx, cy); } 79 drawCurve(float bx, float by, float cx, float cy, float dx, float dy)80 public void drawCurve (float bx, float by, float cx, float cy, float dx, float dy) 81 { nDrawCubic (handle, bx, by, cx, cy, dx, dy); } drawCurveTo(float bx, float by, float cx, float cy, float dx, float dy)82 public void drawCurveTo (float bx, float by, float cx, float cy, float dx, float dy) 83 { nDrawCubicTo (handle, bx, by, cx, cy, dx, dy); } 84 85 drawArc(float r, float startAngle, float endAngle)86 public void drawArc (float r, float startAngle, float endAngle) 87 { iDrawArc (handle, r, startAngle, endAngle); } drawCircle(float r)88 public void drawCircle (float r) 89 { iDrawCircle (handle, r); } 90 drawGlyph(SWFFontI font, int c)91 public void drawGlyph (SWFFontI font, int c) 92 throws SWFException 93 { 94 font.eval(); 95 nDrawGlyph (handle, font.getHandle(), c); 96 preserve (font); 97 } 98 99 end()100 public void end () 101 { nEnd (handle); } 102 103 104 // color & line thickness 105 setLine(short width, int r, int g, int b, int alpha)106 public void setLine (short width, int r, int g, int b, int alpha) 107 { 108 lwidth = width; 109 color = new SWFColor(r,g,b, alpha); 110 nSetLine (handle, width, r,g,b,alpha); 111 } 112 setLine(short width, SWFColor color)113 public void setLine (short width, SWFColor color) 114 { 115 lwidth = width; 116 this.color = color; 117 nSetLine (handle, width, color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()); 118 } 119 setLine(short width)120 public void setLine (short width) 121 { 122 lwidth = width; 123 setLine (width, color); 124 } 125 setColor(SWFColor color)126 public void setColor (SWFColor color) 127 { 128 this.color = color; 129 setLine (lwidth, color); 130 } 131 132 133 // fills 134 addBitmapFill(SWFBitmapI bitmap, int flags)135 public SWFFillI addBitmapFill (SWFBitmapI bitmap, int flags) 136 throws SWFException 137 { 138 bitmap.eval(); 139 preserve (bitmap); 140 return new SWFFill (nAddBitmapFill (handle, bitmap.getHandle(), (short)flags)); 141 } 142 addGradientFill(SWFGradientI gradient, int flags)143 public SWFFillI addGradientFill (SWFGradientI gradient, int flags) 144 throws SWFException 145 { 146 gradient.eval(); 147 preserve (gradient); 148 return new SWFFill (nAddGradientFill (handle, gradient.getHandle(), (short)flags)); 149 } 150 addSolidFill(int r, int g, int b, int alpha)151 public SWFFillI addSolidFill (int r, int g, int b, int alpha) 152 throws SWFException 153 { return new SWFFill (nAddSolidFill (handle, r,g,b, alpha)); } addSolidFill(SWFColor color)154 public SWFFillI addSolidFill (SWFColor color) 155 throws SWFException 156 { return new SWFFill (nAddSolidFill (handle, color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha())); } 157 setLeftFill(SWFFillI fill)158 public void setLeftFill (SWFFillI fill) 159 throws SWFException 160 { 161 fill.eval(); 162 preserve (fill); 163 nSetLeftFill (handle, fill.getHandle()); 164 } 165 setRightFill(SWFFillI fill)166 public void setRightFill (SWFFillI fill) 167 throws SWFException 168 { 169 fill.eval(); 170 preserve (fill); 171 nSetRightFill (handle, fill.getHandle()); 172 } 173 174 finalize()175 protected void finalize() 176 throws Throwable 177 { 178 nDestroy (handle); 179 super.finalize(); 180 } 181 182 183 // internal stuff 184 185 iDrawCircle(int handle, float r)186 protected void iDrawCircle (int handle, float r) 187 { 188 final float a = r * (float)Math.tan (PI/8); 189 final float b = r * (float)Math.sin (PI/4); 190 191 movePen (r, 0); 192 drawCurve (0, -a, b-r, -b+a); 193 drawCurve (-b+a, b-r, -a, 0); 194 drawCurve (-a, 0, a-b, r-b); 195 drawCurve (b-r, b-a, 0, a); 196 drawCurve (0,a, r-b, b-a); 197 drawCurve (b-a,r-b,a,0); 198 drawCurve (a,0,b-a,b-r); 199 drawCurve (r-b,a-b,0,-a); 200 movePen (-r, 0); 201 } 202 203 iDrawArc(int handle, float r, float startAngle, float endAngle)204 protected void iDrawArc (int handle, float r, float startAngle, float endAngle) 205 { 206 nDrawArc (handle,r,startAngle,endAngle); 207 } 208 209 210 211 // native stuff 212 213 nNew()214 protected native int nNew (); nDestroy(int handle)215 protected native void nDestroy (int handle); 216 nMovePen(int handle, float x, float y)217 protected native void nMovePen (int handle, float x, float y); nMovePenTo(int handle, float x, float y)218 protected native void nMovePenTo (int handle, float x, float y); nGetPenX(int handle )219 protected native float nGetPenX(int handle ); nGetPenY(int handle )220 protected native float nGetPenY(int handle ); 221 nDrawLine(int handle, float x, float y)222 protected native void nDrawLine (int handle, float x, float y); nDrawLineTo(int handle, float x, float y)223 protected native void nDrawLineTo (int handle, float x, float y); nDrawLineToRelative(int handle, float dx, float dy)224 protected native void nDrawLineToRelative (int handle, float dx, float dy); 225 nDrawCurve(int handle, float bx, float by, float cx, float cy)226 protected native void nDrawCurve (int handle, float bx, float by, float cx, float cy); nDrawCurveTo(int handle, float bx, float by, float cx, float cy)227 protected native void nDrawCurveTo (int handle, float bx, float by, float cx, float cy); 228 nDrawCubic(int handle, float bx, float by, float cx, float cy, float dx, float dy)229 protected native void nDrawCubic (int handle, float bx, float by, float cx, float cy, float dx, float dy); nDrawCubicTo(int handle, float bx, float by, float cx, float cy, float dx, float dy)230 protected native void nDrawCubicTo (int handle, float bx, float by, float cx, float cy, float dx, float dy); 231 nDrawArc(int handle, float r, float startAngle, float endAngle)232 protected native void nDrawArc (int handle, float r, float startAngle, float endAngle); nDrawCircle(int handle, float r)233 protected native void nDrawCircle (int handle, float r); nDrawGlyph(int handle, int Hfont, int c)234 protected native void nDrawGlyph (int handle, int Hfont, int c); 235 nEnd(int handle)236 protected native void nEnd (int handle); 237 nSetLine(int handle, short width, int r, int g, int b, int alpha)238 protected native void nSetLine (int handle, short width, int r, int g, int b, int alpha); nAddBitmapFill(int handle, int Hbitmap, short flags)239 protected native int nAddBitmapFill (int handle, int Hbitmap, short flags); nAddGradientFill(int handle, int Hgradient, short flags)240 protected native int nAddGradientFill (int handle, int Hgradient, short flags); nAddSolidFill(int handle, int r, int g, int b, int alpha)241 protected native int nAddSolidFill (int handle, int r, int g, int b, int alpha); 242 nSetLeftFill(int handle, int Hfill)243 protected native void nSetLeftFill (int handle, int Hfill); nSetRightFill(int handle, int Hfill)244 protected native void nSetRightFill (int handle, int Hfill); 245 246 247 248 // variables 249 250 protected short lwidth; 251 protected SWFColor color; 252 }; 253 254 255 256 257 258