Really bad hack, someone suggest something better please :) [message #442383] |
Thu, 02 September 2004 19:39 |
Andrew Brampton Messages: 8 Registered: July 2009 |
Junior Member |
|
|
Hi,
I was thinking of a control inspired from my Visual Basic days...
In VB I could set a AutoRedraw property to true, and anything I drew on my
form would be remembered... Such that I could draw, cover the form, bring it
back and voila my drawing is still there.
Now I considered having a similar thing in SWT. I wanted to alter something
like so:
GC gc = new GC(Canvas);
gc.drawSomething();
gc.dispose();
and on my canvas my drawing would appear... However cover up the canvas and
bring it back and doh the drawing had gone...
If I wanted custom drawing on my canvas I would normally listen for the
paint events and draw inside them, but I wanted this to be slightly
different.
I first created a new class that extended Canvas and had a private Image
variable which would store the actual drawing. Then anything outside would
draw to this image instead of the Canvas.. This worked, but I didn't like it
because I would have to do canvas.getImage() and draw on that... Instead I
wanted to just draw on the canvas and by some magic it would know and store
the drawing in the image.
I hacked up a pretty bad solution to this by overriding the internal_new_GC
and internal_dispose_GC methods to return image.internal_dispose_GC instead
of canvas.internal_dispose_GC. Now that didn't work to begin with because
when the canvas was drawn it would be drawing the image instead. So I made
it check the stack and see where the internal_dispose_GC was coming from. If
we were inside some SWT code, then return the canvas, otherwise return my
image.
This solution is working, but I wanted to ask if there is a proper nicer
solution? I fully understand this is not how I should be using SWT, and I
did notice the big warning in the SWT docs about internal_dispose_GC, but I
like giving myself challenges and finding solutions :)
If you wish to check my code out look here:
http://me.bramp.net/java/MemoryCanvas.java
http://me.bramp.net/java/PrinterTest.java
Thanks
Andrew
|
|
|
Re: Really bad hack, someone suggest something better please :) [message #442387 is a reply to message #442383] |
Thu, 02 September 2004 21:51 |
Charlie Surface Messages: 40 Registered: July 2009 |
Member |
|
|
I would ditch this code based solely on the statement: "So I made it check
the stack and see where the internal_dispose_GC was coming from." I think
you would be better off just using the simple double-buffering solution that
you tried originally. Of course, you could always poke around in the SWT or
JFace source to see if any of the custom widgets have implemented double
buffering.
Charlie
"Andrew Brampton" <andrew@bramp.freeserve.co.uk> wrote in message
news:ch7snq$u45$1@eclipse.org...
> Hi,
>
> I was thinking of a control inspired from my Visual Basic days...
>
> In VB I could set a AutoRedraw property to true, and anything I drew on my
> form would be remembered... Such that I could draw, cover the form, bring
it
> back and voila my drawing is still there.
>
>
>
> Now I considered having a similar thing in SWT. I wanted to alter
something
> like so:
>
> GC gc = new GC(Canvas);
>
> gc.drawSomething();
>
> gc.dispose();
>
>
>
> and on my canvas my drawing would appear... However cover up the canvas
and
> bring it back and doh the drawing had gone...
>
>
>
> If I wanted custom drawing on my canvas I would normally listen for the
> paint events and draw inside them, but I wanted this to be slightly
> different.
>
>
>
> I first created a new class that extended Canvas and had a private Image
> variable which would store the actual drawing. Then anything outside would
> draw to this image instead of the Canvas.. This worked, but I didn't like
it
> because I would have to do canvas.getImage() and draw on that... Instead I
> wanted to just draw on the canvas and by some magic it would know and
store
> the drawing in the image.So I made
> it check the stack and see where the internal_dispose_GC was coming from.
>
>
>
> I hacked up a pretty bad solution to this by overriding the
internal_new_GC
> and internal_dispose_GC methods to return image.internal_dispose_GC
instead
> of canvas.internal_dispose_GC. Now that didn't work to begin with because
> when the canvas was drawn it would be drawing the image instead. If
> we were inside some SWT code, then return the canvas, otherwise return my
> image.
>
>
>
> This solution is working, but I wanted to ask if there is a proper nicer
> solution? I fully understand this is not how I should be using SWT, and I
> did notice the big warning in the SWT docs about internal_dispose_GC, but
I
> like giving myself challenges and finding solutions :)
>
>
>
> If you wish to check my code out look here:
>
> http://me.bramp.net/java/MemoryCanvas.java
>
> http://me.bramp.net/java/PrinterTest.java
>
>
>
> Thanks
>
> Andrew
>
>
>
>
|
|
|
Powered by
FUDForum. Page generated in 0.03545 seconds