diff --git a/Cairo/Perspex.Cairo/Media/Imaging/BitmapImpl.cs b/Cairo/Perspex.Cairo/Media/Imaging/BitmapImpl.cs index 1b87ee8fd5..ca36fd7c4d 100644 --- a/Cairo/Perspex.Cairo/Media/Imaging/BitmapImpl.cs +++ b/Cairo/Perspex.Cairo/Media/Imaging/BitmapImpl.cs @@ -1,42 +1,42 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Cairo.Media.Imaging -{ - using System; - using Perspex.Platform; - using Cairo = global::Cairo; - - public class BitmapImpl : IBitmapImpl - { - - public BitmapImpl(Cairo.ImageSurface surface) - { - this.Surface = surface; - } - - public int PixelWidth - { - get { return this.Surface.Width; } - } - - public int PixelHeight - { - get { return this.Surface.Height; } - } - - public Cairo.ImageSurface Surface - { - get; - private set; - } - - public void Save(string fileName) - { - throw new NotImplementedException(); - } - } -} +// ----------------------------------------------------------------------- +// +// Copyright 2014 MIT Licence. See licence.md for more information. +// +// ----------------------------------------------------------------------- + +namespace Perspex.Cairo.Media.Imaging +{ + using System; + using Perspex.Platform; + using Cairo = global::Cairo; + + public class BitmapImpl : IBitmapImpl + { + + public BitmapImpl(Cairo.ImageSurface surface) + { + this.Surface = surface; + } + + public int PixelWidth + { + get { return this.Surface.Width; } + } + + public int PixelHeight + { + get { return this.Surface.Height; } + } + + public Cairo.ImageSurface Surface + { + get; + private set; + } + + public void Save(string fileName) + { + throw new NotImplementedException(); + } + } +} diff --git a/Perspex.Controls/TextBoxView.cs b/Perspex.Controls/TextBoxView.cs index a723395476..2a3a443939 100644 --- a/Perspex.Controls/TextBoxView.cs +++ b/Perspex.Controls/TextBoxView.cs @@ -1,126 +1,126 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2013 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Controls -{ - using System; - using Perspex.Media; - using Perspex.Platform; - using Perspex.Threading; - using Splat; - - internal class TextBoxView : Control - { - private TextBox parent; - - private FormattedText formattedText; - - private DispatcherTimer caretTimer; - - private bool caretBlink; - - public TextBoxView(TextBox parent) - { - this.caretTimer = new DispatcherTimer(); - this.caretTimer.Interval = TimeSpan.FromMilliseconds(500); - this.caretTimer.Tick += this.CaretTimerTick; - this.parent = parent; - } - - public FormattedText FormattedText - { - get - { - if (this.formattedText == null) - { - this.formattedText = this.CreateFormattedText(); - } - - return this.formattedText; - } - } - - public new void GotFocus() - { - this.caretBlink = true; - this.caretTimer.Start(); - } - - public new void LostFocus() - { - this.caretTimer.Stop(); - this.InvalidateVisual(); - } - - public void InvalidateText() - { - this.formattedText = null; - this.InvalidateMeasure(); - } - - internal void CaretMoved() - { - this.caretBlink = true; - this.caretTimer.Stop(); - this.caretTimer.Start(); - this.InvalidateVisual(); - } - - public override void Render(IDrawingContext context) - { - Rect rect = new Rect(this.ActualSize); - - context.DrawText(Brushes.Black, rect, this.FormattedText); - - if (this.parent.IsFocused) - { - ITextService textService = Locator.Current.GetService(); - Point caretPos = textService.GetCaretPosition( - this.formattedText, - this.parent.CaretIndex, - this.ActualSize); - double[] lineHeights = textService.GetLineHeights(this.formattedText, this.ActualSize); - Brush caretBrush = Brushes.Black; - - if (this.caretBlink) - { - context.DrawLine( - new Pen(caretBrush, 1), - caretPos, - new Point(caretPos.X, caretPos.Y + lineHeights[0])); - } - } - } - - protected override Size MeasureOverride(Size constraint) - { - if (!string.IsNullOrEmpty(this.parent.Text)) - { - ITextService textService = Locator.Current.GetService(); - return textService.Measure(this.FormattedText, constraint); - } - - return new Size(); - } - - private FormattedText CreateFormattedText() - { - return new FormattedText - { - FontFamilyName = "Segoe UI", - FontSize = this.GetValue(TextBlock.FontSizeProperty), - FontStyle = this.GetValue(TextBlock.FontStyleProperty), - Text = this.parent.Text, - }; - } - - private void CaretTimerTick(object sender, EventArgs e) - { - this.caretBlink = !this.caretBlink; - this.InvalidateVisual(); - } - } -} +// ----------------------------------------------------------------------- +// +// Copyright 2013 MIT Licence. See licence.md for more information. +// +// ----------------------------------------------------------------------- + +namespace Perspex.Controls +{ + using System; + using Perspex.Media; + using Perspex.Platform; + using Perspex.Threading; + using Splat; + + internal class TextBoxView : Control + { + private TextBox parent; + + private FormattedText formattedText; + + private DispatcherTimer caretTimer; + + private bool caretBlink; + + public TextBoxView(TextBox parent) + { + this.caretTimer = new DispatcherTimer(); + this.caretTimer.Interval = TimeSpan.FromMilliseconds(500); + this.caretTimer.Tick += this.CaretTimerTick; + this.parent = parent; + } + + public FormattedText FormattedText + { + get + { + if (this.formattedText == null) + { + this.formattedText = this.CreateFormattedText(); + } + + return this.formattedText; + } + } + + public new void GotFocus() + { + this.caretBlink = true; + this.caretTimer.Start(); + } + + public new void LostFocus() + { + this.caretTimer.Stop(); + this.InvalidateVisual(); + } + + public void InvalidateText() + { + this.formattedText = null; + this.InvalidateMeasure(); + } + + internal void CaretMoved() + { + this.caretBlink = true; + this.caretTimer.Stop(); + this.caretTimer.Start(); + this.InvalidateVisual(); + } + + public override void Render(IDrawingContext context) + { + Rect rect = new Rect(this.ActualSize); + + context.DrawText(Brushes.Black, rect, this.FormattedText); + + if (this.parent.IsFocused) + { + ITextService textService = Locator.Current.GetService(); + Point caretPos = textService.GetCaretPosition( + this.formattedText, + this.parent.CaretIndex, + this.ActualSize); + double[] lineHeights = textService.GetLineHeights(this.formattedText, this.ActualSize); + Brush caretBrush = Brushes.Black; + + if (this.caretBlink) + { + context.DrawLine( + new Pen(caretBrush, 1), + caretPos, + new Point(caretPos.X, caretPos.Y + lineHeights[0])); + } + } + } + + protected override Size MeasureOverride(Size constraint) + { + if (!string.IsNullOrEmpty(this.parent.Text)) + { + ITextService textService = Locator.Current.GetService(); + return textService.Measure(this.FormattedText, constraint); + } + + return new Size(); + } + + private FormattedText CreateFormattedText() + { + return new FormattedText + { + FontFamilyName = "Segoe UI", + FontSize = this.GetValue(TextBlock.FontSizeProperty), + FontStyle = this.GetValue(TextBlock.FontStyleProperty), + Text = this.parent.Text, + }; + } + + private void CaretTimerTick(object sender, EventArgs e) + { + this.caretBlink = !this.caretBlink; + this.InvalidateVisual(); + } + } +} diff --git a/Perspex.SceneGraph/Platform/ITextService.cs b/Perspex.SceneGraph/Platform/ITextService.cs index 9422f1c392..d4eadd7b91 100644 --- a/Perspex.SceneGraph/Platform/ITextService.cs +++ b/Perspex.SceneGraph/Platform/ITextService.cs @@ -1,21 +1,21 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Platform -{ - using Perspex.Media; - - public interface ITextService - { - int GetCaretIndex(FormattedText text, Point point, Size constraint); - - Point GetCaretPosition(FormattedText text, int caretIndex, Size constraint); - - double[] GetLineHeights(FormattedText text, Size constraint); - - Size Measure(FormattedText text, Size constraint); - } -} +// ----------------------------------------------------------------------- +// +// Copyright 2014 MIT Licence. See licence.md for more information. +// +// ----------------------------------------------------------------------- + +namespace Perspex.Platform +{ + using Perspex.Media; + + public interface ITextService + { + int GetCaretIndex(FormattedText text, Point point, Size constraint); + + Point GetCaretPosition(FormattedText text, int caretIndex, Size constraint); + + double[] GetLineHeights(FormattedText text, Size constraint); + + Size Measure(FormattedText text, Size constraint); + } +}