Exemplo n.º 1
0
            public TreeMapItem(Gtk.TreeModel m,
			                    ref Gtk.TreeIter iter,
			                    bool horiz,
			                    int textColumn,
			                    int weightColumn)
            {
                if (m == null)
                    throw new ArgumentNullException ("m");

                if (iter.Equals (Gtk.TreeIter.Zero))
                    throw new ArgumentException ("iter");

                if (textColumn < 0)
                    throw new ArgumentException ("textColumn");

                if (weightColumn < 0)
                    throw new ArgumentException ("weightColumn");

                Path = m.GetPath (iter);
                Title = (string)m.GetValue (iter, textColumn);
                Weight = (double)m.GetValue (iter, weightColumn);
                X = 0;
                Y = 0;
                Width = 0;
                Height = 0;
                Children = null;
                Horiz = horiz;

                Gtk.TreeIter citer;
                double c_total = 0.0;

                if (m.IterChildren (out citer, iter)) {
                    do {
                        AddChild (new TreeMapItem (m, ref citer, !horiz, textColumn, weightColumn));
                    } while (m.IterNext (ref citer));

                    // Get total weight
                    Children.ForEach (delegate (TreeMapItem i) {
                        c_total += Math.Abs (i.Weight);
                    });

                    this.ChildrenWeight = c_total;
                }
            }
        private bool reload_covers()
        {
            if (Timeline != null) {
                Timeline.Pause ();
            }
            HideAll ();
            Show ();
            if (covers != null && covers.Count != 0) {
                Console.WriteLine("ClutterFlow - Reloading Covers");

                // the old current index
                int old_target_index = CurrentCover!=null ? covers.IndexOf (CurrentCover) : 0;
                // the newly calculated index
                int new_target_index = 0;
                // whether or not to keep the current cover centered
                bool keep_current = false;

                List<ClutterFlowBaseActor> old_covers = new List<ClutterFlowBaseActor> (
                    SafeGetRange (covers, old_target_index - HalfVisCovers - 1, visibleCovers + 2));
                foreach (ClutterFlowBaseActor actor in covers) {
                    if (actor.Data.ContainsKey ("isOldCover")) {
                        actor.Data.Remove ("isOldCover");
                    }
                    actor.Index = -1;
                    if (old_covers.Contains (actor)) {
                        actor.Data.Add ("isOldCover", true);
                    }
                }

                ResetLetterLookup ();
                List<ClutterFlowBaseActor> persistent_covers = new List<ClutterFlowBaseActor>();

                covers = actor_loader.GetActors (this);
                covers.ForEach (delegate (ClutterFlowBaseActor actor) {
                    if (actor.Data.ContainsKey ("isOldCover")) {
                        persistent_covers.Add (actor);
                    }
                    if (CurrentCover==actor) {
                        keep_current = true;
                    }

                    UpdateLetterLookup (actor);
                });
                InvokeLetterLookupChanged ();

                if (covers.Count == 0) {
                    InstallEmptyActor ();
                    if (old_covers.Contains (EmptyActor)) {
                        EmptyActor.Show ();
                        return false;
                    }
                    keep_current = true;
                }

                //recalculate timeline progression and the target index
                if (covers.Count > 1) {
                    if (keep_current) {
                        new_target_index = CurrentCover.Index;
                    } else {
                        if (persistent_covers.Count==0) {
                            new_target_index = (int) Math.Round(Timeline.Progress * (covers.Count-1));
                        } else if (persistent_covers.Count==1) {
                            new_target_index = persistent_covers[0].Index;
                        } else {
                            new_target_index = persistent_covers[(int) (((float) persistent_covers.Count * 0.5f) - 1.0f)].Index;
                        }
                    }
                }
                TargetIndex = new_target_index;
                Timeline.JumpToTarget ();

                //Console.WriteLine ("Timeline progress set to " + Timeline.Progress + " Timeline.RelativeTarget is " + Timeline.RelativeTarget);

                List<ClutterFlowBaseActor> truly_pers = new List<ClutterFlowBaseActor> ();
                List<ClutterFlowBaseActor> new_covers = new List<ClutterFlowBaseActor>(SafeGetRange(covers, new_target_index - HalfVisCovers - 1, visibleCovers + 2));
                foreach (ClutterFlowBaseActor actor in persistent_covers) {
                    if (actor != null) {
                        if (actor.Data.ContainsKey ("isOldCover")) {
                            actor.Data.Remove ("isOldCover");
                        }
                        if (new_covers.Contains (actor)) {
                            truly_pers.Add (actor);
                            new_covers.Remove (actor);
                            old_covers.Remove (actor);
                            actor.Show ();
                        }
                    }
                }
                foreach (ClutterFlowBaseActor actor in old_covers) {
                    if (actor != null) {
                        actor.Data.Remove ("isOldCover");
                    }
                }

                /*Console.WriteLine ("old_covers          contains " + old_covers.Count + " elements:");
                foreach (ClutterFlowBaseActor cover in old_covers)
                    Console.WriteLine("\t- " + cover.Label.Replace("\n", " - "));
                Console.WriteLine ("persistent_covers   contains " + truly_pers.Count + " elements");
                foreach (ClutterFlowBaseActor cover in truly_pers)
                    Console.WriteLine("\t- " + cover.Label.Replace("\n", " - "));
                Console.WriteLine ("new_covers          contains " + new_covers.Count + " elements");
                foreach (ClutterFlowBaseActor cover in new_covers)
                    Console.WriteLine("\t- " + cover.Label.Replace("\n", " - "));*/

                System.EventHandler update_target = delegate (object o, System.EventArgs e) {
                    Timeline.Play ();
                    InvokeCoversChanged();
                };

                Behaviour.FadeCoversInAndOut (old_covers, truly_pers, new_covers, update_target);
            } else {
                Console.WriteLine("ClutterFlow - Loading Covers");
                ResetLetterLookup ();
                covers = actor_loader.GetActors (this);
                covers.ForEach (UpdateLetterLookup);
                InvokeLetterLookupChanged ();
                TargetIndex = 0;
                Timeline.JumpToTarget ();
                if (covers==null || covers.Count==0) {
                    InstallEmptyActor ();
                    Behaviour.UpdateActors ();
                    Behaviour.FadeInActor (EmptyActor);
                }
                Timeline.Play ();
                InvokeCoversChanged ();
            }

            return false;
        }
