📄 graphics.java
字号:
* @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 getClip operation into two methods returning * integers is more performance and memory efficient than one * getClip() 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 setClip 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) { x += transX; y += transY; /* * short values are safe because we guarantee positive numbers * and a width and height which don't exceed the displayable area. */ if (x > clip[0]) { clip[0] = (short) (x & 0x7fff); clipped = true; } if (y > clip[1]) { clip[1] = (short) (y & 0x7fff); clipped = true; } x += width; y += height; if (x < clipX2) { clipX2 = x; clipped = true; } if (y < clipY2) { clipY2 = y; clipped = true; } if (clipped) { clip[2] = (short) (clipX2 - clip[0]); clip[3] = (short) (clipY2 - clip[1]); if ((clip[2] < 0) || (clip[3] < 0)) { clip[2] = 0; clip[3] = 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) { x += transX; y += transY; short clipX1 = (x > 0) ? ((short)(x & 0x7fff)) : 0; short clipY1 = (y > 0) ? ((short)(y & 0x7fff)) : 0; if ((x >= maxWidth) || (width <= 0) || (y >= maxHeight) || (height <= 0)) { clip[0] = clip[1] = clip[2] = clip[3] = 0; clipped = true; return; } clipX2 = x + width; if (clipX2 > maxWidth) { clipX2 = maxWidth; } clipY2 = y + height; if (clipY2 > maxHeight) { clipY2 = maxHeight; } /* safe because we already guaranteed values are small positive */ clip[0] = clipX1; clip[1] = clipY1; clip[2] = (short) (clipX2 - clipX1); clip[3] = (short) (clipY2 - clipY1); if (clip[2] < 0) { clip[2] = 0; } if (clip[3] < 0) { clip[3] = 0; } if ((clipX1 > 0) || (clipY1 > 0) || (clipX2 < maxWidth) || (clipY2 < maxHeight)) { clipped = true; } } /** * Draws a line between the coordinates (x1,y1) and (x2,y2) using * the current color and stroke style. * @param x1 the x coordinate of the start of the line * @param y1 the y coordinate of the start of the line * @param x2 the x coordinate of the end of the line * @param y2 the y coordinate of the end of the line */ public native void drawLine(int x1, int y1, int x2, int y2); /** * Fills the specified rectangle with the current color. * If either width or height is zero or less, * nothing is drawn. * @param x the x coordinate of the rectangle to be filled * @param y the y coordinate of the rectangle to be filled * @param width the width of the rectangle to be filled * @param height the height of the rectangle to be filled * @see #drawRect(int, int, int, int) */ public native void fillRect(int x, int y, int width, int height); /** * Draws the outline of the specified rectangle using the current * color and stroke style. * The resulting rectangle will cover an area (width + 1) * pixels wide by (height + 1) pixels tall. * If either width or height is less than * zero, nothing is drawn. * @param x the x coordinate of the rectangle to be drawn * @param y the y coordinate of the rectangle to be drawn * @param width the width of the rectangle to be drawn * @param height the height of the rectangle to be drawn * @see #fillRect(int, int, int, int) */ public native void drawRect(int x, int y, int width, int height); /** * Draws the outline of the specified rounded corner rectangle * using the current color and stroke style. * The resulting rectangle will cover an area (width + 1) pixels wide * by (height + 1) pixels tall. * If either width or height is less than * zero, nothing is drawn. * @param x the x coordinate of the rectangle to be drawn * @param y the y coordinate of the rectangle to be drawn * @param width the width of the rectangle to be drawn * @param height the height of the rectangle to be drawn * @param arcWidth the horizontal diameter of the arc at the four corners * @param arcHeight the vertical diameter of the arc at the four corners * @see #fillRoundRect(int, int, int, int, int, int) */ public native void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight); /** * Fills the specified rounded corner rectangle with the current color. * If either width or height is zero or less, * nothing is drawn. * @param x the x coordinate of the rectangle to be filled * @param y the y coordinate of the rectangle to be filled * @param width the width of the rectangle to be filled * @param height the height of the rectangle to be filled * @param arcWidth the horizontal diameter of the arc at the four * corners * @param arcHeight the vertical diameter of the arc at the four corners * @see #drawRoundRect(int, int, int, int, int, int) */ public native void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight); /** * Fills a circular or elliptical arc covering the specified rectangle. * <p> * The resulting arc begins at <code>startAngle</code> and extends * for <code>arcAngle</code> degrees. * Angles are interpreted such that 0 degrees * is at the 3 o'clock position. * A positive value indicates a counter-clockwise rotation * while a negative value indicates a clockwise rotation. * <p> * The center of the arc is the center of the rectangle whose origin * is (<em>x</em>, <em>y</em>) and whose size is specified by the * <code>width</code> and <code>height</code> arguments. * <p> * If either width or height is zero or less, * nothing is drawn. * * <p> The filled region consists of the "pie wedge" region bounded * by the arc * segment as if drawn by drawArc(), the radius extending from the * center to * this arc at <code>startAngle</code> degrees, and radius * extending from the * center to this arc at <code>startAngle + arcAngle</code> degrees. </p> * * <p> The angles are specified relative to the non-square extents of * the bounding rectangle such that 45 degrees always falls on the * line from the center of the ellipse to the upper right corner of * the bounding rectangle. As a result, if the bounding rectangle is * noticeably longer in one axis than the other, the angles to the * start and end of the arc segment will be skewed farther along the * longer axis of the bounds. </p> * * @param x the <em>x</em> coordinate of the upper-left corner of * the arc to be filled. * @param y the <em>y</em> coordinate of the upper-left corner of the * arc to be filled. * @param width the width of the arc to be filled * @param height the height of the arc to be filled * @param startAngle the beginning angle. * @param arcAngle the angular extent of the arc, * relative to the start angle. * @see #drawArc(int, int, int, int, int, int) */ public native void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle); /** * Draws the outline of a circular or elliptical arc * covering the specified rectangle, * using the current color and stroke style. * <p> * The resulting arc begins at <code>startAngle</code> and extends * for <code>arcAngle</code> degrees, using the current color. * Angles are interpreted such that 0 degrees * is at the 3 o'clock position. * A positive value indicates a counter-clockwise rotation * while a negative value indicates a clockwise rotation. * <p> * The center of the arc is the center of the rectangle whose origin * is (<em>x</em>, <em>y</em>) and whose size is specified by the * <code>width</code> and <code>height</code> arguments. * <p> * The resulting arc covers an area * <code>width + 1</code> pixels wide * by <code>height + 1</code> pixels tall. * If either width or height is less than zero, * nothing is drawn. * * <p> The angles are specified relative to the non-square extents of * the bounding rectangle such that 45 degrees always falls on the * line from the center of the ellipse to the upper right corner of * the bounding rectangle. As a result, if the bounding rectangle is * noticeably longer in one axis than the other, the angles to the * start and end of the arc segment will be skewed farther along the * longer axis of the bounds. </p> * * @param x the <em>x</em> coordinate of the upper-left corner of * the arc to be drawn. * @param y the <em>y</em> coordinate of the upper-left corner of * the arc to be drawn. * @param width the width of the arc to be drawn * @param height the height of the arc to be drawn * @param startAngle the beginning angle * @param arcAngle the angular extent of the arc, relative to * the start angle. * @see #fillArc(int, int, int, int, int, int) */ public native void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle); /** * Draws the specified String using the current font and color. * The x,y position is the position of the anchor point. * See <a href="#anchor">anchor points</a>. * @param str the String to be drawn * @param x the x coordinate of the anchor point * @param y the y coordinate of the anchor point * @param anchor the anchor point for positioning the text * @throws NullPointerException if str is null * @throws IllegalArgumentException if anchor is not a legal value
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -