Add wxDCTextBgColourChanger and wxDCTextBgModeChanger helpers

These classes are similar to the existing wxDCTextColourChanger and
allow temporarily changing other wxDC attributes.

Closes https://github.com/wxWidgets/wxWidgets/pull/1298
This commit is contained in:
Vsevolod V Gromov
2019-04-17 12:39:03 +03:00
committed by Vadim Zeitlin
parent e41f219131
commit 3674bd1c1f
2 changed files with 184 additions and 1 deletions

View File

@@ -1405,6 +1405,78 @@ private:
wxDECLARE_NO_COPY_CLASS(wxDCTextColourChanger);
};
// ----------------------------------------------------------------------------
// helper class: you can use it to temporarily change the DC text background colour and
// restore it automatically when the object goes out of scope
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_CORE wxDCTextBgColourChanger
{
public:
wxDCTextBgColourChanger(wxDC& dc) : m_dc(dc) { }
wxDCTextBgColourChanger(wxDC& dc, const wxColour& col) : m_dc(dc)
{
Set(col);
}
~wxDCTextBgColourChanger()
{
if ( m_colBgOld.IsOk() )
m_dc.SetTextBackground(m_colBgOld);
}
void Set(const wxColour& col)
{
if ( !m_colBgOld.IsOk() )
m_colBgOld = m_dc.GetTextBackground();
m_dc.SetTextBackground(col);
}
private:
wxDC& m_dc;
wxColour m_colBgOld;
wxDECLARE_NO_COPY_CLASS(wxDCTextBgColourChanger);
};
// ----------------------------------------------------------------------------
// helper class: you can use it to temporarily change the DC text background mode and
// restore it automatically when the object goes out of scope
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_CORE wxDCTextBgModeChanger
{
public:
wxDCTextBgModeChanger(wxDC& dc) : m_dc(dc), m_modeOld(wxBRUSHSTYLE_INVALID) { }
wxDCTextBgModeChanger(wxDC& dc, int mode) : m_dc(dc)
{
Set(mode);
}
~wxDCTextBgModeChanger()
{
if ( m_modeOld != wxBRUSHSTYLE_INVALID )
m_dc.SetBackgroundMode(m_modeOld);
}
void Set(int mode)
{
if ( m_modeOld == wxBRUSHSTYLE_INVALID )
m_modeOld = m_dc.GetBackgroundMode();
m_dc.SetBackgroundMode(mode);
}
private:
wxDC& m_dc;
int m_modeOld;
wxDECLARE_NO_COPY_CLASS(wxDCTextBgModeChanger);
};
// ----------------------------------------------------------------------------
// helper class: you can use it to temporarily change the DC pen and
// restore it automatically when the object goes out of scope