qtgraphics.java
来自「This is a resource based on j2me embedde」· Java 代码 · 共 856 行 · 第 1/2 页
JAVA
856 行
* current color. This is the default paint mode. */ public void setPaintMode() { xorColor = null; pSetPaintMode(psd); } /** * Sets the paint mode to alternate between the current color * and the given color. */ public void setXORMode(Color color) { xorColor = color; pSetXORMode(psd, color.value); } /** Clears the rectangle indicated by x,y,w,h. */ final public void clearRect(int x, int y, final int w, final int h) { x += originX; y += originY; pClearRect(psd, x, y, w, h, background.value); } /** Fills the given rectangle with the foreground color. */ public void fillRect(final int x, final int y, final int w, final int h) { pFillRect(psd, x + originX, y + originY, w, h); } /** Draws the given rectangle. */ public void drawRect(final int x, final int y, final int w, final int h) { pDrawRect(psd, x + originX, y + originY, w, h); } /** Draws the given line. */ public void drawLine(final int x1, final int y1, final int x2, final int y2) { pDrawLine(psd, x1 + originX, y1 + originY, x2 + originX, y2 + originY); } /** * Copies an area of the canvas that this graphics context paints to. * @param X the x-coordinate of the source. * @param Y the y-coordinate of the source. * @param W the width. * @param H the height. * @param dx the horizontal distance to copy the pixels. * @param dy the vertical distance to copy the pixels. */ public void copyArea(int X, int Y, final int W, final int H, final int dx, final int dy) { X += originX; Y += originY; pCopyArea(psd, X, Y, W, H, dx, dy); } /** Draws lines defined by an array of x points and y points */ public void drawPolyline(final int xPoints[], final int yPoints[], final int nPoints) { pDrawPolygon(psd, originX, originY, xPoints, yPoints, nPoints, false); } /** Draws a polygon defined by an array of x points and y points */ public void drawPolygon(final int xPoints[], final int yPoints[], final int nPoints) { pDrawPolygon(psd, originX, originY, xPoints, yPoints, nPoints, true); } /** Fills a polygon with the current fill mask */ public void fillPolygon(final int xPoints[], final int yPoints[], final int nPoints) { pFillPolygon(psd, originX, originY, xPoints, yPoints, nPoints); } /** Draws an oval to fit in the given rectangle */ public void drawOval(final int x, final int y, final int w, final int h) { pDrawOval(psd, x + originX, y + originY, w, h); } /** Fills an oval to fit in the given rectangle */ public void fillOval(final int x, final int y, final int w, final int h) { pFillOval(psd, x + originX, y + originY, w, h); } /** * Draws an arc bounded by the given rectangle from startAngle to * endAngle. 0 degrees is a vertical line straight up from the * center of the rectangle. Positive start angle indicate clockwise * rotations, negative angle are counter-clockwise. */ public void drawArc(final int x, final int y, final int w, final int h, final int startAngle, final int endAngle) { pDrawArc(psd, x + originX, y + originY, w, h, startAngle, endAngle); } /** fills an arc. arguments are the same as drawArc. */ public void fillArc(final int x, final int y, final int w, final int h, final int startAngle, final int endAngle) { pFillArc(psd, x + originX, y + originY, w, h, startAngle, endAngle); } /** Draws a rounded rectangle. */ public void drawRoundRect(final int x, final int y, final int w, final int h, final int arcWidth, final int arcHeight) { pDrawRoundRect(psd, x + originX, y + originY, w, h, arcWidth, arcHeight); } /** Draws a filled rounded rectangle. */ public void fillRoundRect(final int x, final int y, final int w, final int h, final int arcWidth, final int arcHeight) { pFillRoundRect(psd, x + originX, y + originY, w, h, arcWidth, arcHeight); } /** Draws the given string. */ public void drawString(final String string, final int x, final int y) { // 6259215 // throw NPE instead of returning if (string == null) throw new NullPointerException("string is null"); // 6259215 pDrawString(psd, string, x + originX, y + originY); } public void drawString(AttributedCharacterIterator iterator, int x, int y) { char c = iterator.first(); Graphics ng = new QtGraphics(this); while(c != iterator.DONE) { Map attrs = iterator.getAttributes(); Object obj; FontMetrics fm; Font fn; if ((obj = attrs.get(TextAttribute.FONT)) != null) fn = (Font)obj; else fn = new Font(attrs); ((QtGraphics)ng).setFont(fn, false); fm = ng.getFontMetrics(); // Might have to query the FONT first to see if it has a Colour set. if ((obj = attrs.get(TextAttribute.FOREGROUND)) != null) ng.setColor((Color)obj); else ng.setColor(this.foreground); int runIdx = iterator.getRunLimit(); char[] str = new char[runIdx-iterator.getIndex()]; for(int lc=0; iterator.getIndex() < runIdx; c = iterator.next()) str[lc++] = c; String ns = new String(str); ng.drawString(ns, x, y); x += fm.stringWidth(ns); } ng.dispose(); } /** Draws the given character array. */ public void drawChars(final char chars[], final int offset, final int length, final int x, final int y) { pDrawString(psd, new String(chars, offset, length), x + originX, y + originY); } /** * Gets the current clipping area */ public Rectangle getClipBounds() { if (clip != null) return new Rectangle (clip.x - originX, clip.y - originY, clip.width, clip.height); return null; } /** Returns a Shape object representing the MicroWindows clip. */ public Shape getClip() { return getClipBounds(); } public void constrain(final int x, final int y, final int w, final int h) { originX += x; originY += y; Rectangle rect = new Rectangle(originX, originY, w, h); if (constrainedRect != null) constrainedRect = constrainedRect.intersection(rect); else constrainedRect = rect; setupClip(); } /** Crops the clipping rectangle for this MicroWindows context. */ public void clipRect(final int x, final int y, final int w, final int h) { Rectangle rect = new Rectangle(x + originX, y + originY, w, h); if (clip != null) clip = clip.intersection(rect); else clip = rect; setupClip(); } /** Sets up the clip for this Graphics. The clip is the result of combining the user clip with the constrainedRect. */ private void setupClip() { int clipX, clipY, clipW, clipH; if (constrainedRect != null) { Rectangle c = this.constrainedRect ; if (clip != null) { c = constrainedRect.intersection(clip); } clipX = c.x; clipY = c.y; clipW = c.width; clipH = c.height; } else if (clip != null) { clipX = clip.x; clipY = clip.y; clipW = clip.width; clipH = clip.height; } else { return; // this should not happen } pChangeClipRect(psd, clipX, clipY, clipW, clipH); } /** Sets the clipping rectangle for this X11Graphics context. */ public void setClip(final int x, final int y, final int w, final int h) { if(clip == null) clip = new Rectangle (x + originX, y + originY, w, h); else { clip.x = x+originX; clip.y = y+originY; clip.width = w; clip.height = h; } setupClip(); } /** Sets the clip to a Shape (only Rectangle allowed). */ public void setClip(Shape clip) { if (clip == null) { this.clip = null; pRemoveClip(psd); } else if (clip instanceof Rectangle) { Rectangle rect = (Rectangle) clip; setClip(rect.x, rect.y, rect.width, rect.height); } else throw new IllegalArgumentException("setClip(Shape) only supports Rectangle objects"); } /** * Draws an image at x,y in nonblocking mode with a callback object. */ public boolean drawImage(Image img, final int x, final int y, ImageObserver observer) { return drawImage(img, x, y, null, observer); } /** * Draws an image at x,y in nonblocking mode with a solid background * color and a callback object. */ public boolean drawImage(Image img, final int x, final int y, Color bg, ImageObserver observer) { QtImage qtimg; if (img == null) throw new NullPointerException("Image can't be null"); if (img instanceof BufferedImage) qtimg = getBufferedImagePeer((BufferedImage) img); else if(img instanceof QtVolatileImage) qtimg = ((QtVolatileImage)img).qtimage; else qtimg = (QtImage) img; boolean isComplete = qtimg.isComplete(); if(!isComplete) { qtimg.addObserver(observer); qtimg.startProduction(); isComplete = qtimg.isComplete(); } int width = qtimg.getWidth(); int height = qtimg.getHeight(); if (width > 0 && height > 0) { qtimg.drawImage(psd, x + originX, y + originY, bg); } return isComplete; } /** * Draws an image scaled to x,y,w,h in nonblocking mode with a * callback object. */ public boolean drawImage(Image img, final int x, final int y, final int width, final int height, ImageObserver observer) { return drawImage(img, x, y, width, height, null, observer); } /** * Draws an image scaled to x,y,w,h in nonblocking mode with a * solid background color and a callback object. */ public boolean drawImage(Image img, int x, int y, final int width, final int height, Color bg, ImageObserver observer) { QtImage qtimg; if (img == null) throw new NullPointerException("Image can't be null"); if (img instanceof BufferedImage) qtimg = getBufferedImagePeer((BufferedImage) img); else if(img instanceof QtVolatileImage) qtimg = ((QtVolatileImage)img).qtimage; else qtimg = (QtImage) img; boolean isComplete = qtimg.isComplete(); if(!isComplete) { qtimg.addObserver(observer); qtimg.startProduction(); isComplete = qtimg.isComplete(); } int imgWidth = qtimg.getWidth(); int imgHeight = qtimg.getHeight(); if (imgWidth > 0 && imgHeight > 0) { x += originX; y += originY; if(imgWidth==width&&imgHeight==height) qtimg.drawImage(psd, x, y, bg); else qtimg.drawImage(psd, x, y, x + width - 1, y + height - 1, 0, 0, imgWidth - 1, imgHeight - 1, bg); } return isComplete; } /** * Draws a subrectangle of an image scaled to a destination rectangle * in nonblocking mode with a callback object. */ public boolean drawImage(Image img, final int dx1, final int dy1, final int dx2, final int dy2, final int sx1, final int sy1, final int sx2, final int sy2, ImageObserver observer) { return drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, null, observer); } /** * Draws a subrectangle of an image scaled to a destination rectangle in * nonblocking mode with a solid background color and a callback object. */ public boolean drawImage(Image img, final int dx1, final int dy1, final int dx2, final int dy2, final int sx1, final int sy1, final int sx2, final int sy2, Color bg, ImageObserver observer) { QtImage qtimg; if (img == null) throw new NullPointerException("Image can't be null"); if (img instanceof BufferedImage) qtimg = getBufferedImagePeer((BufferedImage) img); else if(img instanceof QtVolatileImage) qtimg = ((QtVolatileImage)img).qtimage; else qtimg = (QtImage) img; boolean isComplete = qtimg.isComplete(); if(!isComplete) { qtimg.addObserver(observer); qtimg.startProduction(); isComplete = qtimg.isComplete(); } int imgWidth = qtimg.getWidth(); int imgHeight = qtimg.getHeight(); if (imgWidth > 0 || imgHeight > 0) { qtimg.drawImage(psd, dx1 + originX, dy1 + originY, dx2 + originX, dy2 + originY, sx1, sy1, sx2, sy2, bg); } return isComplete; } public String toString() { return getClass().getName() + "[" + originX + "," + originY + "]"; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?