]> Pileus Git - grits/blob - src/objects/grits-tile.h
f2b706f8bb927e6d14acac79eb2eed27a99f0951
[grits] / src / objects / grits-tile.h
1 /*
2  * Copyright (C) 2009-2010 Andy Spencer <andy753421@gmail.com>
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program 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
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 #ifndef __GRITS_TILE_H__
19 #define __GRITS_TILE_H__
20
21 #include <glib.h>
22 #include <glib-object.h>
23 #include "grits-object.h"
24
25 #define GRITS_TYPE_TILE            (grits_tile_get_type())
26 #define GRITS_TILE(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj),   GRITS_TYPE_TILE, GritsTile))
27 #define GRITS_IS_TILE(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj),   GRITS_TYPE_TILE))
28 #define GRITS_TILE_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST   ((klass), GRITS_TYPE_TILE, GritsTileClass))
29 #define GRITS_IS_TILE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE   ((klass), GRITS_TYPE_TILE))
30 #define GRITS_TILE_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),   GRITS_TYPE_TILE, GritsTileClass))
31
32 typedef struct _GritsTile      GritsTile;
33 typedef struct _GritsTileClass GritsTileClass;
34
35 struct _GritsTile {
36         GritsObject  parent_instance;
37
38         /* Pointer to the tile data */
39         gpointer data;
40
41         /* Drawing order */
42         gint zindex;
43
44         /* North,South,East,West limits */
45         GritsBounds edge;
46
47         /* Texture mapping coordinates */
48         GritsBounds coords;
49
50         /* Pointers to parent/child nodes */
51         GritsTile *parent;
52         GritsTile *children[2][2];
53
54         /* Last access time (for garbage collection) */
55         time_t atime;
56
57         /* Projection used by tile data */
58         GritsProj proj;
59 };
60
61 struct _GritsTileClass {
62         GritsObjectClass parent_class;
63 };
64
65 /**
66  * GritsTileLoadFunc:
67  * @tile:      the tile to load
68  * @user_data: data paseed to the function
69  *
70  * Used to load the image data associated with a tile. For GritsOpenGL, this
71  * function should store the OpenGL texture number in the tiles data field.
72  */
73 typedef void (*GritsTileLoadFunc)(GritsTile *tile, gpointer user_data);
74
75 /**
76  * GritsTileFreeFunc:
77  * @tile:      the tile to free
78  * @user_data: data paseed to the function
79  *
80  * Used to free the image data associated with a tile
81  */
82 typedef void (*GritsTileFreeFunc)(GritsTile *tile, gpointer user_data);
83
84 /* Forech functions */
85 /**
86  * grits_tile_foreach:
87  * @parent: the #GritsTile to iterate over
88  * @child:  a pointer to a #GritsTile to store the current subtile 
89  *
90  * Iterate over each imediate subtile of @parent. 
91  */
92 #define grits_tile_foreach(parent, child) \
93         for (int _x = 0; _x < G_N_ELEMENTS(parent->children); _x++) \
94         for (int _y = 0; child = parent->children[_x][_y], \
95                 _y < G_N_ELEMENTS(parent->children[_x]); _y++)
96
97 /**
98  * grits_tile_foreach_index:
99  * @parent: the #GritsTile to iterate over
100  * @x:      integer to store the x index of the current subtile
101  * @y:      integer to store the y index of the current subtile
102  *
103  * Iterate over each imediate subtile of @parent. 
104  */
105 #define grits_tile_foreach_index(parent, x, y) \
106         for (x = 0; x < G_N_ELEMENTS(parent->children); x++) \
107         for (y = 0; y < G_N_ELEMENTS(parent->children[x]); y++)
108
109 /* Path to string table, keep in sync with tile->children */
110 extern gchar *grits_tile_path_table[2][2];
111
112 GType grits_tile_get_type(void);
113
114 /* Allocate a new Tile */
115 GritsTile *grits_tile_new(GritsTile *parent,
116         gdouble n, gdouble s, gdouble e, gdouble w);
117
118 /* Return a string representation of the tile's path */
119 gchar *grits_tile_get_path(GritsTile *child);
120
121 /* Update a root tile */
122 /* Based on eye distance */
123 void grits_tile_update(GritsTile *root, GritsPoint *eye,
124                 gdouble res, gint width, gint height,
125                 GritsTileLoadFunc load_func, gpointer user_data);
126
127 /* Find the leaf tile containing lat-lon */
128 GritsTile *grits_tile_find(GritsTile *root, gdouble lat, gdouble lon);
129
130 /* Delete nodes that haven't been accessed since atime */
131 GritsTile *grits_tile_gc(GritsTile *root, time_t atime,
132                 GritsTileFreeFunc free_func, gpointer user_data);
133
134 /* Free a tile and all it's children */
135 void grits_tile_free(GritsTile *root,
136                 GritsTileFreeFunc free_func, gpointer user_data);
137
138 #endif