Skip to content

Commit

Permalink
feat(ui): Display bounding boxes around 'boxes' in the definition
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoliz committed Jul 9, 2024
1 parent 42e4b47 commit a4916e0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 23 deletions.
13 changes: 12 additions & 1 deletion LogoSlideMaker.WinUi/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Windows.Foundation;
Expand Down Expand Up @@ -357,7 +358,17 @@ private void CanvasControl_Draw(CanvasControl _, CanvasDrawEventArgs args)
{
try
{
foreach (var p in viewModel.Primitives)
var primitives = viewModel.ShowBoundingBoxes ?
viewModel.Primitives.Concat(viewModel.BoxPrimitives) :
viewModel.Primitives;

if (primitives is null)
{
logger.LogError("Draw: Primitives failed");
return;
}

foreach (var p in primitives)
{
Draw(p, args.DrawingSession);
}
Expand Down
45 changes: 23 additions & 22 deletions LogoSlideMaker.WinUi/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ public class MainViewModel(IGetImageAspectRatio bitmaps, ILogger<MainViewModel>
/// </summary>
public IReadOnlyList<Primitive> Primitives => _primitives;

/// <summary>
/// Drawing primitives needed to render bounding boxes for the current slide
/// </summary>
public IReadOnlyList<Primitive> BoxPrimitives => _boxPrimitives;

/// <summary>
/// All the image paths we would need to render
/// </summary>
Expand Down Expand Up @@ -400,12 +405,14 @@ public void BackToPreviousSlide()
/// </remarks>
public void GeneratePrimitives()
{
_primitives.Clear();
_boxPrimitives.Clear();

if (_definition is null || _layout is null)
{
return;
}

_primitives.Clear();
var config = _definition.Render;

// Add primitives for a background
Expand Down Expand Up @@ -436,29 +443,22 @@ public void GeneratePrimitives()
var generator = new PrimitivesEngine(config, bitmaps);
_primitives.AddRange(_layout.Logos.SelectMany(generator.ToPrimitives));

#if false
// TODO: Need a new home for this! Elsewhere we are handling bounding boxes
// as a rendering operation NOT a primitive-generating operation.
// Add bounding boxes for any boxes with explicit outer dimensions
if (ShowBoundingBoxes)
{
_primitives.AddRange(
_definition.Boxes
.Where(x => x.Outer is not null)
.Select(x => new RectanglePrimitive()
// Add optional primitives to draw
_boxPrimitives.AddRange(
_definition.Boxes
.Where(x => x.Outer is not null)
.Select(x => new RectanglePrimitive()
{
Rectangle = x.Outer! with
{
Rectangle = x.Outer! with
{
X = x.Outer.X * 96m,
Y = x.Outer.Y * 96m,
Width = x.Outer.Width * 96m,
Height = x.Outer.Height * 96m
}
X = x.Outer.X * 96m,
Y = x.Outer.Y * 96m,
Width = x.Outer.Width * 96m,
Height = x.Outer.Height * 96m
}
)
);
}
#endif
}
)
);
}

/// <summary>
Expand Down Expand Up @@ -635,6 +635,7 @@ private void OnPropertyChanged([CallerMemberName] string? propertyName = null)
private Definition? _definition;
private SlideLayout? _layout;
private readonly List<Primitive> _primitives = [];
private readonly List<Primitive> _boxPrimitives = [];

#endregion
}

0 comments on commit a4916e0

Please sign in to comment.