updated Scintilla to 2.29
[TortoiseGit.git] / ext / scintilla / src / Indicator.cxx
blob6ab0d8a0273623187decdb07bf24c4443a14b195
1 // Scintilla source code edit control
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>
6 // The License.txt file describes the conditions under which this software may be distributed.
8 #include <vector>
9 #include <map>
11 #ifdef _MSC_VER
12 #pragma warning(disable: 4786)
13 #endif
15 #include "Platform.h"
17 #include "Scintilla.h"
18 #include "XPM.h"
19 #include "Indicator.h"
21 #ifdef SCI_NAMESPACE
22 using namespace Scintilla;
23 #endif
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);
30 int x = rc.left + 2;
31 int y = 2;
32 while (x < rc.right) {
33 surface->LineTo(x, rc.top + y);
34 x += 2;
35 y = 2 - 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);
40 int x = rc.left + 3;
41 int y = 0;
42 while (x < rc.right) {
43 surface->LineTo(x-1, rc.top + y);
44 y = 1 - y;
45 surface->LineTo(x, rc.top + y);
46 x += 3;
48 surface->LineTo(rc.right, rc.top + y); // Finish the line
49 } else if (style == INDIC_TT) {
50 surface->MoveTo(rc.left, ymid);
51 int x = rc.left + 5;
52 while (x < rc.right) {
53 surface->LineTo(x, ymid);
54 surface->MoveTo(x-3, ymid);
55 surface->LineTo(x-3, ymid+2);
56 x++;
57 surface->MoveTo(x, ymid);
58 x += 5;
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) {
66 int x = rc.left;
67 while (x < rc.right) {
68 surface->MoveTo(x, rc.top+2);
69 int endX = x+3;
70 int endY = rc.top - 1;
71 if (endX > rc.right) {
72 endY += endX - rc.right;
73 endX = rc.right;
75 surface->LineTo(endX, endY);
76 x += 4;
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) {
82 // Draw nothing
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;
92 rcBox.left = rc.left;
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;
98 rcBox.left = rc.left;
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) {
117 int x = rc.left;
118 while (x < rc.right) {
119 surface->MoveTo(x, ymid);
120 surface->LineTo(Platform::Minimum(x + 4, rc.right), ymid);
121 x += 7;
123 } else if (style == INDIC_DOTS) {
124 int x = rc.left;
125 while (x < rc.right) {
126 PRectangle rcDot(x, ymid, x+1, ymid+1);
127 surface->FillRectangle(rcDot, fore.allocated);
128 x += 2;
130 } else { // Either INDIC_PLAIN or unknown
131 surface->MoveTo(rc.left, ymid);
132 surface->LineTo(rc.right, ymid);