From 4708d2539e8e8dba4ef437f0c57055413725ec65 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Tue, 30 Jul 2019 20:24:20 -0700 Subject: [PATCH 01/41] Add gradient-related attributes to wxGraphicsPenInfo --- include/wx/graphics.h | 121 +++++++++++++++++++++++++++++++--------- interface/wx/graphics.h | 36 ++++++++++++ 2 files changed, 131 insertions(+), 26 deletions(-) diff --git a/include/wx/graphics.h b/include/wx/graphics.h index 86a4444fb0..f3a78b643f 100644 --- a/include/wx/graphics.h +++ b/include/wx/graphics.h @@ -71,6 +71,13 @@ enum wxCompositionMode wxCOMPOSITION_ADD /* R = S + D */ }; +enum wxGradientType { + wxGRADIENT_NONE, + wxGRADIENT_LINEAR, + wxGRADIENT_RADIAL +}; + + class WXDLLIMPEXP_FWD_CORE wxDC; class WXDLLIMPEXP_FWD_CORE wxWindowDC; class WXDLLIMPEXP_FWD_CORE wxMemoryDC; @@ -91,6 +98,7 @@ class WXDLLIMPEXP_FWD_CORE wxGraphicsPen; class WXDLLIMPEXP_FWD_CORE wxGraphicsBrush; class WXDLLIMPEXP_FWD_CORE wxGraphicsFont; class WXDLLIMPEXP_FWD_CORE wxGraphicsBitmap; +class wxGraphicsPenInfo; /* * notes about the graphics context apis @@ -133,33 +141,7 @@ 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 { @@ -449,6 +431,93 @@ private: wxVector m_stops; }; +// ---------------------------------------------------------------------------- +// 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; + m_gradientType = wxGRADIENT_NONE; + } + + // Setters + + wxGraphicsPenInfo& Width(wxDouble width) + { m_width = width; return *this; } + + wxGraphicsPenInfo& + LinearGradient(wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, + const wxColour& c1, const wxColour& c2) + { + m_gradientType = wxGRADIENT_LINEAR; + m_x1 = x1; m_y1 = y1; m_x2 = x2; m_y2 = y2; + m_stops.SetStartColour(c1); + m_stops.SetEndColour(c2); + return *this; + } + + wxGraphicsPenInfo& + LinearGradient(wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, + const wxGraphicsGradientStops& stops) + { + m_gradientType = wxGRADIENT_LINEAR; + m_x1 = x1; m_y1 = y1; m_x2 = x2; m_y2 = y2; + m_stops = stops; + return *this; + } + + wxGraphicsPenInfo& + RadialGradient(wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius, + const wxColour& oColor, const wxColour& cColor) + { + m_gradientType = wxGRADIENT_RADIAL; + m_x1 = xo; m_y1 = yo; m_x2 = xc; m_y2 = yc; + m_stops.SetStartColour(oColor); + m_stops.SetEndColour(cColor); + return *this; + } + + wxGraphicsPenInfo& + RadialGradient(wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, + wxDouble radius, const wxGraphicsGradientStops& stops) + { + m_gradientType = wxGRADIENT_RADIAL; + m_x1 = xo; m_y1 = yo; m_x2 = xc; m_y2 = yc; + m_stops = stops; + return *this; + } + + // Accessors + + wxDouble GetWidth() const { return m_width; } + wxGradientType GetGradientType() const { return m_gradientType; } + wxDouble GetX1() const { return m_x1; } + wxDouble GetY1() const { return m_y1; } + wxDouble GetX2() const { return m_x2; } + wxDouble GetY2() const { return m_y2; } + wxDouble GetXO() const { return m_x1; } + wxDouble GetYO() const { return m_y1; } + wxDouble GetXC() const { return m_x2; } + wxDouble GetYC() const { return m_y2; } + wxDouble GetRadius() const { return m_radius; } + const wxGraphicsGradientStops& GetStops() const { return m_stops; } + +private: + wxDouble m_width; + wxGradientType m_gradientType; + wxDouble m_x1, m_y1, m_x2, m_y2; // also used for m_xo, m_yo, m_xc, m_yx + wxDouble m_radius; + wxGraphicsGradientStops m_stops; +}; + + class WXDLLIMPEXP_CORE wxGraphicsContext : public wxGraphicsObject { public: diff --git a/interface/wx/graphics.h b/interface/wx/graphics.h index 95720f0113..b431691efe 100644 --- a/interface/wx/graphics.h +++ b/interface/wx/graphics.h @@ -305,6 +305,13 @@ enum wxCompositionMode wxCOMPOSITION_ADD /**< @e R = @e S + @e D */ }; +enum wxGradientType { + wxGRADIENT_NONE, + wxGRADIENT_LINEAR, + wxGRADIENT_RADIAL +}; + + /** Represents a bitmap. @@ -1620,6 +1627,35 @@ public: wxGraphicsPenInfo& Join(wxPenJoin join); wxGraphicsPenInfo& Cap(wxPenCap cap); + + wxGraphicsPenInfo& + LinearGradient(wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, + const wxColour& c1, const wxColour& c2); + + wxGraphicsPenInfo& + LinearGradient(wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, + const wxGraphicsGradientStops& stops); + + wxGraphicsPenInfo& + RadialGradient(wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius, + const wxColour& oColor, const wxColour& cColor); + + wxGraphicsPenInfo& + RadialGradient(wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, + wxDouble radius, const wxGraphicsGradientStops& stops); + + wxDouble GetWidth() const; + wxGradientType GetGradientType() const; + wxDouble GetX1() const; + wxDouble GetY1() const; + wxDouble GetX2() const; + wxDouble GetY2() const; + wxDouble GetXO() const; + wxDouble GetYO() const; + wxDouble GetXC() const; + wxDouble GetYC() const; + wxDouble GetRadius() const; + const wxGraphicsGradientStops& GetStops() const; }; From 59ce48924a4d462e1a13592c43009d59619a245b Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Tue, 30 Jul 2019 23:43:48 -0700 Subject: [PATCH 02/41] Add gradient pen support for Cairo --- include/wx/graphics.h | 2 ++ src/generic/graphicc.cpp | 40 +++++++++++++++++++++++++++------------- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/include/wx/graphics.h b/include/wx/graphics.h index f3a78b643f..c23c785953 100644 --- a/include/wx/graphics.h +++ b/include/wx/graphics.h @@ -479,6 +479,7 @@ public: { m_gradientType = wxGRADIENT_RADIAL; m_x1 = xo; m_y1 = yo; m_x2 = xc; m_y2 = yc; + m_radius = radius; m_stops.SetStartColour(oColor); m_stops.SetEndColour(cColor); return *this; @@ -490,6 +491,7 @@ public: { m_gradientType = wxGRADIENT_RADIAL; m_x1 = xo; m_y1 = yo; m_x2 = xc; m_y2 = yc; + m_radius = radius; m_stops = stops; return *this; } diff --git a/src/generic/graphicc.cpp b/src/generic/graphicc.cpp index f855e1e37e..f4c7ccbeff 100644 --- a/src/generic/graphicc.cpp +++ b/src/generic/graphicc.cpp @@ -260,6 +260,13 @@ public: virtual void Apply( wxGraphicsContext* context ); + void CreateLinearGradientBrush(wxDouble x1, wxDouble y1, + wxDouble x2, wxDouble y2, + const wxGraphicsGradientStops& stops); + void CreateRadialGradientBrush(wxDouble xo, wxDouble yo, + wxDouble xc, wxDouble yc, wxDouble radius, + const wxGraphicsGradientStops& stops); + protected: // Call this to use the given bitmap as stipple. Bitmap must be non-null // and valid. @@ -268,6 +275,8 @@ protected: // Call this to use the given hatch style. Hatch style must be valid. void InitHatch(wxHatchStyle hatchStyle); + // common part of Create{Linear,Radial}GradientBrush() + void AddGradientStops(const wxGraphicsGradientStops& stops); double m_red; double m_green; @@ -316,18 +325,8 @@ public: wxCairoBrushData( wxGraphicsRenderer* renderer ); wxCairoBrushData( wxGraphicsRenderer* renderer, const wxBrush &brush ); - void CreateLinearGradientBrush(wxDouble x1, wxDouble y1, - wxDouble x2, wxDouble y2, - const wxGraphicsGradientStops& stops); - void CreateRadialGradientBrush(wxDouble xo, wxDouble yo, - wxDouble xc, wxDouble yc, wxDouble radius, - const wxGraphicsGradientStops& stops); - protected: void Init(); - - // common part of Create{Linear,Radial}GradientBrush() - void AddGradientStops(const wxGraphicsGradientStops& stops); }; class wxCairoFontData : public wxGraphicsObjectRefData @@ -732,6 +731,7 @@ wxCairoPenData::~wxCairoPenData() void wxCairoPenData::Init() { + m_pattern = NULL; m_lengths = NULL; m_userLengths = NULL; m_width = 0; @@ -867,6 +867,20 @@ wxCairoPenData::wxCairoPenData( wxGraphicsRenderer* renderer, const wxGraphicsPe } break; } + + if (info.GetGradientType() == wxGRADIENT_LINEAR) + { + CreateLinearGradientBrush(info.GetX1(), info.GetY1(), + info.GetX2(), info.GetY2(), + info.GetStops()); + } + if (info.GetGradientType() == wxGRADIENT_RADIAL) + { + CreateRadialGradientBrush(info.GetXO(), info.GetYO(), + info.GetXC(), info.GetYC(), + info.GetRadius(), + info.GetStops()); + } } void wxCairoPenData::Apply( wxGraphicsContext* context ) @@ -911,7 +925,7 @@ wxCairoBrushData::wxCairoBrushData( wxGraphicsRenderer* renderer, } } -void wxCairoBrushData::AddGradientStops(const wxGraphicsGradientStops& stops) +void wxCairoPenBrushBaseData::AddGradientStops(const wxGraphicsGradientStops& stops) { // loop over all the stops, they include the beginning and ending ones const unsigned numStops = stops.GetCount(); @@ -937,7 +951,7 @@ void wxCairoBrushData::AddGradientStops(const wxGraphicsGradientStops& stops) } void -wxCairoBrushData::CreateLinearGradientBrush(wxDouble x1, wxDouble y1, +wxCairoPenBrushBaseData::CreateLinearGradientBrush(wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, const wxGraphicsGradientStops& stops) { @@ -947,7 +961,7 @@ wxCairoBrushData::CreateLinearGradientBrush(wxDouble x1, wxDouble y1, } void -wxCairoBrushData::CreateRadialGradientBrush(wxDouble xo, wxDouble yo, +wxCairoPenBrushBaseData::CreateRadialGradientBrush(wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius, const wxGraphicsGradientStops& stops) From 694b7e11fcdffc416edfd16cf2990cb969eb89cf Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Wed, 31 Jul 2019 00:03:37 -0700 Subject: [PATCH 03/41] Move the new methods to the wxCairoPenBrushBaseData section of the file --- src/generic/graphicc.cpp | 92 ++++++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/src/generic/graphicc.cpp b/src/generic/graphicc.cpp index f4c7ccbeff..78bbe25499 100644 --- a/src/generic/graphicc.cpp +++ b/src/generic/graphicc.cpp @@ -720,6 +720,52 @@ void wxCairoPenBrushBaseData::Apply( wxGraphicsContext* context ) cairo_set_source_rgba(ctext, m_red, m_green, m_blue, m_alpha); } +void wxCairoPenBrushBaseData::AddGradientStops(const wxGraphicsGradientStops& stops) +{ + // loop over all the stops, they include the beginning and ending ones + const unsigned numStops = stops.GetCount(); + for ( unsigned n = 0; n < numStops; n++ ) + { + const wxGraphicsGradientStop stop = stops.Item(n); + + const wxColour col = stop.GetColour(); + + cairo_pattern_add_color_stop_rgba + ( + m_pattern, + stop.GetPosition(), + col.Red()/255.0, + col.Green()/255.0, + col.Blue()/255.0, + col.Alpha()/255.0 + ); + } + + wxASSERT_MSG(cairo_pattern_status(m_pattern) == CAIRO_STATUS_SUCCESS, + wxT("Couldn't create cairo pattern")); +} + +void +wxCairoPenBrushBaseData::CreateLinearGradientBrush(wxDouble x1, wxDouble y1, + wxDouble x2, wxDouble y2, + const wxGraphicsGradientStops& stops) +{ + m_pattern = cairo_pattern_create_linear(x1,y1,x2,y2); + + AddGradientStops(stops); +} + +void +wxCairoPenBrushBaseData::CreateRadialGradientBrush(wxDouble xo, wxDouble yo, + wxDouble xc, wxDouble yc, + wxDouble radius, + const wxGraphicsGradientStops& stops) +{ + m_pattern = cairo_pattern_create_radial(xo,yo,0.0,xc,yc,radius); + + AddGradientStops(stops); +} + //----------------------------------------------------------------------------- // wxCairoPenData implementation //----------------------------------------------------------------------------- @@ -925,52 +971,6 @@ wxCairoBrushData::wxCairoBrushData( wxGraphicsRenderer* renderer, } } -void wxCairoPenBrushBaseData::AddGradientStops(const wxGraphicsGradientStops& stops) -{ - // loop over all the stops, they include the beginning and ending ones - const unsigned numStops = stops.GetCount(); - for ( unsigned n = 0; n < numStops; n++ ) - { - const wxGraphicsGradientStop stop = stops.Item(n); - - const wxColour col = stop.GetColour(); - - cairo_pattern_add_color_stop_rgba - ( - m_pattern, - stop.GetPosition(), - col.Red()/255.0, - col.Green()/255.0, - col.Blue()/255.0, - col.Alpha()/255.0 - ); - } - - wxASSERT_MSG(cairo_pattern_status(m_pattern) == CAIRO_STATUS_SUCCESS, - wxT("Couldn't create cairo pattern")); -} - -void -wxCairoPenBrushBaseData::CreateLinearGradientBrush(wxDouble x1, wxDouble y1, - wxDouble x2, wxDouble y2, - const wxGraphicsGradientStops& stops) -{ - m_pattern = cairo_pattern_create_linear(x1,y1,x2,y2); - - AddGradientStops(stops); -} - -void -wxCairoPenBrushBaseData::CreateRadialGradientBrush(wxDouble xo, wxDouble yo, - wxDouble xc, wxDouble yc, - wxDouble radius, - const wxGraphicsGradientStops& stops) -{ - m_pattern = cairo_pattern_create_radial(xo,yo,0.0,xc,yc,radius); - - AddGradientStops(stops); -} - void wxCairoBrushData::Init() { m_pattern = NULL; From 06bf8e0d41370d86f3f7122eab697e818ce56c34 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Wed, 31 Jul 2019 14:33:18 -0700 Subject: [PATCH 04/41] Update include/wx/graphics.h fix opening brace style Co-Authored-By: VZ --- include/wx/graphics.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/wx/graphics.h b/include/wx/graphics.h index c23c785953..9d5d4b80e9 100644 --- a/include/wx/graphics.h +++ b/include/wx/graphics.h @@ -71,7 +71,8 @@ enum wxCompositionMode wxCOMPOSITION_ADD /* R = S + D */ }; -enum wxGradientType { +enum wxGradientType +{ wxGRADIENT_NONE, wxGRADIENT_LINEAR, wxGRADIENT_RADIAL From 0265312297eff1ae196be956d223f26dcefe25e8 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Wed, 31 Jul 2019 14:34:21 -0700 Subject: [PATCH 05/41] Update include/wx/graphics.h fix style Co-Authored-By: VZ --- include/wx/graphics.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/wx/graphics.h b/include/wx/graphics.h index 9d5d4b80e9..739691d1cc 100644 --- a/include/wx/graphics.h +++ b/include/wx/graphics.h @@ -458,7 +458,10 @@ public: const wxColour& c1, const wxColour& c2) { m_gradientType = wxGRADIENT_LINEAR; - m_x1 = x1; m_y1 = y1; m_x2 = x2; m_y2 = y2; + m_x1 = x1; + m_y1 = y1; + m_x2 = x2; + m_y2 = y2; m_stops.SetStartColour(c1); m_stops.SetEndColour(c2); return *this; From 7367f1803db27abad07889f1fd8df91b280d6a19 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Wed, 31 Jul 2019 16:06:44 -0700 Subject: [PATCH 06/41] Reorder classes a bit to resolve ordering conflicts --- include/wx/graphics.h | 346 +++++++++++++++++++++--------------------- 1 file changed, 177 insertions(+), 169 deletions(-) diff --git a/include/wx/graphics.h b/include/wx/graphics.h index 739691d1cc..b8dbb0cb07 100644 --- a/include/wx/graphics.h +++ b/include/wx/graphics.h @@ -99,7 +99,7 @@ class WXDLLIMPEXP_FWD_CORE wxGraphicsPen; class WXDLLIMPEXP_FWD_CORE wxGraphicsBrush; class WXDLLIMPEXP_FWD_CORE wxGraphicsFont; class WXDLLIMPEXP_FWD_CORE wxGraphicsBitmap; -class wxGraphicsPenInfo; + /* * notes about the graphics context apis @@ -143,6 +143,182 @@ protected: }; +// Describes a single gradient stop. +class wxGraphicsGradientStop +{ +public: + wxGraphicsGradientStop(wxColour col = wxTransparentColour, + float pos = 0.) + : m_col(col), + m_pos(pos) + { + } + + // default copy ctor, assignment operator and dtor are ok + + const wxColour& GetColour() const { return m_col; } + void SetColour(const wxColour& col) { m_col = col; } + + float GetPosition() const { return m_pos; } + void SetPosition(float pos) + { + wxASSERT_MSG( pos >= 0 && pos <= 1, "invalid gradient stop position" ); + + m_pos = pos; + } + +private: + // The colour of this gradient band. + wxColour m_col; + + // Its starting position: 0 is the beginning and 1 is the end. + float m_pos; +}; + +// A collection of gradient stops ordered by their positions (from lowest to +// highest). The first stop (index 0, position 0.0) is always the starting +// colour and the last one (index GetCount() - 1, position 1.0) is the end +// colour. +class WXDLLIMPEXP_CORE wxGraphicsGradientStops +{ +public: + wxGraphicsGradientStops(wxColour startCol = wxTransparentColour, + wxColour endCol = wxTransparentColour) + { + // we can't use Add() here as it relies on having start/end stops as + // first/last array elements so do it manually + m_stops.push_back(wxGraphicsGradientStop(startCol, 0.f)); + m_stops.push_back(wxGraphicsGradientStop(endCol, 1.f)); + } + + // default copy ctor, assignment operator and dtor are ok for this class + + + // Add a stop in correct order. + void Add(const wxGraphicsGradientStop& stop); + void Add(wxColour col, float pos) { Add(wxGraphicsGradientStop(col, pos)); } + + // Get the number of stops. + size_t GetCount() const { return m_stops.size(); } + + // Return the stop at the given index (which must be valid). + wxGraphicsGradientStop Item(unsigned n) const { return m_stops.at(n); } + + // Get/set start and end colours. + void SetStartColour(wxColour col) + { m_stops[0].SetColour(col); } + wxColour GetStartColour() const + { return m_stops[0].GetColour(); } + void SetEndColour(wxColour col) + { m_stops[m_stops.size() - 1].SetColour(col); } + wxColour GetEndColour() const + { return m_stops[m_stops.size() - 1].GetColour(); } + +private: + // All the stops stored in ascending order of positions. + wxVector m_stops; +}; + +// ---------------------------------------------------------------------------- +// 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; + m_gradientType = wxGRADIENT_NONE; + } + + // Setters + + wxGraphicsPenInfo& Width(wxDouble width) + { m_width = width; return *this; } + + wxGraphicsPenInfo& + LinearGradient(wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, + const wxColour& c1, const wxColour& c2) + { + m_gradientType = wxGRADIENT_LINEAR; + m_x1 = x1; + m_y1 = y1; + m_x2 = x2; + m_y2 = y2; + m_stops.SetStartColour(c1); + m_stops.SetEndColour(c2); + return *this; + } + + wxGraphicsPenInfo& + LinearGradient(wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, + const wxGraphicsGradientStops& stops) + { + m_gradientType = wxGRADIENT_LINEAR; + m_x1 = x1; + m_y1 = y1; + m_x2 = x2; + m_y2 = y2; + m_stops = stops; + return *this; + } + + wxGraphicsPenInfo& + RadialGradient(wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius, + const wxColour& oColor, const wxColour& cColor) + { + m_gradientType = wxGRADIENT_RADIAL; + m_x1 = xo; + m_y1 = yo; + m_x2 = xc; + m_y2 = yc; + m_radius = radius; + m_stops.SetStartColour(oColor); + m_stops.SetEndColour(cColor); + return *this; + } + + wxGraphicsPenInfo& + RadialGradient(wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, + wxDouble radius, const wxGraphicsGradientStops& stops) + { + m_gradientType = wxGRADIENT_RADIAL; + m_x1 = xo; + m_y1 = yo; + m_x2 = xc; + m_y2 = yc; + m_radius = radius; + m_stops = stops; + return *this; + } + + // Accessors + + wxDouble GetWidth() const { return m_width; } + wxGradientType GetGradientType() const { return m_gradientType; } + wxDouble GetX1() const { return m_x1; } + wxDouble GetY1() const { return m_y1; } + wxDouble GetX2() const { return m_x2; } + wxDouble GetY2() const { return m_y2; } + wxDouble GetXO() const { return m_x1; } + wxDouble GetYO() const { return m_y1; } + wxDouble GetXC() const { return m_x2; } + wxDouble GetYC() const { return m_y2; } + wxDouble GetRadius() const { return m_radius; } + const wxGraphicsGradientStops& GetStops() const { return m_stops; } + +private: + wxDouble m_width; + wxGradientType m_gradientType; + wxDouble m_x1, m_y1, m_x2, m_y2; // also used for m_xo, m_yo, m_xc, m_yx + wxDouble m_radius; + wxGraphicsGradientStops m_stops; +}; + class WXDLLIMPEXP_CORE wxGraphicsPen : public wxGraphicsObject { @@ -356,174 +532,6 @@ private: extern WXDLLIMPEXP_DATA_CORE(wxGraphicsPath) wxNullGraphicsPath; -// Describes a single gradient stop. -class wxGraphicsGradientStop -{ -public: - wxGraphicsGradientStop(wxColour col = wxTransparentColour, - float pos = 0.) - : m_col(col), - m_pos(pos) - { - } - - // default copy ctor, assignment operator and dtor are ok - - const wxColour& GetColour() const { return m_col; } - void SetColour(const wxColour& col) { m_col = col; } - - float GetPosition() const { return m_pos; } - void SetPosition(float pos) - { - wxASSERT_MSG( pos >= 0 && pos <= 1, "invalid gradient stop position" ); - - m_pos = pos; - } - -private: - // The colour of this gradient band. - wxColour m_col; - - // Its starting position: 0 is the beginning and 1 is the end. - float m_pos; -}; - -// A collection of gradient stops ordered by their positions (from lowest to -// highest). The first stop (index 0, position 0.0) is always the starting -// colour and the last one (index GetCount() - 1, position 1.0) is the end -// colour. -class WXDLLIMPEXP_CORE wxGraphicsGradientStops -{ -public: - wxGraphicsGradientStops(wxColour startCol = wxTransparentColour, - wxColour endCol = wxTransparentColour) - { - // we can't use Add() here as it relies on having start/end stops as - // first/last array elements so do it manually - m_stops.push_back(wxGraphicsGradientStop(startCol, 0.f)); - m_stops.push_back(wxGraphicsGradientStop(endCol, 1.f)); - } - - // default copy ctor, assignment operator and dtor are ok for this class - - - // Add a stop in correct order. - void Add(const wxGraphicsGradientStop& stop); - void Add(wxColour col, float pos) { Add(wxGraphicsGradientStop(col, pos)); } - - // Get the number of stops. - size_t GetCount() const { return m_stops.size(); } - - // Return the stop at the given index (which must be valid). - wxGraphicsGradientStop Item(unsigned n) const { return m_stops.at(n); } - - // Get/set start and end colours. - void SetStartColour(wxColour col) - { m_stops[0].SetColour(col); } - wxColour GetStartColour() const - { return m_stops[0].GetColour(); } - void SetEndColour(wxColour col) - { m_stops[m_stops.size() - 1].SetColour(col); } - wxColour GetEndColour() const - { return m_stops[m_stops.size() - 1].GetColour(); } - -private: - // All the stops stored in ascending order of positions. - wxVector m_stops; -}; - -// ---------------------------------------------------------------------------- -// 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; - m_gradientType = wxGRADIENT_NONE; - } - - // Setters - - wxGraphicsPenInfo& Width(wxDouble width) - { m_width = width; return *this; } - - wxGraphicsPenInfo& - LinearGradient(wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, - const wxColour& c1, const wxColour& c2) - { - m_gradientType = wxGRADIENT_LINEAR; - m_x1 = x1; - m_y1 = y1; - m_x2 = x2; - m_y2 = y2; - m_stops.SetStartColour(c1); - m_stops.SetEndColour(c2); - return *this; - } - - wxGraphicsPenInfo& - LinearGradient(wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, - const wxGraphicsGradientStops& stops) - { - m_gradientType = wxGRADIENT_LINEAR; - m_x1 = x1; m_y1 = y1; m_x2 = x2; m_y2 = y2; - m_stops = stops; - return *this; - } - - wxGraphicsPenInfo& - RadialGradient(wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius, - const wxColour& oColor, const wxColour& cColor) - { - m_gradientType = wxGRADIENT_RADIAL; - m_x1 = xo; m_y1 = yo; m_x2 = xc; m_y2 = yc; - m_radius = radius; - m_stops.SetStartColour(oColor); - m_stops.SetEndColour(cColor); - return *this; - } - - wxGraphicsPenInfo& - RadialGradient(wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, - wxDouble radius, const wxGraphicsGradientStops& stops) - { - m_gradientType = wxGRADIENT_RADIAL; - m_x1 = xo; m_y1 = yo; m_x2 = xc; m_y2 = yc; - m_radius = radius; - m_stops = stops; - return *this; - } - - // Accessors - - wxDouble GetWidth() const { return m_width; } - wxGradientType GetGradientType() const { return m_gradientType; } - wxDouble GetX1() const { return m_x1; } - wxDouble GetY1() const { return m_y1; } - wxDouble GetX2() const { return m_x2; } - wxDouble GetY2() const { return m_y2; } - wxDouble GetXO() const { return m_x1; } - wxDouble GetYO() const { return m_y1; } - wxDouble GetXC() const { return m_x2; } - wxDouble GetYC() const { return m_y2; } - wxDouble GetRadius() const { return m_radius; } - const wxGraphicsGradientStops& GetStops() const { return m_stops; } - -private: - wxDouble m_width; - wxGradientType m_gradientType; - wxDouble m_x1, m_y1, m_x2, m_y2; // also used for m_xo, m_yo, m_xc, m_yx - wxDouble m_radius; - wxGraphicsGradientStops m_stops; -}; - - class WXDLLIMPEXP_CORE wxGraphicsContext : public wxGraphicsObject { public: From e297b5ded96dd11471fbff94b7104157fe47215e Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Wed, 31 Jul 2019 16:07:58 -0700 Subject: [PATCH 07/41] Deindent inline code blocks --- include/wx/graphics.h | 80 +++++++++++++++++++++---------------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/include/wx/graphics.h b/include/wx/graphics.h index b8dbb0cb07..f4b75a32e4 100644 --- a/include/wx/graphics.h +++ b/include/wx/graphics.h @@ -243,58 +243,58 @@ public: wxGraphicsPenInfo& LinearGradient(wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, const wxColour& c1, const wxColour& c2) - { - m_gradientType = wxGRADIENT_LINEAR; - m_x1 = x1; - m_y1 = y1; - m_x2 = x2; - m_y2 = y2; - m_stops.SetStartColour(c1); - m_stops.SetEndColour(c2); - return *this; - } + { + m_gradientType = wxGRADIENT_LINEAR; + m_x1 = x1; + m_y1 = y1; + m_x2 = x2; + m_y2 = y2; + m_stops.SetStartColour(c1); + m_stops.SetEndColour(c2); + return *this; + } wxGraphicsPenInfo& LinearGradient(wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, const wxGraphicsGradientStops& stops) - { - m_gradientType = wxGRADIENT_LINEAR; - m_x1 = x1; - m_y1 = y1; - m_x2 = x2; - m_y2 = y2; - m_stops = stops; - return *this; - } + { + m_gradientType = wxGRADIENT_LINEAR; + m_x1 = x1; + m_y1 = y1; + m_x2 = x2; + m_y2 = y2; + m_stops = stops; + return *this; + } wxGraphicsPenInfo& RadialGradient(wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius, const wxColour& oColor, const wxColour& cColor) - { - m_gradientType = wxGRADIENT_RADIAL; - m_x1 = xo; - m_y1 = yo; - m_x2 = xc; - m_y2 = yc; - m_radius = radius; - m_stops.SetStartColour(oColor); - m_stops.SetEndColour(cColor); - return *this; - } + { + m_gradientType = wxGRADIENT_RADIAL; + m_x1 = xo; + m_y1 = yo; + m_x2 = xc; + m_y2 = yc; + m_radius = radius; + m_stops.SetStartColour(oColor); + m_stops.SetEndColour(cColor); + return *this; + } wxGraphicsPenInfo& RadialGradient(wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius, const wxGraphicsGradientStops& stops) - { - m_gradientType = wxGRADIENT_RADIAL; - m_x1 = xo; - m_y1 = yo; - m_x2 = xc; - m_y2 = yc; - m_radius = radius; - m_stops = stops; - return *this; - } + { + m_gradientType = wxGRADIENT_RADIAL; + m_x1 = xo; + m_y1 = yo; + m_x2 = xc; + m_y2 = yc; + m_radius = radius; + m_stops = stops; + return *this; + } // Accessors From c860d50888f4cd89dc633d588f1a482d0b53763d Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Wed, 31 Jul 2019 16:23:21 -0700 Subject: [PATCH 08/41] Rename some *GradientBrush to *GradientPattern --- src/generic/graphicc.cpp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/generic/graphicc.cpp b/src/generic/graphicc.cpp index 78bbe25499..cd3b08e3dd 100644 --- a/src/generic/graphicc.cpp +++ b/src/generic/graphicc.cpp @@ -260,12 +260,12 @@ public: virtual void Apply( wxGraphicsContext* context ); - void CreateLinearGradientBrush(wxDouble x1, wxDouble y1, - wxDouble x2, wxDouble y2, - const wxGraphicsGradientStops& stops); - void CreateRadialGradientBrush(wxDouble xo, wxDouble yo, - wxDouble xc, wxDouble yc, wxDouble radius, - const wxGraphicsGradientStops& stops); + void CreateLinearGradientPattern(wxDouble x1, wxDouble y1, + wxDouble x2, wxDouble y2, + const wxGraphicsGradientStops& stops); + void CreateRadialGradientPattern(wxDouble xo, wxDouble yo, + wxDouble xc, wxDouble yc, wxDouble radius, + const wxGraphicsGradientStops& stops); protected: // Call this to use the given bitmap as stipple. Bitmap must be non-null @@ -275,7 +275,7 @@ protected: // Call this to use the given hatch style. Hatch style must be valid. void InitHatch(wxHatchStyle hatchStyle); - // common part of Create{Linear,Radial}GradientBrush() + // common part of Create{Linear,Radial}GradientPattern() void AddGradientStops(const wxGraphicsGradientStops& stops); double m_red; @@ -746,9 +746,9 @@ void wxCairoPenBrushBaseData::AddGradientStops(const wxGraphicsGradientStops& st } void -wxCairoPenBrushBaseData::CreateLinearGradientBrush(wxDouble x1, wxDouble y1, - wxDouble x2, wxDouble y2, - const wxGraphicsGradientStops& stops) +wxCairoPenBrushBaseData::CreateLinearGradientPattern(wxDouble x1, wxDouble y1, + wxDouble x2, wxDouble y2, + const wxGraphicsGradientStops& stops) { m_pattern = cairo_pattern_create_linear(x1,y1,x2,y2); @@ -756,10 +756,10 @@ wxCairoPenBrushBaseData::CreateLinearGradientBrush(wxDouble x1, wxDouble y1, } void -wxCairoPenBrushBaseData::CreateRadialGradientBrush(wxDouble xo, wxDouble yo, - wxDouble xc, wxDouble yc, - wxDouble radius, - const wxGraphicsGradientStops& stops) +wxCairoPenBrushBaseData::CreateRadialGradientPattern(wxDouble xo, wxDouble yo, + wxDouble xc, wxDouble yc, + wxDouble radius, + const wxGraphicsGradientStops& stops) { m_pattern = cairo_pattern_create_radial(xo,yo,0.0,xc,yc,radius); @@ -3169,7 +3169,7 @@ wxCairoRenderer::CreateLinearGradientBrush(wxDouble x1, wxDouble y1, wxGraphicsBrush p; ENSURE_LOADED_OR_RETURN(p); wxCairoBrushData* d = new wxCairoBrushData( this ); - d->CreateLinearGradientBrush(x1, y1, x2, y2, stops); + d->CreateLinearGradientPattern(x1, y1, x2, y2, stops); p.SetRefData(d); return p; } @@ -3182,7 +3182,7 @@ wxCairoRenderer::CreateRadialGradientBrush(wxDouble xo, wxDouble yo, wxGraphicsBrush p; ENSURE_LOADED_OR_RETURN(p); wxCairoBrushData* d = new wxCairoBrushData( this ); - d->CreateRadialGradientBrush(xo, yo, xc, yc, r, stops); + d->CreateRadialGradientPattern(xo, yo, xc, yc, r, stops); p.SetRefData(d); return p; } From b98ab8b56d02bada46c62d034086612a92caf444 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Wed, 31 Jul 2019 16:26:22 -0700 Subject: [PATCH 09/41] Switch to a switch statement --- src/generic/graphicc.cpp | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/generic/graphicc.cpp b/src/generic/graphicc.cpp index cd3b08e3dd..75de5b096b 100644 --- a/src/generic/graphicc.cpp +++ b/src/generic/graphicc.cpp @@ -914,18 +914,23 @@ wxCairoPenData::wxCairoPenData( wxGraphicsRenderer* renderer, const wxGraphicsPe break; } - if (info.GetGradientType() == wxGRADIENT_LINEAR) + switch ( info.GetGradientType() ) { - CreateLinearGradientBrush(info.GetX1(), info.GetY1(), - info.GetX2(), info.GetY2(), - info.GetStops()); - } - if (info.GetGradientType() == wxGRADIENT_RADIAL) - { - CreateRadialGradientBrush(info.GetXO(), info.GetYO(), - info.GetXC(), info.GetYC(), - info.GetRadius(), - info.GetStops()); + case wxGRADIENT_NONE: + break; + + case wxGRADIENT_LINEAR: + CreateLinearGradientPattern(info.GetX1(), info.GetY1(), + info.GetX2(), info.GetY2(), + info.GetStops()); + break; + + case wxGRADIENT_RADIAL: + CreateRadialGradientPattern(info.GetXO(), info.GetYO(), + info.GetXC(), info.GetYC(), + info.GetRadius(), + info.GetStops()); + break; } } From fd0b19f27790ce598b14f625c82208338ced4c2b Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Wed, 31 Jul 2019 16:39:37 -0700 Subject: [PATCH 10/41] Add the rest of the accessors in wxPenInfo and wxGraphicsPenInfo, so wxPython can see them. --- interface/wx/graphics.h | 9 +++++++++ interface/wx/pen.h | 11 +++++++++++ 2 files changed, 20 insertions(+) diff --git a/interface/wx/graphics.h b/interface/wx/graphics.h index b431691efe..6893f25b57 100644 --- a/interface/wx/graphics.h +++ b/interface/wx/graphics.h @@ -1644,6 +1644,15 @@ public: RadialGradient(wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius, const wxGraphicsGradientStops& stops); + wxColour GetColour() const; + wxBitmap GetStipple() const; + wxPenStyle GetStyle() const; + wxPenJoin GetJoin() const; + wxPenCap GetCap() const; + int GetDashes(wxDash **ptr); + int GetDashCount() const; + wxDash* GetDash() const; + bool IsTransparent() const; wxDouble GetWidth() const; wxGradientType GetGradientType() const; wxDouble GetX1() const; diff --git a/interface/wx/pen.h b/interface/wx/pen.h index d6df1c3f4d..ceeab7ad9e 100644 --- a/interface/wx/pen.h +++ b/interface/wx/pen.h @@ -137,6 +137,17 @@ public: wxPenInfo& Join(wxPenJoin join); wxPenInfo& Cap(wxPenCap cap); + + wxColour GetColour() const; + wxBitmap GetStipple() const; + wxPenStyle GetStyle() const; + wxPenJoin GetJoin() const; + wxPenCap GetCap() const; + int GetDashes(wxDash **ptr); + int GetDashCount() const; + wxDash* GetDash() const; + bool IsTransparent() const; + int GetWidth() const; }; From 7c33d3f9690bbc4daa7051f49aa9b2f98843fc6c Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Wed, 31 Jul 2019 19:29:55 -0700 Subject: [PATCH 11/41] Gradients can have matrix transforms too. Updates for Cairo. --- include/wx/graphics.h | 38 ++++++++++++++++++++++--------- interface/wx/graphics.h | 30 ++++++++++++++++-------- src/common/graphcmn.cpp | 49 +++++++++++++++++++++++++--------------- src/generic/graphicc.cpp | 47 ++++++++++++++++++++++++++++---------- 4 files changed, 113 insertions(+), 51 deletions(-) diff --git a/include/wx/graphics.h b/include/wx/graphics.h index f4b75a32e4..c43a827c7c 100644 --- a/include/wx/graphics.h +++ b/include/wx/graphics.h @@ -242,7 +242,8 @@ public: wxGraphicsPenInfo& LinearGradient(wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, - const wxColour& c1, const wxColour& c2) + const wxColour& c1, const wxColour& c2, + const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) { m_gradientType = wxGRADIENT_LINEAR; m_x1 = x1; @@ -251,12 +252,14 @@ public: m_y2 = y2; m_stops.SetStartColour(c1); m_stops.SetEndColour(c2); + m_matrix = matrix; return *this; } wxGraphicsPenInfo& LinearGradient(wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, - const wxGraphicsGradientStops& stops) + const wxGraphicsGradientStops& stops, + const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) { m_gradientType = wxGRADIENT_LINEAR; m_x1 = x1; @@ -264,27 +267,31 @@ public: m_x2 = x2; m_y2 = y2; m_stops = stops; + m_matrix = matrix; return *this; } wxGraphicsPenInfo& RadialGradient(wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius, - const wxColour& oColor, const wxColour& cColor) + const wxColour& oColor, const wxColour& cColor, + const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) { m_gradientType = wxGRADIENT_RADIAL; - m_x1 = xo; + m_x1 = xo; m_y1 = yo; m_x2 = xc; m_y2 = yc; m_radius = radius; m_stops.SetStartColour(oColor); m_stops.SetEndColour(cColor); + m_matrix = matrix; return *this; } wxGraphicsPenInfo& RadialGradient(wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, - wxDouble radius, const wxGraphicsGradientStops& stops) + wxDouble radius, const wxGraphicsGradientStops& stops, + const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) { m_gradientType = wxGRADIENT_RADIAL; m_x1 = xo; @@ -293,6 +300,7 @@ public: m_y2 = yc; m_radius = radius; m_stops = stops; + m_matrix = matrix; return *this; } @@ -310,6 +318,7 @@ public: wxDouble GetYC() const { return m_y2; } wxDouble GetRadius() const { return m_radius; } const wxGraphicsGradientStops& GetStops() const { return m_stops; } + const wxGraphicsMatrix& GetMatrix() const { return m_matrix; } private: wxDouble m_width; @@ -317,6 +326,7 @@ private: wxDouble m_x1, m_y1, m_x2, m_y2; // also used for m_xo, m_yo, m_xc, m_yx wxDouble m_radius; wxGraphicsGradientStops m_stops; + wxGraphicsMatrix m_matrix; }; @@ -606,11 +616,13 @@ public: wxGraphicsBrush CreateLinearGradientBrush(wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, - const wxColour& c1, const wxColour& c2) const; + const wxColour& c1, const wxColour& c2, + const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) const; wxGraphicsBrush CreateLinearGradientBrush(wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, - const wxGraphicsGradientStops& stops) const; + const wxGraphicsGradientStops& stops, + const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) const; // sets the brush to a radial gradient originating at (xo,yc) and ending // on a circle around (xc,yc) with the given radius; the colours may be @@ -618,12 +630,14 @@ public: wxGraphicsBrush CreateRadialGradientBrush(wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius, - const wxColour& oColor, const wxColour& cColor) const; + const wxColour& oColor, const wxColour& cColor, + const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) const; wxGraphicsBrush CreateRadialGradientBrush(wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius, - const wxGraphicsGradientStops& stops) const; + const wxGraphicsGradientStops& stops, + const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) const; // creates a font virtual wxGraphicsFont CreateFont( const wxFont &font , const wxColour &col = *wxBLACK ) const; @@ -999,13 +1013,15 @@ public: virtual wxGraphicsBrush CreateLinearGradientBrush(wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, - const wxGraphicsGradientStops& stops) = 0; + const wxGraphicsGradientStops& stops, + const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) = 0; virtual wxGraphicsBrush CreateRadialGradientBrush(wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius, - const wxGraphicsGradientStops& stops) = 0; + const wxGraphicsGradientStops& stops, + const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) = 0; // sets the font virtual wxGraphicsFont CreateFont( const wxFont &font , const wxColour &col = *wxBLACK ) = 0; diff --git a/interface/wx/graphics.h b/interface/wx/graphics.h index 6893f25b57..b9ebcb4a02 100644 --- a/interface/wx/graphics.h +++ b/interface/wx/graphics.h @@ -644,7 +644,8 @@ public: wxGraphicsBrush CreateLinearGradientBrush(wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, - const wxColour& c1, const wxColour& c2) const; + const wxColour& c1, const wxColour& c2, + const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) const; /** @overload @@ -652,7 +653,8 @@ public: wxGraphicsBrush CreateLinearGradientBrush(wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, - const wxGraphicsGradientStops& stops) const; + const wxGraphicsGradientStops& stops, + const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) const; /** Creates a native brush with a radial gradient. @@ -670,7 +672,8 @@ public: wxDouble xc, wxDouble yc, wxDouble radius, const wxColour& oColor, - const wxColour& cColor) const; + const wxColour& cColor, + const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) const; /** @overload @@ -679,7 +682,8 @@ public: CreateRadialGradientBrush(wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius, - const wxGraphicsGradientStops& stops) = 0; + const wxGraphicsGradientStops& stops, + const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) = 0; /** Sets the brush for filling paths. @@ -1456,7 +1460,8 @@ public: wxDouble y1, wxDouble x2, wxDouble y2, - const wxGraphicsGradientStops& stops) = 0; + const wxGraphicsGradientStops& stops, + const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) = 0; /** Creates a native affine transformation matrix from the passed in @@ -1488,7 +1493,8 @@ public: virtual wxGraphicsBrush CreateRadialGradientBrush(wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius, - const wxGraphicsGradientStops& stops) = 0; + const wxGraphicsGradientStops& stops, + const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) = 0; /** Extracts a sub-bitmap from an existing bitmap. @@ -1630,19 +1636,23 @@ public: wxGraphicsPenInfo& LinearGradient(wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, - const wxColour& c1, const wxColour& c2); + const wxColour& c1, const wxColour& c2, + const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix); wxGraphicsPenInfo& LinearGradient(wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, - const wxGraphicsGradientStops& stops); + const wxGraphicsGradientStops& stops, + const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix); wxGraphicsPenInfo& RadialGradient(wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius, - const wxColour& oColor, const wxColour& cColor); + const wxColour& oColor, const wxColour& cColor, + const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix); wxGraphicsPenInfo& RadialGradient(wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, - wxDouble radius, const wxGraphicsGradientStops& stops); + wxDouble radius, const wxGraphicsGradientStops& stops, + const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix); wxColour GetColour() const; wxBitmap GetStipple() const; diff --git a/src/common/graphcmn.cpp b/src/common/graphcmn.cpp index e558a254f3..460b16c9df 100644 --- a/src/common/graphcmn.cpp +++ b/src/common/graphcmn.cpp @@ -883,13 +883,15 @@ wxGraphicsBrush wxGraphicsContext::CreateLinearGradientBrush( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, - const wxColour& c1, const wxColour& c2) const + const wxColour& c1, const wxColour& c2, + const wxGraphicsMatrix& matrix) const { return GetRenderer()->CreateLinearGradientBrush ( x1, y1, x2, y2, - wxGraphicsGradientStops(c1,c2) + wxGraphicsGradientStops(c1,c2), + matrix ); } @@ -897,22 +899,15 @@ wxGraphicsBrush wxGraphicsContext::CreateLinearGradientBrush( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, - const wxGraphicsGradientStops& gradientStops) const + const wxGraphicsGradientStops& gradientStops, + const wxGraphicsMatrix& matrix) const { - return GetRenderer()->CreateLinearGradientBrush(x1,y1,x2,y2, gradientStops); -} - -wxGraphicsBrush -wxGraphicsContext::CreateRadialGradientBrush( - wxDouble xo, wxDouble yo, - wxDouble xc, wxDouble yc, wxDouble radius, - const wxColour &oColor, const wxColour &cColor) const -{ - return GetRenderer()->CreateRadialGradientBrush + return GetRenderer()->CreateLinearGradientBrush ( - xo, yo, - xc, yc, radius, - wxGraphicsGradientStops(oColor, cColor) + x1, y1, + x2, y2, + gradientStops, + matrix ); } @@ -920,13 +915,31 @@ wxGraphicsBrush wxGraphicsContext::CreateRadialGradientBrush( wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius, - const wxGraphicsGradientStops& gradientStops) const + const wxColour &oColor, const wxColour &cColor, + const wxGraphicsMatrix& matrix) const { return GetRenderer()->CreateRadialGradientBrush ( xo, yo, xc, yc, radius, - gradientStops + wxGraphicsGradientStops(oColor, cColor), + matrix + ); +} + +wxGraphicsBrush +wxGraphicsContext::CreateRadialGradientBrush( + wxDouble xo, wxDouble yo, + wxDouble xc, wxDouble yc, wxDouble radius, + const wxGraphicsGradientStops& gradientStops, + const wxGraphicsMatrix& matrix) const +{ + return GetRenderer()->CreateRadialGradientBrush + ( + xo, yo, + xc, yc, radius, + gradientStops, + matrix ); } diff --git a/src/generic/graphicc.cpp b/src/generic/graphicc.cpp index 75de5b096b..5366b8ac1e 100644 --- a/src/generic/graphicc.cpp +++ b/src/generic/graphicc.cpp @@ -262,10 +262,12 @@ public: void CreateLinearGradientPattern(wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, - const wxGraphicsGradientStops& stops); + const wxGraphicsGradientStops& stops, + const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix); void CreateRadialGradientPattern(wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius, - const wxGraphicsGradientStops& stops); + const wxGraphicsGradientStops& stops, + const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix); protected: // Call this to use the given bitmap as stipple. Bitmap must be non-null @@ -748,10 +750,17 @@ void wxCairoPenBrushBaseData::AddGradientStops(const wxGraphicsGradientStops& st void wxCairoPenBrushBaseData::CreateLinearGradientPattern(wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, - const wxGraphicsGradientStops& stops) + const wxGraphicsGradientStops& stops, + const wxGraphicsMatrix& matrix) { m_pattern = cairo_pattern_create_linear(x1,y1,x2,y2); + if (! matrix.IsNull()) + { + cairo_matrix_t m = *((cairo_matrix_t*) matrix.GetNativeMatrix()); + cairo_pattern_set_matrix(m_pattern, &m); + } + AddGradientStops(stops); } @@ -759,10 +768,17 @@ void wxCairoPenBrushBaseData::CreateRadialGradientPattern(wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius, - const wxGraphicsGradientStops& stops) + const wxGraphicsGradientStops& stops, + const wxGraphicsMatrix& matrix) { m_pattern = cairo_pattern_create_radial(xo,yo,0.0,xc,yc,radius); + if (! matrix.IsNull()) + { + cairo_matrix_t m = *((cairo_matrix_t*) matrix.GetNativeMatrix()); + cairo_pattern_set_matrix(m_pattern, &m); + } + AddGradientStops(stops); } @@ -922,14 +938,16 @@ wxCairoPenData::wxCairoPenData( wxGraphicsRenderer* renderer, const wxGraphicsPe case wxGRADIENT_LINEAR: CreateLinearGradientPattern(info.GetX1(), info.GetY1(), info.GetX2(), info.GetY2(), - info.GetStops()); + info.GetStops(), + info.GetMatrix()); break; case wxGRADIENT_RADIAL: CreateRadialGradientPattern(info.GetXO(), info.GetYO(), info.GetXC(), info.GetYC(), info.GetRadius(), - info.GetStops()); + info.GetStops(), + info.GetMatrix()); break; } } @@ -2975,13 +2993,15 @@ public : virtual wxGraphicsBrush CreateLinearGradientBrush(wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, - const wxGraphicsGradientStops& stops) wxOVERRIDE; + const wxGraphicsGradientStops& stops, + const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) wxOVERRIDE; virtual wxGraphicsBrush CreateRadialGradientBrush(wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius, - const wxGraphicsGradientStops& stops) wxOVERRIDE; + const wxGraphicsGradientStops& stops, + const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) wxOVERRIDE; // sets the font virtual wxGraphicsFont CreateFont( const wxFont &font , const wxColour &col = *wxBLACK ) wxOVERRIDE ; @@ -3169,12 +3189,13 @@ wxGraphicsBrush wxCairoRenderer::CreateBrush(const wxBrush& brush ) wxGraphicsBrush wxCairoRenderer::CreateLinearGradientBrush(wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, - const wxGraphicsGradientStops& stops) + const wxGraphicsGradientStops& stops, + const wxGraphicsMatrix& matrix) { wxGraphicsBrush p; ENSURE_LOADED_OR_RETURN(p); wxCairoBrushData* d = new wxCairoBrushData( this ); - d->CreateLinearGradientPattern(x1, y1, x2, y2, stops); + d->CreateLinearGradientPattern(x1, y1, x2, y2, stops, matrix); p.SetRefData(d); return p; } @@ -3182,16 +3203,18 @@ wxCairoRenderer::CreateLinearGradientBrush(wxDouble x1, wxDouble y1, wxGraphicsBrush wxCairoRenderer::CreateRadialGradientBrush(wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble r, - const wxGraphicsGradientStops& stops) + const wxGraphicsGradientStops& stops, + const wxGraphicsMatrix& matrix) { wxGraphicsBrush p; ENSURE_LOADED_OR_RETURN(p); wxCairoBrushData* d = new wxCairoBrushData( this ); - d->CreateRadialGradientPattern(xo, yo, xc, yc, r, stops); + d->CreateRadialGradientPattern(xo, yo, xc, yc, r, stops, matrix); p.SetRefData(d); return p; } + wxGraphicsFont wxCairoRenderer::CreateFont( const wxFont &font , const wxColour &col ) { wxGraphicsFont p; From 62ea72e937007418171c1d90f20c25b020162ad3 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Wed, 31 Jul 2019 19:38:20 -0700 Subject: [PATCH 12/41] Adding a matrix to wxGraphicsPenInfo means the classes need reordered again --- include/wx/graphics.h | 255 ++++++++++++++++++++++-------------------- 1 file changed, 131 insertions(+), 124 deletions(-) diff --git a/include/wx/graphics.h b/include/wx/graphics.h index c43a827c7c..50c12f95ab 100644 --- a/include/wx/graphics.h +++ b/include/wx/graphics.h @@ -143,6 +143,137 @@ protected: }; + +class WXDLLIMPEXP_CORE wxGraphicsPen : public wxGraphicsObject +{ +public: + wxGraphicsPen() {} + virtual ~wxGraphicsPen() {} +private: + wxDECLARE_DYNAMIC_CLASS(wxGraphicsPen); +}; + +extern WXDLLIMPEXP_DATA_CORE(wxGraphicsPen) wxNullGraphicsPen; + +class WXDLLIMPEXP_CORE wxGraphicsBrush : public wxGraphicsObject +{ +public: + wxGraphicsBrush() {} + virtual ~wxGraphicsBrush() {} +private: + wxDECLARE_DYNAMIC_CLASS(wxGraphicsBrush); +}; + +extern WXDLLIMPEXP_DATA_CORE(wxGraphicsBrush) wxNullGraphicsBrush; + +class WXDLLIMPEXP_CORE wxGraphicsFont : public wxGraphicsObject +{ +public: + wxGraphicsFont() {} + virtual ~wxGraphicsFont() {} +private: + wxDECLARE_DYNAMIC_CLASS(wxGraphicsFont); +}; + +extern WXDLLIMPEXP_DATA_CORE(wxGraphicsFont) wxNullGraphicsFont; + +class WXDLLIMPEXP_CORE wxGraphicsBitmap : public wxGraphicsObject +{ +public: + wxGraphicsBitmap() {} + virtual ~wxGraphicsBitmap() {} + + // Convert bitmap to wxImage: this is more efficient than converting to + // wxBitmap first and then to wxImage and also works without X server + // connection under Unix that wxBitmap requires. +#if wxUSE_IMAGE + wxImage ConvertToImage() const; +#endif // wxUSE_IMAGE + + void* GetNativeBitmap() const; + + const wxGraphicsBitmapData* GetBitmapData() const + { return (const wxGraphicsBitmapData*) GetRefData(); } + wxGraphicsBitmapData* GetBitmapData() + { return (wxGraphicsBitmapData*) GetRefData(); } + +private: + wxDECLARE_DYNAMIC_CLASS(wxGraphicsBitmap); +}; + +extern WXDLLIMPEXP_DATA_CORE(wxGraphicsBitmap) wxNullGraphicsBitmap; + +class WXDLLIMPEXP_CORE wxGraphicsMatrix : public wxGraphicsObject +{ +public: + wxGraphicsMatrix() {} + + virtual ~wxGraphicsMatrix() {} + + // concatenates the matrix + virtual void Concat( const wxGraphicsMatrix *t ); + void Concat( const wxGraphicsMatrix &t ) { Concat( &t ); } + + // sets the matrix to the respective values + virtual void Set(wxDouble a=1.0, wxDouble b=0.0, wxDouble c=0.0, wxDouble d=1.0, + wxDouble tx=0.0, wxDouble ty=0.0); + + // gets the component valuess of the matrix + virtual void Get(wxDouble* a=NULL, wxDouble* b=NULL, wxDouble* c=NULL, + wxDouble* d=NULL, wxDouble* tx=NULL, wxDouble* ty=NULL) const; + + // makes this the inverse matrix + virtual void Invert(); + + // returns true if the elements of the transformation matrix are equal ? + virtual bool IsEqual( const wxGraphicsMatrix* t) const; + bool IsEqual( const wxGraphicsMatrix& t) const { return IsEqual( &t ); } + + // return true if this is the identity matrix + virtual bool IsIdentity() const; + + // + // transformation + // + + // add the translation to this matrix + virtual void Translate( wxDouble dx , wxDouble dy ); + + // add the scale to this matrix + virtual void Scale( wxDouble xScale , wxDouble yScale ); + + // add the rotation to this matrix (radians) + virtual void Rotate( wxDouble angle ); + + // + // apply the transforms + // + + // applies that matrix to the point + virtual void TransformPoint( wxDouble *x, wxDouble *y ) const; + + // applies the matrix except for translations + virtual void TransformDistance( wxDouble *dx, wxDouble *dy ) const; + + // returns the native representation + virtual void * GetNativeMatrix() const; + + const wxGraphicsMatrixData* GetMatrixData() const + { return (const wxGraphicsMatrixData*) GetRefData(); } + wxGraphicsMatrixData* GetMatrixData() + { return (wxGraphicsMatrixData*) GetRefData(); } + +private: + wxDECLARE_DYNAMIC_CLASS(wxGraphicsMatrix); +}; + +extern WXDLLIMPEXP_DATA_CORE(wxGraphicsMatrix) wxNullGraphicsMatrix; + +// ---------------------------------------------------------------------------- +// wxGradientStop and wxGradientStops: Controls how colors are spread in +// a gradient +// ---------------------------------------------------------------------------- + // Describes a single gradient stop. class wxGraphicsGradientStop { @@ -330,130 +461,6 @@ private: }; -class WXDLLIMPEXP_CORE wxGraphicsPen : public wxGraphicsObject -{ -public: - wxGraphicsPen() {} - virtual ~wxGraphicsPen() {} -private: - wxDECLARE_DYNAMIC_CLASS(wxGraphicsPen); -}; - -extern WXDLLIMPEXP_DATA_CORE(wxGraphicsPen) wxNullGraphicsPen; - -class WXDLLIMPEXP_CORE wxGraphicsBrush : public wxGraphicsObject -{ -public: - wxGraphicsBrush() {} - virtual ~wxGraphicsBrush() {} -private: - wxDECLARE_DYNAMIC_CLASS(wxGraphicsBrush); -}; - -extern WXDLLIMPEXP_DATA_CORE(wxGraphicsBrush) wxNullGraphicsBrush; - -class WXDLLIMPEXP_CORE wxGraphicsFont : public wxGraphicsObject -{ -public: - wxGraphicsFont() {} - virtual ~wxGraphicsFont() {} -private: - wxDECLARE_DYNAMIC_CLASS(wxGraphicsFont); -}; - -extern WXDLLIMPEXP_DATA_CORE(wxGraphicsFont) wxNullGraphicsFont; - -class WXDLLIMPEXP_CORE wxGraphicsBitmap : public wxGraphicsObject -{ -public: - wxGraphicsBitmap() {} - virtual ~wxGraphicsBitmap() {} - - // Convert bitmap to wxImage: this is more efficient than converting to - // wxBitmap first and then to wxImage and also works without X server - // connection under Unix that wxBitmap requires. -#if wxUSE_IMAGE - wxImage ConvertToImage() const; -#endif // wxUSE_IMAGE - - void* GetNativeBitmap() const; - - const wxGraphicsBitmapData* GetBitmapData() const - { return (const wxGraphicsBitmapData*) GetRefData(); } - wxGraphicsBitmapData* GetBitmapData() - { return (wxGraphicsBitmapData*) GetRefData(); } - -private: - wxDECLARE_DYNAMIC_CLASS(wxGraphicsBitmap); -}; - -extern WXDLLIMPEXP_DATA_CORE(wxGraphicsBitmap) wxNullGraphicsBitmap; - -class WXDLLIMPEXP_CORE wxGraphicsMatrix : public wxGraphicsObject -{ -public: - wxGraphicsMatrix() {} - - virtual ~wxGraphicsMatrix() {} - - // concatenates the matrix - virtual void Concat( const wxGraphicsMatrix *t ); - void Concat( const wxGraphicsMatrix &t ) { Concat( &t ); } - - // sets the matrix to the respective values - virtual void Set(wxDouble a=1.0, wxDouble b=0.0, wxDouble c=0.0, wxDouble d=1.0, - wxDouble tx=0.0, wxDouble ty=0.0); - - // gets the component valuess of the matrix - virtual void Get(wxDouble* a=NULL, wxDouble* b=NULL, wxDouble* c=NULL, - wxDouble* d=NULL, wxDouble* tx=NULL, wxDouble* ty=NULL) const; - - // makes this the inverse matrix - virtual void Invert(); - - // returns true if the elements of the transformation matrix are equal ? - virtual bool IsEqual( const wxGraphicsMatrix* t) const; - bool IsEqual( const wxGraphicsMatrix& t) const { return IsEqual( &t ); } - - // return true if this is the identity matrix - virtual bool IsIdentity() const; - - // - // transformation - // - - // add the translation to this matrix - virtual void Translate( wxDouble dx , wxDouble dy ); - - // add the scale to this matrix - virtual void Scale( wxDouble xScale , wxDouble yScale ); - - // add the rotation to this matrix (radians) - virtual void Rotate( wxDouble angle ); - - // - // apply the transforms - // - - // applies that matrix to the point - virtual void TransformPoint( wxDouble *x, wxDouble *y ) const; - - // applies the matrix except for translations - virtual void TransformDistance( wxDouble *dx, wxDouble *dy ) const; - - // returns the native representation - virtual void * GetNativeMatrix() const; - - const wxGraphicsMatrixData* GetMatrixData() const - { return (const wxGraphicsMatrixData*) GetRefData(); } - wxGraphicsMatrixData* GetMatrixData() - { return (wxGraphicsMatrixData*) GetRefData(); } - -private: - wxDECLARE_DYNAMIC_CLASS(wxGraphicsMatrix); -}; - -extern WXDLLIMPEXP_DATA_CORE(wxGraphicsMatrix) wxNullGraphicsMatrix; class WXDLLIMPEXP_CORE wxGraphicsPath : public wxGraphicsObject { From 177f5d4f2a2bdbfa364b0fecc72b58108597c34d Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Wed, 31 Jul 2019 20:04:47 -0700 Subject: [PATCH 13/41] tweak comments --- include/wx/graphics.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/wx/graphics.h b/include/wx/graphics.h index 50c12f95ab..13926d144a 100644 --- a/include/wx/graphics.h +++ b/include/wx/graphics.h @@ -270,8 +270,8 @@ private: extern WXDLLIMPEXP_DATA_CORE(wxGraphicsMatrix) wxNullGraphicsMatrix; // ---------------------------------------------------------------------------- -// wxGradientStop and wxGradientStops: Controls how colors are spread in -// a gradient +// wxGradientStop and wxGradientStops: Specify what intermediate colors are used +// and how they are are spread out in a gradient // ---------------------------------------------------------------------------- // Describes a single gradient stop. @@ -454,7 +454,7 @@ public: private: wxDouble m_width; wxGradientType m_gradientType; - wxDouble m_x1, m_y1, m_x2, m_y2; // also used for m_xo, m_yo, m_xc, m_yx + wxDouble m_x1, m_y1, m_x2, m_y2; // also used for m_xo, m_yo, m_xc, m_yc wxDouble m_radius; wxGraphicsGradientStops m_stops; wxGraphicsMatrix m_matrix; From d6060db6f1ae637cd0887d0104d2a9f795939a7f Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Thu, 1 Aug 2019 11:13:06 -0700 Subject: [PATCH 14/41] Add cairo_pattern_set_matrix --- src/common/cairo.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/common/cairo.cpp b/src/common/cairo.cpp index 3b86f79192..7b29ef4065 100644 --- a/src/common/cairo.cpp +++ b/src/common/cairo.cpp @@ -110,6 +110,8 @@ (cairo_pattern_t *pattern, cairo_extend_t extend), (pattern, extend) ) \ m( cairo_pattern_set_filter, \ (cairo_pattern_t *pattern, cairo_filter_t filter), (pattern, filter) ) \ + m( cairo_pattern_set_matrix, \ + (cairo_pattern_t *pattern, const cairo_matrix_t *matrix), (pattern, matrix) ) \ m( cairo_pop_group_to_source, \ (cairo_t *cr), (cr) ) \ m( cairo_push_group, \ From 2008d443a8a3bc595d861cb037155729e8fa99c2 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Wed, 31 Jul 2019 17:42:58 -0700 Subject: [PATCH 15/41] Set the wrap mode for linear gradient brushes, so the areas beyond the end points are properly filled with the end point colors --- src/msw/graphics.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/msw/graphics.cpp b/src/msw/graphics.cpp index a23948588d..628cf617c9 100644 --- a/src/msw/graphics.cpp +++ b/src/msw/graphics.cpp @@ -974,6 +974,7 @@ wxGDIPlusBrushData::CreateLinearGradientBrush(wxDouble x1, wxDouble y1, brush = new LinearGradientBrush(PointF(x1, y1) , PointF(x2, y2), wxColourToColor(stops.GetStartColour()), wxColourToColor(stops.GetEndColour())); + brush->SetWrapMode(WrapModeTileFlipXY); m_brush = brush; SetGradientStops(brush, stops); From 8478c97ecb22f225bde9947a2263df85b490498c Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Thu, 1 Aug 2019 15:14:50 -0700 Subject: [PATCH 16/41] Add support for gradient pens for GDI+. API also updated for gradient transforms, but that is not working yet. --- src/msw/graphics.cpp | 358 ++++++++++++++++++++++++++----------------- 1 file changed, 217 insertions(+), 141 deletions(-) diff --git a/src/msw/graphics.cpp b/src/msw/graphics.cpp index 628cf617c9..d7c6cac4fc 100644 --- a/src/msw/graphics.cpp +++ b/src/msw/graphics.cpp @@ -255,44 +255,30 @@ private: Matrix* m_matrix ; } ; -class wxGDIPlusPenData : public wxGraphicsObjectRefData + +// Things that pens and brushes have in common +class wxGDIPlusPenBrushBaseData : public wxGraphicsObjectRefData { public: - wxGDIPlusPenData( wxGraphicsRenderer* renderer, const wxGraphicsPenInfo &info ); - ~wxGDIPlusPenData(); + wxGDIPlusPenBrushBaseData(wxGraphicsRenderer* renderer); + ~wxGDIPlusPenBrushBaseData(); - void Init(); - - virtual wxDouble GetWidth() { return m_width; } - virtual Pen* GetGDIPlusPen() { return m_pen; } - -protected : - Pen* m_pen; - Image* m_penImage; - Brush* m_penBrush; - - wxDouble m_width; -}; - -class wxGDIPlusBrushData : public wxGraphicsObjectRefData -{ -public: - wxGDIPlusBrushData( wxGraphicsRenderer* renderer ); - wxGDIPlusBrushData( wxGraphicsRenderer* renderer, const wxBrush &brush ); - ~wxGDIPlusBrushData (); + virtual void Init(); void CreateLinearGradientBrush(wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, - const wxGraphicsGradientStops& stops); + const wxGraphicsGradientStops& stops, + const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix); void CreateRadialGradientBrush(wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius, - const wxGraphicsGradientStops& stops); - - virtual Brush* GetGDIPlusBrush() { return m_brush; } - + const wxGraphicsGradientStops& stops, + const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix); protected: - virtual void Init(); + Brush* m_brush; + GraphicsPath* m_brushPath; + Image* m_image; + private: // common part of Create{Linear,Radial}GradientBrush() @@ -300,10 +286,35 @@ private: void SetGradientStops(T *brush, const wxGraphicsGradientStops& stops, bool reversed = false); +}; + + +class wxGDIPlusPenData : public wxGDIPlusPenBrushBaseData +{ +public: + wxGDIPlusPenData( wxGraphicsRenderer* renderer, const wxGraphicsPenInfo &info ); + ~wxGDIPlusPenData(); + + virtual void Init(); + + virtual wxDouble GetWidth() { return m_width; } + virtual Pen* GetGDIPlusPen() { return m_pen; } + +protected : + Pen* m_pen; + wxDouble m_width; +}; + + +class wxGDIPlusBrushData : public wxGDIPlusPenBrushBaseData +{ +public: + wxGDIPlusBrushData( wxGraphicsRenderer* renderer ); + wxGDIPlusBrushData( wxGraphicsRenderer* renderer, const wxBrush &brush ); + ~wxGDIPlusBrushData (); + + virtual Brush* GetGDIPlusBrush() { return m_brush; } - Brush* m_brush; - Image* m_brushImage; - GraphicsPath* m_brushPath; }; class WXDLLIMPEXP_CORE wxGDIPlusBitmapData : public wxGraphicsBitmapData @@ -624,13 +635,15 @@ public : virtual wxGraphicsBrush CreateLinearGradientBrush(wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, - const wxGraphicsGradientStops& stops) wxOVERRIDE; + const wxGraphicsGradientStops& stops, + const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) wxOVERRIDE; virtual wxGraphicsBrush CreateRadialGradientBrush(wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius, - const wxGraphicsGradientStops& stops) wxOVERRIDE; + const wxGraphicsGradientStops& stops, + const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) wxOVERRIDE; // create a native bitmap representation virtual wxGraphicsBitmap CreateBitmap( const wxBitmap &bitmap ) wxOVERRIDE; @@ -669,6 +682,135 @@ private : wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxGDIPlusRenderer); } ; +//----------------------------------------------------------------------------- +// wxGDIPlusPenBrushBaseData implementation +//----------------------------------------------------------------------------- + +wxGDIPlusPenBrushBaseData::wxGDIPlusPenBrushBaseData(wxGraphicsRenderer* renderer) + : wxGraphicsObjectRefData(renderer) +{ + Init(); +} + +wxGDIPlusPenBrushBaseData::~wxGDIPlusPenBrushBaseData() +{ + delete m_brush; + delete m_brushPath; + delete m_image; +} + +void wxGDIPlusPenBrushBaseData::Init() +{ + m_brush = NULL; + m_brushPath = NULL; + m_image = NULL; +} + +template +void +wxGDIPlusPenBrushBaseData::SetGradientStops(T *brush, + const wxGraphicsGradientStops& stops, + bool reversed) +{ + const unsigned numStops = stops.GetCount(); + if ( numStops <= 2 ) + { + // initial and final colours are set during the brush creation, nothing + // more to do + return; + } + + wxVector colors(numStops); + wxVector positions(numStops); + + if ( reversed ) + { + for ( unsigned i = 0; i < numStops; i++ ) + { + wxGraphicsGradientStop stop = stops.Item(numStops - i - 1); + + colors[i] = wxColourToColor(stop.GetColour()); + positions[i] = 1.0 - stop.GetPosition(); + } + } + else + { + for ( unsigned i = 0; i < numStops; i++ ) + { + wxGraphicsGradientStop stop = stops.Item(i); + + colors[i] = wxColourToColor(stop.GetColour()); + positions[i] = stop.GetPosition(); + } + } + + brush->SetInterpolationColors(&colors[0], &positions[0], numStops); +} + +void +wxGDIPlusPenBrushBaseData::CreateLinearGradientBrush( + wxDouble x1, wxDouble y1, + wxDouble x2, wxDouble y2, + const wxGraphicsGradientStops& stops, + const wxGraphicsMatrix& WXUNUSED(matrix)) +{ + LinearGradientBrush * const + brush = new LinearGradientBrush(PointF(x1, y1) , PointF(x2, y2), + wxColourToColor(stops.GetStartColour()), + wxColourToColor(stops.GetEndColour())); + + // Tell the brush how to draw what's beyond the ends of the gradient + brush->SetWrapMode(WrapModeTileFlipXY); + + // Apply the matrix + // This doesn't work as I expected it to. Comment-out for now... + // FIXME + // if (! matrix.IsNull()) + // { + // const Matrix* m = static_cast(matrix.GetNativeMatrix()); + // brush->SetTransform(m); + // } + + SetGradientStops(brush, stops); + m_brush = brush; +} + +void +wxGDIPlusPenBrushBaseData::CreateRadialGradientBrush( + wxDouble xo, wxDouble yo, + wxDouble xc, wxDouble yc, + wxDouble radius, + const wxGraphicsGradientStops& stops, + const wxGraphicsMatrix& WXUNUSED(matrix)) +{ + m_brushPath = new GraphicsPath(); + m_brushPath->AddEllipse( (REAL)(xc-radius), (REAL)(yc-radius), + (REAL)(2*radius), (REAL)(2*radius)); + + PathGradientBrush * const brush = new PathGradientBrush(m_brushPath); + brush->SetCenterPoint(PointF(xo, yo)); + brush->SetCenterColor(wxColourToColor(stops.GetStartColour())); + + const Color col(wxColourToColor(stops.GetEndColour())); + int count = 1; + brush->SetSurroundColors(&col, &count); + + // Apply the matrix + // This doesn't work as I expected it to. Comment-out for now... + // FIXME + // if (! matrix.IsNull()) + // { + // const Matrix* m = static_cast(matrix.GetNativeMatrix()); + // brush->SetTransform(m); + // } + + // Because the GDI+ API draws radial gradients from outside towards the + // center we have to reverse the order of the gradient stops. + SetGradientStops(brush, stops, true); + m_brush = brush; +} + + //----------------------------------------------------------------------------- // wxGDIPlusPen implementation //----------------------------------------------------------------------------- @@ -676,20 +818,16 @@ private : wxGDIPlusPenData::~wxGDIPlusPenData() { delete m_pen; - delete m_penImage; - delete m_penBrush; } void wxGDIPlusPenData::Init() { m_pen = NULL ; - m_penImage = NULL; - m_penBrush = NULL; } wxGDIPlusPenData::wxGDIPlusPenData( wxGraphicsRenderer* renderer, const wxGraphicsPenInfo &info ) - : wxGraphicsObjectRefData(renderer) + : wxGDIPlusPenBrushBaseData(renderer) { Init(); m_width = info.GetWidth(); @@ -786,15 +924,15 @@ wxGDIPlusPenData::wxGDIPlusPenData( wxGraphicsRenderer* renderer, wxBitmap bmp = info.GetStipple(); if ( bmp.IsOk() ) { - m_penImage = Bitmap::FromHBITMAP((HBITMAP)bmp.GetHBITMAP(), + m_image = Bitmap::FromHBITMAP((HBITMAP)bmp.GetHBITMAP(), #if wxUSE_PALETTE (HPALETTE)bmp.GetPalette()->GetHPALETTE() #else NULL #endif ); - m_penBrush = new TextureBrush(m_penImage); - m_pen->SetBrush( m_penBrush ); + m_brush = new TextureBrush(m_image); + m_pen->SetBrush( m_brush ); } } @@ -827,18 +965,43 @@ wxGDIPlusPenData::wxGDIPlusPenData( wxGraphicsRenderer* renderer, default: style = HatchStyleHorizontal; } - m_penBrush = new HatchBrush + m_brush = new HatchBrush ( style, wxColourToColor(info.GetColour()), Color::Transparent ); - m_pen->SetBrush( m_penBrush ); + m_pen->SetBrush( m_brush ); } break; } if ( dashStyle != DashStyleSolid ) m_pen->SetDashStyle(dashStyle); + + switch (info.GetGradientType() ) + { + case wxGRADIENT_NONE: + break; + + case wxGRADIENT_LINEAR: + if (m_brush) + delete m_brush; + CreateLinearGradientBrush(info.GetX1(), info.GetY1(), + info.GetX2(), info.GetY2(), + info.GetStops()); + m_pen->SetBrush(m_brush); + break; + + case wxGRADIENT_RADIAL: + if (m_brush) + delete m_brush; + CreateRadialGradientBrush(info.GetXO(), info.GetYO(), + info.GetXC(), info.GetYC(), + info.GetRadius(), + info.GetStops()); + m_pen->SetBrush(m_brush); + break; + } } //----------------------------------------------------------------------------- @@ -846,13 +1009,13 @@ wxGDIPlusPenData::wxGDIPlusPenData( wxGraphicsRenderer* renderer, //----------------------------------------------------------------------------- wxGDIPlusBrushData::wxGDIPlusBrushData( wxGraphicsRenderer* renderer ) -: wxGraphicsObjectRefData(renderer) +: wxGDIPlusPenBrushBaseData(renderer) { Init(); } wxGDIPlusBrushData::wxGDIPlusBrushData( wxGraphicsRenderer* renderer , const wxBrush &brush ) -: wxGraphicsObjectRefData(renderer) +: wxGDIPlusPenBrushBaseData(renderer) { Init(); if ( brush.GetStyle() == wxBRUSHSTYLE_SOLID) @@ -897,112 +1060,23 @@ wxGDIPlusBrushData::wxGDIPlusBrushData( wxGraphicsRenderer* renderer , const wxB wxBitmap* bmp = brush.GetStipple(); if ( bmp && bmp->IsOk() ) { - wxDELETE( m_brushImage ); - m_brushImage = Bitmap::FromHBITMAP((HBITMAP)bmp->GetHBITMAP(), + wxDELETE( m_image ); + m_image = Bitmap::FromHBITMAP((HBITMAP)bmp->GetHBITMAP(), #if wxUSE_PALETTE (HPALETTE)bmp->GetPalette()->GetHPALETTE() #else NULL #endif ); - m_brush = new TextureBrush(m_brushImage); + m_brush = new TextureBrush(m_image); } } } wxGDIPlusBrushData::~wxGDIPlusBrushData() { - delete m_brush; - delete m_brushImage; - delete m_brushPath; -}; - -void wxGDIPlusBrushData::Init() -{ - m_brush = NULL; - m_brushImage= NULL; - m_brushPath= NULL; } -template -void -wxGDIPlusBrushData::SetGradientStops(T *brush, - const wxGraphicsGradientStops& stops, - bool reversed) -{ - const unsigned numStops = stops.GetCount(); - if ( numStops <= 2 ) - { - // initial and final colours are set during the brush creation, nothing - // more to do - return; - } - - wxVector colors(numStops); - wxVector positions(numStops); - - if ( reversed ) - { - for ( unsigned i = 0; i < numStops; i++ ) - { - wxGraphicsGradientStop stop = stops.Item(numStops - i - 1); - - colors[i] = wxColourToColor(stop.GetColour()); - positions[i] = 1.0 - stop.GetPosition(); - } - } - else - { - for ( unsigned i = 0; i < numStops; i++ ) - { - wxGraphicsGradientStop stop = stops.Item(i); - - colors[i] = wxColourToColor(stop.GetColour()); - positions[i] = stop.GetPosition(); - } - } - - brush->SetInterpolationColors(&colors[0], &positions[0], numStops); -} - -void -wxGDIPlusBrushData::CreateLinearGradientBrush(wxDouble x1, wxDouble y1, - wxDouble x2, wxDouble y2, - const wxGraphicsGradientStops& stops) -{ - LinearGradientBrush * const - brush = new LinearGradientBrush(PointF(x1, y1) , PointF(x2, y2), - wxColourToColor(stops.GetStartColour()), - wxColourToColor(stops.GetEndColour())); - brush->SetWrapMode(WrapModeTileFlipXY); - m_brush = brush; - - SetGradientStops(brush, stops); -} - -void -wxGDIPlusBrushData::CreateRadialGradientBrush(wxDouble xo, wxDouble yo, - wxDouble xc, wxDouble yc, - wxDouble radius, - const wxGraphicsGradientStops& stops) -{ - m_brushPath = new GraphicsPath(); - m_brushPath->AddEllipse( (REAL)(xc-radius), (REAL)(yc-radius), - (REAL)(2*radius), (REAL)(2*radius)); - - PathGradientBrush * const brush = new PathGradientBrush(m_brushPath); - m_brush = brush; - brush->SetCenterPoint(PointF(xo, yo)); - brush->SetCenterColor(wxColourToColor(stops.GetStartColour())); - - const Color col(wxColourToColor(stops.GetEndColour())); - int count = 1; - brush->SetSurroundColors(&col, &count); - - // Because the GDI+ API draws radial gradients from outside towards the - // center we have to reverse the order of the gradient stops. - SetGradientStops(brush, stops, true); -} //----------------------------------------------------------------------------- // Support for adding private fonts @@ -2614,12 +2688,13 @@ wxGraphicsBrush wxGDIPlusRenderer::CreateBrush(const wxBrush& brush ) wxGraphicsBrush wxGDIPlusRenderer::CreateLinearGradientBrush(wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, - const wxGraphicsGradientStops& stops) + const wxGraphicsGradientStops& stops, + const wxGraphicsMatrix& matrix) { ENSURE_LOADED_OR_RETURN(wxNullGraphicsBrush); wxGraphicsBrush p; wxGDIPlusBrushData* d = new wxGDIPlusBrushData( this ); - d->CreateLinearGradientBrush(x1, y1, x2, y2, stops); + d->CreateLinearGradientBrush(x1, y1, x2, y2, stops, matrix); p.SetRefData(d); return p; } @@ -2628,12 +2703,13 @@ wxGraphicsBrush wxGDIPlusRenderer::CreateRadialGradientBrush(wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius, - const wxGraphicsGradientStops& stops) + const wxGraphicsGradientStops& stops, + const wxGraphicsMatrix& matrix) { ENSURE_LOADED_OR_RETURN(wxNullGraphicsBrush); wxGraphicsBrush p; wxGDIPlusBrushData* d = new wxGDIPlusBrushData( this ); - d->CreateRadialGradientBrush(xo,yo,xc,yc,radius,stops); + d->CreateRadialGradientBrush(xo,yo,xc,yc,radius,stops,matrix); p.SetRefData(d); return p; } From e2fbcf065088fa9d1c3ae3f5026393642cd97c8c Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Thu, 1 Aug 2019 15:15:34 -0700 Subject: [PATCH 17/41] API updates only, to allow building. --- src/msw/graphicsd2d.cpp | 69 +++++++++++++++++++++++++++++------------ 1 file changed, 49 insertions(+), 20 deletions(-) diff --git a/src/msw/graphicsd2d.cpp b/src/msw/graphicsd2d.cpp index a874e7229d..2da384003b 100644 --- a/src/msw/graphicsd2d.cpp +++ b/src/msw/graphicsd2d.cpp @@ -2427,12 +2427,19 @@ public: struct LinearGradientInfo { const wxRect direction; const wxGraphicsGradientStops stops; - LinearGradientInfo(wxDouble& x1, wxDouble& y1, wxDouble& x2, wxDouble& y2, const wxGraphicsGradientStops& stops_) - : direction(x1, y1, x2, y2), stops(stops_) {} + const wxGraphicsMatrix matrix; + LinearGradientInfo(wxDouble& x1, wxDouble& y1, + wxDouble& x2, wxDouble& y2, + const wxGraphicsGradientStops& stops_, + const wxGraphicsMatrix& matrix_) + : direction(x1, y1, x2, y2), stops(stops_), matrix(matrix_) {} }; - wxD2DLinearGradientBrushResourceHolder(wxDouble& x1, wxDouble& y1, wxDouble& x2, wxDouble& y2, const wxGraphicsGradientStops& stops) - : m_linearGradientInfo(x1, y1, x2, y2, stops) {} + wxD2DLinearGradientBrushResourceHolder(wxDouble& x1, wxDouble& y1, + wxDouble& x2, wxDouble& y2, + const wxGraphicsGradientStops& stops, + const wxGraphicsMatrix& matrix) + : m_linearGradientInfo(x1, y1, x2, y2, stops, matrix) {} protected: void DoAcquireResource() wxOVERRIDE @@ -2458,13 +2465,22 @@ public: const wxRect direction; const wxDouble radius; const wxGraphicsGradientStops stops; + const wxGraphicsMatrix matrix; - RadialGradientInfo(wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, wxDouble r, const wxGraphicsGradientStops& stops_) - : direction(x1, y1, x2, y2), radius(r), stops(stops_) {} + RadialGradientInfo(wxDouble x1, wxDouble y1, + wxDouble x2, wxDouble y2, + wxDouble r, + const wxGraphicsGradientStops& stops_, + const wxGraphicsMatrix& matrix_) + : direction(x1, y1, x2, y2), radius(r), stops(stops_), matrix(matrix_) {} }; - wxD2DRadialGradientBrushResourceHolder(wxDouble& x1, wxDouble& y1, wxDouble& x2, wxDouble& y2, wxDouble& r, const wxGraphicsGradientStops& stops) - : m_radialGradientInfo(x1, y1, x2, y2, r, stops) {} + wxD2DRadialGradientBrushResourceHolder(wxDouble& x1, wxDouble& y1, + wxDouble& x2, wxDouble& y2, + wxDouble& r, + const wxGraphicsGradientStops& stops, + const wxGraphicsMatrix& matrix) + : m_radialGradientInfo(x1, y1, x2, y2, r, stops, matrix) {} protected: void DoAcquireResource() wxOVERRIDE @@ -2499,9 +2515,16 @@ public: wxD2DBrushData(wxGraphicsRenderer* renderer); - void CreateLinearGradientBrush(wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, const wxGraphicsGradientStops& stops); + void CreateLinearGradientBrush(wxDouble x1, wxDouble y1, + wxDouble x2, wxDouble y2, + const wxGraphicsGradientStops& stops, + const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix); - void CreateRadialGradientBrush(wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius, const wxGraphicsGradientStops& stops); + void CreateRadialGradientBrush(wxDouble xo, wxDouble yo, + wxDouble xc, wxDouble yc, + wxDouble radius, + const wxGraphicsGradientStops& stops, + const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix); ID2D1Brush* GetBrush() const { @@ -2546,18 +2569,20 @@ wxD2DBrushData::wxD2DBrushData(wxGraphicsRenderer* renderer) void wxD2DBrushData::CreateLinearGradientBrush( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, - const wxGraphicsGradientStops& stops) + const wxGraphicsGradientStops& stops, + const wxGraphicsMatrix& matrix) { - m_brushResourceHolder = new wxD2DLinearGradientBrushResourceHolder(x1, y1, x2, y2, stops); + m_brushResourceHolder = new wxD2DLinearGradientBrushResourceHolder(x1, y1, x2, y2, stops, matrix); } void wxD2DBrushData::CreateRadialGradientBrush( wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius, - const wxGraphicsGradientStops& stops) + const wxGraphicsGradientStops& stops, + const wxGraphicsMatrix& matrix) { - m_brushResourceHolder = new wxD2DRadialGradientBrushResourceHolder(xo, yo, xc, yc, radius, stops); + m_brushResourceHolder = new wxD2DRadialGradientBrushResourceHolder(xo, yo, xc, yc, radius, stops, matrix); } wxD2DBrushData* wxGetD2DBrushData(const wxGraphicsBrush& brush) @@ -4558,13 +4583,15 @@ public : wxGraphicsBrush CreateLinearGradientBrush( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, - const wxGraphicsGradientStops& stops) wxOVERRIDE; + const wxGraphicsGradientStops& stops, + const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) wxOVERRIDE; wxGraphicsBrush CreateRadialGradientBrush( wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius, - const wxGraphicsGradientStops& stops) wxOVERRIDE; + const wxGraphicsGradientStops& stops, + const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) wxOVERRIDE; // create a native bitmap representation wxGraphicsBitmap CreateBitmap(const wxBitmap& bitmap) wxOVERRIDE; @@ -4749,10 +4776,11 @@ wxGraphicsBrush wxD2DRenderer::CreateBrush(const wxBrush& brush) wxGraphicsBrush wxD2DRenderer::CreateLinearGradientBrush( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, - const wxGraphicsGradientStops& stops) + const wxGraphicsGradientStops& stops, + const wxGraphicsMatrix& matrix) { wxD2DBrushData* brushData = new wxD2DBrushData(this); - brushData->CreateLinearGradientBrush(x1, y1, x2, y2, stops); + brushData->CreateLinearGradientBrush(x1, y1, x2, y2, stops, matrix); wxGraphicsBrush brush; brush.SetRefData(brushData); @@ -4764,10 +4792,11 @@ wxGraphicsBrush wxD2DRenderer::CreateRadialGradientBrush( wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius, - const wxGraphicsGradientStops& stops) + const wxGraphicsGradientStops& stops, + const wxGraphicsMatrix& matrix) { wxD2DBrushData* brushData = new wxD2DBrushData(this); - brushData->CreateRadialGradientBrush(xo, yo, xc, yc, radius, stops); + brushData->CreateRadialGradientBrush(xo, yo, xc, yc, radius, stops, matrix); wxGraphicsBrush brush; brush.SetRefData(brushData); From 6d85b566cec6093b09c8e7e95bccf87deace7d13 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Thu, 1 Aug 2019 15:15:34 -0700 Subject: [PATCH 18/41] Create gradient brushes for pens in wxD2DRenderer --- src/msw/graphicsd2d.cpp | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/src/msw/graphicsd2d.cpp b/src/msw/graphicsd2d.cpp index 2da384003b..79048f569b 100644 --- a/src/msw/graphicsd2d.cpp +++ b/src/msw/graphicsd2d.cpp @@ -2572,7 +2572,8 @@ void wxD2DBrushData::CreateLinearGradientBrush( const wxGraphicsGradientStops& stops, const wxGraphicsMatrix& matrix) { - m_brushResourceHolder = new wxD2DLinearGradientBrushResourceHolder(x1, y1, x2, y2, stops, matrix); + m_brushResourceHolder = new wxD2DLinearGradientBrushResourceHolder( + x1, y1, x2, y2, stops, matrix); } void wxD2DBrushData::CreateRadialGradientBrush( @@ -2582,7 +2583,8 @@ void wxD2DBrushData::CreateRadialGradientBrush( const wxGraphicsGradientStops& stops, const wxGraphicsMatrix& matrix) { - m_brushResourceHolder = new wxD2DRadialGradientBrushResourceHolder(xo, yo, xc, yc, radius, stops, matrix); + m_brushResourceHolder = new wxD2DRadialGradientBrushResourceHolder( + xo, yo, xc, yc, radius, stops, matrix); } wxD2DBrushData* wxGetD2DBrushData(const wxGraphicsBrush& brush) @@ -2690,9 +2692,34 @@ wxD2DPenData::wxD2DPenData( strokeBrush.SetStyle(wxBRUSHSTYLE_SOLID); } - m_stippleBrush = new wxD2DBrushData(renderer, strokeBrush); + switch ( m_penInfo.GetGradientType() ) + { + case wxGRADIENT_NONE: + m_stippleBrush = new wxD2DBrushData(renderer, strokeBrush); + break; + + case wxGRADIENT_LINEAR: + m_stippleBrush = new wxD2DBrushData(renderer); + m_stippleBrush->CreateLinearGradientBrush( + m_penInfo.GetX1(), m_penInfo.GetY1(), + m_penInfo.GetX2(), m_penInfo.GetY2(), + m_penInfo.GetStops(), + m_penInfo.GetMatrix()); + break; + + case wxGRADIENT_RADIAL: + m_stippleBrush = new wxD2DBrushData(renderer); + m_stippleBrush->CreateRadialGradientBrush( + m_penInfo.GetXO(), m_penInfo.GetYO(), + m_penInfo.GetXC(), m_penInfo.GetYC(), + m_penInfo.GetRadius(), + m_penInfo.GetStops(), + m_penInfo.GetMatrix()); + break; + } } + void wxD2DPenData::CreateStrokeStyle(ID2D1Factory* const direct2dfactory) { D2D1_CAP_STYLE capStyle = wxD2DConvertPenCap(m_penInfo.GetCap()); From a8eeab3af2879e808a2217f63747955215776c56 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Fri, 2 Aug 2019 16:04:01 -0700 Subject: [PATCH 19/41] Add support for setting the transform on Direct2D gradient brushes --- src/msw/graphicsd2d.cpp | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/src/msw/graphicsd2d.cpp b/src/msw/graphicsd2d.cpp index 79048f569b..9ecf67dabb 100644 --- a/src/msw/graphicsd2d.cpp +++ b/src/msw/graphicsd2d.cpp @@ -2445,14 +2445,23 @@ protected: void DoAcquireResource() wxOVERRIDE { wxD2DGradientStopsHelper helper(m_linearGradientInfo.stops, GetContext()); + ID2D1LinearGradientBrush *linearGradientBrush; HRESULT hr = GetContext()->CreateLinearGradientBrush( D2D1::LinearGradientBrushProperties( - D2D1::Point2F(m_linearGradientInfo.direction.GetX(), m_linearGradientInfo.direction.GetY()), - D2D1::Point2F(m_linearGradientInfo.direction.GetWidth(), m_linearGradientInfo.direction.GetHeight())), + D2D1::Point2F(m_linearGradientInfo.direction.GetX(), m_linearGradientInfo.direction.GetY()), + D2D1::Point2F(m_linearGradientInfo.direction.GetWidth(), m_linearGradientInfo.direction.GetHeight())), helper.GetGradientStopCollection(), - &m_nativeResource); + &linearGradientBrush); wxCHECK_HRESULT_RET(hr); + + if (! m_linearGradientInfo.matrix.IsNull()) + { + D2D1::Matrix3x2F matrix = wxGetD2DMatrixData(m_linearGradientInfo.matrix)->GetMatrix3x2F(); + matrix.Invert(); + linearGradientBrush->SetTransform(matrix); + } + m_nativeResource = linearGradientBrush; } private: const LinearGradientInfo m_linearGradientInfo; @@ -2486,18 +2495,27 @@ protected: void DoAcquireResource() wxOVERRIDE { wxD2DGradientStopsHelper helper(m_radialGradientInfo.stops, GetContext()); + ID2D1RadialGradientBrush *radialGradientBrush; int xo = m_radialGradientInfo.direction.GetLeft() - m_radialGradientInfo.direction.GetWidth(); int yo = m_radialGradientInfo.direction.GetTop() - m_radialGradientInfo.direction.GetHeight(); HRESULT hr = GetContext()->CreateRadialGradientBrush( D2D1::RadialGradientBrushProperties( - D2D1::Point2F(m_radialGradientInfo.direction.GetLeft(), m_radialGradientInfo.direction.GetTop()), - D2D1::Point2F(xo, yo), - m_radialGradientInfo.radius, m_radialGradientInfo.radius), + D2D1::Point2F(m_radialGradientInfo.direction.GetLeft(), m_radialGradientInfo.direction.GetTop()), + D2D1::Point2F(xo, yo), + m_radialGradientInfo.radius, m_radialGradientInfo.radius), helper.GetGradientStopCollection(), - &m_nativeResource); + &radialGradientBrush); wxCHECK_HRESULT_RET(hr); + + if (! m_radialGradientInfo.matrix.IsNull()) + { + D2D1::Matrix3x2F matrix = wxGetD2DMatrixData(m_radialGradientInfo.matrix)->GetMatrix3x2F(); + matrix.Invert(); + radialGradientBrush->SetTransform(matrix); + } + m_nativeResource = radialGradientBrush; } private: From 2571f5962cd25d73e85d975b56be4c3feb709d78 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Fri, 2 Aug 2019 20:06:45 -0700 Subject: [PATCH 20/41] Don't use a wxRect to hold floating point values!! --- src/msw/graphicsd2d.cpp | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/msw/graphicsd2d.cpp b/src/msw/graphicsd2d.cpp index 9ecf67dabb..1dd3425997 100644 --- a/src/msw/graphicsd2d.cpp +++ b/src/msw/graphicsd2d.cpp @@ -2425,14 +2425,17 @@ class wxD2DLinearGradientBrushResourceHolder : public wxD2DResourceHolderCreateLinearGradientBrush( D2D1::LinearGradientBrushProperties( - D2D1::Point2F(m_linearGradientInfo.direction.GetX(), m_linearGradientInfo.direction.GetY()), - D2D1::Point2F(m_linearGradientInfo.direction.GetWidth(), m_linearGradientInfo.direction.GetHeight())), + D2D1::Point2F(m_linearGradientInfo.x1, m_linearGradientInfo.y1), + D2D1::Point2F(m_linearGradientInfo.x2, m_linearGradientInfo.y2)), helper.GetGradientStopCollection(), &linearGradientBrush); wxCHECK_HRESULT_RET(hr); @@ -2471,17 +2474,20 @@ class wxD2DRadialGradientBrushResourceHolder : public wxD2DResourceHolderCreateRadialGradientBrush( D2D1::RadialGradientBrushProperties( - D2D1::Point2F(m_radialGradientInfo.direction.GetLeft(), m_radialGradientInfo.direction.GetTop()), + D2D1::Point2F(m_radialGradientInfo.x1, m_radialGradientInfo.y1), D2D1::Point2F(xo, yo), m_radialGradientInfo.radius, m_radialGradientInfo.radius), helper.GetGradientStopCollection(), From fc35d8b49bc17611f7689a4bf97fdccc2b78d6aa Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Fri, 2 Aug 2019 22:00:49 -0700 Subject: [PATCH 21/41] Comment out some asserts I think are incorrect. Needs verification. --- src/msw/graphicsd2d.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/msw/graphicsd2d.cpp b/src/msw/graphicsd2d.cpp index 1dd3425997..112cebd8fa 100644 --- a/src/msw/graphicsd2d.cpp +++ b/src/msw/graphicsd2d.cpp @@ -1772,9 +1772,12 @@ void wxD2DPathData::AddPath(const wxGraphicsPathData* path) GeometryStateData curStateSrc; pathSrc->SaveGeometryState(curStateSrc); + // I think this assert is incorrect. We need to support paths where the end + // is not connected to the beginning. --Robin // Raise warning if appended path has an open non-empty sub-path. - wxASSERT_MSG( pathSrc->IsStateSafeForFlush(), - wxS("Sub-path in appended path should be closed prior to this operation") ); + // wxASSERT_MSG( pathSrc->IsStateSafeForFlush(), + // wxS("Sub-path in appended path should be closed prior to this operation") ); + // Close appended geometry. pathSrc->Flush(); @@ -1893,8 +1896,12 @@ void wxD2DPathData::Transform(const wxGraphicsMatrixData* matrix) // constraints this can be fully done only if open figure was empty. // So, Transform() can be safely called if path doesn't contain the open // sub-path or if open sub-path is empty. - wxASSERT_MSG( IsStateSafeForFlush(), - wxS("Consider closing sub-path before calling Transform()") ); + + // I think this assert is incorrect. We need to support paths where the end + // is not connected to the beginning. --Robin + // wxASSERT_MSG( IsStateSafeForFlush(), + // wxS("Consider closing sub-path before calling Transform()") ); + // Close current geometry. Flush(); From 1e37cca1628da8952deb30d929c855af2b380a4f Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Fri, 2 Aug 2019 23:03:45 -0700 Subject: [PATCH 22/41] Like Direct2D inverting the matrix is needed for gradient transforms --- src/msw/graphics.cpp | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/src/msw/graphics.cpp b/src/msw/graphics.cpp index d7c6cac4fc..9313f99e75 100644 --- a/src/msw/graphics.cpp +++ b/src/msw/graphics.cpp @@ -752,7 +752,7 @@ wxGDIPlusPenBrushBaseData::CreateLinearGradientBrush( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, const wxGraphicsGradientStops& stops, - const wxGraphicsMatrix& WXUNUSED(matrix)) + const wxGraphicsMatrix& matrix) { LinearGradientBrush * const brush = new LinearGradientBrush(PointF(x1, y1) , PointF(x2, y2), @@ -762,14 +762,13 @@ wxGDIPlusPenBrushBaseData::CreateLinearGradientBrush( // Tell the brush how to draw what's beyond the ends of the gradient brush->SetWrapMode(WrapModeTileFlipXY); - // Apply the matrix - // This doesn't work as I expected it to. Comment-out for now... - // FIXME - // if (! matrix.IsNull()) - // { - // const Matrix* m = static_cast(matrix.GetNativeMatrix()); - // brush->SetTransform(m); - // } + // Apply the matrix if there is one + if (! matrix.IsNull()) + { + Matrix* m = static_cast(matrix.GetNativeMatrix()); + m->Invert(); + brush->MultiplyTransform(m); + } SetGradientStops(brush, stops); m_brush = brush; @@ -781,7 +780,7 @@ wxGDIPlusPenBrushBaseData::CreateRadialGradientBrush( wxDouble xc, wxDouble yc, wxDouble radius, const wxGraphicsGradientStops& stops, - const wxGraphicsMatrix& WXUNUSED(matrix)) + const wxGraphicsMatrix& matrix) { m_brushPath = new GraphicsPath(); m_brushPath->AddEllipse( (REAL)(xc-radius), (REAL)(yc-radius), @@ -795,14 +794,16 @@ wxGDIPlusPenBrushBaseData::CreateRadialGradientBrush( int count = 1; brush->SetSurroundColors(&col, &count); - // Apply the matrix - // This doesn't work as I expected it to. Comment-out for now... - // FIXME - // if (! matrix.IsNull()) - // { - // const Matrix* m = static_cast(matrix.GetNativeMatrix()); - // brush->SetTransform(m); - // } + // TODO: There doesn't seem to be an equivallent for SetWrapMode, so + // the area outside of the gradient's radius is not getting painted. + + // Apply the matrix if there is one + if (! matrix.IsNull()) + { + Matrix* m = static_cast(matrix.GetNativeMatrix()); + m->Invert(); + brush->SetTransform(m); + } // Because the GDI+ API draws radial gradients from outside towards the // center we have to reverse the order of the gradient stops. From 2738565c0d8629df911ba2ff5adb7fdaecfcfe7c Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Thu, 1 Aug 2019 16:01:55 -0700 Subject: [PATCH 23/41] Just API updates to allow building to succeed --- src/osx/carbon/graphics.cpp | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/osx/carbon/graphics.cpp b/src/osx/carbon/graphics.cpp index 65fe9c63a3..74815c3dfa 100644 --- a/src/osx/carbon/graphics.cpp +++ b/src/osx/carbon/graphics.cpp @@ -605,10 +605,12 @@ public: virtual void Apply( wxGraphicsContext* context ); void CreateLinearGradientBrush(wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, - const wxGraphicsGradientStops& stops); + const wxGraphicsGradientStops& stops, + const wxGraphicsMatrix& matrix); void CreateRadialGradientBrush(wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius, - const wxGraphicsGradientStops& stops); + const wxGraphicsGradientStops& stops, + const wxGraphicsMatrix& matrix); virtual bool IsShading() { return m_isShading; } CGShadingRef GetShading() { return m_shading; } @@ -669,7 +671,8 @@ wxMacCoreGraphicsBrushData::wxMacCoreGraphicsBrushData( wxGraphicsRenderer* rend void wxMacCoreGraphicsBrushData::CreateLinearGradientBrush(wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, - const wxGraphicsGradientStops& stops) + const wxGraphicsGradientStops& stops, + const wxGraphicsMatrix& matrix) { m_gradientFunction = CreateGradientFunction(stops); m_shading = CGShadingCreateAxial( wxMacGetGenericRGBColorSpace(), CGPointMake((CGFloat) x1, (CGFloat) y1), @@ -681,7 +684,8 @@ void wxMacCoreGraphicsBrushData::CreateRadialGradientBrush(wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius, - const wxGraphicsGradientStops& stops) + const wxGraphicsGradientStops& stops, + const wxGraphicsMatrix& matrix) { m_gradientFunction = CreateGradientFunction(stops); m_shading = CGShadingCreateRadial( wxMacGetGenericRGBColorSpace(), CGPointMake((CGFloat) xo,(CGFloat) yo), 0, @@ -2667,13 +2671,15 @@ public : virtual wxGraphicsBrush CreateLinearGradientBrush(wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, - const wxGraphicsGradientStops& stops) wxOVERRIDE; + const wxGraphicsGradientStops& stops, + const wxGraphicsMatrix& matrix) wxOVERRIDE; virtual wxGraphicsBrush CreateRadialGradientBrush(wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius, - const wxGraphicsGradientStops& stops) wxOVERRIDE; + const wxGraphicsGradientStops& stops, + const wxGraphicsMatrix& matrix) wxOVERRIDE; // sets the font virtual wxGraphicsFont CreateFont( const wxFont &font , const wxColour &col = *wxBLACK ) wxOVERRIDE ; @@ -2924,11 +2930,12 @@ void wxMacCoreGraphicsRenderer::GetVersion(int *major, int *minor, int *micro) c wxGraphicsBrush wxMacCoreGraphicsRenderer::CreateLinearGradientBrush(wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, - const wxGraphicsGradientStops& stops) + const wxGraphicsGradientStops& stops, + const wxGraphicsMatrix& matrix) { wxGraphicsBrush p; wxMacCoreGraphicsBrushData* d = new wxMacCoreGraphicsBrushData( this ); - d->CreateLinearGradientBrush(x1, y1, x2, y2, stops); + d->CreateLinearGradientBrush(x1, y1, x2, y2, stops, matrix); p.SetRefData(d); return p; } @@ -2937,11 +2944,12 @@ wxGraphicsBrush wxMacCoreGraphicsRenderer::CreateRadialGradientBrush(wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius, - const wxGraphicsGradientStops& stops) + const wxGraphicsGradientStops& stops, + const wxGraphicsMatrix& matrix) { wxGraphicsBrush p; wxMacCoreGraphicsBrushData* d = new wxMacCoreGraphicsBrushData( this ); - d->CreateRadialGradientBrush(xo, yo, xc, yc, radius, stops); + d->CreateRadialGradientBrush(xo, yo, xc, yc, radius, stops, matrix); p.SetRefData(d); return p; } From 239b8a17b1fbc74329e70b56c6bf30fff9a8addc Mon Sep 17 00:00:00 2001 From: Robin Dunn <> Date: Wed, 7 Aug 2019 11:37:18 -0700 Subject: [PATCH 24/41] Add stroking a path with a gradient on OSX, and also gradient transforms --- src/osx/carbon/graphics.cpp | 465 ++++++++++++++++++++++-------------- 1 file changed, 281 insertions(+), 184 deletions(-) diff --git a/src/osx/carbon/graphics.cpp b/src/osx/carbon/graphics.cpp index 74815c3dfa..047ba7bd6f 100644 --- a/src/osx/carbon/graphics.cpp +++ b/src/osx/carbon/graphics.cpp @@ -302,17 +302,221 @@ protected : int m_hatch; }; -class wxMacCoreGraphicsPenData : public wxGraphicsObjectRefData +// ---------------------------------------------------------------------------- +// Base class for information shared between pens and brushes, basically just +// the things needed for gradient support. + +class wxMacCoreGraphicsPenBrushDataBase : public wxGraphicsObjectRefData +{ +public: + wxMacCoreGraphicsPenBrushDataBase(wxGraphicsRenderer* renderer); + ~wxMacCoreGraphicsPenBrushDataBase(); + + void CreateLinearGradientShading(wxDouble x1, wxDouble y1, + wxDouble x2, wxDouble y2, + const wxGraphicsGradientStops& stops, + const wxGraphicsMatrix& matrix); + void CreateRadialGradientShading(wxDouble xo, wxDouble yo, + wxDouble xc, wxDouble yc, wxDouble radius, + const wxGraphicsGradientStops& stops, + const wxGraphicsMatrix& matrix); + + virtual bool IsShading() { return m_isShading; } + CGShadingRef GetShading() { return m_shading; } + wxGraphicsMatrix& GetMatrix() { return m_shadingMatrix; } + +protected: + void Init(); + + CGFunctionRef CreateGradientFunction(const wxGraphicsGradientStops& stops); + static void CalculateShadingValues (void *info, const CGFloat *in, CGFloat *out); + + bool m_isShading; + CGFunctionRef m_gradientFunction; + CGShadingRef m_shading; + wxGraphicsMatrix m_shadingMatrix; + + // information about a single gradient component + struct GradientComponent + { + CGFloat pos; + CGFloat red; + CGFloat green; + CGFloat blue; + CGFloat alpha; + }; + + // and information about all of them + struct GradientComponents + { + GradientComponents() + { + count = 0; + comps = NULL; + } + + void Init(unsigned count_) + { + count = count_; + comps = new GradientComponent[count]; + } + + ~GradientComponents() + { + delete [] comps; + } + + unsigned count; + GradientComponent *comps; + }; + + GradientComponents m_gradientComponents; +}; + + +wxMacCoreGraphicsPenBrushDataBase::wxMacCoreGraphicsPenBrushDataBase(wxGraphicsRenderer* renderer) + : wxGraphicsObjectRefData(renderer) +{ + Init(); +} + +wxMacCoreGraphicsPenBrushDataBase::~wxMacCoreGraphicsPenBrushDataBase() +{ + if ( m_shading ) + CGShadingRelease(m_shading); + + if( m_gradientFunction ) + CGFunctionRelease(m_gradientFunction); +} + +void +wxMacCoreGraphicsPenBrushDataBase::Init() +{ + m_gradientFunction = NULL; + m_shading = NULL; + m_isShading = false; +} + +void +wxMacCoreGraphicsPenBrushDataBase::CreateLinearGradientShading( + wxDouble x1, wxDouble y1, + wxDouble x2, wxDouble y2, + const wxGraphicsGradientStops& stops, + const wxGraphicsMatrix& matrix) +{ + m_gradientFunction = CreateGradientFunction(stops); + m_shading = CGShadingCreateAxial( wxMacGetGenericRGBColorSpace(), + CGPointMake((CGFloat) x1, (CGFloat) y1), + CGPointMake((CGFloat) x2, (CGFloat) y2), + m_gradientFunction, true, true ); + m_isShading = true; + m_shadingMatrix = matrix; +} + +void +wxMacCoreGraphicsPenBrushDataBase::CreateRadialGradientShading( + wxDouble xo, wxDouble yo, + wxDouble xc, wxDouble yc, + wxDouble radius, + const wxGraphicsGradientStops& stops, + const wxGraphicsMatrix& matrix) +{ + m_gradientFunction = CreateGradientFunction(stops); + m_shading = CGShadingCreateRadial( wxMacGetGenericRGBColorSpace(), + CGPointMake((CGFloat) xo, (CGFloat) yo), 0, + CGPointMake((CGFloat) xc, (CGFloat) yc), (CGFloat) radius, + m_gradientFunction, true, true ); + m_isShading = true; + m_shadingMatrix = matrix; +} + +void wxMacCoreGraphicsPenBrushDataBase::CalculateShadingValues(void *info, const CGFloat *in, CGFloat *out) +{ + const GradientComponents& stops = *(GradientComponents*) info ; + + CGFloat f = *in; + if (f <= 0.0) + { + // Start + out[0] = stops.comps[0].red; + out[1] = stops.comps[0].green; + out[2] = stops.comps[0].blue; + out[3] = stops.comps[0].alpha; + } + else if (f >= 1.0) + { + // end + out[0] = stops.comps[stops.count - 1].red; + out[1] = stops.comps[stops.count - 1].green; + out[2] = stops.comps[stops.count - 1].blue; + out[3] = stops.comps[stops.count - 1].alpha; + } + else + { + // Find first component with position greater than f + unsigned i; + for ( i = 0; i < stops.count; i++ ) + { + if (stops.comps[i].pos > f) + break; + } + + // Interpolated between stops + CGFloat diff = (f - stops.comps[i-1].pos); + CGFloat range = (stops.comps[i].pos - stops.comps[i-1].pos); + CGFloat fact = diff / range; + + out[0] = stops.comps[i - 1].red + (stops.comps[i].red - stops.comps[i - 1].red) * fact; + out[1] = stops.comps[i - 1].green + (stops.comps[i].green - stops.comps[i - 1].green) * fact; + out[2] = stops.comps[i - 1].blue + (stops.comps[i].blue - stops.comps[i - 1].blue) * fact; + out[3] = stops.comps[i - 1].alpha + (stops.comps[i].alpha - stops.comps[i - 1].alpha) * fact; + } +} + +CGFunctionRef +wxMacCoreGraphicsPenBrushDataBase::CreateGradientFunction(const wxGraphicsGradientStops& stops) +{ + + static const CGFunctionCallbacks callbacks = { 0, &CalculateShadingValues, NULL }; + static const CGFloat input_value_range [2] = { 0, 1 }; + static const CGFloat output_value_ranges [8] = { 0, 1, 0, 1, 0, 1, 0, 1 }; + + m_gradientComponents.Init(stops.GetCount()); + for ( unsigned i = 0; i < m_gradientComponents.count; i++ ) + { + const wxGraphicsGradientStop stop = stops.Item(i); + + m_gradientComponents.comps[i].pos = stop.GetPosition(); + + const wxColour col = stop.GetColour(); + m_gradientComponents.comps[i].red = (CGFloat) (col.Red() / 255.0); + m_gradientComponents.comps[i].green = (CGFloat) (col.Green() / 255.0); + m_gradientComponents.comps[i].blue = (CGFloat) (col.Blue() / 255.0); + m_gradientComponents.comps[i].alpha = (CGFloat) (col.Alpha() / 255.0); + } + + return CGFunctionCreate ( &m_gradientComponents, 1, + input_value_range, + 4, + output_value_ranges, + &callbacks); +} + +//----------------------------------------------------------------------------- +// Pen data + +class wxMacCoreGraphicsPenData : public wxMacCoreGraphicsPenBrushDataBase { public: wxMacCoreGraphicsPenData( wxGraphicsRenderer* renderer, const wxGraphicsPenInfo& info ); ~wxMacCoreGraphicsPenData(); - void Init(); virtual void Apply( wxGraphicsContext* context ); virtual wxDouble GetWidth() { return m_width; } protected : + void Init(); + CGLineCap m_cap; wxCFRef m_color; wxCFRef m_colorSpace; @@ -332,7 +536,7 @@ protected : wxMacCoreGraphicsPenData::wxMacCoreGraphicsPenData( wxGraphicsRenderer* renderer, const wxGraphicsPenInfo& info ) - : wxGraphicsObjectRefData( renderer ) + : wxMacCoreGraphicsPenBrushDataBase( renderer ) { Init(); @@ -457,7 +661,7 @@ wxMacCoreGraphicsPenData::wxMacCoreGraphicsPenData( wxGraphicsRenderer* renderer 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); + m_patternColorComponents[3] = (CGFloat) (info.GetColour().Alpha() / 255.0); } break; } @@ -466,6 +670,28 @@ wxMacCoreGraphicsPenData::wxMacCoreGraphicsPenData( wxGraphicsRenderer* renderer // force the line cap, otherwise we get artifacts (overlaps) and just solid lines m_cap = kCGLineCapButt; } + + switch ( info.GetGradientType() ) + { + case wxGRADIENT_NONE: + break; + + case wxGRADIENT_LINEAR: + CreateLinearGradientShading(info.GetX1(), info.GetY1(), + info.GetX2(), info.GetY2(), + info.GetStops(), + info.GetMatrix()); + break; + + case wxGRADIENT_RADIAL: + CreateRadialGradientShading(info.GetXO(), info.GetYO(), + info.GetXC(), info.GetYC(), + info.GetRadius(), + info.GetStops(), + info.GetMatrix()); + break; + } + } wxMacCoreGraphicsPenData::~wxMacCoreGraphicsPenData() @@ -595,7 +821,7 @@ wxMacCoreGraphicsColour::wxMacCoreGraphicsColour( const wxBrush &brush ) } } -class wxMacCoreGraphicsBrushData : public wxGraphicsObjectRefData +class wxMacCoreGraphicsBrushData : public wxMacCoreGraphicsPenBrushDataBase { public: wxMacCoreGraphicsBrushData( wxGraphicsRenderer* renderer ); @@ -603,117 +829,24 @@ public: ~wxMacCoreGraphicsBrushData (); virtual void Apply( wxGraphicsContext* context ); - void CreateLinearGradientBrush(wxDouble x1, wxDouble y1, - wxDouble x2, wxDouble y2, - const wxGraphicsGradientStops& stops, - const wxGraphicsMatrix& matrix); - void CreateRadialGradientBrush(wxDouble xo, wxDouble yo, - wxDouble xc, wxDouble yc, wxDouble radius, - const wxGraphicsGradientStops& stops, - const wxGraphicsMatrix& matrix); - virtual bool IsShading() { return m_isShading; } - CGShadingRef GetShading() { return m_shading; } protected: - CGFunctionRef CreateGradientFunction(const wxGraphicsGradientStops& stops); - - static void CalculateShadingValues (void *info, const CGFloat *in, CGFloat *out); - virtual void Init(); - wxMacCoreGraphicsColour m_cgColor; - - bool m_isShading; - CGFunctionRef m_gradientFunction; - CGShadingRef m_shading; - - // information about a single gradient component - struct GradientComponent - { - CGFloat pos; - CGFloat red; - CGFloat green; - CGFloat blue; - CGFloat alpha; - }; - - // and information about all of them - struct GradientComponents - { - GradientComponents() - { - count = 0; - comps = NULL; - } - - void Init(unsigned count_) - { - count = count_; - comps = new GradientComponent[count]; - } - - ~GradientComponents() - { - delete [] comps; - } - - unsigned count; - GradientComponent *comps; - }; - - GradientComponents m_gradientComponents; }; -wxMacCoreGraphicsBrushData::wxMacCoreGraphicsBrushData( wxGraphicsRenderer* renderer) : wxGraphicsObjectRefData( renderer ) +wxMacCoreGraphicsBrushData::wxMacCoreGraphicsBrushData( wxGraphicsRenderer* renderer) : + wxMacCoreGraphicsPenBrushDataBase( renderer ) { - Init(); } -void -wxMacCoreGraphicsBrushData::CreateLinearGradientBrush(wxDouble x1, wxDouble y1, - wxDouble x2, wxDouble y2, - const wxGraphicsGradientStops& stops, - const wxGraphicsMatrix& matrix) -{ - m_gradientFunction = CreateGradientFunction(stops); - m_shading = CGShadingCreateAxial( wxMacGetGenericRGBColorSpace(), CGPointMake((CGFloat) x1, (CGFloat) y1), - CGPointMake((CGFloat) x2,(CGFloat) y2), m_gradientFunction, true, true ) ; - m_isShading = true ; -} - -void -wxMacCoreGraphicsBrushData::CreateRadialGradientBrush(wxDouble xo, wxDouble yo, - wxDouble xc, wxDouble yc, - wxDouble radius, - const wxGraphicsGradientStops& stops, - const wxGraphicsMatrix& matrix) -{ - m_gradientFunction = CreateGradientFunction(stops); - m_shading = CGShadingCreateRadial( wxMacGetGenericRGBColorSpace(), CGPointMake((CGFloat) xo,(CGFloat) yo), 0, - CGPointMake((CGFloat) xc,(CGFloat) yc), (CGFloat) radius, m_gradientFunction, true, true ) ; - m_isShading = true ; -} - -wxMacCoreGraphicsBrushData::wxMacCoreGraphicsBrushData(wxGraphicsRenderer* renderer, const wxBrush &brush) : wxGraphicsObjectRefData( renderer ), +wxMacCoreGraphicsBrushData::wxMacCoreGraphicsBrushData(wxGraphicsRenderer* renderer, const wxBrush &brush) : + wxMacCoreGraphicsPenBrushDataBase( renderer ), m_cgColor( brush ) { - Init(); - } wxMacCoreGraphicsBrushData::~wxMacCoreGraphicsBrushData() { - if ( m_shading ) - CGShadingRelease(m_shading); - - if( m_gradientFunction ) - CGFunctionRelease(m_gradientFunction); -} - -void wxMacCoreGraphicsBrushData::Init() -{ - m_gradientFunction = NULL; - m_shading = NULL; - m_isShading = false; } void wxMacCoreGraphicsBrushData::Apply( wxGraphicsContext* context ) @@ -730,77 +863,6 @@ void wxMacCoreGraphicsBrushData::Apply( wxGraphicsContext* context ) } } -void wxMacCoreGraphicsBrushData::CalculateShadingValues (void *info, const CGFloat *in, CGFloat *out) -{ - const GradientComponents& stops = *(GradientComponents*) info ; - - CGFloat f = *in; - if (f <= 0.0) - { - // Start - out[0] = stops.comps[0].red; - out[1] = stops.comps[0].green; - out[2] = stops.comps[0].blue; - out[3] = stops.comps[0].alpha; - } - else if (f >= 1.0) - { - // end - out[0] = stops.comps[stops.count - 1].red; - out[1] = stops.comps[stops.count - 1].green; - out[2] = stops.comps[stops.count - 1].blue; - out[3] = stops.comps[stops.count - 1].alpha; - } - else - { - // Find first component with position greater than f - unsigned i; - for ( i = 0; i < stops.count; i++ ) - { - if (stops.comps[i].pos > f) - break; - } - - // Interpolated between stops - CGFloat diff = (f - stops.comps[i-1].pos); - CGFloat range = (stops.comps[i].pos - stops.comps[i-1].pos); - CGFloat fact = diff / range; - - out[0] = stops.comps[i - 1].red + (stops.comps[i].red - stops.comps[i - 1].red) * fact; - out[1] = stops.comps[i - 1].green + (stops.comps[i].green - stops.comps[i - 1].green) * fact; - out[2] = stops.comps[i - 1].blue + (stops.comps[i].blue - stops.comps[i - 1].blue) * fact; - out[3] = stops.comps[i - 1].alpha + (stops.comps[i].alpha - stops.comps[i - 1].alpha) * fact; - } -} - -CGFunctionRef -wxMacCoreGraphicsBrushData::CreateGradientFunction(const wxGraphicsGradientStops& stops) -{ - - static const CGFunctionCallbacks callbacks = { 0, &CalculateShadingValues, NULL }; - static const CGFloat input_value_range [2] = { 0, 1 }; - static const CGFloat output_value_ranges [8] = { 0, 1, 0, 1, 0, 1, 0, 1 }; - - m_gradientComponents.Init(stops.GetCount()); - for ( unsigned i = 0; i < m_gradientComponents.count; i++ ) - { - const wxGraphicsGradientStop stop = stops.Item(i); - - m_gradientComponents.comps[i].pos = stop.GetPosition(); - - const wxColour col = stop.GetColour(); - m_gradientComponents.comps[i].red = (CGFloat) (col.Red() / 255.0); - m_gradientComponents.comps[i].green = (CGFloat) (col.Green() / 255.0); - m_gradientComponents.comps[i].blue = (CGFloat) (col.Blue() / 255.0); - m_gradientComponents.comps[i].alpha = (CGFloat) (col.Alpha() / 255.0); - } - - return CGFunctionCreate ( &m_gradientComponents, 1, - input_value_range, - 4, - output_value_ranges, - &callbacks); -} // // Font @@ -833,8 +895,9 @@ private : #endif }; -wxMacCoreGraphicsFontData::wxMacCoreGraphicsFontData(wxGraphicsRenderer* renderer, const wxFont &font, const wxColour& col) : wxGraphicsObjectRefData( renderer ) - , m_colour(col) +wxMacCoreGraphicsFontData::wxMacCoreGraphicsFontData(wxGraphicsRenderer* renderer, const wxFont &font, const wxColour& col) + : wxGraphicsObjectRefData( renderer ), + m_colour(col) { m_underlined = font.GetUnderlined(); m_strikethrough = font.GetStrikethrough(); @@ -1468,7 +1531,7 @@ private: // device context implementation // // more and more of the dc functionality should be implemented by calling -// the appropricate wxMacCoreGraphicsContext, but we will have to do that step by step +// the appropriate wxMacCoreGraphicsContext, but we will have to do that step by step // also coordinate conversions should be moved to native matrix ops //----------------------------------------------------------------------------- @@ -2056,10 +2119,34 @@ void wxMacCoreGraphicsContext::StrokePath( const wxGraphicsPath &path ) return; wxQuartzOffsetHelper helper( m_cgContext , ShouldOffset() ); + wxMacCoreGraphicsPenData* penData = (wxMacCoreGraphicsPenData*)m_pen.GetRefData(); - ((wxMacCoreGraphicsPenData*)m_pen.GetRefData())->Apply(this); - CGContextAddPath( m_cgContext , (CGPathRef) path.GetNativePath() ); - CGContextStrokePath( m_cgContext ); + penData->Apply(this); + + if (penData->IsShading()) + { + // To stroke with a gradient we first have to turn the path into a path + // that is essentially the outline of the original stroke, and then fill + // that path. + CGContextSaveGState( m_cgContext ); + CGContextAddPath( m_cgContext, (CGPathRef)path.GetNativePath() ); + CGContextReplacePathWithStrokedPath(m_cgContext); + CGContextClip( m_cgContext ); + // Apply the gradient's transform, if there is one. + if (! penData->GetMatrix().IsNull() ) + { + wxGraphicsMatrix m = penData->GetMatrix(); + m.Invert(); + ConcatTransform(m); + } + CGContextDrawShading( m_cgContext, penData->GetShading() ); + CGContextRestoreGState( m_cgContext); + } + else + { + CGContextAddPath( m_cgContext, (CGPathRef)path.GetNativePath() ); + CGContextStrokePath( m_cgContext ); + } CheckInvariants(); } @@ -2072,7 +2159,8 @@ void wxMacCoreGraphicsContext::DrawPath( const wxGraphicsPath &path , wxPolygonF if (m_composition == wxCOMPOSITION_DEST) return; - if ( !m_brush.IsNull() && ((wxMacCoreGraphicsBrushData*)m_brush.GetRefData())->IsShading() ) + if ( (!m_brush.IsNull() && ((wxMacCoreGraphicsBrushData*)m_brush.GetRefData())->IsShading()) || + (!m_pen.IsNull() && ((wxMacCoreGraphicsPenData*)m_pen.GetRefData())->IsShading()) ) { // when using shading, we cannot draw pen and brush at the same time // revert to the base implementation of first filling and then stroking @@ -2130,12 +2218,21 @@ void wxMacCoreGraphicsContext::FillPath( const wxGraphicsPath &path , wxPolygonF if (m_composition == wxCOMPOSITION_DEST) return; - if ( ((wxMacCoreGraphicsBrushData*)m_brush.GetRefData())->IsShading() ) + wxMacCoreGraphicsBrushData* brushData = (wxMacCoreGraphicsBrushData*)m_brush.GetRefData(); + + if ( brushData->IsShading() ) { CGContextSaveGState( m_cgContext ); CGContextAddPath( m_cgContext , (CGPathRef) path.GetNativePath() ); CGContextClip( m_cgContext ); - CGContextDrawShading( m_cgContext, ((wxMacCoreGraphicsBrushData*)m_brush.GetRefData())->GetShading() ); + // Apply the gradient's transform, if there is one. + if (! brushData->GetMatrix().IsNull() ) + { + wxGraphicsMatrix m = brushData->GetMatrix(); + m.Invert(); + ConcatTransform(m); + } + CGContextDrawShading( m_cgContext, brushData->GetShading() ); CGContextRestoreGState( m_cgContext); } else @@ -2935,7 +3032,7 @@ wxMacCoreGraphicsRenderer::CreateLinearGradientBrush(wxDouble x1, wxDouble y1, { wxGraphicsBrush p; wxMacCoreGraphicsBrushData* d = new wxMacCoreGraphicsBrushData( this ); - d->CreateLinearGradientBrush(x1, y1, x2, y2, stops, matrix); + d->CreateLinearGradientShading(x1, y1, x2, y2, stops, matrix); p.SetRefData(d); return p; } @@ -2949,7 +3046,7 @@ wxMacCoreGraphicsRenderer::CreateRadialGradientBrush(wxDouble xo, wxDouble yo, { wxGraphicsBrush p; wxMacCoreGraphicsBrushData* d = new wxMacCoreGraphicsBrushData( this ); - d->CreateRadialGradientBrush(xo, yo, xc, yc, radius, stops, matrix); + d->CreateRadialGradientShading(xo, yo, xc, yc, radius, stops, matrix); p.SetRefData(d); return p; } From 97b8d67984b3edeafc89a57b5c9bc034392c5d32 Mon Sep 17 00:00:00 2001 From: Robin Dunn <> Date: Wed, 7 Aug 2019 11:42:22 -0700 Subject: [PATCH 25/41] Make section header comments a little more consistent --- src/osx/carbon/graphics.cpp | 42 +++++++++++-------------------------- 1 file changed, 12 insertions(+), 30 deletions(-) diff --git a/src/osx/carbon/graphics.cpp b/src/osx/carbon/graphics.cpp index 047ba7bd6f..e0144d3fce 100644 --- a/src/osx/carbon/graphics.cpp +++ b/src/osx/carbon/graphics.cpp @@ -87,7 +87,7 @@ extern "C" const double M_PI = 3.14159265358979; #endif -// +//----------------------------------------------------------------------------- // Pen, Brushes and Fonts // @@ -117,6 +117,7 @@ CGColorRef wxMacCreateCGColor( const wxColour& col ) return retval; } +//----------------------------------------------------------------------------- // CGPattern wrapper class: always allocate on heap, never call destructor class wxMacCoreGraphicsPattern @@ -732,9 +733,8 @@ void wxMacCoreGraphicsPenData::Apply( wxGraphicsContext* context ) } } -// -// Brush -// +//----------------------------------------------------------------------------- +// Brush data and supporting colour class // make sure we all use one class for all conversions from wx to native colour @@ -864,9 +864,8 @@ void wxMacCoreGraphicsBrushData::Apply( wxGraphicsContext* context ) } -// -// Font -// +//----------------------------------------------------------------------------- +// Font data class wxMacCoreGraphicsFontData : public wxGraphicsObjectRefData { @@ -913,6 +912,9 @@ wxMacCoreGraphicsFontData::~wxMacCoreGraphicsFontData() { } +//----------------------------------------------------------------------------- +// Bitmap data + class wxMacCoreGraphicsBitmapData : public wxGraphicsBitmapData { public: @@ -946,13 +948,8 @@ wxMacCoreGraphicsBitmapData::~wxMacCoreGraphicsBitmapData() } -// -// Graphics Matrix -// - -//----------------------------------------------------------------------------- -// wxMacCoreGraphicsMatrix declaration //----------------------------------------------------------------------------- +// Graphics Matrix data class WXDLLIMPEXP_CORE wxMacCoreGraphicsMatrixData : public wxGraphicsMatrixData { @@ -1013,9 +1010,6 @@ private : CGAffineTransform m_matrix; } ; -//----------------------------------------------------------------------------- -// wxMacCoreGraphicsMatrix implementation -//----------------------------------------------------------------------------- wxMacCoreGraphicsMatrixData::wxMacCoreGraphicsMatrixData(wxGraphicsRenderer* renderer) : wxGraphicsMatrixData(renderer) { @@ -1125,13 +1119,8 @@ void * wxMacCoreGraphicsMatrixData::GetNativeMatrix() const return (void*) &m_matrix; } -// -// Graphics Path -// - -//----------------------------------------------------------------------------- -// wxMacCoreGraphicsPath declaration //----------------------------------------------------------------------------- +// Graphics Path data class WXDLLEXPORT wxMacCoreGraphicsPathData : public wxGraphicsPathData { @@ -1200,9 +1189,6 @@ private : CGMutablePathRef m_path; }; -//----------------------------------------------------------------------------- -// wxMacCoreGraphicsPath implementation -//----------------------------------------------------------------------------- wxMacCoreGraphicsPathData::wxMacCoreGraphicsPathData( wxGraphicsRenderer* renderer, CGMutablePathRef path) : wxGraphicsPathData(renderer) { @@ -1359,13 +1345,9 @@ bool wxMacCoreGraphicsPathData::Contains( wxDouble x, wxDouble y, wxPolygonFillM return CGPathContainsPoint( m_path, NULL, CGPointMake((CGFloat) x,(CGFloat) y), fillStyle == wxODDEVEN_RULE ); } -// -// Graphics Context -// //----------------------------------------------------------------------------- -// wxMacCoreGraphicsContext declaration -//----------------------------------------------------------------------------- +// Graphics Context class WXDLLEXPORT wxMacCoreGraphicsContext : public wxGraphicsContext { From 222049f3ce7ec29cbeb18f31bef90308b3e6e91c Mon Sep 17 00:00:00 2001 From: Robin Dunn <> Date: Wed, 7 Aug 2019 12:10:44 -0700 Subject: [PATCH 26/41] Move wxMacCoreGraphicsMatrixData so it can be used in wxMacCoreGraphicsPenBrushDataBase --- src/osx/carbon/graphics.cpp | 377 ++++++++++++++++++------------------ 1 file changed, 191 insertions(+), 186 deletions(-) diff --git a/src/osx/carbon/graphics.cpp b/src/osx/carbon/graphics.cpp index e0144d3fce..2614051455 100644 --- a/src/osx/carbon/graphics.cpp +++ b/src/osx/carbon/graphics.cpp @@ -303,9 +303,181 @@ protected : int m_hatch; }; +//----------------------------------------------------------------------------- +// Graphics Matrix data + +class WXDLLIMPEXP_CORE wxMacCoreGraphicsMatrixData : public wxGraphicsMatrixData +{ +public : + wxMacCoreGraphicsMatrixData(wxGraphicsRenderer* renderer) ; + + virtual ~wxMacCoreGraphicsMatrixData() ; + + virtual wxGraphicsObjectRefData *Clone() const wxOVERRIDE ; + + // concatenates the matrix + virtual void Concat( const wxGraphicsMatrixData *t ) wxOVERRIDE; + + // sets the matrix to the respective values + virtual void Set(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; + + // gets the component valuess of the matrix + virtual void Get(wxDouble* a=NULL, wxDouble* b=NULL, wxDouble* c=NULL, + wxDouble* d=NULL, wxDouble* tx=NULL, wxDouble* ty=NULL) const wxOVERRIDE; + + // makes this the inverse matrix + virtual void Invert() wxOVERRIDE; + + // returns true if the elements of the transformation matrix are equal ? + virtual bool IsEqual( const wxGraphicsMatrixData* t) const wxOVERRIDE ; + + // return true if this is the identity matrix + virtual bool IsIdentity() const wxOVERRIDE; + + // + // transformation + // + + // add the translation to this matrix + virtual void Translate( wxDouble dx , wxDouble dy ) wxOVERRIDE; + + // add the scale to this matrix + virtual void Scale( wxDouble xScale , wxDouble yScale ) wxOVERRIDE; + + // add the rotation to this matrix (radians) + virtual void Rotate( wxDouble angle ) wxOVERRIDE; + + // + // apply the transforms + // + + // applies that matrix to the point + virtual void TransformPoint( wxDouble *x, wxDouble *y ) const wxOVERRIDE; + + // applies the matrix except for translations + virtual void TransformDistance( wxDouble *dx, wxDouble *dy ) const wxOVERRIDE; + + // returns the native representation + virtual void * GetNativeMatrix() const wxOVERRIDE; + +private : + CGAffineTransform m_matrix; +} ; + + +wxMacCoreGraphicsMatrixData::wxMacCoreGraphicsMatrixData(wxGraphicsRenderer* renderer) : wxGraphicsMatrixData(renderer) +{ +} + +wxMacCoreGraphicsMatrixData::~wxMacCoreGraphicsMatrixData() +{ +} + +wxGraphicsObjectRefData *wxMacCoreGraphicsMatrixData::Clone() const +{ + wxMacCoreGraphicsMatrixData* m = new wxMacCoreGraphicsMatrixData(GetRenderer()) ; + m->m_matrix = m_matrix ; + return m; +} + +// concatenates the matrix +void wxMacCoreGraphicsMatrixData::Concat( const wxGraphicsMatrixData *t ) +{ + m_matrix = CGAffineTransformConcat(*((CGAffineTransform*) t->GetNativeMatrix()), m_matrix ); +} + +// sets the matrix to the respective values +void wxMacCoreGraphicsMatrixData::Set(wxDouble a, wxDouble b, wxDouble c, wxDouble d, + wxDouble tx, wxDouble ty) +{ + m_matrix = CGAffineTransformMake((CGFloat) a,(CGFloat) b,(CGFloat) c,(CGFloat) d,(CGFloat) tx,(CGFloat) ty); +} + +// gets the component valuess of the matrix +void wxMacCoreGraphicsMatrixData::Get(wxDouble* a, wxDouble* b, wxDouble* c, + wxDouble* d, wxDouble* tx, wxDouble* ty) const +{ + if (a) *a = m_matrix.a; + if (b) *b = m_matrix.b; + if (c) *c = m_matrix.c; + if (d) *d = m_matrix.d; + if (tx) *tx= m_matrix.tx; + if (ty) *ty= m_matrix.ty; +} + +// makes this the inverse matrix +void wxMacCoreGraphicsMatrixData::Invert() +{ + m_matrix = CGAffineTransformInvert( m_matrix ); +} + +// returns true if the elements of the transformation matrix are equal ? +bool wxMacCoreGraphicsMatrixData::IsEqual( const wxGraphicsMatrixData* t) const +{ + return CGAffineTransformEqualToTransform(m_matrix, *((CGAffineTransform*) t->GetNativeMatrix())); +} + +// return true if this is the identity matrix +bool wxMacCoreGraphicsMatrixData::IsIdentity() const +{ + return ( m_matrix.a == 1 && m_matrix.d == 1 && + m_matrix.b == 0 && m_matrix.d == 0 && m_matrix.tx == 0 && m_matrix.ty == 0); +} + +// +// transformation +// + +// add the translation to this matrix +void wxMacCoreGraphicsMatrixData::Translate( wxDouble dx , wxDouble dy ) +{ + m_matrix = CGAffineTransformTranslate( m_matrix, (CGFloat) dx, (CGFloat) dy); +} + +// add the scale to this matrix +void wxMacCoreGraphicsMatrixData::Scale( wxDouble xScale , wxDouble yScale ) +{ + m_matrix = CGAffineTransformScale( m_matrix, (CGFloat) xScale, (CGFloat) yScale); +} + +// add the rotation to this matrix (radians) +void wxMacCoreGraphicsMatrixData::Rotate( wxDouble angle ) +{ + m_matrix = CGAffineTransformRotate( m_matrix, (CGFloat) angle); +} + +// +// apply the transforms +// + +// applies that matrix to the point +void wxMacCoreGraphicsMatrixData::TransformPoint( wxDouble *x, wxDouble *y ) const +{ + CGPoint pt = CGPointApplyAffineTransform( CGPointMake((CGFloat) *x,(CGFloat) *y), m_matrix); + + *x = pt.x; + *y = pt.y; +} + +// applies the matrix except for translations +void wxMacCoreGraphicsMatrixData::TransformDistance( wxDouble *dx, wxDouble *dy ) const +{ + CGSize sz = CGSizeApplyAffineTransform( CGSizeMake((CGFloat) *dx,(CGFloat) *dy) , m_matrix ); + *dx = sz.width; + *dy = sz.height; +} + +// returns the native representation +void * wxMacCoreGraphicsMatrixData::GetNativeMatrix() const +{ + return (void*) &m_matrix; +} + + // ---------------------------------------------------------------------------- -// Base class for information shared between pens and brushes, basically just -// the things needed for gradient support. +// Pen and Brush common data. Base class for information shared between pens and +// brushes, basically just the things needed for gradient support. class wxMacCoreGraphicsPenBrushDataBase : public wxGraphicsObjectRefData { @@ -324,7 +496,7 @@ public: virtual bool IsShading() { return m_isShading; } CGShadingRef GetShading() { return m_shading; } - wxGraphicsMatrix& GetMatrix() { return m_shadingMatrix; } + wxMacCoreGraphicsMatrixData* GetMatrix() { return m_shadingMatrix; } protected: void Init(); @@ -335,7 +507,7 @@ protected: bool m_isShading; CGFunctionRef m_gradientFunction; CGShadingRef m_shading; - wxGraphicsMatrix m_shadingMatrix; + wxMacCoreGraphicsMatrixData* m_shadingMatrix; // information about a single gradient component struct GradientComponent @@ -386,8 +558,11 @@ wxMacCoreGraphicsPenBrushDataBase::~wxMacCoreGraphicsPenBrushDataBase() if ( m_shading ) CGShadingRelease(m_shading); - if( m_gradientFunction ) + if ( m_gradientFunction ) CGFunctionRelease(m_gradientFunction); + + if ( m_shadingMatrix ) + delete m_shadingMatrix; } void @@ -396,6 +571,7 @@ wxMacCoreGraphicsPenBrushDataBase::Init() m_gradientFunction = NULL; m_shading = NULL; m_isShading = false; + m_shadingMatrix = NULL; } void @@ -411,7 +587,8 @@ wxMacCoreGraphicsPenBrushDataBase::CreateLinearGradientShading( CGPointMake((CGFloat) x2, (CGFloat) y2), m_gradientFunction, true, true ); m_isShading = true; - m_shadingMatrix = matrix; + m_shadingMatrix = (wxMacCoreGraphicsMatrixData*)((wxMacCoreGraphicsMatrixData*)matrix.GetRefData())->Clone(); + m_shadingMatrix->Invert(); } void @@ -428,7 +605,8 @@ wxMacCoreGraphicsPenBrushDataBase::CreateRadialGradientShading( CGPointMake((CGFloat) xc, (CGFloat) yc), (CGFloat) radius, m_gradientFunction, true, true ); m_isShading = true; - m_shadingMatrix = matrix; + m_shadingMatrix = (wxMacCoreGraphicsMatrixData*)((wxMacCoreGraphicsMatrixData*)matrix.GetRefData())->Clone(); + m_shadingMatrix->Invert(); } void wxMacCoreGraphicsPenBrushDataBase::CalculateShadingValues(void *info, const CGFloat *in, CGFloat *out) @@ -948,177 +1126,6 @@ wxMacCoreGraphicsBitmapData::~wxMacCoreGraphicsBitmapData() } -//----------------------------------------------------------------------------- -// Graphics Matrix data - -class WXDLLIMPEXP_CORE wxMacCoreGraphicsMatrixData : public wxGraphicsMatrixData -{ -public : - wxMacCoreGraphicsMatrixData(wxGraphicsRenderer* renderer) ; - - virtual ~wxMacCoreGraphicsMatrixData() ; - - virtual wxGraphicsObjectRefData *Clone() const wxOVERRIDE ; - - // concatenates the matrix - virtual void Concat( const wxGraphicsMatrixData *t ) wxOVERRIDE; - - // sets the matrix to the respective values - virtual void Set(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; - - // gets the component valuess of the matrix - virtual void Get(wxDouble* a=NULL, wxDouble* b=NULL, wxDouble* c=NULL, - wxDouble* d=NULL, wxDouble* tx=NULL, wxDouble* ty=NULL) const wxOVERRIDE; - - // makes this the inverse matrix - virtual void Invert() wxOVERRIDE; - - // returns true if the elements of the transformation matrix are equal ? - virtual bool IsEqual( const wxGraphicsMatrixData* t) const wxOVERRIDE ; - - // return true if this is the identity matrix - virtual bool IsIdentity() const wxOVERRIDE; - - // - // transformation - // - - // add the translation to this matrix - virtual void Translate( wxDouble dx , wxDouble dy ) wxOVERRIDE; - - // add the scale to this matrix - virtual void Scale( wxDouble xScale , wxDouble yScale ) wxOVERRIDE; - - // add the rotation to this matrix (radians) - virtual void Rotate( wxDouble angle ) wxOVERRIDE; - - // - // apply the transforms - // - - // applies that matrix to the point - virtual void TransformPoint( wxDouble *x, wxDouble *y ) const wxOVERRIDE; - - // applies the matrix except for translations - virtual void TransformDistance( wxDouble *dx, wxDouble *dy ) const wxOVERRIDE; - - // returns the native representation - virtual void * GetNativeMatrix() const wxOVERRIDE; - -private : - CGAffineTransform m_matrix; -} ; - - -wxMacCoreGraphicsMatrixData::wxMacCoreGraphicsMatrixData(wxGraphicsRenderer* renderer) : wxGraphicsMatrixData(renderer) -{ -} - -wxMacCoreGraphicsMatrixData::~wxMacCoreGraphicsMatrixData() -{ -} - -wxGraphicsObjectRefData *wxMacCoreGraphicsMatrixData::Clone() const -{ - wxMacCoreGraphicsMatrixData* m = new wxMacCoreGraphicsMatrixData(GetRenderer()) ; - m->m_matrix = m_matrix ; - return m; -} - -// concatenates the matrix -void wxMacCoreGraphicsMatrixData::Concat( const wxGraphicsMatrixData *t ) -{ - m_matrix = CGAffineTransformConcat(*((CGAffineTransform*) t->GetNativeMatrix()), m_matrix ); -} - -// sets the matrix to the respective values -void wxMacCoreGraphicsMatrixData::Set(wxDouble a, wxDouble b, wxDouble c, wxDouble d, - wxDouble tx, wxDouble ty) -{ - m_matrix = CGAffineTransformMake((CGFloat) a,(CGFloat) b,(CGFloat) c,(CGFloat) d,(CGFloat) tx,(CGFloat) ty); -} - -// gets the component valuess of the matrix -void wxMacCoreGraphicsMatrixData::Get(wxDouble* a, wxDouble* b, wxDouble* c, - wxDouble* d, wxDouble* tx, wxDouble* ty) const -{ - if (a) *a = m_matrix.a; - if (b) *b = m_matrix.b; - if (c) *c = m_matrix.c; - if (d) *d = m_matrix.d; - if (tx) *tx= m_matrix.tx; - if (ty) *ty= m_matrix.ty; -} - -// makes this the inverse matrix -void wxMacCoreGraphicsMatrixData::Invert() -{ - m_matrix = CGAffineTransformInvert( m_matrix ); -} - -// returns true if the elements of the transformation matrix are equal ? -bool wxMacCoreGraphicsMatrixData::IsEqual( const wxGraphicsMatrixData* t) const -{ - return CGAffineTransformEqualToTransform(m_matrix, *((CGAffineTransform*) t->GetNativeMatrix())); -} - -// return true if this is the identity matrix -bool wxMacCoreGraphicsMatrixData::IsIdentity() const -{ - return ( m_matrix.a == 1 && m_matrix.d == 1 && - m_matrix.b == 0 && m_matrix.d == 0 && m_matrix.tx == 0 && m_matrix.ty == 0); -} - -// -// transformation -// - -// add the translation to this matrix -void wxMacCoreGraphicsMatrixData::Translate( wxDouble dx , wxDouble dy ) -{ - m_matrix = CGAffineTransformTranslate( m_matrix, (CGFloat) dx, (CGFloat) dy); -} - -// add the scale to this matrix -void wxMacCoreGraphicsMatrixData::Scale( wxDouble xScale , wxDouble yScale ) -{ - m_matrix = CGAffineTransformScale( m_matrix, (CGFloat) xScale, (CGFloat) yScale); -} - -// add the rotation to this matrix (radians) -void wxMacCoreGraphicsMatrixData::Rotate( wxDouble angle ) -{ - m_matrix = CGAffineTransformRotate( m_matrix, (CGFloat) angle); -} - -// -// apply the transforms -// - -// applies that matrix to the point -void wxMacCoreGraphicsMatrixData::TransformPoint( wxDouble *x, wxDouble *y ) const -{ - CGPoint pt = CGPointApplyAffineTransform( CGPointMake((CGFloat) *x,(CGFloat) *y), m_matrix); - - *x = pt.x; - *y = pt.y; -} - -// applies the matrix except for translations -void wxMacCoreGraphicsMatrixData::TransformDistance( wxDouble *dx, wxDouble *dy ) const -{ - CGSize sz = CGSizeApplyAffineTransform( CGSizeMake((CGFloat) *dx,(CGFloat) *dy) , m_matrix ); - *dx = sz.width; - *dy = sz.height; -} - -// returns the native representation -void * wxMacCoreGraphicsMatrixData::GetNativeMatrix() const -{ - return (void*) &m_matrix; -} - //----------------------------------------------------------------------------- // Graphics Path data @@ -2115,11 +2122,10 @@ void wxMacCoreGraphicsContext::StrokePath( const wxGraphicsPath &path ) CGContextReplacePathWithStrokedPath(m_cgContext); CGContextClip( m_cgContext ); // Apply the gradient's transform, if there is one. - if (! penData->GetMatrix().IsNull() ) + if ( penData->GetMatrix() != NULL ) { - wxGraphicsMatrix m = penData->GetMatrix(); - m.Invert(); - ConcatTransform(m); + wxMacCoreGraphicsMatrixData* m = penData->GetMatrix(); + CGContextConcatCTM( m_cgContext, *(CGAffineTransform*) m->GetNativeMatrix()); } CGContextDrawShading( m_cgContext, penData->GetShading() ); CGContextRestoreGState( m_cgContext); @@ -2208,11 +2214,10 @@ void wxMacCoreGraphicsContext::FillPath( const wxGraphicsPath &path , wxPolygonF CGContextAddPath( m_cgContext , (CGPathRef) path.GetNativePath() ); CGContextClip( m_cgContext ); // Apply the gradient's transform, if there is one. - if (! brushData->GetMatrix().IsNull() ) + if ( brushData->GetMatrix() != NULL ) { - wxGraphicsMatrix m = brushData->GetMatrix(); - m.Invert(); - ConcatTransform(m); + wxMacCoreGraphicsMatrixData* m = brushData->GetMatrix(); + CGContextConcatCTM( m_cgContext, *(CGAffineTransform*) m->GetNativeMatrix()); } CGContextDrawShading( m_cgContext, brushData->GetShading() ); CGContextRestoreGState( m_cgContext); From 320acc1796c935e0eaf29da68f437eb7bf72a3cb Mon Sep 17 00:00:00 2001 From: Robin Dunn <> Date: Wed, 7 Aug 2019 15:38:28 -0700 Subject: [PATCH 27/41] Only clone the gradient's matrix when there is one --- src/osx/carbon/graphics.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/osx/carbon/graphics.cpp b/src/osx/carbon/graphics.cpp index 2614051455..5e2c89e3d7 100644 --- a/src/osx/carbon/graphics.cpp +++ b/src/osx/carbon/graphics.cpp @@ -475,6 +475,7 @@ void * wxMacCoreGraphicsMatrixData::GetNativeMatrix() const } + // ---------------------------------------------------------------------------- // Pen and Brush common data. Base class for information shared between pens and // brushes, basically just the things needed for gradient support. @@ -587,8 +588,11 @@ wxMacCoreGraphicsPenBrushDataBase::CreateLinearGradientShading( CGPointMake((CGFloat) x2, (CGFloat) y2), m_gradientFunction, true, true ); m_isShading = true; - m_shadingMatrix = (wxMacCoreGraphicsMatrixData*)((wxMacCoreGraphicsMatrixData*)matrix.GetRefData())->Clone(); - m_shadingMatrix->Invert(); + if (! matrix.IsNull() ) + { + m_shadingMatrix = (wxMacCoreGraphicsMatrixData*)((wxMacCoreGraphicsMatrixData*)matrix.GetRefData())->Clone(); + m_shadingMatrix->Invert(); + } } void @@ -605,8 +609,11 @@ wxMacCoreGraphicsPenBrushDataBase::CreateRadialGradientShading( CGPointMake((CGFloat) xc, (CGFloat) yc), (CGFloat) radius, m_gradientFunction, true, true ); m_isShading = true; - m_shadingMatrix = (wxMacCoreGraphicsMatrixData*)((wxMacCoreGraphicsMatrixData*)matrix.GetRefData())->Clone(); - m_shadingMatrix->Invert(); + if (! matrix.IsNull() ) + { + m_shadingMatrix = (wxMacCoreGraphicsMatrixData*)((wxMacCoreGraphicsMatrixData*)matrix.GetRefData())->Clone(); + m_shadingMatrix->Invert(); + } } void wxMacCoreGraphicsPenBrushDataBase::CalculateShadingValues(void *info, const CGFloat *in, CGFloat *out) From 78c1c6ca6d8a0e35ac297820dfe490c01167f0c3 Mon Sep 17 00:00:00 2001 From: Robin Dunn <> Date: Mon, 26 Aug 2019 15:47:19 -0700 Subject: [PATCH 28/41] Remove TODO --- src/msw/graphicsd2d.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/msw/graphicsd2d.cpp b/src/msw/graphicsd2d.cpp index 112cebd8fa..07c242ddf3 100644 --- a/src/msw/graphicsd2d.cpp +++ b/src/msw/graphicsd2d.cpp @@ -2510,7 +2510,6 @@ protected: wxD2DGradientStopsHelper helper(m_radialGradientInfo.stops, GetContext()); ID2D1RadialGradientBrush *radialGradientBrush; - // TODO: double check this. The other backends just use the passed in values for xo, yo wxDouble xo = m_radialGradientInfo.x1 - m_radialGradientInfo.x2; wxDouble yo = m_radialGradientInfo.y1 - m_radialGradientInfo.y2; From 80f24d9e74a98c940e90b224cdefd0b4735489cb Mon Sep 17 00:00:00 2001 From: Robin Dunn <> Date: Mon, 26 Aug 2019 20:24:07 -0700 Subject: [PATCH 29/41] User more easily understandable names for the radial gradient coordinate parameters in wxGraphicsPenInfo --- include/wx/graphics.h | 30 ++++++++++++++++-------------- include/wx/motif/cursor.h | 2 +- interface/wx/graphics.h | 14 ++++++++------ src/generic/graphicc.cpp | 4 ++-- src/msw/graphics.cpp | 4 ++-- src/msw/graphicsd2d.cpp | 4 ++-- src/osx/carbon/graphics.cpp | 4 ++-- 7 files changed, 33 insertions(+), 29 deletions(-) diff --git a/include/wx/graphics.h b/include/wx/graphics.h index 13926d144a..9f71f7cd60 100644 --- a/include/wx/graphics.h +++ b/include/wx/graphics.h @@ -403,15 +403,16 @@ public: } wxGraphicsPenInfo& - RadialGradient(wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius, + RadialGradient(wxDouble startX, wxDouble startY, + wxDouble endX, wxDouble endY, wxDouble radius, const wxColour& oColor, const wxColour& cColor, const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) { m_gradientType = wxGRADIENT_RADIAL; - m_x1 = xo; - m_y1 = yo; - m_x2 = xc; - m_y2 = yc; + m_x1 = startX; + m_y1 = startY; + m_x2 = endX; + m_y2 = endY; m_radius = radius; m_stops.SetStartColour(oColor); m_stops.SetEndColour(cColor); @@ -420,15 +421,16 @@ public: } wxGraphicsPenInfo& - RadialGradient(wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, + RadialGradient(wxDouble startX, wxDouble startY, + wxDouble endX, wxDouble endY, wxDouble radius, const wxGraphicsGradientStops& stops, const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) { m_gradientType = wxGRADIENT_RADIAL; - m_x1 = xo; - m_y1 = yo; - m_x2 = xc; - m_y2 = yc; + m_x1 = startX; + m_y1 = startY; + m_x2 = endX; + m_y2 = endY; m_radius = radius; m_stops = stops; m_matrix = matrix; @@ -443,10 +445,10 @@ public: wxDouble GetY1() const { return m_y1; } wxDouble GetX2() const { return m_x2; } wxDouble GetY2() const { return m_y2; } - wxDouble GetXO() const { return m_x1; } - wxDouble GetYO() const { return m_y1; } - wxDouble GetXC() const { return m_x2; } - wxDouble GetYC() const { return m_y2; } + wxDouble GetStartX() const { return m_x1; } + wxDouble GetStartY() const { return m_y1; } + wxDouble GetEndX() const { return m_x2; } + wxDouble GetEndY() const { return m_y2; } wxDouble GetRadius() const { return m_radius; } const wxGraphicsGradientStops& GetStops() const { return m_stops; } const wxGraphicsMatrix& GetMatrix() const { return m_matrix; } diff --git a/include/wx/motif/cursor.h b/include/wx/motif/cursor.h index 0658abc6ec..0cce9a83a1 100644 --- a/include/wx/motif/cursor.h +++ b/include/wx/motif/cursor.h @@ -43,7 +43,7 @@ public: // Motif-specific. // Create/get a cursor for the current display - WXCursor GetXCursor(WXDisplay* display) const; + WXCursor GetEndXursor(WXDisplay* display) const; protected: virtual wxGDIRefData *CreateGDIRefData() const; diff --git a/interface/wx/graphics.h b/interface/wx/graphics.h index b9ebcb4a02..6901f0ea43 100644 --- a/interface/wx/graphics.h +++ b/interface/wx/graphics.h @@ -1645,12 +1645,14 @@ public: const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix); wxGraphicsPenInfo& - RadialGradient(wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius, + RadialGradient(wxDouble startX, wxDouble startY, + wxDouble endX, wxDouble endY, wxDouble radius, const wxColour& oColor, const wxColour& cColor, const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix); wxGraphicsPenInfo& - RadialGradient(wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, + RadialGradient(wxDouble startX, wxDouble startY, + wxDouble endX, wxDouble endY, wxDouble radius, const wxGraphicsGradientStops& stops, const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix); @@ -1669,10 +1671,10 @@ public: wxDouble GetY1() const; wxDouble GetX2() const; wxDouble GetY2() const; - wxDouble GetXO() const; - wxDouble GetYO() const; - wxDouble GetXC() const; - wxDouble GetYC() const; + wxDouble GetStartX() const; + wxDouble GetStartY() const; + wxDouble GetEndX() const; + wxDouble GetEndY() const; wxDouble GetRadius() const; const wxGraphicsGradientStops& GetStops() const; }; diff --git a/src/generic/graphicc.cpp b/src/generic/graphicc.cpp index 5366b8ac1e..7674e11370 100644 --- a/src/generic/graphicc.cpp +++ b/src/generic/graphicc.cpp @@ -943,8 +943,8 @@ wxCairoPenData::wxCairoPenData( wxGraphicsRenderer* renderer, const wxGraphicsPe break; case wxGRADIENT_RADIAL: - CreateRadialGradientPattern(info.GetXO(), info.GetYO(), - info.GetXC(), info.GetYC(), + CreateRadialGradientPattern(info.GetStartX(), info.GetStartY(), + info.GetEndX(), info.GetEndY(), info.GetRadius(), info.GetStops(), info.GetMatrix()); diff --git a/src/msw/graphics.cpp b/src/msw/graphics.cpp index 9313f99e75..a8644d3e07 100644 --- a/src/msw/graphics.cpp +++ b/src/msw/graphics.cpp @@ -996,8 +996,8 @@ wxGDIPlusPenData::wxGDIPlusPenData( wxGraphicsRenderer* renderer, case wxGRADIENT_RADIAL: if (m_brush) delete m_brush; - CreateRadialGradientBrush(info.GetXO(), info.GetYO(), - info.GetXC(), info.GetYC(), + CreateRadialGradientBrush(info.GetStartX(), info.GetStartY(), + info.GetEndX(), info.GetEndY(), info.GetRadius(), info.GetStops()); m_pen->SetBrush(m_brush); diff --git a/src/msw/graphicsd2d.cpp b/src/msw/graphicsd2d.cpp index 07c242ddf3..67febac98d 100644 --- a/src/msw/graphicsd2d.cpp +++ b/src/msw/graphicsd2d.cpp @@ -2741,8 +2741,8 @@ wxD2DPenData::wxD2DPenData( case wxGRADIENT_RADIAL: m_stippleBrush = new wxD2DBrushData(renderer); m_stippleBrush->CreateRadialGradientBrush( - m_penInfo.GetXO(), m_penInfo.GetYO(), - m_penInfo.GetXC(), m_penInfo.GetYC(), + m_penInfo.GetStartX(), m_penInfo.GetStartY(), + m_penInfo.GetEndX(), m_penInfo.GetEndY(), m_penInfo.GetRadius(), m_penInfo.GetStops(), m_penInfo.GetMatrix()); diff --git a/src/osx/carbon/graphics.cpp b/src/osx/carbon/graphics.cpp index 5e2c89e3d7..9d48d2f106 100644 --- a/src/osx/carbon/graphics.cpp +++ b/src/osx/carbon/graphics.cpp @@ -870,8 +870,8 @@ wxMacCoreGraphicsPenData::wxMacCoreGraphicsPenData( wxGraphicsRenderer* renderer break; case wxGRADIENT_RADIAL: - CreateRadialGradientShading(info.GetXO(), info.GetYO(), - info.GetXC(), info.GetYC(), + CreateRadialGradientShading(info.GetStartX(), info.GetStartY(), + info.GetEndX(), info.GetEndY(), info.GetRadius(), info.GetStops(), info.GetMatrix()); From 30dfe45759f6c28f0c62e51b5be9c48b40a08605 Mon Sep 17 00:00:00 2001 From: Robin Dunn <> Date: Tue, 27 Aug 2019 08:08:22 -0700 Subject: [PATCH 30/41] undo incorrect search/replace --- include/wx/motif/cursor.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/wx/motif/cursor.h b/include/wx/motif/cursor.h index 0cce9a83a1..0658abc6ec 100644 --- a/include/wx/motif/cursor.h +++ b/include/wx/motif/cursor.h @@ -43,7 +43,7 @@ public: // Motif-specific. // Create/get a cursor for the current display - WXCursor GetEndXursor(WXDisplay* display) const; + WXCursor GetXCursor(WXDisplay* display) const; protected: virtual wxGDIRefData *CreateGDIRefData() const; From c79085b54de3b0cc5263b42b24476199e3556901 Mon Sep 17 00:00:00 2001 From: Robin Dunn <> Date: Tue, 27 Aug 2019 13:54:26 -0700 Subject: [PATCH 31/41] (blind) compilation fix for wxQtGraphicsRenderer gradient brush methods --- src/qt/graphics.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/qt/graphics.cpp b/src/qt/graphics.cpp index be97b85cfe..8a9059cced 100644 --- a/src/qt/graphics.cpp +++ b/src/qt/graphics.cpp @@ -1137,13 +1137,15 @@ public: virtual wxGraphicsBrush CreateLinearGradientBrush(wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, - const wxGraphicsGradientStops& stops) wxOVERRIDE; + const wxGraphicsGradientStops& stops, + const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) wxOVERRIDE; virtual wxGraphicsBrush CreateRadialGradientBrush(wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius, - const wxGraphicsGradientStops& stops) wxOVERRIDE; + const wxGraphicsGradientStops& stops, + const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) wxOVERRIDE; // sets the font virtual wxGraphicsFont CreateFont(const wxFont& font, @@ -1274,7 +1276,8 @@ wxGraphicsBrush wxQtGraphicsRenderer::CreateBrush(const wxBrush& brush) wxGraphicsBrush wxQtGraphicsRenderer::CreateLinearGradientBrush( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, - const wxGraphicsGradientStops& stops) + const wxGraphicsGradientStops& stops, + const wxGraphicsMatrix& WXUNUSED(matrix)) { wxGraphicsBrush p; wxQtBrushData* d = new wxQtBrushData(this); @@ -1286,7 +1289,8 @@ wxGraphicsBrush wxQtGraphicsRenderer::CreateLinearGradientBrush( wxGraphicsBrush wxQtGraphicsRenderer::CreateRadialGradientBrush( wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble r, - const wxGraphicsGradientStops& stops) + const wxGraphicsGradientStops& stops, + const wxGraphicsMatrix& WXUNUSED(matrix)) { wxGraphicsBrush p; wxQtBrushData* d = new wxQtBrushData(this); From f7896d4dffea70ace810b775912d944c081cf092 Mon Sep 17 00:00:00 2001 From: Robin Dunn <> Date: Tue, 27 Aug 2019 18:02:19 -0700 Subject: [PATCH 32/41] Use new parameter names in the existing CreateRadialGradientBrush methods too --- include/wx/graphics.h | 12 ++++++------ interface/wx/graphics.h | 16 ++++++++-------- src/common/graphcmn.cpp | 16 ++++++++-------- src/generic/graphicc.cpp | 20 ++++++++++---------- src/msw/graphics.cpp | 22 +++++++++++----------- src/msw/graphicsd2d.cpp | 20 ++++++++++---------- src/osx/carbon/graphics.cpp | 22 +++++++++++----------- src/qt/graphics.cpp | 16 ++++++++-------- 8 files changed, 72 insertions(+), 72 deletions(-) diff --git a/include/wx/graphics.h b/include/wx/graphics.h index 9f71f7cd60..ddc1393610 100644 --- a/include/wx/graphics.h +++ b/include/wx/graphics.h @@ -637,14 +637,14 @@ public: // on a circle around (xc,yc) with the given radius; the colours may be // specified by just the two extremes or the full array of gradient stops wxGraphicsBrush - CreateRadialGradientBrush(wxDouble xo, wxDouble yo, - wxDouble xc, wxDouble yc, wxDouble radius, + CreateRadialGradientBrush(wxDouble startX, wxDouble startY, + wxDouble endX, wxDouble endY, wxDouble radius, const wxColour& oColor, const wxColour& cColor, const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) const; wxGraphicsBrush - CreateRadialGradientBrush(wxDouble xo, wxDouble yo, - wxDouble xc, wxDouble yc, wxDouble radius, + CreateRadialGradientBrush(wxDouble startX, wxDouble startY, + wxDouble endX, wxDouble endY, wxDouble radius, const wxGraphicsGradientStops& stops, const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) const; @@ -1026,8 +1026,8 @@ public: const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) = 0; virtual wxGraphicsBrush - CreateRadialGradientBrush(wxDouble xo, wxDouble yo, - wxDouble xc, wxDouble yc, + CreateRadialGradientBrush(wxDouble startX, wxDouble startY, + wxDouble endX, wxDouble endY, wxDouble radius, const wxGraphicsGradientStops& stops, const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) = 0; diff --git a/interface/wx/graphics.h b/interface/wx/graphics.h index 6901f0ea43..48d8301e42 100644 --- a/interface/wx/graphics.h +++ b/interface/wx/graphics.h @@ -659,8 +659,8 @@ public: /** Creates a native brush with a radial gradient. - The brush originates at (@a xo, @a yc) and ends on a circle around - (@a xc, @a yc) with the given @a radius. + The brush originates at (@a startX, @a startY) and ends on a circle around + (@a endX, @a endY) with the given @a radius. The gradient may be specified either by its start and end colours @a oColor and @a cColor or by a full set of gradient @a stops. @@ -668,8 +668,8 @@ public: The version taking wxGraphicsGradientStops is new in wxWidgets 2.9.1. */ virtual wxGraphicsBrush - CreateRadialGradientBrush(wxDouble xo, wxDouble yo, - wxDouble xc, wxDouble yc, + CreateRadialGradientBrush(wxDouble startX, wxDouble startY, + wxDouble endX, wxDouble endY, wxDouble radius, const wxColour& oColor, const wxColour& cColor, @@ -679,8 +679,8 @@ public: @overload */ virtual wxGraphicsBrush - CreateRadialGradientBrush(wxDouble xo, wxDouble yo, - wxDouble xc, wxDouble yc, + CreateRadialGradientBrush(wxDouble startX, wxDouble startY, + wxDouble endX, wxDouble endY, wxDouble radius, const wxGraphicsGradientStops& stops, const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) = 0; @@ -1490,8 +1490,8 @@ public: Stops support is new since wxWidgets 2.9.1, previously only the start and end colours could be specified. */ - virtual wxGraphicsBrush CreateRadialGradientBrush(wxDouble xo, wxDouble yo, - wxDouble xc, wxDouble yc, + virtual wxGraphicsBrush CreateRadialGradientBrush(wxDouble startX, wxDouble startY, + wxDouble endX, wxDouble endY, wxDouble radius, const wxGraphicsGradientStops& stops, const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) = 0; diff --git a/src/common/graphcmn.cpp b/src/common/graphcmn.cpp index 460b16c9df..99f1e81532 100644 --- a/src/common/graphcmn.cpp +++ b/src/common/graphcmn.cpp @@ -913,15 +913,15 @@ wxGraphicsContext::CreateLinearGradientBrush( wxGraphicsBrush wxGraphicsContext::CreateRadialGradientBrush( - wxDouble xo, wxDouble yo, - wxDouble xc, wxDouble yc, wxDouble radius, + wxDouble startX, wxDouble startY, + wxDouble endX, wxDouble endY, wxDouble radius, const wxColour &oColor, const wxColour &cColor, const wxGraphicsMatrix& matrix) const { return GetRenderer()->CreateRadialGradientBrush ( - xo, yo, - xc, yc, radius, + startX, startY, + endX, endY, radius, wxGraphicsGradientStops(oColor, cColor), matrix ); @@ -929,15 +929,15 @@ wxGraphicsContext::CreateRadialGradientBrush( wxGraphicsBrush wxGraphicsContext::CreateRadialGradientBrush( - wxDouble xo, wxDouble yo, - wxDouble xc, wxDouble yc, wxDouble radius, + wxDouble startX, wxDouble startY, + wxDouble endX, wxDouble endY, wxDouble radius, const wxGraphicsGradientStops& gradientStops, const wxGraphicsMatrix& matrix) const { return GetRenderer()->CreateRadialGradientBrush ( - xo, yo, - xc, yc, radius, + startX, startY, + endX, endY, radius, gradientStops, matrix ); diff --git a/src/generic/graphicc.cpp b/src/generic/graphicc.cpp index 7674e11370..3fce559fef 100644 --- a/src/generic/graphicc.cpp +++ b/src/generic/graphicc.cpp @@ -264,8 +264,8 @@ public: wxDouble x2, wxDouble y2, const wxGraphicsGradientStops& stops, const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix); - void CreateRadialGradientPattern(wxDouble xo, wxDouble yo, - wxDouble xc, wxDouble yc, wxDouble radius, + void CreateRadialGradientPattern(wxDouble startX, wxDouble startY, + wxDouble endX, wxDouble endY, wxDouble radius, const wxGraphicsGradientStops& stops, const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix); @@ -765,13 +765,13 @@ wxCairoPenBrushBaseData::CreateLinearGradientPattern(wxDouble x1, wxDouble y1, } void -wxCairoPenBrushBaseData::CreateRadialGradientPattern(wxDouble xo, wxDouble yo, - wxDouble xc, wxDouble yc, +wxCairoPenBrushBaseData::CreateRadialGradientPattern(wxDouble startX, wxDouble startY, + wxDouble endX, wxDouble endY, wxDouble radius, const wxGraphicsGradientStops& stops, const wxGraphicsMatrix& matrix) { - m_pattern = cairo_pattern_create_radial(xo,yo,0.0,xc,yc,radius); + m_pattern = cairo_pattern_create_radial(startX,startY,0.0,endX,endY,radius); if (! matrix.IsNull()) { @@ -2997,8 +2997,8 @@ public : const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) wxOVERRIDE; virtual wxGraphicsBrush - CreateRadialGradientBrush(wxDouble xo, wxDouble yo, - wxDouble xc, wxDouble yc, + CreateRadialGradientBrush(wxDouble startX, wxDouble startY, + wxDouble endX, wxDouble endY, wxDouble radius, const wxGraphicsGradientStops& stops, const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) wxOVERRIDE; @@ -3201,15 +3201,15 @@ wxCairoRenderer::CreateLinearGradientBrush(wxDouble x1, wxDouble y1, } wxGraphicsBrush -wxCairoRenderer::CreateRadialGradientBrush(wxDouble xo, wxDouble yo, - wxDouble xc, wxDouble yc, wxDouble r, +wxCairoRenderer::CreateRadialGradientBrush(wxDouble startX, wxDouble startX, + wxDouble endX, wxDouble endY, wxDouble r, const wxGraphicsGradientStops& stops, const wxGraphicsMatrix& matrix) { wxGraphicsBrush p; ENSURE_LOADED_OR_RETURN(p); wxCairoBrushData* d = new wxCairoBrushData( this ); - d->CreateRadialGradientPattern(xo, yo, xc, yc, r, stops, matrix); + d->CreateRadialGradientPattern(startX, startY, endX, endY, r, stops, matrix); p.SetRefData(d); return p; } diff --git a/src/msw/graphics.cpp b/src/msw/graphics.cpp index a8644d3e07..bcd1ceb4c4 100644 --- a/src/msw/graphics.cpp +++ b/src/msw/graphics.cpp @@ -269,8 +269,8 @@ public: wxDouble x2, wxDouble y2, const wxGraphicsGradientStops& stops, const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix); - void CreateRadialGradientBrush(wxDouble xo, wxDouble yo, - wxDouble xc, wxDouble yc, + void CreateRadialGradientBrush(wxDouble startX, wxDouble startY, + wxDouble endX, wxDouble endY, wxDouble radius, const wxGraphicsGradientStops& stops, const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix); @@ -639,8 +639,8 @@ public : const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) wxOVERRIDE; virtual wxGraphicsBrush - CreateRadialGradientBrush(wxDouble xo, wxDouble yo, - wxDouble xc, wxDouble yc, + CreateRadialGradientBrush(wxDouble startX, wxDouble startY, + wxDouble endX, wxDouble endY, wxDouble radius, const wxGraphicsGradientStops& stops, const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) wxOVERRIDE; @@ -776,18 +776,18 @@ wxGDIPlusPenBrushBaseData::CreateLinearGradientBrush( void wxGDIPlusPenBrushBaseData::CreateRadialGradientBrush( - wxDouble xo, wxDouble yo, - wxDouble xc, wxDouble yc, + wxDouble startX, wxDouble startY, + wxDouble endX, wxDouble endY, wxDouble radius, const wxGraphicsGradientStops& stops, const wxGraphicsMatrix& matrix) { m_brushPath = new GraphicsPath(); - m_brushPath->AddEllipse( (REAL)(xc-radius), (REAL)(yc-radius), + m_brushPath->AddEllipse( (REAL)(endX-radius), (REAL)(endY-radius), (REAL)(2*radius), (REAL)(2*radius)); PathGradientBrush * const brush = new PathGradientBrush(m_brushPath); - brush->SetCenterPoint(PointF(xo, yo)); + brush->SetCenterPoint(PointF(startX, startY)); brush->SetCenterColor(wxColourToColor(stops.GetStartColour())); const Color col(wxColourToColor(stops.GetEndColour())); @@ -2701,8 +2701,8 @@ wxGDIPlusRenderer::CreateLinearGradientBrush(wxDouble x1, wxDouble y1, } wxGraphicsBrush -wxGDIPlusRenderer::CreateRadialGradientBrush(wxDouble xo, wxDouble yo, - wxDouble xc, wxDouble yc, +wxGDIPlusRenderer::CreateRadialGradientBrush(wxDouble startX, wxDouble startY, + wxDouble endX, wxDouble endY, wxDouble radius, const wxGraphicsGradientStops& stops, const wxGraphicsMatrix& matrix) @@ -2710,7 +2710,7 @@ wxGDIPlusRenderer::CreateRadialGradientBrush(wxDouble xo, wxDouble yo, ENSURE_LOADED_OR_RETURN(wxNullGraphicsBrush); wxGraphicsBrush p; wxGDIPlusBrushData* d = new wxGDIPlusBrushData( this ); - d->CreateRadialGradientBrush(xo,yo,xc,yc,radius,stops,matrix); + d->CreateRadialGradientBrush(startX,startY,endX,endY,radius,stops,matrix); p.SetRefData(d); return p; } diff --git a/src/msw/graphicsd2d.cpp b/src/msw/graphicsd2d.cpp index 67febac98d..805b1d9b76 100644 --- a/src/msw/graphicsd2d.cpp +++ b/src/msw/graphicsd2d.cpp @@ -2551,8 +2551,8 @@ public: const wxGraphicsGradientStops& stops, const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix); - void CreateRadialGradientBrush(wxDouble xo, wxDouble yo, - wxDouble xc, wxDouble yc, + void CreateRadialGradientBrush(wxDouble startX, wxDouble startY, + wxDouble endX, wxDouble endY, wxDouble radius, const wxGraphicsGradientStops& stops, const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix); @@ -2608,14 +2608,14 @@ void wxD2DBrushData::CreateLinearGradientBrush( } void wxD2DBrushData::CreateRadialGradientBrush( - wxDouble xo, wxDouble yo, - wxDouble xc, wxDouble yc, + wxDouble startX, wxDouble startY, + wxDouble endX, wxDouble endY, wxDouble radius, const wxGraphicsGradientStops& stops, const wxGraphicsMatrix& matrix) { m_brushResourceHolder = new wxD2DRadialGradientBrushResourceHolder( - xo, yo, xc, yc, radius, stops, matrix); + startX, startY, endX, endY, radius, stops, matrix); } wxD2DBrushData* wxGetD2DBrushData(const wxGraphicsBrush& brush) @@ -4645,8 +4645,8 @@ public : const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) wxOVERRIDE; wxGraphicsBrush CreateRadialGradientBrush( - wxDouble xo, wxDouble yo, - wxDouble xc, wxDouble yc, + wxDouble startX, wxDouble startY, + wxDouble endX, wxDouble endY, wxDouble radius, const wxGraphicsGradientStops& stops, const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) wxOVERRIDE; @@ -4847,14 +4847,14 @@ wxGraphicsBrush wxD2DRenderer::CreateLinearGradientBrush( } wxGraphicsBrush wxD2DRenderer::CreateRadialGradientBrush( - wxDouble xo, wxDouble yo, - wxDouble xc, wxDouble yc, + wxDouble startX, wxDouble startY, + wxDouble endX, wxDouble endY, wxDouble radius, const wxGraphicsGradientStops& stops, const wxGraphicsMatrix& matrix) { wxD2DBrushData* brushData = new wxD2DBrushData(this); - brushData->CreateRadialGradientBrush(xo, yo, xc, yc, radius, stops, matrix); + brushData->CreateRadialGradientBrush(startX, startY, endX, endY, radius, stops, matrix); wxGraphicsBrush brush; brush.SetRefData(brushData); diff --git a/src/osx/carbon/graphics.cpp b/src/osx/carbon/graphics.cpp index 9d48d2f106..d137f81d4e 100644 --- a/src/osx/carbon/graphics.cpp +++ b/src/osx/carbon/graphics.cpp @@ -490,8 +490,8 @@ public: wxDouble x2, wxDouble y2, const wxGraphicsGradientStops& stops, const wxGraphicsMatrix& matrix); - void CreateRadialGradientShading(wxDouble xo, wxDouble yo, - wxDouble xc, wxDouble yc, wxDouble radius, + void CreateRadialGradientShading(wxDouble startX, wxDouble startY, + wxDouble endX, wxDouble endY, wxDouble radius, const wxGraphicsGradientStops& stops, const wxGraphicsMatrix& matrix); @@ -597,16 +597,16 @@ wxMacCoreGraphicsPenBrushDataBase::CreateLinearGradientShading( void wxMacCoreGraphicsPenBrushDataBase::CreateRadialGradientShading( - wxDouble xo, wxDouble yo, - wxDouble xc, wxDouble yc, + wxDouble startX, wxDouble startY, + wxDouble endX, wxDouble endY, wxDouble radius, const wxGraphicsGradientStops& stops, const wxGraphicsMatrix& matrix) { m_gradientFunction = CreateGradientFunction(stops); m_shading = CGShadingCreateRadial( wxMacGetGenericRGBColorSpace(), - CGPointMake((CGFloat) xo, (CGFloat) yo), 0, - CGPointMake((CGFloat) xc, (CGFloat) yc), (CGFloat) radius, + CGPointMake((CGFloat) startX, (CGFloat) startY), 0, + CGPointMake((CGFloat) endX, (CGFloat) endY), (CGFloat) radius, m_gradientFunction, true, true ); m_isShading = true; if (! matrix.IsNull() ) @@ -2766,8 +2766,8 @@ public : const wxGraphicsMatrix& matrix) wxOVERRIDE; virtual wxGraphicsBrush - CreateRadialGradientBrush(wxDouble xo, wxDouble yo, - wxDouble xc, wxDouble yc, + CreateRadialGradientBrush(wxDouble startX, wxDouble startY, + wxDouble endX, wxDouble endY, wxDouble radius, const wxGraphicsGradientStops& stops, const wxGraphicsMatrix& matrix) wxOVERRIDE; @@ -3032,15 +3032,15 @@ wxMacCoreGraphicsRenderer::CreateLinearGradientBrush(wxDouble x1, wxDouble y1, } wxGraphicsBrush -wxMacCoreGraphicsRenderer::CreateRadialGradientBrush(wxDouble xo, wxDouble yo, - wxDouble xc, wxDouble yc, +wxMacCoreGraphicsRenderer::CreateRadialGradientBrush(wxDouble startX, wxDouble startY, + wxDouble endX, wxDouble endY, wxDouble radius, const wxGraphicsGradientStops& stops, const wxGraphicsMatrix& matrix) { wxGraphicsBrush p; wxMacCoreGraphicsBrushData* d = new wxMacCoreGraphicsBrushData( this ); - d->CreateRadialGradientShading(xo, yo, xc, yc, radius, stops, matrix); + d->CreateRadialGradientShading(startX, startY, endX, endY, radius, stops, matrix); p.SetRefData(d); return p; } diff --git a/src/qt/graphics.cpp b/src/qt/graphics.cpp index 8a9059cced..6470256314 100644 --- a/src/qt/graphics.cpp +++ b/src/qt/graphics.cpp @@ -91,12 +91,12 @@ public: m_brush = QBrush(gradient); } - void CreateRadialGradientBrush(wxDouble xo, wxDouble yo, - wxDouble xc, wxDouble yc, + void CreateRadialGradientBrush(wxDouble startX, wxDouble startY, + wxDouble endX, wxDouble endY, wxDouble radius, const wxGraphicsGradientStops& stops) { - QRadialGradient gradient(QPointF(xc, yc), radius, QPointF(xo, yo)); + QRadialGradient gradient(QPointF(endX, endY), radius, QPointF(startX, startY)); SetStops(gradient, stops); m_brush = QBrush(gradient); } @@ -1141,8 +1141,8 @@ public: const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) wxOVERRIDE; virtual wxGraphicsBrush - CreateRadialGradientBrush(wxDouble xo, wxDouble yo, - wxDouble xc, wxDouble yc, + CreateRadialGradientBrush(wxDouble startX, wxDouble startY, + wxDouble endX, wxDouble endY, wxDouble radius, const wxGraphicsGradientStops& stops, const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) wxOVERRIDE; @@ -1287,14 +1287,14 @@ wxGraphicsBrush wxQtGraphicsRenderer::CreateLinearGradientBrush( } wxGraphicsBrush wxQtGraphicsRenderer::CreateRadialGradientBrush( - wxDouble xo, wxDouble yo, - wxDouble xc, wxDouble yc, wxDouble r, + wxDouble startX, wxDouble startY, + wxDouble endX, wxDouble endY, wxDouble r, const wxGraphicsGradientStops& stops, const wxGraphicsMatrix& WXUNUSED(matrix)) { wxGraphicsBrush p; wxQtBrushData* d = new wxQtBrushData(this); - d->CreateRadialGradientBrush(xo, yo, xc, yc, r, stops); + d->CreateRadialGradientBrush(startX, startY, endX, endY, r, stops); p.SetRefData(d); return p; } From 61a39165b8bc0e521fabee9dd61dbe6a4187578c Mon Sep 17 00:00:00 2001 From: Robin Dunn <> Date: Tue, 3 Sep 2019 16:32:44 -0700 Subject: [PATCH 33/41] documentation tweaks --- interface/wx/graphics.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/interface/wx/graphics.h b/interface/wx/graphics.h index 48d8301e42..d6762be285 100644 --- a/interface/wx/graphics.h +++ b/interface/wx/graphics.h @@ -640,6 +640,8 @@ public: of gradient @a stops can be specified. The version taking wxGraphicsGradientStops is new in wxWidgets 2.9.1. + + The ability to apply a transformation matrix to the gradient was added in 3.1.3 */ wxGraphicsBrush CreateLinearGradientBrush(wxDouble x1, wxDouble y1, @@ -666,6 +668,8 @@ public: oColor and @a cColor or by a full set of gradient @a stops. The version taking wxGraphicsGradientStops is new in wxWidgets 2.9.1. + + The ability to apply a transformation matrix to the gradient was added in 3.1.3 */ virtual wxGraphicsBrush CreateRadialGradientBrush(wxDouble startX, wxDouble startY, @@ -1455,6 +1459,9 @@ public: Stops support is new since wxWidgets 2.9.1, previously only the start and end colours could be specified. + + The ability to apply a transformation matrix to the gradient was added in 3.1.3 + */ virtual wxGraphicsBrush CreateLinearGradientBrush(wxDouble x1, wxDouble y1, @@ -1489,6 +1496,8 @@ public: Stops support is new since wxWidgets 2.9.1, previously only the start and end colours could be specified. + + The ability to apply a transformation matrix to the gradient was added in 3.1.3 */ virtual wxGraphicsBrush CreateRadialGradientBrush(wxDouble startX, wxDouble startY, wxDouble endX, wxDouble endY, From 699f019c76242f1c0408b357c53bfbaf289a6025 Mon Sep 17 00:00:00 2001 From: Robin Dunn <> Date: Tue, 3 Sep 2019 16:33:15 -0700 Subject: [PATCH 34/41] Add notes about gradient pens and gradient transforms to changes.txt --- docs/changes.txt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/changes.txt b/docs/changes.txt index f8e072900a..b053bf8d84 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -150,6 +150,13 @@ All (GUI): in wxPGArrayEditorDialog. - Fix wxPropertyGrid issues with horizontal scrolling. - Add wxPG_DIALOG_TITLE wxPGProperty attribute. +- Add support for creating a wxGraphicsPen with a gradient. The gradient will + be used when stroking a path in a wxGraphicsContext, if supported by the + graphics context backend. +- Add support for applying a transformation matrix to a gradient for both + wxGraphicsPen and wxGraphicsBrush, if supported by the graphics context + backend. + wxGTK: From df31204f983c8dff2f29b0f3d928e47e1abd04cb Mon Sep 17 00:00:00 2001 From: Robin Dunn <> Date: Tue, 3 Sep 2019 16:33:42 -0700 Subject: [PATCH 35/41] Add example of using a gradient pen to the drawing sample --- samples/drawing/drawing.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/samples/drawing/drawing.cpp b/samples/drawing/drawing.cpp index d9cb0dfa8d..2ec40a6229 100644 --- a/samples/drawing/drawing.cpp +++ b/samples/drawing/drawing.cpp @@ -1638,6 +1638,29 @@ void MyCanvas::DrawGradients(wxDC& dc) pth.GetBox(&boxX, &boxY, &boxWidth, &boxHeight); dc.CalcBoundingBox(wxRound(boxX), wxRound(boxY)); dc.CalcBoundingBox(wxRound(boxX+boxWidth), wxRound(boxY+boxHeight)); + + gfr.Offset(0, gfr.height + 10); + dc.DrawText("Stroked path with a gradient pen", gfr.x, gfr.y); + gfr.Offset(0, TEXT_HEIGHT); + + pth = gc->CreatePath(); + pth.MoveToPoint(gfr.x + gfr.width/2, gfr.y); + pth.AddLineToPoint(gfr.x + gfr.width, gfr.y + gfr.height/2); + pth.AddLineToPoint(gfr.x + gfr.width/2, gfr.y + gfr.height); + pth.AddLineToPoint(gfr.x, gfr.y + gfr.height/2); + pth.CloseSubpath(); + + stops = wxGraphicsGradientStops(*wxRED, *wxBLUE); + stops.Add(wxColour(255,255,0), 0.33f); + stops.Add(*wxGREEN, 0.67f); + + wxGraphicsPen pen = gc->CreatePen( + wxGraphicsPenInfo(wxColour(0,0,0)).Width(6).Join(wxJOIN_BEVEL).LinearGradient( + gfr.x + gfr.width/2, gfr.y, + gfr.x + gfr.width/2, gfr.y + gfr.height, + stops)); + gc->SetPen(pen); + gc->StrokePath(pth); } #endif // wxUSE_GRAPHICS_CONTEXT } From 1afb4afe25335dc32f1fd8c4b0abd0ce88954513 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Wed, 4 Sep 2019 15:01:22 -0700 Subject: [PATCH 36/41] Fix typo --- src/generic/graphicc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/generic/graphicc.cpp b/src/generic/graphicc.cpp index 3fce559fef..dcdc0efa24 100644 --- a/src/generic/graphicc.cpp +++ b/src/generic/graphicc.cpp @@ -3201,7 +3201,7 @@ wxCairoRenderer::CreateLinearGradientBrush(wxDouble x1, wxDouble y1, } wxGraphicsBrush -wxCairoRenderer::CreateRadialGradientBrush(wxDouble startX, wxDouble startX, +wxCairoRenderer::CreateRadialGradientBrush(wxDouble startX, wxDouble startY, wxDouble endX, wxDouble endY, wxDouble r, const wxGraphicsGradientStops& stops, const wxGraphicsMatrix& matrix) From a8a19e25eed63650172f871ccd5a9276e3049e81 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Thu, 5 Sep 2019 13:33:15 -0700 Subject: [PATCH 37/41] Various typo and coding style fixes --- docs/changes.txt | 8 ++------ include/wx/graphics.h | 22 +++++++++++----------- interface/wx/graphics.h | 28 +++++++++++++++++----------- src/generic/graphicc.cpp | 12 ++++++------ src/msw/graphics.cpp | 17 +++++++++-------- src/msw/graphicsd2d.cpp | 8 ++++---- src/osx/carbon/graphics.cpp | 4 ++-- src/qt/graphics.cpp | 4 ++-- 8 files changed, 53 insertions(+), 50 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index b053bf8d84..d21707be89 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -150,12 +150,8 @@ All (GUI): in wxPGArrayEditorDialog. - Fix wxPropertyGrid issues with horizontal scrolling. - Add wxPG_DIALOG_TITLE wxPGProperty attribute. -- Add support for creating a wxGraphicsPen with a gradient. The gradient will - be used when stroking a path in a wxGraphicsContext, if supported by the - graphics context backend. -- Add support for applying a transformation matrix to a gradient for both - wxGraphicsPen and wxGraphicsBrush, if supported by the graphics context - backend. +- Add support for creating a wxGraphicsPen with a gradient. +- Add support for applying a transformation matrix to a gradient. wxGTK: diff --git a/include/wx/graphics.h b/include/wx/graphics.h index ddc1393610..059d11c62d 100644 --- a/include/wx/graphics.h +++ b/include/wx/graphics.h @@ -271,7 +271,7 @@ extern WXDLLIMPEXP_DATA_CORE(wxGraphicsMatrix) wxNullGraphicsMatrix; // ---------------------------------------------------------------------------- // wxGradientStop and wxGradientStops: Specify what intermediate colors are used -// and how they are are spread out in a gradient +// and how they are spread out in a gradient // ---------------------------------------------------------------------------- // Describes a single gradient stop. @@ -374,7 +374,7 @@ public: wxGraphicsPenInfo& LinearGradient(wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, const wxColour& c1, const wxColour& c2, - const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) + const wxGraphicsMatrix& matrix = wxNullGraphicsMatrix) { m_gradientType = wxGRADIENT_LINEAR; m_x1 = x1; @@ -390,7 +390,7 @@ public: wxGraphicsPenInfo& LinearGradient(wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, const wxGraphicsGradientStops& stops, - const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) + const wxGraphicsMatrix& matrix = wxNullGraphicsMatrix) { m_gradientType = wxGRADIENT_LINEAR; m_x1 = x1; @@ -406,7 +406,7 @@ public: RadialGradient(wxDouble startX, wxDouble startY, wxDouble endX, wxDouble endY, wxDouble radius, const wxColour& oColor, const wxColour& cColor, - const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) + const wxGraphicsMatrix& matrix = wxNullGraphicsMatrix) { m_gradientType = wxGRADIENT_RADIAL; m_x1 = startX; @@ -424,7 +424,7 @@ public: RadialGradient(wxDouble startX, wxDouble startY, wxDouble endX, wxDouble endY, wxDouble radius, const wxGraphicsGradientStops& stops, - const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) + const wxGraphicsMatrix& matrix = wxNullGraphicsMatrix) { m_gradientType = wxGRADIENT_RADIAL; m_x1 = startX; @@ -626,12 +626,12 @@ public: CreateLinearGradientBrush(wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, const wxColour& c1, const wxColour& c2, - const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) const; + const wxGraphicsMatrix& matrix = wxNullGraphicsMatrix) const; wxGraphicsBrush CreateLinearGradientBrush(wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, const wxGraphicsGradientStops& stops, - const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) const; + const wxGraphicsMatrix& matrix = wxNullGraphicsMatrix) const; // sets the brush to a radial gradient originating at (xo,yc) and ending // on a circle around (xc,yc) with the given radius; the colours may be @@ -640,13 +640,13 @@ public: CreateRadialGradientBrush(wxDouble startX, wxDouble startY, wxDouble endX, wxDouble endY, wxDouble radius, const wxColour& oColor, const wxColour& cColor, - const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) const; + const wxGraphicsMatrix& matrix = wxNullGraphicsMatrix) const; wxGraphicsBrush CreateRadialGradientBrush(wxDouble startX, wxDouble startY, wxDouble endX, wxDouble endY, wxDouble radius, const wxGraphicsGradientStops& stops, - const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) const; + const wxGraphicsMatrix& matrix = wxNullGraphicsMatrix) const; // creates a font virtual wxGraphicsFont CreateFont( const wxFont &font , const wxColour &col = *wxBLACK ) const; @@ -1023,14 +1023,14 @@ public: CreateLinearGradientBrush(wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, const wxGraphicsGradientStops& stops, - const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) = 0; + const wxGraphicsMatrix& matrix = wxNullGraphicsMatrix) = 0; virtual wxGraphicsBrush CreateRadialGradientBrush(wxDouble startX, wxDouble startY, wxDouble endX, wxDouble endY, wxDouble radius, const wxGraphicsGradientStops& stops, - const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) = 0; + const wxGraphicsMatrix& matrix = wxNullGraphicsMatrix) = 0; // sets the font virtual wxGraphicsFont CreateFont( const wxFont &font , const wxColour &col = *wxBLACK ) = 0; diff --git a/interface/wx/graphics.h b/interface/wx/graphics.h index d6762be285..e9fcc856ed 100644 --- a/interface/wx/graphics.h +++ b/interface/wx/graphics.h @@ -305,6 +305,12 @@ enum wxCompositionMode wxCOMPOSITION_ADD /**< @e R = @e S + @e D */ }; +/** + Used to indicate what kind of gradient is set in a wxGraphicsPenInfo + object. + + @since 3.1.3 + */ enum wxGradientType { wxGRADIENT_NONE, wxGRADIENT_LINEAR, @@ -641,13 +647,13 @@ public: The version taking wxGraphicsGradientStops is new in wxWidgets 2.9.1. - The ability to apply a transformation matrix to the gradient was added in 3.1.3 + The @ matrix parameter was added in wxWidgets 3.1.3 */ wxGraphicsBrush CreateLinearGradientBrush(wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, const wxColour& c1, const wxColour& c2, - const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) const; + const wxGraphicsMatrix& matrix = wxNullGraphicsMatrix) const; /** @overload @@ -656,7 +662,7 @@ public: CreateLinearGradientBrush(wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, const wxGraphicsGradientStops& stops, - const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) const; + const wxGraphicsMatrix& matrix = wxNullGraphicsMatrix) const; /** Creates a native brush with a radial gradient. @@ -677,7 +683,7 @@ public: wxDouble radius, const wxColour& oColor, const wxColour& cColor, - const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) const; + const wxGraphicsMatrix& matrix = wxNullGraphicsMatrix) const; /** @overload @@ -687,7 +693,7 @@ public: wxDouble endX, wxDouble endY, wxDouble radius, const wxGraphicsGradientStops& stops, - const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) = 0; + const wxGraphicsMatrix& matrix = wxNullGraphicsMatrix) = 0; /** Sets the brush for filling paths. @@ -1468,7 +1474,7 @@ public: wxDouble x2, wxDouble y2, const wxGraphicsGradientStops& stops, - const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) = 0; + const wxGraphicsMatrix& matrix = wxNullGraphicsMatrix) = 0; /** Creates a native affine transformation matrix from the passed in @@ -1503,7 +1509,7 @@ public: wxDouble endX, wxDouble endY, wxDouble radius, const wxGraphicsGradientStops& stops, - const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) = 0; + const wxGraphicsMatrix& matrix = wxNullGraphicsMatrix) = 0; /** Extracts a sub-bitmap from an existing bitmap. @@ -1646,24 +1652,24 @@ public: wxGraphicsPenInfo& LinearGradient(wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, const wxColour& c1, const wxColour& c2, - const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix); + const wxGraphicsMatrix& matrix = wxNullGraphicsMatrix); wxGraphicsPenInfo& LinearGradient(wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, const wxGraphicsGradientStops& stops, - const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix); + const wxGraphicsMatrix& matrix = wxNullGraphicsMatrix); wxGraphicsPenInfo& RadialGradient(wxDouble startX, wxDouble startY, wxDouble endX, wxDouble endY, wxDouble radius, const wxColour& oColor, const wxColour& cColor, - const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix); + const wxGraphicsMatrix& matrix = wxNullGraphicsMatrix); wxGraphicsPenInfo& RadialGradient(wxDouble startX, wxDouble startY, wxDouble endX, wxDouble endY, wxDouble radius, const wxGraphicsGradientStops& stops, - const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix); + const wxGraphicsMatrix& matrix = wxNullGraphicsMatrix); wxColour GetColour() const; wxBitmap GetStipple() const; diff --git a/src/generic/graphicc.cpp b/src/generic/graphicc.cpp index dcdc0efa24..c6586c98e8 100644 --- a/src/generic/graphicc.cpp +++ b/src/generic/graphicc.cpp @@ -263,11 +263,11 @@ public: void CreateLinearGradientPattern(wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, const wxGraphicsGradientStops& stops, - const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix); + const wxGraphicsMatrix& matrix = wxNullGraphicsMatrix); void CreateRadialGradientPattern(wxDouble startX, wxDouble startY, wxDouble endX, wxDouble endY, wxDouble radius, const wxGraphicsGradientStops& stops, - const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix); + const wxGraphicsMatrix& matrix = wxNullGraphicsMatrix); protected: // Call this to use the given bitmap as stipple. Bitmap must be non-null @@ -755,7 +755,7 @@ wxCairoPenBrushBaseData::CreateLinearGradientPattern(wxDouble x1, wxDouble y1, { m_pattern = cairo_pattern_create_linear(x1,y1,x2,y2); - if (! matrix.IsNull()) + if ( !matrix.IsNull() ) { cairo_matrix_t m = *((cairo_matrix_t*) matrix.GetNativeMatrix()); cairo_pattern_set_matrix(m_pattern, &m); @@ -773,7 +773,7 @@ wxCairoPenBrushBaseData::CreateRadialGradientPattern(wxDouble startX, wxDouble s { m_pattern = cairo_pattern_create_radial(startX,startY,0.0,endX,endY,radius); - if (! matrix.IsNull()) + if ( !matrix.IsNull() ) { cairo_matrix_t m = *((cairo_matrix_t*) matrix.GetNativeMatrix()); cairo_pattern_set_matrix(m_pattern, &m); @@ -2994,14 +2994,14 @@ public : CreateLinearGradientBrush(wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, const wxGraphicsGradientStops& stops, - const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) wxOVERRIDE; + const wxGraphicsMatrix& matrix = wxNullGraphicsMatrix) wxOVERRIDE; virtual wxGraphicsBrush CreateRadialGradientBrush(wxDouble startX, wxDouble startY, wxDouble endX, wxDouble endY, wxDouble radius, const wxGraphicsGradientStops& stops, - const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) wxOVERRIDE; + const wxGraphicsMatrix& matrix = wxNullGraphicsMatrix) wxOVERRIDE; // sets the font virtual wxGraphicsFont CreateFont( const wxFont &font , const wxColour &col = *wxBLACK ) wxOVERRIDE ; diff --git a/src/msw/graphics.cpp b/src/msw/graphics.cpp index bcd1ceb4c4..fe33e8077b 100644 --- a/src/msw/graphics.cpp +++ b/src/msw/graphics.cpp @@ -261,20 +261,21 @@ class wxGDIPlusPenBrushBaseData : public wxGraphicsObjectRefData { public: wxGDIPlusPenBrushBaseData(wxGraphicsRenderer* renderer); - ~wxGDIPlusPenBrushBaseData(); - virtual void Init(); + virtual void Init() wxOVERRIDE; void CreateLinearGradientBrush(wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, const wxGraphicsGradientStops& stops, - const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix); + const wxGraphicsMatrix& matrix = wxNullGraphicsMatrix); void CreateRadialGradientBrush(wxDouble startX, wxDouble startY, wxDouble endX, wxDouble endY, wxDouble radius, const wxGraphicsGradientStops& stops, - const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix); + const wxGraphicsMatrix& matrix = wxNullGraphicsMatrix); protected: + virtual ~wxGDIPlusPenBrushBaseData(); + Brush* m_brush; GraphicsPath* m_brushPath; Image* m_image; @@ -636,14 +637,14 @@ public : CreateLinearGradientBrush(wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, const wxGraphicsGradientStops& stops, - const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) wxOVERRIDE; + const wxGraphicsMatrix& matrix = wxNullGraphicsMatrix) wxOVERRIDE; virtual wxGraphicsBrush CreateRadialGradientBrush(wxDouble startX, wxDouble startY, wxDouble endX, wxDouble endY, wxDouble radius, const wxGraphicsGradientStops& stops, - const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) wxOVERRIDE; + const wxGraphicsMatrix& matrix = wxNullGraphicsMatrix) wxOVERRIDE; // create a native bitmap representation virtual wxGraphicsBitmap CreateBitmap( const wxBitmap &bitmap ) wxOVERRIDE; @@ -763,7 +764,7 @@ wxGDIPlusPenBrushBaseData::CreateLinearGradientBrush( brush->SetWrapMode(WrapModeTileFlipXY); // Apply the matrix if there is one - if (! matrix.IsNull()) + if ( !matrix.IsNull() ) { Matrix* m = static_cast(matrix.GetNativeMatrix()); m->Invert(); @@ -798,7 +799,7 @@ wxGDIPlusPenBrushBaseData::CreateRadialGradientBrush( // the area outside of the gradient's radius is not getting painted. // Apply the matrix if there is one - if (! matrix.IsNull()) + if ( !matrix.IsNull() ) { Matrix* m = static_cast(matrix.GetNativeMatrix()); m->Invert(); diff --git a/src/msw/graphicsd2d.cpp b/src/msw/graphicsd2d.cpp index 805b1d9b76..17b8909c60 100644 --- a/src/msw/graphicsd2d.cpp +++ b/src/msw/graphicsd2d.cpp @@ -2549,13 +2549,13 @@ public: void CreateLinearGradientBrush(wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, const wxGraphicsGradientStops& stops, - const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix); + const wxGraphicsMatrix& matrix = wxNullGraphicsMatrix); void CreateRadialGradientBrush(wxDouble startX, wxDouble startY, wxDouble endX, wxDouble endY, wxDouble radius, const wxGraphicsGradientStops& stops, - const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix); + const wxGraphicsMatrix& matrix = wxNullGraphicsMatrix); ID2D1Brush* GetBrush() const { @@ -4642,14 +4642,14 @@ public : wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, const wxGraphicsGradientStops& stops, - const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) wxOVERRIDE; + const wxGraphicsMatrix& matrix = wxNullGraphicsMatrix) wxOVERRIDE; wxGraphicsBrush CreateRadialGradientBrush( wxDouble startX, wxDouble startY, wxDouble endX, wxDouble endY, wxDouble radius, const wxGraphicsGradientStops& stops, - const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) wxOVERRIDE; + const wxGraphicsMatrix& matrix = wxNullGraphicsMatrix) wxOVERRIDE; // create a native bitmap representation wxGraphicsBitmap CreateBitmap(const wxBitmap& bitmap) wxOVERRIDE; diff --git a/src/osx/carbon/graphics.cpp b/src/osx/carbon/graphics.cpp index d137f81d4e..2ded6cf21f 100644 --- a/src/osx/carbon/graphics.cpp +++ b/src/osx/carbon/graphics.cpp @@ -588,7 +588,7 @@ wxMacCoreGraphicsPenBrushDataBase::CreateLinearGradientShading( CGPointMake((CGFloat) x2, (CGFloat) y2), m_gradientFunction, true, true ); m_isShading = true; - if (! matrix.IsNull() ) + if ( !matrix.IsNull() ) { m_shadingMatrix = (wxMacCoreGraphicsMatrixData*)((wxMacCoreGraphicsMatrixData*)matrix.GetRefData())->Clone(); m_shadingMatrix->Invert(); @@ -609,7 +609,7 @@ wxMacCoreGraphicsPenBrushDataBase::CreateRadialGradientShading( CGPointMake((CGFloat) endX, (CGFloat) endY), (CGFloat) radius, m_gradientFunction, true, true ); m_isShading = true; - if (! matrix.IsNull() ) + if ( !matrix.IsNull() ) { m_shadingMatrix = (wxMacCoreGraphicsMatrixData*)((wxMacCoreGraphicsMatrixData*)matrix.GetRefData())->Clone(); m_shadingMatrix->Invert(); diff --git a/src/qt/graphics.cpp b/src/qt/graphics.cpp index 6470256314..c427099b08 100644 --- a/src/qt/graphics.cpp +++ b/src/qt/graphics.cpp @@ -1138,14 +1138,14 @@ public: CreateLinearGradientBrush(wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, const wxGraphicsGradientStops& stops, - const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) wxOVERRIDE; + const wxGraphicsMatrix& matrix = wxNullGraphicsMatrix) wxOVERRIDE; virtual wxGraphicsBrush CreateRadialGradientBrush(wxDouble startX, wxDouble startY, wxDouble endX, wxDouble endY, wxDouble radius, const wxGraphicsGradientStops& stops, - const wxGraphicsMatrix& matrix=wxNullGraphicsMatrix) wxOVERRIDE; + const wxGraphicsMatrix& matrix = wxNullGraphicsMatrix) wxOVERRIDE; // sets the font virtual wxGraphicsFont CreateFont(const wxFont& font, From f705cb30876681b059d38b4686f67ece5022b7cb Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Thu, 5 Sep 2019 17:47:33 -0700 Subject: [PATCH 38/41] Another typo fix --- interface/wx/graphics.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/wx/graphics.h b/interface/wx/graphics.h index e9fcc856ed..7e09c7d6ee 100644 --- a/interface/wx/graphics.h +++ b/interface/wx/graphics.h @@ -647,7 +647,7 @@ public: The version taking wxGraphicsGradientStops is new in wxWidgets 2.9.1. - The @ matrix parameter was added in wxWidgets 3.1.3 + The @a matrix parameter was added in wxWidgets 3.1.3 */ wxGraphicsBrush CreateLinearGradientBrush(wxDouble x1, wxDouble y1, From 53d3888180d7ee8d6e63087934b756595eec8685 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Thu, 5 Sep 2019 17:51:51 -0700 Subject: [PATCH 39/41] Add another missed wxOVERRIDE --- src/msw/graphics.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/msw/graphics.cpp b/src/msw/graphics.cpp index fe33e8077b..ddebc3a170 100644 --- a/src/msw/graphics.cpp +++ b/src/msw/graphics.cpp @@ -296,7 +296,7 @@ public: wxGDIPlusPenData( wxGraphicsRenderer* renderer, const wxGraphicsPenInfo &info ); ~wxGDIPlusPenData(); - virtual void Init(); + virtual void Init() wxOVERRIDE; virtual wxDouble GetWidth() { return m_width; } virtual Pen* GetGDIPlusPen() { return m_pen; } From b10c7a982f766bdeb5bf06659ee3dbdfdc76fa1e Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Wed, 11 Sep 2019 12:59:27 -0700 Subject: [PATCH 40/41] Remove misplaced wxOVERRIDE --- src/msw/graphics.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/msw/graphics.cpp b/src/msw/graphics.cpp index ddebc3a170..eaced69010 100644 --- a/src/msw/graphics.cpp +++ b/src/msw/graphics.cpp @@ -262,7 +262,7 @@ class wxGDIPlusPenBrushBaseData : public wxGraphicsObjectRefData public: wxGDIPlusPenBrushBaseData(wxGraphicsRenderer* renderer); - virtual void Init() wxOVERRIDE; + virtual void Init(); void CreateLinearGradientBrush(wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, From 1c2e71920a895782e56895b4e00de283657c8bbc Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Wed, 11 Sep 2019 13:09:12 -0700 Subject: [PATCH 41/41] Remove commented-out asserts --- src/msw/graphicsd2d.cpp | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/msw/graphicsd2d.cpp b/src/msw/graphicsd2d.cpp index 17b8909c60..19fa4b1411 100644 --- a/src/msw/graphicsd2d.cpp +++ b/src/msw/graphicsd2d.cpp @@ -1772,12 +1772,6 @@ void wxD2DPathData::AddPath(const wxGraphicsPathData* path) GeometryStateData curStateSrc; pathSrc->SaveGeometryState(curStateSrc); - // I think this assert is incorrect. We need to support paths where the end - // is not connected to the beginning. --Robin - // Raise warning if appended path has an open non-empty sub-path. - // wxASSERT_MSG( pathSrc->IsStateSafeForFlush(), - // wxS("Sub-path in appended path should be closed prior to this operation") ); - // Close appended geometry. pathSrc->Flush(); @@ -1897,11 +1891,6 @@ void wxD2DPathData::Transform(const wxGraphicsMatrixData* matrix) // So, Transform() can be safely called if path doesn't contain the open // sub-path or if open sub-path is empty. - // I think this assert is incorrect. We need to support paths where the end - // is not connected to the beginning. --Robin - // wxASSERT_MSG( IsStateSafeForFlush(), - // wxS("Consider closing sub-path before calling Transform()") ); - // Close current geometry. Flush();