Wed, 08 May 2013 04:10:31 +0300
Moved LDraw path setting out of the configuration dialog to the LDraw path dialog, it does the job better.
48
113eb6446c61
Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1 | /* |
113eb6446c61
Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
2 | * LDForge: LDraw parts authoring CAD |
104 | 3 | * Copyright (C) 2013 Santeri Piippo |
48
113eb6446c61
Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
4 | * |
113eb6446c61
Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
5 | * This program is free software: you can redistribute it and/or modify |
113eb6446c61
Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
6 | * it under the terms of the GNU General Public License as published by |
113eb6446c61
Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
7 | * the Free Software Foundation, either version 3 of the License, or |
113eb6446c61
Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
8 | * (at your option) any later version. |
113eb6446c61
Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
9 | * |
113eb6446c61
Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
113eb6446c61
Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
113eb6446c61
Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
113eb6446c61
Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
13 | * GNU General Public License for more details. |
113eb6446c61
Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
14 | * |
113eb6446c61
Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
113eb6446c61
Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
113eb6446c61
Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
17 | */ |
113eb6446c61
Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
18 | |
113eb6446c61
Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
19 | #include "common.h" |
113eb6446c61
Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
20 | #include "colors.h" |
72
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
21 | #include "file.h" |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
22 | #include "misc.h" |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
23 | #include <qcolor.h> |
48
113eb6446c61
Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
24 | |
68
c637b172d565
Further fixes to bad color handling. Allow main color be represented with arbitrary transparency.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
67
diff
changeset
|
25 | static color* g_LDColors[MAX_COLORS]; |
48
113eb6446c61
Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
26 | static bool g_bColorsInit = false; |
113eb6446c61
Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
27 | |
113eb6446c61
Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
28 | void initColors () { |
113eb6446c61
Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
29 | if (g_bColorsInit) |
113eb6446c61
Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
30 | return; |
113eb6446c61
Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
31 | |
117
7eb7a43a511b
Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
104
diff
changeset
|
32 | logf ("%s: initializing color information.\n", __func__); |
99
920d51fec412
Recent files are now remembered and displayed in a submenu
Santeri Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
33 | |
147
291a1fe2d278
Further work on constrained cameras
Santeri Piippo <crimsondusk64@gmail.com>
parents:
138
diff
changeset
|
34 | color* col; |
291a1fe2d278
Further work on constrained cameras
Santeri Piippo <crimsondusk64@gmail.com>
parents:
138
diff
changeset
|
35 | |
72
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
36 | // Always make sure there's 16 and 24 available. They're special like that. |
147
291a1fe2d278
Further work on constrained cameras
Santeri Piippo <crimsondusk64@gmail.com>
parents:
138
diff
changeset
|
37 | col = new color; |
291a1fe2d278
Further work on constrained cameras
Santeri Piippo <crimsondusk64@gmail.com>
parents:
138
diff
changeset
|
38 | col->zColorString = "#AAAAAA"; |
291a1fe2d278
Further work on constrained cameras
Santeri Piippo <crimsondusk64@gmail.com>
parents:
138
diff
changeset
|
39 | col->qColor = col->zColorString.chars (); |
156
d35b7e440585
Added axes rendering
Santeri Piippo <crimsondusk64@gmail.com>
parents:
147
diff
changeset
|
40 | col->qEdge = Qt::black; |
147
291a1fe2d278
Further work on constrained cameras
Santeri Piippo <crimsondusk64@gmail.com>
parents:
138
diff
changeset
|
41 | g_LDColors[maincolor] = col; |
72
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
42 | |
147
291a1fe2d278
Further work on constrained cameras
Santeri Piippo <crimsondusk64@gmail.com>
parents:
138
diff
changeset
|
43 | col = new color; |
291a1fe2d278
Further work on constrained cameras
Santeri Piippo <crimsondusk64@gmail.com>
parents:
138
diff
changeset
|
44 | col->zColorString = "#000000"; |
156
d35b7e440585
Added axes rendering
Santeri Piippo <crimsondusk64@gmail.com>
parents:
147
diff
changeset
|
45 | col->qEdge = col->qColor = Qt::black; |
147
291a1fe2d278
Further work on constrained cameras
Santeri Piippo <crimsondusk64@gmail.com>
parents:
138
diff
changeset
|
46 | g_LDColors[edgecolor] = col; |
72
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
47 | |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
48 | parseLDConfig (); |
48
113eb6446c61
Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
49 | |
113eb6446c61
Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
50 | g_bColorsInit = true; |
68
c637b172d565
Further fixes to bad color handling. Allow main color be represented with arbitrary transparency.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
67
diff
changeset
|
51 | } |
c637b172d565
Further fixes to bad color handling. Allow main color be represented with arbitrary transparency.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
67
diff
changeset
|
52 | |
c637b172d565
Further fixes to bad color handling. Allow main color be represented with arbitrary transparency.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
67
diff
changeset
|
53 | // ============================================================================= |
c637b172d565
Further fixes to bad color handling. Allow main color be represented with arbitrary transparency.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
67
diff
changeset
|
54 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
c637b172d565
Further fixes to bad color handling. Allow main color be represented with arbitrary transparency.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
67
diff
changeset
|
55 | // ============================================================================= |
c637b172d565
Further fixes to bad color handling. Allow main color be represented with arbitrary transparency.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
67
diff
changeset
|
56 | color* getColor (short dColorNum) { |
c637b172d565
Further fixes to bad color handling. Allow main color be represented with arbitrary transparency.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
67
diff
changeset
|
57 | // Check bounds |
c637b172d565
Further fixes to bad color handling. Allow main color be represented with arbitrary transparency.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
67
diff
changeset
|
58 | if (dColorNum < 0 || dColorNum >= MAX_COLORS) |
104 | 59 | return null; |
68
c637b172d565
Further fixes to bad color handling. Allow main color be represented with arbitrary transparency.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
67
diff
changeset
|
60 | |
c637b172d565
Further fixes to bad color handling. Allow main color be represented with arbitrary transparency.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
67
diff
changeset
|
61 | return g_LDColors[dColorNum]; |
72
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
62 | } |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
63 | |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
64 | // ============================================================================= |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
65 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
66 | // ============================================================================= |
117
7eb7a43a511b
Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
104
diff
changeset
|
67 | static bool parseLDConfigTag (StringParser& pars, char const* sTag, str& zVal) { |
72
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
68 | short dPos; |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
69 | if (!pars.findToken (dPos, sTag, 1)) |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
70 | return false; |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
71 | |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
72 | return pars.getToken (zVal, dPos + 1); |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
73 | } |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
74 | |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
75 | // ============================================================================= |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
76 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
77 | // ============================================================================= |
100
e40358266290
Added user-configurable quick-coloring toolbar for.. quick coloring.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
99
diff
changeset
|
78 | short color::index () { |
e40358266290
Added user-configurable quick-coloring toolbar for.. quick coloring.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
99
diff
changeset
|
79 | short idx = 0; |
e40358266290
Added user-configurable quick-coloring toolbar for.. quick coloring.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
99
diff
changeset
|
80 | for (color* it : g_LDColors) { |
e40358266290
Added user-configurable quick-coloring toolbar for.. quick coloring.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
99
diff
changeset
|
81 | if (it == this) |
e40358266290
Added user-configurable quick-coloring toolbar for.. quick coloring.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
99
diff
changeset
|
82 | return idx; |
e40358266290
Added user-configurable quick-coloring toolbar for.. quick coloring.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
99
diff
changeset
|
83 | idx++; |
e40358266290
Added user-configurable quick-coloring toolbar for.. quick coloring.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
99
diff
changeset
|
84 | } |
e40358266290
Added user-configurable quick-coloring toolbar for.. quick coloring.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
99
diff
changeset
|
85 | |
e40358266290
Added user-configurable quick-coloring toolbar for.. quick coloring.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
99
diff
changeset
|
86 | return -1; |
e40358266290
Added user-configurable quick-coloring toolbar for.. quick coloring.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
99
diff
changeset
|
87 | } |
e40358266290
Added user-configurable quick-coloring toolbar for.. quick coloring.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
99
diff
changeset
|
88 | |
e40358266290
Added user-configurable quick-coloring toolbar for.. quick coloring.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
99
diff
changeset
|
89 | // ============================================================================= |
138
d22d5c1d9e8a
Added new subfile dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
90 | uchar luma (QColor& col) { |
d22d5c1d9e8a
Added new subfile dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
91 | return (0.2126f * col.red ()) + |
d22d5c1d9e8a
Added new subfile dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
92 | (0.7152f * col.green ()) + |
d22d5c1d9e8a
Added new subfile dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
93 | (0.0722f * col.blue ()); |
d22d5c1d9e8a
Added new subfile dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
94 | } |
d22d5c1d9e8a
Added new subfile dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
95 | |
d22d5c1d9e8a
Added new subfile dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
96 | // ============================================================================= |
100
e40358266290
Added user-configurable quick-coloring toolbar for.. quick coloring.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
99
diff
changeset
|
97 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
e40358266290
Added user-configurable quick-coloring toolbar for.. quick coloring.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
99
diff
changeset
|
98 | // ============================================================================= |
72
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
99 | void parseLDConfig () { |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
100 | FILE* fp = openLDrawFile ("LDConfig.ldr", false); |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
101 | |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
102 | if (!fp) |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
103 | return; |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
104 | |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
105 | // Even though LDConfig.ldr is technically an LDraw file, parsing it as one |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
106 | // would be overkill by any standard. |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
107 | char line[1024]; |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
108 | while (fgets (line, sizeof line, fp)) { |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
109 | if (strlen (line) == 0 || line[0] != '0') |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
110 | continue; // empty or illogical |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
111 | |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
112 | str zLine = line; |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
113 | zLine.replace ("\n", ""); |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
114 | zLine.replace ("\r", ""); |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
115 | |
117
7eb7a43a511b
Generalized SetContentsHistory to an EditHistory
Santeri Piippo <crimsondusk64@gmail.com>
parents:
104
diff
changeset
|
116 | StringParser pars (zLine, ' '); |
72
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
117 | short dCode = 0, dAlpha = 255; |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
118 | str zName, zColor, zEdge, zValue; |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
119 | |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
120 | // Check 0 !COLOUR, parse the name |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
121 | if (!pars.tokenCompare (0, "0") || !pars.tokenCompare (1, "!COLOUR") || !pars.getToken (zName, 2)) |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
122 | continue; |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
123 | |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
124 | // Replace underscores in the name with spaces for readability |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
125 | zName.replace ("_", " "); |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
126 | |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
127 | // get the CODE tag |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
128 | if (!parseLDConfigTag (pars, "CODE", zValue)) |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
129 | continue; |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
130 | |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
131 | // Ensure that the code is within range. must be within 0 - 512 |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
132 | dCode = atoi (zValue); |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
133 | if (dCode < 0 || dCode >= 512) |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
134 | continue; |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
135 | |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
136 | // Don't let LDConfig.ldr override the special colors 16 and 24. However, |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
137 | // do take the name it gives for the color |
147
291a1fe2d278
Further work on constrained cameras
Santeri Piippo <crimsondusk64@gmail.com>
parents:
138
diff
changeset
|
138 | if (dCode == maincolor || dCode == edgecolor) { |
72
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
139 | g_LDColors[dCode]->zName = zName; |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
140 | continue; |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
141 | } |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
142 | |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
143 | // VALUE tag |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
144 | if (!parseLDConfigTag (pars, "VALUE", zColor)) |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
145 | continue; |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
146 | |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
147 | // EDGE tag |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
148 | if (!parseLDConfigTag (pars, "EDGE", zEdge)) |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
149 | continue; |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
150 | |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
151 | // Ensure that our colors are correct |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
152 | QColor qColor (zColor.chars()), |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
153 | qEdge (zEdge.chars()); |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
154 | |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
155 | if (!qColor.isValid () || !qEdge.isValid ()) |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
156 | continue; |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
157 | |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
158 | // Parse alpha if given. |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
159 | if (parseLDConfigTag (pars, "ALPHA", zValue)) |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
160 | dAlpha = clamp<short> (atoi (zValue), 0, 255); |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
161 | |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
162 | color* col = new color; |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
163 | col->zName = zName; |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
164 | col->qColor = qColor; |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
165 | col->qEdge = qEdge; |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
166 | col->zColorString = zColor; |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
167 | col->qColor.setAlpha (dAlpha); |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
168 | |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
169 | g_LDColors[dCode] = col; |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
170 | } |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
171 | |
5755c02d89f0
Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
71
diff
changeset
|
172 | fclose (fp); |
48
113eb6446c61
Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
173 | } |