Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrating to Avalonia 0.10.0-preview1 #6

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Adapters/AvaloniaAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ protected override RBrush CreateLinearGradientBrush(RRect rect, RColor color1, R
{
StartPoint = new RelativePoint(x, y, RelativeUnit.Relative),
EndPoint = new RelativePoint(1 - x, 1 - y, RelativeUnit.Relative),
GradientStops = new[]
GradientStops = new GradientStops
{
new GradientStop(startColor, 0),
new GradientStop(endColor, 1)
Expand Down
5 changes: 3 additions & 2 deletions Adapters/ControlAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ public override RPoint MouseLocation
{
get
{
var pos = (_control.GetVisualRoot() as IInputRoot)?.MouseDevice?.Position ?? default(Point);
return Util.Convert(pos);
var pos = (_control.GetVisualRoot() as IInputRoot)?.MouseDevice?.Position;
//TODO: DPI
return Util.Convert(pos.Value.ToPointWithDpi(96));
}
}

Expand Down
18 changes: 10 additions & 8 deletions Adapters/GraphicsAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ public override void ReturnPreviousSmoothingMode(Object prevMode)
public override RSize MeasureString(string str, RFont font)
{
var text = GetText(str, font);
var measure = text.Measure();
return new RSize(measure.Width, measure.Height);
return new RSize(text.Bounds.Width, text.Bounds.Height);

}

Expand All @@ -120,14 +119,15 @@ FormattedText GetText(string str, RFont font)
return new FormattedText
{
Text = str,
Typeface = new Typeface(f.Name, font.Size, f.FontStyle, f.Weight),
Typeface = new Typeface(f.Name, f.FontStyle, f.Weight),
FontSize = font.Size
};
}

public override void MeasureString(string str, RFont font, double maxWidth, out int charFit, out double charFitWidth)
{
var text = GetText(str, font);
var fullLength = text.Measure().Width;
var fullLength = text.Bounds.Width;
if (fullLength < maxWidth)
{
charFitWidth = fullLength;
Expand All @@ -140,7 +140,7 @@ public override void MeasureString(string str, RFont font, double maxWidth, out
BinarySearch(len =>
{
text = GetText(str.Substring(0, len), font);
var size = text.Measure().Width;
var size = text.Bounds.Width;
lastMeasure = size;
lastLen = len;
if (size <= maxWidth)
Expand All @@ -151,7 +151,7 @@ public override void MeasureString(string str, RFont font, double maxWidth, out
if (lastMeasure > maxWidth)
{
lastLen--;
lastMeasure = GetText(str.Substring(0, lastLen), font).Measure().Width;
lastMeasure = GetText(str.Substring(0, lastLen), font).Bounds.Width;
}
charFit = lastLen;
charFitWidth = lastMeasure;
Expand Down Expand Up @@ -253,12 +253,14 @@ public override void DrawRectangle(RBrush brush, double x, double y, double widt

public override void DrawImage(RImage image, RRect destRect, RRect srcRect)
{
_g.DrawImage(((ImageAdapter) image).Image, 1, Util.Convert(srcRect), Util.Convert(destRect));
_g.PushOpacity(1);
_g.DrawImage(((ImageAdapter)image).Image, Util.Convert(srcRect), Util.Convert(destRect));
}

public override void DrawImage(RImage image, RRect destRect)
{
_g.DrawImage(((ImageAdapter) image).Image, 1, new Rect(0, 0, image.Width, image.Height),
_g.PushOpacity(1);
_g.DrawImage(((ImageAdapter)image).Image, new Rect(0, 0, image.Width, image.Height),
Util.Convert(destRect));
}

Expand Down
4 changes: 2 additions & 2 deletions Adapters/ImageAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public ImageAdapter(Bitmap image)
/// </summary>
public Bitmap Image => _image;

public override double Width => _image.PixelWidth;
public override double Width => _image.PixelSize.Width;

public override double Height => _image.PixelHeight;
public override double Height => _image.PixelSize.Height;

public override void Dispose()
{
Expand Down
21 changes: 7 additions & 14 deletions Adapters/PenAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,7 @@ internal sealed class PenAdapter : RPen
/// </summary>
private readonly IBrush _brush;

/// <summary>
/// the width of the pen
/// </summary>
private double _width;

private DashStyle _dashStyle;
private IDashStyle _dashStyle;

/// <summary>
/// the dash style of the pen
Expand All @@ -47,18 +42,17 @@ public PenAdapter(IBrush brush)
_brush = brush;
}

public override double Width
{
get { return _width; }
set { _width = value; }
}
/// <summary>
/// the width of the pen
/// </summary>
public override double Width { get; set; }

public override RDashStyle DashStyle
{
set { DashStyles.TryGetValue(value, out _dashStyle); }
}

private static readonly Dictionary<RDashStyle, DashStyle> DashStyles = new Dictionary<RDashStyle, DashStyle>
private static readonly Dictionary<RDashStyle, IDashStyle> DashStyles = new Dictionary<RDashStyle, IDashStyle>
{
{RDashStyle.Solid,null },
{RDashStyle.Dash, global::Avalonia.Media.DashStyle.Dash },
Expand All @@ -72,8 +66,7 @@ public override RDashStyle DashStyle
/// </summary>
public Pen CreatePen()
{
var pen = new Pen(_brush, _width, _dashStyle);
return pen;
return new Pen(_brush, Width, _dashStyle);
}
}
}
2 changes: 1 addition & 1 deletion Avalonia.HtmlRenderer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,6 @@
<Compile Include="Utilities\Util.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.6.1" />
<PackageReference Include="Avalonia" Version="0.10.0-preview1" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion HtmlControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ protected virtual void InvokeMouseMove()
/// <summary>
/// Handle when dependency property value changes to update the underline HtmlContainer with the new value.
/// </summary>
private static void OnAvaloniaProperty_valueChanged(AvaloniaObject AvaloniaObject,
private static void OnAvaloniaProperty_valueChanged(IAvaloniaObject AvaloniaObject,
AvaloniaPropertyChangedEventArgs e)
{
var control = AvaloniaObject as HtmlControl;
Expand Down
2 changes: 1 addition & 1 deletion HtmlLabel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ protected override Size MeasureOverride(Size constraint)
/// <summary>
/// Handle when dependency property value changes to update the underline HtmlContainer with the new value.
/// </summary>
private static void OnAvaloniaProperty_valueChanged(AvaloniaObject AvaloniaObject, AvaloniaPropertyChangedEventArgs e)
private static void OnAvaloniaProperty_valueChanged(IAvaloniaObject AvaloniaObject, AvaloniaPropertyChangedEventArgs e)
{
var control = AvaloniaObject as HtmlLabel;
if (control != null)
Expand Down
2 changes: 1 addition & 1 deletion PropertyHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Avalonia.HtmlRenderer
static class PropertyHelper
{

public static AvaloniaProperty Register<TOwner, T>(string name, T def, Action<AvaloniaObject, AvaloniaPropertyChangedEventArgs> changed) where TOwner : AvaloniaObject
public static AvaloniaProperty Register<TOwner, T>(string name, T def, Action<IAvaloniaObject, AvaloniaPropertyChangedEventArgs> changed) where TOwner : AvaloniaObject
{
var pp = AvaloniaProperty.Register<TOwner, T>(name, def);
Action<AvaloniaPropertyChangedEventArgs> cb = args =>
Expand Down