diff options
Diffstat (limited to 'src/draw.c')
| -rw-r--r-- | src/draw.c | 50 |
1 files changed, 32 insertions, 18 deletions
@@ -6,7 +6,8 @@ #include "color.h" // struct for storing dimensions used for calculations, movement, etc. -struct dimensions { +struct +dimensions { // Multiplication factors int row_count; /* rows */ int column_count; /* columns */ @@ -28,7 +29,8 @@ struct dimensions { // struct to hold Month-specific info, like what day of the week the first // day lands on, how many days are in the month, etc. -struct month_info { +struct +month_info { int month_position; int first_day; int num_of_days; @@ -37,7 +39,8 @@ struct month_info { // struct for defining RGB colors -struct RGB { +struct +RGB { double r; double g; double b; @@ -48,7 +51,8 @@ struct RGB { // Convert Hex color strings to their RGB counterparts. // IMO, hex strings are easier to work with, so this is // a nice helper function. -struct RGB hex_to_rgb(char *str) { +struct +RGB hex_to_rgb(char *str) { unsigned int r, g, b; struct RGB color; @@ -65,7 +69,8 @@ struct RGB hex_to_rgb(char *str) { // Set a context's color using a HEX code. Color macros are defined // in color.h -int set_color(cairo_t *c, char *hex) { +int +set_color(cairo_t *c, char *hex) { struct RGB color = hex_to_rgb(hex); cairo_set_source_rgb (c, color.r, color.g, color.b); return 0; @@ -77,16 +82,16 @@ int set_color(cairo_t *c, char *hex) { // Relative to "Su Mo Tu ... Sa" frame, not when Su and Sa are together // Range is 0 -> 6 // https://wiki.c2.com/?PerpetualCalendarAlgorithm -int day_of_week (int d, int m, int y) { +int +day_of_week (int d, int m, int y) { return((d += m < 3 ? y-- : y - 2, 23*m/9 + d + 4 + y/4- y/100 + y/400)%7); } - - // Fill entire background with current color // Function name is changed for clarity -int fill_bg(cairo_t *c) { +int +fill_bg(cairo_t *c) { cairo_paint(c); return 0; } @@ -98,7 +103,8 @@ int fill_bg(cairo_t *c) { // Requires Font Family (string) and Size (int) // Creates and destroys layout within the scope of the function // Is that performant when looped over 365 operations? -int draw_text (cairo_t *c, double x, double y, char *font_family, int font_size, char *text) { +int +draw_text (cairo_t *c, double x, double y, char *font_family, int font_size, char *text) { char font[100]; // Concat font string for pango_font_description_from_string @@ -127,7 +133,8 @@ int draw_text (cairo_t *c, double x, double y, char *font_family, int font_size, // Get the dimensions of a string of text // Returns a PangoRectangle struct -PangoRectangle get_logical_extents (cairo_t *c, char *font_family, int font_size, char *text) { +PangoRectangle +get_logical_extents (cairo_t *c, char *font_family, int font_size, char *text) { char font[100]; // Concat font string for pango_font_description_from_string @@ -155,7 +162,8 @@ PangoRectangle get_logical_extents (cairo_t *c, char *font_family, int font_size // Calculate dimenions for one page and stores it in the dimensions struct // Used for determining where elements should be drawn on the page -int calculate_dimensions(double pw, double ph, struct dimensions *d) { +int +calculate_dimensions(double pw, double ph, struct dimensions *d) { d->row_count = 6; d->column_count = 7; @@ -191,7 +199,8 @@ int calculate_dimensions(double pw, double ph, struct dimensions *d) { // Print the contents of a dimensions struct. // Use for debugging -int print_dimensions(struct dimensions *d) { +int +print_dimensions(struct dimensions *d) { printf("row count: %d\n", d->row_count); printf("column count: %d\n", d->column_count); printf("paper width: %.2f\n", d->paper_width); @@ -213,7 +222,8 @@ int print_dimensions(struct dimensions *d) { // Calculate minimum amount of rows a month can fit in. // 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) { +int +calculate_minimum_rows(struct month_info *m, struct dimensions *d) { int extra_rows = 0; int days_in_first_week = (d->column_count - m->first_day); @@ -242,7 +252,8 @@ int 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) { +int +draw_month_grid (cairo_t *c, struct month_info *m, struct dimensions *d) { double cursor_x = d->month_top_corner_x; int row_offset = d->row_count - calculate_minimum_rows(m, d); @@ -276,7 +287,8 @@ int draw_month_grid (cairo_t *c, struct month_info *m, struct dimensions *d) { -int construct_day_box(cairo_t *cd, int month, int day, int week_day) { +int +construct_day_box(cairo_t *cd, int month, int day, int week_day) { char str[20]; double padding = 8.0; @@ -298,7 +310,8 @@ int construct_day_box(cairo_t *cd, int month, int day, int week_day) { // Draws one month using daybox sub-surface & context, main context, and dimension struct -int draw_month (cairo_t *c, cairo_t *cd, cairo_surface_t *s, struct month_info *m, struct dimensions *d) { +int +draw_month(cairo_t *c, cairo_t *cd, cairo_surface_t *s, struct month_info *m, struct dimensions *d) { double cursor_x = d->month_top_corner_x; if (m->first_day != 0) cursor_x = cursor_x + (d->day_width * m->first_day); @@ -344,7 +357,8 @@ int draw_month (cairo_t *c, cairo_t *cd, cairo_surface_t *s, struct month_info * // Draws the month being drawn at the top of the page -int draw_month_title(cairo_t *c, struct dimensions *d, char *font_family, int font_size, char *name) { +int +draw_month_title(cairo_t *c, struct dimensions *d, char *font_family, int font_size, char *name) { PangoRectangle rect; |
