Minor formatting and style changes in wxPenInfo code

Use more standard formatting, wrap some overlong lines.
This commit is contained in:
Vadim Zeitlin 2017-09-10 01:09:46 +02:00
parent 999c750ca7
commit cc91a7d6d4
7 changed files with 60 additions and 47 deletions

View File

@ -140,8 +140,10 @@ protected:
class wxGraphicsPenInfo : public wxPenInfoBase<wxGraphicsPenInfo>
{
public:
explicit wxGraphicsPenInfo(const wxColour& colour = wxColour(), wxDouble width = 1.0, wxPenStyle style = wxPENSTYLE_SOLID)
: wxPenInfoBase(colour, style)
explicit wxGraphicsPenInfo(const wxColour& colour = wxColour(),
wxDouble width = 1.0,
wxPenStyle style = wxPENSTYLE_SOLID)
: wxPenInfoBase(colour, style)
{
m_width = width;
}

View File

@ -61,9 +61,10 @@ enum wxPenCap
};
// ----------------------------------------------------------------------------
// wxPenInfo describes a wxPen
// wxPenInfoBase is a common base for wxPenInfo and wxGraphicsPenInfo
// ----------------------------------------------------------------------------
// This class uses CRTP, the template parameter is the derived class itself.
template <class T>
class wxPenInfoBase
{
@ -82,21 +83,21 @@ public:
// Setters for the various attributes. All of them return the object itself
// so that the calls to them could be chained.
T &Colour(const wxColour& colour)
{ m_colour = colour; return static_cast<T&>(*this); }
T& Colour(const wxColour& colour)
{ m_colour = colour; return This(); }
T &Style(wxPenStyle style)
{ m_style = style; return static_cast<T&>(*this); }
T &Stipple(const wxBitmap& stipple)
{ m_stipple = stipple; m_style = wxPENSTYLE_STIPPLE; return static_cast<T&>(*this); }
T &Dashes(int nb_dashes, const wxDash *dash)
{ m_nb_dashes = nb_dashes; m_dash = (wxDash *)dash; return static_cast<T&>(*this); }
T &Join(wxPenJoin join)
{ m_join = join; return static_cast<T&>(*this); }
T &Cap(wxPenCap cap)
{ m_cap = cap; return static_cast<T&>(*this); }
T& Style(wxPenStyle style)
{ m_style = style; return This(); }
T& Stipple(const wxBitmap& stipple)
{ m_stipple = stipple; m_style = wxPENSTYLE_STIPPLE; return This(); }
T& Dashes(int nb_dashes, const wxDash *dash)
{ m_nb_dashes = nb_dashes; m_dash = (wxDash *)dash; return This(); }
T& Join(wxPenJoin join)
{ m_join = join; return This(); }
T& Cap(wxPenCap cap)
{ m_cap = cap; return This(); }
// Accessors are mostly meant to be used by wxPen itself.
// Accessors are mostly meant to be used by wxWidgets itself.
wxColour GetColour() const { return m_colour; }
wxBitmap GetStipple() const { return m_stipple; }
@ -113,6 +114,9 @@ public:
bool IsTransparent() const { return m_style == wxPENSTYLE_TRANSPARENT; }
private:
// Helper to return this object itself cast to its real type T.
T& This() { return static_cast<T&>(*this); }
wxColour m_colour;
wxBitmap m_stipple;
wxPenStyle m_style;
@ -123,11 +127,17 @@ private:
wxDash* m_dash;
};
// ----------------------------------------------------------------------------
// wxPenInfo contains all parameters describing a wxPen
// ----------------------------------------------------------------------------
class wxPenInfo : public wxPenInfoBase<wxPenInfo>
{
public:
explicit wxPenInfo(const wxColour& colour = wxColour(), int width = 1, wxPenStyle style = wxPENSTYLE_SOLID)
: wxPenInfoBase(colour, style)
explicit wxPenInfo(const wxColour& colour = wxColour(),
int width = 1,
wxPenStyle style = wxPENSTYLE_SOLID)
: wxPenInfoBase(colour, style)
{
m_width = width;
}

View File

@ -81,10 +81,7 @@ wxPen::wxPen(const wxBitmap& WXUNUSED(stipple), int WXUNUSED(width))
wxPen::wxPen(const wxPenInfo& info)
{
m_refData = new wxPenRefData(
info.GetColour(),
info.GetStyle()
);
m_refData = new wxPenRefData(info.GetColour(), info.GetStyle());
}
bool wxPen::operator==(const wxPen& pen) const

View File

@ -750,7 +750,7 @@ wxCairoPenData::wxCairoPenData( wxGraphicsRenderer* renderer, const wxGraphicsPe
void wxCairoPenData::InitFromPenInfo( const wxGraphicsPenInfo &info )
{
Init();
m_width = info.GetWidth();
m_width = info.GetWidth();
if (m_width <= 0.0)
m_width = 0.1;

View File

@ -653,8 +653,9 @@ wxGDIPlusPenData::wxGDIPlusPenData( wxGraphicsRenderer* renderer, const wxPen &p
InitFromPenInfo(wxGraphicsPenInfo::CreateFromPen(pen));
}
wxGDIPlusPenData::wxGDIPlusPenData( wxGraphicsRenderer* renderer, const wxGraphicsPenInfo &info )
: wxGraphicsObjectRefData(renderer)
wxGDIPlusPenData::wxGDIPlusPenData( wxGraphicsRenderer* renderer,
const wxGraphicsPenInfo &info )
: wxGraphicsObjectRefData(renderer)
{
InitFromPenInfo(info);
}

View File

@ -2478,9 +2478,9 @@ public:
}
private:
// We store the source info for later when we need to recreate the
// device-dependent resources.
const wxGraphicsPenInfo m_sourceInfo;
// We store the original pen description for later when we need to recreate
// the device-dependent resources.
const wxGraphicsPenInfo m_penInfo;
// A stroke style is a device-independent resource.
// Describes the caps, miter limit, line join, and dash information.
@ -2500,10 +2500,10 @@ private:
wxD2DPenData::wxD2DPenData(
wxGraphicsRenderer* renderer,
ID2D1Factory* direct2dFactory,
const wxPen& pen) :
wxGraphicsObjectRefData(renderer),
m_sourceInfo(wxGraphicsPenInfo::CreateFromPen(pen)),
m_width(pen.GetWidth())
const wxPen& pen)
: wxGraphicsObjectRefData(renderer),
m_penInfo(wxGraphicsPenInfo::CreateFromPen(pen)),
m_width(pen.GetWidth())
{
Init(renderer, direct2dFactory);
}
@ -2512,7 +2512,9 @@ wxD2DPenData::wxD2DPenData(
wxGraphicsRenderer* renderer,
ID2D1Factory* direct2dFactory,
const wxGraphicsPenInfo& info)
: wxGraphicsObjectRefData(renderer), m_sourceInfo(info), m_width(info.GetWidth())
: wxGraphicsObjectRefData(renderer),
m_penInfo(info),
m_width(info.GetWidth())
{
Init(renderer, direct2dFactory);
}
@ -2525,19 +2527,19 @@ void wxD2DPenData::Init(
wxBrush strokeBrush;
if (m_sourceInfo.GetStyle() == wxPENSTYLE_STIPPLE)
if (m_penInfo.GetStyle() == wxPENSTYLE_STIPPLE)
{
strokeBrush.SetStipple(m_sourceInfo.GetStipple());
strokeBrush.SetStipple(m_penInfo.GetStipple());
strokeBrush.SetStyle(wxBRUSHSTYLE_STIPPLE);
}
else if(wxIsHatchPenStyle(m_sourceInfo.GetStyle()))
else if(wxIsHatchPenStyle(m_penInfo.GetStyle()))
{
strokeBrush.SetStyle(wxConvertPenStyleToBrushStyle(m_sourceInfo.GetStyle()));
strokeBrush.SetColour(m_sourceInfo.GetColour());
strokeBrush.SetStyle(wxConvertPenStyleToBrushStyle(m_penInfo.GetStyle()));
strokeBrush.SetColour(m_penInfo.GetColour());
}
else
{
strokeBrush.SetColour(m_sourceInfo.GetColour());
strokeBrush.SetColour(m_penInfo.GetColour());
strokeBrush.SetStyle(wxBRUSHSTYLE_SOLID);
}
@ -2546,21 +2548,21 @@ void wxD2DPenData::Init(
void wxD2DPenData::CreateStrokeStyle(ID2D1Factory* const direct2dfactory)
{
D2D1_CAP_STYLE capStyle = wxD2DConvertPenCap(m_sourceInfo.GetCap());
D2D1_LINE_JOIN lineJoin = wxD2DConvertPenJoin(m_sourceInfo.GetJoin());
D2D1_DASH_STYLE dashStyle = wxD2DConvertPenStyle(m_sourceInfo.GetStyle());
D2D1_CAP_STYLE capStyle = wxD2DConvertPenCap(m_penInfo.GetCap());
D2D1_LINE_JOIN lineJoin = wxD2DConvertPenJoin(m_penInfo.GetJoin());
D2D1_DASH_STYLE dashStyle = wxD2DConvertPenStyle(m_penInfo.GetStyle());
int dashCount = 0;
FLOAT* dashes = NULL;
if (dashStyle == D2D1_DASH_STYLE_CUSTOM)
{
dashCount = m_sourceInfo.GetDashCount();
dashCount = m_penInfo.GetDashCount();
dashes = new FLOAT[dashCount];
for (int i = 0; i < dashCount; ++i)
{
dashes[i] = m_sourceInfo.GetDash()[i];
dashes[i] = m_penInfo.GetDash()[i];
}
}

View File

@ -337,8 +337,9 @@ wxMacCoreGraphicsPenData::wxMacCoreGraphicsPenData( wxGraphicsRenderer* renderer
InitFromPenInfo(wxGraphicsPenInfo::CreateFromPen(pen));
}
wxMacCoreGraphicsPenData::wxMacCoreGraphicsPenData( wxGraphicsRenderer* renderer, const wxGraphicsPenInfo& info ) :
wxGraphicsObjectRefData( renderer )
wxMacCoreGraphicsPenData::wxMacCoreGraphicsPenData( wxGraphicsRenderer* renderer,
const wxGraphicsPenInfo& info )
: wxGraphicsObjectRefData( renderer )
{
InitFromPenInfo(info);
}
@ -350,7 +351,7 @@ void wxMacCoreGraphicsPenData::InitFromPenInfo( const wxGraphicsPenInfo& info )
m_color.reset( wxMacCreateCGColor( info.GetColour() ) ) ;
// TODO: * m_dc->m_scaleX
m_width = info.GetWidth();
m_width = info.GetWidth();
if (m_width <= 0.0)
m_width = (CGFloat) 0.1;