2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
2002-12-12 12:07:46 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-12-12 12:07:46 +00:00
|
|
|
*
|
2006-02-11 10:08:56 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2002-12-12 12:07:46 +00:00
|
|
|
*/
|
|
|
|
|
2005-05-19 17:03:31 +00:00
|
|
|
#include "common/system.h"
|
2007-06-22 07:49:02 +00:00
|
|
|
#include "common/events.h"
|
2003-11-10 23:40:48 +00:00
|
|
|
#include "gui/dialog.h"
|
2009-01-02 03:21:40 +00:00
|
|
|
#include "gui/GuiManager.h"
|
2005-01-10 22:06:49 +00:00
|
|
|
#include "gui/PopUpWidget.h"
|
2006-09-23 00:42:35 +00:00
|
|
|
#include "engines/engine.h"
|
2002-12-12 12:07:46 +00:00
|
|
|
|
2008-08-07 18:42:47 +00:00
|
|
|
#include "gui/ThemeEval.h"
|
|
|
|
|
2003-11-10 23:40:48 +00:00
|
|
|
namespace GUI {
|
|
|
|
|
2002-12-13 21:35:04 +00:00
|
|
|
//
|
|
|
|
// PopUpDialog
|
|
|
|
//
|
|
|
|
|
2002-12-12 12:07:46 +00:00
|
|
|
class PopUpDialog : public Dialog {
|
|
|
|
protected:
|
|
|
|
PopUpWidget *_popUpBoss;
|
|
|
|
int _clickX, _clickY;
|
|
|
|
byte *_buffer;
|
|
|
|
int _selection;
|
2002-12-12 23:31:58 +00:00
|
|
|
uint32 _openTime;
|
2005-08-22 17:25:03 +00:00
|
|
|
bool _twoColumns;
|
|
|
|
int _entriesPerColumn;
|
2006-04-16 10:23:36 +00:00
|
|
|
|
|
|
|
int _leftPadding;
|
|
|
|
int _rightPadding;
|
|
|
|
|
2002-12-12 12:07:46 +00:00
|
|
|
public:
|
2006-05-31 12:09:00 +00:00
|
|
|
PopUpDialog(PopUpWidget *boss, int clickX, int clickY);
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2002-12-12 12:07:46 +00:00
|
|
|
void drawDialog();
|
|
|
|
|
|
|
|
void handleMouseUp(int x, int y, int button, int clickCount);
|
2002-12-13 21:35:04 +00:00
|
|
|
void handleMouseWheel(int x, int y, int direction); // Scroll through entries with scroll wheel
|
2002-12-12 12:07:46 +00:00
|
|
|
void handleMouseMoved(int x, int y, int button); // Redraw selections depending on mouse position
|
2007-06-30 12:26:59 +00:00
|
|
|
void handleKeyDown(Common::KeyState state); // Scroll through entries with arrow keys etc.
|
2002-12-12 12:07:46 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void drawMenuEntry(int entry, bool hilite);
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2002-12-12 12:07:46 +00:00
|
|
|
int findItem(int x, int y) const;
|
2002-12-13 21:35:04 +00:00
|
|
|
void setSelection(int item);
|
|
|
|
bool isMouseDown();
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2002-12-14 17:59:22 +00:00
|
|
|
void moveUp();
|
|
|
|
void moveDown();
|
2002-12-12 12:07:46 +00:00
|
|
|
};
|
|
|
|
|
2006-05-31 12:09:00 +00:00
|
|
|
PopUpDialog::PopUpDialog(PopUpWidget *boss, int clickX, int clickY)
|
2008-08-13 17:46:00 +00:00
|
|
|
: Dialog(0, 0, 16, 16),
|
2003-03-06 19:52:54 +00:00
|
|
|
_popUpBoss(boss) {
|
2005-05-19 17:03:31 +00:00
|
|
|
|
2002-12-13 22:19:26 +00:00
|
|
|
// Copy the selection index
|
|
|
|
_selection = _popUpBoss->_selectedItem;
|
2003-03-06 19:52:54 +00:00
|
|
|
|
2002-12-12 12:07:46 +00:00
|
|
|
// Calculate real popup dimensions
|
2009-06-06 17:52:44 +00:00
|
|
|
_x = _popUpBoss->getAbsX();
|
2005-06-03 09:32:58 +00:00
|
|
|
_y = _popUpBoss->getAbsY() - _popUpBoss->_selectedItem * kLineHeight;
|
|
|
|
_h = _popUpBoss->_entries.size() * kLineHeight + 2;
|
2009-06-06 17:52:44 +00:00
|
|
|
_w = _popUpBoss->_w - kLineHeight + 2;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2006-04-16 10:23:36 +00:00
|
|
|
_leftPadding = _popUpBoss->_leftPadding;
|
|
|
|
_rightPadding = _popUpBoss->_rightPadding;
|
|
|
|
|
2002-12-13 22:19:26 +00:00
|
|
|
// Perform clipping / switch to scrolling mode if we don't fit on the screen
|
2005-05-19 17:03:31 +00:00
|
|
|
// FIXME - OSystem should send out notification messages when the screen
|
2002-12-13 22:19:26 +00:00
|
|
|
// resolution changes... we could generalize CommandReceiver and CommandSender.
|
2005-05-19 17:03:31 +00:00
|
|
|
|
|
|
|
const int screenH = g_system->getOverlayHeight();
|
|
|
|
|
2005-08-22 17:25:03 +00:00
|
|
|
// HACK: For now, we do not do scrolling. Instead, we draw the dialog
|
|
|
|
// in two columns if it's too tall.
|
|
|
|
|
|
|
|
if (_h >= screenH) {
|
|
|
|
const int screenW = g_system->getOverlayWidth();
|
|
|
|
|
|
|
|
_twoColumns = true;
|
|
|
|
_entriesPerColumn = _popUpBoss->_entries.size() / 2;
|
|
|
|
|
|
|
|
if (_popUpBoss->_entries.size() & 1)
|
|
|
|
_entriesPerColumn++;
|
|
|
|
|
|
|
|
_h = _entriesPerColumn * kLineHeight + 2;
|
|
|
|
_w = 0;
|
|
|
|
|
|
|
|
for (uint i = 0; i < _popUpBoss->_entries.size(); i++) {
|
|
|
|
int width = g_gui.getStringWidth(_popUpBoss->_entries[i].name);
|
|
|
|
|
|
|
|
if (width > _w)
|
|
|
|
_w = width;
|
|
|
|
}
|
|
|
|
|
|
|
|
_w = 2 * _w + 10;
|
|
|
|
|
|
|
|
if (!(_w & 1))
|
|
|
|
_w++;
|
|
|
|
|
|
|
|
if (_popUpBoss->_selectedItem >= _entriesPerColumn) {
|
|
|
|
_x -= _w / 2;
|
|
|
|
_y = _popUpBoss->getAbsY() - (_popUpBoss->_selectedItem - _entriesPerColumn) * kLineHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_w >= screenW)
|
|
|
|
_w = screenW - 1;
|
|
|
|
if (_x < 0)
|
|
|
|
_x = 0;
|
|
|
|
if (_x + _w >= screenW)
|
|
|
|
_x = screenW - 1 - _w;
|
|
|
|
} else
|
|
|
|
_twoColumns = false;
|
|
|
|
|
2005-05-19 17:03:31 +00:00
|
|
|
if (_h >= screenH)
|
|
|
|
_h = screenH - 1;
|
2002-12-13 22:19:26 +00:00
|
|
|
if (_y < 0)
|
|
|
|
_y = 0;
|
2005-05-19 17:03:31 +00:00
|
|
|
else if (_y + _h >= screenH)
|
|
|
|
_y = screenH - 1 - _h;
|
2002-12-13 22:19:26 +00:00
|
|
|
|
|
|
|
// TODO - implement scrolling if we had to move the menu, or if there are too many entries
|
2002-12-12 12:07:46 +00:00
|
|
|
|
|
|
|
// Remember original mouse position
|
|
|
|
_clickX = clickX - _x;
|
|
|
|
_clickY = clickY - _y;
|
2003-03-06 19:52:54 +00:00
|
|
|
|
2007-02-26 22:38:24 +00:00
|
|
|
_openTime = 0;
|
2002-12-12 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 19:52:54 +00:00
|
|
|
void PopUpDialog::drawDialog() {
|
2002-12-12 12:07:46 +00:00
|
|
|
// Draw the menu border
|
2008-08-13 17:46:00 +00:00
|
|
|
g_gui.theme()->drawWidgetBackground(Common::Rect(_x, _y, _x+_w, _y+_h), 0);
|
2002-12-12 12:07:46 +00:00
|
|
|
|
2006-01-27 15:43:23 +00:00
|
|
|
/*if (_twoColumns)
|
|
|
|
g_gui.vLine(_x + _w / 2, _y, _y + _h - 2, g_gui._color);*/
|
2005-08-22 17:25:03 +00:00
|
|
|
|
2002-12-12 12:07:46 +00:00
|
|
|
// Draw the entries
|
|
|
|
int count = _popUpBoss->_entries.size();
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
drawMenuEntry(i, i == _selection);
|
|
|
|
}
|
|
|
|
|
2005-08-22 17:25:03 +00:00
|
|
|
// The last entry may be empty. Fill it with black.
|
2006-01-27 15:43:23 +00:00
|
|
|
/*if (_twoColumns && (count & 1)) {
|
2005-08-22 17:25:03 +00:00
|
|
|
g_gui.fillRect(_x + 1 + _w / 2, _y + 1 + kLineHeight * (_entriesPerColumn - 1), _w / 2 - 1, kLineHeight, g_gui._bgcolor);
|
2006-01-27 15:43:23 +00:00
|
|
|
}*/
|
2007-02-26 22:38:24 +00:00
|
|
|
|
|
|
|
if (_openTime == 0) {
|
|
|
|
// Time the popup was opened
|
2010-03-11 23:41:28 +00:00
|
|
|
_openTime = g_system->getMillis();
|
2007-02-26 22:38:24 +00:00
|
|
|
}
|
2002-12-12 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 19:52:54 +00:00
|
|
|
void PopUpDialog::handleMouseUp(int x, int y, int button, int clickCount) {
|
2005-07-30 21:11:48 +00:00
|
|
|
// Mouse was released. If it wasn't moved much since the original mouse down,
|
2002-12-12 12:07:46 +00:00
|
|
|
// let the popup stay open. If it did move, assume the user made his selection.
|
|
|
|
int dist = (_clickX - x) * (_clickX - x) + (_clickY - y) * (_clickY - y);
|
2010-03-11 23:41:28 +00:00
|
|
|
if (dist > 3 * 3 || g_system->getMillis() - _openTime > 300) {
|
2002-12-12 12:07:46 +00:00
|
|
|
setResult(_selection);
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
_clickX = -1;
|
|
|
|
_clickY = -1;
|
2002-12-12 23:31:58 +00:00
|
|
|
_openTime = (uint32)-1;
|
2002-12-12 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 19:52:54 +00:00
|
|
|
void PopUpDialog::handleMouseWheel(int x, int y, int direction) {
|
2002-12-14 17:59:22 +00:00
|
|
|
if (direction < 0)
|
|
|
|
moveUp();
|
|
|
|
else if (direction > 0)
|
|
|
|
moveDown();
|
2002-12-13 21:35:04 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 19:52:54 +00:00
|
|
|
void PopUpDialog::handleMouseMoved(int x, int y, int button) {
|
2002-12-13 21:35:04 +00:00
|
|
|
// Compute over which item the mouse is...
|
2002-12-12 12:07:46 +00:00
|
|
|
int item = findItem(x, y);
|
|
|
|
|
2002-12-14 17:59:22 +00:00
|
|
|
if (item >= 0 && _popUpBoss->_entries[item].name.size() == 0)
|
2002-12-13 22:19:26 +00:00
|
|
|
item = -1;
|
|
|
|
|
2006-12-26 20:57:29 +00:00
|
|
|
if (item == -1 && !isMouseDown()) {
|
|
|
|
setSelection(_popUpBoss->_selectedItem);
|
2002-12-13 21:35:04 +00:00
|
|
|
return;
|
2006-12-26 20:57:29 +00:00
|
|
|
}
|
2002-12-12 12:07:46 +00:00
|
|
|
|
2002-12-13 21:35:04 +00:00
|
|
|
// ...and update the selection accordingly
|
|
|
|
setSelection(item);
|
|
|
|
}
|
|
|
|
|
2007-06-30 12:26:59 +00:00
|
|
|
void PopUpDialog::handleKeyDown(Common::KeyState state) {
|
|
|
|
if (state.keycode == Common::KEYCODE_ESCAPE) {
|
2006-12-26 20:57:29 +00:00
|
|
|
// Don't change the previous selection
|
|
|
|
setResult(-1);
|
2002-12-13 21:35:04 +00:00
|
|
|
close();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isMouseDown())
|
|
|
|
return;
|
|
|
|
|
2007-06-30 12:26:59 +00:00
|
|
|
switch (state.keycode) {
|
2010-02-21 04:04:13 +00:00
|
|
|
|
2007-06-22 07:49:02 +00:00
|
|
|
case Common::KEYCODE_RETURN:
|
|
|
|
case Common::KEYCODE_KP_ENTER:
|
2003-09-24 06:33:59 +00:00
|
|
|
setResult(_selection);
|
|
|
|
close();
|
|
|
|
break;
|
2010-02-21 04:04:13 +00:00
|
|
|
|
|
|
|
// Keypad & special keys
|
|
|
|
// - if num lock is set, we ignore the keypress
|
|
|
|
// - if num lock is not set, we fall down to the special key case
|
|
|
|
|
|
|
|
case Common::KEYCODE_KP1:
|
|
|
|
if (state.flags & Common::KBD_NUM)
|
|
|
|
break;
|
|
|
|
case Common::KEYCODE_END:
|
|
|
|
setSelection(_popUpBoss->_entries.size()-1);
|
2003-09-24 06:33:59 +00:00
|
|
|
break;
|
2010-02-21 04:04:13 +00:00
|
|
|
|
|
|
|
case Common::KEYCODE_KP2:
|
|
|
|
if (state.flags & Common::KBD_NUM)
|
|
|
|
break;
|
2007-06-22 07:49:02 +00:00
|
|
|
case Common::KEYCODE_DOWN:
|
2003-09-24 06:33:59 +00:00
|
|
|
moveDown();
|
|
|
|
break;
|
2010-02-21 04:04:13 +00:00
|
|
|
|
|
|
|
case Common::KEYCODE_KP7:
|
|
|
|
if (state.flags & Common::KBD_NUM)
|
|
|
|
break;
|
2007-06-22 07:49:02 +00:00
|
|
|
case Common::KEYCODE_HOME:
|
2003-09-24 06:33:59 +00:00
|
|
|
setSelection(0);
|
|
|
|
break;
|
2010-02-21 04:04:13 +00:00
|
|
|
|
|
|
|
case Common::KEYCODE_KP8:
|
|
|
|
if (state.flags & Common::KBD_NUM)
|
|
|
|
break;
|
|
|
|
case Common::KEYCODE_UP:
|
|
|
|
moveUp();
|
2003-09-24 06:33:59 +00:00
|
|
|
break;
|
2010-02-21 04:04:13 +00:00
|
|
|
|
2007-06-30 12:26:59 +00:00
|
|
|
default:
|
|
|
|
break;
|
2002-12-12 12:07:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-06 19:52:54 +00:00
|
|
|
int PopUpDialog::findItem(int x, int y) const {
|
2002-12-12 12:07:46 +00:00
|
|
|
if (x >= 0 && x < _w && y >= 0 && y < _h) {
|
2005-08-22 17:25:03 +00:00
|
|
|
if (_twoColumns) {
|
|
|
|
uint entry = (y - 2) / kLineHeight;
|
|
|
|
if (x > _w / 2) {
|
|
|
|
entry += _entriesPerColumn;
|
|
|
|
|
|
|
|
if (entry >= _popUpBoss->_entries.size())
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return entry;
|
|
|
|
}
|
2005-06-03 09:32:58 +00:00
|
|
|
return (y - 2) / kLineHeight;
|
2002-12-12 12:07:46 +00:00
|
|
|
}
|
2002-12-13 21:35:04 +00:00
|
|
|
return -1;
|
2002-12-12 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 19:52:54 +00:00
|
|
|
void PopUpDialog::setSelection(int item) {
|
2002-12-13 21:35:04 +00:00
|
|
|
if (item != _selection) {
|
|
|
|
// Undraw old selection
|
|
|
|
if (_selection >= 0)
|
|
|
|
drawMenuEntry(_selection, false);
|
|
|
|
|
|
|
|
// Change selection
|
|
|
|
_selection = item;
|
2002-12-12 12:07:46 +00:00
|
|
|
|
2002-12-13 21:35:04 +00:00
|
|
|
// Draw new selection
|
|
|
|
if (item >= 0)
|
|
|
|
drawMenuEntry(item, true);
|
|
|
|
}
|
2002-12-12 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 19:52:54 +00:00
|
|
|
bool PopUpDialog::isMouseDown() {
|
2002-12-13 21:35:04 +00:00
|
|
|
// TODO/FIXME - need a way to determine whether any mouse buttons are pressed or not.
|
|
|
|
// Sure, we could just count mouse button up/down events, but that is cumbersome and
|
|
|
|
// error prone. Would be much nicer to add an API to OSystem for this...
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2002-12-13 21:35:04 +00:00
|
|
|
return false;
|
2002-12-12 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 19:52:54 +00:00
|
|
|
void PopUpDialog::moveUp() {
|
2002-12-14 17:59:22 +00:00
|
|
|
if (_selection < 0) {
|
|
|
|
setSelection(_popUpBoss->_entries.size() - 1);
|
|
|
|
} else if (_selection > 0) {
|
|
|
|
int item = _selection;
|
|
|
|
do {
|
|
|
|
item--;
|
|
|
|
} while (item >= 0 && _popUpBoss->_entries[item].name.size() == 0);
|
|
|
|
if (item >= 0)
|
|
|
|
setSelection(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-06 19:52:54 +00:00
|
|
|
void PopUpDialog::moveDown() {
|
2002-12-14 17:59:22 +00:00
|
|
|
int lastItem = _popUpBoss->_entries.size() - 1;
|
|
|
|
|
|
|
|
if (_selection < 0) {
|
|
|
|
setSelection(0);
|
|
|
|
} else if (_selection < lastItem) {
|
|
|
|
int item = _selection;
|
|
|
|
do {
|
|
|
|
item++;
|
|
|
|
} while (item <= lastItem && _popUpBoss->_entries[item].name.size() == 0);
|
|
|
|
if (item <= lastItem)
|
|
|
|
setSelection(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-06 19:52:54 +00:00
|
|
|
void PopUpDialog::drawMenuEntry(int entry, bool hilite) {
|
2002-12-12 12:07:46 +00:00
|
|
|
// Draw one entry of the popup menu, including selection
|
|
|
|
assert(entry >= 0);
|
2005-08-22 17:25:03 +00:00
|
|
|
int x, y, w;
|
|
|
|
|
|
|
|
if (_twoColumns) {
|
|
|
|
int n = _popUpBoss->_entries.size() / 2;
|
|
|
|
|
|
|
|
if (_popUpBoss->_entries.size() & 1)
|
|
|
|
n++;
|
|
|
|
|
|
|
|
if (entry >= n) {
|
|
|
|
x = _x + 1 + _w / 2;
|
|
|
|
y = _y + 1 + kLineHeight * (entry - n);
|
|
|
|
} else {
|
|
|
|
x = _x + 1;
|
|
|
|
y = _y + 1 + kLineHeight * entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
w = _w / 2 - 1;
|
|
|
|
} else {
|
|
|
|
x = _x + 1;
|
|
|
|
y = _y + 1 + kLineHeight * entry;
|
|
|
|
w = _w - 2;
|
|
|
|
}
|
|
|
|
|
2006-06-03 13:33:39 +00:00
|
|
|
Common::String &name(_popUpBoss->_entries[entry].name);
|
2002-12-13 22:19:26 +00:00
|
|
|
|
2002-12-14 17:59:22 +00:00
|
|
|
if (name.size() == 0) {
|
2003-11-07 02:31:44 +00:00
|
|
|
// Draw a separator
|
2006-01-27 15:43:23 +00:00
|
|
|
g_gui.theme()->drawLineSeparator(Common::Rect(x, y, x+w, y+kLineHeight));
|
2002-12-13 22:19:26 +00:00
|
|
|
} else {
|
2008-11-10 11:24:55 +00:00
|
|
|
g_gui.theme()->drawText(Common::Rect(x+1, y+2, x+w, y+2+kLineHeight), name, hilite ? ThemeEngine::kStateHighlight : ThemeEngine::kStateEnabled,
|
2009-07-15 18:05:37 +00:00
|
|
|
Graphics::kTextAlignLeft, ThemeEngine::kTextInversionNone, _leftPadding);
|
2002-12-13 22:19:26 +00:00
|
|
|
}
|
2002-12-12 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
2003-03-26 12:30:20 +00:00
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
2002-12-12 12:07:46 +00:00
|
|
|
//
|
2002-12-13 21:35:04 +00:00
|
|
|
// PopUpWidget
|
2002-12-12 12:07:46 +00:00
|
|
|
//
|
|
|
|
|
2010-06-15 10:52:35 +00:00
|
|
|
PopUpWidget::PopUpWidget(GuiObject *boss, const String &name, const char *tooltip)
|
|
|
|
: Widget(boss, name, tooltip), CommandSender(boss) {
|
2009-01-02 01:31:46 +00:00
|
|
|
setFlags(WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS | WIDGET_IGNORE_DRAG);
|
2003-11-03 01:00:26 +00:00
|
|
|
_type = kPopUpWidget;
|
2002-12-12 12:07:46 +00:00
|
|
|
|
|
|
|
_selectedItem = -1;
|
|
|
|
}
|
|
|
|
|
2003-03-06 19:52:54 +00:00
|
|
|
void PopUpWidget::handleMouseDown(int x, int y, int button, int clickCount) {
|
2003-03-26 12:30:20 +00:00
|
|
|
if (isEnabled()) {
|
2006-05-31 12:09:00 +00:00
|
|
|
PopUpDialog popupDialog(this, x + getAbsX(), y + getAbsY());
|
2003-03-26 12:30:20 +00:00
|
|
|
int newSel = popupDialog.runModal();
|
|
|
|
if (newSel != -1 && _selectedItem != newSel) {
|
|
|
|
_selectedItem = newSel;
|
|
|
|
sendCommand(kPopUpItemSelectedCmd, _entries[_selectedItem].tag);
|
|
|
|
}
|
2002-12-12 12:07:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-23 23:47:16 +00:00
|
|
|
void PopUpWidget::handleMouseWheel(int x, int y, int direction) {
|
|
|
|
int newSelection = _selectedItem + direction;
|
|
|
|
|
|
|
|
// Skip separator entries
|
|
|
|
while ((newSelection >= 0) && (newSelection < (int)_entries.size()) &&
|
|
|
|
_entries[newSelection].name.equals("")) {
|
|
|
|
newSelection += direction;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Just update the selected item when we're in range
|
|
|
|
if ((newSelection >= 0) && (newSelection < (int)_entries.size()) &&
|
|
|
|
(newSelection != _selectedItem)) {
|
|
|
|
_selectedItem = newSelection;
|
|
|
|
draw();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-04 13:55:53 +00:00
|
|
|
void PopUpWidget::reflowLayout() {
|
2008-08-07 18:42:47 +00:00
|
|
|
_leftPadding = g_gui.xmlEval()->getVar("Globals.PopUpWidget.Padding.Left", 0);
|
|
|
|
_rightPadding = g_gui.xmlEval()->getVar("Globals.PopUpWidget.Padding.Right", 0);
|
2006-04-19 01:05:28 +00:00
|
|
|
|
2006-08-04 13:55:53 +00:00
|
|
|
Widget::reflowLayout();
|
2006-04-19 01:05:28 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 19:52:54 +00:00
|
|
|
void PopUpWidget::appendEntry(const String &entry, uint32 tag) {
|
2002-12-12 12:07:46 +00:00
|
|
|
Entry e;
|
|
|
|
e.name = entry;
|
|
|
|
e.tag = tag;
|
|
|
|
_entries.push_back(e);
|
|
|
|
}
|
|
|
|
|
2003-03-06 19:52:54 +00:00
|
|
|
void PopUpWidget::clearEntries() {
|
2002-12-12 12:07:46 +00:00
|
|
|
_entries.clear();
|
|
|
|
_selectedItem = -1;
|
|
|
|
}
|
|
|
|
|
2003-03-06 19:52:54 +00:00
|
|
|
void PopUpWidget::setSelected(int item) {
|
2002-12-12 12:07:46 +00:00
|
|
|
if (item != _selectedItem) {
|
2004-02-05 00:19:57 +00:00
|
|
|
if (item >= 0 && item < (int)_entries.size()) {
|
2002-12-12 12:07:46 +00:00
|
|
|
_selectedItem = item;
|
|
|
|
} else {
|
|
|
|
_selectedItem = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-13 12:33:31 +00:00
|
|
|
void PopUpWidget::setSelectedTag(uint32 tag) {
|
|
|
|
uint item;
|
|
|
|
for (item = 0; item < _entries.size(); ++item) {
|
|
|
|
if (_entries[item].tag == tag) {
|
|
|
|
setSelected(item);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-04 03:38:30 +00:00
|
|
|
void PopUpWidget::drawWidget() {
|
2006-06-03 13:33:39 +00:00
|
|
|
Common::String sel;
|
2006-04-18 18:40:33 +00:00
|
|
|
if (_selectedItem >= 0)
|
|
|
|
sel = _entries[_selectedItem].name;
|
2009-06-06 17:52:44 +00:00
|
|
|
g_gui.theme()->drawPopUpWidget(Common::Rect(_x, _y, _x + _w, _y + _h), sel, _leftPadding, _state, Graphics::kTextAlignLeft);
|
2002-12-12 12:07:46 +00:00
|
|
|
}
|
2003-11-10 23:40:48 +00:00
|
|
|
|
|
|
|
} // End of namespace GUI
|