Extract Style::FillDefaultStyle.

This commit is contained in:
EvilSpirit 2016-02-27 12:15:15 +06:00 committed by whitequark
parent c9a2092b9c
commit 171f208cfb
3 changed files with 19 additions and 11 deletions

View File

@ -437,6 +437,7 @@ bool SolveSpaceUI::LoadFromFile(const std::string &filename) {
sv = {};
sv.g.scale = 1; // default is 1, not 0; so legacy files need this
Style::FillDefaultStyle(&sv.s);
char line[1024];
while(fgets(line, (int)sizeof(line), fh)) {
@ -479,6 +480,7 @@ bool SolveSpaceUI::LoadFromFile(const std::string &filename) {
} else if(strcmp(line, "AddStyle")==0) {
SK.style.Add(&(sv.s));
sv.s = {};
Style::FillDefaultStyle(&sv.s);
} else if(strcmp(line, VERSION_STRING)==0) {
// do nothing, version string
} else if(StrStartsWith(line, "Triangle ") ||

View File

@ -774,6 +774,7 @@ public:
static void CreateAllDefaultStyles(void);
static void CreateDefaultStyle(hStyle h);
static void FillDefaultStyle(Style *s, const Default *d = NULL);
static void FreezeDefaultStyles(void);
static void LoadFactoryDefaults(void);

View File

@ -65,17 +65,7 @@ void Style::CreateDefaultStyle(hStyle h) {
}
Style ns = {};
ns.color = CnfThawColor(d->color, CnfColor(d->cnfPrefix));
ns.width = CnfThawFloat((float)(d->width), CnfWidth(d->cnfPrefix));
ns.widthAs = UNITS_AS_PIXELS;
ns.textHeight = DEFAULT_TEXT_HEIGHT;
ns.textHeightAs = UNITS_AS_PIXELS;
ns.textOrigin = 0;
ns.textAngle = 0;
ns.visible = true;
ns.exportable = true;
ns.filled = false;
ns.fillColor = RGBf(0.3, 0.3, 0.3);
FillDefaultStyle(&ns, d);
ns.h = h;
if(isDefaultStyle) {
ns.name = CnfPrefixToName(d->cnfPrefix);
@ -86,6 +76,21 @@ void Style::CreateDefaultStyle(hStyle h) {
SK.style.Add(&ns);
}
void Style::FillDefaultStyle(Style *s, const Default *d) {
if(d == NULL) d = &Defaults[0];
s->color = CnfThawColor(d->color, CnfColor(d->cnfPrefix));
s->width = CnfThawFloat((float)(d->width), CnfWidth(d->cnfPrefix));
s->widthAs = UNITS_AS_PIXELS;
s->textHeight = DEFAULT_TEXT_HEIGHT;
s->textHeightAs = UNITS_AS_PIXELS;
s->textOrigin = 0;
s->textAngle = 0;
s->visible = true;
s->exportable = true;
s->filled = false;
s->fillColor = RGBf(0.3, 0.3, 0.3);
}
void Style::LoadFactoryDefaults(void) {
const Default *d;
for(d = &(Defaults[0]); d->h.v; d++) {