aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/PositionCache.cxx
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2014-02-26 12:08:20 +1100
committerNeil <nyamatongwe@gmail.com>2014-02-26 12:08:20 +1100
commit1f51cbbccab97cb10f1cbf63b422c6a9cb4dfa78 (patch)
tree6a64fc8a895321291bea24a95988b43a8635c722 /src/PositionCache.cxx
parentebba676e693c952b36546bff7870602f3b269b7f (diff)
downloadscintilla-mirror-1f51cbbccab97cb10f1cbf63b422c6a9cb4dfa78.tar.gz
Refactor methods for converting screen points to and from document index, moving code
from Editor to LineLayout.
Diffstat (limited to 'src/PositionCache.cxx')
-rw-r--r--src/PositionCache.cxx44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/PositionCache.cxx b/src/PositionCache.cxx
index db64b1160..90a3f02f0 100644
--- a/src/PositionCache.cxx
+++ b/src/PositionCache.cxx
@@ -132,6 +132,10 @@ int LineLayout::LineLastVisible(int line) const {
}
}
+Range LineLayout::SubLineRange(int subLine) const {
+ return Range(LineStart(subLine), LineLastVisible(subLine));
+}
+
bool LineLayout::InLine(int offset, int line) const {
return ((offset >= LineStart(line)) && (offset < LineStart(line + 1))) ||
((offset == numCharsInLine) && (line == (lines-1)));
@@ -205,6 +209,46 @@ int LineLayout::FindBefore(XYPOSITION x, int lower, int upper) const {
return lower;
}
+
+int LineLayout::FindPositionFromX(XYPOSITION x, Range range, bool charPosition) const {
+ int pos = FindBefore(x, range.start, range.end);
+ while (pos < range.end) {
+ if (charPosition) {
+ if (x < (positions[pos + 1])) {
+ return pos;
+ }
+ } else {
+ if (x < ((positions[pos] + positions[pos + 1]) / 2)) {
+ return pos;
+ }
+ }
+ pos++;
+ }
+ return range.end;
+}
+
+Point LineLayout::PointFromPosition(int posInLine, int lineHeight) const {
+ Point pt;
+ // In case of very long line put x at arbitrary large position
+ if (posInLine > maxLineLength) {
+ pt.x = positions[maxLineLength] - positions[LineStart(lines)];
+ }
+
+ for (int subLine = 0; subLine < lines; subLine++) {
+ const Range rangeSubLine = SubLineRange(subLine);
+ if (posInLine >= rangeSubLine.start) {
+ pt.y = subLine*lineHeight;
+ if (posInLine <= rangeSubLine.end) {
+ pt.x = positions[posInLine] - positions[rangeSubLine.start];
+ if (rangeSubLine.start != 0) // Wrapped lines may be indented
+ pt.x += wrapIndent;
+ break;
+ }
+ }
+ }
+ return pt;
+}
+
int LineLayout::EndLineStyle() const {
return styles[numCharsBeforeEOL > 0 ? numCharsBeforeEOL-1 : 0];
}