Example usage for java.awt Graphics clipRect

List of usage examples for java.awt Graphics clipRect

Introduction

In this page you can find the example usage for java.awt Graphics clipRect.

Prototype

public abstract void clipRect(int x, int y, int width, int height);

Source Link

Document

Intersects the current clip with the specified rectangle.

Usage

From source file:com.jcraft.weirdx.XWindow.java

static final void reqCopyArea(Client c) throws IOException {
    int foo;/*from w  ww  .  ja v  a2s  . com*/
    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);
    }
}

From source file:org.jcurl.svg.Graphics2Svg.java

@Override
public Graphics create(final int x, final int y, final int width, final int height) {
    try {/*  ww w . j a  va2 s.  c o  m*/
        dst.comment("create");
    } catch (final SAXException e) {
        throw new RuntimeException("Unhandled", e);
    }
    log.info("implemented");
    final Graphics ret = create();
    ret.clipRect(x, y, width, height);
    return ret;
}