Linux中国 Linux中国门户站!
设为主页 设为主页
收藏本站 收藏本站
 
当前位置 :首页 ->Linux技术 ->系统管理 ->正文

GTK v1.2 Tutorial(英文)

来源:Linux-cn.com 作者:Webmaster 时间:2007-05-05 点击: [收藏] [投稿]

  To load a file from an XPM data file called icon0.xpm in the current directory, we would have created the pixmap thus


/* load a pixmap from a file */
pixmap = gdk_pixmap_create_from_xpm( window->window, &mask,
 &style->bg[GTK_STATE_NORMAL],
 "./icon0.xpm" );
pixmapwid = gtk_pixmap_new( pixmap, mask );
gtk_widget_show( pixmapwid );
gtk_container_add( GTK_CONTAINER(window), pixmapwid );

  A disadvantage of using pixmaps is that the displayed object is always rectangular, regardless of the image. We would like to create desktops and applications with icons that have more natural shapes. For example, for a game interface, we would like to have round buttons to push. The way to do this is using shaped windows.

  A shaped window is simply a pixmap where the background pixels are transparent. This way, when the background image is multi-colored, we don't overwrite it with a rectangular, non-matching border around our icon. The following example displays a full wheelbarrow image on the desktop.


/* example-start wheelbarrow wheelbarrow.c */
#include <gtk/gtk.h>
/* XPM */
static char * WheelbarrowFull_xpm[] = {
"48 48 64 1",
" c None",
".c #DF7DCF3CC71B",
"Xc #965875D669A6",
"oc #71C671C671C6",
"Oc #A699A289A699",
"+c #965892489658",
"@c #8E38410330C2",
"#c #D75C7DF769A6",
"$c #F7DECF3CC71B",
"%c #96588A288E38",
"&c #A69992489E79",
"*c #8E3886178E38",
"=c #104008200820",
"-c #596510401040",
";c #C71B30C230C2",
":c #C71B9A699658",
">c #618561856185",
",c #20811C712081",
"<c #104000000000",
"1c #861720812081",
"2c #DF7D4D344103",
"3c #79E769A671C6",
"4c #861782078617",
"5c #41033CF34103",
"6c #000000000000",
"7c #49241C711040",
"8c #492445144924",
"9c #082008200820",
"0c #69A618611861",
"qc #B6DA71C65144",
"wc #410330C238E3",
"ec #CF3CBAEAB6DA",
"rc #71C6451430C2",
"tc #EFBEDB6CD75C",
"yc #28A208200820",
"uc #186110401040",
"ic #596528A21861",
"pc #71C661855965",
"ac #A69996589658",
"sc #30C228A230C2",
"dc #BEFBA289AEBA",
"fc #596545145144",
"gc #30C230C230C2",
"hc #8E3882078617",
"jc #208118612081",
"kc #38E30C300820",
"lc #30C2208128A2",
"zc #38E328A238E3",
"xc #514438E34924",
"cc #618555555965",
"vc #30C2208130C2",
"bc #38E328A230C2",
"nc #28A228A228A2",
"mc #41032CB228A2",
"Mc #104010401040",
"Nc #492438E34103",
"Bc #28A2208128A2",
"Vc #A699596538E3",
"Cc #30C21C711040",
"Zc #30C218611040",
"Ac #965865955965",
"Sc #618534D32081",
"Dc #38E31C711040",
"Fc #082000000820",
"",
".XoO",
" +@#$%o&",
" *=-;#::o+",
" >,<12#:34",
" 45671#:X3",
" +89<02qwo",
"e*>,67;ro ",
"ty> 459@>+&&",
"$2u+><ipas8*",
"%$;=**3:.Xa.dfg>",
"Oh$;ya *3d.a8j,Xe.d3g8+ ",
" Oh$;ka*3d$a8lz,,xxc:.e3g54 ",
"Oh$;kO *pd$%svbzz,sxxxxfX..&wn> ",
" Oh$@mO*3dthwlsslszjzxxxxxxx3:td8M4 ",
"Oh$@g& *3d$XNlvvvlllm,mNwxxxxxxxfa.:,B* ",
" Oh$@,Od.czlllllzlmmqV@V#V@fxxxxxxxf:%j5& ",
"Oh$1hd5lllslllCCZrV#r#:#2AxxxxxxxxxcdwM*",
" OXq6c.%8vvvllZZiqqApA:mq:Xxcpcxxxxxfdc9* ",
"2r<6gde3bllZZrVi7S@SV77A::qApxxxxxxfdcM ",
":,q-6MN.dfmZZrrSS:#riirDSAX@Af5xxxxxfevo",
" +A26jguXtAZZZC7iDiCCrVVii7Cmmmxxxxxx%3g",
"*#16jszN..3DZZZZrCVSA2rZrV7Dmmwxxxx&en",
" p2yFvzssXe:fCZZCiiD7iiZDiDSSZwwxx8e*>",
" OA1<jzxwwc:$d%NDZZZZCCCZCCZZCmxxfd.B ",
"3206Bwxxszx%et.eaAp77m77mmmf3&eeeg* ",
" @26MvzxNzvlbwfpdettttttttttt.c,n&",
" *;16=lsNwwNwgsvslbwwvccc3pcfu<o",
"p;<69BvwwsszslllbBlllllllu<5+ ",
"OS0y6FBlvvvzvzss,u=Blllj=54 ",
" c1-699Blvlllllu7k96MMMg4 ",
" *10y8n6FjvllllB<166668 ",
"S-kg+>666<M<996-y6n<8*",
"p71=4 m69996kD8Z-66698&&",
"&i0ycm6n4 ogk17,0<6666g ",
" N-k-<> >=01-kuu666>",
" ,6ky&&46-10ul,66,",
" Ou0<> o66y<ulw<66& ",
"*kk5 >66By7=xu664 ",
" <<M4466lj<Mxu66o ",
" *>> +66uv,zN666* ",
"566,xxj669",
"4666FF666>",
" >966666M ",
"oM6668+ ",
"*4",
"",
""};
/* When invoked (via signal delete_event), terminates the application */
gint close_application( GtkWidget *widget,
GdkEvent*event,
gpointer data )
{
gtk_main_quit();
return(FALSE);
}
int main (int argc,
char *argv[] )
{
/* GtkWidget is the storage type for widgets */
GtkWidget *window, *pixmap, *fixed;
GdkPixmap *gdk_pixmap;
GdkBitmap *mask;
GtkStyle *style;
GdkGC *gc;
/* Create the main window, and attach delete_event signal to terminate
 * the application.Note that the main window will not have a titlebar
 * since we're making it a popup. */
gtk_init (&argc, &argv);
window = gtk_window_new( GTK_WINDOW_POPUP );
gtk_signal_connect (GTK_OBJECT (window), "delete_event",
GTK_SIGNAL_FUNC (close_application), NULL);
gtk_widget_show (window);
/* Now for the pixmap and the pixmap widget */
style = gtk_widget_get_default_style();
gc = style->black_gc;
gdk_pixmap = gdk_pixmap_create_from_xpm_d( window->window, &mask,
 &style->bg[GTK_STATE_NORMAL],
 WheelbarrowFull_xpm );
pixmap = gtk_pixmap_new( gdk_pixmap, mask );
gtk_widget_show( pixmap );
/* To display the pixmap, we use a fixed widget to place the pixmap */
fixed = gtk_fixed_new();
gtk_widget_set_usize( fixed, 200, 200 );
gtk_fixed_put( GTK_FIXED(fixed), pixmap, 0, 0 );
gtk_container_add( GTK_CONTAINER(window), fixed );
gtk_widget_show( fixed );
/* This masks out everything except for the image itself */
gtk_widget_shape_combine_mask( window, mask, 0, 0 );
/* show the window */
gtk_widget_set_uposition( window, 20, 400 );
gtk_widget_show( window );
gtk_main ();
return(0);
}
/* example-end */


 如果您对本文有任何疑问或者建议,请到讨论区发表您的意见: >> 论坛入口 <<



上一篇:GTK入门导引   下一篇:GDK Reference Manual

文章评论】 【收藏本文】 【推荐好友】 【打印本文】 【我要投稿】 【论坛讨论
更多相关文章
Power by linux-cn.com 粤ICP备05006655号