Пример #1
0
static void
gtk_bubble_window_update_shape (GtkBubbleWindow *window)
{
  cairo_surface_t *surface;
  cairo_region_t *region;
  GdkWindow *win;
  cairo_t *cr;

  win = gtk_widget_get_window (GTK_WIDGET (window));
  surface =
    gdk_window_create_similar_surface (win,
                                       CAIRO_CONTENT_COLOR_ALPHA,
                                       gdk_window_get_width (win),
                                       gdk_window_get_height (win));

  cr = cairo_create (surface);
  gtk_bubble_window_apply_border_path (window, cr);
  cairo_fill (cr);
  cairo_destroy (cr);

  region = gdk_cairo_region_create_from_surface (surface);
  cairo_surface_destroy (surface);

  if (!gtk_widget_is_composited (GTK_WIDGET (window)))
    gtk_widget_shape_combine_region (GTK_WIDGET (window), region);

  gtk_widget_input_shape_combine_region (GTK_WIDGET (window), region);
  cairo_region_destroy (region);
}
static void
maybe_update_shape (GtkWidget *widget)
{
	cairo_t *cr;
	cairo_surface_t *surface;
	cairo_region_t *region;

	/* fallback to XShape only for non-composited clients */
	if (gtk_widget_is_composited (widget)) {
		gtk_widget_shape_combine_region (widget, NULL);
		return;
	}

	surface = gdk_window_create_similar_surface (gtk_widget_get_window (widget),
						     CAIRO_CONTENT_COLOR_ALPHA,
						     gtk_widget_get_allocated_width (widget),
						     gtk_widget_get_allocated_height (widget));

	cr = cairo_create (surface);
	label_draw_background_and_frame (widget, cr, TRUE);
	cairo_destroy (cr);

	region = gdk_cairo_region_create_from_surface (surface);
	gtk_widget_shape_combine_region (widget, region);

	cairo_surface_destroy (surface);
	cairo_region_destroy (region);
}
Пример #3
0
static void
maybe_update_shape (GtkTooltip *tooltip)
{
  cairo_t *cr;
  cairo_surface_t *surface;
  cairo_region_t *region;

  /* fallback to XShape only for non-composited clients */
  if (gtk_widget_is_composited (tooltip->window))
    {
      gtk_widget_shape_combine_region (tooltip->window, NULL);
      return;
    }

  surface = gdk_window_create_similar_surface (gtk_widget_get_window (tooltip->window),
                                               CAIRO_CONTENT_COLOR_ALPHA,
                                               gtk_widget_get_allocated_width (tooltip->window),
                                               gtk_widget_get_allocated_height (tooltip->window));

  cr = cairo_create (surface);
  paint_background_and_frame (tooltip, cr);
  cairo_destroy (cr);

  region = gdk_cairo_region_create_from_surface (surface);
  gtk_widget_shape_combine_region (tooltip->window, region);

  cairo_surface_destroy (surface);
  cairo_region_destroy (region);
}
Пример #4
0
static gboolean on_draw(GtkWidget *widget, gpointer data)
{
    cairo_t *cr;
    GtkAllocation alloc;
    gtk_widget_get_allocation(widget, &alloc);
    gint width = alloc.width;
    gint height = alloc.height;
    gint r = 5;

    cr = gdk_cairo_create(gtk_widget_get_window(widget));
    cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
                                                          width,
                                                          height);
    cairo_t *cr2 = cairo_create(surface);
    draw_round_rectangle(cr2, 0, 0, width, height, r);
    cairo_stroke_preserve(cr2);
    cairo_fill(cr2) ;
    cairo_destroy(cr2);

    cairo_region_t *region = gdk_cairo_region_create_from_surface(surface);
    gtk_widget_shape_combine_region(widget, region);

    cairo_set_line_width(cr, 0.3);
    cairo_set_source_rgb(cr, 0.78, 0.78, 0.78);
    draw_round_rectangle(cr, 0, 0, width, height, r);
    cairo_stroke(cr);

    cairo_region_destroy(region);
    cairo_surface_destroy(surface);
    cairo_destroy(cr);
}
Пример #5
0
static void
dnd_hints_realized_cb(GtkWidget *window, GtkWidget *pix)
{
	GdkPixbuf *pixbuf;
	cairo_surface_t *surface;
	cairo_region_t *region;
	cairo_t *cr;

	pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(pix));

	surface = cairo_image_surface_create(CAIRO_FORMAT_A1,
	                                     gdk_pixbuf_get_width(pixbuf),
	                                     gdk_pixbuf_get_height(pixbuf));

	cr = cairo_create(surface);
	gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0);
	cairo_paint(cr);
	cairo_destroy(cr);

	region = gdk_cairo_region_create_from_surface(surface);
	gtk_widget_shape_combine_region(window, region);
	cairo_region_destroy(region);

	cairo_surface_destroy(surface);
}
Пример #6
0
static void
update_shape_region (cairo_surface_t *surface,
		     WindowData      *windata)
{
	if (windata->width == windata->last_width && windata->height == windata->last_height)
	{
		return;
	}

	if (windata->width == 0 || windata->height == 0)
	{
		GtkAllocation allocation;
		gtk_widget_get_allocation (windata->win, &allocation);

		windata->width = MAX (allocation.width, 1);
		windata->height = MAX (allocation.height, 1);
	}

	if (!windata->composited) {
		cairo_region_t *region;

		region = gdk_cairo_region_create_from_surface (surface);
		gtk_widget_shape_combine_region (windata->win, region);
		cairo_region_destroy (region);
	} else {
		gtk_widget_shape_combine_region (windata->win, NULL);
		return;
	}

	windata->last_width = windata->width;
	windata->last_height = windata->height;
}
Пример #7
0
void on_monitors_changed ( GdkScreen *screen,
			   gpointer   user_data) 
{
  GromitData *data = (GromitData *) user_data;

  if(data->debug)
    g_printerr("DEBUG: screen size changed!\n");

  // get new sizes
  data->width = gdk_screen_get_width (data->screen);
  data->height = gdk_screen_get_height (data->screen);

  // change size
  gtk_widget_set_size_request(GTK_WIDGET(data->win), data->width, data->height);
  // try to set transparent for input
  cairo_region_t* r =  cairo_region_create();
  gtk_widget_input_shape_combine_region(data->win, r);
  cairo_region_destroy(r);

  /* recreate the shape surface */
  cairo_surface_t *new_shape = cairo_image_surface_create(CAIRO_FORMAT_ARGB32 ,data->width, data->height);
  cairo_t *cr = cairo_create (new_shape);
  cairo_set_source_surface (cr, data->backbuffer, 0, 0);
  cairo_paint (cr);
  cairo_destroy (cr);
  cairo_surface_destroy(data->backbuffer);
  data->backbuffer = new_shape;
 
  /*
     these depend on the shape surface
  */
  GHashTableIter it;
  gpointer value;
  g_hash_table_iter_init (&it, data->tool_config);
  while (g_hash_table_iter_next (&it, NULL, &value)) 
    paint_context_free(value);
  g_hash_table_remove_all(data->tool_config);


  parse_config(data); // also calls paint_context_new() :-(


  data->default_pen = paint_context_new (data, GROMIT_PEN,
					 data->red, 7, 0, 1);
  data->default_eraser = paint_context_new (data, GROMIT_ERASER,
					    data->red, 75, 0, 1);

  if(!data->composited) // set shape
    {
      cairo_region_t* r = gdk_cairo_region_create_from_surface(data->backbuffer);
      gtk_widget_shape_combine_region(data->win, r);
      cairo_region_destroy(r);
    }

  setup_input_devices(data);


  gtk_widget_show_all (data->win);
}
Пример #8
0
void gMainWindow::drawMask()
{
	bool do_remap = false;
	 
	if (!isVisible())
		return;
	
#ifdef GTK3

	cairo_region_t *mask;

	if (_mask && _picture)
		mask = gdk_cairo_region_create_from_surface(_picture->getSurface());
	else
		mask = NULL;

	gdk_window_shape_combine_region(gtk_widget_get_window(border), mask, 0, 0);
	if (mask)
		cairo_region_destroy(mask);

	refresh();

#else

	GdkBitmap *mask = (_mask && _picture) ? _picture->getMask() : NULL;
	do_remap = !mask && _masked;

	gdk_window_shape_combine_mask(border->window, mask, 0, 0);

#endif

	if (_picture)
	{
		gtk_widget_set_app_paintable(border, TRUE);
		gtk_widget_realize(border);
		gtk_widget_realize(widget);
		for (int i = 0; i < controlCount(); i++)
			getControl(i)->refresh();
	}
	else if (!_transparent)
	{
		gtk_widget_set_app_paintable(border, FALSE);
		setRealBackground(background());
	}
	
	_masked = mask != NULL;
	
	if (do_remap)
		remap();
	else
	{
		if (!_skip_taskbar)
		{
			setSkipTaskBar(true);
			setSkipTaskBar(false);
		}
	}
}
Пример #9
0
static cairo_region_t*
curved_rect_mask(GtkWidget *widget)
{
    GdkWindow *window;
    cairo_region_t *shape;
    cairo_surface_t *surface;
    cairo_t *cr;
    double w, h;
    int radius;

    if (!gtk_widget_get_realized(widget))
        return NULL;

    window = gtk_widget_get_window(widget);
    w = gdk_window_get_width(window);
    h = gdk_window_get_height(window);
    if (w <= 50 || h <= 50)
        return NULL;
    radius = h / 4;
    surface = gdk_window_create_similar_surface(window,
                                                CAIRO_CONTENT_COLOR_ALPHA,
                                                w, h);
    cr = cairo_create (surface);

    if (radius > w / 2)
        radius = w / 2;
    if (radius > h / 2)
        radius = h / 2;

    // fill shape with black
    cairo_save(cr);
    cairo_rectangle (cr, 0, 0, w, h);
    cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
    cairo_fill (cr);
    cairo_restore (cr);

    cairo_move_to  (cr, 0, radius);
    cairo_curve_to (cr, 0 , 0, 0 , 0, radius, 0);
    cairo_line_to (cr, w - radius, 0);
    cairo_curve_to (cr, w, 0, w, 0, w, radius);
    cairo_line_to (cr, w , h - radius);
    cairo_curve_to (cr, w, h, w, h, w - radius, h);
    cairo_line_to (cr, 0 + radius, h);
    cairo_curve_to (cr, 0, h, 0, h, 0, h - radius);

    cairo_close_path(cr);

    cairo_set_source_rgb(cr, 1, 1, 1);
    cairo_fill(cr);

    cairo_destroy(cr);
    shape = gdk_cairo_region_create_from_surface(surface);
    cairo_surface_destroy(surface);

    return shape;
}
Пример #10
0
    virtual bool DoSetShape(GdkWindow *window)
    {
        if (!m_mask)
            return false;

#ifdef __WXGTK3__
        cairo_region_t* region = gdk_cairo_region_create_from_surface(m_mask);
        gdk_window_shape_combine_region(window, region, 0, 0);
        cairo_region_destroy(region);
#else
        gdk_window_shape_combine_mask(window, m_mask, 0, 0);
#endif

        return true;
    }
