Graphics Contexts

Graphics Contexts — Drawing regions

Functions

Types and Values

Object Hierarchy

    GBoxed
    ╰── GrxContext

Includes

#include <grx-3.0.h>

Description

The library supports a set of drawing regions called contexts (GrxContext). These can be in video memory or in system memory. Contexts in system memory always have the same memory organization as the video memory. When grx_set_mode() is called, a default context is created which maps to the whole graphics screen.

Functions

grx_get_screen_context ()

GrxContext *
grx_get_screen_context (void);

Gets the screen context.

Returns

the screen context.

[transfer none]


grx_get_current_context ()

GrxContext *
grx_get_current_context (void);

Gets the current context.

Returns

the current context.

[transfer none]


grx_set_current_context ()

void
grx_set_current_context (const GrxContext *context);

Sets the current context to context .

The current context structure is stored in a static location in the library. (For efficiency reasons – it is used quite frequently, and this way no pointer dereferencing is necessary.) The context stores all relevant information about the video organization, coordinate limits, etc...

Parameters

context

the context

 

grx_save_current_context ()

GrxContext *
grx_save_current_context (GrxContext *where);

Saves a copy of the current context.

This is generally used to temporarily save and restore a context. Example:

void my_function (GrxContext *my_context)
{
    GrxContext save;

    grx_save_current_context (&save);
    grx_set_current_context (my_context);
    // call some drawing functions
    grx_set_current_context (&save);
}

Parameters

where

unused GrxContext where the context will be saved or NULL.

[nullable]

Returns

where or a new context if where was NULL. Returns NULL on error.

[nullable]


grx_context_new ()

GrxContext *
grx_context_new (gint w,
                 gint h,
                 GrxFrameMemory *memory,
                 GrxContext *where);

Creates a new context in system memory using the memory layout specified by grx_frame_mode_get_screen_core().

memory must contain grx_screen_get_n_planes() pointers (usually just one, but could be as many as 4) of size grx_screen_get_plane_size(). NULL may also be passed to memory , in which case the memory will be dynamically allocated.

Likewise, where can be an unused GrxContext (e.g. you may want to do this if you want a stack allocated context) or it can be NULL to dynamically allocate a new context.

Parameters

w

the width of the context

 

h

the height of the context

 

memory

memory location(s) or NULL.

[nullable]

where

an unused GrxContext struct or NULL.

[nullable]

Returns

where or a new context if where was NULL. Returns NULL on error.

[nullable]


grx_context_new_full ()

GrxContext *
grx_context_new_full (GrxFrameMode mode,
                      gint w,
                      gint h,
                      GrxFrameMemory *memory,
                      GrxContext *where);

Creates a new context in system memory using the memory layout specified by mode .

memory must contain grx_frame_mode_get_n_planes() pointers (usually just one, but could be as many as 4) of size grx_frame_mode_get_plane_size(). NULL may also be passed to memory , in which case the memory will be dynamically allocated.

Likewise, where can be an unused GrxContext (e.g. you may want to do this if you want a stack allocated context) or it can be NULL to dynamically allocate a new context.

Parameters

mode

the frame mode

 

w

the width of the context

 

h

the height of the context

 

memory

memory location(s) or NULL.

[nullable]

where

an unused GrxContext struct or NULL.

[nullable]

Returns

where or a new context if where was NULL. Returns NULL on error.

[nullable]


grx_context_new_subcontext ()

GrxContext *
grx_context_new_subcontext (gint x1,
                            gint y1,
                            gint x2,
                            gint y2,
                            const GrxContext *parent,
                            GrxContext *where);

Creates a new sub-context which maps to a part of an existing context.

The coordinate arguments (x1 through y2) are interpreted relative to the parent context's limits. Pixel addressing is zero-based even in sub-contexts, i.e. the address of the top left pixel is (0,0) even in a sub-context which has been mapped onto the interior of its parent context.

Parameters

x1

the left bounds

 

y1

the top bounds

 

x2

the right bounds

 

y2

the bottom bounds

 

parent

the parent context or NULL to use the screen.

[nullable]

where

an unused GrxContext struct to hold the subcontext or NULL.

[nullable]

Returns

where or a new context if where was NULL. Return NULL on error.

