Back to index

gcompris  8.2.2
Functions
cursor.c File Reference
#include "gcompris.h"

Go to the source code of this file.

Functions

GdkCursor * gdk_cursor_new_from_data (const gchar *bits[], gint width, gint height, GdkColor *fg, GdkColor *bg, gint hot_x, gint hot_y)

Function Documentation

GdkCursor* gdk_cursor_new_from_data ( const gchar *  bits[],
gint  width,
gint  height,
GdkColor *  fg,
GdkColor *  bg,
gint  hot_x,
gint  hot_y 
)

Definition at line 37 of file cursor.c.

{
  GdkBitmap *bitmap, *mask;
  GdkCursor *cursor;
  guchar *data, *ptr;
  gint i, j;

  /* Though it does not say so on the X11 manual pages, the bitmap
   * format consists of scan lines padded to byte boundaries with the
   * bits in "reverse" order within each byte (lo bits come before hi
   * bits in the bitmap).  I assume this representation is platform
   * independent.  Let me know if it doesn't work for you. */

  /* Create space for the bitmap, padding the scanlines to byte boundaries. */
  data = g_new(guchar, ((width+7)/8)*height);

  /* Build bitmap */
  ptr = data;
  for (i=0; i < height; i++) {
    for (j=0; j < width; j++) {
      *ptr = (*ptr >> 1)|(bits[i][j]=='1'?0x80:0);
      if (j%8 == 7) ptr++;
    }
    if (j%8) *ptr++ >>= 8-j%8;
  }
  bitmap = gdk_bitmap_create_from_data(NULL, (gchar *)data, width, height);

  /* Build mask */
  ptr = data;
  for (i=0; i < height; i++) {
    for (j=0; j < width; j++) {
      *ptr = (*ptr >> 1)|(bits[i][j]==' '?0:0x80);
      if (j%8 == 7) ptr++;
    }
    if (j%8) *ptr++ >>= 8-j%8;
  }
  mask = gdk_bitmap_create_from_data(NULL, (gchar *)data, width, height);

  /* Build cursor from bitmap and mask */
  cursor = gdk_cursor_new_from_pixmap(bitmap, mask, /* Image and mask */
                                  fg, bg, /* colors */
                                  hot_x, hot_y); /* Hot point */

  /* No longer need bitmap or mask */
  gdk_pixmap_unref(bitmap);
  gdk_pixmap_unref(mask);
  g_free(data);

  return cursor;
}

Here is the caller graph for this function: