Re: Pixmaps AGAIN .... PLEASE HELP!!! (SOLUTION)
- From: Julio Pastrana <pastrana informatik uni-freiburg de>
- To: gtk-app-devel-list gnome org
- Subject: Re: Pixmaps AGAIN .... PLEASE HELP!!! (SOLUTION)
- Date: Wed, 8 Oct 2003 12:31:47 +0200 (MEST)
Hello gtk list!!!
After several days traying to achieve transparency I did it!!!
I DO NOT KNOW if it is a very optimal solution but it works for me.
I wrote a working example { at least in my computer =) } and I want to
share it with you, I hope this helps some one.
Regards,
Julio C. Pastrana.
ps.- If you know a better way to do this ... please tell me!
ps2.- Thanks to all the people that gave me hints.
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
#include <gtk/gtk.h>
#include <stdlib.h>
void close_application( GtkWidget *widget, GdkEvent
*event, gpointer data ) {
gtk_main_quit();
}
int main (int argc, char *argv[])
{
GtkWidget *window, *pixmap;
GdkPixmap *bk_pixmap, *p;
GdkColor *color;
GdkGC *gcc;
GdkGC *gccc;
GdkGC *gc;
GdkColor white;
GdkColor black;
GdkColor red;
GdkPixmap *xpm;
GdkFont *label_font=NULL;
GtkWidget *vbox1;
int sizeX = 300;
int sizeY = 300;
gtk_init (&argc, &argv);
window = gtk_window_new( GTK_WINDOW_TOPLEVEL );
gtk_signal_connect (GTK_OBJECT (window), "delete_event",
GTK_SIGNAL_FUNC (close_application), NULL);
gtk_widget_show (window);
vbox1 = gtk_vbox_new (FALSE, 0);
gtk_widget_set_name (vbox1, "vbox1");
gtk_widget_ref (vbox1);
gtk_object_set_data_full (GTK_OBJECT (window), "vbox1", vbox1, (GtkDestroyNotify) gtk_widget_unref);
gtk_container_add (GTK_CONTAINER (window), vbox1);
gtk_widget_show (vbox1);
/*Just to define a color*/
gcc = gdk_gc_new(window->window);
color = (GdkColor *) malloc(sizeof(GdkColor));
color->red = 0;
color->green = 0xffff;
color->blue = 0;
color->pixel = (gulong)(0);
gdk_color_alloc(gtk_widget_get_colormap(window),color);
/*________________________________________________________*/
bk_pixmap = gdk_pixmap_new ( window->window,sizeX, sizeY, -1);
gdk_gc_set_foreground (gcc, color);
gdk_draw_rectangle ( bk_pixmap, gcc, TRUE,0, 0,sizeX,sizeY);
/* setting a Pixmap as the Background of my window*/
gtk_widget_set_app_paintable(window, TRUE);
gdk_window_set_back_pixmap(window -> window,bk_pixmap, 0);
gdk_color_parse("white", &white);
gdk_color_alloc(gtk_widget_get_colormap(window),&white);
gdk_color_parse("black", &black);
gdk_color_alloc(gtk_widget_get_colormap(window),&black);
gdk_color_parse("red", &red);
gdk_color_alloc(gtk_widget_get_colormap(window),&red);
p = gdk_pixmap_new ( window->window, sizeX,sizeY, -1); //color pixmap
xpm = gdk_pixmap_new ( NULL, sizeX, sizeY,1); // one color pixmap (It is actually a BITMAP)
gc = gdk_gc_new(xpm); // getting the gc for the bitmap
gdk_gc_set_foreground(gc, &black);
gdk_draw_rectangle(xpm, gc, TRUE, 0,0, sizeX,sizeY);
gdk_gc_set_foreground(gc, &white);
/* everything you draw you have to draw it on the mask also */
/* just with the white color */
gccc = gdk_gc_new(p);
gdk_gc_set_background(gccc, &white);
gdk_draw_rectangle(p, gccc, TRUE, 0,0, sizeX,sizeY);
gdk_gc_set_foreground(gccc, &white);
gdk_draw_rectangle(p, gccc, TRUE, 100,100, 100,100);
gdk_draw_rectangle(xpm, gc, TRUE, 100,100, 100,100);
gdk_gc_set_foreground(gccc, &red);
gdk_draw_rectangle(p, gccc, FALSE, 30,30, 100, 100);
gdk_draw_rectangle(xpm, gc, FALSE, 30,30, 100,100);
gdk_gc_set_foreground(gccc, &red);
gdk_draw_rectangle(p, gccc, TRUE, 200,50, 50,50);
gdk_draw_rectangle(xpm, gc, TRUE, 200,50, 50,50);
gdk_gc_set_foreground(gccc, &black);
gdk_draw_arc(p , gccc, FALSE, 200, 200 , 60, 60, 0, 64 * 360);
gdk_draw_arc(xpm , gc, FALSE, 200, 200 , 60, 60, 0, 64 * 360);
label_font = gdk_font_load("-*-helvetica-*-r-normal-*-14-*-*-*-*-*-*-*");
char * text = "Example =) ";
gdk_draw_string(p , label_font , gccc , 30, 250, text);
gdk_draw_string(xpm , label_font , gc , 30, 250, text);
pixmap = gtk_pixmap_new( p, xpm);
gdk_pixmap_unref(p);
gdk_pixmap_unref(xpm);
gtk_container_add( GTK_CONTAINER(vbox1), pixmap);
gtk_widget_show( pixmap );
gtk_widget_show( pixmap );
gtk_main ();
return 0;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]