Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » FigureCanvas Transparency (regression in 3.2?)
FigureCanvas Transparency (regression in 3.2?) [message #224245] Thu, 12 October 2006 19:30 Go to next message
Eclipse UserFriend
Originally posted by: not_a_valid_email.appliedbiosystems.com

Hello all,

In my excitement to use the latest, I am in the process of upgrading our
project software from Eclispe 3.1.2 to 3.2.1. I encountered a problem that
I have distilled in the attached example and output.

The example has a FigureCanvas in a Shell. The canvas has a root figure,
and the root figure has 2 round rectangles. The example I have provided
attempts to draw a transparent rectangle on the canvas. Drawing this
transparent rectangle is as follows: when the user holds the left mouse
button down and moves from point A to point B, the rectangle is drawn based
on these 2 points.

The result using the 3.1.2 libraries is as expected - shown in
FigureCanvasTransparencyWith_3.1.2_correct.png
The result using the 3.2.1 libraries is clipped - shown in
FigureCanvasTransparencyWith_3.2.1_incorrect.png, and the transparent
rectangle is only partially shown over the 2nd child figure added.

Attached is also the source code for the snippet.

Anyone have any ideas as to what may be causing this? The same incorrect
behavior is exhibited using 3.2.0.

Thanks a bunch!
E.





Re: FigureCanvas Transparency (regression in 3.2?) [message #224452 is a reply to message #224245] Mon, 16 October 2006 13:59 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.ibm.com

You snippet's paint listener is not using draw2d or GEF, so I don't see how
this change in behavior could be because of either.

Why are you adding a second paint listener to a canvas that already has a
primary listener (draw2d)? In what state does SWT claim that a paint
listener will find the GC passed on the paint event?

"E F" <not_a_valid_email@appliedbiosystems.com> wrote in message
news:egm556$k73$1@utils.eclipse.org...
> Hello all,
>
> In my excitement to use the latest, I am in the process of upgrading our
> project software from Eclispe 3.1.2 to 3.2.1. I encountered a problem
> that I have distilled in the attached example and output.
>
> The example has a FigureCanvas in a Shell. The canvas has a root figure,
> and the root figure has 2 round rectangles. The example I have provided
> attempts to draw a transparent rectangle on the canvas. Drawing this
> transparent rectangle is as follows: when the user holds the left mouse
> button down and moves from point A to point B, the rectangle is drawn
> based on these 2 points.
>
> The result using the 3.1.2 libraries is as expected - shown in
> FigureCanvasTransparencyWith_3.1.2_correct.png
> The result using the 3.2.1 libraries is clipped - shown in
> FigureCanvasTransparencyWith_3.2.1_incorrect.png, and the transparent
> rectangle is only partially shown over the 2nd child figure added.
>
> Attached is also the source code for the snippet.
>
> Anyone have any ideas as to what may be causing this? The same incorrect
> behavior is exhibited using 3.2.0.
>
> Thanks a bunch!
> E.
>
>
>
>
Re: FigureCanvas Transparency (regression in 3.2?) [message #224498 is a reply to message #224452] Mon, 16 October 2006 16:21 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: not_a_valid_email.appliedbiosystems.com

This is a multi-part message in MIME format.
--------------040808030206060403030407
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Randy Hudson wrote:
> You snippet's paint listener is not using draw2d or GEF, so I don't see how this change in behavior could be because of either.
>
Thanks for the response, Randy.

Granted. The original snippet's paint listener is not using draw2d or
GEF. I guess I assumed that it was draw2d or GEF related because when I
use a Canvas instead of FigureCanvas, the interaction works just fine.
Attached is a the non draw2d example working as desired. So I thought
(perhaps mistakenly) that it was FigureCanvas related, and thus,
draw2d. I apologize if I made an incorrect assumption.
> Why are you adding a second paint listener to a canvas that already has a primary listener (draw2d)?
As we're not using full blown GEF, we needed to implement our own
zooming functionality. The original functionality is to allow the user
to draw a rectangle to specify the zoom extents for the figure being
displayed. In my attached example, I attempt to draw the rectangle on
top of the FigureCanvas to specify just that. If that's not the proper
way to interactively draw on top of the FigureCanvas, I would be
grateful to be led down the right path.
> In what state does SWT claim that a paint listener will find the GC passed on the paint event?
>
I will admit that I do not know that that's stated anywhere in the
documentation, but that's how the SWT snippets do it. Snippet207.java
< http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/org. eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet207 .java>
is just one example showing access to the GC via the paint listener's
paint event.
e.g.

final Image image = new Image(display, 110, 60);
...
canvas.addPaintListener(new PaintListener () {
public void paintControl(PaintEvent e) {
e.gc.drawImage(image, 30, 30);
...
...
}
}

or, from another SWT snippet:

shell.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
Rectangle rect = shell.getClientArea();
e.gc.drawOval(0, 0, rect.width - 1, rect.height - 1);
}
});

Is that not the proper way to do so?

Again, I would appreciate the help in finding the correct solution to my
problem.

Thank you!
E.


> "E F" <not_a_valid_email@appliedbiosystems.com> wrote in message
> news:egm556$k73$1@utils.eclipse.org...
>
>> Hello all,
>>
>> In my excitement to use the latest, I am in the process of upgrading our
>> project software from Eclispe 3.1.2 to 3.2.1. I encountered a problem
>> that I have distilled in the attached example and output.
>>
>> The example has a FigureCanvas in a Shell. The canvas has a root figure,
>> and the root figure has 2 round rectangles. The example I have provided
>> attempts to draw a transparent rectangle on the canvas. Drawing this
>> transparent rectangle is as follows: when the user holds the left mouse
>> button down and moves from point A to point B, the rectangle is drawn
>> based on these 2 points.
>>
>> The result using the 3.1.2 libraries is as expected - shown in
>> FigureCanvasTransparencyWith_3.1.2_correct.png
>> The result using the 3.2.1 libraries is clipped - shown in
>> FigureCanvasTransparencyWith_3.2.1_incorrect.png, and the transparent
>> rectangle is only partially shown over the 2nd child figure added.
>>
>> Attached is also the source code for the snippet.
>>
>> Anyone have any ideas as to what may be causing this? The same incorrect
>> behavior is exhibited using 3.2.0.
>>
>> Thanks a bunch!
>> E.
>>

--------------040808030206060403030407
Content-Type: text/plain;
name="CanvasTransparency.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="CanvasTransparency.java"

package standalone;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class CanvasTransparency {

private static int xStart = -1;
private static int yStart = -1;
private static int xEnd = -1;
private static int yEnd = -1;
private static boolean mouseDown = false;
private static Canvas canvas;
private static Image image;
private static CanvasTransparency instance;

public static void main(String[] args) {
final Display display = new Display();
Image tempImage = new Image(display, 110, 60);
GC gc = new GC(tempImage);
Font font = new Font(display, "Times", 30, SWT.BOLD);
gc.setFont(font);
gc.setBackground(display.getSystemColor(SWT.COLOR_RED));
gc.fillRectangle(0, 0, 110, 60);
gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
gc.drawText("SWT", 10, 10, true);
font.dispose();
gc.dispose();
image = tempImage;

instance = new CanvasTransparency();
final Shell canvasTransparencyTestShell = new Shell();
canvasTransparencyTestShell.setLayout(new FillLayout());
canvasTransparencyTestShell.setText("Canvas Transparency Test");

canvas = new Canvas(canvasTransparencyTestShell, SWT.NONE);
instance.createGesturePaintListener();
instance.createGestureOnMouseMove();
instance.createZoomGestureOnMouseClick();

canvasTransparencyTestShell.setSize(600, 400);
canvasTransparencyTestShell.open();
canvasTransparencyTestShell.layout();
while (!canvasTransparencyTestShell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}

private void createZoomGestureOnMouseClick() {
canvas.addMouseListener(new org.eclipse.swt.events.MouseAdapter() {
public void mouseDown(org.eclipse.swt.events.MouseEvent event) {
doGestureOnMouseDown(event);
}

public void mouseUp(org.eclipse.swt.events.MouseEvent event) {
doGestureOnMouseUp(event);
}
});
}

private void doGestureOnMouseDown(org.eclipse.swt.events.MouseEvent event) {
final org.eclipse.swt.events.MouseEvent e = event;
mouseDown = true;
xStart = e.x;
yStart = e.y;
}

/**
* @param event
*/
private void doGestureOnMouseUp(org.eclipse.swt.events.MouseEvent event) {
final org.eclipse.swt.events.MouseEvent e = event;
mouseDown = false;
xEnd = e.x;
yEnd = e.y;
}

private void createGestureOnMouseMove() {
canvas.addMouseMoveListener(new org.eclipse.swt.events.MouseMoveListener() {
public void mouseMove(org.eclipse.swt.events.MouseEvent e) {
if (!mouseDown) {
return;
}
xEnd = e.x;
yEnd = e.y;
canvas.redraw();
}
});
}

/**
*
*/
private void createGesturePaintListener() {
canvas.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent event) {
GC gc = event.gc;
gc.setAdvanced(true);
if (!gc.getAdvanced()){
gc.drawText("Advanced graphics not supported", 30, 30, true);
return;
}
int x = 30, y = 30;
gc.drawImage(image, x, y);
if (mouseDown) {
drawGesture(gc);
}
}
});
}

