1 /*****************************************************************************
2 * This file is part of gfxprim library. *
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. *
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. *
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 *
19 * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos *
20 * <jiri.bluebear.dluhos@gmail.com> *
22 * Copyright (C) 2009-2010 Cyril Hrubis <metan@ucw.cz> *
24 * Copyright (C) 2011 Tomas Gavenciak <gavento@ucw.cz> *
26 *****************************************************************************/
28 #ifndef GP_TRANSFORM_H
29 #define GP_TRANSFORM_H
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; \
39 #define GP_TRANSFORM_Y(context, y) do { \
40 if ((context)->y_swap) \
41 y = (context)->h - y - 1; \
45 * Swap coordinates (axes) according to context transformation.
47 #define GP_TRANSFORM_SWAP(context, x, y) do { \
48 if ((context)->axes_swap) \
53 * Transform "user"-coordinates to "real"-coordinates according to context
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); \
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.
66 * Arguments x, y, w, h are modified.
68 #define GP_TRANSFORM_RECT(context, x, y, w, h) do { \
69 GP_TRANSFORM_SWAP(context, x, y); \
70 GP_TRANSFORM_SWAP(context, w, h); \
71 if ((context)->x_swap) { \
72 x = (context)->w - x - w; \
74 if ((context)->y_swap) { \
75 y = (context)->h - y - h; \
80 * Transform "user"-coordinates to "real"-coordinates for a blit
81 * called as GP_Blit(c1, x1, y1, w, h, c2, x2, y2).
82 * All x1, y1, x2, y2, w, h are adjusted.
84 #define GP_TRANSFORM_BLIT(c1, x1, y1, w, h, c2, x2, y2) do { \
85 GP_TRANSFORM_RECT(c1, x1, y1, w, h); \
87 GP_TRANSFORM_SWAP(c2, w2, h2); \
88 GP_TRANSFORM_RECT(c2, x2, y2, w2, h2); \
92 * Inverse transformation to GP_TRANSFORM_POINT.
93 * Use for translating mouse pointer coordinates to coordinates on context.
95 #define GP_RETRANSFORM_POINT(context, x, y) do { \
96 GP_TRANSFORM_X(context, x); \
97 GP_TRANSFORM_Y(context, y); \
98 GP_TRANSFORM_SWAP(context, x, y); \
101 #endif /* GP_TRANSFORM_H */