protected StaveGroup CreateEmptyStaveGroup() { var group = new StaveGroup(); group.Layout = this; var isFirstTrack = true; for (var i = 0; i < Renderer.Tracks.Length; i++) { var track = Renderer.Tracks[i]; for (var j = 0; j < Renderer.Settings.Staves.Count; j++) { var s = Renderer.Settings.Staves[j]; if (Environment.StaveFactories.ContainsKey(s.Id)) { var factory = Environment.StaveFactories[s.Id](this); if (factory.CanCreate(track) && (isFirstTrack || !factory.HideOnMultiTrack)) { group.AddStave(track, new Stave(s.Id, factory, s.AdditionalSettings)); } } } isFirstTrack = false; } return group; }
public override void DoLayoutAndRender() { if (Renderer.Settings.Staves.Count == 0) return; var score = Renderer.Score; var canvas = Renderer.Canvas; var startIndex = Renderer.Settings.Layout.Get("start", 1); startIndex--; // map to array index startIndex = Math.Min(score.MasterBars.Count - 1, Math.Max(0, startIndex)); var currentBarIndex = startIndex; var endBarIndex = Renderer.Settings.Layout.Get("count", score.MasterBars.Count); endBarIndex = startIndex + endBarIndex - 1; // map count to array index endBarIndex = Math.Min(score.MasterBars.Count - 1, Math.Max(0, endBarIndex)); var x = PagePadding[0]; var y = PagePadding[1]; _group = CreateEmptyStaveGroup(); while (currentBarIndex <= endBarIndex) { _group.AddBars(Renderer.Tracks, currentBarIndex); currentBarIndex++; } _group.X = x; _group.Y = y; _group.FinalizeGroup(this); y += _group.Height + (GroupSpacing * Scale); Height = y + PagePadding[3]; Width = _group.X + _group.Width + PagePadding[2]; // TODO: Find a good way to render the score partwise // we need to precalculate the final height somehow canvas.BeginRender(Width, Height); canvas.Color = Renderer.RenderingResources.MainGlyphColor; canvas.TextAlign = TextAlign.Left; _group.Paint(0, 0, Renderer.Canvas); var result = canvas.EndRender(); OnPartialRenderFinished(new RenderFinishedEventArgs { TotalWidth = Width, TotalHeight = y, Width = Width, Height = Height, RenderResult = result }); }
public StaveTrackGroup(StaveGroup staveGroup, Track track) { StaveGroup = staveGroup; Track = track; Staves = new FastList <Stave>(); }
public override void DoLayoutAndRender() { if (Renderer.Settings.Staves.Count == 0) return; var score = Renderer.Score; var canvas = Renderer.Canvas; var startIndex = Renderer.Settings.Layout.Get("start", 1); startIndex--; // map to array index startIndex = Math.Min(score.MasterBars.Count - 1, Math.Max(0, startIndex)); var currentBarIndex = startIndex; var endBarIndex = Renderer.Settings.Layout.Get("count", score.MasterBars.Count); endBarIndex = startIndex + endBarIndex - 1; // map count to array index endBarIndex = Math.Min(score.MasterBars.Count - 1, Math.Max(0, endBarIndex)); _group = CreateEmptyStaveGroup(); _group.X = PagePadding[0]; _group.Y = PagePadding[1]; var countPerPartial = Renderer.Settings.Layout.Get("countPerPartial", 10); var partials = new FastList<HorizontalScreenLayoutPartialInfo>(); var currentPartial = new HorizontalScreenLayoutPartialInfo(); while (currentBarIndex <= endBarIndex) { var result = _group.AddBars(Renderer.Tracks, currentBarIndex); // if we detect that the new renderer is linked to the previous // renderer, we need to put it into the previous partial var renderer = _group.GetBarRenderer(currentBarIndex); if (currentPartial.MasterBars.Count == 0 && result.IsLinkedToPrevious && partials.Count > 0) { var previousPartial = partials[partials.Count - 1]; previousPartial.MasterBars.Add(score.MasterBars[currentBarIndex]); previousPartial.Width += renderer.Width; } else { currentPartial.MasterBars.Add(score.MasterBars[currentBarIndex]); currentPartial.Width += renderer.Width; // no targetPartial here because previous partials already handled this code if (currentPartial.MasterBars.Count >= countPerPartial) { if (partials.Count == 0) { currentPartial.Width += _group.X + _group.AccoladeSpacing; } partials.Add(currentPartial); currentPartial = new HorizontalScreenLayoutPartialInfo(); } } currentBarIndex++; } // don't miss the last partial if not empty if (currentPartial.MasterBars.Count >= 0) { if (partials.Count == 0) { currentPartial.Width += _group.X + _group.AccoladeSpacing; } partials.Add(currentPartial); } _group.FinalizeGroup(this); Height = _group.Y + _group.Height + PagePadding[3]; Width = _group.X + _group.Width + PagePadding[2]; // TODO: Find a good way to render the score partwise // we need to precalculate the final height somehow //canvas.BeginRender(Width, Height); //canvas.Color = Renderer.RenderingResources.MainGlyphColor; //canvas.TextAlign = TextAlign.Left; //_group.Paint(0, 0, Renderer.Canvas); //var result = canvas.EndRender(); //OnPartialRenderFinished(new RenderFinishedEventArgs //{ // TotalWidth = Width, // TotalHeight = y, // Width = Width, // Height = Height, // RenderResult = result //}); currentBarIndex = 0; for (var i = 0; i < partials.Count; i++) { var partial = partials[i]; canvas.BeginRender(partial.Width, Height); canvas.Color = Renderer.RenderingResources.MainGlyphColor; canvas.TextAlign = TextAlign.Left; var renderer = _group.GetBarRenderer(partial.MasterBars[0].Index); var renderX = renderer.X + _group.AccoladeSpacing; if (i == 0) { renderX -= _group.X + _group.AccoladeSpacing; } _group.PaintPartial(-renderX, _group.Y, Renderer.Canvas, currentBarIndex, partial.MasterBars.Count); var result = canvas.EndRender(); OnPartialRenderFinished(new RenderFinishedEventArgs { TotalWidth = Width, TotalHeight = Height, Width = partial.Width, Height = Height, RenderResult = result }); currentBarIndex += partial.MasterBars.Count; } }
/// <summary> /// Realignes the bars in this line according to the available space /// </summary> private void FitGroup(StaveGroup group) { // calculate additional space for each bar (can be negative!) float barSpace = 0f; float freeSpace = MaxWidth - group.Width; if (freeSpace != 0 && group.MasterBars.Count > 0) { barSpace = freeSpace / group.MasterBars.Count; } if (group.IsFull || barSpace < 0) { // add it to the measures group.ApplyBarSpacing(barSpace); } Width = Math.Max(Width, group.Width); }
public StaveTrackGroup(StaveGroup staveGroup, Track track) { StaveGroup = staveGroup; Track = track; Staves = new FastList<Stave>(); }
protected StaveGroup CreateEmptyStaveGroup() { var group = new StaveGroup(); group.Layout = this; var isFirstTrack = true; for (var trackIndex = 0; trackIndex < Renderer.Tracks.Length; trackIndex++) { var track = Renderer.Tracks[trackIndex]; for (int staveIndex = 0; staveIndex < track.Staves.Count; staveIndex++) { for (var renderStaveIndex = 0; renderStaveIndex < Renderer.Settings.Staves.Count; renderStaveIndex++) { var s = Renderer.Settings.Staves[renderStaveIndex]; if (Environment.StaveFactories.ContainsKey(s.Id)) { var factory = Environment.StaveFactories[s.Id](this); if (factory.CanCreate(track) && (isFirstTrack || !factory.HideOnMultiTrack) && (staveIndex == 0 || !factory.HideOnMultiTrack)) { group.AddStave(track, new Staff(track.Staves[staveIndex], s.Id, factory, s.AdditionalSettings)); } } } } isFirstTrack = false; } return group; }