Exemple #1
0
        protected CCSpriteBatchNode AddSpriteWithoutQuad(CCSprite child, int z, int aTag)
        {
            Debug.Assert(child != null, "Argument must be non-NULL");

            // quad index is Z
            child.AtlasIndex = z;

            // XXX: optimize with a binary search
            int i = 0;

            if (Descendants.Count > 0)
            {
                CCSprite[] elements = Descendants.Elements;
                for (int j = 0, count = Descendants.Count; j < count; j++)
                {
                    if (elements[i].AtlasIndex <= z)
                    {
                        ++i;
                    }
                }
            }

            Descendants.Insert(i, child);

            base.AddChild(child, z, aTag);

            //#issue 1262 don't use lazy sorting, tiles are added as quads not as sprites, so sprites need to be added in order
            ReorderBatch(false);

            return(this);
        }
Exemple #2
0
        private void AddSpriteWithoutQuad(CCSprite child, int z, int aTag)
        {
            Debug.Assert(child != null, "Argument must be non-NULL");

            // quad index is Z
            child.AtlasIndex   = z;
            child.TextureAtlas = TextureAtlas;

            int i = 0;

            if (Descendants.Count > 0)
            {
                CCSprite[] elements = Descendants.Elements;
                for (int j = 0, count = Descendants.Count; j < count; j++)
                {
                    if (elements[i].AtlasIndex <= z)
                    {
                        ++i;
                    }
                }
            }

            Descendants.Insert(i, child);

            base.AddChild(child, z, aTag);
        }
Exemple #3
0
        public void InsertChild(CCSprite sprite, int uIndex)
        {
            if (TextureAtlas.TotalQuads == TextureAtlas.Capacity)
            {
                IncreaseAtlasCapacity();
            }

            TextureAtlas.InsertQuad(ref sprite.transformedQuad, uIndex);
            sprite.BatchNode  = this;
            sprite.AtlasIndex = uIndex;

            Descendants.Insert(uIndex, sprite);

            // update indices
            CCSprite[] delements = Descendants.Elements;
            for (int i = uIndex + 1, count = Descendants.Count; i < count; i++)
            {
                delements[i].AtlasIndex++;
            }

            // add children recursively
            CCRawList <CCNode> children = sprite.Children;

            if (children != null && children.Count > 0)
            {
                CCNode[] elements = children.Elements;
                for (int j = 0, count = children.Count; j < count; j++)
                {
                    var child = (CCSprite)elements[j];
                    uIndex = AtlasIndexForChild(child, child.ZOrder);
                    InsertChild(child, uIndex);
                }
            }
        }
 public void CopyToDesc(DescendantsViewModel descendantsViewModel, Descendants descendants)
 {
     descendants.Id        = descendantsViewModel.Id;
     descendants.FirstName = descendantsViewModel.FirstName;
     descendants.LastName  = descendantsViewModel.LastName;
     descendants.UserId    = descendantsViewModel.UserId;
 }
Exemple #5
0
        // addChild helper, faster than insertChild
        public void AppendChild(CCSprite sprite)
        {
            IsReorderChildDirty = true;

            if (TextureAtlas.TotalQuads == TextureAtlas.Capacity)
            {
                IncreaseAtlasCapacity();
            }

            Descendants.Add(sprite);

            int index = Descendants.Count - 1;

            sprite.AtlasIndex = index;
            sprite.BatchNode  = this;

            TextureAtlas.UpdateQuad(ref sprite.transformedQuad, index);

            // add children recursively
            CCRawList <CCNode> children = sprite.Children;

            if (children != null && children.Count > 0)
            {
                CCNode[] elements = children.Elements;
                int      count    = children.Count;
                for (int i = 0; i < count; i++)
                {
                    AppendChild((CCSprite)elements[i]);
                }
            }
        }
Exemple #6
0
 public void InvalidateMaterials()
 {
     foreach (var mesh in Descendants.OfType <Mesh3D>().SelectMany((m) => m.Submeshes))
     {
         mesh.Material.Invalidate();
     }
 }
Exemple #7
0
 public void AddSubsymbol(ISymbolInformation child)
 {
     if (Descendants == null)
     {
         Descendants = new List <ISymbolInformation>();
     }
     Descendants.Add(child);
 }
Exemple #8
0
 private void ResetLightning()
 {
     foreach (var mesh in Descendants.OfType <Mesh3D>())
     {
         mesh.ProcessLightning = lightningEnabled;
         mesh.RecieveShadow    = recieveShadow;
         mesh.CastShadow       = castShadow;
     }
 }
 private DescendantsViewModel MapToDescendantsViewModel(Descendants descendants)
 {
     return(new DescendantsViewModel
     {
         Id = descendants.Id,
         FirstName = descendants.FirstName,
         LastName = descendants.LastName,
         UserId = descendants.UserId,
     });
 }
