[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gtkmm
Subject:    [gtkmm] gtkmm custom cursor creation
From:       "Antonio-M. Corbi Bellot" <acorbi () dlsi ! ua ! es>
Date:       2001-12-28 2:19:05
[Download RAW message or body]

Hi everyone!:

I have just began to use gtkmm (1.2.8) and having the need to create
custom mouse cursors had a lot of problems until I found a solution (not
to clear for a beginner with gtkmm).

I talked to Karl Nelson about it and he advised me to forward it to the
list, so here it is.

If this is not the right solution and exists other I would be pleased to
know it. Please (if it doesn't bother) email-me directly as I'm not
subscribed to the list.

Thanks in advance for your help.

------- 

Ok Karl, I think I have it!, but please take a look and correct me if
you think so (this solution seems a bit cumbersome for me [:)] .

Well I wanted to 'gdkmm-mimic' something like the one in:

http://developer.gnome.org/doc/API/gdk/gdk-cursors.html

/* example-start */
/* This data is in X bitmap format, and can be created with the 'bitmap'
   utility. */
define cursor1_width 16
define cursor1_height 16
static unsigned char cursor1_bits[] = {
   0x80, 0x01, 0x40, 0x02, 0x20, 0x04, 0x10, 0x08, 0x08, 0x10, 0x04,
0x20,
   0x82, 0x41, 0x41, 0x82, 0x41, 0x82, 0x82, 0x41, 0x04, 0x20, 0x08,
0x10,
   0x10, 0x08, 0x20, 0x04, 0x40, 0x02, 0x80, 0x01};

static unsigned char cursor1mask_bits[] = {
   0x80, 0x01, 0xc0, 0x03, 0x60, 0x06, 0x30, 0x0c, 0x18, 0x18, 0x8c,
0x31,
   0xc6, 0x63, 0x63, 0xc6, 0x63, 0xc6, 0xc6, 0x63, 0x8c, 0x31, 0x18,
0x18,
   0x30, 0x0c, 0x60, 0x06, 0xc0, 0x03, 0x80, 0x01};


  GdkCursor *cursor;
  GdkPixmap *source, *mask;
  GdkColor fg = { 0, 65535, 0, 0 }; /* Red. */
  GdkColor bg = { 0, 0, 0, 65535 }; /* Blue. */


  source = gdk_bitmap_create_from_data (NULL, cursor1_bits,
                    cursor1_width, cursor1_height);
  mask = gdk_bitmap_create_from_data (NULL, cursor1mask_bits,
                      cursor1_width, cursor1_height);
  cursor = gdk_cursor_new_from_pixmap (source, mask, &fg, &bg, 8, 8);
  gdk_pixmap_unref (source);
  gdk_pixmap_unref (mask);


  gdk_window_set_cursor (widget->window, cursor);

/* example-end */

--------------------------------------------

The gdkmm-solution that works for me is something like this (taken from
the code I'm working on now):

tagger::tagger()
{
  Gdk_Cursor c;
  Gdk_Bitmap source, mask;
  Gdk_Color fg; /* Black. */
  Gdk_Color bg; /* White. */


  bg.set_rgb(65535,65535,65535);

  source.create(NULL, (gchar*) crArrow_b,
        crArrow_width,  crArrow_height);

  mask.create(NULL, (gchar*) crArrow_m,
          crArrow_width,  crArrow_height);

  c.create(reinterpret_cast<Gdk_Pixmap&>(source),
       reinterpret_cast<Gdk_Pixmap&>(mask), fg, bg, 1, 1);

  drawingarea->get_window().set_cursor(c);

  c.destroy();
}

-------

Actually the names of the char vectors in my C++ example are different
from the originals in C, but I think it's easy to follow...

The 'cumbersome' is because of C++ strong typing I have to declare
'source' and 'mask' as Gdk_Bitmap (not Gdk_Pixmap that I will need later
in the 'c.create(' call).

As Gdk_Bitmap/Gdk_Pixmap are unrelated classes in gdkmm (both derive
from Gdk_Drawable), I don't have automatic conversion from Gdk_Bitmap to
Gdk_Pixmap, also it is no useful  a static or dynamic cast, so I have to
'force' a reinterpret_cast from Bitmap to Pixmap...

The trick does work, but don't know if:
1) Is ok, I mean if it is well done.
2) Is obvious for a beginner to gtkmm (like me) that reads plain Gtk
docs and tries to mimic it in gtkmm.

Note that in the Gtk example 'source' and 'mask' are declared 'Pixmap'
(pointer to), but are created with 'gdk_bitmap_create...', I think
that's what was confusing me at first.

-------

A. Corbi.



_______________________________________________
to unsubscribe or change your subscription parameters :
https://lists.sourceforge.net/lists/listinfo/gtkmm-main
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic