コード例 #1
0
static GdkCursor *
make_cursor (GdkDisplay *display)
{
  GdkPixbuf *pixbuf;
  GError    *error = NULL;

  pixbuf = gdk_pixbuf_new_from_resource ("/org/gimp/color-picker-cursors/cursor-color-picker.png",
                                         &error);

  if (pixbuf)
    {
      GdkCursor *cursor = gdk_cursor_new_from_pixbuf (display, pixbuf, 1, 30);

      g_object_unref (pixbuf);

      return cursor;
    }
  else
    {
      g_critical ("Failed to create cursor image: %s", error->message);
      g_clear_error (&error);
    }

  return NULL;
}
コード例 #2
0
ファイル: cursor.c プロジェクト: AmiGanguli/dia
GdkCursor *
create_cursor(GdkWindow *window,
	      const guint8 *data,
	      int hot_x, int hot_y)
{
  GdkPixbuf *pixbuf;
  GdkCursor *cursor;
  GdkDisplay *display;

  g_return_val_if_fail(window != NULL, NULL);
#if GTK_CHECK_VERSION (2,24,0)
  display = gdk_window_get_display (window);
#else
  display = gdk_drawable_get_display (GDK_DRAWABLE (window));
#endif

  pixbuf = gdk_pixbuf_new_from_inline(-1, data, FALSE, NULL);

  cursor = gdk_cursor_new_from_pixbuf (display, pixbuf, hot_x,hot_y);
  g_assert(cursor != NULL);

  g_object_unref(pixbuf);

  return cursor;
}
コード例 #3
0
ファイル: doppelganger.c プロジェクト: gpoudrel/xzibit
Doppelganger*
doppelganger_new (char *name)
{
  Doppelganger *result =
    g_malloc (sizeof (Doppelganger));
  GdkPixbuf *blank;
  int current_pointer;

  result->mpx = add_mpx_for_window (name);

  result->cursor = NULL;
  doppelganger_set_image (result, NULL);

  blank = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
			  TRUE,
			  8, 1, 1);
  gdk_pixbuf_fill (blank,
                   0); /* transparent */

  result->blank = gdk_cursor_new_from_pixbuf
    (gdk_display_get_default (),
     blank,
     0, 0);
  gdk_pixbuf_unref (blank);

  show_cursor (result);

  return result;
}
コード例 #4
0
ファイル: gimppickbutton.c プロジェクト: DevMaggio/gimp
static GdkCursor *
make_cursor (GdkDisplay *display)
{
  GdkCursor           *cursor;
  GdkPixbuf           *pixbuf;
  static const guint8 *data;

  if (gdk_display_supports_cursor_alpha (display) &&
      gdk_display_supports_cursor_color (display))
    {
      data = cursor_color_picker;
    }
  else
    {
      data = cursor_color_picker_bw;
    }

  pixbuf = gdk_pixbuf_new_from_inline (-1, data, FALSE, NULL);

  cursor = gdk_cursor_new_from_pixbuf (display, pixbuf, 1, 30);

  g_object_unref (pixbuf);

  return cursor;
}
コード例 #5
0
/* Redraw the screen from the backing pixmap */
static gboolean expose_event (GtkWidget      *widget,
                              GdkEventExpose *event)
{
	static GdkImage *image = NULL;
	GdkCursor *cursor;
	GdkPixbuf *pixbuf;

	if (framebuffer_allocated == FALSE) {

		rfbClientSetClientData (cl, gtk_init, widget);

		image = gdk_drawable_get_image (widget->window, 0, 0,
		                                widget->allocation.width,
		                                widget->allocation.height);

		cl->frameBuffer= image->mem;

		cl->width  = widget->allocation.width;
		cl->height = widget->allocation.height;

		cl->format.bitsPerPixel = image->bits_per_pixel;
		cl->format.redShift     = image->visual->red_shift;
		cl->format.greenShift   = image->visual->green_shift;
		cl->format.blueShift    = image->visual->blue_shift;

		cl->format.redMax   = (1 << image->visual->red_prec) - 1;
		cl->format.greenMax = (1 << image->visual->green_prec) - 1;
		cl->format.blueMax  = (1 << image->visual->blue_prec) - 1;

#ifdef LIBVNCSERVER_CONFIG_LIBVA
		/* Allow libvncclient to use a more efficient way
		 * of putting the framebuffer on the screen when
		 * using the H.264 format.
		 */
		cl->outputWindow = GDK_WINDOW_XID(widget->window);
#endif

		SetFormatAndEncodings (cl);

		framebuffer_allocated = TRUE;

		/* Also disable local cursor */
                pixbuf = gdk_pixbuf_new_from_xpm_data(dot_cursor_xpm);
	        cursor = gdk_cursor_new_from_pixbuf(gdk_display_get_default(), pixbuf, dot_cursor_x_hot, dot_cursor_y_hot);
		g_object_unref(pixbuf);	
		gdk_window_set_cursor (gtk_widget_get_window(GTK_WIDGET(window)), cursor);
		gdk_cursor_unref(cursor);
	}

#ifndef LIBVNCSERVER_CONFIG_LIBVA
	gdk_draw_image (GDK_DRAWABLE (widget->window),
	                widget->style->fg_gc[gtk_widget_get_state(widget)],
	                image,
	                event->area.x, event->area.y,
	                event->area.x, event->area.y,
	                event->area.width, event->area.height);
#endif

	return FALSE;
}
コード例 #6
0
ファイル: window.c プロジェクト: galexcode/NetSurf68k
static GdkCursor *nsgtk_create_menu_cursor(void)
{
	GdkCursor *cursor = NULL;
	GdkPixbuf *pixbuf;
	pixbuf = gdk_pixbuf_from_pixdata(&menu_cursor_pixdata, FALSE, NULL);
	cursor = gdk_cursor_new_from_pixbuf(gdk_display_get_default(), pixbuf, 0, 3);
	g_object_unref (pixbuf);

	return cursor;
}
コード例 #7
0
static GRefPtr<GdkCursor> createCustomCursor(Image* image, const IntPoint& hotSpot)
{
    GRefPtr<GdkPixbuf> pixbuf = adoptGRef(image->getGdkPixbuf());

    if (!image->nativeImageForCurrentFrame() || !pixbuf)
        return 0;

    IntPoint effectiveHotSpot = determineHotSpot(image, hotSpot);
    return adoptGRef(gdk_cursor_new_from_pixbuf(gdk_display_get_default(), pixbuf.get(), effectiveHotSpot.x(), effectiveHotSpot.y()));
}
コード例 #8
0
ファイル: xo-paint.c プロジェクト: xenobyte/xournal
/* gdk_cursor_new_from_pixmap is broken on Windows.
   this is a workaround using gdk_cursor_new_from_pixbuf. */
