diff options
| author | foswret | 2026-04-30 23:50:37 -0500 |
|---|---|---|
| committer | foswret | 2026-04-30 23:50:37 -0500 |
| commit | e291d28cdb37534ad5b22c1eff94a9b389edd2ad (patch) | |
| tree | 75aaccee1d05ff91eb24f6ca15a7cff530ccf5cf | |
| parent | 6f21b2bc0af8325420980e6c75eb71d39551072e (diff) | |
implement wrapper function for pango text drawing
| -rwxr-xr-x | calp | bin | 19904 -> 21992 bytes | |||
| -rw-r--r-- | src/calp.c | 7 | ||||
| -rw-r--r-- | src/draw.c | 28 | ||||
| -rw-r--r-- | src/draw.h | 2 |
4 files changed, 32 insertions, 5 deletions
| Binary files differ @@ -31,9 +31,10 @@ int main (int argc, char **argv) { // Draw stuff here fill_bg(cr, width, height); - // FUNCTIONS TO MAKE - // Draw Grid - // Draw Numbers + // Draw text in upper left corner + draw_text(cr, 0.0, 0.0, "1"); + + // Clean up cairo_destroy(cr); @@ -1,8 +1,32 @@ #include <cairo/cairo.h> +#include <pango/pangocairo.h> -int fill_bg(cairo_t *c, double x, double y) { +int fill_bg(cairo_t *c, double w, double h) { cairo_set_source_rgb (c, 255.0, 255.0, 255.0); - cairo_rectangle(c, 0, 0, x, y); + cairo_rectangle(c, 0, 0, w, h); cairo_fill(c); return 0; } + +int draw_text (cairo_t *c, double x, double y, char *text) { +#define FONT "Sans Bold 27" + PangoLayout *layout; + PangoFontDescription *desc; + + // Create a PangoLayout, setting font & text + layout = pango_cairo_create_layout(c); + + desc = pango_font_description_from_string(FONT); + pango_layout_set_font_description(layout, desc); + pango_font_description_free(desc); + + cairo_set_source_rgb (c, 0.0, 0.0, 0.0); + pango_layout_set_text(layout, text, -1); + + //pango_cairo_update_layout (c, layout); + + cairo_move_to (c, x, y); + pango_cairo_show_layout (c, layout); + g_object_unref(layout); + return 0; +} @@ -1 +1,3 @@ int fill_bg(cairo_t *c, double w, double h); + +int draw_text(cairo_t *c, double x, double y, char *text); |
