Introduce wxPenInfo class

This commit is contained in:
Adrien Tétar 2017-05-02 11:02:37 +02:00 committed by Vadim Zeitlin
parent f045323934
commit bc562289c6
14 changed files with 212 additions and 0 deletions

View File

@ -35,6 +35,8 @@ public:
wxPen(const wxBitmap& stipple, int width);
wxPen(const wxPenInfo& info);
bool operator==(const wxPen& pen) const;
bool operator!=(const wxPen& pen) const { return !(*this == pen); }

View File

@ -20,6 +20,8 @@ public:
wxPen( const wxColour &colour, int width = 1, wxPenStyle style = wxPENSTYLE_SOLID );
wxPen( const wxPenInfo& info );
virtual ~wxPen();
bool operator==(const wxPen& pen) const;

View File

@ -38,6 +38,8 @@ public:
wxPen( const wxColour &colour, int width = 1, wxPenStyle style = wxPENSTYLE_SOLID );
wxPen( const wxPenInfo& info );
bool operator==(const wxPen& pen) const;
bool operator!=(const wxPen& pen) const { return !(*this == pen); }

View File

@ -25,6 +25,9 @@ public:
wxPen(const wxColour& col, int width = 1, wxPenStyle style = wxPENSTYLE_SOLID);
wxPen(const wxBitmap& stipple, int width);
wxPen(const wxPenInfo& info);
virtual ~wxPen() { }
bool operator==(const wxPen& pen) const;

View File

@ -23,6 +23,9 @@ public:
wxPen(const wxColour& col, int width = 1, wxPenStyle style = wxPENSTYLE_SOLID);
wxPen(const wxBitmap& stipple, int width);
wxPen(const wxPenInfo& info);
virtual ~wxPen();
bool operator==(const wxPen& pen) const;

View File

