1 /* EINA - EFL data type library
2 * Copyright (C) 2002-2009 Rafael Antognolli
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.
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.
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/>.
19 #ifndef EINA_TILER_INLINE_H_
20 #define EINA_TILER_INLINE_H_
22 #include "eina_safety_checks.h"
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.
30 struct _Eina_Tile_Grid_Slicer
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
45 static inline Eina_Bool
46 eina_tile_grid_slicer_next(Eina_Tile_Grid_Slicer *slc, const Eina_Tile_Grid_Info **rect)
48 EINA_SAFETY_ON_NULL_RETURN_VAL(slc, 0);
59 if (slc->info.col > slc->col2)
62 if (slc->info.row > slc->row2)
64 else if (slc->info.row < slc->row2)
65 slc->info.rect.h = slc->tile_h;
67 slc->info.rect.h = slc->h2_rel;
69 slc->info.col = slc->col1;
70 slc->info.rect.x = slc->x_rel;
71 slc->info.rect.w = slc->w1_rel;
76 if (slc->info.col < slc->col2)
77 slc->info.rect.w = slc->tile_w;
79 slc->info.rect.w = slc->w2_rel;
82 if (slc->info.rect.w == slc->tile_w && slc->info.rect.h == slc->tile_h)
83 slc->info.full = EINA_TRUE;
85 slc->info.full = EINA_FALSE;
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)
95 int tx1, tx2, ty1, ty2;
97 EINA_SAFETY_ON_NULL_RETURN_VAL(slc, 0);
104 if (x < 0 || y < 0 || w <= 0 || h <= 0 || tile_w <= 0 || tile_h <= 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;
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;
125 slc->tile_w = tile_w;
126 slc->tile_h = tile_h;
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;
134 if (slc->info.col == slc->col2)
135 slc->w1_rel = slc->w2_rel - slc->x_rel;
137 if (slc->info.row == slc->row2)
138 slc->h1_rel = slc->h2_rel - slc->y_rel;
140 slc->info.rect.w = slc->w1_rel;
141 slc->info.rect.h = slc->h1_rel;
143 if (slc->info.rect.w == slc->tile_w && slc->info.rect.h == slc->tile_h)
144 slc->info.full = EINA_TRUE;
146 slc->info.full = EINA_FALSE;