cgraphicsutil.java
来自「This is a resource based on j2me embedde」· Java 代码 · 共 395 行 · 第 1/2 页
JAVA
395 行
return; } int iW = image[1].getWidth(); g.drawImage(image[0], x, y, Graphics.LEFT | Graphics.TOP); w -= image[2].getWidth(); for (int i = image[0].getWidth() + x; i < w; i += iW) { g.drawImage(image[1], i, y, Graphics.LEFT | Graphics.TOP); } w += image[2].getWidth(); g.drawImage(image[2], w, y, Graphics.RIGHT | Graphics.TOP); } /** * Draws a border of <code>borderWidth</code> at location * <code>x, y</code> with dimensions <code>width, height</code>. * The border is drawn with one color. * 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 borderWidth The width of the border line. * @param borderColor The color for the border line. */ public static void draw1ColorBorder(Graphics g, int x, int y, int w, int h, int borderWidth, int borderColor) { g.setColor(borderColor); w--; h--; if (borderWidth == 1) { g.drawRect(x, y, w, h); return; } g.translate(x, y); for (int i = 0; i < borderWidth; i++, w -= 2, h -= 2) { g.drawRect(i, i, w, h); } g.translate(-x, -y); } /** * Draws a border of <code>borderWidth</code> at location * <code>x, y</code> with dimensions <code>width, height</code>. * The border is drawn out of two colors. * 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 hasFocus The flag indicating the item has input focus. * @param darkBorder The color of the dark border. * @param lightBorder The color of the light border. * @param borderWidth The wodth of the border line. */ public static void draw2ColorBorder(Graphics g, int x, int y, int w, int h, boolean hasFocus, int darkBorder, int lightBorder, int borderWidth) { g.setColor(hasFocus ? darkBorder : lightBorder); g.fillRect(x, y, w, borderWidth); g.fillRect(x, y, borderWidth, h); g.setColor(hasFocus ? lightBorder : darkBorder); g.fillTriangle(x, y + h, x + borderWidth, y + h - borderWidth, x + borderWidth, y + h); g.fillRect(x + borderWidth, y + h - borderWidth, w - borderWidth, borderWidth); g.fillTriangle(x + w, y, x + w - borderWidth, y + borderWidth, x + w, y + borderWidth); g.fillRect(x + w - borderWidth, y + borderWidth, borderWidth, h - borderWidth); } /** * Paints the background according to image or color * requested. * @param g The graphics context to be used for rendering button. * @param bgImage The background image to render or null. * @param tileBG Flag to indicate the background image should be * tiled. * @param bgColor The background color to paint if bgImage is null. * @param width The width of the background. * @param height The height of the background. */ public static void paintBackground(Graphics g, Image bgImage, boolean tileBG, int bgColor, int width, int height) { // return if a null graphics context if (g == null) { return; } // We first try for a background image if (bgImage != null) { if (!tileBG) { // Note: this way draws the entire background image and lets // the Graphics object clip what it doesn't need. We use this // method as the drawRegion routine has more overhead and // should be slower. g.drawImage(bgImage, 0, 0, Graphics.TOP | Graphics.LEFT); } else { // We'll re-use our bg* variables while we're in tile mode int bgX = bgImage.getWidth(); int bgY = bgImage.getHeight(); // Reduce the size of the two loops such that the tiling // only covers the clip region int clipX = g.getClipX(); int clipY = g.getClipY(); int leftX = (clipX / bgX) * bgX; int leftY = (clipY / bgY) * bgY; int rightX = clipX + g.getClipWidth(); int rightY = clipY + g.getClipHeight(); for (int i = leftY; i < rightY; i += bgY) { for (int j = leftX; j < rightX; j += bgX) { g.drawImage(bgImage, j, i, Graphics.TOP | Graphics.LEFT); } } } return; } // If the background image is null, we use a fill color. if (bgColor >= 0) { int color = g.getColor(); g.setColor(bgColor); // Optimization: Just fill the clip region g.fillRect(g.getClipX(), g.getClipY(), g.getClipWidth(), g.getClipHeight());/* if (borderWidth > 0 && borderColor >= 0) { // IMPL_NOTE : there is a possible optimization whereby the clip is // entirely inside the border and the border does not need to // be painted at all. CGraphicsUtil.draw1ColorBorder(g, 0, 0, bounds[W], bounds[H], borderWidth, borderColor); }*/ // We reset to the cached color stored in paint() g.setColor(color); } } /** * Draws a drop shadow box with a border of border of * <code>borderColor</code>, a drop shadow of * <code>shadowColor</code>, and a filled area of <code>color</code> * at location <code>x, y</code> with dimensions * <code>width, height</code>. * 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 borderColor The border color. * @param shadowColor The shadow color. * @param color The drawing color. */ public static void drawDropShadowBox(Graphics g, int x, int y, int w, int h, int borderColor, int shadowColor, int color) { g.setColor(color); w--; h--; g.fillRect(x, y, w, h); g.setColor(shadowColor); g.drawRect(x + 1, y + 1, w - 1, h - 1); g.setColor(borderColor); g.drawRect(x, y, w, h); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?