Exemple #10
0
        public void RebuildSkeleton()
        {
            var submeshes = Descendants
                            .OfType <Mesh3D>()
                            .SelectMany(m => m.Submeshes);

            foreach (var sm in submeshes)
            {
                sm.RebuildSkeleton(this);
            }
        }
Exemple #11
0
        public override void RemoveAllChildren(bool cleanup)
        {
            // Invalidate atlas index. issue #569
            // useSelfRender should be performed on all descendants. issue #1216
            CCSprite[] elements = Descendants.Elements;
            for (int i = 0, count = Descendants.Count; i < count; i++)
            {
                elements[i].BatchNode = null;
            }

            base.RemoveAllChildren(cleanup);

            Descendants.Clear();
            TextureAtlas.RemoveAllQuads();
        }
        public T AddChildNode <T>(T child, Position position) where T : XmlPortNode
        {
            switch (position)
            {
            case Position.FirstWithinContainer:
                Container.Insert(Index + 1, child);
                break;

            case Position.LastWithinContainer:
                var lastIndex = Descendants.Any() ? Descendants.Last().Index : Index;
                Container.Insert(lastIndex + 1, child);
                break;
            }

            return(child);
        }
Exemple #13
0
        /// <summary>
        /// Tries to looks for the specified message type and returns it.
        /// </summary>
        /// <param name="result">The message of the specified type.</param>
        /// <typeparam name="T">The message type that needs to be searched.</typeparam>
        /// <returns><c>true</c>, if the message was found; otherwise <c>false</c>.</returns>
        /// <remarks>
        /// This method is necessary because there can be a hierarchy of messages. In this case the whole stack needs to be searched for the message.
        /// </remarks>
        /// <example>
        /// <code>
        /// protected override void ExecuteCore(Message messageData)
        /// {
        ///     //This will not execute if the message was decorated
        ///     if(messageData is SpecificMessage message)
        ///     {
        ///         //...
        ///     }
        ///
        ///     //This will work either way
        ///     if(messageData.TryGet(out SpecificMessage message))
        ///     {
        ///         //...
        ///     }
        /// }
        /// </code>
        /// </example>
        public bool TryGet <T>(out T result) where T : Message
        {
            result = this as T;
            if (result == null)
            {
                if (this != HeadMessage)
                {
                    HeadMessage.TryGet(out result);
                }
                else
                {
                    result = Descendants.OfType <T>().FirstOrDefault();
                }
            }

            return(result != null);
        }
Exemple #14
0
 private void ManageFocusOnWindowActivation()
 {
     if (Window.Active)
     {
         if (Widget.Focused != null && Widget.Focused.SameOrDescendantOf(this))
         {
             lastFocused = Widget.Focused;
         }
     }
     if (windowActivated)
     {
         windowActivated = false;
         if (lastFocused == null || !lastFocused.GloballyVisible || !lastFocused.SameOrDescendantOf(this))
         {
             // Looking the first focus scope widget on the window and make it focused.
             lastFocused = Descendants.OfType <Widget>().FirstOrDefault(i => i.FocusScope != null && i.GloballyVisible);
         }
         Widget.SetFocus(lastFocused);
     }
 }
Exemple #15
0
        public void RemoveSpriteFromAtlas(CCSprite sprite)
        {
            // remove from TextureAtlas
            TextureAtlas.RemoveQuadAtIndex(sprite.AtlasIndex);

            // Cleanup sprite. It might be reused (issue #569)
            sprite.BatchNode = null;

            var uIndex = Descendants.IndexOf(sprite);

            if (uIndex >= 0)
            {
                // update all sprites beyond this one
                var count    = Descendants.Count;
                var elements = Descendants.Elements;

                for (var index = uIndex; index < count; ++index)
                {
                    elements[index].AtlasIndex--;
                }

                Descendants.RemoveAt(uIndex);
            }

            // remove children recursively
            var spriteChildren = sprite.Children;

            if (spriteChildren != null && spriteChildren.Count > 0)
            {
                var elements = spriteChildren.Elements;
                for (int i = 0, count = spriteChildren.Count; i < count; i++)
                {
                    RemoveSpriteFromAtlas((CCSprite)elements[i]);
                }
            }
        }
        public void RemoveSpriteFromAtlas(CCSprite sprite)
        {
            // remove from TextureAtlas
            TextureAtlas.RemoveQuadAtIndex(sprite.AtlasIndex);

            // Cleanup sprite. It might be reused (issue #569)
            sprite.BatchNode = null;

            int uIndex = Descendants.IndexOf(sprite);

            if (uIndex >= 0)
            {
                Descendants.RemoveAt(uIndex);

                // update all sprites beyond this one
                int        count    = Descendants.Count;
                CCSprite[] elements = Descendants.Elements;

                for (; uIndex < count; ++uIndex)
                {
                    elements[uIndex].AtlasIndex--;
                }
            }

            // remove children recursively
            CCRawList <CCNode> pChildren = sprite.Children;

            if (pChildren != null && pChildren.Count > 0)
            {
                CCNode[] elements = pChildren.Elements;
                for (int i = 0, count = pChildren.Count; i < count; i++)
                {
                    RemoveSpriteFromAtlas((CCSprite)elements[i]);
                }
            }
        }
