Example #1
0
        public void RemoveTargetWithActionForControlEvent(object target, Action <object, CCControlEvent> action, CCControlEvent controlEvent)
        {
            // Retrieve all invocations for the given control event
            //<CCInvocation*>
            CCRawList <CCInvocation> eventInvocationList = DispatchListforControlEvent(controlEvent);

            //remove all invocations if the target and action are null
            if (target == null && action == null)
            {
                //remove objects
                eventInvocationList.Clear();
            }
            else
            {
                //normally we would use a predicate, but this won't work here. Have to do it manually
                foreach (CCInvocation invocation in eventInvocationList)
                {
                    bool shouldBeRemoved = true;
                    if (target != null)
                    {
                        shouldBeRemoved = (target == invocation.Target);
                    }
                    if (action != null)
                    {
                        shouldBeRemoved = (shouldBeRemoved && (action == invocation.Action));
                    }
                    // Remove the corresponding invocation object
                    if (shouldBeRemoved)
                    {
                        eventInvocationList.Remove(invocation);
                    }
                }
            }
        }
Example #2
0
        void DrawBatchedQuads()
        {
            int numOfQuads = 0;
            int startIndex = 0;

            if (currentBatchedQuads.Count <= 0 || quadCommands.Count == 0)
            {
                return;
            }

            uint lastMaterialId         = 0;
            bool originalDepthTestState = drawManager.DepthTest;
            bool usingDepthTest         = originalDepthTestState;

            drawManager.PushMatrix();
            drawManager.SetIdentityMatrix();

            CCQuadCommand prevCommand = null;

            foreach (CCQuadCommand command in quadCommands)
            {
                var  newMaterialID        = command.MaterialId;
                bool commandUsesDepthTest = command.UsingDepthTest;

                if (lastMaterialId != newMaterialID || commandUsesDepthTest != usingDepthTest)
                {
                    if (numOfQuads > 0 && prevCommand != null)
                    {
                        prevCommand.UseMaterial(drawManager);
                        drawManager.DrawQuads(currentBatchedQuads, startIndex, numOfQuads);

                        startIndex += numOfQuads;
                        numOfQuads  = 0;
                    }

                    lastMaterialId = newMaterialID;
                    usingDepthTest = commandUsesDepthTest;

                    drawManager.DepthTest = usingDepthTest;
                }

                numOfQuads += command.QuadCount;
                prevCommand = command;
            }

            // Draw any remaining quads
            if (numOfQuads > 0 && prevCommand != null)
            {
                prevCommand.UseMaterial(drawManager);
                drawManager.DrawQuads(currentBatchedQuads, startIndex, numOfQuads);
            }

            quadCommands.Clear();
            currentBatchedQuads.Clear();

            drawManager.PopMatrix();

            drawManager.DepthTest = originalDepthTestState;
        }
Example #3
0
        internal void VisitRenderQueue()
        {
            currentCommandType       = CCCommandType.None;
            currentViewportGroupId   = 0;
            currentViewportIdIndex   = 0;
            currentLayerGroupId      = 0;
            currentLayerGroupIdIndex = 0;
            currentGroupId           = 0;
            currentGroupIdIndex      = 0;
            currentArrivalIndex      = 0;
            maxViewportGroupId       = 0;
            maxLayerGroupId          = 0;
            maxGroupId = 0;

            Array.Sort <CCRenderCommand>(renderQueue.Elements, 0, renderQueue.Count);

            drawManager.ViewMatrix       = Matrix.Identity;
            drawManager.ProjectionMatrix = Matrix.Identity;

            foreach (CCRenderCommand command in renderQueue)
            {
                byte viewportGroupId = command.ViewportGroup;

                if (viewportGroupId != currentViewportGroupId)
                {
                    // We're about to change viewport
                    // So flush any pending render commands which use previous viewport
                    Flush();

                    currentViewportGroupId = viewportGroupId;
                    drawManager.Viewport   = viewportGroupStack[currentViewportGroupId];
                }

                byte layerGroupId = command.LayerGroup;

                if (layerGroupId != currentLayerGroupId)
                {
                    // We're about to change view/proj matrices
                    // So flush any pending render commands which use previous MVP state
                    Flush();

                    currentLayerGroupId          = layerGroupId;
                    drawManager.ViewMatrix       = layerGroupViewMatrixStack[currentLayerGroupId];
                    drawManager.ProjectionMatrix = layerGroupProjMatrixStack[currentLayerGroupId];
                }

                command.RequestRenderCommand(this);
            }

            // This only resets the count of the queue so is inexpensive
            renderQueue.Clear();

            // Flush any remaining render commands
            Flush();

            currentViewportGroupId = 0;
            currentLayerGroupId    = 0;
        }
