diff options
| author | foswret <foswret@posteo.com> | 2025-11-10 23:13:02 -0600 |
|---|---|---|
| committer | foswret <foswret@posteo.com> | 2025-11-10 23:13:02 -0600 |
| commit | 8bb9c7ebf9d902774134bc6aa94b0886fbf82933 (patch) | |
| tree | 5fbf5947592a62648e3d9ba38ecbddcf94114023 /include | |
| parent | d6ff91295f1a6eb5f6f8a7e77c66d4c9cba694ac (diff) | |
moved all drawing functions to /include
Diffstat (limited to 'include')
| -rw-r--r-- | include/color.h | 9 | ||||
| -rw-r--r-- | include/date.h | 1 | ||||
| -rw-r--r-- | include/draw.h | 94 |
3 files changed, 104 insertions, 0 deletions
diff --git a/include/color.h b/include/color.h index f7ac991..e2b4cc0 100644 --- a/include/color.h +++ b/include/color.h @@ -2,8 +2,17 @@ if (strcmp("BLACK", str) == 0) { cairo_set_source_rgb (c, 0.0, 0.0, 0.0); } + if (strcmp("RED", str) == 0) { + cairo_set_source_rgb (c, 255.0, 0.0, 0.0); + } + if (strcmp("GREEN", str) == 0) { + cairo_set_source_rgb (c, 0.0, 255.0, 0.0); + } if (strcmp("BLUE", str) == 0) { cairo_set_source_rgb (c, 0.0, 0.0, 255.0); } + if (strcmp("GREY", str) == 0) { + cairo_set_source_rgb (c, 128.0, 128.0, 128.0); + } return(0); } diff --git a/include/date.h b/include/date.h new file mode 100644 index 0000000..4ff3d32 --- /dev/null +++ b/include/date.h @@ -0,0 +1 @@ +/* date.h: Includes all the functions relating to calculating months, days, etc. */ diff --git a/include/draw.h b/include/draw.h new file mode 100644 index 0000000..503b9c5 --- /dev/null +++ b/include/draw.h @@ -0,0 +1,94 @@ +struct dimensions { + double pw; /* paper width */ + double ph; /* paper height */ + double mw; /* month width */ + double mh; /* month height */ + double bw; /* day box width */ + double bh; /* day box height */ + double r; /* rows */ + double c; /* columns */ + double m; /* margin */ +}; + + + +int draw_calendar(cairo_t *c, double x, double y, struct dimensions d) { + double x1, y1, x2, y2; + x1 = x; + y1 = y; + x2 = d.pw - x1; /* Set the line endpoint to right side of the page */ + + for (int i = 0; i < d.r + 1; i++) { /* Draw Horizontal Lines */ + cairo_move_to (c, x, y); + cairo_line_to (c, x2, y); + y = y + d.bh; + } + + x = x1; + y = y1; + y2 = y1 + d.mh; /* Set the line endpoint as the bottom of the month */ + for (int i = 0; i < d.c + 1; i++) { /* Draw Vertical Lines */ + cairo_move_to (c, x, y); + cairo_line_to (c, x, y2); + x = x + d.bw; + } + cairo_stroke(c); + return(0); +} + + + +int draw_numbers(cairo_t *c, double x, double y, struct dimensions d, int wd, int nd) { + char str[3]; + cairo_text_extents_t te; + cairo_font_extents_t fe; + + cairo_select_font_face (c, "sans-serif", + CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD); + cairo_set_font_size (c, d.bw / 2); + + int iterative = 0; + cairo_font_extents (c, &fe); + double yi = y; + double xi = x; + int current_weekday = wd; + x = d.m + (wd * d.bw); + for (int j = 0; j < d.r; j++) { + y = y + d.bh - ((d.bh - fe.ascent) / 2); + for (int k = current_weekday; k < d.c; k++) { + if (iterative < nd) { + sprintf(str, "%d", iterative + 1); + cairo_text_extents (c, str, &te); + double box_margins = (d.bw - te.width) / 2; + + cairo_move_to(c, x + box_margins - te.x_bearing, y); /* center the number within the box */ + cairo_show_text(c, str); + cairo_move_to(c, x, y); /* Sort of backtrack to realign with the spacing of the boxes */ + x = x + d.bw; + iterative++; + current_weekday++; + } + } + current_weekday = 0; + y = y - (d.bh - ((d.bh - fe.ascent) / 2)); + y = y + d.bh; + x = xi; + } + return(0); +} + + + +int draw_month_name(cairo_t *c, char *name, struct dimensions d) { + double x, y = d.m; + cairo_set_font_size(c, 1.0); + cairo_text_extents_t te; + cairo_font_extents_t fe; + cairo_text_extents(c, name, &te); + x = (d.pw / 2) - (te.width / 2); + y = 1.5; + cairo_move_to(c, x, y); + cairo_show_text(c, &name[0]); + return(0); +} + |
