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

📄 moviebuilder.java

📁 java版本的flash文件(swf)播放器
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    protected class ButtonActionBuilder extends MovieBuilder.ActionsBuilder 
    {
        protected Button but;
        
        protected ButtonActionBuilder( Button b, int flashVersion )
        {
            super( flashVersion );
            but = b;
        }
        
        public void start( int conditions )
        {
            //--DefineButton has implicit conditions..
            if( conditions == 0 ) conditions = SWFConstants.BUTTON2_OVERDOWN2OVERUP;
            
            acts = but.addActions( conditions, version );
        }        
    }
    
    protected class ClipActionBuilder extends MovieBuilder.ActionsBuilder
    {
        protected Symbol symbol;
        protected Transform matrix;
        protected AlphaTransform cxform;
        protected String name;
        protected int depth;
        protected boolean isMove;

        protected ClipActionBuilder( Symbol symbol, Matrix matrix, 
                                     AlphaTransform cxform, int depth,
                                     String name, int version, boolean isMove )
        {
            super( version );
            this.symbol = symbol;
            this.matrix = (matrix != null) ? new Transform(matrix) : null;
            this.cxform = cxform;
            this.name   = name;            
            this.depth  = depth;
            this.isMove = isMove;
        }
        
        /**
         * All actions are done - place the instance
         */
        public void done() throws IOException
        {
            Frame frame = currentFrame();
            
            Instance inst = null;
            
            if( isMove )
            {
                frame.replaceMovieClip( symbol, depth, matrix, cxform, name, getActions() );
            }
            else
            {
                timeline.setAvailableDepth( depth );
            
                frame.placeMovieClip( symbol, matrix, cxform, name, getActions() );
            }
            
            saveInstance( depth, inst );
        }                
    }

    /**
     * SWFShape implementation that builds a Shape
     */
    protected class ShapeBuilder implements SWFShape 
    {
        protected Shape s;
        protected int currx, curry;
        
        protected ShapeBuilder( Shape s )
        {
            this.s = s;
        }

        public void done()
        {
            //nothing
        }
    
        public void line( int dx, int dy )
        {
            currx += dx;
            curry += dy;
            
            s.line( ((double)currx) / SWFConstants.TWIPS,
                    ((double)curry) / SWFConstants.TWIPS );
        }
    
        public void curve( int cx, int cy, int dx, int dy )
        {
            cx += currx;
            cy += curry;
            
            currx = cx + dx;
            curry = cy + dy;
            
            s.curve( ((double)currx) / SWFConstants.TWIPS,
                     ((double)curry) / SWFConstants.TWIPS,
                     ((double)cx   ) / SWFConstants.TWIPS,
                     ((double)cy   ) / SWFConstants.TWIPS );
        }
    
        public void move( int x, int y )
        {
            currx = x;
            curry = y;
            
            s.move( ((double)currx) / SWFConstants.TWIPS,
                    ((double)curry) / SWFConstants.TWIPS );
        }
        
        public void setFillStyle0( int styleIndex )
        {
            s.setLeftFillStyle( styleIndex );
        }
    
        public void setFillStyle1( int styleIndex )
        {
            s.setRightFillStyle( styleIndex );
        }
    
        public void setLineStyle( int styleIndex )
        {
            s.setLineStyle( styleIndex );
        }

        public void defineFillStyle( Color color )
        {
            s.defineFillStyle( color );
        }

        public void defineFillStyle( Matrix matrix, int[] ratios,
                                     Color[] colors, boolean radial )
        {
            s.defineFillStyle( colors, ratios, new Transform(matrix), radial );
        }

        public void defineFillStyle( int bitmapId, Matrix matrix, boolean clipped )
        {
            Symbol image = getSymbol( bitmapId );           
            s.defineFillStyle( image, new Transform(matrix), clipped );
        }
    
        public void defineLineStyle( int width, Color color )
        {
            s.defineLineStyle( ((double)width)/SWFConstants.TWIPS, color );
        }
    }
    
    protected class MorphShapeBuilder extends MovieBuilder.ShapeBuilder 
    {
        protected int id;
        protected Rect startBounds;
        protected Rect endBounds;
        protected Shape shape1;
        
        protected MorphShapeBuilder( int id, Rect startBounds, Rect endBounds )
        {
            super( new Shape() );
            this.id          = id;
            this.startBounds = startBounds;
            this.endBounds   = endBounds;
        }
                
        public void done()
        {
            if( shape1 == null )
            {
                shape1 = s;
                s = new Shape();
                return;
            }
            
            Shape shape2 = s;
            
            MorphShape morph = new MorphShape( shape1, shape2 );
            saveSymbol( id, morph );
        }        
    }
    
    protected class GlyphBuilder extends MovieBuilder.ShapeBuilder 
    {
        protected FontDefinition fontDef;
        protected Font   font;
        protected int    count;
        protected int[]  advances;
        protected int[]  codes;
        protected Rect[] bounds;
        protected List defGlyphs;
        protected List fontGlyphs;
        protected int index = 0;
        
        public GlyphBuilder( FontDefinition fontDef, Font font, int glyphCount )
        {
            super( new Shape() );

            this.fontDef = fontDef;
            this.font    = font;
            this.count   = glyphCount;
            
            defGlyphs  = fontDef.getGlyphList();
            fontGlyphs = font.getGlyphList();
        }

        public GlyphBuilder( FontDefinition fontDef, Font font, int[] codes,
                             int[] advances, Rect[] bounds )
        {
            this( fontDef, font, codes.length );
            this.codes    = codes;
            this.advances = advances;
            this.bounds   = bounds;
        }
        
        public void done()
        {
            if( index >= count ) return;
            
            if( bounds != null )
            {
                Rect r = bounds[index];
                s.setBoundingRectangle( ((double)r.getMinX())/SWFConstants.TWIPS, 
                                        ((double)r.getMinY())/SWFConstants.TWIPS,
                                        ((double)r.getMaxX())/SWFConstants.TWIPS,
                                        ((double)r.getMaxY())/SWFConstants.TWIPS );
            }
            
            double advance = (advances != null) ?
                                 (((double)advances[index])/SWFConstants.TWIPS ) :
                                 0.0;
            
            int code = (codes != null) ? codes[index] : 0;
            
            FontDefinition.Glyph g = new FontDefinition.Glyph( s, advance, code ); 
            
            defGlyphs .add( g );
            font.addGlyph( g );
            
            index++;
            
            if( index < count ) s = new Shape();
        }        
    }
    
    /**
     * A SWFText implementation that builds a Text object
     */
    protected class TextBuilder implements SWFText 
    {
        protected Text t;
        protected Font font;
        protected double size;
        protected Color color;
        protected double x;
        protected double y;
        protected boolean hasX;
        protected boolean hasY;
        
        protected TextBuilder( Text text )
        {
            t = text;
        }

        /**
         * SWFText interface
         */
        public void font( int fontId, int textHeight )
        {
            Symbol f = getSymbol( fontId );
            if( f == null || !(f instanceof Font)) return;
            
            font = (Font)f;
            size = ((double)textHeight)/SWFConstants.TWIPS;
        }
    
        /**
         * SWFText interface
         */
        public void color( Color color )
        {
            this.color = color;
        }
    
        /**
         * SWFText interface
         */
        public void setX( int x )
        {
            hasX = true;
            this.x = ((double)x)/SWFConstants.TWIPS;
        }

        /**
         * SWFText interface
         */
        public void setY( int y )
        {
            hasY = true;
            this.y = ((double)y)/SWFConstants.TWIPS;
        }
    
        /**
         * SWFText interface
         */
        public void text( int[] glyphIndices, int[] glyphAdvances )
        {
            List glyphs = font.getGlyphList();
            char[] chars = new char[ glyphIndices.length ];
            
            for( int i = 0; i < glyphIndices.length; i++ )
            {
                int index = glyphIndices[i];
                double advance = ((double)glyphAdvances[i])/SWFConstants.TWIPS;
                
                //normalize the advance
                advance = advance * (1024.0/SWFConstants.TWIPS)/size;
                
                FontDefinition.Glyph g = (FontDefinition.Glyph)glyphs.get(index);
                
                chars[i] = (char)g.getCode();
                                                
                //--retrofit the glyph advance - this will tend to cancel out
                // any kerning (unfortunately)
                if( advance > g.getAdvance() ) g.setAdvance( advance );
            }
            
            try
            {
                Font.Chars cc = font.chars( new String(chars), size );
            
                t.row( cc, color, x, y, hasX, hasY );
            }
            catch( Font.NoGlyphException nge ) {}
            
            color = null;
            hasX = false;
            hasY = false;
        }
    
        /**
         * SWFText interface
         */
        public void done()
        {
            //nothing
        }
    }
    
    
}

⌨️ 快捷键说明

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