AlphaTab.Rendering.EffectBarRenderer.CreateOrResizeGlyph C# (CSharp) Method

CreateOrResizeGlyph() private method

private CreateOrResizeGlyph ( EffectBarGlyphSizing sizing, Beat b ) : EffectGlyph
sizing EffectBarGlyphSizing
b AlphaTab.Model.Beat
return AlphaTab.Rendering.Glyphs.EffectGlyph
        private EffectGlyph CreateOrResizeGlyph(EffectBarGlyphSizing sizing, Beat b)
        {
            switch (sizing)
            {
                case EffectBarGlyphSizing.SinglePreBeat:
                case EffectBarGlyphSizing.SingleOnBeat:
                    var g = _info.CreateNewGlyph(this, b);
                    g.Renderer = this;
                    g.Beat = b;
                    g.DoLayout();
                    _effectGlyphs[b.Voice.Index][b.Index] = g;
                    _uniqueEffectGlyphs[b.Voice.Index].Add(g);
                    return g;

                case EffectBarGlyphSizing.GroupedOnBeat:
                    if (b.Index > 0 || Index > 0)
                    {
                        // check if the previous beat also had this effect
                        Beat prevBeat = b.PreviousBeat;
                        if (_info.ShouldCreateGlyph(this, prevBeat))
                        {
                            // first load the effect bar renderer and glyph
                            EffectBarRenderer previousRenderer = null;
                            EffectGlyph prevEffect = null;

                            if (b.Index > 0 && _effectGlyphs[b.Voice.Index].ContainsKey(prevBeat.Index))
                            {
                                // load effect from previous beat in the same renderer
                                prevEffect = _effectGlyphs[b.Voice.Index][prevBeat.Index];
                            }
                            else if (Index > 0)
                            {
                                // load the effect from the previous renderer if possible.
                                previousRenderer = (EffectBarRenderer)Staff.BarRenderers[Index - 1];
                                var voiceGlyphs = previousRenderer._effectGlyphs[b.Voice.Index];
                                if (voiceGlyphs.ContainsKey(prevBeat.Index))
                                {
                                    prevEffect = voiceGlyphs[prevBeat.Index];
                                }
                            }

                            // if the effect cannot be expanded, create a new glyph
                            // in case of expansion also create a new glyph, but also link the glyphs together
                            // so for rendering it might be expanded.
                            EffectGlyph newGlyph = CreateOrResizeGlyph(EffectBarGlyphSizing.SingleOnBeat, b);

                            if (prevEffect != null && _info.CanExpand(this, prevBeat, b))
                            {
                                // link glyphs
                                prevEffect.NextGlyph = newGlyph;
                                newGlyph.PreviousGlyph = prevEffect;

                                // mark renderers as linked for consideration when layouting the renderers (line breaking, partial breaking)
                                if (previousRenderer != null)
                                {
                                    IsLinkedToPrevious = true;
                                }
                            }

                            return newGlyph;
                        }

                        // in case the previous beat did not have the same effect, we simply create a new glyph
                        return CreateOrResizeGlyph(EffectBarGlyphSizing.SingleOnBeat, b);
                    }

                    // in case of the very first beat, we simply create the glyph.
                    return CreateOrResizeGlyph(EffectBarGlyphSizing.SingleOnBeat, b);
            }

            return null;
        }