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 |