diff options
author | Mike Krüger <mkrueger@xamarin.com> | 2013-08-11 09:54:52 +0400 |
---|---|---|
committer | Mike Krüger <mkrueger@xamarin.com> | 2013-08-11 09:54:52 +0400 |
commit | 18abf23d043d68087c0bfaaf45dacfba847c4dbb (patch) | |
tree | ccea66212638ae7523d459b7265b10cdd06a3946 /main/src/addins/MonoDevelop.HexEditor | |
parent | ceebcf6594fad37f3f2c049e7d9a379a7176d9b4 (diff) |
[HexEditor] Fixed caret painting.
Diffstat (limited to 'main/src/addins/MonoDevelop.HexEditor')
3 files changed, 28 insertions, 15 deletions
diff --git a/main/src/addins/MonoDevelop.HexEditor/Mono.MHex.Rendering/HexEditorMargin.cs b/main/src/addins/MonoDevelop.HexEditor/Mono.MHex.Rendering/HexEditorMargin.cs index a9ae4d100d..0d64e497e2 100644 --- a/main/src/addins/MonoDevelop.HexEditor/Mono.MHex.Rendering/HexEditorMargin.cs +++ b/main/src/addins/MonoDevelop.HexEditor/Mono.MHex.Rendering/HexEditorMargin.cs @@ -123,9 +123,9 @@ namespace Mono.MHex.Rendering ctx.Fill (); LayoutWrapper layout = GetLayout (line); - + char ch; if (!Data.IsSomethingSelected && Caret.InTextEditor && line == Data.Caret.Line) { - ctx.Rectangle (CalculateCaretXPos (false), y, byteWidth, Editor.LineHeight); + ctx.Rectangle (CalculateCaretXPos (false, out ch), y, byteWidth, Editor.LineHeight); ctx.SetColor (Style.HighlightOffset); ctx.Fill (); @@ -136,11 +136,11 @@ namespace Mono.MHex.Rendering layout.Dispose (); } - public double CalculateCaretXPos () + public double CalculateCaretXPos (out char ch) { - return CalculateCaretXPos (true); + return CalculateCaretXPos (true, out ch); } - double CalculateCaretXPos (bool useSubPositon) + double CalculateCaretXPos (bool useSubPositon, out char ch) { int byteInRow = (int)Caret.Offset % BytesInRow; int groupNumber = byteInRow / Editor.Options.GroupBytes; @@ -150,6 +150,7 @@ namespace Mono.MHex.Rendering caretIndex += Caret.SubPosition; LayoutWrapper layout = GetLayout ((int)Caret.Line); var rectangle = layout.Layout.GetCoordinateFromIndex (caretIndex); + ch = layout.Layout.Text [caretIndex]; if (layout.IsUncached) layout.Dispose (); return XOffset + rectangle.X / 1024.0; // FIX XWT !!!! Pango.Scale bug diff --git a/main/src/addins/MonoDevelop.HexEditor/Mono.MHex.Rendering/TextEditorMargin.cs b/main/src/addins/MonoDevelop.HexEditor/Mono.MHex.Rendering/TextEditorMargin.cs index 15ea5e8c3b..d86619bd3e 100644 --- a/main/src/addins/MonoDevelop.HexEditor/Mono.MHex.Rendering/TextEditorMargin.cs +++ b/main/src/addins/MonoDevelop.HexEditor/Mono.MHex.Rendering/TextEditorMargin.cs @@ -111,8 +111,16 @@ namespace Mono.MHex.Rendering layout.Dispose (); } - public double CalculateCaretXPos () + public double CalculateCaretXPos (out char ch) { + byte b = Data.GetByte (Caret.Offset); + ch = (char)b; + if (b < 128 && (Char.IsLetterOrDigit (ch) || Char.IsPunctuation (ch))) { + // ok + } else { + ch = '.'; + } + return XOffset + (Caret.Offset % BytesInRow) * charWidth; } diff --git a/main/src/addins/MonoDevelop.HexEditor/Mono.MHex/HexEditor.cs b/main/src/addins/MonoDevelop.HexEditor/Mono.MHex/HexEditor.cs index 0cef984c4a..b21270983b 100644 --- a/main/src/addins/MonoDevelop.HexEditor/Mono.MHex/HexEditor.cs +++ b/main/src/addins/MonoDevelop.HexEditor/Mono.MHex/HexEditor.cs @@ -472,7 +472,7 @@ namespace Mono.MHex StopCaretThread (); if (caretTimer == null) { - caretTimer = new Timer (400); + caretTimer = new Timer (800); caretTimer.Elapsed += UpdateCaret; } caretBlink = true; @@ -516,17 +516,13 @@ namespace Mono.MHex { if (!caretBlink || HexEditorData.IsSomethingSelected) return; - /*if (caretGc == null) { - caretGc = new Gdk.GC (win); - caretGc.RgbFgColor = new Color (255, 255, 255); - caretGc.Function = Gdk.Function.Xor; - }*/ long caretY = HexEditorData.Caret.Line * LineHeight - (long)HexEditorData.VAdjustment.Value; double caretX; + char ch; if (HexEditorData.Caret.InTextEditor) { - caretX = textEditorMargin.CalculateCaretXPos (); + caretX = textEditorMargin.CalculateCaretXPos (out ch); } else { - caretX = hexEditorMargin.CalculateCaretXPos (); + caretX = hexEditorMargin.CalculateCaretXPos (out ch); } if (!area.Contains (caretX, (int)caretY)) @@ -537,8 +533,16 @@ namespace Mono.MHex } else { ctx.Rectangle (caretX, (int)caretY, textEditorMargin.charWidth, LineHeight); } - ctx.SetColor (new Color (0, 0, 0)); + + ctx.SetColor (HexEditorStyle.HexDigit); ctx.Fill (); + + using (var layout = new TextLayout (this)) { + layout.Font = Options.Font; + layout.Text = ch.ToString (); + ctx.SetColor (HexEditorStyle.HexDigitBg); + ctx.DrawTextLayout (layout, caretX, caretY); + } } public void ScrollToCaret () |