Beispiel #1
0
        public override bool AddChild(Balloon generatedBalloon, bool isFromStatic, bool staticDockedBottomFlag)
        {
            RectangleNormal newRect = new RectangleNormal();

            if (isFromStatic)
            {
                // add it to the list
                this.AddChildToList(generatedBalloon);
            }
            else
            {
                if (!this.GetNewRect(generatedBalloon, ref newRect))
                {
                    return(false);
                }
                else
                {
                    generatedBalloon.WidthInPixels     = newRect.right - newRect.left;
                    generatedBalloon.HeightInPixels    = newRect.bottom - newRect.top;
                    generatedBalloon.positionRect.top  = newRect.top;
                    generatedBalloon.positionRect.left = newRect.left;
                    generatedBalloon.containerRect     = newRect;
                    this.AddChildToList(generatedBalloon);
                }

                // 1. ask for free space and get new rect for it
                // 2. in case there is no space
                //       check for conditions to grow
                //          try to grow this balloon (also parents). Return which one failed growing if anyone failed and return FALSE
                //          if balloon grew goto 1.
                //		if cannot grow return false
                // 3. in case there is enough space.
                //		move new balloon to the rect position and set position and sizes to structure
                //	    add balloon to rect List and return true.
            }
            return(true);
        }
Beispiel #2
0
        /// <summary>
        /// Adds new child to this balloon and performs resize if necessary.
        ///
        /// </summary>
        /// <param name="generatedBalloon">newly created balloon that needs to fit into this one</param>
        /// <param name="staticBalloonFlag">this flag is true if generated balloon should be threated as static. if true
        /// then it is put exactly where it should be. If this is true staticDockedBottomFlag is ignored</param>
        /// <param name="staticDockedBottomFlag">Flag that tells if this should be threated as static bottom docked ballooon. </param>
        /// <returns></returns>
        public override bool AddChild(Balloon generatedBalloon, bool staticBalloonFlag, bool staticDockedBottomFlag)
        {
            RectangleNormal newRect = new RectangleNormal();

            if (staticBalloonFlag)
            {
                // add it to the list
                this.AddChildToList(generatedBalloon);
            }
            else
            {
                // if there is no room for another child here
                if (this.FillCapacity > 0 && (this.DynamicChildBalloons + 1 > this.FillCapacity) && !staticDockedBottomFlag)
                {
                    return(false);
                }

                if (!this.GetNewRect(generatedBalloon, ref newRect))
                {
                    if (this.CanGrow)
                    {
                        // we established that balloon need to grow to put this new one inside and determined ammount of grow
                        // we need to check if grow is allowed on parents side (maybe it is already taken on parents size and allocated in
                        // rect matrix. this is checked before grow
                        if (this.GrowBalloon(generatedBalloon, generatedBalloon.HeightInPixels - (this.HeightInPixels - newRect.top)))
                        {
                            return(this.AddChild(generatedBalloon, staticBalloonFlag, staticDockedBottomFlag));
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    if (staticDockedBottomFlag && !this.FitToContent)
                    {
                        // in case this one is static docked bottom and we wont to put him on the bottom of this balloon
                        newRect.top    = this.containerRect.bottom - (newRect.bottom - newRect.top);
                        newRect.bottom = this.containerRect.bottom;

                        generatedBalloon.WidthInPixels     = newRect.right - newRect.left;
                        generatedBalloon.HeightInPixels    = newRect.bottom - newRect.top;
                        generatedBalloon.positionRect.top  = newRect.top;
                        generatedBalloon.positionRect.left = newRect.left;
                        generatedBalloon.containerRect     = newRect;
                    }
                    else
                    {
                        generatedBalloon.WidthInPixels     = newRect.right - newRect.left;
                        generatedBalloon.HeightInPixels    = newRect.bottom - newRect.top;
                        generatedBalloon.positionRect.top  = newRect.top;
                        generatedBalloon.positionRect.left = newRect.left;
                        generatedBalloon.containerRect     = newRect;
                    }
                    this.AddChildToList(generatedBalloon);
                }

                // 1. ask for free space and get new rect for it
                // 2. in case there is no space
                //       check for conditions to grow
                //          try to grow this balloon (also parents). Return which one failed growing if anyone failed and return FALSE
                //          if balloon grew goto 1.
                //		if cannot grow return false
                // 3. in case there is enough space.
                //		move new balloon to the rect position and set position and sizes to structure
                //	    add balloon to rect List and return true.
            }
            return(true);
        }
Beispiel #3
0
        public bool GrowBalloon(Balloon generatedBalloon, float growDelta)
        {
            RectangleNormal rect1 = new RectangleNormal();
            RectangleNormal rect2 = new RectangleNormal();

            Debug.Assert(growDelta >= -Epsilon, "Grow Delta Should never be negative");

            // check what generate algorithm is used and do logic from that
            //if (generatedBalloon->generatingAlgorithm == GENERATING_ALGORITHM_RIGHT_BOTTOM)
            {
                // this means we can grow only on bottom. growDelta contains info how much we need to grow
                // 1. Grow Parent if can grow
                if (this.Parent != null)
                {
                    // check if parent needs to grow at all
                    // rect of parent
                    rect1.top    = 0;
                    rect1.left   = 0;
                    rect1.right  = this.Parent.WidthInPixels;
                    rect1.bottom = this.Parent.HeightInPixels;

                    //desired rect after growth. Growth to allow generatedBalloon to fall in
                    rect2.left   = this.positionRect.left;
                    rect2.top    = this.positionRect.top;
                    rect2.bottom = (rect2.top + this.HeightInPixels + growDelta);
                    rect2.right  = (rect2.left + this.WidthInPixels);

                    if (rect1.Contains(rect2))
                    {
                        // check if we intersect some rectangle in rectMatrix and in case we do return false
                        foreach (RectangleNormal rect in this.Parent.rectMatrix)
                        {
                            // if rect.top != rect2.top && rect.left != rect2.left - or if this is not the same rect which already has taken place
                            // and if it does insterest something return false
                            if (!(System.Math.Abs(rect.top - rect2.top) < Epsilon &&
                                  System.Math.Abs(rect.left - rect2.left) < Epsilon) &&
                                rect.Intersect(rect2))
                            {
                                return(false);
                            }
                        }

                        // we don't need to grow parent just increase size of self
                        this.HeightInPixels       += growDelta;
                        this.containerRect.bottom += growDelta;
                    }
                    else
                    {
                        // can parent grow at all
                        if (this.CanGrow)
                        {
                            // grow parent
                            if (this.Parent is Balloon)
                            {
                                Balloon parentBallon = (Balloon)this.Parent;
                                if (parentBallon.CanGrow && parentBallon.GrowBalloon(generatedBalloon, growDelta))
                                {
                                    this.HeightInPixels       += growDelta;
                                    this.containerRect.bottom += growDelta;
                                }
                                else
                                {
                                    return(false);
                                }
                            }
                            else
                            {
                                return(false);
                            }
                        }
                        else
                        {
                            // cannot increase size return FALSE
                            return(false);
                        }
                    }
                }
                else
                {
                    // no parent ... grow in height by required size.
                    this.HeightInPixels       += growDelta;
                    this.containerRect.bottom += growDelta;
                }

                this.positionRect.bottom = rect2.bottom;
            }
            //if (generatedBalloon->generatingAlgorithm == GENERATING_ALGORITHM_BOTTOM_RIGHT)
            //{
            //    // this means we can grow only on left
            //    // TODO: Not implemented yet
            //}

            return(true);
        }