From ad0ac642d5764497804bee2caad4fc1f20fc6cea Mon Sep 17 00:00:00 2001 From: =?utf8?q?W=C5=82odzimierz=20Skiba?= Date: Fri, 16 Sep 2005 12:55:05 +0000 Subject: [PATCH] Native spline drawing. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@35519 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 2 + include/wx/msw/dc.h | 6 ++- src/msw/dc.cpp | 103 +++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 108 insertions(+), 3 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 38a383ea9e..f2c703329f 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -50,6 +50,7 @@ wxMSW: - Fixed bugs with wxStatusBar positioning (with or withour sizers) (Jamie Gadd) - Mouse move events are now generated for all static controls (Jamie Gadd) - Made wxJoystick::GetProductName() more useful (John Ratliff) +- Native spline drawing implementation (Wlodzimierz ABX Skiba). wxGTK: @@ -67,6 +68,7 @@ wxMac: - Automatic menu management improved. - Fixed crash when wxRadioButton is deleted from a group of radio buttons, due to dangling cycle pointers. +- Native spline drawing implementation for CoreGraphics (Robert J. Lang). wxOS2 diff --git a/include/wx/msw/dc.h b/include/wx/msw/dc.h index 3ee358dad6..58317dde2b 100644 --- a/include/wx/msw/dc.h +++ b/include/wx/msw/dc.h @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: dc.h +// Name: wx/msw/dc.h // Purpose: wxDC class // Author: Julian Smart // Modified by: @@ -164,6 +164,10 @@ protected: double radius); virtual void DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height); +#if wxUSE_SPLINES + virtual void DoDrawSpline(wxList *points); +#endif + virtual void DoCrossHair(wxCoord x, wxCoord y); virtual void DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y); diff --git a/src/msw/dc.cpp b/src/msw/dc.cpp index ad20e6ec9b..f126f133d2 100644 --- a/src/msw/dc.cpp +++ b/src/msw/dc.cpp @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: dc.cpp -// Purpose: wxDC class +// Name: src/msw/dc.cpp +// Purpose: wxDC class for MSW port // Author: Julian Smart // Modified by: // Created: 01/02/97 @@ -977,6 +977,105 @@ void wxDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height) CalcBoundingBox(x2, y2); } +#if wxUSE_SPLINES +void wxDC::DoDrawSpline(wxList *points) +{ +#ifdef __WXWINCE__ + // WinCE does not support ::PolyBezier so use generic version + wxDCBase::DoDrawSpline(points); +#else + // quadratic b-spline to cubic bezier spline conversion + // + // quadratic spline with control points P0,P1,P2 + // P(s) = P0*(1-s)^2 + P1*2*(1-s)*s + P2*s^2 + // + // bezier spline with control points B0,B1,B2,B3 + // B(s) = B0*(1-s)^3 + B1*3*(1-s)^2*s + B2*3*(1-s)*s^2 + B3*s^3 + // + // control points of bezier spline calculated from b-spline + // B0 = P0 + // B1 = (2*P1 + P0)/3 + // B2 = (2*P1 + P2)/3 + // B3 = P2 + + WXMICROWIN_CHECK_HDC + + wxASSERT_MSG( points, wxT("NULL pointer to spline points?") ); + + const size_t n_points = points->GetCount(); + wxASSERT_MSG( n > 2 , wxT("incomplete list of spline points?") ); + + const size_t n_bezier_points = n_points * 3 + 1; + POINT *lppt = (POINT *)malloc(n_bezier_points*sizeof(POINT)); + size_t bezier_pos = 0; + wxCoord x1, y1, x2, y2, cx1, cy1, cx4, cy4; + + wxList::compatibility_iterator node = points->GetFirst(); + wxPoint *p = (wxPoint *)node->GetData(); + lppt[ bezier_pos ].x = x1 = p->x; + lppt[ bezier_pos ].y = y1 = p->y; + bezier_pos++; + lppt[ bezier_pos ] = lppt[ bezier_pos-1 ]; + bezier_pos++; + + node = node->GetNext(); + p = (wxPoint *)node->GetData(); + + x2 = p->x; + y2 = p->y; + cx1 = ( x1 + x2 ) / 2; + cy1 = ( y1 + y2 ) / 2; + lppt[ bezier_pos ].x = XLOG2DEV(cx1); + lppt[ bezier_pos ].y = YLOG2DEV(cy1); + bezier_pos++; + lppt[ bezier_pos ] = lppt[ bezier_pos-1 ]; + bezier_pos++; + +#if !wxUSE_STL + while ((node = node->GetNext()) != NULL) +#else + while ((node = node->GetNext())) +#endif // !wxUSE_STL + { + p = (wxPoint *)node->GetData(); + x1 = x2; + y1 = y2; + x2 = p->x; + y2 = p->y; + cx4 = (x1 + x2) / 2; + cy4 = (y1 + y2) / 2; + // B0 is B3 of previous segment + // B1: + lppt[ bezier_pos ].x = XLOG2DEV((x1*2+cx1)/3); + lppt[ bezier_pos ].y = YLOG2DEV((y1*2+cy1)/3); + bezier_pos++; + // B2: + lppt[ bezier_pos ].x = XLOG2DEV((x1*2+cx4)/3); + lppt[ bezier_pos ].y = YLOG2DEV((y1*2+cy4)/3); + bezier_pos++; + // B3: + lppt[ bezier_pos ].x = XLOG2DEV(cx4); + lppt[ bezier_pos ].y = YLOG2DEV(cy4); + bezier_pos++; + cx1 = cx4; + cy1 = cy4; + } + + lppt[ bezier_pos ] = lppt[ bezier_pos-1 ]; + bezier_pos++; + lppt[ bezier_pos ].x = XLOG2DEV(x2); + lppt[ bezier_pos ].y = YLOG2DEV(y2); + bezier_pos++; + lppt[ bezier_pos ] = lppt[ bezier_pos-1 ]; + bezier_pos++; + + ::PolyBezier( GetHdc(), lppt, bezier_pos ); + + free(lppt); +#endif +} +#endif + // Chris Breeze 20/5/98: first implementation of DrawEllipticArc on Windows void wxDC::DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,double sa,double ea) { -- 2.45.2