Disabled toggling of the collision bits in TIA tab, since the

required infrastructure won't be complete for the next release.
The checkboxes are now read-only, so the collision bits can
still be seen (but not changed).

Refactored ToggleBitWidget into a new ToggleWidget class.  Added
new classes ToggleBitWidget and TogglePixelWidget, which derive
from ToggleWidget.  ToggleBitWidget works as before.
TogglePixelWidget works much the same as ToggleBitWidget, but
instead of drawing text, it fills a block with color.  Also,
it doesn't support change-tracking.

Modified grP0 and grP1 TIA registers in TIA tab to be
TogglePixelWidgets.  Now when these registers change, you
can see line by line how the graphics are drawn.  Thanks to
Brian for the advice; I had to add this because it's just
too cool :)


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@728 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2005-08-19 15:05:09 +00:00
parent b18c3809cb
commit 4274028040
11 changed files with 469 additions and 259 deletions

View File

@ -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();

View File

@ -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]);

View File

@ -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;

View File

@ -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;

View File

@ -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

View File

@ -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);
}
}
}

View File

@ -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

View File

@ -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;
}
}

View File

@ -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

View File

@ -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);

View File

@ -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 \