Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » gc.setClipping
gc.setClipping [message #458778] Wed, 20 July 2005 23:19 Go to next message
Connie Lam is currently offline Connie LamFriend
Messages: 24
Registered: July 2009
Junior Member
Hi,

On Windows, I was trying to set a clipping region on the GC, do some
painting, reset the clipping region and do some more painting:

public static void main(String[] args) {
final Display display = new Display();
final Shell shell = new Shell(display);

shell.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent event) {
GC gc = event.gc;
Display display = event.display;
Transform transform = new Transform(display);
gc.setTransform(transform); // <-- clipping is fine if I
comment this line

/* Set the clipping region. */
Region region = new Region(display);
gc.getClipping(region);
gc.setClipping(50, 50, 100, 100);

/* Do some painting. */
gc.setBackground(display.getSystemColor(SWT.COLOR_RED));
gc.fillRectangle(50, 50, 100, 100);

/* Restore the clipping region. */
gc.setClipping(/* (Region)null */region);

/* Do some more painting. */
gc.fillRectangle(200, 50, 100, 100);

transform.dispose();
region.dispose();
}
});

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

Whatever is painted after restoring the clipping region does not show up
on the shell - it seems that the clipping region is not reset properly.
However, clipping works fine if I don't set the transform on the GC.

I found a bug with the similar problem:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=103642

Then I tried to reset my GC by calling gc.setClipping((Region)null) and it
works!

Question:
Is there any difference between calling

gc.getClipping(region);
gc.setClipping(...);
gc.setClipping(region);

vs.

gc.setClipping(...);
gc.setClipping((Region)null);?

Thanks,
Connie
Re: gc.setClipping [message #458853 is a reply to message #458778] Fri, 22 July 2005 21:31 Go to previous messageGo to next message
Michael Baehr is currently offline Michael BaehrFriend
Messages: 5
Registered: July 2009
Junior Member
Connie,

the bug you mentioned was fixed today. It's surely worth a try to
check the newest SWT build.

Michael

On Wed, 20 Jul 2005 23:19:39 +0000 (UTC), kkconcome@yahoo.com (Connie
Lam) wrote:

>Hi,
>
>On Windows, I was trying to set a clipping region on the GC, do some
>painting, reset the clipping region and do some more painting:
>
>public static void main(String[] args) {
> final Display display = new Display();
> final Shell shell = new Shell(display);
>
> shell.addPaintListener(new PaintListener() {
> public void paintControl(PaintEvent event) {
> GC gc = event.gc;
> Display display = event.display;
> Transform transform = new Transform(display);
> gc.setTransform(transform); // <-- clipping is fine if I
>comment this line
>
> /* Set the clipping region. */
> Region region = new Region(display);
> gc.getClipping(region);
> gc.setClipping(50, 50, 100, 100);
>
> /* Do some painting. */
> gc.setBackground(display.getSystemColor(SWT.COLOR_RED));
> gc.fillRectangle(50, 50, 100, 100);
>
> /* Restore the clipping region. */
> gc.setClipping(/* (Region)null */region);
>
> /* Do some more painting. */
> gc.fillRectangle(200, 50, 100, 100);
>
> transform.dispose();
> region.dispose();
> }
> });
>
> shell.open();
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch()) display.sleep();
> }
> display.dispose();
> }
>
>Whatever is painted after restoring the clipping region does not show up
>on the shell - it seems that the clipping region is not reset properly.
>However, clipping works fine if I don't set the transform on the GC.
>
>I found a bug with the similar problem:
>https://bugs.eclipse.org/bugs/show_bug.cgi?id=103642
>
>Then I tried to reset my GC by calling gc.setClipping((Region)null) and it
>works!
>
>Question:
>Is there any difference between calling
>
>gc.getClipping(region);
>gc.setClipping(...);
>gc.setClipping(region);
>
>vs.
>
>gc.setClipping(...);
>gc.setClipping((Region)null);?
>
>Thanks,
>Connie
Re: gc.setClipping [message #458977 is a reply to message #458853] Wed, 27 July 2005 18:51 Go to previous message
Connie Lam is currently offline Connie LamFriend
Messages: 24
Registered: July 2009
Junior Member
Thanks Michael! Unfortunately my code still doesn't work with the latest
build. The problem I encountered is a little different from the one
described in the bug report. I'll file a separate bug for it.

Thanks,
Connie

Michael Baehr wrote:

> Connie,

> the bug you mentioned was fixed today. It's surely worth a try to
> check the newest SWT build.

> Michael

> On Wed, 20 Jul 2005 23:19:39 +0000 (UTC), kkconcome@yahoo.com (Connie
> Lam) wrote:

>>Hi,
>>
>>On Windows, I was trying to set a clipping region on the GC, do some
>>painting, reset the clipping region and do some more painting:
>>
>>public static void main(String[] args) {
>> final Display display = new Display();
>> final Shell shell = new Shell(display);
>>
>> shell.addPaintListener(new PaintListener() {
>> public void paintControl(PaintEvent event) {
>> GC gc = event.gc;
>> Display display = event.display;
>> Transform transform = new Transform(display);
>> gc.setTransform(transform); // <-- clipping is fine if I
>>comment this line
>>
>> /* Set the clipping region. */
>> Region region = new Region(display);
>> gc.getClipping(region);
>> gc.setClipping(50, 50, 100, 100);
>>
>> /* Do some painting. */
>> gc.setBackground(display.getSystemColor(SWT.COLOR_RED));
>> gc.fillRectangle(50, 50, 100, 100);
>>
>> /* Restore the clipping region. */
>> gc.setClipping(/* (Region)null */region);
>>
>> /* Do some more painting. */
>> gc.fillRectangle(200, 50, 100, 100);
>>
>> transform.dispose();
>> region.dispose();
>> }
>> });
>>
>> shell.open();
>> while (!shell.isDisposed()) {
>> if (!display.readAndDispatch()) display.sleep();
>> }
>> display.dispose();
>> }
>>
>>Whatever is painted after restoring the clipping region does not show up
>>on the shell - it seems that the clipping region is not reset properly.
>>However, clipping works fine if I don't set the transform on the GC.
>>
>>I found a bug with the similar problem:
>>https://bugs.eclipse.org/bugs/show_bug.cgi?id=103642
>>
>>Then I tried to reset my GC by calling gc.setClipping((Region)null) and it
>>works!
>>
>>Question:
>>Is there any difference between calling
>>
>>gc.getClipping(region);
>>gc.setClipping(...);
>>gc.setClipping(region);
>>
>>vs.
>>
>>gc.setClipping(...);
>>gc.setClipping((Region)null);?
>>
>>Thanks,
>>Connie
Previous Topic:HIDE_SELECTION in Table
Next Topic:Deranged wizard pages
Goto Forum:
  


Current Time: Wed Oct 21 07:56:09 GMT 2020

Powered by FUDForum. Page generated in 0.02354 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top