Пример #1
0
/**
 * ppg_ruler_size_allocate:
 * @ruler: (in): A #PpgRuler.
 *
 * Handle the "size-allocate" for the #GtkWidget. The pixmap for the
 * background is created and drawn if necessary.
 *
 * Returns: None.
 * Side effects: None.
 */
static void
ppg_ruler_size_allocate (GtkWidget     *widget,
                         GtkAllocation *alloc)
{
	PpgRuler *ruler = (PpgRuler *)widget;
	PpgRulerPrivate *priv;
	GdkColormap *colormap;
	GdkVisual *visual;

	g_return_if_fail(PPG_IS_RULER(ruler));

	priv = ruler->priv;

	GTK_WIDGET_CLASS(ppg_ruler_parent_class)->size_allocate(widget, alloc);

	if (priv->ruler) {
		g_object_unref(priv->ruler);
	}

	priv->ruler = gdk_pixmap_new(NULL, alloc->width, alloc->height, 32);
	visual = gdk_visual_get_best_with_depth(32);
	colormap = gdk_colormap_new(visual, FALSE);
	gdk_drawable_set_colormap(priv->ruler, colormap);

	if (GTK_WIDGET_DRAWABLE(widget)) {
		ppg_ruler_draw_ruler(ruler);
	}
}
Пример #2
0
/**
 * ppg_ruler_realize:
 * @widget: (in): A #PpgRuler.
 *
 * Handle the "realize" event for the widget.
 *
 * Returns: None.
 * Side effects: None.
 */
