📄 j3dgraphics2dimpl.java
字号:
validate(dx1, dy1, dx2, dy2); return offScreenGraphics2D.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, observer); } public final boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer) { validate(dx1, dy1, dx2, dy2); return offScreenGraphics2D.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, bgcolor, observer); } public final boolean drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer) { validate(x, y, x+img.getWidth(observer), y+img.getHeight(observer)); return offScreenGraphics2D.drawImage(img, x, y, bgcolor, observer); } public final boolean hit(Rectangle rect, Shape s, boolean onStroke) { return offScreenGraphics2D.hit(rect, s, onStroke); } public final void addRenderingHints(Map hints) { offScreenGraphics2D.addRenderingHints(hints); } public final void clipRect(int x, int y, int width, int height) { offScreenGraphics2D.clipRect(x, y, width, height); } public final void copyArea(int x, int y, int width, int height, int dx, int dy) { validate(x+dx, y+dy, x+dx+width, y+dy+height); offScreenGraphics2D.copyArea(x, y, width, height, dx, dy); } public final void draw(Shape s) { Rectangle rect = s.getBounds(); validate(rect.x, rect.y, rect.x + rect.width, rect.y + rect.height); offScreenGraphics2D.draw(s); } public final void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) { // XXXX: call validate with bounding box of primitive validate(); offScreenGraphics2D.drawArc(x, y, width, height, startAngle, arcAngle); } public final void drawGlyphVector(GlyphVector g, float x, float y) { // XXXX: call validate with bounding box of primitive validate(); offScreenGraphics2D.drawGlyphVector(g, x, y); } public final void drawLine(int x1, int y1, int x2, int y2) { int minx, miny, maxx, maxy; if (!strokeSet) { if (x1 > x2) { minx = x2; maxx = x1; } else { minx = x1; maxx = x2; } if (y1 > y2) { miny = y2; maxy = y1; } else { miny = y1; maxy = y2; } validate(minx, miny, maxx, maxy); } else { // XXXX: call validate with bounding box of primitive // XXXX: Need to consider Stroke width validate(); } offScreenGraphics2D.drawLine(x1, y1, x2, y2); } public final void drawOval(int x, int y, int width, int height) { // XXXX: call validate with bounding box of primitive validate(); offScreenGraphics2D.drawOval(x, y, width, height); } public final void drawPolygon(int xPoints[], int yPoints[], int nPoints) { // XXXX: call validate with bounding box of primitive validate(); offScreenGraphics2D.drawPolygon(xPoints, yPoints, nPoints); } public final void drawPolyline(int xPoints[], int yPoints[], int nPoints) { // XXXX: call validate with bounding box of primitive validate(); offScreenGraphics2D.drawPolyline(xPoints, yPoints, nPoints); } public final void drawRenderableImage(RenderableImage img, AffineTransform xform) { validate(0, 0, img.getWidth(), img.getHeight(), xform); offScreenGraphics2D.drawRenderableImage(img, xform); } public final void drawRenderedImage(RenderedImage img, AffineTransform xform) { validate(0, 0, img.getWidth(), img.getHeight(), xform); offScreenGraphics2D.drawRenderedImage(img, xform); } public final void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) { // XXXX: call validate with bounding box of primitive validate(); offScreenGraphics2D.drawRoundRect(x, y, width, height, arcWidth, arcHeight); } public final void drawString(AttributedCharacterIterator iterator, int x, int y) { // XXXX: call validate with bounding box of primitive validate(); offScreenGraphics2D.drawString(iterator, x, y); } public final void drawString(AttributedCharacterIterator iterator, float x, float y) { // XXXX: call validate with bounding box of primitive validate(); offScreenGraphics2D.drawString(iterator, x, y); } public final void drawString(String s, float x, float y) { TextLayout layout = new TextLayout(s, getFont(), getFontRenderContext()); Rectangle2D bounds = layout.getBounds(); float x1 = (float) bounds.getX(); float y1 = (float) bounds.getY(); validate(x1+x, y1+y, x1 + x + (float) bounds.getWidth(), y1 + y + (float) bounds.getHeight()); offScreenGraphics2D.drawString(s, x, y); } public final void drawString(String s, int x, int y) { drawString(s, (float) x, (float) y); } public final void fill(Shape s) { Rectangle rect = s.getBounds(); validate(rect.x, rect.y, rect.x + rect.width, rect.y + rect.height); offScreenGraphics2D.fill(s); } public final void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) { // XXXX: call validate with bounding box of primitive validate(); offScreenGraphics2D.fillArc(x, y, width, height, startAngle, arcAngle); } public final void fillOval(int x, int y, int width, int height) { // XXXX: call validate with bounding box of primitive validate(); offScreenGraphics2D.fillOval(x, y, width, height); } public final void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) { // XXXX: call validate with bounding box of primitive validate(); offScreenGraphics2D.fillRoundRect(x, y, width, height, arcWidth, arcHeight); } public final void rotate(double theta) { offScreenGraphics2D.rotate(theta); } public final void rotate(double theta, double x, double y) { offScreenGraphics2D.rotate(theta, x, y); } public final void scale(double sx, double sy) { offScreenGraphics2D.scale(sx, sy); } public final void setClip(Shape clip) { offScreenGraphics2D.setClip(clip); } public final void setClip(int x, int y, int width, int height) { offScreenGraphics2D.setClip(x, y, width, height); } public final void setColor(Color c) { offScreenGraphics2D.setColor(c); } public final void setComposite(Composite comp) { offScreenGraphics2D.setComposite(comp); } public final void setFont(Font font) { offScreenGraphics2D.setFont(font); } public final void setPaint( Paint paint ) { offScreenGraphics2D.setPaint(paint); } public final void setPaintMode() { xOrModeColor = null; offScreenGraphics2D.setPaintMode(); } public final void setRenderingHint(Key hintKey, Object hintValue) { offScreenGraphics2D.setRenderingHint(hintKey, hintValue); } public final void setRenderingHints(Map hints) { offScreenGraphics2D.setRenderingHints(hints); } public final void setStroke(Stroke s) { strokeSet = (s != null); offScreenGraphics2D.setStroke(s); } public final void setTransform(AffineTransform Tx) { offScreenGraphics2D.setTransform(Tx); } public final void setXORMode(Color c1) { xOrModeColor = c1; offScreenGraphics2D.setXORMode(c1); } public final void shear(double shx, double shy) { offScreenGraphics2D.shear(shx, shy); } public final void transform(AffineTransform Tx) { offScreenGraphics2D.transform(Tx); } public final void translate(double tx, double ty) { offScreenGraphics2D.translate(tx, ty); } public final void translate(int x, int y) { offScreenGraphics2D.translate(x, y); } public boolean hitClip(int x, int y, int width, int height) { return offScreenGraphics2D.hitClip(x, y, width, height); } public void draw3DRect(int x, int y, int width, int height, boolean raised) { // XXXX: call validate with bounding box of primitive validate(); offScreenGraphics2D.draw3DRect(x, y, width, height, raised); } public void drawBytes(byte data[], int offset, int length, int x, int y) { // XXXX: call validate with bounding box of primitive validate(); offScreenGraphics2D.drawBytes(data, offset, length, x, y); } public void drawChars(char data[], int offset, int length, int x, int y) { // XXXX: call validate with bounding box of primitive validate(); offScreenGraphics2D.drawChars(data, offset, length, x, y); } public void drawPolygon(Polygon p) { // XXXX: call validate with bounding box of primitive validate(); offScreenGraphics2D.drawPolygon(p); } public void drawRect(int x, int y, int width, int height) { // XXXX: call validate with bounding box of primitive // XXXX: need to consider Stroke width validate(); offScreenGraphics2D.drawRect(x, y, width, height); } public void fill3DRect(int x, int y, int width, int height, boolean raised) { // XXXX: call validate with bounding box of primitive // XXXX: need to consider Stroke width validate(); offScreenGraphics2D.fill3DRect(x, y, width, height, raised); } public void fillPolygon(Polygon p) { // XXXX: call validate with bounding box of primitive validate(); offScreenGraphics2D.fillPolygon(p); } public final void fillPolygon(int xPoints[], int yPoints[], int nPoints) { // XXXX: call validate with bounding box of primitive validate(); offScreenGraphics2D.fillPolygon(xPoints, yPoints, nPoints); } public final void fillRect(int x, int y, int width, int height) { // XXXX: call validate with bounding box of primitive validate(); offScreenGraphics2D.fillRect(x, y, width, height); } // Issue 121 - release all resources, mark as disposed public void dispose() { if (Thread.currentThread() == canvas3d.screen.renderer) { doDispose(); } else { // Behavior Scheduler or other threads // XXXX: may not be legal for behaviorScheduler // May cause deadlock if it is in behaviorScheduler // and we wait for Renderer to finish boolean renderRun = (Thread.currentThread() != canvas3d.view.universe.behaviorScheduler); sendRenderMessage(renderRun, GraphicsContext3D.DISPOSE2D, null, null, null); } } public void doDispose() { if (hasBeenDisposed) { return; } if (objectId != -1) { canvas3d.freeTexture(canvas3d.ctx, objectId); VirtualUniverse.mc.freeTexture2DId(objectId); objectId = -1; } // Dispose of the underlying Graphics2D offScreenGraphics2D.dispose(); // Mark as disposed hasBeenDisposed = true; } public void drawAndFlushImage(BufferedImage img, int x, int y, ImageObserver observer) { if (hasBeenDisposed) { throw new IllegalStateException(J3dI18N.getString("J3DGraphics2D0")); } if (!(initCtx && abgr && (img.getType() == BufferedImage.TYPE_4BYTE_ABGR))) { drawImage(img, x, y, observer); flush(false); return; } if (Thread.currentThread() == canvas3d.screen.renderer) { doDrawAndFlushImage(img, x, y, observer); } else { // Behavior Scheduler or other threads // XXXX: may not be legal for behaviorScheduler // May cause deadlock if it is in behaviorScheduler // and we wait for Renderer to finish boolean renderRun = (Thread.currentThread() != canvas3d.view.universe.behaviorScheduler); sendRenderMessage(renderRun, GraphicsContext3D.DRAWANDFLUSH2D, img, new Point(x, y), observer); } } void doDrawAndFlushImage(BufferedImage img, int x, int y, ImageObserver observer) { assert !hasBeenDisposed; int imgWidth = img.getWidth(observer); int imgHeight = img.getHeight(observer); int px, py, x1, y1, x2, y2; if (canvas3d.ctx == null) { canvas3d.getGraphicsContext3D().doClear(); } // format needs to be 4BYTE_ABGR and abgr needs to be supported // also must be in canvas callback data = ((DataBufferByte)img.getRaster().getDataBuffer()).getData(); // Transform the affine transform, // note we do not handle scale/rotate etc. AffineTransform tr = getTransform(); ptSrc.x = x; ptSrc.y = y; tr.transform(ptSrc, ptDst1); px = (int) ptDst1.x; py = (int) ptDst1.y; // clip to offscreen buffer size if (px + imgWidth > width) { x2 = width - px; } else { x2 = imgWidth; } if (px < 0) { x1 = -px; px = 0; } else { x1 = 0; } if (py + imgHeight > height) { y2 = height - py; } else { y2 = imgHeight; } if (py < 0) { y1 = -py; py = 0; } else { y1 = 0; } if ((y2 - y1 > 0) && (x2 - x1 > 0)) { copyDataToCanvas(px, py, x1,y1, x2, y2,imgWidth, imgHeight); } } void copyDataToCanvas(int px, int py, int x1, int y1, int x2, int y2, int w, int h) { try { if (!canvas3d.drawingSurfaceObject.renderLock()) { return; } if (!initTexMap) { if (objectId == -1) { objectId = VirtualUniverse.mc.getTexture2DId(); } texWidth = getGreaterPowerOf2(w); texHeight = getGreaterPowerOf2(h); // Canvas got resize, need to init texture map again // in Renderer thread if (!canvas3d.initTexturemapping(canvas3d.ctx, texWidth, texHeight, objectId)) { // Fail to get the texture surface, most likely // there is not enough texture memory initTexMap = false; VirtualUniverse.mc.freeTexture2DId(objectId); objectId = -1; // TODO : Need to find a better way to report no resource problem --- Chien. System.err.println("J3DGraphics2DImpl.copyDataToCanvas() : Fail to get texture resources ..."); } else { initTexMap = true; } } if (initTexMap) { canvas3d.texturemapping(canvas3d.ctx, px, py, x1, y1, x2, y2, texWidth, texHeight, w, (abgr ? ImageComponentRetained.TYPE_BYTE_ABGR: ImageComponentRetained.TYPE_BYTE_RGBA), objectId, data, width, height); } canvas3d.drawingSurfaceObject.unLock(); } catch (NullPointerException ne) { canvas3d.drawingSurfaceObject.unLock(); throw ne; } clearOffScreen(); runMonitor(J3dThread.NOTIFY); } void clearOffScreen() { Composite comp = offScreenGraphics2D.getComposite(); Color c = offScreenGraphics2D.getColor(); offScreenGraphics2D.setComposite(AlphaComposite.Src); offScreenGraphics2D.setColor(blackTransparent); offScreenGraphics2D.fillRect(xmin, ymin, (xmax-xmin), (ymax-ymin)); offScreenGraphics2D.setComposite(comp); offScreenGraphics2D.setColor(c); } /** * Return an integer of power 2 greater than x */ static int getGreaterPowerOf2(int x) { int i = -1; if (x >= 0) { for (i = 1; i < x; i <<= 1); } return i; } /** * MC may not scheduler Renderer thread or Renderer thread * may not process message FLUSH. This will hang user * thread. */ synchronized void runMonitor(int action) { if (action == J3dThread.WAIT) { // Issue 279 - loop until ready while (threadWaiting) { try { wait(); } catch (InterruptedException e){} } } else if (action == J3dThread.NOTIFY) { notify(); threadWaiting = false; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -