diff options
Diffstat (limited to 'libraries/eina/src/include/eina_inline_tiler.x')
-rw-r--r-- | libraries/eina/src/include/eina_inline_tiler.x | 151 |
1 files changed, 151 insertions, 0 deletions
diff --git a/libraries/eina/src/include/eina_inline_tiler.x b/libraries/eina/src/include/eina_inline_tiler.x new file mode 100644 index 0000000..2a8b205 --- /dev/null +++ b/libraries/eina/src/include/eina_inline_tiler.x | |||
@@ -0,0 +1,151 @@ | |||
1 | /* EINA - EFL data type library | ||
2 | * Copyright (C) 2002-2009 Rafael Antognolli | ||
3 | * | ||
4 | * This library 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 | * This library 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 this library; | ||
16 | * if not, see <http://www.gnu.org/licenses/>. | ||
17 | */ | ||
18 | |||
19 | #ifndef EINA_TILER_INLINE_H_ | ||
20 | #define EINA_TILER_INLINE_H_ | ||
21 | |||
22 | #include "eina_safety_checks.h" | ||
23 | |||
24 | /** | ||
25 | * @cond LOCAL | ||
26 | * This struct should not be accessed directly, it is used by | ||
27 | * eina_tile_grid_slicer functions to maintain context and fill "info" | ||
28 | * member with correct values for given iteration. | ||
29 | */ | ||
30 | struct _Eina_Tile_Grid_Slicer | ||
31 | { | ||
32 | unsigned long col1, col2, row1, row2; // initial and final col,row | ||
33 | int tile_w, tile_h; // tile width, height | ||
34 | int x_rel, y_rel; // starting x,y coordinates of the first col,row | ||
35 | int w1_rel, h1_rel; // width,height of the first col,row | ||
36 | int w2_rel, h2_rel; // width,height of the last col,row | ||
37 | struct Eina_Tile_Grid_Info info; // info about the current tile | ||
38 | Eina_Bool first; | ||
39 | }; | ||
40 | |||
41 | /** | ||
42 | * @endcond | ||
43 | */ | ||
44 | |||
45 | static inline Eina_Bool | ||
46 | eina_tile_grid_slicer_next(Eina_Tile_Grid_Slicer *slc, const Eina_Tile_Grid_Info **rect) | ||
47 | { | ||
48 | EINA_SAFETY_ON_NULL_RETURN_VAL(slc, 0); | ||
49 | |||
50 | if (slc->first) | ||
51 | { | ||
52 | slc->first = 0; | ||
53 | *rect = &slc->info; | ||
54 | return EINA_TRUE; | ||
55 | } | ||
56 | |||
57 | slc->info.col++; | ||
58 | |||
59 | if (slc->info.col > slc->col2) | ||
60 | { | ||
61 | slc->info.row++; | ||
62 | if (slc->info.row > slc->row2) | ||
63 | return EINA_FALSE; | ||
64 | else if (slc->info.row < slc->row2) | ||
65 | slc->info.rect.h = slc->tile_h; | ||
66 | else | ||
67 | slc->info.rect.h = slc->h2_rel; | ||
68 | slc->info.rect.y = 0; | ||
69 | slc->info.col = slc->col1; | ||
70 | slc->info.rect.x = slc->x_rel; | ||
71 | slc->info.rect.w = slc->w1_rel; | ||
72 | } | ||
73 | else | ||
74 | { | ||
75 | slc->info.rect.x = 0; | ||
76 | if (slc->info.col < slc->col2) | ||
77 | slc->info.rect.w = slc->tile_w; | ||
78 | else | ||
79 | slc->info.rect.w = slc->w2_rel; | ||
80 | } | ||
81 | |||
82 | if (slc->info.rect.w == slc->tile_w && slc->info.rect.h == slc->tile_h) | ||
83 | slc->info.full = EINA_TRUE; | ||
84 | else | ||
85 | slc->info.full = EINA_FALSE; | ||
86 | |||
87 | *rect = &slc->info; | ||
88 | |||
89 | return EINA_TRUE; | ||
90 | } | ||
91 | |||
92 | static inline Eina_Bool | ||
93 | eina_tile_grid_slicer_setup(Eina_Tile_Grid_Slicer *slc, int x, int y, int w, int h, int tile_w, int tile_h) | ||
94 | { | ||
95 | int tx1, tx2, ty1, ty2; | ||
96 | |||
97 | EINA_SAFETY_ON_NULL_RETURN_VAL(slc, 0); | ||
98 | |||
99 | tx1 = x; | ||
100 | ty1 = y; | ||
101 | tx2 = x + w - 1; | ||
102 | ty2 = y + h - 1; | ||
103 | |||
104 | if (x < 0 || y < 0 || w <= 0 || h <= 0 || tile_w <= 0 || tile_h <= 0) | ||
105 | { | ||
106 | slc->first = 0; | ||
107 | slc->col1 = slc->row1 = 0; | ||
108 | slc->col2 = slc->row2 = 0; | ||
109 | slc->info.col = slc->col1; | ||
110 | slc->info.row = slc->row1; | ||
111 | return EINA_TRUE; | ||
112 | } | ||
113 | |||
114 | slc->col1 = tx1 / tile_w; | ||
115 | slc->row1 = ty1 / tile_h; | ||
116 | slc->col2 = (tx2 - 0) / tile_w; | ||
117 | slc->row2 = (ty2 - 0) / tile_h; | ||
118 | slc->x_rel = tx1 % tile_w; | ||
119 | slc->y_rel = ty1 % tile_h; | ||
120 | slc->w1_rel = tile_w - slc->x_rel; | ||
121 | slc->h1_rel = tile_h - slc->y_rel; | ||
122 | slc->w2_rel = tx2 % tile_w + 1; | ||
123 | slc->h2_rel = ty2 % tile_h + 1; | ||
124 | |||
125 | slc->tile_w = tile_w; | ||
126 | slc->tile_h = tile_h; | ||
127 | |||
128 | slc->first = 1; | ||
129 | slc->info.col = slc->col1; | ||
130 | slc->info.row = slc->row1; | ||
131 | slc->info.rect.x = slc->x_rel; | ||
132 | slc->info.rect.y = slc->y_rel; | ||
133 | |||
134 | if (slc->info.col == slc->col2) | ||
135 | slc->w1_rel = slc->w2_rel - slc->x_rel; | ||
136 | |||
137 | if (slc->info.row == slc->row2) | ||
138 | slc->h1_rel = slc->h2_rel - slc->y_rel; | ||
139 | |||
140 | slc->info.rect.w = slc->w1_rel; | ||
141 | slc->info.rect.h = slc->h1_rel; | ||
142 | |||
143 | if (slc->info.rect.w == slc->tile_w && slc->info.rect.h == slc->tile_h) | ||
144 | slc->info.full = EINA_TRUE; | ||
145 | else | ||
146 | slc->info.full = EINA_FALSE; | ||
147 | |||
148 | return EINA_TRUE; | ||
149 | } | ||
150 | |||
151 | #endif | ||