From 5443c3705048a110ece3acd77d0ecb1b5bf3619d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Kristian=20H=C3=B8gsberg?= Date: Sun, 11 Jun 2006 18:38:02 -0400 Subject: [PATCH] Improve initial icon placement. --- dock.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/dock.c b/dock.c index 37707a9..782d5d2 100644 --- a/dock.c +++ b/dock.c @@ -32,8 +32,8 @@ timeout_callback (gpointer data) for (i = 0; i < closure->num_icons; i++) { gdk_window_move (closure->windows[i], - closure->model.objects[i + 1].position.x, - closure->model.objects[i + 1].position.y); + closure->model.objects[i + 1].position.x + 0.5, + closure->model.objects[i + 1].position.y + 0.5); } model_step (&closure->model, 0.1); @@ -77,7 +77,8 @@ model_init_dock (Model *model, int num_items, int x, int y, int spacing) const int num_objects = num_items + 1; const int num_spacers = (num_objects - 1) * (num_objects - 2) / 2; const int num_springs = num_objects - 1; - int i, j; + const int spread = spacing + 20; + int i, j, left_edge; Object *object; Spring *spring; Spacer *spacer; @@ -101,14 +102,15 @@ model_init_dock (Model *model, int num_items, int x, int y, int spacing) model->anchors[0].y = y; model->anchors[0].object = &model->objects[0]; - object_init (&model->objects[0], x, y, 20); + object_init (&model->objects[0], x, y, 0); object = &model->objects[1]; spring = model->springs; spacer = model->spacers; + left_edge = (1024 - (num_items - 1) * spread) / 2; for (i = 1; i < num_objects; i++, object++) { - object_init (&model->objects[i], 200 + i * spacing / 2, 300, 3); + object_init (&model->objects[i], left_edge + (i - 1) * spread, y - 100, 1); spring_init (spring++, &model->objects[0], object, spacing); for (j = 1; j < num_objects - i; j++) { spacer_init (spacer++, object, object + j, spacing); @@ -145,8 +147,8 @@ window_event (GdkXEvent *xevent, GdkEvent *event, gpointer data) case MotionNotify: gdk_window_get_pointer (gdk_get_default_root_window(), &x, &y, &state); - closure->model.mouse_anchor.x = x + 0.5 - closure->drag_offset_x; - closure->model.mouse_anchor.y = y + 0.5 - closure->drag_offset_y; + closure->model.mouse_anchor.x = x - closure->drag_offset_x; + closure->model.mouse_anchor.y = y - closure->drag_offset_y; if (closure->model.mouse_anchor.y > closure->anchor_y) closure->model.mouse_anchor.y = closure->anchor_y; break; @@ -191,13 +193,17 @@ int main (int argc, char *argv[]) closure.spacing = spacing; closure.num_icons = num_icons; closure.windows = g_new (GdkWindow *, num_icons); + + model_init_dock (&closure.model, num_icons, + closure.anchor_x, closure.anchor_y, spacing); + for (i = 0; i < num_icons; i++) { handle = rsvg_handle_new_from_file (icons[i], NULL); rsvg_handle_get_dimensions (handle, &dimension); - x = (screen_width - spacing * num_icons) / 2 + i * spacing; - y = closure.anchor_y; + x = closure.model.objects[i + 1].position.x; + y = closure.model.objects[i + 1].position.y; width = dimension.width; height = dimension.height; closure.windows[i] = create_window (screen, x, y, width, height); @@ -215,8 +221,6 @@ int main (int argc, char *argv[]) gdk_window_add_filter (closure.windows[i], window_event, &closure); } - model_init_dock (&closure.model, num_icons, - closure.anchor_x, closure.anchor_y, spacing); g_timeout_add (20, timeout_callback, &closure); gtk_main (); -- 2.43.0