Hi guys,

Someone could help with scroll bar, zoom gesture and pan gesture ?

I add this zoom callback, and i need to change the scroll bar. But i 
don't understand the paramentes of gtk_adjustment_configure().

static void
zoom_scale_changed (GtkGestureZoom *gesture,
                     gdouble         scale,
                     GtkWidget      *widget)
{

     double lower = gtk_adjustment_get_lower(hadjustment);
     double upper = gtk_adjustment_get_upper(hadjustment);

double dif = ((upper - lower)*scale - (upper -lower) ) / 2.0 ;

        if(dif > 0){
         linechart_set_xaxis_minmax(chart, dif , PAGE_SIZE - dif);
       gtk_adjustment_configure(hadjustment, dif, lower, PAGE_SIZE - 
dif, 1.0, 1.0, PAGE_SIZE);
     }else{
         linechart_set_xaxis_minmax(chart, 0.0 , PAGE_SIZE);
         gtk_adjustment_configure(hadjustment, 0.0, 0.0, PAGE_SIZE, 1.0, 
1.0, PAGE_SIZE);
     }
     gtk_widget_queue_draw (widget);
}

static void pan_pos_changed (GtkGesturePan  *gesture,
         GtkPanDirection direction,
         gdouble         offset,
         GtkWidget      *widget){
     double value = gtk_adjustment_get_value(hadjustment);
     double lower = gtk_adjustment_get_lower(hadjustment);
     double upper = gtk_adjustment_get_upper(hadjustment);

     switch (direction){
         case GTK_PAN_DIRECTION_LEFT:
             linechart_set_xaxis_minmax(chart, lower - offset , upper - 
offset);
             break;
         case GTK_PAN_DIRECTION_RIGHT:
             linechart_set_xaxis_minmax(chart, lower + offset , upper + 
offset);
         break;
     }

     gtk_widget_queue_draw (widget);
}

To configure callback and gesture i use this:

     /* Zoom */
     gesture = gtk_gesture_zoom_new (canvas);
     g_signal_connect (gesture, "scale-changed",
                         G_CALLBACK (zoom_scale_changed), canvas);
     gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER 
(gesture),
GTK_PHASE_BUBBLE);
     g_object_weak_ref (G_OBJECT (canvas), (GWeakNotify) g_object_unref, 
gesture);

     /* Pan */
     gesture = gtk_gesture_pan_new(canvas,GTK_ORIENTATION_HORIZONTAL);
     g_signal_connect (gesture, "pan",
                     G_CALLBACK (pan_pos_changed), canvas);
     gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER 
(gesture),
GTK_PHASE_BUBBLE);
     g_object_weak_ref (G_OBJECT (canvas), (GWeakNotify) g_object_unref, 
gesture);

    hadjustment = gtk_adjustment_new(0, 0, 0, 0, 0, 0);

    g_signal_connect(G_OBJECT(hadjustment), "value-changed", 
(GCallback)value_changed, NULL);

    hscrollbar = gtk_scrollbar_new(GTK_ORIENTATION_HORIZONTAL, hadjustment);

    gtk_adjustment_configure(hadjustment, 0.0, 0.0, PAGE_SIZE, 1.0, 1.0, 
PAGE_SIZE);

The pan gesture don't works, never go to callback function.

Thanks



---
Este e-mail foi verificado em termos de vírus pelo software antivírus Avast.
https://www.avast.com/antivirus

_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Reply via email to