Fix transform bugs, add docs to GP_Transform.h
[gfxprim.git] / core / GP_Transform.h
blob152253d1080403ae9e376934997e7fdb871bf3ce
1 /*****************************************************************************
2 * This file is part of gfxprim library. *
3 * *
4 * Gfxprim is free software; you can redistribute it and/or *
5 * modify it under the terms of the GNU Lesser General Public *
6 * License as published by the Free Software Foundation; either *
7 * version 2.1 of the License, or (at your option) any later version. *
8 * *
9 * Gfxprim is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
12 * Lesser General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU Lesser General Public *
15 * License along with gfxprim; if not, write to the Free Software *
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
17 * Boston, MA 02110-1301 USA *
18 * *
19 * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos *
20 * <jiri.bluebear.dluhos@gmail.com> *
21 * *
22 * Copyright (C) 2009-2010 Cyril Hrubis <metan@ucw.cz> *
23 * *
24 * Copyright (C) 2011 Tomas Gavenciak <gavento@ucw.cz> *
25 * *
26 *****************************************************************************/
28 #ifndef GP_TRANSFORM_H
29 #define GP_TRANSFORM_H
31 /*
32 * Flip a coordinate within context according to context transformation.
34 #define GP_TRANSFORM_X(context, x) do { \
35 if ((context)->x_swap) \
36 x = (context)->w - x - 1; \
37 } while (0)
39 #define GP_TRANSFORM_Y(context, y) do { \
40 if ((context)->y_swap) \
41 y = (context)->h - y - 1; \
42 } while (0)
44 /*
45 * Swap coordinates (axes) according to context transformation.
47 #define GP_TRANSFORM_SWAP(context, x, y) do { \
48 if ((context)->axes_swap) \
49 GP_SWAP(x, y); \
50 } while (0)
52 /*
53 * Transform "user"-coordinates to "real"-coordinates according to context
54 * transformation.
56 #define GP_TRANSFORM_POINT(context, x, y) do { \
57 GP_TRANSFORM_SWAP(context, x, y); \
58 GP_TRANSFORM_X(context, x); \
59 GP_TRANSFORM_Y(context, y); \
60 } while (0)
62 /*
63 * Transform "user"-coordinates to "real"-coordinates of a rectangle corner
64 * according to context transformation. Corner with min-coordinates is
65 * transformed to (different) corner with min-coordinates etc.
67 #define GP_TRANSFORM_RECT(context, x, y, rw, rh) do { \
68 GP_TRANSFORM_SWAP(context, x, y); \
69 GP_TRANSFORM_SWAP(context, w, h); \
70 if ((context)->x_swap) { \
71 x = (context)->w - x - rw; \
72 } \
73 if ((context)->y_swap) { \
74 y = (context)->h - y - rh; \
75 } \
76 } while (0)
79 * Inverse transformation to GP_TRANSFORM_POINT.
80 * Use for translating mouse pointer coordinates to coordinates on context.
82 #define GP_RETRANSFORM_POINT(context, x, y) do { \
83 GP_TRANSFORM_X(context, x); \
84 GP_TRANSFORM_Y(context, y); \
85 GP_TRANSFORM_SWAP(context, x, y); \
86 } while (0)
88 #endif /* GP_TRANSFORM_H */