static void
ppg_ruler_realize (GtkWidget *widget)
{
	PpgRuler *ruler = (PpgRuler *)widget;
	PpgRulerPrivate *priv;
	GdkColormap *colormap;
	GdkVisual *visual;

	g_return_if_fail(PPG_IS_RULER(ruler));

	priv = ruler->priv;

	GTK_WIDGET_CLASS(ppg_ruler_parent_class)->realize(widget);
	gtk_widget_queue_resize(widget);

	/*
	 * Create pixmap for arrow.
	 */
	if (priv->arrow) {
		g_object_unref(priv->arrow);
	}
	priv->arrow = gdk_pixmap_new(NULL, ARROW_SIZE, ARROW_SIZE, 32);
	visual = gdk_visual_get_best_with_depth(32);
	colormap = gdk_colormap_new(visual, FALSE);
	gdk_drawable_set_colormap(priv->arrow, colormap);
}
Пример #3
0
/* Visual */
CAMLprim value ml_gdk_visual_get_best (value depth, value type)
{
     GdkVisual *vis;
     if (type == Val_unit)
          if (depth == Val_unit) vis = gdk_visual_get_best ();
          else vis = gdk_visual_get_best_with_depth (Int_val(Field(depth,0)));
     else
          if (depth == Val_unit)
               vis = gdk_visual_get_best_with_type
                    (GdkVisualType_val(Field(type,0)));
          else vis = gdk_visual_get_best_with_both
                    (Int_val(Field(depth,0)),GdkVisualType_val(Field(type,0)));
     if (!vis) ml_raise_gdk("Gdk.Visual.get_best");
     return Val_GdkVisual(vis);
}
Пример #4
0
static XImage * drawtheme_calc_alpha ( MCThemeDrawInfo &p_info)
{
	XImage *t_bm_black ;
	XImage *t_bm_white ;
		
	GdkPixmap *t_black ;
	GdkPixmap *t_white ;

	GdkColormap *cm ;
	GdkVisual *best_vis ;
	
	uint4	t_w ;
	uint4	t_h ;	
		
	t_w = p_info.drect.width ;
	t_h = p_info.drect.height ;

	// MM-2013-11-06: [[ Bug 11360 ]] Make sure we take into account the screen depth when creating pixmaps.
	uint4 t_screen_depth;
	t_screen_depth = ((MCScreenDC*) MCscreen) -> getdepth();
	
	// Create two new pixmaps
	t_black = gdk_pixmap_new( NULL, t_w, t_h, t_screen_depth);
	t_white = gdk_pixmap_new( NULL, t_w, t_h, t_screen_depth);
	
	// We need to attach a colourmap to the Drawables in GDK
	best_vis = gdk_visual_get_best_with_depth(t_screen_depth);
	cm = gdk_colormap_new( best_vis , False ) ;
	gdk_drawable_set_colormap( t_black, cm);
	gdk_drawable_set_colormap( t_white, cm);

	//gdk_flush();
	
	// Render solid black into one and white into the other.
	//black_and_white_masks ( gdk_x11_drawable_get_xid( t_black ) , gdk_x11_drawable_get_xid(t_white));
	
	fill_gdk_drawable(t_black, cm, 0, 0, 0, t_w, t_h);
	fill_gdk_drawable(t_white, cm, 65535, 65535, 65535, t_w, t_h);
	
	MCThemeDrawInfo t_info;
	
	t_info = p_info;
	moz_gtk_widget_paint ( p_info.moztype, t_white , &t_info.drect, &t_info.cliprect, &t_info.state, t_info.flags ) ;
	
	t_info = p_info;
	moz_gtk_widget_paint ( p_info.moztype, t_black , &t_info.drect, &t_info.cliprect, &t_info.state, t_info.flags ) ;

	gdk_flush();
	
	// Get the byte data for each of these pixmaps
	t_bm_black = ((MCScreenDC*)MCscreen) -> getimage ( gdk_x11_drawable_get_xid(t_black), 0, 0, t_w, t_h, False ) ;
	t_bm_white = ((MCScreenDC*)MCscreen) -> getimage ( gdk_x11_drawable_get_xid(t_white), 0, 0, t_w, t_h, False ) ;
	
	// Calculate the alpha from these two bitmaps --- the t_bm_black image now has full ARGB
	calc_alpha_from_bitmaps ( t_bm_black, t_bm_white ) ;
	
	// clean up.
	g_object_unref( t_black ) ;
	g_object_unref( t_white ) ;
	g_object_unref( cm ) ;
		
	return ( t_bm_black ) ;
}
Пример #5
0
static VALUE
rg_s_best_with_depth(G_GNUC_UNUSED VALUE self, VALUE depth)
{
    return GOBJ2RVAL(gdk_visual_get_best_with_depth(NUM2INT(depth)));
}
Пример #6
0
static VALUE
rg_s_best_with_type(G_GNUC_UNUSED VALUE self, VALUE type)
{
    return GOBJ2RVAL(gdk_visual_get_best_with_depth(
                         (GdkVisualType)GENUM2RVAL(type, GDK_TYPE_VISUAL_TYPE)));
}
Пример #7
0
static GdkPixbuf* drawtheme_calc_alpha (MCThemeDrawInfo &p_info)
{
	GdkPixbuf *t_pb_black;
    GdkPixbuf *t_pb_white;
    
	GdkPixmap *t_black ;
	GdkPixmap *t_white ;

	GdkColormap *cm ;
	GdkVisual *best_vis ;
	
	uint4	t_w ;
	uint4	t_h ;	
		
	t_w = p_info.drect.width ;
	t_h = p_info.drect.height ;

	// MM-2013-11-06: [[ Bug 11360 ]] Make sure we take into account the screen depth when creating pixmaps.
	uint4 t_screen_depth;
	t_screen_depth = ((MCScreenDC*) MCscreen) -> getdepth();
	
	// Create two new pixmaps
	t_black = gdk_pixmap_new(NULL, t_w, t_h, t_screen_depth);
	t_white = gdk_pixmap_new(NULL, t_w, t_h, t_screen_depth);
	
	// We need to attach a colourmap to the Drawables in GDK
	best_vis = gdk_visual_get_best_with_depth(t_screen_depth);
    if (best_vis == NULL)
        return NULL;
    
	cm = gdk_colormap_new(best_vis, FALSE) ;
	gdk_drawable_set_colormap(t_black, cm);
	gdk_drawable_set_colormap(t_white, cm);

	// Render solid black into one and white into the other.
	fill_gdk_drawable(t_black, cm, 0, 0, 0, t_w, t_h);
	fill_gdk_drawable(t_white, cm, 65535, 65535, 65535, t_w, t_h);
	
	MCThemeDrawInfo t_info;
	
	t_info = p_info;
	moz_gtk_widget_paint ( p_info.moztype, t_white , &t_info.drect, &t_info.cliprect, &t_info.state, t_info.flags ) ;
	
	t_info = p_info;
	moz_gtk_widget_paint ( p_info.moztype, t_black , &t_info.drect, &t_info.cliprect, &t_info.state, t_info.flags ) ;

	gdk_flush();
	
    // Convert the server-side pixmaps into client-side pixbufs. The black
    // pixbuf will need to have an alpha channel so that we can fill it in.
    t_pb_black = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, t_w, t_h);
    if (t_pb_black == NULL)
        return NULL;
        
    t_pb_white = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, t_w, t_h);
    if (t_pb_white == NULL)
        return NULL;
    
    t_pb_black = gdk_pixbuf_get_from_drawable(t_pb_black, t_black, NULL, 0, 0, 0, 0, t_w, t_h);
    if (t_pb_black == NULL)
        return NULL;
    
    t_pb_white = gdk_pixbuf_get_from_drawable(t_pb_white, t_white, NULL, 0, 0, 0, 0, t_w, t_h);
    if (t_pb_white == NULL)
        return NULL;
    
	// Calculate the alpha from these two bitmaps --- the t_bm_black image now has full ARGB
    // Note that this also frees the t_pb_white pixbuf
	calc_alpha_from_pixbufs(t_pb_black, t_pb_white);
	
	// clean up.
	g_object_unref(t_black);
	g_object_unref(t_white);
	g_object_unref(cm);
		
	return t_pb_black;
}
Пример #8
0
int main(int argc, char *argv[]) {
    //
    GtkWidget *window;
    GtkWidget *fixed;
    GtkWidget *area;

    //
    gtk_init(&argc, &argv);

    // Window
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title(GTK_WINDOW(window), "gui");
    gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
    gtk_container_set_border_width(GTK_CONTAINER(window), 0);
    gtk_window_set_default_size(GTK_WINDOW(window), width, height);
    printf("window ok\n");

    // layout
    fixed = gtk_fixed_new();
    gtk_container_add(GTK_CONTAINER(window), fixed);
    printf("fixed ok\n");

    // Image
    GList *visuals = gdk_list_visuals();
    void tst(gpointer data, gpointer udata) {
        if (((GdkVisual*)data)->depth == 32)
        printf("visual :\n\ttype = %d\n\ttype = %d\n\tdepth = %d\n\tbits/rgb = %d\n\torder = %d\n\tred = %08X\n\tgreen = %08X\n\tblue = %08X\n"
                , ((GdkVisual*)data)->type
                , ((GdkVisual*)data)->colormap_size
                , ((GdkVisual*)data)->depth
                , ((GdkVisual*)data)->bits_per_rgb
                , ((GdkVisual*)data)->byte_order
                , ((GdkVisual*)data)->red_mask
                , ((GdkVisual*)data)->green_mask
                , ((GdkVisual*)data)->blue_mask
        );
    }
    g_list_foreach(visuals, &tst, NULL);
    GdkVisual *visu = gdk_visual_get_best_with_depth(32);
    ximg = gdk_image_new(GDK_IMAGE_SHARED, visu, width, height);
    printf("GdkImage : bytes/pix = %d, linesize = %d, bits/pix = %d ; type %d (mem = %p)\n"
            , ximg->bpp, ximg->bpl, ximg->bits_per_pixel
            , ximg->type, ximg->mem
    );
    // GdkPixbufAnimation
    //gtk_image_set_from_pixbuf

    //
    GdkColormap *dcm = gdk_colormap_new(visu, FALSE);
    // drawing area
    area = gtk_drawing_area_new();
    gdk_drawable_set_colormap(window, dcm);
    gdk_drawable_set_colormap(area, dcm);
    gtk_drawing_area_size(GTK_DRAWING_AREA(area), width, height);
    printf("area ok\n");

    //
    gtk_fixed_put(GTK_FIXED(fixed), area, 0, 0);
    printf("fixed ok\n");


    //
    bgra_alloc650(&bgra, width, height);
    bgra_origin650(&bgra, +width/2, +height/2);
    bgra_scale650(&bgra, 1, -1);
    printf("bgra alloc ok\n");
    maj();
    printf("bgra maj done, still (%p <- %p)\n", ximg->mem, bgra.data);
//    // Ximg
//    memcpy(ximg->mem, bgra.data, bgra.size);
//    printf("mcpy done\n");
    // Pixmap
    GdkColor bg;
    GdkColor fg;
    fg.pixel = 0xff000000;
    fg.red = 0;
    fg.green = 0;
    fg.blue = 0;
    bg.pixel = 0xff000000;
    bg.red = 0;
    bg.green = 0;
    bg.blue = 0;
    pixmap = gdk_pixmap_create_from_data(
            GTK_WINDOW(window)
            , bgra.data
            , width
            , height
            , 32
            , &fg
            , &bg
    );


//    img = gdk_pixbuf_new_from_data(
//              (guchar*)bgra.data
//            , GDK_COLORSPACE_RGB
//            , TRUE
//            , 8
//            , width
//            , height
//            , width << 2
//            , &pbd, NULL
//    );
//    printf("PixBuf new ok\n");

    //
    // Image
//    frame = gtk_image_new_from_pixbuf(img);
////    frame = gtimg;
//    gtk_fixed_put(GTK_FIXED(fixed), frame, 0, 0);
//    printf("fixed ok\n");


    // Events
    g_signal_connect(area, "expose-event", G_CALLBACK (on_expose_event), NULL);
//    g_signal_connect(frame, "expose-event", G_CALLBACK (on_expose_event), NULL);
    g_signal_connect(window, "delete-event", G_CALLBACK (delete_event), NULL);
    g_signal_connect(window, "destroy", G_CALLBACK (destroy), NULL);
    printf("signals ok\n");

    // Show
//    gtk_widget_show(area);
    gtk_widget_show(fixed);
    gtk_widget_show_all(window);
    printf("show ok\n");

    // Timer
    g_timeout_add(500, (GSourceFunc)time_handler, (gpointer)area);
    printf("timer ok\n");

    gtk_main();

    return 0;
}