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

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

initial libmemphis class skeletons

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