Creating a Gdk::Cursor



Hi everyone,
I've been trying to learn how to use Gdk::Cursor to create and apply a custom cursor.

I can do it using the gtk methods:

#define sq24d_width 24
#define sq24d_height 24
#define sq24d_x_hot 23
#define sq24d_y_hot 23
    static gchar sq24d_bits[] = {
        0xff, 0xff, 0xff, 0x01, 0x00, 0x80, 0x01, 0x00, 0x80, 0x01, 0x00, 0x80,
        0x01, 0x00, 0x80, 0x01, 0x00, 0x80, 0x01, 0x00, 0x80, 0x01, 0x00, 0x80,
        0x01, 0x00, 0x80, 0x01, 0x00, 0x80, 0x01, 0x00, 0x80, 0x01, 0x00, 0x80,
        0x01, 0x00, 0x80, 0x01, 0x00, 0x80, 0x01, 0x00, 0x80, 0x01, 0x00, 0x80,
        0x01, 0x00, 0x80, 0x01, 0x00, 0x80, 0x01, 0x00, 0x80, 0x01, 0x00, 0x80,
        0x01, 0x00, 0x80, 0x01, 0x00, 0x80, 0x01, 0x00, 0x80, 0xff, 0xff, 0xff };

//-----------------------------
#define sq24d_mask_width 24
#define sq24d_mask_height 24
#define sq24d_mask_x_hot 23
#define sq24d_mask_y_hot 23
    static gchar sq24d_mask_bits[] = {
        0xff, 0xff, 0xff, 0x01, 0x00, 0x80, 0x01, 0x00, 0x80, 0x01, 0x00, 0x80,
        0x01, 0x00, 0x80, 0x01, 0x00, 0x80, 0x01, 0x00, 0x80, 0x01, 0x00, 0x80,
        0x01, 0x00, 0x80, 0x01, 0x00, 0x80, 0x01, 0x00, 0x80, 0x01, 0x00, 0x80,
        0x01, 0x00, 0x80, 0x01, 0x00, 0x80, 0x01, 0x00, 0x80, 0x01, 0x00, 0x80,
        0x01, 0x00, 0x80, 0x01, 0x00, 0x80, 0x01, 0x00, 0x80, 0x01, 0x00, 0x80,
        0x01, 0x00, 0x80, 0x01, 0x00, 0x80, 0x01, 0x00, 0x80, 0xff, 0xff, 0xff };

    GdkPixmap *source, *mask;
    GdkColor fg = { 65535, 65535, 65535, 0 }; /* Red. */
    GdkColor bg = { 0, 0, 0, 65535 }; /* Blue. */
    
    source = gdk_bitmap_create_from_data (
        NULL, sq24d_bits, sq24d_width, sq24d_height);
    mask = gdk_bitmap_create_from_data (
        NULL, sq24d_mask_bits,
        sq24d_mask_width, sq24d_mask_height);
    _sq24 = gdk_cursor_new_from_pixmap (
        source, mask, &fg, &bg, 12, 12);
    gdk_pixmap_unref (source);
    gdk_pixmap_unref (mask);
    Gdk::Cursor temp( _sq24, true);
    SQ = temp;    // SQ is declared in the header file


The above seems kind of cumbersome, so I've been trying to create the cursor using Gdk::Cursr

    Glib::RefPtr<Gdk::Pixmap> data, mask;
    Glib::RefPtr<Gdk::Drawable> win = get_window();

    Gdk::Color white, blue;
    white.set_rgb(65535, 65535, 65535);
    blue.set_rgb( 0, 0, 65353);

    data = "">        win, sq24j_bits, 24, 24, 1, white, blue );
    mask = Gdk::Pixmap::create_from_data(
        win, sq24j_mask_bits, 24, 24, 1, white, blue );

    Gdk::Cursor sq( data, mask, white, blue, 12, 12 );

    cout << "gui contr_cursor 8: sq type = "
         << sq.get_cursor_type() << endl;
    _ref_window = get_window();
    _ref_window->set_cursor(sq);





This results in an errlr:


(x:1715): Gdk-CRITICAL **: IA__gdk_cursor_get_cursor_type: assertion `cursor != NULL' failed

The above cursor type output is -2

Can anyone tell me what I'm doing wrong?

Thanks for your help,
Marty




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