Пример #11
0
gboolean on_draw(GtkWidget *widget, gpointer data)
{
    GtkAllocation alloc;
    gint x, y, width, height, r;
    gtk_widget_get_allocation(widget, &alloc);
    x = alloc.x;
    y = alloc.y;
    width = alloc.width;
    height = alloc.height;
    r = 5;

    cairo_t *cr = gdk_cairo_create(gtk_widget_get_window(widget));

    cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
    cairo_t *cr2 = cairo_create(surface);

    cairo_move_to(cr2, r, 0);
    cairo_line_to(cr2, width-r, 0);

	cairo_move_to(cr2, width, r);
	cairo_line_to(cr2, width, height-r);

	cairo_move_to(cr2, width-r, height);
	cairo_move_to(cr2, r, height);

	cairo_move_to(cr2, 0, height-r);
	cairo_line_to(cr2, 0, r);

	cairo_arc(cr2, r, r, r, G_PI, 3 * G_PI / 2.0 );
	cairo_arc(cr2, width-r, r, r, 3 * G_PI /2.0, 2 * G_PI);
	cairo_arc(cr2, width-r, height-r, r, 0, G_PI / 2);
	cairo_arc(cr2, r, height-r, r, G_PI / 2, G_PI);
    cairo_fill(cr2);

    cairo_set_source_rgba(cr, 0, 0, 0, 0);
    cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
    cairo_paint(cr);
 
    cairo_region_t *region = gdk_cairo_region_create_from_surface(surface);
    gtk_widget_shape_combine_region(widget, region);

    cairo_destroy(cr2);
    cairo_destroy(cr);
    cairo_region_destroy(region);
    cairo_surface_destroy(surface);

    return FALSE;
}
static void
update_shape (CsdLocatePointerData *data)
{
  cairo_t *cr;
  cairo_region_t *region;
  cairo_surface_t *mask;

  mask = cairo_image_surface_create (CAIRO_FORMAT_A1, WINDOW_SIZE, WINDOW_SIZE);
  cr = cairo_create (mask);

  locate_pointer_paint (data, cr, FALSE);

  region = gdk_cairo_region_create_from_surface (mask);
  gdk_window_shape_combine_region (data->window, region, 0, 0);

  cairo_region_destroy (region);
  cairo_destroy (cr);
  cairo_surface_destroy (mask);
}
/* Clear the background. */
void clear_background_window      ()
{
  /*
   * @HACK Deny the mouse input to go below the window putting the opacity greater than 0
   * I avoid a complete transparent window because in some operating system this would become
   * transparent to the pointer input also.
   *
   */
  gtk_window_set_opacity (GTK_WINDOW (background_data->background_window), BACKGROUND_OPACITY);

  clear_cairo_context (background_data->background_cr);

  /* This allows the mouse event to be passed to the window below. */
#ifndef _WIN32
  cairo_region_t* r = gdk_cairo_region_create_from_surface(cairo_get_target (background_data->background_cr));
  gtk_widget_input_shape_combine_region (background_data->background_window, r);
  cairo_region_destroy(r);
#endif
}
Пример #14
0
static int gtkDialogSetOpacityImageAttrib(Ihandle *ih, const char *value)
{
  GdkPixbuf* pixbuf = iupImageGetImage(value, ih, 0);
  if (pixbuf)
  {
#if GTK_CHECK_VERSION(3, 0, 0)
    GdkWindow* window = iupgtkGetWindow(ih->handle);
    if (window)
    {
      cairo_region_t *shape;

#if GTK_CHECK_VERSION(3, 10, 0)
      cairo_surface_t* surface = gdk_cairo_surface_create_from_pixbuf(pixbuf, 0, window);
#else
      int width = gdk_pixbuf_get_width(pixbuf);
      int height = gdk_pixbuf_get_height(pixbuf);
      cairo_surface_t* surface = gdk_window_create_similar_surface(window, CAIRO_CONTENT_COLOR_ALPHA, width, height);
      cairo_t* cr = cairo_create(surface);
      gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0);
      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
      cairo_paint(cr);
      cairo_destroy(cr);
#endif

      shape = gdk_cairo_region_create_from_surface(surface);
      cairo_surface_destroy(surface);

      gtk_widget_shape_combine_region(ih->handle, shape);
      cairo_region_destroy(shape);
    }
#else
    GdkBitmap* mask = NULL;
    gdk_pixbuf_render_pixmap_and_mask(pixbuf, NULL, &mask, 255);
    if (mask) 
    {
      gtk_widget_shape_combine_mask(ih->handle, mask, 0, 0);
      g_object_unref(mask);
    }
#endif
    return 1;
  }
  return 0;
}
Пример #15
0
static inline
cairo_region_t *
get_cairo_region_create_from_surface(struct qp_graph *gr,
    cairo_surface_t *surface, int width, int height)
{
  /* TODO: this is a resource pig.  Make it better. */

  cairo_rectangle_int_t rect;
  cairo_surface_t *image;
  cairo_region_t *region;
  cairo_t *cr;
  uint32_t *data, bg;
  int x, y, stride;

  if(!gr->x11)
    /* Creates region that covers the area where the
     * given surface is more than 50% opaque.
     * The below code copies this method.  This GDK
     * code is a pig too. */
    return gdk_cairo_region_create_from_surface(surface);

  if(!gr->x11->background_set)
  {
    /* We need to see what the background color is when it is
     * applied to an image.  A small image. */
    image = cairo_image_surface_create(CAIRO_FORMAT_RGB24, 1, 1);
    cr = cairo_create(image);
    cairo_set_source_rgba(cr, gr->background_color.r,
        gr->background_color.g, gr->background_color.b,
        gr->background_color.a);
    cairo_paint (cr);
    cairo_destroy (cr);
    data = (void *) cairo_image_surface_get_data(image);
    gr->x11->background = (data[0] & 0x00FFFFFF);
    cairo_surface_destroy(image);
    gr->x11->background_set = 1;
  }

  bg = gr->x11->background;

  image = cairo_image_surface_create(CAIRO_FORMAT_RGB24, width, height);
  cr = cairo_create(image);
  cairo_set_source_surface(cr, surface, 0, 0);
  cairo_paint (cr);
  cairo_destroy (cr);

  data = (void *) cairo_image_surface_get_data(image);
  stride = cairo_image_surface_get_stride(image);

  region = cairo_region_create();

  for(y=0; y < height; y++)
    {
      for(x=0; x < width; x++)
        {
          /* Search for a continuous range of "background pixels"*/
          gint x0=x;
          while(x < width)
            {
              if((data[x] & 0x00FFFFFF) == bg)
                /* This pixel is the background color */
                break;
              x++;
            }

          if(x > x0)
            {
              /* Add the pixels (x0, y) to (x, y+1) as a new rectangle
               * in the region
               */
              rect.x = x0;
              rect.width = x - x0;
              rect.y = y;
              rect.height = 1;

              cairo_region_union_rectangle(region, &rect);
            }
        }
      data += stride/4;
    }

  cairo_surface_destroy(image);

  return region;
}
Пример #16
0
static void create_win_message(char *icon, char *text, int duration)
{
  GtkWidget *gwin_message = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_has_resize_grip(GTK_WINDOW(gwin_message), FALSE);
  gtk_container_set_border_width (GTK_CONTAINER (gwin_message), 0);
  gtk_widget_realize (gwin_message);
  GdkWindow *gdkwin = gtk_widget_get_window(gwin_message);
  set_no_focus(gwin_message);

  GtkWidget *hbox = gtk_hbox_new (FALSE, 0);
  gtk_container_add (GTK_CONTAINER (gwin_message), hbox);

  if (icon[0] != '-') {
    GtkWidget *image = gtk_image_new_from_file(icon);
    if (text[0] == '-') {
#if GTK_CHECK_VERSION(2,91,0)
      GdkPixbuf *pixbuf = NULL;
      GdkPixbufAnimation *anime = NULL;
      switch(gtk_image_get_storage_type(GTK_IMAGE(image))) {
        case GTK_IMAGE_PIXBUF:
          pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(image));
          break;
        case GTK_IMAGE_ANIMATION:
          anime = gtk_image_get_animation(GTK_IMAGE(image));
          pixbuf = gdk_pixbuf_animation_get_static_image(anime);
          break;
        default:
          break;
      }
      cairo_surface_t *img = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, gdk_pixbuf_get_width(pixbuf), gdk_pixbuf_get_height(pixbuf));
      cairo_t *cr = cairo_create(img);
      gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0);
      cairo_paint(cr);
      cairo_region_t *mask = gdk_cairo_region_create_from_surface(img);
      gtk_widget_shape_combine_region(gwin_message, mask);
      cairo_region_destroy(mask);
      cairo_destroy(cr);
      cairo_surface_destroy(img);
