From: mfranz Date: Wed, 2 Nov 2005 13:11:19 +0000 (+0000) Subject: allow to trigger widgets via accelerator key, which is defined via "keynum" X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=fd5ed5a8fadb80c0d1858685978a223b89e609a2;p=flightgear.git allow to trigger widgets via accelerator key, which is defined via "keynum" property (e.g. 49). The numbers are the same as in keyboard.xml. (Could later be replaced/enhanced with Ctrl-a notation.) This does, of course, only work for widgets with assigned bindings. --- diff --git a/src/GUI/dialog.cxx b/src/GUI/dialog.cxx index 7d1475bb9..f5c27696e 100644 --- a/src/GUI/dialog.cxx +++ b/src/GUI/dialog.cxx @@ -11,6 +11,73 @@ #include "AirportList.hxx" #include "layout.hxx" +/** + * User data for a GUI object. + */ +struct GUIInfo +{ + GUIInfo (FGDialog * d); + virtual ~GUIInfo (); + + FGDialog * dialog; + vector bindings; + int key; +}; + + +/** + * Key handler. + */ +int fgPopup::checkKey(int key, int updown) +{ + if (updown == PU_UP || !isVisible() || !isActive() || window != puGetWindow()) + return false; + + puObject *input = getActiveInputField(this); + if (input) + return input->checkKey(key, updown); + + puObject *object = getKeyObject(this, key); + if (!object) + return puPopup::checkKey(key, updown); + + object->invokeCallback() ; + return true; +} + +puObject *fgPopup::getKeyObject(puObject *object, int key) +{ + puObject *ret; + if(object->getType() & PUCLASS_GROUP) + for (puObject *obj = ((puGroup *)object)->getFirstChild(); + obj; obj = obj->getNextObject()) + if ((ret = getKeyObject(obj, key))) + return ret; + + GUIInfo *info = (GUIInfo *)object->getUserData(); + if (info && info->key == key) + return object; + + return 0; +} + +puObject *fgPopup::getActiveInputField(puObject *object) +{ + if(object->getType() & PUCLASS_GROUP) + for (puObject *obj = ((puGroup *)object)->getFirstChild(); + obj; obj = obj->getNextObject()) + if (getActiveInputField(obj)) + return obj; + + if (object->getType() & PUCLASS_INPUT && ((puInput *)object)->isAcceptingInput()) + return object; + + return 0; +} + +/** + * Mouse handler. + */ int fgPopup::checkHit(int button, int updown, int x, int y) { int result = puPopup::checkHit(button, updown, x, y); @@ -67,19 +134,6 @@ int fgPopup::getHitObjects(puObject *object, int x, int y) // Callbacks. //////////////////////////////////////////////////////////////////////// -/** - * User data for a GUI object. - */ -struct GUIInfo -{ - GUIInfo (FGDialog * d); - virtual ~GUIInfo (); - - FGDialog * dialog; - vector bindings; -}; - - /** * Action callback. */ @@ -237,7 +291,8 @@ copy_from_pui (puObject * object, SGPropertyNode * node) //////////////////////////////////////////////////////////////////////// GUIInfo::GUIInfo (FGDialog * d) - : dialog(d) + : dialog(d), + key(-1) { } @@ -630,6 +685,7 @@ FGDialog::setupObject (puObject * object, SGPropertyNode * props) vector bindings = props->getChildren("binding"); if (bindings.size() > 0) { GUIInfo * info = new GUIInfo(this); + info->key = props->getIntValue("keynum", -1); for (unsigned int i = 0; i < bindings.size(); i++) { unsigned int j = 0; @@ -679,13 +735,12 @@ FGDialog::setColor(puObject * object, SGPropertyNode * props, int which) if (c->isValid()) object->setColourScheme(c->red(), c->green(), c->blue(), c->alpha()); - const int numcol = 6; const struct { int mask; int id; const char *name; const char *cname; - } pucol[numcol] = { + } pucol[] = { { BACKGROUND, PUCOL_BACKGROUND, "background", "color-background" }, { FOREGROUND, PUCOL_FOREGROUND, "foreground", "color-foreground" }, { HIGHLIGHT, PUCOL_HIGHLIGHT, "highlight", "color-highlight" }, @@ -694,6 +749,8 @@ FGDialog::setColor(puObject * object, SGPropertyNode * props, int which) { MISC, PUCOL_MISC, "misc", "color-misc" } }; + const int numcol = sizeof(pucol) / sizeof(pucol[0]); + for (int i = 0; i < numcol; i++) { bool dirty = false; c->clear(); diff --git a/src/GUI/dialog.hxx b/src/GUI/dialog.hxx index 473e839b5..26b89bb96 100644 --- a/src/GUI/dialog.hxx +++ b/src/GUI/dialog.hxx @@ -177,7 +177,10 @@ class fgPopup : public puPopup { public: fgPopup(int x, int y, bool d = true) : puPopup(x, y) { _dragging = false; _draggable = d;} int checkHit(int b, int up, int x, int y); + int checkKey(int key, int updown); int getHitObjects(puObject *, int x, int y); + puObject *getKeyObject(puObject *, int key); + puObject *getActiveInputField(puObject *); private: bool _draggable; bool _dragging;