forked from AuroraMiddleware/gtk
Merge branch 'projective-transform' into 'master'
Replace uses of graphene_matrix_transform_ See merge request GNOME/gtk!2514
This commit is contained in:
commit
7051fdee5d
@ -1822,7 +1822,7 @@ gsk_transform_transform_bounds (GskTransform *self,
|
||||
graphene_matrix_t mat;
|
||||
|
||||
gsk_transform_to_matrix (self, &mat);
|
||||
graphene_matrix_transform_bounds (&mat, rect, out_rect);
|
||||
gsk_matrix_transform_bounds (&mat, rect, out_rect);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -1878,7 +1878,7 @@ gsk_transform_transform_point (GskTransform *self,
|
||||
graphene_matrix_t mat;
|
||||
|
||||
gsk_transform_to_matrix (self, &mat);
|
||||
graphene_matrix_transform_point (&mat, point, out_point);
|
||||
gsk_matrix_transform_point (&mat, point, out_point);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -2165,3 +2165,80 @@ gsk_transform_parse (const char *string,
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Some of the graphene_matrix_transform apis yield unexpected
|
||||
* results with projective matrices, since they silently drop
|
||||
* the w component, so we provide working alternatives here.
|
||||
*/
|
||||
void
|
||||
gsk_matrix_transform_point (const graphene_matrix_t *m,
|
||||
const graphene_point_t *p,
|
||||
graphene_point_t *res)
|
||||
{
|
||||
graphene_vec4_t vec4;
|
||||
float w;
|
||||
|
||||
graphene_vec4_init (&vec4, p->x, p->y, 0.0f, 1.0f);
|
||||
graphene_matrix_transform_vec4 (m, &vec4, &vec4);
|
||||
|
||||
w = graphene_vec4_get_w (&vec4);
|
||||
res->x = graphene_vec4_get_x (&vec4) / w;
|
||||
res->y = graphene_vec4_get_y (&vec4) / w;
|
||||
}
|
||||
|
||||
void
|
||||
gsk_matrix_transform_point3d (const graphene_matrix_t *m,
|
||||
const graphene_point3d_t *p,
|
||||
graphene_point3d_t *res)
|
||||
{
|
||||
graphene_vec4_t vec4;
|
||||
float w;
|
||||
|
||||
graphene_vec4_init (&vec4, p->x, p->y, 0.0f, 1.0f);
|
||||
graphene_matrix_transform_vec4 (m, &vec4, &vec4);
|
||||
|
||||
w = graphene_vec4_get_w (&vec4);
|
||||
res->x = graphene_vec4_get_x (&vec4) / w;
|
||||
res->y = graphene_vec4_get_y (&vec4) / w;
|
||||
res->z = graphene_vec4_get_z (&vec4) / w;
|
||||
}
|
||||
|
||||
void
|
||||
gsk_matrix_transform_bounds (const graphene_matrix_t *m,
|
||||
const graphene_rect_t *r,
|
||||
graphene_rect_t *res)
|
||||
{
|
||||
graphene_point_t ret[4];
|
||||
float min_x, min_y;
|
||||
float max_x, max_y;
|
||||
graphene_rect_t rr;
|
||||
|
||||
graphene_rect_normalize_r (r, &rr);
|
||||
|
||||
#define TRANSFORM_POINT(matrix, rect, corner, out_p) do {\
|
||||
graphene_vec4_t __s; \
|
||||
graphene_point_t __p; \
|
||||
float w; \
|
||||
graphene_rect_get_ ## corner (rect, &__p); \
|
||||
graphene_vec4_init (&__s, __p.x, __p.y, 0.f, 1.f); \
|
||||
graphene_matrix_transform_vec4 (matrix, &__s, &__s); \
|
||||
w = graphene_vec4_get_w (&__s); \
|
||||
out_p.x = graphene_vec4_get_x (&__s) / w; \
|
||||
out_p.y = graphene_vec4_get_y (&__s) / w; } while (0)
|
||||
|
||||
TRANSFORM_POINT (m, &rr, top_left, ret[0]);
|
||||
TRANSFORM_POINT (m, &rr, top_right, ret[1]);
|
||||
TRANSFORM_POINT (m, &rr, bottom_right, ret[2]);
|
||||
TRANSFORM_POINT (m, &rr, bottom_left, ret[3]);
|
||||
|
||||
#undef TRANSFORM_POINT
|
||||
|
||||
/* FIXME: graphene doesn't export a fast way to do this */
|
||||
min_x = MIN (MIN (ret[0].x, ret[1].x), MIN (ret[2].x, ret[3].x));
|
||||
min_y = MIN (MIN (ret[0].y, ret[1].y), MIN (ret[2].y, ret[3].y));
|
||||
|
||||
max_x = MAX (MAX (ret[0].x, ret[1].x), MAX (ret[2].x, ret[3].x));
|
||||
max_y = MAX (MAX (ret[0].y, ret[1].y), MAX (ret[2].y, ret[3].y));
|
||||
|
||||
graphene_rect_init (res, min_x, min_y, max_x - min_x, max_y - min_y);
|
||||
}
|
||||
|
@ -32,6 +32,16 @@ G_BEGIN_DECLS
|
||||
gboolean gsk_transform_parser_parse (GtkCssParser *parser,
|
||||
GskTransform **out_transform);
|
||||
|
||||
void gsk_matrix_transform_point (const graphene_matrix_t *m,
|
||||
const graphene_point_t *p,
|
||||
graphene_point_t *res);
|
||||
void gsk_matrix_transform_point3d (const graphene_matrix_t *m,
|
||||
const graphene_point3d_t *p,
|
||||
graphene_point3d_t *res);
|
||||
void gsk_matrix_transform_bounds (const graphene_matrix_t *m,
|
||||
const graphene_rect_t *r,
|
||||
graphene_rect_t *res);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
@ -4050,7 +4050,7 @@ gtk_widget_compute_point (GtkWidget *widget,
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
graphene_matrix_transform_point (&transform, point, out_point);
|
||||
gsk_matrix_transform_point (&transform, point, out_point);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@ -9370,8 +9370,8 @@ gtk_widget_do_pick (GtkWidget *widget,
|
||||
gsk_transform_unref (transform);
|
||||
graphene_point3d_init (&p0, x, y, 0);
|
||||
graphene_point3d_init (&p1, x, y, 1);
|
||||
graphene_matrix_transform_point3d (&inv, &p0, &p0);
|
||||
graphene_matrix_transform_point3d (&inv, &p1, &p1);
|
||||
gsk_matrix_transform_point3d (&inv, &p0, &p0);
|
||||
gsk_matrix_transform_point3d (&inv, &p1, &p1);
|
||||
if (fabs (p0.z - p1.z) < 1.f / 4096)
|
||||
continue;
|
||||
|
||||
@ -9547,7 +9547,7 @@ gtk_widget_compute_bounds (GtkWidget *widget,
|
||||
}
|
||||
|
||||
gtk_css_boxes_init (&boxes, widget);
|
||||
graphene_matrix_transform_bounds (&transform,
|
||||
gsk_matrix_transform_bounds (&transform,
|
||||
gtk_css_boxes_get_border_rect (&boxes),
|
||||
out_bounds);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user