GdkCursor* fixed_gdk_cursor_new_from_pixmap(GdkPixmap *source, GdkPixmap *mask,
					    const GdkColor *fg, const GdkColor *bg,
					    gint x, gint y)
{
  GdkPixmap *rgb_pixmap;
  GdkGC *gc;
  GdkPixbuf *rgb_pixbuf, *rgba_pixbuf;
  GdkCursor *cursor;
  int width, height;

  /* HACK!  It seems impossible to work with RGBA pixmaps directly in
     GDK-Win32.  Instead we pick some third color, different from fg
     and bg, and use that as the 'transparent color'.  We do this using
     colors_too_similar (see above) because two colors could be
     unequal in GdkColor's 16-bit/sample, but equal in GdkPixbuf's
     8-bit/sample. */
  GdkColor candidates[3] = {{0,65535,0,0}, {0,0,65535,0}, {0,0,0,65535}};
  GdkColor *trans = &candidates[0];
  if (colors_too_similar(trans, fg) || colors_too_similar(trans, bg)) {
    trans = &candidates[1];
    if (colors_too_similar(trans, fg) || colors_too_similar(trans, bg)) {
      trans = &candidates[2];
    }
  } /* trans is now guaranteed to be unique from fg and bg */

  /* create an empty pixmap to hold the cursor image */
  gdk_drawable_get_size(source, &width, &height);
  rgb_pixmap = gdk_pixmap_new(NULL, width, height, 24);

  /* blit the bitmaps defining the cursor onto a transparent background */
  gc = gdk_gc_new(rgb_pixmap);
  gdk_gc_set_fill(gc, GDK_SOLID);
  gdk_gc_set_rgb_fg_color(gc, trans);
  gdk_draw_rectangle(rgb_pixmap, gc, TRUE, 0, 0, width, height);
  gdk_gc_set_fill(gc, GDK_OPAQUE_STIPPLED);
  gdk_gc_set_stipple(gc, source);
  gdk_gc_set_clip_mask(gc, mask);
  gdk_gc_set_rgb_fg_color(gc, fg);
  gdk_gc_set_rgb_bg_color(gc, bg);
  gdk_draw_rectangle(rgb_pixmap, gc, TRUE, 0, 0, width, height);
  gdk_gc_unref(gc);

  /* create a cursor out of the created pixmap */
  rgb_pixbuf = gdk_pixbuf_get_from_drawable(
    NULL, rgb_pixmap, gdk_colormap_get_system(), 0, 0, 0, 0, width, height);
  gdk_pixmap_unref(rgb_pixmap);
  rgba_pixbuf = gdk_pixbuf_add_alpha(
    rgb_pixbuf, TRUE, trans->red, trans->green, trans->blue);
  gdk_pixbuf_unref(rgb_pixbuf);
  cursor = gdk_cursor_new_from_pixbuf(gdk_display_get_default(), rgba_pixbuf, x, y);
  gdk_pixbuf_unref(rgba_pixbuf);

  return cursor;
}
コード例 #9
0
ファイル: egg-toolbar-editor.c プロジェクト: GNOME/galeon
static void
set_drag_cursor (GtkWidget *widget)
{
  GdkCursor *cursor;
  GdkPixbuf *pixbuf;

  pixbuf = gdk_pixbuf_new_from_file (CURSOR_DIR "/hand-open.png", NULL);
  cursor = gdk_cursor_new_from_pixbuf (gdk_display_get_default (), pixbuf, 12, 12);

  gdk_window_set_cursor (widget->window, cursor);
  gdk_cursor_unref (cursor);
  g_object_unref (pixbuf);
}
コード例 #10
0
ファイル: GlassCursor.cpp プロジェクト: Anthony-Biget/openjfx
/*
 * Class:     com_sun_glass_ui_gtk_GtkCursor
 * Method:    _createCursor
 * Signature: (IILcom/sun/glass/ui/Pixels;)J
 */