[nullable]


grx_context_resize_subcontext ()

void
grx_context_resize_subcontext (GrxContext *context,
                               gint x1,
                               gint y1,
                               gint x2,
                               gint y2);

Sub-contexts can be resized, but not their parents (i.e. anything returned by grx_context_new() or set up by grx_set_mode() cannot be resized – because this could lead to irrecoverable "loss" of drawing memory.

The coordinate arguments (x1 through y2) are interpreted relative to the parent context's limits.

Parameters

context

the context

 

x1

the new left bounds

 

y1

the new top bounds

 

x2

the new right bounds

 

y2

the new bottom bounds

 

grx_context_ref ()

GrxContext *
grx_context_ref (GrxContext *context);

Increases the reference count to context .

Parameters

context

the context

 

Returns

the context


grx_context_unref ()

void
grx_context_unref (GrxContext *context);

Decreases the reference count to context .

When the reference count drops to 0, the context and any dynamically allocated memory of the context will be freed.

Parameters

context

the context.

[transfer full]

grx_context_get_width ()

gint
grx_context_get_width (GrxContext *context);

Gets the width of context .

Parameters

context

a GrxContext

 

Returns

the width


grx_context_get_height ()

gint
grx_context_get_height (GrxContext *context);

Gets the height of context .

Parameters

context

a GrxContext

 

Returns

the height


grx_context_get_max_x ()

gint
grx_context_get_max_x (GrxContext *context);

Gets the right bounds of context .

Parameters

context

a GrxContext

 

Returns

the value


grx_context_get_max_y ()

gint
grx_context_get_max_y (GrxContext *context);

Gets the bottom bounds of context .

Parameters

context

a GrxContext

 

Returns

the value


grx_context_clear ()

void
grx_context_clear (GrxContext *context,
                   GrxColor bg);

Clears the specified context using the specified background color.

Thanks to the special GrxColor definition, you can do more than simple clear with this functions, by example with:

grx_context_clear (ctx, grx_color_to_xor_mode (GRX_COLOR_WHITE));

the context is negativized, do it again and the context is restored.

Also see grx_clear_context() for clearing the current context and grx_clear_screen() for clearing the screen.

Parameters

context

the context

 

bg

the background color

 

grx_context_flood_spill ()

void
grx_context_flood_spill (GrxContext *context,
                         gint x1,
                         gint y1,
                         gint x2,
                         gint y2,
                         GrxColor old_c,
                         GrxColor new_c);

Replaces old color with new color in the context in the area bounded by the rectangle x1, y1, x2, y2.

This is quite useful for highlighting a selected item in a list, or changing a selected color(s) in a multi colored area.

Also see grx_flood_spill() for operating on the current context.

Parameters

context

the context

 

x1

the left edge of the bounding rectangle

 

y1

the top edge of the bounding rectangle

 

x2

the right edge of the bounding rectangle

 

y2

the bottom edge of the bounding rectangle

 

old_c

the color to be replaced

 

new_c

the new color

 

grx_context_flood_spill2 ()

void
grx_context_flood_spill2 (GrxContext *context,
                          gint x1,
                          gint y1,
                          gint x2,
                          gint y2,
                          GrxColor old_c1,
                          GrxColor new_c1,
                          GrxColor old_c2,
                          GrxColor new_c2);

Replaces two old colors with two new colors in the context in the area bounded by the rectangle x1, y1, x2, y2. old_c1 is replaced with new_c1 and old_c2 is replaced with new_c2 .

This is quite useful for highlighting a selected item in a list, or changing a selected color(s) in a multi colored area.

Also see grx_flood_spill2() for operating on the current context.

Parameters

context

the context

 

x1

the left edge of the bounding rectangle

 

y1

the top edge of the bounding rectangle

 

x2

the right edge of the bounding rectangle

 

y2

the bottom edge of the bounding rectangle

 

old_c1

the first color to be replaced

 

new_c1

the first new color

 

old_c2

the second color to be replaced

 

new_c2

the second new color

 

grx_context_get_pixel_at ()

GrxColor
grx_context_get_pixel_at (GrxContext *context,
                          gint x,
                          gint y);

Gets the color value of the pixel in the context at the specified coordinates.

Also see grx_get_pixel_at() for operating on the current context.

Parameters

context

the context

 

x

the X coordinate

 

y

the Y coordinate

 

grx_context_bit_blt ()

void
grx_context_bit_blt (GrxContext *context,
                     gint x,
                     gint y,
                     GrxContext *src,
                     gint x1,
                     gint y1,
                     gint x2,
                     gint y2,
                     GrxColor op);

Copies an area bounded by x1, y2, x2, y2 in the source context to the destination context at the location specified by dx, dy using the specified operation.

Also see grx_bit_blt() for operating on the current context.

Parameters

context

the destination context

 

x

the destination X coordinate

 

y

the destination Y coordinate

 

src

the source context or NULL to use the current context.

[nullable]

x1

the source bounding rectangle left coordinate

 

y1

the source bounding rectangle top coordinate

 

x2

the source bounding rectangle right coordinate

 

y2

the source bounding rectangle bottom coordinate

 

op

the GrxColorMode operator and optional transparent color

 

grx_context_bit_blt_1bpp ()

void
grx_context_bit_blt_1bpp (GrxContext *context,
                          gint x,
                          gint y,
                          GrxContext *src,
                          gint x1,
                          gint y1,
                          gint x2,
                          gint y2,
                          GrxColor fg,
                          GrxColor bg);

Copies an area bounded by x1, y2, x2, y2 in the source context to the destination context at the location specified by dx, dy using the specified operation.

The source must be a 1 bit per pixel bitmap. The foreground color is used for bits = 1 and the background color is used for bits = 0.

Also see grx_bit_blt_1bpp() for operating on the current context.

Parameters

context

the destination context

 

x

the destination X coordinate

 

y

the destination Y coordinate

 

src

the source context or NULL to use the current context.

[nullable]

x1

the source bounding rectangle left coordinate

 

y1

the source bounding rectangle top coordinate

 

x2

the source bounding rectangle right coordinate

 

y2

the source bounding rectangle bottom coordinate

 

fg

the foreground color

 

bg

the background color

 

grx_context_get_scanline ()

const GrxColor *
grx_context_get_scanline (GrxContext *context,
                          gint x1,
                          gint x2,
                          gint y,
                          guint *n);

An efficient way to get pixels from a context. Important: the return value is only valid until the next Grx call!

Also see grx_get_scanline() for operating on the current context.

Parameters

context

the context

 

x1

the starting X coordinate

 

x2

the ending X coordinate

 

y

the Y coordinate

 

n

the length of the array.

[out][optional]

Returns

an array of color values from the scanned pixels or NULL if there was an error.

[array length=n][nullable][transfer none]


grx_context_set_clip_box ()

void
grx_context_set_clip_box (GrxContext *context,
                          gint x1,
                          gint y1,
                          gint x2,
                          gint y2);

Sets the clipping limits on context .

Parameters

context

the context

 

x1

the left bounds

 

y1

the top bounds

 

x2

the right bounds

 

y2

the bottom bounds

 

grx_context_get_clip_box ()

void
grx_context_get_clip_box (const GrxContext *context,
                          gint *x1,
                          gint *y1,
                          gint *x2,
                          gint *y2);

Gets the clipping limits of context .

Parameters

context

the context

 

x1

the left bounds.

[out]

y1

the top bounds.

[out]

x2

the right bounds.

[out]

y2

the bottom bounds.

[out]

grx_context_reset_clip_box ()

void
grx_context_reset_clip_box (GrxContext *context);

Resets the clipping limits on context to the size of context .

Parameters

context

the context

 

GRX_FRAME_MEMORY_PLANE()

#define GRX_FRAME_MEMORY_PLANE(f,i) (((guint8**)f)[i])

Gets a plane from GrxFrameMemory by its index.

Parameters

f

pointer to GrxFrameMemory

 

i

the index of the plane (0-3)

 

Types and Values

GrxFrameMemory

typedef struct {
} GrxFrameMemory;

Private data structure used by GrxFrame.


GrxFrame

typedef struct {
} GrxFrame;

Private data structure used by GrxContext.


GrxContext

typedef struct {
} GrxContext;

Private data structure used by GrxContext.