sources/coloredline.h

Wed, 27 Jan 2021 19:32:55 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Wed, 27 Jan 2021 19:32:55 +0200
changeset 191
2e6cbacafdc7
parent 190
90bf9049e5eb
child 195
be953e1621d9
permissions
-rw-r--r--

various little touchups

46
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 /*
190
90bf9049e5eb updated copyright year
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
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,
142
b4f89893c702 Restyled parentheses in coloredline.cpp/.h
Teemu Piippo <teemu@compsta2.com>
parents: 132
diff changeset
23 EXEMPLARY, OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO,
46
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
142
b4f89893c702 Restyled parentheses in coloredline.cpp/.h
Teemu Piippo <teemu@compsta2.com>
parents: 132
diff changeset
26 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING
46
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 #pragma once
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32 #include "main.h"
88
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 73
diff changeset
33 BEGIN_ZFC_NAMESPACE
46
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
34
142
b4f89893c702 Restyled parentheses in coloredline.cpp/.h
Teemu Piippo <teemu@compsta2.com>
parents: 132
diff changeset
35 // The order of these colors appears to differ between curses distributions(PDCurses and its
89
777b2a10b835 Add support for standard pdcurses, thanks to Leonard for pointing out the solutions to a few mysteries.
Teemu Piippo <tsapii@utu.fi>
parents: 88
diff changeset
36 // win32a for instance have blue and red swapped). So we need to explicitly define the values
777b2a10b835 Add support for standard pdcurses, thanks to Leonard for pointing out the solutions to a few mysteries.
Teemu Piippo <tsapii@utu.fi>
parents: 88
diff changeset
37 // of the enumerators based on their curses values.
777b2a10b835 Add support for standard pdcurses, thanks to Leonard for pointing out the solutions to a few mysteries.
Teemu Piippo <tsapii@utu.fi>
parents: 88
diff changeset
38 enum Color
777b2a10b835 Add support for standard pdcurses, thanks to Leonard for pointing out the solutions to a few mysteries.
Teemu Piippo <tsapii@utu.fi>
parents: 88
diff changeset
39 {
100
d301ead29d7c Apply Leonard's patch for fixing the colors:
Teemu Piippo <tsapii@utu.fi>
parents: 89
diff changeset
40 BLACK = COLOR_BLACK,
d301ead29d7c Apply Leonard's patch for fixing the colors:
Teemu Piippo <tsapii@utu.fi>
parents: 89
diff changeset
41 RED = COLOR_RED,
d301ead29d7c Apply Leonard's patch for fixing the colors:
Teemu Piippo <tsapii@utu.fi>
parents: 89
diff changeset
42 GREEN = COLOR_GREEN,
d301ead29d7c Apply Leonard's patch for fixing the colors:
Teemu Piippo <tsapii@utu.fi>
parents: 89
diff changeset
43 YELLOW = COLOR_YELLOW,
d301ead29d7c Apply Leonard's patch for fixing the colors:
Teemu Piippo <tsapii@utu.fi>
parents: 89
diff changeset
44 BLUE = COLOR_BLUE,
d301ead29d7c Apply Leonard's patch for fixing the colors:
Teemu Piippo <tsapii@utu.fi>
parents: 89
diff changeset
45 MAGENTA = COLOR_MAGENTA,
d301ead29d7c Apply Leonard's patch for fixing the colors:
Teemu Piippo <tsapii@utu.fi>
parents: 89
diff changeset
46 CYAN = COLOR_CYAN,
d301ead29d7c Apply Leonard's patch for fixing the colors:
Teemu Piippo <tsapii@utu.fi>
parents: 89
diff changeset
47 WHITE = COLOR_WHITE,
d301ead29d7c Apply Leonard's patch for fixing the colors:
Teemu Piippo <tsapii@utu.fi>
parents: 89
diff changeset
48 DEFAULT = 8,
89
777b2a10b835 Add support for standard pdcurses, thanks to Leonard for pointing out the solutions to a few mysteries.
Teemu Piippo <tsapii@utu.fi>
parents: 88
diff changeset
49 NUM_COLORS
777b2a10b835 Add support for standard pdcurses, thanks to Leonard for pointing out the solutions to a few mysteries.
Teemu Piippo <tsapii@utu.fi>
parents: 88
diff changeset
50 };
777b2a10b835 Add support for standard pdcurses, thanks to Leonard for pointing out the solutions to a few mysteries.
Teemu Piippo <tsapii@utu.fi>
parents: 88
diff changeset
51
191
2e6cbacafdc7 various little touchups
Teemu Piippo <teemu@hecknology.net>
parents: 190
diff changeset
52 constexpr int RLINE_ON_COLOR = 256;
2e6cbacafdc7 various little touchups
Teemu Piippo <teemu@hecknology.net>
parents: 190
diff changeset
53 constexpr int RLINE_OFF_COLOR = 264;
2e6cbacafdc7 various little touchups
Teemu Piippo <teemu@hecknology.net>
parents: 190
diff changeset
54 constexpr int RLINE_ON_BOLD = 272;
2e6cbacafdc7 various little touchups
Teemu Piippo <teemu@hecknology.net>
parents: 190
diff changeset
55 constexpr int RLINE_OFF_BOLD = 273;
46
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
56
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
57 class ColoredLine
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
58 {
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
59 public:
88
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 73
diff changeset
60 ColoredLine();
46
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61
191
2e6cbacafdc7 various little touchups
Teemu Piippo <teemu@hecknology.net>
parents: 190
diff changeset
62 const std::vector<int>& data() const { return m_data; }
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
63 int length() const { return m_length; }
143
b9993733952a Renamed the methods of ColoredLine
Teemu Piippo <teemu@compsta2.com>
parents: 142
diff changeset
64 void addChar(char ch);
183
9b6a0daedfc0 renamed String and StringList uses
Teemu Piippo <teemu@hecknology.net>
parents: 143
diff changeset
65 void addString(const std::string& msg);
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
66 void finalize();
142
b4f89893c702 Restyled parentheses in coloredline.cpp/.h
Teemu Piippo <teemu@compsta2.com>
parents: 132
diff changeset
67 int 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
68
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
69 private:
143
b9993733952a Renamed the methods of ColoredLine
Teemu Piippo <teemu@compsta2.com>
parents: 142
diff changeset
70 void activateColor(Color color, bool bold);
b9993733952a Renamed the methods of ColoredLine
Teemu Piippo <teemu@compsta2.com>
parents: 142
diff changeset
71 void 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
72
191
2e6cbacafdc7 various little touchups
Teemu Piippo <teemu@hecknology.net>
parents: 190
diff changeset
73 std::vector<int> m_data;
88
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 73
diff changeset
74 int m_length;
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 73
diff changeset
75 bool m_final;
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 73
diff changeset
76 Color m_activeColor;
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 73
diff changeset
77 bool m_boldActive;
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 73
diff changeset
78 int m_colorCodeStage;
183
9b6a0daedfc0 renamed String and StringList uses
Teemu Piippo <teemu@hecknology.net>
parents: 143
diff changeset
79 std::string m_string;
9b6a0daedfc0 renamed String and StringList uses
Teemu Piippo <teemu@hecknology.net>
parents: 143
diff changeset
80 std::string m_incomingColorName;
46
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
81 };
88
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 73
diff changeset
82
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 73
diff changeset
83 END_ZFC_NAMESPACE

mercurial