JNIEXPORT jlong JNICALL Java_com_sun_glass_ui_gtk_GtkCursor__1createCursor
  (JNIEnv * env, jobject obj, jint x, jint y, jobject pixels)
{
    GdkPixbuf *pixbuf = NULL;
    GdkCursor *cursor = NULL;
    env->CallVoidMethod(pixels, jPixelsAttachData, PTR_TO_JLONG(&pixbuf));
    if (!EXCEPTION_OCCURED(env)) {
        cursor = gdk_cursor_new_from_pixbuf(gdk_display_get_default(), pixbuf, x, y);
    }
    g_object_unref(pixbuf);

    return PTR_TO_JLONG(cursor);
}
コード例 #11
0
ファイル: rdp_graphics.c プロジェクト: dupondje/Remmina
void rf_Pointer_New(rdpContext* context, rdpPointer* pointer)
{
	rfContext* rfi = (rfContext*) context;
	GdkPixbuf *pixbuf;
	guchar* pixbuf_data;

	pixbuf_data = g_malloc(pointer->width * pointer->height * 4);
	if ((pointer->andMaskData != 0) && (pointer->xorMaskData != 0))
	{
		freerdp_alpha_cursor_convert(pixbuf_data, pointer->xorMaskData, pointer->andMaskData, pointer->width, pointer->height, pointer->xorBpp, rfi->clrconv);
	}
	pixbuf = gdk_pixbuf_new_from_data(pixbuf_data, GDK_COLORSPACE_RGB, TRUE, 8, pointer->width, pointer->height, (pointer->width * 4), (GdkPixbufDestroyNotify) g_free, NULL);
	((rfPointer*) pointer)->cursor = gdk_cursor_new_from_pixbuf(rfi->display, pixbuf, pointer->xPos, pointer->yPos);
}
コード例 #12
0
ファイル: sp-cursor.cpp プロジェクト: AakashDabas/inkscape
GdkCursor *sp_cursor_new_from_xpm(char const *const *xpm, int hot_x, int hot_y)
{
    GdkCursor *cursor = 0;
    GdkPixbuf *pixbuf = gdk_pixbuf_new_from_xpm_data((const gchar **)xpm);
    
    if (pixbuf) {
        cursor = gdk_cursor_new_from_pixbuf(gdk_display_get_default(),
			pixbuf, hot_x, hot_y);

        g_object_unref(pixbuf);
    }

    return cursor;
}
コード例 #13
0
ファイル: resources.c プロジェクト: EyMenZ/NetSurf-OS3
/* exported interface documented in gtk/resources.h */
GdkCursor *nsgtk_create_menu_cursor(void)
{
	GdkCursor *cursor = NULL;
	GdkPixbuf *pixbuf;
	nserror res;

	res = nsgdk_pixbuf_new_from_resname("menu_cursor.png", &pixbuf);
	if (res == NSERROR_OK) {
		cursor = gdk_cursor_new_from_pixbuf(gdk_display_get_default(),
						    pixbuf, 0, 3);
		g_object_unref(pixbuf);
	}

	return cursor;
}
コード例 #14
0
HCURSOR SWELL_LoadCursorFromFile(const char *fn)
{
#ifdef SWELL_TARGET_GDK
  GdkPixbuf *pb = gdk_pixbuf_new_from_file(fn,NULL);
  if (pb) 
  {
    POINT hs = {0,};
    getHotSpotForFile(fn,&hs);
    GdkCursor *curs = gdk_cursor_new_from_pixbuf(gdk_display_get_default(),pb,hs.x,hs.y);
    g_object_unref(pb);
    return (HCURSOR) curs;
  }
#endif

  return NULL;
}
コード例 #15
0
ファイル: view-ellipse.c プロジェクト: DroiDev/glabels
GdkCursor *
gl_view_ellipse_get_create_cursor (void)
{
	GdkCursor       *cursor = NULL;
	GdkPixbuf       *pixbuf;

	gl_debug (DEBUG_VIEW, "START");

        pixbuf = gdk_pixbuf_from_pixdata (&cursor_ellipse_pixdata, FALSE, NULL);
        cursor = gdk_cursor_new_from_pixbuf (gdk_display_get_default (), pixbuf, X_HOTSPOT, Y_HOTSPOT);
        g_object_unref (pixbuf);

	gl_debug (DEBUG_VIEW, "END");

	return cursor;
}
コード例 #16
0
HCURSOR SWELL_LoadCursor(const char *_idx)
{
#ifdef SWELL_TARGET_GDK

  GdkCursorType def = GDK_LEFT_PTR;
  if (_idx == IDC_NO) def = GDK_PIRATE;
  else if (_idx == IDC_SIZENWSE) def = GDK_BOTTOM_LEFT_CORNER;
  else if (_idx == IDC_SIZENESW) def = GDK_BOTTOM_RIGHT_CORNER;
  else if (_idx == IDC_SIZEALL) def = GDK_FLEUR;
  else if (_idx == IDC_SIZEWE) def =  GDK_RIGHT_SIDE;
  else if (_idx == IDC_SIZENS) def = GDK_TOP_SIDE;
  else if (_idx == IDC_ARROW) def = GDK_LEFT_PTR;
  else if (_idx == IDC_HAND) def = GDK_HAND1;
  else if (_idx == IDC_UPARROW) def = GDK_CENTER_PTR;
  else if (_idx == IDC_IBEAM) def = GDK_XTERM;
  else 
  {
    SWELL_CursorResourceIndex *p = SWELL_curmodule_cursorresource_head;
    while (p)
    {
      if (p->resid == _idx)
      {
        if (p->cachedCursor) return p->cachedCursor;
        // todo: load from p->resname, into p->cachedCursor, p->hotspot
        char buf[1024];
        GetModuleFileName(NULL,buf,sizeof(buf));
        WDL_remove_filepart(buf);
        snprintf_append(buf,sizeof(buf),"/Resources/%s.cur",p->resname);
        GdkPixbuf *pb = gdk_pixbuf_new_from_file(buf,NULL);
        if (pb) 
        {
          getHotSpotForFile(buf,&p->hotspot);
          GdkCursor *curs = gdk_cursor_new_from_pixbuf(gdk_display_get_default(),pb,p->hotspot.x,p->hotspot.y);
          return (p->cachedCursor = (HCURSOR) curs);
        }
      }
      p=p->_next;
    }
  }

  HCURSOR hc= (HCURSOR)gdk_cursor_new_for_display(gdk_display_get_default(),def);

  return hc;
#endif
  return NULL;
}
コード例 #17
0
static GRefPtr<GdkCursor> createNamedCursor(CustomCursorType cursorType)
{
    CustomCursor cursor = CustomCursors[cursorType];
    GRefPtr<GdkCursor> c = adoptGRef(gdk_cursor_new_from_name(gdk_display_get_default(), cursor.name));
    if (c)
        return c;

    RefPtr<cairo_surface_t> source = adoptRef(cairo_image_surface_create_for_data(const_cast<unsigned char*>(cursor.bits), CAIRO_FORMAT_A1, 32, 32, 4));
    RefPtr<cairo_surface_t> mask = adoptRef(cairo_image_surface_create_for_data(const_cast<unsigned char*>(cursor.mask_bits), CAIRO_FORMAT_A1, 32, 32, 4));
    RefPtr<cairo_surface_t> surface = adoptRef(cairo_image_surface_create(CAIRO_FORMAT_A1, 32, 32));
    RefPtr<cairo_t> cr = adoptRef(cairo_create(surface.get()));

    cairo_set_source_surface(cr.get(), source.get(), 0, 0);
    cairo_mask_surface(cr.get(), mask.get(), 0, 0);

    GRefPtr<GdkPixbuf> pixbuf = adoptGRef(gdk_pixbuf_get_from_surface(surface.get(), 0, 0, 32, 32));
    return adoptGRef(gdk_cursor_new_from_pixbuf(gdk_display_get_default(), pixbuf.get(), cursor.hot_x, cursor.hot_y));
}
コード例 #18
0
ファイル: graphics.c プロジェクト: 4nakin/freeciv-android
/***************************************************************************
...
***************************************************************************/
void load_cursors(void)
{
  enum cursor_type cursor;
  GdkDisplay *display = gdk_display_get_default();
  int frame;

  for (cursor = 0; cursor < CURSOR_LAST; cursor++) {
    for (frame = 0; frame < NUM_CURSOR_FRAMES; frame++) {
      int hot_x, hot_y;
      struct sprite *sprite
	= get_cursor_sprite(tileset, cursor, &hot_x, &hot_y, frame);
      GdkPixbuf *pixbuf = sprite_get_pixbuf(sprite);

      fc_cursors[cursor][frame] = gdk_cursor_new_from_pixbuf(display, pixbuf,
							     hot_x, hot_y);
    }
  }
}
コード例 #19
0
ファイル: gdk_Cursor.cpp プロジェクト: Klaim/falcon
/*#
    @method new_from_pixbuf GdkCursor
    @brief Creates a new cursor from a pixbuf.
    @param display the GdkDisplay for which the cursor will be created
    @param pixbuf the GdkPixbuf containing the cursor image
    @param x the horizontal offset of the 'hotspot' of the cursor.
    @param y the vertical offset of the 'hotspot' of the cursor.
    @return a new GdkCursor.

    Not all GDK backends support RGBA cursors. If they are not supported, a
    monochrome approximation will be displayed. The functions gdk_display_supports_cursor_alpha()
    and gdk_display_supports_cursor_color() can be used to determine whether
    RGBA cursors are supported; gdk_display_get_default_cursor_size() and
    gdk_display_get_maximal_cursor_size() give information about cursor sizes.

    On the X backend, support for RGBA cursors requires a sufficently new
    version of the X Render extension.
 */
