From 58e906998a4c8d5db81647fefac287434cc5f5a6 Mon Sep 17 00:00:00 2001 From: stephena Date: Wed, 4 May 2005 00:43:22 +0000 Subject: [PATCH] Updated ListWidget class to automatically select an item based on keypresses. For example, if you enter 'co', it will automatically select and move to the "Color/BW TV" item. This will become very useful in the ROM launcher, to move very quickly to desired game. Changed the keys to (de)activate the TIA registers to Alt (z,x,c,v,b,n), to match their definitions in z26. Added 'Alt .' to disable all TIA registers, and 'Alt /' to enable all registers. Eventually, I'll add the ability to select PF0, PF1, and PF2 separately (instead of treating them all the same, as it's done now). git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@407 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba --- stella/src/emucore/Console.cxx | 26 ++++++++---- stella/src/emucore/Console.hxx | 27 ++++++------ stella/src/emucore/EventHandler.cxx | 66 +++++++++++++++-------------- stella/src/emucore/TIA.hxx | 11 ++++- stella/src/gui/ListWidget.cxx | 40 ++++++++--------- 5 files changed, 93 insertions(+), 77 deletions(-) diff --git a/stella/src/emucore/Console.cxx b/stella/src/emucore/Console.cxx index a7e1cbda4..0f5890d1d 100644 --- a/stella/src/emucore/Console.cxx +++ b/stella/src/emucore/Console.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: Console.cxx,v 1.48 2005-05-01 18:57:20 stephena Exp $ +// $Id: Console.cxx,v 1.49 2005-05-04 00:43:22 stephena Exp $ //============================================================================ #include @@ -286,14 +286,6 @@ void Console::togglePalette(const string& palette) myOSystem->frameBuffer().showMessage(message); } -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Console::toggleTIABit(TIA::TIABit bit, const string& bitname, bool show) -{ - bool result = ((TIA*)myMediaSource)->toggleBit(bit); - string message = bitname + (result ? " enabled" : " disabled"); - myOSystem->frameBuffer().showMessage(message); -} - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Console::saveProperties(string filename, bool merge) { @@ -493,4 +485,20 @@ void Console::changeHeight(const uInt32 direction) message += strval.str(); myOSystem->frameBuffer().showMessage(message); } + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void Console::toggleTIABit(TIA::TIABit bit, const string& bitname, bool show) +{ + bool result = ((TIA*)myMediaSource)->toggleBit(bit); + string message = bitname + (result ? " enabled" : " disabled"); + myOSystem->frameBuffer().showMessage(message); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void Console::enableBits(bool enable) +{ + ((TIA*)myMediaSource)->enableBits(enable); + string message = string("TIA bits") + (enable ? " enabled" : " disabled"); + myOSystem->frameBuffer().showMessage(message); +} #endif diff --git a/stella/src/emucore/Console.hxx b/stella/src/emucore/Console.hxx index 241264271..859e141e6 100644 --- a/stella/src/emucore/Console.hxx +++ b/stella/src/emucore/Console.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: Console.hxx,v 1.28 2005-05-01 18:57:20 stephena Exp $ +// $Id: Console.hxx,v 1.29 2005-05-04 00:43:22 stephena Exp $ //============================================================================ #ifndef CONSOLE_HXX @@ -35,7 +35,7 @@ class System; This class represents the entire game console. @author Bradford W. Mott - @version $Id: Console.hxx,v 1.28 2005-05-01 18:57:20 stephena Exp $ + @version $Id: Console.hxx,v 1.29 2005-05-04 00:43:22 stephena Exp $ */ class Console { @@ -132,16 +132,6 @@ class Console */ void togglePalette(const string& palette = ""); - /** - Toggles the TIA bit specified in the method name. - */ - void toggleP0Bit() { toggleTIABit(TIA::P0, "P0"); } - void toggleP1Bit() { toggleTIABit(TIA::P1, "P1"); } - void toggleM0Bit() { toggleTIABit(TIA::M0, "M0"); } - void toggleM1Bit() { toggleTIABit(TIA::M1, "M1"); } - void toggleBLBit() { toggleTIABit(TIA::BL, "BL"); } - void togglePFBit() { toggleTIABit(TIA::PF, "PF"); } - /** Save a copy of the current properties after any changes. @@ -194,10 +184,21 @@ class Console @param direction A 1 indicates increase, 0 indicates decrease. */ void changeHeight(const uInt32 direction); -#endif + + /** + Toggles the TIA bit specified in the method name. + */ + void toggleP0Bit() { toggleTIABit(TIA::P0, "P0"); } + void toggleP1Bit() { toggleTIABit(TIA::P1, "P1"); } + void toggleM0Bit() { toggleTIABit(TIA::M0, "M0"); } + void toggleM1Bit() { toggleTIABit(TIA::M1, "M1"); } + void toggleBLBit() { toggleTIABit(TIA::BL, "BL"); } + void togglePFBit() { toggleTIABit(TIA::PF, "PF"); } + void enableBits(bool enable); private: void toggleTIABit(TIA::TIABit bit, const string& bitname, bool show = true); +#endif private: // Pointer to the osystem object diff --git a/stella/src/emucore/EventHandler.cxx b/stella/src/emucore/EventHandler.cxx index 9c540ef60..5fbd4c682 100644 --- a/stella/src/emucore/EventHandler.cxx +++ b/stella/src/emucore/EventHandler.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: EventHandler.cxx,v 1.47 2005-05-01 20:11:07 stephena Exp $ +// $Id: EventHandler.cxx,v 1.48 2005-05-04 00:43:22 stephena Exp $ //============================================================================ #include @@ -246,36 +246,7 @@ void EventHandler::handleKeyEvent(SDLKey key, SDLMod mod, uInt8 state) // An attempt to speed up event processing // All SDL-specific event actions are accessed by either // Control and/or Alt keys. So we quickly check for those. - if((mod & KMOD_ALT) && (mod & KMOD_CTRL) && state) - { - switch(int(key)) - { - case SDLK_1: - myOSystem->console().toggleP0Bit(); - break; - - case SDLK_2: - myOSystem->console().toggleP1Bit(); - break; - - case SDLK_3: - myOSystem->console().toggleM0Bit(); - break; - - case SDLK_4: - myOSystem->console().toggleM1Bit(); - break; - - case SDLK_5: - myOSystem->console().toggleBLBit(); - break; - - case SDLK_6: - myOSystem->console().togglePFBit(); - break; - } - } - else if(mod & KMOD_ALT && state) + if(mod & KMOD_ALT && state) { switch(int(key)) { @@ -303,6 +274,39 @@ void EventHandler::handleKeyEvent(SDLKey key, SDLMod mod, uInt8 state) case SDLK_PAGEDOWN: // Alt-PageDown decreases YStart myOSystem->console().changeYStart(0); break; +#endif +#ifdef DEVELOPER_SUPPORT + case SDLK_z: + myOSystem->console().toggleP0Bit(); + break; + + case SDLK_x: + myOSystem->console().toggleP1Bit(); + break; + + case SDLK_c: + myOSystem->console().toggleM0Bit(); + break; + + case SDLK_v: + myOSystem->console().toggleM1Bit(); + break; + + case SDLK_b: + myOSystem->console().toggleBLBit(); + break; + + case SDLK_n: + myOSystem->console().togglePFBit(); + break; + + case SDLK_PERIOD: + myOSystem->console().enableBits(false); + break; + + case SDLK_SLASH: + myOSystem->console().enableBits(true); + break; #endif } } diff --git a/stella/src/emucore/TIA.hxx b/stella/src/emucore/TIA.hxx index bacfd494b..73040994a 100644 --- a/stella/src/emucore/TIA.hxx +++ b/stella/src/emucore/TIA.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: TIA.hxx,v 1.19 2005-05-01 18:57:21 stephena Exp $ +// $Id: TIA.hxx,v 1.20 2005-05-04 00:43:22 stephena Exp $ //============================================================================ #ifndef TIA_HXX @@ -42,7 +42,7 @@ class Settings; be displayed on screen. @author Bradford W. Mott - @version $Id: TIA.hxx,v 1.19 2005-05-01 18:57:21 stephena Exp $ + @version $Id: TIA.hxx,v 1.20 2005-05-04 00:43:22 stephena Exp $ */ class TIA : public Device , public MediaSource { @@ -198,6 +198,13 @@ class TIA : public Device , public MediaSource */ bool toggleBit(TIABit b) { myBitEnabled[b] = !myBitEnabled[b]; return myBitEnabled[b]; } + /** + Enables/disables all TIABit bits. + + @param mode Whether to enable or disable all bits + */ + void enableBits(bool mode) { for(uInt8 i = 0; i < 6; ++i) myBitEnabled[i] = mode; } + private: // Compute the ball mask table void computeBallMaskTable(); diff --git a/stella/src/gui/ListWidget.cxx b/stella/src/gui/ListWidget.cxx index ae1cbd915..febf34d2e 100644 --- a/stella/src/gui/ListWidget.cxx +++ b/stella/src/gui/ListWidget.cxx @@ -13,12 +13,15 @@ // 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.3 2005-05-03 19:11:25 stephena Exp $ +// $Id: ListWidget.cxx,v 1.4 2005-05-04 00:43:22 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" @@ -185,17 +188,16 @@ void ListWidget::handleMouseWheel(Int32 x, Int32 y, Int32 direction) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -static int matchingCharsIgnoringCase(const char* x, const char* y, bool& stop) +static bool matchingCharsIgnoringCase(string s, string pattern) { - int match = 0; - while (*x && *y && toupper(*x) == toupper(*y)) - { - ++x; - ++y; - ++match; - } - stop = !*y || (*x && (toupper(*x) >= toupper(*y))); - return match; + // 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); + + uInt32 pos = s.find(pattern, 0); + + // Make sure that if the pattern is found, it occurs at the start of 's' + return (pos != string::npos && pos < pattern.length()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -205,7 +207,7 @@ bool ListWidget::handleKeyDown(uInt16 ascii, Int32 keycode, Int32 modifiers) bool dirty = false; Int32 oldSelectedItem = _selectedItem; - if (!_editMode && isprint((char)ascii)) + if (!_editMode && isalpha((char)ascii)) { // Quick selection mode: Go to first list item starting with this key // (or a substring accumulated from the last couple key presses). @@ -217,7 +219,7 @@ bool ListWidget::handleKeyDown(uInt16 ascii, Int32 keycode, Int32 modifiers) _quickSelectStr = (char)ascii; else _quickSelectStr += (char)ascii; -cerr << "_quickSelectStr = " << _quickSelectStr << endl; + _quickSelectTime = time + 300; // TODO: Turn this into a proper constant (kQuickSelectDelay ?) // FIXME: This is bad slow code (it scans the list linearly each time a @@ -225,19 +227,13 @@ cerr << "_quickSelectStr = " << _quickSelectStr << endl; // quite big lists to deal with -- so for now we can live with this lazy // implementation :-) int newSelectedItem = 0; - int bestMatch = 0; - bool stop; for (StringList::const_iterator i = _list.begin(); i != _list.end(); ++i) { - const int match = matchingCharsIgnoringCase(i->c_str(), _quickSelectStr.c_str(), stop); - if (match > bestMatch || stop) + const bool match = matchingCharsIgnoringCase(*i, _quickSelectStr); + if (match) { _selectedItem = newSelectedItem; - bestMatch = match; - if (stop) -{cerr << *i << endl; - break; -} + break; } newSelectedItem++; }