@ -59,6 +59,82 @@ enum wxPenCap
wxCAP_BUTT
};
// ----------------------------------------------------------------------------
// wxPenInfo describes a wxPen
// ----------------------------------------------------------------------------
class wxPenInfo
{
public:
wxPenInfo() :
m_colour(wxNullColour)
{
Init();
m_width = 1;
m_style = wxPENSTYLE_SOLID;
}
explicit wxPenInfo(const wxColour& colour, int width = 1, wxPenStyle style = wxPENSTYLE_SOLID) :
m_colour((wxColour&) colour)
{
Init();
m_width = width;
m_style = style;
}
// Setters for the various attributes. All of them return the object itself
// so that the calls to them could be chained.
wxPenInfo& Colour(const wxColour& colour)
{ m_colour = colour; return *this; }
wxPenInfo& Width(int width)
{ m_width = width; return *this; }
wxPenInfo& Style(wxPenStyle style)
{ m_style = style; return *this; }
wxPenInfo& Stipple(const wxBitmap& stipple)
{ m_stipple = stipple; m_style = wxPENSTYLE_STIPPLE; return *this; }
wxPenInfo& Dashes(int nb_dashes, const wxDash *dash)
{ m_nb_dashes = nb_dashes; m_dash = (wxDash *)dash; return *this; }
wxPenInfo& Join(wxPenJoin join)
{ m_join = join; return *this; }
wxPenInfo& Cap(wxPenCap cap)
{ m_cap = cap; return *this; }
// Accessors are mostly meant to be used by wxPen itself.
wxColour GetColour() const { return m_colour; }
wxBitmap* GetStipple() { return &m_stipple; }
wxPenStyle GetStyle() const { return m_style; }
wxPenJoin GetJoin() const { return m_join; }
wxPenCap GetCap() const { return m_cap; }
int GetWidth() const { return m_width; }
int GetDashes(wxDash **ptr) const { *ptr = m_dash; return m_nb_dashes; }
private:
void Init()
{
m_stipple = wxNullBitmap;
m_nb_dashes = 0;
m_dash = NULL;
m_join = wxJOIN_ROUND;
m_cap = wxCAP_ROUND;
}
wxColour& m_colour;
int m_width;
wxBitmap m_stipple;
wxPenStyle m_style;
wxPenJoin m_join;
wxPenCap m_cap;
int m_nb_dashes;
wxDash* m_dash;
};
class WXDLLIMPEXP_CORE wxPenBase : public wxGDIObject
{

View File

@ -36,6 +36,9 @@ public:
wxPen( const wxColour &colour, int width = 1, wxPenStyle style = wxPENSTYLE_SOLID );
wxPen( const wxBitmap &stipple, int width );
wxPen( const wxPenInfo& info );
virtual ~wxPen();
bool operator == ( const wxPen& pen ) const;

View File

@ -100,6 +100,43 @@ enum wxPenCap
};
/**
@class wxPenInfo
This class is a helper used for wxPen creation using named parameter
idiom: it allows to specify various wxPen attributes using the chained
calls to its clearly named methods instead of passing them in the fixed
order to wxPen constructors.
@since 3.1.0
*/
class wxPenInfo
{
public:
wxPenInfo();
explicit wxPen(const wxColour& colour, int width = 1, wxPenStyle style = wxPENSTYLE_SOLID);
wxPenInfo& ();
wxPenInfo& Colour(const wxColour& col);
wxPenInfo& Width(int width);
wxPenInfo& Style(wxPenStyle style);
wxPenInfo& Style(wxPenStyle style);
wxPenInfo& Stipple(const wxBitmap& stipple);
wxPenInfo& Dashes(int nb_dashes, const wxDash *dash);
wxPenInfo& Join(wxPenJoin join);
wxPenInfo& Cap(wxPenCap cap);
};
/**
@class wxPen
@ -157,6 +194,11 @@ public:
*/
wxPen();
/**
Creates a pen object using the specified pen description.
*/
wxPen(const wxPenInfo& info);
/**
Constructs a pen from a colour object, pen width and style.

View File

@ -79,6 +79,14 @@ wxPen::wxPen(const wxBitmap& WXUNUSED(stipple), int WXUNUSED(width))
m_refData = new wxPenRefData();
}
wxPen::wxPen(const wxPenInfo& info)
{
m_refData = new wxPenRefData(
info.GetColour(),
info.GetStyle()
);
}
bool wxPen::operator==(const wxPen& pen) const
{
#warning "this is incorrect"

View File

@ -103,6 +103,19 @@ wxPen::wxPen(const wxColour& colour, int width, int style)
M_PENDATA->m_colour = colour;
}
wxPen::wxPen(const wxPenInfo& info)
{
m_refData = new wxPenRefData();
M_PENDATA->m_colour = info.GetColour();
M_PENDATA->m_width = info.GetWidth();
M_PENDATA->m_style = info.GetStyle();
M_PENDATA->m_joinStyle = info.GetJoin();
M_PENDATA->m_capStyle = info.GetCap();
wxDash *dashes;
M_PENDATA->m_countDashes = info.GetDashes(&dashes);
M_PENDATA->m_dash = dashes;
}
wxPen::~wxPen()
{
// m_refData unrefed in ~wxObject

View File

@ -103,6 +103,20 @@ wxPen::wxPen(const wxColour& colour, int width, int style)
M_PENDATA->m_colour = colour;
}
wxPen::wxPen(const wxPenInfo& info)
{
m_refData = new wxPenRefData();
M_PENDATA->m_colour = info.GetColour();
M_PENDATA->m_width = info.GetWidth();
M_PENDATA->m_style = info.GetStyle();
M_PENDATA->m_joinStyle = info.GetJoin();
M_PENDATA->m_capStyle = info.GetCap();
wxDash *dashes;
M_PENDATA->m_countDashes = info.GetDashes(&dashes);
M_PENDATA->m_dash = dashes;
}
wxGDIRefData *wxPen::CreateGDIRefData() const
{
return new wxPenRefData;

View File

@ -414,6 +414,20 @@ wxPen::wxPen(const wxBitmap& stipple, int width)
m_refData = new wxPenRefData(stipple, width);
}
wxPen::wxPen(const wxPenInfo& info)
{
m_refData = new wxPenRefData();
M_PENDATA->SetColour(info.GetColour());
M_PENDATA->SetWidth(info.GetWidth());
M_PENDATA->SetStyle(info.GetStyle());
M_PENDATA->SetJoin(info.GetJoin());
M_PENDATA->SetCap(info.GetCap());
wxDash *dash;
int nb_dashes = info.GetDashes(&dash);
M_PENDATA->SetDashes(nb_dashes, dash)
}
bool wxPen::operator==(const wxPen& pen) const
{
const wxPenRefData *

View File

@ -141,6 +141,22 @@ wxPen::wxPen(const wxBitmap& stipple, int Width)
RealizeResource();
}
wxPen::wxPen(const wxPenInfo& info)
{
m_refData = new wxPenRefData;
M_PENDATA->m_colour = info.GetColour();
M_PENDATA->m_width = info.GetWidth();
M_PENDATA->m_style = info.GetStyle();
M_PENDATA->m_join = info.GetJoin();
M_PENDATA->m_cap = info.GetCap();
wxDash *dashes;
M_PENDATA->m_nbDash = info.GetDashes(&dashes);
M_PENDATA->m_dash = dashes;
RealizeResource();
}
wxGDIRefData *wxPen::CreateGDIRefData() const
{
return new wxPenRefData;

View File

@ -93,6 +93,20 @@ wxPen::wxPen(const wxColour& colour, int width, int style)
M_PENDATA->m_colour = colour;
}
wxPen::wxPen(const wxPenInfo& info)
{
m_refData = new wxPenRefData();
M_PENDATA->m_width = info.GetWidth();
M_PENDATA->m_style = info.GetStyle();
M_PENDATA->m_colour = info.GetColour();
M_PENDATA->m_capStyle = info.GetCap();
M_PENDATA->m_joinStyle = info.GetJoin();
M_PENDATA->m_stipple = info.GetStipple();
wxDash *dashes;
M_PENDATA->m_countDashes = info.GetDashes(&dashes);
M_PENDATA->m_dash = dashes;
}
wxPen::~wxPen()
{
// m_refData unrefed in ~wxObject