src/colors.cc

changeset 557
04e140bdeb0b
child 600
209e3f1f7b2c
equal deleted inserted replaced
556:5f4395ec5db0 557:04e140bdeb0b
1 /*
2 * LDForge: LDraw parts authoring CAD
3 * Copyright (C) 2013 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 { LDColor* col;
38 log ("%1: initializing color information.\n", __func__);
39
40 // Always make sure there's 16 and 24 available. They're special like that.
41 col = new LDColor;
42 col->faceColor = col->hexcode = "#AAAAAA";
43 col->edgeColor = Qt::black;
44 g_LDColors[maincolor] = col;
45
46 col = new LDColor;
47 col->faceColor = col->edgeColor = col->hexcode = "#000000";
48 g_LDColors[edgecolor] = col;
49
50 parseLDConfig();
51 }
52
53 // =============================================================================
54 // -----------------------------------------------------------------------------
55 LDColor* getColor (int colnum)
56 { // Check bounds
57 if (colnum < 0 || colnum >= MAX_COLORS)
58 return null;
59
60 return g_LDColors[colnum];
61 }
62
63 // =============================================================================
64 // -----------------------------------------------------------------------------
65 void setColor (int colnum, LDColor* col)
66 { if (colnum < 0 || colnum >= MAX_COLORS)
67 return;
68
69 g_LDColors[colnum] = col;
70 }
71
72 // =============================================================================
73 // -----------------------------------------------------------------------------
74 int luma (QColor& col)
75 { return (0.2126f * col.red()) +
76 (0.7152f * col.green()) +
77 (0.0722f * col.blue());
78 }

mercurial