[cairo-commit] cairo-demo/sproing ChangeLog, 1.6, 1.7 sproing.c, 1.5, 1.6

Carl Worth commit at pdx.freedesktop.org
Mon Mar 28 12:29:18 PST 2005


Committed by: cworth

Update of /cvs/cairo/cairo-demo/sproing
In directory gabe:/tmp/cvs-serv998

Modified Files:
	ChangeLog sproing.c 
Log Message:

        * sproing.c: (model_step_object), (sproing_button_release_event),
        (create_window): Increase default spring constant to 15. Release
        the immobile anchor point when the user releases the button.


Index: ChangeLog
===================================================================
RCS file: /cvs/cairo/cairo-demo/sproing/ChangeLog,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- ChangeLog	28 Mar 2005 20:02:43 -0000	1.6
+++ ChangeLog	28 Mar 2005 20:29:14 -0000	1.7
@@ -1,5 +1,11 @@
 2005-03-28  Carl Worth  <cworth at cworth.org>
 
+	* sproing.c: (model_step_object), (sproing_button_release_event),
+	(create_window): Increase default spring constant to 15. Release
+	the immobile anchor point when the user releases the button.
+
+2005-03-28  Carl Worth  <cworth at cworth.org>
+
 	* sproing.c: Reworked to have 2-way springs in the model, rather
 	than 1-way attractors in the objects. The 2-way behavior lets us
 	now pull any point around, (which is what's in place here). But

Index: sproing.c
===================================================================
RCS file: /cvs/cairo/cairo-demo/sproing/sproing.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- sproing.c	28 Mar 2005 20:02:43 -0000	1.5
+++ sproing.c	28 Mar 2005 20:29:15 -0000	1.6
@@ -20,8 +20,8 @@
 #define MODEL_MAX_SPRINGS 50
 #define MASS_INFINITE -1.0
 
-#define DEFAULT_SPRING_K 2.0
-#define DEFAULT_FRICTION 4.2
+#define DEFAULT_SPRING_K 15.0
+#define DEFAULT_FRICTION  4.2
 
 struct _Spring {
   Object *a;
@@ -260,10 +260,13 @@
   acceleration.x = object->force.x / object->mass;
   acceleration.y = object->force.y / object->mass;
 
-  object->velocity.x += acceleration.x;
-  object->velocity.y += acceleration.y;
+  if (object->immobile) {
+    object->velocity.x = 0;
+    object->velocity.y = 0;
+  } else {
+    object->velocity.x += acceleration.x;
+    object->velocity.y += acceleration.y;
 
-  if (! object->immobile) {
     object->position.x += object->velocity.x;
     object->position.y += object->velocity.y;
   }
@@ -555,6 +558,22 @@
 }
 
 static gboolean
+sproing_button_release_event (GtkWidget	     *widget,
+			      GdkEventButton *event,
+			      gpointer	      data)
+{
+  Model *model = data;
+
+  if (event->button != 1)
+    return TRUE;
+
+  if (model->anchor_object)
+    model->anchor_object->immobile = 0;
+
+  return TRUE;
+}
+
+static gboolean
 sproing_button_press_event (GtkWidget	   *widget,
 			    GdkEventButton *event,
 			    gpointer	    data)
@@ -692,7 +711,8 @@
 		    G_CALLBACK (sproing_motion_notify_event), model);
   g_signal_connect (da, "button_press_event",
 		    G_CALLBACK (sproing_button_press_event), model);
-
+  g_signal_connect (da, "button_release_event",
+		    G_CALLBACK (sproing_button_release_event), model);
 
   /* Ask to receive events the drawing area doesn't normally
    * subscribe to
@@ -700,6 +720,7 @@
   gtk_widget_set_events (da, gtk_widget_get_events (da)
 			 | GDK_LEAVE_NOTIFY_MASK
 			 | GDK_BUTTON_PRESS_MASK
+			 | GDK_BUTTON_RELEASE_MASK
 			 | GDK_POINTER_MOTION_MASK
 			 | GDK_POINTER_MOTION_HINT_MASK);
 




More information about the cairo-commit mailing list