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:
committed by
Vadim Zeitlin
parent
e41f219131
commit
3674bd1c1f
@@ -1405,6 +1405,78 @@ private:
|
|||||||
wxDECLARE_NO_COPY_CLASS(wxDCTextColourChanger);
|
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
|
// helper class: you can use it to temporarily change the DC pen and
|
||||||
// restore it automatically when the object goes out of scope
|
// restore it automatically when the object goes out of scope
|
||||||
|
@@ -1799,7 +1799,7 @@ public:
|
|||||||
@category{gdi}
|
@category{gdi}
|
||||||
|
|
||||||
@see wxDC::SetTextForeground(), wxDCFontChanger, wxDCPenChanger, wxDCBrushChanger,
|
@see wxDC::SetTextForeground(), wxDCFontChanger, wxDCPenChanger, wxDCBrushChanger,
|
||||||
wxDCClipper
|
wxDCClipper, wxDCTextBgColourChanger, wxDCBgModeChanger
|
||||||
*/
|
*/
|
||||||
class wxDCTextColourChanger
|
class wxDCTextColourChanger
|
||||||
{
|
{
|
||||||
@@ -1842,6 +1842,117 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
@class wxDCTextBgColourChanger
|
||||||
|
|
||||||
|
wxDCTextBgColourChanger is a small helper class for setting a background
|
||||||
|
text colour on a wxDC and unsetting it automatically in the destructor,
|
||||||
|
restoring the previous one.
|
||||||
|
|
||||||
|
@library{wxcore}
|
||||||
|
@category{gdi}
|
||||||
|
|
||||||
|
@see wxDC::SetTextBackground(), wxDCFontChanger, wxDCPenChanger, wxDCBrushChanger,
|
||||||
|
wxDCClipper, wxDCTextColourChanger, wxDCBgModeChanger
|
||||||
|
|
||||||
|
@since 3.1.3
|
||||||
|
*/
|
||||||
|
class wxDCTextBgColourChanger
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
Trivial constructor not changing anything.
|
||||||
|
|
||||||
|
This constructor is useful if you don't know beforehand if the colour
|
||||||
|
needs to be changed or not. It simply creates the object which won't do
|
||||||
|
anything in its destructor unless Set() is called -- in which case it
|
||||||
|
would reset the previous colour.
|
||||||
|
*/
|
||||||
|
wxDCTextBgColourChanger(wxDC& dc);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Sets @a col on the given @a dc, storing the old one.
|
||||||
|
|
||||||
|
@param dc
|
||||||
|
The DC where the colour must be temporary set.
|
||||||
|
@param col
|
||||||
|
The text background colour to set.
|
||||||
|
*/
|
||||||
|
wxDCTextBgColourChanger(wxDC& dc, const wxColour& col);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Set the background colour to use.
|
||||||
|
|
||||||
|
This method is meant to be called once only and only on the objects
|
||||||
|
created with the constructor overload not taking wxColour argument and
|
||||||
|
has the same effect as the other constructor, i.e. sets the background colour to
|
||||||
|
the given @a col and ensures that the old value is restored when this
|
||||||
|
object is destroyed.
|
||||||
|
*/
|
||||||
|
void Set(const wxColour& col);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Restores the background colour originally selected in the DC passed to the ctor.
|
||||||
|
*/
|
||||||
|
~wxDCTextBgColourChanger();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
@class wxDCTextBgModeChanger
|
||||||
|
|
||||||
|
wxDCTextBgModeChanger is a small helper class for setting a background
|
||||||
|
text mode on a wxDC and unsetting it automatically in the destructor,
|
||||||
|
restoring the previous one.
|
||||||
|
|
||||||
|
@library{wxcore}
|
||||||
|
@category{gdi}
|
||||||
|
|
||||||
|
@see wxDC::SetBackgroundMode(), wxDCFontChanger, wxDCPenChanger, wxDCBrushChanger,
|
||||||
|
wxDCClipper, wxDCTextColourChanger, wxDCTextBgColourChanger
|
||||||
|
|
||||||
|
@since 3.1.3
|
||||||
|
*/
|
||||||
|
class wxDCBgModeChanger
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
Trivial constructor not changing anything.
|
||||||
|
|
||||||
|
This constructor is useful if you don't know beforehand if the background mode
|
||||||
|
needs to be changed or not. It simply creates the object which won't do
|
||||||
|
anything in its destructor unless Set() is called -- in which case it
|
||||||
|
would reset the previous mode.
|
||||||
|
*/
|
||||||
|
wxDCBgModeChanger(wxDC& dc);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Sets @a mode on the given @a dc, storing the old one.
|
||||||
|
|
||||||
|
@param dc
|
||||||
|
The DC where the mode must be temporary set.
|
||||||
|
@param mode
|
||||||
|
The background mode to set.
|
||||||
|
*/
|
||||||
|
wxDCBgModeChanger(wxDC& dc, int mode);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Set the text background mode to use.
|
||||||
|
|
||||||
|
This method is meant to be called once only and only on the objects
|
||||||
|
created with the constructor overload not taking mode argument and
|
||||||
|
has the same effect as the other constructor, i.e. sets the background mode to
|
||||||
|
the given @a one, and ensures that the old value is restored when this
|
||||||
|
object is destroyed.
|
||||||
|
*/
|
||||||
|
void Set(int mode);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Restores the text background mode originally selected in the DC passed to the ctor.
|
||||||
|
*/
|
||||||
|
~wxDCBgModeChanger();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@class wxDCFontChanger
|
@class wxDCFontChanger
|
||||||
|
Reference in New Issue
Block a user