📄 graphics.java
字号:
} /** * Sets the current color to the specified RGB values. All subsequent * rendering operations will use this specified color. * @param red the red component of the color being set in range * <code>0-255</code> * @param green the green component of the color being set in range * <code>0-255</code> * @param blue the blue component of the color being set in range * <code>0-255</code> * @throws IllegalArgumentException if any of the color components * are outside of range <code>0-255</code> * @see #getColor */ public synchronized void setColor(int red, int green, int blue) { if ((red < 0) || (red > 255) || (green < 0) || (green > 255) || (blue < 0) || (blue > 255)) { throw new IllegalArgumentException("Value out of range"); } rgbColor = (red << 16) | (green << 8) | blue; gray = grayVal(red, green, blue); pixel = getPixel(rgbColor, gray, false); } /** * Sets the current color to the specified RGB values. All subsequent * rendering operations will use this specified color. The RGB value * passed in is interpreted with the least significant eight bits * giving the blue component, the next eight more significant bits * giving the green component, and the next eight more significant * bits giving the red component. That is to say, the color component * is specified in the form of <code>0x00RRGGBB</code>. The high * order byte of * this value is ignored. * * @param RGB the color being set * @see #getColor */ public synchronized void setColor(int RGB) { if (pixel == -1 || (RGB & 0x00ffffff) != rgbColor) { int red = (RGB >> 16) & 0xff; int green = (RGB >> 8) & 0xff; int blue = (RGB) & 0xff; rgbColor = RGB & 0x00ffffff; gray = grayVal(red, green, blue); pixel = getPixel(rgbColor, gray, false); } } /** * Sets the current grayscale to be used for all subsequent * rendering operations. For monochrome displays, the behavior * is clear. For color displays, this sets the color for all * subsequent drawing operations to be a gray color equivalent * to the value passed in. The value must be in the range * <code>0-255</code>. * @param value the desired grayscale value * @throws IllegalArgumentException if the gray value is out of range * @see #getGrayScale */ public synchronized void setGrayScale(int value) { if ((value < 0) || (value > 255)) { throw new IllegalArgumentException("Gray value out of range"); } if (pixel == -1 || gray != value) { rgbColor = (value << 16) | (value << 8) | value; gray = value; pixel = getPixel(rgbColor, gray, true); } } /** * Gets the current font. * @return current font * @see javax.microedition.lcdui.Font * @see #setFont(javax.microedition.lcdui.Font) */ public synchronized Font getFont() { return currentFont; } /** * Sets the stroke style used for drawing lines, arcs, rectangles, and * rounded rectangles. This does not affect fill, text, and image * operations. * @param style can be <code>SOLID</code> or <code>DOTTED</code> * @throws IllegalArgumentException if the <code>style</code> is illegal * @see #getStrokeStyle */ public synchronized void setStrokeStyle(int style) { if ((style != SOLID) && (style != DOTTED)) { throw new IllegalArgumentException("Invalid line style"); } this.style = style; } /** * Gets the stroke style used for drawing operations. * @return stroke style, <code>SOLID</code> or <code>DOTTED</code> * @see #setStrokeStyle */ public synchronized int getStrokeStyle() { return style; } /** * Sets the font for all subsequent text rendering operations. If font is * <code>null</code>, it is equivalent to * <code>setFont(Font.getDefaultFont())</code>. * * @param font the specified font * @see javax.microedition.lcdui.Font * @see #getFont() * @see #drawString(java.lang.String, int, int, int) * @see #drawChars(char[], int, int, int, int, int) */ public synchronized void setFont(Font font) { currentFont = (font == null) ? Font.getDefaultFont() : font; } /** * Gets the X offset of the current clipping area, relative * to the coordinate system origin of this graphics context. * Separating the <code>getClip</code> operation into two methods returning * integers is more performance and memory efficient than one * <code>getClip()</code> call returning an object. * @return X offset of the current clipping area * @see #clipRect(int, int, int, int) * @see #setClip(int, int, int, int) */ public synchronized int getClipX() { return clipX1 - transX; } /** * Gets the Y offset of the current clipping area, relative * to the coordinate system origin of this graphics context. * Separating the <code>getClip</code> operation into two methods returning * integers is more performance and memory efficient than one * <code>getClip()</code> call returning an object. * @return Y offset of the current clipping area * @see #clipRect(int, int, int, int) * @see #setClip(int, int, int, int) */ public synchronized int getClipY() { return clipY1 - transY; } /** * Gets the width of the current clipping area. * @return width of the current clipping area. * @see #clipRect(int, int, int, int) * @see #setClip(int, int, int, int) */ public synchronized int getClipWidth() { return clipX2 - clipX1; } /** * Gets the height of the current clipping area. * @return height of the current clipping area. * @see #clipRect(int, int, int, int) * @see #setClip(int, int, int, int) */ public synchronized int getClipHeight() { return clipY2 - clipY1; } /** * Internal routine to get the clip in a single call. The input * parameter must be a 4 element integer array. The values of the * array upon return will be equal to the same values as would be * returned from getClipX(), getClipY(), getClipX()+getClipWidth(), * and getClipY()+getClipHeight(). * * @param region a four element array to hold the clip rectangle */ void getClip(int[] region) { region[0] = clipX1 - transX; region[1] = clipY1 - transY; region[2] = clipX2 - transX; region[3] = clipY2 - transY; } /** * Intersects the current clip with the specified rectangle. * The resulting clipping area is the intersection of the current * clipping area and the specified rectangle. * This method can only be used to make the current clip smaller. * To set the current clip larger, use the <code>setClip</code> method. * Rendering operations have no effect outside of the clipping area. * @param x the x coordinate of the rectangle to intersect the clip with * @param y the y coordinate of the rectangle to intersect the clip with * @param width the width of the rectangle to intersect the clip with * @param height the height of the rectangle to intersect the clip with * @see #setClip(int, int, int, int) */ public synchronized void clipRect(int x, int y, int width, int height) { int translatedX1, translatedY1; int translatedX2, translatedY2; if (width <= 0 || height <= 0) { clipX1 = clipY1 = clipX2 = clipY2 = 0; clipped = true; return; } // Translate the given coordinates translatedX1 = x + transX; translatedY1 = y + transY; // Detect overflow if (translatedX1 < 0) { translatedX1 = (x < 0 || transX < 0) ? 0 : maxWidth; } if (translatedY1 < 0) { translatedY1 = (y < 0 || transY < 0) ? 0 : maxHeight; } // If the passed in rect is below our current clip if ((clipX2 < translatedX1) || (clipY2 < translatedY1)) { // we have no intersection clipX1 = clipY1 = clipX2 = clipY2 = 0; clipped = true; return; } if (translatedX1 > clipX1) { clipX1 = (short) (translatedX1 & 0x7fff); clipped = true; } if (translatedY1 > clipY1) { clipY1 = (short) (translatedY1 & 0x7fff); clipped = true; } // Start handling bottom right area translatedX2 = x + transX + width; translatedY2 = y + transY + height; // Detect Overflow if (translatedX2 < 0) { translatedX2 = (x < 0 || transX < 0) ? translatedX1 : maxWidth; } if (translatedY2 < 0) { translatedY2 = (y < 0 || transY < 0) ? translatedY1 : maxHeight; } // If the passed in rect is above our current clip if (translatedX2 < clipX1 || translatedY2 < clipY1) { // we have no intersection clipX1 = clipY1 = clipX2 = clipY2 = 0; clipped = true; return; } if (translatedX2 <= clipX2) { clipX2 = (short) translatedX2; clipped = true; } if (translatedY2 <= clipY2) { clipY2 = (short) translatedY2; clipped = true; } if (clipped == true) { if (clipX2 < clipX1) clipX2 = clipX1; if (clipY2 < clipY1) clipY2 = clipY1; } /** * sanity check if (clipX1 < 0 || clipY1 < 0 || clipX2 > maxWidth || clipY2 > maxHeight || clipX1 > clipX2 || clipY1 > clipY2) System.out.println("Graphics:clipRect error: clipX1 = "+clipX1+ " clipY1 = "+clipY1+" clipX2 = "+clipX2+" clipY2 = "+clipY2+ " maxWidth = "+maxWidth+" maxHeight = "+maxHeight); if (runtimeClipEnforce) System.out.println("Graphics:clipRect runtimeClipEnforce:"+ " systemClipX1 = "+systemClipX1+" systemClipY1 = "+systemClipY1+ " systemClipX2 = "+systemClipX2+" systemClipY2 = "+systemClipY2); * end sanity check */ } /** * Sets the current clip to the rectangle specified by the * given coordinates. * Rendering operations have no effect outside of the clipping area. * @param x the x coordinate of the new clip rectangle * @param y the y coordinate of the new clip rectangle * @param width the width of the new clip rectangle * @param height the height of the new clip rectangle * @see #clipRect(int, int, int, int) */ public synchronized void setClip(int x, int y, int width, int height) { int translatedX1, translatedY1; int translatedX2, translatedY2; // If width or height is zero or less then zero, // we do not preserve the current clipping and // set all clipping values to zero. if ((width <= 0) || (height <= 0)) { clipX1 = clipY1 = clipX2 = clipY2 = 0; clipped = true;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -