Browse Source

Started fixing VisualBrush.

Make sure control is initialized before it is used in a visual brush.
Previously the colored rectangle in the DropDown in ControlCatalog
didn't have the correct color until the DropDown was opened. This fixes
the color, although initial measurement is still off.
portable-xaml
Steven Kirk 11 years ago
parent
commit
0fce7e8150
  1. 16
      src/Gtk/Perspex.Cairo/Perspex.Cairo.csproj
  2. 64
      src/Shared/RenderHelpers/TileBrushImplHelper.cs
  3. 7
      src/Windows/Perspex.Direct2D1/Media/TileBrushImpl.cs
  4. 16
      src/Windows/Perspex.Direct2D1/Perspex.Direct2D1.csproj

16
src/Gtk/Perspex.Cairo/Perspex.Cairo.csproj

@ -80,6 +80,18 @@
<Project>{B09B78D8-9B26-48B0-9149-D64A2F120F3F}</Project>
<Name>Perspex.Base</Name>
</ProjectReference>
<ProjectReference Include="..\..\Perspex.Controls\Perspex.Controls.csproj">
<Project>{d2221c82-4a25-4583-9b43-d791e3f6820c}</Project>
<Name>Perspex.Controls</Name>
</ProjectReference>
<ProjectReference Include="..\..\Perspex.Input\Perspex.Input.csproj">
<Project>{62024b2d-53eb-4638-b26b-85eeaa54866e}</Project>
<Name>Perspex.Input</Name>
</ProjectReference>
<ProjectReference Include="..\..\Perspex.Interactivity\Perspex.Interactivity.csproj">
<Project>{6b0ed19d-a08b-461c-a9d9-a9ee40b0c06b}</Project>
<Name>Perspex.Interactivity</Name>
</ProjectReference>
<ProjectReference Include="..\..\Perspex.Layout\Perspex.Layout.csproj">
<Project>{42472427-4774-4C81-8AFF-9F27B8E31721}</Project>
<Name>Perspex.Layout</Name>
@ -88,6 +100,10 @@
<Project>{EB582467-6ABB-43A1-B052-E981BA910E3A}</Project>
<Name>Perspex.SceneGraph</Name>
</ProjectReference>
<ProjectReference Include="..\..\Perspex.Styling\Perspex.Styling.csproj">
<Project>{f1baa01a-f176-4c6a-b39d-5b40bb1b148f}</Project>
<Name>Perspex.Styling</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="app.config" />

64
src/Shared/RenderHelpers/TileBrushImplHelper.cs

