]> err.no Git - mapper/commitdiff
Map widget:
authorKaj-Michael Lang <milang@tal.org>
Wed, 7 May 2008 13:12:32 +0000 (16:12 +0300)
committerKaj-Michael Lang <milang@tal.org>
Wed, 7 May 2008 13:12:32 +0000 (16:12 +0300)
- Move buffer rendering to its own function
- Add placeholder for click event and connect signals

src/gtkmap.c

index 526d330e219b5f3a506fc5418c3ececce2c85d6c..64cbf261caa8d71216e166d20b546a5e63095178 100644 (file)
@@ -235,12 +235,12 @@ static void gtk_map_size_request(GtkWidget *widget, GtkRequisition *requisition)
 static void gtk_map_size_allocate(GtkWidget *widget, GtkAllocation *allocate);
 static void gtk_map_realize(GtkWidget *widget);
 static gboolean gtk_map_expose(GtkWidget *widget, GdkEventExpose *event);
-static gboolean gtk_map_configure(GtkWidget *widget, GdkEventConfigure *event);
 
 static void gtk_map_scale_draw(GtkWidget *widget, GdkEventExpose *event);
 static void gtk_map_mark_draw(GtkWidget *widget, GdkEventExpose *event);
 static void gtk_map_speed_draw(GtkWidget *widget, GdkEventExpose *event);
 
+static void gtk_map_render_buffer(GtkWidget *widget, GdkEventExpose *event);
 static void gtk_map_render_markers(GtkWidget *widget, GdkEventExpose *event);
 static void gtk_map_render_paths(GtkWidget *widget, GdkEventExpose *event);
 
@@ -394,7 +394,7 @@ priv->show_markers=TRUE;
 priv->show_location=TRUE;
 
 priv->rotate_angle=M_PI;
-priv->rotate_view=TRUE;
+priv->rotate_view=FALSE;
 
 priv->gl=FALSE;
 priv->buffer=NULL;
@@ -608,13 +608,6 @@ if (priv->gl_config) {
 }
 #endif
 
-#if 0
-g_signal_connect(G_OBJECT(map), "button_press_event", G_CALLBACK(map_cb_button_press), NULL);
-g_signal_connect(G_OBJECT(map), "button_release_event",G_CALLBACK(map_cb_button_release), NULL);
-#endif
-
-g_signal_connect(G_OBJECT(map), "scroll_event",  G_CALLBACK(gtk_map_scroll_event_cb), NULL);
-
 priv->scale_context=gtk_widget_get_pango_context(widget);
 priv->scale_layout=pango_layout_new(priv->scale_context);
 priv->scale_font=pango_font_description_new();
@@ -666,62 +659,73 @@ pango_font_description_set_size(priv->speed_font, 48 * PANGO_SCALE);
 pango_layout_set_font_description(priv->speed_layout, priv->speed_font);
 pango_layout_set_alignment(priv->speed_layout, PANGO_ALIGN_LEFT);
 
-#if 0
-g_signal_connect(G_OBJECT(widget), "button_press_event", G_CALLBACK(gtk_map_press_cb), NULL);
-#endif
+g_signal_connect(G_OBJECT(map), "button_press_event", G_CALLBACK(gtk_map_button_press_cb), NULL);
+g_signal_connect(G_OBJECT(map), "button_release_event",G_CALLBACK(gtk_map_button_release_cb), NULL);
+g_signal_connect(G_OBJECT(map), "scroll_event",  G_CALLBACK(gtk_map_scroll_event_cb), NULL);
 
 gtk_widget_queue_resize(widget);
 }
 
