📄 gc.java
字号:
* rectangle specified by the <code>x</code>, <code>y</code>, * <code>width</code>, and <code>height</code> arguments. * </p><p> * The oval covers an area that is <code>width + 1</code> * pixels wide and <code>height + 1</code> pixels tall. * </p> * * @param x the x coordinate of the upper left corner of the oval to be drawn * @param y the y coordinate of the upper left corner of the oval to be drawn * @param width the width of the oval to be drawn * @param height the height of the oval to be drawn * * @exception SWTException <ul> * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */ public void drawOval (int x, int y, int width, int height) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); // Check performance impact of always setting null brush. If the user has not // set the background color, we may not have to do this work? int nullBrush = OS.GetStockObject(OS.NULL_BRUSH); int oldBrush = OS.SelectObject(handle, nullBrush); OS.Ellipse(handle, x,y,x+width+1,y+height+1); OS.SelectObject(handle,oldBrush);}/** * Draws a pixel, using the foreground color, at the specified * point (<code>x</code>, <code>y</code>). * <p> * Note that the receiver's line attributes do not affect this * operation. * </p> * * @param x the point's x coordinate * @param y the point's y coordinate * * @exception SWTException <ul> * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> * * @since 3.0 */public void drawPoint (int x, int y) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); OS.SetPixel (handle, x, y, OS.GetTextColor (handle));}/** * Draws the closed polygon which is defined by the specified array * of integer coordinates, using the receiver's foreground color. The array * contains alternating x and y values which are considered to represent * points which are the vertices of the polygon. Lines are drawn between * each consecutive pair, and between the first pair and last pair in the * array. * * @param pointArray an array of alternating x and y values which are the vertices of the polygon * * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT if pointArray is null</li> * </ul> * @exception SWTException <ul> * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */public void drawPolygon(int[] pointArray) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); int nullBrush = OS.GetStockObject(OS.NULL_BRUSH); int oldBrush = OS.SelectObject(handle, nullBrush); OS.Polygon(handle, pointArray, pointArray.length / 2); OS.SelectObject(handle, oldBrush); }/** * Draws the polyline which is defined by the specified array * of integer coordinates, using the receiver's foreground color. The array * contains alternating x and y values which are considered to represent * points which are the corners of the polyline. Lines are drawn between * each consecutive pair, but not between the first pair and last pair in * the array. * * @param pointArray an array of alternating x and y values which are the corners of the polyline * * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT - if the point array is null</li> * </ul> * @exception SWTException <ul> * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */public void drawPolyline(int[] pointArray) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); OS.Polyline(handle, pointArray, pointArray.length / 2); int length = pointArray.length; if (length >= 2) { OS.SetPixel (handle, pointArray[length - 2], pointArray[length - 1], OS.GetTextColor (handle)); }}/** * Draws the outline of the rectangle specified by the arguments, * using the receiver's foreground color. The left and right edges * of the rectangle are at <code>x</code> and <code>x + width</code>. * The top and bottom edges are at <code>y</code> and <code>y + height</code>. * * @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 * * @exception SWTException <ul> * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */public void drawRectangle (int x, int y, int width, int height) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); int hOld = OS.SelectObject (handle, OS.GetStockObject (OS.NULL_BRUSH)); OS.Rectangle (handle, x, y, x + width + 1, y + height + 1); OS.SelectObject (handle, hOld);}/** * Draws the outline of the specified rectangle, using the receiver's * foreground color. The left and right edges of the rectangle are at * <code>rect.x</code> and <code>rect.x + rect.width</code>. The top * and bottom edges are at <code>rect.y</code> and * <code>rect.y + rect.height</code>. * * @param rect the rectangle to draw * * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT - if the rectangle is null</li> * </ul> * @exception SWTException <ul> * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */public void drawRectangle (Rectangle rect) { if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); drawRectangle (rect.x, rect.y, rect.width, rect.height);}/** * Draws the outline of the round-cornered rectangle specified by * the arguments, using the receiver's foreground color. The left and * right edges of the rectangle are at <code>x</code> and <code>x + width</code>. * The top and bottom edges are at <code>y</code> and <code>y + height</code>. * The <em>roundness</em> of the corners is specified by the * <code>arcWidth</code> and <code>arcHeight</code> arguments. * * @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 * * @exception SWTException <ul> * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */public void drawRoundRectangle (int x, int y, int width, int height, int arcWidth, int arcHeight) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (OS.IsWinCE) { /* * Bug in WinCE PPC. On certain devices, RoundRect does not draw * all the pixels. The workaround is to draw a round rectangle * using lines and arcs. */ if (width == 0 || height == 0) return; if (arcWidth == 0 || arcHeight == 0) { drawRectangle(x, y, width, height); return; } if (width < 0) { x += width; width = -width; } if (height < 0) { y += height; height = -height; } if (arcWidth < 0) arcWidth = -arcWidth; if (arcHeight < 0) arcHeight = -arcHeight; if (arcWidth > width) arcWidth = width; if (arcHeight > height) arcHeight = height; if (arcWidth < width) { drawLine(x+arcWidth/2, y, x+width-arcWidth/2, y); drawLine(x+arcWidth/2, y+height, x+width-arcWidth/2, y+height); } if (arcHeight < height) { drawLine(x, y+arcHeight/2, x, y+height-arcHeight/2); drawLine(x+width, y+arcHeight/2, x+width, y+height-arcHeight/2); } if (arcWidth != 0 && arcHeight != 0) { drawArc(x, y, arcWidth, arcHeight, 90, 90); drawArc(x+width-arcWidth, y, arcWidth, arcHeight, 0, 90); drawArc(x+width-arcWidth, y+height-arcHeight, arcWidth, arcHeight, 0, -90); drawArc(x, y+height-arcHeight, arcWidth, arcHeight, 180, 90); } } else { int nullBrush = OS.GetStockObject(OS.NULL_BRUSH); int oldBrush = OS.SelectObject(handle, nullBrush); OS.RoundRect(handle, x,y,x+width+1,y+height+1, arcWidth, arcHeight); OS.SelectObject(handle,oldBrush); }}/** * Draws the given string, using the receiver's current font and * foreground color. No tab expansion or carriage return processing * will be performed. The background of the rectangular area where * the string is being drawn will be filled with the receiver's * background color. * * @param string the string to be drawn * @param x the x coordinate of the top left corner of the rectangular area where the string is to be drawn * @param y the y coordinate of the top left corner of the rectangular area where the string is to be drawn * * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT - if the string is null</li> * </ul> * @exception SWTException <ul> * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */public void drawString (String string, int x, int y) { drawString(string, x, y, false);}/** * Draws the given string, using the receiver's current font and * foreground color. No tab expansion or carriage return processing * will be performed. If <code>isTransparent</code> is <code>true</code>, * then the background of the rectangular area where the string is being * drawn will not be modified, otherwise it will be filled with the * receiver's background color. * * @param string the string to be drawn * @param x the x coordinate of the top left corner of the rectangular area where the string is to be drawn * @param y the y coordinate of the top left corner of the rectangular area where the string is to be drawn * @param isTransparent if <code>true</code> the background will be transparent, otherwise it will be opaque * * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT - if the string is null</li> * </ul> * @exception SWTException <ul> * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */public void drawString (String string, int x, int y, boolean isTransparent) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);// TCHAR buffer = new TCHAR (getCodePage(), string, false); int length = string.length(); if (length == 0) return; char[] buffer = new char [length]; string.getChars(0, length, buffer, 0); int rop2 = 0; if (OS.IsWinCE) { rop2 = OS.SetROP2(handle, OS.R2_COPYPEN); OS.SetROP2(handle, rop2); } else { rop2 = OS.GetROP2(handle); } int oldBkMode = OS.SetBkMode(handle, isTransparent ? OS.TRANSPARENT : OS.OPAQUE); if (rop2 != OS.R2_XORPEN) { OS.ExtTextOutW(handle, x, y, 0, null, buffer, length, null); } else { int foreground = OS.GetTextColor(handle); if (isTransparent) { SIZE size = new SIZE(); OS.GetTextExtentPoint32W(handle, buffer, length, size); int width = size.cx, height = size.cy; int hBitmap = OS.CreateCompatibleBitmap(handle, width, height); if (hBitmap == 0) SWT.error(SWT.ERROR_NO_HANDLES); int memDC = OS.CreateCompatibleDC(handle); int hOldBitmap = OS.SelectObject(memDC, hBitmap); OS.PatBlt(memDC, 0, 0, width, height, OS.BLACKNESS); OS.SetBkMode(memDC, OS.TRANSPARENT); OS.SetTextColor(memDC, foreground); OS.SelectObject(memDC, OS.GetCurrentObject(handle, OS.OBJ_FONT)); OS.ExtTextOutW(memDC, 0, 0, 0, null, buffer, length, null); OS.BitBlt(handle, x, y, width, height, memDC, 0, 0, OS.SRCINVERT); OS.SelectObject(memDC, hOldBitmap); OS.DeleteDC(memDC); OS.DeleteObject(hBitmap); } else { int background = OS.GetBkColor(handle); OS.SetTextColor(handle, foreground ^ background); OS.ExtTextOutW(handle, x, y, 0, null, buffer, length, null); OS.SetTextColor(handle, foreground); } } OS.SetBkMode(handle, oldBkMode);}/** * Draws the given string, using the receiver's current font and * foreground color. Tab expansion and carriage return processing * are performed. The background of the rectangular area where * the text is being drawn will be filled with the receiver's * background color. * * @param string the string to be drawn * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn * * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT - if the string is null</li> * </ul> * @exception SWTException <ul> * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */public void drawText (String string, int x, int y) { drawText(string, x, y, SWT.DRAW_DELIMITER | SWT.DRAW_TAB);}/** * Draws the given string, using the receiver's current font and * foreground color. Tab expansion and carriage return processing * are performed. If <code>isTransparent</code> is <code>true</code>, * then the background of the rectangular area where the text is being * drawn will not be modified, otherwise it will be filled with the * receiver's background color. * * @param string the string to be drawn * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn * @param isTransparent if <code>true</code> the background will be transparent, otherwise it will be opaque * * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT - if the string is null</li> * </ul> * @exception SWTException <ul> * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */public void drawText (String string, int x, int y, boolean isTransparent) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -