diff --git a/stella/src/emucore/EventHandler.cxx b/stella/src/emucore/EventHandler.cxx index 7bc277244..9b3222905 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.161 2006-05-04 17:45:24 stephena Exp $ +// $Id: EventHandler.cxx,v 1.162 2006-05-05 18:00:50 stephena Exp $ //============================================================================ #include @@ -1848,6 +1848,28 @@ inline bool EventHandler::eventIsAnalog(Event::Type event) } } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +StringList EventHandler::getEmulationActions() +{ + StringList l; + + for(int i = 0; i < kActionListSize; ++i) + l.push_back(EventHandler::ourActionList[i].action); + + return l; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +StringList EventHandler::getMenuActions() +{ + StringList l; // FIXME + +// for(int i = 0; i < kActionListSize; ++i) +// l.push_back(EventHandler::ourActionList[i].action); + + return l; +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Event::Type EventHandler::eventForKey(int key, EventMode mode) { diff --git a/stella/src/emucore/EventHandler.hxx b/stella/src/emucore/EventHandler.hxx index a3a8d25ca..d8346e833 100644 --- a/stella/src/emucore/EventHandler.hxx +++ b/stella/src/emucore/EventHandler.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: EventHandler.hxx,v 1.86 2006-05-04 17:45:24 stephena Exp $ +// $Id: EventHandler.hxx,v 1.87 2006-05-05 18:00:51 stephena Exp $ //============================================================================ #ifndef EVENTHANDLER_HXX @@ -65,8 +65,8 @@ enum { }; enum EventMode { - kEmulation, - kMenuOverlay + kEmulationMode, + kMenuMode }; // Joystick related items @@ -91,7 +91,7 @@ struct Stella_Joystick { }; // Used for joystick to mouse emulation -struct JoyMouse { +struct JoyMouse { bool active; int x, y, x_vel, y_vel, x_max, y_max, x_amt, y_amt, amt, x_down_count, y_down_count; @@ -112,7 +112,7 @@ struct JoyMouse { mapping can take place. @author Stephen Anthony - @version $Id: EventHandler.hxx,v 1.86 2006-05-04 17:45:24 stephena Exp $ + @version $Id: EventHandler.hxx,v 1.87 2006-05-05 18:00:51 stephena Exp $ */ class EventHandler { @@ -333,6 +333,9 @@ class EventHandler inline SDL_Joystick* getJoystick(int i) { return ourJoysticks[i].stick; } + StringList getEmulationActions(); + StringList getMenuActions(); + Event::Type eventForKey(int key, EventMode mode); Event::Type eventForJoyButton(int stick, int button, EventMode mode); Event::Type eventForJoyAxis(int stick, int axis, int value, EventMode mode); diff --git a/stella/src/gui/Dialog.cxx b/stella/src/gui/Dialog.cxx index f89da3afa..2262a7b88 100644 --- a/stella/src/gui/Dialog.cxx +++ b/stella/src/gui/Dialog.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: Dialog.cxx,v 1.44 2006-05-04 17:45:25 stephena Exp $ +// $Id: Dialog.cxx,v 1.45 2006-05-05 18:00:51 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -313,7 +313,7 @@ void Dialog::handleKeyDown(int ascii, int keycode, int modifiers) // which must always be processed before any widget sees it. bool handled = false; if(e == Event::NoType) - e = instance()->eventHandler().eventForKey(ascii, kMenuOverlay); + e = instance()->eventHandler().eventForKey(ascii, kMenuMode); switch(e) { diff --git a/stella/src/gui/EventMappingWidget.cxx b/stella/src/gui/EventMappingWidget.cxx index 838694c40..14b0cb078 100644 --- a/stella/src/gui/EventMappingWidget.cxx +++ b/stella/src/gui/EventMappingWidget.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: EventMappingWidget.cxx,v 1.15 2006-05-04 17:45:25 stephena Exp $ +// $Id: EventMappingWidget.cxx,v 1.16 2006-05-05 18:00:51 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -33,9 +33,11 @@ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - EventMappingWidget::EventMappingWidget(GuiObject* boss, const GUI::Font& font, - int x, int y, int w, int h) + int x, int y, int w, int h, + const StringList& actions, EventMode mode) : Widget(boss, font, x, y, w, h), CommandSender(boss), + myEventMode(mode), myActionSelected(-1), myRemapStatus(false), myFirstTime(true) @@ -50,6 +52,7 @@ EventMappingWidget::EventMappingWidget(GuiObject* boss, const GUI::Font& font, myActionsList->setTarget(this); myActionsList->setNumberingMode(kListNumberingOff); myActionsList->setEditable(false); + myActionsList->setList(actions); addFocusWidget(myActionsList); // Add remap, erase, cancel and default buttons @@ -80,14 +83,6 @@ EventMappingWidget::EventMappingWidget(GuiObject* boss, const GUI::Font& font, myKeyMapping = new StaticTextWidget(boss, font, xpos, ypos, _w - 20, fontHeight, "Action: ", kTextAlignLeft); myKeyMapping->setFlags(WIDGET_CLEARBG); - - // Get actions names - StringList l; - - for(int i = 0; i < kActionListSize; ++i) - l.push_back(EventHandler::ourActionList[i].action); - - myActionsList->setList(l); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -98,7 +93,7 @@ EventMappingWidget::~EventMappingWidget() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void EventMappingWidget::loadConfig() { -//cerr << "EventMappingWidget::loadConfig()\n"; +cerr << "EventMappingWidget::loadConfig() for " << myEventMode << endl; if(myFirstTime) { myActionsList->setSelected(0); diff --git a/stella/src/gui/EventMappingWidget.hxx b/stella/src/gui/EventMappingWidget.hxx index 5d212bec8..57ea63a44 100644 --- a/stella/src/gui/EventMappingWidget.hxx +++ b/stella/src/gui/EventMappingWidget.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: EventMappingWidget.hxx,v 1.9 2006-05-04 17:45:25 stephena Exp $ +// $Id: EventMappingWidget.hxx,v 1.10 2006-05-05 18:00:51 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -42,7 +42,8 @@ class EventMappingWidget : public Widget, public CommandSender public: EventMappingWidget(GuiObject* boss, const GUI::Font& font, - int x, int y, int w, int h); + int x, int y, int w, int h, + const StringList& actions, EventMode mode); ~EventMappingWidget(); bool handleKeyDown(int ascii, int keycode, int modifiers); @@ -78,6 +79,10 @@ class EventMappingWidget : public Widget, public CommandSender void drawKeyMapping(); private: + // Since this widget can be used for different collections of events, + // we need to specify exactly which group of events we are remapping + EventMode myEventMode; + // Indicates the event that is currently selected int myActionSelected; diff --git a/stella/src/gui/InputDialog.cxx b/stella/src/gui/InputDialog.cxx index a4e1f76f2..802a19f9c 100644 --- a/stella/src/gui/InputDialog.cxx +++ b/stella/src/gui/InputDialog.cxx @@ -13,9 +13,12 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: InputDialog.cxx,v 1.14 2006-05-04 17:45:25 stephena Exp $ +// $Id: InputDialog.cxx,v 1.15 2006-05-05 18:00:51 stephena Exp $ //============================================================================ +// FIXME - this whole dialog should be a dialog of buttons instead of +// a tabwidget. It would make things sooo much easier. + #include "OSystem.hxx" #include "Widget.hxx" #include "Array.hxx" @@ -49,15 +52,27 @@ InputDialog::InputDialog(OSystem* osystem, DialogContainer* parent, myTab = new TabWidget(this, font, xpos, ypos, _w - 2*xpos, _h - 24 - 2*ypos); addTabWidget(myTab); - // 1) Event mapper - tabID = myTab->addTab("Event Mapping"); - myEventMapper = new EventMappingWidget(myTab, font, 2, 2, - myTab->getWidth(), - myTab->getHeight() - ypos); - myTab->setParentWidget(tabID, myEventMapper); - addToFocusList(myEventMapper->getFocusList(), tabID); + // 1) Event mapper for emulation actions + tabID = myTab->addTab("Emul. Events"); + const StringList& eactions = instance()->eventHandler().getEmulationActions(); + myEmulEventMapper = new EventMappingWidget(myTab, font, 2, 2, + myTab->getWidth(), + myTab->getHeight() - ypos, + eactions, kEmulationMode); + myTab->setParentWidget(tabID, myEmulEventMapper); + addToFocusList(myEmulEventMapper->getFocusList(), tabID); - // 2) Virtual device support + // 2) Event mapper for menu actions + tabID = myTab->addTab("Menu Events"); + const StringList& mactions = instance()->eventHandler().getMenuActions(); + myMenuEventMapper = new EventMappingWidget(myTab, font, 2, 2, + myTab->getWidth(), + myTab->getHeight() - ypos, + mactions, kMenuMode); + myTab->setParentWidget(tabID, myMenuEventMapper); + addToFocusList(myMenuEventMapper->getFocusList(), tabID); + + // 3) Virtual device support addVDeviceTab(font); // Finalize the tabs, and activate the first tab @@ -93,7 +108,7 @@ void InputDialog::addVDeviceTab(const GUI::Font& font) WidgetArray wid; // Virtual device/ports - tabID = myTab->addTab("Virtual Devices"); + tabID = myTab->addTab("Virtual Devs"); // Stelladaptor mappings xpos = 5; ypos = 5; @@ -194,7 +209,8 @@ void InputDialog::addVDeviceTab(const GUI::Font& font) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void InputDialog::loadConfig() { - myEventMapper->loadConfig(); + myEmulEventMapper->loadConfig(); + myMenuEventMapper->loadConfig(); // Left & right ports const string& sa1 = instance()->settings().getString("sa1"); @@ -247,9 +263,11 @@ void InputDialog::saveConfig() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void InputDialog::handleKeyDown(int ascii, int keycode, int modifiers) { - // Remap key events in remap mode, otherwise pass to listwidget - if(myEventMapper->remapMode()) - myEventMapper->handleKeyDown(ascii, keycode, modifiers); + // Remap key events in remap mode, otherwise pass to parent dialog + if(myEmulEventMapper->remapMode()) + myEmulEventMapper->handleKeyDown(ascii, keycode, modifiers); + else if(myMenuEventMapper->remapMode()) + myMenuEventMapper->handleKeyDown(ascii, keycode, modifiers); else Dialog::handleKeyDown(ascii, keycode, modifiers); } @@ -257,9 +275,11 @@ void InputDialog::handleKeyDown(int ascii, int keycode, int modifiers) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void InputDialog::handleJoyDown(int stick, int button) { - // Remap joystick buttons in remap mode, otherwise pass to listwidget - if(myEventMapper->remapMode()) - myEventMapper->handleJoyDown(stick, button); + // Remap joystick buttons in remap mode, otherwise pass to parent dialog + if(myEmulEventMapper->remapMode()) + myEmulEventMapper->handleJoyDown(stick, button); + else if(myMenuEventMapper->remapMode()) + myMenuEventMapper->handleJoyDown(stick, button); else Dialog::handleJoyDown(stick, button); } @@ -267,9 +287,11 @@ void InputDialog::handleJoyDown(int stick, int button) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void InputDialog::handleJoyAxis(int stick, int axis, int value) { - // Remap joystick axis in remap mode, otherwise pass to listwidget - if(myEventMapper->remapMode()) - myEventMapper->handleJoyAxis(stick, axis, value); + // Remap joystick axis in remap mode, otherwise pass to parent dialog + if(myEmulEventMapper->remapMode()) + myEmulEventMapper->handleJoyAxis(stick, axis, value); + else if(myMenuEventMapper->remapMode()) + myMenuEventMapper->handleJoyAxis(stick, axis, value); else Dialog::handleJoyAxis(stick, axis, value); } @@ -277,9 +299,11 @@ void InputDialog::handleJoyAxis(int stick, int axis, int value) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool InputDialog::handleJoyHat(int stick, int hat, int value) { - // Remap joystick hat in remap mode, otherwise pass to listwidget - if(myEventMapper->remapMode()) - return myEventMapper->handleJoyHat(stick, hat, value); + // Remap joystick hat in remap mode, otherwise pass to parent dialog + if(myEmulEventMapper->remapMode()) + return myEmulEventMapper->handleJoyHat(stick, hat, value); + else if(myMenuEventMapper->remapMode()) + return myMenuEventMapper->handleJoyHat(stick, hat, value); else return Dialog::handleJoyHat(stick, hat, value); } diff --git a/stella/src/gui/InputDialog.hxx b/stella/src/gui/InputDialog.hxx index 9a7718cdb..3de81d75e 100644 --- a/stella/src/gui/InputDialog.hxx +++ b/stella/src/gui/InputDialog.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: InputDialog.hxx,v 1.8 2006-04-05 12:28:39 stephena Exp $ +// $Id: InputDialog.hxx,v 1.9 2006-05-05 18:00:51 stephena Exp $ //============================================================================ #ifndef INPUT_DIALOG_HXX @@ -54,7 +54,8 @@ class InputDialog : public Dialog private: TabWidget* myTab; - EventMappingWidget* myEventMapper; + EventMappingWidget* myEmulEventMapper; + EventMappingWidget* myMenuEventMapper; PopUpWidget* myLeftPort; PopUpWidget* myRightPort; @@ -65,8 +66,6 @@ class InputDialog : public Dialog StaticTextWidget* myPaddleThresholdLabel; SliderWidget* myPaddleSpeed[4]; StaticTextWidget* myPaddleLabel[4]; - - CheckBoxWidget* myJoyMouse; }; #endif diff --git a/stella/src/gui/ListWidget.cxx b/stella/src/gui/ListWidget.cxx index 6131157e9..66b6ed7c0 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.42 2006-05-04 17:45:25 stephena Exp $ +// $Id: ListWidget.cxx,v 1.43 2006-05-05 18:00:51 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -67,7 +67,8 @@ ListWidget::~ListWidget() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void ListWidget::setSelected(int item) { - assert(item >= -2 && item < (int)_list.size()); + if(item < -1 || item >= (int)_list.size()) + return; if(isEnabled()) { @@ -85,7 +86,8 @@ void ListWidget::setSelected(int item) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void ListWidget::setHighlighted(int item) { - assert(item >= -1 && item < (int)_list.size()); + if(item < -1 || item >= (int)_list.size()) + return; if(isEnabled()) { @@ -463,7 +465,6 @@ void ListWidget::endEditMode() void ListWidget::abortEditMode() { // Undo any changes made - assert(_selectedItem >= 0); _editMode = false; // Reset to normal data entry diff --git a/stella/src/gui/PopUpWidget.cxx b/stella/src/gui/PopUpWidget.cxx index 37e4898a0..f9db99257 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.25 2006-05-04 17:45:25 stephena Exp $ +// $Id: PopUpWidget.cxx,v 1.26 2006-05-05 18:00:51 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -141,12 +141,8 @@ void PopUpDialog::handleKeyDown(int ascii, int keycode, int modifiers) cancelSelection(); break; default: - { - Event::Type e = instance()->eventHandler().eventForKey(ascii, - kMenuOverlay); - handleEvent(e); + handleEvent(instance()->eventHandler().eventForKey(ascii, kMenuMode)); break; - } } }