Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Text on a GC
Text on a GC [message #466888] Wed, 18 January 2006 23:03 Go to next message
Adam Kumpf is currently offline Adam KumpfFriend
Messages: 14
Registered: July 2009
Junior Member
Hello all.

I have a canvas with lots of objects. (painted lines, rectangles, etc.)
and would like to place a text editor on the top of it.. The most
straight-forward way I see to get all the functionality of a word
processor is to simply use a "Text" or "StyledText" widget. The problem
is that is paints the background white (or some other color) no matter
what I try. I thought the SWT.NO_BACKGROUND style might do the trick, but
no luck there either. I also thought a LineBackgroundListener could work
by setting the background color to null, but it still paints it white.

The items on my canvas are being drawn by the Paint method in my canvas.
I pass the GC, location, and some other variables to the objects on the
canvas and they paint themselves. Does anyone have any good ideas on how
I can make a nice text editor following this same form?? i.e. having
access to the paint method of the object so I can paint it where I want it
on my existing canvas's GC (maybe even transform the GC first to do
dynamic scaling of text.. fun fun!). The "TextLayout" seems to get close,
but doesn't have any of the functionality to handle cursors and seems to
undo any transformations to the GC I pass to it. I implemented most of
what I need with the TextLayout and a simple cursor, but it's very clunky
and slow and will need TONs of hours of testing to catch all the little
edge cases that SWT has already done a nice job considering. Any ideas?

Thanks so much for your help. :)

Best Regards,
Adam Kumpf
kumpf@mit.edu
http://web.mit.edu/kumpf/www/
Re: Text on a GC [message #466899 is a reply to message #466888] Thu, 19 January 2006 02:16 Go to previous messageGo to next message
Jeremy Dowdall is currently offline Jeremy DowdallFriend
Messages: 48
Registered: July 2009
Member
there's no transparent background for SWT widgets, so have you tried
using the StyledText widget as the Canvas and drawing your objects in
its paint method?

are these objects able to be selected and moved / resized? if so, GEF
may be helpful (they also have a wysiwyg text editor example that may
prove interesting)


Adam Kumpf wrote:
> Hello all.
>
> I have a canvas with lots of objects. (painted lines, rectangles, etc.)
> and would like to place a text editor on the top of it.. The most
> straight-forward way I see to get all the functionality of a word
> processor is to simply use a "Text" or "StyledText" widget. The problem
> is that is paints the background white (or some other color) no matter
> what I try. I thought the SWT.NO_BACKGROUND style might do the trick,
> but no luck there either. I also thought a LineBackgroundListener could
> work by setting the background color to null, but it still paints it white.
>
> The items on my canvas are being drawn by the Paint method in my
> canvas. I pass the GC, location, and some other variables to the
> objects on the canvas and they paint themselves. Does anyone have any
> good ideas on how I can make a nice text editor following this same
> form?? i.e. having access to the paint method of the object so I can
> paint it where I want it on my existing canvas's GC (maybe even
> transform the GC first to do dynamic scaling of text.. fun fun!). The
> "TextLayout" seems to get close, but doesn't have any of the
> functionality to handle cursors and seems to undo any transformations to
> the GC I pass to it. I implemented most of what I need with the
> TextLayout and a simple cursor, but it's very clunky and slow and will
> need TONs of hours of testing to catch all the little edge cases that
> SWT has already done a nice job considering. Any ideas?
>
> Thanks so much for your help. :)
>
> Best Regards,
> Adam Kumpf
> kumpf@mit.edu
> http://web.mit.edu/kumpf/www/
>
>
Re: Text on a GC [message #466942 is a reply to message #466899] Thu, 19 January 2006 15:09 Go to previous messageGo to next message
Jan is currently offline JanFriend
Messages: 10
Registered: July 2009
Junior Member
Jeremy Dowdall wrote:
> there's no transparent background for SWT widgets, so have you tried
> using the StyledText widget as the Canvas and drawing your objects in
> its paint method?
>
> are these objects able to be selected and moved / resized? if so, GEF
> may be helpful (they also have a wysiwyg text editor example that may
> prove interesting)
>
>
> Adam Kumpf wrote:
>
>> Hello all.
>>
>> I have a canvas with lots of objects. (painted lines, rectangles,
>> etc.) and would like to place a text editor on the top of it.. The
>> most straight-forward way I see to get all the functionality of a word
>> processor is to simply use a "Text" or "StyledText" widget. The
>> problem is that is paints the background white (or some other color)
>> no matter what I try. I thought the SWT.NO_BACKGROUND style might do
>> the trick, but no luck there either. I also thought a
>> LineBackgroundListener could work by setting the background color to
>> null, but it still paints it white.
>>
>> The items on my canvas are being drawn by the Paint method in my
>> canvas. I pass the GC, location, and some other variables to the
>> objects on the canvas and they paint themselves. Does anyone have any
>> good ideas on how I can make a nice text editor following this same
>> form?? i.e. having access to the paint method of the object so I can
>> paint it where I want it on my existing canvas's GC (maybe even
>> transform the GC first to do dynamic scaling of text.. fun fun!). The
>> "TextLayout" seems to get close, but doesn't have any of the
>> functionality to handle cursors and seems to undo any transformations
>> to the GC I pass to it. I implemented most of what I need with the
>> TextLayout and a simple cursor, but it's very clunky and slow and will
>> need TONs of hours of testing to catch all the little edge cases that
>> SWT has already done a nice job considering. Any ideas?
>>
>> Thanks so much for your help. :)
>>
>> Best Regards,
>> Adam Kumpf
>> kumpf@mit.edu
>> http://web.mit.edu/kumpf/www/
>>
>>
there is just use the latest development release 3.2 M4 and see this
snippet
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet214.java?rev=HEAD& amp;content-type=text/vnd.viewcvs-markup
Re: Text on a GC [message #466944 is a reply to message #466942] Thu, 19 January 2006 17:20 Go to previous messageGo to next message
Adam Kumpf is currently offline Adam KumpfFriend
Messages: 14
Registered: July 2009
Junior Member
Jan wrote:

> Jeremy Dowdall wrote:
>> there's no transparent background for SWT widgets, so have you tried
>> using the StyledText widget as the Canvas and drawing your objects in
>> its paint method?
>>
>> are these objects able to be selected and moved / resized? if so, GEF
>> may be helpful (they also have a wysiwyg text editor example that may
>> prove interesting)
>>
>>
>> Adam Kumpf wrote:
>>
>>> Hello all.
>>>
>>> I have a canvas with lots of objects. (painted lines, rectangles,
>>> etc.) and would like to place a text editor on the top of it.. The
>>> most straight-forward way I see to get all the functionality of a word
>>> processor is to simply use a "Text" or "StyledText" widget. The
>>> problem is that is paints the background white (or some other color)
>>> no matter what I try. I thought the SWT.NO_BACKGROUND style might do
>>> the trick, but no luck there either. I also thought a
>>> LineBackgroundListener could work by setting the background color to
>>> null, but it still paints it white.
>>>
>>> The items on my canvas are being drawn by the Paint method in my
>>> canvas. I pass the GC, location, and some other variables to the
>>> objects on the canvas and they paint themselves. Does anyone have any
>>> good ideas on how I can make a nice text editor following this same
>>> form?? i.e. having access to the paint method of the object so I can
>>> paint it where I want it on my existing canvas's GC (maybe even
>>> transform the GC first to do dynamic scaling of text.. fun fun!). The
>>> "TextLayout" seems to get close, but doesn't have any of the
>>> functionality to handle cursors and seems to undo any transformations
>>> to the GC I pass to it. I implemented most of what I need with the
>>> TextLayout and a simple cursor, but it's very clunky and slow and will
>>> need TONs of hours of testing to catch all the little edge cases that
>>> SWT has already done a nice job considering. Any ideas?
>>>
>>> Thanks so much for your help. :)
>>>
>>> Best Regards,
>>> Adam Kumpf
>>> kumpf@mit.edu
>>> http://web.mit.edu/kumpf/www/
>>>
>>>
> there is just use the latest development release 3.2 M4 and see this
> snippet
>
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet214.java?rev=HEAD& amp;content-type=text/vnd.viewcvs-markup


