diff options
Diffstat (limited to 'src/draw.c')
| -rw-r--r-- | src/draw.c | 47 |
1 files changed, 33 insertions, 14 deletions
@@ -47,6 +47,16 @@ RGB { }; +// Generic struct for storing where an object is and how +// it takes up space. +struct extents { + double x; + double y; + double width; + double height; +}; + + // Convert Hex color strings to their RGB counterparts. // IMO, hex strings are easier to work with, so this is @@ -58,6 +68,7 @@ RGB hex_to_rgb(char *str) { sscanf(str, "%02x%02x%02x", &r, &g, &b); + // R, G, B values are from 0.0 - 1.0, so needs to be divided by 255.0 color.r = (r / 255.0); color.g = (g / 255.0); color.b = (b / 255.0); @@ -223,10 +234,10 @@ print_dimensions(struct dimensions *d) { // Most months can fit within 4 or 5 rows instead of 6. // TBD: This can probably done in a more efficient way int -calculate_minimum_rows(struct month_info *m, struct dimensions *d) { +calculate_minimum_rows(struct month_info *m) { int extra_rows = 0; - int days_in_first_week = (d->column_count - m->first_day); + int days_in_first_week = (7 - m->first_day); if (m->first_day == 0) { days_in_first_week = m->first_day; @@ -253,32 +264,40 @@ calculate_minimum_rows(struct month_info *m, struct dimensions *d) { // Draws the grid lines for a month int -draw_month_grid (cairo_t *c, struct month_info *m, struct dimensions *d) { - double cursor_x = d->month_top_corner_x; +draw_month_grid (cairo_t *c, struct month_info *m, struct extents *me, struct extents *de) { + double cursor_x = me->x; - int row_offset = d->row_count - calculate_minimum_rows(m, d); - double cursor_y = d->month_top_corner_y + (row_offset * d->day_height); + int column_count = 7; + int row_count = 6; + // double cursor_x = month_grid_pos->x; + + // make d->row_count reside in month_info *m + int row_offset = row_count - calculate_minimum_rows(m); + // double cursor_y = month_grid_pos->y; + double cursor_y = me->y + (row_offset * de->height); double x = cursor_x; double y = cursor_y; set_color(c, BLACK); - cairo_set_line_width (c, 1.0); + cairo_set_line_width(c, 1.0); - for (int i = 0; i <= d->column_count; i++) { + // Vertical lines + for (int i = 0; i <= column_count; i++) { cairo_move_to(c, cursor_x, cursor_y); - cairo_line_to(c, cursor_x, cursor_y + (d->month_height - (row_offset * d->day_height))); - cursor_x = cursor_x + d->day_width; + cairo_line_to(c, cursor_x, cursor_y + (me->height - (row_offset * de->height))); + cursor_x = cursor_x + de->width; } // Recenter the cursor cursor_x = x; cursor_y = y; - for (int i = 0; i <= d->row_count; i++) { + // Horizontal lines + for (int i = 0; i <= row_count; i++) { cairo_move_to(c, cursor_x, cursor_y); - cairo_line_to(c, cursor_x + d->month_width, cursor_y); - cursor_y = cursor_y + d->day_height; + cairo_line_to(c, cursor_x + me->width, cursor_y); + cursor_y = cursor_y + de->height; } cairo_stroke(c); @@ -317,7 +336,7 @@ draw_month(cairo_t *c, cairo_t *cd, cairo_surface_t *s, struct month_info *m, st if (m->first_day != 0) cursor_x = cursor_x + (d->day_width * m->first_day); // Push bottom of month as far down the page as the margin allows - int row_offset = d->row_count - calculate_minimum_rows(m, d); + int row_offset = d->row_count - calculate_minimum_rows(m); double cursor_y = d->month_top_corner_y + (row_offset * d->day_height); int current_day = m->first_day; |
