Browse Source

Make mono stuff work (kinda) again.

pull/10/head
Steven Kirk 12 years ago
parent
commit
e34db29251
  1. 9
      Cairo/Perspex.Cairo/CairoExtensions.cs
  2. 11
      Cairo/Perspex.Cairo/CairoPlatform.cs
  3. 12
      Cairo/Perspex.Cairo/Media/DrawingContext.cs
  4. 97
      Cairo/Perspex.Cairo/Media/FormattedTextImpl.cs
  5. 1
      Cairo/Perspex.Cairo/Perspex.Cairo.csproj
  6. 6
      Gtk/Perspex.Gtk/Input/GtkKeyboardDevice.cs
  7. 2
      Perspex.SceneGraph/Media/TextHitTestResult.cs
  8. 1
      Windows/Perspex.Direct2D1/Media/FormattedTextImpl.cs

9
Cairo/Perspex.Cairo/CairoExtensions.cs

@ -24,5 +24,14 @@ namespace Perspex.Cairo
{
return new Cairo.Rectangle(rect.X, rect.Y, rect.Width, rect.Height);
}
public static Rect ToPerspex(this Pango.Rectangle rect)
{
return new Rect(
Pango.Units.ToDouble(rect.X),
Pango.Units.ToDouble(rect.Y),
Pango.Units.ToDouble(rect.Width),
Pango.Units.ToDouble(rect.Height));
}
}
}

11
Cairo/Perspex.Cairo/CairoPlatform.cs

@ -10,6 +10,7 @@ namespace Perspex.Cairo
using global::Cairo;
using Perspex.Cairo.Media;
using Perspex.Cairo.Media.Imaging;
using Perspex.Media;
using Perspex.Platform;
using Perspex.Threading;
using Splat;
@ -30,8 +31,18 @@ namespace Perspex.Cairo
////return new BitmapImpl(imagingFactory, width, height);
}
public IFormattedTextImpl CreateFormattedText(
string text,
string fontFamily,
double fontSize,
FontStyle fontStyle)
{
return new FormattedTextImpl(text, fontFamily, fontSize, fontStyle);
}
public IRenderer CreateRenderer(IPlatformHandle handle, double width, double height)
{
Locator.CurrentMutable.RegisterConstant(this.GetPangoContext(handle), typeof(Pango.Context));
return new Renderer(handle, width, height);
}

12
Cairo/Perspex.Cairo/Media/DrawingContext.cs

@ -133,14 +133,14 @@ namespace Perspex.Cairo.Media
/// Draws text.
/// </summary>
/// <param name="foreground">The foreground brush.</param>
/// <param name="rect">The output rectangle.</param>
/// <param name="origin">The upper-left corner of the text.</param>
/// <param name="text">The text.</param>
public void DrawText(Perspex.Media.Brush foreground, Rect rect, FormattedText text)
public void DrawText(Brush foreground, Point origin, FormattedText text)
{
////var layout = this.textService.CreateLayout(text);
////this.SetBrush(foreground);
////this.context.MoveTo(rect.X, rect.Y);
////Pango.CairoHelper.ShowLayout(this.context, layout);
var layout = ((FormattedTextImpl)text.PlatformImpl).Layout;
this.SetBrush(foreground);
this.context.MoveTo(origin.X, origin.Y);
Pango.CairoHelper.ShowLayout(this.context, layout);
}
/// <summary>

97
Cairo/Perspex.Cairo/Media/FormattedTextImpl.cs

@ -0,0 +1,97 @@
// -----------------------------------------------------------------------
// <copyright file="TextService.cs" company="Steven Kirk">
// Copyright 2014 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.Cairo.Media
{
using System;
using System.Collections.Generic;
using System.Linq;
using Perspex.Media;
using Perspex.Platform;
using Splat;
public class FormattedTextImpl : IFormattedTextImpl
{
public FormattedTextImpl(
string text,
string fontFamily,
double fontSize,
FontStyle fontStyle)
{
var context = Locator.Current.GetService<Pango.Context>();
this.Layout = new Pango.Layout(context);
this.Layout.SetText(text);
this.Layout.FontDescription = new Pango.FontDescription
{
Family = fontFamily,
Size = Pango.Units.FromDouble(fontSize),
Style = (Pango.Style)fontStyle,
};
}
public Size Constraint
{
get
{
return new Size(this.Layout.Width, double.PositiveInfinity);
}
set
{
this.Layout.Width = Pango.Units.FromDouble(value.Width);
}
}
public Pango.Layout Layout
{
get;
private set;
}
public void Dispose()
{
this.Layout.Dispose();
}
public TextHitTestResult HitTestPoint(Point point)
{
int textPosition;
int trailing;
var isInside = this.Layout.XyToIndex(
Pango.Units.FromDouble(point.X),
Pango.Units.FromDouble(point.Y),
out textPosition,
out trailing);
return new TextHitTestResult
{
IsInside = isInside,
TextPosition = textPosition,
IsTrailing = trailing == 0,
};
}
public Rect HitTestTextPosition(int index)
{
return this.Layout.IndexToPos(index).ToPerspex();
}
public IEnumerable<Rect> HitTestTextRange(int index, int length, Point origin)
{
// TODO: Implement.
return new Rect[0];
}
public Size Measure()
{
int width;
int height;
this.Layout.GetPixelSize(out width, out height);
return new Size(width, height);
}
}
}

1
Cairo/Perspex.Cairo/Perspex.Cairo.csproj

@ -67,6 +67,7 @@
<ItemGroup>
<Compile Include="CairoPlatform.cs" />
<Compile Include="Media\DrawingContext.cs" />
<Compile Include="Media\FormattedTextImpl.cs" />
<Compile Include="Media\Imaging\BitmapImpl.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Renderer.cs" />

6
Gtk/Perspex.Gtk/Input/GtkKeyboardDevice.cs

@ -29,7 +29,11 @@ namespace Perspex.Gtk
public override ModifierKeys Modifiers
{
get { throw new System.NotImplementedException(); }
get
{
// TODO: Implement.
return ModifierKeys.None;
}
}
public static Perspex.Input.Key ConvertKey(Gdk.Key key)

2
Perspex.SceneGraph/Media/TextHitTestResult.cs

@ -8,6 +8,8 @@ namespace Perspex.Media
{
public class TextHitTestResult
{
public bool IsInside { get; set; }
public int TextPosition { get; set; }
public bool IsTrailing { get; set; }

1
Windows/Perspex.Direct2D1/Media/FormattedTextImpl.cs

@ -70,6 +70,7 @@ namespace Perspex.Direct2D1.Media
return new TextHitTestResult
{
IsInside = isInside,
TextPosition = result.TextPosition,
IsTrailing = isTrailingHit,
};

Loading…
Cancel
Save