diff --git a/stella/src/debugger/CpuWidget.cxx b/stella/src/debugger/CpuWidget.cxx index a3e369fa4..0da615a85 100644 --- a/stella/src/debugger/CpuWidget.cxx +++ b/stella/src/debugger/CpuWidget.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: CpuWidget.cxx,v 1.7 2005-08-12 17:12:43 stephena Exp $ +// $Id: CpuWidget.cxx,v 1.8 2005-08-19 15:05:09 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -178,7 +178,7 @@ void CpuWidget::handleCommand(CommandSender* sender, int cmd, int data, int id) } break; - case kTBItemDataChangedCmd: + case kTWItemDataChangedCmd: { bool state = myPSRegister->getSelectedState(); diff --git a/stella/src/debugger/TiaWidget.cxx b/stella/src/debugger/TiaWidget.cxx index 406035761..ed5de544e 100644 --- a/stella/src/debugger/TiaWidget.cxx +++ b/stella/src/debugger/TiaWidget.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: TiaWidget.cxx,v 1.9 2005-08-18 18:18:59 stephena Exp $ +// $Id: TiaWidget.cxx,v 1.10 2005-08-19 15:05:09 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -29,6 +29,7 @@ #include "DataGridWidget.hxx" #include "ColorWidget.hxx" #include "ToggleBitWidget.hxx" +#include "TogglePixelWidget.hxx" #include "TiaWidget.hxx" // ID's for the various widgets @@ -213,7 +214,8 @@ TiaWidget::TiaWidget(GuiObject* boss, int x, int y, int w, int h) myCollision[idx]->setFont(font); myCollision[idx]->setTarget(this); myCollision[idx]->setID(idx); - addFocusWidget(myCollision[idx]); + myCollision[idx]->setEditable(false); +// addFocusWidget(myCollision[idx]); collX += myCollision[idx]->getWidth() + 10; idx++; @@ -288,8 +290,7 @@ TiaWidget::TiaWidget(GuiObject* boss, int x, int y, int w, int h) "P0: GR:", kTextAlignLeft); t->setFont(font); xpos += 7*fontWidth + 5; - myGRP0 = new ToggleBitWidget(boss, font, xpos, ypos, 8, 1); - myGRP0->setList(off, on); + myGRP0 = new TogglePixelWidget(boss, xpos, ypos+2, 8, 1); myGRP0->setTarget(this); myGRP0->setID(kGRP0ID); addFocusWidget(myGRP0); @@ -336,7 +337,7 @@ TiaWidget::TiaWidget(GuiObject* boss, int x, int y, int w, int h) addFocusWidget(myDelP0); // NUSIZ0 (player portion) - xpos = 10 + lwidth; ypos += myGRP0->getHeight() + 2; + xpos = 10 + lwidth; ypos += myGRP0->getHeight() + 5; t = new StaticTextWidget(boss, xpos, ypos+2, 8*fontWidth, fontHeight, "NusizP0:", kTextAlignLeft); @@ -363,8 +364,7 @@ TiaWidget::TiaWidget(GuiObject* boss, int x, int y, int w, int h) "P1: GR:", kTextAlignLeft); t->setFont(font); xpos += 7*fontWidth + 5; - myGRP1 = new ToggleBitWidget(boss, font, xpos, ypos, 8, 1); - myGRP1->setList(off, on); + myGRP1 = new TogglePixelWidget(boss, xpos, ypos+2, 8, 1); myGRP1->setTarget(this); myGRP1->setID(kGRP1ID); addFocusWidget(myGRP1); @@ -411,7 +411,7 @@ TiaWidget::TiaWidget(GuiObject* boss, int x, int y, int w, int h) addFocusWidget(myDelP1); // NUSIZ1 (player portion) - xpos = 10 + lwidth; ypos += myGRP1->getHeight() + 2; + xpos = 10 + lwidth; ypos += myGRP1->getHeight() + 5; t = new StaticTextWidget(boss, xpos, ypos+2, 8*fontWidth, fontHeight, "NusizP1:", kTextAlignLeft); @@ -753,7 +753,7 @@ void TiaWidget::handleCommand(CommandSender* sender, int cmd, int data, int id) } break; - case kTBItemDataChangedCmd: + case kTWItemDataChangedCmd: switch(id) { case kGRP0ID: @@ -890,7 +890,7 @@ void TiaWidget::fillGrid() { IntArray alist; IntArray vlist; - BoolArray orig, changed, grNew, grOld; + BoolArray blist, changed, grNew, grOld; Debugger& dbg = instance()->debugger(); TIADebug& tia = dbg.tiaDebug(); @@ -945,15 +945,10 @@ void TiaWidget::fillGrid() // P0 register info //////////////////////////// // grP0 - grNew.clear(); grOld.clear(); - convertCharToBool(grNew, state.gr[P0]); - convertCharToBool(grOld, oldstate.gr[P0]); - - changed.clear(); - for(unsigned int i = 0; i < 8; ++i) - changed.push_back(grNew[i] != grOld[i]); - - myGRP0->setState(grNew, changed); + blist.clear(); + convertCharToBool(blist, state.gr[P0]); + myGRP0->setState(blist); + myGRP0->setColor((OverlayColor)state.coluRegs[0]); // posP0 myPosP0->setList(0, state.pos[P0], state.pos[P0] != oldstate.pos[P0]); @@ -973,15 +968,10 @@ void TiaWidget::fillGrid() // P1 register info //////////////////////////// // grP1 - grNew.clear(); grOld.clear(); - convertCharToBool(grNew, state.gr[P1]); - convertCharToBool(grOld, oldstate.gr[P1]); - - changed.clear(); - for(unsigned int i = 0; i < 8; ++i) - changed.push_back(grNew[i] != grOld[i]); - - myGRP1->setState(grNew, changed); + blist.clear(); + convertCharToBool(blist, state.gr[P1]); + myGRP1->setState(blist); + myGRP1->setColor((OverlayColor)state.coluRegs[1]); // posP1 myPosP1->setList(0, state.pos[P1], state.pos[P1] != oldstate.pos[P1]); diff --git a/stella/src/debugger/TiaWidget.hxx b/stella/src/debugger/TiaWidget.hxx index b9007d85e..f36fefbbd 100644 --- a/stella/src/debugger/TiaWidget.hxx +++ b/stella/src/debugger/TiaWidget.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: TiaWidget.hxx,v 1.7 2005-08-18 18:18:59 stephena Exp $ +// $Id: TiaWidget.hxx,v 1.8 2005-08-19 15:05:09 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -27,6 +27,7 @@ class ButtonWidget; class DataGridWidget; class StaticTextWidget; class ToggleBitWidget; +class TogglePixelWidget; class EditTextWidget; class ColorWidget; @@ -62,8 +63,8 @@ class TiaWidget : public Widget, public CommandSender ColorWidget* myCOLUPFColor; ColorWidget* myCOLUBKColor; - ToggleBitWidget* myGRP0; - ToggleBitWidget* myGRP1; + TogglePixelWidget* myGRP0; + TogglePixelWidget* myGRP1; DataGridWidget* myPosP0; DataGridWidget* myPosP1; diff --git a/stella/src/gui/ToggleBitWidget.cxx b/stella/src/gui/ToggleBitWidget.cxx index 4a38e11f9..5f18b1f46 100644 --- a/stella/src/gui/ToggleBitWidget.cxx +++ b/stella/src/gui/ToggleBitWidget.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: ToggleBitWidget.cxx,v 1.9 2005-08-17 21:38:34 stephena Exp $ +// $Id: ToggleBitWidget.cxx,v 1.10 2005-08-19 15:05:09 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -24,29 +24,22 @@ #include "Dialog.hxx" #include "Debugger.hxx" #include "FrameBuffer.hxx" +#include "StringList.hxx" #include "ToggleBitWidget.hxx" // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ToggleBitWidget::ToggleBitWidget(GuiObject* boss, const GUI::Font& font, int x, int y, int cols, int rows, int colchars) - : Widget(boss, x, y, 16, 16), - CommandSender(boss), - _rows(rows), - _cols(cols), - _currentRow(0), - _currentCol(0), - _rowHeight(font.getLineHeight()), - _colWidth(colchars * font.getMaxCharWidth() + 8), - _selectedItem(0) + : ToggleWidget(boss, x, y, cols, rows) { - // Calculate real dimensions - _w = cols*(colchars * font.getMaxCharWidth() + 8) + 1; - _h = font.getLineHeight()*rows + 1; - setFont(font); - _flags = WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS; - _type = kToggleBitWidget; + _rowHeight = font.getLineHeight(); + _colWidth = colchars * font.getMaxCharWidth() + 8; + + // Calculate real dimensions + _w = _colWidth * cols + 1; + _h = _rowHeight * rows + 1; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -77,180 +70,9 @@ void ToggleBitWidget::setState(const BoolArray& state, const BoolArray& changed) setDirty(); draw(); } -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void ToggleBitWidget::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)_stateList.size() - 1) - newSelectedItem = -1; - - if (_selectedItem != newSelectedItem) - { - _selectedItem = newSelectedItem; - _currentRow = _selectedItem / _cols; - _currentCol = _selectedItem - (_currentRow * _cols); - setDirty(); draw(); - } -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void ToggleBitWidget::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))) - { - _stateList[_selectedItem] = !_stateList[_selectedItem]; - _changedList[_selectedItem] = !_changedList[_selectedItem]; - sendCommand(kTBItemDataChangedCmd, _selectedItem, _id); - setDirty(); draw(); - } -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -int ToggleBitWidget::findItem(int x, int y) -{ - int row = (y - 1) / _rowHeight; - if(row >= _rows) row = _rows - 1; - - int col = x / _colWidth; - if(col >= _cols) col = _cols - 1; - - return row * _cols + col; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool ToggleBitWidget::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, toggle = false; - - switch (keycode) - { - case '\n': // enter/return - case '\r': - if (_currentRow >= 0 && _currentCol >= 0) - { - dirty = true; - toggle = true; - } - break; - - case 256+17: // up arrow - if (_currentRow > 0) - { - _currentRow--; - dirty = true; - } - break; - - case 256+18: // down arrow - if (_currentRow < (int) _rows - 1) - { - _currentRow++; - dirty = true; - } - break; - - case 256+20: // left arrow - if (_currentCol > 0) - { - _currentCol--; - dirty = true; - } - break; - - case 256+19: // right arrow - if (_currentCol < (int) _cols - 1) - { - _currentCol++; - dirty = true; - } - break; - - case 256+24: // pageup - if (_currentRow > 0) - { - _currentRow = 0; - dirty = true; - } - break; - - case 256+25: // pagedown - if (_currentRow < (int) _rows - 1) - { - _currentRow = _rows - 1; - dirty = true; - } - break; - - case 256+22: // home - if (_currentCol > 0) - { - _currentCol = 0; - dirty = true; - } - break; - - case 256+23: // end - if (_currentCol < (int) _cols - 1) - { - _currentCol = _cols - 1; - dirty = true; - } - break; - - default: - handled = false; - } - - if (dirty) - { - _selectedItem = _currentRow*_cols + _currentCol; - - if(toggle) - { - _stateList[_selectedItem] = !_stateList[_selectedItem]; - _changedList[_selectedItem] = !_changedList[_selectedItem]; - sendCommand(kTBItemDataChangedCmd, _selectedItem, _id); - } - - setDirty(); draw(); - } - - return handled; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void ToggleBitWidget::handleCommand(CommandSender* sender, int cmd, - int data, int id) -{ - switch (cmd) - { - case kSetPositionCmd: - if (_selectedItem != (int)data) - { - _selectedItem = data; - setDirty(); draw(); - } - break; - } -} - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void ToggleBitWidget::drawWidget(bool hilite) { -//cerr << "ToggleBitWidget::drawWidget\n"; FrameBuffer& fb = instance()->frameBuffer(); int row, col; string buffer; diff --git a/stella/src/gui/ToggleBitWidget.hxx b/stella/src/gui/ToggleBitWidget.hxx index 4fadb3d99..4fc48186e 100644 --- a/stella/src/gui/ToggleBitWidget.hxx +++ b/stella/src/gui/ToggleBitWidget.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: ToggleBitWidget.hxx,v 1.5 2005-08-16 18:34:12 stephena Exp $ +// $Id: ToggleBitWidget.hxx,v 1.6 2005-08-19 15:05:09 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -22,21 +22,12 @@ #ifndef TOGGLE_BIT_WIDGET_HXX #define TOGGLE_BIT_WIDGET_HXX -#include "GuiObject.hxx" -#include "Widget.hxx" -#include "Command.hxx" -#include "Debugger.hxx" -#include "StringList.hxx" -#include "Array.hxx" +class StringList; -// Some special commands -enum { - kTBItemDataChangedCmd = 'TBch', - kTBSelectionChangedCmd = 'TBsc' -}; +#include "ToggleWidget.hxx" /* ToggleBitWidget */ -class ToggleBitWidget : public Widget, public CommandSender +class ToggleBitWidget : public ToggleWidget { public: ToggleBitWidget(GuiObject* boss, const GUI::Font& font, @@ -46,35 +37,12 @@ class ToggleBitWidget : public Widget, public CommandSender void setList(const StringList& off, const StringList& on); void setState(const BoolArray& state, const BoolArray& changed); - const BoolArray& getState() { return _stateList; } - bool getSelectedState() const { return _stateList[_selectedItem]; } - - virtual void handleMouseDown(int x, int y, int button, int clickCount); - virtual void handleMouseUp(int x, int y, int button, int clickCount); - virtual bool handleKeyDown(int ascii, int keycode, int modifiers); - virtual void handleCommand(CommandSender* sender, int cmd, int data, int id); - - virtual bool wantsFocus() { return true; } - - int colWidth() { return _colWidth; } - protected: void drawWidget(bool hilite); - int findItem(int x, int y); protected: - int _rows; - int _cols; - int _currentRow; - int _currentCol; - int _rowHeight; - int _colWidth; - int _selectedItem; - StringList _offList; StringList _onList; - BoolArray _stateList; - BoolArray _changedList; }; #endif diff --git a/stella/src/gui/TogglePixelWidget.cxx b/stella/src/gui/TogglePixelWidget.cxx new file mode 100644 index 000000000..788284b60 --- /dev/null +++ b/stella/src/gui/TogglePixelWidget.cxx @@ -0,0 +1,95 @@ +//============================================================================ +// +// SSSS tt lll lll +// SS SS tt ll ll +// SS tttttt eeee ll ll aaaa +// SSSS tt ee ee ll ll aa +// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" +// SS SS tt ee ll ll aa aa +// SSSS ttt eeeee llll llll aaaaa +// +// Copyright (c) 1995-2005 by Bradford W. Mott and the Stella team +// +// See the file "license" for information on usage and redistribution of +// this file, and for a DISCLAIMER OF ALL WARRANTIES. +// +// $Id: TogglePixelWidget.cxx,v 1.1 2005-08-19 15:05:09 stephena Exp $ +// +// Based on code from ScummVM - Scumm Interpreter +// Copyright (C) 2002-2004 The ScummVM project +//============================================================================ + +#include "OSystem.hxx" +#include "Widget.hxx" +#include "Dialog.hxx" +#include "Debugger.hxx" +#include "FrameBuffer.hxx" +#include "TogglePixelWidget.hxx" + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +TogglePixelWidget::TogglePixelWidget(GuiObject* boss, int x, int y, + int cols, int rows) + : ToggleWidget(boss, x, y, cols, rows), + _pixelColor(kBGColor) +{ + _rowHeight = _font->getLineHeight(); + _colWidth = 15; + + // Calculate real dimensions + _w = _colWidth * cols + 1; + _h = _rowHeight * rows + 1; + + // Changed state isn't used, but we still need to fill it + while((int)_changedList.size() < rows * cols) + _changedList.push_back(false); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +TogglePixelWidget::~TogglePixelWidget() +{ +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void TogglePixelWidget::setState(const BoolArray& state) +{ + _stateList.clear(); + _stateList = state; + + setDirty(); draw(); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void TogglePixelWidget::drawWidget(bool hilite) +{ + FrameBuffer& fb = instance()->frameBuffer(); + int row, col; + + // Draw the internal grid and labels + int linewidth = _cols * _colWidth; + for (row = 0; row <= _rows; row++) + fb.hLine(_x, _y + (row * _rowHeight), _x + linewidth, kColor); + int lineheight = _rows * _rowHeight; + for (col = 0; col <= _cols; col++) + fb.vLine(_x + (col * _colWidth), _y, _y + lineheight, kColor); + + // Draw the pixels + for (row = 0; row < _rows; row++) + { + for (col = 0; col < _cols; col++) + { + int x = _x + 4 + (col * _colWidth); + int y = _y + 2 + (row * _rowHeight); + int pos = row*_cols + col; + + // Draw the selected item inverted, on a highlighted background. + if (_currentRow == row && _currentCol == col && _hasFocus) + fb.fillRect(x - 4, y - 2, _colWidth+1, _rowHeight+1, kTextColorHi); + + // Either draw the pixel in given color, or erase (show background) + if(_stateList[pos]) + fb.fillRect(x - 3, y - 1, _colWidth-1, _rowHeight-1, _pixelColor); + else + fb.fillRect(x - 3, y - 1, _colWidth-1, _rowHeight-1, kBGColor); + } + } +} diff --git a/stella/src/gui/TogglePixelWidget.hxx b/stella/src/gui/TogglePixelWidget.hxx new file mode 100644 index 000000000..c70b89535 --- /dev/null +++ b/stella/src/gui/TogglePixelWidget.hxx @@ -0,0 +1,45 @@ +//============================================================================ +// +// SSSS tt lll lll +// SS SS tt ll ll +// SS tttttt eeee ll ll aaaa +// SSSS tt ee ee ll ll aa +// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" +// SS SS tt ee ll ll aa aa +// SSSS ttt eeeee llll llll aaaaa +// +// Copyright (c) 1995-2005 by Bradford W. Mott and the Stella team +// +// See the file "license" for information on usage and redistribution of +// this file, and for a DISCLAIMER OF ALL WARRANTIES. +// +// $Id: TogglePixelWidget.hxx,v 1.1 2005-08-19 15:05:09 stephena Exp $ +// +// Based on code from ScummVM - Scumm Interpreter +// Copyright (C) 2002-2004 The ScummVM project +//============================================================================ + +#ifndef TOGGLE_PIXEL_WIDGET_HXX +#define TOGGLE_PIXEL_WIDGET_HXX + +#include "FrameBuffer.hxx" +#include "ToggleWidget.hxx" + +/* TogglePixelWidget */ +class TogglePixelWidget : public ToggleWidget +{ + public: + TogglePixelWidget(GuiObject* boss, int x, int y, int cols, int rows); + virtual ~TogglePixelWidget(); + + void setColor(OverlayColor color) { _pixelColor = color; } + void setState(const BoolArray& state); + + protected: + void drawWidget(bool hilite); + + protected: + OverlayColor _pixelColor; +}; + +#endif diff --git a/stella/src/gui/ToggleWidget.cxx b/stella/src/gui/ToggleWidget.cxx new file mode 100644 index 000000000..aacef4374 --- /dev/null +++ b/stella/src/gui/ToggleWidget.cxx @@ -0,0 +1,213 @@ +//============================================================================ +// +// SSSS tt lll lll +// SS SS tt ll ll +// SS tttttt eeee ll ll aaaa +// SSSS tt ee ee ll ll aa +// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" +// SS SS tt ee ll ll aa aa +// SSSS ttt eeeee llll llll aaaaa +// +// Copyright (c) 1995-2005 by Bradford W. Mott and the Stella team +// +// See the file "license" for information on usage and redistribution of +// this file, and for a DISCLAIMER OF ALL WARRANTIES. +// +// $Id: ToggleWidget.cxx,v 1.1 2005-08-19 15:05:09 stephena Exp $ +// +// Based on code from ScummVM - Scumm Interpreter +// Copyright (C) 2002-2004 The ScummVM project +//============================================================================ + +#include "OSystem.hxx" +#include "Widget.hxx" +#include "ToggleWidget.hxx" + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +ToggleWidget::ToggleWidget(GuiObject* boss, int x, int y, int cols, int rows) + : Widget(boss, x, y, 16, 16), + CommandSender(boss), + _rows(rows), + _cols(cols), + _currentRow(0), + _currentCol(0), + _selectedItem(0) +{ + _flags = WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS; + _type = kToggleWidget; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +ToggleWidget::~ToggleWidget() +{ +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void ToggleWidget::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)_stateList.size() - 1) + newSelectedItem = -1; + + if (_selectedItem != newSelectedItem) + { + _selectedItem = newSelectedItem; + _currentRow = _selectedItem / _cols; + _currentCol = _selectedItem - (_currentRow * _cols); + setDirty(); draw(); + } +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void ToggleWidget::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))) + { + _stateList[_selectedItem] = !_stateList[_selectedItem]; + _changedList[_selectedItem] = !_changedList[_selectedItem]; + sendCommand(kTWItemDataChangedCmd, _selectedItem, _id); + setDirty(); draw(); + } +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +int ToggleWidget::findItem(int x, int y) +{ + int row = (y - 1) / _rowHeight; + if(row >= _rows) row = _rows - 1; + + int col = x / _colWidth; + if(col >= _cols) col = _cols - 1; + + return row * _cols + col; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool ToggleWidget::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, toggle = false; + + switch (keycode) + { + case '\n': // enter/return + case '\r': + if (_currentRow >= 0 && _currentCol >= 0) + { + dirty = true; + toggle = true; + } + break; + + case 256+17: // up arrow + if (_currentRow > 0) + { + _currentRow--; + dirty = true; + } + break; + + case 256+18: // down arrow + if (_currentRow < (int) _rows - 1) + { + _currentRow++; + dirty = true; + } + break; + + case 256+20: // left arrow + if (_currentCol > 0) + { + _currentCol--; + dirty = true; + } + break; + + case 256+19: // right arrow + if (_currentCol < (int) _cols - 1) + { + _currentCol++; + dirty = true; + } + break; + + case 256+24: // pageup + if (_currentRow > 0) + { + _currentRow = 0; + dirty = true; + } + break; + + case 256+25: // pagedown + if (_currentRow < (int) _rows - 1) + { + _currentRow = _rows - 1; + dirty = true; + } + break; + + case 256+22: // home + if (_currentCol > 0) + { + _currentCol = 0; + dirty = true; + } + break; + + case 256+23: // end + if (_currentCol < (int) _cols - 1) + { + _currentCol = _cols - 1; + dirty = true; + } + break; + + default: + handled = false; + } + + if (dirty) + { + _selectedItem = _currentRow*_cols + _currentCol; + + if(toggle) + { + _stateList[_selectedItem] = !_stateList[_selectedItem]; + _changedList[_selectedItem] = !_changedList[_selectedItem]; + sendCommand(kTWItemDataChangedCmd, _selectedItem, _id); + } + + setDirty(); draw(); + } + + return handled; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void ToggleWidget::handleCommand(CommandSender* sender, int cmd, + int data, int id) +{ + switch (cmd) + { + case kSetPositionCmd: + if (_selectedItem != (int)data) + { + _selectedItem = data; + setDirty(); draw(); + } + break; + } +} diff --git a/stella/src/gui/ToggleWidget.hxx b/stella/src/gui/ToggleWidget.hxx new file mode 100644 index 000000000..364eb7dc5 --- /dev/null +++ b/stella/src/gui/ToggleWidget.hxx @@ -0,0 +1,72 @@ +//============================================================================ +// +// SSSS tt lll lll +// SS SS tt ll ll +// SS tttttt eeee ll ll aaaa +// SSSS tt ee ee ll ll aa +// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" +// SS SS tt ee ll ll aa aa +// SSSS ttt eeeee llll llll aaaaa +// +// Copyright (c) 1995-2005 by Bradford W. Mott and the Stella team +// +// See the file "license" for information on usage and redistribution of +// this file, and for a DISCLAIMER OF ALL WARRANTIES. +// +// $Id: ToggleWidget.hxx,v 1.1 2005-08-19 15:05:09 stephena Exp $ +// +// Based on code from ScummVM - Scumm Interpreter +// Copyright (C) 2002-2004 The ScummVM project +//============================================================================ + +#ifndef TOGGLE_WIDGET_HXX +#define TOGGLE_WIDGET_HXX + +#include "GuiObject.hxx" +#include "Widget.hxx" +#include "Command.hxx" +#include "Array.hxx" + +// Some special commands +enum { + kTWItemDataChangedCmd = 'TWch', + kTWSelectionChangedCmd = 'TWsc' +}; + +/* ToggleWidget */ +class ToggleWidget : public Widget, public CommandSender +{ + public: + ToggleWidget(GuiObject* boss, int x, int y, int cols, int rows); + virtual ~ToggleWidget(); + + const BoolArray& getState() { return _stateList; } + bool getSelectedState() const { return _stateList[_selectedItem]; } + + virtual void handleMouseDown(int x, int y, int button, int clickCount); + virtual void handleMouseUp(int x, int y, int button, int clickCount); + virtual bool handleKeyDown(int ascii, int keycode, int modifiers); + virtual void handleCommand(CommandSender* sender, int cmd, int data, int id); + + virtual bool wantsFocus() { return true; } + + int colWidth() { return _colWidth; } + + protected: + void drawWidget(bool hilite) = 0; + int findItem(int x, int y); + + protected: + int _rows; + int _cols; + int _currentRow; + int _currentCol; + int _rowHeight; + int _colWidth; + int _selectedItem; + + BoolArray _stateList; + BoolArray _changedList; +}; + +#endif diff --git a/stella/src/gui/Widget.hxx b/stella/src/gui/Widget.hxx index 53064d6c1..b1cdc333f 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.29 2005-08-18 16:19:07 stephena Exp $ +// $Id: Widget.hxx,v 1.30 2005-08-19 15:05:09 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -58,7 +58,7 @@ enum { kTabWidget = 'TABW', kPromptWidget = 'PROM', kDataGridWidget = 'BGRI', - kToggleBitWidget = 'TGBT', + kToggleWidget = 'TOGL', kColorWidget = 'COLR' }; @@ -71,7 +71,7 @@ enum { This is the base class for all widgets. @author Stephen Anthony - @version $Id: Widget.hxx,v 1.29 2005-08-18 16:19:07 stephena Exp $ + @version $Id: Widget.hxx,v 1.30 2005-08-19 15:05:09 stephena Exp $ */ class Widget : public GuiObject { @@ -223,6 +223,8 @@ class CheckboxWidget : public ButtonWidget virtual void handleMouseLeft(int button) {} virtual bool handleKeyDown(int ascii, int keycode, int modifiers); + bool wantsFocus() { return _editable; }; + void setEditable(bool editable) { _editable = editable; } void setState(bool state); diff --git a/stella/src/gui/module.mk b/stella/src/gui/module.mk index e35740cc4..2f13f9742 100644 --- a/stella/src/gui/module.mk +++ b/stella/src/gui/module.mk @@ -30,7 +30,9 @@ MODULE_OBJS := \ src/gui/ProgressDialog.o \ src/gui/ScrollBarWidget.o \ src/gui/TabWidget.o \ + src/gui/ToggleWidget.o \ src/gui/ToggleBitWidget.o \ + src/gui/TogglePixelWidget.o \ src/gui/VideoDialog.o \ src/gui/Widget.o \