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

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

start of the map class implementation and renederer class enhancements

File size: 7.8 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.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  //cfgRules *ruleset;
63  //osmFile *osm;
64  //stringChunk = g_string_chunk_new (265);
65  //stringTree = g_tree_new (m_tree_strcmp);
66
67  //ruleset = (cfgRules *) rulesetRead ("rule.xml");
68
69  //osm = (osmFile *) osmRead("zh.osm");
70
71  //g_tree_destroy(stringTree);
72
73  //renderCairo(ruleset, osm);
74
75  //osmFree(osm);
76  //rulesetFree(ruleset);
77
78  //g_string_chunk_free(stringChunk);
79}
80
81void
82memphis_renderer_draw_tile (MemphisRenderer *renderer,
83    cairo_t *cr,
84    guint x,
85    guint y)
86{
87  g_return_if_fail (MEMPHIS_IS_RENDERER (renderer));
88
89  // TODO
90}
91
92void
93memphis_renderer_set_resolution (MemphisRenderer *self, guint resolution)
94{
95  g_return_if_fail (MEMPHIS_IS_RENDERER (self));
96
97  MemphisRendererPrivate *priv = MEMPHIS_RENDERER_GET_PRIVATE (self);
98  priv->resolution = resolution;
99}
100
101guint
102memphis_renderer_get_resolution (MemphisRenderer *self)
103{
104  g_return_val_if_fail (MEMPHIS_IS_RENDERER (self), 0);
105
106  MemphisRendererPrivate *priv = MEMPHIS_RENDERER_GET_PRIVATE (self);
107  return priv->resolution;
108}
109
110void
111memphis_renderer_set_zoom_level (MemphisRenderer *self, guint zoom_level)
112{
113  g_return_if_fail (MEMPHIS_IS_RENDERER (self));
114
115  MemphisRendererPrivate *priv = MEMPHIS_RENDERER_GET_PRIVATE (self);
116  priv->zoom_level = zoom_level;
117}
118
119guint
120memphis_renderer_get_zoom_level (MemphisRenderer *self)
121{
122  g_return_val_if_fail (MEMPHIS_IS_RENDERER (self), 0);
123
124  MemphisRendererPrivate *priv = MEMPHIS_RENDERER_GET_PRIVATE (self);
125  return priv->zoom_level;
126}
127
128void
129memphis_renderer_set_map (MemphisRenderer *self, MemphisMap *map)
130{
131  g_return_if_fail (MEMPHIS_IS_RENDERER (self) && MEMPHIS_IS_MAP (map));
132
133  MemphisRendererPrivate *priv = MEMPHIS_RENDERER_GET_PRIVATE (self);
134  priv->map = g_object_ref (map);
135}
136
137MemphisMap*
138memphis_renderer_get_map (MemphisRenderer *self)
139{
140  g_return_val_if_fail (MEMPHIS_IS_RENDERER (self), 0);
141
142  MemphisRendererPrivate *priv = MEMPHIS_RENDERER_GET_PRIVATE (self);
143  return priv->map;
144}
145
146void
147memphis_renderer_set_rules_set (MemphisRenderer *self,
148    MemphisRuleSet *rules)
149{
150  g_return_if_fail (MEMPHIS_IS_RENDERER (self) &&
151      MEMPHIS_IS_RULESET (rules));
152
153  MemphisRendererPrivate *priv = MEMPHIS_RENDERER_GET_PRIVATE (self);
154  priv->rules = g_object_ref (rules);
155}
156
157MemphisRuleSet*
158memphis_renderer_get_rule_set (MemphisRenderer *self)
159{
160  g_return_val_if_fail (MEMPHIS_IS_RENDERER (self), 0);
161
162  MemphisRendererPrivate *priv = MEMPHIS_RENDERER_GET_PRIVATE (self);
163  return priv->rules;
164}
165
166
167static void
168memphis_renderer_dispose (GObject *object)
169{
170  MemphisRenderer *self = MEMPHIS_RENDERER (object);
171  MemphisRendererPrivate *priv = MEMPHIS_RENDERER_GET_PRIVATE (self);
172
173  g_object_unref (G_OBJECT (priv->map));
174  g_object_unref (G_OBJECT (priv->rules));
175
176  G_OBJECT_CLASS (memphis_renderer_parent_class)->dispose (object);
177}
178
179/*
180static void
181memphis_renderer_finalize (GObject *object)
182{
183  G_OBJECT_CLASS (memphis_renderer_parent_class)->finalize (object);
184}
185*/
186
187static void
188memphis_renderer_get_property (GObject *object,
189    guint property_id,
190    GValue *value,
191    GParamSpec *pspec)
192{
193  MemphisRenderer *self = MEMPHIS_RENDERER (object);
194  MemphisRendererPrivate *priv = MEMPHIS_RENDERER_GET_PRIVATE (self);
195  switch (property_id)
196    {
197      case PROP_RESOLUTION:
198        g_value_set_uint (value, priv->resolution);
199        break;
200      case PROP_ZOOM_LEVEL:
201        g_value_set_uint (value, priv->zoom_level);
202        break;
203      case PROP_MAP:
204        g_value_set_object (value, priv->map);
205        break;
206      case PROP_RULE_SET:
207        g_value_set_object (value, priv->rules);
208        break;
209      default:
210        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
211    }
212}
213
214static void
215memphis_renderer_set_property (GObject *object,
216    guint property_id,
217    const GValue *value,
218    GParamSpec *pspec)
219{
220  MemphisRenderer *self = MEMPHIS_RENDERER (object);
221  switch (property_id)
222    {
223      case PROP_RESOLUTION:
224        memphis_renderer_set_resolution (self, g_value_get_uint (value));
225        break;
226      case PROP_ZOOM_LEVEL:
227        memphis_renderer_set_zoom_level (self, g_value_get_uint (value));
228        break;
229      case PROP_MAP:
230        memphis_renderer_set_map (self, g_value_get_object (value));
231        break;
232      case PROP_RULE_SET:
233        memphis_renderer_set_rules_set (self, g_value_get_object (value));
234        break;
235      default:
236        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
237    }
238}
239
240static void
241memphis_renderer_class_init (MemphisRendererClass *klass)
242{
243  GObjectClass *object_class = G_OBJECT_CLASS (klass);
244
245  g_type_class_add_private (klass, sizeof (MemphisRendererPrivate));
246
247  object_class->get_property = memphis_renderer_get_property;
248  object_class->set_property = memphis_renderer_set_property;
249  object_class->dispose = memphis_renderer_dispose;
250  //object_class->finalize = memphis_renderer_finalize;
251
252  /**
253  * MemphisRenderer:resolution:
254  *
255  * The tile resolution in pixel.
256  *
257  * Since: 0.1
258  */
259  g_object_class_install_property (object_class,
260      PROP_RESOLUTION,
261      g_param_spec_uint ("resolution",
262        "Tile resolution",
263        "The tile resolution in pixel",
264        8,
265        2048,
266        256,
267        G_PARAM_READWRITE));
268
269  /**
270  * MemphisRenderer:zoom-level:
271  *
272  * The zoom level.
273  *
274  * Since: 0.1
275  */
276  g_object_class_install_property (object_class,
277      PROP_ZOOM_LEVEL,
278      g_param_spec_uint ("zoom-level",
279        "Map zoom level",
280        "The zoom level",
281        0,
282        17,
283        12,
284        G_PARAM_READWRITE));
285
286  /**
287  * MemphisRenderer:map:
288  *
289  * A MemphisMap.
290  *
291  * Since: 0.1
292  */
293  g_object_class_install_property (object_class,
294      PROP_MAP,
295      g_param_spec_object ("map",
296        "A MemphisMap",
297        "OSM map data",
298        MEMPHIS_TYPE_MAP,
299        G_PARAM_READWRITE));
300
301  /**
302  * MemphisRenderer:rule-set:
303  *
304  * A MemphisRuleSet.
305  *
306  * Since: 0.1
307  */
308  g_object_class_install_property (object_class,
309      PROP_ZOOM_LEVEL,
310      g_param_spec_object ("rule-set",
311        "A MemphisRuleSet",
312        "Memphis rendering rules",
313        MEMPHIS_TYPE_RULESET,
314        G_PARAM_READWRITE));
315
316}
317
318static void
319memphis_renderer_init (MemphisRenderer *self)
320{
321  MemphisRendererPrivate *priv = MEMPHIS_RENDERER_GET_PRIVATE (self);
322  priv->resolution = 256;
323  priv->zoom_level = 12;
324
325  /* initialize all public and private members to reasonable default values. */
326
327}
328
Note: See TracBrowser for help on using the repository browser.