Browse Source

Adapted to drawing context changes

droid
Nikita Tsukanov 10 years ago
parent
commit
a02fb1308c
  1. 56
      src/Android/Perspex.Android/Rendering/DrawingContext.cs
  2. 4
      src/Android/Perspex.Android/Rendering/PerspexView.cs

56
src/Android/Perspex.Android/Rendering/DrawingContext.cs

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Disposables;
using Android.Graphics;
@ -12,11 +13,22 @@ using ATextAlign = Android.Graphics.Paint.Align;
namespace Perspex.Android.Rendering
{
public class DrawingContext : IDrawingContext
public class DrawingContext : IDrawingContextImpl
{
private static readonly BrushImpl FallbackBrush = new SolidColorBrushImpl(new SolidColorBrush(Colors.Magenta));
private float _currentOpacity = 1.0f;
private double _currentOpacity = 1.0f;
private double CurrentOpacity
{
get { return _currentOpacity; }
set
{
_currentOpacity = value;
_nativebrush.Alpha = (int) (_currentOpacity*255);
}
}
private TextPaint _nativebrush;
public Canvas Canvas;
@ -32,10 +44,17 @@ namespace Perspex.Android.Rendering
_nativebrush = null;
}
public Matrix CurrentTransform
Matrix _currentTransform = Matrix.Identity;
public Matrix Transform
{
get { return Canvas.Matrix.ToPerspex(); }
set { Canvas.Matrix = value.ToAndroidGraphics(); }
get { return _currentTransform; }
set
{
if(_currentTransform == value)
return;
_currentTransform = value;
Canvas.Matrix = value.ToAndroidGraphics();
}
}
public void DrawImage(IBitmap source, double opacity, Rect sourceRect, Rect destRect)
@ -125,33 +144,24 @@ namespace Perspex.Android.Rendering
}
}
public IDisposable PushClip(Rect clip)
public void PushClip(Rect clip)
{
Canvas.Save();
Canvas.ClipBounds.Set(clip.ToAndroidGraphics());
return Disposable.Create(() => Canvas.Restore());
}
public IDisposable PushOpacity(double opacity)
{
var previous = _currentOpacity;
_currentOpacity = (float) opacity;
_nativebrush.Alpha = (int) _currentOpacity;
public void PopClip() => Canvas.Restore();
return Disposable.Create(() =>
{
_currentOpacity = previous;
_nativebrush.Alpha = (int) _currentOpacity;
});
Stack<double> _opacityStack = new Stack<double>();
public void PushOpacity(double opacity)
{
_opacityStack.Push(_currentOpacity);
CurrentOpacity = CurrentOpacity*opacity;
}
public IDisposable PushTransform(Matrix matrix)
{
var oldMatrix = CurrentTransform;
CurrentTransform = oldMatrix*matrix;
public void PopOpacity() => CurrentOpacity = _opacityStack.Pop();
return Disposable.Create(() => { CurrentTransform = oldMatrix; });
}
private Path RoundRectPath(Rect rc, float radius)
{

4
src/Android/Perspex.Android/Rendering/PerspexView.cs

@ -35,9 +35,9 @@ namespace Perspex.Android.Rendering
IntPtr IPlatformHandle.Handle => Handle;
public string HandleDescriptor => "Perspex View";
public IDrawingContext CreateDrawingContext()
public Media.DrawingContext CreateDrawingContext()
{
return new DrawingContext();
return new Media.DrawingContext(new DrawingContext());
}
public void Resize(int width, int height)

Loading…
Cancel
Save