1 // Scintilla source code edit control
2 /** @file Indicator.cxx
3 ** Defines the style of indicators which are text decorations such as underlining.
5 // Copyright 1998-2001 by Neil Hodgson <neilh@scintilla.org>
6 // The License.txt file describes the conditions under which this software may be distributed.
12 #pragma warning(disable: 4786)
17 #include "Scintilla.h"
19 #include "Indicator.h"
22 using namespace Scintilla
;
25 void Indicator::Draw(Surface
*surface
, const PRectangle
&rc
, const PRectangle
&rcLine
) {
26 surface
->PenColour(fore
.allocated
);
27 int ymid
= (rc
.bottom
+ rc
.top
) / 2;
28 if (style
== INDIC_SQUIGGLE
) {
29 surface
->MoveTo(rc
.left
, rc
.top
);
32 while (x
< rc
.right
) {
33 surface
->LineTo(x
, rc
.top
+ y
);
37 surface
->LineTo(rc
.right
, rc
.top
+ y
); // Finish the line
38 } else if (style
== INDIC_SQUIGGLELOW
) {
39 surface
->MoveTo(rc
.left
, rc
.top
);
42 while (x
< rc
.right
) {
43 surface
->LineTo(x
-1, rc
.top
+ y
);
45 surface
->LineTo(x
, rc
.top
+ y
);
48 surface
->LineTo(rc
.right
, rc
.top
+ y
); // Finish the line
49 } else if (style
== INDIC_TT
) {
50 surface
->MoveTo(rc
.left
, ymid
);
52 while (x
< rc
.right
) {
53 surface
->LineTo(x
, ymid
);
54 surface
->MoveTo(x
-3, ymid
);
55 surface
->LineTo(x
-3, ymid
+2);
57 surface
->MoveTo(x
, ymid
);
60 surface
->LineTo(rc
.right
, ymid
); // Finish the line
61 if (x
- 3 <= rc
.right
) {
62 surface
->MoveTo(x
-3, ymid
);
63 surface
->LineTo(x
-3, ymid
+2);
65 } else if (style
== INDIC_DIAGONAL
) {
67 while (x
< rc
.right
) {
68 surface
->MoveTo(x
, rc
.top
+2);
70 int endY
= rc
.top
- 1;
71 if (endX
> rc
.right
) {
72 endY
+= endX
- rc
.right
;
75 surface
->LineTo(endX
, endY
);
78 } else if (style
== INDIC_STRIKE
) {
79 surface
->MoveTo(rc
.left
, rc
.top
- 4);
80 surface
->LineTo(rc
.right
, rc
.top
- 4);
81 } else if (style
== INDIC_HIDDEN
) {
83 } else if (style
== INDIC_BOX
) {
84 surface
->MoveTo(rc
.left
, ymid
+1);
85 surface
->LineTo(rc
.right
, ymid
+1);
86 surface
->LineTo(rc
.right
, rcLine
.top
+1);
87 surface
->LineTo(rc
.left
, rcLine
.top
+1);
88 surface
->LineTo(rc
.left
, ymid
+1);
89 } else if (style
== INDIC_ROUNDBOX
|| style
== INDIC_STRAIGHTBOX
) {
90 PRectangle rcBox
= rcLine
;
91 rcBox
.top
= rcLine
.top
+ 1;
93 rcBox
.right
= rc
.right
;
94 surface
->AlphaRectangle(rcBox
, (style
== INDIC_ROUNDBOX
) ? 1 : 0, fore
.allocated
, fillAlpha
, fore
.allocated
, outlineAlpha
, 0);
95 } else if (style
== INDIC_DOTBOX
) {
96 PRectangle rcBox
= rcLine
;
97 rcBox
.top
= rcLine
.top
+ 1;
99 rcBox
.right
= rc
.right
;
100 // Cap width at 4000 to avoid large allocations when mistakes made
101 int width
= Platform::Minimum(rcBox
.Width(), 4000);
102 RGBAImage
image(width
, rcBox
.Height(), 0);
103 // Draw horizontal lines top and bottom
104 for (int x
=0; x
<width
; x
++) {
105 for (int y
=0; y
<rcBox
.Height(); y
+= rcBox
.Height()-1) {
106 image
.SetPixel(x
, y
, fore
.desired
, ((x
+ y
) % 2) ? outlineAlpha
: fillAlpha
);
109 // Draw vertical lines left and right
110 for (int y
=1; y
<rcBox
.Height(); y
++) {
111 for (int x
=0; x
<width
; x
+= width
-1) {
112 image
.SetPixel(x
, y
, fore
.desired
, ((x
+ y
) % 2) ? outlineAlpha
: fillAlpha
);
115 surface
->DrawRGBAImage(rcBox
, image
.GetWidth(), image
.GetHeight(), image
.Pixels());
116 } else if (style
== INDIC_DASH
) {
118 while (x
< rc
.right
) {
119 surface
->MoveTo(x
, ymid
);
120 surface
->LineTo(Platform::Minimum(x
+ 4, rc
.right
), ymid
);
123 } else if (style
== INDIC_DOTS
) {
125 while (x
< rc
.right
) {
126 PRectangle
rcDot(x
, ymid
, x
+1, ymid
+1);
127 surface
->FillRectangle(rcDot
, fore
.allocated
);
130 } else { // Either INDIC_PLAIN or unknown
131 surface
->MoveTo(rc
.left
, ymid
);
132 surface
->LineTo(rc
.right
, ymid
);