X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/505810425a47f73e5110f5287a711abcd750f293..edba2de33ede5bbef0726e889d89fea2732d592d:/src/common/graphcmn.cpp diff --git a/src/common/graphcmn.cpp b/src/common/graphcmn.cpp index eb9d9084fa..094186fdf7 100644 --- a/src/common/graphcmn.cpp +++ b/src/common/graphcmn.cpp @@ -9,14 +9,6 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -// ============================================================================ -// declarations -// ============================================================================ - -// --------------------------------------------------------------------------- -// headers -// --------------------------------------------------------------------------- - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -24,9 +16,37 @@ #pragma hdrstop #endif +#if wxUSE_GRAPHICS_CONTEXT + #include "wx/graphics.h" -#if wxUSE_GRAPHICS_CONTEXT +#ifndef WX_PRECOMP + #include "wx/icon.h" + #include "wx/bitmap.h" + #include "wx/dcmemory.h" + #include "wx/region.h" +#endif + +#if !defined(wxMAC_USE_CORE_GRAPHICS_BLEND_MODES) +#define wxMAC_USE_CORE_GRAPHICS_BLEND_MODES 0 +#endif + +//----------------------------------------------------------------------------- +// constants +//----------------------------------------------------------------------------- + +static const double RAD2DEG = 180.0 / M_PI; + +//----------------------------------------------------------------------------- +// Local functions +//----------------------------------------------------------------------------- + +static inline double DegToRad(double deg) +{ + return (deg * M_PI) / 180.0; +} + +//----------------------------------------------------------------------------- wxPoint2DDouble wxGraphicsPath::GetCurrentPoint() { @@ -68,8 +88,8 @@ void wxGraphicsPath::AddQuadCurveToPoint( wxDouble cx, wxDouble cy, wxDouble x, wxPoint2DDouble start = GetCurrentPoint() ; wxPoint2DDouble end(x,y); wxPoint2DDouble c(cx,cy); - c1 = (1/3.0) * start + (2/3.0) * c; - c2 = (2/3.0) * c + (1/3.0) * end ; + c1 = wxDouble(1/3.0) * start + wxDouble(2/3.0) * c; + c2 = wxDouble(2/3.0) * c + wxDouble(1/3.0) * end ; AddCurveToPoint(c1.m_x,c1.m_y,c2.m_x,c2.m_y,x,y); } @@ -89,6 +109,43 @@ void wxGraphicsPath::AddCircle( wxDouble x, wxDouble y, wxDouble r ) CloseSubpath(); } +// draws a an arc to two tangents connecting (current) to (x1,y1) and (x1,y1) to (x2,y2), also a straight line from (current) to (x1,y1) +void wxGraphicsPath::AddArcToPoint( wxDouble x1, wxDouble y1 , wxDouble x2, wxDouble y2, wxDouble r ) +{ + wxPoint2DDouble current = GetCurrentPoint(); + wxPoint2DDouble p1(x1,y1); + wxPoint2DDouble p2(x2,y2); + + wxPoint2DDouble v1 = current - p1 ; + v1.Normalize(); + wxPoint2DDouble v2 = p2 - p1 ; + v2.Normalize(); + + wxDouble alpha = v1.GetVectorAngle() - v2.GetVectorAngle(); + + if ( alpha < 0 ) + alpha = 360 + alpha ; + // TODO obtuse angles + + alpha = DegToRad(alpha); + + wxDouble dist = r / sin(alpha/2) * cos(alpha/2) ; + // calculate tangential points + wxPoint2DDouble t1 = dist*v1 + p1 ; + wxPoint2DDouble t2 = dist*v2 + p1 ; + + wxPoint2DDouble nv1 = v1 ; + nv1.SetVectorAngle(v1.GetVectorAngle()-90); + wxPoint2DDouble c = t1 + r*nv1; + + wxDouble a1 = v1.GetVectorAngle()+90 ; + wxDouble a2 = v2.GetVectorAngle()-90 ; + + AddLineToPoint(t1); + AddArc(c.m_x,c.m_y,r,DegToRad(a1),DegToRad(a2),true); + AddLineToPoint(p2); +} + //----------------------------------------------------------------------------- // wxGraphicsContext Convenience Methods //----------------------------------------------------------------------------- @@ -159,9 +216,6 @@ void wxGraphicsContext::DrawRoundedRectangle( wxDouble x, wxDouble y, wxDouble w PushState(); Translate( x , y ); - double fw = w / radius; - double fh = h / radius; - path->MoveToPoint(w, h / 2); path->AddArcToPoint(w, h, w / 2, h, radius); path->AddArcToPoint(0, h, 0, h / 2, radius); @@ -179,7 +233,7 @@ void wxGraphicsContext::StrokeLines( size_t n, const wxPoint2DDouble *points) wxASSERT(n > 1); wxGraphicsPath* path = CreatePath(); path->MoveToPoint(points[0].m_x, points[0].m_y) ; - for ( int i = 1 ; i < n; ++i) + for ( size_t i = 1 ; i < n; ++i) path->AddLineToPoint( points[i].m_x, points[i].m_y ); StrokePath( path ); delete path; @@ -190,7 +244,7 @@ void wxGraphicsContext::DrawLines( size_t n, const wxPoint2DDouble *points, int wxASSERT(n > 1); wxGraphicsPath* path = CreatePath(); path->MoveToPoint(points[0].m_x, points[0].m_y) ; - for ( int i = 1 ; i < n; ++i) + for ( size_t i = 1 ; i < n; ++i) path->AddLineToPoint( points[i].m_x, points[i].m_y ); DrawPath( path , fillStyle); delete path; @@ -200,7 +254,7 @@ void wxGraphicsContext::StrokeLines( size_t n, const wxPoint2DDouble *beginPoint { wxASSERT(n > 0); wxGraphicsPath* path = CreatePath(); - for ( int i = 0 ; i < n; ++i) + for ( size_t i = 0 ; i < n; ++i) { path->MoveToPoint(beginPoints[i].m_x, beginPoints[i].m_y) ; path->AddLineToPoint( endPoints[i].m_x, endPoints[i].m_y ); @@ -209,44 +263,8 @@ void wxGraphicsContext::StrokeLines( size_t n, const wxPoint2DDouble *beginPoint delete path; } -// draws a an arc to two tangents connecting (current) to (x1,y1) and (x1,y1) to (x2,y2), also a straight line from (current) to (x1,y1) -void wxGraphicsPath::AddArcToPoint( wxDouble x1, wxDouble y1 , wxDouble x2, wxDouble y2, wxDouble r ) -{ - // TODO -} - IMPLEMENT_ABSTRACT_CLASS(wxGCDC, wxObject) -//----------------------------------------------------------------------------- -// constants -//----------------------------------------------------------------------------- - -const double RAD2DEG = 180.0 / M_PI; -const short kEmulatedMode = -1; -const short kUnsupportedMode = -2; - -//----------------------------------------------------------------------------- -// Local functions -//----------------------------------------------------------------------------- - -static inline double dmin(double a, double b) -{ - return a < b ? a : b; -} -static inline double dmax(double a, double b) -{ - return a > b ? a : b; -} - -static inline double DegToRad(double deg) -{ - return (deg * M_PI) / 180.0; -} -static inline double RadToDeg(double deg) -{ - return (deg * 180.0) / M_PI; -} - //----------------------------------------------------------------------------- // wxDC bridge class //----------------------------------------------------------------------------- @@ -262,7 +280,13 @@ wxGCDC::wxGCDC(const wxWindowDC& dc) Init(); m_graphicContext = wxGraphicsContext::Create(dc); m_ok = true; - m_graphicContext->SetFont(dc.GetFont()); + if ( dc.GetFont().Ok()) + m_graphicContext->SetFont(dc.GetFont()); + if ( dc.GetPen().Ok()) + m_graphicContext->SetPen(dc.GetPen()); + if ( dc.GetBrush().Ok()) + m_graphicContext->SetBrush(dc.GetBrush()); + m_graphicContext->SetTextColor(dc.GetTextForeground()); } void wxGCDC::Init() @@ -285,7 +309,7 @@ wxGCDC::~wxGCDC() delete m_graphicContext; } -void wxGCDC::DoDrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask ) +void wxGCDC::DoDrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, bool WXUNUSED(useMask) ) { wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawBitmap - invalid DC") ); wxCHECK_RET( bmp.Ok(), wxT("wxGCDC(cg)::DoDrawBitmap - invalid bitmap") ); @@ -315,7 +339,7 @@ void wxGCDC::DoDrawIcon( const wxIcon &icon, wxCoord x, wxCoord y ) m_graphicContext->DrawIcon( icon , xx, yy, ww, hh ); } -void wxGCDC::DoSetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) +void wxGCDC::DoSetClippingRegion( wxCoord WXUNUSED(x), wxCoord WXUNUSED(y), wxCoord WXUNUSED(width), wxCoord WXUNUSED(height) ) { // TODO Clipping #if 0 @@ -542,8 +566,10 @@ void wxGCDC::ComputeScaleAndOrigin() SetPen( pen ); } -void wxGCDC::SetPalette( const wxPalette& palette ) -{} +void wxGCDC::SetPalette( const wxPalette& WXUNUSED(palette) ) +{ + +} void wxGCDC::SetBackgroundMode( int mode ) { @@ -637,17 +663,13 @@ void wxGCDC::SetLogicalFunction( int function ) } -extern bool wxDoFloodFill(wxDC *dc, wxCoord x, wxCoord y, - const wxColour & col, int style); - -bool wxGCDC::DoFloodFill(wxCoord x, wxCoord y, - const wxColour& col, int style) +bool wxGCDC::DoFloodFill(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y), + const wxColour& WXUNUSED(col), int WXUNUSED(style)) { - // return wxDoFloodFill(this, x, y, col, style); return false; } -bool wxGCDC::DoGetPixel( wxCoord x, wxCoord y, wxColour *col ) const +bool wxGCDC::DoGetPixel( wxCoord WXUNUSED(x), wxCoord WXUNUSED(y), wxColour *WXUNUSED(col) ) const { // wxCHECK_MSG( 0 , false, wxT("wxGCDC(cg)::DoGetPixel - not implemented") ); return false; @@ -785,7 +807,9 @@ void wxGCDC::DoDrawEllipticArc( wxCoord x, wxCoord y, wxCoord w, wxCoord h, m_graphicContext->Scale( factor , 1.0) ; if ( fill && (sa!=ea) ) path->MoveToPoint(0,0); - path->AddArc( 0, 0, hh/2 , DegToRad(sa) , DegToRad(ea), sa > ea ); + // since these angles (ea,sa) are measured counter-clockwise, we invert them to + // get clockwise angles + path->AddArc( 0, 0, hh/2 , DegToRad(-sa) , DegToRad(-ea), sa > ea ); if ( fill && (sa!=ea) ) path->AddLineToPoint(0,0); m_graphicContext->DrawPath( path ); @@ -882,7 +906,7 @@ void wxGCDC::DoDrawSpline(wxList *points) m_graphicContext->StrokePath( path ); delete path; } -#endif +#endif // wxUSE_SPLINES void wxGCDC::DoDrawPolygon( int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset, @@ -1044,9 +1068,9 @@ bool wxGCDC::CanDrawBitmap() const } bool wxGCDC::DoBlit( - wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, - wxDC *source, wxCoord xsrc, wxCoord ysrc, int logical_func , bool useMask, - wxCoord xsrcMask, wxCoord ysrcMask ) + wxCoord WXUNUSED(xdest), wxCoord WXUNUSED(ydest), wxCoord WXUNUSED(width), wxCoord WXUNUSED(height), + wxDC *source, wxCoord WXUNUSED(xsrc), wxCoord WXUNUSED(ysrc), int logical_func , bool WXUNUSED(useMask), + wxCoord WXUNUSED(xsrcMask), wxCoord WXUNUSED(ysrcMask) ) { wxCHECK_MSG( Ok(), false, wxT("wxGCDC(cg)::DoBlit - invalid DC") ); wxCHECK_MSG( source->Ok(), false, wxT("wxGCDC(cg)::DoBlit - invalid source DC") ); @@ -1054,6 +1078,7 @@ bool wxGCDC::DoBlit( if ( logical_func == wxNO_OP ) return true; +#if 0 if (xsrcMask == -1 && ysrcMask == -1) { xsrcMask = xsrc; @@ -1073,7 +1098,6 @@ bool wxGCDC::DoBlit( wxMemoryDC* memdc = dynamic_cast(source); if ( memdc && logical_func == wxCOPY ) { -#if 0 wxBitmap blit = memdc->GetSelectedObject(); wxASSERT_MSG( blit.Ok() , wxT("Invalid bitmap for blitting") ); @@ -1110,7 +1134,6 @@ bool wxGCDC::DoBlit( { m_graphicContext->DrawBitmap( blit, xxdest , yydest , wwdest , hhdest ); } -#endif } else @@ -1118,8 +1141,9 @@ bool wxGCDC::DoBlit( wxFAIL_MSG( wxT("Blitting is only supported from bitmap contexts") ); return false; } +#endif - return true; + return false; } void wxGCDC::DoDrawRotatedText(const wxString& str, wxCoord x, wxCoord y, @@ -1166,7 +1190,6 @@ void wxGCDC::DoGetTextExtent( const wxString &str, wxCoord *width, wxCoord *heig { wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoGetTextExtent - invalid DC") ); - wxFont formerFont = m_font; if ( theFont ) { m_graphicContext->SetFont( *theFont ); @@ -1348,5 +1371,4 @@ void wxGCDC::DoDrawCheckMark(wxCoord x, wxCoord y, wxDCBase::DoDrawCheckMark(x,y,width,height); } -#endif - +#endif // wxUSE_GRAPHICS_CONTEXT