From 8309adf6dac298b5c78b754f064bfdeb40e47933 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Fri, 25 Sep 2015 00:35:11 +0100 Subject: [PATCH 1/3] Implemented caret inverting background colour. --- src/Perspex.Controls/Presenters/TextPresenter.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Perspex.Controls/Presenters/TextPresenter.cs b/src/Perspex.Controls/Presenters/TextPresenter.cs index d594d6495b..4d1dccfb52 100644 --- a/src/Perspex.Controls/Presenters/TextPresenter.cs +++ b/src/Perspex.Controls/Presenters/TextPresenter.cs @@ -93,7 +93,17 @@ namespace Perspex.Controls.Presenters if (selectionStart == selectionEnd) { var charPos = FormattedText.HitTestTextPosition(CaretIndex); - Brush caretBrush = Brushes.Black; + + var background = this.GetVisualAncestors() + .OfType() + .FirstOrDefault(x => x.IsSet(BackgroundProperty)) + ?.GetValue(BackgroundProperty) as SolidColorBrush; + + byte red = (byte)~(background.Color.R); + byte green = (byte)~(background.Color.G); + byte blue = (byte)~(background.Color.B); + + var caretBrush = new SolidColorBrush(Color.FromRgb(red, green, blue)); if (_caretBlink) { From c56b7bd0ed3e7f10bdb7106e53a250aaf1caf893 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Fri, 25 Sep 2015 00:50:45 +0100 Subject: [PATCH 2/3] Implemented Caret inverting background colour, by finding templated parent. --- src/Perspex.Controls/Presenters/TextPresenter.cs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/Perspex.Controls/Presenters/TextPresenter.cs b/src/Perspex.Controls/Presenters/TextPresenter.cs index 4d1dccfb52..6aed45893e 100644 --- a/src/Perspex.Controls/Presenters/TextPresenter.cs +++ b/src/Perspex.Controls/Presenters/TextPresenter.cs @@ -94,14 +94,11 @@ namespace Perspex.Controls.Presenters { var charPos = FormattedText.HitTestTextPosition(CaretIndex); - var background = this.GetVisualAncestors() - .OfType() - .FirstOrDefault(x => x.IsSet(BackgroundProperty)) - ?.GetValue(BackgroundProperty) as SolidColorBrush; - - byte red = (byte)~(background.Color.R); - byte green = (byte)~(background.Color.G); - byte blue = (byte)~(background.Color.B); + var backgroundColor = (((Control)TemplatedParent).GetValue(BackgroundProperty) as SolidColorBrush).Color; + + byte red = (byte)~(backgroundColor.R); + byte green = (byte)~(backgroundColor.G); + byte blue = (byte)~(backgroundColor.B); var caretBrush = new SolidColorBrush(Color.FromRgb(red, green, blue)); From 65a133a440f772bad8604b0418ae892f942a702e Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Fri, 25 Sep 2015 01:02:30 +0100 Subject: [PATCH 3/3] Implemented caret inverting background color. --- src/Perspex.Controls/Presenters/TextPresenter.cs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Perspex.Controls/Presenters/TextPresenter.cs b/src/Perspex.Controls/Presenters/TextPresenter.cs index 6aed45893e..9679ba78a1 100644 --- a/src/Perspex.Controls/Presenters/TextPresenter.cs +++ b/src/Perspex.Controls/Presenters/TextPresenter.cs @@ -93,15 +93,19 @@ namespace Perspex.Controls.Presenters if (selectionStart == selectionEnd) { var charPos = FormattedText.HitTestTextPosition(CaretIndex); - - var backgroundColor = (((Control)TemplatedParent).GetValue(BackgroundProperty) as SolidColorBrush).Color; - byte red = (byte)~(backgroundColor.R); - byte green = (byte)~(backgroundColor.G); - byte blue = (byte)~(backgroundColor.B); + var backgroundColor = (((Control)TemplatedParent).GetValue(BackgroundProperty) as SolidColorBrush)?.Color; + var caretBrush = Brushes.Black; - var caretBrush = new SolidColorBrush(Color.FromRgb(red, green, blue)); + if(backgroundColor.HasValue) + { + byte red = (byte)~(backgroundColor.Value.R); + byte green = (byte)~(backgroundColor.Value.G); + byte blue = (byte)~(backgroundColor.Value.B); + caretBrush = new SolidColorBrush(Color.FromRgb(red, green, blue)); + } + if (_caretBlink) { var x = Math.Floor(charPos.X) + 0.5;