private void drawGesture(GC gc) {

org.eclipse.swt.graphics.Rectangle mouseRect = new org.eclipse.swt.graphics.Rectangle(
Math.min(xEnd, xStart), Math.min(yEnd, yStart),
Math.abs(xEnd - xStart), Math.abs(yEnd - yStart));

// draw gesture rectangle
gc.setAlpha(192);
gc.setBackground(new Color(canvas.getDisplay(), 240, 240, 240));
gc.setForeground(new Color(canvas.getDisplay(), 64, 64, 64));
gc.fillRectangle(mouseRect);
gc.drawRectangle(mouseRect);
}

}

--------------040808030206060403030407--
Re: FigureCanvas Transparency (regression in 3.2?) [message #224506 is a reply to message #224498] Mon, 16 October 2006 18:07 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.ibm.com

It seems like there is no isolation between two independant paint listeners
on a Control. So, for some reason, the GC is being left in a different state
in 3.2 than it was in 3.1.

You can fix the GC's clip by setting it back to the event's clip area.
Also, you could switch to using a figure on a transparent layer above your
primary figures. This is how marquees are done.

"E F" <not_a_valid_email@appliedbiosystems.com> wrote in message
news:eh0bii$nvc$1@utils.eclipse.org...
> Randy Hudson wrote:
>> You snippet's paint listener is not using draw2d or GEF, so I don't see
>> how this change in behavior could be because of either.
>>
> Thanks for the response, Randy.
>
> Granted. The original snippet's paint listener is not using draw2d or
> GEF. I guess I assumed that it was draw2d or GEF related because when I
> use a Canvas instead of FigureCanvas, the interaction works just fine.
> Attached is a the non draw2d example working as desired. So I thought
> (perhaps mistakenly) that it was FigureCanvas related, and thus,
> draw2d. I apologize if I made an incorrect assumption.
>> Why are you adding a second paint listener to a canvas that already has a
>> primary listener (draw2d)?
> As we're not using full blown GEF, we needed to implement our own
> zooming functionality. The original functionality is to allow the user
> to draw a rectangle to specify the zoom extents for the figure being
> displayed. In my attached example, I attempt to draw the rectangle on
> top of the FigureCanvas to specify just that. If that's not the proper
> way to interactively draw on top of the FigureCanvas, I would be
> grateful to be led down the right path.
>> In what state does SWT claim that a paint listener will find the GC
>> passed on the paint event?
>>
> I will admit that I do not know that that's stated anywhere in the
> documentation, but that's how the SWT snippets do it. Snippet207.java
> < http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/org. eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet207 .java>
> is just one example showing access to the GC via the paint listener's
> paint event.
> e.g.
>
> final Image image = new Image(display, 110, 60);
> ...
> canvas.addPaintListener(new PaintListener () {
> public void paintControl(PaintEvent e) {
> e.gc.drawImage(image, 30, 30);
> ...
> ...
> }
> }
>
> or, from another SWT snippet:
>
> shell.addPaintListener(new PaintListener() {
> public void paintControl(PaintEvent e) {
> Rectangle rect = shell.getClientArea();
> e.gc.drawOval(0, 0, rect.width - 1, rect.height - 1);
> }
> });
>
> Is that not the proper way to do so?
>
> Again, I would appreciate the help in finding the correct solution to my
> problem.
>
> Thank you!
> E.
>
>
>> "E F" <not_a_valid_email@appliedbiosystems.com> wrote in message
>> news:egm556$k73$1@utils.eclipse.org...
>>
>>> Hello all,
>>>
>>> In my excitement to use the latest, I am in the process of upgrading our
>>> project software from Eclispe 3.1.2 to 3.2.1. I encountered a problem
>>> that I have distilled in the attached example and output.
>>>
>>> The example has a FigureCanvas in a Shell. The canvas has a root
>>> figure,
>>> and the root figure has 2 round rectangles. The example I have provided
>>> attempts to draw a transparent rectangle on the canvas. Drawing this
>>> transparent rectangle is as follows: when the user holds the left mouse
>>> button down and moves from point A to point B, the rectangle is drawn
>>> based on these 2 points.
>>>
>>> The result using the 3.1.2 libraries is as expected - shown in
>>> FigureCanvasTransparencyWith_3.1.2_correct.png
>>> The result using the 3.2.1 libraries is clipped - shown in
>>> FigureCanvasTransparencyWith_3.2.1_incorrect.png, and the transparent
>>> rectangle is only partially shown over the 2nd child figure added.
>>>
>>> Attached is also the source code for the snippet.
>>>
>>> Anyone have any ideas as to what may be causing this? The same
>>> incorrect
>>> behavior is exhibited using 3.2.0.
>>>
>>> Thanks a bunch!
>>> E.
>>>
>


------------------------------------------------------------ --------------------


> package standalone;
>
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.events.PaintEvent;
> import org.eclipse.swt.events.PaintListener;
> import org.eclipse.swt.graphics.Color;
> import org.eclipse.swt.graphics.Font;
> import org.eclipse.swt.graphics.GC;
> import org.eclipse.swt.graphics.Image;
> import org.eclipse.swt.layout.FillLayout;
> import org.eclipse.swt.widgets.Canvas;
> import org.eclipse.swt.widgets.Display;
> import org.eclipse.swt.widgets.Shell;
>
> public class CanvasTransparency {
>
> private static int xStart = -1;
> private static int yStart = -1;
> private static int xEnd = -1;
> private static int yEnd = -1;
> private static boolean mouseDown = false;
> private static Canvas canvas;
> private static Image image;
> private static CanvasTransparency instance;
>
> public static void main(String[] args) {
> final Display display = new Display();
> Image tempImage = new Image(display, 110, 60);
> GC gc = new GC(tempImage);
> Font font = new Font(display, "Times", 30, SWT.BOLD);
> gc.setFont(font);
> gc.setBackground(display.getSystemColor(SWT.COLOR_RED));
> gc.fillRectangle(0, 0, 110, 60);
> gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
> gc.drawText("SWT", 10, 10, true);
> font.dispose();
> gc.dispose();
> image = tempImage;
>
> instance = new CanvasTransparency();
> final Shell canvasTransparencyTestShell = new Shell();
> canvasTransparencyTestShell.setLayout(new FillLayout());
> canvasTransparencyTestShell.setText("Canvas Transparency Test");
>
> canvas = new Canvas(canvasTransparencyTestShell, SWT.NONE);
> instance.createGesturePaintListener();
> instance.createGestureOnMouseMove();
> instance.createZoomGestureOnMouseClick();
>
> canvasTransparencyTestShell.setSize(600, 400);
> canvasTransparencyTestShell.open();
> canvasTransparencyTestShell.layout();
> while (!canvasTransparencyTestShell.isDisposed()) {
> if (!display.readAndDispatch())
> display.sleep();
> }
> }
>
> private void createZoomGestureOnMouseClick() {
> canvas.addMouseListener(new org.eclipse.swt.events.MouseAdapter() {
> public void mouseDown(org.eclipse.swt.events.MouseEvent event) {
> doGestureOnMouseDown(event);
> }
>
> public void mouseUp(org.eclipse.swt.events.MouseEvent event) {
> doGestureOnMouseUp(event);
> }
> });
> }
>
> private void doGestureOnMouseDown(org.eclipse.swt.events.MouseEvent
> event) {
> final org.eclipse.swt.events.MouseEvent e = event;
> mouseDown = true;
> xStart = e.x;
> yStart = e.y;
> }
>
> /**
> * @param event
> */
> private void doGestureOnMouseUp(org.eclipse.swt.events.MouseEvent event)
> {
> final org.eclipse.swt.events.MouseEvent e = event;
> mouseDown = false;
> xEnd = e.x;
> yEnd = e.y;
> }
>
> private void createGestureOnMouseMove() {
> canvas.addMouseMoveListener(new
> org.eclipse.swt.events.MouseMoveListener() {
> public void mouseMove(org.eclipse.swt.events.MouseEvent e) {
> if (!mouseDown) {
> return;
> }
> xEnd = e.x;
> yEnd = e.y;
> canvas.redraw();
> }
> });
> }
>
> /**
> *
> */
> private void createGesturePaintListener() {
> canvas.addPaintListener(new PaintListener() {
> public void paintControl(PaintEvent event) {
> GC gc = event.gc;
> gc.setAdvanced(true);
> if (!gc.getAdvanced()){
> gc.drawText("Advanced graphics not supported", 30, 30, true);
> return;
> }
> int x = 30, y = 30;
> gc.drawImage(image, x, y);
> if (mouseDown) {
> drawGesture(gc);
> }
> }
> });
> }
>
> private void drawGesture(GC gc) {
>
> org.eclipse.swt.graphics.Rectangle mouseRect = new
> org.eclipse.swt.graphics.Rectangle(
> Math.min(xEnd, xStart), Math.min(yEnd, yStart),
> Math.abs(xEnd - xStart), Math.abs(yEnd - yStart));
>
> // draw gesture rectangle
> gc.setAlpha(192);
> gc.setBackground(new Color(canvas.getDisplay(), 240, 240, 240));
> gc.setForeground(new Color(canvas.getDisplay(), 64, 64, 64));
> gc.fillRectangle(mouseRect);
> gc.drawRectangle(mouseRect);
> }
>
> }
>
Re: FigureCanvas Transparency (regression in 3.2?) [message #224619 is a reply to message #224506] Tue, 17 October 2006 15:46 Go to previous message
Eclipse UserFriend
Originally posted by: not_a_valid_email.appliedbiosystems.com

Thanks, Randy.

Setting the GC's clip did the trick. I'll look into the transparent
layer option too.

Thanks again,
E.


Randy Hudson wrote:
> It seems like there is no isolation between two independant paint listeners on a Control. So, for some reason, the GC is being left in a different state in 3.2 than it was in 3.1.
>
> You can fix the GC's clip by setting it back to the event's clip area. Also, you could switch to using a figure on a transparent layer above your primary figures. This is how marquees are done.
>
Previous Topic:Three requests
Next Topic:How to put a TextField in a ToolBar?
Goto Forum:
  


Current Time: Fri Mar 29 05:21:43 GMT 2024

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

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

Back to the top