📄 gc.java
字号:
int flags = SWT.DRAW_DELIMITER | SWT.DRAW_TAB; if (isTransparent) flags |= SWT.DRAW_TRANSPARENT; drawText(string, x, y, flags);}/** * Draws the given string, using the receiver's current font and * foreground color. Tab expansion, line delimiter and mnemonic * processing are performed according to the specified flags. If * <code>flags</code> includes <code>DRAW_TRANSPARENT</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. * <p> * The parameter <code>flags</code> may be a combination of: * <dl> * <dt><b>DRAW_DELIMITER</b></dt> * <dd>draw multiple lines</dd> * <dt><b>DRAW_TAB</b></dt> * <dd>expand tabs</dd> * <dt><b>DRAW_MNEMONIC</b></dt> * <dd>underline the mnemonic character</dd> * <dt><b>DRAW_TRANSPARENT</b></dt> * <dd>transparent background</dd> * </dl> * </p> * * @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 flags the flags specifing how to process the text * * @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, int flags) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); if (string.length() == 0) return; TCHAR buffer = new TCHAR(getCodePage(), string, false); int length = buffer.length(); if (length == 0) return; RECT rect = new RECT(); /* * Feature in Windows. For some reason DrawText(), the maximum * value for the bottom and right coordinates for the RECT that * is used to position the text is different on between Windows * versions. If this value is larger than the maximum, nothing * is drawn. On Windows 98, the limit is 0x7FFF. On Windows CE, * NT, and 2000 it is 0x6FFFFFF. And on XP, it is 0x7FFFFFFF. * The fix is to use the the smaller limit for Windows 98 and the * larger limit on the other Windows platforms. */ int limit = OS.IsWin95 ? 0x7FFF : 0x6FFFFFF; OS.SetRect(rect, x, y, limit, limit); int uFormat = OS.DT_LEFT; if ((flags & SWT.DRAW_DELIMITER) == 0) uFormat |= OS.DT_SINGLELINE; if ((flags & SWT.DRAW_TAB) != 0) uFormat |= OS.DT_EXPANDTABS; if ((flags & SWT.DRAW_MNEMONIC) == 0) uFormat |= OS.DT_NOPREFIX; 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, (flags & SWT.DRAW_TRANSPARENT) != 0 ? OS.TRANSPARENT : OS.OPAQUE); if (rop2 != OS.R2_XORPEN) { OS.DrawText(handle, buffer, length, rect, uFormat); } else { int foreground = OS.GetTextColor(handle); if ((flags & SWT.DRAW_TRANSPARENT) != 0) { OS.DrawText(handle, buffer, buffer.length(), rect, uFormat | OS.DT_CALCRECT); int width = rect.right - rect.left; int height = rect.bottom - rect.top; 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.SetRect(rect, 0, 0, 0x7FFF, 0x7FFF); OS.DrawText(memDC, buffer, length, rect, uFormat); 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.DrawText(handle, buffer, length, rect, uFormat); OS.SetTextColor(handle, foreground); } } OS.SetBkMode(handle, oldBkMode);}/** * Compares the argument to the receiver, and returns true * if they represent the <em>same</em> object using a class * specific comparison. * * @param object the object to compare with this object * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise * * @see #hashCode */public boolean equals (Object object) { return (object == this) || ((object instanceof GC) && (handle == ((GC)object).handle));}/** * Fills the interior of a circular or elliptical arc within * the specified rectangular area, with the receiver's background * color. * <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><p> * The center of the arc is the center of the rectangle whose origin * is (<code>x</code>, <code>y</code>) and whose size is specified by the * <code>width</code> and <code>height</code> arguments. * </p><p> * The resulting arc covers an area <code>width + 1</code> pixels wide * by <code>height + 1</code> pixels tall. * </p> * * @param x the x coordinate of the upper-left corner of the arc to be filled * @param y the y 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 * * @exception SWTException <ul> * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> * * @see #drawArc */public void fillArc (int x, int y, int width, int height, int startAngle, int arcAngle) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (width < 0) { x = x + width; width = -width; } if (height < 0) { y = y + height; height = -height; } if (width == 0 || height == 0 || arcAngle == 0) return; /* * Feature in WinCE. The function Pie is not present in the * WinCE SDK. The fix is to emulate it by using Polygon. */ if (OS.IsWinCE) { /* compute arc with a simple linear interpolation */ if (arcAngle < 0) { startAngle += arcAngle; arcAngle = -arcAngle; } boolean drawSegments = true; if (arcAngle >= 360) { arcAngle = 360; drawSegments = false; } int[] points = new int[(arcAngle + 1) * 2 + (drawSegments ? 4 : 0)]; int cteX = 2 * x + width; int cteY = 2 * y + height; int index = (drawSegments ? 2 : 0); for (int i = 0; i <= arcAngle; i++) { points[index++] = (Compatibility.cos(startAngle + i, width) + cteX) >> 1; points[index++] = (cteY - Compatibility.sin(startAngle + i, height)) >> 1; } if (drawSegments) { points[0] = points[points.length - 2] = cteX >> 1; points[1] = points[points.length - 1] = cteY >> 1; } int nullPen = OS.GetStockObject(OS.NULL_PEN); int oldPen = OS.SelectObject(handle, nullPen); OS.Polygon(handle, points, points.length / 2); OS.SelectObject(handle, oldPen); } else { int x1, y1, x2, y2,tmp; boolean isNegative; if (arcAngle >= 360 || arcAngle <= -360) { x1 = x2 = x + width; y1 = y2 = y + height / 2; } else { isNegative = arcAngle < 0; arcAngle = arcAngle + startAngle; if (isNegative) { // swap angles tmp = startAngle; startAngle = arcAngle; arcAngle = tmp; } x1 = Compatibility.cos(startAngle, width) + x + width/2; y1 = -1 * Compatibility.sin(startAngle, height) + y + height/2; x2 = Compatibility.cos(arcAngle, width) + x + width/2; y2 = -1 * Compatibility.sin(arcAngle, height) + y + height/2; } int nullPen = OS.GetStockObject(OS.NULL_PEN); int oldPen = OS.SelectObject(handle, nullPen); OS.Pie(handle, x, y, x + width + 1, y + height + 1, x1, y1, x2, y2); OS.SelectObject(handle, oldPen); }}/** * Fills the interior of the specified rectangle with a gradient * sweeping from left to right or top to bottom progressing * from the receiver's foreground color to its background color. * * @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, may be negative * (inverts direction of gradient if horizontal) * @param height the height of the rectangle to be filled, may be negative * (inverts direction of gradient if vertical) * @param vertical if true sweeps from top to bottom, else * sweeps from left to right * * @exception SWTException <ul> * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> * * @see #drawRectangle */public void fillGradientRectangle(int x, int y, int width, int height, boolean vertical) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (width == 0 || height == 0) return; int fromColor = OS.GetTextColor(handle); if (fromColor == OS.CLR_INVALID) { fromColor = OS.GetSysColor(OS.COLOR_WINDOWTEXT); } int toColor = OS.GetBkColor(handle); if (toColor == OS.CLR_INVALID) { toColor = OS.GetSysColor(OS.COLOR_WINDOW); } boolean swapColors = false; if (width < 0) { x += width; width = -width; if (! vertical) swapColors = true; } if (height < 0) { y += height; height = -height; if (vertical) swapColors = true; } if (swapColors) { final int t = fromColor; fromColor = toColor; toColor = t; } int rop2 = 0; if (OS.IsWinCE) { rop2 = OS.SetROP2(handle, OS.R2_COPYPEN); OS.SetROP2(handle, rop2); } else { rop2 = OS.GetROP2(handle); } final RGB fromRGB = new RGB(fromColor & 0xff, (fromColor >>> 8) & 0xff, (fromColor >>> 16) & 0xff); final RGB toRGB = new RGB(toColor & 0xff, (toColor >>> 8) & 0xff, (toColor >>> 16) & 0xff); if (fromRGB.red == toRGB.red && fromRGB.green == toRGB.green && fromRGB.blue == toRGB.blue) { int dwRop = rop2 == OS.R2_XORPEN ? OS.PATINVERT : OS.PATCOPY; OS.PatBlt(handle, x, y, width, height, dwRop); return; } /* Use GradientFill if supported, only on Windows 98, 2000 and newer. */ /* * Bug in Windows: On Windows 2000 when the device is a printer, * GradientFill swaps red and blue color components, causing the * gradient to be printed in the wrong color. On Windows 98 when * the device is a printer, GradientFill does not fill completely * to the right edge of the rectangle. The fix is not to use * GradientFill for printer devices. */ if (!OS.IsWinCE && rop2 != OS.R2_XORPEN && OS.GetDeviceCaps(handle, OS.TECHNOLOGY) != OS.DT_RASPRINTER) { final int hHeap = OS.GetProcessHeap(); final int pMesh = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, GRADIENT_RECT.sizeof + TRIVERTEX.sizeof * 2); final int pVertex = pMesh + GRADIENT_RECT.sizeof; GRADIENT_RECT gradientRect = new GRADIENT_RECT(); gradientRect.UpperLeft = 0; gradientRect.LowerRight = 1; OS.MoveMemory(pMesh, gradientRect, GRADIENT_RECT.sizeof); TRIVERTEX trivertex = new TRIVERTEX(); trivertex.x = x; trivertex.y = y; trivertex.Red = (short)((fromRGB.red << 8) | fromRGB.red); trivertex.Green = (short)((fromRGB.green << 8) | fromRGB.green); trivertex.Blue = (short)((fromRGB.blue << 8) | fromRGB.blue); trivertex.Alpha = -1; OS.MoveMemory(pVertex, trivertex, TRIVERTEX.sizeof); trivertex.x = x + width; trivertex.y = y + height; trivertex.Red = (short)((toRGB.red << 8) | toRGB.red); trivertex.Green = (short)((toRGB.green << 8) | toRGB.green); trivertex.Blue = (short)((toRGB.blue << 8) | toRGB.blue); trivertex.Alpha = -1; OS.MoveMemory(pVertex + TRIVERTEX.sizeof, trivertex, TRIVERTEX.sizeof); boolean success = OS.GradientFill(handle, pVertex, 2, pMesh, 1, vertical ? OS.GRADIENT_FILL_RECT_V : OS.GRADIENT_FILL_RECT_H); OS.HeapFree(hHeap, 0, pMesh); if (success) return; } final int depth = OS.GetDeviceCaps(handle, OS.BITSPIXEL); final int bitResolution = (depth >= 24) ? 8 : (depth >= 15) ? 5 : 0; ImageData.fillGradientRectangle(this, data.device, x, y, width, height, vertical, fromRGB, toRGB, bitResolution, bitResolution, bitResolution);}/** * Fills the interior of an oval, within the specified * rectangular area, with the receiver's background * color. * * @param x the x coordinate of the upper left corner of the oval to be filled * @param y the y coordinate of the
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -