Пример #1
0
GdkPixmap *
ghid_render_pixmap (int cx, int cy, double zoom, int width, int height, int depth)
{
  GdkPixmap *pixmap;
  GdkDrawable *save_drawable;
  view_data save_view;
  int save_width, save_height;
  BoxType region;
  render_priv *priv = gport->render_priv;

  save_drawable = gport->drawable;
  save_view = gport->view;
  save_width = gport->width;
  save_height = gport->height;

  pixmap = gdk_pixmap_new (NULL, width, height, depth);

  /* Setup drawable and zoom factor for drawing routines
   */

  gport->drawable = pixmap;
  gport->view.coord_per_px = zoom;
  gport->width = width;
  gport->height = height;
  gport->view.width = width * gport->view.coord_per_px;
  gport->view.height = height * gport->view.coord_per_px;
  gport->view.x0 = gport->view.flip_x ? PCB->MaxWidth - cx : cx;
  gport->view.x0 -= gport->view.height / 2;
  gport->view.y0 = gport->view.flip_y ? PCB->MaxHeight - cy : cy;
  gport->view.y0 -= gport->view.width  / 2;

  /* clear background */
  gdk_draw_rectangle (pixmap, priv->bg_gc, TRUE, 0, 0, width, height);

  /* call the drawing routine */
  region.X1 = MIN(Px(0), Px(gport->width + 1));
  region.Y1 = MIN(Py(0), Py(gport->height + 1));
  region.X2 = MAX(Px(0), Px(gport->width + 1));
  region.Y2 = MAX(Py(0), Py(gport->height + 1));

  region.X1 = MAX (0, MIN (PCB->MaxWidth,  region.X1));
  region.X2 = MAX (0, MIN (PCB->MaxWidth,  region.X2));
  region.Y1 = MAX (0, MIN (PCB->MaxHeight, region.Y1));
  region.Y2 = MAX (0, MIN (PCB->MaxHeight, region.Y2));

  hid_expose_callback (&ghid_hid, &region, NULL);

  gport->drawable = save_drawable;
  gport->view = save_view;
  gport->width = save_width;
  gport->height = save_height;

  return pixmap;
}
Пример #2
0
/* 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;
}
Пример #3
0
static int
karea_configure_event (GtkWidget *w, GdkEventConfigure *event)
{
  if (kpixmap)
    g_object_unref (kpixmap);

  kpixmap = gdk_pixmap_new (gtk_widget_get_window(w), event->width, event->height, -1);

  karea_draw (w);
  
  return TRUE;
}
Пример #4
0
static gint timeout(gpointer user_data)
{
    GtkWidget *image = user_data;
    PangoLayout *layout;
    GdkRectangle area;
    gint offset_x = 0;

    if (about_timeout < 0)
        return FALSE;

    layout = gtk_widget_create_pango_layout(image, NULL);

    pango_layout_set_markup(layout, about_text, -1);
    pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER);
    pango_layout_set_justify(layout, TRUE);

    if (about_y <= 0 && about_area_y <= 0)
    {
        about_y = image->allocation.width - 80;
        pango_layout_get_pixel_size(layout, &about_area_x, &about_area_y);
        if (about_area_x > image->allocation.width)
        {
            GdkPixmap *old = pixmap;
            gtk_widget_set_size_request(image, about_area_x, 200);

            pixmap = gdk_pixmap_new(image->window, about_area_x, image->allocation.height, -1);
            gdk_pixmap_unref(old);
        }
    }

    if (image->allocation.width > about_area_x)
        offset_x = (image->allocation.width - about_area_x) / 2;

    if (about_y <= 0)
        about_area_y--;

    about_y--;

    area.x = 0;
    area.y = 0;
    area.width = image->allocation.width;
    area.height = image->allocation.height;

    gdk_draw_rectangle(pixmap, gc, TRUE, 0, 0, image->allocation.width, image->allocation.height);

    gtk_paint_layout(image->style, pixmap, GTK_WIDGET_STATE(image), FALSE, &area, image, "about", image->allocation.x + offset_x, about_y, layout);

    gdk_draw_drawable(image->window, gc, pixmap, 0, 0, 0, 0, image->allocation.width, image->allocation.height);

    g_object_unref(layout);

    return TRUE;
}
Пример #5
0
void
ghid_use_mask (int use_it)
{
  static int mask_seq_id = 0;
  GdkColor color;
  render_priv *priv = gport->render_priv;

  if (!gport->pixmap)
    return;
  if (use_it == cur_mask)
    return;
  switch (use_it)
    {
    case HID_MASK_OFF:
      gport->drawable = gport->pixmap;
      mask_seq = 0;
      break;

    case HID_MASK_BEFORE:
      /* The HID asks not to receive this mask type, so warn if we get it */
      g_return_if_reached ();

    case HID_MASK_CLEAR:
      if (!gport->mask)
	gport->mask = gdk_pixmap_new (0, gport->width, gport->height, 1);
      gport->drawable = gport->mask;
      mask_seq = 0;
      if (!priv->mask_gc)
	{
	  priv->mask_gc = gdk_gc_new (gport->drawable);
	  gdk_gc_set_clip_origin (priv->mask_gc, 0, 0);
	  set_clip (priv, priv->mask_gc);
	}
      color.pixel = 1;
      gdk_gc_set_foreground (priv->mask_gc, &color);
      gdk_draw_rectangle (gport->drawable, priv->mask_gc, TRUE, 0, 0,
			  gport->width, gport->height);
      color.pixel = 0;
      gdk_gc_set_foreground (priv->mask_gc, &color);
      break;

    case HID_MASK_AFTER:
      mask_seq_id++;
      if (!mask_seq_id)
	mask_seq_id = 1;
      mask_seq = mask_seq_id;

      gport->drawable = gport->pixmap;
      break;

    }
  cur_mask = use_it;
}
Пример #6
0
int
init_opengl_gdk_3Demu( GdkDrawable * drawable) {
  GdkGLConfig *glconfig;

  /* create the off screen pixmap */
  target_pixmap = gdk_pixmap_new ( drawable, 256, 192, -1);

  if ( target_pixmap == NULL) {
      g_print ("*** Failed to create pixmap.\n");
      return 0;
  }

  glconfig = gdk_gl_config_new_by_mode ((GdkGLConfigMode)(GDK_GL_MODE_RGBA   |
                                        GDK_GL_MODE_DEPTH  |
                                        GDK_GL_MODE_STENCIL |
                                        GDK_GL_MODE_SINGLE));
  if (glconfig == NULL)
    {
      g_print ("*** No appropriate OpenGL-capable visual found.\n");
      return 0;
    }

  /*
   * Set OpenGL-capability to the pixmap
   */

  gldrawable = GDK_GL_DRAWABLE (gdk_pixmap_set_gl_capability (target_pixmap,
                                                              glconfig,
                                                              NULL));

  if ( gldrawable == NULL) {
    g_print ("Failed to create the GdkGLPixmap\n");
    return 0;
  }

  glcontext = gdk_gl_context_new (gldrawable,
                                  NULL,
                                  FALSE,
                                  GDK_GL_RGBA_TYPE);
  if (glcontext == NULL)
    {
      g_print ("Connot create the OpenGL rendering context\n");
      return 0;
    }


	oglrender_init = _oglrender_init;
	oglrender_beginOpenGL = _oglrender_beginOpenGL;
	oglrender_endOpenGL = _oglrender_endOpenGL;


  return 1;
}
Пример #7
0
/**
 * exp_pixmap_new:
 * @window: Reference drawing surface
 * @cx: Initial pixmap width
 * @cy: Initial pixmap height
 * @depth: Pixmap depth
 *
 * Creates a new "expanding pixmap". An expanding pixmap can be resized later on. When the size is to increase,
 * a new pixmap is created and the old one is copied into the top left corner of the new one.
 *
 * Returns: A new "expanding pixmap".
 */
