From f09ae155862f456d70bbb1fc24b21784d69aea0e Mon Sep 17 00:00:00 2001 From: Jonathan Westhues Date: Sun, 3 Nov 2013 15:09:17 -0800 Subject: [PATCH] Fix broken colors in file import/export. The move to RgbColor() missed the code that reads and writes Style.color and Group.color. Also clarify redefinition of RGB() in w32main.cpp. --- file.cpp | 10 ++++++++-- win32/w32main.cpp | 8 ++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/file.cpp b/file.cpp index db55175f..6c5d0285 100644 --- a/file.cpp +++ b/file.cpp @@ -94,7 +94,7 @@ const SolveSpace::SaveTable SolveSpace::SAVED[] = { { 'g', "Group.valA", 'f', &(SS.sv.g.valA) }, { 'g', "Group.valB", 'f', &(SS.sv.g.valB) }, { 'g', "Group.valC", 'f', &(SS.sv.g.valB) }, - { 'g', "Group.color", 'x', &(SS.sv.g.color) }, + { 'g', "Group.color", 'c', &(SS.sv.g.color) }, { 'g', "Group.subtype", 'd', &(SS.sv.g.subtype) }, { 'g', "Group.skipFirst", 'b', &(SS.sv.g.skipFirst) }, { 'g', "Group.meshCombine", 'd', &(SS.sv.g.meshCombine) }, @@ -192,7 +192,7 @@ const SolveSpace::SaveTable SolveSpace::SAVED[] = { { 's', "Style.textHeightAs", 'd', &(SS.sv.s.textHeightAs) }, { 's', "Style.textAngle", 'f', &(SS.sv.s.textAngle) }, { 's', "Style.textOrigin", 'x', &(SS.sv.s.textOrigin) }, - { 's', "Style.color", 'x', &(SS.sv.s.color) }, + { 's', "Style.color", 'c', &(SS.sv.s.color) }, { 's', "Style.fillColor", 'x', &(SS.sv.s.fillColor) }, { 's', "Style.filled", 'b', &(SS.sv.s.filled) }, { 's', "Style.visible", 'b', &(SS.sv.s.visible) }, @@ -221,6 +221,7 @@ void SolveSpace::SaveUsingTable(int type) { case 'x': fprintf(fh, "%08x", *((uint32_t *)p)); break; case 'f': fprintf(fh, "%.20f", *((double *)p)); break; case 'N': fprintf(fh, "%s", ((NameStr *)p)->str); break; + case 'c': fprintf(fh, "%08x", ((RgbColor *)p)->ToPackedInt());break; case 'P': fprintf(fh, "%s", (char *)p); break; case 'M': { @@ -368,6 +369,11 @@ void SolveSpace::LoadUsingTable(char *key, char *val) { case 'f': *((double *)p) = atof(val); break; case 'N': ((NameStr *)p)->strcpy(val); break; + case 'c': + sscanf(val, "%x", &u); + *((RgbColor *)p) = RgbColor::FromPackedInt(u); + break; + case 'P': if(strlen(val)+1 < MAX_PATH) strcpy((char *)p, val); break; diff --git a/win32/w32main.cpp b/win32/w32main.cpp index 3946b6d4..3fd94020 100644 --- a/win32/w32main.cpp +++ b/win32/w32main.cpp @@ -8,8 +8,12 @@ #include "solvespace.h" #include #include -#undef RGB // our definition clashes with Microsoft's -#define RGB(r, g, b) ((COLORREF)0) +// we define RGB() to return our RgbColor, but that conflicts with Win32's +// definition; so put that back like Windows expects +#undef RGB +#define RGB(r,g,b) \ + ((COLORREF)(((BYTE)(r)|((WORD)((BYTE)(g))<<8))|(((DWORD)(BYTE)(b))<<16))) + #include #include