⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shape.java

📁 java版本的flash文件(swf)播放器
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        if( color == null ) color = new Color(255,255,255);
        ColorFill fill = new ColorFill( color );
        
        if( color instanceof AlphaColor ) hasAlpha = true;
        
        elements.add( fill );
    }
    
    /**
     * Define an image fill
     */
    public void defineFillStyle( Symbol image, Transform matrix, boolean clipped )
    {
        ImageFill fill = new ImageFill(image,matrix,clipped);
        
        elements.add( fill );
    }
    
    /**
     * Define a gradient fill
     */
    public void defineFillStyle( Color[] colors, int[] ratios, 
                                 Transform matrix, boolean radial )
    {
        GradientFill fill = new GradientFill( colors, ratios, matrix, radial );

        elements.add( fill );
        
        for( int i = 0; i < colors.length; i++ )
        {
            if( colors[i] == null ) continue;
            if( colors[i] instanceof AlphaColor ) hasAlpha = true;
        }        
    }
    
    /**
     * Set the left fill style
     */
    public void setLeftFillStyle( int index )
    {
        SetLeftFillStyle fill = new SetLeftFillStyle( index );
        
        elements.add( fill );
    }

    /**
     * Set the right fill style
     */
    public void setRightFillStyle( int index )
    {
        SetRightFillStyle fill = new SetRightFillStyle( index );
        
        elements.add( fill );
    }

    /**
     * Set the line style
     */
    public void setLineStyle( int index )
    {
        SetLineStyle style = new SetLineStyle( index );
        
        elements.add( style );
    }
    
    /**
     * Move the pen without drawing any line
     */
    public void move( double x, double y )
    {
        Move move = new Move( x, y );
    
        if( x < minX ) minX = x;
        if( y < minY ) minY = y;
        if( x > maxX ) maxX = x;
        if( y > maxY ) maxY = y;
        
        elements.add( move );
    }
    
    /**
     * Draw a line in the current line style (if any)
     */
    public void line( double x, double y )
    {
        Line line = new Line( x, y );
    
        if( x < minX ) minX = x;
        if( y < minY ) minY = y;
        if( x > maxX ) maxX = x;
        if( y > maxY ) maxY = y;
        
        elements.add( line );
    }

    /**
     * Draw a curve in the current line style (if any)
     */
    public void curve( double x, double y, double controlX, double controlY )
    {
        Curve curve = new Curve( x, y, controlX, controlY );
        
        if( x < minX ) minX = x;
        if( y < minY ) minY = y;
        if( x > maxX ) maxX = x;
        if( y > maxY ) maxY = y;
        
        if( controlX < minX ) minX = controlX;
        if( controlY < minY ) minY = controlY;
        if( controlX > maxX ) maxX = controlX;
        if( controlY > maxY ) maxY = controlY;
        
        elements.add( curve );
    }
    
    protected int defineSymbol( Movie movie, 
                                SWFTagTypes timelineWriter,
                                SWFTagTypes definitionWriter )
        throws IOException
    {
        currx = 0.0;
        curry = 0.0;

        predefineImageFills( movie, timelineWriter, definitionWriter );
        
        int id = getNextId(movie);
        
        Rect outline = getRect();
        
        SWFShape shape = hasAlpha ? 
                             definitionWriter.tagDefineShape3( id, outline ) :
                             definitionWriter.tagDefineShape2( id, outline );

        writeShape( shape );
        
        return id;
    }

    protected Rect getRect()
    {
        double adjust = maxLineWidth/2.0;
        
        Rect outline = new Rect( (int)(minX*SWFConstants.TWIPS - adjust*SWFConstants.TWIPS),
                                 (int)(minY*SWFConstants.TWIPS - adjust*SWFConstants.TWIPS),
                                 (int)(maxX*SWFConstants.TWIPS + adjust*SWFConstants.TWIPS),
                                 (int)(maxY*SWFConstants.TWIPS + adjust*SWFConstants.TWIPS));
        
        return outline;
    }
    
    protected void predefineImageFills( Movie movie, 
                                        SWFTagTypes timelineWriter,
                                        SWFTagTypes definitionWriter )
        throws IOException 
    {
        //--Make sure any image fills are defined prior to the shape
        for( Iterator it = elements.iterator(); it.hasNext(); )
        {
            Object el = it.next();
            
            if( el instanceof Shape.ImageFill )
            {        
                Symbol image = ((Shape.ImageFill)el).getImage();
                
                if( image != null ) image.define( movie,
                                                  timelineWriter, 
                                                  definitionWriter );
            }
        }        
    }
    
    protected void writeShape( SWFShape shape ) throws IOException
    {
        for( Iterator it = elements.iterator(); it.hasNext(); )
        {
            Object el = it.next();
            
            if( el instanceof Shape.ColorFill )
            {
                Shape.ColorFill fill = (Shape.ColorFill)el;
                shape.defineFillStyle( fill.getColor() );
            }
            else if( el instanceof Shape.ImageFill )
            {
                Shape.ImageFill fill = (Shape.ImageFill)el;

                Symbol image = fill.getImage();
                int imgId = (image != null) ? image.getId() : 65535;
                
                shape.defineFillStyle( imgId, fill.getTransform(), fill.isClipped() );
            }
            else if( el instanceof Shape.GradientFill )
            {
                Shape.GradientFill fill = (Shape.GradientFill)el;

                shape.defineFillStyle( fill.getTransform(), 
                                       fill.getRatios(),
                                       fill.getColors(),
                                       fill.isRadial() );
            }
            else if( el instanceof Shape.LineStyle )
            {
                Shape.LineStyle style = (Shape.LineStyle)el;
                
                shape.defineLineStyle( (int)(style.getWidth() * SWFConstants.TWIPS),
                                       style.getColor() );
            }
            else if( el instanceof Shape.SetLeftFillStyle )
            {
                Shape.SetLeftFillStyle style = (Shape.SetLeftFillStyle)el;
                shape.setFillStyle0( style.getStyleIndex() );
            }            
            else if( el instanceof Shape.SetRightFillStyle )
            {
                Shape.SetRightFillStyle style = (Shape.SetRightFillStyle)el;
                shape.setFillStyle1( style.getStyleIndex() );
            }            
            else if( el instanceof Shape.SetLineStyle )
            {
                Shape.SetLineStyle style = (Shape.SetLineStyle)el;
                shape.setLineStyle( style.getStyleIndex() );
            }            
            else writeVector( shape, el );        
        }
        
        shape.done();
    }
    
    protected void writeVector( SWFVectors vecs, Object el ) throws IOException
    {
        if( el instanceof Shape.Move )
        {
            Shape.Move move = (Shape.Move)el;

            currx = move.getX()*SWFConstants.TWIPS;
            curry = move.getY()*SWFConstants.TWIPS;

            int x = (int)currx;
            int y = (int)curry;

            vecs.move( x, y );
                
            //System.out.println( "M: " + x + " " + y );
        }            
        else if( el instanceof Shape.Line )
        {
            Shape.Line line = (Shape.Line)el;

            double xx = line.getX()*SWFConstants.TWIPS;
            double yy = line.getY()*SWFConstants.TWIPS;
                
            int dx = (int)(xx - currx);
            int dy = (int)(yy - curry);
                
            vecs.line( dx, dy );
                
            //System.out.println( "currx=" + currx + " curry=" + curry + " xx=" + xx + " yy=" + yy + " (xx - currx)=" + (xx - currx) + "  (yy - curry)=" + (yy - curry) );
            //System.out.println( "L: " + dx + " " + dy );

            currx = xx;
            curry = yy;                
        }            
        else if( el instanceof Shape.Curve )
        {
            Shape.Curve curve = (Shape.Curve)el;

            double xx  = curve.getX()       *SWFConstants.TWIPS;
            double yy  = curve.getY()       *SWFConstants.TWIPS;
            double cxx = curve.getControlX()*SWFConstants.TWIPS;
            double cyy = curve.getControlY()*SWFConstants.TWIPS;
                
            int dx = (int)(xx - cxx);
            int dy = (int)(yy - cyy);
            int cx = (int)(cxx - currx);
            int cy = (int)(cyy - curry);       
                
            vecs.curve( cx, cy, dx, dy );
                
            currx = xx;
            curry = yy;                

            //System.out.println( "C: " + cx + " " + cy + " " + dx + " " + dy );
        }            
     }
    
    protected void writeGlyph( SWFVectors vecs ) throws IOException
    {
        currx = 0.0;
        curry = 0.0;
        
        for( Iterator it = elements.iterator(); it.hasNext(); )
        {
            writeVector( vecs, it.next() );    
        }        
        
        vecs.done();        
   }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -