stretchbitmapsprite.java

来自「Sony Ericsson手机上的Facebook客户端全套代码」· Java 代码 · 共 129 行

JAVA
129
字号
// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   StretchBitmapSprite.java

package se.southend.drops.gui;

import java.io.PrintStream;
import java.util.Vector;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

// Referenced classes of package se.southend.drops.gui:
//            BitmapSprite, StretchTemplate

public class StretchBitmapSprite extends BitmapSprite
{

    public StretchBitmapSprite()
    {
        changed = true;
    }

    public StretchBitmapSprite(Image image, StretchTemplate stretch)
    {
        super(image);
        setImage(image);
        setStretchTemplate(stretch);
    }

    public void setImage(Image image)
    {
        super.setImage(image);
        changed = true;
    }

    public void setStretchTemplate(StretchTemplate stretch)
    {
        stretchTemplate = stretch;
        changed = true;
    }

    public void setWidth(int width)
    {
        this.width = width;
        changed = true;
    }

    public void setHeight(int height)
    {
        this.height = height;
        changed = true;
    }

    public void setSize(int width, int height)
    {
        setWidth(width);
        setHeight(height);
    }

    public int getWidth()
    {
        return width;
    }

    public int getHeight()
    {
        return height;
    }

    protected void paintFrame(Graphics graphics, Image frame, int xScr, int yScr)
    {
        if(changed)
        {
            if(frame.getWidth() != stretchTemplate.getSourceWidth() || frame.getHeight() != stretchTemplate.getSourceHeight())
            {
                System.out.println("StretchBitmapSprite.paintFrame: Sum of row/column widths in stretch template does not match the source image.\n");
                return;
            }
            if(!stretchTemplate.isSizePossible(width, height))
            {
                System.out.println("StretchBitmapSprite.paintFrame: Image cannot be stretched to wanted size.\n");
                return;
            }
            colWidth = stretchTemplate.getWidths(width);
            rowHeight = stretchTemplate.getHeights(height);
            changed = false;
        }
        int sourceY = 0;
        int destY = yScr;
        for(int row = 0; row < rowHeight.size(); row++)
        {
            int sourceRowHeight = stretchTemplate.getSourceRowHeight(row);
            for(int yPixelsLeft = ((Integer)rowHeight.elementAt(row)).intValue(); yPixelsLeft > 0;)
            {
                int sourceX = 0;
                int destX = xScr;
                int partYPixels = yPixelsLeft <= sourceRowHeight ? yPixelsLeft : sourceRowHeight;
                for(int col = 0; col < colWidth.size(); col++)
                {
                    int sourceColWidth = stretchTemplate.getSourceColumnWidth(col);
                    for(int xPixelsLeft = ((Integer)colWidth.elementAt(col)).intValue(); xPixelsLeft > 0;)
                    {
                        int partXPixels = xPixelsLeft <= sourceColWidth ? xPixelsLeft : sourceColWidth;
                        graphics.drawRegion(frame, sourceX, sourceY, partXPixels, partYPixels, 0, destX, destY, 20);
                        xPixelsLeft -= partXPixels;
                        destX += partXPixels;
                    }

                    sourceX += sourceColWidth;
                }

                yPixelsLeft -= partYPixels;
                destY += partYPixels;
            }

            sourceY += sourceRowHeight;
        }

    }

    private StretchTemplate stretchTemplate;
    private int width;
    private int height;
    private boolean changed;
    Vector colWidth;
    Vector rowHeight;
}

⌨️ 快捷键说明

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