-static gboolean
-gtk_map_expose(GtkWidget *widget, GdkEventExpose *event)
+static void 
+gtk_map_render_buffer(GtkWidget *widget, GdkEventExpose *event)
 {
 GtkMap *map;
 GtkMapPriv *priv;
 
-g_return_val_if_fail(GTK_IS_MAP(widget), FALSE);
-g_return_val_if_fail(event != NULL, FALSE);
+g_return_if_fail(GTK_IS_MAP(widget));
+g_return_if_fail(event != NULL);
 
 map=GTK_MAP(widget);
 priv=GTK_MAP_GET_PRIVATE(map);
 
-#ifdef WITH_CAIRO
-priv->ct=gdk_cairo_create(widget->window);
-#endif
+if (!priv->buffer)
+       return
 
 g_debug("GTKMAP: expose (%d, %d)-(%d, %d)", event->area.x, event->area.y, event->area.width, event->area.height);
 g_debug("GTKMAP: expose (%d, %d)", event->area.x + priv->offsetx, event->area.y + priv->offsety);
 g_debug("GTKMAP: expose (%d, %d)", unit2x(priv->center.unitx), unit2y(priv->center.unity));
 
-if (priv->buffer) {
-#ifdef WITH_CAIRO
-       cairo_save(priv->ct);
-       cairo_rectangle(priv->ct, event->area.x, event->area.y, event->area.width, event->area.height);
-       cairo_clip(priv->ct);
-       cairo_translate(priv->ct, -(event->area.x+priv->offsetx), -(event->area.y+priv->offsety));
-#if 0
-       if (priv->rotate_view) {
-               cairo_translate(priv->ct, (gdouble)-unit2x(priv->center.unitx), (gdouble)-unit2y(priv->center.unity) );
-               cairo_rotate(priv->ct, (gdouble)priv->rotate_angle);
-               cairo_translate(priv->ct, (gdouble)unit2x(priv->center.unitx), (gdouble)unit2y(priv->center.unity) );
-       }
-#endif
+#ifdef WITH_CAIROa
+cairo_save(priv->ct);
+cairo_rectangle(priv->ct, event->area.x, event->area.y, event->area.width, event->area.height);
+cairo_clip(priv->ct);
 #if 0
-       if (priv->animate_zoom_change) {
-               cairo_scale(priv->ct, 0.5, 0.5);
-       }
+if (priv->rotate_view) {
+       cairo_translate(priv->ct, (gdouble)-unit2x(priv->center.unitx), (gdouble)-unit2y(priv->center.unity) );
+       cairo_rotate(priv->ct, (gdouble)priv->rotate_angle);
+       cairo_translate(priv->ct, (gdouble)unit2x(priv->center.unitx), (gdouble)unit2y(priv->center.unity) );
+}
 #endif
-       gdk_cairo_set_source_pixmap(priv->ct, priv->buffer, event->area.x, event->area.y);
-       cairo_set_operator (priv->ct, CAIRO_OPERATOR_SOURCE);
-       cairo_paint(priv->ct);
-       cairo_restore(priv->ct);
+cairo_translate(priv->ct, -(event->area.x+priv->offsetx), -(event->area.y+priv->offsety));
+gdk_cairo_set_source_pixmap(priv->ct, priv->buffer, event->area.x, event->area.y);
+cairo_set_operator (priv->ct, CAIRO_OPERATOR_SOURCE);
+cairo_paint(priv->ct);
+cairo_restore(priv->ct);
 #else
-       gdk_draw_drawable(widget->window, widget->style->fg_gc[GTK_STATE_NORMAL], priv->buffer,
-               event->area.x + priv->offsetx, event->area.y + priv->offsety,
-               event->area.x, event->area.y, event->area.width, event->area.height);
+gdk_draw_drawable(widget->window, widget->style->fg_gc[GTK_STATE_NORMAL], priv->buffer,
+       event->area.x + priv->offsetx, event->area.y + priv->offsety,
+       event->area.x, event->area.y, event->area.width, event->area.height);
 #endif
 }
 
+static gboolean
+gtk_map_expose(GtkWidget *widget, GdkEventExpose *event)
+{
+GtkMap *map;
+GtkMapPriv *priv;
+
+g_return_val_if_fail(GTK_IS_MAP(widget), FALSE);
+g_return_val_if_fail(event != NULL, FALSE);
+
+map=GTK_MAP(widget);
+priv=GTK_MAP_GET_PRIVATE(map);
+
+#ifdef WITH_CAIRO
+priv->ct=gdk_cairo_create(widget->window);
+#endif
+
+gtk_map_render_buffer(widget, event);
+
 if (priv->show_paths!=0)
        gtk_map_render_paths(widget, event);
 
@@ -916,8 +920,8 @@ if (priv->show_velvec) {
        cairo_line_to(priv->ct, priv->mark_x2, priv->mark_y2);
        cairo_restore(priv->ct);
 }
-cairo_restore(priv->ct);
 cairo_stroke(priv->ct);
+cairo_restore(priv->ct);
 #else
 gdk_draw_arc(widget->window, priv->gc_mark, FALSE,
        priv->mark_x1 - priv->draw_width,
@@ -992,6 +996,7 @@ else
 g_debug("SCALE: %s", buffer);
 
 #ifdef WITH_CAIRO
+cairo_save(priv->ct);
 cairo_rectangle(priv->ct, priv->scale_rect.x, priv->scale_rect.y, priv->scale_rect.width, priv->scale_rect.height);
 cairo_set_source_rgba(priv->ct, 1, 1, 1, 0.65);
 cairo_fill_preserve(priv->ct);
@@ -1022,6 +1027,7 @@ cairo_move_to(priv->ct, priv->scale_rect.x + priv->scale_rect.width - SCALE_PADD
 cairo_line_to(priv->ct, priv->scale_rect.x + (priv->scale_rect.width + width) / 2 + SCALE_PADDING, priv->scale_rect.y + priv->scale_rect.height / 2);
 
 cairo_stroke(priv->ct);
+cairo_restore(priv->ct);
 #else
 gdk_draw_line(widget->window, widget->style->fg_gc[GTK_WIDGET_STATE(widget)],
            priv->scale_rect.x + SCALE_PADDING, priv->scale_rect.y + priv->scale_rect.height / 2 - SCALE_PADDING,
@@ -1553,3 +1559,17 @@ if (priv->zoom_to_mouse)
        gtk_map_set_center(widget, x2unit((gint) (event->x + 0.5)), y2unit((gint) (event->y + 0.5)));
 return FALSE;
 }
+
+static gboolean
+gtk_map_button_press_cb(GtkWidget *widget, GdkEventButton *event)
+{
+
+return FALSE;
+}
+
+static gboolean
+gtk_map_button_release_cb(GtkWidget *widget, GdkEventButton *event)
+{
+
+return FALSE;
+}