Eliminate DEFAULT_TEXT_HEIGHT from drawing code.

Instead, query the text height for constraint style.
This commit is contained in:
EvilSpirit 2016-03-02 23:15:28 +06:00 committed by whitequark
parent 1f0649d1bb
commit 96344c85a6
7 changed files with 26 additions and 21 deletions

View File

@ -809,7 +809,7 @@ nogrid:;
ssglColorRGB(Style::Color(Style::DATUM)); ssglColorRGB(Style::Color(Style::DATUM));
ssglWriteText("previewing exported geometry; press Esc to return", ssglWriteText("previewing exported geometry; press Esc to return",
DEFAULT_TEXT_HEIGHT, Style::DefaultTextHeight(),
p.Plus(u.ScaledBy(10/scale)).Plus(v.ScaledBy(10/scale)), p.Plus(u.ScaledBy(10/scale)).Plus(v.ScaledBy(10/scale)),
u, v, NULL, NULL); u, v, NULL, NULL);
@ -823,9 +823,9 @@ nogrid:;
glEnd(); glEnd();
ssglWriteText("(x, y) = (0, 0) for file just exported", ssglWriteText("(x, y) = (0, 0) for file just exported",
DEFAULT_TEXT_HEIGHT, Style::DefaultTextHeight(),
p.Plus(u.ScaledBy(40/scale)).Plus( p.Plus(u.ScaledBy(40/scale)).Plus(
v.ScaledBy(-(DEFAULT_TEXT_HEIGHT)/scale)), v.ScaledBy(-(Style::DefaultTextHeight())/scale)),
u, v, NULL, NULL); u, v, NULL, NULL);
} }
} }

View File