Exemple #17
0
 public bool IsParentOf(Construct construct)
 {
     return(Descendants.Contains(construct));
 }
Exemple #18
0
 public void AddDescendant(IStackableVertex vertex)
 {
     Descendants.AddLast(vertex);
 }
 public void it_should_return_the_correct_number_of_descendants_including_the_waste_basket_page()
 {
     Descendants.Count().ShouldBe(11);
 }
Exemple #20
0
        void LayoutLabel()
        {
            if (FontAtlas == null || string.IsNullOrEmpty(Text))
            {
                ContentSize = CCSize.Zero;
                return;
            }

            TextureAtlas.RemoveAllQuads();
            Descendants.Clear();
            lettersInfo.Clear();

            FontAtlas.PrepareLetterDefinitions(Text);

            var start      = 0;
            var typesetter = new CCTLTextLayout(this);

            var length      = Text.Length;
            var insetBounds = labelDimensions;

            var layoutAvailable = true;

            if (insetBounds == CCSize.Zero)
            {
                insetBounds     = new CCSize(8388608, 8388608);
                layoutAvailable = false;
            }

            var boundsWidth              = insetBounds.Width;
            var contentScaleFactorWidth  = CCLabel.DefaultTexelToContentSizeRatios.Width;
            var contentScaleFactorHeight = CCLabel.DefaultTexelToContentSizeRatios.Height;

            List <CCTLLine> lineList = new List <CCTLLine>();

            while (start < length)// && textPosition.Y < insetBounds.Bottom)
            {
                // Now we ask the typesetter to break off a line for us.
                // This also will take into account line feeds embedded in the text.
                //  Example: "This is text \n with a line feed embedded inside it"
                int count = typesetter.SuggestLineBreak(start, boundsWidth);
                var line  = typesetter.GetLine(start, start + count);
                lineList.Add(line);

                start += count;
            }


            // Calculate our vertical starting position
            var totalHeight       = lineList.Count * LineHeight;
            var nextFontPositionY = totalHeight;

            if (Dimensions.Height > 0)
            {
                var labelHeightPixel = Dimensions.Height * contentScaleFactorHeight;
                if (totalHeight > labelHeightPixel)
                {
                    int numLines = (int)(labelHeightPixel / LineHeight);
                    totalHeight = numLines * LineHeight;
                }
                switch (VerticalAlignment)
                {
                case CCVerticalTextAlignment.Top:
                    nextFontPositionY = labelHeightPixel;
                    break;

                case CCVerticalTextAlignment.Center:
                    nextFontPositionY = (labelHeightPixel + totalHeight) * 0.5f;
                    break;

                case CCVerticalTextAlignment.Bottom:
                    nextFontPositionY = totalHeight;
                    break;

                default:
                    break;
                }
            }


            var   lineGlyphIndex = 0;
            float longestLine    = (labelDimensions.Width > 0) ? labelDimensions.Width : 0;

            // Used for calculating overlapping on last line character
            var lastCharWidth   = 0.0f;
            int lastCharAdvance = 0;

            // Define our horizontal justification
            var flushFactor = (float)HorizontalAlignment / (float)CCTextAlignment.Right;

            // We now loop through all of our line's glyph runs
            foreach (var line in lineList)
            {
                var gliphRun  = line.GlyphRun;
                var lineWidth = line.Bounds.Width * contentScaleFactorWidth;
                var flush     = line.PenOffsetForFlush(flushFactor, boundsWidth);

                foreach (var glyph in gliphRun)
                {
                    var letterPosition = glyph.Position;
                    var letterDef      = glyph.Definition;
                    lastCharWidth     = letterDef.Width * contentScaleFactorWidth;
                    letterPosition.X += flush;
                    letterPosition.Y  = (nextFontPositionY - letterDef.YOffset) / contentScaleFactorHeight;

                    //recordLetterInfo(letterPosition, glyph.def, lineGlyphIndex++);

                    var tmpInfo = new LetterInfo();

                    tmpInfo.Definition         = letterDef;
                    tmpInfo.Position           = letterPosition;
                    tmpInfo.ContentSize.Width  = letterDef.Width;
                    tmpInfo.ContentSize.Height = letterDef.Height;

                    if (lineGlyphIndex >= lettersInfo.Count)
                    {
                        lettersInfo.Add(tmpInfo);
                    }
                    else
                    {
                        lettersInfo[lineGlyphIndex] = tmpInfo;
                    }

                    lineGlyphIndex++;

                    lastCharAdvance = (int)glyph.Definition.XAdvance;
                }

                // calculate our longest line which is used for calculating our ContentSize
                if (lineWidth > longestLine)
                {
                    longestLine = lineWidth;
                }

                nextFontPositionY -= LineHeight;
            }

            CCSize tmpSize;

            // If the last character processed has an xAdvance which is less that the width of the characters image, then we need
            // to adjust the width of the string to take this into account, or the character will overlap the end of the bounding
            // box
            if (lastCharAdvance < lastCharWidth)
            {
                tmpSize.Width = longestLine - lastCharAdvance + lastCharWidth;
            }
            else
            {
                tmpSize.Width = longestLine;
            }

            tmpSize.Height = totalHeight;

            if (Dimensions.Height > 0)
            {
                tmpSize.Height = Dimensions.Height * contentScaleFactorHeight;
            }

            ContentSize = tmpSize / CCLabel.DefaultTexelToContentSizeRatios;

            lineList.Clear();

            CCRect   uvRect;
            CCSprite letterSprite;

            for (int c = 0; c < Children.Count; c++)
            {
                letterSprite = (CCSprite)Children[c];
                int tag = letterSprite.Tag;
                if (tag >= length)
                {
                    RemoveChild(letterSprite, true);
                }
                else if (tag >= 0)
                {
                    if (letterSprite != null)
                    {
                        uvRect = lettersInfo[tag].Definition.Subrect;
                        letterSprite.TextureRectInPixels = uvRect;
                        letterSprite.ContentSize         = uvRect.Size;
                    }
                }
            }

            UpdateQuads();
            UpdateColor();
        }
 public void it_should_return_the_correct_number_of_descendants()
 {
     Descendants.Count().ShouldBe(6);
 }
