Ejemplo n.º 1
0
static void port_display_expose(GdkEventExpose *ev,
	GtkWidget *widget, GdkRectangle *rect, gdouble sliderstate, GdkPixbuf *image)
{
	cairo_t *cr = gdk_cairo_create(gtk_widget_get_window(widget));
    GxPortDisplay *port_display = GX_PORT_DISPLAY(widget);
    GdkRegion *region;
	region = gdk_region_rectangle (&widget->allocation);
	gdk_region_intersect (region, ev->region);
    gdk_cairo_region (cr, region);
    cairo_clip (cr);
	gdk_cairo_set_source_pixbuf(cr, image, rect->x - (rect->width-(gint)sliderstate), rect->y);
	cairo_rectangle(cr, rect->x, rect->y, rect->width, rect->height);
	cairo_fill(cr);
    if (port_display->cutoff_low + port_display->cutoff_high) {
      cairo_set_source_rgba (cr, 0.8, 0.1, 0.1, 0.4);
      cairo_set_line_width(cr, rect->height);
      gint low = rect->width * port_display->cutoff_low * 0.01;
      gint high = (rect->width* port_display->cutoff_high * 0.01)-2;
      gint lw = rect->height/2;
      cairo_move_to(cr,rect->x, rect->y+lw);
      cairo_line_to(cr,rect->x + low, rect->y+lw);
      cairo_stroke (cr);
      cairo_move_to(cr,rect->width - high, rect->y+lw);
      cairo_line_to(cr,rect->width+2, rect->y+lw);
      cairo_stroke (cr);
      cairo_set_source_rgba (cr, 0.1, 0.6, 0.1, 0.4);
      cairo_move_to(cr,rect->x+ low, rect->y+lw);
      cairo_line_to(cr,rect->width - high, rect->y+lw);
      cairo_stroke (cr);
      
    }
	cairo_destroy(cr);
    gdk_region_destroy (region);
}
Ejemplo n.º 2
0
/* Returns the intersection of two regions. */
int
clip_GDK_REGIONSINTERSECT(ClipMachine * ClipMachineMemory)
{
   C_object *creg = _fetch_co_arg(ClipMachineMemory);

   C_object *creg2 = _fetch_cobject(ClipMachineMemory, _clip_spar(ClipMachineMemory, 2));

   C_object *cdest;

   CHECKCOBJ(creg, GDK_IS_REGION(creg->object));
   CHECKARG2(2, MAP_type_of_ClipVarType, NUMERIC_type_of_ClipVarType);
   CHECKCOBJ(creg2, GDK_IS_REGION(creg->object));

   gdk_region_intersect(GDK_REGION(creg), GDK_REGION(creg2));

   if (creg)
    {
       cdest = _register_object(ClipMachineMemory, GDK_REGION(creg), GDK_TYPE_REGION, NULL, NULL);
       if (cdest)
	  _clip_mclone(ClipMachineMemory, RETPTR(ClipMachineMemory), &cdest->obj);
    }

   return 0;
 err:
   return 1;
}
gboolean scenemanager_can_draw_rectangle(scenemanager_t* pSceneManager, GdkRectangle* pRect, gint nFlags)
{
	//
	// 1) Enforce on-screen rules
	//
	if(nFlags & SCENEMANAGER_FLAG_FULLY_ON_SCREEN) {
		// basic rect1 contains rect2 test
		if((pRect->x) <= 0) return FALSE;
		if((pRect->y) <= 0) return FALSE;
		if((pRect->x + pRect->width) > pSceneManager->nWindowWidth) return FALSE;
		if((pRect->y + pRect->height) > pSceneManager->nWindowHeight) return FALSE;
	}
	else if(nFlags & SCENEMANAGER_FLAG_PARTLY_ON_SCREEN) {
		// basic rect intersect test
		if((pRect->x + pRect->width) <= 0) return FALSE;
		if((pRect->y + pRect->height) <= 0) return FALSE;
		if((pRect->x) > pSceneManager->nWindowWidth) return FALSE;
		if((pRect->y) > pSceneManager->nWindowHeight) return FALSE;
	}

	//
	// 2) Enforce overlap rules
	//
	GdkRegion* pNewRegion = gdk_region_rectangle(pRect);

	gdk_region_intersect(pNewRegion, pSceneManager->pTakenRegion); // sets pNewRegion to the intersection of itself and the 'taken region'
	gboolean bOK = gdk_region_empty(pNewRegion);	// it's ok to draw here if the intersection is empty
	gdk_region_destroy(pNewRegion);

	return bOK;
}
Ejemplo n.º 4
0
bool wxRegion::DoIntersect( const wxRegion& region )
{
    if (region.m_refData == NULL || m_refData == NULL)
        return false;

    AllocExclusive();

#ifdef __WXGTK3__
    cairo_region_intersect(M_REGIONDATA->m_region, M_REGIONDATA_OF(region)->m_region);
#else
    gdk_region_intersect( M_REGIONDATA->m_region, region.GetRegion() );
#endif

    return true;
}
Ejemplo n.º 5
0
static gboolean
about_dialog_anim_expose (GtkWidget       *widget,
                          GdkEventExpose  *event,
                          GimpAboutDialog *dialog)
{
  GtkStyle      *style = gtk_widget_get_style (widget);
  cairo_t       *cr;
  GtkAllocation  allocation;
  gint           x, y;
  gint           width, height;

  if (! dialog->visible)
    return FALSE;

  cr = gdk_cairo_create (event->window);

  gdk_cairo_set_source_color (cr, &style->text[GTK_STATE_NORMAL]);

  gtk_widget_get_allocation (widget, &allocation);
  pango_layout_get_pixel_size (dialog->layout, &width, &height);

  x = (allocation.width  - width)  / 2;
  y = (allocation.height - height) / 2;

  if (dialog->textrange[1] > 0)
    {
      GdkRegion *covered_region;

      covered_region = gdk_pango_layout_get_clip_region (dialog->layout,
                                                         x, y,
                                                         dialog->textrange, 1);

      gdk_region_intersect (covered_region, event->region);

      gdk_cairo_region (cr, covered_region);
      cairo_clip (cr);

      gdk_region_destroy (covered_region);
    }

  cairo_move_to (cr, x, y);

  pango_cairo_show_layout (cr, dialog->layout);

  cairo_destroy (cr);

  return FALSE;
}
Ejemplo n.º 6
0
bool wxRegion::DoIntersect( const wxRegion& region )
{
    wxCHECK_MSG( region.Ok(), false, _T("invalid region") );

    if (!m_refData)
    {
        // intersecting with invalid region doesn't make sense
        return false;
    }

    AllocExclusive();

    gdk_region_intersect( M_REGIONDATA->m_region, region.GetRegion() );

    return true;
}
gboolean scenemanager_can_draw_polygon(scenemanager_t* pSceneManager, GdkPoint *pPoints, gint nNumPoints, gint nFlags)
{
	//
	// 1) Enforce on-screen rules
	//
	if(nFlags & SCENEMANAGER_FLAG_FULLY_ON_SCREEN) {
		// all points must be within screen box
		gint i;
		for(i=0 ; i<nNumPoints ; i++) {
			GdkPoint* pPoint = &pPoints[i];
			if(pPoint->x < 0 || pPoint->x > pSceneManager->nWindowWidth) return FALSE;
			if(pPoint->y < 0 || pPoint->y > pSceneManager->nWindowHeight) return FALSE;
		}
		// else go on to test below
	}
	else if(nFlags & SCENEMANAGER_FLAG_PARTLY_ON_SCREEN) {
		// one point must be withing screen box   XXX: handle polygon bigger than window case?
		gint i;
		gboolean bFound = FALSE;
		for(i=0 ; i<nNumPoints ; i++) {
			GdkPoint* pPoint = &pPoints[i];
			if(pPoint->x > 0 && pPoint->x < pSceneManager->nWindowWidth) {
				bFound = TRUE;
				break;
			}
			if(pPoint->y > 0 && pPoint->y < pSceneManager->nWindowHeight) {
				bFound = TRUE;
				break;
			}
		}
		if(!bFound) return FALSE;
		// else go on to test below
	}

	//
	// 2) Enforce overlap rules
	//
	GdkRegion* pNewRegion = gdk_region_polygon(pPoints, nNumPoints, GDK_WINDING_RULE);

	gdk_region_intersect(pNewRegion, pSceneManager->pTakenRegion); // sets pNewRegion to the intersection of itself and the 'taken region'
	gboolean bOK = gdk_region_empty(pNewRegion);	// it's ok to draw here if the intersection is empty
	gdk_region_destroy(pNewRegion);

	return bOK;
}
Ejemplo n.º 8
0
void
_gdk_window_process_expose (GdkWindow *window,
			    GdkRegion *invalidate_region)
{
  GdkWindowImplWin32 *impl;
  GdkRegion *clip_region;
  impl = GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (window)->impl);
  
  GDK_NOTE (EVENTS, g_print ("_gdk_window_process_expose: %p %s\n",
			     GDK_WINDOW_HWND (window),
			     _gdk_win32_gdkregion_to_string (invalidate_region)));
  clip_region = gdk_region_rectangle (&impl->position_info.clip_rect);
  gdk_region_intersect (invalidate_region, clip_region);

  if (!gdk_region_empty (invalidate_region))
    gdk_window_invalidate_region (window, invalidate_region, FALSE);
  
  gdk_region_destroy (clip_region);
}
Ejemplo n.º 9
0
static gboolean
about_dialog_anim_expose (GtkWidget       *widget,
                          GdkEventExpose  *event,
                          GimpAboutDialog *dialog)
{
  GdkGC *text_gc;
  gint   x, y;
  gint   width, height;

  if (! dialog->visible)
    return FALSE;

  text_gc = widget->style->text_gc[GTK_STATE_NORMAL];

  pango_layout_get_pixel_size (dialog->layout, &width, &height);

  x = (widget->allocation.width - width) / 2;
  y = (widget->allocation.height - height) / 2;

  if (dialog->textrange[1] > 0)
    {
      GdkRegion *covered_region = NULL;
      GdkRegion *rect_region;

      covered_region = gdk_pango_layout_get_clip_region (dialog->layout,
                                                         x, y,
                                                         dialog->textrange, 1);

      rect_region = gdk_region_rectangle (&event->area);

      gdk_region_intersect (covered_region, rect_region);
      gdk_region_destroy (rect_region);

      gdk_gc_set_clip_region (text_gc, covered_region);
      gdk_region_destroy (covered_region);
    }

  gdk_draw_layout (widget->window, text_gc, x, y, dialog->layout);

  gdk_gc_set_clip_region (text_gc, NULL);

  return FALSE;
}
Ejemplo n.º 10
0
Archivo: cdgdk.c Proyecto: LuaDist/cd
static void sCombineRegion(cdCtxCanvas *ctxcanvas, GdkRegion* rgn)
{
  switch(ctxcanvas->canvas->combine_mode)
  {                          
  case CD_UNION:
    gdk_region_union(ctxcanvas->new_rgn, rgn);
    break;
  case CD_INTERSECT:   
    gdk_region_intersect(ctxcanvas->new_rgn, rgn);
    break;
  case CD_DIFFERENCE:           
    gdk_region_subtract(ctxcanvas->new_rgn, rgn);
    break;
  case CD_NOTINTERSECT:
    gdk_region_xor(ctxcanvas->new_rgn, rgn);
    break;
  }

  gdk_region_destroy(rgn);
}
Ejemplo n.º 11
0
/* Draw handler for the pixbuf canvas item */
static void
foo_canvas_pixbuf_draw (FooCanvasItem *item, GdkDrawable *drawable,
			  GdkEventExpose *expose)
{
	FooCanvasPixbuf *gcp;
	PixbufPrivate *priv;
	GdkRectangle display_rect, draw_rect;
	GdkRegion *draw_region;
	int w, h;

	gcp = FOO_CANVAS_PIXBUF (item);
	priv = gcp->priv;

	if (!priv->pixbuf)
		return;

	/* Compute the area we need to repaint */

	w = item->x2 - item->x1;
	h = item->y2 - item->y1;

	display_rect.x = item->x1;
	display_rect.y = item->y1;
	display_rect.width  = w;
	display_rect.height = h;
	draw_region = gdk_region_rectangle (&display_rect);
	gdk_region_intersect (draw_region, expose->region);
	if (!gdk_region_empty (draw_region)) {
		gdk_region_get_clipbox (draw_region, &draw_rect);
		gdk_draw_pixbuf (drawable, NULL, priv->pixbuf_scaled,
			/* pixbuf 0, 0 is at pix_rect.x, pix_rect.y */
			     draw_rect.x - display_rect.x,
			     draw_rect.y - display_rect.y,
			     draw_rect.x,
			     draw_rect.y,
			     draw_rect.width,
			     draw_rect.height,
			     GDK_RGB_DITHER_NORMAL, 0, 0);
	}
	gdk_region_destroy (draw_region);
}
Ejemplo n.º 12
0
static GdkRegion *
gdk_window_clip_changed (GdkWindow    *window,
			 GdkRectangle *old_clip,
			 GdkRectangle *new_clip)
{
  GdkWindowImplWin32 *impl;
  GdkWindowObject *obj;
  GdkRegion *old_clip_region;
  GdkRegion *new_clip_region;
  
  if (((GdkWindowObject *)window)->input_only)
    return NULL;

  obj = (GdkWindowObject *) window;
  impl = GDK_WINDOW_IMPL_WIN32 (obj->impl);
  
  old_clip_region = gdk_region_rectangle (old_clip);
  new_clip_region = gdk_region_rectangle (new_clip);

  /* Trim invalid region of window to new clip rectangle
   */
  if (obj->update_area)
    gdk_region_intersect (obj->update_area, new_clip_region);

  /* Invalidate newly exposed portion of window
   */
  gdk_region_subtract (new_clip_region, old_clip_region);
  if (!gdk_region_empty (new_clip_region))
    gdk_window_tmp_unset_bg (window);
  else
    {
      gdk_region_destroy (new_clip_region);
      new_clip_region = NULL;
    }
  gdk_region_destroy (old_clip_region);

  return new_clip_region;
}
Ejemplo n.º 13
0
static GdkRegion *
get_selected_clip (GtkTextRenderState *render_state,
                   PangoLayout        *layout,
                   PangoLayoutLine    *line,
                   int                 x,
                   int                 y,
                   int                 height,
                   int                 start_index,
                   int                 end_index)
{
  gint *ranges;
  gint n_ranges, i;
  GdkRegion *clip_region = gdk_region_new ();
  GdkRegion *tmp_region;

  pango_layout_line_get_x_ranges (line, start_index, end_index, &ranges, &n_ranges);

  for (i=0; i < n_ranges; i++)
    {
      GdkRectangle rect;

      rect.x = x + PANGO_PIXELS (ranges[2*i]);
      rect.y = y;
      rect.width = PANGO_PIXELS (ranges[2*i + 1]) - PANGO_PIXELS (ranges[2*i]);
      rect.height = height;
      
      gdk_region_union_with_rect (clip_region, &rect);
    }

  tmp_region = gdk_region_rectangle (&render_state->clip_rect);
  gdk_region_intersect (clip_region, tmp_region);
  gdk_region_destroy (tmp_region);

  g_free (ranges);
  return clip_region;
}
Ejemplo n.º 14
0
static VALUE
rg_intersect(VALUE self, VALUE region)
{
    gdk_region_intersect(_SELF(self), _SELF(region));
    return self;
}
Ejemplo n.º 15
0
static gboolean gx_selector_expose (GtkWidget *widget, GdkEventExpose *event)
{
	g_assert(GX_IS_SELECTOR(widget));
	GxSelector *selector = GX_SELECTOR(widget);
	GxSelectorPrivate *priv = selector->priv;
	int selectorstate = get_selector_state(selector);
    
    gx_selector_create_icon(selector);
    
	PangoLayout *layout = gtk_widget_create_pango_layout(widget, NULL);
	GdkRectangle arrow, text;
	gint off_x, off_y;
	gx_selector_get_positions(widget, &arrow, &text, &off_x, &off_y);
    gint rad;
    float bevel;
    gtk_widget_style_get(widget, "border-radius", &rad, "bevel", &bevel, NULL);
    if (!rad)
        rad = 0;
    if (!bevel)
        bevel = 0;
    cairo_t * cr = gdk_cairo_create(GDK_DRAWABLE(widget->window));
    GdkRegion *reg = gdk_region_rectangle(&widget->allocation);
    if (event->region)
        gdk_region_intersect(reg, event->region);
    gdk_cairo_region(cr, reg);
    cairo_clip (cr);
   
    gx_draw_rect(widget, "bg", NULL, widget->allocation.x,
        widget->allocation.y + (widget->allocation.height - widget->requisition.height) / 2,
        widget->allocation.width,
        widget->requisition.height,
        rad,
        bevel);
    
    if (widget->style->ythickness >= 3)
        gx_draw_inset(widget, text.x, text.y, text.width, text.height,
            std::max(rad - std::max(widget->style->ythickness, widget->style->ythickness), 0), 1);
        
    gx_draw_rect(widget, "base", NULL, text.x,
        text.y,
        text.width,
        text.height,
        std::max(rad - std::max(widget->style->ythickness, widget->style->ythickness), 0),
        0);
    
    gx_draw_glass(widget, text.x, text.y, text.width, text.height,
        std::max(rad - std::max(widget->style->ythickness, widget->style->ythickness), 0));
    
    gdk_cairo_set_source_pixbuf(cr, selector->icon, arrow.x, arrow.y);
    cairo_rectangle(cr, arrow.x, arrow.y, arrow.width, arrow.height);
    cairo_fill(cr);
    
	cairo_destroy(cr);
    
	if (selector->model) {
		gint x, y;
		PangoRectangle logical;
		char *s;
		GtkTreeIter iter;
		gtk_tree_model_iter_nth_child(selector->model, &iter, NULL, selectorstate);
		gtk_tree_model_get(selector->model, &iter, 0, &s, -1);
		pango_layout_set_text(layout, s, -1);
		pango_layout_get_pixel_extents(layout, NULL, &logical);
		x = text.x + (text.width - logical.width) / 2;
		y = text.y + off_y + (priv->textsize.height - logical.height)/ 2;
		gtk_paint_layout(widget->style, widget->window, gtk_widget_get_state(widget),
		                 FALSE, NULL, widget, "label", x, y, layout);
		g_free(s);
	}
	g_object_unref(layout);
	gdk_region_destroy(reg);
	return TRUE;
}
Ejemplo n.º 16
0
/* Doesn't handle HIPPO_WINDOW_STATE_ACTIVE - see comment below */
static HippoWindowState
get_window_state(Display *display, Window window)
{
    HippoWindowState result =  HIPPO_WINDOW_STATE_HIDDEN;
    XWindowAttributes window_attributes;
    GdkRectangle rect;
    GdkRegion *visible_region = NULL;
    Window child = None;
    
    Window root;
    Window parent;
    Window *children = NULL;
    guint n_children;

    gdk_error_trap_push();
    
    /* First check if the window and all ancestors are mapped
     */

    if (!XGetWindowAttributes(display, window, &window_attributes)) {
        g_debug("XGetWindowAttributes failed\n");
        goto out;
    }

    if (window_attributes.map_state != IsViewable)
        goto out;

    /* Get the area of the window in parent coordinates
     */
    rect.x = window_attributes.x;
    rect.y = window_attributes.y;
    rect.width = window_attributes.width;
    rect.height = window_attributes.height;

    visible_region = gdk_region_rectangle(&rect);

    if (!XQueryTree(display, window, &root, &parent, &children, &n_children)) {
        g_debug("XQueryTree failed\n");
        goto out;
    }

    XFree(children);
    children = NULL;

    child = window;
    window = parent;

    /* Walk up the hierarchy, clipping to parents, and subtracting
     * overlayed siblings (yuck!)
     */
    while (TRUE) {
        GdkRegion *parent_region;
        gboolean seen_child = FALSE;
        int x, y;
        unsigned int width, height, border, depth;
        unsigned int i;

        gdk_region_get_clipbox(visible_region, &rect);
        
        /* Clip to parent */
        if (!XGetGeometry(display, window, &root, &x, &y, &width, &height, &border, &depth)) {
            g_debug("XGetGeometry failed\n");
            goto out;
        }

        rect.x = 0;
        rect.y = 0;
        rect.width = width;
        rect.height= height;

        parent_region = gdk_region_rectangle(&rect);
        gdk_region_intersect(visible_region, parent_region);
        gdk_region_destroy(parent_region);

        if (gdk_region_empty(visible_region))
            goto out;
                
        if (!XQueryTree(display, window, &root, &parent, &children, &n_children)) {
            g_debug("XQueryTree failed\n");
            goto out;
        }

        for (i = 0; i < n_children; i++) {
            if (seen_child) {
                /* A sibling above */
                GdkRegion *child_region;
                XWindowAttributes child_attributes;
                
                if (!XGetWindowAttributes(display, children[i], &child_attributes)) {
                    g_debug("XGetWindowAttributes failed for child\n");
                    goto out;
                }

                if (child_attributes.map_state == IsViewable) {
                    rect.x = child_attributes.x - child_attributes.border_width;
                    rect.y = child_attributes.y - child_attributes.border_width;
                    rect.width = child_attributes.width + 2 * child_attributes.border_width;
                    rect.height = child_attributes.height + 2 * child_attributes.border_width;

                    child_region = gdk_region_rectangle(&rect);
                    gdk_region_subtract(visible_region, child_region);
                    gdk_region_destroy(child_region);
                    
                    if (gdk_region_empty(visible_region))
                        goto out;
                }
                
            } else if (children[i] == child) {
                seen_child = TRUE;
            }
        }
    
        XFree(children);
        children = NULL;

        if (window == root)
            break;
        
        child = window;
        window = parent;

        /* Translate to parent coordinates */
        gdk_region_offset(visible_region, x, y);
    }

    if (!gdk_region_empty(visible_region))
        result = HIPPO_WINDOW_STATE_ONSCREEN;

 out:
    gdk_error_trap_pop();

    if (children)
        XFree(children);

    if (visible_region)
        gdk_region_destroy(visible_region);

    return result;
}