Exemplo n.º 1
0
        public void RebuildLayout()
        {
            if (LayoutChanges.Count == 1 && LayoutChanges[0] is PropertyChange pc && pc.Property == nameof(LeftHanded))
            {
                if (VisualElements.Count > 0)
                {
                    VisualElements.ForEach(e => e.FlipHandedness());
                    isLayoutDirty = false;
                    LayoutChanges.Clear();
                    OnLayoutUpdated();
                    return;
                }
            }

            VisualElements.Clear();
            for (int i = 0; i < NumberOfStrings; i++)
            {
                Strings[i].ClearLayoutData();
            }

            _CachedBounds = RectangleM.Empty;

            if (StringSpacing is StringSpacingSimple)
            {
                (StringSpacing as StringSpacingSimple).CalculateAdjustedPositions();
            }

            Measure nutCenter    = Measure.Zero;
            Measure bridgeCenter = Measure.Zero;

            Measure[] nutStringPos    = StringSpacing.GetStringPositions(FingerboardEnd.Nut, out nutCenter);
            Measure[] bridgeStringPos = StringSpacing.GetStringPositions(FingerboardEnd.Bridge, out bridgeCenter);

            LayoutStrings(nutStringPos, bridgeStringPos);
            CreateFingerboardEdges();
            PlaceFrets();
            FinishFingerboardShape();

            var layoutBounds = GetLayoutBounds();

            VisualElements.Add(new LayoutLine(new PointM(Measure.Zero, layoutBounds.Top), new PointM(Measure.Zero, layoutBounds.Bottom), VisualElementType.CenterLine));

            if (LeftHanded)
            {
                VisualElements.ForEach(e => e.FlipHandedness());
            }

            isLayoutDirty = false;
            LayoutChanges.Clear();
            OnLayoutUpdated();
        }