diff options
author | StapleButter <thetotalworm@gmail.com> | 2017-09-09 02:30:51 +0200 |
---|---|---|
committer | StapleButter <thetotalworm@gmail.com> | 2017-09-09 02:30:51 +0200 |
commit | 70e4841d311d68689724768157cc9cbfbde7a9fc (patch) | |
tree | ba9499f77d1258530a7e60aa6e1732c41d98161c /src/libui_sdl/libui/unix/drawmatrix.c | |
parent | 81747d6c34eb159481a6ca3f283d065fa3568617 (diff) |
another UI attempt, I guess.
sorry.
Diffstat (limited to 'src/libui_sdl/libui/unix/drawmatrix.c')
-rw-r--r-- | src/libui_sdl/libui/unix/drawmatrix.c | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/src/libui_sdl/libui/unix/drawmatrix.c b/src/libui_sdl/libui/unix/drawmatrix.c new file mode 100644 index 0000000..ac7ac57 --- /dev/null +++ b/src/libui_sdl/libui/unix/drawmatrix.c @@ -0,0 +1,109 @@ +// 6 september 2015 +#include "uipriv_unix.h" +#include "draw.h" + +void m2c(uiDrawMatrix *m, cairo_matrix_t *c) +{ + c->xx = m->M11; + c->yx = m->M12; + c->xy = m->M21; + c->yy = m->M22; + c->x0 = m->M31; + c->y0 = m->M32; +} + +static void c2m(cairo_matrix_t *c, uiDrawMatrix *m) +{ + m->M11 = c->xx; + m->M12 = c->yx; + m->M21 = c->xy; + m->M22 = c->yy; + m->M31 = c->x0; + m->M32 = c->y0; +} + +void uiDrawMatrixTranslate(uiDrawMatrix *m, double x, double y) +{ + cairo_matrix_t c; + + m2c(m, &c); + cairo_matrix_translate(&c, x, y); + c2m(&c, m); +} + +void uiDrawMatrixScale(uiDrawMatrix *m, double xCenter, double yCenter, double x, double y) +{ + cairo_matrix_t c; + double xt, yt; + + m2c(m, &c); + xt = x; + yt = y; + scaleCenter(xCenter, yCenter, &xt, &yt); + cairo_matrix_translate(&c, xt, yt); + cairo_matrix_scale(&c, x, y); + cairo_matrix_translate(&c, -xt, -yt); + c2m(&c, m); +} + +void uiDrawMatrixRotate(uiDrawMatrix *m, double x, double y, double amount) +{ + cairo_matrix_t c; + + m2c(m, &c); + cairo_matrix_translate(&c, x, y); + cairo_matrix_rotate(&c, amount); + cairo_matrix_translate(&c, -x, -y); + c2m(&c, m); +} + +void uiDrawMatrixSkew(uiDrawMatrix *m, double x, double y, double xamount, double yamount) +{ + fallbackSkew(m, x, y, xamount, yamount); +} + +void uiDrawMatrixMultiply(uiDrawMatrix *dest, uiDrawMatrix *src) +{ + cairo_matrix_t c; + cairo_matrix_t d; + + m2c(dest, &c); + m2c(src, &d); + cairo_matrix_multiply(&c, &c, &d); + c2m(&c, dest); +} + +int uiDrawMatrixInvertible(uiDrawMatrix *m) +{ + cairo_matrix_t c; + + m2c(m, &c); + return cairo_matrix_invert(&c) == CAIRO_STATUS_SUCCESS; +} + +int uiDrawMatrixInvert(uiDrawMatrix *m) +{ + cairo_matrix_t c; + + m2c(m, &c); + if (cairo_matrix_invert(&c) != CAIRO_STATUS_SUCCESS) + return 0; + c2m(&c, m); + return 1; +} + +void uiDrawMatrixTransformPoint(uiDrawMatrix *m, double *x, double *y) +{ + cairo_matrix_t c; + + m2c(m, &c); + cairo_matrix_transform_point(&c, x, y); +} + +void uiDrawMatrixTransformSize(uiDrawMatrix *m, double *x, double *y) +{ + cairo_matrix_t c; + + m2c(m, &c); + cairo_matrix_transform_distance(&c, x, y); +} |