using-libgcontext
Skill4 starsChanged 8 months agoMITView on GitHub
Guidance for using the GContext graphics library on RISC OS for drawing primitives and rendering text. Use when the agent needs to implement screen output, handle font metrics, or manage graphics contexts.
In this repository47 other files it gives its agents.
- allocating-resourcesSkill
- ci-testingSkill
- creating-pull-requestsSkill
- designing-modulesSkill
- porting-to-riscos-cSkill
- reading-assemblySkill
- riscos-commandsSkill
- riscos-desktop-fileractionSkill
- riscos-filer-likeSkill
- riscos-filesystemSkill
- riscos-graphics-convertersSkill
- riscos-network-dcistatisticsSkill
- riscos-network-resolverSkill
- riscos-outputSkill
- riscos-reSkill
- riscos-styleSkill
- riscos-throwbackSkill
- riscos-urls-fetchingSkill
- riscos-urls-launchingSkill
- riscos-wimp-appSkill
- riscos-wimpSkill
- riscos-wimp-templatesSkill
- updating-robe-skillsSkill
- using-bbcbasicSkill
- using-cmhgSkill
- using-ghSkill
- using-gitSkill
- using-libasmSkill
- using-liboslibSkill
- using-libriscoslibSkill
- using-libtoolboxSkill
- using-makefilesSkill
- using-perlSkill
- using-stronghelpSkill
- using-toolbox-imagefilegadgetSkill
- using-tooltesterSkill
- writing-assemblySkill
- writing-assembly-testsSkill
- writing-cmodulesSkill
- writing-cplusplusSkill
- writing-cSkill
- writing-fortranSkill
- writing-oslib-defsSkill
- writing-pascalSkill
- writing-prminxmlSkill
- writing-pymodulesSkill
- writing-pyromaniac-integration-testsSkill
The file
We split this skill into the rules it gives an agent
10 rules. About 0 are common, 1 is distinctive, and 9 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
9
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 17
All operations require a gcontext_t pointer.
- Distinctive: line 19
Use one of these initialisers depending on the backend you need:
- Very specific: line 25
When finished with any backend, release it with gcontext_destroy(gc).
- Very specific: line 33
Use colour_t for all colour parameters.
- Very specific: line 34
Use COLOUR_RGB(r, g, b) to create a colour value.
- Very specific: line 35
Use COLOUR_NONE to skip drawing (e.g., for transparent backgrounds).
- Very specific: line 54
If you need to size a memory buffer before rendering, create a sizing context with gcontext_initdrawfilememory(NULL, 0), perform the …
- Very specific: line 61
Use rectangle_fill or rectangle_outline for boxes.
- Very specific: line 75
Use clip_rectangle(gc, &bbox) to request clipping and clip_rectangle(gc, NULL) to reset it.
- Very specific: line 93
Ensure C$Path includes the directory containing the GContext library.
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Using GContext
The GContext library provides an abstracted interface for 2D graphics operations.
Core Concepts
Graphics Context
All operations require a gcontext_t pointer.
Use one of these initialisers depending on the backend you need:
gcontext_initvdu(2)for normal rendering through VDU/Font output.gcontext_initdrawfile(filename)to construct a DrawFile and write it on finalisation.gcontext_initdrawfilememory(memory, memorysize)to construct a DrawFile in memory.
When finished with any backend, release it with gcontext_destroy(gc).
Coordinate System
- Coordinates are standard RISC OS OS-units.
- Y-axis typically increases upwards.
- For text painting, the coordinates specified are for the baseline of the string.
Colours
- Use
colour_tfor all colour parameters. - Use
COLOUR_RGB(r, g, b)to create a colour value. - Use
COLOUR_NONEto skip drawing (e.g., for transparent backgrounds).
Workflows
VDU Rendering
- Initialise the context with
gcontext_initvdu(...). - Draw shapes and text through the function pointers in
gcontext_t. - Release the context with
gcontext_destroy(gc).
DrawFile Rendering
- Initialise the context with
gcontext_initdrawfile(...)orgcontext_initdrawfilememory(...). - Draw through the normal
gcontext_tplotting and text interfaces. - Finalise the DrawFile with
gcontext_drawfile_finalise(gc). - Release the context with
gcontext_destroy(gc).
The DrawFile backend accumulates the generated content in memory until finalisation.
Even file-backed output is serialised in memory first and only written to the destination
file during gcontext_drawfile_finalise(gc).
If you need to size a memory buffer before rendering, create a sizing context with
gcontext_initdrawfilememory(NULL, 0), perform the drawing, call
gcontext_drawfile_datasize(gc), destroy that context, then create a second memory-backed
context with a buffer of the required size and render again before finalising.
Drawing Primitives
- Initialize the context.
- Use
rectangle_fillorrectangle_outlinefor boxes. - For lines, use the sequence:
line_start(gc, colour), then one or moreline_line(gc, x0, y0, x1, y1), and finallyline_end(gc). - Filled polygons can use
fill_start,fill_move,fill_line,fill_close, andfill_endwhen the backend supports them.
Rendering Text
- Find a font using
text_findfont(gc, name, xsize, ysize). - Calculate dimensions if needed using
text_getstringsize. Crucial: Use thexoffsetfield ofstringbounds_tfor advancing the cursor horizontally, as it accounts for character spacing correctly. The total width of the string isbounds.xoffset + bounds.rbearing. - Paint text using
text_paint(gc, font, xb, yb, bg, fg, str, len). UseGCONTEXT_ZEROTERMfor the length if the string is null-terminated. - Release the font when finished using
text_losefont(gc, font).
For aligned text in a bounding box, use text_paintattrib with FONTATTRIB_ALIGN_*
and FONTATTRIB_UNDERLINE.
Clipping
Use clip_rectangle(gc, &bbox) to request clipping and clip_rectangle(gc, NULL) to reset it.
For DrawFile output this is not represented as a Draw clipping object; the backend only suppresses objects that are wholly outside the requested clip area.
Installation and Setup
Linking
Link against the GContext library in your Makefile,fe1:
LIBS = ${CLIB} C:GContext.o.libGContextThe DrawFile backend is implemented in a separate object inside the library so code which only uses the VDU entry points does not need to reference the DrawFile initialisers or finalisation routines.
Environment
Ensure C$Path includes the directory containing the GContext library. In .robuild.yaml, you can add:
- Set C$Path @.Lib.,<C$Path>(Assuming the library is extracted to a Lib directory in your project root).
Continuous Integration (GitHub Actions)
To use GContext in CI, download and extract the library:
- name: Obtain the GContext library
run: |
curl -s -L -o libgcontext.zip https://github.com/gerph/riscos-gcontext/releases/download/v0.05/GContext-0.05.zip
python3 -m rozipfile --verbose --extract libgcontext.zip
rm libgcontext.zipAPI Reference
See api.md for detailed structure definitions and function pointer signatures.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

