Don't calculate halfRow for ShowEditControl manually.

Instead, grab it from hoveredRow, since almost always (with only one
exception) this is where the edit control has to be shown.

This makes it much easier to adjust views, e.g. add a new editable
field in the middle of configuration view, because it's not necessary
to manually change and test all the indexes below the row being
changed.

Additionally, it removes a lot of awkward and opaque row calculations.
pull/4/head
EvilSpirit 2016-01-26 17:19:52 +06:00 committed by whitequark
parent fd0b7fbc29
commit 76d582720a
8 changed files with 47 additions and 68 deletions

View File

@ -303,17 +303,17 @@ bool TextWindow::EditControlDoneForPaste(const char *s) {
void TextWindow::ScreenChangePasteTransformed(int link, uint32_t v) {
switch(link) {
case 't':
SS.TW.ShowEditControl(10, 13, ssprintf("%d", SS.TW.shown.paste.times));
SS.TW.ShowEditControl(13, ssprintf("%d", SS.TW.shown.paste.times));
SS.TW.edit.meaning = EDIT_PASTE_TIMES_REPEATED;
break;
case 'r':
SS.TW.ShowEditControl(12, 13, ssprintf("%.3f", SS.TW.shown.paste.theta*180/PI));
SS.TW.ShowEditControl(13, ssprintf("%.3f", SS.TW.shown.paste.theta*180/PI));
SS.TW.edit.meaning = EDIT_PASTE_ANGLE;
break;
case 's':
SS.TW.ShowEditControl(18, 13, ssprintf("%.3f", SS.TW.shown.paste.scale));
SS.TW.ShowEditControl(13, ssprintf("%.3f", SS.TW.shown.paste.scale));
SS.TW.edit.meaning = EDIT_PASTE_SCALE;
break;
}

View File

@ -7,56 +7,56 @@
#include "solvespace.h"
void TextWindow::ScreenChangeLightDirection(int link, uint32_t v) {
SS.TW.ShowEditControl(29+2*v, 8, ssprintf("%.2f, %.2f, %.2f", CO(SS.lightDir[v])));
SS.TW.ShowEditControl(8, ssprintf("%.2f, %.2f, %.2f", CO(SS.lightDir[v])));
SS.TW.edit.meaning = EDIT_LIGHT_DIRECTION;
SS.TW.edit.i = v;
}
void TextWindow::ScreenChangeLightIntensity(int link, uint32_t v) {
SS.TW.ShowEditControl(29+2*v, 31, ssprintf("%.2f", SS.lightIntensity[v]));
SS.TW.ShowEditControl(31, ssprintf("%.2f", SS.lightIntensity[v]));
SS.TW.edit.meaning = EDIT_LIGHT_INTENSITY;
SS.TW.edit.i = v;
}
void TextWindow::ScreenChangeColor(int link, uint32_t v) {
SS.TW.ShowEditControlWithColorPicker(9+2*v, 13, SS.modelColor[v]);
SS.TW.ShowEditControlWithColorPicker(13, SS.modelColor[v]);
SS.TW.edit.meaning = EDIT_COLOR;
SS.TW.edit.i = v;
}
void TextWindow::ScreenChangeChordTolerance(int link, uint32_t v) {
SS.TW.ShowEditControl(37, 3, ssprintf("%.2f", SS.chordTol));
SS.TW.ShowEditControl(3, ssprintf("%.2f", SS.chordTol));
SS.TW.edit.meaning = EDIT_CHORD_TOLERANCE;
}
void TextWindow::ScreenChangeMaxSegments(int link, uint32_t v) {
SS.TW.ShowEditControl(41, 3, ssprintf("%d", SS.maxSegments));
SS.TW.ShowEditControl(3, ssprintf("%d", SS.maxSegments));
SS.TW.edit.meaning = EDIT_MAX_SEGMENTS;
}
void TextWindow::ScreenChangeCameraTangent(int link, uint32_t v) {
SS.TW.ShowEditControl(47, 3, ssprintf("%.3f", 1000*SS.cameraTangent));
SS.TW.ShowEditControl(3, ssprintf("%.3f", 1000*SS.cameraTangent));
SS.TW.edit.meaning = EDIT_CAMERA_TANGENT;
}
void TextWindow::ScreenChangeGridSpacing(int link, uint32_t v) {
SS.TW.ShowEditControl(51, 3, SS.MmToString(SS.gridSpacing));
SS.TW.ShowEditControl(3, SS.MmToString(SS.gridSpacing));
SS.TW.edit.meaning = EDIT_GRID_SPACING;
}
void TextWindow::ScreenChangeDigitsAfterDecimal(int link, uint32_t v) {
SS.TW.ShowEditControl(55, 3, ssprintf("%d", SS.UnitDigitsAfterDecimal()));
SS.TW.ShowEditControl(3, ssprintf("%d", SS.UnitDigitsAfterDecimal()));
SS.TW.edit.meaning = EDIT_DIGITS_AFTER_DECIMAL;
}
void TextWindow::ScreenChangeExportScale(int link, uint32_t v) {
SS.TW.ShowEditControl(61, 5, ssprintf("%.3f", (double)SS.exportScale));
SS.TW.ShowEditControl(5, ssprintf("%.3f", (double)SS.exportScale));
SS.TW.edit.meaning = EDIT_EXPORT_SCALE;
}
void TextWindow::ScreenChangeExportOffset(int link, uint32_t v) {
SS.TW.ShowEditControl(65, 3, SS.MmToString(SS.exportOffset));
SS.TW.ShowEditControl(3, SS.MmToString(SS.exportOffset));
SS.TW.edit.meaning = EDIT_EXPORT_OFFSET;
}
@ -108,52 +108,41 @@ void TextWindow::ScreenChangeCanvasSize(int link, uint32_t v) {
default: return;
}
int row = 81, col;
if(v < 10) {
row += v*2;
col = 11;
} else {
row += (v - 10)*2;
col = 13;
}
SS.TW.ShowEditControl(row, col, SS.MmToString(d));
int col = 13;
if(v < 10) col = 11;
SS.TW.ShowEditControl(col, SS.MmToString(d));
SS.TW.edit.meaning = EDIT_CANVAS_SIZE;
SS.TW.edit.i = v;
}
void TextWindow::ScreenChangeGCodeParameter(int link, uint32_t v) {
std::string buf;
int row = 93;
switch(link) {
case 'd':
SS.TW.edit.meaning = EDIT_G_CODE_DEPTH;
buf += SS.MmToString(SS.gCode.depth);
row += 0;
break;
case 's':
SS.TW.edit.meaning = EDIT_G_CODE_PASSES;
buf += std::to_string(SS.gCode.passes);
row += 2;
break;
case 'F':
SS.TW.edit.meaning = EDIT_G_CODE_FEED;
buf += SS.MmToString(SS.gCode.feed);
row += 4;
break;
case 'P':
SS.TW.edit.meaning = EDIT_G_CODE_PLUNGE_FEED;
buf += SS.MmToString(SS.gCode.plungeFeed);
row += 6;
break;
}
SS.TW.ShowEditControl(row, 14, buf);
SS.TW.ShowEditControl(14, buf);
}
void TextWindow::ScreenChangeAutosaveInterval(int link, uint32_t v) {
SS.TW.ShowEditControl(111, 3, std::to_string(SS.autosaveInterval));
SS.TW.ShowEditControl(3, std::to_string(SS.autosaveInterval));
SS.TW.edit.meaning = EDIT_AUTOSAVE_INTERVAL;
}

View File

@ -14,7 +14,7 @@ void TextWindow::ScreenEditTtfText(int link, uint32_t v) {
hRequest hr = { v };
Request *r = SK.GetRequest(hr);
SS.TW.ShowEditControl(13, 10, r->str.c_str());
SS.TW.ShowEditControl(10, r->str.c_str());
SS.TW.edit.meaning = EDIT_TTF_TEXT;
SS.TW.edit.request = hr;
}

View File

@ -339,7 +339,7 @@ void TextWindow::ScreenCreateCustomStyle(int link, uint32_t v) {
void TextWindow::ScreenChangeBackgroundColor(int link, uint32_t v) {
RgbaColor rgb = SS.backgroundColor;
SS.TW.ShowEditControlWithColorPicker(v, 3, rgb);
SS.TW.ShowEditControlWithColorPicker(3, rgb);
SS.TW.edit.meaning = EDIT_BACKGROUND_COLOR;
}
@ -418,7 +418,7 @@ err:
void TextWindow::ScreenChangeBackgroundImageScale(int link, uint32_t v) {
SS.TW.edit.meaning = EDIT_BACKGROUND_IMG_SCALE;
SS.TW.ShowEditControl(v, 10, ssprintf("%.3f", SS.bgImage.scale * SS.MmPerUnit()));
SS.TW.ShowEditControl(10, ssprintf("%.3f", SS.bgImage.scale * SS.MmPerUnit()));
}
void TextWindow::ShowListOfStyles(void) {
@ -476,7 +476,7 @@ void TextWindow::ShowListOfStyles(void) {
void TextWindow::ScreenChangeStyleName(int link, uint32_t v) {
hStyle hs = { v };
Style *s = Style::Get(hs);
SS.TW.ShowEditControl(10, 12, s->name.c_str());
SS.TW.ShowEditControl(12, s->name.c_str());
SS.TW.edit.style = hs;
SS.TW.edit.meaning = EDIT_STYLE_NAME;
}
@ -506,16 +506,9 @@ void TextWindow::ScreenChangeStyleWidthOrTextHeight(int link, uint32_t v) {
} else {
edit_value = SS.MmToString(val);
}
int row = 0, col = 9;
if(link == 'w') {
row = 17; // width for a default style
} else if(link == 'W') {
row = 17; // width for a custom style
} else if(link == 't') {
row = 33; // text height (for custom styles only)
col++;
}
SS.TW.ShowEditControl(row, col, edit_value);
int col = 9;
if(link == 't') col++;
SS.TW.ShowEditControl(col, edit_value);
SS.TW.edit.style = hs;
SS.TW.edit.meaning = (link == 't') ? EDIT_STYLE_TEXT_HEIGHT :
EDIT_STYLE_WIDTH;
@ -524,7 +517,7 @@ void TextWindow::ScreenChangeStyleWidthOrTextHeight(int link, uint32_t v) {
void TextWindow::ScreenChangeStyleTextAngle(int link, uint32_t v) {
hStyle hs = { v };
Style *s = Style::Get(hs);
SS.TW.ShowEditControl(37, 9, ssprintf("%.2f", s->textAngle));
SS.TW.ShowEditControl(9, ssprintf("%.2f", s->textAngle));
SS.TW.edit.style = hs;
SS.TW.edit.meaning = EDIT_STYLE_TEXT_ANGLE;
}
@ -533,20 +526,18 @@ void TextWindow::ScreenChangeStyleColor(int link, uint32_t v) {
hStyle hs = { v };
Style *s = Style::Get(hs);
// Same function used for stroke and fill colors
int row, col, em;
int em;
RgbaColor rgb;
if(link == 's') {
row = 15; col = 13;
em = EDIT_STYLE_COLOR;
rgb = s->color;
} else if(link == 'f') {
row = 25; col = 13;
em = EDIT_STYLE_FILL_COLOR;
rgb = s->fillColor;
} else {
oops();
}
SS.TW.ShowEditControlWithColorPicker(row, col, rgb);
SS.TW.ShowEditControlWithColorPicker(13, rgb);
SS.TW.edit.style = hs;
SS.TW.edit.meaning = em;
}

View File

@ -223,36 +223,33 @@ void TextWindow::ScreenColor(int link, uint32_t v) {
SS.UndoRemember();
Group *g = SK.GetGroup(SS.TW.shown.group);
SS.TW.ShowEditControlWithColorPicker(v, 3, g->color);
SS.TW.ShowEditControlWithColorPicker(3, g->color);
SS.TW.edit.meaning = EDIT_GROUP_COLOR;
}
void TextWindow::ScreenOpacity(int link, uint32_t v) {
Group *g = SK.GetGroup(SS.TW.shown.group);
SS.TW.ShowEditControl(22, 11, ssprintf("%.2f", g->color.alphaF()));
SS.TW.ShowEditControl(11, ssprintf("%.2f", g->color.alphaF()));
SS.TW.edit.meaning = EDIT_GROUP_OPACITY;
SS.TW.edit.group.v = g->h.v;
}
void TextWindow::ScreenChangeExprA(int link, uint32_t v) {
Group *g = SK.GetGroup(SS.TW.shown.group);
// There's an extra line for the skipFirst parameter in one-sided groups.
int r = (g->subtype == Group::ONE_SIDED) ? 16 : 14;
SS.TW.ShowEditControl(r, 10, ssprintf("%d", (int)g->valA));
SS.TW.ShowEditControl(10, ssprintf("%d", (int)g->valA));
SS.TW.edit.meaning = EDIT_TIMES_REPEATED;
SS.TW.edit.group.v = v;
}
void TextWindow::ScreenChangeGroupName(int link, uint32_t v) {
Group *g = SK.GetGroup(SS.TW.shown.group);
SS.TW.ShowEditControl(7, 12, g->DescriptionString().substr(5));
SS.TW.ShowEditControl(12, g->DescriptionString().substr(5));
SS.TW.edit.meaning = EDIT_GROUP_NAME;
SS.TW.edit.group.v = v;
}
void TextWindow::ScreenChangeGroupScale(int link, uint32_t v) {
Group *g = SK.GetGroup(SS.TW.shown.group);
SS.TW.ShowEditControl(14, 13, ssprintf("%.3f", g->scale));
SS.TW.ShowEditControl(13, ssprintf("%.3f", g->scale));
SS.TW.edit.meaning = EDIT_GROUP_SCALE;
SS.TW.edit.group.v = v;
}
@ -537,11 +534,11 @@ void TextWindow::ScreenStepDimFinish(int link, uint32_t v) {
} else {
edit_value = ssprintf("%.3f", SS.TW.shown.dimFinish);
}
SS.TW.ShowEditControl(12, 12, edit_value);
SS.TW.ShowEditControl(12, edit_value);
}
void TextWindow::ScreenStepDimSteps(int link, uint32_t v) {
SS.TW.edit.meaning = EDIT_STEP_DIM_STEPS;
SS.TW.ShowEditControl(14, 12, ssprintf("%d", SS.TW.shown.dimSteps));
SS.TW.ShowEditControl(12, ssprintf("%d", SS.TW.shown.dimSteps));
}
void TextWindow::ScreenStepDimGo(int link, uint32_t v) {
hConstraint hc = SS.TW.shown.constraint;
@ -601,7 +598,7 @@ void TextWindow::ScreenChangeTangentArc(int link, uint32_t v) {
switch(link) {
case 'r': {
SS.TW.edit.meaning = EDIT_TANGENT_ARC_RADIUS;
SS.TW.ShowEditControl(12, 3, SS.MmToString(SS.tangentArcRadius));
SS.TW.ShowEditControl(3, SS.MmToString(SS.tangentArcRadius));
break;
}

View File

@ -79,7 +79,8 @@ void TextWindow::HideEditControl(void) {
HideTextEditControl();
}
void TextWindow::ShowEditControl(int halfRow, int col, const std::string &str) {
void TextWindow::ShowEditControl(int col, const std::string &str, int halfRow) {
if(halfRow < 0) halfRow = top[hoveredRow];
editControl.halfRow = halfRow;
editControl.col = col;
@ -89,7 +90,7 @@ void TextWindow::ShowEditControl(int halfRow, int col, const std::string &str) {
ShowTextEditControl(x - 3, y + 2, str);
}
void TextWindow::ShowEditControlWithColorPicker(int halfRow, int col, RgbaColor rgb)
void TextWindow::ShowEditControlWithColorPicker(int col, RgbaColor rgb)
{
SS.ScheduleShowTW();
@ -98,7 +99,7 @@ void TextWindow::ShowEditControlWithColorPicker(int halfRow, int col, RgbaColor
editControl.colorPicker.h = 0;
editControl.colorPicker.s = 0;
editControl.colorPicker.v = 1;
ShowEditControl(halfRow, col, ssprintf("%.2f, %.2f, %.2f", rgb.redF(), rgb.greenF(), rgb.blueF()));
ShowEditControl(col, ssprintf("%.2f, %.2f, %.2f", rgb.redF(), rgb.greenF(), rgb.blueF()));
}
void TextWindow::ClearScreen(void) {

View File

@ -208,8 +208,8 @@ public:
} editControl;
void HideEditControl(void);
void ShowEditControl(int halfRow, int col, const std::string &str);
void ShowEditControlWithColorPicker(int halfRow, int col, RgbaColor rgb);
void ShowEditControl(int col, const std::string &str, int halfRow = -1);
void ShowEditControlWithColorPicker(int col, RgbaColor rgb);
void ClearSuper(void);

View File

@ -39,7 +39,7 @@ void TextWindow::ShowEditView(void) {
void TextWindow::ScreenChangeViewScale(int link, uint32_t v) {
SS.TW.edit.meaning = EDIT_VIEW_SCALE;
SS.TW.ShowEditControl(12, 3, ssprintf("%.3f", SS.GW.scale * SS.MmPerUnit()));
SS.TW.ShowEditControl(3, ssprintf("%.3f", SS.GW.scale * SS.MmPerUnit()));
}
void TextWindow::ScreenChangeViewOrigin(int link, uint32_t v) {
@ -50,14 +50,14 @@ void TextWindow::ScreenChangeViewOrigin(int link, uint32_t v) {
SS.MmToString(-SS.GW.offset.z).c_str());
SS.TW.edit.meaning = EDIT_VIEW_ORIGIN;
SS.TW.ShowEditControl(18, 3, edit_value);
SS.TW.ShowEditControl(3, edit_value);
}
void TextWindow::ScreenChangeViewProjection(int link, uint32_t v) {
std::string edit_value =
ssprintf("%.3f, %.3f, %.3f", CO(SS.GW.projRight));
SS.TW.edit.meaning = EDIT_VIEW_PROJ_RIGHT;
SS.TW.ShowEditControl(24, 10, edit_value);
SS.TW.ShowEditControl(10, edit_value);
}
bool TextWindow::EditControlDoneForView(const char *s) {
@ -98,7 +98,8 @@ bool TextWindow::EditControlDoneForView(const char *s) {
SS.GW.NormalizeProjectionVectors();
edit.meaning = EDIT_VIEW_PROJ_UP;
HideEditControl();
ShowEditControl(26, 10, ssprintf("%.3f, %.3f, %.3f", CO(SS.GW.projUp)));
ShowEditControl(10, ssprintf("%.3f, %.3f, %.3f", CO(SS.GW.projUp)),
editControl.halfRow + 2);
edit.showAgain = true;
} else {
SS.GW.projUp = pt;