]> git.cworth.org Git - akamaru/blobdiff - akamaru.c
Add anchor constraint and use it to lock center point in dock model.
[akamaru] / akamaru.c
index ae01a27223ba5896eefe5ec53fed9b25c33f0849..804545411e5c4227f2e5a0e6982fe3d3cd5d2a1d 100644 (file)
--- a/akamaru.c
+++ b/akamaru.c
@@ -76,6 +76,14 @@ spacer_init (Spacer *spacer, Object *a, Object *b, double length)
   spacer->length = length;
 }
 
+void
+anchor_init (Anchor *anchor, Object *object, double x, double y)
+{
+  anchor->object = object;
+  anchor->x = x;
+  anchor->y = y;
+}
+
 void
 polygon_init (Polygon *p, int num_points, ...)
 {
@@ -316,6 +324,15 @@ model_constrain_polygon (Model *model, Polygon *polygon)
   }
 }
 
+static void
+model_constrain_anchor (Model *model, Anchor *anchor)
+{
+  anchor->object->position.x = anchor->x;
+  anchor->object->position.y = anchor->y;
+  anchor->object->previous_position.x = anchor->x;
+  anchor->object->previous_position.y = anchor->y;
+}
+
 static void
 model_constrain_offset (Model *model, Offset *offset)
 {
@@ -344,13 +361,10 @@ model_constrain (Model *model)
   double dx, dy, x, y, distance, fraction;
   int i;
 
-  /* Anchor object constraint. */
-  if (model->anchor_object != NULL) {
-    model->anchor_object->position.x = model->anchor_position.x;
-    model->anchor_object->position.y = model->anchor_position.y;
-    model->anchor_object->previous_position.x = model->anchor_position.x;
-    model->anchor_object->previous_position.y = model->anchor_position.y;
-  }
+  if (model->mouse_anchor.object != NULL)
+    model_constrain_anchor (model, &model->mouse_anchor);
+  for (i = 0; i < model->num_anchors; i++)
+    model_constrain_anchor (model, &model->anchors[i]);
 
   /* String constraints. */
   for (i = 0; i < model->num_strings; i++) {