Re: Howto make a button pressed callback acting as long as the button state is down ?



Jean-Max,

I've done this before... I needed a continuously pressed button to keep a
relay closed (this was an instrumentation GUI interface), so I used the
"pressed" event to set a flag which was checked periodically by a timer
(1-second interval); if the flag was set, the relay remained energized. When
the user released the button, the "released" event cleared the flag... the
timer event saw that the flag was cleared and de-energized the relay. Been
working like a charm for the last couple of years.

In your case, you probably would want a timer event set for about 1/4 second
so that a single click would result in a single rotation, but holding the
button down would continue rotations. Use the "pressed" event to set a flag
which can be seen in a repeating timer function, then use the "released"
event to clear the flag so the rotation stops.

Hope this helps a bit!

Bob Lawson

----- Original Message -----
From: "Jean-Max Redonnet" <jmax redonnet meca insa-tlse fr>
To: <gtk-app-devel-list gnome org>
Sent: Tuesday, June 12, 2001 11:43 PM
Subject: Howto make a button pressed callback acting as long as the button
state is down ?


Sorry if this has been covered before.

I have 4 buttons that makes my model rotate in a drawing area
(in a gtkglarea in fact but doesn't matters).

First try :
When I press one of this buttons a single step rotation is
done. Well good job ! but I would like the rotation process
follows as long as the button is pressed.

The problem is I don't know how to make this. I have a single
event (pressed or clicked) thus a single rotation step.

Second try :
I've tried to work with GTK_WIDGET_STATE(button) but this not
works. Here the concerned code :

void
on_rotate_left_btn_pressed             (GtkButton       *button,
                                        gpointer         user_data)
{
  GtkWidget *glarea;
  scene *pscene;
  Vec3 axis;
  double angle;

  g_print("Rotate left button clicked \n");
  glarea = lookup_widget(GTK_WIDGET(button), "glarea");
  pscene = gtk_object_get_data(GTK_OBJECT(glarea), "scene");

  axis.x = 0.0;
  axis.y = -1.0;
  axis.z = 0.0;
  angle = 5.0;

  while(GTK_WIDGET_STATE(button) == GTK_STATE_ACTIVE ) {
    g_print("GTK_WIDGET_STATE(button) : %i \n",
GTK_WIDGET_STATE(button));
    rotate_view_XY(axis, DEG2RAD(angle), pscene);
    redraw_widget(glarea);
  }

}

void
on_rotate_left_btn_released            (GtkButton       *button,
                                        gpointer         user_data)
{
  gtk_widget_set_state(GTK_WIDGET(button), GTK_STATE_NORMAL);
}

The problem is when I press the left_btn the rotation starts but
never ends, so the on_rotate_left_btn_released callback is never called.

How to make this to work ?

Thanks for any help.

--
JMR

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





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]