From e2a5251d0109a1be6b9ce5c818d89f56ebfaeae1 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 11 Apr 2003 14:02:32 +0000 Subject: [PATCH] fixes for user dash handling (patch 717736) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@20135 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + include/wx/msw/pen.h | 25 +++++++++++++++++++++++-- samples/drawing/drawing.cpp | 27 ++++++++++++++++++--------- src/gtk/pen.cpp | 5 +++++ src/gtk1/pen.cpp | 5 +++++ src/msw/pen.cpp | 3 ++- 6 files changed, 54 insertions(+), 12 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 60c90ad516..528869d0de 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -42,6 +42,7 @@ All GUI ports: - implemented alignment for wxGrid bool editor and renderer - support wxListCtrl columns alignment for all platforms and not just MSW - added wxToolBar Add/InsertTool(tool) (Janusz Piwowarski) +- fixed user dash handling for MSW and GTK (Ken Edwards) - WXR resources can now be used in Unicode builds - it is now possible to use several wxFileHistory objects in the same menu by giving them different base IDs (Dimitri Schoolwerth) diff --git a/include/wx/msw/pen.h b/include/wx/msw/pen.h index 2a96b98338..07325f94a4 100644 --- a/include/wx/msw/pen.h +++ b/include/wx/msw/pen.h @@ -53,6 +53,7 @@ private: }; #define M_PENDATA ((wxPenRefData *)m_refData) +#define wxPENDATA(x) ((wxPenRefData *)(x).m_refData) // Pen class WXDLLEXPORT wxPen: public wxGDIObject @@ -66,8 +67,28 @@ public: ~wxPen(); inline wxPen& operator = (const wxPen& pen) { if (*this == pen) return (*this); Ref(pen); return *this; } - inline bool operator == (const wxPen& pen) const { return m_refData == pen.m_refData; } - inline bool operator != (const wxPen& pen) const { return m_refData != pen.m_refData; } + inline bool operator == (const wxPen& pen) const + { + // It is impossible to know if the user dashes have changed, + // so we must assume that they have + if ( m_refData && pen.m_refData ) + { + if ( M_PENDATA->m_nbDash != 0 || wxPENDATA(pen)->m_nbDash != 0 ) + return false; + } + return m_refData == pen.m_refData; + } + inline bool operator != (const wxPen& pen) const + { + // It is impossible to know if the user dashes have changed, + // so we must assume that they have + if ( m_refData && pen.m_refData ) + { + if ( M_PENDATA->m_nbDash != 0 || wxPENDATA(pen)->m_nbDash != 0 ) + return true; + } + return m_refData != pen.m_refData; + } virtual bool Ok() const { return (m_refData != NULL) ; } diff --git a/samples/drawing/drawing.cpp b/samples/drawing/drawing.cpp index 573ef9c94a..1f1fd268da 100644 --- a/samples/drawing/drawing.cpp +++ b/samples/drawing/drawing.cpp @@ -464,18 +464,27 @@ void MyCanvas::DrawTestLines( int x, int y, int width, wxDC &dc ) dc.DrawText(_T("User dash"), x + 150, y + 140); wxPen ud( wxT("black"), width, wxUSER_DASH ); - wxDash dash1[1]; - dash1[0] = 0; - ud.SetDashes( 1, dash1 ); + wxDash dash1[6]; + dash1[0] = 8; // Long dash <---------+ + dash1[1] = 2; // Short gap | + dash1[2] = 3; // Short dash | + dash1[3] = 2; // Short gap | + dash1[4] = 3; // Short dash | + dash1[5] = 2; // Short gap and repeat + + ud.SetDashes( 6, dash1 ); + dc.SetPen( ud ); dc.DrawLine( x+20, y+140, 100, y+140 ); - dash1[0] = 1; - ud.SetDashes( 1, dash1 ); + dash1[0] = 5; // Make first dash shorter + ud.SetDashes( 6, dash1 ); + dc.SetPen( ud ); dc.DrawLine( x+20, y+150, 100, y+150 ); - dash1[0] = 2; - ud.SetDashes( 1, dash1 ); + dash1[2] = 5; // Make second dash longer + ud.SetDashes( 6, dash1 ); + dc.SetPen( ud ); dc.DrawLine( x+20, y+160, 100, y+160 ); - dash1[0] = 0x7F; - ud.SetDashes( 1, dash1 ); + dash1[4] = 5; // Make third dash longer + ud.SetDashes( 6, dash1 ); + dc.SetPen( ud ); dc.DrawLine( x+20, y+170, 100, y+170 ); } diff --git a/src/gtk/pen.cpp b/src/gtk/pen.cpp index 66470bcc89..176463b69d 100644 --- a/src/gtk/pen.cpp +++ b/src/gtk/pen.cpp @@ -52,6 +52,11 @@ public: bool operator == (const wxPenRefData& data) const { + // It is impossible to tell if the dashes have changed + // so the only thing to do is assume they have + if (m_countDashes != 0 || data.m_countDashes != 0) + return false; + return (m_style == data.m_style && m_width == data.m_width && m_joinStyle == data.m_joinStyle && diff --git a/src/gtk1/pen.cpp b/src/gtk1/pen.cpp index 66470bcc89..176463b69d 100644 --- a/src/gtk1/pen.cpp +++ b/src/gtk1/pen.cpp @@ -52,6 +52,11 @@ public: bool operator == (const wxPenRefData& data) const { + // It is impossible to tell if the dashes have changed + // so the only thing to do is assume they have + if (m_countDashes != 0 || data.m_countDashes != 0) + return false; + return (m_style == data.m_style && m_width == data.m_width && m_joinStyle == data.m_joinStyle && diff --git a/src/msw/pen.cpp b/src/msw/pen.cpp index a5a30412ad..a7dc903a5d 100644 --- a/src/msw/pen.cpp +++ b/src/msw/pen.cpp @@ -232,8 +232,9 @@ bool wxPen::RealizeResource() if (M_PENDATA->m_style==wxUSER_DASH && M_PENDATA->m_nbDash && M_PENDATA->m_dash) { real_dash = new wxMSWDash[M_PENDATA->m_nbDash]; + int rw = M_PENDATA->m_width > 1 ? M_PENDATA->m_width : 1; for ( int i = 0; i < M_PENDATA->m_nbDash; i++ ) - real_dash[i] = M_PENDATA->m_dash[i] * M_PENDATA->m_width; + real_dash[i] = M_PENDATA->m_dash[i] * rw; } else { -- 2.47.2