Example #4
0
 public void Clear()
 {
     triangleVertices.Clear();
     lineVertices.Clear();
     if (stringData != null)
     {
         stringData.Clear();
     }
 }
Example #5
0
        public void Clear()
        {
            triangleVertices.Clear();
            lineVertices.Clear();
            if (stringData != null)
            {
                stringData.Clear();
            }

            dirty            = false;
            base.ContentSize = CCSize.Zero;
        }
Example #6
0
        internal void VisitRenderQueue()
        {
            IsRendering = true;
            quads.Clear();

            while (RenderQueue.HasItems)
            {
                var command = RenderQueue.Dequeue();
                ExecuteRenderCommand(command);
            }

            Flush();

            IsRendering = false;
        }
Example #7
0
        protected void UpdateLabel()
        {
            SetString(labelInitialText, false);

            if (string.IsNullOrEmpty(labelText))
            {
                return;
            }

            if (labelDimensions.Width > 0)
            {
                // Step 1: Make multiline
                string str_whole        = labelText;
                int    stringLength     = str_whole.Length;
                var    multiline_string = new StringBuilder(stringLength);
                var    last_word        = new StringBuilder(stringLength);

                int   line = 1, i = 0;
                bool  start_line = false, start_word = false;
                float startOfLine = -1, startOfWord = -1;
                int   skip = 0;

                CCRawList <CCNode> children = Children;
                for (int j = 0; j < children.Count; j++)
                {
                    CCSprite characterSprite;
                    int      justSkipped = 0;

                    while ((characterSprite = (CCSprite)this[(j + skip + justSkipped)]) == null)
                    {
                        justSkipped++;
                    }

                    skip += justSkipped;

                    if (!characterSprite.Visible)
                    {
                        continue;
                    }

                    if (i >= stringLength)
                    {
                        break;
                    }

                    char character = str_whole[i];

                    if (!start_word)
                    {
                        startOfWord = GetLetterPosXLeft(characterSprite);
                        start_word  = true;
                    }
                    if (!start_line)
                    {
                        startOfLine = startOfWord;
                        start_line  = true;
                    }

                    // Newline.
                    if (character == '\n')
                    {
                        int len = last_word.Length;
                        while (len > 0 && Char.IsWhiteSpace(last_word[len - 1]))
                        {
                            len--;
                            last_word.Remove(len, 1);
                        }

                        multiline_string.Append(last_word);
                        multiline_string.Append('\n');

                        last_word.Clear();

                        start_word  = false;
                        start_line  = false;
                        startOfWord = -1;
                        startOfLine = -1;
                        i          += justSkipped;
                        line++;

                        if (i >= stringLength)
                        {
                            break;
                        }

                        character = str_whole[i];

                        if (startOfWord == 0)
                        {
                            startOfWord = GetLetterPosXLeft(characterSprite);
                            start_word  = true;
                        }
                        if (startOfLine == 0)
                        {
                            startOfLine = startOfWord;
                            start_line  = true;
                        }
                    }

                    // Whitespace.
                    if (Char.IsWhiteSpace(character))
                    {
                        last_word.Append(character);
                        multiline_string.Append(last_word);
                        last_word.Clear();
                        start_word  = false;
                        startOfWord = -1;
                        i++;
                        continue;
                    }

                    // Out of bounds.
                    if (GetLetterPosXRight(characterSprite) - startOfLine > labelDimensions.Width)
                    {
                        if (!lineBreakWithoutSpaces)
                        {
                            last_word.Append(character);

                            int len = multiline_string.Length;
                            while (len > 0 && Char.IsWhiteSpace(multiline_string[len - 1]))
                            {
                                len--;
                                multiline_string.Remove(len, 1);
                            }

                            if (multiline_string.Length > 0)
                            {
                                multiline_string.Append('\n');
                            }

                            line++;
                            start_line  = false;
                            startOfLine = -1;
                            i++;
                        }
                        else
                        {
                            int len = last_word.Length;
                            while (len > 0 && Char.IsWhiteSpace(last_word[len - 1]))
                            {
                                len--;
                                last_word.Remove(len, 1);
                            }

                            multiline_string.Append(last_word);
                            multiline_string.Append('\n');

                            last_word.Clear();

                            start_word  = false;
                            start_line  = false;
                            startOfWord = -1;
                            startOfLine = -1;
                            line++;

                            if (i >= stringLength)
                            {
                                break;
                            }

                            if (startOfWord == 0)
                            {
                                startOfWord = GetLetterPosXLeft(characterSprite);
                                start_word  = true;
                            }
                            if (startOfLine == 0)
                            {
                                startOfLine = startOfWord;
                                start_line  = true;
                            }

                            j--;
                        }

                        continue;
                    }
                    else
                    {
                        // Character is normal.
                        last_word.Append(character);
                        i++;
                        continue;
                    }
                }

                multiline_string.Append(last_word);

                SetString(multiline_string.ToString(), false);
            }

            // Step 2: Make alignment
            if (horzAlignment != CCTextAlignment.Left)
            {
                int i = 0;

                int lineNumber = 0;
                int str_len    = labelText.Length;
                var last_line  = new CCRawList <char>();
                // If label dim is 0, then we need to use the content size width instead
                float maxLabelWidth = labelDimensions.Width > 0 ? labelDimensions.Width : ContentSize.Width;
                for (int ctr = 0; ctr <= str_len; ++ctr)
                {
                    if (ctr == str_len || labelText[ctr] == '\n')
                    {
                        float lineWidth   = 0.0f;
                        int   line_length = last_line.Count;
                        // if last line is empty we must just increase lineNumber and work with next line
                        if (line_length == 0)
                        {
                            lineNumber++;
                            continue;
                        }
                        int index = i + line_length - 1 + lineNumber;
                        if (index < 0)
                        {
                            continue;
                        }

                        var lastChar = (CCSprite)this[index];
                        if (lastChar == null)
                        {
                            continue;
                        }

                        lineWidth = lastChar.Position.X + lastChar.ContentSize.Width;

                        var shift = maxLabelWidth - lineWidth;
                        if (horzAlignment == CCTextAlignment.Center)
                        {
                            shift /= 2;
                        }

                        for (int j = 0; j < line_length; j++)
                        {
                            index = i + j + lineNumber;
                            if (index < 0)
                            {
                                continue;
                            }

                            var characterSprite = this[index];
                            characterSprite.PositionX += shift;
                        }

                        i += line_length;
                        lineNumber++;

                        last_line.Clear();
                        continue;
                    }

                    last_line.Add(labelText[ctr]);
                }
            }

            if (vertAlignment != CCVerticalTextAlignment.Bottom && labelDimensions.Height > 0)
            {
                int lineNumber = 1;
                int str_len    = labelText.Length;
                for (int ctr = 0; ctr < str_len; ++ctr)
                {
                    if (labelText[ctr] == '\n')
                    {
                        lineNumber++;
                    }
                }

                float yOffset = labelDimensions.Height - FontConfiguration.CommonHeight * lineNumber;

                if (vertAlignment == CCVerticalTextAlignment.Center)
                {
                    yOffset /= 2f;
                }

                for (int i = 0; i < str_len; i++)
                {
                    var characterSprite = this[i] as CCSprite;
                    if (characterSprite != null && characterSprite.Visible)
                    {
                        characterSprite.PositionY += yOffset;
                    }
                }
            }
        }
Example #8
0
 public void ClearInstances()
 {
     batchItemList.Clear();
 }