source: branches/client-library-split/memphis-renderer.c @ 87

Last change on this file since 87 was 87, checked in by simon, 5 years ago

remove the global debug variable, fix crash in main.c

File size: 7.5 KB
Line 
1/*
2 * Memphis - Cairo Rederer for OSM in C
3 * Copyright (C) 2009  Simon Wenner <simon@wenner.ch>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18 */
19
20#include "memphis-renderer.h"
21#include "mlib.h"
22
23G_DEFINE_TYPE (MemphisRenderer, memphis_renderer, G_TYPE_OBJECT);
24
25#define MEMPHIS_RENDERER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), MEMPHIS_TYPE_RENDERER, MemphisRendererPrivate))
26
27enum
28{
29  PROP_0,
30  PROP_MAP,
31  PROP_RULE_SET,
32  PROP_RESOLUTION,
33  PROP_ZOOM_LEVEL
34};
35
36struct _MemphisRendererPrivate
37{
38  MemphisMap *map;
39  MemphisRuleSet *rules;
40  guint resolution;
41  guint zoom_level;
42};
43
44MemphisRenderer*
45memphis_renderer_new ()
46{
47  return g_object_new (MEMPHIS_TYPE_RENDERER, NULL);
48}
49
50void
51memphis_renderer_free (MemphisRenderer *renderer)
52{
53  g_object_unref (G_OBJECT (renderer));
54}
55
56void
57memphis_renderer_draw (MemphisRenderer *renderer,
58    cairo_t *cr)
59{
60  g_return_if_fail (MEMPHIS_IS_RENDERER (renderer));
61
62  //renderCairo(ruleset, osm);
63
64}
65
66void
67memphis_renderer_draw_tile (MemphisRenderer *renderer,
68    cairo_t *cr,
69    guint x,
70    guint y)
71{
72  g_return_if_fail (MEMPHIS_IS_RENDERER (renderer));
73
74  // TODO
75}
76
77void
78memphis_renderer_set_resolution (MemphisRenderer *self, guint resolution)
79{
80  g_return_if_fail (MEMPHIS_IS_RENDERER (self));
81
82  MemphisRendererPrivate *priv = MEMPHIS_RENDERER_GET_PRIVATE (self);
83  priv->resolution = resolution;
84}
85
86guint
87memphis_renderer_get_resolution (MemphisRenderer *self)
88{
89  g_return_val_if_fail (MEMPHIS_IS_RENDERER (self), 0);
90
91  MemphisRendererPrivate *priv = MEMPHIS_RENDERER_GET_PRIVATE (self);
92  return priv->resolution;
93}
94
95void
96memphis_renderer_set_zoom_level (MemphisRenderer *self, guint zoom_level)
97{
98  g_return_if_fail (MEMPHIS_IS_RENDERER (self));
99
100  MemphisRendererPrivate *priv = MEMPHIS_RENDERER_GET_PRIVATE (self);
101  priv->zoom_level = zoom_level;
102}
103
104guint
105memphis_renderer_get_zoom_level (MemphisRenderer *self)
106{
107  g_return_val_if_fail (MEMPHIS_IS_RENDERER (self), 0);
108
109  MemphisRendererPrivate *priv = MEMPHIS_RENDERER_GET_PRIVATE (self);
110  return priv->zoom_level;
111}
112
113void
114memphis_renderer_set_map (MemphisRenderer *self, MemphisMap *map)
115{
116  g_return_if_fail (MEMPHIS_IS_RENDERER (self) && MEMPHIS_IS_MAP (map));
117
118  MemphisRendererPrivate *priv = MEMPHIS_RENDERER_GET_PRIVATE (self);
119  priv->map = g_object_ref (map);
120}
121
122MemphisMap*
123memphis_renderer_get_map (MemphisRenderer *self)
124{
125  g_return_val_if_fail (MEMPHIS_IS_RENDERER (self), 0);
126
127  MemphisRendererPrivate *priv = MEMPHIS_RENDERER_GET_PRIVATE (self);
128  return priv->map;
129}
130
131void
132memphis_renderer_set_rules_set (MemphisRenderer *self,
133    MemphisRuleSet *rules)
134{
135  g_return_if_fail (MEMPHIS_IS_RENDERER (self) &&
136      MEMPHIS_IS_RULESET (rules));
137
138  MemphisRendererPrivate *priv = MEMPHIS_RENDERER_GET_PRIVATE (self);
139  priv->rules = g_object_ref (rules);
140}
141
142MemphisRuleSet*
143memphis_renderer_get_rule_set (MemphisRenderer *self)
144{
145  g_return_val_if_fail (MEMPHIS_IS_RENDERER (self), 0);
146
147  MemphisRendererPrivate *priv = MEMPHIS_RENDERER_GET_PRIVATE (self);
148  return priv->rules;
149}
150
151
152static void
153memphis_renderer_dispose (GObject *object)
154{
155  MemphisRenderer *self = MEMPHIS_RENDERER (object);
156  MemphisRendererPrivate *priv = MEMPHIS_RENDERER_GET_PRIVATE (self);
157
158  g_object_unref (G_OBJECT (priv->map));
159  g_object_unref (G_OBJECT (priv->rules));
160
161  G_OBJECT_CLASS (memphis_renderer_parent_class)->dispose (object);
162}
163
164/*
165static void
166memphis_renderer_finalize (GObject *object)
167{
168  G_OBJECT_CLASS (memphis_renderer_parent_class)->finalize (object);
169}
170*/
171
172static void
173memphis_renderer_get_property (GObject *object,
174    guint property_id,
175    GValue *value,
176    GParamSpec *pspec)
177{
178  MemphisRenderer *self = MEMPHIS_RENDERER (object);
179  MemphisRendererPrivate *priv = MEMPHIS_RENDERER_GET_PRIVATE (self);
180  switch (property_id)
181    {
182      case PROP_RESOLUTION:
183        g_value_set_uint (value, priv->resolution);
184        break;
185      case PROP_ZOOM_LEVEL:
186        g_value_set_uint (value, priv->zoom_level);
187        break;
188      case PROP_MAP:
189        g_value_set_object (value, priv->map);
190        break;
191      case PROP_RULE_SET:
192        g_value_set_object (value, priv->rules);
193        break;
194      default:
195        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
196    }
197}
198
199static void
200memphis_renderer_set_property (GObject *object,
201    guint property_id,
202    const GValue *value,
203    GParamSpec *pspec)
204{
205  MemphisRenderer *self = MEMPHIS_RENDERER (object);
206  switch (property_id)
207    {
208      case PROP_RESOLUTION:
209        memphis_renderer_set_resolution (self, g_value_get_uint (value));
210        break;
211      case PROP_ZOOM_LEVEL:
212        memphis_renderer_set_zoom_level (self, g_value_get_uint (value));
213        break;
214      case PROP_MAP:
215        memphis_renderer_set_map (self, g_value_get_object (value));
216        break;
217      case PROP_RULE_SET:
218        memphis_renderer_set_rules_set (self, g_value_get_object (value));
219        break;
220      default:
221        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
222    }
223}
224
225static void
226memphis_renderer_class_init (MemphisRendererClass *klass)
227{
228  GObjectClass *object_class = G_OBJECT_CLASS (klass);
229
230  g_type_class_add_private (klass, sizeof (MemphisRendererPrivate));
231
232  object_class->get_property = memphis_renderer_get_property;
233  object_class->set_property = memphis_renderer_set_property;
234  object_class->dispose = memphis_renderer_dispose;
235  //object_class->finalize = memphis_renderer_finalize;
236
237  /**
238  * MemphisRenderer:resolution:
239  *
240  * The tile resolution in pixel.
241  *
242  * Since: 0.1
243  */
244  g_object_class_install_property (object_class,
245      PROP_RESOLUTION,
246      g_param_spec_uint ("resolution",
247        "Tile resolution",
248        "The tile resolution in pixel",
249        8,
250        2048,
251        256,
252        G_PARAM_READWRITE));
253
254  /**
255  * MemphisRenderer:zoom-level:
256  *
257  * The zoom level.
258  *
259  * Since: 0.1
260  */
261  g_object_class_install_property (object_class,
262      PROP_ZOOM_LEVEL,
263      g_param_spec_uint ("zoom-level",
264        "Map zoom level",
265        "The zoom level",
266        0,
267        17,
268        12,
269        G_PARAM_READWRITE));
270
271  /**
272  * MemphisRenderer:map:
273  *
274  * A MemphisMap.
275  *
276  * Since: 0.1
277  */
278  g_object_class_install_property (object_class,
279      PROP_MAP,
280      g_param_spec_object ("map",
281        "A MemphisMap",
282        "OSM map data",
283        MEMPHIS_TYPE_MAP,
284        G_PARAM_READWRITE));
285
286  /**
287  * MemphisRenderer:rule-set:
288  *
289  * A MemphisRuleSet.
290  *
291  * Since: 0.1
292  */
293  g_object_class_install_property (object_class,
294      PROP_ZOOM_LEVEL,
295      g_param_spec_object ("rule-set",
296        "A MemphisRuleSet",
297        "Memphis rendering rules",
298        MEMPHIS_TYPE_RULESET,
299        G_PARAM_READWRITE));
300
301}
302
303static void
304memphis_renderer_init (MemphisRenderer *self)
305{
306  MemphisRendererPrivate *priv = MEMPHIS_RENDERER_GET_PRIVATE (self);
307  priv->resolution = 256;
308  priv->zoom_level = 12;
309
310  /* initialize all public and private members to reasonable default values. */
311
312}
313
Note: See TracBrowser for help on using the repository browser.