]> Pileus Git - grits/blob - src/grits-viewer.h
Add thread safe grits_viewer_queue_draw function
[grits] / src / grits-viewer.h
1 /*
2  * Copyright (C) 2009-2011 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 /**
19  * Hack alert: grits-opengl.h needs to be included before grits-viewer
20  *   - GritsViewer depends on GritsObject for add/remove functions
21  *   - GritsObject depends on GritsOpenGL for load/unload functions
22  *   - GritsOpenGL depends on GritsViewer for inheritance
23  *
24  * The problem here is that GritsOpenGL needs the GritsViewer definition but
25  * GritsViewer only needs the typedefs (through GritsObject), so GritsViewer
26  * needs to be included after the GritsOpenGL typedefs but before the
27  * GritsOpenGL definition. This is handled internally by grits-opengl.h
28  *
29  * This should probably be fixed, but making a GritsGLObject interface seems
30  * like too much work. Merging GritsViewer and GritsOpenGL would also work, but
31  * I like the separate that that's provided by having two.
32  */
33 #include "grits-opengl.h"
34
35 #ifndef __GRITS_VIEWER_H__
36 #define __GRITS_VIEWER_H__
37
38 #include <gtk/gtk.h>
39 #include <glib-object.h>
40
41 /* Projections */
42 typedef enum {
43         GRITS_PROJ_LATLON,
44         GRITS_PROJ_MERCATOR,
45 } GritsProj;
46
47 /* Rendering levels */
48 /**
49  * GRITS_LEVEL_BACKGROUND: 
50  *
51  * The level used to draw background objects (stars, atmosphere, etc).
52  */
53 #define GRITS_LEVEL_BACKGROUND -100
54
55 /**
56  * GRITS_LEVEL_WORLD: 
57  *
58  * The level used to draw world objects. This is for both surface data as well
59  * as things in the air or underground. Most objects should use
60  * %GRITS_LEVEL_WORLD;
61  */
62 #define GRITS_LEVEL_WORLD         0
63
64 /**
65  * GRITS_LEVEL_OVERLAY: 
66  *
67  * The level used to draw screen overlays. These will be drawn in front of most
68  * of ther objects. Text and markers should use %GRITS_LEVEL_OVERLAY.
69  */
70 #define GRITS_LEVEL_OVERLAY     100
71
72 /**
73  * GRITS_LEVEL_HUD: 
74  *
75  * The level used to draw the Heads Up Display. This is for things that are not
76  * anchored at all the the world. They should be drawn in front of everything
77  * else.
78  */
79 #define GRITS_LEVEL_HUD         200
80
81 /* Type macros */
82 #define GRITS_TYPE_VIEWER            (grits_viewer_get_type())
83 #define GRITS_VIEWER(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj),   GRITS_TYPE_VIEWER, GritsViewer))
84 #define GRITS_IS_VIEWER(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj),   GRITS_TYPE_VIEWER))
85 #define GRITS_VIEWER_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST   ((klass), GRITS_TYPE_VIEWER, GritsViewerClass))
86 #define GRITS_IS_VIEWER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE   ((klass), GRITS_TYPE_VIEWER))
87 #define GRITS_VIEWER_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),   GRITS_TYPE_VIEWER, GritsViewerClass))
88
89 typedef struct _GritsViewer      GritsViewer;
90 typedef struct _GritsViewerClass GritsViewerClass;
91
92 /**
93  * GritsHeightFunc:
94  * @lat:       the target latitude
95  * @lon:       the target longitude
96  * @user_data: user data passed to the function
97  *
98  * Determine the surface elevation (ground level) at a given point.
99  *
100  * Returns: the elevation in meters above sea level
101  */
102 typedef gdouble (*GritsHeightFunc)(gdouble lat, gdouble lon, gpointer user_data);
103
104 #include "grits-plugin.h"
105 #include "grits-prefs.h"
106 #include "objects/grits-object.h"
107
108 struct _GritsViewer {
109         GtkDrawingArea parent_instance;
110
111         /* instance members */
112         GritsPlugins *plugins;
113         GritsPrefs   *prefs;
114         time_t      time;
115         gdouble     location[3];
116         gdouble     rotation[3];
117         gboolean    offline;
118
119         /* For dragging */
120         gint    drag_mode;
121         gdouble drag_x, drag_y;
122
123         /* For queue_draw */
124         guint   draw_source;
125 };
126
127 struct _GritsViewerClass {
128         GtkDrawingAreaClass parent_class;
129
130         /* class members */
131         void (*center_position)  (GritsViewer *viewer,
132                                   gdouble lat, gdouble lon, gdouble elev);
133
134         void (*project)          (GritsViewer *viewer,
135                                   gdouble lat, gdouble lon, gdouble elev,
136                                   gdouble *px, gdouble *py, gdouble *pz);
137         void (*unproject)        (GritsViewer *viewer,
138                                   gdouble px, gdouble py,gdouble pz,
139                                   gdouble *lat, gdouble *lon, gdouble *elev);
140
141         void (*clear_height_func)(GritsViewer *viewer);
142         void (*set_height_func)  (GritsViewer *viewer, GritsBounds *bounds,
143                                   GritsHeightFunc height_func, gpointer user_data,
144                                   gboolean update);
145
146         void (*add)              (GritsViewer *viewer, GritsObject *object,
147                                   gint level, gboolean sort);
148         void (*remove)           (GritsViewer *viewer, GritsObject *object);
149 };
150
151 GType grits_viewer_get_type(void);
152
153 /* Methods */
154 void grits_viewer_setup(GritsViewer *viewer, GritsPlugins *plugins, GritsPrefs *prefs);
155
156 void grits_viewer_set_time(GritsViewer *viewer, time_t time);
157 time_t grits_viewer_get_time(GritsViewer *viewer);
158
159 void grits_viewer_set_location(GritsViewer *viewer, gdouble  lat, gdouble  lon, gdouble  elev);
160 void grits_viewer_get_location(GritsViewer *viewer, gdouble *lat, gdouble *lon, gdouble *elev);
161 void grits_viewer_pan(GritsViewer *viewer, gdouble forward, gdouble right, gdouble up);
162 void grits_viewer_zoom(GritsViewer *viewer, gdouble  scale);
163
164 void grits_viewer_set_rotation(GritsViewer *viewer, gdouble  x, gdouble  y, gdouble  z);
165 void grits_viewer_get_rotation(GritsViewer *viewer, gdouble *x, gdouble *y, gdouble *z);
166 void grits_viewer_rotate      (GritsViewer *viewer, gdouble  x, gdouble  y, gdouble  z);
167
168 void grits_viewer_refresh(GritsViewer *viewer);
169
170 void grits_viewer_set_offline(GritsViewer *viewer, gboolean offline);
171 gboolean grits_viewer_get_offline(GritsViewer *viewer);
172
173 /* To be implemented by subclasses */
174 void grits_viewer_center_position(GritsViewer *viewer,
175                 gdouble lat, gdouble lon, gdouble elev);
176
177 void grits_viewer_project(GritsViewer *viewer,
178                 gdouble lat, gdouble lon, gdouble elev,
179                 gdouble *px, gdouble *py, gdouble *pz);
180 void grits_viewer_unproject(GritsViewer *viewer,
181                 gdouble px, gdouble py, gdouble pz,
182                 gdouble *lat, gdouble *lon, gdouble *elev);
183
184 void grits_viewer_clear_height_func(GritsViewer *viewer);
185 void grits_viewer_set_height_func(GritsViewer *viewer, GritsBounds *bounds,
186                 GritsHeightFunc height_func, gpointer user_data,
187                 gboolean update);
188
189 void grits_viewer_add(GritsViewer *viewer, GritsObject *object,
190                 gint level, gboolean sort);
191 void grits_viewer_remove(GritsViewer *viewer, GritsObject *object);
192
193 void grits_viewer_queue_draw(GritsViewer *viewer);
194
195 #endif