Wed, 27 Jan 2021 19:28:18 +0200
updated copyright year
46
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1 | /* |
190 | 2 | Copyright 2014 - 2021 Teemu Piippo |
46
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
3 | All rights reserved. |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
4 | |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
5 | Redistribution and use in source and binary forms, with or without |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
6 | modification, are permitted provided that the following conditions |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
7 | are met: |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
8 | |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
9 | 1. Redistributions of source code must retain the above copyright |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
10 | notice, this list of conditions and the following disclaimer. |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
11 | 2. Redistributions in binary form must reproduce the above copyright |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
12 | notice, this list of conditions and the following disclaimer in the |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
13 | documentation and/or other materials provided with the distribution. |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
14 | 3. Neither the name of the copyright holder nor the names of its |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
15 | contributors may be used to endorse or promote products derived from |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
16 | this software without specific prior written permission. |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
17 | |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
20 | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
21 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
22 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
23 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
24 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
25 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
26 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
27 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
29 | */ |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
30 | |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
31 | #include "coloredline.h" |
88
08ccaf26cffd
Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents:
87
diff
changeset
|
32 | BEGIN_ZFC_NAMESPACE |
46
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
33 | |
87
53c2aecb9704
some work on MSVC support (still doesn't work yet...)
Teemu Piippo <tsapii@utu.fi>
parents:
73
diff
changeset
|
34 | struct ColorCodeInfo |
63
0da5f358f298
- now supports upper-case color codes too
Teemu Piippo <crimsondusk64@gmail.com>
parents:
48
diff
changeset
|
35 | { |
0da5f358f298
- now supports upper-case color codes too
Teemu Piippo <crimsondusk64@gmail.com>
parents:
48
diff
changeset
|
36 | const char* name; |
0da5f358f298
- now supports upper-case color codes too
Teemu Piippo <crimsondusk64@gmail.com>
parents:
48
diff
changeset
|
37 | Color color; |
0da5f358f298
- now supports upper-case color codes too
Teemu Piippo <crimsondusk64@gmail.com>
parents:
48
diff
changeset
|
38 | bool bold; |
46
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
39 | }; |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
40 | |
88
08ccaf26cffd
Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents:
87
diff
changeset
|
41 | ColoredLine::ColoredLine() : |
142
b4f89893c702
Restyled parentheses in coloredline.cpp/.h
Teemu Piippo <teemu@compsta2.com>
parents:
137
diff
changeset
|
42 | m_length(0), |
b4f89893c702
Restyled parentheses in coloredline.cpp/.h
Teemu Piippo <teemu@compsta2.com>
parents:
137
diff
changeset
|
43 | m_final(false), |
b4f89893c702
Restyled parentheses in coloredline.cpp/.h
Teemu Piippo <teemu@compsta2.com>
parents:
137
diff
changeset
|
44 | m_activeColor(DEFAULT), |
b4f89893c702
Restyled parentheses in coloredline.cpp/.h
Teemu Piippo <teemu@compsta2.com>
parents:
137
diff
changeset
|
45 | m_boldActive(false), |
b4f89893c702
Restyled parentheses in coloredline.cpp/.h
Teemu Piippo <teemu@compsta2.com>
parents:
137
diff
changeset
|
46 | m_colorCodeStage(0) {} |
88
08ccaf26cffd
Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents:
87
diff
changeset
|
47 | |
46
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
48 | // ------------------------------------------------------------------------------------------------- |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
49 | // |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
63
diff
changeset
|
50 | void ColoredLine::finalize() |
46
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
51 | { |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
52 | if (m_activeColor != DEFAULT) |
143
b9993733952a
Renamed the methods of ColoredLine
Teemu Piippo <teemu@compsta2.com>
parents:
142
diff
changeset
|
53 | setColor(m_activeColor, false); |
46
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
54 | |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
55 | if (m_boldActive) |
181
e254398fcc7c
removed Container classes in favor of std::vector
Teemu Piippo <teemu@hecknology.net>
parents:
145
diff
changeset
|
56 | m_data.push_back(RLINE_OFF_BOLD); |
46
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
57 | |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
58 | m_final = true; |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
59 | } |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
60 | |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
61 | // ------------------------------------------------------------------------------------------------- |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
62 | // |
143
b9993733952a
Renamed the methods of ColoredLine
Teemu Piippo <teemu@compsta2.com>
parents:
142
diff
changeset
|
63 | void ColoredLine::addChar(char ch) |
46
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
64 | { |
87
53c2aecb9704
some work on MSVC support (still doesn't work yet...)
Teemu Piippo <tsapii@utu.fi>
parents:
73
diff
changeset
|
65 | static const ColorCodeInfo colorCodes[] = |
53c2aecb9704
some work on MSVC support (still doesn't work yet...)
Teemu Piippo <tsapii@utu.fi>
parents:
73
diff
changeset
|
66 | { |
53c2aecb9704
some work on MSVC support (still doesn't work yet...)
Teemu Piippo <tsapii@utu.fi>
parents:
73
diff
changeset
|
67 | { "Brick", RED, true }, // a |
53c2aecb9704
some work on MSVC support (still doesn't work yet...)
Teemu Piippo <tsapii@utu.fi>
parents:
73
diff
changeset
|
68 | { "Tan", YELLOW, true }, // b |
53c2aecb9704
some work on MSVC support (still doesn't work yet...)
Teemu Piippo <tsapii@utu.fi>
parents:
73
diff
changeset
|
69 | { "Gray", WHITE, false }, // c |
53c2aecb9704
some work on MSVC support (still doesn't work yet...)
Teemu Piippo <tsapii@utu.fi>
parents:
73
diff
changeset
|
70 | { "Green", GREEN, true }, // d |
53c2aecb9704
some work on MSVC support (still doesn't work yet...)
Teemu Piippo <tsapii@utu.fi>
parents:
73
diff
changeset
|
71 | { "Brown", YELLOW, false }, // e |
53c2aecb9704
some work on MSVC support (still doesn't work yet...)
Teemu Piippo <tsapii@utu.fi>
parents:
73
diff
changeset
|
72 | { "Gold", YELLOW, true }, // f |
53c2aecb9704
some work on MSVC support (still doesn't work yet...)
Teemu Piippo <tsapii@utu.fi>
parents:
73
diff
changeset
|
73 | { "Red", RED, true }, // g |
53c2aecb9704
some work on MSVC support (still doesn't work yet...)
Teemu Piippo <tsapii@utu.fi>
parents:
73
diff
changeset
|
74 | { "Blue", BLUE, false }, // h |
53c2aecb9704
some work on MSVC support (still doesn't work yet...)
Teemu Piippo <tsapii@utu.fi>
parents:
73
diff
changeset
|
75 | { "Orange", YELLOW, false }, // i |
53c2aecb9704
some work on MSVC support (still doesn't work yet...)
Teemu Piippo <tsapii@utu.fi>
parents:
73
diff
changeset
|
76 | { "White", WHITE, true }, // j |
53c2aecb9704
some work on MSVC support (still doesn't work yet...)
Teemu Piippo <tsapii@utu.fi>
parents:
73
diff
changeset
|
77 | { "Yellow", YELLOW, true }, // k |
53c2aecb9704
some work on MSVC support (still doesn't work yet...)
Teemu Piippo <tsapii@utu.fi>
parents:
73
diff
changeset
|
78 | { "Untranslated", DEFAULT, false }, // l |
53c2aecb9704
some work on MSVC support (still doesn't work yet...)
Teemu Piippo <tsapii@utu.fi>
parents:
73
diff
changeset
|
79 | { "Black", BLACK, false }, // m |
53c2aecb9704
some work on MSVC support (still doesn't work yet...)
Teemu Piippo <tsapii@utu.fi>
parents:
73
diff
changeset
|
80 | { "Blue", BLUE, true }, // n |
53c2aecb9704
some work on MSVC support (still doesn't work yet...)
Teemu Piippo <tsapii@utu.fi>
parents:
73
diff
changeset
|
81 | { "Cream", YELLOW, true }, // o |
53c2aecb9704
some work on MSVC support (still doesn't work yet...)
Teemu Piippo <tsapii@utu.fi>
parents:
73
diff
changeset
|
82 | { "Olive", GREEN, true }, // p |
53c2aecb9704
some work on MSVC support (still doesn't work yet...)
Teemu Piippo <tsapii@utu.fi>
parents:
73
diff
changeset
|
83 | { "Dark Green", GREEN, false }, // q |
53c2aecb9704
some work on MSVC support (still doesn't work yet...)
Teemu Piippo <tsapii@utu.fi>
parents:
73
diff
changeset
|
84 | { "Dark Red", RED, false }, // r |
53c2aecb9704
some work on MSVC support (still doesn't work yet...)
Teemu Piippo <tsapii@utu.fi>
parents:
73
diff
changeset
|
85 | { "Dark Brown", YELLOW, false }, // s |
53c2aecb9704
some work on MSVC support (still doesn't work yet...)
Teemu Piippo <tsapii@utu.fi>
parents:
73
diff
changeset
|
86 | { "Purple", MAGENTA, false }, // t |
53c2aecb9704
some work on MSVC support (still doesn't work yet...)
Teemu Piippo <tsapii@utu.fi>
parents:
73
diff
changeset
|
87 | { "Dark Gray", BLACK, true }, // u |
53c2aecb9704
some work on MSVC support (still doesn't work yet...)
Teemu Piippo <tsapii@utu.fi>
parents:
73
diff
changeset
|
88 | { "Cyan", CYAN, true }, // v |
53c2aecb9704
some work on MSVC support (still doesn't work yet...)
Teemu Piippo <tsapii@utu.fi>
parents:
73
diff
changeset
|
89 | }; |
53c2aecb9704
some work on MSVC support (still doesn't work yet...)
Teemu Piippo <tsapii@utu.fi>
parents:
73
diff
changeset
|
90 | |
46
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
91 | if (m_final) |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
92 | return; // Don't touch finalized lines. |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
93 | |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
94 | if (ch == '\x1C' and m_colorCodeStage == 0) |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
95 | { |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
96 | m_colorCodeStage = 1; |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
97 | return; |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
98 | } |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
99 | |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
100 | if (m_colorCodeStage == 1) |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
101 | { |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
102 | if (m_activeColor != DEFAULT) |
143
b9993733952a
Renamed the methods of ColoredLine
Teemu Piippo <teemu@compsta2.com>
parents:
142
diff
changeset
|
103 | setColor(m_activeColor, false); |
46
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
104 | |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
105 | if (m_boldActive) |
181
e254398fcc7c
removed Container classes in favor of std::vector
Teemu Piippo <teemu@hecknology.net>
parents:
145
diff
changeset
|
106 | m_data.push_back(RLINE_OFF_BOLD); |
46
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
107 | |
113
b3a33bc2e482
Added support for long-form color codes, such as \c[Green]
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
108 | m_boldActive = false; |
b3a33bc2e482
Added support for long-form color codes, such as \c[Green]
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
109 | |
63
0da5f358f298
- now supports upper-case color codes too
Teemu Piippo <crimsondusk64@gmail.com>
parents:
48
diff
changeset
|
110 | // Chars may be in uppercase |
0da5f358f298
- now supports upper-case color codes too
Teemu Piippo <crimsondusk64@gmail.com>
parents:
48
diff
changeset
|
111 | if (ch >= 'A' and ch <= 'V') |
0da5f358f298
- now supports upper-case color codes too
Teemu Piippo <crimsondusk64@gmail.com>
parents:
48
diff
changeset
|
112 | ch += 'a' - 'A'; |
0da5f358f298
- now supports upper-case color codes too
Teemu Piippo <crimsondusk64@gmail.com>
parents:
48
diff
changeset
|
113 | |
46
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
114 | if (ch >= 'a' and ch <= 'v' and ch != 'l') |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
115 | { |
113
b3a33bc2e482
Added support for long-form color codes, such as \c[Green]
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
116 | const ColorCodeInfo& colorInfo = colorCodes[ch - 'a']; |
143
b9993733952a
Renamed the methods of ColoredLine
Teemu Piippo <teemu@compsta2.com>
parents:
142
diff
changeset
|
117 | activateColor(colorInfo.color, colorInfo.bold); |
46
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
118 | } |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
119 | |
113
b3a33bc2e482
Added support for long-form color codes, such as \c[Green]
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
120 | if (ch == '[') |
b3a33bc2e482
Added support for long-form color codes, such as \c[Green]
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
121 | m_colorCodeStage = 2; |
b3a33bc2e482
Added support for long-form color codes, such as \c[Green]
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
122 | else |
b3a33bc2e482
Added support for long-form color codes, such as \c[Green]
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
123 | m_colorCodeStage = 0; |
b3a33bc2e482
Added support for long-form color codes, such as \c[Green]
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
124 | return; |
b3a33bc2e482
Added support for long-form color codes, such as \c[Green]
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
125 | } |
b3a33bc2e482
Added support for long-form color codes, such as \c[Green]
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
126 | else if (m_colorCodeStage == 2) |
b3a33bc2e482
Added support for long-form color codes, such as \c[Green]
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
127 | { |
b3a33bc2e482
Added support for long-form color codes, such as \c[Green]
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
128 | if (ch == ']') |
b3a33bc2e482
Added support for long-form color codes, such as \c[Green]
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
129 | { |
183
9b6a0daedfc0
renamed String and StringList uses
Teemu Piippo <teemu@hecknology.net>
parents:
182
diff
changeset
|
130 | std::string color = to_lowercase(m_incomingColorName); |
113
b3a33bc2e482
Added support for long-form color codes, such as \c[Green]
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
131 | |
137
485cb6d6b98c
Made Range not include the 'max' parameter, replaced a lot of for()-loops with C++11-style range-for-loops
Teemu Piippo <teemu@compsta2.com>
parents:
132
diff
changeset
|
132 | for (const ColorCodeInfo &colorInfo : colorCodes) |
113
b3a33bc2e482
Added support for long-form color codes, such as \c[Green]
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
133 | { |
182
20ca0a6be175
removed the String class in favor of std::string
Teemu Piippo <teemu@hecknology.net>
parents:
181
diff
changeset
|
134 | if (to_lowercase(colorInfo.name) == color) |
113
b3a33bc2e482
Added support for long-form color codes, such as \c[Green]
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
135 | { |
143
b9993733952a
Renamed the methods of ColoredLine
Teemu Piippo <teemu@compsta2.com>
parents:
142
diff
changeset
|
136 | activateColor(colorInfo.color, colorInfo.bold); |
113
b3a33bc2e482
Added support for long-form color codes, such as \c[Green]
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
137 | m_colorCodeStage = 0; |
b3a33bc2e482
Added support for long-form color codes, such as \c[Green]
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
138 | break; |
b3a33bc2e482
Added support for long-form color codes, such as \c[Green]
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
139 | } |
b3a33bc2e482
Added support for long-form color codes, such as \c[Green]
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
140 | } |
b3a33bc2e482
Added support for long-form color codes, such as \c[Green]
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
141 | |
b3a33bc2e482
Added support for long-form color codes, such as \c[Green]
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
142 | m_incomingColorName = ""; |
b3a33bc2e482
Added support for long-form color codes, such as \c[Green]
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
143 | m_colorCodeStage = 0; |
b3a33bc2e482
Added support for long-form color codes, such as \c[Green]
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
144 | } |
b3a33bc2e482
Added support for long-form color codes, such as \c[Green]
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
145 | else if (isprint(ch)) |
b3a33bc2e482
Added support for long-form color codes, such as \c[Green]
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
146 | m_incomingColorName += ch; |
b3a33bc2e482
Added support for long-form color codes, such as \c[Green]
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
147 | |
46
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
148 | return; |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
149 | } |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
150 | |
142
b4f89893c702
Restyled parentheses in coloredline.cpp/.h
Teemu Piippo <teemu@compsta2.com>
parents:
137
diff
changeset
|
151 | if (isprint(ch)) |
46
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
152 | { |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
153 | m_string += ch; |
181
e254398fcc7c
removed Container classes in favor of std::vector
Teemu Piippo <teemu@hecknology.net>
parents:
145
diff
changeset
|
154 | m_data.push_back(static_cast<int>(ch)); |
46
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
155 | ++m_length; |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
156 | } |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
157 | } |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
158 | |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
159 | // ------------------------------------------------------------------------------------------------- |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
160 | // |
143
b9993733952a
Renamed the methods of ColoredLine
Teemu Piippo <teemu@compsta2.com>
parents:
142
diff
changeset
|
161 | void ColoredLine::activateColor(Color color, bool bold) |
113
b3a33bc2e482
Added support for long-form color codes, such as \c[Green]
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
162 | { |
b3a33bc2e482
Added support for long-form color codes, such as \c[Green]
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
163 | if (m_boldActive) |
181
e254398fcc7c
removed Container classes in favor of std::vector
Teemu Piippo <teemu@hecknology.net>
parents:
145
diff
changeset
|
164 | { |
e254398fcc7c
removed Container classes in favor of std::vector
Teemu Piippo <teemu@hecknology.net>
parents:
145
diff
changeset
|
165 | m_data.push_back(RLINE_OFF_BOLD); |
e254398fcc7c
removed Container classes in favor of std::vector
Teemu Piippo <teemu@hecknology.net>
parents:
145
diff
changeset
|
166 | } |
113
b3a33bc2e482
Added support for long-form color codes, such as \c[Green]
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
167 | m_activeColor = color; |
b3a33bc2e482
Added support for long-form color codes, such as \c[Green]
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
168 | m_boldActive = bold; |
142
b4f89893c702
Restyled parentheses in coloredline.cpp/.h
Teemu Piippo <teemu@compsta2.com>
parents:
137
diff
changeset
|
169 | assert(m_activeColor < 8); |
143
b9993733952a
Renamed the methods of ColoredLine
Teemu Piippo <teemu@compsta2.com>
parents:
142
diff
changeset
|
170 | setColor(m_activeColor, true); |
113
b3a33bc2e482
Added support for long-form color codes, such as \c[Green]
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
171 | if (m_boldActive) |
181
e254398fcc7c
removed Container classes in favor of std::vector
Teemu Piippo <teemu@hecknology.net>
parents:
145
diff
changeset
|
172 | { |
e254398fcc7c
removed Container classes in favor of std::vector
Teemu Piippo <teemu@hecknology.net>
parents:
145
diff
changeset
|
173 | m_data.push_back(RLINE_ON_BOLD); |
e254398fcc7c
removed Container classes in favor of std::vector
Teemu Piippo <teemu@hecknology.net>
parents:
145
diff
changeset
|
174 | } |
113
b3a33bc2e482
Added support for long-form color codes, such as \c[Green]
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
175 | } |
b3a33bc2e482
Added support for long-form color codes, such as \c[Green]
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
176 | |
b3a33bc2e482
Added support for long-form color codes, such as \c[Green]
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
177 | // ------------------------------------------------------------------------------------------------- |
b3a33bc2e482
Added support for long-form color codes, such as \c[Green]
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
178 | // |
183
9b6a0daedfc0
renamed String and StringList uses
Teemu Piippo <teemu@hecknology.net>
parents:
182
diff
changeset
|
179 | void ColoredLine::addString(const std::string& text) |
132
8a4690db252e
Added support for colored nicknames
Teemu Piippo <crimsondusk64@gmail.com>
parents:
113
diff
changeset
|
180 | { |
8a4690db252e
Added support for colored nicknames
Teemu Piippo <crimsondusk64@gmail.com>
parents:
113
diff
changeset
|
181 | for (char a : text) |
143
b9993733952a
Renamed the methods of ColoredLine
Teemu Piippo <teemu@compsta2.com>
parents:
142
diff
changeset
|
182 | addChar(a); |
132
8a4690db252e
Added support for colored nicknames
Teemu Piippo <crimsondusk64@gmail.com>
parents:
113
diff
changeset
|
183 | } |
8a4690db252e
Added support for colored nicknames
Teemu Piippo <crimsondusk64@gmail.com>
parents:
113
diff
changeset
|
184 | |
8a4690db252e
Added support for colored nicknames
Teemu Piippo <crimsondusk64@gmail.com>
parents:
113
diff
changeset
|
185 | // ------------------------------------------------------------------------------------------------- |
8a4690db252e
Added support for colored nicknames
Teemu Piippo <crimsondusk64@gmail.com>
parents:
113
diff
changeset
|
186 | // |
143
b9993733952a
Renamed the methods of ColoredLine
Teemu Piippo <teemu@compsta2.com>
parents:
142
diff
changeset
|
187 | void ColoredLine::setColor(Color a, bool on) |
46
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
188 | { |
142
b4f89893c702
Restyled parentheses in coloredline.cpp/.h
Teemu Piippo <teemu@compsta2.com>
parents:
137
diff
changeset
|
189 | assert(a < 8); |
181
e254398fcc7c
removed Container classes in favor of std::vector
Teemu Piippo <teemu@hecknology.net>
parents:
145
diff
changeset
|
190 | m_data.push_back(a + (on ? RLINE_ON_COLOR : RLINE_OFF_COLOR)); |
46
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
191 | } |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
192 | |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
193 | // ------------------------------------------------------------------------------------------------- |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
194 | // How many rows does this line take up? |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
195 | // |
142
b4f89893c702
Restyled parentheses in coloredline.cpp/.h
Teemu Piippo <teemu@compsta2.com>
parents:
137
diff
changeset
|
196 | int ColoredLine::rows(int cols) const |
46
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
197 | { |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
198 | int rows = length() / cols; |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
199 | |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
200 | if (length() % cols != 0) |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
201 | rows++; |
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
202 | |
142
b4f89893c702
Restyled parentheses in coloredline.cpp/.h
Teemu Piippo <teemu@compsta2.com>
parents:
137
diff
changeset
|
203 | return max(rows, 1); |
46
19be47c9bab7
- renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
204 | } |
88
08ccaf26cffd
Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents:
87
diff
changeset
|
205 | |
08ccaf26cffd
Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents:
87
diff
changeset
|
206 | END_ZFC_NAMESPACE |