cgraphicsutil.java
来自「This is a resource based on j2me embedde」· Java 代码 · 共 395 行 · 第 1/2 页
JAVA
395 行
/* * * * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 only, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License version 2 for more details (a copy is * included at /legal/license.txt). * * You should have received a copy of the GNU General Public License * version 2 along with this work; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa * Clara, CA 95054 or visit www.sun.com if you need additional * information or have any questions. */package com.sun.midp.chameleon;import javax.microedition.lcdui.*;/** * Chameleon graphics utility class. This class is a collection of * commonly used graphics routines. These routines can be used by * layer implementations as well as widgets themselves. */public class CGraphicsUtil { /** * Fill width from <code>start</code> to <code>end</code> * with imgTop at <code>y1</code> coordinate and * with imgBottom at <code>y2</code>coordinate. * * @param g The Graphics context to paint to * @param imgTop The top image. * @param imgBottom The bottom image. * @param start start x co-ordinate of ImageItem * @param end end x co-ordinate of ImageItem * @param y1 y co-ordinate of Top ImageItem * @param y2 y co-ordinate of Bottom ImageItem */ public static void drawTop_BottomBorder(Graphics g, Image imgTop, Image imgBottom, int start, int end, int y1, int y2) { int imgWidth = imgTop.getWidth(); // The assumption is that imgTop and imgBottom will have // the same width // save the clip, before clipping the width; // we need to clip since the last imgTop and imgBottom images // might go over the area that needs to be filled int xClip = g.getClipX(); int clipWidth = g.getClipWidth(); g.clipRect(start, g.getClipY(), end - start, g.getClipHeight()); // IMPL_NOTE add clipping if last img piece is wider than we need for (int x = start; x < end; x += imgWidth) { // draw the top border g.drawImage(imgTop, x, y1, Graphics.TOP | Graphics.LEFT); // draw the bottom border g.drawImage(imgBottom, x, y2, Graphics.TOP | Graphics.LEFT); } g.setClip(xClip, g.getClipY(), clipWidth, g.getClipHeight()); } /** * Fill width from <code>start</code> to <code>end</code> * with imgTop at <code>y1</code> coordinate and * with imgBottom at <code>y2</code>coordinate. * * @param g The Graphics context to paint to * @param imgLeft The left image. * @param imgRight The right image. * @param start start y co-ordinate of ImageItem * @param end end y co-ordinate of ImageItem * @param x1 x co-ordinate of Left ImageItem * @param x2 x co-ordinate of Right ImageItem */ public static void drawLeft_RightBorder(Graphics g, Image imgLeft, Image imgRight, int start, int end, int x1, int x2) { // the assumption is that imgLeft and imgRight will have the // same height int imgHeight = imgLeft.getHeight(); // save the clip, before clipping the height; // we need to clip since the last imgLeft and imgRight images // might go over the area that needs to be filled int yClip = g.getClipY(); int clipHeight = g.getClipHeight(); g.clipRect(g.getClipX(), start, g.getClipWidth(), end - start); // IMPL_NOTE add clipping if last img piece is taller than we need for (int y = start; y < end; y += imgHeight) { // draw the left border g.drawImage(imgLeft, x1, y, Graphics.TOP | Graphics.LEFT); // draw the right border g.drawImage(imgRight, x2, y, Graphics.TOP | Graphics.LEFT); } g.setClip(g.getClipX(), yClip, g.getClipWidth(), clipHeight); } /** * Draws the button background of the size specified (x, y, w, h). * Different background can be drawn when the ImageItem has and * does not have focus. * IMPL_NOTE: update params * @param g The graphics context to be used for rendering button * @param x The x coordinate of the button's background top left corner * @param y The y coordinate of the button's background top left corner * @param w The width of the button's background * @param h The height of the button's background * @param image Array of background images to render. */ public static void draw9pcsBackground(Graphics g, int x, int y, int w, int h, Image[] image) { if (image == null || image.length != 9) { return; } // The assumption is that only middle image can be null the // rest are not null if this method is called g.translate(x, y); // NOTE : If topMiddle is 1 pixel wide, this is fine, but if it is // wider, the clip should be adjusted so that it does not overwrite // the topRight // Top Border int iW = image[1].getWidth(); g.drawImage(image[0], 0, 0, Graphics.LEFT | Graphics.TOP); w -= image[2].getWidth(); for (int i = image[0].getWidth(); i < w; i += iW) { g.drawImage(image[1], i, 0, Graphics.LEFT | Graphics.TOP); } w += image[2].getWidth(); g.drawImage(image[2], w, 0, Graphics.RIGHT | Graphics.TOP); // Tile middle rows if (image[4] != null) { iW = image[4].getWidth(); } int iH = image[3].getHeight(); h -= image[6].getHeight(); w -= image[5].getWidth(); for (int i = image[0].getHeight(); i <= h; i += iH) { g.drawImage(image[3], 0, i, Graphics.LEFT | Graphics.TOP); for (int j = image[3].getWidth(); j <= w; j += iW) { g.drawImage(image[4], j, i, Graphics.LEFT | Graphics.TOP); } g.drawImage(image[5], w + image[5].getWidth(), i, Graphics.RIGHT | Graphics.TOP); } w += image[5].getWidth(); h += image[6].getHeight(); // Bottom border iW = image[7].getWidth(); g.drawImage(image[6], 0, h, Graphics.LEFT | Graphics.BOTTOM); w -= image[8].getWidth(); for (int i = image[6].getWidth(); i < w; i += iW) { g.drawImage(image[7], i, h, Graphics.LEFT | Graphics.BOTTOM); } w += image[8].getWidth(); g.drawImage(image[8], w, h, Graphics.RIGHT | Graphics.BOTTOM); g.translate(-x, -y); } /** * Draws the button background of the size specified (x, y, w). * Different background can be drawn when the ImageItem has and * does not have focus. * IMPL_NOTE: update params * @param g The graphics context to be used for rendering button * @param x The x coordinate of the button's background top left corner * @param y The y coordinate of the button's background top left corner * @param w The width of the button's background * @param image Array of background images to render. */ public static void draw3pcsBackground(Graphics g, int x, int y, int w, Image[] image) { if (image == null || image.length != 3) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?