Further work on the RamWidget. It now shows row labels in hex, but I

may not be able to add column labels because we need the vertical space
for buttons.  Also, the ByteGrid is now drawn correctly.

Added initial infrastructure for a tab to reload itself, either on command
or when a new tab is selected.


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@515 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2005-06-16 22:18:02 +00:00
parent 028f95768d
commit f1617b1db8
9 changed files with 73 additions and 77 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: ByteGridWidget.cxx,v 1.1 2005-06-16 18:40:17 stephena Exp $
// $Id: ByteGridWidget.cxx,v 1.2 2005-06-16 22:18:02 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -29,13 +29,12 @@
#include "ByteGridWidget.hxx"
enum {
kColWidth = 2 * 6 + 4 // FIXME - get this info from _font
kColWidth = 2 * 6 + 8
};
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ByteGridWidget::ByteGridWidget(GuiObject* boss, int x, int y, int w, int h,
int cols, int rows)
: EditableWidget(boss, x, y, w, h),
ByteGridWidget::ByteGridWidget(GuiObject* boss, int x, int y, int cols, int rows)
: EditableWidget(boss, x, y, kColWidth*cols + 1, kLineHeight*rows + 1),
CommandSender(boss),
_rows(rows),
_cols(cols),
@ -43,12 +42,14 @@ ByteGridWidget::ByteGridWidget(GuiObject* boss, int x, int y, int w, int h,
_currentCol(0),
_selectedItem(0)
{
// This widget always uses a monospace font
setFont(instance()->consoleFont());
_flags = WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS |
WIDGET_TAB_NAVIGATE;
_type = kByteGridWidget;
_editMode = false;
_entriesPerPage = _rows;//(_h - 2) / kLineHeight;
_currentPos = 0;
_currentKeyDown = 0;
@ -85,6 +86,8 @@ void ByteGridWidget::setList(const ByteAddrList& alist, const ByteValueList& vli
char temp[10];
for(unsigned int i = 0; i < (unsigned int)size; ++i)
{
sprintf(temp, "%.4x:", _addrList[i]);
_addrStringList.push_back(temp);
sprintf(temp, "%.2x", _valueList[i]);
_valueStringList.push_back(temp);
}
@ -309,19 +312,20 @@ void ByteGridWidget::drawWidget(bool hilite)
int row, col, deltax;
string buffer;
// Draw the internal grid
// int linewidth =
// Draw the internal grid and labels
int linewidth = _cols * kColWidth;
for (row = 0; row <= _rows; row++)
fb.hLine(_x, _y + (row * kLineHeight), _x + _w - 1, kColor);
fb.hLine(_x, _y + (row * kLineHeight), _x + linewidth, kColor);
int lineheight = _rows * kLineHeight;
for (col = 0; col <= _cols; col++)
fb.vLine(_x + (col * kColWidth), _y, _y + _h - 1, kColor);
fb.vLine(_x + (col * kColWidth), _y, _y + lineheight, kColor);
// Draw the list items
for (row = 0; row < _rows; row++)
{
for (col = 0; col < _cols; col++)
{
int x = _x + 2 + (col * kColWidth);
int x = _x + 4 + (col * kColWidth);
int y = _y + 2 + (row * kLineHeight);
int pos = row*_cols + col;
@ -329,19 +333,17 @@ void ByteGridWidget::drawWidget(bool hilite)
if (_currentRow == row && _currentCol == col)
{
if (_hasFocus && !_editMode)
fb.fillRect(x - 2, y - 2, kColWidth+1, kLineHeight+1, kTextColorHi);
fb.fillRect(x - 4, y - 2, kColWidth+1, kLineHeight+1, kTextColorHi);
else
fb.frameRect(x - 2, y - 2, kColWidth+1, kLineHeight+1, kTextColorHi);
fb.frameRect(x - 4, y - 2, kColWidth+1, kLineHeight+1, kTextColorHi);
}
// GUI::Rect r(getEditRect());
if (_selectedItem == pos && _editMode)
{
buffer = _editString;
adjustOffset();
deltax = -_editScrollOffset;
// fb.drawString(_font, buffer, _x + r.left, y, r.width(), kTextColor,
fb.drawString(_font, buffer, x, y, kColWidth, kTextColor,
kTextAlignLeft, deltax, false);
}
@ -354,38 +356,6 @@ void ByteGridWidget::drawWidget(bool hilite)
}
}
/*
for (i = 0, pos = _currentPos; i < _entriesPerPage && pos < len; i++, pos++)
{
const int y = _y + 2 + kLineHeight * i;
GUI::Rect r(getEditRect());
// 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 - 2, kLineHeight, kTextColorHi);
}
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 = _valueStringList[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)
drawCaret();
@ -396,11 +366,11 @@ GUI::Rect ByteGridWidget::getEditRect() const
{
GUI::Rect r(1, 0, kColWidth, kLineHeight);
const int rowoffset = _currentRow * kLineHeight;
const int coloffset = _currentCol * kColWidth;
const int coloffset = _currentCol * kColWidth + 4;
r.top += rowoffset;
r.bottom += rowoffset;
r.left += coloffset;
r.right += coloffset - 1;
r.right += coloffset - 5;
return r;
}

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: ByteGridWidget.hxx,v 1.1 2005-06-16 18:40:17 stephena Exp $
// $Id: ByteGridWidget.hxx,v 1.2 2005-06-16 22:18:02 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -45,8 +45,7 @@ enum {
class ByteGridWidget : public EditableWidget, public CommandSender
{
public:
ByteGridWidget(GuiObject* boss, int x, int y, int w, int h,
int cols, int rows);
ByteGridWidget(GuiObject* boss, int x, int y, int cols, int rows);
virtual ~ByteGridWidget();
void setList(const ByteAddrList& alist, const ByteValueList& vlist);

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: DebuggerDialog.cxx,v 1.10 2005-06-16 18:40:17 stephena Exp $
// $Id: DebuggerDialog.cxx,v 1.11 2005-06-16 22:18:02 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -41,7 +41,7 @@ DebuggerDialog::DebuggerDialog(OSystem* osystem, DialogContainer* parent,
// 1) The Prompt/console tab
myTab->addTab("Prompt");
PromptWidget* prompt = new PromptWidget(myTab, 2, 2, _w - vBorder, _h - 25);
myTab->setActiveWidget(0, prompt);
myTab->setParentWidget(0, prompt, prompt);
// 2) The CPU tab
myTab->addTab("CPU");
@ -50,8 +50,7 @@ DebuggerDialog::DebuggerDialog(OSystem* osystem, DialogContainer* parent,
// 3) The RAM tab
myTab->addTab("RAM");
RamWidget* ram = new RamWidget(myTab, 2, 2, _w - vBorder, _h - 25);
myTab->setActiveWidget(2, ram->activeWidget());
myTab->setParentWidget(2, ram, ram->activeWidget());
// 4) The ROM tab
myTab->addTab("ROM");
@ -65,7 +64,7 @@ DebuggerDialog::DebuggerDialog(OSystem* osystem, DialogContainer* parent,
myTab->addTab("Cheat");
CheatWidget* cheat = new CheatWidget(myTab, 2, 2,
_w - vBorder, _h - 25);
myTab->setActiveWidget(5, cheat->activeWidget());
myTab->setParentWidget(5, cheat, cheat->activeWidget());
// Set active tab to prompt
myTab->setActiveTab(0);

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: RamWidget.cxx,v 1.1 2005-06-16 18:40:17 stephena Exp $
// $Id: RamWidget.cxx,v 1.2 2005-06-16 22:18:02 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -44,12 +44,21 @@ RamWidget::RamWidget(GuiObject* boss, int x, int y, int w, int h)
: Widget(boss, x, y, w, h),
CommandSender(boss)
{
int gwidth = 16 * 2 * instance()->consoleFont().getMaxCharWidth() + 20;
int gheight = 8 * instance()->consoleFont().getFontHeight() + 20;
int xpos = 10;
int ypos = 20;
int lwidth = 30;
// Create a 16x8 grid (16 x 8 = 128 RAM bytes)
myRamGrid = new ByteGridWidget(boss, 10, 10, gwidth, gheight, 16, 8);
myRamGrid->setFont(instance()->consoleFont());
// Create a 16x8 grid (16 x 8 = 128 RAM bytes) with labels
for(int col = 0; col < 8; ++col)
{
StaticTextWidget* t = new StaticTextWidget(boss, xpos, ypos + col*kLineHeight + 2,
lwidth, kLineHeight,
Debugger::to_hex_16(col*16 + kRamStart) + string(":"),
kTextAlignLeft);
t->setFont(instance()->consoleFont());
}
myRamGrid = new ByteGridWidget(boss, xpos+lwidth + 5, ypos, 16, 8);
myRamGrid->setTarget(this);
myActiveWidget = myRamGrid;
@ -145,6 +154,14 @@ void RamWidget::handleCommand(CommandSender* sender, int cmd, int data)
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void RamWidget::loadConfig()
{
cerr << "RamWidget::loadConfig()\n";
fillGrid();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void RamWidget::fillGrid()
{
@ -153,7 +170,7 @@ void RamWidget::fillGrid()
for(unsigned int i = 0; i < kRamSize; i++)
{
alist.push_back(i);
alist.push_back(kRamStart + i);
vlist.push_back(instance()->debugger().readRAM(i));
}

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: RamWidget.hxx,v 1.1 2005-06-16 18:40:17 stephena Exp $
// $Id: RamWidget.hxx,v 1.2 2005-06-16 22:18:02 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -41,6 +41,7 @@ class RamWidget : public Widget, public CommandSender
Widget* activeWidget() { return myActiveWidget; }
void handleCommand(CommandSender* sender, int cmd, int data);
void loadConfig();
public:
void fillGrid();

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: TabWidget.cxx,v 1.7 2005-06-16 00:56:00 stephena Exp $
// $Id: TabWidget.cxx,v 1.8 2005-06-16 22:18:02 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -56,6 +56,7 @@ TabWidget::~TabWidget()
{
delete _tabs[i].firstWidget;
_tabs[i].firstWidget = 0;
// _tabs[i].parentWidget is deleted elsewhere
// _tabs[i].activeWidget is deleted elsewhere
}
_tabs.clear();
@ -74,6 +75,7 @@ int TabWidget::addTab(const string& title)
Tab newTab;
newTab.title = title;
newTab.firstWidget = NULL;
newTab.parentWidget = NULL;
newTab.activeWidget = NULL;
_tabs.push_back(newTab);
@ -108,6 +110,10 @@ void TabWidget::setActiveTab(int tabID)
_activeTab = tabID;
_firstWidget = _tabs[tabID].firstWidget;
// Reload the settings for the parent widget in this tab
if(_tabs[tabID].parentWidget)
_tabs[tabID].parentWidget->loadConfig();
// If a widget has been activated elsewhere and it belongs to the
// current view, use it. Otherwise use the default.
if(_activeWidget && isWidgetInChain(_firstWidget, _activeWidget))
@ -167,11 +173,12 @@ void TabWidget::cycleWidget(int direction)
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void TabWidget::setActiveWidget(int tabID, Widget* widID)
void TabWidget::setParentWidget(int tabID, Widget* parent, Widget* active)
{
assert(0 <= tabID && tabID < (int)_tabs.size());
_tabs[tabID].activeWidget = widID;
widID->receivedFocus();
_tabs[tabID].parentWidget = parent;
_tabs[tabID].activeWidget = active;
_tabs[tabID].activeWidget->receivedFocus();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

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: TabWidget.hxx,v 1.5 2005-06-16 00:56:00 stephena Exp $
// $Id: TabWidget.hxx,v 1.6 2005-06-16 22:18:02 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -33,6 +33,7 @@ class TabWidget : public Widget, public CommandSender
struct Tab {
string title;
Widget* firstWidget;
Widget* parentWidget;
Widget* activeWidget;
};
typedef GUI::Array<Tab> TabList;
@ -58,7 +59,7 @@ class TabWidget : public Widget, public CommandSender
void cycleWidget(int direction);
// setActiveTab changes the value of _firstWidget. This means Widgets added afterwards
// will be added to the active tab.
void setActiveWidget(int tabID, Widget* widID);
void setParentWidget(int tabID, Widget* parent, Widget* active);
virtual void handleMouseDown(int x, int y, int button, int clickCount);
virtual bool handleKeyDown(int ascii, int keycode, int modifiers);

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.cxx,v 1.17 2005-06-16 18:40:17 stephena Exp $
// $Id: Widget.cxx,v 1.18 2005-06-16 22:18:02 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -87,12 +87,12 @@ void Widget::draw()
// Now perform the actual widget draw
drawWidget((_flags & WIDGET_HILITED) ? true : false);
/* FIXME
// Indicate if this is the currently active widget
// by drawing a box around it.
if((_activeWidget == this) && (_flags & WIDGET_TAB_NAVIGATE))
fb.frameRect(_x, _y, _w, _h, kTextColorEm); // FIXME - maybe chose a better color
*/
fb.frameRect(_x-1, _y-1, _w+2, _h+2, kTextColorEm); // FIXME - maybe chose a better color
// Restore x/y
if (_flags & WIDGET_BORDER) {
_x -= 4;

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.18 2005-06-16 18:40:17 stephena Exp $
// $Id: Widget.hxx,v 1.19 2005-06-16 22:18:02 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -67,7 +67,7 @@ enum {
This is the base class for all widgets.
@author Stephen Anthony
@version $Id: Widget.hxx,v 1.18 2005-06-16 18:40:17 stephena Exp $
@version $Id: Widget.hxx,v 1.19 2005-06-16 22:18:02 stephena Exp $
*/
class Widget : public GuiObject
{
@ -113,6 +113,8 @@ class Widget : public GuiObject
void setFont(const GUI::Font& font) { _font = (GUI::Font*) &font; }
const GUI::Font* font() { return _font; }
virtual void loadConfig() {}
protected:
virtual void drawWidget(bool hilite) {}