Next: , Previous: Points Rectangles and Regions, Up: Top


7 Graphics Contexts

Objects to encapsulate drawing properties

7.1 Overview

All drawing operations in GDK take a graphics context (GC) argument. A graphics context encapsulates information about the way things are drawn, such as the foreground color or line width. By using graphics contexts, the number of arguments to each drawing call is greatly reduced, and communication overhead is minimized, since identical arguments do not need to be passed repeatedly.

Most values of a graphics context can be set at creation time by using gdk-gc-new-with-values, or can be set one-by-one using functions such as gdk-gc-set-foreground. A few of the values in the GC, such as the dash pattern, can only be set by the latter method.

7.2 Usage

— Class: <gdk-gc>

Derives from <gobject>.

This class defines no direct slots.

— Function: gdk-gc-new (drawable <gdk-drawable>) ⇒  (ret <gdk-gc>)

Create a new graphics context with default values.

drawable
a <gdk-drawable>. The created GC must always be used with drawables of the same depth as this one.
ret
the new graphics context.
— Function: gdk-gc-get-screen (self <gdk-gc>) ⇒  (ret <gdk-screen>)
— Method: get-screen

Gets the <gdk-screen> for which gc was created

gc
a <gdk-gc>.
ret
the <gdk-screen> for gc.

Since 2.2

— Function: gdk-gc-set-foreground (self <gdk-gc>) (color <gdk-color>)
— Method: set-foreground

Sets the foreground color for a graphics context. Note that this function uses color->pixel, use gdk-gc-set-rgb-fg-color to specify the foreground color as red, green, blue components.

gc
a <gdk-gc>.
color
the new foreground color.
— Function: gdk-gc-set-background (self <gdk-gc>) (color <gdk-color>)
— Method: set-background

Sets the background color for a graphics context. Note that this function uses color->pixel, use gdk-gc-set-rgb-bg-color to specify the background color as red, green, blue components.

gc
a <gdk-gc>.
color
the new background color.
— Function: gdk-gc-set-rgb-fg-color (self <gdk-gc>) (color <gdk-color>)
— Method: set-rgb-fg-color

Set the foreground color of a GC using an unallocated color. The pixel value for the color will be determined using GdkRGB. If the colormap for the GC has not previously been initialized for GdkRGB, then for pseudo-color colormaps (colormaps with a small modifiable number of colors), a colorcube will be allocated in the colormap.

Calling this function for a GC without a colormap is an error.

gc
a <gdk-gc>
color
an unallocated <gdk-color>.
— Function: gdk-gc-set-rgb-bg-color (self <gdk-gc>) (color <gdk-color>)
— Method: set-rgb-bg-color

Set the background color of a GC using an unallocated color. The pixel value for the color will be determined using GdkRGB. If the colormap for the GC has not previously been initialized for GdkRGB, then for pseudo-color colormaps (colormaps with a small modifiable number of colors), a colorcube will be allocated in the colormap.

Calling this function for a GC without a colormap is an error.

gc
a <gdk-gc>
color
an unallocated <gdk-color>.
— Function: gdk-gc-set-font (self <gdk-gc>) (font <gdk-font>)
— Method: set-font

gdk_gc_set_font’ is deprecated and should not be used in newly-written code.

