]> Pileus Git - grits/blob - src/objects/grits-tile.h
39cdeea3dbfad2419b93dc63ebde078741fc824e
[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 __GIS_TILE_H__
19 #define __GIS_TILE_H__
20
21 #include <glib.h>
22 #include <glib-object.h>
23 #include "gis-object.h"
24
25 #define GIS_TYPE_TILE            (gis_tile_get_type())
26 #define GIS_TILE(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj),   GIS_TYPE_TILE, GisTile))
27 #define GIS_IS_TILE(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj),   GIS_TYPE_TILE))
28 #define GIS_TILE_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST   ((klass), GIS_TYPE_TILE, GisTileClass))
29 #define GIS_IS_TILE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE   ((klass), GIS_TYPE_TILE))
30 #define GIS_TILE_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),   GIS_TYPE_TILE, GisTileClass))
31
32 typedef struct _GisTile      GisTile;
33 typedef struct _GisTileClass GisTileClass;
34
35 struct _GisTile {
36         GisObject  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         GisBounds edge;
46
47         /* Texture mapping coordinates */
48         GisBounds coords;
49
50         /* Pointers to parent/child nodes */
51         GisTile *parent;
52         GisTile *children[2][2];
53
54         /* Last access time (for garbage collection) */
55         time_t atime;
56 };
57
58 struct _GisTileClass {
59         GisObjectClass parent_class;
60 };
61
62 /**
63  * GisTileLoadFunc:
64  * @tile:      the tile to load
65  * @user_data: data paseed to the function
66  *
67  * Used to load the image data associated with a tile. For GisOpenGL, this
68  * function should store the OpenGL texture number in the tiles data field.
69  */
70 typedef void (*GisTileLoadFunc)(GisTile *tile, gpointer user_data);
71
72 /**
73  * GisTileFreeFunc:
74  * @tile:      the tile to free
75  * @user_data: data paseed to the function
76  *
77  * Used to free the image data associated with a tile
78  */
79 typedef void (*GisTileFreeFunc)(GisTile *tile, gpointer user_data);
80
81 /* Forech functions */
82 /**
83  * gis_tile_foreach:
84  * @parent: the #GisTile to iterate over
85  * @child:  a pointer to a #GisTile to store the current subtile 
86  *
87  * Iterate over each imediate subtile of @parent. 
88  */
89 #define gis_tile_foreach(parent, child) \
90         for (int _x = 0; _x < G_N_ELEMENTS(parent->children); _x++) \
91         for (int _y = 0; child = parent->children[_x][_y], \
92                 _y < G_N_ELEMENTS(parent->children[_x]); _y++)
93
94 /**
95  * gis_tile_foreach_index:
96  * @parent: the #GisTile to iterate over
97  * @x:      integer to store the x index of the current subtile
98  * @y:      integer to store the y index of the current subtile
99  *
100  * Iterate over each imediate subtile of @parent. 
101  */
102 #define gis_tile_foreach_index(parent, x, y) \
103         for (x = 0; x < G_N_ELEMENTS(parent->children); x++) \
104         for (y = 0; y < G_N_ELEMENTS(parent->children[x]); y++)
105
106 /* Path to string table, keep in sync with tile->children */
107 extern gchar *gis_tile_path_table[2][2];
108
109 GType gis_tile_get_type(void);
110
111 /* Allocate a new Tile */
112 GisTile *gis_tile_new(GisTile *parent,
113         gdouble n, gdouble s, gdouble e, gdouble w);
114
115 /* Return a string representation of the tile's path */
116 gchar *gis_tile_get_path(GisTile *child);
117
118 /* Update a root tile */
119 /* Based on eye distance */
120 void gis_tile_update(GisTile *root, GisPoint *eye,
121                 gdouble res, gint width, gint height,
122                 GisTileLoadFunc load_func, gpointer user_data);
123
124 /* Find the leaf tile containing lat-lon */
125 GisTile *gis_tile_find(GisTile *root, gdouble lat, gdouble lon);
126
127 /* Delete nodes that haven't been accessed since atime */
128 GisTile *gis_tile_gc(GisTile *root, time_t atime,
129                 GisTileFreeFunc free_func, gpointer user_data);
130
131 /* Free a tile and all it's children */
132 void gis_tile_free(GisTile *root,
133                 GisTileFreeFunc free_func, gpointer user_data);
134
135 #endif