EXP_PIXMAP *exp_pixmap_new (GdkWindow *window, int cx, int cy, int depth)
  {
  EXP_PIXMAP *exp_pixmap = NULL ;

  exp_pixmap = g_malloc0 (sizeof (EXP_PIXMAP)) ;

  exp_pixmap->pixmap = gdk_pixmap_new (window,
    exp_pixmap->cxUsed = exp_pixmap->cxAvail = cx,
    exp_pixmap->cyUsed = exp_pixmap->cyAvail = cy, depth) ;

  return exp_pixmap ;
  }
Пример #8
0
static cairo_surface_t *
tile_surface (cairo_surface_t *surface,
              int              width,
              int              height)
{
	cairo_surface_t *copy;
	cairo_t *cr;

#if GTK_CHECK_VERSION (3, 0, 0)
	if (surface == NULL)
	{
		copy = gdk_window_create_similar_surface (gdk_get_default_root_window (),
		                                          CAIRO_CONTENT_COLOR,
		                                          width, height);
	}
	else
	{
		copy = cairo_surface_create_similar (surface,
		                                     cairo_surface_get_content (surface),
		                                     width, height);
	}
#else
	copy = gdk_pixmap_new(surface, width, height, surface == NULL? 24 : -1);
#endif

	cr = cairo_create (copy);

	if (surface != NULL)
	{
		cairo_pattern_t *pattern;
		cairo_set_source_surface (cr, surface, 0.0, 0.0);
		pattern = cairo_get_source (cr);
		cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);
	}
	else
	{
		GtkStyle *style;
		style = gtk_widget_get_default_style ();
		gdk_cairo_set_source_color(cr, &style->bg[GTK_STATE_NORMAL]);
	}

	cairo_paint (cr);

	if (cairo_status (cr) != CAIRO_STATUS_SUCCESS)
	{
		cairo_surface_destroy (copy);
		copy = NULL;
	}

	cairo_destroy(cr);

	return copy;
}
Пример #9
0
Файл: mapa.c Проект: Lamieur/Lac
G_MODULE_EXPORT gint configure_event( GtkWidget *widget, GdkEventConfigure *event )
{
    if ( dmapa.pixmap )
	g_object_unref( dmapa.pixmap );

    dmapa.pixmap = gdk_pixmap_new( widget->window,
				widget->allocation.width,
				widget->allocation.height, -1 );

    maluj_mape( dmapa.drawingarea );
    return TRUE;
}
static void init_gc(void)	{
	
	count_new = 0;
	calculate_standard_signal();
	calculate_difficulty();
	calculate_sensitivity();

	count = 0;
	count_new = 0;
	count_standard_signal = border; /* border so that signal starts with low */
	initial_count=0;


	// drawing

	is_stop=FALSE;
	is_pause=FALSE;
	mute=FALSE;
	image_volume_on = GTK_WIDGET(gtk_image_new_from_file("/home/pi/gtk_drawing/lautsprecher_mit.png"));
	gtk_button_set_image(GTK_BUTTON(cmd_mute), image_volume_on);
	gtk_button_set_label(GTK_BUTTON(cmd_pause), "Pause");


	count = 0;
	count_new = 0;
	count_standard_signal = border; /* border so that signal starts with low */


	gtk_widget_get_allocation(draw_area, &draw_area_size);
	g_print("width: %d \n height: %d \n", draw_area_size.width, draw_area_size.height);
	
	pixmap = gdk_pixmap_new(draw_area->window, 2*draw_area_size.width, draw_area_size.height, -1);

	gdk_colormap_alloc_color(gtk_widget_get_colormap(draw_area), &red, FALSE, TRUE);
	gdk_colormap_alloc_color(gtk_widget_get_colormap(draw_area), &black, FALSE, TRUE);
	gdk_colormap_alloc_color(gtk_widget_get_colormap(draw_area), &green, FALSE, TRUE);
	
	gc = gdk_gc_new(pixmap);
	*gc = *(draw_area->style->fg_gc[gtk_widget_get_state(draw_area)]);
	gdk_gc_set_foreground(gc, &red);
	gdk_gc_set_line_attributes(gc, 2, GDK_LINE_SOLID, GDK_CAP_NOT_LAST, GDK_JOIN_MITER);

	gcgr = gdk_gc_new(pixmap);
	*gcgr = *(draw_area->style->fg_gc[gtk_widget_get_state(draw_area)]);
	gdk_gc_set_foreground(gcgr, &green);
	gdk_gc_set_line_attributes(gcgr, 2, GDK_LINE_SOLID, GDK_CAP_NOT_LAST, GDK_JOIN_MITER);

	gcbl = gdk_gc_new(pixmap); // black graphic context
	*gcbl = *(draw_area->style->fg_gc[gtk_widget_get_state(draw_area)]);
	gdk_gc_set_foreground(gcbl, &black);
	gdk_gc_set_line_attributes(gcbl, 2, GDK_LINE_SOLID, GDK_CAP_NOT_LAST, GDK_JOIN_MITER);

}
Пример #11
0
static GdkPixmap* createPixmapFromBits(const unsigned char* bits, const IntSize& size)
{
    cairo_surface_t* dataSurface = cairo_image_surface_create_for_data(const_cast<unsigned char*>(bits), CAIRO_FORMAT_A1, size.width(), size.height(), size.width() / 8);
    GdkPixmap* pixmap = gdk_pixmap_new(0, size.width(), size.height(), 1);
    cairo_t* cr = gdk_cairo_create(pixmap);
    cairo_set_source_surface(cr, dataSurface, 0, 0);
    cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
    cairo_paint(cr);
    cairo_destroy(cr);
    cairo_surface_destroy(dataSurface);
    return pixmap;
}
Пример #12
0
// conversion to mono bitmap:
bool wxBitmap::CreateFromImageAsBitmap(const wxImage& img)
{
    // convert alpha channel to mask, if it is present:
    wxImage image(img);
    image.ConvertAlphaToMask();
    
    int width = image.GetWidth();
    int height = image.GetHeight();

    SetHeight( height );
    SetWidth( width );

    SetBitmap( gdk_pixmap_new( wxGetRootWindow()->window, width, height, 1 ) );

    SetDepth( 1 );

    GdkVisual *visual = wxTheApp->GetGdkVisual();

    // Create picture image

    unsigned char *data_data = (unsigned char*)malloc( ((width >> 3)+8) * height );

    GdkImage *data_image =
        gdk_image_new_bitmap( visual, data_data, width, height );

    // Create mask image

    GdkImage *mask_image = (GdkImage*) NULL;

    if (image.HasMask())
    {
        unsigned char *mask_data = (unsigned char*)malloc( ((width >> 3)+8) * height );

        mask_image =  gdk_image_new_bitmap( visual, mask_data, width, height );

        wxMask *mask = new wxMask();
        mask->m_bitmap = gdk_pixmap_new( wxGetRootWindow()->window, width, height, 1 );

        SetMask( mask );
    }
Пример #13
0
static void
update_shape(WindowData *windata) {
    GdkBitmap *mask;
    cairo_t   *cr;

    if (windata->width == windata->last_width
        && windata->height == windata->last_height) {
            return;
    }

    if (windata->width == 0 || windata->height == 0) {
            windata->width = MAX(windata->win->allocation.width, 1);
            windata->height = MAX(windata->win->allocation.height, 1);
    }

    if (windata->composited) {
            gtk_widget_shape_combine_mask (windata->win, NULL, 0, 0);
            return;
    }

    windata->last_width = windata->width;
    windata->last_height = windata->height;
    mask = (GdkBitmap *) gdk_pixmap_new (NULL,
                                         windata->width,
                                         windata->height,
                                         1);
    if (mask == NULL) {
            return;
    }

    cr = gdk_cairo_create (mask);
    if (cairo_status (cr) == CAIRO_STATUS_SUCCESS) {
            cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
            cairo_paint (cr);

            cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
            cairo_set_source_rgb (cr, 1.0f, 1.0f, 1.0f);
            draw_round_rect (cr,
                             1.0f,
                             DEFAULT_X0,
                             DEFAULT_Y0,
                             windata->settings.corner_radius,
                             windata->width,
                             windata->height);
            cairo_fill (cr);

            gtk_widget_shape_combine_mask (windata->win, mask, 0, 0);
    }
    cairo_destroy (cr);

    g_object_unref (mask);
}
static gboolean lack_configure_event(GtkWidget *widget,  
        GdkEventConfigure *event, gpointer data)  
{  
    if (lack_graph)  
    {  
        g_object_unref(lack_graph);  
    }  
    lack_graph = gdk_pixmap_new(widget->window, widget->allocation.width,  
            widget->allocation.height, -1);  
    gdk_draw_rectangle(lack_graph, widget->style->white_gc, TRUE, 0, 0,  
            widget->allocation.width, widget->allocation.height);  
    return TRUE;  
}  
Пример #15
0
gboolean vik_viewport_configure ( VikViewport *vvp )
{
  g_return_val_if_fail ( vvp != NULL, TRUE );

  vvp->width = GTK_WIDGET(vvp)->allocation.width;
  vvp->height = GTK_WIDGET(vvp)->allocation.height;

  vvp->width_2 = vvp->width/2;
  vvp->height_2 = vvp->height/2;

  if ( vvp->scr_buffer )
    g_object_unref ( G_OBJECT ( vvp->scr_buffer ) );

  vvp->scr_buffer = gdk_pixmap_new ( gtk_widget_get_window(GTK_WIDGET(vvp)), vvp->width, vvp->height, -1 );

  /* TODO trigger: only if enabled! */
  if ( vvp->snapshot_buffer )
    g_object_unref ( G_OBJECT ( vvp->snapshot_buffer ) );

  vvp->snapshot_buffer = gdk_pixmap_new ( gtk_widget_get_window(GTK_WIDGET(vvp)), vvp->width, vvp->height, -1 );
  /* TODO trigger */

  /* this is down here so it can get a GC (necessary?) */
  if ( !vvp->background_gc )
  {
    vvp->background_gc = vik_viewport_new_gc ( vvp, DEFAULT_BACKGROUND_COLOR, 1 );
    vik_viewport_set_background_color ( vvp, DEFAULT_BACKGROUND_COLOR );
  }
  if ( ! vvp->highlight_gc )
  {
    vvp->highlight_gc = vik_viewport_new_gc ( vvp, DEFAULT_HIGHLIGHT_COLOR, 1 );
    vik_viewport_set_highlight_color ( vvp, DEFAULT_HIGHLIGHT_COLOR );
  }
  if ( !vvp->scale_bg_gc) {
    vvp->scale_bg_gc = vik_viewport_new_gc(vvp, "grey", 3);
  }

  return FALSE;	
}
static void
update_shape (GsdLocatePointerData *data)
{
  cairo_t *cr;
  GdkBitmap *mask;

  mask = gdk_pixmap_new (data->window, WINDOW_SIZE, WINDOW_SIZE, 1);
  cr = gdk_cairo_create (mask);
  locate_pointer_paint (data, cr, FALSE);
  gdk_window_shape_combine_mask (data->window, mask, 0, 0);
  g_object_unref (mask);
  cairo_destroy (cr);
}
Пример #17
0
void setup_drawing_context(struct ScreenContext *screenContext)
{
	if(screenContext->canvas) {
		g_object_unref(screenContext->canvas);
		cairo_destroy(screenContext->cr_on_canvas);
	}
  	if(screenContext->gc) gdk_gc_unref(screenContext->gc);
	
	screenContext->canvas = gdk_pixmap_new(screenContext->drawingArea->window, screenContext->drawingArea->allocation.width, screenContext->drawingArea->allocation.height, -1);
	screenContext->cr_on_canvas = gdk_cairo_create(screenContext->canvas);
	screenContext->cr_on_screen = gdk_cairo_create(screenContext->drawingArea->window);
  	screenContext->gc = gdk_gc_new(screenContext->drawingArea->window);
}
Пример #18
0
static int
pad_area_configure_event (GtkWidget *w, GdkEventConfigure *event,
			  PadArea *area)
{
  if (area->pixmap)
    g_object_unref (area->pixmap);

  area->pixmap = gdk_pixmap_new (w->window, event->width, event->height, -1);

  pad_area_init (area);
  
  return TRUE;
}
Пример #19
0
static gint
linewidth_area_events (GtkWidget *widget,
		       GdkEvent  *event)
{
  GdkEventButton *bevent;
  GdkEventConfigure *cevent;
  int target;
  
  switch (event->type)
    {
    case GDK_CONFIGURE:
      cevent = (GdkEventConfigure *)  event;
      if (cevent->width > 1) {
	linewidth_area_pixmap = gdk_pixmap_new (widget->window,
						cevent->width,
						cevent->height, -1);
      }
      break;
    case GDK_EXPOSE:
      linewidth_area_draw (linewidth_area_widget);
      break;

    case GDK_BUTTON_PRESS:
      bevent = (GdkEventButton *) event;
      if (bevent->button == 1) {
	target = linewidth_area_target (bevent->x, bevent->y);
	
	if (target != 0) {
	  active_linewidth = target;
	  linewidth_area_draw(linewidth_area_widget);
	  attributes_set_default_linewidth(BASE_WIDTH*(target-1));
	}
      }
      break;

    case GDK_2BUTTON_PRESS:
      if (linewidth_dialog == NULL)
        linewidth_create_dialog();
      else
        gtk_widget_grab_focus(linewidth_button);
      gtk_spin_button_set_value(GTK_SPIN_BUTTON(linewidth_button), attributes_get_default_linewidth());

      gtk_widget_show(linewidth_dialog);
      break;

    default:
      break;
    }

  return FALSE;
}
Пример #20
0
static void scope_realize(GtkWidget *widget)
{
	Scope *scope;
	GdkWindowAttr attributes;
	gint attributes_mask;
	GdkGCValues gc_values;

	g_return_if_fail(widget != NULL);
	g_return_if_fail(IS_SCOPE(widget));

	scope = SCOPE(widget);
	GTK_WIDGET_SET_FLAGS(widget, GTK_REALIZED);

	attributes.window_type = GDK_WINDOW_CHILD;
	attributes.x = widget->allocation.x;
	attributes.y = widget->allocation.y;
	attributes.width = widget->allocation.width;
	attributes.height = widget->allocation.height;
	attributes.wclass = GDK_INPUT_OUTPUT;
	attributes.visual = gtk_widget_get_visual(widget);
	attributes.colormap = gtk_widget_get_colormap(widget);
	attributes.event_mask = gtk_widget_get_events(widget) | GDK_EXPOSURE_MASK;

	attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;

	widget->window = gdk_window_new(gtk_widget_get_parent_window(widget), &attributes, attributes_mask);
	gdk_window_set_user_data(widget->window, scope);

	widget->style = gtk_style_attach(widget->style, widget->window);
	gtk_style_set_background(widget->style, widget->window, GTK_STATE_NORMAL);

	/* gc's if necessary */
	if (!gdk_color_alloc(widget->style->colormap, &scope->tracecol))
		g_warning("unable to allocate color: ( %d %d %d )",
			  scope->tracecol.red, scope->tracecol.green, scope->tracecol.blue);
	gc_values.foreground = scope->tracecol;
	scope->trace_gc = gtk_gc_get(widget->style->depth, 
				    widget->style->colormap,
				    &gc_values, GDK_GC_FOREGROUND);
	if (!gdk_color_alloc(widget->style->colormap, &scope->gridcol))
		g_warning("unable to allocate color: ( %d %d %d )",
			  scope->gridcol.red, scope->gridcol.green, scope->gridcol.blue);
	gc_values.foreground = scope->gridcol;
	scope->grid_gc = gtk_gc_get(widget->style->depth,
				   widget->style->colormap,
				   &gc_values, GDK_GC_FOREGROUND);
	/* create backing store */
	scope->pixmap = gdk_pixmap_new(widget->window, SCOPE_WIDTH, SCOPE_HEIGHT, -1);

	scope_send_configure(SCOPE(widget));
}
Пример #21
0
void iupDrawUpdateSize(IdrawCanvas* dc)
{
  int w, h;
  gdk_drawable_get_size(dc->wnd, &w, &h);

  if (w != dc->w || h != dc->h)
  {
    g_object_unref(dc->pixmap_gc); 
    g_object_unref(dc->pixmap); 

    dc->pixmap = gdk_pixmap_new(dc->wnd, dc->w, dc->h, gdk_drawable_get_depth(dc->wnd));
    dc->pixmap_gc = gdk_gc_new(dc->pixmap);
  }
}
Пример #22
0
GdkPixmap *make_pixmap(GtkScrollbox *self, gchar *value)
{
        GdkWindow *rootwin;
        PangoLayout *pl;
        gint width, height, middle;
        GdkPixmap *pixmap;
        GtkRequisition widgsize = {0, }; 
        GtkWidget *widget = (GtkWidget *)self;
        

	/* If we can't draw yet, don't do anything to avoid screwing things */
	if (!GDK_IS_GC(widget->style->bg_gc[0]))
		return NULL;

        rootwin = gtk_widget_get_root_window(widget);

        pl = gtk_widget_create_pango_layout(widget, NULL);
        pango_layout_set_markup(pl, value, -1);

        pango_layout_get_pixel_size(pl, &width, &height);

        pixmap = gdk_pixmap_new(GDK_DRAWABLE(rootwin), width, height, -1);

        gdk_draw_rectangle(GDK_DRAWABLE(pixmap), 
                        widget->style->bg_gc[0],
                        TRUE, 0, 0, width, height);

        gdk_draw_layout(GDK_DRAWABLE(pixmap), widget->style->fg_gc[0], 0, 0, pl);

        g_object_unref(pl);

        gtk_widget_size_request(widget, &widgsize);

        if (width <= widgsize.width)
                width = widgsize.width;

        if (height <= widgsize.height)
                height = widgsize.height;
        else
                self->draw_maxoffset = -height;

        if (width != widgsize.width || height != widgsize.height)
                gtk_widget_set_size_request(widget, width, height);

        middle = width / 2;
        if (self->draw_maxmiddle < middle)
                self->draw_maxmiddle = middle;

        return pixmap;
}
Пример #23
0
Файл: osd.c Проект: iolo/liteamp
static void update_image(Osd * self)
{
    GdkPixmap *shape;
    GdkGC *shape_gc;
    GdkPixbuf *shape_pixbuf;
    GdkPixbuf *pixbuf;

    // make shape pixmap from pango layout
    shape =
	gdk_pixmap_new(GTK_WIDGET(self)->window, self->width,
		       self->height, -1);

    shape_gc = gdk_gc_new(shape);

    gdk_gc_set_rgb_fg_color(shape_gc, &self->mask_color);
    gdk_draw_rectangle(shape, shape_gc, TRUE, 0, 0, self->width + 1,
		       self->height + 1);

    gdk_gc_set_rgb_fg_color(shape_gc, &self->shadow_color);
    gdk_draw_layout(shape, shape_gc, self->shadow_offset_x,
		    self->shadow_offset_y, self->layout);

    gdk_gc_set_rgb_fg_color(shape_gc, &self->text_color);
    gdk_draw_layout(shape, shape_gc, 0, 0, self->layout);

    gtk_image_set_from_pixmap(GTK_IMAGE(self->image), shape, NULL);

    // make shape pixbuf from shape pixmap
    shape_pixbuf = gdk_pixbuf_get_from_drawable(NULL, shape, NULL,
						0, 0, 0, 0,
						self->width, self->height);

    g_object_unref(shape);
    g_object_unref(shape_gc);

    // make alpha enabled pixbuf from shape pixbuf
    pixbuf =
	gdk_pixbuf_add_alpha(shape_pixbuf, TRUE, self->mask_color.red,
			     self->mask_color.green,
			     self->mask_color.blue);

    // finally, i got the mask bitmap!
    // it's needed to update_shape().
    // FIXME: somewhat clumsy :( need better/easy/efficient way.
    gdk_pixbuf_render_pixmap_and_mask(pixbuf, NULL, &self->mask, 1);

    g_object_unref(pixbuf);
    g_object_unref(shape_pixbuf);
}
Пример #24
0
static void get_alpha_mask(float_shape_t *shape)
{
   GdkColormap *colormap;
   GdkColor black;
   GdkColor white;
   GdkGC *gc;
   int rowstride, nchannels, x, y;
   guchar *pixels, *p;
   bool bright_green, has_alpha;

   colormap = gdk_colormap_get_system();
   gdk_color_black(colormap, &black);
   gdk_color_white(colormap, &white);

   shape->mask_bitmap =
      (GdkDrawable*)gdk_pixmap_new(NULL, shape->width, shape->height, 1);
   gc = gdk_gc_new(shape->mask_bitmap);
   
   gdk_gc_set_foreground(gc, &black);
   gdk_gc_set_background(gc, &white);
   gdk_draw_rectangle(shape->mask_bitmap, gc, TRUE, 0, 0,
                      shape->width, shape->height);

   nchannels = gdk_pixbuf_get_n_channels(shape->pixbuf);
   g_assert(gdk_pixbuf_get_colorspace(shape->pixbuf) == GDK_COLORSPACE_RGB);
   g_assert(gdk_pixbuf_get_bits_per_sample(shape->pixbuf) == 8);

   has_alpha = gdk_pixbuf_get_has_alpha(shape->pixbuf);
   
   rowstride = gdk_pixbuf_get_rowstride(shape->pixbuf);
   pixels = gdk_pixbuf_get_pixels(shape->pixbuf);

   gdk_gc_set_foreground(gc, &white);
   gdk_gc_set_background(gc, &black);
   
   for (y = 0; y < shape->height; y++) {
      for (x = 0; x < shape->width; x++) {
         p = pixels + y*rowstride + x*nchannels;
         bright_green = 0 == p[0] && 255 == p[1] && 0 == p[2];
         if (has_alpha) {
            if (255 == p[3])  // p[3] is alpha channel
               gdk_draw_point(shape->mask_bitmap, gc, x, y);
         } 
         else if (!bright_green) {   // Bright green is alpha for RGB images
            gdk_draw_point(shape->mask_bitmap, gc, x, y);
         }
      }
   }
}
Пример #25
0
int
main(int argc, char **argv)
{
  GtkWidget *image;
  GdkBitmap *mask;
  GdkPixbuf *pixbuf;
  GdkGC *gc;

  gtk_init (&argc, &argv);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  g_signal_connect (window, "delete_event", G_CALLBACK (gtk_main_quit), NULL);
  gtk_window_set_decorated (GTK_WINDOW (window), FALSE);

  pixbuf = gdk_pixbuf_new_from_file ("romeo.png",
				     NULL);

  if (!pixbuf)
    {
      g_error ("Could not load image");
    }

  mask = gdk_pixmap_new (NULL,
			 gdk_pixbuf_get_width (pixbuf),
			 gdk_pixbuf_get_height (pixbuf),
			 1);

  gdk_pixbuf_render_threshold_alpha (pixbuf,
				     mask,
				     0, 0, 0, 0,
				     -1, -1,
				     127);

  gtk_widget_shape_combine_mask (window,
				 mask,
				 0, 0);

  image = gtk_image_new_from_pixbuf (pixbuf);
  gtk_container_add (GTK_CONTAINER (window),
		     image);

  gtk_widget_show_all (window);

  g_timeout_add (10,
		 turn,
		 NULL);

  gtk_main ();
}
Пример #26
0
Файл: pager.c Проект: g7/fbpanel
/* Upon realize and every resize creates a new backing pixmap of the appropriate size */
static gint
desk_configure_event (GtkWidget *widget, GdkEventConfigure *event, desk *d)
{
    int w, h;

    ENTER;
    w = widget->allocation.width;
    h = widget->allocation.height;

    DBG("d->no=%d %dx%d %dx%d\n", d->no, w, h, d->pg->daw, d->pg->dah);
    if (d->pix)
        g_object_unref(d->pix);
    if (d->gpix)
        g_object_unref(d->gpix);
    d->pix = gdk_pixmap_new(widget->window, w, h, -1);
    if (d->pg->wallpaper) {
        d->gpix = gdk_pixmap_new(widget->window, w, h, -1);
        desk_draw_bg(d->pg, d);
    }
    d->scalew = (gfloat)h / (gfloat)gdk_screen_height();
    d->scaleh = (gfloat)w / (gfloat)gdk_screen_width();
    desk_set_dirty(d);
    RET(FALSE);
}
Пример #27
0
static void
set_size(DiaRenderer *object, gpointer window,
		      int width, int height)
{
  DiaGdkRenderer *renderer = DIA_GDK_RENDERER (object);

  if (renderer->pixmap != NULL)
    g_object_unref(renderer->pixmap);

  if (window)
    renderer->pixmap = gdk_pixmap_new(GDK_WINDOW(window),  width, height, -1);
  else /* the integrated UI insist to call us too early */
    renderer->pixmap = gdk_pixmap_new(NULL,  width, height, 24);

  if (renderer->gc == NULL) {
    renderer->gc = gdk_gc_new(renderer->pixmap);

    gdk_gc_set_line_attributes(renderer->gc,
			       renderer->line_width,
			       renderer->line_style,
			       renderer->cap_style,
			       renderer->join_style);
  }
}
Пример #28
0
gboolean Fenetre::configure_event(GtkWidget *widget, GdkEventConfigure *event)
{ // init => on crée une image mémoire pour le rafraîchissement
  if (dessin!=NULL) // enlever l'ancien bitmap
      g_object_unref (dessin);
  // en créer un nouveau
  dessin = gdk_pixmap_new (widget->window,
			   widget->allocation.width,
			   widget->allocation.height, -1);
  // l'image est effacée = remplie par la couleur de fond
  gdk_gc_set_rgb_fg_color(widget->style->bg_gc[GTK_STATE_NORMAL],&fond);
  gdk_draw_rectangle (dessin, widget->style->bg_gc[GTK_STATE_NORMAL],
              TRUE, 0, 0, 
              widget->allocation.width, widget->allocation.height);
  return TRUE;
}
Пример #29
0
/* Create a new backing pixmap of the appropriate size */
static  gint
configure_event(GtkWidget * widget, GdkEventConfigure * event, gpointer data)
{
    GdkPixmap **ppixmap;
    if ((ppixmap = findpixmap(widget))) {
        if (*ppixmap)
            gdk_pixmap_unref(*ppixmap);
        *ppixmap = gdk_pixmap_new(widget->window,
                                  widget->allocation.width, widget->allocation.height, -1);
        gdk_draw_rectangle(*ppixmap,
                           widget->style->white_gc,
                           TRUE, 0, 0, widget->allocation.width, widget->allocation.height);
    }
    return TRUE;
}
Пример #30
0
GdkPixmap* glyph_get_pixmap(glyph_t* pGlyph, GtkWidget* pTargetWidget)
{
	g_assert(pGlyph != NULL);

	if(pGlyph->pPixmap == NULL) {
		// XXX: This assumes that we aren't being passed different pTargetWidgets each time
        pGlyph->pPixmap = gdk_pixmap_new(pTargetWidget->window, pGlyph->nWidth, pGlyph->nHeight, -1);	// -1 is bpp
		GdkGC* pGC = pTargetWidget->style->fg_gc[GTK_WIDGET_STATE(pTargetWidget)];
		gdk_draw_pixbuf(pGlyph->pPixmap, pGC, pGlyph->pPixbuf, 0,0,0,0,-1,-1,
						GDK_RGB_DITHER_NONE,0,0);           // no dithering
	}
	g_assert(pGlyph->pPixmap != NULL);

	return pGlyph->pPixmap;
}