Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 312242 - Add support for clipRect functionality similar that J2D implements
Summary: Add support for clipRect functionality similar that J2D implements
Status: CLOSED DUPLICATE of bug 87776
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.0   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-05-10 08:13 EDT by antti.tirkkonen CLA
Modified: 2010-05-10 08:17 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description antti.tirkkonen CLA 2010-05-10 08:13:02 EDT
Build Identifier: 

Currently there is no way of giving intersection of clips. 
This would be very usefull from nested "figures" point of view. 
GEF/Draw2d would benefit a lot as at the moment they are implementing it by them selves. Also this would enable possibility to support rotate in Draw2d/GEF/GMF.

I did some dummy implementation for Windows:
    void clipRect(int /* long */clipRgn) {
        int /* long */hRgn = clipRgn;
        int /* long */gdipGraphics = data.gdipGraphics;
        if (gdipGraphics != 0) {
            if (hRgn != 0) {
                int /* long */region = Gdip.Region_new(hRgn);
                Gdip.Graphics_SetClip(gdipGraphics, region, Gdip.CombineModeIntersect);
                Gdip.Region_delete(region);
            } else {
                Gdip.Graphics_ResetClip(gdipGraphics);
            }
        } else {
            POINT pt = null;
            if (hRgn != 0 && !OS.IsWinCE) {
                pt = new POINT();
                OS.GetWindowOrgEx(handle, pt);
                OS.OffsetRgn(hRgn, -pt.x, -pt.y);
            }
            OS.SelectClipRgn(handle, hRgn);
            if (hRgn != 0 && !OS.IsWinCE) {
                OS.OffsetRgn(hRgn, pt.x, pt.y);
            }
        }
        if (hRgn != 0 && hRgn != clipRgn) {
            OS.DeleteObject(hRgn);
        }
    }

    public void clipRect(int x, int y, int width, int height) {
        if (handle == 0)
            SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
        int /* long */hRgn = OS.CreateRectRgn(x, y, x + width, y + height);
        clip(hRgn);
        OS.DeleteObject(hRgn);
    }



Reproducible: Always

Steps to Reproduce:
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.graphics.Transform;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class NestedRectangles {
    static Shell shell;

  public static void main(String[] args) {

        Display display = Display.getDefault();
        shell = new Shell(display);
        shell.addPaintListener(new PaintListener() {
            public void paintControl(PaintEvent e) {
                e.gc.setBackground(new Color(null, 255, 0, 0));
                Rectangle bounds1 = new Rectangle(100, 100, 200, 100);
                e.gc.fillRectangle(bounds1);
                e.gc.setClipping(bounds1);
                Transform transform = new Transform(Display.getCurrent());
                Rectangle bounds2 = new Rectangle(100, 100, 100, 200);
                transform.translate(bounds2.x + bounds2.width / 2, bounds2.y + bounds2.height / 2);
                transform.rotate(15);
                transform.translate(-(bounds2.x + bounds2.width / 2), -(bounds2.y + bounds2.height / 2));
                e.gc.setTransform(transform);

                e.gc.clip(bounds2.x, bounds2.y, bounds2.width, bounds2.height);
                e.gc.setBackground(new Color(null, 0, 255, 0));
                e.gc.fillRectangle(bounds2);
                e.gc.setBackground(new Color(null, 0, 0, 255));
                e.gc.fillRectangle(bounds2.x - 20, bounds2.y + 50, bounds2.width + 40, 20);

                e.gc.setTransform(null);
            }
        });
    shell.open();


    while (!shell.isDisposed()) {
      if (!display.readAndDispatch())
        display.sleep();
    }

    display.dispose();
  }
Comment 1 antti.tirkkonen CLA 2010-05-10 08:17:01 EDT

*** This bug has been marked as a duplicate of bug 87776 ***