Added ability to change debug colors from "Video Settings".

Moved ColorWidget from src/debugger/gui to src/gui, since it needs to be
compiled even when the debugger is disabled.

Minor code refactoring.
This commit is contained in:
Stephen Anthony 2017-07-13 18:40:42 -02:30
parent d9f52599dc
commit 626ff450d9
8 changed files with 188 additions and 43 deletions

View File

@ -14,7 +14,6 @@ MODULE_OBJS := \
src/debugger/gui/TiaInfoWidget.o \
src/debugger/gui/TiaOutputWidget.o \
src/debugger/gui/TiaZoomWidget.o \
src/debugger/gui/ColorWidget.o \
src/debugger/gui/DataGridOpsWidget.o \
src/debugger/gui/DataGridWidget.o \
src/debugger/gui/DebuggerDialog.o \

View File

@ -88,7 +88,6 @@ TIA::TIA(Console& console, Sound& sound, Settings& settings)
}
);
setFixedColorPalette(mySettings.getString("tia.dbgcolors"));
myTIAPinsDriven = mySettings.getBool("tiadriven");
myBackground.setTIA(this);
@ -145,9 +144,12 @@ void TIA::reset()
mySound.reset();
myDelayQueue.reset();
myFrameManager.reset();
toggleFixedColors(0); // Turn off debug colours
frameReset(); // Recalculate the size of the display
// Must be done last, after all other items have reset
enableFixedColors(false);
setFixedColorPalette(mySettings.getString("tia.dbgcolors"));
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -860,12 +862,8 @@ bool TIA::toggleCollisions()
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool TIA::toggleFixedColors(uInt8 mode)
bool TIA::enableFixedColors(bool enable)
{
// If mode is 0 or 1, use it as a boolean (off or on)
// Otherwise, flip the state
bool on = (mode == 0 || mode == 1) ? bool(mode) : myColorHBlank == 0;
int layout = myFrameManager.layout() == FrameLayout::pal ? 1 : 0;
myMissile0.setDebugColor(myFixedColorPalette[layout][FixedObject::M0]);
myMissile1.setDebugColor(myFixedColorPalette[layout][FixedObject::M1]);
@ -875,21 +873,26 @@ bool TIA::toggleFixedColors(uInt8 mode)
myPlayfield.setDebugColor(myFixedColorPalette[layout][FixedObject::PF]);
myBackground.setDebugColor(FixedColor::BK_GREY);
myMissile0.enableDebugColors(on);
myMissile1.enableDebugColors(on);
myPlayer0.enableDebugColors(on);
myPlayer1.enableDebugColors(on);
myBall.enableDebugColors(on);
myPlayfield.enableDebugColors(on);
myBackground.enableDebugColors(on);
myColorHBlank = on ? FixedColor::HBLANK_WHITE : 0x00;
myMissile0.enableDebugColors(enable);
myMissile1.enableDebugColors(enable);
myPlayer0.enableDebugColors(enable);
myPlayer1.enableDebugColors(enable);
myBall.enableDebugColors(enable);
myPlayfield.enableDebugColors(enable);
myBackground.enableDebugColors(enable);
myColorHBlank = enable ? FixedColor::HBLANK_WHITE : 0x00;
return on;
return enable;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void TIA::setFixedColorPalette(const string& colors)
bool TIA::setFixedColorPalette(const string& colors)
{
string s = colors;
sort(s.begin(), s.end());
if(s != "bgopry")
return false;
for(int i = 0; i < 6; ++i)
{
switch(colors[i])
@ -920,6 +923,12 @@ void TIA::setFixedColorPalette(const string& colors)
break;
}
}
// If already in fixed debug colours mode, update the current palette
if(usingFixedColors())
enableFixedColors(true);
return true;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -60,6 +60,25 @@ class TIA : public Device
shuffleBL = 0xF2
};
enum FixedColor {
NTSC_RED = 0x30,
NTSC_ORANGE = 0x38,
NTSC_YELLOW = 0x1c,
NTSC_GREEN = 0xc4,
NTSC_BLUE = 0x9e,
NTSC_PURPLE = 0x66,
PAL_RED = 0x62,
PAL_ORANGE = 0x4a,
PAL_YELLOW = 0x2e,
PAL_GREEN = 0x34,
PAL_BLUE = 0xbc,
PAL_PURPLE = 0xa6,
BK_GREY = 0x0a,
HBLANK_WHITE = 0x0e
};
public:
friend class TIADebug;
friend class RiotDebug;
@ -275,12 +294,12 @@ class TIA : public Device
/**
Enables/disable/toggle/query 'fixed debug colors' mode.
@param mode 1/0 indicates on/off, otherwise flip from
its current state
@param enable Whether to enable fixed debug colors mode
@return Whether the mode was enabled or disabled
*/
bool toggleFixedColors(uInt8 mode = 2);
bool enableFixedColors(bool enable);
bool toggleFixedColors() { return enableFixedColors(!usingFixedColors()); }
bool usingFixedColors() const { return myColorHBlank != 0x00; }
/**
@ -291,8 +310,10 @@ class TIA : public Device
@param colors Each character in the 6-char string represents the
first letter of the color to use for
P0/M0/P1/M1/PF/BL, respectively.
@return True if colors were changed successfully, else false
*/
void setFixedColorPalette(const string& colors);
bool setFixedColorPalette(const string& colors);
/**
Enable/disable/query state of 'undriven/floating TIA pins'.
@ -384,24 +405,6 @@ class TIA : public Device
enum HState {blank, frame};
enum Priority {pfp, score, normal};
enum FixedColor {
NTSC_RED = 0x30,
NTSC_ORANGE = 0x38,
NTSC_YELLOW = 0x1c,
NTSC_GREEN = 0xc4,
NTSC_BLUE = 0x9e,
NTSC_PURPLE = 0x66,
PAL_RED = 0x62,
PAL_ORANGE = 0x4a,
PAL_YELLOW = 0x2e,
PAL_GREEN = 0x34,
PAL_BLUE = 0xbc,
PAL_PURPLE = 0xa6,
BK_GREY = 0x0a,
HBLANK_WHITE = 0x0e
};
enum FixedObject { P0, M0, P1, M1, PF, BL };
FixedColor myFixedColorPalette[2][6];

View File

@ -30,7 +30,8 @@ ColorWidget::ColorWidget(GuiObject* boss, const GUI::Font& font,
: Widget(boss, font, x, y, w, h),
CommandSender(boss),
_color(0),
_cmd(cmd)
_cmd(cmd),
_crossGrid(false)
{
_flags = WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS;
}

View File

@ -23,6 +23,7 @@
#include "Dialog.hxx"
#include "Menu.hxx"
#include "OSystem.hxx"
#include "ColorWidget.hxx"
#include "EditTextWidget.hxx"
#include "PopUpWidget.hxx"
#include "Console.hxx"
@ -310,6 +311,42 @@ VideoDialog::VideoDialog(OSystem& osystem, DialogContainer& parent,
tabID = myTab->addTab(" Debug Colors ");
xpos = ypos = 8;
items.clear();
VarList::push_back(items, "Red", "r");
VarList::push_back(items, "Orange", "o");
VarList::push_back(items, "Yellow", "y");
VarList::push_back(items, "Green", "g");
VarList::push_back(items, "Blue", "b");
VarList::push_back(items, "Purple", "p");
static constexpr int dbg_cmds[6] = {
kP0ColourChangedCmd, kM0ColourChangedCmd, kP1ColourChangedCmd,
kM1ColourChangedCmd, kPFColourChangedCmd, kBLColourChangedCmd
};
auto createDebugColourWidgets = [&](int idx, const string& desc) {
int x = xpos;
myDbgColour[idx] = new PopUpWidget(myTab, font, x, ypos,
pwidth, lineHeight, items, desc, lwidth, dbg_cmds[idx]);
wid.push_back(myDbgColour[idx]);
x += myDbgColour[idx]->getWidth() + 10;
myDbgColourSwatch[idx] = new ColorWidget(myTab, font, x, ypos,
uInt32(2*lineHeight), lineHeight);
ypos += lineHeight + 8;
};
createDebugColourWidgets(0, "Player 0 ");
createDebugColourWidgets(1, "Missile 0 ");
createDebugColourWidgets(2, "Player 1 ");
createDebugColourWidgets(3, "Missile 1 ");
createDebugColourWidgets(4, "Playfield ");
createDebugColourWidgets(5, "Ball ");
// Add message concerning usage
ypos = myTab->getHeight() - 5 - fontHeight - infofont.getFontHeight() - 10;
new StaticTextWidget(myTab, infofont, 10, ypos,
font.getStringWidth("(*) Colors must be different for each object"), fontHeight,
"(*) Colors must be different for each object", kTextAlignLeft);
// Activate the first tab
myTab->setActiveTab(0);
@ -412,6 +449,9 @@ void VideoDialog::loadConfig()
myTVScanIntenseLabel->setLabel(instance().settings().getString("tv.scanlines"));
myTVScanInterpolate->setState(instance().settings().getBool("tv.scaninter"));
// Debug colours
handleDebugColours(instance().settings().getString("tia.dbgcolors"));
myTab->loadConfig();
}
@ -510,6 +550,14 @@ void VideoDialog::saveConfig()
instance().settings().setValue("tv.scanlines", myTVScanIntenseLabel->getLabel());
instance().settings().setValue("tv.scaninter", myTVScanInterpolate->getState());
// Debug colours
string dbgcolors;
for(int i = 0; i < 6; ++i)
dbgcolors += myDbgColour[i]->getSelectedTag().toString();
if(instance().hasConsole() &&
instance().console().tia().setFixedColorPalette(dbgcolors))
instance().settings().setValue("tia.dbgcolors", dbgcolors);
// Finally, issue a complete framebuffer re-initialization
instance().createFrameBuffer();
}
@ -566,6 +614,12 @@ void VideoDialog::setDefaults()
loadTVAdjustables(NTSCFilter::PRESET_CUSTOM);
break;
}
case 2: // Debug colours
{
handleDebugColours("roygpb");
break;
}
}
_dirty = true;
@ -619,6 +673,51 @@ void VideoDialog::handleTVJitterChange(bool enable)
myTVJitterRecLabel->setEnabled(enable);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void VideoDialog::handleDebugColours(int idx, int color)
{
if(idx < 0 || idx > 5)
return;
static constexpr int dbg_color[2][6] = {
{ TIA::FixedColor::NTSC_RED,
TIA::FixedColor::NTSC_ORANGE,
TIA::FixedColor::NTSC_YELLOW,
TIA::FixedColor::NTSC_GREEN,
TIA::FixedColor::NTSC_BLUE,
TIA::FixedColor::NTSC_PURPLE
},
{ TIA::FixedColor::PAL_RED,
TIA::FixedColor::PAL_ORANGE,
TIA::FixedColor::PAL_YELLOW,
TIA::FixedColor::PAL_GREEN,
TIA::FixedColor::PAL_BLUE,
TIA::FixedColor::PAL_PURPLE
}
};
int mode = instance().console().tia().frameLayout() == FrameLayout::ntsc ? 0 : 1;
myDbgColourSwatch[idx]->setColor(dbg_color[mode][color]);
myDbgColour[idx]->setSelectedIndex(color);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void VideoDialog::handleDebugColours(const string& colors)
{
for(int i = 0; i < 6; ++i)
{
switch(colors[i])
{
case 'r': handleDebugColours(i, 0); break;
case 'o': handleDebugColours(i, 1); break;
case 'y': handleDebugColours(i, 2); break;
case 'g': handleDebugColours(i, 3); break;
case 'b': handleDebugColours(i, 4); break;
case 'p': handleDebugColours(i, 5); break;
default: break;
}
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void VideoDialog::loadTVAdjustables(NTSCFilter::Preset preset)
{
@ -719,6 +818,25 @@ void VideoDialog::handleCommand(CommandSender* sender, int cmd,
case kCloneCustomCmd: loadTVAdjustables(NTSCFilter::PRESET_CUSTOM);
break;
case kP0ColourChangedCmd:
handleDebugColours(0, myDbgColour[0]->getSelected());
break;
case kM0ColourChangedCmd:
handleDebugColours(1, myDbgColour[1]->getSelected());
break;
case kP1ColourChangedCmd:
handleDebugColours(2, myDbgColour[2]->getSelected());
break;
case kM1ColourChangedCmd:
handleDebugColours(3, myDbgColour[3]->getSelected());
break;
case kPFColourChangedCmd:
handleDebugColours(4, myDbgColour[4]->getSelected());
break;
case kBLColourChangedCmd:
handleDebugColours(5, myDbgColour[5]->getSelected());
break;
default:
Dialog::handleCommand(sender, cmd, data, 0);
break;

View File

@ -21,6 +21,7 @@
class CommandSender;
class CheckboxWidget;
class DialogContainer;
class ColorWidget;
class PopUpWidget;
class SliderWidget;
class StaticTextWidget;
@ -45,6 +46,8 @@ class VideoDialog : public Dialog
void handleFullscreenChange(bool enable);
void handleTVModeChange(NTSCFilter::Preset);
void handleTVJitterChange(bool enable);
void handleDebugColours(int cmd, int color);
void handleDebugColours(const string& colors);
void loadTVAdjustables(NTSCFilter::Preset preset);
void handleCommand(CommandSender* sender, int cmd, int data, int id) override;
@ -118,6 +121,10 @@ class VideoDialog : public Dialog
ButtonWidget* myCloneBad;
ButtonWidget* myCloneCustom;
// Debug colours selection
PopUpWidget* myDbgColour[6];
ColorWidget* myDbgColourSwatch[6];
enum {
kNAspectRatioChanged = 'VDan',
kPAspectRatioChanged = 'VDap',
@ -145,7 +152,14 @@ class VideoDialog : public Dialog
kCloneSvideoCmd = 'CLsv',
kCloneRGBCmd = 'CLrb',
kCloneBadCmd = 'CLbd',
kCloneCustomCmd = 'CLcu'
kCloneCustomCmd = 'CLcu',
kP0ColourChangedCmd = 'GOp0',
kM0ColourChangedCmd = 'GOm0',
kP1ColourChangedCmd = 'GOp1',
kM1ColourChangedCmd = 'GOm1',
kPFColourChangedCmd = 'GOpf',
kBLColourChangedCmd = 'GObl'
};
private:

View File

@ -4,6 +4,7 @@ MODULE_OBJS := \
src/gui/AboutDialog.o \
src/gui/AudioDialog.o \
src/gui/BrowserDialog.o \
src/gui/ColorWidget.o \
src/gui/ComboDialog.o \
src/gui/CommandDialog.o \
src/gui/CommandMenu.o \
@ -47,5 +48,5 @@ MODULE_OBJS := \
MODULE_DIRS += \
src/gui
# Include common rules
# Include common rules
include $(srcdir)/common.rules