📄 graphics.java
字号:
* 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 void setColor(int RGB) { 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 void setGrayScale(int value) { if ((value < 0) || (value > 255)) { throw new IllegalArgumentException("Gray value out of range"); } 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 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 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 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 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 int getClipX() { return clip[0] - 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 int getClipY() { return clip[1] - 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 int getClipWidth() { return clip[2]; } /** * 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 int getClipHeight() { return clip[3]; } /** * 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 void clipRect(int x, int y, int width, int height) { // If the passed in rect's width/height // is 0 or < 0 then set to zero and return if (width <= 0 || height <= 0) { // no pixels should be in clip clip[2] = 0; clip[3] = 0; clipped = true; return; } translatedX1 = x + transX; translatedY1 = y + transY; if (translatedX1 < 0) { translatedX1 = (x < 0 || transX < 0) ? 0 : maxWidth; } if (translatedY1 < 0) { translatedY1 = (y < 0 || transY < 0) ? 0 : maxHeight; } /* * short values are safe because we guarantee positive numbers * and a width and height which don't exceed the displayable area. */ clipX2 = clip[0] + clip[2]; clipY2 = clip[1] + clip[3]; // If the passed in rect is below our current clip if (clipX2 < translatedX1 || clipY2 < translatedY1) { // we have no intersection clip[2] = 0; clip[3] = 0; clipped = true; return; } if (translatedX1 > clip[0]) { clip[0] = (short) (translatedX1 & 0x7fff); clipped = true; } if (translatedY1 > clip[1]) { clip[1] = (short) (translatedY1 & 0x7fff); clipped = true; } // bottom right translatedX2 = x + transX + width; translatedY2 = y + transY + height; if (translatedX2 < 0) { translatedX2 = (x < 0 || transX < 0) ? 0 : maxWidth; } if (translatedY2 < 0) { translatedY2 = (y < 0 || transY < 0) ? 0 : maxHeight; } // If the passed in rect is above our current clip if (translatedX2 < clip[0] || translatedY2 < clip[1]) { // we have no intersection clip[2] = 0; clip[3] = 0; clipped = true; return; } if (translatedX2 <= clipX2) { clipX2 = translatedX2; clipped = true; } if (translatedY2 <= clipY2) { clipY2 = translatedY2; clipped = true; } if (clipped == true) { clipX2 -= clip[0]; clipY2 -= clip[1]; clip[2] = (clipX2 > 0) ? ((short) (clipX2 & 0x7fff)) : 0; clip[3] = (clipY2 > 0) ? ((short) (clipY2 & 0x7fff)) : 0; } } /** * 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 void setClip(int x, int y, int width, int height) { if ((width <= 0) || (height <= 0)) { clip[0] = clip[1] = clip[2] = clip[3] = 0; clipped = true; return; } translatedX1 = x + transX; translatedY1 = y + transY; if (translatedX1 < 0) { translatedX1 = (x < 0 || transX < 0) ? 0 : maxWidth; } if (translatedY1 < 0) { translatedY1 = (y < 0 || transY < 0) ? 0 : maxHeight; } clipX1 = (short)(translatedX1 & 0x7fff); clipY1 = (short)(translatedY1 & 0x7fff); if ((translatedX1 >= maxWidth) || (translatedY1 >= maxHeight)) { clip[0] = clip[1] = clip[2] = clip[3] = 0; clipped = true; return; } // safe because we already guaranteed values are small positive clip[0] = clipX1; clip[1] = clipY1; translatedX2 = x + transX + width; translatedY2 = y + transY + height; if (translatedX2 < 0) { translatedX2 = (x < 0 || transX < 0) ? 0 : maxWidth; } if (translatedY2 < 0) { translatedY2 = (y < 0 || transY < 0) ? 0 : maxHeight; } clip[2] = (short) ((translatedX2 - clipX1) & 0x7fff); clip[3] = (short) ((translatedY2 - clipY1) & 0x7fff); if (clip[2] > maxWidth) { clip[2] = maxWidth; } if (clip[3] > maxHeight) { clip[3] = maxHeight; } if ((clip[0] > 0) || (clip[1] > 0) || (clip[2] < maxWidth) || (clip[3] < maxHeight)) { clipped = true; } } /** * Draws a line between the coordinates <code>(x1,y1)</code> and * <code>(x2,y2)</code> using * the current color and stroke style. * @param x1 the x coordinate of the start of the line
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -