]> Pileus Git - grits/blob - src/gis-viewer.h
Move OpenGL code from GisOpenGL to objects
[grits] / src / gis-viewer.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 /**
19  * Hack alert: gis-opengl.h needs to be included before gis-viewer
20  *   - GisViewer depends on GisObject for add/remove functions
21  *   - GisObject depends on GisOpenGL for load/unload functions
22  *   - GisOpenGL depends on GisViewer for inheritance
23  *
24  * The problem here is that GisOpenGL needs the GisViewer definition
25  * but GisViewer only needs the typedefs (through GisObject),
26  * so GisViewer needs to be included after the GisOpenGL typedefs but
27  * before the GisOpenGL definition. This is handled internally by
28  * gis-opengl.h
29  *
30  * This should probably be fixed, but making a GisGLObject interface
31  * seems like too much work. Merging GisViewer and GisOpenGL would also work,
32  * but I like the separate that that's provided by having two.
33  */
34 #include "gis-opengl.h"
35
36 #ifndef __GIS_VIEWER_H__
37 #define __GIS_VIEWER_H__
38
39 #include <gtk/gtk.h>
40 #include <glib-object.h>
41
42 /* Rendering levels */
43 /**
44  * GIS_LEVEL_BACKGROUND: 
45  *
46  * The level used to draw background objects (stars, atmosphere, etc).
47  */
48 #define GIS_LEVEL_BACKGROUND -100
49
50 /**
51  * GIS_LEVEL_WORLD: 
52  *
53  * The level used to draw world objects. This is for both surface data as well
54  * as things in the air or underground. Most objects should use
55  * %GIS_LEVEL_WORLD;
56  */
57 #define GIS_LEVEL_WORLD         0
58
59 /**
60  * GIS_LEVEL_OVERLAY: 
61  *
62  * The level used to draw screen overlays. These will be drawn in front of most
63  * of ther objects. Text and markers should use %GIS_LEVEL_OVERLAY.
64  */
65 #define GIS_LEVEL_OVERLAY     100
66
67 /**
68  * GIS_LEVEL_HUD: 
69  *
70  * The level used to draw the Heads Up Display. This is for things that are not
71  * anchored at all the the world. They should be drawn in front of everything
72  * else.
73  */
74 #define GIS_LEVEL_HUD         200
75
76 /* Type macros */
77 #define GIS_TYPE_VIEWER            (gis_viewer_get_type())
78 #define GIS_VIEWER(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj),   GIS_TYPE_VIEWER, GisViewer))
79 #define GIS_IS_VIEWER(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj),   GIS_TYPE_VIEWER))
80 #define GIS_VIEWER_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST   ((klass), GIS_TYPE_VIEWER, GisViewerClass))
81 #define GIS_IS_VIEWER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE   ((klass), GIS_TYPE_VIEWER))
82 #define GIS_VIEWER_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),   GIS_TYPE_VIEWER, GisViewerClass))
83
84 typedef struct _GisViewer      GisViewer;
85 typedef struct _GisViewerClass GisViewerClass;
86
87 /**
88  * GisHeightFunc:
89  * @lat:       the target latitude
90  * @lon:       the target longitude
91  * @user_data: user data passed to the function
92  *
93  * Determine the surface elevation (ground level) at a given point.
94  *
95  * Returns: the elevation in meters above sea level
96  */
97 typedef gdouble (*GisHeightFunc)(gdouble lat, gdouble lon, gpointer user_data);
98
99 #include "gis-plugin.h"
100 #include "gis-prefs.h"
101 #include "objects/gis-object.h"
102
103 struct _GisViewer {
104         GtkDrawingArea parent_instance;
105
106         /* instance members */
107         GisPlugins *plugins;
108         GisPrefs   *prefs;
109         time_t      time;
110         gdouble     location[3];
111         gdouble     rotation[3];
112         gboolean    offline;
113
114         /* For dragging */
115         gint    drag_mode;
116         gdouble drag_x, drag_y;
117 };
118
119 struct _GisViewerClass {
120         GtkDrawingAreaClass parent_class;
121
122         /* class members */
123         void (*center_position)  (GisViewer *viewer,
124                                   gdouble lat, gdouble lon, gdouble elev);
125
126         void (*project)          (GisViewer *viewer,
127                                   gdouble lat, gdouble lon, gdouble elev,
128                                   gdouble *px, gdouble *py, gdouble *pz);
129
130         void (*clear_height_func)(GisViewer *viewer);
131         void (*set_height_func)  (GisViewer *viewer, GisBounds *bounds,
132                                   GisHeightFunc height_func, gpointer user_data,
133                                   gboolean update);
134
135         gpointer (*add)          (GisViewer *viewer, GisObject *object,
136                                   gint level, gboolean sort);
137         GisObject *(*remove)     (GisViewer *viewer, gpointer ref);
138 };
139
140 GType gis_viewer_get_type(void);
141
142 /* Methods */
143 void gis_viewer_setup(GisViewer *viewer, GisPlugins *plugins, GisPrefs *prefs);
144
145 void gis_viewer_set_time(GisViewer *viewer, time_t time);
146 time_t gis_viewer_get_time(GisViewer *viewer);
147
148 void gis_viewer_set_location(GisViewer *viewer, gdouble  lat, gdouble  lon, gdouble  elev);
149 void gis_viewer_get_location(GisViewer *viewer, gdouble *lat, gdouble *lon, gdouble *elev);
150 void gis_viewer_pan(GisViewer *viewer, gdouble forward, gdouble right, gdouble up);
151 void gis_viewer_zoom(GisViewer *viewer, gdouble  scale);
152
153 void gis_viewer_set_rotation(GisViewer *viewer, gdouble  x, gdouble  y, gdouble  z);
154 void gis_viewer_get_rotation(GisViewer *viewer, gdouble *x, gdouble *y, gdouble *z);
155 void gis_viewer_rotate      (GisViewer *viewer, gdouble  x, gdouble  y, gdouble  z);
156
157 void gis_viewer_refresh(GisViewer *viewer);
158
159 void gis_viewer_set_offline(GisViewer *viewer, gboolean offline);
160 gboolean gis_viewer_get_offline(GisViewer *viewer);
161
162 /* To be implemented by subclasses */
163 void gis_viewer_center_position(GisViewer *viewer,
164                 gdouble lat, gdouble lon, gdouble elev);
165
166 void gis_viewer_project(GisViewer *viewer,
167                 gdouble lat, gdouble lon, gdouble elev,
168                 gdouble *px, gdouble *py, gdouble *pz);
169
170 void gis_viewer_clear_height_func(GisViewer *viewer);
171 void gis_viewer_set_height_func(GisViewer *viewer, GisBounds *bounds,
172                 GisHeightFunc height_func, gpointer user_data,
173                 gboolean update);
174
175 gpointer gis_viewer_add(GisViewer *viewer, GisObject *object,
176                 gint level, gboolean sort);
177 GisObject *gis_viewer_remove(GisViewer *viewer, gpointer ref);
178
179 #endif