GDK的一点总结(不完全)
GDK introduce<br /><br />GDK是标准Xlib函数调用的一个基本封装(wrapper).<br />GDK (GIMP Drawing Kit) is a computer graphics library that acts as a wrapper<br />around the low-level drawing and windowing functions provided by the underlying<br />graphics system.<br /><br /><br /><br /> pixmaps and drawables<br /><br />A pixmap is an off-screen buffer you can draw graphics into. In GDK, the<br />pixmap type is called GdkPixmap. A pixmap with a single bit representing<br />each pixel is called a bitmap; GDK's bitmap type is GdkBitmap.<br />A drawable is anything you can draw graphics on. GDK has a corresponding<br />type, called GdkDrawable(include GdkWindow,GdkPixmap,GdkBitmap).<br /><br />#include <gdk/gdk><br />GdkPixmap* gdk_pixmap_new (GdkWindow* window, gint width,<br /> gint height, gint depth); /* window is the surface pixmap to display */<br />void gdk_pixmap_unref (GdkPixmap* pixmap); /* destroy a pixmap. */<br />void gdk_draw_drawable (GdkDrawable *drawable, GdkGC *gc, GdkDrawable *src,<br /> gint xsrc, gint ysrc, gint xdest, gint ydest, gint width, gint height);<br /><br /><br /><br /> colormaps and visuals<br /><br />A bitmap display consists of a rectangular grid of pixels. Each pixel consists<br />of some fixed number of bits. Pixels are mapped to visible colors.<br />In the X Window System, pixels represent entries in a color lookup table. A<br />color is a red, green, blue (RGB) value. Take an eight bit display, for<br />example: eight bits are not enough to encode a color in-place; only a few<br />arbitrary RGB values would be possible. Instead, the bits are interpreted<br />as an integer and used to index an array of RGB color values. This table<br />of colors is called the colormap.<br /><br />A visual is required to determine how a pixel's bit pattern is converted into<br />a visible color. On an 8-bit display, the X server might interpret each pixel<br />as an index into a single colormap containing the 256 possible colors. 24-bit<br />visuals typically have three colormaps: one for shades of red, one for shades<br />of green, and one for shades of blue. Each colormap is indexed with an<br />eight-bit value; the three eight-bit values are packed into a 24-bit pixel.<br />The visual defines the meaning of the pixel contents. Visuals also define<br />whether the colormap is read-only or modifiable.<br /><br /><br /> GdkVisual<br /><br />Xlib can report a list of all available visuals and information about each;<br />GDK keeps a client-side copy of this information in a struct called GdkVisual.<br />GDK can report the available visuals, and rank them in different ways. Most<br />of the time you will only use gdk_visual_get_system(), which returns a pointer<br />to the default visual.<br /><br /><br /> Color and GdkColormap<br /><br />struct GdkColor<br />{<br /> gulong pixel;<br /> gushort red;<br /> gushort green;<br /> gushort blue;<br />};<br /><br />A convenient way to obtain RGB values is the gdk_color_parse() function. This<br />takes an X color specification, and fills in the red, green, and blue fields<br />of a GdkColor. An X color specification can have many forms; one possibility<br />is an RGB string:<br /> RGB:FF/FF/FF<br />Another form:<br /> #include <gdk/gdk.h><br /> GdkColor color;<br /> if (gdk_color_parse("orange", &color)) {<br /> if (gdk_colormap_alloc_color(colormap, &color, FALSE, FALSE)) {<br /> /* We have orange! */<br /> }<br /> }<br /><br /><br /> Obtaining a Colormap<br /><br />Call gdk_colormap_get_system() to get the default colormap.<br /><br /><br /><br /> GdkPixbuf and GdkPixmap<br /><br />GdkPixbuf is used to represent images. It contains information about the<br />image's pixel data, its color space, bits per sample, width, height, etc.<br /><br />A GdkPixbuf is stored on the client, and a Pixmap on the server.<br /><br /><br /><br /> Drawing<br /><br /> Points<br />gdk_draw_point <br />gdk_draw_points<br /> Lines<br />gdk_draw_line <br />gdk_draw_lines <br />gdk_draw_segments <br /> Rectangles<br />gdk_draw_rectangle<br /> Arcs<br />gdk_draw_arc<br /> Polygons<br />gdk_draw_polygon<br /> Text<br />gdk_draw_layout<br /><br /><br /><br /> RGB Buffers<br /><br />GDK's GdkRGB module allows you to copy a client-side buffer of image data to<br />a drawable. You can't directly manipulate a GdkPixmap because a pixmap is a<br />server-side object.<br />Internally, GdkRGB uses an object called GdkImage to rapidly copy image data<br />to the server in a single request.<br />Before using any GdkRGB functions, you must initialize the module with<br />gdk_rgb_init() this sets up the visual and colormap GdkRGB will use,<br />and some internal data structures.<br />The drawable you intend to copy the RGB buffer to must use GdkRGB's visual<br />and colormap. If the drawable is a part of a widget, the easiest way to ensure<br />this is to push the GdkRGB visual and colormap when you create the widget:<br /><br />GtkWidget* widget;<br />gtk_widget_push_colormap (gdk_rgb_get_cmap());<br />widget = gtk_whatever_new ();<br />gtk_widget_pop_colormap();<br /><br />GdkRGB understands several kinds of image data. The simplest is 24-bit RGB<br />data; this kind of buffer is rendered with gdk_draw_rgb_image().<br /><br />A 24-bit RGB buffer is a one-dimensional array of bytes; every byte triplet<br />makes up a pixel (byte 0 is red, byte 1 is green, byte 2 is blue). Three<br />numbers describe the size of the array and the location of bytes within it:<br />The width is the number of pixels (byte triplets) per row of the image.<br />The height is the number of rows in the image.<br />The x,y,width,height arguments to gdk_rgb_draw_image() define a region of<br />the target drawable to copy the RGB buffer to. The RGB buffer must have at<br />least width columns and height rows. Row 0, column 0 of the RGB buffer will<br />be copied to point (x,y) on the drawable.<br /><br />#include <gdk/gdk.h><br />void gdk_rgb_init(void);<br />GdkVisual* gdk_rgb_get_visual(void);<br />void gdk_draw_rgb_image (GdkDrawable *drawable, GdkGC *gc, gint x, gint y,<br /> gint width, gint height, GdkRgbDither dith, guchar *rgb_buf,<br /> gint rowstride);<br /><br /><br /><br /> Events<br /><br />Events are sent to your application to indicate changes in a GdkWindow or user<br />actions you might be interested in. All events are associated with a GdkWindow.<br />They also come to be associated with a GtkWidget.<br /><br /><br /> Types of Event<br /><br />There are many kinds of events; the GdkEvent union can represent any of them.<br />A special event type, GdkEventAny, contains the three fields common to all<br />events; any event can be cast to GdkEventAny. The first field in GdkEventAny<br />is a type marker, GdkEventType; GdkEventType is also included in the GdkEvent<br />union. Confused yet? Seeing the code should help. Here is GdkEventAny:<br /><br />struct _GdkEventAny<br />{<br /> GdkEventType type;<br /> GdkWindow *window;<br /> gint8 send_event;<br />};<br /><br />and GdkEvent:<br /><br />union _GdkEvent<br />{<br /> GdkEventType type;<br /> GdkEventAny any;<br /> GdkEventExpose expose;<br /> GdkEventNoExpose no_expose;<br /> GdkEventVisibility visibility;<br /> GdkEventMotion motion;<br /> GdkEventButton button;<br /> GdkEventKey key;<br /> GdkEventCrossing crossing;<br /> GdkEventFocus focus_change;<br /> GdkEventConfigure configure;<br /> GdkEventProperty property;<br /> GdkEventSelection selection;<br /> GdkEventProximity proximity;<br /> GdkEventClient client;<br /> GdkEventDND dnd;<br />};<br /><br />The window field of GdkEventAny is the GdkWindow the event was sent to.<br /><br /><br /> The Event Mask<br /><br />Each GdkWindow has an associated event mask which determines which events on<br />that window the X server will forward to your application. You specify the<br />event mask when a GdkWindow is created, as part of the GdkWindowAttr struct.<br />You can access and change the event mask later using gdk_window_set_events()<br />and gdk_window_get_events(). If the GdkWindow in question belongs to a widget,<br />you should not change the event mask directly; rather, call<br />gtk_widget_set_events() or gtk_widget_add_events().<br /><br /><br /> Receiving GDK Events in GTK+<br /><br />In a GTK+ program, you will never receive GDK events directly. Instead, all<br />events are passed to a GtkWidget, which emits a corresponding signal. You<br />handle events by connecting handlers to GtkWidget signals.<br />In general, events go to the widget owning the GdkWindow the event occurred on.<br /><br />If the emission of an event signal returns TRUE, the GTK+ main loop will stop<br />propagating the current event. If it returns FALSE, the main loop will<br />propagate the event to the widget's parent.<br /><br /><br /><br /><br /><br /> 学习学习。。。。。。。。。。。。。 呵呵,学习中
页:
[1]