Introduced wxDCPenChanger and wxDCBrushChanger.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@39269 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
// Name: dc.h
|
// Name: wx/dc.h
|
||||||
// Purpose: wxDC class
|
// Purpose: wxDC class
|
||||||
// Author: Vadim Zeitlin
|
// Author: Vadim Zeitlin
|
||||||
// Modified by:
|
// Modified by:
|
||||||
@@ -161,20 +161,20 @@ public:
|
|||||||
// fill the area specified by rect with a radial gradient, starting from
|
// fill the area specified by rect with a radial gradient, starting from
|
||||||
// initialColour in the centre of the cercle and fading to destColour.
|
// initialColour in the centre of the cercle and fading to destColour.
|
||||||
void GradientFillConcentric(const wxRect& rect,
|
void GradientFillConcentric(const wxRect& rect,
|
||||||
const wxColour& initialColour,
|
const wxColour& initialColour,
|
||||||
const wxColour& destColour)
|
const wxColour& destColour)
|
||||||
{ GradientFillConcentric(rect, initialColour, destColour,
|
{ GradientFillConcentric(rect, initialColour, destColour,
|
||||||
wxPoint(rect.GetWidth() / 2,
|
wxPoint(rect.GetWidth() / 2,
|
||||||
rect.GetHeight() / 2)); }
|
rect.GetHeight() / 2)); }
|
||||||
|
|
||||||
void GradientFillConcentric(const wxRect& rect,
|
void GradientFillConcentric(const wxRect& rect,
|
||||||
const wxColour& initialColour,
|
const wxColour& initialColour,
|
||||||
const wxColour& destColour,
|
const wxColour& destColour,
|
||||||
const wxPoint& circleCenter);
|
const wxPoint& circleCenter);
|
||||||
|
|
||||||
// fill the area specified by rect with a linear gradient
|
// fill the area specified by rect with a linear gradient
|
||||||
void GradientFillLinear(const wxRect& rect,
|
void GradientFillLinear(const wxRect& rect,
|
||||||
const wxColour& initialColour,
|
const wxColour& initialColour,
|
||||||
const wxColour& destColour,
|
const wxColour& destColour,
|
||||||
wxDirection nDirection = wxEAST)
|
wxDirection nDirection = wxEAST)
|
||||||
{ DoGradientFillLinear(rect, initialColour, destColour, nDirection); }
|
{ DoGradientFillLinear(rect, initialColour, destColour, nDirection); }
|
||||||
@@ -659,7 +659,7 @@ protected:
|
|||||||
const wxColour& initialColour,
|
const wxColour& initialColour,
|
||||||
const wxColour& destColour,
|
const wxColour& destColour,
|
||||||
wxDirection nDirection = wxEAST);
|
wxDirection nDirection = wxEAST);
|
||||||
|
|
||||||
virtual bool DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const = 0;
|
virtual bool DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const = 0;
|
||||||
|
|
||||||
virtual void DoDrawPoint(wxCoord x, wxCoord y) = 0;
|
virtual void DoDrawPoint(wxCoord x, wxCoord y) = 0;
|
||||||
@@ -868,6 +868,68 @@ private:
|
|||||||
DECLARE_NO_COPY_CLASS(wxDCTextColourChanger)
|
DECLARE_NO_COPY_CLASS(wxDCTextColourChanger)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// helper class: you can use it to temporarily change the DC pen and
|
||||||
|
// restore it automatically when the object goes out of scope
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
class WXDLLEXPORT wxDCPenChanger
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
wxDCPenChanger(wxDC& dc) : m_dc(dc), m_penOld() { }
|
||||||
|
|
||||||
|
~wxDCPenChanger()
|
||||||
|
{
|
||||||
|
if ( m_penOld.Ok() )
|
||||||
|
m_dc.SetPen(m_penOld);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Set(const wxPen& pen)
|
||||||
|
{
|
||||||
|
if ( !m_penOld.Ok() )
|
||||||
|
m_penOld = m_dc.GetPen();
|
||||||
|
m_dc.SetPen(pen);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
wxDC& m_dc;
|
||||||
|
|
||||||
|
wxPen m_penOld;
|
||||||
|
|
||||||
|
DECLARE_NO_COPY_CLASS(wxDCPenChanger)
|
||||||
|
};
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// helper class: you can use it to temporarily change the DC brush and
|
||||||
|
// restore it automatically when the object goes out of scope
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
class WXDLLEXPORT wxDCBrushChanger
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
wxDCBrushChanger(wxDC& dc) : m_dc(dc), m_brushOld() { }
|
||||||
|
|
||||||
|
~wxDCBrushChanger()
|
||||||
|
{
|
||||||
|
if ( m_brushOld.Ok() )
|
||||||
|
m_dc.SetBrush(m_brushOld);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Set(const wxBrush& brush)
|
||||||
|
{
|
||||||
|
if ( !m_brushOld.Ok() )
|
||||||
|
m_brushOld = m_dc.GetBrush();
|
||||||
|
m_dc.SetBrush(brush);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
wxDC& m_dc;
|
||||||
|
|
||||||
|
wxBrush m_brushOld;
|
||||||
|
|
||||||
|
DECLARE_NO_COPY_CLASS(wxDCBrushChanger)
|
||||||
|
};
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// another small helper class: sets the clipping region in its ctor and
|
// another small helper class: sets the clipping region in its ctor and
|
||||||
// destroys it in the dtor
|
// destroys it in the dtor
|
||||||
|
@@ -232,12 +232,13 @@ wxRendererGeneric::DrawTreeItemButton(wxWindow * WXUNUSED(win),
|
|||||||
int flags)
|
int flags)
|
||||||
{
|
{
|
||||||
// store settings
|
// store settings
|
||||||
wxPen pen(dc.GetPen());
|
wxDCPenChanger penChanger(dc);
|
||||||
wxBrush brush(dc.GetBrush());
|
wxDCBrushChanger brushChanger(dc);
|
||||||
|
|
||||||
// white background
|
// white background
|
||||||
dc.SetPen(*wxGREY_PEN);
|
penChanger.Set(*wxGREY_PEN);
|
||||||
dc.SetBrush(*wxWHITE_BRUSH);
|
brushChanger.Set(*wxWHITE_BRUSH);
|
||||||
|
|
||||||
dc.DrawRectangle(rect);
|
dc.DrawRectangle(rect);
|
||||||
|
|
||||||
// black lines
|
// black lines
|
||||||
@@ -257,9 +258,6 @@ wxRendererGeneric::DrawTreeItemButton(wxWindow * WXUNUSED(win),
|
|||||||
dc.DrawLine(xMiddle, yMiddle - halfHeight,
|
dc.DrawLine(xMiddle, yMiddle - halfHeight,
|
||||||
xMiddle, yMiddle + halfHeight + 1);
|
xMiddle, yMiddle + halfHeight + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
dc.SetPen(pen);
|
|
||||||
dc.SetBrush(brush);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
Reference in New Issue
Block a user