GdK event and GTK Signal's past and present life

Source: Internet
Author: User
Tags gtk

GDK is the GTK of the following layer of things, usually with the GTK function, rarely directly call the GDK function. But GTK inside the event, signal, callback, drawing and so on and GdK have a direct relationship, so need to GDK drawing and event-related content again to reason.

I originally intended to analyze, Baidu after a few, I gave up, there are good analysis of the article to help understand GDK events and drawings, the following is a good analysis, you can click on the link to see. I also put a few summary back, more convenient. The 5th part of the Netizen analysis is very good.

1. GDK Foundation:

Http://hi.baidu.com/phoenix20080808/blog/item/d2515519ec73f64043a9ada6.html

2. Graphics context

Http://blog.csdn.net/hahapro/archive/2007/07/25/1708132.aspx

3. GdK Event Type

Http://www.huihoo.org/gnu/gtk2-tut/a2711.html

4. GTK Message Flow Description (X window do back end)

Http://blog.csdn.net/absurd/archive/2006/03/08/619170.aspx

5. GTK event and Signal relationship

Http://blog.csdn.net/c_spark/archive/2009/05/06/4155958.aspx

1. GDK Foundation

1 Color tables and colors

1.1 Color Table

In the X Window System, the pixel value represents the entry in a color lookup table, in order for the system to have multiple display modes (8-bit, 16-bit). For example: Consider a eight-bit display mode: eight-bit is not enough to do as the color coding in the display, only a small number of RGB values encoded, display, the system will use the pixel value as an index, from the color table to find its corresponding RGB value to display pixels. This color table is called ColorMap. Sometimes, we can modify the color table to include the color to use (some colormap are read-only and cannot be modified). In GdK, Gdkcolormap is used to represent a color table gdk_widget_get_colormap: Gets the color table for the specified widget Gdk_colormap_get_system: Gets the default color table for the system

1.2 Color values

GDK uses Gdkcolor to store RGB values and pixel values. The red, green, and blue values are given in 1 6-bit unsigned integers, with a value range of 0 to 65535GdkColor defined as follows:


struct Gdkcolor
{
Gulong Pixel; Pixel value
Gushort Red;
Gushort Green;
Gushort Blue;
};

When painting with one color, you must ensure that the pixel value contains the appropriate value to ensure that the color value exists in the color table of the area to be used.

Example: To paint with a specified color


Gdkcolor color;

Color.Red = 65535;
Color.green = 0;
Color.Blue = 0;

if (Gdk_colormap_alloc_color (ColorMap, &color, FALSE, TRUE))//Fill Gdkcolor pixel component
{
/* Successful. */
}
Where ColorMap is the color table for the painted area you want to paint, you can then use the Gtkcolor color to paint gdk_colormap_alloc_color: Find the color table based on the values of the red, green, and blue components in the GDKCOLOR structure to find the red, green , the pixel value corresponding to the blue component and fills the pixel member of the Gdkcolor. When you finish using one color, you should remove it from the color table by using the Gdk_colormap_free_colors () function Gdk_color_parse: Gets the RGB value of the color from the name of the color and fills the specified Gdkcolor variable

2 painting area and Pixmap

2.1 Definition Pixmap refers to a picture buffer in memory, can be drawn inside, and then copy the data in the pixmap to memory, so you can quickly update the screen. Therefore, Pixmap is typically used to store image data that is loaded from disk. In GdK, using Gdkpixmap to represent a pixmap bitmap refers to a depth of 1 pixmap, in GdK, the use of Gdkbitmap to represent a bitmap can be painted area refers to the area that can be used for drawing, in GdK, Use gdkdrawable to represent a paint area. The painted areas include Gdkwindow, Gdkpixmap, and Gdkbitmap (depth 1 pixmap)

2.2 Operation Gdk_pixmap_new (gdkdrawable*drawable,gint width,gint height,gint depth): Create a Pixmap
When you create a pixmap, you should make the color depth of the pixmap the same as the color depth of the target window it is drawing to.
If you specify a window in its drawable parameter, the color depth is the same as the color depth of the specified window, and the depth parameter should be set to-1.
If the drawable parameter is NULL, you must specify a color depth in its depth parameter

================================================================================================ GDK_PIXMAP_ Unref: Destroying a pixmap gtk_pixmap_new: creating artifacts using the specified Gdkpixmap

The use of 2.3 gdkpixmap

gtkwidget* parent;
Gchar *xpm_filename;
Gdkpixmap *pixmap;
Gdkbitmap *mask;
Gtkstyle *style;

Create the target widget that gtkpixmap to copy to. Note: This widget must be implemented to use its Window property
Parent=gtk_window_new (Gtk_window_toplevel);
Gtk_widget_realize (parent);

Style=gtk_widget_get_style (parent);
PIXMAP=GDK_PIXMAP_CREATE_FROM_XPM (parent->window,&mask,&style->bg[gtk_state_normal],xpm_filename );

3 mouse pointer gdk_window_get_pointer The coordinate gdk_pointer_grab function used to get the mouse pointer to use a window exclusive pointer gdk_pointer_is_grabbed function to determine whether the mouse is exclusive Gdk_ Pointer_ungrab to remove the exclusive use of the mouse pointer
==========================================================

How to change the mouse pointer in a program
gdkcursor* cursor;
cursor = gdk_cursor_new (gdk_clock);
Gdk_window_set_cursor (window, cursor);
Gdk_cursor_destroy (cursor);
Attention

2. Graphic context:

A graphics context, or GC (Graphicscontext), is a set of parameters (such as color, clipping mask value, font, and so on) to use when drawing.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.