@ -89,7 +89,7 @@ void Constraint::DoLabel(Vector ref, Vector *labelPos, Vector gr, Vector gu) {
if(type == COMMENT) { if(type == COMMENT) {
th = Style::TextHeight(disp.style); th = Style::TextHeight(disp.style);
} else { } else {
th = DEFAULT_TEXT_HEIGHT; th = Style::DefaultTextHeight();
} }
std::string s = Label(); std::string s = Label();
@ -164,8 +164,8 @@ int Constraint::DoLineTrimmedAgainstBox(Vector ref, Vector a, Vector b) {
double pixels = 1.0 / SS.GW.scale; double pixels = 1.0 / SS.GW.scale;
std::string s = Label(); std::string s = Label();
double swidth = ssglStrWidth(s, DEFAULT_TEXT_HEIGHT) + 4*pixels, double swidth = ssglStrWidth(s, Style::DefaultTextHeight()) + 4*pixels,
sheight = ssglStrHeight(DEFAULT_TEXT_HEIGHT) + 8*pixels; sheight = ssglStrHeight(Style::DefaultTextHeight()) + 8*pixels;
struct { struct {
Vector n; Vector n;
@ -369,8 +369,8 @@ void Constraint::DoArcForAngle(Vector a0, Vector da, Vector b0, Vector db,
// complex and this looks pretty good. // complex and this looks pretty good.
double tl = atan2(rm.Dot(gu), rm.Dot(gr)); double tl = atan2(rm.Dot(gu), rm.Dot(gr));
double adj = EllipticalInterpolation( double adj = EllipticalInterpolation(
ssglStrWidth(Label(), DEFAULT_TEXT_HEIGHT)/2, ssglStrWidth(Label(), Style::DefaultTextHeight())/2,
ssglStrHeight(DEFAULT_TEXT_HEIGHT)/2, ssglStrHeight(Style::DefaultTextHeight())/2,
tl); tl);
*ref = (*ref).Plus(rm.WithMagnitude(adj + 3/SS.GW.scale)); *ref = (*ref).Plus(rm.WithMagnitude(adj + 3/SS.GW.scale));
} else { } else {
@ -379,8 +379,8 @@ void Constraint::DoArcForAngle(Vector a0, Vector da, Vector b0, Vector db,
*ref = (*ref).ScaledBy(0.5).Plus(disp.offset); *ref = (*ref).ScaledBy(0.5).Plus(disp.offset);
gu = gu.WithMagnitude(1); gu = gu.WithMagnitude(1);
Vector trans = Vector trans =
(*ref).Plus(gu.ScaledBy(-1.5*ssglStrHeight(DEFAULT_TEXT_HEIGHT))); (*ref).Plus(gu.ScaledBy(-1.5*ssglStrHeight(Style::DefaultTextHeight())));
ssglWriteTextRefCenter("angle between skew lines", DEFAULT_TEXT_HEIGHT, ssglWriteTextRefCenter("angle between skew lines", Style::DefaultTextHeight(),
trans, gr, gu, LineCallback, this); trans, gr, gu, LineCallback, this);
} }
} }
@ -490,7 +490,7 @@ void Constraint::DrawOrGetDistance(Vector *labelPos) {
if(!pt.Equals(closest)) { if(!pt.Equals(closest)) {
DoLineWithArrows(ref, pt, closest, true); DoLineWithArrows(ref, pt, closest, true);
// Extensions to line // Extensions to line
double pixels = 1.0 / SS.GW.scale; double pixels = 1.0 / SS.GW.scale;
Vector refClosest = ref.ClosestPointOnLine(lA, dl); Vector refClosest = ref.ClosestPointOnLine(lA, dl);
@ -824,7 +824,7 @@ void Constraint::DrawOrGetDistance(Vector *labelPos) {
} }
if(dogd.drawing) { if(dogd.drawing) {
ssglWriteTextRefCenter("T", DEFAULT_TEXT_HEIGHT, ssglWriteTextRefCenter("T", Style::DefaultTextHeight(),
textAt, u, v, LineCallback, this); textAt, u, v, LineCallback, this);
} else { } else {
dogd.refp = textAt; dogd.refp = textAt;
@ -1008,7 +1008,7 @@ s:
(type == VERTICAL) ? "V" : ( (type == VERTICAL) ? "V" : (
(type == AT_MIDPOINT) ? "M" : NULL)); (type == AT_MIDPOINT) ? "M" : NULL));
ssglWriteTextRefCenter(s, DEFAULT_TEXT_HEIGHT, ssglWriteTextRefCenter(s, Style::DefaultTextHeight(),
m.Plus(offset), r, u, LineCallback, this); m.Plus(offset), r, u, LineCallback, this);
} else { } else {
dogd.refp = m.Plus(offset); dogd.refp = m.Plus(offset);

View File

@ -602,7 +602,7 @@ void Entity::DrawOrGetDistance(void) {
glDisable(GL_LINE_STIPPLE); glDisable(GL_LINE_STIPPLE);
std::string str = DescriptionString().substr(5); std::string str = DescriptionString().substr(5);
double th = DEFAULT_TEXT_HEIGHT; double th = Style::DefaultTextHeight();
if(dogd.drawing) { if(dogd.drawing) {
ssglWriteText(str, th, mm2, u, v, NULL, NULL); ssglWriteText(str, th, mm2, u, v, NULL, NULL);
} else { } else {

View File

@ -505,7 +505,7 @@ void Group::Draw(void) {
glEnd(); glEnd();
ssglColorRGB(Style::Color(Style::DRAW_ERROR)); ssglColorRGB(Style::Color(Style::DRAW_ERROR));
ssglWriteText("not closed contour, or not all same style!", ssglWriteText("not closed contour, or not all same style!",
DEFAULT_TEXT_HEIGHT, Style::DefaultTextHeight(),
polyError.notClosedAt.b, SS.GW.projRight, SS.GW.projUp, polyError.notClosedAt.b, SS.GW.projRight, SS.GW.projUp,
NULL, NULL); NULL, NULL);
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
@ -526,7 +526,7 @@ void Group::Draw(void) {
} else { } else {
msg = "zero-length edge!"; msg = "zero-length edge!";
} }
ssglWriteText(msg, DEFAULT_TEXT_HEIGHT, ssglWriteText(msg, Style::DefaultTextHeight(),
polyError.errorPointAt, SS.GW.projRight, SS.GW.projUp, polyError.errorPointAt, SS.GW.projRight, SS.GW.projUp,
NULL, NULL); NULL, NULL);
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);

View File

@ -808,6 +808,7 @@ public:
static float Width(int hs); static float Width(int hs);
static double WidthMm(int hs); static double WidthMm(int hs);
static double TextHeight(hStyle hs); static double TextHeight(hStyle hs);
static double DefaultTextHeight();
static bool Exportable(int hs); static bool Exportable(int hs);
static hStyle ForEntity(hEntity he); static hStyle ForEntity(hEntity he);
static int PatternType(hStyle hs); static int PatternType(hStyle hs);

View File

@ -334,7 +334,6 @@ void ssglLineWidth(GLfloat width);
void ssglVertex3v(Vector u); void ssglVertex3v(Vector u);
void ssglAxisAlignedQuad(double l, double r, double t, double b, bool lone = true); void ssglAxisAlignedQuad(double l, double r, double t, double b, bool lone = true);
void ssglAxisAlignedLineLoop(double l, double r, double t, double b); void ssglAxisAlignedLineLoop(double l, double r, double t, double b);
#define DEFAULT_TEXT_HEIGHT (11.5)
#ifdef WIN32 #ifdef WIN32
# define SSGL_CALLBACK __stdcall # define SSGL_CALLBACK __stdcall
#else #else

View File

@ -8,6 +8,8 @@
#include "solvespace.h" #include "solvespace.h"
#include <png.h> #include <png.h>
#define DEFAULT_TEXT_HEIGHT 11.5
const Style::Default Style::Defaults[] = { const Style::Default Style::Defaults[] = {
{ { ACTIVE_GRP }, "ActiveGrp", RGBf(1.0, 1.0, 1.0), 1.5, }, { { ACTIVE_GRP }, "ActiveGrp", RGBf(1.0, 1.0, 1.0), 1.5, },
{ { CONSTRUCTION }, "Construction", RGBf(0.1, 0.7, 0.1), 1.5, }, { { CONSTRUCTION }, "Construction", RGBf(0.1, 0.7, 0.1), 1.5, },
@ -66,7 +68,7 @@ void Style::CreateDefaultStyle(hStyle h) {
Style ns = {}; Style ns = {};
FillDefaultStyle(&ns, d); FillDefaultStyle(&ns, d);
ns.h = h; ns.h = h;
if(isDefaultStyle) { if(isDefaultStyle) {
ns.name = CnfPrefixToName(d->cnfPrefix); ns.name = CnfPrefixToName(d->cnfPrefix);
} else { } else {
@ -278,13 +280,16 @@ double Style::TextHeight(hStyle hs) {
Style *s = Get(hs); Style *s = Get(hs);
if(s->textHeightAs == UNITS_AS_MM) { if(s->textHeightAs == UNITS_AS_MM) {
return s->textHeight * SS.GW.scale; return s->textHeight * SS.GW.scale;
} else if(s->textHeightAs == UNITS_AS_PIXELS) { } else /* s->textHeightAs == UNITS_AS_PIXELS */ {
return s->textHeight; 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 // Should lines and curves from this style appear in the output file? Only
// if it's both shown and exportable. // if it's both shown and exportable.