Exemple #22
0
 public bool HasChild(T value)
 {
     return(Descendants.Any(vertex => Equals(vertex.Value, value)));
 }
Exemple #23
0
 public void AddDescendant(ASTNode node)
 {
     Descendants.Add(node);
     node.Parent = this;
 }
Exemple #24
0
        /// <summary>Remove branches without any content to reduce the size of the tree</summary>
        internal void PruneBranches()
        {
            // Notes:
            //  - This method can change the addresses of dock panes.

            m_prune_pending = false;

            // A branch can be disposed between 'SignalPruneBranches' and the method
            // being invoked. In this case, ignore the prune branches.
            if (DockContainer == null)
            {
                return;
            }

            // Depth-first recursive
            foreach (var b in Descendants.Select(x => x.Item as Branch).NotNull())
            {
                b.PruneBranches();
            }

            // Remove empty panes. If any of L,R,T,B contain empty panes, prune them.
            // Don't prune 'C', we need to leave somewhere for content to be dropped.
            foreach (var c in Descendants.Where(x => x.Item is DockPane))
            {
                var p = (DockPane)c.Item !;

                if (p.AllContent.Count == 0 && c.DockSite != EDockSite.Centre)
                {
                    // Dispose the pane
                    c.Item = null;
                    Util.Dispose(ref p !);
                }
            }

            // If any of the child branches only have a single child, replace the branch with it's child
            foreach (var c in Descendants.Where(x => x.Item is Branch).NotNull())
            {
                var b = (Branch)c.Item !;

                // The child must, itself, have only one child
                if (b.Descendants.Count != 1)
                {
                    continue;
                }

                // Replace the branch with it's single child
                var old = c.Item;
                var nue = b.Descendants[0].Item;
                b.Descendants[0].Item = null;
                c.Item = nue;
                Util.Dispose(ref old !);
            }

            // If the branch has only one child, ensure it's in the Centre position.
            if (Descendants.Count == 1 && Descendants[EDockSite.Centre].Item == null)
            {
                var item = Descendants[0].Item;
                Descendants[0].Item = null;
                Descendants[EDockSite.Centre].Item = item;
            }

            // If the centre position is empty, and there is only one other descendant, move it to the centre.
            if (Descendants.Count == 2 && Descendants[EDockSite.Centre]?.Item is DockPane dp && dp.AllContent.Count == 0)
            {
                var item = Descendants[1].Item;
                Descendants[1].Item = null;
                Descendants[0].Item = null;
                Descendants[EDockSite.Centre].Item = item;
                Util.Dispose(ref dp !);
            }

            // Ensure there is always a centre pane
            if (Descendants[EDockSite.Centre].Item == null)
            {
                Descendants[EDockSite.Centre].Item = new DockPane(DockContainer);
            }

            // Check all the logic is correct
            Debug.Assert(ValidateTree());
        }