Wed, 21 Aug 2013 14:07:02 +0300
stuff
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1 | /* |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
2 | * LDForge: LDraw parts authoring CAD |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
3 | * Copyright (C) 2013 Santeri Piippo |
359
bcdfc801658b
more restyle/refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents:
321
diff
changeset
|
4 | * |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
5 | * This program is free software: you can redistribute it and/or modify |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
6 | * it under the terms of the GNU General Public License as published by |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
7 | * the Free Software Foundation, either version 3 of the License, or |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
8 | * (at your option) any later version. |
359
bcdfc801658b
more restyle/refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents:
321
diff
changeset
|
9 | * |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
13 | * GNU General Public License for more details. |
359
bcdfc801658b
more restyle/refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents:
321
diff
changeset
|
14 | * |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
471 | 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. | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
22 | */ |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
23 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
24 | #include "common.h" |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
25 | #include "colors.h" |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
26 | #include "file.h" |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
27 | #include "misc.h" |
248
4431371f3ffe
Added a progress dialog for file loading to respond to desktops while loading files. With large files the no-response policy could be a bad thing. My first real use case of multi-threading...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
211
diff
changeset
|
28 | #include "gui.h" |
406
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
364
diff
changeset
|
29 | #include "ldconfig.h" |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
364
diff
changeset
|
30 | #include <QColor> |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
31 | |
364
7c3af0a6f8ab
Renamed the color class to LDColor for clarity
Santeri Piippo <crimsondusk64@gmail.com>
parents:
359
diff
changeset
|
32 | static LDColor* g_LDColors[MAX_COLORS]; |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
33 | |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
421
diff
changeset
|
34 | // ============================================================================= |
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
421
diff
changeset
|
35 | // ----------------------------------------------------------------------------- |
406
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
364
diff
changeset
|
36 | void initColors() { |
364
7c3af0a6f8ab
Renamed the color class to LDColor for clarity
Santeri Piippo <crimsondusk64@gmail.com>
parents:
359
diff
changeset
|
37 | LDColor* col; |
421
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
406
diff
changeset
|
38 | print ("%1: initializing color information.\n", __func__); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
39 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
40 | // Always make sure there's 16 and 24 available. They're special like that. |
364
7c3af0a6f8ab
Renamed the color class to LDColor for clarity
Santeri Piippo <crimsondusk64@gmail.com>
parents:
359
diff
changeset
|
41 | col = new LDColor; |
471 | 42 | col->faceColor = |
189
ac2d3e8dd110
Rewrote the string class with a simpler version. The old one was more than probably leaking water like a boat with an elephant on board...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
185
diff
changeset
|
43 | col->hexcode = "#AAAAAA"; |
ac2d3e8dd110
Rewrote the string class with a simpler version. The old one was more than probably leaking water like a boat with an elephant on board...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
185
diff
changeset
|
44 | col->edgeColor = Qt::black; |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
45 | g_LDColors[maincolor] = col; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
46 | |
364
7c3af0a6f8ab
Renamed the color class to LDColor for clarity
Santeri Piippo <crimsondusk64@gmail.com>
parents:
359
diff
changeset
|
47 | col = new LDColor; |
471 | 48 | col->faceColor = |
49 | col->edgeColor = | |
189
ac2d3e8dd110
Rewrote the string class with a simpler version. The old one was more than probably leaking water like a boat with an elephant on board...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
185
diff
changeset
|
50 | col->hexcode = "#000000"; |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
51 | g_LDColors[edgecolor] = col; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
52 | |
359
bcdfc801658b
more restyle/refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents:
321
diff
changeset
|
53 | parseLDConfig(); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
54 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
55 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
56 | // ============================================================================= |
406
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
364
diff
changeset
|
57 | // ----------------------------------------------------------------------------- |
421
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
406
diff
changeset
|
58 | LDColor* getColor (short colnum) { |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
59 | // Check bounds |
421
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
406
diff
changeset
|
60 | if (colnum < 0 || colnum >= MAX_COLORS) |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
61 | return null; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
62 | |
359
bcdfc801658b
more restyle/refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents:
321
diff
changeset
|
63 | return g_LDColors[colnum]; |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
64 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
65 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
66 | // ============================================================================= |
406
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
364
diff
changeset
|
67 | // ----------------------------------------------------------------------------- |
421
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
406
diff
changeset
|
68 | void setColor (short colnum, LDColor* col) { |
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
406
diff
changeset
|
69 | if (colnum < 0 || colnum >= MAX_COLORS) |
406
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
364
diff
changeset
|
70 | return; |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
364
diff
changeset
|
71 | |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
364
diff
changeset
|
72 | g_LDColors[colnum] = col; |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
364
diff
changeset
|
73 | } |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
364
diff
changeset
|
74 | |
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
364
diff
changeset
|
75 | // ============================================================================= |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
421
diff
changeset
|
76 | // ----------------------------------------------------------------------------- |
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
421
diff
changeset
|
77 | int luma (QColor& col) { |
421
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
406
diff
changeset
|
78 | return (0.2126f * col.red()) + |
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
406
diff
changeset
|
79 | (0.7152f * col.green()) + |
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
406
diff
changeset
|
80 | (0.0722f * col.blue()); |
406
5371baa17346
Separated LDConfig.ldr-specific stuff to ldconfig.cpp/h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
364
diff
changeset
|
81 | } |