diff options
author | Leon Henrik Plickat <leonhenrik.plickat@stud.uni-goettingen.de> | 2020-09-25 11:19:32 +0200 |
---|---|---|
committer | Leon Henrik Plickat <leonhenrik.plickat@stud.uni-goettingen.de> | 2020-09-25 11:19:32 +0200 |
commit | f53c7341152bbc4b642935953e317a2a29abc99c (patch) | |
tree | 6e90223a7706da85ddfe85fbd440c6596a08a6cf /src/render.c | |
parent | 74a155389c20d4e546050c756b7fa94e445e1c1d (diff) | |
download | wlclock-f53c7341152bbc4b642935953e317a2a29abc99c.tar.gz wlclock-f53c7341152bbc4b642935953e317a2a29abc99c.tar.bz2 |
Change dimension model to ensure square center
Diffstat (limited to 'src/render.c')
-rw-r--r-- | src/render.c | 104 |
1 files changed, 42 insertions, 62 deletions
diff --git a/src/render.c b/src/render.c index 2b3d626..6aa459f 100644 --- a/src/render.c +++ b/src/render.c @@ -27,91 +27,75 @@ static void rounded_rectangle (cairo_t *cairo, uint32_t x, uint32_t y, uint32_t cairo_close_path(cairo); } -static void draw_background (cairo_t *cairo, - uint32_t x, uint32_t y, uint32_t w, uint32_t h, - uint32_t border_top, uint32_t border_right, - uint32_t border_bottom, uint32_t border_left, - uint32_t top_left_radius, uint32_t top_right_radius, - uint32_t bottom_left_radius, uint32_t bottom_right_radius, - uint32_t scale, - struct Wlclock_colour *background_colour, - struct Wlclock_colour *border_colour) +static void draw_background (cairo_t *cairo, struct Wlclock_dimensions *dimensions, + int32_t scale, struct Wlclock *clock) { - if ( colour_is_transparent(background_colour) && colour_is_transparent(border_colour) ) + if ( colour_is_transparent(&clock->background_colour) + && colour_is_transparent(&clock->border_colour) ) return; - /* Scale. */ - x *= scale, y *= scale, w *= scale, h *= scale; - border_top *= scale, border_bottom *= scale; - border_left *= scale, border_right *= scale; - top_left_radius *= scale, top_right_radius *= scale; - bottom_left_radius *= scale, bottom_right_radius *= scale; + int32_t w = scale * dimensions->w; + int32_t h = scale * dimensions->h; + int32_t center_x = scale * dimensions->center_x; + int32_t center_y = scale * dimensions->center_y; + int32_t center_size = scale * dimensions->center_size; + int32_t radius_top_left = scale * clock->radius_top_left; + int32_t radius_top_right = scale * clock->radius_top_right; + int32_t radius_bottom_left = scale * clock->radius_bottom_left; + int32_t radius_bottom_right = scale * clock->radius_bottom_right; + + clocklog(clock, 2, "[render] Render dimensions: size=%d cx=%d cy=%d w=%d h=%d\n", + center_size, center_x, center_y, w, h); cairo_save(cairo); cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE); - if ( top_left_radius == 0 && top_right_radius == 0 - && bottom_left_radius == 0 && bottom_right_radius == 0 ) + if ( radius_top_left == 0 && radius_top_right == 0 + && radius_bottom_left == 0 && radius_bottom_right == 0 ) { - if ( border_top == 0 && border_bottom == 0 - && border_left == 0 && border_right == 0 ) + if ( center_x == 0 && center_y == 0 && center_size == w && center_size == h ) { - cairo_rectangle(cairo, x, y, w, h); - colour_set_cairo_source(cairo, background_colour); + cairo_rectangle(cairo, 0, 0, w, h); + colour_set_cairo_source(cairo, &clock->background_colour); cairo_fill(cairo); } else { - /* Calculate dimensions of center. */ - uint32_t cx = x + border_left, - cy = y + border_top, - cw = w - (border_left + border_right), - ch = h - (border_top + border_bottom); - - /* Borders. */ - cairo_rectangle(cairo, x, y, w, border_top); - cairo_rectangle(cairo, x + w - border_right, y + border_top, - border_right, h - border_top - border_bottom); - cairo_rectangle(cairo, x, y + h - border_bottom, w, border_bottom); - cairo_rectangle(cairo, x, y + border_top, border_left, - h - border_top - border_bottom); - colour_set_cairo_source(cairo, border_colour); + cairo_rectangle(cairo, 0, 0, w, h); + colour_set_cairo_source(cairo, &clock->border_colour); cairo_fill(cairo); - /* Center. */ - cairo_rectangle(cairo, cx, cy, cw, ch); - colour_set_cairo_source(cairo, background_colour); + cairo_rectangle(cairo, center_x, center_y, center_size, center_size); + colour_set_cairo_source(cairo, &clock->background_colour); cairo_fill(cairo); } } else { - if ( border_top == 0 && border_bottom == 0 - && border_left == 0 && border_right == 0 ) + if ( center_x == 0 && center_y == 0 && center_size == w && center_size == h ) { - rounded_rectangle(cairo, x, y, w, h, - top_left_radius, top_right_radius, - bottom_left_radius, bottom_right_radius); - colour_set_cairo_source(cairo, background_colour); + rounded_rectangle(cairo, 0, 0, w, h, + radius_top_left, radius_top_right, + radius_bottom_left, radius_bottom_right); + colour_set_cairo_source(cairo, &clock->background_colour); cairo_fill(cairo); } else { - rounded_rectangle(cairo, x, y, w, h, - top_left_radius, top_right_radius, - bottom_left_radius, bottom_right_radius); - colour_set_cairo_source(cairo, border_colour); + rounded_rectangle(cairo, 0, 0, w, h, + radius_top_left, radius_top_right, + radius_bottom_left, radius_bottom_right); + colour_set_cairo_source(cairo, &clock->border_colour); cairo_fill(cairo); - rounded_rectangle(cairo, x + border_left, y + border_top, - w - (border_left + border_right), - h - (border_bottom + border_top), - top_left_radius, top_right_radius, - bottom_left_radius, bottom_right_radius); - colour_set_cairo_source(cairo, background_colour); + rounded_rectangle(cairo, center_x, center_y, center_size, center_size, + radius_top_left, radius_top_right, + radius_bottom_left, radius_bottom_right); + colour_set_cairo_source(cairo, &clock->background_colour); cairo_fill(cairo); } } + cairo_restore(cairo); } @@ -132,18 +116,14 @@ void render_surface_frame (struct Wlclock_surface *surface) /* Get new/next buffer. */ if (! next_buffer(&surface->current_buffer, clock->shm, surface->buffers, - surface->size * scale, surface->size * scale)) + surface->dimensions.w * scale, + surface->dimensions.h * scale)) return; cairo_t *cairo = surface->current_buffer->cairo; clear_buffer(cairo); - draw_background(cairo, 0, 0, surface->size, surface->size, - clock->border_top, clock->border_right, - clock->border_bottom, clock->border_left, - clock->radius_top_left, clock->radius_top_right, - clock->radius_bottom_left, clock->radius_bottom_right, - scale, &clock->background_colour, &clock->border_colour); + draw_background(cairo, &surface->dimensions, scale, clock); // TODO draw clock face // TODO draw clock hands to subsurface |