#else
      GdkBitmap *bitmap = NULL;
      gdk_pixbuf_render_pixmap_and_mask(gdk_pixbuf_new_from_file(icon, NULL), NULL, &bitmap, 128);
      gtk_widget_shape_combine_mask(gwin_message, bitmap, 0, 0);
#endif
    }
    gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
  }

  if (text[0] != '-') {
    GtkWidget *label = gtk_label_new(text);
    gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
  }

  gtk_widget_show_all(gwin_message);

  int width, height;
  get_win_size(gwin_message, &width, &height);

  int ox=-1, oy;
  int szx, szy;
  if (tray_da_win) {
    gdk_window_get_origin  (tray_da_win, &ox, &oy);
#if !GTK_CHECK_VERSION(2,91,0)
    gdk_drawable_get_size(tray_da_win, &szx, &szy);
#else
    szx = gdk_window_get_width(tray_da_win);
    szy = gdk_window_get_height(tray_da_win);
#endif

    if (oy<height) {
      oy = szy;
    } else {
      oy -= height;
      if (oy + height > dpy_yl)
        oy = dpy_yl - height;
      if (oy < 0)
        oy = 0;
    }

    if (ox + width > dpy_xl)
      ox = dpy_xl - width;
    if (ox < 0)
      ox = 0;
  } else
  if (icon_main) {
    GdkRectangle rect;
    GtkOrientation ori;
    if (gtk_status_icon_get_geometry(icon_main, NULL, &rect, &ori)) {
      dbg("rect %d,%d\n", rect.x, rect.y, rect.width, rect.height);
      if (ori==GTK_ORIENTATION_HORIZONTAL) {
        ox=rect.x;
        if (rect.y > 100)
          oy=rect.y - height;
        else
          oy=rect.y + rect.height;
      } else {
        oy=rect.y;
        if (rect.x > 100)
          ox=rect.x - width;
        else
          ox=rect.x + rect.width;
      }
    }
  }

  if (ox < 0) {
    ox = dpy_xl - width;
    oy = dpy_yl - height;
  }

  gtk_window_move(GTK_WINDOW(gwin_message), ox, oy);

  g_timeout_add(duration, (GSourceFunc)timeout_destroy_window, gwin_message);
}
Пример #17
0
wxRegion::wxRegion( size_t n, const wxPoint *points,
                    wxPolygonFillMode fillStyle )
{
#ifdef __WXGTK3__
    // Make a cairo path from the points, draw it onto an image surface, use
    // gdk_cairo_region_create_from_surface() to get a cairo region

    // need at least 3 points to make a useful polygon
    if (n < 3)
        return;
    // get bounding rect
    int min_x = points[0].x;
    int max_x = min_x;
    int min_y = points[0].y;
    int max_y = min_y;
    size_t i;
    for (i = 1; i < n; i++)
    {
        const int x = points[i].x;
        if (min_x > x)
            min_x = x;
        else if (max_x < x)
            max_x = x;
        const int y = points[i].y;
        if (min_y > y)
            min_y = y;
        else if (max_y < y)
            max_y = y;
    }
    const int w = max_x - min_x + 1;
    const int h = max_y - min_y + 1;
    // make surface just big enough to contain polygon (A1 is native format
    //   for gdk_cairo_region_create_from_surface)
    cairo_surface_t* surface = cairo_image_surface_create(CAIRO_FORMAT_A1, w, h);
    memset(cairo_image_surface_get_data(surface), 0, cairo_image_surface_get_stride(surface) * h);
    cairo_surface_mark_dirty(surface);
    cairo_surface_set_device_offset(surface, -min_x, -min_y);
    cairo_t* cr = cairo_create(surface);
    cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE);
    if (fillStyle == wxODDEVEN_RULE)
        cairo_set_fill_rule(cr, CAIRO_FILL_RULE_EVEN_ODD);
    // make path
    cairo_move_to(cr, points[0].x, points[0].y);
    for (i = 1; i < n; i++)
        cairo_line_to(cr, points[i].x, points[i].y);
    cairo_close_path(cr);
    cairo_fill(cr);
    cairo_destroy(cr);
    cairo_surface_flush(surface);
    m_refData = new wxRegionRefData;
    M_REGIONDATA->m_region = gdk_cairo_region_create_from_surface(surface);
    cairo_surface_destroy(surface);
