2013-08-09 06:57:18 +02:00
|
|
|
#include "lc_global.h"
|
|
|
|
#include "lc_colors.h"
|
|
|
|
#include "lc_file.h"
|
2021-01-22 23:16:28 +01:00
|
|
|
#include "lc_library.h"
|
2021-01-24 12:53:02 +01:00
|
|
|
#include "lc_application.h"
|
2013-08-09 06:57:18 +02:00
|
|
|
#include <float.h>
|
|
|
|
|
2019-07-05 02:06:26 +02:00
|
|
|
std::vector<lcColor> gColorList;
|
2013-08-09 06:57:18 +02:00
|
|
|
lcColorGroup gColorGroups[LC_NUM_COLORGROUPS];
|
|
|
|
int gEdgeColor;
|
|
|
|
int gDefaultColor;
|
|
|
|
|
2015-05-04 02:51:41 +02:00
|
|
|
lcVector4 gInterfaceColors[LC_NUM_INTERFACECOLORS] = // todo: make the colors configurable and include the grid and other hardcoded colors here as well.
|
|
|
|
{
|
2016-03-12 01:38:02 +01:00
|
|
|
lcVector4(0.898f, 0.298f, 0.400f, 1.000f), // LC_COLOR_SELECTED
|
|
|
|
lcVector4(0.400f, 0.298f, 0.898f, 1.000f), // LC_COLOR_FOCUSED
|
|
|
|
lcVector4(0.500f, 0.800f, 0.500f, 1.000f), // LC_COLOR_CAMERA
|
|
|
|
lcVector4(0.500f, 0.800f, 0.500f, 1.000f), // LC_COLOR_LIGHT
|
|
|
|
lcVector4(0.500f, 0.800f, 0.500f, 0.500f), // LC_COLOR_CONTROL_POINT
|
2017-06-20 03:30:54 +02:00
|
|
|
lcVector4(0.400f, 0.298f, 0.898f, 0.500f), // LC_COLOR_CONTROL_POINT_FOCUSED
|
2015-05-04 02:51:41 +02:00
|
|
|
};
|
|
|
|
|
2013-08-09 06:57:18 +02:00
|
|
|
static void GetToken(char*& Ptr, char* Token)
|
|
|
|
{
|
|
|
|
while (*Ptr && *Ptr <= 32)
|
|
|
|
Ptr++;
|
|
|
|
|
|
|
|
while (*Ptr > 32)
|
|
|
|
*Token++ = *Ptr++;
|
|
|
|
|
|
|
|
*Token = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int lcGetBrickLinkColor(int ColorIndex)
|
|
|
|
{
|
|
|
|
struct lcBrickLinkEntry
|
|
|
|
{
|
2019-06-06 00:24:53 +02:00
|
|
|
int LDraw;
|
|
|
|
int BrickLink;
|
2013-08-09 06:57:18 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
lcBrickLinkEntry BrickLinkColors[] =
|
|
|
|
{
|
2019-06-06 00:24:53 +02:00
|
|
|
{ 0, 11 }, // Black
|
|
|
|
{ 1, 7 }, // Blue
|
|
|
|
{ 2, 6 }, // Green
|
|
|
|
{ 3, 39 }, // Dark Turquoise
|
|
|
|
{ 4, 5 }, // Red
|
|
|
|
{ 5, 47 }, // Dark Pink
|
|
|
|
{ 6, 8 }, // Brown
|
|
|
|
{ 7, 9 }, // Light Gray
|
|
|
|
{ 8, 10 }, // Dark Gray
|
|
|
|
{ 9, 62 }, // Light Blue
|
|
|
|
{ 10, 36 }, // Bright Green
|
|
|
|
{ 11, 40 }, // Light Turquoise
|
|
|
|
{ 12, 25 }, // Salmon
|
|
|
|
{ 13, 23 }, // Pink
|
|
|
|
{ 14, 3 }, // Yellow
|
|
|
|
{ 15, 1 }, // White
|
2019-10-05 19:07:08 +02:00
|
|
|
{ 16, -1 }, // None
|
2019-06-06 00:24:53 +02:00
|
|
|
{ 17, 38 }, // Light Green
|
|
|
|
{ 18, 33 }, // Light Yellow
|
|
|
|
{ 19, 2 }, // Tan
|
|
|
|
{ 20, 44 }, // Light Violet
|
2019-10-05 19:07:08 +02:00
|
|
|
{ 21, 46 }, // Glow in Dark Opaque
|
2019-06-06 00:24:53 +02:00
|
|
|
{ 22, 24 }, // Purple
|
|
|
|
{ 23, 109 }, // Dark Blue-Violet
|
2019-10-05 19:07:08 +02:00
|
|
|
{ 24, -1 }, // None
|
2019-06-06 00:24:53 +02:00
|
|
|
{ 25, 4 }, // Orange
|
|
|
|
{ 26, 71 }, // Magenta
|
|
|
|
{ 27, 34 }, // Lime
|
|
|
|
{ 28, 69 }, // Dark Tan
|
|
|
|
{ 29, 104 }, // Bright Pink
|
2019-10-05 19:07:08 +02:00
|
|
|
{ 30, 157 }, // Medium Lavender
|
|
|
|
{ 31, 154 }, // Lavender
|
|
|
|
{ 32, 11 }, // Black
|
2019-06-06 00:24:53 +02:00
|
|
|
{ 33, 14 }, // Trans-Dark Blue
|
|
|
|
{ 34, 20 }, // Trans-Green
|
|
|
|
{ 35, 108 }, // Trans-Bright Green
|
|
|
|
{ 36, 17 }, // Trans-Red
|
2019-10-05 19:07:08 +02:00
|
|
|
{ 37, 50 }, // Trans-Dark Pink
|
|
|
|
{ 38, 18 }, // Trans-Neon Orange
|
|
|
|
{ 39, 113 }, // Trans-Very Lt Blue
|
2019-06-06 00:24:53 +02:00
|
|
|
{ 40, 13 }, // Trans-Black
|
2019-10-05 19:07:08 +02:00
|
|
|
{ 41, 74 }, // Trans-Medium Blue
|
2019-06-06 00:24:53 +02:00
|
|
|
{ 42, 16 }, // Trans-Neon Green
|
2019-10-05 19:07:08 +02:00
|
|
|
{ 43, 15 }, // Trans-Light Blue
|
|
|
|
{ 44, 114 }, // Trans-Light Purple
|
|
|
|
{ 45, 107 }, // Trans-Pink
|
2019-06-06 00:24:53 +02:00
|
|
|
{ 46, 19 }, // Trans-Yellow
|
|
|
|
{ 47, 12 }, // Trans-Clear
|
2019-10-05 19:07:08 +02:00
|
|
|
{ 52, 51 }, // Trans-Purple
|
2019-06-06 00:24:53 +02:00
|
|
|
{ 54, 121 }, // Trans-Neon Yellow
|
2019-10-05 19:07:08 +02:00
|
|
|
{ 57, 98 }, // Trans-Orange
|
2019-06-06 00:24:53 +02:00
|
|
|
{ 60, 57 }, // Chrome Antique Brass
|
|
|
|
{ 61, 52 }, // Chrome Blue
|
|
|
|
{ 62, 64 }, // Chrome Green
|
|
|
|
{ 63, 82 }, // Chrome Pink
|
|
|
|
{ 64, 122 }, // Chrome Black
|
2019-10-05 19:07:08 +02:00
|
|
|
{ 65, 3 }, // Yellow
|
|
|
|
{ 66, 19 }, // Trans-Yellow
|
|
|
|
{ 67, 12 }, // Trans-Clear
|
2019-06-06 00:24:53 +02:00
|
|
|
{ 68, 96 }, // Very Light Orange
|
|
|
|
{ 69, 93 }, // Light Purple
|
|
|
|
{ 70, 88 }, // Reddish Brown
|
|
|
|
{ 71, 86 }, // Light Bluish Gray
|
|
|
|
{ 72, 85 }, // Dark Bluish Gray
|
|
|
|
{ 73, 42 }, // Medium Blue
|
|
|
|
{ 74, 37 }, // Medium Green
|
|
|
|
{ 75, 116 }, // Speckle Black-Copper
|
|
|
|
{ 76, 117 }, // Speckle DBGray-Silver
|
|
|
|
{ 77, 56 }, // Light Pink
|
|
|
|
{ 78, 90 }, // Light Flesh
|
|
|
|
{ 79, 60 }, // Milky White
|
2019-10-05 19:07:08 +02:00
|
|
|
{ 80, 67 }, // Metallic Silver
|
|
|
|
{ 81, 70 }, // Metallic Green
|
|
|
|
{ 82, 65 }, // Metallic Gold
|
|
|
|
{ 83, 11 }, // Black
|
2019-06-06 00:24:53 +02:00
|
|
|
{ 84, 150 }, // Medium Dark Flesh
|
|
|
|
{ 85, 89 }, // Dark Purple
|
|
|
|
{ 86, 91 }, // Dark Flesh
|
2019-10-05 19:07:08 +02:00
|
|
|
{ 87, 77 }, // Pearl Dark Gray
|
|
|
|
{ 89, 97 }, // Blue - Violet
|
2019-06-06 00:24:53 +02:00
|
|
|
{ 92, 28 }, // Flesh
|
|
|
|
{ 100, 26 }, // Light Salmon
|
|
|
|
{ 110, 43 }, // Violet
|
2019-10-05 19:07:08 +02:00
|
|
|
{ 112, 73 }, // Medium Violet
|
2019-06-06 00:24:53 +02:00
|
|
|
{ 114, 100 }, // Glitter Trans-Dark Pink
|
|
|
|
{ 115, 76 }, // Medium Lime
|
|
|
|
{ 117, 101 }, // Glitter Trans-Clear
|
|
|
|
{ 118, 41 }, // Aqua
|
|
|
|
{ 120, 35 }, // Light Lime
|
|
|
|
{ 125, 32 }, // Light Orange
|
2019-10-05 19:07:08 +02:00
|
|
|
{ 128, 68 }, // Dark Orange
|
2019-06-06 00:24:53 +02:00
|
|
|
{ 129, 102 }, // Glitter Trans-Purple
|
|
|
|
{ 132, 111 }, // Speckle Black-Silver
|
2019-10-05 19:07:08 +02:00
|
|
|
{ 133, 151 }, // Speckle Black-Gold
|
2019-06-06 00:24:53 +02:00
|
|
|
{ 134, 84 }, // Copper
|
|
|
|
{ 135, 66 }, // Pearl Light Gray
|
|
|
|
{ 137, 78 }, // Metal Blue
|
|
|
|
{ 142, 61 }, // Pearl Light Gold
|
|
|
|
{ 148, 77 }, // Pearl Dark Gray
|
|
|
|
{ 150, 119 }, // Pearl Very Light Gray
|
|
|
|
{ 151, 99 }, // Very Light Bluish Gray
|
|
|
|
{ 178, 81 }, // Flat Dark Gold
|
|
|
|
{ 179, 95 }, // Flat Silver
|
|
|
|
{ 183, 83 }, // Pearl White
|
|
|
|
{ 191, 110 }, // Bright Light Orange
|
|
|
|
{ 212, 105 }, // Bright Light Blue
|
|
|
|
{ 216, 27 }, // Rust
|
|
|
|
{ 226, 103 }, // Bright Light Yellow
|
|
|
|
{ 232, 87 }, // Sky Blue
|
2019-10-05 19:07:08 +02:00
|
|
|
{ 256, 11 }, // Black
|
2019-06-06 00:24:53 +02:00
|
|
|
{ 272, 63 }, // Dark Blue
|
2019-10-05 19:07:08 +02:00
|
|
|
{ 273, 7 }, // Blue
|
|
|
|
{ 284, 114 }, // Trans-Light Purple
|
2019-06-06 00:24:53 +02:00
|
|
|
{ 288, 80 }, // Dark Green
|
|
|
|
{ 294, 118 }, // Glow In Dark Trans
|
|
|
|
{ 297, 115 }, // Pearl Gold
|
|
|
|
{ 308, 120 }, // Dark Brown
|
|
|
|
{ 313, 72 }, // Maersk Blue
|
|
|
|
{ 320, 59 }, // Dark Red
|
|
|
|
{ 321, 153 }, // Dark Azure
|
2019-10-05 19:07:08 +02:00
|
|
|
{ 322, 156 }, // Medium Azure
|
2019-06-06 00:24:53 +02:00
|
|
|
{ 323, 152 }, // Light Aqua
|
2019-10-05 19:07:08 +02:00
|
|
|
{ 324, 5 }, // Red
|
|
|
|
{ 326, 158 }, // Yellowish Green
|
|
|
|
{ 330, 155 }, // Olive Green
|
2019-06-06 00:24:53 +02:00
|
|
|
{ 334, 21 }, // Chrome Gold
|
|
|
|
{ 335, 58 }, // Sand Red
|
2019-10-05 19:07:08 +02:00
|
|
|
{ 350, 4 }, // Orange
|
2019-06-06 00:24:53 +02:00
|
|
|
{ 351, 94 }, // Medium Dark Pink
|
|
|
|
{ 366, 29 }, // Earth Orange
|
|
|
|
{ 373, 54 }, // Sand Purple
|
2019-10-05 19:07:08 +02:00
|
|
|
{ 375, 9 }, // Light Gray
|
2019-06-06 00:24:53 +02:00
|
|
|
{ 378, 48 }, // Sand Green
|
|
|
|
{ 379, 55 }, // Sand Blue
|
|
|
|
{ 383, 22 }, // Chrome Silver
|
2019-10-05 19:07:08 +02:00
|
|
|
{ 406, 63 }, // Dark Blue
|
|
|
|
{ 449, 24 }, // Purple
|
2019-06-06 00:24:53 +02:00
|
|
|
{ 450, 106 }, // Fabuland Brown
|
|
|
|
{ 462, 31 }, // Medium Orange
|
|
|
|
{ 484, 68 }, // Dark Orange
|
2019-10-05 19:07:08 +02:00
|
|
|
{ 490, 34 }, // Lime
|
|
|
|
{ 493, -10 }, // Magnet
|
|
|
|
{ 494, -11 }, // Electric_Contact_Alloy
|
|
|
|
{ 495, -12 }, // Electric_Contact_Copper
|
|
|
|
{ 496, 86 }, // Light Bluish Gray
|
2019-06-06 00:24:53 +02:00
|
|
|
{ 503, 49 }, // Very Light Gray
|
2019-10-05 19:07:08 +02:00
|
|
|
{ 504, 95 }, // Flat Silver
|
|
|
|
{ 511, 1 }, // White
|
|
|
|
{ 10001, 159 }, // Glow In Dark White
|
|
|
|
{ 10002, 160 }, // Fabuland Orange
|
|
|
|
{ 10003, 161 }, // Dark Yellow
|
|
|
|
{ 10004, 162 }, // Glitter Trans-Light Blue
|
|
|
|
{ 10005, 163 }, // Glitter Trans-Neon Green
|
|
|
|
{ 10006, 164 }, // Trans-Light Orange
|
|
|
|
{ 10007, 165 }, // Neon Orange
|
|
|
|
{ 10008, 220 }, // Coral
|
|
|
|
{ 10009, 166 }, // Neon Green
|
|
|
|
{ 10010, 221 } // Trans-Light Green
|
2013-08-09 06:57:18 +02:00
|
|
|
};
|
|
|
|
|
2019-06-06 00:24:53 +02:00
|
|
|
int ColorCode = gColorList[ColorIndex].Code;
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2019-12-09 20:43:54 +01:00
|
|
|
for (unsigned int Color = 0; Color < LC_ARRAY_COUNT(BrickLinkColors); Color++)
|
2019-06-06 00:24:53 +02:00
|
|
|
if (BrickLinkColors[Color].LDraw == ColorCode)
|
|
|
|
return BrickLinkColors[Color].BrickLink;
|
2013-08-09 06:57:18 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-01-23 19:16:44 +01:00
|
|
|
static void lcAdjustStudStyleColors(std::vector<lcColor>& Colors, lcStudStyle StudStyle)
|
2013-08-09 06:57:18 +02:00
|
|
|
{
|
2021-01-26 01:52:49 +01:00
|
|
|
const lcPreferences& Preferences = lcGetPreferences();
|
2021-01-26 23:58:02 +01:00
|
|
|
|
|
|
|
if (!Preferences.mAutomateEdgeColor && !lcIsHighContrast(StudStyle))
|
2021-01-26 18:38:34 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
const lcVector4 Edge = lcVector4FromColor(Preferences.mPartEdgeColor);
|
|
|
|
const lcVector4 DarkEdge = lcVector4FromColor(Preferences.mDarkEdgeColor);
|
|
|
|
const lcVector4 BlackEdge = lcVector4FromColor(Preferences.mBlackEdgeColor);
|
2021-01-26 01:52:49 +01:00
|
|
|
|
2021-02-02 18:23:01 +01:00
|
|
|
const float ContrastControl = Preferences.mPartEdgeContrast;
|
|
|
|
const float LightDarkControl = Preferences.mAutomateEdgeColor ?
|
|
|
|
Preferences.mPartColorValueLDIndex :
|
|
|
|
LC_SRGB_TO_LINEAR(Preferences.mPartColorValueLDIndex);
|
|
|
|
|
2021-01-26 18:38:34 +01:00
|
|
|
for (lcColor& Color : Colors)
|
2021-01-24 12:53:02 +01:00
|
|
|
{
|
2021-02-03 15:14:06 +01:00
|
|
|
const float ValueLuminescence = lcLuminescenceFromSRGB(Color.Value);
|
2021-01-24 12:53:02 +01:00
|
|
|
|
2021-01-26 18:38:34 +01:00
|
|
|
if (Preferences.mAutomateEdgeColor)
|
|
|
|
{
|
2021-02-02 18:23:01 +01:00
|
|
|
if (Color.Adjusted)
|
|
|
|
continue;
|
2021-01-24 12:53:02 +01:00
|
|
|
|
2021-02-03 15:14:06 +01:00
|
|
|
const float EdgeLuminescence = lcLuminescenceFromSRGB(Color.Edge);
|
2021-01-24 12:53:02 +01:00
|
|
|
|
2021-02-02 18:23:01 +01:00
|
|
|
Color.Edge = lcAlgorithmicEdgeColor(Color.Value, ValueLuminescence, EdgeLuminescence, ContrastControl, LightDarkControl);
|
|
|
|
Color.Adjusted = true;
|
2021-01-24 12:53:02 +01:00
|
|
|
}
|
2021-01-25 13:35:04 +01:00
|
|
|
else
|
2021-01-26 18:38:34 +01:00
|
|
|
{
|
|
|
|
if (Color.Code == 4242)
|
|
|
|
continue;
|
|
|
|
else if (Color.Code == 0)
|
|
|
|
Color.Edge = BlackEdge;
|
2021-02-02 18:23:01 +01:00
|
|
|
else if (ValueLuminescence < LightDarkControl)
|
2021-01-26 18:38:34 +01:00
|
|
|
Color.Edge = DarkEdge;
|
|
|
|
else
|
|
|
|
Color.Edge = Edge;
|
|
|
|
}
|
2021-01-20 11:56:30 +01:00
|
|
|
}
|
2021-01-22 22:40:16 +01:00
|
|
|
}
|
|
|
|
|
2021-01-23 19:16:44 +01:00
|
|
|
static std::vector<lcColor> lcParseColorFile(lcFile& File)
|
2021-01-22 22:40:16 +01:00
|
|
|
{
|
|
|
|
char Line[1024], Token[1024];
|
2021-01-23 19:16:44 +01:00
|
|
|
std::vector<lcColor> Colors;
|
|
|
|
lcColor Color;
|
2013-08-09 06:57:18 +02:00
|
|
|
|
|
|
|
while (File.ReadLine(Line, sizeof(Line)))
|
|
|
|
{
|
|
|
|
char* Ptr = Line;
|
|
|
|
|
|
|
|
GetToken(Ptr, Token);
|
|
|
|
if (strcmp(Token, "0"))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
GetToken(Ptr, Token);
|
|
|
|
strupr(Token);
|
|
|
|
if (strcmp(Token, "!COLOUR"))
|
|
|
|
continue;
|
|
|
|
|
2017-12-13 07:17:14 +01:00
|
|
|
Color.Code = ~0U;
|
2013-08-09 06:57:18 +02:00
|
|
|
Color.Translucent = false;
|
2021-01-23 19:16:44 +01:00
|
|
|
Color.Group = LC_COLORGROUP_SOLID;
|
2013-08-09 06:57:18 +02:00
|
|
|
Color.Value[0] = FLT_MAX;
|
|
|
|
Color.Value[1] = FLT_MAX;
|
|
|
|
Color.Value[2] = FLT_MAX;
|
|
|
|
Color.Value[3] = 1.0f;
|
|
|
|
Color.Edge[0] = FLT_MAX;
|
|
|
|
Color.Edge[1] = FLT_MAX;
|
|
|
|
Color.Edge[2] = FLT_MAX;
|
|
|
|
Color.Edge[3] = 1.0f;
|
|
|
|
|
|
|
|
GetToken(Ptr, Token);
|
|
|
|
strncpy(Color.Name, Token, sizeof(Color.Name));
|
|
|
|
Color.Name[LC_MAX_COLOR_NAME - 1] = 0;
|
|
|
|
strncpy(Color.SafeName, Color.Name, sizeof(Color.SafeName));
|
|
|
|
|
|
|
|
for (char* Underscore = strchr((char*)Color.Name, '_'); Underscore; Underscore = strchr(Underscore, '_'))
|
|
|
|
*Underscore = ' ';
|
|
|
|
|
|
|
|
for (GetToken(Ptr, Token); Token[0]; GetToken(Ptr, Token))
|
|
|
|
{
|
|
|
|
strupr(Token);
|
|
|
|
|
|
|
|
if (!strcmp(Token, "CODE"))
|
|
|
|
{
|
|
|
|
GetToken(Ptr, Token);
|
|
|
|
Color.Code = atoi(Token);
|
|
|
|
}
|
|
|
|
else if (!strcmp(Token, "VALUE"))
|
|
|
|
{
|
|
|
|
GetToken(Ptr, Token);
|
|
|
|
if (Token[0] == '#')
|
|
|
|
Token[0] = ' ';
|
|
|
|
|
|
|
|
int Value;
|
2017-04-03 02:15:09 +02:00
|
|
|
if (sscanf(Token, "%x", &Value) != 1)
|
|
|
|
Value = 0;
|
2013-08-09 06:57:18 +02:00
|
|
|
|
|
|
|
Color.Value[2] = (float)(Value & 0xff) / 255.0f;
|
|
|
|
Value >>= 8;
|
|
|
|
Color.Value[1] = (float)(Value & 0xff) / 255.0f;
|
|
|
|
Value >>= 8;
|
|
|
|
Color.Value[0] = (float)(Value & 0xff) / 255.0f;
|
|
|
|
}
|
|
|
|
else if (!strcmp(Token, "EDGE"))
|
|
|
|
{
|
|
|
|
GetToken(Ptr, Token);
|
|
|
|
if (Token[0] == '#')
|
|
|
|
Token[0] = ' ';
|
|
|
|
|
|
|
|
int Value;
|
2017-04-03 02:15:09 +02:00
|
|
|
if (sscanf(Token, "%x", &Value) != 1)
|
|
|
|
Value = 0;
|
2013-08-09 06:57:18 +02:00
|
|
|
|
|
|
|
Color.Edge[2] = (float)(Value & 0xff) / 255.0f;
|
|
|
|
Value >>= 8;
|
|
|
|
Color.Edge[1] = (float)(Value & 0xff) / 255.0f;
|
|
|
|
Value >>= 8;
|
|
|
|
Color.Edge[0] = (float)(Value & 0xff) / 255.0f;
|
|
|
|
}
|
|
|
|
else if (!strcmp(Token, "ALPHA"))
|
|
|
|
{
|
|
|
|
GetToken(Ptr, Token);
|
|
|
|
int Value = atoi(Token);
|
|
|
|
Color.Value[3] = (float)(Value & 0xff) / 255.0f;
|
|
|
|
if (Value != 255)
|
|
|
|
Color.Translucent = true;
|
|
|
|
|
|
|
|
if (Value == 128)
|
2021-01-23 19:16:44 +01:00
|
|
|
Color.Group = LC_COLORGROUP_TRANSLUCENT;
|
2013-08-09 06:57:18 +02:00
|
|
|
else if (Value != 0)
|
2021-01-23 19:16:44 +01:00
|
|
|
Color.Group = LC_COLORGROUP_SPECIAL;
|
2013-08-09 06:57:18 +02:00
|
|
|
}
|
|
|
|
else if (!strcmp(Token, "CHROME") || !strcmp(Token, "PEARLESCENT") || !strcmp(Token, "RUBBER") ||
|
2021-01-26 18:38:34 +01:00
|
|
|
!strcmp(Token, "MATTE_METALIC") || !strcmp(Token, "METAL") || !strcmp(Token, "LUMINANCE"))
|
2013-08-09 06:57:18 +02:00
|
|
|
{
|
2021-01-23 19:16:44 +01:00
|
|
|
Color.Group = LC_COLORGROUP_SPECIAL;
|
2013-08-09 06:57:18 +02:00
|
|
|
}
|
|
|
|
else if (!strcmp(Token, "MATERIAL"))
|
|
|
|
{
|
2021-01-23 19:16:44 +01:00
|
|
|
Color.Group = LC_COLORGROUP_SPECIAL;
|
2013-08-09 06:57:18 +02:00
|
|
|
break; // Material is always last so ignore it and the rest of the line.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-13 07:17:14 +01:00
|
|
|
if (Color.Code == ~0U || Color.Value[0] == FLT_MAX)
|
2013-08-09 06:57:18 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (Color.Edge[0] == FLT_MAX)
|
|
|
|
{
|
|
|
|
Color.Edge[0] = 33.0f / 255.0f;
|
|
|
|
Color.Edge[1] = 33.0f / 255.0f;
|
|
|
|
Color.Edge[2] = 33.0f / 255.0f;
|
|
|
|
}
|
|
|
|
|
2021-01-22 22:40:16 +01:00
|
|
|
bool Duplicate = false;
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2019-07-05 02:06:26 +02:00
|
|
|
for (lcColor& ExistingColor : Colors)
|
2013-08-09 06:57:18 +02:00
|
|
|
{
|
2019-07-05 02:06:26 +02:00
|
|
|
if (ExistingColor.Code == Color.Code)
|
2013-08-09 06:57:18 +02:00
|
|
|
{
|
2019-07-05 02:06:26 +02:00
|
|
|
ExistingColor = Color;
|
2021-01-22 22:40:16 +01:00
|
|
|
Duplicate = true;
|
2013-08-09 06:57:18 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-23 19:16:44 +01:00
|
|
|
if (!Duplicate)
|
|
|
|
Colors.push_back(Color);
|
|
|
|
}
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2021-01-23 19:16:44 +01:00
|
|
|
return Colors;
|
|
|
|
}
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2021-01-23 19:16:44 +01:00
|
|
|
bool lcLoadColorFile(lcFile& File, lcStudStyle StudStyle)
|
|
|
|
{
|
|
|
|
std::vector<lcColor> Colors = lcParseColorFile(File);
|
|
|
|
const bool Valid = !Colors.empty();
|
|
|
|
|
|
|
|
if (Valid)
|
|
|
|
lcAdjustStudStyleColors(Colors, StudStyle);
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2021-02-01 02:32:38 +01:00
|
|
|
bool FoundMain = false, FoundEdge = false, FoundStud = false, FoundNoColor = false;
|
2021-01-23 19:16:44 +01:00
|
|
|
|
|
|
|
for (const lcColor& Color : Colors)
|
|
|
|
{
|
|
|
|
switch (Color.Code)
|
2021-01-22 22:40:16 +01:00
|
|
|
{
|
2021-01-23 19:16:44 +01:00
|
|
|
case 16:
|
|
|
|
FoundMain = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 24:
|
|
|
|
FoundEdge = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4242:
|
|
|
|
FoundStud = true;
|
|
|
|
break;
|
2021-02-01 02:32:38 +01:00
|
|
|
|
|
|
|
case LC_COLOR_NOCOLOR:
|
|
|
|
FoundNoColor = true;
|
|
|
|
break;
|
2021-01-22 22:40:16 +01:00
|
|
|
}
|
2021-01-23 19:16:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!FoundMain)
|
|
|
|
{
|
|
|
|
lcColor MainColor;
|
|
|
|
|
|
|
|
MainColor.Code = 16;
|
|
|
|
MainColor.Translucent = false;
|
|
|
|
MainColor.Group = LC_COLORGROUP_SOLID;
|
|
|
|
MainColor.Value[0] = 1.0f;
|
|
|
|
MainColor.Value[1] = 1.0f;
|
|
|
|
MainColor.Value[2] = 0.5f;
|
|
|
|
MainColor.Value[3] = 1.0f;
|
|
|
|
MainColor.Edge[0] = 0.2f;
|
|
|
|
MainColor.Edge[1] = 0.2f;
|
|
|
|
MainColor.Edge[2] = 0.2f;
|
|
|
|
MainColor.Edge[3] = 1.0f;
|
|
|
|
strcpy(MainColor.Name, "Main Color");
|
|
|
|
strcpy(MainColor.SafeName, "Main_Color");
|
|
|
|
|
|
|
|
Colors.push_back(MainColor);
|
|
|
|
}
|
2021-01-22 22:40:16 +01:00
|
|
|
|
2021-01-23 19:16:44 +01:00
|
|
|
if (!FoundEdge)
|
|
|
|
{
|
|
|
|
lcColor EdgeColor;
|
|
|
|
|
|
|
|
EdgeColor.Code = 24;
|
|
|
|
EdgeColor.Translucent = false;
|
|
|
|
EdgeColor.Group = LC_NUM_COLORGROUPS;
|
|
|
|
EdgeColor.Value[0] = 0.5f;
|
|
|
|
EdgeColor.Value[1] = 0.5f;
|
|
|
|
EdgeColor.Value[2] = 0.5f;
|
|
|
|
EdgeColor.Value[3] = 1.0f;
|
|
|
|
EdgeColor.Edge[0] = 0.2f;
|
|
|
|
EdgeColor.Edge[1] = 0.2f;
|
|
|
|
EdgeColor.Edge[2] = 0.2f;
|
|
|
|
EdgeColor.Edge[3] = 1.0f;
|
|
|
|
strcpy(EdgeColor.Name, "Edge Color");
|
|
|
|
strcpy(EdgeColor.SafeName, "Edge_Color");
|
|
|
|
|
|
|
|
Colors.push_back(EdgeColor);
|
|
|
|
}
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2021-01-23 19:16:44 +01:00
|
|
|
if (!FoundStud)
|
|
|
|
{
|
2021-01-26 01:52:49 +01:00
|
|
|
const lcPreferences& Preferences = lcGetPreferences();
|
2021-01-26 16:42:19 +01:00
|
|
|
lcColor StudCylinderColor;
|
2021-01-26 01:52:49 +01:00
|
|
|
|
2021-01-26 16:42:19 +01:00
|
|
|
StudCylinderColor.Code = 4242;
|
|
|
|
StudCylinderColor.Translucent = false;
|
|
|
|
StudCylinderColor.Group = LC_NUM_COLORGROUPS;
|
|
|
|
StudCylinderColor.Value = lcVector4FromColor(Preferences.mStudCylinderColor);
|
|
|
|
StudCylinderColor.Edge = lcVector4FromColor(Preferences.mPartEdgeColor);
|
|
|
|
strcpy(StudCylinderColor.Name, "Stud Cylinder Color");
|
|
|
|
strcpy(StudCylinderColor.SafeName, "Stud_Cylinder_Color");
|
2021-01-23 19:16:44 +01:00
|
|
|
|
2021-01-26 16:42:19 +01:00
|
|
|
Colors.push_back(StudCylinderColor);
|
2013-08-09 06:57:18 +02:00
|
|
|
}
|
|
|
|
|
2021-02-01 02:32:38 +01:00
|
|
|
if (!FoundNoColor)
|
|
|
|
{
|
|
|
|
lcColor NoColor;
|
|
|
|
|
|
|
|
NoColor.Code = LC_COLOR_NOCOLOR;
|
|
|
|
NoColor.Translucent = false;
|
|
|
|
NoColor.Group = LC_NUM_COLORGROUPS;
|
|
|
|
NoColor.Value[0] = 0.5f;
|
|
|
|
NoColor.Value[1] = 0.5f;
|
|
|
|
NoColor.Value[2] = 0.5f;
|
|
|
|
NoColor.Value[3] = 1.0f;
|
|
|
|
NoColor.Edge[0] = 0.2f;
|
|
|
|
NoColor.Edge[1] = 0.2f;
|
|
|
|
NoColor.Edge[2] = 0.2f;
|
|
|
|
NoColor.Edge[3] = 1.0f;
|
|
|
|
strcpy(NoColor.Name, "No Color");
|
|
|
|
strcpy(NoColor.SafeName, "No_Color");
|
|
|
|
|
|
|
|
Colors.push_back(NoColor);
|
|
|
|
}
|
|
|
|
|
2021-01-23 19:16:44 +01:00
|
|
|
for (lcColor& Color : gColorList)
|
|
|
|
Color.Group = LC_NUM_COLORGROUPS;
|
|
|
|
|
|
|
|
for (int GroupIdx = 0; GroupIdx < LC_NUM_COLORGROUPS; GroupIdx++)
|
|
|
|
gColorGroups[GroupIdx].Colors.clear();
|
|
|
|
|
|
|
|
gColorGroups[0].Name = QApplication::tr("Solid", "Colors");
|
|
|
|
gColorGroups[1].Name = QApplication::tr("Translucent", "Colors");
|
|
|
|
gColorGroups[2].Name = QApplication::tr("Special", "Colors");
|
|
|
|
|
|
|
|
for (lcColor& Color : Colors)
|
|
|
|
{
|
|
|
|
int ColorIndex;
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2021-01-23 19:16:44 +01:00
|
|
|
for (ColorIndex = 0; ColorIndex < static_cast<int>(gColorList.size()); ColorIndex++)
|
|
|
|
if (gColorList[ColorIndex].Code == Color.Code)
|
|
|
|
break;
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2021-01-23 19:52:45 +01:00
|
|
|
if (ColorIndex == static_cast<int>(gColorList.size()))
|
2021-01-23 19:16:44 +01:00
|
|
|
gColorList.push_back(Color);
|
|
|
|
else
|
|
|
|
gColorList[ColorIndex] = Color;
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2021-01-23 19:16:44 +01:00
|
|
|
if (Color.Group != LC_NUM_COLORGROUPS)
|
|
|
|
gColorGroups[Color.Group].Colors.push_back(ColorIndex);
|
|
|
|
|
|
|
|
if (Color.Code == 16)
|
|
|
|
gDefaultColor = ColorIndex;
|
|
|
|
else if (Color.Code == 24)
|
|
|
|
gEdgeColor = ColorIndex;
|
|
|
|
}
|
2021-01-22 22:40:16 +01:00
|
|
|
|
2021-01-23 19:16:44 +01:00
|
|
|
return Valid;
|
2013-08-09 06:57:18 +02:00
|
|
|
}
|
|
|
|
|
2021-01-22 23:16:28 +01:00
|
|
|
void lcLoadDefaultColors(lcStudStyle StudStyle)
|
2013-08-09 06:57:18 +02:00
|
|
|
{
|
2020-12-11 23:14:54 +01:00
|
|
|
lcDiskFile ConfigFile(":/resources/ldconfig.ldr");
|
2017-02-05 04:37:40 +01:00
|
|
|
|
2020-12-11 23:14:54 +01:00
|
|
|
if (ConfigFile.Open(QIODevice::ReadOnly))
|
2021-01-22 22:40:16 +01:00
|
|
|
lcLoadColorFile(ConfigFile, StudStyle);
|
2013-08-09 06:57:18 +02:00
|
|
|
}
|
|
|
|
|
2017-12-02 21:22:04 +01:00
|
|
|
int lcGetColorIndex(quint32 ColorCode)
|
2013-08-09 06:57:18 +02:00
|
|
|
{
|
2019-07-09 03:34:34 +02:00
|
|
|
for (size_t ColorIdx = 0; ColorIdx < gColorList.size(); ColorIdx++)
|
2013-08-09 06:57:18 +02:00
|
|
|
if (gColorList[ColorIdx].Code == ColorCode)
|
2019-07-09 17:47:15 +02:00
|
|
|
return (int)ColorIdx;
|
2013-08-09 06:57:18 +02:00
|
|
|
|
|
|
|
lcColor Color;
|
|
|
|
|
|
|
|
Color.Code = ColorCode;
|
|
|
|
Color.Translucent = false;
|
|
|
|
Color.Edge[0] = 0.2f;
|
|
|
|
Color.Edge[1] = 0.2f;
|
|
|
|
Color.Edge[2] = 0.2f;
|
|
|
|
Color.Edge[3] = 1.0f;
|
|
|
|
|
|
|
|
if (ColorCode & LC_COLOR_DIRECT)
|
|
|
|
{
|
|
|
|
Color.Value[0] = (float)((ColorCode & 0xff0000) >> 16) / 255.0f;
|
2021-01-22 22:40:16 +01:00
|
|
|
Color.Value[1] = (float)((ColorCode & 0x00ff00) >> 8) / 255.0f;
|
|
|
|
Color.Value[2] = (float)((ColorCode & 0x0000ff) >> 0) / 255.0f;
|
2013-08-09 06:57:18 +02:00
|
|
|
Color.Value[3] = 1.0f;
|
|
|
|
sprintf(Color.Name, "Color %06X", ColorCode & 0xffffff);
|
|
|
|
sprintf(Color.SafeName, "Color_%06X", ColorCode & 0xffffff);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Color.Value[0] = 0.5f;
|
|
|
|
Color.Value[1] = 0.5f;
|
|
|
|
Color.Value[2] = 0.5f;
|
|
|
|
Color.Value[3] = 1.0f;
|
|
|
|
sprintf(Color.Name, "Color %03d", ColorCode);
|
|
|
|
sprintf(Color.SafeName, "Color_%03d", ColorCode);
|
|
|
|
}
|
|
|
|
|
2019-07-05 02:06:26 +02:00
|
|
|
gColorList.push_back(Color);
|
|
|
|
return (int)gColorList.size() - 1;
|
2013-08-09 06:57:18 +02:00
|
|
|
}
|