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

@@ -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;
}