diff --git a/Makefile.in b/Makefile.in index 0199d265ce..cb53fe1902 100644 --- a/Makefile.in +++ b/Makefile.in @@ -3908,6 +3908,7 @@ COND_USE_GUI_1_ALL_GUI_HEADERS = \ wx/collheaderctrl.h \ wx/generic/collheaderctrl.h \ wx/itemattr.h \ + wx/peninfobase.h \ $(LOWLEVEL_HDR) \ $(GUI_CORE_HEADERS) \ $(ADVANCED_HDR) \ diff --git a/build/bakefiles/files.bkl b/build/bakefiles/files.bkl index 630090e8b8..d163adb16f 100644 --- a/build/bakefiles/files.bkl +++ b/build/bakefiles/files.bkl @@ -1188,6 +1188,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file! wx/collheaderctrl.h wx/generic/collheaderctrl.h wx/itemattr.h + wx/peninfobase.h diff --git a/build/files b/build/files index d5f864909d..bd58f84fcd 100644 --- a/build/files +++ b/build/files @@ -946,6 +946,7 @@ GUI_CMN_HDR = wx/palette.h wx/panel.h wx/pen.h + wx/peninfobase.h wx/position.h wx/preferences.h wx/radiobox.h diff --git a/build/msw/wx_core.vcxproj b/build/msw/wx_core.vcxproj index 7c52eeda3a..d530592aae 100644 --- a/build/msw/wx_core.vcxproj +++ b/build/msw/wx_core.vcxproj @@ -1382,6 +1382,7 @@ + diff --git a/build/msw/wx_core.vcxproj.filters b/build/msw/wx_core.vcxproj.filters index d4418f6617..eecc9366e6 100644 --- a/build/msw/wx_core.vcxproj.filters +++ b/build/msw/wx_core.vcxproj.filters @@ -1714,6 +1714,9 @@ Common Headers + + Common Headers + Common Headers diff --git a/build/msw/wx_vc7.sln b/build/msw/wx_vc7.sln index 4a7988c948..d1554b6b3c 100644 --- a/build/msw/wx_vc7.sln +++ b/build/msw/wx_vc7.sln @@ -1,4 +1,3 @@ - Microsoft Visual Studio Solution File, Format Version 8.00 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "wxregex", "wx_vc7_wxregex.vcproj", "{7A1A5354-6DB4-53F1-B75C-FE909D796167}" EndProject diff --git a/build/msw/wx_vc7_core.vcproj b/build/msw/wx_vc7_core.vcproj index 9b9fd90ae9..40acebe351 100644 --- a/build/msw/wx_vc7_core.vcproj +++ b/build/msw/wx_vc7_core.vcproj @@ -2393,6 +2393,9 @@ + + diff --git a/build/msw/wx_vc8.sln b/build/msw/wx_vc8.sln index 052e8057e8..c5337121df 100644 --- a/build/msw/wx_vc8.sln +++ b/build/msw/wx_vc8.sln @@ -1,4 +1,3 @@ - Microsoft Visual Studio Solution File, Format Version 9.00 # Visual Studio 2005 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "wxregex", "wx_vc8_wxregex.vcproj", "{078F4E39-D258-54B5-B1B1-4905D10E06DC}" diff --git a/build/msw/wx_vc8_core.vcproj b/build/msw/wx_vc8_core.vcproj index c8d45bf837..d874619c11 100644 --- a/build/msw/wx_vc8_core.vcproj +++ b/build/msw/wx_vc8_core.vcproj @@ -3692,6 +3692,10 @@ RelativePath="..\..\include\wx\pen.h" > + + diff --git a/build/msw/wx_vc9.sln b/build/msw/wx_vc9.sln index d5cda2e8b8..56f929fe3b 100644 --- a/build/msw/wx_vc9.sln +++ b/build/msw/wx_vc9.sln @@ -1,4 +1,3 @@ - Microsoft Visual Studio Solution File, Format Version 10.00 # Visual Studio 2008 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "wxregex", "wx_vc9_wxregex.vcproj", "{56A4B526-BB81-5D01-AAA9-16D23BBB169D}" diff --git a/build/msw/wx_vc9_core.vcproj b/build/msw/wx_vc9_core.vcproj index e81eaeafc6..362cc6a67f 100644 --- a/build/msw/wx_vc9_core.vcproj +++ b/build/msw/wx_vc9_core.vcproj @@ -3688,6 +3688,10 @@ RelativePath="..\..\include\wx\pen.h" > + + diff --git a/docs/changes.txt b/docs/changes.txt index 4635dd2ff4..068307df0e 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -58,6 +58,10 @@ Changes in behaviour which may result in build errors - Never documented and not always available private wxGetClipboardData() function now doesn't exist at all any more in wxMSW, use wxClipboard instead. +- wxGraphicsRenderer::CreatePen() now takes wxGraphicsPenInfo and not a wxPen. + This only affects code defining its own custom renderers, code just using + wxGraphicsContext::CreatePen() continues to compile and work as before. + 3.1.1: (not released yet) ---------------------------- @@ -97,6 +101,7 @@ All: All (GUI): +- Allow using fractional pen widths with wxGraphicsContext (Adrien Tétar). - Improve wxSVGFileDC to support more of wxDC API (Maarten Bent). - Add support for wxAuiManager and wxAuiPaneInfo to XRC (Andrea Zanellato). - Add support for wxSL_MIN_MAX_LABELS and wxSL_VALUE_LABEL to XRC (ousnius). 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/graphics.h b/include/wx/graphics.h index 2af989a3c4..7cbe1bc52f 100644 --- a/include/wx/graphics.h +++ b/include/wx/graphics.h @@ -21,6 +21,7 @@ #include "wx/dynarray.h" #include "wx/font.h" #include "wx/image.h" +#include "wx/peninfobase.h" #include "wx/vector.h" enum wxAntialiasMode @@ -132,6 +133,34 @@ protected: wxDECLARE_DYNAMIC_CLASS(wxGraphicsObject); }; +// ---------------------------------------------------------------------------- +// wxGraphicsPenInfo describes a wxGraphicsPen +// ---------------------------------------------------------------------------- + +class wxGraphicsPenInfo : public wxPenInfoBase +{ +public: + explicit wxGraphicsPenInfo(const wxColour& colour = wxColour(), + wxDouble width = 1.0, + wxPenStyle style = wxPENSTYLE_SOLID) + : wxPenInfoBase(colour, style) + { + m_width = width; + } + + // Setters + + wxGraphicsPenInfo& Width(wxDouble width) + { m_width = width; return *this; } + + // Accessors + + wxDouble GetWidth() const { return m_width; } + +private: + wxDouble m_width; +}; + class WXDLLIMPEXP_CORE wxGraphicsPen : public wxGraphicsObject { public: @@ -479,7 +508,10 @@ public: wxGraphicsPath CreatePath() const; - virtual wxGraphicsPen CreatePen(const wxPen& pen) const; + wxGraphicsPen CreatePen(const wxPen& pen) const; + + wxGraphicsPen CreatePen(const wxGraphicsPenInfo& info) const + { return DoCreatePen(info); } virtual wxGraphicsBrush CreateBrush(const wxBrush& brush ) const; @@ -744,6 +776,8 @@ protected: // implementations of overloaded public functions: we use different names // for them to avoid the virtual function hiding problems in the derived // classes + virtual wxGraphicsPen DoCreatePen(const wxGraphicsPenInfo& info) const; + virtual void DoDrawText(const wxString& str, wxDouble x, wxDouble y) = 0; virtual void DoDrawRotatedText(const wxString& str, wxDouble x, wxDouble y, wxDouble angle); @@ -861,7 +895,7 @@ public: // Paints - virtual wxGraphicsPen CreatePen(const wxPen& pen) = 0; + virtual wxGraphicsPen CreatePen(const wxGraphicsPenInfo& info) = 0; virtual wxGraphicsBrush CreateBrush(const wxBrush& brush ) = 0; 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..9ebddc3b6d 100644 --- a/include/wx/pen.h +++ b/include/wx/pen.h @@ -12,51 +12,34 @@ #define _WX_PEN_H_BASE_ #include "wx/gdiobj.h" -#include "wx/gdicmn.h" +#include "wx/peninfobase.h" -enum wxPenStyle +// ---------------------------------------------------------------------------- +// wxPenInfo contains all parameters describing a wxPen +// ---------------------------------------------------------------------------- + +class wxPenInfo : public wxPenInfoBase { - wxPENSTYLE_INVALID = -1, +public: + explicit wxPenInfo(const wxColour& colour = wxColour(), + int width = 1, + wxPenStyle style = wxPENSTYLE_SOLID) + : wxPenInfoBase(colour, style) + { + m_width = width; + } - wxPENSTYLE_SOLID = wxSOLID, - wxPENSTYLE_DOT = wxDOT, - wxPENSTYLE_LONG_DASH = wxLONG_DASH, - wxPENSTYLE_SHORT_DASH = wxSHORT_DASH, - wxPENSTYLE_DOT_DASH = wxDOT_DASH, - wxPENSTYLE_USER_DASH = wxUSER_DASH, + // Setters - wxPENSTYLE_TRANSPARENT = wxTRANSPARENT, + wxPenInfo& Width(int width) + { m_width = width; return *this; } - wxPENSTYLE_STIPPLE_MASK_OPAQUE = wxSTIPPLE_MASK_OPAQUE, - wxPENSTYLE_STIPPLE_MASK = wxSTIPPLE_MASK, - wxPENSTYLE_STIPPLE = wxSTIPPLE, + // Accessors - wxPENSTYLE_BDIAGONAL_HATCH = wxHATCHSTYLE_BDIAGONAL, - wxPENSTYLE_CROSSDIAG_HATCH = wxHATCHSTYLE_CROSSDIAG, - wxPENSTYLE_FDIAGONAL_HATCH = wxHATCHSTYLE_FDIAGONAL, - wxPENSTYLE_CROSS_HATCH = wxHATCHSTYLE_CROSS, - wxPENSTYLE_HORIZONTAL_HATCH = wxHATCHSTYLE_HORIZONTAL, - wxPENSTYLE_VERTICAL_HATCH = wxHATCHSTYLE_VERTICAL, - wxPENSTYLE_FIRST_HATCH = wxHATCHSTYLE_FIRST, - wxPENSTYLE_LAST_HATCH = wxHATCHSTYLE_LAST -}; + int GetWidth() const { return m_width; } -enum wxPenJoin -{ - wxJOIN_INVALID = -1, - - wxJOIN_BEVEL = 120, - wxJOIN_MITER, - wxJOIN_ROUND -}; - -enum wxPenCap -{ - wxCAP_INVALID = -1, - - wxCAP_ROUND = 130, - wxCAP_PROJECTING, - wxCAP_BUTT +private: + int m_width; }; diff --git a/include/wx/peninfobase.h b/include/wx/peninfobase.h new file mode 100644 index 0000000000..33a0c40674 --- /dev/null +++ b/include/wx/peninfobase.h @@ -0,0 +1,130 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: wx/peninfobase.h +// Purpose: Declaration of wxPenInfoBase class and related constants +// Author: Adrien Tétar, Vadim Zeitlin +// Created: 2017-09-10 +// Copyright: (c) 2017 Vadim Zeitlin +// Licence: wxWindows licence +/////////////////////////////////////////////////////////////////////////////// + +#ifndef _WX_PENINFOBASE_H_ +#define _WX_PENINFOBASE_H_ + +#include "wx/bitmap.h" +#include "wx/colour.h" +#include "wx/gdicmn.h" // for wxDash + +enum wxPenStyle +{ + wxPENSTYLE_INVALID = -1, + + wxPENSTYLE_SOLID = wxSOLID, + wxPENSTYLE_DOT = wxDOT, + wxPENSTYLE_LONG_DASH = wxLONG_DASH, + wxPENSTYLE_SHORT_DASH = wxSHORT_DASH, + wxPENSTYLE_DOT_DASH = wxDOT_DASH, + wxPENSTYLE_USER_DASH = wxUSER_DASH, + + wxPENSTYLE_TRANSPARENT = wxTRANSPARENT, + + wxPENSTYLE_STIPPLE_MASK_OPAQUE = wxSTIPPLE_MASK_OPAQUE, + wxPENSTYLE_STIPPLE_MASK = wxSTIPPLE_MASK, + wxPENSTYLE_STIPPLE = wxSTIPPLE, + + wxPENSTYLE_BDIAGONAL_HATCH = wxHATCHSTYLE_BDIAGONAL, + wxPENSTYLE_CROSSDIAG_HATCH = wxHATCHSTYLE_CROSSDIAG, + wxPENSTYLE_FDIAGONAL_HATCH = wxHATCHSTYLE_FDIAGONAL, + wxPENSTYLE_CROSS_HATCH = wxHATCHSTYLE_CROSS, + wxPENSTYLE_HORIZONTAL_HATCH = wxHATCHSTYLE_HORIZONTAL, + wxPENSTYLE_VERTICAL_HATCH = wxHATCHSTYLE_VERTICAL, + wxPENSTYLE_FIRST_HATCH = wxHATCHSTYLE_FIRST, + wxPENSTYLE_LAST_HATCH = wxHATCHSTYLE_LAST +}; + +enum wxPenJoin +{ + wxJOIN_INVALID = -1, + + wxJOIN_BEVEL = 120, + wxJOIN_MITER, + wxJOIN_ROUND +}; + +enum wxPenCap +{ + wxCAP_INVALID = -1, + + wxCAP_ROUND = 130, + wxCAP_PROJECTING, + wxCAP_BUTT +}; + +// ---------------------------------------------------------------------------- +// wxPenInfoBase is a common base for wxPenInfo and wxGraphicsPenInfo +// ---------------------------------------------------------------------------- + +// This class uses CRTP, the template parameter is the derived class itself. +template +class wxPenInfoBase +{ +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 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 wxWidgets itself. + + wxColour GetColour() const { return m_colour; } + wxBitmap GetStipple() const { return m_stipple; } + wxPenStyle GetStyle() const { return m_style; } + wxPenJoin GetJoin() const { return m_join; } + wxPenCap GetCap() const { return m_cap; } + int GetDashes(wxDash **ptr) const { *ptr = m_dash; return m_nb_dashes; } + + int GetDashCount() const { return m_nb_dashes; } + wxDash* GetDash() const { return m_dash; } + + // Convenience + + bool IsTransparent() const { return m_style == wxPENSTYLE_TRANSPARENT; } + +protected: + wxPenInfoBase(const wxColour& colour, wxPenStyle style) + { + m_nb_dashes = 0; + m_dash = NULL; + m_join = wxJOIN_ROUND; + m_cap = wxCAP_ROUND; + + m_colour = colour; + m_style = style; + } + +private: + // Helper to return this object itself cast to its real type T. + T& This() { return static_cast(*this); } + + wxColour m_colour; + wxBitmap m_stipple; + wxPenStyle m_style; + wxPenJoin m_join; + wxPenCap m_cap; + + int m_nb_dashes; + wxDash* m_dash; +}; + +#endif // _WX_PENINFOBASE_H_ 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/graphics.h b/interface/wx/graphics.h index ba37013b88..84ab4dd929 100644 --- a/interface/wx/graphics.h +++ b/interface/wx/graphics.h @@ -253,7 +253,7 @@ enum wxInterpolationQuality /** default interpolation, based on type of context, in general medium quality */ wxINTERPOLATION_DEFAULT, /** no interpolation */ - wxINTERPOLATION_NONE, + wxINTERPOLATION_NONE, /** fast interpolation, suited for interactivity */ wxINTERPOLATION_FAST, /** better quality */ @@ -331,7 +331,7 @@ public: wxImage ConvertToImage() const; /** - Return the pointer to the native bitmap data. (CGImageRef for Core Graphics, + Return the pointer to the native bitmap data. (CGImageRef for Core Graphics, cairo_surface_t for Cairo, Bitmap* for GDI+.) @since 2.9.4 @@ -677,8 +677,19 @@ public: /** Creates a native pen from a wxPen. + + Prefer to use the overload taking wxGraphicsPenInfo unless you already + have a wxPen as constructing one only to pass it to this method is + wasteful. */ - virtual wxGraphicsPen CreatePen(const wxPen& pen) const; + wxGraphicsPen CreatePen(const wxPen& pen) const; + + /** + Creates a native pen from a wxGraphicsPenInfo. + + @since 3.1.1 + */ + wxGraphicsPen CreatePen(const wxGraphicsPenInfo& info) const; /** Sets the pen used for stroking. @@ -1415,9 +1426,11 @@ public: virtual wxGraphicsPath CreatePath() = 0; /** - Creates a native pen from a wxPen. + Creates a native pen from its description. + + @since 3.1.1 */ - virtual wxGraphicsPen CreatePen(const wxPen& pen) = 0; + virtual wxGraphicsPen CreatePen(const wxGraphicsPenInfo& info) = 0; /** Creates a native brush with a radial gradient. @@ -1528,6 +1541,51 @@ public: +/** + @class wxGraphicsPenInfo + + This class is a helper used for wxGraphicsPen creation using named parameter + idiom: it allows to specify various wxGraphicsPen attributes using the chained + calls to its clearly named methods instead of passing them in the fixed + order to wxGraphicsPen constructors. + + Typically you would use wxGraphicsPenInfo with a wxGraphicsContext, e.g. to + start drawing with a dotted blue pen slightly wider than normal you could + write the following: + @code + wxGraphicsContext ctx = wxGraphicsContext::Create(dc); + + ctx.SetPen(wxGraphicsPenInfo(*wxBLUE).Width(1.25).Style(wxPENSTYLE_DOT)); + @endcode + + @since 3.1.1 + */ +class wxGraphicsPenInfo +{ +public: + explicit wxGraphicsPenInfo(const wxColour& colour = wxColour(), + wxDouble width = 1.0, + wxPenStyle style = wxPENSTYLE_SOLID); + + wxGraphicsPenInfo& Colour(const wxColour& col); + + wxGraphicsPenInfo& Width(wxDouble width); + + wxGraphicsPenInfo& Style(wxPenStyle style); + + wxGraphicsPenInfo& Style(wxPenStyle style); + + wxGraphicsPenInfo& Stipple(const wxBitmap& stipple); + + wxGraphicsPenInfo& Dashes(int nb_dashes, const wxDash *dash); + + wxGraphicsPenInfo& Join(wxPenJoin join); + + wxGraphicsPenInfo& Cap(wxPenCap cap); +}; + + + /** @class wxGraphicsPen diff --git a/interface/wx/pen.h b/interface/wx/pen.h index 6d42f19e36..04000e478f 100644 --- a/interface/wx/pen.h +++ b/interface/wx/pen.h @@ -101,6 +101,48 @@ 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. + + For instance, to create a dotted blue pen with the given join style you + could do + @code + wxPen pen(wxPenInfo(*wxBLUE).Style(wxPENSTYLE_DOT).Join(wxJOIN_BEVEL)); + @endcode + + @since 3.1.1 + */ +class wxPenInfo +{ +public: + explicit wxPenInfo(const wxColour& colour = wxColour(), + int width = 1, + wxPenStyle style = wxPENSTYLE_SOLID); + + 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 +199,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/common/graphcmn.cpp b/src/common/graphcmn.cpp index 979e4423e6..5f88faf950 100644 --- a/src/common/graphcmn.cpp +++ b/src/common/graphcmn.cpp @@ -26,6 +26,7 @@ #include "wx/dcmemory.h" #include "wx/dcprint.h" #include "wx/math.h" + #include "wx/pen.h" #include "wx/region.h" #include "wx/log.h" #endif @@ -824,7 +825,25 @@ wxGraphicsPath wxGraphicsContext::CreatePath() const wxGraphicsPen wxGraphicsContext::CreatePen(const wxPen& pen) const { - return GetRenderer()->CreatePen(pen); + if ( !pen.IsOk() ) + return wxGraphicsPen(); + + wxDash *dashes; + int nb_dashes = pen.GetDashes(&dashes); + + return DoCreatePen(wxGraphicsPenInfo() + .Colour(pen.GetColour()) + .Width(pen.GetWidth()) + .Style(pen.GetStyle()) + .Stipple(*pen.GetStipple()) + .Dashes(nb_dashes, dashes) + .Join(pen.GetJoin()) + .Cap(pen.GetCap())); +} + +wxGraphicsPen wxGraphicsContext::DoCreatePen(const wxGraphicsPenInfo& info) const +{ + return GetRenderer()->CreatePen(info); } wxGraphicsBrush wxGraphicsContext::CreateBrush(const wxBrush& brush ) const diff --git a/src/dfb/pen.cpp b/src/dfb/pen.cpp index e36ed6dde0..02f290da02 100644 --- a/src/dfb/pen.cpp +++ b/src/dfb/pen.cpp @@ -79,6 +79,11 @@ 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/generic/graphicc.cpp b/src/generic/graphicc.cpp index bc35b45a17..12e858d9c9 100644 --- a/src/generic/graphicc.cpp +++ b/src/generic/graphicc.cpp @@ -284,7 +284,7 @@ private: class WXDLLIMPEXP_CORE wxCairoPenData : public wxCairoPenBrushBaseData { public: - wxCairoPenData( wxGraphicsRenderer* renderer, const wxPen &pen ); + wxCairoPenData( wxGraphicsRenderer* renderer, const wxGraphicsPenInfo &info ); ~wxCairoPenData(); void Init(); @@ -733,15 +733,15 @@ void wxCairoPenData::Init() m_count = 0; } -wxCairoPenData::wxCairoPenData( wxGraphicsRenderer* renderer, const wxPen &pen ) - : wxCairoPenBrushBaseData(renderer, pen.GetColour(), pen.IsTransparent()) +wxCairoPenData::wxCairoPenData( wxGraphicsRenderer* renderer, const wxGraphicsPenInfo &info ) + : wxCairoPenBrushBaseData(renderer, info.GetColour(), info.IsTransparent()) { Init(); - m_width = pen.GetWidth(); + m_width = info.GetWidth(); if (m_width <= 0.0) m_width = 0.1; - switch ( pen.GetCap() ) + switch ( info.GetCap() ) { case wxCAP_ROUND : m_cap = CAIRO_LINE_CAP_ROUND; @@ -760,7 +760,7 @@ wxCairoPenData::wxCairoPenData( wxGraphicsRenderer* renderer, const wxPen &pen ) break; } - switch ( pen.GetJoin() ) + switch ( info.GetJoin() ) { case wxJOIN_BEVEL : m_join = CAIRO_LINE_JOIN_BEVEL; @@ -797,7 +797,7 @@ wxCairoPenData::wxCairoPenData( wxGraphicsRenderer* renderer, const wxPen &pen ) 9.0 , 6.0 , 3.0 , 3.0 }; - switch ( pen.GetStyle() ) + switch ( info.GetStyle() ) { case wxPENSTYLE_SOLID : break; @@ -827,7 +827,7 @@ wxCairoPenData::wxCairoPenData( wxGraphicsRenderer* renderer, const wxPen &pen ) case wxPENSTYLE_USER_DASH : { wxDash *wxdashes ; - m_count = pen.GetDashes( &wxdashes ) ; + m_count = info.GetDashes( &wxdashes ) ; if ((wxdashes != NULL) && (m_count > 0)) { m_userLengths = new double[m_count] ; @@ -848,14 +848,17 @@ wxCairoPenData::wxCairoPenData( wxGraphicsRenderer* renderer, const wxPen &pen ) case wxPENSTYLE_STIPPLE : case wxPENSTYLE_STIPPLE_MASK : case wxPENSTYLE_STIPPLE_MASK_OPAQUE : - InitStipple(pen.GetStipple()); + { + wxBitmap stipple = info.GetStipple(); + InitStipple(&stipple); + } break; default : - if ( pen.GetStyle() >= wxPENSTYLE_FIRST_HATCH - && pen.GetStyle() <= wxPENSTYLE_LAST_HATCH ) + if ( info.GetStyle() >= wxPENSTYLE_FIRST_HATCH + && info.GetStyle() <= wxPENSTYLE_LAST_HATCH ) { - InitHatch(static_cast(pen.GetStyle())); + InitHatch(static_cast(info.GetStyle())); } break; } @@ -2900,7 +2903,7 @@ public : wxDouble tx=0.0, wxDouble ty=0.0) wxOVERRIDE; - virtual wxGraphicsPen CreatePen(const wxPen& pen) wxOVERRIDE ; + virtual wxGraphicsPen CreatePen(const wxGraphicsPenInfo& info) wxOVERRIDE ; virtual wxGraphicsBrush CreateBrush(const wxBrush& brush ) wxOVERRIDE ; @@ -3076,13 +3079,13 @@ wxGraphicsMatrix wxCairoRenderer::CreateMatrix( wxDouble a, wxDouble b, wxDouble return m; } -wxGraphicsPen wxCairoRenderer::CreatePen(const wxPen& pen) +wxGraphicsPen wxCairoRenderer::CreatePen(const wxGraphicsPenInfo& info) { wxGraphicsPen p; ENSURE_LOADED_OR_RETURN(p); - if (pen.IsOk() && pen.GetStyle() != wxPENSTYLE_TRANSPARENT) + if (info.GetStyle() != wxPENSTYLE_TRANSPARENT) { - p.SetRefData(new wxCairoPenData( this, pen )); + p.SetRefData(new wxCairoPenData( this, info )); } return p; } diff --git a/src/gtk/pen.cpp b/src/gtk/pen.cpp index d6d4da8427..e5976eb85a 100644 --- a/src/gtk/pen.cpp +++ b/src/gtk/pen.cpp @@ -46,6 +46,16 @@ public: m_dash = data.m_dash; } + wxPenRefData( const wxPenInfo& info ) + { + m_width = info.GetWidth(); + m_style = info.GetStyle(); + m_joinStyle = info.GetJoin(); + m_capStyle = info.GetCap(); + m_colour = info.GetColour(); + m_countDashes = info.GetDashes((wxDash**)&m_dash); + } + bool operator == (const wxPenRefData& data) const { if ( m_countDashes != data.m_countDashes ) @@ -89,18 +99,20 @@ wxIMPLEMENT_DYNAMIC_CLASS(wxPen, wxGDIObject); wxPen::wxPen( const wxColour &colour, int width, wxPenStyle style ) { - m_refData = new wxPenRefData(); - M_PENDATA->m_width = width; - M_PENDATA->m_style = style; - M_PENDATA->m_colour = colour; + m_refData = new wxPenRefData(wxPenInfo(colour, width).Style(style)); } wxPen::wxPen(const wxColour& colour, int width, int style) { - m_refData = new wxPenRefData(); - M_PENDATA->m_width = width; - M_PENDATA->m_style = (wxPenStyle)style; - M_PENDATA->m_colour = colour; + m_refData = new wxPenRefData + ( + wxPenInfo(colour, width).Style((wxPenStyle)style) + ); +} + +wxPen::wxPen(const wxPenInfo& info) +{ + m_refData = new wxPenRefData(info); } wxPen::~wxPen() diff --git a/src/gtk1/pen.cpp b/src/gtk1/pen.cpp index 8e5d64ea25..3e145d18ec 100644 --- a/src/gtk1/pen.cpp +++ b/src/gtk1/pen.cpp @@ -46,6 +46,18 @@ public: m_dash = data.m_dash; } + wxPenRefData( const wxPenInfo& info ) + { + m_width = info.GetWidth(); + m_style = info.GetStyle(); + m_joinStyle = info.GetJoin(); + m_capStyle = info.GetCap(); + m_colour = info.GetColour(); + wxDash* dash; + m_countDashes = info.GetDashes(&dash); + m_dash = (wxGTKDash*)dash; + } + bool operator == (const wxPenRefData& data) const { if ( m_countDashes != data.m_countDashes ) @@ -89,18 +101,20 @@ wxIMPLEMENT_DYNAMIC_CLASS(wxPen, wxGDIObject); wxPen::wxPen( const wxColour &colour, int width, wxPenStyle style ) { - m_refData = new wxPenRefData(); - M_PENDATA->m_width = width; - M_PENDATA->m_style = style; - M_PENDATA->m_colour = colour; + m_refData = new wxPenRefData(wxPenInfo(colour, width).Style(style)); } wxPen::wxPen(const wxColour& colour, int width, int style) { - m_refData = new wxPenRefData(); - M_PENDATA->m_width = width; - M_PENDATA->m_style = (wxPenStyle)style; - M_PENDATA->m_colour = colour; + m_refData = new wxPenRefData + ( + wxPenInfo(colour, width).Style((wxPenStyle)style) + ); +} + +wxPen::wxPen(const wxPenInfo& info) +{ + m_refData = new wxPenRefData(info); } wxGDIRefData *wxPen::CreateGDIRefData() const diff --git a/src/msw/graphics.cpp b/src/msw/graphics.cpp index 9aeea9ed01..b518dbdd99 100644 --- a/src/msw/graphics.cpp +++ b/src/msw/graphics.cpp @@ -260,7 +260,7 @@ private: class wxGDIPlusPenData : public wxGraphicsObjectRefData { public: - wxGDIPlusPenData( wxGraphicsRenderer* renderer, const wxPen &pen ); + wxGDIPlusPenData( wxGraphicsRenderer* renderer, const wxGraphicsPenInfo &info ); ~wxGDIPlusPenData(); void Init(); @@ -400,7 +400,7 @@ public: virtual bool SetAntialiasMode(wxAntialiasMode antialias) wxOVERRIDE; virtual bool SetInterpolationQuality(wxInterpolationQuality interpolation) wxOVERRIDE; - + virtual bool SetCompositionMode(wxCompositionMode op) wxOVERRIDE; virtual void BeginLayer(wxDouble opacity) wxOVERRIDE; @@ -573,7 +573,7 @@ public : wxDouble tx=0.0, wxDouble ty=0.0) wxOVERRIDE; - virtual wxGraphicsPen CreatePen(const wxPen& pen) wxOVERRIDE; + virtual wxGraphicsPen CreatePen(const wxGraphicsPenInfo& pen) wxOVERRIDE; virtual wxGraphicsBrush CreateBrush(const wxBrush& brush ) wxOVERRIDE; @@ -643,18 +643,19 @@ void wxGDIPlusPenData::Init() m_penBrush = NULL; } -wxGDIPlusPenData::wxGDIPlusPenData( wxGraphicsRenderer* renderer, const wxPen &pen ) -: wxGraphicsObjectRefData(renderer) +wxGDIPlusPenData::wxGDIPlusPenData( wxGraphicsRenderer* renderer, + const wxGraphicsPenInfo &info ) + : wxGraphicsObjectRefData(renderer) { Init(); - m_width = pen.GetWidth(); + m_width = info.GetWidth(); if (m_width <= 0.0) m_width = 0.1; - m_pen = new Pen(wxColourToColor(pen.GetColour()), m_width ); + m_pen = new Pen(wxColourToColor(info.GetColour()), m_width ); LineCap cap; - switch ( pen.GetCap() ) + switch ( info.GetCap() ) { case wxCAP_ROUND : cap = LineCapRound; @@ -675,7 +676,7 @@ wxGDIPlusPenData::wxGDIPlusPenData( wxGraphicsRenderer* renderer, const wxPen &p m_pen->SetLineCap(cap,cap, DashCapFlat); LineJoin join; - switch ( pen.GetJoin() ) + switch ( info.GetJoin() ) { case wxJOIN_BEVEL : join = LineJoinBevel; @@ -699,7 +700,7 @@ wxGDIPlusPenData::wxGDIPlusPenData( wxGraphicsRenderer* renderer, const wxPen &p m_pen->SetDashStyle(DashStyleSolid); DashStyle dashStyle = DashStyleSolid; - switch ( pen.GetStyle() ) + switch ( info.GetStyle() ) { case wxPENSTYLE_SOLID : break; @@ -723,7 +724,7 @@ wxGDIPlusPenData::wxGDIPlusPenData( wxGraphicsRenderer* renderer, const wxPen &p { dashStyle = DashStyleCustom; wxDash *dashes; - int count = pen.GetDashes( &dashes ); + int count = info.GetDashes( &dashes ); if ((dashes != NULL) && (count > 0)) { REAL *userLengths = new REAL[count]; @@ -738,12 +739,12 @@ wxGDIPlusPenData::wxGDIPlusPenData( wxGraphicsRenderer* renderer, const wxPen &p break; case wxPENSTYLE_STIPPLE : { - wxBitmap* bmp = pen.GetStipple(); - if ( bmp && bmp->IsOk() ) + wxBitmap bmp = info.GetStipple(); + if ( bmp.IsOk() ) { - m_penImage = Bitmap::FromHBITMAP((HBITMAP)bmp->GetHBITMAP(), + m_penImage = Bitmap::FromHBITMAP((HBITMAP)bmp.GetHBITMAP(), #if wxUSE_PALETTE - (HPALETTE)bmp->GetPalette()->GetHPALETTE() + (HPALETTE)bmp.GetPalette()->GetHPALETTE() #else NULL #endif @@ -755,11 +756,11 @@ wxGDIPlusPenData::wxGDIPlusPenData( wxGraphicsRenderer* renderer, const wxPen &p } break; default : - if ( pen.GetStyle() >= wxPENSTYLE_FIRST_HATCH && - pen.GetStyle() <= wxPENSTYLE_LAST_HATCH ) + if ( info.GetStyle() >= wxPENSTYLE_FIRST_HATCH && + info.GetStyle() <= wxPENSTYLE_LAST_HATCH ) { HatchStyle style; - switch( pen.GetStyle() ) + switch( info.GetStyle() ) { case wxPENSTYLE_BDIAGONAL_HATCH : style = HatchStyleBackwardDiagonal; @@ -785,7 +786,7 @@ wxGDIPlusPenData::wxGDIPlusPenData( wxGraphicsRenderer* renderer, const wxPen &p m_penBrush = new HatchBrush ( style, - wxColourToColor(pen.GetColour()), + wxColourToColor(info.GetColour()), Color::Transparent ); m_pen->SetBrush( m_penBrush ); @@ -2047,7 +2048,7 @@ void wxGDIPlusContext::DoDrawText(const wxString& str, wxGDIPlusFontData * const fontData = (wxGDIPlusFontData *)m_font.GetRefData(); - + m_context->DrawString ( str.wc_str(*wxConvUI), // string to draw, always Unicode @@ -2160,7 +2161,7 @@ bool wxGDIPlusContext::ShouldOffset() const { if ( !m_enableOffset ) return false; - + int penwidth = 0 ; if ( !m_pen.IsNull() ) { @@ -2448,15 +2449,15 @@ wxGraphicsMatrix wxGDIPlusRenderer::CreateMatrix( wxDouble a, wxDouble b, wxDoub return m; } -wxGraphicsPen wxGDIPlusRenderer::CreatePen(const wxPen& pen) +wxGraphicsPen wxGDIPlusRenderer::CreatePen(const wxGraphicsPenInfo& info) { ENSURE_LOADED_OR_RETURN(wxNullGraphicsPen); - if ( !pen.IsOk() || pen.GetStyle() == wxPENSTYLE_TRANSPARENT ) + if ( info.GetStyle() == wxPENSTYLE_TRANSPARENT ) return wxNullGraphicsPen; else { wxGraphicsPen p; - p.SetRefData(new wxGDIPlusPenData( this, pen )); + p.SetRefData(new wxGDIPlusPenData( this, info )); return p; } } diff --git a/src/msw/graphicsd2d.cpp b/src/msw/graphicsd2d.cpp index cd9d7e9684..22306f9169 100644 --- a/src/msw/graphicsd2d.cpp +++ b/src/msw/graphicsd2d.cpp @@ -2458,7 +2458,9 @@ wxBrushStyle wxConvertPenStyleToBrushStyle(wxPenStyle penStyle) class wxD2DPenData : public wxGraphicsObjectRefData, public wxD2DManagedGraphicsData { public: - wxD2DPenData(wxGraphicsRenderer* renderer, ID2D1Factory* direct2dFactory, const wxPen& pen); + wxD2DPenData(wxGraphicsRenderer* renderer, + ID2D1Factory* direct2dFactory, + const wxGraphicsPenInfo& info); void CreateStrokeStyle(ID2D1Factory* const direct2dfactory); @@ -2474,9 +2476,9 @@ public: } private: - // We store the source pen for later when we need to recreate the - // device-dependent resources. - const wxPen m_sourcePen; + // 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. @@ -2496,26 +2498,28 @@ private: wxD2DPenData::wxD2DPenData( wxGraphicsRenderer* renderer, ID2D1Factory* direct2dFactory, - const wxPen& pen) - : wxGraphicsObjectRefData(renderer), m_sourcePen(pen), m_width(pen.GetWidth()) + const wxGraphicsPenInfo& info) + : wxGraphicsObjectRefData(renderer), + m_penInfo(info), + m_width(info.GetWidth()) { CreateStrokeStyle(direct2dFactory); wxBrush strokeBrush; - if (m_sourcePen.GetStyle() == wxPENSTYLE_STIPPLE) + if (m_penInfo.GetStyle() == wxPENSTYLE_STIPPLE) { - strokeBrush.SetStipple(*(m_sourcePen.GetStipple())); + strokeBrush.SetStipple(m_penInfo.GetStipple()); strokeBrush.SetStyle(wxBRUSHSTYLE_STIPPLE); } - else if(wxIsHatchPenStyle(m_sourcePen.GetStyle())) + else if(wxIsHatchPenStyle(m_penInfo.GetStyle())) { - strokeBrush.SetStyle(wxConvertPenStyleToBrushStyle(m_sourcePen.GetStyle())); - strokeBrush.SetColour(m_sourcePen.GetColour()); + strokeBrush.SetStyle(wxConvertPenStyleToBrushStyle(m_penInfo.GetStyle())); + strokeBrush.SetColour(m_penInfo.GetColour()); } else { - strokeBrush.SetColour(m_sourcePen.GetColour()); + strokeBrush.SetColour(m_penInfo.GetColour()); strokeBrush.SetStyle(wxBRUSHSTYLE_SOLID); } @@ -2524,21 +2528,21 @@ wxD2DPenData::wxD2DPenData( void wxD2DPenData::CreateStrokeStyle(ID2D1Factory* const direct2dfactory) { - D2D1_CAP_STYLE capStyle = wxD2DConvertPenCap(m_sourcePen.GetCap()); - D2D1_LINE_JOIN lineJoin = wxD2DConvertPenJoin(m_sourcePen.GetJoin()); - D2D1_DASH_STYLE dashStyle = wxD2DConvertPenStyle(m_sourcePen.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_sourcePen.GetDashCount(); + dashCount = m_penInfo.GetDashCount(); dashes = new FLOAT[dashCount]; for (int i = 0; i < dashCount; ++i) { - dashes[i] = m_sourcePen.GetDash()[i]; + dashes[i] = m_penInfo.GetDash()[i]; } } @@ -4384,7 +4388,7 @@ public : wxDouble a = 1.0, wxDouble b = 0.0, wxDouble c = 0.0, wxDouble d = 1.0, wxDouble tx = 0.0, wxDouble ty = 0.0) wxOVERRIDE; - wxGraphicsPen CreatePen(const wxPen& pen) wxOVERRIDE; + wxGraphicsPen CreatePen(const wxGraphicsPenInfo& info) wxOVERRIDE; wxGraphicsBrush CreateBrush(const wxBrush& brush) wxOVERRIDE; @@ -4553,16 +4557,16 @@ wxGraphicsMatrix wxD2DRenderer::CreateMatrix( return matrix; } -wxGraphicsPen wxD2DRenderer::CreatePen(const wxPen& pen) +wxGraphicsPen wxD2DRenderer::CreatePen(const wxGraphicsPenInfo& info) { - if ( !pen.IsOk() || pen.GetStyle() == wxPENSTYLE_TRANSPARENT ) + if ( info.GetStyle() == wxPENSTYLE_TRANSPARENT ) { return wxNullGraphicsPen; } else { wxGraphicsPen p; - wxD2DPenData* penData = new wxD2DPenData(this, m_direct2dFactory, pen); + wxD2DPenData* penData = new wxD2DPenData(this, m_direct2dFactory, info); p.SetRefData(penData); return p; } diff --git a/src/msw/pen.cpp b/src/msw/pen.cpp index 1e1dac1d7e..61a8648d3b 100644 --- a/src/msw/pen.cpp +++ b/src/msw/pen.cpp @@ -46,8 +46,7 @@ public: wxPenRefData(); wxPenRefData(const wxPenRefData& data); - wxPenRefData(const wxColour& col, int width, wxPenStyle style); - wxPenRefData(const wxBitmap& stipple, int width); + wxPenRefData(const wxPenInfo& info); virtual ~wxPenRefData(); bool operator==(const wxPenRefData& data) const @@ -170,24 +169,17 @@ wxPenRefData::wxPenRefData(const wxPenRefData& data) m_hPen = 0; } -wxPenRefData::wxPenRefData(const wxColour& col, int width, wxPenStyle style) +wxPenRefData::wxPenRefData(const wxPenInfo& info) { Init(); - m_style = style; - m_width = width; - - m_colour = col; -} - -wxPenRefData::wxPenRefData(const wxBitmap& stipple, int width) -{ - Init(); - - m_style = wxPENSTYLE_STIPPLE; - m_width = width; - - m_stipple = stipple; + m_style = info.GetStyle(); + m_width = info.GetWidth(); + m_join = info.GetJoin(); + m_cap = info.GetCap(); + m_stipple = info.GetStipple(); + m_nbDash = info.GetDashes(&m_dash); + m_colour = info.GetColour(); } wxPenRefData::~wxPenRefData() @@ -401,17 +393,25 @@ wxIMPLEMENT_DYNAMIC_CLASS(wxPen, wxGDIObject); wxPen::wxPen(const wxColour& col, int width, wxPenStyle style) { - m_refData = new wxPenRefData(col, width, style); + m_refData = new wxPenRefData(wxPenInfo(col, width).Style(style)); } wxPen::wxPen(const wxColour& colour, int width, int style) { - m_refData = new wxPenRefData(colour, width, (wxPenStyle)style); + m_refData = new wxPenRefData + ( + wxPenInfo(colour, width).Style((wxPenStyle)style) + ); } wxPen::wxPen(const wxBitmap& stipple, int width) { - m_refData = new wxPenRefData(stipple, width); + m_refData = new wxPenRefData(wxPenInfo().Stipple(stipple).Width(width)); +} + +wxPen::wxPen(const wxPenInfo& info) +{ + m_refData = new wxPenRefData(info); } bool wxPen::operator==(const wxPen& pen) const diff --git a/src/osx/carbon/graphics.cpp b/src/osx/carbon/graphics.cpp index 767e052367..e77c6172cf 100644 --- a/src/osx/carbon/graphics.cpp +++ b/src/osx/carbon/graphics.cpp @@ -304,7 +304,7 @@ protected : class wxMacCoreGraphicsPenData : public wxGraphicsObjectRefData { public: - wxMacCoreGraphicsPenData( wxGraphicsRenderer* renderer, const wxPen &pen ); + wxMacCoreGraphicsPenData( wxGraphicsRenderer* renderer, const wxGraphicsPenInfo& info ); ~wxMacCoreGraphicsPenData(); void Init(); @@ -329,19 +329,20 @@ protected : CGFloat* m_patternColorComponents; }; -wxMacCoreGraphicsPenData::wxMacCoreGraphicsPenData( wxGraphicsRenderer* renderer, const wxPen &pen ) : - wxGraphicsObjectRefData( renderer ) +wxMacCoreGraphicsPenData::wxMacCoreGraphicsPenData( wxGraphicsRenderer* renderer, + const wxGraphicsPenInfo& info ) + : wxGraphicsObjectRefData( renderer ) { Init(); - m_color.reset( wxMacCreateCGColor( pen.GetColour() ) ) ; + m_color.reset( wxMacCreateCGColor( info.GetColour() ) ) ; // TODO: * m_dc->m_scaleX - m_width = pen.GetWidth(); + m_width = info.GetWidth(); if (m_width <= 0.0) m_width = (CGFloat) 0.1; - switch ( pen.GetCap() ) + switch ( info.GetCap() ) { case wxCAP_ROUND : m_cap = kCGLineCapRound; @@ -360,7 +361,7 @@ wxMacCoreGraphicsPenData::wxMacCoreGraphicsPenData( wxGraphicsRenderer* renderer break; } - switch ( pen.GetJoin() ) + switch ( info.GetJoin() ) { case wxJOIN_BEVEL : m_join = kCGLineJoinBevel; @@ -386,7 +387,7 @@ wxMacCoreGraphicsPenData::wxMacCoreGraphicsPenData( wxGraphicsRenderer* renderer static const CGFloat dashed[] = { (CGFloat) 19.0 , (CGFloat) 9.0 }; static const CGFloat dotted_dashed[] = { (CGFloat) 9.0 , (CGFloat) 6.0 , (CGFloat) 3.0 , (CGFloat) 3.0 }; - switch ( pen.GetStyle() ) + switch ( info.GetStyle() ) { case wxPENSTYLE_SOLID: break; @@ -415,7 +416,7 @@ wxMacCoreGraphicsPenData::wxMacCoreGraphicsPenData( wxGraphicsRenderer* renderer case wxPENSTYLE_USER_DASH: wxDash *dashes; - m_count = pen.GetDashes( &dashes ); + m_count = info.GetDashes( &dashes ); if ((dashes != NULL) && (m_count > 0)) { m_userLengths = new CGFloat[m_count]; @@ -434,11 +435,11 @@ wxMacCoreGraphicsPenData::wxMacCoreGraphicsPenData( wxGraphicsRenderer* renderer case wxPENSTYLE_STIPPLE: { - wxBitmap* bmp = pen.GetStipple(); - if ( bmp && bmp->IsOk() ) + wxBitmap bmp = info.GetStipple(); + if ( bmp.IsOk() ) { m_colorSpace.reset( CGColorSpaceCreatePattern( NULL ) ); - m_pattern.reset( (CGPatternRef) *( new ImagePattern( bmp , CGAffineTransformMakeScale( 1,-1 ) ) ) ); + m_pattern.reset( (CGPatternRef) *( new ImagePattern( &bmp , CGAffineTransformMakeScale( 1,-1 ) ) ) ); m_patternColorComponents = new CGFloat[1] ; m_patternColorComponents[0] = (CGFloat) 1.0; m_isPattern = true; @@ -450,12 +451,12 @@ wxMacCoreGraphicsPenData::wxMacCoreGraphicsPenData( wxGraphicsRenderer* renderer { m_isPattern = true; m_colorSpace.reset( CGColorSpaceCreatePattern( wxMacGetGenericRGBColorSpace() ) ); - m_pattern.reset( (CGPatternRef) *( new HatchPattern( pen.GetStyle() , CGAffineTransformMakeScale( 1,-1 ) ) ) ); + m_pattern.reset( (CGPatternRef) *( new HatchPattern( info.GetStyle() , CGAffineTransformMakeScale( 1,-1 ) ) ) ); m_patternColorComponents = new CGFloat[4] ; - m_patternColorComponents[0] = (CGFloat) (pen.GetColour().Red() / 255.0); - m_patternColorComponents[1] = (CGFloat) (pen.GetColour().Green() / 255.0); - m_patternColorComponents[2] = (CGFloat) (pen.GetColour().Blue() / 255.0); - m_patternColorComponents[3] = (CGFloat) (pen.GetColour().Alpha() / 255.0); + m_patternColorComponents[0] = (CGFloat) (info.GetColour().Red() / 255.0); + m_patternColorComponents[1] = (CGFloat) (info.GetColour().Green() / 255.0); + m_patternColorComponents[2] = (CGFloat) (info.GetColour().Blue() / 255.0); + m_patternColorComponents[3] = (CGFloat) (info.GetColour().Alpha() / 255.0); } break; } @@ -2536,7 +2537,7 @@ public : wxDouble tx=0.0, wxDouble ty=0.0) wxOVERRIDE; - virtual wxGraphicsPen CreatePen(const wxPen& pen) wxOVERRIDE ; + virtual wxGraphicsPen CreatePen(const wxGraphicsPenInfo& info) wxOVERRIDE ; virtual wxGraphicsBrush CreateBrush(const wxBrush& brush ) wxOVERRIDE ; @@ -2705,14 +2706,14 @@ wxGraphicsMatrix wxMacCoreGraphicsRenderer::CreateMatrix( wxDouble a, wxDouble b return m; } -wxGraphicsPen wxMacCoreGraphicsRenderer::CreatePen(const wxPen& pen) +wxGraphicsPen wxMacCoreGraphicsRenderer::CreatePen(const wxGraphicsPenInfo& info) { - if ( !pen.IsOk() || pen.GetStyle() == wxPENSTYLE_TRANSPARENT ) + if ( info.IsTransparent() ) return wxNullGraphicsPen; else { wxGraphicsPen p; - p.SetRefData(new wxMacCoreGraphicsPenData( this, pen )); + p.SetRefData(new wxMacCoreGraphicsPenData( this, info )); return p; } } diff --git a/src/osx/pen.cpp b/src/osx/pen.cpp index b835196261..40c9fba41b 100644 --- a/src/osx/pen.cpp +++ b/src/osx/pen.cpp @@ -23,6 +23,7 @@ class WXDLLEXPORT wxPenRefData : public wxGDIRefData public: wxPenRefData(); wxPenRefData(const wxPenRefData& data); + wxPenRefData(const wxPenInfo& info); virtual ~wxPenRefData(); wxPenRefData& operator=(const wxPenRefData& data); @@ -79,6 +80,16 @@ wxPenRefData::wxPenRefData(const wxPenRefData& data) m_colour = data.m_colour; } +wxPenRefData::wxPenRefData(const wxPenInfo& info) +{ + m_style = info.GetStyle(); + m_width = info.GetWidth(); + m_join = info.GetJoin(); + m_cap = info.GetCap(); + m_nbDash = info.GetDashes(&m_dash); + m_colour = info.GetColour(); +} + wxPenRefData::~wxPenRefData() { } @@ -98,45 +109,28 @@ wxPen::~wxPen() // Should implement Create wxPen::wxPen(const wxColour& col, int Width, wxPenStyle Style) { - m_refData = new wxPenRefData; - - M_PENDATA->m_colour = col; - M_PENDATA->m_width = Width; - M_PENDATA->m_style = Style; - M_PENDATA->m_join = wxJOIN_ROUND ; - M_PENDATA->m_cap = wxCAP_ROUND ; - M_PENDATA->m_nbDash = 0 ; - M_PENDATA->m_dash = 0 ; + m_refData = new wxPenRefData(wxPenInfo(col, Width).Style(Style)); RealizeResource(); } wxPen::wxPen(const wxColour& col, int Width, int Style) { - m_refData = new wxPenRefData; - - M_PENDATA->m_colour = col; - M_PENDATA->m_width = Width; - M_PENDATA->m_style = (wxPenStyle)Style; - M_PENDATA->m_join = wxJOIN_ROUND ; - M_PENDATA->m_cap = wxCAP_ROUND ; - M_PENDATA->m_nbDash = 0 ; - M_PENDATA->m_dash = 0 ; + m_refData = new wxPenRefData(wxPenInfo(col, Width).Style((wxPenStyle)Style)); RealizeResource(); } -wxPen::wxPen(const wxBitmap& stipple, int Width) +wxPen::wxPen(const wxBitmap& stipple, int width) { - m_refData = new wxPenRefData; + m_refData = new wxPenRefData(wxPenInfo().Stipple(stipple).Width(width)); - M_PENDATA->m_stipple = stipple; - M_PENDATA->m_width = Width; - M_PENDATA->m_style = wxPENSTYLE_STIPPLE; - M_PENDATA->m_join = wxJOIN_ROUND ; - M_PENDATA->m_cap = wxCAP_ROUND ; - M_PENDATA->m_nbDash = 0 ; - M_PENDATA->m_dash = 0 ; + RealizeResource(); +} + +wxPen::wxPen(const wxPenInfo& info) +{ + m_refData = new wxPenRefData(info); RealizeResource(); } diff --git a/src/x11/pen.cpp b/src/x11/pen.cpp index 036c52f3da..007c35fe25 100644 --- a/src/x11/pen.cpp +++ b/src/x11/pen.cpp @@ -52,6 +52,18 @@ public: m_stipple = data.m_stipple; } + wxPenRefData( const wxPenInfo& info ) + { + m_width = info.GetWidth(); + m_style = info.GetStyle(); + m_joinStyle = info.GetJoin(); + m_capStyle = info.GetCap(); + m_colour = info.GetColour(); + wxDash* dash; + m_countDashes = info.GetDashes(&dash); + m_dash = (wxX11Dash*)dash; + } + bool operator == (const wxPenRefData& data) const { return (m_style == data.m_style && @@ -79,18 +91,20 @@ wxIMPLEMENT_DYNAMIC_CLASS(wxPen, wxGDIObject); wxPen::wxPen( const wxColour &colour, int width, wxPenStyle style ) { - m_refData = new wxPenRefData(); - M_PENDATA->m_width = width; - M_PENDATA->m_style = style; - M_PENDATA->m_colour = colour; + m_refData = new wxPenRefData(wxPenInfo(colour, width).Style(style)); } wxPen::wxPen(const wxColour& colour, int width, int style) { - m_refData = new wxPenRefData(); - M_PENDATA->m_width = width; - M_PENDATA->m_style = (wxPenStyle)style; - M_PENDATA->m_colour = colour; + m_refData = new wxPenRefData + ( + wxPenInfo(colour, width).Style((wxPenStyle)style) + ); +} + +wxPen::wxPen(const wxPenInfo& info) +{ + m_refData = new wxPenRefData(info); } wxPen::~wxPen()