diff --git a/stella/src/gui/PopUpWidget.cxx b/stella/src/gui/PopUpWidget.cxx index 46a760731..88d5a2b27 100644 --- a/stella/src/gui/PopUpWidget.cxx +++ b/stella/src/gui/PopUpWidget.cxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: PopUpWidget.cxx,v 1.21 2005-10-01 01:42:36 stephena Exp $ +// $Id: PopUpWidget.cxx,v 1.22 2005-10-02 22:09:12 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -45,8 +45,8 @@ static unsigned int up_down_arrows[8] = { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - PopUpDialog::PopUpDialog(PopUpWidget* boss, int clickX, int clickY) - : Dialog(boss->instance(), boss->parent(), 0, 0, 16, 16), - _popUpBoss(boss) + : Dialog(boss->instance(), boss->parent(), 0, 0, 16, 16), + _popUpBoss(boss) { // Copy the selection index _selection = _popUpBoss->_selectedItem; @@ -56,10 +56,6 @@ PopUpDialog::PopUpDialog(PopUpWidget* boss, int clickX, int clickY) _y = _popUpBoss->getAbsY() - _popUpBoss->_selectedItem * kLineHeight; _w = _popUpBoss->_w - kLineHeight + 2 - _popUpBoss->_labelWidth; _h = 2; - - // Remember original mouse position - _clickX = clickX - _x; - _clickY = clickY - _y; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -70,7 +66,6 @@ void PopUpDialog::drawDialog() // by the ScummVM guys, so I'm not going to mess with it. if(_dirty) { -// cerr << "PopUpDialog::drawDialog()\n"; FrameBuffer& fb = instance()->frameBuffer(); // Draw the menu border @@ -101,11 +96,11 @@ void PopUpDialog::drawDialog() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void PopUpDialog::handleMouseDown(int x, int y, int button, int clickCount) { - sendSelection(); - - _clickX = -1; - _clickY = -1; - _openTime = (unsigned int)-1; + // Only make a selection if we're in the dialog area + if(x >= 0 && x < _w && y >= 0 && y < _h) + sendSelection(); + else + cancelSelection(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -145,6 +140,9 @@ void PopUpDialog::handleKeyDown(int ascii, int keycode, int modifiers) case '\r': sendSelection(); break; + case 27: // escape + cancelSelection(); + break; case 256+17: // up arrow moveUp(); break; @@ -320,6 +318,13 @@ void PopUpDialog::sendSelection() parent()->removeDialog(); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void PopUpDialog::cancelSelection() +{ + setSelection(_oldSelection); + parent()->removeDialog(); +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool PopUpDialog::isMouseDown() { @@ -374,11 +379,11 @@ void PopUpDialog::moveDown() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - PopUpWidget::PopUpWidget(GuiObject* boss, int x, int y, int w, int h, const string& label, int labelWidth, int cmd) - : Widget(boss, x, y - 1, w, h + 2), - CommandSender(boss), - _label(label), - _labelWidth(labelWidth), - _cmd(cmd) + : Widget(boss, x, y - 1, w, h + 2), + CommandSender(boss), + _label(label), + _labelWidth(labelWidth), + _cmd(cmd) { _flags = WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS | WIDGET_NODRAW_FOCUS; @@ -403,7 +408,10 @@ PopUpWidget::~PopUpWidget() void PopUpWidget::handleMouseDown(int x, int y, int button, int clickCount) { if(isEnabled()) + { + myPopUpDialog->_oldSelection = _selectedItem; parent()->addDialog(myPopUpDialog); + } } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/stella/src/gui/PopUpWidget.hxx b/stella/src/gui/PopUpWidget.hxx index 4bcf98bab..cc2d32304 100644 --- a/stella/src/gui/PopUpWidget.hxx +++ b/stella/src/gui/PopUpWidget.hxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: PopUpWidget.hxx,v 1.9 2005-10-01 01:42:36 stephena Exp $ +// $Id: PopUpWidget.hxx,v 1.10 2005-10-02 22:09:12 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -118,12 +118,14 @@ class PopUpDialog : public Dialog private: void sendSelection(); + void cancelSelection(); protected: PopUpWidget* _popUpBoss; int _clickX, _clickY; uInt8* _buffer; int _selection; + int _oldSelection; int _openTime; bool _twoColumns; int _entriesPerColumn;