From 96344c85a6a318543e909ed6bf3b554d086cf760 Mon Sep 17 00:00:00 2001 From: EvilSpirit Date: Wed, 2 Mar 2016 23:15:28 +0600 Subject: [PATCH] Eliminate DEFAULT_TEXT_HEIGHT from drawing code. Instead, query the text height for constraint style. --- src/draw.cpp | 6 +++--- src/drawconstraint.cpp | 20 ++++++++++---------- src/drawentity.cpp | 2 +- src/groupmesh.cpp | 4 ++-- src/sketch.h | 1 + src/solvespace.h | 1 - src/style.cpp | 13 +++++++++---- 7 files changed, 26 insertions(+), 21 deletions(-) diff --git a/src/draw.cpp b/src/draw.cpp index 1a3ad0b6..cbd40630 100644 --- a/src/draw.cpp +++ b/src/draw.cpp @@ -809,7 +809,7 @@ nogrid:; ssglColorRGB(Style::Color(Style::DATUM)); ssglWriteText("previewing exported geometry; press Esc to return", - DEFAULT_TEXT_HEIGHT, + Style::DefaultTextHeight(), p.Plus(u.ScaledBy(10/scale)).Plus(v.ScaledBy(10/scale)), u, v, NULL, NULL); @@ -823,9 +823,9 @@ nogrid:; glEnd(); ssglWriteText("(x, y) = (0, 0) for file just exported", - DEFAULT_TEXT_HEIGHT, + Style::DefaultTextHeight(), p.Plus(u.ScaledBy(40/scale)).Plus( - v.ScaledBy(-(DEFAULT_TEXT_HEIGHT)/scale)), + v.ScaledBy(-(Style::DefaultTextHeight())/scale)), u, v, NULL, NULL); } } diff --git a/src/drawconstraint.cpp b/src/drawconstraint.cpp index 6f61149e..e689ecad 100644 --- a/src/drawconstraint.cpp +++ b/src/drawconstraint.cpp @@ -89,7 +89,7 @@ void Constraint::DoLabel(Vector ref, Vector *labelPos, Vector gr, Vector gu) { if(type == COMMENT) { th = Style::TextHeight(disp.style); } else { - th = DEFAULT_TEXT_HEIGHT; + th = Style::DefaultTextHeight(); } std::string s = Label(); @@ -164,8 +164,8 @@ int Constraint::DoLineTrimmedAgainstBox(Vector ref, Vector a, Vector b) { double pixels = 1.0 / SS.GW.scale; std::string s = Label(); - double swidth = ssglStrWidth(s, DEFAULT_TEXT_HEIGHT) + 4*pixels, - sheight = ssglStrHeight(DEFAULT_TEXT_HEIGHT) + 8*pixels; + double swidth = ssglStrWidth(s, Style::DefaultTextHeight()) + 4*pixels, + sheight = ssglStrHeight(Style::DefaultTextHeight()) + 8*pixels; struct { Vector n; @@ -369,8 +369,8 @@ void Constraint::DoArcForAngle(Vector a0, Vector da, Vector b0, Vector db, // complex and this looks pretty good. double tl = atan2(rm.Dot(gu), rm.Dot(gr)); double adj = EllipticalInterpolation( - ssglStrWidth(Label(), DEFAULT_TEXT_HEIGHT)/2, - ssglStrHeight(DEFAULT_TEXT_HEIGHT)/2, + ssglStrWidth(Label(), Style::DefaultTextHeight())/2, + ssglStrHeight(Style::DefaultTextHeight())/2, tl); *ref = (*ref).Plus(rm.WithMagnitude(adj + 3/SS.GW.scale)); } else { @@ -379,8 +379,8 @@ void Constraint::DoArcForAngle(Vector a0, Vector da, Vector b0, Vector db, *ref = (*ref).ScaledBy(0.5).Plus(disp.offset); gu = gu.WithMagnitude(1); Vector trans = - (*ref).Plus(gu.ScaledBy(-1.5*ssglStrHeight(DEFAULT_TEXT_HEIGHT))); - ssglWriteTextRefCenter("angle between skew lines", DEFAULT_TEXT_HEIGHT, + (*ref).Plus(gu.ScaledBy(-1.5*ssglStrHeight(Style::DefaultTextHeight()))); + ssglWriteTextRefCenter("angle between skew lines", Style::DefaultTextHeight(), trans, gr, gu, LineCallback, this); } } @@ -490,7 +490,7 @@ void Constraint::DrawOrGetDistance(Vector *labelPos) { if(!pt.Equals(closest)) { DoLineWithArrows(ref, pt, closest, true); - + // Extensions to line double pixels = 1.0 / SS.GW.scale; Vector refClosest = ref.ClosestPointOnLine(lA, dl); @@ -824,7 +824,7 @@ void Constraint::DrawOrGetDistance(Vector *labelPos) { } if(dogd.drawing) { - ssglWriteTextRefCenter("T", DEFAULT_TEXT_HEIGHT, + ssglWriteTextRefCenter("T", Style::DefaultTextHeight(), textAt, u, v, LineCallback, this); } else { dogd.refp = textAt; @@ -1008,7 +1008,7 @@ s: (type == VERTICAL) ? "V" : ( (type == AT_MIDPOINT) ? "M" : NULL)); - ssglWriteTextRefCenter(s, DEFAULT_TEXT_HEIGHT, + ssglWriteTextRefCenter(s, Style::DefaultTextHeight(), m.Plus(offset), r, u, LineCallback, this); } else { dogd.refp = m.Plus(offset); diff --git a/src/drawentity.cpp b/src/drawentity.cpp index c007457e..bb860264 100644 --- a/src/drawentity.cpp +++ b/src/drawentity.cpp @@ -602,7 +602,7 @@ void Entity::DrawOrGetDistance(void) { glDisable(GL_LINE_STIPPLE); std::string str = DescriptionString().substr(5); - double th = DEFAULT_TEXT_HEIGHT; + double th = Style::DefaultTextHeight(); if(dogd.drawing) { ssglWriteText(str, th, mm2, u, v, NULL, NULL); } else { diff --git a/src/groupmesh.cpp b/src/groupmesh.cpp index aba9f371..2ec0c682 100644 --- a/src/groupmesh.cpp +++ b/src/groupmesh.cpp @@ -505,7 +505,7 @@ void Group::Draw(void) { glEnd(); ssglColorRGB(Style::Color(Style::DRAW_ERROR)); ssglWriteText("not closed contour, or not all same style!", - DEFAULT_TEXT_HEIGHT, + Style::DefaultTextHeight(), polyError.notClosedAt.b, SS.GW.projRight, SS.GW.projUp, NULL, NULL); glEnable(GL_DEPTH_TEST); @@ -526,7 +526,7 @@ void Group::Draw(void) { } else { msg = "zero-length edge!"; } - ssglWriteText(msg, DEFAULT_TEXT_HEIGHT, + ssglWriteText(msg, Style::DefaultTextHeight(), polyError.errorPointAt, SS.GW.projRight, SS.GW.projUp, NULL, NULL); glEnable(GL_DEPTH_TEST); diff --git a/src/sketch.h b/src/sketch.h index 6b9f95a7..17d38010 100644 --- a/src/sketch.h +++ b/src/sketch.h @@ -808,6 +808,7 @@ public: static float Width(int hs); static double WidthMm(int hs); static double TextHeight(hStyle hs); + static double DefaultTextHeight(); static bool Exportable(int hs); static hStyle ForEntity(hEntity he); static int PatternType(hStyle hs); diff --git a/src/solvespace.h b/src/solvespace.h index efc9c2b5..b1b034c9 100644 --- a/src/solvespace.h +++ b/src/solvespace.h @@ -334,7 +334,6 @@ void ssglLineWidth(GLfloat width); void ssglVertex3v(Vector u); void ssglAxisAlignedQuad(double l, double r, double t, double b, bool lone = true); void ssglAxisAlignedLineLoop(double l, double r, double t, double b); -#define DEFAULT_TEXT_HEIGHT (11.5) #ifdef WIN32 # define SSGL_CALLBACK __stdcall #else diff --git a/src/style.cpp b/src/style.cpp index 0bb16c84..48a52a70 100644 --- a/src/style.cpp +++ b/src/style.cpp @@ -8,6 +8,8 @@ #include "solvespace.h" #include +#define DEFAULT_TEXT_HEIGHT 11.5 + const Style::Default Style::Defaults[] = { { { ACTIVE_GRP }, "ActiveGrp", RGBf(1.0, 1.0, 1.0), 1.5, }, { { CONSTRUCTION }, "Construction", RGBf(0.1, 0.7, 0.1), 1.5, }, @@ -66,7 +68,7 @@ void Style::CreateDefaultStyle(hStyle h) { Style ns = {}; FillDefaultStyle(&ns, d); - ns.h = h; + ns.h = h; if(isDefaultStyle) { ns.name = CnfPrefixToName(d->cnfPrefix); } else { @@ -278,13 +280,16 @@ double Style::TextHeight(hStyle hs) { Style *s = Get(hs); if(s->textHeightAs == UNITS_AS_MM) { return s->textHeight * SS.GW.scale; - } else if(s->textHeightAs == UNITS_AS_PIXELS) { + } else /* s->textHeightAs == UNITS_AS_PIXELS */ { return s->textHeight; - } else { - return DEFAULT_TEXT_HEIGHT; } } +double Style::DefaultTextHeight() { + hStyle hs { Style::CONSTRAINT }; + return TextHeight(hs); +} + //----------------------------------------------------------------------------- // Should lines and curves from this style appear in the output file? Only // if it's both shown and exportable.