added some minor refinements of RamWidget and CpuWidget

This commit is contained in:
thrust26 2020-10-12 14:12:57 +02:00
parent f4fdebb425
commit 71ed38855c
4 changed files with 64 additions and 21 deletions

View File

@ -43,7 +43,7 @@ CpuWidget::CpuWidget(GuiObject* boss, const GUI::Font& lfont, const GUI::Font& n
// Create a 1x1 grid with label for the PC register
xpos = x; ypos = y; lwidth = 4 * fontWidth;
new StaticTextWidget(boss, lfont, xpos, ypos+1, lwidth-2, fontHeight,
new StaticTextWidget(boss, lfont, xpos, ypos + 2, lwidth-2, fontHeight,
"PC ", TextAlign::Left);
myPCGrid =
new DataGridWidget(boss, nfont, xpos + lwidth, ypos, 1, 1, 4, 16, Common::Base::Fmt::_16);
@ -66,14 +66,14 @@ CpuWidget::CpuWidget(GuiObject* boss, const GUI::Font& lfont, const GUI::Font& n
addFocusWidget(myCpuGrid);
// Create a 1x4 grid with decimal and binary values for the other CPU registers
xpos = x + lwidth + myPCGrid->getWidth() + 10;
xpos = myPCGrid->getRight() + 10;
myCpuGridDecValue =
new DataGridWidget(boss, nfont, xpos, ypos, 1, 4, 3, 8, Common::Base::Fmt::_10);
myCpuGridDecValue->setTarget(this);
myCpuGridDecValue->setID(kCpuRegDecID);
addFocusWidget(myCpuGridDecValue);
xpos += myCpuGridDecValue->getWidth() + 5;
xpos = myCpuGridDecValue->getRight() + fontWidth * 2;
myCpuGridBinValue =
new DataGridWidget(boss, nfont, xpos, ypos, 1, 4, 8, 8, Common::Base::Fmt::_2);
myCpuGridBinValue->setTarget(this);
@ -104,14 +104,25 @@ CpuWidget::CpuWidget(GuiObject* boss, const GUI::Font& lfont, const GUI::Font& n
const std::array<string, 4> labels = { "SP ", "A ", "X ", "Y " };
for(int row = 0; row < 4; ++row)
{
new StaticTextWidget(boss, lfont, xpos, ypos + row*lineHeight + 1,
new StaticTextWidget(boss, lfont, xpos, ypos + row*lineHeight + 2,
lwidth-2, fontHeight,
labels[row], TextAlign::Left);
}
// Add prefixes for decimal and binary values
for(int row = 0; row < 4; ++row)
{
new StaticTextWidget(boss, lfont, myCpuGridDecValue->getLeft() - fontWidth,
ypos + row * lineHeight + 2,
lwidth - 2, fontHeight, "#");
new StaticTextWidget(boss, lfont, myCpuGridBinValue->getLeft() - fontWidth,
ypos + row * lineHeight + 2,
lwidth - 2, fontHeight, "%");
}
// Create a bitfield widget for changing the processor status
xpos = x; ypos += 4*lineHeight + 2;
new StaticTextWidget(boss, lfont, xpos, ypos+1, lwidth-2, fontHeight,
new StaticTextWidget(boss, lfont, xpos, ypos + 2, lwidth-2, fontHeight,
"PS ", TextAlign::Left);
myPSRegister = new ToggleBitWidget(boss, nfont, xpos+lwidth, ypos, 8, 1);
myPSRegister->setTarget(this);

View File

@ -69,6 +69,7 @@ class DataGridWidget : public EditableWidget
int getSelectedAddr() const { return _addrList[_selectedItem]; }
int getSelectedValue() const { return _valueList[_selectedItem]; }
bool getSelectedChanged() const { return _changedList[_selectedItem]; }
void setRange(int lower, int upper);

View File

@ -37,14 +37,16 @@ RamWidget::RamWidget(GuiObject* boss, const GUI::Font& lfont, const GUI::Font& n
myFontWidth(lfont.getMaxCharWidth()),
myFontHeight(lfont.getFontHeight()),
myLineHeight(lfont.getLineHeight()),
myButtonHeight(myLineHeight + 4),
myButtonHeight(myLineHeight * 1.25),
myRamSize(ramsize),
myNumRows(numrows),
myPageSize(pagesize)
{
const int bwidth = lfont.getStringWidth("Compare " + ELLIPSIS),
bheight = myLineHeight + 2;
const int VGAP = 4;
//const int VGAP = 4;
const int VGAP = myFontHeight / 4;
StaticTextWidget* s;
WidgetArray wid;
int ypos = y + myLineHeight;
@ -54,7 +56,7 @@ RamWidget::RamWidget(GuiObject* boss, const GUI::Font& lfont, const GUI::Font& n
myRamGrid = new DataGridWidget(_boss, _nfont, xpos, ypos,
16, myNumRows, 2, 8, Common::Base::Fmt::_16, true);
myRamGrid->setTarget(this);
myRamGrid->setID(kRamHexID);
myRamGrid->setID(kRamGridID);
addFocusWidget(myRamGrid);
// Create actions buttons to the left of the RAM grid
@ -119,35 +121,44 @@ RamWidget::RamWidget(GuiObject* boss, const GUI::Font& lfont, const GUI::Font& n
// For smaller grids, make sure RAM cell detail fields are below the RESET button
row = myNumRows < 8 ? 9 : myNumRows + 1;
ypos += row * myLineHeight;
ypos += (row - 1) * myLineHeight + VGAP * 2;
// We need to define these widgets from right to left since the leftmost
// one resizes as much as possible
// Add Binary display of selected RAM cell
xpos = x + w - 11*myFontWidth - 22;
new StaticTextWidget(boss, lfont, xpos, ypos, "Bin");
myBinValue = new DataGridWidget(boss, nfont, xpos + 3*myFontWidth + 5, ypos-2,
xpos = x + w - 9.6 * myFontWidth - 9;
s = new StaticTextWidget(boss, lfont, xpos, ypos, "%");
myBinValue = new DataGridWidget(boss, nfont, s->getRight() + myFontWidth * 0.1, ypos-2,
1, 1, 8, 8, Common::Base::Fmt::_2);
myBinValue->setTarget(this);
myBinValue->setID(kRamBinID);
// Add Decimal display of selected RAM cell
xpos -= 7*myFontWidth + 5 + 20;
new StaticTextWidget(boss, lfont, xpos, ypos, "Dec");
myDecValue = new DataGridWidget(boss, nfont, xpos + 3*myFontWidth + 5, ypos-2,
xpos -= 6.5 * myFontWidth;
s = new StaticTextWidget(boss, lfont, xpos, ypos, "#");
myDecValue = new DataGridWidget(boss, nfont, s->getRight(), ypos-2,
1, 1, 3, 8, Common::Base::Fmt::_10);
myDecValue->setTarget(this);
myDecValue->setID(kRamDecID);
// Add Hex display of selected RAM cell
xpos -= 4.5 * myFontWidth;
//s = new StaticTextWidget(boss, lfont, xpos, ypos, "$");
myHexValue = new DataGridWidget(boss, nfont, xpos, ypos - 2,
1, 1, 2, 8, Common::Base::Fmt::_16);
myHexValue->setTarget(this);
myHexValue->setID(kRamHexID);
addFocusWidget(myHexValue);
addFocusWidget(myDecValue);
addFocusWidget(myBinValue);
// Add Label of selected RAM cell
int xpos_r = xpos - 20;
int xpos_r = xpos - myFontWidth * 1.5;
xpos = x;
new StaticTextWidget(boss, lfont, xpos, ypos, "Label");
xpos += 5*myFontWidth + 5;
s = new StaticTextWidget(boss, lfont, xpos, ypos, "Label");
xpos = s->getRight() + myFontWidth / 2;
myLabel = new EditTextWidget(boss, nfont, xpos, ypos-2, xpos_r-xpos,
myLineHeight);
myLabel->setEditable(false, true);
@ -184,11 +195,16 @@ void RamWidget::handleCommand(CommandSender* sender, int cmd, int data, int id)
{
switch(id)
{
case kRamHexID:
case kRamGridID:
addr = myRamGrid->getSelectedAddr();
value = myRamGrid->getSelectedValue();
break;
case kRamHexID:
addr = myRamGrid->getSelectedAddr();
value = myHexValue->getSelectedValue();
break;
case kRamDecID:
addr = myRamGrid->getSelectedAddr();
value = myDecValue->getSelectedValue();
@ -210,6 +226,7 @@ void RamWidget::handleCommand(CommandSender* sender, int cmd, int data, int id)
myUndoValue = oldval;
myRamGrid->setValueInternal(addr - myCurrentRamBank*myPageSize, value, true);
myHexValue->setValueInternal(0, value, true);
myDecValue->setValueInternal(0, value, true);
myBinValue->setValueInternal(0, value, true);
@ -222,10 +239,12 @@ void RamWidget::handleCommand(CommandSender* sender, int cmd, int data, int id)
{
addr = myRamGrid->getSelectedAddr();
value = myRamGrid->getSelectedValue();
bool changed = myRamGrid->getSelectedChanged();
myLabel->setText(getLabel(addr));
myDecValue->setValueInternal(0, value, false);
myBinValue->setValueInternal(0, value, false);
myHexValue->setValueInternal(0, value, changed);
myDecValue->setValueInternal(0, value, changed);
myBinValue->setValueInternal(0, value, changed);
break;
}
@ -288,6 +307,7 @@ void RamWidget::handleCommand(CommandSender* sender, int cmd, int data, int id)
void RamWidget::setOpsWidget(DataGridOpsWidget* w)
{
myRamGrid->setOpsWidget(w);
myHexValue->setOpsWidget(w);
myBinValue->setOpsWidget(w);
myDecValue->setOpsWidget(w);
}
@ -296,6 +316,13 @@ void RamWidget::setOpsWidget(DataGridOpsWidget* w)
void RamWidget::loadConfig()
{
fillGrid(true);
int value = myRamGrid->getSelectedValue();
bool changed = myRamGrid->getSelectedChanged();
myHexValue->setValueInternal(0, value, changed);
myDecValue->setValueInternal(0, value, changed);
myBinValue->setValueInternal(0, value, changed);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -79,8 +79,10 @@ class RamWidget : public Widget, public CommandSender
kRestartCmd = 'RWrs',
kSValEntered = 'RWsv',
kCValEntered = 'RWcv',
kRamGridID,
kRamHexID,
kRamDecID,
kRamSignID,
kRamBinID
};
@ -96,7 +98,9 @@ class RamWidget : public Widget, public CommandSender
std::array<StaticTextWidget*, 16> myRamLabels{nullptr};
DataGridWidget* myRamGrid{nullptr};
DataGridWidget* myHexValue{nullptr};
DataGridWidget* myDecValue{nullptr};
DataGridWidget* mySignValue{nullptr};
DataGridWidget* myBinValue{nullptr};
EditTextWidget* myLabel{nullptr};