]>
Commit | Line | Data |
---|---|---|
9ce192d4 | 1 | // Scintilla source code edit control |
65ec6247 RD |
2 | /** @file Indicator.cxx |
3 | ** Defines the style of indicators which are text decorations such as underlining. | |
4 | **/ | |
5 | // Copyright 1998-2001 by Neil Hodgson <neilh@scintilla.org> | |
9ce192d4 RD |
6 | // The License.txt file describes the conditions under which this software may be distributed. |
7 | ||
1dcf666d RD |
8 | #include <vector> |
9 | #include <map> | |
10 | ||
9ce192d4 RD |
11 | #include "Platform.h" |
12 | ||
13 | #include "Scintilla.h" | |
1dcf666d | 14 | #include "XPM.h" |
9ce192d4 RD |
15 | #include "Indicator.h" |
16 | ||
7e0c58e9 RD |
17 | #ifdef SCI_NAMESPACE |
18 | using namespace Scintilla; | |
19 | #endif | |
20 | ||
8e54aaed | 21 | void Indicator::Draw(Surface *surface, const PRectangle &rc, const PRectangle &rcLine) { |
1dcf666d | 22 | surface->PenColour(fore); |
9ce192d4 RD |
23 | int ymid = (rc.bottom + rc.top) / 2; |
24 | if (style == INDIC_SQUIGGLE) { | |
25 | surface->MoveTo(rc.left, rc.top); | |
26 | int x = rc.left + 2; | |
27 | int y = 2; | |
28 | while (x < rc.right) { | |
29 | surface->LineTo(x, rc.top + y); | |
30 | x += 2; | |
31 | y = 2 - y; | |
32 | } | |
33 | surface->LineTo(rc.right, rc.top + y); // Finish the line | |
1dcf666d RD |
34 | } else if (style == INDIC_SQUIGGLELOW) { |
35 | surface->MoveTo(rc.left, rc.top); | |
36 | int x = rc.left + 3; | |
37 | int y = 0; | |
38 | while (x < rc.right) { | |
39 | surface->LineTo(x-1, rc.top + y); | |
40 | y = 1 - y; | |
41 | surface->LineTo(x, rc.top + y); | |
42 | x += 3; | |
43 | } | |
44 | surface->LineTo(rc.right, rc.top + y); // Finish the line | |
9ce192d4 RD |
45 | } else if (style == INDIC_TT) { |
46 | surface->MoveTo(rc.left, ymid); | |
47 | int x = rc.left + 5; | |
48 | while (x < rc.right) { | |
49 | surface->LineTo(x, ymid); | |
50 | surface->MoveTo(x-3, ymid); | |
51 | surface->LineTo(x-3, ymid+2); | |
52 | x++; | |
53 | surface->MoveTo(x, ymid); | |
54 | x += 5; | |
55 | } | |
56 | surface->LineTo(rc.right, ymid); // Finish the line | |
57 | if (x - 3 <= rc.right) { | |
58 | surface->MoveTo(x-3, ymid); | |
59 | surface->LineTo(x-3, ymid+2); | |
60 | } | |
f6bcfd97 BP |
61 | } else if (style == INDIC_DIAGONAL) { |
62 | int x = rc.left; | |
63 | while (x < rc.right) { | |
64 | surface->MoveTo(x, rc.top+2); | |
65 | int endX = x+3; | |
66 | int endY = rc.top - 1; | |
67 | if (endX > rc.right) { | |
68 | endY += endX - rc.right; | |
69 | endX = rc.right; | |
70 | } | |
71 | surface->LineTo(endX, endY); | |
72 | x += 4; | |
73 | } | |
74 | } else if (style == INDIC_STRIKE) { | |
75 | surface->MoveTo(rc.left, rc.top - 4); | |
76 | surface->LineTo(rc.right, rc.top - 4); | |
88a8b04e RD |
77 | } else if (style == INDIC_HIDDEN) { |
78 | // Draw nothing | |
8e54aaed RD |
79 | } else if (style == INDIC_BOX) { |
80 | surface->MoveTo(rc.left, ymid+1); | |
81 | surface->LineTo(rc.right, ymid+1); | |
82 | surface->LineTo(rc.right, rcLine.top+1); | |
83 | surface->LineTo(rc.left, rcLine.top+1); | |
84 | surface->LineTo(rc.left, ymid+1); | |
1dcf666d | 85 | } else if (style == INDIC_ROUNDBOX || style == INDIC_STRAIGHTBOX) { |
b8193d80 RD |
86 | PRectangle rcBox = rcLine; |
87 | rcBox.top = rcLine.top + 1; | |
88 | rcBox.left = rc.left; | |
89 | rcBox.right = rc.right; | |
1dcf666d RD |
90 | surface->AlphaRectangle(rcBox, (style == INDIC_ROUNDBOX) ? 1 : 0, fore, fillAlpha, fore, outlineAlpha, 0); |
91 | } else if (style == INDIC_DOTBOX) { | |
92 | PRectangle rcBox = rcLine; | |
93 | rcBox.top = rcLine.top + 1; | |
94 | rcBox.left = rc.left; | |
95 | rcBox.right = rc.right; | |
96 | // Cap width at 4000 to avoid large allocations when mistakes made | |
97 | int width = Platform::Minimum(rcBox.Width(), 4000); | |
98 | RGBAImage image(width, rcBox.Height(), 0); | |
99 | // Draw horizontal lines top and bottom | |
100 | for (int x=0; x<width; x++) { | |
101 | for (int y=0; y<rcBox.Height(); y += rcBox.Height()-1) { | |
102 | image.SetPixel(x, y, fore, ((x + y) % 2) ? outlineAlpha : fillAlpha); | |
103 | } | |
104 | } | |
105 | // Draw vertical lines left and right | |
106 | for (int y=1; y<rcBox.Height(); y++) { | |
107 | for (int x=0; x<width; x += width-1) { | |
108 | image.SetPixel(x, y, fore, ((x + y) % 2) ? outlineAlpha : fillAlpha); | |
109 | } | |
110 | } | |
111 | surface->DrawRGBAImage(rcBox, image.GetWidth(), image.GetHeight(), image.Pixels()); | |
112 | } else if (style == INDIC_DASH) { | |
113 | int x = rc.left; | |
114 | while (x < rc.right) { | |
115 | surface->MoveTo(x, ymid); | |
116 | surface->LineTo(Platform::Minimum(x + 4, rc.right), ymid); | |
117 | x += 7; | |
118 | } | |
119 | } else if (style == INDIC_DOTS) { | |
120 | int x = rc.left; | |
121 | while (x < rc.right) { | |
122 | PRectangle rcDot(x, ymid, x+1, ymid+1); | |
123 | surface->FillRectangle(rcDot, fore); | |
124 | x += 2; | |
125 | } | |
9ce192d4 RD |
126 | } else { // Either INDIC_PLAIN or unknown |
127 | surface->MoveTo(rc.left, ymid); | |
128 | surface->LineTo(rc.right, ymid); | |
129 | } | |
130 | } | |
131 |