List of usage examples for java.awt Graphics getClip
public abstract Shape getClip();
From source file:com.jcraft.weirdx.XWindow.java
void makeBackgroundTile(int xx, int yy, int w, int h) { XWindow win = this; int i = (attr & backgroundState); if (i == ParentRelative) { win = parent;//from ww w .j a va 2 s .c o m if (win == null) return; i = (win.attr & backgroundState); } if (i == BackgroundPixmap && win.background.pixmap != null) { Image img = win.background.img; if (img == null) return; if (!win.ddxwindow.isVisible()) return; Graphics g = null; java.awt.Shape tmp = null; if (xx != 0 || yy != 0 || w != width || h != height) { g = getGraphics(); tmp = g.getClip(); g.clipRect(xx, yy, w, h); } if (win == this) { ddxwindow.fillImage(img, win.background.pixmap.width, win.background.pixmap.height); } else { ddxwindow.fillImage(img, win.background.pixmap.width, win.background.pixmap.height, origin.x - borderWidth, origin.y - borderWidth); } if (g != null) { if (tmp == null) { g.setClip(0, 0, width, height); } else { g.setClip(tmp); } } } else if (i == BackgroundPixel) { XColormap cmap = win.getColormap(); ddxwindow.setBackground(cmap.getColor(win.background.pixel), xx, yy, w, h); } }
From source file:com.jcraft.weirdx.XWindow.java
static final void reqCopyPlane(Client c) throws IOException { int foo;//from w w w .j av a 2 s .c o m XDrawable dsrc = null, ddst = null; InputOutput io = c.client; foo = io.readInt(); dsrc = c.lookupDrawable(foo); if (dsrc == null) { c.errorValue = foo; c.errorReason = 9; // Drawable } int dest = io.readInt(); ddst = c.lookupDrawable(dest); if (ddst == null && c.errorReason == 0) { c.errorValue = dest; c.errorReason = 9; // Drawable } foo = io.readInt(); GC gc = c.lookupGC(foo); if (gc == null && c.errorReason == 0) { c.errorValue = foo; c.errorReason = 13; // BadGC; } int sx, sy, dx, dy, width, height; sx = (short) io.readShort(); sy = (short) io.readShort(); int destx, desty; destx = (short) io.readShort(); dx = destx - sx; desty = (short) io.readShort(); dy = desty - sy; width = io.readShort(); height = io.readShort(); int bplane = io.readInt(); c.length -= 8; if (c.errorReason != 0) { return; } Graphics g = ddst.getGraphics(); if (((dsrc instanceof XWindow) && !((XWindow) dsrc).ddxwindow.isVisible())) { g = null; } if (dsrc.width <= sx || dsrc.height <= sy || (sx + width) <= 0 || (sy + height) <= 0 || (destx + width) <= 0 || (desty + height) <= 0) { g = null; } if (g != null) { if (dsrc instanceof XWindow) { if (ddst instanceof XWindow) { ((XWindow) dsrc).ddxwindow.copyArea(((XWindow) ddst), gc, sx, sy, width, height, destx, desty); } } else { Image img = null; if (ddst instanceof XPixmap) { ((XPixmap) dsrc).copyPlane((XPixmap) ddst, gc, sx, sy, destx, desty, width, height); } else { img = ((XPixmap) dsrc).getImage((XWindow) ddst, gc, sx, sy, width, height); XWindow wdst = (XWindow) ddst; if (sx == 0 && sy == 0 && width == dsrc.width && height == dsrc.height) { wdst.ddxwindow.drawImage(gc.clip_mask, img, destx, desty, width, height); } else { java.awt.Shape tmp = g.getClip(); g.clipRect(destx, desty, width, height); wdst.ddxwindow.drawImage(gc.clip_mask, img, destx - sx, desty - sy, dsrc.width, dsrc.height); if (tmp == null) { g.setClip(0, 0, wdst.width, wdst.height); } else { g.setClip(tmp); } } wdst.draw(destx, desty, width, height); if (img != ((XPixmap) dsrc).getImage()) { img.flush(); } } } } }
From source file:com.jcraft.weirdx.Draw.java
@SuppressWarnings("unused") static void reqPolyFillRectangle(Client c, XDrawable d, GC gc) throws IOException { int n = c.length; //int foo;//from w w w . java 2 s . co m Graphics graphics = d.getGraphics(gc, GC.GCFunction | GC.GCSubwindowMode); if (graphics == null) { c.client.readPad(n * 4); return; } if (gc.clip_mask != null && gc.clip_mask instanceof ClipPixmap && (d instanceof XPixmap) && ((XPixmap) d).data != null) { XPixmap p = (XPixmap) d; byte[] data = p.data; XPixmap cpixmap = (XPixmap) (gc.clip_mask.getMask()); short x, y; int ww, hh; byte f = (byte) gc.fgPixel; while (n != 0) { x = (short) c.client.readShort(); y = (short) c.client.readShort(); ww = c.client.readShort(); hh = c.client.readShort(); n -= 2; if (x < 0) { ww += x; x = 0; } if (y < 0) { hh += y; y = 0; } if (d.width <= x || d.height <= y) continue; if (ww <= 0 || hh <= 0) continue; // if((x+ww)<=0 || (y+hh)<=0) continue; if (ww > cpixmap.width) ww = cpixmap.width; if (hh > cpixmap.height) hh = cpixmap.height; if (ww > d.width) ww = d.width; if (hh > d.height) hh = d.height; for (int i = 0; i < hh; i++) { for (int j = 0; j < ww; j++) { if (p.data[(i + y) * p.width + x + j] == 0) { p.data[(i + y) * p.width + x + j] = f; } } } } return; } /* if(gc.clip_mask!=null && (d instanceof Pixmap) && gc.clip_mask.width==d.width && gc.clip_mask.height==d.height && ((Pixmap)d).data!=null){ Pixmap p=(Pixmap)d; // for(int i=0;i<p.height;i++){ // for(int j=0;j<p.width;j++){ // System.out.print(p.data[i*p.width+j]+" "); // } // System.out.println(""); // } byte f=(byte)gc.fgPixel; for(int i=0;i<gc.clip_mask.height;i++){ for(int j=0;j<gc.clip_mask.width;j++){ if(p.data[i*gc.clip_mask.width+j]==0){ p.data[i*gc.clip_mask.width+j]=f; } } } // for(int i=0;i<((Pixmap)d).height;i++){ // for(int j=0;j<((Pixmap)d).width;j++){ // System.out.print(((Pixmap)d).data[i*((Pixmap)d).width+j]+" "); // } // System.out.println(""); // } while(n!=0){ c.client.readPad(8); n-=2; } return; } */ if (gc.clip_mask != null && gc.clip_mask instanceof ClipRectangles) { java.awt.Rectangle rec = (Rectangle) (gc.clip_mask.getMask()); if (rec == null) { while (n > 0) { c.client.readPad(8); n -= 2; } return; } } XPixmap p = null; if (((gc.attr & GC.fillStyle) == GC.FillOpaqueStippled) || ((gc.attr & GC.fillStyle) == GC.FillStippled)) { p = gc.stipple; } if (((gc.attr & GC.fillStyle) == GC.FillTiled)) { p = gc.tile.pixmap; } short x, y; int ww, hh; int sx = d.width; int sy = d.height; int lx = 0; int ly = 0; while (n != 0) { x = (short) c.client.readShort(); y = (short) c.client.readShort(); ww = c.client.readShort(); hh = c.client.readShort(); n -= 2; if (x < 0) { ww += x; x = 0; } if (y < 0) { hh += y; y = 0; } if (d.width <= x || d.height <= y) continue; if (ww <= 0 || hh <= 0) continue; if (x < sx) sx = x; ; if (lx < x + ww) lx = x + ww; if (y < sy) sy = y; if (ly < y + hh) ly = y + hh; if (((gc.attr & GC.fillStyle) == GC.FillOpaqueStippled) || ((gc.attr & GC.fillStyle) == GC.FillStippled) || ((gc.attr & GC.fillStyle) == GC.FillTiled)) { java.awt.Shape tmp = null; ww += x; hh += y; if ((p.width > ww - x) || (p.height > hh - y)) { tmp = graphics.getClip(); graphics.clipRect(x, y, ww - x, hh - y); } graphics.drawImage(p.img, x, y, Screen.screen[0].root.ddxwindow); if (tmp != null) graphics.setClip(tmp); for (int i = x + p.width; i < ww; i += p.width) { int www = p.width; int hhh = p.height; if (i + www > ww) www = ww - i; if (y + hhh >= hh) hhh = hh - y; graphics.copyArea(x, y, www, hhh, i - x, 0); } for (int j = y + p.height; j < hh; j += p.height) { int hhh = p.height; if (j + hhh >= hh) hhh = hh - j; graphics.copyArea(x, y, ww - x, hhh, 0, j - y); } } else { graphics.fillRect(x, y, ww, hh); } } if (sx < 0) sx = 0; if (sy < 0) sy = 0; if (d instanceof XWindow) { ((XWindow) d).draw(sx, sy, lx - sx + 2, ly - sy + 2); } if (gc.function == GC.GXxor || gc.function == GC.GXinvert) { graphics.setPaintMode(); } if (gc.clip_mask != null && gc.clip_mask instanceof ClipRectangles) { d.restoreClip(); } }
From source file:com.jcraft.weirdx.XWindow.java
static final void reqCopyArea(Client c) throws IOException { int foo;//from w w w .ja v a 2s. c om XDrawable dsrc = null, ddst = null; InputOutput io = c.client; foo = io.readInt(); dsrc = c.lookupDrawable(foo); if (dsrc == null) { c.errorValue = foo; c.errorReason = 9; // BadDrawable; } int dest = io.readInt(); ddst = c.lookupDrawable(dest); if (ddst == null && c.errorReason == 0) { c.errorValue = dest; c.errorReason = 9; // BadDrawable; } foo = io.readInt(); GC gc = c.lookupGC(foo); if (gc == null && c.errorReason == 0) { c.errorValue = foo; c.errorReason = 13; // BadGC; } int sx, sy; sx = (short) io.readShort(); sy = (short) io.readShort(); int destx, desty; destx = (short) io.readShort(); desty = (short) io.readShort(); int width, height; width = io.readShort(); height = io.readShort(); c.length -= 7; if (c.errorReason != 0) { return; } Graphics g = ddst.getGraphics(); if (((dsrc instanceof XWindow) && !((XWindow) dsrc).ddxwindow.isVisible())) { g = null; } if (dsrc.width <= sx || dsrc.height <= sy || (sx + width) <= 0 || (sy + height) <= 0 || (destx + width) <= 0 || (desty + height) <= 0) { g = null; } /* LOG.info("copyArea: "+dsrc+" sx="+sx+",sy="+sy+ ", w="+width+", h="+height+" "+ ddst+" destx="+destx+",desty="+desty); */ if (g != null) { if (dsrc instanceof XWindow) { if (sx < 0) { sx = 0; } if (sy < 0) { sy = 0; } if (destx < 0) { destx = 0; } if (desty < 0) { desty = 0; } if (ddst instanceof XWindow) { ((XWindow) dsrc).ddxwindow.copyArea(((XWindow) ddst), gc, sx, sy, width, height, destx, desty); } // else{ // ((Window)dsrc).ddxwindow. // copyArea((Pixmap)ddst, gc, // sx, sy, destx, desty, width, height); // } } else { if (ddst instanceof XPixmap) { if (sx < 0) { sx = 0; } if (sy < 0) { sy = 0; } if (destx < 0) { destx = 0; } if (desty < 0) { desty = 0; } ((XPixmap) dsrc).copyArea((XPixmap) ddst, gc, sx, sy, destx, desty, width, height); } else { Image img = ((XPixmap) dsrc).getImage((XWindow) ddst, gc, sx, sy, width, height); XWindow wdst = (XWindow) ddst; if (sx == 0 && sy == 0 && width == dsrc.width && height == dsrc.height) { wdst.ddxwindow.drawImage(gc.clip_mask, img, destx, desty, width, height); } else { java.awt.Shape tmp = g.getClip(); if (destx >= 0 && desty >= 0) { g.clipRect(destx, desty, width, height); } else { g.clipRect((destx < 0 ? 0 : destx), (desty < 0 ? 0 : desty), (destx < 0 ? width + destx : width), (desty < 0 ? height + desty : height)); } wdst.ddxwindow.drawImage(gc.clip_mask, img, destx - sx, desty - sy, dsrc.width, dsrc.height); if (tmp == null) { g.setClip(0, 0, wdst.width, wdst.height); } else { g.setClip(tmp); } } wdst.draw(destx, desty, width, height); if (img != ((XPixmap) dsrc).getImage()) { img.flush(); } } } } if ((gc.attr & GC.graphicsExposures) != 0) { c.cevent.mkNoExposure(dest, 0, 62); c.sendEvent(c.cevent, 1, 0, Event.NoEventMask, null); } }