FALCON_FUNC Cursor::new_from_pixbuf( VMARG )
{
    Item* i_display = vm->param( 0 );
    Item* i_pix = vm->param( 1 );
    Item* i_x = vm->param( 2 );
    Item* i_y = vm->param( 3 );
#ifndef NO_PARAMETER_CHECK
    if ( !i_display || !i_display->isObject() || !IS_DERIVED( i_display, GdkDisplay )
        || !i_pix || !i_pix->isObject() || !IS_DERIVED( i_pix, GdkPixbuf )
        || !i_x || !i_x->isInteger()
        || !i_y || !i_y->isInteger() )
        throw_inv_params( "GdkDisplay,GdkPixbuf,I,I" );
#endif
    vm->retval( new Gdk::Cursor( vm->findWKI( "GdkCursor" )->asClass(),
                        gdk_cursor_new_from_pixbuf( GET_DISPLAY( *i_display ),
                                                    GET_PIXBUF( *i_pix ),
                                                    i_x->asInteger(),
                                                    i_y->asInteger() ) ) );
}
コード例 #20
0
ファイル: he-helper.c プロジェクト: rlevi/xournal
/**
 * he_helper_show_cursor:
 * @context: A realized GtkWidget.
 *
 * Shows a cursor on the screen, for a window.
 * Its method of getting the x and y coordinate is dodgy - please fix...
 *
 **/
