if (!object)
return puPopup::checkKey(key, updown);
- object->invokeCallback() ;
+ // invokeCallback() isn't enough; we need to simulate a mouse button press
+ object->checkHit(PU_LEFT_BUTTON, PU_DOWN,
+ (object->getABox()->min[0] + object->getABox()->max[0]) / 2,
+ (object->getABox()->min[1] + object->getABox()->max[1]) / 2);
+ object->checkHit(PU_LEFT_BUTTON, PU_UP,
+ (object->getABox()->min[0] + object->getABox()->max[0]) / 2,
+ (object->getABox()->min[1] + object->getABox()->max[1]) / 2);
return true;
}
GUIInfo *info = (GUIInfo *)object->getUserData();
if (info && info->key == key)
- return object;
+ return object;
return 0;
}
wid.setDefaultFont(fnt, int(fnt->getPointSize()));
int pw=0, ph=0;
+ int px, py, savex, savey;
if(!userw || !userh)
wid.calcPrefSize(&pw, &ph);
pw = props->getIntValue("width", pw);
ph = props->getIntValue("height", ph);
- int px = props->getIntValue("x", (screenw - pw) / 2);
- int py = props->getIntValue("y", (screenh - ph) / 2);
+ px = savex = props->getIntValue("x", (screenw - pw) / 2);
+ py = savey = props->getIntValue("y", (screenh - ph) / 2);
+
+ // Negative x/y coordinates are interpreted as distance from the top/right
+ // corner rather than bottom/left.
+ if (px < 0)
+ px = screenw - pw + px;
+ if (py < 0)
+ py = screenh - ph + py;
// Define "x", "y", "width" and/or "height" in the property tree if they
// are not specified in the configuration file.
_object = makeObject(props, screenw, screenh);
// Remove automatically generated properties, so the layout looks
- // the same next time around.
- if(!userx) props->removeChild("x");
- if(!usery) props->removeChild("y");
+ // the same next time around, or restore x and y to preserve negative coords.
+ if(userx)
+ props->setIntValue("x", savex);
+ else
+ props->removeChild("x");
+
+ if(usery)
+ props->setIntValue("y", savey);
+ else
+ props->removeChild("y");
+
if(!userw) props->removeChild("width");
if(!userh) props->removeChild("height");
i < value_nodes.size();
i++, j--)
entries[i] = strdup((char *)value_nodes[i]->getStringValue());
- puaComboBox * obj = new puaComboBox(x, y, x + width, y + height, entries,
+ puComboBox * obj = new puComboBox(x, y, x + width, y + height, entries,
props->getBoolValue("editable", false));
setupObject(obj, props);
setColor(obj, props, FOREGROUND|LABEL);
int slider_width = props->getIntValue("slider", parentHeight);
int wrap = props->getBoolValue("wrap", true);
if (slider_width==0) slider_width=20;
- puaLargeInput * obj = new puaLargeInput(x, y,
+ puLargeInput * obj = new puLargeInput(x, y,
x+width, x+height, 2, slider_width, wrap);
if (props->hasValue("editable")) {
i < value_nodes.size();
i++, j--)
entries[i] = strdup((char *)value_nodes[i]->getName());
- puaSelectBox * obj =
- new puaSelectBox(x, y, x + width, y + height, entries);
+ puSelectBox * obj =
+ new puSelectBox(x, y, x + width, y + height, entries);
setupObject(obj, props);
setColor(obj, props, FOREGROUND|LABEL);
return obj;
if (bindings.size() > 0) {
GUIInfo * info = new GUIInfo(this);
info->key = props->getIntValue("keynum", -1);
+ if (props->hasValue("key"))
+ info->key = getKeyCode(props->getStringValue("key", ""));
for (unsigned int i = 0; i < bindings.size(); i++) {
unsigned int j = 0;
}
}
+
+static struct {
+ const char *name;
+ int key;
+} keymap[] = {
+ {"tab", 9},
+ {"return", 13},
+ {"enter", 13},
+ {"esc", 27},
+ {"escape", 27},
+ {"space", ' '},
+ {"&", '&'},
+ {"and", '&'},
+ {"<", '<'},
+ {">", '>'},
+ {"f1", PU_KEY_F1},
+ {"f2", PU_KEY_F2},
+ {"f3", PU_KEY_F3},
+ {"f4", PU_KEY_F4},
+ {"f5", PU_KEY_F5},
+ {"f6", PU_KEY_F6},
+ {"f7", PU_KEY_F7},
+ {"f8", PU_KEY_F8},
+ {"f9", PU_KEY_F9},
+ {"f10", PU_KEY_F10},
+ {"f11", PU_KEY_F11},
+ {"f12", PU_KEY_F12},
+ {"left", PU_KEY_LEFT},
+ {"up", PU_KEY_UP},
+ {"right", PU_KEY_RIGHT},
+ {"down", PU_KEY_DOWN},
+ {"pageup", PU_KEY_PAGE_UP},
+ {"pagedn", PU_KEY_PAGE_DOWN},
+ {"home", PU_KEY_HOME},
+ {"end", PU_KEY_END},
+ {"insert", PU_KEY_INSERT},
+ {0, -1},
+};
+
+int
+FGDialog::getKeyCode(const char *str)
+{
+ enum {
+ CTRL = 0x1,
+ SHIFT = 0x2,
+ ALT = 0x4,
+ };
+
+ while (*str == ' ')
+ str++;
+
+ char *buf = new char[strlen(str) + 1];
+ strcpy(buf, str);
+ char *s = buf + strlen(buf);
+ while (s > str && s[-1] == ' ')
+ s--;
+ *s = 0;
+ s = buf;
+
+ int mod = 0;
+ while (1) {
+ if (!strncmp(s, "Ctrl-", 5) || !strncmp(s, "CTRL-", 5))
+ s += 5, mod |= CTRL;
+ else if (!strncmp(s, "Shift-", 6) || !strncmp(s, "SHIFT-", 6))
+ s += 6, mod |= SHIFT;
+ else if (!strncmp(s, "Alt-", 4) || !strncmp(s, "ALT-", 4))
+ s += 4, mod |= ALT;
+ else
+ break;
+ }
+
+ int key = -1;
+ if (strlen(s) == 1 && isascii(*s)) {
+ key = *s;
+ if (mod & SHIFT)
+ key = toupper(key);
+ if (mod & CTRL)
+ key = toupper(key) - 64;
+ if (mod & ALT)
+ ; // Alt not propagated to the gui
+ } else {
+ for (char *t = s; *t; t++)
+ *t = tolower(*t);
+ for (int i = 0; keymap[i].name; i++) {
+ if (!strcmp(s, keymap[i].name)) {
+ key = keymap[i].key;
+ break;
+ }
+ }
+ }
+ delete[] buf;
+ return key;
+}
+
char **
FGDialog::make_char_array (int size)
{