committed by
GitHub
44 changed files with 748 additions and 96 deletions
@ -0,0 +1,14 @@ |
|||
//
|
|||
// AvnString.h
|
|||
// Avalonia.Native.OSX
|
|||
//
|
|||
// Created by Dan Walmsley on 07/11/2018.
|
|||
// Copyright © 2018 Avalonia. All rights reserved.
|
|||
//
|
|||
|
|||
#ifndef AvnString_h |
|||
#define AvnString_h |
|||
|
|||
extern IAvnString* CreateAvnString(NSString* string); |
|||
|
|||
#endif /* AvnString_h */ |
|||
@ -0,0 +1,55 @@ |
|||
// |
|||
// AvnString.m |
|||
// Avalonia.Native.OSX |
|||
// |
|||
// Created by Dan Walmsley on 07/11/2018. |
|||
// Copyright © 2018 Avalonia. All rights reserved. |
|||
// |
|||
|
|||
#include "common.h" |
|||
|
|||
class AvnStringImpl : public virtual ComSingleObject<IAvnString, &IID_IAvnString> |
|||
{ |
|||
private: |
|||
NSString* _string; |
|||
|
|||
public: |
|||
FORWARD_IUNKNOWN() |
|||
|
|||
AvnStringImpl(NSString* string) |
|||
{ |
|||
_string = string; |
|||
} |
|||
|
|||
virtual HRESULT Pointer(void**retOut) override |
|||
{ |
|||
@autoreleasepool |
|||
{ |
|||
if(retOut == nullptr) |
|||
{ |
|||
return E_POINTER; |
|||
} |
|||
|
|||
*retOut = (void*)_string.UTF8String; |
|||
|
|||
return S_OK; |
|||
} |
|||
} |
|||
|
|||
virtual HRESULT Length(int*retOut) override |
|||
{ |
|||
if(retOut == nullptr) |
|||
{ |
|||
return E_POINTER; |
|||
} |
|||
|
|||
*retOut = (int)_string.length; |
|||
|
|||
return S_OK; |
|||
} |
|||
}; |
|||
|
|||
IAvnString* CreateAvnString(NSString* string) |
|||
{ |
|||
return new AvnStringImpl(string); |
|||
} |
|||
@ -0,0 +1,6 @@ |
|||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
|||
<PropertyGroup> |
|||
<AvaloniaPreviewerNetCoreToolPath>$(MSBuildThisFileDirectory)\..\tools\netcoreapp2.0\designer\Avalonia.Designer.HostApp.dll</AvaloniaPreviewerNetCoreToolPath> |
|||
<AvaloniaPreviewerNetFullToolPath>$(MSBuildThisFileDirectory)\..\tools\net461\designer\Avalonia.Designer.HostApp.exe</AvaloniaPreviewerNetFullToolPath> |
|||
</PropertyGroup> |
|||
</Project> |
|||
@ -0,0 +1 @@ |
|||
Generated/*.cs |
|||
@ -0,0 +1,56 @@ |
|||
<Style xmlns="https://github.com/avaloniaui" |
|||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
|||
xmlns:sys="clr-namespace:System;assembly=mscorlib"> |
|||
<Style.Resources> |
|||
|
|||
<Color x:Key="ThemeAccentColor">#CC119EDA</Color> |
|||
<Color x:Key="ThemeAccentColor2">#99119EDA</Color> |
|||
<Color x:Key="ThemeAccentColor3">#66119EDA</Color> |
|||
<Color x:Key="ThemeAccentColor4">#33119EDA</Color> |
|||
|
|||
<Color x:Key="ThemeBackgroundColor">#FF282828</Color> |
|||
<Color x:Key="ThemeBorderLowColor">#FF505050</Color> |
|||
<Color x:Key="ThemeBorderMidColor">#FF808080</Color> |
|||
<Color x:Key="ThemeBorderHighColor">#FFA0A0A0</Color> |
|||
<Color x:Key="ThemeControlLowColor">#FF282828</Color> |
|||
<Color x:Key="ThemeControlMidColor">#FF505050</Color> |
|||
<Color x:Key="ThemeControlHighColor">#FF808080</Color> |
|||
<Color x:Key="ThemeControlHighlightLowColor">#FFA8A8A8</Color> |
|||
<Color x:Key="ThemeControlHighlightMidColor">#FF828282</Color> |
|||
<Color x:Key="ThemeControlHighlightHighColor">#FF505050</Color> |
|||
<Color x:Key="ThemeForegroundColor">#FFDEDEDE</Color> |
|||
<Color x:Key="ThemeForegroundLowColor">#FF808080</Color> |
|||
|
|||
<Color x:Key="HighlightColor">#FF119EDA</Color> |
|||
<Color x:Key="ErrorColor">#FFFF0000</Color> |
|||
<Color x:Key="ErrorLowColor">#10FF0000</Color> |
|||
|
|||
<SolidColorBrush x:Key="ThemeBackgroundBrush" Color="{DynamicResource ThemeBackgroundColor}"></SolidColorBrush> |
|||
<SolidColorBrush x:Key="ThemeBorderLowBrush" Color="{DynamicResource ThemeBorderLowColor}"></SolidColorBrush> |
|||
<SolidColorBrush x:Key="ThemeBorderMidBrush" Color="{DynamicResource ThemeBorderMidColor}"></SolidColorBrush> |
|||
<SolidColorBrush x:Key="ThemeBorderHighBrush" Color="{DynamicResource ThemeBorderHighColor}"></SolidColorBrush> |
|||
<SolidColorBrush x:Key="ThemeControlLowBrush" Color="{DynamicResource ThemeControlLowColor}"></SolidColorBrush> |
|||
<SolidColorBrush x:Key="ThemeControlMidBrush" Color="{DynamicResource ThemeControlMidColor}"></SolidColorBrush> |
|||
<SolidColorBrush x:Key="ThemeControlHighBrush" Color="{DynamicResource ThemeControlHighColor}"></SolidColorBrush> |
|||
<SolidColorBrush x:Key="ThemeControlHighlightLowBrush" Color="{DynamicResource ThemeControlHighlightLowColor}"></SolidColorBrush> |
|||
<SolidColorBrush x:Key="ThemeControlHighlightMidBrush" Color="{DynamicResource ThemeControlHighlightMidColor}"></SolidColorBrush> |
|||
<SolidColorBrush x:Key="ThemeControlHighlightHighBrush" Color="{DynamicResource ThemeControlHighlightHighColor}"></SolidColorBrush> |
|||
<SolidColorBrush x:Key="ThemeForegroundBrush" Color="{DynamicResource ThemeForegroundColor}"></SolidColorBrush> |
|||
<SolidColorBrush x:Key="ThemeForegroundLowBrush" Color="{DynamicResource ThemeForegroundLowColor}"></SolidColorBrush> |
|||
|
|||
<SolidColorBrush x:Key="HighlightBrush" Color="{DynamicResource HighlightColor}"></SolidColorBrush> |
|||
<SolidColorBrush x:Key="ThemeAccentBrush" Color="{DynamicResource ThemeAccentColor}"></SolidColorBrush> |
|||
<SolidColorBrush x:Key="ThemeAccentBrush2" Color="{DynamicResource ThemeAccentColor2}"></SolidColorBrush> |
|||
<SolidColorBrush x:Key="ThemeAccentBrush3" Color="{DynamicResource ThemeAccentColor3}"></SolidColorBrush> |
|||
<SolidColorBrush x:Key="ThemeAccentBrush4" Color="{DynamicResource ThemeAccentColor4}"></SolidColorBrush> |
|||
<SolidColorBrush x:Key="ErrorBrush" Color="{DynamicResource ErrorColor}"></SolidColorBrush> |
|||
<SolidColorBrush x:Key="ErrorLowBrush" Color="{DynamicResource ErrorLowColor}"></SolidColorBrush> |
|||
|
|||
<Thickness x:Key="ThemeBorderThickness">1,1,1,1</Thickness> |
|||
<sys:Double x:Key="ThemeDisabledOpacity">0.5</sys:Double> |
|||
|
|||
<sys:Double x:Key="FontSizeSmall">10</sys:Double> |
|||
<sys:Double x:Key="FontSizeNormal">12</sys:Double> |
|||
<sys:Double x:Key="FontSizeLarge">16</sys:Double> |
|||
</Style.Resources> |
|||
</Style> |
|||
@ -0,0 +1,15 @@ |
|||
<Style xmlns="https://github.com/avaloniaui" Selector="UserControl"> |
|||
<Setter Property="Template"> |
|||
<ControlTemplate> |
|||
<ContentPresenter Name="PART_ContentPresenter" |
|||
Background="{TemplateBinding Background}" |
|||
BorderBrush="{TemplateBinding BorderBrush}" |
|||
BorderThickness="{TemplateBinding BorderThickness}" |
|||
ContentTemplate="{TemplateBinding ContentTemplate}" |
|||
Content="{TemplateBinding Content}" |
|||
Padding="{TemplateBinding Padding}" |
|||
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" |
|||
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"/> |
|||
</ControlTemplate> |
|||
</Setter> |
|||
</Style> |
|||
@ -0,0 +1,98 @@ |
|||
using System.Collections.Generic; |
|||
using Avalonia.Collections; |
|||
using Avalonia.Media; |
|||
using Avalonia.Platform; |
|||
using Avalonia.Rendering; |
|||
using Avalonia.VisualTree; |
|||
using Moq; |
|||
using Xunit; |
|||
|
|||
namespace Avalonia.Visuals.UnitTests.Rendering |
|||
{ |
|||
public class ImmediateRendererTests |
|||
{ |
|||
[Fact] |
|||
public void AddDirty_Call_RenderRoot_Invalidate() |
|||
{ |
|||
var visual = new Mock<Visual>(); |
|||
var child = new Mock<Visual>() { CallBase = true }; |
|||
var renderRoot = visual.As<IRenderRoot>(); |
|||
|
|||
visual.As<IVisual>().Setup(v => v.Bounds).Returns(new Rect(0, 0, 400, 400)); |
|||
|
|||
child.As<IVisual>().Setup(v => v.Bounds).Returns(new Rect(10, 10, 100, 100)); |
|||
child.As<IVisual>().Setup(v => v.VisualParent).Returns(visual.Object); |
|||
|
|||
var target = new ImmediateRenderer(visual.Object); |
|||
|
|||
target.AddDirty(child.Object); |
|||
|
|||
renderRoot.Verify(v => v.Invalidate(new Rect(10, 10, 100, 100))); |
|||
} |
|||
|
|||
[Fact] |
|||
public void AddDirty_With_RenderTransform_Call_RenderRoot_Invalidate() |
|||
{ |
|||
var visual = new Mock<Visual>(); |
|||
var child = new Mock<Visual>() { CallBase = true }; |
|||
var renderRoot = visual.As<IRenderRoot>(); |
|||
|
|||
visual.As<IVisual>().Setup(v => v.Bounds).Returns(new Rect(0, 0, 400, 400)); |
|||
|
|||
child.As<IVisual>().Setup(v => v.Bounds).Returns(new Rect(100, 100, 100, 100)); |
|||
child.As<IVisual>().Setup(v => v.VisualParent).Returns(visual.Object); |
|||
child.Object.RenderTransform = new ScaleTransform() { ScaleX = 2, ScaleY = 2 }; |
|||
|
|||
var target = new ImmediateRenderer(visual.Object); |
|||
|
|||
target.AddDirty(child.Object); |
|||
|
|||
renderRoot.Verify(v => v.Invalidate(new Rect(50, 50, 200, 200))); |
|||
} |
|||
|
|||
[Fact] |
|||
public void AddDirty_For_Child_Moved_Should_Invalidate_Previous_Bounds() |
|||
{ |
|||
var visual = new Mock<Visual>() { CallBase = true }; |
|||
var child = new Mock<Visual>() { CallBase = true }; |
|||
var renderRoot = visual.As<IRenderRoot>(); |
|||
var renderTarget = visual.As<IRenderTarget>(); |
|||
|
|||
renderRoot.Setup(r => r.CreateRenderTarget()).Returns(renderTarget.Object); |
|||
renderTarget.Setup(r => r.CreateDrawingContext(It.IsAny<IVisualBrushRenderer>())).Returns(Mock.Of<IDrawingContextImpl>()); |
|||
|
|||
visual.As<IVisual>().Setup(v => v.Bounds).Returns(new Rect(0, 0, 400, 400)); |
|||
visual.As<IVisual>().Setup(v => v.VisualChildren).Returns(new AvaloniaList<IVisual>() { child.As<IVisual>().Object }); |
|||
|
|||
Rect childBounds = new Rect(0, 0, 100, 100); |
|||
child.As<IVisual>().Setup(v => v.Bounds).Returns(() => childBounds); |
|||
child.As<IVisual>().Setup(v => v.VisualParent).Returns(visual.Object); |
|||
child.As<IVisual>().Setup(v => v.VisualChildren).Returns(new AvaloniaList<IVisual>()); |
|||
|
|||
var invalidationCalls = new List<Rect>(); |
|||
|
|||
renderRoot.Setup(v => v.Invalidate(It.IsAny<Rect>())).Callback<Rect>(v => invalidationCalls.Add(v)); |
|||
|
|||
var target = new ImmediateRenderer(visual.Object); |
|||
|
|||
target.AddDirty(child.Object); |
|||
|
|||
Assert.Equal(new Rect(0, 0, 100, 100), invalidationCalls[0]); |
|||
|
|||
target.Paint(new Rect(0, 0, 100, 100)); |
|||
|
|||
//move child 100 pixels bottom/right
|
|||
childBounds = new Rect(100, 100, 100, 100); |
|||
|
|||
//renderer should invalidate old child bounds with new one
|
|||
//as on old area there can be artifacts
|
|||
target.AddDirty(child.Object); |
|||
|
|||
//invalidate first old position
|
|||
Assert.Equal(new Rect(0, 0, 100, 100), invalidationCalls[1]); |
|||
|
|||
//then new position
|
|||
Assert.Equal(new Rect(100, 100, 100, 100), invalidationCalls[2]); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue