⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gtk_tut-13.html

📁 gtk 开发手册和参考文档。 包括gtk glib gdk等
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Draft//EN"><HTML><HEAD><meta http-equiv="pragma" content="no-cache"><TITLE>GTK Tutorial: Undocumented Widgets</TITLE></HEAD><BODY><A HREF="gtk_tut-12.html" tppabs="http://extend.hk.hi.cn/%7ehusuyu/http/beginner/gtk/gtk_tut-12.html"><IMG SRC="prev.gif" tppabs="http://extend.hk.hi.cn/%7ehusuyu/http/beginner/gtk/prev.gif" ALT="Previous"></A><A HREF="gtk_tut-14.html" tppabs="http://extend.hk.hi.cn/%7ehusuyu/http/beginner/gtk/gtk_tut-14.html"><IMG SRC="next.gif" tppabs="http://extend.hk.hi.cn/%7ehusuyu/http/beginner/gtk/next.gif" ALT="Next"></A><A HREF="gtk_tut.html#toc13" tppabs="http://extend.hk.hi.cn/%7ehusuyu/http/beginner/gtk/gtk_tut.html#toc13"><IMG SRC="toc.gif" tppabs="http://extend.hk.hi.cn/%7ehusuyu/http/beginner/gtk/toc.gif" ALT="Contents"></A><HR><H2><A NAME="s13">13. Undocumented Widgets</A></H2><P>These all require authors! :)  Please consider contributing to our tutorial.<P>If you must use one of these widgets that are undocumented, I stronglysuggest you take a look at their respective header files in the GTK distro.GTK's function names are very descriptive.  Once you have an understandingof how things work, it's not easy to figure out how to use a widget simplyby looking at it's function declarations.  This, along with a few examplesfrom others' code, and it should be no problem.<P>When you do come to understand all the functions of a new undocumentedwidget, please consider writing a tutorial on it so others may benifit fromyour time.<P><H2><A NAME="ss13.1">13.1 Text Entries</A></H2><P><P><H2><A NAME="ss13.2">13.2 Color Selections</A></H2><P><P><H2><A NAME="ss13.3">13.3 Range Controls</A></H2><P><P><H2><A NAME="ss13.4">13.4 Rulers</A></H2><P><P><H2><A NAME="ss13.5">13.5 Text Boxes</A></H2><P><P><H2><A NAME="ss13.6">13.6 Previews</A></H2><P><P>(This may need to be rewritten to follow the style of the rest of the tutorial)<P><BLOCKQUOTE><CODE><PRE>Previews serve a number of purposes in GIMP/GTK. The most important one isthis. High quality images may take up to tens of megabytes of memory - easy!Any operation on an image that big is bound to take a long time. If it takesyou 5-10 trial-and-errors (i.e. 10-20 steps, since you have to revert afteryou make an error) to choose the desired modification, it make take youliterally hours to make the right one - if you don't run out of memoryfirst. People who have spent hours in color darkrooms know the feeling.Previews to the rescue!But the annoyance of the delay is not the only issue. Oftentimes it ishelpful to compare the Before and After versions side-by-side or at leastback-to-back. If you're working with big images and 10 second delays,obtaining the Before and After impressions is, to say the least, difficult.For 30M images (4&quot;x6&quot;, 600dpi, 24 bit) the side-by-side comparison is rightout for most people, while back-to-back is more like back-to-1001, 1002,..., 1010-back! Previews to the rescue!But there's more. Previews allow for side-by-side pre-previews. In otherwords, you write a plug-in (e.g. the filterpack simulation) which would havea 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 veryeffective fow subtle changes. Let's go previews!There's more. For certain plug-ins real-time image-specific humanintervention maybe necessary. In the SuperNova plug-in, for example, theuser is asked to enter the coordinates of the center of the futuresupernova. The easiest way to do this, really, is to present the user with apreview 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 workingwith big images. For example, they are useful when rendering compicatedpatterns. (Just check out the venerable Diffraction plug-in + many otherones!) 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 youplug-ins and even for an image of yourself, The Author. Let's go previews!When Not to Use PreviewsDon't use previews for graphs, drawing etc. GDK is much faster for that. Usepreviews only for rendered images!Let's go previews!You can stick a preview into just about anything. In a vbox, an hbox, atable, 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. (Ofcourse, if the flat look is what you want...) Tight frames provide thenecessary borders.                               [Image][Image]Previews in many ways are like any other widgets in GTK (whatever thatmeans) except they possess an addtional feature: they need to be filled withsome sort of an image! First, we will deal exclusively with the GTK aspectof 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(int        Width,                            int        Height,                            int        Colorfulness){  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 &quot;parent&quot; frame so you canplace it somewhere else in your interface. Of course, you can pass theparent frame to this routine as a parameter. In many situations, however,the contents of the preview are changed continually by your application. Inthis case you may want to pass a pointer to the preview to a&quot;create_a_preview()&quot; and thus have control of it later.One more important note that may one day save you a lot of time. Sometimesit is desirable to label you preview. For example, you may label the previewcontaining the original image as &quot;Original&quot; and the one containing themodified image as &quot;Less Original&quot;. It might occure to you to pack thepreview along with the appropriate label into a vbox. The unexpected caveatis that if the label is wider than the preview (which may happen for avariety of reasons unforseeable to you, from the dynamic decision on thesize of the preview to the size of the font) the frame expands and no longerfits tightly over the preview. The same problem can probably arise in othersituations as well.                                   [Image]The solution is to place the preview and the label into a 2x1 table and byattaching them with the following paramters (this is one possible variationsof 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:                                   [Image]MiscMaking a preview clickable is achieved most easily by placing it in abutton. It also adds a nice border around the preview and you may not evenneed to place it in a frame. See the Filter Pack Simulation plug-in for anexample.This is pretty much it as far as GTK is concerned.Filling In a PreviewIn order to familiarize ourselves with the basics of filling in previews,let's create the following pattern (contrived by trial and error):                                   [Image]voidmy_preview_rendering_function(GtkWidget     *preview){#define SIZE 100#define HALF (SIZE/2)  guchar *row=(guchar *) malloc(3*SIZE); /* 3 bits per dot */  gint i, j;                             /* Coordinates    */  double r, alpha, x, y;  if (preview==NULL) return; /* I usually add this when I want */                             /* to avoid silly crashes. You    */                             /* should probably make sure that */                             /* everything has been nicely     */                             /* initialized!                   */  for (j=0; j &lt; ABS(cos(2*alpha)) ) { /* Are we inside the shape?  */                                         /* glib.h contains ABS(x).   */        row[i*3+0] = sqrt(1-r)*255;      /* Define Red                */        row[i*3+1] = 128;                /* Define Green              */        row[i*3+2] = 224;                /* Define Blue               */      }                                  /* &quot;+0&quot; is for alignment!    */      else {        row[i*3+0] = r*255;        row[i*3+1] = ABS(sin((float)i/SIZE*2*PI))*255;        row[i*3+2] = ABS(sin((float)j/SIZE*2*PI))*255;      }    }    gtk_preview_draw_row( GTK_PREVIEW(preview),row,0,j,SIZE);    /* Insert &quot;row&quot; into &quot;preview&quot; starting at the point with  */    /* coordinates (0,j) first column, j_th row extending SIZE */    /* pixels to the right */  }  free(row); /* save some space */  gtk_widget_draw(preview,NULL); /* what does this do? */  gdk_flush(); /* or this? */}Non-GIMP users can have probably seen enough to do a lot of things already.For the GIMP users I have a few pointers to add.Image PreviewIt is probably wize to keep a reduced version of the image around with justenough pixels to fill the preview. This is done by selecting every n'thpixel where n is the ratio of the size of the image to the size of thepreview. All further operations (including filling in the previews) are thenperformed on the reduced number of pixels only. The following is my

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -