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

GTK入门导引

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

  But there's more. Previews allow for side-by-side pre-previews. In other words, you write a plug-in (e.g. the filterpack simulation) which would have a number of here's-what-it-would-look-like-if-you-were-to-do-this previews.An approach like this acts as a sort of a preview palette and is very effective fow subtle changes. Let's go previews!

  There's more. For certain plug-ins real-time image-specific human intervention maybe necessary. In the SuperNova plug-in, for example, the user is asked to enter the coordinates of the center of the future supernova. The easiest way to do this, really, is to present the user with a preview and ask him to intereactively select the spot. Let's go previews!

  Finally, a couple of misc uses. One can use previews even when not working with big images. For example, they are useful when rendering compicated patterns. (Just check out the venerable Diffraction plug-in + many other ones!) As another example, take a look at the colormap rotation plug-in (work in progress). You can also use previews for little logo's inside you plug-ins and even for an image of yourself, The Author. Let's go previews!

  When Not to Use Previews

  Don't use previews for graphs, drawing etc. GDK is much faster for that. Use previews only for rendered images!

  Let's go previews!

  You can stick a preview into just about anything. In a vbox, an hbox, a table, a button, etc. But they look their best in tight frames around them. Previews by themselves do not have borders and look flat without them. (Of course, if the flat look is what you want...) Tight frames provide the necessary borders.

  [Image][Image]

  Previews in many ways are like any other widgets in GTK (whatever that means) except they possess an addtional feature: they need to be filled with some sort of an image! First, we will deal exclusively with the GTK aspect of previews and then we'll discuss how to fill them.


GtkWidget *preview!
Without any ado:
/* Create a preview widget,
set its size, an show it */
GtkWidget *preview;
preview=gtk_preview_new(GTK_PREVIEW_COLOR)
/*Other option:
GTK_PREVIEW_GRAYSCALE);*/
gtk_preview_size (GTK_PREVIEW (preview), WIDTH, HEIGHT);
gtk_widget_show(preview);
my_preview_rendering_function(preview);
Oh yeah, like I said, previews look good inside frames, so how about:
GtkWidget *create_a_preview(intWidth,
intHeight,
intColorfulness)
{
GtkWidget *preview;
GtkWidget *frame;
frame = gtk_frame_new(NULL);
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
gtk_container_border_width (GTK_CONTAINER(frame),0);
gtk_widget_show(frame);
preview=gtk_preview_new (Colorfulness?GTK_PREVIEW_COLOR
:GTK_PREVIEW_GRAYSCALE);
gtk_preview_size (GTK_PREVIEW (preview), Width, Height);
gtk_container_add(GTK_CONTAINER(frame),preview);
gtk_widget_show(preview);
my_preview_rendering_function(preview);
return frame;
}

  That's my basic preview. This routine returns the "parent" frame so you can place it somewhere else in your interface. Of course, you can pass the parent frame to this routine as a parameter. In many situations, however, the contents of the preview are changed continually by your application. In this case you may want to pass a pointer to the preview to a "create_a_preview()" and thus have control of it later.

  One more important note that may one day save you a lot of time. Sometimes it is desirable to label you preview. For example, you may label the preview containing the original image as "Original" and the one containing the modified image as "Less Original". It might occure to you to pack the preview along with the appropriate label into a vbox. The unexpected caveat is that if the label is wider than the preview (which may happen for a variety of reasons unforseeable to you, from the dynamic decision on the size of the preview to the size of the font) the frame expands and no longer fits tightly over the preview. The same problem can probably arise in other situations as well.

  The solution is to place the preview and the label into a 2x1 table and by attaching them with the following paramters (this is one possible variations of course. The key is no GTK_FILL in the second attachment):


gtk_table_attach(GTK_TABLE(table),label,0,1,0,1,
 0,
 GTK_EXPAND|GTK_FILL,
 0,0);
gtk_table_attach(GTK_TABLE(table),frame,0,1,1,2,
 GTK_EXPAND,
 GTK_EXPAND,
 0,0);

  And here's the result:

  Misc

  Making a preview clickable is achieved most easily by placing it in a button. It also adds a nice border around the preview and you may not even need to place it in a frame. See the Filter Pack Simulation plug-in for an example.

  This is pretty much it as far as GTK is concerned.

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



上一篇:GTK+/Gnome应用开发   下一篇:GTK v1.2 Tutorial(英文)

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