//----------------------------------------------------------------------------- // The edit control is visible, and the user just pressed enter. //----------------------------------------------------------------------------- void TextWindow::EditControlDone(const char *s) { edit.showAgain = false; switch(edit.meaning) { case EDIT_TIMES_REPEATED: { Expr *e = Expr::From(s, true); if(e) { SS.UndoRemember(); double ev = e->Eval(); if((int)ev < 1) { Error("Can't repeat fewer than 1 time."); break; } if((int)ev > 999) { Error("Can't repeat more than 999 times."); break; } Group *g = SK.GetGroup(edit.group); g->valA = ev; if(g->type == Group::ROTATE) { int i, c = 0; for(i = 0; i < SK.constraint.n; i++) { if(SK.constraint.elem[i].group.v == g->h.v) c++; } // If the group does not contain any constraints, then // set the numerical guess to space the copies uniformly // over one rotation. Don't touch the guess if we're // already constrained, because that would break // convergence. if(c == 0) { double copies = (g->skipFirst) ? (ev + 1) : ev; SK.GetParam(g->h.param(3))->val = PI/(2*copies); } } SS.MarkGroupDirty(g->h); SS.later.generateAll = true; } break; } case EDIT_GROUP_NAME: { if(!StringAllPrintable(s) || !*s) { Error("Invalid characters. Allowed are: A-Z a-z 0-9 _ -"); } else { SS.UndoRemember(); Group *g = SK.GetGroup(edit.group); g->name.strcpy(s); } break; } case EDIT_GROUP_SCALE: { Expr *e = Expr::From(s, true); if(e) { double ev = e->Eval(); if(fabs(ev) < 1e-6) { Error("Scale cannot be zero."); } else { Group *g = SK.GetGroup(edit.group); g->scale = ev; SS.MarkGroupDirty(g->h); SS.later.generateAll = true; } } break; } case EDIT_GROUP_COLOR: { Vector rgb; if(sscanf(s, "%lf, %lf, %lf", &rgb.x, &rgb.y, &rgb.z)==3) { rgb = rgb.ClampWithin(0, 1); Group *g = SK.group.FindByIdNoOops(SS.TW.shown.group); if(!g) break; g->color = RGBf(rgb.x, rgb.y, rgb.z); SS.MarkGroupDirty(g->h); SS.later.generateAll = true; SS.GW.ClearSuper(); } else { Error("Bad format: specify color as r, g, b"); } break; } case EDIT_TTF_TEXT: { SS.UndoRemember(); Request *r = SK.request.FindByIdNoOops(edit.request); if(r) { r->str.strcpy(s); SS.MarkGroupDirty(r->group); SS.later.generateAll = true; } break; } case EDIT_STEP_DIM_FINISH: { Expr *e = Expr::From(s, true); if(!e) { break; } if(shown.dimIsDistance) { shown.dimFinish = SS.ExprToMm(e); } else { shown.dimFinish = e->Eval(); } break; } case EDIT_STEP_DIM_STEPS: shown.dimSteps = min(300, max(1, atoi(s))); break; case EDIT_TANGENT_ARC_RADIUS: { Expr *e = Expr::From(s, true); if(!e) break; if(e->Eval() < LENGTH_EPS) { Error("Radius cannot be zero or negative."); break; } SS.tangentArcRadius = SS.ExprToMm(e); break; } default: { int cnt = 0; if(EditControlDoneForStyles(s)) cnt++; if(EditControlDoneForConfiguration(s)) cnt++; if(EditControlDoneForPaste(s)) cnt++; if(EditControlDoneForView(s)) cnt++; if(cnt > 1) { // The identifiers were somehow assigned not uniquely? oops(); } break; } } InvalidateGraphics(); SS.later.showTW = true; if(!edit.showAgain) { HideEditControl(); edit.meaning = EDIT_NOTHING; } }
bool TextWindow::EditControlDoneForStyles(const char *str) { Style *s; switch(edit.meaning) { case EDIT_STYLE_TEXT_HEIGHT: case EDIT_STYLE_WIDTH: { SS.UndoRemember(); s = Style::Get(edit.style); double v; int units = (edit.meaning == EDIT_STYLE_TEXT_HEIGHT) ? s->textHeightAs : s->widthAs; if(units == Style::UNITS_AS_MM) { v = SS.StringToMm(str); } else { v = atof(str); } v = max(0, v); if(edit.meaning == EDIT_STYLE_TEXT_HEIGHT) { s->textHeight = v; } else { s->width = v; } break; } case EDIT_STYLE_TEXT_ANGLE: SS.UndoRemember(); s = Style::Get(edit.style); s->textAngle = WRAP_SYMMETRIC(atof(str), 360); break; case EDIT_BACKGROUND_COLOR: case EDIT_STYLE_FILL_COLOR: case EDIT_STYLE_COLOR: { Vector rgb; if(sscanf(str, "%lf, %lf, %lf", &rgb.x, &rgb.y, &rgb.z)==3) { rgb = rgb.ClampWithin(0, 1); if(edit.meaning == EDIT_STYLE_COLOR) { SS.UndoRemember(); s = Style::Get(edit.style); s->color = RGBf(rgb.x, rgb.y, rgb.z); } else if(edit.meaning == EDIT_STYLE_FILL_COLOR) { SS.UndoRemember(); s = Style::Get(edit.style); s->fillColor = RGBf(rgb.x, rgb.y, rgb.z); } else { SS.backgroundColor = RGBf(rgb.x, rgb.y, rgb.z); } } else { Error("Bad format: specify color as r, g, b"); } break; } case EDIT_STYLE_NAME: if(!StringAllPrintable(str) || !*str) { Error("Invalid characters. Allowed are: A-Z a-z 0-9 _ -"); } else { SS.UndoRemember(); s = Style::Get(edit.style); s->name.strcpy(str); } break; case EDIT_BACKGROUND_IMG_SCALE: { Expr *e = Expr::From(str, true); if(e) { double ev = e->Eval(); if(ev < 0.001 || isnan(ev)) { Error("Scale must not be zero or negative!"); } else { SS.bgImage.scale = ev / SS.MmPerUnit(); } } break; } default: return false; } return true; }