sources/coloredline.h

Thu, 23 Jul 2015 00:16:47 +0300

author
Teemu Piippo <tsapii@utu.fi>
date
Thu, 23 Jul 2015 00:16:47 +0300
changeset 87
53c2aecb9704
parent 73
07dda51a7a8e
child 78
c1d43ade656e
child 88
08ccaf26cffd
permissions
-rw-r--r--

some work on MSVC support (still doesn't work yet...)

46
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 /*
73
07dda51a7a8e Update license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 69
diff changeset
2 Copyright 2014, 2015 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 #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"
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33
60
268721e6be20 - formatting
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
34 // -------------------------------------------------------------------------------------------------
268721e6be20 - formatting
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
35 //
46
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36 enum
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37 {
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
38 RLINE_ON_BLACK = 256,
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39 RLINE_ON_RED,
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40 RLINE_ON_GREEN,
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
41 RLINE_ON_YELLOW,
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
42 RLINE_ON_BLUE,
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
43 RLINE_ON_MAGENTA,
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
44 RLINE_ON_CYAN,
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
45 RLINE_ON_WHITE,
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
46 RLINE_ON_BOLD,
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
47 RLINE_OFF_BLACK,
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48 RLINE_OFF_RED,
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
49 RLINE_OFF_GREEN,
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
50 RLINE_OFF_YELLOW,
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
51 RLINE_OFF_BLUE,
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
52 RLINE_OFF_MAGENTA,
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
53 RLINE_OFF_CYAN,
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54 RLINE_OFF_WHITE,
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55 RLINE_OFF_BOLD,
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
60
268721e6be20 - formatting
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
58 // -------------------------------------------------------------------------------------------------
268721e6be20 - formatting
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
59 //
46
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60 class ColoredLine
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 public:
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
63 ColoredLine() {}
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
64
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
65 const Vector<int>& data() const { return m_data; }
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
66 int length() const { return m_length; }
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
67 void add_char (char ch);
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
68 void finalize();
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
69 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
70
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
71 private:
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
72 void set_color (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
73
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
74 Vector<int> m_data;
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
75 int m_length = 0;
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
76 bool m_final = false;
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
77 Color m_activeColor = DEFAULT;
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
78 bool m_boldActive = false;
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
79 int m_colorCodeStage = 0;
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
80 String m_string;
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
81 };

mercurial