2015-10-11 10:13:01 -05:00
|
|
|
// 11 october 2015
|
2015-10-12 08:08:50 -05:00
|
|
|
#include <math.h>
|
2015-10-16 17:31:14 -05:00
|
|
|
#include "../ui.h"
|
2015-10-11 10:13:01 -05:00
|
|
|
#include "uipriv.h"
|
|
|
|
|
2016-05-13 16:54:10 -05:00
|
|
|
void uiDrawMatrixSetIdentity(uiDrawMatrix *m)
|
2015-10-11 10:13:01 -05:00
|
|
|
{
|
|
|
|
m->M11 = 1;
|
|
|
|
m->M12 = 0;
|
|
|
|
m->M21 = 0;
|
|
|
|
m->M22 = 1;
|
|
|
|
m->M31 = 0;
|
|
|
|
m->M32 = 0;
|
|
|
|
}
|
|
|
|
|
2016-05-13 17:10:43 -05:00
|
|
|
// The rest of this file provides basic utilities in case the platform doesn't provide any of its own for these tasks.
|
|
|
|
// Keep these as minimal as possible. They should generally not call other fallbacks.
|
2015-10-12 06:58:07 -05:00
|
|
|
|
2015-10-12 08:08:50 -05:00
|
|
|
// see https://msdn.microsoft.com/en-us/library/windows/desktop/ff684171%28v=vs.85%29.aspx#skew_transform
|
2016-05-13 17:10:43 -05:00
|
|
|
// TODO see if there's a way we can avoid the multiplication
|
2015-10-12 06:58:07 -05:00
|
|
|
void fallbackSkew(uiDrawMatrix *m, double x, double y, double xamount, double yamount)
|
|
|
|
{
|
2015-10-12 08:08:50 -05:00
|
|
|
uiDrawMatrix n;
|
2015-10-12 06:58:07 -05:00
|
|
|
|
2016-05-13 17:10:43 -05:00
|
|
|
uiDrawMatrixSetIdentity(&n);
|
2015-10-12 08:08:50 -05:00
|
|
|
// TODO explain this
|
|
|
|
n.M12 = tan(yamount);
|
|
|
|
n.M21 = tan(xamount);
|
|
|
|
n.M31 = -y * tan(xamount);
|
|
|
|
n.M32 = -x * tan(yamount);
|
2016-05-13 17:10:43 -05:00
|
|
|
uiDrawMatrixMultiply(m, &n);
|
2015-10-11 11:36:48 -05:00
|
|
|
}
|
|
|
|
|
2015-10-12 00:43:12 -05:00
|
|
|
void scaleCenter(double xCenter, double yCenter, double *x, double *y)
|
|
|
|
{
|
|
|
|
*x = xCenter - (*x * xCenter);
|
|
|
|
*y = yCenter - (*y * yCenter);
|
|
|
|
}
|
|
|
|
|
2016-05-13 17:10:43 -05:00
|
|
|
// the basic algorithm is from cairo
|
|
|
|
// but it's the same algorithm as the transform point, just without M31 and M32 taken into account, so let's just do that instead
|
2015-10-11 11:36:48 -05:00
|
|
|
void fallbackTransformSize(uiDrawMatrix *m, double *x, double *y)
|
|
|
|
{
|
2016-05-13 17:10:43 -05:00
|
|
|
uiDrawMatrix m2;
|
2015-10-11 11:36:48 -05:00
|
|
|
|
2016-05-13 17:10:43 -05:00
|
|
|
m2 = *m;
|
|
|
|
m2.M31 = 0;
|
|
|
|
m2.M32 = 0;
|
|
|
|
uiDrawMatrixTransformPoint(&m2, x, y);
|
2015-10-11 11:36:48 -05:00
|
|
|
}
|