]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/graphcmn.cpp
Split wxLocale into wxLocale and wxTranslations.
[wxWidgets.git] / src / common / graphcmn.cpp
index 3c38c0704fe1dd465185ef52595c5f94212bf860..7ab4da0b5ca535759d92828398e0f17cc397f06f 100644 (file)
@@ -18,7 +18,7 @@
 
 #if wxUSE_GRAPHICS_CONTEXT
 
-#include "wx/private/graphics.h"
+#include "wx/graphics.h"
 
 #ifndef WX_PRECOMP
     #include "wx/icon.h"
     #include "wx/log.h"
 #endif
 
-//-----------------------------------------------------------------------------
-// constants
-//-----------------------------------------------------------------------------
-
-static const double RAD2DEG = 180.0 / M_PI;
+#include "wx/private/graphics.h"
 
 //-----------------------------------------------------------------------------
 // Local functions
@@ -257,7 +253,7 @@ wxRect2DDouble wxGraphicsPath::GetBox() const
     return wxRect2DDouble( x,y,w,h );
 }
 
-bool wxGraphicsPath::Contains( const wxPoint2DDouble& c, int fillStyle ) const
+bool wxGraphicsPath::Contains( const wxPoint2DDouble& c, wxPolygonFillMode fillStyle ) const
 {
     return Contains( c.m_x, c.m_y, fillStyle);
 }
@@ -383,7 +379,7 @@ void wxGraphicsPath::GetBox(wxDouble *x, wxDouble *y, wxDouble *w, wxDouble *h)
     GetPathData()->GetBox(x,y,w,h);
 }
 
-bool wxGraphicsPath::Contains( wxDouble x, wxDouble y, int fillStyle ) const
+bool wxGraphicsPath::Contains( wxDouble x, wxDouble y, wxPolygonFillMode fillStyle ) const
 {
     return GetPathData()->Contains(x,y,fillStyle);
 }
@@ -480,7 +476,6 @@ void wxGraphicsPathData::AddArcToPoint( wxDouble x1, wxDouble y1 , wxDouble x2,
     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);
@@ -494,6 +489,41 @@ void wxGraphicsPathData::AddArcToPoint( wxDouble x1, wxDouble y1 , wxDouble x2,
     AddLineToPoint(p2.m_x,p2.m_y);
 }
 
+//-----------------------------------------------------------------------------
+// wxGraphicsGradientStops
+//-----------------------------------------------------------------------------
+
+void wxGraphicsGradientStops::Add(const wxGraphicsGradientStop& stop)
+{
+    for ( wxVector<wxGraphicsGradientStop>::iterator it = m_stops.begin();
+          it != m_stops.end();
+          ++it )
+    {
+        if ( stop.GetPosition() < it->GetPosition() )
+        {
+            if ( it != m_stops.begin() )
+            {
+                m_stops.insert(it, stop);
+            }
+            else // we shouldn't be inserting it at the beginning
+            {
+                wxFAIL_MSG( "invalid gradient stop position < 0" );
+            }
+
+            return;
+        }
+    }
+
+    if ( stop.GetPosition() == 1. )
+    {
+        m_stops.insert(m_stops.end() - 1, stop);
+    }
+    else
+    {
+        wxFAIL_MSG( "invalid gradient stop position > 1" );
+    }
+}
+
 //-----------------------------------------------------------------------------
 // wxGraphicsContext Convenience Methods
 //-----------------------------------------------------------------------------
