Re: Canvas basics



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Jody Goldberg <jody gnome org> writes:

On Sat, Jan 08, 2005 at 11:26:45PM +0000, Roger Leigh wrote:

I'd like to let the mouse wheel and Alt + mouse wheel scroll
horizontally and vertically when over any of the canvas widgets.

With Gtk2 this is nice and clean, not like gtk1 where you had to
look for buttons 4&5.

Just put a handler for "scroll-event" onto the window.
Have a look at gnumeric/src/workbook-control-gui.c:wbcg_scroll_wheel_support_cb
for an example.

That works fairly straightforwardly.  I can now scroll and zoom
nicely.  The only problem is the slowness of zooming: I have to signal
all my "CanvasCell" objects to re-set the "font-desc" property; this
turns out to be quite expensive with as few as 256 cells.

The other thing I'd like to do is set a GdkCursor to show when the
mouse moves over certain items, like the edge of the current selection
or the drag handle in the bottom right corner.  Is this simple to do?

You can look at an example in gnumeric/src/item-bar.c:item_bar_event
      case GDK_ENTER_NOTIFY:
      case GDK_MOTION_NOTIFY:
              ib_set_cursor (ib, x, y);

I hadn't thought of setting the cursor on the main GdkWindow!

- - gnome_canvas_item_new allows one to set object properties on the
  created item.  However, it does not pass them to g_object_new, so
  they can't be used as construction parameters.  (Though I can't
  remember why I wanted this now.)
That is indeed irritating.  Likely a throw back to the old
pre-gobject days that is still visible because canvas doesn't see
much maintenance.

I had a look at fixing this today (using g_object_new_valist in
gnome_canvas_item_new).  Unfortunately, it's not as straightforward as
I hoped.  At least item.parent and item.canvas must be set as
construction parameters for it to work.  I may get it fixed tomorrow
if I have time.

I also found a bug with setting the zoom factor (pixels per unit).
For example, in an event handler:

   gnome_canvas_c2w(canvas, event->button.x, event->button.y, &ix, &iy);
   gnome_canvas_item_w2i(GNOME_CANVAS_ITEM(self), &ix, &iy);
   ix *= cell_base->cse_canvas->zoom;
   iy *= cell_base->cse_canvas->zoom;;

If I don't multiply the coordinates by the zoom factor, they are
wrong.  I thought the world/item coordinates should be independent of
that.

If you don't need anti-aliasing you may want to look at foocanvas, a
smaller lighter canvas used in gnumeric and nautilus.

I may well do.  Does it support alpha transparency fills on
rectangles, for example?  Also, does this fix the construction
parameter problem?


Thanks,
Roger

- -- 
Roger Leigh
                Printing on GNU/Linux?  http://gimp-print.sourceforge.net/
                Debian GNU/Linux        http://www.debian.org/
                GPG Public Key: 0x25BFB848.  Please sign and encrypt your mail.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.8 <http://mailcrypt.sourceforge.net/>

iD8DBQFB5GSTVcFcaSW/uEgRAjITAKChbe9RVkVpJiWE02aE1wdlmgsrFwCeOuZx
3hp8RztGZ9ly7x+skEY7eIM=
=PqGd
-----END PGP SIGNATURE-----



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]