Fix empty space at the end of the tooltips.
Also, bring MakeAcceleratorLabel to modernity.pull/4/head
parent
accd73fe02
commit
a61544ea9c
|
@ -175,39 +175,31 @@ const GraphicsWindow::MenuEntry GraphicsWindow::menu[] = {
|
|||
#undef TC
|
||||
#undef TR
|
||||
|
||||
bool SolveSpace::MakeAcceleratorLabel(int accel, char *out) {
|
||||
if(!accel) {
|
||||
out[0] = '\0';
|
||||
return false;
|
||||
std::string SolveSpace::MakeAcceleratorLabel(int accel) {
|
||||
if(!accel) return "";
|
||||
|
||||
std::string label;
|
||||
if(accel & GraphicsWindow::CTRL_MASK) {
|
||||
label += "Ctrl+";
|
||||
}
|
||||
if(accel & GraphicsWindow::SHIFT_MASK) {
|
||||
label += "Shift+";
|
||||
}
|
||||
|
||||
const char *ctrl = accel & GraphicsWindow::CTRL_MASK ? "Ctrl+" : "";
|
||||
const char *shift = accel & GraphicsWindow::SHIFT_MASK ? "Shift+" : "";
|
||||
|
||||
char buf[8];
|
||||
buf[0] = (char)(accel & 0xff);
|
||||
buf[1] = '\0';
|
||||
|
||||
if(accel >= GraphicsWindow::FUNCTION_KEY_BASE + 1 &&
|
||||
accel <= GraphicsWindow::FUNCTION_KEY_BASE + 12) {
|
||||
sprintf(buf, "F%d", accel - GraphicsWindow::FUNCTION_KEY_BASE);
|
||||
label += ssprintf("F%d", accel - GraphicsWindow::FUNCTION_KEY_BASE);
|
||||
} else if(accel == '\t') {
|
||||
label += "Tab";
|
||||
} else if(accel == ' ') {
|
||||
label += "Space";
|
||||
} else if(accel == GraphicsWindow::ESCAPE_KEY) {
|
||||
label += "Esc";
|
||||
} else if(accel == GraphicsWindow::DELETE_KEY) {
|
||||
label += "Del";
|
||||
} else {
|
||||
label += (char)(accel & 0xff);
|
||||
}
|
||||
|
||||
const char *key = buf;
|
||||
|
||||
switch(accel) {
|
||||
case '\t': key = "Tab"; break;
|
||||
case ' ': key = "Space"; break;
|
||||
|
||||
case GraphicsWindow::ESCAPE_KEY: key = "Esc"; break;
|
||||
case GraphicsWindow::DELETE_KEY: key = "Del"; break;
|
||||
}
|
||||
|
||||
if(key[0] < '!' || key[0] > '~') oops();
|
||||
if(key[0] >= 'a' && key[0] <= 'z') oops();
|
||||
|
||||
sprintf(out, "%s%s%s", ctrl, shift, key);
|
||||
return true;
|
||||
return label;
|
||||
}
|
||||
|
||||
void GraphicsWindow::Init(void) {
|
||||
|
|
|
@ -388,7 +388,7 @@ void MakeMatrix(double *mat, double a11, double a12, double a13, double a14,
|
|||
double a21, double a22, double a23, double a24,
|
||||
double a31, double a32, double a33, double a34,
|
||||
double a41, double a42, double a43, double a44);
|
||||
bool MakeAcceleratorLabel(int accel, char *out);
|
||||
std::string MakeAcceleratorLabel(int accel);
|
||||
bool FilenameHasExtension(const std::string &str, const char *ext);
|
||||
void Message(const char *str, ...);
|
||||
void Error(const char *str, ...);
|
||||
|
|
|
@ -447,7 +447,7 @@ void TextWindow::DrawOrHitTestIcons(int how, double mx, double my)
|
|||
double ox = oldMousePos.x, oy = oldMousePos.y - LINE_HEIGHT;
|
||||
ox += 3;
|
||||
oy -= 3;
|
||||
int tw = (str.length() + 1)*CHAR_WIDTH;
|
||||
int tw = (str.length() + 1)*(CHAR_WIDTH - 1);
|
||||
ox = min(ox, (double) (width - 25) - tw);
|
||||
oy = max(oy, 5.0);
|
||||
|
||||
|
|
|
@ -206,20 +206,19 @@ bool GraphicsWindow::ToolbarDrawOrHitTest(int mx, int my,
|
|||
// Do this last so that nothing can draw over it.
|
||||
if(toolTip.show) {
|
||||
ssglInitializeBitmapFont();
|
||||
if(strlen(toolTip.str) >= 200) oops();
|
||||
std::string str { toolTip.str };
|
||||
std::string str = toolTip.str;
|
||||
|
||||
for(i = 0; SS.GW.menu[i].level >= 0; i++) {
|
||||
if(toolbarTooltipped == SS.GW.menu[i].id) {
|
||||
char accelbuf[40];
|
||||
if(MakeAcceleratorLabel(SS.GW.menu[i].accel, accelbuf)) {
|
||||
str += ssprintf(" (%s)", accelbuf);
|
||||
std::string accel = MakeAcceleratorLabel(SS.GW.menu[i].accel);
|
||||
if(!accel.empty()) {
|
||||
str += ssprintf(" (%s)", accel.c_str());
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int tw = str.length() * SS.TW.CHAR_WIDTH + 10,
|
||||
int tw = str.length() * (SS.TW.CHAR_WIDTH - 1) + 10,
|
||||
th = SS.TW.LINE_HEIGHT + 2;
|
||||
|
||||
double ox = toolbarMouseX + 3, oy = toolbarMouseY + 3;
|
||||
|
|
|
@ -1208,11 +1208,9 @@ HMENU CreateGraphicsWindowMenus(void)
|
|||
for(i = 0; SS.GW.menu[i].level >= 0; i++) {
|
||||
std::string label;
|
||||
if(SS.GW.menu[i].label) {
|
||||
char accelbuf[40];
|
||||
const char *sep =
|
||||
MakeAcceleratorLabel(SS.GW.menu[i].accel, accelbuf) ?
|
||||
"\t" : "";
|
||||
label = ssprintf("%s%s%s", SS.GW.menu[i].label, sep, accelbuf);
|
||||
std::string accel = MakeAcceleratorLabel(SS.GW.menu[i].accel);
|
||||
const char *sep = accel.empty() ? "" : "\t";
|
||||
label = ssprintf("%s%s%s", SS.GW.menu[i].label, sep, accel.c_str());
|
||||
}
|
||||
|
||||
if(SS.GW.menu[i].level == 0) {
|
||||
|
|
Loading…
Reference in New Issue