src/colors.cc

changeset 629
b75c6cce02e2
parent 628
6b13e4c2e97b
child 630
42ec68fcad9e
child 675
450827da2376
equal deleted inserted replaced
628:6b13e4c2e97b 629:b75c6cce02e2
1 /*
2 * LDForge: LDraw parts authoring CAD
3 * Copyright (C) 2013, 2014 Santeri Piippo
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 * =====================================================================
18 *
19 * colors.cpp: LDraw color management. LDConfig.ldr parsing is not here!
20 * TODO: Make LDColor more full-fledged, add support for direct colors.
21 * TODO: g_LDColors should probably be a map.
22 */
23
24 #include "main.h"
25 #include "colors.h"
26 #include "document.h"
27 #include "misc.h"
28 #include "gui.h"
29 #include "ldconfig.h"
30 #include <QColor>
31
32 static LDColor* g_LDColors[MAX_COLORS];
33
34 // =============================================================================
35 // -----------------------------------------------------------------------------
36 void initColors()
37 {
38 LDColor* col;
39 log ("%1: initializing color information.\n", __func__);
40
41 // Always make sure there's 16 and 24 available. They're special like that.
42 col = new LDColor;
43 col->faceColor = col->hexcode = "#AAAAAA";
44 col->edgeColor = Qt::black;
45 g_LDColors[maincolor] = col;
46
47 col = new LDColor;
48 col->faceColor = col->edgeColor = col->hexcode = "#000000";
49 g_LDColors[edgecolor] = col;
50
51 parseLDConfig();
52 }
53
54 // =============================================================================
55 // -----------------------------------------------------------------------------
56 LDColor* getColor (int colnum)
57 {
58 // Check bounds
59 if (colnum < 0 || colnum >= MAX_COLORS)
60 return null;
61
62 return g_LDColors[colnum];
63 }
64
65 // =============================================================================
66 // -----------------------------------------------------------------------------
67 void setColor (int colnum, LDColor* col)
68 {
69 if (colnum < 0 || colnum >= MAX_COLORS)
70 return;
71
72 g_LDColors[colnum] = col;
73 }
74
75 // =============================================================================
76 // -----------------------------------------------------------------------------
77 int luma (QColor& col)
78 {
79 return (0.2126f * col.red()) +
80 (0.7152f * col.green()) +
81 (0.0722f * col.blue());
82 }

mercurial