Allow changing text size for default styles.

This is especially useful for High-DPI displays on non-OS X.
pull/4/head
EvilSpirit 2016-02-22 01:07:58 +06:00 committed by whitequark
parent 96344c85a6
commit a0576e2a50
3 changed files with 25 additions and 27 deletions

View File

@ -10,21 +10,13 @@
void Constraint::LineDrawOrGetDistance(Vector a, Vector b) {
if(dogd.drawing) {
// Draw comments in the specified style, but everything else in the
// default style for constraints.
hStyle hs;
if(type == COMMENT && disp.style.v) {
hs = disp.style;
} else {
hs.v = Style::CONSTRAINT;
}
hStyle hs = disp.style;
if(hs.v == 0) hs.v = Style::CONSTRAINT;
if(dogd.sel) {
dogd.sel->AddEdge(a, b, hs.v);
} else {
// The only constraints with styles should be comments, so don't
// check otherwise, save looking up the styles constantly.
if(type == COMMENT && Style::Width(hs) >= 3.0) {
if(Style::Width(hs) >= 3.0) {
ssglFatLine(a, b, Style::Width(hs) / SS.GW.scale);
} else {
glBegin(GL_LINE_STRIP);
@ -85,12 +77,9 @@ std::string Constraint::Label(void) {
}
void Constraint::DoLabel(Vector ref, Vector *labelPos, Vector gr, Vector gu) {
double th;
if(type == COMMENT) {
th = Style::TextHeight(disp.style);
} else {
th = Style::DefaultTextHeight();
}
hStyle hs = disp.style;
if(hs.v == 0) hs.v = Style::CONSTRAINT;
double th = Style::TextHeight(hs);
std::string s = Label();
double swidth = ssglStrWidth(s, th),
@ -159,13 +148,16 @@ void Constraint::DoProjectedPoint(Vector *r) {
// depending whether that extension was from A or from B.
//-----------------------------------------------------------------------------
int Constraint::DoLineTrimmedAgainstBox(Vector ref, Vector a, Vector b) {
hStyle hs = disp.style;
if(hs.v == 0) hs.v = Style::CONSTRAINT;
double th = Style::TextHeight(hs);
Vector gu = SS.GW.projUp.WithMagnitude(1),
gr = SS.GW.projRight.WithMagnitude(1);
double pixels = 1.0 / SS.GW.scale;
std::string s = Label();
double swidth = ssglStrWidth(s, Style::DefaultTextHeight()) + 4*pixels,
sheight = ssglStrHeight(Style::DefaultTextHeight()) + 8*pixels;
double swidth = ssglStrWidth(s, th) + 4*pixels,
sheight = ssglStrHeight(th) + 8*pixels;
struct {
Vector n;
@ -1077,9 +1069,11 @@ s:
void Constraint::Draw(void) {
dogd.drawing = true;
dogd.sel = NULL;
hStyle hs = disp.style;
if(hs.v == 0) hs.v = Style::CONSTRAINT;
ssglLineWidth(Style::Width(Style::CONSTRAINT));
ssglColorRGB(Style::Color(Style::CONSTRAINT));
ssglLineWidth(Style::Width(hs));
ssglColorRGB(Style::Color(hs));
DrawOrGetDistance(NULL);
}

View File

@ -787,6 +787,7 @@ public:
static std::string CnfColor(const std::string &prefix);
static std::string CnfWidth(const std::string &prefix);
static std::string CnfTextHeight(const std::string &prefix);
static std::string CnfPrefixToName(const std::string &prefix);
static void CreateAllDefaultStyles(void);

View File

@ -33,6 +33,9 @@ std::string Style::CnfColor(const std::string &prefix) {
std::string Style::CnfWidth(const std::string &prefix) {
return "Style_" + prefix + "_Width";
}
std::string Style::CnfTextHeight(const std::string &prefix) {
return "Style_" + prefix + "_TextHeight";
}
std::string Style::CnfPrefixToName(const std::string &prefix) {
std::string name = "#def-";
@ -83,7 +86,7 @@ void Style::FillDefaultStyle(Style *s, const Default *d) {
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->textHeight = CnfThawFloat(DEFAULT_TEXT_HEIGHT, CnfTextHeight(d->cnfPrefix));
s->textHeightAs = UNITS_AS_PIXELS;
s->textOrigin = 0;
s->textAngle = 0;
@ -125,6 +128,7 @@ void Style::FreezeDefaultStyles(void) {
for(d = &(Defaults[0]); d->h.v; d++) {
CnfFreezeColor(Color(d->h), CnfColor(d->cnfPrefix));
CnfFreezeFloat((float)Width(d->h), CnfWidth(d->cnfPrefix));
CnfFreezeFloat((float)TextHeight(d->h), CnfTextHeight(d->cnfPrefix));
}
}
@ -810,7 +814,7 @@ void TextWindow::ShowStyleInfo(void) {
if(s->h.v < Style::FIRST_CUSTOM) {
Printf(false," %Ftin units of %Fdpixels%E");
} else {
Printf(false," %Ftin units of %Fd"
Printf(false,"%Ba %Ftin units of %Fd"
"%D%f%LW%s pixels%E "
"%D%f%Lw%s %s",
s->h.v, &ScreenChangeStyleYesNo,
@ -877,19 +881,18 @@ void TextWindow::ShowStyleInfo(void) {
// The text height, and its units
Printf(false, "");
Printf(false, "%Ft text comment style%E");
Printf(false, "%Ft text style%E");
const char *chng = (s->h.v < Style::FIRST_CUSTOM) ? "" : "[change]";
if(s->textHeightAs == Style::UNITS_AS_PIXELS) {
Printf(false, "%Ba %Ftheight %E%@ %D%f%Lt%Fl%s%E",
s->textHeight,
s->h.v, &ScreenChangeStyleMetric,
chng);
"[change]");
} else {
Printf(false, "%Ba %Ftheight %E%s %D%f%Lt%Fl%s%E",
SS.MmToString(s->textHeight).c_str(),
s->h.v, &ScreenChangeStyleMetric,
chng);
"[change]");
}
bool textHeightpx = (s->textHeightAs == Style::UNITS_AS_PIXELS);