⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gc.java

📁 源码为Eclipse开源开发平台桌面开发工具SWT的源代码,
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
 * * @param x the x coordinate of the upper-left corner of the arc to be drawn * @param y the y 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 * * @exception SWTException <ul> *    <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */public void drawArc (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 Arc is not present in the	* WinCE SDK.  The fix is to emulate arc drawing by using	* Polyline.	*/	if (OS.IsWinCE) {		/* compute arc with a simple linear interpolation */		if (arcAngle < 0) {			startAngle += arcAngle;			arcAngle = -arcAngle;		}		if (arcAngle > 360) arcAngle = 360;		int[] points = new int[(arcAngle + 1) * 2];				int cteX = 2 * x + width;		int cteY = 2 * y + height;		int index = 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;		} 		OS.Polyline(handle, points, points.length / 2);	} 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 nullBrush = OS.GetStockObject(OS.NULL_BRUSH);		int oldBrush = OS.SelectObject(handle, nullBrush);		OS.Arc(handle, x, y, x + width + 1, y + height + 1, x1, y1, x2, y2);		OS.SelectObject(handle, oldBrush);	}}/**  * Draws a rectangle, based on the specified arguments, which has * the appearance of the platform's <em>focus rectangle</em> if the * platform supports such a notion, and otherwise draws a simple * rectangle in the receiver's foreground color. * * @param x the x coordinate of the rectangle * @param y the y coordinate of the rectangle * @param width the width of the rectangle * @param height the height of the rectangle * * @exception SWTException <ul> *    <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> * * @see #drawRectangle */	 public void drawFocus (int x, int y, int width, int height) {	if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);	RECT rect = new RECT();	OS.SetRect(rect, x, y, x + width, y + height);	OS.DrawFocusRect(handle, rect);}/** * Draws the given image in the receiver at the specified * coordinates. * * @param image the image to draw * @param x the x coordinate of where to draw * @param y the y coordinate of where to draw * * @exception IllegalArgumentException <ul> *    <li>ERROR_NULL_ARGUMENT - if the image is null</li> *    <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li> *    <li>ERROR_INVALID_ARGUMENT - if the given coordinates are outside the bounds of the image</li> * @exception SWTError <ul> *    <li>ERROR_NO_HANDLES - if no handles are available to perform the operation</li> * </ul> * @exception SWTException <ul> *    <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */public void drawImage(Image image, int x, int y) {	if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);	if (image == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);	if (image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);	drawImage(image, 0, 0, -1, -1, x, y, -1, -1, true);}/** * Copies a rectangular area from the source image into a (potentially * different sized) rectangular area in the receiver. If the source * and destination areas are of differing sizes, then the source * area will be stretched or shrunk to fit the destination area * as it is copied. The copy fails if any part of the source rectangle * lies outside the bounds of the source image, or if any of the width * or height arguments are negative. * * @param image the source image * @param srcX the x coordinate in the source image to copy from * @param srcY the y coordinate in the source image to copy from * @param srcWidth the width in pixels to copy from the source * @param srcHeight the height in pixels to copy from the source * @param destX the x coordinate in the destination to copy to * @param destY the y coordinate in the destination to copy to * @param destWidth the width in pixels of the destination rectangle * @param destHeight the height in pixels of the destination rectangle * * @exception IllegalArgumentException <ul> *    <li>ERROR_NULL_ARGUMENT - if the image is null</li> *    <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li> *    <li>ERROR_INVALID_ARGUMENT - if any of the width or height arguments are negative. *    <li>ERROR_INVALID_ARGUMENT - if the source rectangle is not contained within the bounds of the source image</li> * </ul> * @exception SWTError <ul> *    <li>ERROR_NO_HANDLES - if no handles are available to perform the operation</li> * </ul> * @exception SWTException <ul> *    <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */public void drawImage(Image image, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight) {	if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);	if (srcWidth == 0 || srcHeight == 0 || destWidth == 0 || destHeight == 0) return;	if (srcX < 0 || srcY < 0 || srcWidth < 0 || srcHeight < 0 || destWidth < 0 || destHeight < 0) {		SWT.error (SWT.ERROR_INVALID_ARGUMENT);	}	if (image == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);	if (image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);	drawImage(image, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, false);	}void drawImage(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple) {	switch (srcImage.type) {		case SWT.BITMAP:			drawBitmap(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple);			break;		case SWT.ICON:			drawIcon(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple);			break;		default:			SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT);	}}void drawIcon(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple) {	int technology = OS.GetDeviceCaps(handle, OS.TECHNOLOGY);	/* Simple case: no stretching, entire icon */	if (simple && technology != OS.DT_RASPRINTER) {		OS.DrawIconEx(handle, destX, destY, srcImage.handle, 0, 0, 0, 0, OS.DI_NORMAL);		return;	}	/* Get the icon info */	ICONINFO srcIconInfo = new ICONINFO();	if (OS.IsWinCE) {		Image.GetIconInfo(srcImage, srcIconInfo);	} else {		OS.GetIconInfo(srcImage.handle, srcIconInfo);	}	/* Get the icon width and height */	int hBitmap = srcIconInfo.hbmColor;	if (hBitmap == 0) hBitmap = srcIconInfo.hbmMask;	BITMAP bm = new BITMAP();	OS.GetObject(hBitmap, BITMAP.sizeof, bm);	int iconWidth = bm.bmWidth, iconHeight = bm.bmHeight;	if (hBitmap == srcIconInfo.hbmMask) iconHeight /= 2;		if (simple) {		srcWidth = destWidth = iconWidth;		srcHeight = destHeight = iconHeight;	}	/* Draw the icon */	boolean failed = srcX + srcWidth > iconWidth || srcY + srcHeight > iconHeight;	if (!failed) {		simple = srcX == 0 && srcY == 0 &&			srcWidth == destWidth && srcHeight == destHeight &&			srcWidth == iconWidth && srcHeight == iconHeight;		if (simple && technology != OS.DT_RASPRINTER)	{			/* Simple case: no stretching, entire icon */			OS.DrawIconEx(handle, destX, destY, srcImage.handle, 0, 0, 0, 0, OS.DI_NORMAL);		} else {			/* Get the HDC for the device */			Device device = data.device; 			int hDC = device.internal_new_GC(null); 	 			/* Create the icon info and HDC's */			ICONINFO newIconInfo = new ICONINFO();			newIconInfo.fIcon = true;			int srcHdc = OS.CreateCompatibleDC(hDC);			int dstHdc = OS.CreateCompatibleDC(hDC);									/* Blt the color bitmap */			int srcColorY = srcY;			int srcColor = srcIconInfo.hbmColor;			if (srcColor == 0) {				srcColor = srcIconInfo.hbmMask;				srcColorY += iconHeight;			}			int oldSrcBitmap = OS.SelectObject(srcHdc, srcColor);			newIconInfo.hbmColor = OS.CreateCompatibleBitmap(srcHdc, destWidth, destHeight);			if (newIconInfo.hbmColor == 0) SWT.error(SWT.ERROR_NO_HANDLES);			int oldDestBitmap = OS.SelectObject(dstHdc, newIconInfo.hbmColor);			boolean stretch = !simple && (srcWidth != destWidth || srcHeight != destHeight);			if (stretch) {				if (!OS.IsWinCE) OS.SetStretchBltMode(dstHdc, OS.COLORONCOLOR);				OS.StretchBlt(dstHdc, 0, 0, destWidth, destHeight, srcHdc, srcX, srcColorY, srcWidth, srcHeight, OS.SRCCOPY);			} else {				OS.BitBlt(dstHdc, 0, 0, destWidth, destHeight, srcHdc, srcX, srcColorY, OS.SRCCOPY);			}						/* Blt the mask bitmap */			OS.SelectObject(srcHdc, srcIconInfo.hbmMask);			newIconInfo.hbmMask = OS.CreateBitmap(destWidth, destHeight, 1, 1, null);			if (newIconInfo.hbmMask == 0) SWT.error(SWT.ERROR_NO_HANDLES);			OS.SelectObject(dstHdc, newIconInfo.hbmMask);			if (stretch) {				OS.StretchBlt(dstHdc, 0, 0, destWidth, destHeight, srcHdc, srcX, srcY, srcWidth, srcHeight, OS.SRCCOPY);			} else {				OS.BitBlt(dstHdc, 0, 0, destWidth, destHeight, srcHdc, srcX, srcY, OS.SRCCOPY);			}						if (technology == OS.DT_RASPRINTER) {				OS.SelectObject(srcHdc, newIconInfo.hbmColor);				OS.SelectObject(dstHdc, srcIconInfo.hbmMask);				drawBitmapTransparentByClipping(srcHdc, dstHdc, 0, 0, destWidth, destHeight, destX, destY, destWidth, destHeight, true, destWidth, destHeight);					OS.SelectObject(srcHdc, oldSrcBitmap);				OS.SelectObject(dstHdc, oldDestBitmap);			} else {				OS.SelectObject(srcHdc, oldSrcBitmap);				OS.SelectObject(dstHdc, oldDestBitmap);				int hIcon = OS.CreateIconIndirect(newIconInfo);				if (hIcon == 0) SWT.error(SWT.ERROR_NO_HANDLES);				OS.DrawIconEx(handle, destX, destY, hIcon, destWidth, destHeight, 0, 0, OS.DI_NORMAL);				OS.DestroyIcon(hIcon);			}						/* Destroy the new icon src and mask and hdc's*/			OS.DeleteObject(newIconInfo.hbmMask);			OS.DeleteObject(newIconInfo.hbmColor);			OS.DeleteDC(dstHdc);			OS.DeleteDC(srcHdc);			/* Release the HDC for the device */			device.internal_dispose_GC(hDC, null);		}	}	/* Free icon info */	OS.DeleteObject(srcIconInfo.hbmMask);	if (srcIconInfo.hbmColor != 0) {		OS.DeleteObject(srcIconInfo.hbmColor);	}		if (failed) SWT.error(SWT.ERROR_INVALID_ARGUMENT);}void drawBitmap(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple) {	BITMAP bm = new BITMAP();	OS.GetObject(srcImage.handle, BITMAP.sizeof, bm);	int imgWidth = bm.bmWidth;	int imgHeight = bm.bmHeight;	if (simple) {		srcWidth = destWidth = imgWidth;		srcHeight = destHeight = imgHeight;	} else {		if (srcX + srcWidth > imgWidth || srcY + srcHeight > imgHeight) {			SWT.error (SWT.ERROR_INVALID_ARGUMENT);		}		simple = srcX == 0 && srcY == 0 && 			srcWidth == destWidth && destWidth == imgWidth &&			srcHeight == destHeight && destHeight == imgHeight;	}	boolean mustRestore = false;	GC memGC = srcImage.memGC;	if (memGC != null && !memGC.isDisposed()) {		mustRestore = true;		GCData data = memGC.data;		if (data.hNullBitmap != 0) {			OS.SelectObject(memGC.handle, data.hNullBitmap);			data.hNullBitmap = 0;		}	}	if (srcImage.alpha != -1 || srcImage.alphaData != null) {		drawBitmapAlpha(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, bm, imgWidth, imgHeight);	} else if (srcImage.transparentPixel != -1) {		drawBitmapTransparent(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, bm, imgWidth, imgHeight);	} else {		drawBitmap(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, bm, imgWidth, imgHeight);	}	if (mustRestore) {		int hOldBitmap = OS.SelectObject(memGC.handle, srcImage.handle);		memGC.data.hNullBitmap = hOldBitmap;	}}void drawBitmapAlpha(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple, BITMAP bm, int imgWidth, int imgHeight) {	/* Simple cases */	if (srcImage.alpha == 0) return;	if (srcImage.alpha == 255) {		drawBitmap(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, bm, imgWidth, imgHeight);		return;	}	/* Check clipping */	Rectangle rect = getClipping();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -