我用C,GTK +和cairo编码。我正在尝试使用滑块来更改变量的值。这就是我到目前为止所做的:
adj = (GtkAdjustment *) gtk_adjustment_new (300.0, -50.0, 500.0, 1.0, 1.0, 1.0);
scale = gtk_hscale_new (GTK_ADJUSTMENT (adj));
gtk_box_pack_start (GTK_BOX (vbox1), scale, FALSE, TRUE, 5);
gtk_signal_connect(GTK_OBJECT(adj), "value_changed", GTK_SIGNAL_FUNC(value_changed), NULL);
这是我创建调整并在用户移动滑块时发送信号的地方。
double
value_changed (GtkAdjustment *adj)
{
pos1x = gtk_adjustment_get_value(adj);
printf ("\n%lf", pos1x);
return pos1x;
}
这里我将pos1x值更改为滑块的值。
gboolean
on_expose_event (GtkWidget *widget,
GdkEventExpose *event,
gpointer data)
{
cairo_t *cr;
double posy;
static gdouble pos2x = 450., pos2y = 290.; //Coordenadas Espelho
static gdouble pos3x = 450., pos3y = 250.;
cr = gdk_cairo_create(widget->window);
pos1x = gtk_adjustment_get_value(adj);
posy = 250.;
cairo_set_source_rgb (cr, 0, 0, 0);
cairo_set_line_width (cr, 1.0);
cairo_rectangle (cr, (double) pos1x, (double) posy, 20, 80);
cairo_stroke_preserve (cr);
cairo_set_source_rgb (cr, 1, 1, 1);
cairo_fill (cr);
现在我想使用pos1x变量来改变我用cairo创建的矩形的坐标,当用户移动滑块时。但是,我只能得到调整的初始值,而不是变化。我无法想办法做到这一点,如果你能伸出援手,我会很感激。
提前致谢。
答案 0 :(得分:1)
您需要从gdk_window_invalidate_rect()
函数中调用value_changed()
或类似内容,让GTK +重新发出expose-event
。