From d5da3d3319e191982ab2b26517a33f11a607832f Mon Sep 17 00:00:00 2001 From: stephena Date: Mon, 22 Aug 2005 18:17:10 +0000 Subject: [PATCH] Broke old ListWidget down to a base class, and created a new StringListWidget and CheckListWidget to extend from it. This means the derived classes can concentrate on their main purpose, and leave all the ListWidget stuff to the parent class. Turned the TIA debugger area into an absolute size; 320x260. This should be large enough to accommodate all PAL ROMS. This means the tabset got shorter, but it's just too difficult to add widgets when the area can change. A zoom widget is going to be added to the right of the TIA image, and we need absolute sizes for that area. Besides, now that area is usable for other widgets ... git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@732 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba --- stella/src/debugger/Debugger.cxx | 13 +- stella/src/debugger/Debugger.hxx | 15 +- stella/src/debugger/RomWidget.cxx | 8 +- stella/src/gui/BrowserDialog.cxx | 9 +- stella/src/gui/BrowserDialog.hxx | 6 +- stella/src/gui/CheckListWidget.cxx | 375 ++------------------------ stella/src/gui/CheckListWidget.hxx | 67 +---- stella/src/gui/EventMappingDialog.cxx | 10 +- stella/src/gui/EventMappingDialog.hxx | 6 +- stella/src/gui/LauncherDialog.cxx | 7 +- stella/src/gui/LauncherDialog.hxx | 6 +- stella/src/gui/ListWidget.cxx | 148 +++------- stella/src/gui/ListWidget.hxx | 62 ++--- stella/src/gui/Widget.cxx | 5 +- stella/src/gui/Widget.hxx | 6 +- stella/src/gui/module.mk | 3 +- 16 files changed, 138 insertions(+), 608 deletions(-) diff --git a/stella/src/debugger/Debugger.cxx b/stella/src/debugger/Debugger.cxx index 399464e34..9bad4a49f 100644 --- a/stella/src/debugger/Debugger.cxx +++ b/stella/src/debugger/Debugger.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: Debugger.cxx,v 1.84 2005-08-20 18:19:51 urchlay Exp $ +// $Id: Debugger.cxx,v 1.85 2005-08-22 18:17:10 stephena Exp $ //============================================================================ #include "bspf.hxx" @@ -913,6 +913,8 @@ void Debugger::setQuitState() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - GUI::Rect Debugger::getDialogBounds() const { + GUI::Rect tia = getTiaBounds(); + int userHeight = myOSystem->settings().getInt("debugheight"); if(userHeight < kDebuggerLines) { @@ -921,14 +923,19 @@ GUI::Rect Debugger::getDialogBounds() const } userHeight = (userHeight + 3) * kDebuggerLineHeight - 8; - GUI::Rect r(0, 0, kDebuggerWidth, userHeight + myConsole->mediaSource().height()); + // Make sure window is always at least 'kDebuggerHeight' high + // We need this to make positioning of widget easier + if(userHeight < kDebuggerHeight + tia.height()) + userHeight = kDebuggerHeight - tia.height(); + + GUI::Rect r(0, 0, kDebuggerWidth, userHeight + tia.height()); return r; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - GUI::Rect Debugger::getTiaBounds() const { - GUI::Rect r(0, 0, 320, myConsole->mediaSource().height()); + GUI::Rect r(0, 0, 320, 260); return r; } diff --git a/stella/src/debugger/Debugger.hxx b/stella/src/debugger/Debugger.hxx index 4264b9c1d..a8c33c66d 100644 --- a/stella/src/debugger/Debugger.hxx +++ b/stella/src/debugger/Debugger.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: Debugger.hxx,v 1.68 2005-08-20 18:19:52 urchlay Exp $ +// $Id: Debugger.hxx,v 1.69 2005-08-22 18:17:10 stephena Exp $ //============================================================================ #ifndef DEBUGGER_HXX @@ -47,19 +47,12 @@ typedef ListFile::const_iterator ListIter; typedef map FunctionMap; typedef map FunctionDefMap; -#if 1 enum { - kDebuggerWidth = 1023, + kDebuggerWidth = 1023, + kDebuggerHeight = 767, kDebuggerLineHeight = 15, // based on the height of the console font kDebuggerLines = 35, }; -#else -enum { - kDebuggerWidth = 639, - kDebuggerLineHeight = 15, // based on the height of the console font - kDebuggerLines = 20, -}; -#endif // Constants for RAM area enum { @@ -83,7 +76,7 @@ typedef uInt16 (Debugger::*DEBUGGER_WORD_METHOD)(); for all debugging operations in Stella (parser, 6502 debugger, etc). @author Stephen Anthony - @version $Id: Debugger.hxx,v 1.68 2005-08-20 18:19:52 urchlay Exp $ + @version $Id: Debugger.hxx,v 1.69 2005-08-22 18:17:10 stephena Exp $ */ class Debugger : public DialogContainer { diff --git a/stella/src/debugger/RomWidget.cxx b/stella/src/debugger/RomWidget.cxx index f42fa13c3..9132a5263 100644 --- a/stella/src/debugger/RomWidget.cxx +++ b/stella/src/debugger/RomWidget.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: RomWidget.cxx,v 1.1 2005-08-22 13:53:23 stephena Exp $ +// $Id: RomWidget.cxx,v 1.2 2005-08-22 18:17:10 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -30,7 +30,10 @@ RomWidget::RomWidget(GuiObject* boss, const GUI::Font& font, int x, int y) : Widget(boss, x, y, 16, 16), CommandSender(boss) { - myRomList = new CheckListWidget(boss, font, x, y, 58, 31); + int w = 58 * font.getMaxCharWidth(), + h = 31 * font.getLineHeight(); + + myRomList = new CheckListWidget(boss, font, x, y, w, h); myRomList->setTarget(this); addFocusWidget(myRomList); @@ -54,6 +57,7 @@ void RomWidget::loadConfig() { cerr << "RomWidget::loadConfig()\n"; fillGrid(); + myRomList->setDirty(); myRomList->draw(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/stella/src/gui/BrowserDialog.cxx b/stella/src/gui/BrowserDialog.cxx index 38cc6581f..bacb205e6 100644 --- a/stella/src/gui/BrowserDialog.cxx +++ b/stella/src/gui/BrowserDialog.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: BrowserDialog.cxx,v 1.9 2005-08-10 12:23:42 stephena Exp $ +// $Id: BrowserDialog.cxx,v 1.10 2005-08-22 18:17:10 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -21,7 +21,7 @@ #include "OSystem.hxx" #include "Widget.hxx" -#include "ListWidget.hxx" +#include "StringListWidget.hxx" #include "Dialog.hxx" #include "FSNode.hxx" #include "GuiObject.hxx" @@ -54,8 +54,9 @@ BrowserDialog::BrowserDialog(GuiObject* boss, int x, int y, int w, int h) _currentPath = new StaticTextWidget(this, 10, 20, _w - 2 * 10, kLineHeight, "DUMMY", kTextAlignLeft); - // Add file list - _fileList = new ListWidget(this, 10, 34, _w - 2 * 10, _h - 34 - 24 - 10); + // Add file list FIXME_NOW + _fileList = new StringListWidget(this, instance()->font(), + 10, 34, _w - 2 * 10, _h - 34 - 24 - 10); _fileList->setNumberingMode(kListNumberingOff); _fileList->setEditable(false); _fileList->setFlags(WIDGET_NODRAW_FOCUS); diff --git a/stella/src/gui/BrowserDialog.hxx b/stella/src/gui/BrowserDialog.hxx index c759dd3ae..1dd0fb998 100644 --- a/stella/src/gui/BrowserDialog.hxx +++ b/stella/src/gui/BrowserDialog.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: BrowserDialog.hxx,v 1.5 2005-07-05 15:25:44 stephena Exp $ +// $Id: BrowserDialog.hxx,v 1.6 2005-08-22 18:17:10 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -24,7 +24,7 @@ class GuiObject; class StaticTextWidget; -class ListWidget; +class StringListWidget; #include "Dialog.hxx" #include "Command.hxx" @@ -47,7 +47,7 @@ class BrowserDialog : public Dialog, public CommandSender void updateListing(); protected: - ListWidget* _fileList; + StringListWidget* _fileList; StaticTextWidget* _currentPath; StaticTextWidget* _title; FilesystemNode _node; diff --git a/stella/src/gui/CheckListWidget.cxx b/stella/src/gui/CheckListWidget.cxx index 3a3f1541e..b4ead2c67 100644 --- a/stella/src/gui/CheckListWidget.cxx +++ b/stella/src/gui/CheckListWidget.cxx @@ -13,54 +13,22 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: CheckListWidget.cxx,v 1.1 2005-08-22 13:53:23 stephena Exp $ +// $Id: CheckListWidget.cxx,v 1.2 2005-08-22 18:17:10 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project //============================================================================ -#include -#include - -#include "OSystem.hxx" -#include "Widget.hxx" #include "ScrollBarWidget.hxx" -#include "Dialog.hxx" -#include "FrameBuffer.hxx" #include "CheckListWidget.hxx" + #include "bspf.hxx" // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - CheckListWidget::CheckListWidget(GuiObject* boss, const GUI::Font& font, - int x, int y, int cols, int rows) - : EditableWidget(boss, x, y, 16, 16) + int x, int y, int w, int h) + : ListWidget(boss, font, x, y, w, h) { - _flags = WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS; - - setFont(font); - - _cols = cols; - _rows = rows; - - _colWidth = font.getMaxCharWidth(); - _rowHeight = font.getLineHeight(); - - _w = _cols * _colWidth - kScrollBarWidth; - _h = _rows * _rowHeight + 2; - - - _editMode = false; - _currentPos = 0; - _selectedItem = -1; - _scrollBar = new ScrollBarWidget(boss, _x + _w, _y, kScrollBarWidth, _h); - _scrollBar->setTarget(this); - _currentKeyDown = 0; - - _quickSelectTime = 0; - - // The item is selected, thus _bgcolor is used to draw the caret and - // _textcolorhi to erase it - _caretInverse = true; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -68,279 +36,10 @@ CheckListWidget::~CheckListWidget() { } -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void CheckListWidget::setSelected(int item) -{ - assert(item >= -1 && item < (int)_list.size()); - - if (isEnabled() && _selectedItem != item) - { - if (_editMode) - abortEditMode(); - - _selectedItem = item; - sendCommand(kListSelectionChangedCmd, _selectedItem, _id); - - _currentPos = _selectedItem - _rows / 2; - scrollToCurrent(); - setDirty(); draw(); - } -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void CheckListWidget::setList(const StringList& list) -{ - int size = list.size(); - _list = list; - if (_currentPos >= size) - _currentPos = size - 1; - if (_currentPos < 0) - _currentPos = 0; - _selectedItem = -1; - _editMode = false; - scrollBarRecalc(); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void CheckListWidget::scrollTo(int item) -{ - int size = _list.size(); - if (item >= size) - item = size - 1; - if (item < 0) - item = 0; - - if (_currentPos != item) - { - _currentPos = item; - scrollBarRecalc(); - } -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void CheckListWidget::scrollBarRecalc() -{ - _scrollBar->_numEntries = _list.size(); - _scrollBar->_entriesPerPage = _rows; - _scrollBar->_currentPos = _currentPos; - _scrollBar->recalc(); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void CheckListWidget::handleMouseDown(int x, int y, int button, int clickCount) -{ - if (!isEnabled()) - return; - - // First check whether the selection changed - int newSelectedItem; - newSelectedItem = findItem(x, y); - if (newSelectedItem > (int)_list.size() - 1) - newSelectedItem = -1; - - if (_selectedItem != newSelectedItem) - { - if (_editMode) - abortEditMode(); - _selectedItem = newSelectedItem; - sendCommand(kListSelectionChangedCmd, _selectedItem, _id); - setDirty(); draw(); - } - - // TODO: Determine where inside the string the user clicked and place the - // caret accordingly. See _editScrollOffset and EditTextWidget::handleMouseDown. -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void CheckListWidget::handleMouseUp(int x, int y, int button, int clickCount) -{ - // If this was a double click and the mouse is still over the selected item, - // send the double click command - if (clickCount == 2 && (_selectedItem == findItem(x, y))) - { - sendCommand(kListItemDoubleClickedCmd, _selectedItem, _id); - - // Start edit mode - if(_editable && !_editMode) - startEditMode(); - } -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void CheckListWidget::handleMouseWheel(int x, int y, int direction) -{ - _scrollBar->handleMouseWheel(x, y, direction); - setDirty(); draw(); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -int CheckListWidget::findItem(int x, int y) const -{ - return (y - 1) / _rowHeight + _currentPos; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -static bool matchingCharsIgnoringCase(string s, string pattern) -{ - // Make the strings uppercase so we can compare them - transform(s.begin(), s.end(), s.begin(), (int(*)(int)) toupper); - transform(pattern.begin(), pattern.end(), pattern.begin(), (int(*)(int)) toupper); - - // Make sure that if the pattern is found, it occurs at the start of 's' - return (s.find(pattern, 0) == string::size_type(0)); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool CheckListWidget::handleKeyDown(int ascii, int keycode, int modifiers) -{ - // Ignore all mod keys - if(instance()->eventHandler().kbdControl(modifiers) || - instance()->eventHandler().kbdAlt(modifiers)) - return true; - - bool handled = true; - bool dirty = false; - int oldSelectedItem = _selectedItem; - - if (!_editMode && isalnum((char)ascii)) - { - // Quick selection mode: Go to first list item starting with this key - // (or a substring accumulated from the last couple key presses). - // Only works in a useful fashion if the list entries are sorted. - // TODO: Maybe this should be off by default, and instead we add a - // method "enableQuickSelect()" or so ? - int time = instance()->getTicks() / 1000; - if (_quickSelectTime < time) - _quickSelectStr = (char)ascii; - else - _quickSelectStr += (char)ascii; - _quickSelectTime = time + 300; - - // FIXME: This is bad slow code (it scans the list linearly each time a - // key is pressed); it could be much faster. Only of importance if we have - // quite big lists to deal with -- so for now we can live with this lazy - // implementation :-) - int newSelectedItem = 0; - for (StringList::const_iterator i = _list.begin(); i != _list.end(); ++i) - { - const bool match = matchingCharsIgnoringCase(*i, _quickSelectStr); - if (match) - { - _selectedItem = newSelectedItem; - break; - } - newSelectedItem++; - } - scrollToCurrent(); - } - else if (_editMode) - { - // Class EditableWidget handles all text editing related key presses for us - handled = EditableWidget::handleKeyDown(ascii, keycode, modifiers); - } - else - { - // not editmode - switch (keycode) - { - case '\n': // enter/return - case '\r': - if (_selectedItem >= 0) - { - // override continuous enter keydown - if (_editable && (_currentKeyDown != '\n' && _currentKeyDown != '\r')) - { - dirty = true; - startEditMode(); - } - else - sendCommand(kListItemActivatedCmd, _selectedItem, _id); - } - break; - - case 256+17: // up arrow - if (_selectedItem > 0) - _selectedItem--; - break; - - case 256+18: // down arrow - if (_selectedItem < (int)_list.size() - 1) - _selectedItem++; - break; - - case 256+24: // pageup - _selectedItem -= _rows - 1; - if (_selectedItem < 0) - _selectedItem = 0; - break; - - case 256+25: // pagedown - _selectedItem += _rows - 1; - if (_selectedItem >= (int)_list.size() ) - _selectedItem = _list.size() - 1; - break; - - case 256+22: // home - _selectedItem = 0; - break; - - case 256+23: // end - _selectedItem = _list.size() - 1; - break; - - default: - handled = false; - } - - scrollToCurrent(); - } - - if (_selectedItem != oldSelectedItem) - { - sendCommand(kListSelectionChangedCmd, _selectedItem, _id); - // also draw scrollbar - _scrollBar->draw(); - - setDirty(); draw(); - } - - _currentKeyDown = keycode; - return handled; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool CheckListWidget::handleKeyUp(int ascii, int keycode, int modifiers) -{ - if (keycode == _currentKeyDown) - _currentKeyDown = 0; - return true; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void CheckListWidget::lostFocusWidget() -{ - _editMode = false; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void CheckListWidget::handleCommand(CommandSender* sender, int cmd, int data, int id) -{ - switch (cmd) - { - case kSetPositionCmd: - if (_currentPos != (int)data) - { - _currentPos = data; - setDirty(); draw(); - } - break; - } -} - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void CheckListWidget::drawWidget(bool hilite) { -//cerr << "CheckListWidget::drawWidget\n"; +cerr << "CheckListWidget::drawWidget\n"; FrameBuffer& fb = _boss->instance()->frameBuffer(); int i, pos, len = _list.size(); string buffer; @@ -398,60 +97,16 @@ GUI::Rect CheckListWidget::getEditRect() const const int offset = (_selectedItem - _currentPos) * _rowHeight; r.top += offset; r.bottom += offset; + +/* + if (_numberingMode != kListNumberingOff) + { + char temp[10]; + // FIXME: Assumes that all digits have the same width. + sprintf(temp, "%2d. ", (_list.size() - 1 + _numberingMode)); + r.left += _font->getStringWidth(temp); + } +*/ return r; } - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void CheckListWidget::scrollToCurrent() -{ - // Only do something if the current item is not in our view port - if (_selectedItem < _currentPos) - { - // it's above our view - _currentPos = _selectedItem; - } - else if (_selectedItem >= _currentPos + _rows) - { - // it's below our view - _currentPos = _selectedItem - _rows + 1; - } - - if (_currentPos < 0 || _rows > (int)_list.size()) - _currentPos = 0; - else if (_currentPos + _rows > (int)_list.size()) - _currentPos = _list.size() - _rows; - - _scrollBar->_currentPos = _currentPos; - _scrollBar->recalc(); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void CheckListWidget::startEditMode() -{ - if (_editable && !_editMode && _selectedItem >= 0) - { - _editMode = true; - setEditString(_list[_selectedItem]); - } -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void CheckListWidget::endEditMode() -{ - if (!_editMode) - return; - - // send a message that editing finished with a return/enter key press - _editMode = false; - _list[_selectedItem] = _editString; - sendCommand(kListItemDataChangedCmd, _selectedItem, _id); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void CheckListWidget::abortEditMode() -{ - // undo any changes made - assert(_selectedItem >= 0); - _editMode = false; -} diff --git a/stella/src/gui/CheckListWidget.hxx b/stella/src/gui/CheckListWidget.hxx index 9ddc0fe33..28e164310 100644 --- a/stella/src/gui/CheckListWidget.hxx +++ b/stella/src/gui/CheckListWidget.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: CheckListWidget.hxx,v 1.1 2005-08-22 13:53:23 stephena Exp $ +// $Id: CheckListWidget.hxx,v 1.2 2005-08-22 18:17:10 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -22,84 +22,27 @@ #ifndef CHECK_LIST_WIDGET_HXX #define CHECK_LIST_WIDGET_HXX -#include "GuiObject.hxx" -#include "Widget.hxx" -#include "Command.hxx" -#include "StringList.hxx" -#include "EditableWidget.hxx" -#include "Rect.hxx" - -class ScrollBarWidget; +#include "ListWidget.hxx" // Some special commands enum { - kListItemChecked = 'LIct', - kListItemDoubleClickedCmd = 'LIdb', // double click on item - 'data' will be item index - kListItemActivatedCmd = 'LIac', // item activated by return/enter - 'data' will be item index - kListItemDataChangedCmd = 'LIch', // item data changed - 'data' will be item index - kListSelectionChangedCmd = 'Lsch' // selection changed - 'data' will be item index - + kListItemChecked = 'LIct' // checkbox toggled on current line }; /* CheckListWidget */ -class CheckListWidget : public EditableWidget +class CheckListWidget : public ListWidget { public: CheckListWidget(GuiObject* boss, const GUI::Font& font, - int x, int y, int cols, int rows); + int x, int y, int w, int h); virtual ~CheckListWidget(); - void setList(const StringList& list); - const StringList& getList() const { return _list; } - int getSelected() const { return _selectedItem; } - void setSelected(int item); - const string& getSelectedString() const { return _list[_selectedItem]; } - void scrollTo(int item); - - virtual void handleMouseDown(int x, int y, int button, int clickCount); - virtual void handleMouseUp(int x, int y, int button, int clickCount); - virtual void handleMouseWheel(int x, int y, int direction); - virtual bool handleKeyDown(int ascii, int keycode, int modifiers); - virtual bool handleKeyUp(int ascii, int keycode, int modifiers); - virtual void handleCommand(CommandSender* sender, int cmd, int data, int id); - - virtual bool wantsFocus() { return true; } - - void startEditMode(); - void endEditMode(); - protected: void drawWidget(bool hilite); - - int findItem(int x, int y) const; - void scrollBarRecalc(); - - void abortEditMode(); - GUI::Rect getEditRect() const; - void lostFocusWidget(); - void scrollToCurrent(); - protected: - int _rows; - int _cols; - int _rowHeight; - int _colWidth; - int _currentPos; - int _selectedItem; - - - StringList _list; BoolArray _checkList; - - bool _editMode; - ScrollBarWidget* _scrollBar; - int _currentKeyDown; - string _backupString; - - string _quickSelectStr; - int _quickSelectTime; }; #endif diff --git a/stella/src/gui/EventMappingDialog.cxx b/stella/src/gui/EventMappingDialog.cxx index 1e162bc68..1e2abbf8b 100644 --- a/stella/src/gui/EventMappingDialog.cxx +++ b/stella/src/gui/EventMappingDialog.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: EventMappingDialog.cxx,v 1.18 2005-08-10 12:23:42 stephena Exp $ +// $Id: EventMappingDialog.cxx,v 1.19 2005-08-22 18:17:10 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -21,7 +21,7 @@ #include "OSystem.hxx" #include "Widget.hxx" -#include "ListWidget.hxx" +#include "StringListWidget.hxx" #include "PopUpWidget.hxx" #include "Dialog.hxx" #include "GuiUtils.hxx" @@ -42,8 +42,10 @@ EventMappingDialog::EventMappingDialog(OSystem* osystem, DialogContainer* parent myDefaultsButton = addButton(10, h - 24, "Defaults", kDefaultsCmd, 0); myOKButton = addButton(w - (kButtonWidth + 10), h - 24, "OK", kOKCmd, 0); - new StaticTextWidget(this, 10, 8, 150, kFontHeight, "Select an event to remap:", kTextAlignCenter); - myActionsList = new ListWidget(this, 10, 20, 150, 100); + new StaticTextWidget(this, 10, 8, 150, kFontHeight, + "Select an event to remap:", kTextAlignCenter); + + myActionsList = new StringListWidget(this, instance()->font(), 10, 20, 150, 100); myActionsList->setNumberingMode(kListNumberingOff); myActionsList->setEditable(false); myActionsList->setFlags(WIDGET_NODRAW_FOCUS); diff --git a/stella/src/gui/EventMappingDialog.hxx b/stella/src/gui/EventMappingDialog.hxx index 483d7268d..f8f9f893c 100644 --- a/stella/src/gui/EventMappingDialog.hxx +++ b/stella/src/gui/EventMappingDialog.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: EventMappingDialog.hxx,v 1.11 2005-07-05 15:25:44 stephena Exp $ +// $Id: EventMappingDialog.hxx,v 1.12 2005-08-22 18:17:10 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -26,7 +26,7 @@ class DialogContainer; class CommandSender; class ButtonWidget; class StaticTextWidget; -class ListWidget; +class StringListWidget; class PopUpWidget; #include "OSystem.hxx" @@ -48,7 +48,7 @@ class EventMappingDialog : public Dialog ButtonWidget* myEraseButton; ButtonWidget* myOKButton; ButtonWidget* myDefaultsButton; - ListWidget* myActionsList; + StringListWidget* myActionsList; StaticTextWidget* myKeyMapping; PopUpWidget* myPaddleModePopup; StaticTextWidget* myPaddleModeText; diff --git a/stella/src/gui/LauncherDialog.cxx b/stella/src/gui/LauncherDialog.cxx index 964b7f675..153416e2d 100644 --- a/stella/src/gui/LauncherDialog.cxx +++ b/stella/src/gui/LauncherDialog.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: LauncherDialog.cxx,v 1.28 2005-08-11 19:12:39 stephena Exp $ +// $Id: LauncherDialog.cxx,v 1.29 2005-08-22 18:17:10 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -29,7 +29,7 @@ #include "MD5.hxx" #include "FSNode.hxx" #include "Widget.hxx" -#include "ListWidget.hxx" +#include "StringListWidget.hxx" #include "Dialog.hxx" #include "DialogContainer.hxx" #include "GuiUtils.hxx" @@ -92,7 +92,8 @@ LauncherDialog::LauncherDialog(OSystem* osystem, DialogContainer* parent, #endif // Add list with game titles - myList = new ListWidget(this, 10, 24, _w - 20, _h - 24 - 26 - 10 - 10); + myList = new StringListWidget(this, instance()->font(), + 10, 24, _w - 20, _h - 24 - 26 - 10 - 10); // FIXME_NOW myList->setNumberingMode(kListNumberingOff); myList->setEditable(false); myList->setFlags(WIDGET_NODRAW_FOCUS); diff --git a/stella/src/gui/LauncherDialog.hxx b/stella/src/gui/LauncherDialog.hxx index f2673aaea..685d59809 100644 --- a/stella/src/gui/LauncherDialog.hxx +++ b/stella/src/gui/LauncherDialog.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: LauncherDialog.hxx,v 1.12 2005-08-11 19:12:39 stephena Exp $ +// $Id: LauncherDialog.hxx,v 1.13 2005-08-22 18:17:10 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -27,7 +27,7 @@ class LauncherOptionsDialog; class ProgressDialog; class CommandSender; class StaticTextWidget; -class ListWidget; +class StringListWidget; class ButtonWidget; class OSystem; @@ -65,7 +65,7 @@ class LauncherDialog : public Dialog ButtonWidget* myReloadButton; ButtonWidget* myQuitButton; - ListWidget* myList; + StringListWidget* myList; StaticTextWidget* myNote; StaticTextWidget* myRomCount; GameList* myGameList; diff --git a/stella/src/gui/ListWidget.cxx b/stella/src/gui/ListWidget.cxx index cc746054e..7fad3873b 100644 --- a/stella/src/gui/ListWidget.cxx +++ b/stella/src/gui/ListWidget.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: ListWidget.cxx,v 1.26 2005-08-11 19:12:39 stephena Exp $ +// $Id: ListWidget.cxx,v 1.27 2005-08-22 18:17:10 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -31,27 +31,35 @@ #include "bspf.hxx" // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -ListWidget::ListWidget(GuiObject* boss, int x, int y, int w, int h) - : EditableWidget(boss, x, y, w, h) +ListWidget::ListWidget(GuiObject* boss, const GUI::Font& font, + int x, int y, int w, int h) + : EditableWidget(boss, x, y, 16, 16), + _rows(0), + _cols(0), + _currentPos(0), + _selectedItem(-1), + _currentKeyDown(0), + _editMode(false), + _caretInverse(true), + _quickSelectTime(0) { - _w = w - kScrollBarWidth; - _flags = WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS; _type = kListWidget; - _editMode = false; - _numberingMode = kListNumberingOne; - _entriesPerPage = (_h - 2) / kLineHeight; - _currentPos = 0; - _selectedItem = -1; + + setFont(font); + + _colWidth = font.getMaxCharWidth(); + _rowHeight = font.getLineHeight(); + _cols = w / _colWidth; + _rows = h / _rowHeight; + + // Set real dimensions + _w = w - kScrollBarWidth; + _h = h + 2; + + // Create scrollbar and attach to the list _scrollBar = new ScrollBarWidget(boss, _x + _w, _y, kScrollBarWidth, _h); _scrollBar->setTarget(this); - _currentKeyDown = 0; - - _quickSelectTime = 0; - - // The item is selected, thus _bgcolor is used to draw the caret and - // _textcolorhi to erase it - _caretInverse = true; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -72,7 +80,7 @@ void ListWidget::setSelected(int item) _selectedItem = item; sendCommand(kListSelectionChangedCmd, _selectedItem, _id); - _currentPos = _selectedItem - _entriesPerPage / 2; + _currentPos = _selectedItem - _rows / 2; scrollToCurrent(); setDirty(); draw(); } @@ -111,9 +119,9 @@ void ListWidget::scrollTo(int item) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void ListWidget::scrollBarRecalc() { - _scrollBar->_numEntries = _list.size(); - _scrollBar->_entriesPerPage = _entriesPerPage; - _scrollBar->_currentPos = _currentPos; + _scrollBar->_numEntries = _list.size(); + _scrollBar->_entriesPerPage = _rows; + _scrollBar->_currentPos = _currentPos; _scrollBar->recalc(); } @@ -167,7 +175,7 @@ void ListWidget::handleMouseWheel(int x, int y, int direction) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - int ListWidget::findItem(int x, int y) const { - return (y - 1) / kLineHeight + _currentPos; + return (y - 1) / _rowHeight + _currentPos; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -260,13 +268,13 @@ bool ListWidget::handleKeyDown(int ascii, int keycode, int modifiers) break; case 256+24: // pageup - _selectedItem -= _entriesPerPage - 1; + _selectedItem -= _rows - 1; if (_selectedItem < 0) _selectedItem = 0; break; case 256+25: // pagedown - _selectedItem += _entriesPerPage - 1; + _selectedItem += _rows - 1; if (_selectedItem >= (int)_list.size() ) _selectedItem = _list.size() - 1; break; @@ -328,88 +336,6 @@ void ListWidget::handleCommand(CommandSender* sender, int cmd, int data, int id) } } -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void ListWidget::drawWidget(bool hilite) -{ -cerr << "ListWidget::drawWidget\n"; - FrameBuffer& fb = _boss->instance()->frameBuffer(); - int i, pos, len = _list.size(); - string buffer; - int deltax; - - // Draw a thin frame around the list. - fb.hLine(_x, _y, _x + _w - 1, kColor); - fb.hLine(_x, _y + _h - 1, _x + _w - 1, kShadowColor); - fb.vLine(_x, _y, _y + _h - 1, kColor); - - // Draw the list items - for (i = 0, pos = _currentPos; i < _entriesPerPage && pos < len; i++, pos++) - { - const OverlayColor textColor = (_selectedItem == pos && _editMode) - ? kColor : kTextColor; - const int y = _y + 2 + kLineHeight * i; - - // Draw the selected item inverted, on a highlighted background. - if (_selectedItem == pos) - { - if (_hasFocus && !_editMode) - fb.fillRect(_x + 1, _y + 1 + kLineHeight * i, _w - 1, kLineHeight, kTextColorHi); - else - fb.frameRect(_x + 1, _y + 1 + kLineHeight * i, _w - 1, kLineHeight, kTextColorHi); - } - - // If in numbering mode, we first print a number prefix - if (_numberingMode != kListNumberingOff) - { - char temp[10]; - sprintf(temp, "%2d. ", (pos + _numberingMode)); - buffer = temp; - fb.drawString(_font, buffer, _x + 2, y, _w - 4, textColor); - } - - GUI::Rect r(getEditRect()); - if (_selectedItem == pos && _editMode) - { - buffer = _editString; - adjustOffset(); - deltax = -_editScrollOffset; - - fb.drawString(_font, buffer, _x + r.left, y, r.width(), kTextColor, - kTextAlignLeft, deltax, false); - } - else - { - buffer = _list[pos]; - deltax = 0; - fb.drawString(_font, buffer, _x + r.left, y, r.width(), kTextColor); - } - } - - // Only draw the caret while editing, and if it's in the current viewport - if(_editMode && (_selectedItem >= _scrollBar->_currentPos) && - (_selectedItem < _scrollBar->_currentPos + _entriesPerPage)) - drawCaret(); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -GUI::Rect ListWidget::getEditRect() const -{ - GUI::Rect r(2, 1, _w - 2 , kLineHeight); - const int offset = (_selectedItem - _currentPos) * kLineHeight; - r.top += offset; - r.bottom += offset; - - if (_numberingMode != kListNumberingOff) - { - char temp[10]; - // FIXME: Assumes that all digits have the same width. - sprintf(temp, "%2d. ", (_list.size() - 1 + _numberingMode)); - r.left += _font->getStringWidth(temp); - } - - return r; -} - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void ListWidget::scrollToCurrent() { @@ -419,16 +345,16 @@ void ListWidget::scrollToCurrent() // it's above our view _currentPos = _selectedItem; } - else if (_selectedItem >= _currentPos + _entriesPerPage ) + else if (_selectedItem >= _currentPos + _rows ) { // it's below our view - _currentPos = _selectedItem - _entriesPerPage + 1; + _currentPos = _selectedItem - _rows + 1; } - if (_currentPos < 0 || _entriesPerPage > (int)_list.size()) + if (_currentPos < 0 || _rows > (int)_list.size()) _currentPos = 0; - else if (_currentPos + _entriesPerPage > (int)_list.size()) - _currentPos = _list.size() - _entriesPerPage; + else if (_currentPos + _rows > (int)_list.size()) + _currentPos = _list.size() - _rows; _scrollBar->_currentPos = _currentPos; _scrollBar->recalc(); diff --git a/stella/src/gui/ListWidget.hxx b/stella/src/gui/ListWidget.hxx index 5f34c7112..16b2ef755 100644 --- a/stella/src/gui/ListWidget.hxx +++ b/stella/src/gui/ListWidget.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: ListWidget.hxx,v 1.9 2005-08-11 19:12:39 stephena Exp $ +// $Id: ListWidget.hxx,v 1.10 2005-08-22 18:17:10 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -25,18 +25,12 @@ #include "GuiObject.hxx" #include "Widget.hxx" #include "Command.hxx" -#include "StringList.hxx" #include "EditableWidget.hxx" #include "Rect.hxx" +class StringList; class ScrollBarWidget; -enum NumberingMode { - kListNumberingOff = -1, - kListNumberingZero = 0, - kListNumberingOne = 1 -}; - // Some special commands enum { kListItemDoubleClickedCmd = 'LIdb', // double click on item - 'data' will be item index @@ -45,21 +39,23 @@ enum { kListSelectionChangedCmd = 'Lsch' // selection changed - 'data' will be item index }; -/* ListWidget */ +/** ListWidget */ class ListWidget : public EditableWidget { public: - ListWidget(GuiObject* boss, int x, int y, int w, int h); + ListWidget(GuiObject* boss, const GUI::Font& font, + int x, int y, int w, int h); virtual ~ListWidget(); - void setList(const StringList& list); - const StringList& getList() const { return _list; } - int getSelected() const { return _selectedItem; } + int getSelected() const { return _selectedItem; } void setSelected(int item); - const string& getSelectedString() const { return _list[_selectedItem]; } - void setNumberingMode(NumberingMode numberingMode) { _numberingMode = numberingMode; } + + void setList(const StringList& list); + const StringList& getList() const { return _list; } + const string& getSelectedString() const { return _list[_selectedItem]; } + void scrollTo(int item); - + virtual void handleMouseDown(int x, int y, int button, int clickCount); virtual void handleMouseUp(int x, int y, int button, int clickCount); virtual void handleMouseWheel(int x, int y, int direction); @@ -73,31 +69,35 @@ class ListWidget : public EditableWidget void endEditMode(); protected: - void drawWidget(bool hilite); + virtual void drawWidget(bool hilite) = 0; + virtual GUI::Rect getEditRect() const = 0; int findItem(int x, int y) const; void scrollBarRecalc(); void abortEditMode(); - GUI::Rect getEditRect() const; - void lostFocusWidget(); void scrollToCurrent(); -protected: - StringList _list; - bool _editMode; - NumberingMode _numberingMode; - int _currentPos; - int _entriesPerPage; - int _selectedItem; - ScrollBarWidget* _scrollBar; - int _currentKeyDown; - string _backupString; + protected: + int _rows; + int _cols; + int _rowHeight; + int _colWidth; + int _currentPos; + int _selectedItem; + int _currentKeyDown; - string _quickSelectStr; - int _quickSelectTime; + bool _editMode; + bool _caretInverse; + + ScrollBarWidget* _scrollBar; + + StringList _list; + string _backupString; + string _quickSelectStr; + int _quickSelectTime; }; #endif diff --git a/stella/src/gui/Widget.cxx b/stella/src/gui/Widget.cxx index 284a901af..5fd114a3a 100644 --- a/stella/src/gui/Widget.cxx +++ b/stella/src/gui/Widget.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: Widget.cxx,v 1.30 2005-08-18 16:19:07 stephena Exp $ +// $Id: Widget.cxx,v 1.31 2005-08-22 18:17:10 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -325,8 +325,7 @@ ButtonWidget::ButtonWidget(GuiObject *boss, int x, int y, int w, int h, _cmd(cmd), _hotkey(hotkey) { - _flags = WIDGET_ENABLED | WIDGET_BORDER | WIDGET_CLEARBG | - WIDGET_RETAIN_FOCUS; + _flags = WIDGET_ENABLED | WIDGET_BORDER | WIDGET_CLEARBG; _type = kButtonWidget; } diff --git a/stella/src/gui/Widget.hxx b/stella/src/gui/Widget.hxx index 8efb3b469..957488943 100644 --- a/stella/src/gui/Widget.hxx +++ b/stella/src/gui/Widget.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: Widget.hxx,v 1.31 2005-08-22 13:53:23 stephena Exp $ +// $Id: Widget.hxx,v 1.32 2005-08-22 18:17:10 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -71,7 +71,7 @@ enum { This is the base class for all widgets. @author Stephen Anthony - @version $Id: Widget.hxx,v 1.31 2005-08-22 13:53:23 stephena Exp $ + @version $Id: Widget.hxx,v 1.32 2005-08-22 18:17:10 stephena Exp $ */ class Widget : public GuiObject { @@ -200,8 +200,6 @@ class ButtonWidget : public StaticTextWidget, public CommandSender void handleMouseEntered(int button); void handleMouseLeft(int button); - bool wantsFocus() { return true; }; - protected: void drawWidget(bool hilite); diff --git a/stella/src/gui/module.mk b/stella/src/gui/module.mk index 6824a4ece..ae9bd6e78 100644 --- a/stella/src/gui/module.mk +++ b/stella/src/gui/module.mk @@ -4,7 +4,6 @@ MODULE_OBJS := \ src/gui/AboutDialog.o \ src/gui/AudioDialog.o \ src/gui/BrowserDialog.o \ - src/gui/CheckListWidget.o \ src/gui/ColorWidget.o \ src/gui/CheatCodeDialog.o \ src/gui/DataGridWidget.o \ @@ -30,6 +29,8 @@ MODULE_OBJS := \ src/gui/PopUpWidget.o \ src/gui/ProgressDialog.o \ src/gui/ScrollBarWidget.o \ + src/gui/CheckListWidget.o \ + src/gui/StringListWidget.o \ src/gui/TabWidget.o \ src/gui/ToggleWidget.o \ src/gui/ToggleBitWidget.o \