From: andy Date: Mon, 3 May 2004 00:40:50 +0000 (+0000) Subject: GUI windows are now draggable. This missing feature has annoyed me X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=09d4176e963be04dec40943083e369081b8f7a18;p=flightgear.git GUI windows are now draggable. This missing feature has annoyed me for a while, it turned out to be pretty easy to implement. Also, the property picker is now non-modal, I presume the modality wasn't an intentional feature. --- diff --git a/src/GUI/dialog.cxx b/src/GUI/dialog.cxx index 3750d8b86..6d3c7c7cb 100644 --- a/src/GUI/dialog.cxx +++ b/src/GUI/dialog.cxx @@ -8,6 +8,42 @@ #include "puList.hxx" #include "AirportList.hxx" +int fgPopup::checkHit(int button, int updown, int x, int y) +{ + int result = puPopup::checkHit(button, updown, x, y); + + // This is annoying. We would really want a true result from the + // superclass to indicate "handled by child object", but all it + // tells us is that the pointer is inside the dialog. So do the + // intersection test (again) to make sure we don't start a drag + // when inside controls. A further weirdness: plib inserts a + // "ghost" child which covers the whole control. (?) Skip it. + if(!result) return result; + puObject* child = getFirstChild(); + if(child) child = child->getNextObject(); + while(child) { + int cx, cy, cw, ch; + child->getAbsolutePosition(&cx, &cy); + child->getSize(&cw, &ch); + if(x >= cx && x < cx + cw && y >= cy && y < cy + ch) + return result; + child = child->getNextObject(); + } + + // Finally, handle the mouse event + if(updown == PU_DOWN) { + int px, py; + getPosition(&px, &py); + _dragging = true; + _dX = px - x; + _dY = py - y; + } else if(updown == PU_DRAG && _dragging) { + setPosition(x + _dX, y + _dY); + } else { + _dragging = false; + } + return 1; +} //////////////////////////////////////////////////////////////////////// @@ -230,7 +266,7 @@ FGDialog::makeObject (SGPropertyNode * props, int parentWidth, int parentHeight) if (props->getBoolValue("modal", false)) dialog = new puDialogBox(x, y); else - dialog = new puPopup(x, y); + dialog = new fgPopup(x, y); setupGroup(dialog, props, width, height, true); return dialog; } else if (type == "group") { diff --git a/src/GUI/dialog.hxx b/src/GUI/dialog.hxx index a399849ff..2cb6f4ed1 100644 --- a/src/GUI/dialog.hxx +++ b/src/GUI/dialog.hxx @@ -135,4 +135,23 @@ private: vector _char_arrays; }; +// +// Custom subclass of puPopup to implement "draggable" windows in the +// interface. Note that this is a subclass of puPopup, not +// puDialogBox. Sadly, PUI (mis)uses subclassing to implement a +// boolean property: modality. That means that we can't implement +// dragging of both puPopup windows and puDialogBoxes with the same +// code. Rather than duplicate code, I've chosen to implement only +// "non-modal dragability" here. Modal dialog boxes (like the exit +// confirmation) are not draggable. +// +class fgPopup : public puPopup { +public: + fgPopup(int x, int y) : puPopup(x, y) { _dragging = false; } + int checkHit(int b, int up, int x, int y); +private: + bool _dragging; + int _dX, _dY; +}; + #endif // __DIALOG_HXX diff --git a/src/GUI/prop_picker.cxx b/src/GUI/prop_picker.cxx index 20480755f..767769ad9 100755 --- a/src/GUI/prop_picker.cxx +++ b/src/GUI/prop_picker.cxx @@ -346,7 +346,7 @@ fgPropPicker::~fgPropPicker () */ fgPropPicker::fgPropPicker ( int x, int y, int w, int h, int arrows, - const char *dir, const char *title ) : puDialogBox ( x,y ) + const char *dir, const char *title ) : fgPopup ( x,y ) { puFont LegendFont, LabelFont; puGetDefaultFonts ( &LegendFont, &LabelFont ); @@ -570,7 +570,7 @@ void fgPropEdit::fgPropEditHandleOK ( puObject* b ) FG_POP_PUI_DIALOG( prop_edit ); } -fgPropEdit::fgPropEdit ( const char *name, const char *value, char *proppath ) : puDialogBox ( 0, 0 ) +fgPropEdit::fgPropEdit ( const char *name, const char *value, char *proppath ) : fgPopup ( 0, 0 ) { puFont LegendFont, LabelFont; diff --git a/src/GUI/prop_picker.hxx b/src/GUI/prop_picker.hxx index e2c293a74..21018f34a 100755 --- a/src/GUI/prop_picker.hxx +++ b/src/GUI/prop_picker.hxx @@ -7,6 +7,7 @@ #include #include "gui.h" +#include "dialog.hxx" #include void prop_pickerInit(); @@ -19,7 +20,7 @@ class fgPropPicker ; class fgPropEdit ; class fgPropPicker : - public puDialogBox, + public fgPopup, public SGPropertyChangeListener { @@ -76,7 +77,7 @@ public: virtual void valueChanged (SGPropertyNode * node); } ; -class fgPropEdit : public puDialogBox +class fgPropEdit : public fgPopup { static void fgPropEditHandleCancel ( puObject *b ) ;