Exemplo n.º 3
0
        void UpdateBgImage()
        {
            m_bgImage = null;

            if (TextColumn < 0 || WeightColumn < 0)
                return;

            m_bgImage = new Cairo.ImageSurface (Format.Rgb24, Allocation.Width, this.Allocation.Height);

            using (var c = new Cairo.Context (m_bgImage))
            {
                // Paint the default background (linear gradient)
                var g = new Cairo.LinearGradient (0, 0, 1, this.Allocation.Height);
                g.AddColorStop (0.2, CairoExtensions.GdkColorToCairoColor (m_Background));
                g.AddColorStop (0.9, CairoExtensions.GdkColorToCairoColor (this.Style.Background (Gtk.StateType.Normal)));
                c.Rectangle (0, 0, this.Allocation.Width, this.Allocation.Height);
                c.Pattern = g;
                c.Paint ();
                g.Dispose ();

                Gtk.TreeIter iter;

                List<TreeMapItem> rootItems = new List<TreeMapItem> ();

                if (m_Model.GetIterFirst (out iter)) {
                    do {
                        var item = new TreeMapItem (m_Model, ref iter, true, m_TextColumn, m_WeightColumn);
                        rootItems.Add (item);
                    } while (m_Model.IterNext (ref iter));

                    double t = 0.0;

                    rootItems.ForEach (delegate (TreeMapItem i) {
                        t += Math.Abs (i.Weight);
                    });

                    double x = 0, y = 0, w = this.Allocation.Width, h = this.Allocation.Height;
                    double myx = 0, myy = 0, myw = 0, myh = 0;

                    rootItems.ForEach (delegate (TreeMapItem i) {
                        var ratio = Math.Abs (i.Weight) / t;
                        myx = x;
                        myy = y;
                        myw = w * ratio;
                        myh = h;
                        x += myw;

                        i.SetArea (myx, myy, myw, myh);
                        i.Render (c, m_Background);
                    });

                    // clear right away to lower refs
                    if (this.m_rootItems != null)
                        this.m_rootItems.Clear ();

                    this.m_rootItems = rootItems;
                }
            }
        }