void
he_helper_show_cursor                  (GtkWidget *widget)
{
	GdkDisplay *display;
	GdkScreen *screen;
	GtkIconTheme *theme;
	GdkPixbuf *pixbuf;
	gint x;
	gint y;
	GdkCursor *cursor = NULL;

	g_return_if_fail (widget);
	g_return_if_fail (GTK_WIDGET_DRAWABLE(widget));

	display = gdk_drawable_get_display (GDK_DRAWABLE(widget->window));
	g_return_if_fail (display);

	screen = gtk_widget_get_screen (widget);
	g_return_if_fail (screen);

	theme = gtk_icon_theme_get_for_screen (screen);
	g_return_if_fail (theme);

	pixbuf = gtk_icon_theme_load_icon (theme, CURSOR_ICON_NAME, CURSOR_ICON_SIZE, 0, NULL);
	if (!pixbuf)
		goto cleanup;

	x = (gdk_pixbuf_get_width (pixbuf) / 2) - 7;
	y = (gdk_pixbuf_get_height (pixbuf) / 2) - 7;

	cursor = gdk_cursor_new_from_pixbuf (display, pixbuf, x, y);
	if (!cursor)
		goto cleanup;

	gdk_window_set_cursor (widget->window, cursor);

cleanup:
	if (pixbuf)
		g_object_unref (pixbuf); 
	if (cursor)
		gdk_cursor_unref (cursor);
}
コード例 #21
0
ファイル: cursors.c プロジェクト: Nikhar/gnome-robots
void
make_cursors (void)
{
  GdkPixbuf *pixbuf;
  int i;
  cursor_props *c;

  default_cursor = gdk_cursor_new (GDK_LEFT_PTR);

  c = cursor_list;
  for (i = 0; i < G_N_ELEMENTS (cursor_list); ++i) {
    pixbuf = gdk_pixbuf_new_from_inline (c->data_len, c->data, FALSE, NULL);
    c->cursor = gdk_cursor_new_from_pixbuf (gdk_display_get_default (),
                                            pixbuf,
                                            c->hsx, c->hsy);
    g_object_unref (pixbuf);

    c++;
  }
}
コード例 #22
0
QCursor::QCursor(const QPixmap &pixmap)
    : cursor(NULL)
{
    ERROR("not yet implemented");

    GdkPixbuf* buf = pixmap.image()->handle();
    QPoint hotSpot(0,0);
#if (GTK_MAJOR_VERSION >= 2) && (GTK_MINOR_VERSION >=4)
    cursor =  gdk_cursor_new_from_pixbuf(GDK_DISPLAY(), buf, hotSpot.x(), hotSpot.y());
#else
    GdkPixmap *gdkpixmap;
    GdkBitmap *mask;
    gdk_pixbuf_render_pixmap_and_mask(buf, &gdkpixmap, &mask, 100);
    GdkColor fg = { 0, 65535, 65535, 65535 }; /* White. */
    GdkColor bg = { 0, 0, 0, 0 }; /* Black. */
    cursor = gdk_cursor_new_from_pixmap(mask, mask, &fg, &bg, hotSpot.x(), hotSpot.y());
    g_object_unref(gdkpixmap);
    g_object_unref(mask);
#endif

}
コード例 #23
0
ファイル: rbgdkcursor.c プロジェクト: Mazwak/ruby-gnome2
static VALUE
rg_initialize(int argc, VALUE *argv, VALUE self)
{
    GdkCursor* cursor = NULL;

    if (argc == 1){
        VALUE type;
        rb_scan_args(argc, argv, "10", &type);
        cursor = gdk_cursor_new(RVAL2GDKCURSORTYPE(type));
    } else if (argc == 2) {
        VALUE display, type_or_name;
        rb_scan_args(argc, argv, "20", &display, &type_or_name);
        if (TYPE(type_or_name) == T_STRING)
            cursor = gdk_cursor_new_from_name(RVAL2GDKDISPLAYOBJECT(display),
                                              RVAL2CSTR(type_or_name));
        else
            cursor = gdk_cursor_new_for_display(RVAL2GDKDISPLAYOBJECT(display), 
                                                RVAL2GDKCURSORTYPE(type_or_name));
    } else if (argc == 4) {
        VALUE display, pixbuf, x, y;
        rb_scan_args(argc, argv, "40", &display, &pixbuf, &x, &y);
        cursor = gdk_cursor_new_from_pixbuf(RVAL2GDKDISPLAYOBJECT(display), 
                                            RVAL2GDKPIXBUF(pixbuf), 
                                            NUM2INT(x), NUM2INT(y));
/* deprecated
    } else if (argc == 6) {
        VALUE pixmap, mask, fg, bg, x, y;
        rb_scan_args(argc, argv, "60", &pixmap, &mask, &fg, &bg, &x, &y);
        cursor = gdk_cursor_new_from_pixmap(RVAL2GDKPIXMAP(pixmap), 
                                            NIL_P(mask)?NULL:RVAL2GDKPIXMAP(mask), 
                                            RVAL2GDKCOLOR(fg),
                                            RVAL2GDKCOLOR(bg),
                                            NUM2INT(x), NUM2INT(y));
*/
    }
    G_INITIALIZE(self, cursor);

    return Qnil;
}
コード例 #24
0
ファイル: cursor.cpp プロジェクト: CobaltBlues/wxWidgets
void wxCursor::InitFromImage( const wxImage & image )
{
    const int w = image.GetWidth();
    const int h = image.GetHeight();
    const guchar* alpha = image.GetAlpha();
    const bool hasMask = image.HasMask();
    int hotSpotX = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X);
    int hotSpotY = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_Y);
    if (hotSpotX < 0 || hotSpotX > w) hotSpotX = 0;
    if (hotSpotY < 0 || hotSpotY > h) hotSpotY = 0;
    GdkPixbuf* pixbuf = gdk_pixbuf_new_from_data(image.GetData(), GDK_COLORSPACE_RGB, false, 8, w, h, w * 3, NULL, NULL);
    if (alpha || hasMask)
    {
        guchar r = 0, g = 0, b = 0;
        if (hasMask)
        {
            r = image.GetMaskRed();
            g = image.GetMaskGreen();
            b = image.GetMaskBlue();
        }
        GdkPixbuf* pixbuf0 = pixbuf;
        pixbuf = gdk_pixbuf_add_alpha(pixbuf, hasMask, r, g, b);
        g_object_unref(pixbuf0);
        if (alpha)
        {
            guchar* d = gdk_pixbuf_get_pixels(pixbuf);
            const int stride = gdk_pixbuf_get_rowstride(pixbuf);
            for (int j = 0; j < h; j++, d += stride)
                for (int i = 0; i < w; i++, alpha++)
                    if (d[4 * i + 3])
                        d[4 * i + 3] = *alpha;
        }
    }
    m_refData = new wxCursorRefData;
    M_CURSORDATA->m_cursor = gdk_cursor_new_from_pixbuf(gtk_widget_get_display(wxGetRootWindow()), pixbuf, hotSpotX, hotSpotY);
    g_object_unref(pixbuf);
}
コード例 #25
0
ファイル: GtkWnd.cpp プロジェクト: guowei8412/upp-mirror
void  Ctrl::SetMouseCursor(const Image& image)
{
	LLOG("SetMouseCursor");
	GuiLock __;
	int64 id = image.GetSerialId();
	Ctrl *topctrl = NULL;
	Top *top = NULL;
	if(mouseCtrl)
		topctrl = mouseCtrl->GetTopCtrl();
	else
		topctrl = GetActiveCtrl();
	if(topctrl)
		top = topctrl->top;
	if(top && id != top->cursor_id) {
		top->cursor_id = id;
		int64 aux = image.GetAuxData();
		GdkCursor *c = NULL;
		if(aux)
			c = gdk_cursor_new((GdkCursorType)(aux - 1));
		else
		if(IsNull(image))
			c = gdk_cursor_new(GDK_BLANK_CURSOR);
		else {
			Point p = image.GetHotSpot();
			ImageGdk m;
			m.Set(image);
			GdkPixbuf *pb = m;
			if(pb)
				c = gdk_cursor_new_from_pixbuf(gdk_display_get_default(), pb, p.x, p.y);
		}
		if(c && topctrl->IsOpen()) {
			gdk_window_set_cursor(topctrl->gdk(), c);
			gdk_cursor_unref(c);
			gdk_flush(); // Make it visible immediately
		}
	}
}
コード例 #26
0
ファイル: item-grid.c プロジェクト: paulfitz/gnumeric
static void
item_grid_realize (GocItem *item)
{
	GdkDisplay *display;
	GnmItemGrid *ig;
	GdkPixbuf *cursor_cross_pixbuf;

	parent_class->realize (item);

	ig = GNM_ITEM_GRID (item);
	ig_reload_style (ig);

	display = gtk_widget_get_display (GTK_WIDGET (item->canvas));
	ig->cursor_link  = gdk_cursor_new_for_display (display, GDK_HAND2);
	cursor_cross_pixbuf =
		gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
					  "cursor_cross", 32, 0, NULL);
	ig->cursor_cross =
		gdk_cursor_new_from_pixbuf (display,
					    cursor_cross_pixbuf,
					    17, 17);
	g_object_unref (cursor_cross_pixbuf);
	cb_cursor_motion (ig);
}
コード例 #27
0
ファイル: gamine.c プロジェクト: btong/gamine
gint
main (gint argc, gchar *argv[])
{
    Window root;
    //gettext
    bindtextdomain( "gamine", LOCALDIR );
    textdomain( "gamine" );
    gamine_t cb;
    GtkWidget *window;
    GdkWindow *gdkwindow;
    GtkWindow *gtkwindow;
    GdkScreen *screen;
    GdkPixbuf *cursor_pixbuf;
    GdkPixbuf *icon_pixbuf;
    GdkCursor *cursor;
    GdkColor bg_color;
    gchar *cursorfile;
    gchar *iconfile;

    cb.is_cairo = FALSE;
    gtk_init (&argc, &argv);
    gst_init (&argc, &argv);
    gconf_init(argc, argv, NULL);
    gst_play_background (cb.bus,
              "BachJSBrandenburgConcertNo2inFMajorBWV1047mvmt1.ogg", TRUE);

    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
/* Create the drawing area and configuration */
    cb.da = gtk_drawing_area_new ();
    bg_color.red   = 65535;
    bg_color.green = 65535;
    bg_color.blue  = 65535;
    gtk_widget_modify_bg (cb.da, GTK_STATE_NORMAL, &bg_color);
    gtk_container_add (GTK_CONTAINER (window), cb.da);
    cb.gc = gconf_client_get_default();

    gtkwindow = GTK_WINDOW(window);
    gtk_window_set_title (gtkwindow, "Gamine");
    gtk_window_set_wmclass(gtkwindow, "gamine", "Gamine");
    gtk_container_set_border_width (GTK_CONTAINER (gtkwindow), 0);


/* Event signals */
    g_signal_connect (gtkwindow, "destroy",
         G_CALLBACK (gtk_main_quit), &gtkwindow);
    g_signal_connect (G_OBJECT (cb.da), "expose-event",
        G_CALLBACK (display_help), &cb);
    g_signal_connect (cb.da, "motion_notify_event",
        G_CALLBACK (draw_line), &cb);
    g_signal_connect (cb.da, "button_press_event",
        G_CALLBACK (draw_star), &cb);
    g_signal_connect (gtkwindow, "key-press-event",
        G_CALLBACK (gamine_on_key), &cb);
    gtk_widget_set_events (cb.da, gtk_widget_get_events (cb.da)
        | GDK_LEAVE_NOTIFY_MASK
        | GDK_BUTTON_PRESS_MASK
        | GDK_BUTTON_RELEASE_MASK
        | GDK_POINTER_MOTION_MASK
        | GDK_POINTER_MOTION_HINT_MASK);
/* Set fullscreen, grab mouse/keyboard, ...*/
    gtk_widget_show_all (GTK_WIDGET(gtkwindow));
    gdkwindow = GDK_WINDOW(GTK_WIDGET(gtkwindow)->window);
    screen = gtk_widget_get_screen (cb.da);
    gtk_window_present (gtkwindow);
    gtk_window_stick(gtkwindow);

    //gtk_window_set_keep_above (gtkwindow), True);
    //gtk_window_set_transient_for (gtkwindow, NULL);
    //set fullscreen
    gdk_window_fullscreen (gdkwindow);
    gtk_window_fullscreen (gtkwindow);
    gdk_window_raise (gdkwindow);
    //set full screen without window manager
    XMoveResizeWindow(GDK_WINDOW_XDISPLAY(gdkwindow), GDK_WINDOW_XID(gdkwindow),
        0, 0, gdk_screen_get_width (screen), gdk_screen_get_height (screen));
    root = DefaultRootWindow(GDK_WINDOW_XDISPLAY (gdkwindow));
    XGrabPointer(GDK_WINDOW_XDISPLAY (gdkwindow), root, True, PointerMotionMask,
        GrabModeAsync, GrabModeAsync, root, None, CurrentTime); 
    XGrabKeyboard(GDK_WINDOW_XDISPLAY (gdkwindow), root, True,
                    GrabModeAsync, GrabModeAsync, CurrentTime);
    //remove keyboard repeat
    XAutoRepeatOff(GDK_WINDOW_XDISPLAY (gdkwindow));
    gtk_window_has_toplevel_focus (gtkwindow);
/*cursor*/
    cursorfile = g_build_filename(DATADIR, "pencil.png", NULL);
    if (!g_file_test (cursorfile, G_FILE_TEST_EXISTS)) {
        printf(gettext("*** error: %s does not exists***\n"), cursorfile);
    } else {
        cursor_pixbuf = gdk_pixbuf_new_from_file(cursorfile, NULL);
        cursor = gdk_cursor_new_from_pixbuf(gdk_display_get_default(),
            cursor_pixbuf, 0, 38);
        gdk_window_set_cursor(gdkwindow, cursor);
        gdk_cursor_unref(cursor);
        gdk_pixbuf_unref(cursor_pixbuf);
    }
    g_free(cursorfile);
/*Set icon*/
    iconfile = g_build_filename(DATADIR, "gamine.png", NULL);
    if (!g_file_test (iconfile, G_FILE_TEST_EXISTS))
        printf(gettext("*** error: %s does not exists***\n"), iconfile);
    else {
        icon_pixbuf = gdk_pixbuf_new_from_file(iconfile, NULL);
        gtk_window_set_icon (gtkwindow, icon_pixbuf);
        gdk_pixbuf_unref (icon_pixbuf);
    }
    g_free(iconfile);

    load_conf(&cb);
    gtk_main ();
    //set keyboard repeat
    XAutoRepeatOn(GDK_WINDOW_XDISPLAY (gdkwindow));
    XCloseDisplay(GDK_WINDOW_XDISPLAY (gdkwindow));
    return 0;
}
コード例 #28
0
JNIEXPORT void JNICALL 
Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkWidgetSetCursorUnlocked
  (JNIEnv *env, jobject obj, jint type, jobject image, jint x, jint y) 
{
  void *ptr;
  GtkWidget *widget;
  GdkWindow *win;
  GdkCursorType gdk_cursor_type;
  GdkCursor *gdk_cursor;

  ptr = gtkpeer_get_widget (env, obj);

  switch (type)
    {
    case AWT_CROSSHAIR_CURSOR:
      gdk_cursor_type = GDK_CROSSHAIR;
      break;
    case AWT_TEXT_CURSOR:
      gdk_cursor_type = GDK_XTERM;
      break;
    case AWT_WAIT_CURSOR:
      gdk_cursor_type = GDK_WATCH;
      break;
    case AWT_SW_RESIZE_CURSOR:
      gdk_cursor_type = GDK_BOTTOM_LEFT_CORNER;
      break;
    case AWT_SE_RESIZE_CURSOR:
      gdk_cursor_type = GDK_BOTTOM_RIGHT_CORNER;
      break;
    case AWT_NW_RESIZE_CURSOR:
      gdk_cursor_type = GDK_TOP_LEFT_CORNER;
      break;
    case AWT_NE_RESIZE_CURSOR:
      gdk_cursor_type = GDK_TOP_RIGHT_CORNER;
      break;
    case AWT_N_RESIZE_CURSOR:
      gdk_cursor_type = GDK_TOP_SIDE;
      break;
    case AWT_S_RESIZE_CURSOR:
      gdk_cursor_type = GDK_BOTTOM_SIDE;
      break;
    case AWT_W_RESIZE_CURSOR:
      gdk_cursor_type = GDK_LEFT_SIDE;
      break;
    case AWT_E_RESIZE_CURSOR:
      gdk_cursor_type = GDK_RIGHT_SIDE;
      break;
    case AWT_HAND_CURSOR:
      gdk_cursor_type = GDK_HAND2;
      break;
    case AWT_MOVE_CURSOR:
      gdk_cursor_type = GDK_FLEUR;
      break;
    default:
      gdk_cursor_type = GDK_LEFT_PTR;
    }
      
  widget = get_widget(GTK_WIDGET(ptr));
  
  win = widget->window;
  if ((widget->window) == NULL)
    win = GTK_WIDGET(ptr)->window;
    
  if (image == NULL)
    gdk_cursor = gdk_cursor_new (gdk_cursor_type);
  else
    gdk_cursor
      = gdk_cursor_new_from_pixbuf (gdk_drawable_get_display (win),
				    cp_gtk_image_get_pixbuf (env, image),
				    x, y);

  gdk_window_set_cursor (win, gdk_cursor);
  gdk_cursor_unref (gdk_cursor);

  /* Make sure the cursor is replaced on screen. */
  gdk_flush();
}
コード例 #29
0
static PlatformRefPtr<GdkCursor> createCustomCursor(Image* image, const IntPoint& hotSpot)
{
    IntPoint effectiveHotSpot = determineHotSpot(image, hotSpot);
    PlatformRefPtr<GdkPixbuf> pixbuf = adoptPlatformRef(image->getGdkPixbuf());
    return adoptPlatformRef(gdk_cursor_new_from_pixbuf(gdk_display_get_default(), pixbuf.get(), effectiveHotSpot.x(), effectiveHotSpot.y()));
}
コード例 #30
0
ファイル: iupgtk_image.c プロジェクト: svn2github/iup-iup
void* iupdrvImageCreateCursor(Ihandle *ih)
{
  GdkCursor *cursor;
  int hx, hy, bpp;

  hx=0; hy=0;
  iupStrToIntInt(iupAttribGet(ih, "HOTSPOT"), &hx, &hy, ':');

  bpp = iupAttribGetInt(ih, "BPP");

  if (bpp == 8 && !iupAttribGet(ih, "3"))
  {
    GdkPixmap *source, *mask;
    GdkColor fg, bg;
    unsigned char r, g, b;
    char *sbits, *mbits, *sb, *mb;
    int y, x, line_size = (ih->currentwidth+7)/8;
    int size_bytes = line_size*ih->currentheight;
    unsigned char* imgdata = (unsigned char*)iupAttribGetStr(ih, "WID");

    r = 255; g = 255; b = 255;
    iupStrToRGB(iupAttribGet(ih, "1"), &r, &g, &b );
    iupgdkColorSet(&fg, r, g, b);

    r = 0; g = 0; b = 0;
    iupStrToRGB(iupAttribGet(ih, "2"), &r, &g, &b );
    iupgdkColorSet(&bg, r, g, b);

    sbits = (char*)malloc(2*size_bytes);
    if (!sbits) return NULL;
    memset(sbits, 0, 2*size_bytes);
    mbits = sbits + size_bytes;

    sb = sbits;
    mb = mbits;
    for (y=0; y<ih->currentheight; y++)
    {
      for (x=0; x<ih->currentwidth; x++)
      {
        int byte = x/8;
        int bit = x%8;
        int index = (int)imgdata[y*ih->currentwidth+x];
        /* index==0 is transparent */
        if (index == 1)
          sb[byte] = (char)(sb[byte] | (1<<bit));
        if (index != 0)
          mb[byte] = (char)(mb[byte] | (1<<bit));
      }

      sb += line_size;
      mb += line_size;
    }
  
    source = gdk_bitmap_create_from_data(NULL, sbits, ih->currentwidth, ih->currentheight);
    mask = gdk_bitmap_create_from_data(NULL, mbits, ih->currentwidth, ih->currentheight);

    cursor = gdk_cursor_new_from_pixmap(source, mask, &fg, &bg, hx, hy);

    gdk_pixmap_unref(source);
    gdk_pixmap_unref(mask);
    free(sbits);
  }
  else
  {
    GdkPixbuf* pixbuf = iupdrvImageCreateImage(ih, NULL, 0);
    cursor = gdk_cursor_new_from_pixbuf(gdk_display_get_default(), pixbuf, hx, hy);
    g_object_unref(pixbuf);
  }

  return cursor;
}