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/include/wx/graphics.h b/include/wx/graphics.h index 0e340df715..f9d7f33db2 100644 --- a/include/wx/graphics.h +++ b/include/wx/graphics.h @@ -21,8 +21,8 @@ #include "wx/dynarray.h" #include "wx/font.h" #include "wx/image.h" +#include "wx/peninfobase.h" #include "wx/vector.h" -#include "wx/pen.h" enum wxAntialiasMode { @@ -148,20 +148,6 @@ public: m_width = width; } - static wxGraphicsPenInfo CreateFromPen(const wxPen& pen) - { - wxDash *dashes; - int nb_dashes = pen.GetDashes(&dashes); - return wxGraphicsPenInfo() - .Colour(pen.GetColour()) - .Width(pen.GetWidth()) - .Style(pen.GetStyle()) - .Stipple(*pen.GetStipple()) - .Dashes(nb_dashes, dashes) - .Join(pen.GetJoin()) - .Cap(pen.GetCap()); - } - // Setters wxGraphicsPenInfo& Width(wxDouble width) @@ -171,6 +157,10 @@ public: wxDouble GetWidth() const { return m_width; } + // This is a helper used by wxWidgets itself, it doesn't make much sense to + // use it outside of the library. + static wxGraphicsPenInfo CreateFromPen(const wxPen& pen); + private: wxDouble m_width; }; diff --git a/include/wx/pen.h b/include/wx/pen.h index a1c59130e8..9ebddc3b6d 100644 --- a/include/wx/pen.h +++ b/include/wx/pen.h @@ -11,122 +11,8 @@ #ifndef _WX_PEN_H_BASE_ #define _WX_PEN_H_BASE_ -#include "wx/bitmap.h" #include "wx/gdiobj.h" -#include "wx/gdicmn.h" - -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; -}; +#include "wx/peninfobase.h" // ---------------------------------------------------------------------------- // wxPenInfo contains all parameters describing a wxPen 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/src/common/graphcmn.cpp b/src/common/graphcmn.cpp index 5f39c47e07..30d136b5ca 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 @@ -116,6 +117,21 @@ WXDLLIMPEXP_DATA_CORE(wxGraphicsBrush) wxNullGraphicsBrush; WXDLLIMPEXP_DATA_CORE(wxGraphicsFont) wxNullGraphicsFont; WXDLLIMPEXP_DATA_CORE(wxGraphicsBitmap) wxNullGraphicsBitmap; +/* static */ +wxGraphicsPenInfo wxGraphicsPenInfo::CreateFromPen(const wxPen& pen) +{ + wxDash *dashes; + int nb_dashes = pen.GetDashes(&dashes); + return wxGraphicsPenInfo() + .Colour(pen.GetColour()) + .Width(pen.GetWidth()) + .Style(pen.GetStyle()) + .Stipple(*pen.GetStipple()) + .Dashes(nb_dashes, dashes) + .Join(pen.GetJoin()) + .Cap(pen.GetCap()); +} + //----------------------------------------------------------------------------- // matrix //-----------------------------------------------------------------------------