Drawing in a GUI

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?

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)

···

On Wed, 17 Nov 2004 08:33:19 +0900, Joe Van Dyk <joe.vandyk@boeing.com> wrote:

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

···

On Wed, 17 Nov 2004 08:33:19 +0900 "Joe Van Dyk" <joe.vandyk@boeing.com> wrote:

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?

--
Brian Schröder
http://www.brian-schroeder.de/