aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2014-03-26 10:07:32 +1100
committerNeil <nyamatongwe@gmail.com>2014-03-26 10:07:32 +1100
commit7617b84467db2acec9de99a2a2e800f3d59689d5 (patch)
treee525d0a96e6e183cf0c63adfc27affc4601741e6 /src
parent907de3d67de5e1365d7c93c597dcfd9ae7373351 (diff)
downloadscintilla-mirror-7617b84467db2acec9de99a2a2e800f3d59689d5.tar.gz
Bug [#1588]. Round caret positions to the pixel grid instead of truncating.
This may move the caret to the right 1 pixel in some situations. While sometimes this appears a little worse, on average it is slightly better than the precious code, with carets appearing inside the previous character less often.
Diffstat (limited to 'src')
-rw-r--r--src/Editor.cxx12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/Editor.cxx b/src/Editor.cxx
index c340bedf2..6c29e7100 100644
--- a/src/Editor.cxx
+++ b/src/Editor.cxx
@@ -88,6 +88,10 @@ Timer::Timer() :
Idler::Idler() :
state(false), idlerID(0) {}
+static int RoundXYPosition(XYPOSITION xyPos) {
+ return int(xyPos+0.5);
+}
+
static inline bool IsControlCharacter(int ch) {
// iscntrl returns true for lots of chars > 127 which are displayable
return ch >= 0 && ch < ' ';
@@ -3417,7 +3421,7 @@ void Editor::DrawCarets(Surface *surface, ViewStyle &vsDraw, int lineDoc, int xS
bool caretAtEOL = false;
bool drawBlockCaret = false;
XYPOSITION widthOverstrikeCaret;
- int caretWidthOffset = 0;
+ XYPOSITION caretWidthOffset = 0;
PRectangle rcCaret = rcLine;
if (posCaret.Position() == pdoc->Length()) { // At end of document
@@ -3433,11 +3437,11 @@ void Editor::DrawCarets(Surface *surface, ViewStyle &vsDraw, int lineDoc, int xS
widthOverstrikeCaret = 3;
if (xposCaret > 0)
- caretWidthOffset = 1; // Move back so overlaps both character cells.
+ caretWidthOffset = 0.51f; // Move back so overlaps both character cells.
xposCaret += xStart;
if (posDrag.IsValid()) {
/* Dragging text, use a line caret */
- rcCaret.left = xposCaret - caretWidthOffset;
+ rcCaret.left = RoundXYPosition(xposCaret - caretWidthOffset);
rcCaret.right = rcCaret.left + vsDraw.caretWidth;
} else if (inOverstrike && drawOverstrikeCaret) {
/* Overstrike (insert mode), use a modified bar caret */
@@ -3455,7 +3459,7 @@ void Editor::DrawCarets(Surface *surface, ViewStyle &vsDraw, int lineDoc, int xS
}
} else {
/* Line caret */
- rcCaret.left = xposCaret - caretWidthOffset;
+ rcCaret.left = RoundXYPosition(xposCaret - caretWidthOffset);
rcCaret.right = rcCaret.left + vsDraw.caretWidth;
}
ColourDesired caretColour = mainCaret ? vsDraw.caretcolour : vsDraw.additionalCaretColour;