From 171f208cfb6f47cf6a6c19cfb2beed884c59664b Mon Sep 17 00:00:00 2001 From: EvilSpirit Date: Sat, 27 Feb 2016 12:15:15 +0600 Subject: [PATCH] Extract Style::FillDefaultStyle. --- src/file.cpp | 2 ++ src/sketch.h | 1 + src/style.cpp | 27 ++++++++++++++++----------- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/file.cpp b/src/file.cpp index 3bb88ab..d5b87b0 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -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 ") || diff --git a/src/sketch.h b/src/sketch.h index a6b5178..6c410ae 100644 --- a/src/sketch.h +++ b/src/sketch.h @@ -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); diff --git a/src/style.cpp b/src/style.cpp index a14a921..d18e9a0 100644 --- a/src/style.cpp +++ b/src/style.cpp @@ -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++) {