Possible To Predraw things on the 'Canvas'?

SWT Designer allows you to create the views, editors, perspectives, pref pages, composites, etc. that comprise Eclipse SWT & RCP applications and plug-ins.

Moderators: Konstantin.Scheglov, gnebling, Alexander.Mitin, jwren, Eric Clayberg

Possible To Predraw things on the 'Canvas'?

Postby Andrew_of_New_Zealand » Tue Jul 19, 2005 9:05 pm

I'm creating a video game interface and want to see if i can use a canvas 'widget' as a video screen. Can anyone tell me how to draw pictures on the canvas?
Andrew_of_New_Zealand
 
Posts: 8
Joined: Mon Jul 11, 2005 10:14 pm

Re: Possible To Predraw things on the 'Canvas'?

Postby Eric Clayberg » Wed Jul 20, 2005 3:36 am

Andrew_of_New_Zealand wrote:I'm creating a video game interface and want to see if i can use a canvas 'widget' as a video screen. Can anyone tell me how to draw pictures on the canvas?

The following page has an impressive collection of SWT canvas drawing examples...

Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA

Postby Andrew_of_New_Zealand » Thu Jul 21, 2005 7:52 pm

Right thanks. This'll give me something to go on.
Andrew_of_New_Zealand
 
Posts: 8
Joined: Mon Jul 11, 2005 10:14 pm

Postby Andrew_of_New_Zealand » Thu Jul 21, 2005 8:56 pm

Eric or anyone, do you know if you can clear a canvas, ready to print a new 'screen' (or canvas-painting, which ever you want to call it)? I've set a button to progress from Title Screen to Start Screen (My game is called "Jolly Joy Stick"), but am I able to use a SWT instruction to bare a canvas for the next screen? I've looked through the list of things you can do with a canvas, but couldn't find an instruction that does that.

Well thanks.
Andrew_of_New_Zealand
 
Posts: 8
Joined: Mon Jul 11, 2005 10:14 pm

Postby Kelly » Fri Jul 22, 2005 4:52 am

I am no expert but you might have to use the GC class and use fillRectangle method to draw a solid color onto the image.

A good site that helps me is
http://dev.eclipse.org/viewcvs/index.cg ... e/dev.html
Kelly
 
Posts: 38
Joined: Wed Feb 02, 2005 8:22 am

Postby Andrew_of_New_Zealand » Sat Jul 23, 2005 1:50 am

Thanks Kelly, yes they way you discribe reminds me of image drawing I used to do with the Java abstract window toolkit.
Over writing images I knew to be onscreen didn't seem like a very easy way of doing it, but I guess, if theres no other way, I'll make progress that way.
Andrew_of_New_Zealand
 
Posts: 8
Joined: Mon Jul 11, 2005 10:14 pm

Postby Andrew_of_New_Zealand » Mon Jul 25, 2005 10:45 pm

lol. there is the 'e.gc' (is it PaintEvent-Graphics Controller?), has a big stack of drawing functions with it, but even the dispose function won't clear the canvas. I've even tried the delete function. There is a Java delete function isn't there?

Well I guess might be some way to do what I want to do, if I keep tryying.
I can't find the right 'e.gc' function for deleting ovals and strings yet.
Andrew_of_New_Zealand
 
Posts: 8
Joined: Mon Jul 11, 2005 10:14 pm

Postby Kelly » Tue Jul 26, 2005 4:03 am

The one way I used to erase the last object drawn on an image was to keep a copy of the image being drawn on and using the

GC gc = new GC(canvas);
gc.drawImage(savedimg, x, y, w, h, x, y, w, h);

This copies a rectangle from savedimg to the canvas.

If you want to undo more than one event then you need to save copies of the area being drawn on in memory or on disk.

This is from my limited adventures into writing drawning programs in java.

You might look at http://alistairdickie.com/ at the free java drawing program thier for ideas.
Kelly
 
Posts: 38
Joined: Wed Feb 02, 2005 8:22 am

Postby Andrew_of_New_Zealand » Thu Jul 28, 2005 8:16 pm

Thanks, I'll try some of this some time. Right now I'm deviating from my little game, to attmepted to do this Doctor-Office building computer project, that the school has set us.
Andrew_of_New_Zealand
 
Posts: 8
Joined: Mon Jul 11, 2005 10:14 pm


Return to SWT Designer

Who is online

Users browsing this forum: No registered users and 1 guest