#else
    GdkPoint *gdkpoints = new GdkPoint[n];
    for ( size_t i = 0 ; i < n ; i++ )
    {
        gdkpoints[i].x = points[i].x;
        gdkpoints[i].y = points[i].y;
    }

    m_refData = new wxRegionRefData();

    GdkRegion* reg = gdk_region_polygon
                     (
                        gdkpoints,
                        n,
                        fillStyle == wxWINDING_RULE ? GDK_WINDING_RULE
                                                    : GDK_EVEN_ODD_RULE
                     );

    M_REGIONDATA->m_region = reg;

    delete [] gdkpoints;
#endif
}
Пример #18
0
void wxDropSource::PrepareIcon( int action, GdkDragContext *context )
{
    // get the right icon to display
    wxIcon *icon = NULL;
    if ( action & GDK_ACTION_MOVE )
        icon = &m_iconMove;
    else if ( action & GDK_ACTION_COPY )
        icon = &m_iconCopy;
    else
        icon = &m_iconNone;

#ifndef __WXGTK3__
    GdkBitmap *mask;
    if ( icon->GetMask() )
        mask = *icon->GetMask();
    else
        mask = NULL;

    GdkPixmap *pixmap = icon->GetPixmap();

    GdkColormap *colormap = gtk_widget_get_colormap( m_widget );
    gtk_widget_push_colormap (colormap);
#endif

    m_iconWindow = gtk_window_new (GTK_WINDOW_POPUP);
    gtk_widget_set_events (m_iconWindow, GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
    gtk_widget_set_app_paintable (m_iconWindow, TRUE);

#ifdef __WXGTK3__
    gtk_widget_set_visual(m_iconWindow, gtk_widget_get_visual(m_widget));
#else
    gtk_widget_pop_colormap ();
#endif

    gtk_widget_set_size_request (m_iconWindow, icon->GetWidth(), icon->GetHeight());
    gtk_widget_realize (m_iconWindow);

    g_signal_connect (m_iconWindow, "configure_event",
                      G_CALLBACK (gtk_dnd_window_configure_callback), this);

#ifdef __WXGTK3__
    cairo_t* cr = gdk_cairo_create(gtk_widget_get_window(m_iconWindow));
    icon->SetSourceSurface(cr, 0, 0);
    cairo_pattern_t* pattern = cairo_get_source(cr);
    gdk_window_set_background_pattern(gtk_widget_get_window(m_iconWindow), pattern);
    cairo_destroy(cr);
    cairo_surface_t* mask = NULL;
    if (icon->GetMask())
        mask = *icon->GetMask();
    if (mask)
    {
        cairo_region_t* region = gdk_cairo_region_create_from_surface(mask);
        gtk_widget_shape_combine_region(m_iconWindow, region);
        cairo_region_destroy(region);
    }
#else
    gdk_window_set_back_pixmap(gtk_widget_get_window(m_iconWindow), pixmap, false);

    if (mask)
        gtk_widget_shape_combine_mask (m_iconWindow, mask, 0, 0);
#endif

    gtk_drag_set_icon_widget( context, m_iconWindow, 0, 0 );
}