@ -1,18 +1,14 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Perspex;
// Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using Perspex.Controls;
using Perspex.Media;
using Perspex.Rendering;
using Perspex.Layout;
using Perspex.Media.Imaging;
using Perspex.Platform;
using Perspex.VisualTree;
namespace Perspex.RenderHelpers
{
class TileBrushImplHelper
internal class TileBrushImplHelper
{
public Size IntermediateSize { get; }
public Rect DestinationRect { get; }
@ -27,8 +23,7 @@ namespace Perspex.RenderHelpers
private readonly Rect _drawRect;
public bool IsValid { get; }
public TileBrushImplHelper(TileBrush brush, Size targetSize)
{
_imageBrush = brush as ImageBrush;
@ -42,20 +37,19 @@ namespace Perspex.RenderHelpers
}
else if (_visualBrush != null)
{
var visual = _visualBrush.Visual;
if (visual == null)
return;
var layoutable = visual as ILayoutable;
var control = _visualBrush.Visual as IControl;
if (layoutable != null)
if (control != null)
{
if (layoutable.IsArrangeValid == false)
EnsureInitialized(control);
if (control.IsArrangeValid == false)
{
layoutable.Measure(Size.Infinity);
layoutable.Arrange(new Rect(layoutable.DesiredSize));
control.Measure(Size.Infinity);
control.Arrange(new Rect(control.DesiredSize));
}
_imageSize = layoutable.Bounds.Size;
_imageSize = control.Bounds.Size;
IsValid = true;
}
}
@ -118,8 +112,8 @@ namespace Perspex.RenderHelpers
/// <summary>
/// Calculates a _translate based on a <see cref="TileBrush"/>, a source and destination
/// rectangle and a _scale.
/// Calculates a translate based on a <see cref="TileBrush"/>, a source and destination
/// rectangle and a scale.
/// </summary>
/// <param name="brush">The brush.</param>
/// <param name="sourceRect">The source rectangle.</param>
@ -160,7 +154,6 @@ namespace Perspex.RenderHelpers
return new Vector(x, y);
}
public static Matrix CalculateIntermediateTransform(
TileMode tileMode,
Rect sourceRect,
@ -189,13 +182,28 @@ namespace Perspex.RenderHelpers
return transform;
}
static Size CalculateIntermediateSize(
private static Size CalculateIntermediateSize(
TileMode tileMode,
Size targetSize,
Size destinationSize) => tileMode == TileMode.None ? targetSize : destinationSize;
private static void EnsureInitialized(IControl control)
{
foreach (var i in control.GetSelfAndVisualDescendents())
{
var c = i as IControl;
if (c?.IsInitialized == false)
{
var init = c as ISupportInitialize;
if (init != null)
{
init.BeginInit();
init.EndInit();
}
}
}
}
}
}

7
src/Windows/Perspex.Direct2D1/Media/TileBrushImpl.cs

@ -1,13 +1,9 @@
// Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using Perspex.Layout;
using Perspex.Media;
using SharpDX;
using SharpDX.Direct2D1;
using Perspex.RenderHelpers;
using SharpDX.Direct2D1;
namespace Perspex.Direct2D1.Media
{
@ -38,7 +34,6 @@ namespace Perspex.Direct2D1.Media
}
}
private static BrushProperties GetBrushProperties(TileBrush brush, Rect destinationRect)
{
var tileTransform =

16
src/Windows/Perspex.Direct2D1/Perspex.Direct2D1.csproj

@ -107,6 +107,18 @@
<Project>{B09B78D8-9B26-48B0-9149-D64A2F120F3F}</Project>
<Name>Perspex.Base</Name>
</ProjectReference>
<ProjectReference Include="..\..\Perspex.Controls\Perspex.Controls.csproj">
<Project>{d2221c82-4a25-4583-9b43-d791e3f6820c}</Project>
<Name>Perspex.Controls</Name>
</ProjectReference>
<ProjectReference Include="..\..\Perspex.Input\Perspex.Input.csproj">
<Project>{62024b2d-53eb-4638-b26b-85eeaa54866e}</Project>
<Name>Perspex.Input</Name>
</ProjectReference>
<ProjectReference Include="..\..\Perspex.Interactivity\Perspex.Interactivity.csproj">
<Project>{6b0ed19d-a08b-461c-a9d9-a9ee40b0c06b}</Project>
<Name>Perspex.Interactivity</Name>
</ProjectReference>
<ProjectReference Include="..\..\Perspex.Layout\Perspex.Layout.csproj">
<Project>{42472427-4774-4C81-8AFF-9F27B8E31721}</Project>
<Name>Perspex.Layout</Name>
@ -115,6 +127,10 @@
<Project>{EB582467-6ABB-43A1-B052-E981BA910E3A}</Project>
<Name>Perspex.SceneGraph</Name>
</ProjectReference>
<ProjectReference Include="..\..\Perspex.Styling\Perspex.Styling.csproj">
<Project>{f1baa01a-f176-4c6a-b39d-5b40bb1b148f}</Project>
<Name>Perspex.Styling</Name>
</ProjectReference>
</ItemGroup>
<Import Project="..\..\Shared\RenderHelpers\RenderHelpers.projitems" Label="Shared" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

Loading…
Cancel
Save