Contents of /trunk/src/canvas.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 103 - (show annotations)
Tue Mar 3 12:12:53 2009 UTC (15 years, 3 months ago) by harbaum
File MIME type: text/plain
File size: 4700 byte(s)
Canvas code cleanups
1 /*
2 * Copyright (C) 2008 Till Harbaum <till@harbaum.org>.
3 *
4 * This file is part of OSM2Go.
5 *
6 * OSM2Go is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * OSM2Go is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with OSM2Go. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #ifndef CANVAS_H
21 #define CANVAS_H
22
23 typedef enum {
24 CANVAS_GROUP_BG=0, // background layer (wms overlay)
25 CANVAS_GROUP_POLYGONS, // polygons (forrests, buildings, lakes) */
26 CANVAS_GROUP_TRACK, // (GPS) track
27 CANVAS_GROUP_GPS, // current GPS position
28 CANVAS_GROUP_WAYS_HL, // highlighting of ways
29 CANVAS_GROUP_WAYS_OL, // outlines for ways (e.g. for highways)
30 CANVAS_GROUP_WAYS, // ways
31 CANVAS_GROUP_NODES_HL, // highlighting for nodes
32 CANVAS_GROUP_NODES, // nodes
33 CANVAS_GROUP_FRISKET, // the (white) frisket limiting the view
34 CANVAS_GROUP_DRAW, // "cursor" functionality
35 CANVAS_GROUPS
36 } canvas_group_t;
37
38 #if defined(USE_GOOCANVAS)
39
40 #include <goocanvas.h>
41
42 typedef GooCanvasItem canvas_item_t;
43 typedef GooCanvasPoints canvas_points_t;
44
45 typedef struct {
46 GtkWidget *widget;
47 GooCanvasItem *group[CANVAS_GROUPS];
48 } canvas_t;
49
50 typedef gulong canvas_color_t;
51
52 #define CANVAS_COLOR(r,g,b,a) ((((guint) (r) & 0xff) << 24) \
53 | (((guint) (g) & 0xff) << 16) \
54 | (((guint) (b) & 0xff) << 8) \
55 | ((guint) (a) & 0xff))
56
57
58
59 #else
60 #error "No canvas type defined!"
61 #endif
62
63 typedef enum { CANVAS_UNIT_METER = 0, CANVAS_UNIT_PIXEL } canvas_unit_t;
64
65 /***** creating/destroying the canvas ******/
66 canvas_t *canvas_new(canvas_color_t color);
67 GtkWidget *canvas_get_widget(canvas_t *canvas);
68
69 /****** manipulating the canvas ******/
70 void canvas_set_antialias(canvas_t *canvas, gboolean antialias);
71 void canvas_erase(canvas_t *canvas, gint group_mask);
72 void canvas_window2world(canvas_t *canvas, gint x, gint y, gint *wx, gint *wy);
73 canvas_item_t *canvas_get_item_at(canvas_t *canvas, gint x, gint y);
74 void canvas_set_zoom(canvas_t *canvas, gdouble zoom);
75 gdouble canvas_get_zoom(canvas_t *canvas);
76 gdouble canvas_get_viewport_width(canvas_t *canvas, canvas_unit_t unit);
77 gdouble canvas_get_viewport_height(canvas_t *canvas, canvas_unit_t unit);
78 void canvas_scroll_to(canvas_t *canvas, canvas_unit_t unit, gint sx, gint sy);
79 void canvas_scroll_get(canvas_t *canvas, canvas_unit_t unit, gint *sx, gint *sy);
80 void canvas_set_bounds(canvas_t *canvas, gint minx, gint miny,
81 gint maxx, gint maxy);
82
83
84 /***** creating/destroying items ******/
85 canvas_item_t *canvas_circle_new(canvas_t *canvas, canvas_group_t group,
86 gint x, gint y, gint radius, gint border,
87 canvas_color_t fill_col, canvas_color_t border_col);
88 canvas_item_t *canvas_polyline_new(canvas_t *canvas, canvas_group_t group,
89 canvas_points_t *points, gint width, canvas_color_t color);
90 canvas_item_t *canvas_polygon_new(canvas_t *canvas, canvas_group_t group,
91 canvas_points_t *points, gint width, canvas_color_t color,
92 canvas_color_t fill);
93 canvas_item_t *canvas_image_new(canvas_t *canvas, canvas_group_t group,
94 GdkPixbuf *pix, gint x, gint y,
95 float hscale, float vscale);
96 canvas_points_t *canvas_points_new(gint points);
97 void canvas_point_set_pos(canvas_points_t *points, gint index, lpos_t *lpos);
98 void canvas_points_free(canvas_points_t *points);
99 void canvas_item_destroy(canvas_item_t *item);
100
101 /****** manipulating items ******/
102 void canvas_item_set_pos(canvas_item_t *item, lpos_t *lpos, gint radius);
103 void canvas_item_set_points(canvas_item_t *item, canvas_points_t *points);
104 void canvas_item_set_zoom_max(canvas_item_t *item, float zoom_max);
105 void canvas_item_set_dashed(canvas_item_t *item, gint line_width, gint dash_length);
106 void canvas_item_to_bottom(canvas_item_t *item);
107 void canvas_item_set_user_data(canvas_item_t *item, void *data);
108 void *canvas_item_get_user_data(canvas_item_t *item);
109 void canvas_item_destroy_connect(canvas_item_t *item,
110 GCallback c_handler, gpointer data);
111 void canvas_image_move(canvas_item_t *item, gint x, gint y,
112 float hscale, float vscale);
113 gint canvas_item_get_segment(canvas_item_t *item, gint x, gint y);
114 void canvas_item_get_segment_pos(canvas_item_t *item, gint seg,
115 gint *x0, gint *y0, gint *x1, gint *y1);
116
117 #endif // CANVAS_H