From bc562289c66cb58e59842462bed2329f0f52a3da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20T=C3=A9tar?= Date: Tue, 2 May 2017 11:02:37 +0200 Subject: [PATCH] Introduce wxPenInfo class --- include/wx/dfb/pen.h | 2 ++ include/wx/gtk/pen.h | 2 ++ include/wx/gtk1/pen.h | 2 ++ include/wx/msw/pen.h | 3 ++ include/wx/osx/pen.h | 3 ++ include/wx/pen.h | 76 +++++++++++++++++++++++++++++++++++++++++++ include/wx/x11/pen.h | 3 ++ interface/wx/pen.h | 42 ++++++++++++++++++++++++ src/dfb/pen.cpp | 8 +++++ src/gtk/pen.cpp | 13 ++++++++ src/gtk1/pen.cpp | 14 ++++++++ src/msw/pen.cpp | 14 ++++++++ src/osx/pen.cpp | 16 +++++++++ src/x11/pen.cpp | 14 ++++++++ 14 files changed, 212 insertions(+) diff --git a/include/wx/dfb/pen.h b/include/wx/dfb/pen.h index 642c6569f6..24b03a9404 100644 --- a/include/wx/dfb/pen.h +++ b/include/wx/dfb/pen.h @@ -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); } diff --git a/include/wx/gtk/pen.h b/include/wx/gtk/pen.h index c6bfbe3b0b..6e95eb9c40 100644 --- a/include/wx/gtk/pen.h +++ b/include/wx/gtk/pen.h @@ -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; diff --git a/include/wx/gtk1/pen.h b/include/wx/gtk1/pen.h index 77e754ec4c..b3124dc9bf 100644 --- a/include/wx/gtk1/pen.h +++ b/include/wx/gtk1/pen.h @@ -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); } diff --git a/include/wx/msw/pen.h b/include/wx/msw/pen.h index f1648cc82a..00e021bd87 100644 --- a/include/wx/msw/pen.h +++ b/include/wx/msw/pen.h @@ -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; diff --git a/include/wx/osx/pen.h b/include/wx/osx/pen.h index c203e2faeb..f028df68e9 100644 --- a/include/wx/osx/pen.h +++ b/include/wx/osx/pen.h @@ -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; diff --git a/include/wx/pen.h b/include/wx/pen.h index e7eb2ff4a1..56100361b9 100644 --- a/include/wx/pen.h +++ b/include/wx/pen.h @@ -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 { diff --git a/include/wx/x11/pen.h b/include/wx/x11/pen.h index b71eb45cc7..bb3f9dc2e4 100644 --- a/include/wx/x11/pen.h +++ b/include/wx/x11/pen.h @@ -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; diff --git a/interface/wx/pen.h b/interface/wx/pen.h index 6d42f19e36..3b9a361dea 100644 --- a/interface/wx/pen.h +++ b/interface/wx/pen.h @@ -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. diff --git a/src/dfb/pen.cpp b/src/dfb/pen.cpp index e36ed6dde0..4b6d2f824a 100644 --- a/src/dfb/pen.cpp +++ b/src/dfb/pen.cpp @@ -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" diff --git a/src/gtk/pen.cpp b/src/gtk/pen.cpp index d6d4da8427..0adc41a458 100644 --- a/src/gtk/pen.cpp +++ b/src/gtk/pen.cpp @@ -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 diff --git a/src/gtk1/pen.cpp b/src/gtk1/pen.cpp index 8e5d64ea25..0e6eab5239 100644 --- a/src/gtk1/pen.cpp +++ b/src/gtk1/pen.cpp @@ -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; diff --git a/src/msw/pen.cpp b/src/msw/pen.cpp index 1e1dac1d7e..1992349f24 100644 --- a/src/msw/pen.cpp +++ b/src/msw/pen.cpp @@ -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 * diff --git a/src/osx/pen.cpp b/src/osx/pen.cpp index b835196261..b1b0ce79d7 100644 --- a/src/osx/pen.cpp +++ b/src/osx/pen.cpp @@ -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; diff --git a/src/x11/pen.cpp b/src/x11/pen.cpp index 036c52f3da..9c1699d97d 100644 --- a/src/x11/pen.cpp +++ b/src/x11/pen.cpp @@ -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