Add function to check for default colours

This commit is contained in:
G.K.MacGregor
2020-12-18 22:07:27 +00:00
parent 19be00f4fe
commit df22fda290
3 changed files with 39 additions and 33 deletions

View File

@@ -82,7 +82,7 @@ void LevelOnePage::clearPage()
m_leftSidePanelDisplayed = m_rightSidePanelDisplayed = false;
m_sidePanelStatusL25 = true;
m_sidePanelColumns = 0;
std::copy(defaultCLUT, defaultCLUT+32, m_CLUT);
std::copy(m_defaultCLUT, m_defaultCLUT+32, m_CLUT);
// If clearPage() is called outside constructor, we need to implement localEnhance.clear();
}
@@ -91,9 +91,8 @@ bool LevelOnePage::isEmpty() const
if (!localEnhance.isEmpty())
return false;
for (int i=0; i<32; i++)
if (m_CLUT[i] != defaultCLUT[i])
return false;
if (!isPaletteDefault(0, 31))
return false;
for (int r=0; r<25; r++)
for (int c=0; c<40; c++)
@@ -348,17 +347,10 @@ bool LevelOnePage::packetNeeded(int packetNumber, int designationCode) const
if (designationCode == 0) {
if (m_leftSidePanelDisplayed || m_rightSidePanelDisplayed || m_defaultScreenColour !=0 || m_defaultRowColour !=0 || m_blackBackgroundSubst || m_colourTableRemap !=0 || m_defaultCharSet != 0 || m_secondCharSet != 0xf)
return true;
for (int i=16; i<32; i++)
if (m_CLUT[i] != defaultCLUT[i])
return true;
return false;
}
if (designationCode == 4) {
for (int i=0; i<16; i++)
if (m_CLUT[i] != defaultCLUT[i])
return true;
return false;
return !isPaletteDefault(16, 31);
}
if (designationCode == 4)
return !isPaletteDefault(0,15);
}
return PageBase::packetNeeded(packetNumber, designationCode);
@@ -428,12 +420,32 @@ void LevelOnePage::setBlackBackgroundSubst(bool newBlackBackgroundSubst) { m_bla
int LevelOnePage::CLUT(int index, int renderLevel) const
{
if (renderLevel == 2)
return index>=16 ? m_CLUT[index] : defaultCLUT[index];
return index>=16 ? m_CLUT[index] : m_defaultCLUT[index];
else
return renderLevel==3 ? m_CLUT[index] : defaultCLUT[index];
return renderLevel==3 ? m_CLUT[index] : m_defaultCLUT[index];
}
void LevelOnePage::setCLUT(int index, int newColour)
{
if (index == 8)
return;
m_CLUT[index] = newColour;
}
bool LevelOnePage::isPaletteDefault(int colour) const
{
return m_CLUT[colour] == m_defaultCLUT[colour];
}
bool LevelOnePage::isPaletteDefault(int fromColour, int toColour) const
{
for (int i=fromColour; i<toColour; i++)
if (m_CLUT[i] != m_defaultCLUT[i])
return false;
return true;
}
void LevelOnePage::setCLUT(int index, int newColour) { m_CLUT[index] = newColour; }
void LevelOnePage::setLeftSidePanelDisplayed(bool newLeftSidePanelDisplayed) { m_leftSidePanelDisplayed = newLeftSidePanelDisplayed; }
void LevelOnePage::setRightSidePanelDisplayed(bool newRightSidePanelDisplayed) { m_rightSidePanelDisplayed = newRightSidePanelDisplayed; }
void LevelOnePage::setSidePanelColumns(int newSidePanelColumns) { m_sidePanelColumns = newSidePanelColumns; }

View File

@@ -81,6 +81,8 @@ public:
void setBlackBackgroundSubst(bool);
int CLUT(int index, int renderLevel=3) const;
void setCLUT(int, int);
bool isPaletteDefault(int) const;
bool isPaletteDefault(int, int) const;
bool leftSidePanelDisplayed() const { return m_leftSidePanelDisplayed; }
void setLeftSidePanelDisplayed(bool);
bool rightSidePanelDisplayed() const { return m_rightSidePanelDisplayed; }
@@ -125,11 +127,11 @@ private:
X26Triplet m_paddingX26Triplet;
const int defaultCLUT[32] = {
0x000, 0xf00, 0x0f0, 0xff0, 0x00f, 0xf0f, 0x0ff, 0xfff,
0x000, 0x700, 0x070, 0x770, 0x007, 0x707, 0x077, 0x777,
0xf05, 0xf70, 0x0f7, 0xffb, 0x0ca, 0x500, 0x652, 0xc77,
0x333, 0xf77, 0x7f7, 0xff7, 0x77f, 0xf7f, 0x7ff, 0xddd
const int m_defaultCLUT[32] = {
0x000, 0xf00, 0x0f0, 0xff0, 0x00f, 0xf0f, 0x0ff, 0xfff,
0x000, 0x700, 0x070, 0x770, 0x007, 0x707, 0x077, 0x777,
0xf05, 0xf70, 0x0f7, 0xffb, 0x0ca, 0x500, 0x652, 0xc77,
0x333, 0xf77, 0x7f7, 0xff7, 0x77f, 0xf7f, 0x7ff, 0xddd
};
};

View File

@@ -75,18 +75,10 @@ void PaletteDockWidget::updateColourButton(int colourIndex)
QString qss = QString("background-color: #%1; color: #%2%2%2; border: none").arg(colourString).arg(blackOrWhite);
m_colourButton[colourIndex]->setStyleSheet(qss);
if (m_parentMainWidget->document()->currentSubPage()->CLUT(colourIndex) == m_parentMainWidget->document()->currentSubPage()->CLUT(colourIndex, 0)) {
if (m_parentMainWidget->document()->currentSubPage()->isPaletteDefault(colourIndex))
// Default colour was set, disable Reset button if all colours in row are default as well
for (int i=colourIndex & 0x18; i<(colourIndex & 0x18)+8; i++) {
if (i == 8)
continue;
if (m_parentMainWidget->document()->currentSubPage()->CLUT(i) != m_parentMainWidget->document()->currentSubPage()->CLUT(i, 0)) {
m_resetButton[colourIndex>>3]->setEnabled(true);
return;
}
}
m_resetButton[colourIndex>>3]->setEnabled(false);
} else
m_resetButton[colourIndex>>3]->setEnabled(!m_parentMainWidget->document()->currentSubPage()->isPaletteDefault(colourIndex & 0x18, colourIndex | 0x07));
else
m_resetButton[colourIndex>>3]->setEnabled(true);
}