From 16d2de1a0fa0c2fb7c76aa78dd5a89cb09b66c5b Mon Sep 17 00:00:00 2001 From: mfranz Date: Sun, 11 Jan 2009 15:59:28 +0000 Subject: [PATCH] allow resizing dialogs by grabbing the frame (without Ctrl-key); Ctrl extends the resize sensible area to the whole dialog --- src/GUI/dialog.cxx | 84 +++++++++++++++++++++++++++++++++++----------- src/GUI/dialog.hxx | 5 ++- 2 files changed, 68 insertions(+), 21 deletions(-) diff --git a/src/GUI/dialog.cxx b/src/GUI/dialog.cxx index 0cf54472b..7a011a6e0 100644 --- a/src/GUI/dialog.cxx +++ b/src/GUI/dialog.cxx @@ -211,40 +211,83 @@ int fgPopup::checkHit(int button, int updown, int x, int y) int hit = getHitObjects(this, x, y); if (hit & (PUCLASS_BUTTON|PUCLASS_ONESHOT|PUCLASS_INPUT|PUCLASS_LARGEINPUT)) - return puPopup::checkHit(button, updown, x, y); + return result; getPosition(&_dlgX, &_dlgY); getSize(&_dlgW, &_dlgH); - _modifier = fgGetKeyModifiers(); + _start_cursor = fgGetMouseCursor(); _dragging = true; _startX = x; _startY = y; + // check and prepare for resizing + static const int cursor[] = { + MOUSE_CURSOR_POINTER, MOUSE_CURSOR_LEFTSIDE, MOUSE_CURSOR_RIGHTSIDE, 0, + MOUSE_CURSOR_TOPSIDE, MOUSE_CURSOR_TOPLEFT, MOUSE_CURSOR_TOPRIGHT, 0, + MOUSE_CURSOR_BOTTOMSIDE, MOUSE_CURSOR_BOTTOMLEFT, MOUSE_CURSOR_BOTTOMRIGHT, 0, + }; + + _resizing = 0; + int global_resize = fgGetKeyModifiers() & KEYMOD_CTRL; + int hmargin = global_resize ? _dlgW / 3 : 10; + int vmargin = global_resize ? _dlgH / 3 : 10; + + if (y - _dlgY < vmargin) + _resizing |= BOTTOM; + else if (_dlgY + _dlgH - y < vmargin) + _resizing |= TOP; + + if (x - _dlgX < hmargin) + _resizing |= LEFT; + else if (_dlgX + _dlgW - x < hmargin) + _resizing |= RIGHT; + + if (!_resizing && global_resize) + _resizing = BOTTOM|RIGHT; + + _cursor = cursor[_resizing]; + if (_resizing && _resizable) + fgSetMouseCursor(_cursor); + } else if (updown == PU_DRAG && _dragging) { - if (_modifier & KEYMOD_CTRL) { + if (_resizing) { if (!_resizable) return result; - int w = _dlgW + x - _startX; - int h = _dlgH + _startY - y; - GUIInfo *info = (GUIInfo *)getUserData(); if (info && info->node) { - int pw, ph; + int w = _dlgW; + int h = _dlgH; + int prefw, prefh; LayoutWidget wid(info->node); - wid.calcPrefSize(&pw, &ph); - if (w < pw) - w = pw; - if (h < ph) - h = ph; - int y = _dlgY + _dlgH - h; + wid.calcPrefSize(&prefw, &prefh); - // first child is always the dialog background puFrame - getFirstChild()->setSize(w, h); + if (_resizing & LEFT) + w += _startX - x; + if (_resizing & RIGHT) + w += x - _startX; + if (_resizing & TOP) + h += y - _startY; + if (_resizing & BOTTOM) + h += _startY - y; + + if (w < prefw) + w = prefw; + if (h < prefh) + h = prefh; + + int x = _dlgX; + int y = _dlgY; + if (_resizing & LEFT) + x += _dlgW - w; + if (_resizing & BOTTOM) + y += _dlgH - h; + + getFirstChild()->setSize(w, h); // dialog background puFrame setSize(w, h); - setPosition(_dlgX, y); + setPosition(x, y); - wid.layout(_dlgX, y, w, h); + wid.layout(x, y, w, h); applySize(static_cast(this)); } } else { @@ -253,6 +296,7 @@ int fgPopup::checkHit(int button, int updown, int x, int y) } else { _dragging = false; + fgSetMouseCursor(_start_cursor); } return result; } @@ -278,8 +322,8 @@ int fgPopup::getHitObjects(puObject *object, int x, int y) void fgPopup::applySize(puObject *object) { - // compound plib widgets use setUserData() for internal purposes, so refuse to - // descend into anything that has more bits set than the following + // compound plib widgets use setUserData() for internal purposes, so refuse + // to descend into anything that has other bits set than the following const int validUserData = PUCLASS_VALUE|PUCLASS_OBJECT|PUCLASS_GROUP|PUCLASS_INTERFACE |PUCLASS_FRAME|PUCLASS_TEXT|PUCLASS_BUTTON|PUCLASS_ONESHOT|PUCLASS_INPUT |PUCLASS_ARROW|PUCLASS_DIAL|PUCLASS_POPUP; @@ -296,7 +340,7 @@ void fgPopup::applySize(puObject *object) SGPropertyNode *n = info->node; if (!n) { - SG_LOG(SG_GENERAL, SG_ALERT, "applySize: no props"); + SG_LOG(SG_GENERAL, SG_ALERT, "fgPopup::applySize: no props"); return; } int x = n->getIntValue("x"); diff --git a/src/GUI/dialog.hxx b/src/GUI/dialog.hxx index f9fb4227f..0751a4a4f 100644 --- a/src/GUI/dialog.hxx +++ b/src/GUI/dialog.hxx @@ -185,10 +185,13 @@ public: puObject *getActiveInputField(puObject *); void applySize(puObject *); private: + enum { LEFT = 1, RIGHT = 2, TOP = 4, BOTTOM = 8 }; bool _draggable; bool _resizable; bool _dragging; - int _modifier; + int _resizing; + int _start_cursor; + int _cursor; int _dlgX, _dlgY, _dlgW, _dlgH; int _startX, _startY; };