src/colors.h

Tue, 24 May 2022 16:11:10 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Tue, 24 May 2022 16:11:10 +0300
changeset 188
64ea7282611e
parent 178
a23024fc98e0
child 196
6bcb284679d4
permissions
-rw-r--r--

more work on circle tool + cleanup

24
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
1 /*
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
2 * LDForge: LDraw parts authoring CAD
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
3 * Copyright (C) 2013 - 2020 Teemu Piippo
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
4 *
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
5 * This program is free software: you can redistribute it and/or modify
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
6 * it under the terms of the GNU General Public License as published by
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
8 * (at your option) any later version.
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
9 *
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
10 * This program is distributed in the hope that it will be useful,
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
13 * GNU General Public License for more details.
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
14 *
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
15 * You should have received a copy of the GNU General Public License
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
17 */
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
18
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
19 #pragma once
26
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 24
diff changeset
20 #include <QColor>
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
21 #include "main.h"
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
22
35
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
23 namespace ldraw
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
24 {
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
25 struct Color;
139
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
26 struct ColorDefinition;
35
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
27 class ColorTable;
94
164f53fb5921 added a color select dialog
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
28 Color directColor(const QColor& color);
164f53fb5921 added a color select dialog
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
29 bool isDirectColor(Color color);
164f53fb5921 added a color select dialog
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
30 QColor directColorFace(Color color);
164f53fb5921 added a color select dialog
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
31 QColor colorFace(Color color, const ColorTable& colorTable);
178
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents: 139
diff changeset
32 QColor colorEdge(Color color, const ColorTable& colorTable);
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents: 139
diff changeset
33 QString colorDisplayName(Color color, const ColorTable& colorTable);
35
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
34 }
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
35
139
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
36 /**
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
37 * @brief Represents an LDraw color index (e.g 16, 24, ...)
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
38 *
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
39 * @details
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
40 * This is essentially just an integer. It is its own structure for the sake
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
41 * of type correctness. Commonly used color values are 16 for the main color
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
42 * and 24 for the edge color.
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
43 *
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
44 * Use @c ldraw::ColorTable to obtain rgb values for color indices.
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
45 *
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
46 * Direct colors are colors whose index is at least 0x2000000. These colors
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
47 * encode the rgb values directly in the index. The color table code also
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
48 * handles these cases.
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
49 *
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
50 * Note that it only makes sense to construct a color index from an integer
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
51 * value if the integer comes from an external source (e.g. user or
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
52 * LDConfig.ldr). Since this structure only contains an integer, it should be
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
53 * passed by value to functions instead of l-value reference.
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
54 */
35
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
55 struct ldraw::Color
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
56 {
89
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents: 73
diff changeset
57 qint32 index = 0;
188
64ea7282611e more work on circle tool + cleanup
Teemu Piippo <teemu@hecknology.net>
parents: 178
diff changeset
58 constexpr auto operator<=>(const Color&) const = default;
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
59 };
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
60
89
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents: 73
diff changeset
61 Q_DECLARE_METATYPE(ldraw::Color)
139
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
62 QDataStream& operator<<(QDataStream&, ldraw::Color);
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
63 QDataStream& operator>>(QDataStream&, ldraw::Color&);
89
7abaf1d64719 object editing
Teemu Piippo <teemu@hecknology.net>
parents: 73
diff changeset
64
139
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
65 namespace ldraw
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
66 {
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
67 static constexpr Color BLACK {0};
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
68 static constexpr Color BLUE {1};
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
69 static constexpr Color GREEN {2};
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
70 static constexpr Color RED {4};
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
71 static constexpr Color YELLOW {14};
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
72 static constexpr Color WHITE {15};
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
73 static constexpr Color MAIN_COLOR {16};
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
74 static constexpr Color EDGE_COLOR {24};
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
75 }
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
76
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
77 /**
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
78 * @brief Contains the information about a specific color
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
79 */
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
80 struct ldraw::ColorDefinition
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
81 {
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
82 /**
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
83 * @brief The face color. This is the color used for most objects.
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
84 * This is also used for the polygons of a subfile reference.
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
85 */
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
86 QColor faceColor;
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
87 /**
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
88 * @brief The edge color, used for the edge lines of a subfile reference.
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
89 * Note that edges using a color actually use the face color. LDraw standards
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
90 * require edges to use color 24, however.
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
91 */
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
92 QColor edgeColor;
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
93 /**
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
94 * @brief Name of the color
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
95 */
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
96 QString name;
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
97 /**
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
98 * @brief A version of the name that can be shown to the user.
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
99 */
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
100 QString displayName;
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
101 };
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
102
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
103 /**
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
104 * @brief Reads LDConfig.ldr and contains color table information for lookup purposes.
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
105 */
35
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
106 class ldraw::ColorTable
26
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 24
diff changeset
107 {
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 24
diff changeset
108 public:
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 24
diff changeset
109 void clear();
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 24
diff changeset
110 Result load(QIODevice& device, QTextStream& errors);
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 24
diff changeset
111 const ColorDefinition& operator[](Color index) const;
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 24
diff changeset
112 static const ColorDefinition unknownColor;
94
164f53fb5921 added a color select dialog
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
113 auto begin() const { return this->definitions.begin(); }
164f53fb5921 added a color select dialog
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
114 auto end() const { return this->definitions.end(); }
139
72098474d362 Document and refactor colors.cpp and colors.h
Teemu Piippo <teemu@hecknology.net>
parents: 132
diff changeset
115 int size() const;
26
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 24
diff changeset
116 private:
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 24
diff changeset
117 void loadColorFromString(const QString& string);
94
164f53fb5921 added a color select dialog
Teemu Piippo <teemu@hecknology.net>
parents: 89
diff changeset
118 std::map<qint32, ColorDefinition> definitions;
26
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 24
diff changeset
119 };
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 24
diff changeset
120
43
08dc62e03a6d made edges white in dark backgrounds
Teemu Piippo <teemu@hecknology.net>
parents: 35
diff changeset
121 double luma(const QColor& color);

mercurial