sources/coloredline.cpp

Tue, 16 Dec 2014 03:59:52 +0200

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Tue, 16 Dec 2014 03:59:52 +0200
changeset 63
0da5f358f298
parent 48
02009f1ec2b7
child 69
eb4c25284a19
permissions
-rw-r--r--

- now supports upper-case color codes too

46
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 /*
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
2 Copyright 2014 Teemu Piippo
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"
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32
63
0da5f358f298 - now supports upper-case color codes too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
33 static const struct
0da5f358f298 - now supports upper-case color codes too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
34 {
0da5f358f298 - now supports upper-case color codes too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
35 const char* name;
0da5f358f298 - now supports upper-case color codes too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
36 Color color;
0da5f358f298 - now supports upper-case color codes too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
37 bool bold;
0da5f358f298 - now supports upper-case color codes too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
38 } g_colorCodes['v' - 'a' + 1] =
46
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39 {
63
0da5f358f298 - now supports upper-case color codes too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
40 { "Brick", RED, true }, // a
0da5f358f298 - now supports upper-case color codes too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
41 { "Tan", YELLOW, true }, // b
0da5f358f298 - now supports upper-case color codes too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
42 { "Gray", WHITE, false }, // c
0da5f358f298 - now supports upper-case color codes too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
43 { "Green", GREEN, true }, // d
0da5f358f298 - now supports upper-case color codes too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
44 { "Brown", YELLOW, false }, // e
0da5f358f298 - now supports upper-case color codes too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
45 { "Gold", YELLOW, true }, // f
0da5f358f298 - now supports upper-case color codes too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
46 { "Red", RED, true }, // g
0da5f358f298 - now supports upper-case color codes too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
47 { "Blue", BLUE, false }, // h
0da5f358f298 - now supports upper-case color codes too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
48 { "Orange", YELLOW, false }, // i
0da5f358f298 - now supports upper-case color codes too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
49 { "White", WHITE, true }, // j
0da5f358f298 - now supports upper-case color codes too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
50 { "Yellow", YELLOW, true }, // k
0da5f358f298 - now supports upper-case color codes too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
51 { "Untranslated", DEFAULT, false }, // l
0da5f358f298 - now supports upper-case color codes too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
52 { "Black", BLACK, false }, // m
0da5f358f298 - now supports upper-case color codes too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
53 { "Blue", BLUE, true }, // n
0da5f358f298 - now supports upper-case color codes too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
54 { "Cream", YELLOW, true }, // o
0da5f358f298 - now supports upper-case color codes too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
55 { "Olive", GREEN, true }, // p
0da5f358f298 - now supports upper-case color codes too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
56 { "Dark Green", GREEN, false }, // q
0da5f358f298 - now supports upper-case color codes too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
57 { "Dark Red", RED, false }, // r
0da5f358f298 - now supports upper-case color codes too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
58 { "Dark Brown", YELLOW, false }, // s
0da5f358f298 - now supports upper-case color codes too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
59 { "Purple", MAGENTA, false }, // t
0da5f358f298 - now supports upper-case color codes too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
60 { "Dark Gray", BLACK, true }, // u
0da5f358f298 - now supports upper-case color codes too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
61 { "Cyan", CYAN, true }, // v
46
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
62 };
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
63
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
64 // -------------------------------------------------------------------------------------------------
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
65 //
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
66 METHOD
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
67 ColoredLine::finalize() -> void
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
68 {
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
69 if (m_activeColor != DEFAULT)
63
0da5f358f298 - now supports upper-case color codes too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
70 set_color (m_activeColor, false);
46
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
71
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
72 if (m_boldActive)
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
73 m_data << RLINE_OFF_BOLD;
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
74
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
75 m_final = true;
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
76 }
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
77
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
78 // -------------------------------------------------------------------------------------------------
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
79 //
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
80 METHOD
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
81 ColoredLine::add_char (char ch) -> void
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
82 {
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
83 if (m_final)
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
84 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
85
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
86 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
87 {
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
88 m_colorCodeStage = 1;
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
89 return;
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
90 }
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
91
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
92 if (m_colorCodeStage == 1)
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 (m_activeColor != DEFAULT)
63
0da5f358f298 - now supports upper-case color codes too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
95 set_color (m_activeColor, false);
46
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
96
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
97 if (m_boldActive)
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
98 m_data << RLINE_OFF_BOLD;
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
99
63
0da5f358f298 - now supports upper-case color codes too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
100 // Chars may be in uppercase
0da5f358f298 - now supports upper-case color codes too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
101 if (ch >= 'A' and ch <= 'V')
0da5f358f298 - now supports upper-case color codes too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
102 ch += 'a' - 'A';
0da5f358f298 - now supports upper-case color codes too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
103
46
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
104 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
105 {
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
106 auto colorInfo = g_colorCodes[ch - 'a'];
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
107 m_activeColor = colorInfo.color;
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
108 m_boldActive = colorInfo.bold;
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
109 assert (m_activeColor < 8);
63
0da5f358f298 - now supports upper-case color codes too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
110 set_color (m_activeColor, true);
46
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
111
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
112 if (m_boldActive)
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
113 m_data << RLINE_ON_BOLD;
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
114 }
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
115
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
116 m_colorCodeStage = 0;
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
117 return;
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
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
120 if (isprint (ch))
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
121 {
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
122 m_string += ch;
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
123 m_data << int (ch);
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
124 ++m_length;
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
125 }
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
126 }
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
127
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
128 // -------------------------------------------------------------------------------------------------
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
129 //
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
130 METHOD
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
131 ColoredLine::set_color (Color a, bool on) -> void
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
132 {
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
133 switch (a)
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
134 {
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
135 case BLACK: m_data << (on ? RLINE_ON_BLACK : RLINE_OFF_BLACK); break;
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
136 case RED: m_data << (on ? RLINE_ON_RED : RLINE_OFF_RED); break;
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
137 case GREEN: m_data << (on ? RLINE_ON_GREEN : RLINE_OFF_GREEN); break;
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
138 case YELLOW: m_data << (on ? RLINE_ON_YELLOW : RLINE_OFF_YELLOW); break;
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
139 case BLUE: m_data << (on ? RLINE_ON_BLUE : RLINE_OFF_BLUE); break;
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
140 case MAGENTA: m_data << (on ? RLINE_ON_MAGENTA : RLINE_OFF_MAGENTA); break;
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
141 case CYAN: m_data << (on ? RLINE_ON_CYAN : RLINE_OFF_CYAN); break;
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
142 case WHITE: m_data << (on ? RLINE_ON_WHITE : RLINE_OFF_WHITE); break;
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
143 case NUM_COLORS:
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
144 case DEFAULT: assert (false); break;
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
145 }
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
146 }
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
147
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
148 // -------------------------------------------------------------------------------------------------
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
149 // 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
150 //
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
151 METHOD
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
152 ColoredLine::rows (int cols) const -> int
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
153 {
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
154 int rows = length() / cols;
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
155
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
156 if (length() % cols != 0)
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
157 rows++;
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 return max (rows, 1);
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
160 }

mercurial