2 * Copyright (C) 2009-2010 Andy Spencer <andy753421@gmail.com>
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.
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.
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/>.
18 #ifndef __GRITS_TILE_H__
19 #define __GRITS_TILE_H__
22 #include <glib-object.h>
23 #include "grits-object.h"
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))
32 typedef struct _GritsTile GritsTile;
33 typedef struct _GritsTileClass GritsTileClass;
36 GritsObject parent_instance;
38 /* Pointer to the tile data */
45 /* North,South,East,West limits */
48 /* Texture mapping coordinates */
51 /* Pointers to parent/child nodes */
53 GritsTile *children[2][2];
55 /* Last access time (for garbage collection) */
58 /* Projection used by tile data */
62 struct _GritsTileClass {
63 GritsObjectClass parent_class;
68 * @tile: the tile to load
69 * @user_data: data paseed to the function
71 * Used to load the image data associated with a tile. For GritsOpenGL, this
72 * function should store the OpenGL texture number in the tiles data field.
74 typedef void (*GritsTileLoadFunc)(GritsTile *tile, gpointer user_data);
78 * @tile: the tile to free
79 * @user_data: data paseed to the function
81 * Used to free the image data associated with a tile
83 typedef void (*GritsTileFreeFunc)(GritsTile *tile, gpointer user_data);
85 /* Forech functions */
88 * @parent: the #GritsTile to iterate over
89 * @child: a pointer to a #GritsTile to store the current subtile
91 * Iterate over each imediate subtile of @parent.
93 #define grits_tile_foreach(parent, child) \
94 for (int _x = 0; _x < G_N_ELEMENTS(parent->children); _x++) \
95 for (int _y = 0; child = parent->children[_x][_y], \
96 _y < G_N_ELEMENTS(parent->children[_x]); _y++)
99 * grits_tile_foreach_index:
100 * @parent: the #GritsTile to iterate over
101 * @x: integer to store the x index of the current subtile
102 * @y: integer to store the y index of the current subtile
104 * Iterate over each imediate subtile of @parent.
106 #define grits_tile_foreach_index(parent, x, y) \
107 for (x = 0; x < G_N_ELEMENTS(parent->children); x++) \
108 for (y = 0; y < G_N_ELEMENTS(parent->children[x]); y++)
110 /* Path to string table, keep in sync with tile->children */
111 extern gchar *grits_tile_path_table[2][2];
113 GType grits_tile_get_type(void);
115 /* Allocate a new Tile */
116 GritsTile *grits_tile_new(GritsTile *parent,
117 gdouble n, gdouble s, gdouble e, gdouble w);
119 /* Return a string representation of the tile's path */
120 gchar *grits_tile_get_path(GritsTile *child);
122 /* Update a root tile */
123 /* Based on eye distance */
124 void grits_tile_update(GritsTile *root, GritsPoint *eye,
125 gdouble res, gint width, gint height,
126 GritsTileLoadFunc load_func, gpointer user_data);
128 /* Find the leaf tile containing lat-lon */
129 GritsTile *grits_tile_find(GritsTile *root, gdouble lat, gdouble lon);
131 /* Delete nodes that haven't been accessed since atime */
132 GritsTile *grits_tile_gc(GritsTile *root, time_t atime,
133 GritsTileFreeFunc free_func, gpointer user_data);
135 /* Free a tile and all it's children */
136 void grits_tile_free(GritsTile *root,
137 GritsTileFreeFunc free_func, gpointer user_data);