transformed: Rely on transformation in widget_cairo_create
Rather than doing our own transformation handling when drawing we just rely on the generic code in widget_cairo_create
This commit is contained in:
parent
15901f0377
commit
fd456fb5e0
@ -42,67 +42,14 @@ struct transformed {
|
||||
};
|
||||
|
||||
static void
|
||||
update_transform(cairo_t *cr, enum wl_output_transform transform)
|
||||
draw_stuff(cairo_t *cr, int width, int height)
|
||||
{
|
||||
double angle;
|
||||
|
||||
cairo_matrix_t m;
|
||||
cairo_get_matrix (cr, &m);
|
||||
|
||||
switch(transform) {
|
||||
case WL_OUTPUT_TRANSFORM_FLIPPED:
|
||||
case WL_OUTPUT_TRANSFORM_FLIPPED_90:
|
||||
case WL_OUTPUT_TRANSFORM_FLIPPED_180:
|
||||
case WL_OUTPUT_TRANSFORM_FLIPPED_270:
|
||||
cairo_matrix_init(&m, -1, 0, 0, 1, 0, 0);
|
||||
break;
|
||||
default:
|
||||
cairo_matrix_init_identity(&m);
|
||||
break;
|
||||
}
|
||||
switch (transform) {
|
||||
case WL_OUTPUT_TRANSFORM_NORMAL:
|
||||
case WL_OUTPUT_TRANSFORM_FLIPPED:
|
||||
default:
|
||||
angle = 0;
|
||||
break;
|
||||
case WL_OUTPUT_TRANSFORM_90:
|
||||
case WL_OUTPUT_TRANSFORM_FLIPPED_90:
|
||||
angle = M_PI_2;
|
||||
break;
|
||||
case WL_OUTPUT_TRANSFORM_180:
|
||||
case WL_OUTPUT_TRANSFORM_FLIPPED_180:
|
||||
angle = M_PI;
|
||||
break;
|
||||
case WL_OUTPUT_TRANSFORM_270:
|
||||
case WL_OUTPUT_TRANSFORM_FLIPPED_270:
|
||||
angle = M_PI + M_PI_2;
|
||||
break;
|
||||
}
|
||||
|
||||
cairo_rotate(cr, angle);
|
||||
cairo_transform(cr, &m);
|
||||
}
|
||||
|
||||
static void
|
||||
draw_stuff(cairo_surface_t *surface, int width, int height, int transform)
|
||||
{
|
||||
cairo_t *cr;
|
||||
int tmp;
|
||||
|
||||
if (transform & 1) {
|
||||
tmp = width;
|
||||
width = height;
|
||||
height = tmp;
|
||||
}
|
||||
|
||||
cr = cairo_create(surface);
|
||||
|
||||
cairo_identity_matrix(cr);
|
||||
cairo_translate(cr, width / 2, height / 2);
|
||||
cairo_scale(cr, width / 2, height / 2);
|
||||
|
||||
update_transform(cr, transform);
|
||||
|
||||
cairo_set_source_rgba(cr, 0, 0, 0.3, 1.0);
|
||||
cairo_set_source_rgba(cr, 0, 0, 0, 1.0);
|
||||
cairo_rectangle(cr, -1, -1, 2, 2);
|
||||
@ -113,7 +60,7 @@ draw_stuff(cairo_surface_t *surface, int width, int height, int transform)
|
||||
cairo_line_to(cr, 0, -1);
|
||||
|
||||
cairo_save(cr);
|
||||
cairo_identity_matrix(cr);
|
||||
cairo_set_matrix(cr, &m);
|
||||
cairo_set_line_width(cr, 2.0);
|
||||
cairo_stroke(cr);
|
||||
cairo_restore(cr);
|
||||
@ -123,7 +70,7 @@ draw_stuff(cairo_surface_t *surface, int width, int height, int transform)
|
||||
cairo_line_to(cr, 1, 0);
|
||||
|
||||
cairo_save(cr);
|
||||
cairo_identity_matrix(cr);
|
||||
cairo_set_matrix(cr, &m);
|
||||
cairo_set_line_width(cr, 2.0);
|
||||
cairo_stroke(cr);
|
||||
cairo_restore(cr);
|
||||
@ -135,7 +82,7 @@ draw_stuff(cairo_surface_t *surface, int width, int height, int transform)
|
||||
cairo_line_to(cr, -1, 0);
|
||||
|
||||
cairo_save(cr);
|
||||
cairo_identity_matrix(cr);
|
||||
cairo_set_matrix(cr, &m);
|
||||
cairo_set_line_width(cr, 2.0);
|
||||
cairo_stroke(cr);
|
||||
cairo_restore(cr);
|
||||
@ -168,7 +115,7 @@ redraw_handler(struct widget *widget, void *data)
|
||||
struct transformed *transformed = data;
|
||||
struct rectangle allocation;
|
||||
cairo_surface_t *surface;
|
||||
int transform;
|
||||
cairo_t *cr;
|
||||
|
||||
surface = window_get_surface(transformed->window);
|
||||
if (surface == NULL ||
|
||||
@ -178,9 +125,9 @@ redraw_handler(struct widget *widget, void *data)
|
||||
}
|
||||
|
||||
widget_get_allocation(transformed->widget, &allocation);
|
||||
transform = window_get_buffer_transform(transformed->window);
|
||||
|
||||
draw_stuff(surface, allocation.width, allocation.height, transform);
|
||||
cr = widget_cairo_create(widget);
|
||||
draw_stuff(cr, allocation.width, allocation.height);
|
||||
|
||||
cairo_surface_destroy(surface);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user