@@ -501,9 +531,11 @@ void wxGraphicsPathData::AddArcToPoint( wxDouble x1, wxDouble y1 , wxDouble x2,
 IMPLEMENT_ABSTRACT_CLASS(wxGraphicsContext, wxObject)
 
 
-wxGraphicsContext::wxGraphicsContext(wxGraphicsRenderer* renderer) : wxGraphicsObject(renderer)
+wxGraphicsContext::wxGraphicsContext(wxGraphicsRenderer* renderer) :
+    wxGraphicsObject(renderer),
+      m_antialias(wxANTIALIAS_DEFAULT),
+      m_composition(wxCOMPOSITION_OVER)
 {
-    m_logicalFunction = wxCOPY;
 }
 
 wxGraphicsContext::~wxGraphicsContext()
@@ -563,7 +595,7 @@ void wxGraphicsContext::SetPen( const wxGraphicsPen& pen )
 
 void wxGraphicsContext::SetPen( const wxPen& pen )
 {
-    if ( !pen.Ok() || pen.GetStyle() == wxTRANSPARENT )
+    if ( !pen.Ok() || pen.GetStyle() == wxPENSTYLE_TRANSPARENT )
         SetPen( wxNullGraphicsPen );
     else
         SetPen( CreatePen( pen ) );
@@ -577,7 +609,7 @@ void wxGraphicsContext::SetBrush( const wxGraphicsBrush& brush )
 
 void wxGraphicsContext::SetBrush( const wxBrush& brush )
 {
-    if ( !brush.Ok() || brush.GetStyle() == wxTRANSPARENT )
+    if ( !brush.Ok() || brush.GetStyle() == wxBRUSHSTYLE_TRANSPARENT )
         SetBrush( wxNullGraphicsBrush );
     else
         SetBrush( CreateBrush( brush ) );
@@ -589,16 +621,6 @@ void wxGraphicsContext::SetFont( const wxGraphicsFont& font )
     m_font = font;
 }
 
-bool wxGraphicsContext::SetLogicalFunction( int function )
-{
-    if ( function == wxCOPY )
-    {
-        m_logicalFunction = function;
-        return true;
-    }
-    return false;
-}
-
 void wxGraphicsContext::SetFont( const wxFont& font, const wxColour& colour )
 {
     if ( font.Ok() )
@@ -607,13 +629,17 @@ void wxGraphicsContext::SetFont( const wxFont& font, const wxColour& colour )
         SetFont( wxNullGraphicsFont );
 }
 
-void wxGraphicsContext::DrawPath( const wxGraphicsPath& path, int fillStyle )
+void wxGraphicsContext::DrawPath( const wxGraphicsPath& path, wxPolygonFillMode fillStyle )
 {
     FillPath( path , fillStyle );
     StrokePath( path );
 }
 
-void wxGraphicsContext::DrawText( const wxString &str, wxDouble x, wxDouble y, wxDouble angle )
+void
+wxGraphicsContext::DoDrawRotatedText(const wxString &str,
+                                     wxDouble x,
+                                     wxDouble y,
+                                     wxDouble angle)
 {
     Translate(x,y);
     Rotate( -angle );
@@ -622,7 +648,11 @@ void wxGraphicsContext::DrawText( const wxString &str, wxDouble x, wxDouble y, w
     Translate(-x,-y);
 }
 
-void wxGraphicsContext::DrawText( const wxString &str, wxDouble x, wxDouble y, const wxGraphicsBrush& backgroundBrush )
+void
+wxGraphicsContext::DoDrawFilledText(const wxString &str,
+                                    wxDouble x,
+                                    wxDouble y,
+                                    const wxGraphicsBrush& backgroundBrush)
 {
     wxGraphicsBrush formerBrush = m_brush;
     wxGraphicsPen formerPen = m_pen;
@@ -644,7 +674,11 @@ void wxGraphicsContext::DrawText( const wxString &str, wxDouble x, wxDouble y, c
     SetPen( formerPen );
 }
 
-void wxGraphicsContext::DrawText( const wxString &str, wxDouble x, wxDouble y, wxDouble angle, const wxGraphicsBrush& backgroundBrush )
+void
+wxGraphicsContext::DoDrawRotatedFilledText(const wxString &str,
+                                           wxDouble x, wxDouble y,
+                                           wxDouble angle,
+                                           const wxGraphicsBrush& backgroundBrush)
 {
     wxGraphicsBrush formerBrush = m_brush;
     wxGraphicsPen formerPen = m_pen;
@@ -710,7 +744,7 @@ void wxGraphicsContext::StrokeLines( size_t n, const wxPoint2DDouble *points)
     StrokePath( path );
 }
 
-void wxGraphicsContext::DrawLines( size_t n, const wxPoint2DDouble *points, int fillStyle)
+void wxGraphicsContext::DrawLines( size_t n, const wxPoint2DDouble *points, wxPolygonFillMode fillStyle)
 {
     wxASSERT(n > 1);
     wxGraphicsPath path = CreatePath();
@@ -754,19 +788,55 @@ wxGraphicsBrush wxGraphicsContext::CreateBrush(const wxBrush& brush ) const
     return GetRenderer()->CreateBrush(brush);
 }
 
-// sets the brush to a linear gradient, starting at (x1,y1) with color c1 to (x2,y2) with color c2
-wxGraphicsBrush wxGraphicsContext::CreateLinearGradientBrush( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2,
-                                                   const wxColour&c1, const wxColour&c2) const
+wxGraphicsBrush
+wxGraphicsContext::CreateLinearGradientBrush(
+    wxDouble x1, wxDouble y1,
+    wxDouble x2, wxDouble y2,
+    const wxColour& c1, const wxColour& c2) const
 {
-    return GetRenderer()->CreateLinearGradientBrush(x1,y1,x2,y2,c1,c2);
+    return GetRenderer()->CreateLinearGradientBrush
+                          (
+                            x1, y1,
+                            x2, y2,
+                            wxGraphicsGradientStops(c1,c2)
+                          );
 }
 
-// sets the brush to a radial gradient originating at (xo,yc) with color oColor and ends on a circle around (xc,yc)
-// with radius r and color cColor
-wxGraphicsBrush wxGraphicsContext::CreateRadialGradientBrush( wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius,
-                                                   const wxColour &oColor, const wxColour &cColor) const
+wxGraphicsBrush
+wxGraphicsContext::CreateLinearGradientBrush(
+    wxDouble x1, wxDouble y1,
+    wxDouble x2, wxDouble y2,
+    const wxGraphicsGradientStops& gradientStops) const
 {
-    return GetRenderer()->CreateRadialGradientBrush(xo,yo,xc,yc,radius,oColor,cColor);
+    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
+                          (
+                            xo, yo,
+                            xc, yc, radius,
+                            wxGraphicsGradientStops(oColor, cColor)
+                          );
+}
+
+wxGraphicsBrush
+wxGraphicsContext::CreateRadialGradientBrush(
+        wxDouble xo, wxDouble yo,
+        wxDouble xc, wxDouble yc, wxDouble radius,
+        const wxGraphicsGradientStops& gradientStops) const
+{
+    return GetRenderer()->CreateRadialGradientBrush
+                          (
+                            xo, yo,
+                            xc, yc, radius,
+                            gradientStops
+                          );
 }
 
 // sets the font
@@ -777,20 +847,12 @@ wxGraphicsFont wxGraphicsContext::CreateFont( const wxFont &font , const wxColou
 
 wxGraphicsBitmap wxGraphicsContext::CreateBitmap( const wxBitmap& bmp ) const
 {
-#ifndef __WXGTK20__
     return GetRenderer()->CreateBitmap(bmp);
-#else
-    return wxNullGraphicsBitmap;
-#endif
 }
 
 wxGraphicsBitmap wxGraphicsContext::CreateSubBitmap( const wxGraphicsBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h   ) const
 {
-#ifndef __WXGTK20__
     return GetRenderer()->CreateSubBitmap(bmp,x,y,w,h);
-#else
-    return wxNullGraphicsBitmap;
-#endif
 }
 
 /* static */ wxGraphicsContext* wxGraphicsContext::Create( const wxWindowDC& dc)