Sets the font for a graphics context. (Note that all text-drawing functions in GDK take a font argument; the value set here is used when that argument is ‘#f’.)

gc
a <gdk-gc>.
font
the new font.
— Function: gdk-gc-set-function (self <gdk-gc>) (function <gdk-function>)
— Method: set-function

Determines how the current pixel values and the pixel values being drawn are combined to produce the final pixel values.

gc
a <gdk-gc>.
function
the <gdk-function> to use
— Function: gdk-gc-set-fill (self <gdk-gc>) (fill <gdk-fill>)
— Method: set-fill

Set the fill mode for a graphics context.

gc
a <gdk-gc>.
fill
the new fill mode.
— Function: gdk-gc-set-tile (self <gdk-gc>) (tile <gdk-pixmap>)
— Method: set-tile

Set a tile pixmap for a graphics context. This will only be used if the fill mode is ‘GDK_TILED’.

gc
a <gdk-gc>.
tile
the new tile pixmap.
— Function: gdk-gc-set-stipple (self <gdk-gc>) (stipple <gdk-pixmap>)
— Method: set-stipple

Set the stipple bitmap for a graphics context. The stipple will only be used if the fill mode is ‘GDK_STIPPLED’ or ‘GDK_OPAQUE_STIPPLED’.

gc
a <gdk-gc>.
stipple
the new stipple bitmap.
— Function: gdk-gc-set-ts-origin (self <gdk-gc>) (int) (int)
— Method: set-ts-origin

Set the origin when using tiles or stipples with the GC. The tile or stipple will be aligned such that the upper left corner of the tile or stipple will coincide with this point.

gc
a <gdk-gc>.
x
the x-coordinate of the origin.
y
the y-coordinate of the origin.
— Function: gdk-gc-set-clip-origin (self <gdk-gc>) (int) (int)
— Method: set-clip-origin

Sets the origin of the clip mask. The coordinates are interpreted relative to the upper-left corner of the destination drawable of the current operation.

gc
a <gdk-gc>.
x
the x-coordinate of the origin.
y
the y-coordinate of the origin.
— Function: gdk-gc-set-clip-mask (self <gdk-gc>) (mask <gdk-drawable>)
— Method: set-clip-mask

Sets the clip mask for a graphics context from a bitmap. The clip mask is interpreted relative to the clip origin. (See gdk-gc-set-clip-origin).

gc
the <gdk-gc>.
mask
a bitmap.
— Function: gdk-gc-set-clip-rectangle (self <gdk-gc>) (rectangle <gdk-rectangle>)
— Method: set-clip-rectangle

Sets the clip mask for a graphics context from a rectangle. The clip mask is interpreted relative to the clip origin. (See gdk-gc-set-clip-origin).

gc
a <gdk-gc>.
rectangle
the rectangle to clip to.
— Function: gdk-gc-set-clip-region (self <gdk-gc>) (region <gdk-region>)
— Method: set-clip-region

Sets the clip mask for a graphics context from a region structure. The clip mask is interpreted relative to the clip origin. (See gdk-gc-set-clip-origin).

gc
a <gdk-gc>.
region
the <gdk-region>.
— Function: gdk-gc-set-subwindow (self <gdk-gc>) (mode <gdk-subwindow-mode>)
— Method: set-subwindow

Sets how drawing with this GC on a window will affect child windows of that window.

gc
a <gdk-gc>.
mode
the subwindow mode.
— Function: gdk-gc-set-exposures (self <gdk-gc>) (exposures bool)
— Method: set-exposures

Sets whether copying non-visible portions of a drawable using this graphics context generate exposure events for the corresponding regions of the destination drawable. (See gdk-draw-drawable).

gc
a <gdk-gc>.
exposures
if ‘#t’, exposure events will be generated.
— Function: gdk-gc-set-line-attributes (self <gdk-gc>) (line_width int) (line_style <gdk-line-style>) (cap_style <gdk-cap-style>) (join_style <gdk-join-style>)
— Method: set-line-attributes

Sets various attributes of how lines are drawn. See the corresponding members of <gdk-gc-values> for full explanations of the arguments.

gc
a <gdk-gc>.
line-width
the width of lines.
line-style
the dash-style for lines.
cap-style
the manner in which the ends of lines are drawn.
join-style
the in which lines are joined together.
— Function: gdk-gc-copy (self <gdk-gc>) (src_gc <gdk-gc>)
— Method: copy

Copy the set of values from one graphics context onto another graphics context.

dst-gc
the destination graphics context.
src-gc
the source graphics context.
— Function: gdk-gc-set-colormap (self <gdk-gc>) (colormap <gdk-colormap>)
— Method: set-colormap

Sets the colormap for the GC to the given colormap. The depth of the colormap's visual must match the depth of the drawable for which the GC was created.

gc
a <gdk-gc>
colormap
a <gdk-colormap>
— Function: gdk-gc-get-colormap (self <gdk-gc>) ⇒  (ret <gdk-colormap>)
— Method: get-colormap

Retrieves the colormap for a given GC, if it exists. A GC will have a colormap if the drawable for which it was created has a colormap, or if a colormap was set explicitely with gdk_gc_set_colormap.

gc
a <gdk-gc>
ret
the colormap of gc, or ‘#f’ if gc doesn't have one.
— Function: gdk-gc-offset (self <gdk-gc>) (x_offset int) (y_offset int)
— Method: offset

Offset attributes such as the clip and tile-stipple origins of the GC so that drawing at x - x_offset, y - y_offset with the offset GC has the same effect as drawing at x, y with the original GC.

gc
a <gdk-gc>
x-offset
amount by which to offset the GC in the X direction
y-offset
amount by which to offset the GC in the Y direction