It seems like lots of people are in the same boat here. I think it is
clever to suggest setting the background image of a component to mimic
transparency, however, computationaly this must be very expensive...
especially if the underlying objects change somewhat often.

I'm sure that I'm over-simplifying, but shouldn't it be fairly straight
forward to implement the "NO_BACKGROUND" style fairly easily within a
component? In fact, most of it can probably be done at a higher level
class that most of the components use.. I think it boils down to this:
1. If no double buffering is used, simply do not paint/fill any color
for the background. This makes the component transparent.
2. If double-buffering is being used, allow the image to start out
transparent instead of with a background color. Transparency seems to
work when I load images, so I imagine if the offScreenImage is initializd
as transparent (instead of White, for example), then checking for the
style NO_BACKGROUND and choosing not to fill the background color on the
offScreenImage should work..


What do people think about this? This would probably be a pretty big
step forward for SWT as you could do some pretty advanced things in a
hurry (and do them quickly without excessing computation!!).

Thanks,
Adam
kumpf@mit.edu
http://web.mit.edu/kumpf/www/
Re: Text on a GC [message #466946 is a reply to message #466944] Thu, 19 January 2006 17:39 Go to previous messageGo to next message
Jeff Myers is currently offline Jeff MyersFriend
Messages: 489
Registered: July 2009
Senior Member
Adam,

With SWT, the native OS is responsible for drawing widgets. Changing the
drawing behavior to act as you describe only would work if the native
operating system widgets on all platforms could do what you want. So
basically the answer is if you want to do custom text widget drawing,
you're better off emulating a text widget yourself - as the GEF project
has done, rather than relying on the SWT widget.

Hope this helps,
- Jeff
Re: Text on a GC [message #466949 is a reply to message #466946] Thu, 19 January 2006 19:31 Go to previous message
Adam Kumpf is currently offline Adam KumpfFriend
Messages: 14
Registered: July 2009
Junior Member
Jeff Myers wrote:

> Adam,

> With SWT, the native OS is responsible for drawing widgets. Changing the
> drawing behavior to act as you describe only would work if the native
> operating system widgets on all platforms could do what you want. So
> basically the answer is if you want to do custom text widget drawing,
> you're better off emulating a text widget yourself - as the GEF project
> has done, rather than relying on the SWT widget.

> Hope this helps,
> - Jeff

Thank Jeff,

that makes a lot of sense. It's hard to know where the real lines of
compatability are since I only really code on one OS. What you said seems
quite logical and I guess that brings me back to square one.. emulating my
own version of a text widget to get the desired transparency and redraw
behavior. :)

Thanks again,
Adam
kumpf@mit.edu
Previous Topic:Transparent
Next Topic:FormLayout aligning to biggest label?
Goto Forum:
  


Current Time: Thu Mar 28 08:26:38 GMT 2024

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

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

Back to the top