Drawing in a GUI

J

Joe Van Dyk

So, I have a bunch of objects that are responsible for drawing on something
on the screen (in this case, a GnomeCanvas object).

Say I need to have a grid drawn on this canvas. In order to draw a line, I
need to call Gnome::CanvasLine with a reference to the GnomeCanvas I want to
draw on (and various other details about the line).

If I have a Grid class

class Grid
def draw_grid
...
end
end

How should I tell Grid what GnomeCanvas to draw on? Pass it in when it's
initialized? For some reason, that doesn't seem like the best thing to do.

Any ideas?
 
L

Lyndon Samson

How should I tell Grid what GnomeCanvas to draw on? Pass it in when it's
initialized? For some reason, that doesn't seem like the best thing to do.

Using components have something like

paint(paintContext)
 
B

Brian Schröder

So, I have a bunch of objects that are responsible for drawing on something
on the screen (in this case, a GnomeCanvas object).

Say I need to have a grid drawn on this canvas. In order to draw a line, I
need to call Gnome::CanvasLine with a reference to the GnomeCanvas I want to
draw on (and various other details about the line).

If I have a Grid class

class Grid
def draw_grid
...
end
end

How should I tell Grid what GnomeCanvas to draw on? Pass it in when it's
initialized? For some reason, that doesn't seem like the best thing to do.

Any ideas?

As far as I know, a gnome-canvas remembers its objects. So why don't you subclass the Grid from a CanvasGroup and pass it the canvas on creation?
Ok, I see that this has the disadvantage of coupling you a lot faster to GnomeCanvas, but otherwise you will have problems when changing the grid, because you can't simple draw a new grid (the line-objects on the canvas), but have to delete the old grid first.

I hope this is not totally confusing or unhelpfull.

Regards,

Brian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,161
Messages
2,570,892
Members
47,430
Latest member
7dog123

Latest Threads

Top