]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/graphcmn.cpp
add support for alpha in color dialog on OSX, see #14127
[wxWidgets.git] / src / common / graphcmn.cpp
index dcdf8485e370678ef4df531baee9dc5e162b2461..9a75c2bf7167ca202accd9ace860a9c5a5915e95 100644 (file)
@@ -489,6 +489,46 @@ 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" );
+    }
+}
+
+void * wxGraphicsBitmap::GetNativeBitmap() const
+{
+    return GetBitmapData()->GetNativeBitmap();
+}
+
 //-----------------------------------------------------------------------------
 // wxGraphicsContext Convenience Methods
 //-----------------------------------------------------------------------------
@@ -499,7 +539,8 @@ IMPLEMENT_ABSTRACT_CLASS(wxGraphicsContext, wxObject)
 wxGraphicsContext::wxGraphicsContext(wxGraphicsRenderer* renderer) :
     wxGraphicsObject(renderer),
       m_antialias(wxANTIALIAS_DEFAULT),
-      m_composition(wxCOMPOSITION_OVER)
+      m_composition(wxCOMPOSITION_OVER),
+      m_enableOffset(false)
 {
 }
 
@@ -529,6 +570,11 @@ void wxGraphicsContext::Flush()
 {
 }
 
+void wxGraphicsContext::EnableOffset(bool enable) 
+{ 
+    m_enableOffset = enable; 
+}
+
 #if 0
 void wxGraphicsContext::SetAlpha( wxDouble WXUNUSED(alpha) )
 {
@@ -540,12 +586,6 @@ wxDouble wxGraphicsContext::GetAlpha() const
 }
 #endif
 
-void wxGraphicsContext::GetSize( wxDouble* width, wxDouble* height)
-{
-    *width = 10000.0;
-    *height = 10000.0;
-}
-
 void wxGraphicsContext::GetDPI( wxDouble* dpiX, wxDouble* dpiY)
 {
     *dpiX = 72.0;
@@ -560,7 +600,7 @@ void wxGraphicsContext::SetPen( const wxGraphicsPen& pen )
 
 void wxGraphicsContext::SetPen( const wxPen& pen )
 {
-    if ( !pen.Ok() || pen.GetStyle() == wxPENSTYLE_TRANSPARENT )
+    if ( !pen.IsOk() || pen.GetStyle() == wxPENSTYLE_TRANSPARENT )
         SetPen( wxNullGraphicsPen );
     else
         SetPen( CreatePen( pen ) );
@@ -574,7 +614,7 @@ void wxGraphicsContext::SetBrush( const wxGraphicsBrush& brush )
 
 void wxGraphicsContext::SetBrush( const wxBrush& brush )
 {
-    if ( !brush.Ok() || brush.GetStyle() == wxBRUSHSTYLE_TRANSPARENT )
+    if ( !brush.IsOk() || brush.GetStyle() == wxBRUSHSTYLE_TRANSPARENT )
         SetBrush( wxNullGraphicsBrush );
     else
         SetBrush( CreateBrush( brush ) );
@@ -588,7 +628,7 @@ void wxGraphicsContext::SetFont( const wxGraphicsFont& font )
 
 void wxGraphicsContext::SetFont( const wxFont& font, const wxColour& colour )
 {
-    if ( font.Ok() )
+    if ( font.IsOk() )
         SetFont( CreateFont( font, colour ) );
     else
         SetFont( wxNullGraphicsFont );
@@ -630,9 +670,7 @@ wxGraphicsContext::DoDrawFilledText(const wxString &str,
     // to make sure our 'OffsetToPixelBoundaries' doesn't move the fill shape
     SetPen( wxNullGraphicsPen );
 
-    wxGraphicsPath path = CreatePath();
-    path.AddRectangle( x , y, width, height );
-    FillPath( path );
+    DrawRectangle(x , y, width, height);
 
     DrawText( str, x ,y);
     SetBrush( formerBrush );
@@ -753,32 +791,83 @@ 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,
+                            wxGraphicsGradientStops(c1,c2)
+                          );
+}
+
+wxGraphicsBrush
+wxGraphicsContext::CreateLinearGradientBrush(
+    wxDouble x1, wxDouble y1,
+    wxDouble x2, wxDouble y2,
+    const wxGraphicsGradientStops& gradientStops) const
 {
-    return GetRenderer()->CreateLinearGradientBrush(x1,y1,x2,y2,c1,c2);
+    return GetRenderer()->CreateLinearGradientBrush(x1,y1,x2,y2, gradientStops);
 }
 
-// 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::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,oColor,cColor);
+    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
 wxGraphicsFont wxGraphicsContext::CreateFont( const wxFont &font , const wxColour &col ) const
 {
     return GetRenderer()->CreateFont(font,col);
 }
 
+wxGraphicsFont
+wxGraphicsContext::CreateFont(double size,
+                              const wxString& facename,
+                              int flags,
+                              const wxColour& col) const
+{
+    return GetRenderer()->CreateFont(size, facename, flags, col);
+}
+
 wxGraphicsBitmap wxGraphicsContext::CreateBitmap( const wxBitmap& bmp ) const
 {
     return GetRenderer()->CreateBitmap(bmp);
 }
 
+#if wxUSE_IMAGE
+wxGraphicsBitmap wxGraphicsContext::CreateBitmapFromImage(const wxImage& image) const
+{
+    return GetRenderer()->CreateBitmapFromImage(image);
+}
+#endif // wxUSE_IMAGE
+
 wxGraphicsBitmap wxGraphicsContext::CreateSubBitmap( const wxGraphicsBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h   ) const
 {
     return GetRenderer()->CreateSubBitmap(bmp,x,y,w,h);
@@ -801,6 +890,15 @@ wxGraphicsBitmap wxGraphicsContext::CreateSubBitmap( const wxGraphicsBitmap &bmp
 }
 #endif
 
+#ifdef __WXMSW__
+#if wxUSE_ENH_METAFILE
+/* static */ wxGraphicsContext* wxGraphicsContext::Create( const wxEnhMetaFileDC& dc)
+{
+    return wxGraphicsRenderer::GetDefaultRenderer()->CreateContext(dc);
+}
+#endif
+#endif
+
 wxGraphicsContext* wxGraphicsContext::CreateFromNative( void * context )
 {
     return wxGraphicsRenderer::GetDefaultRenderer()->CreateContextFromNativeContext(context);
@@ -816,6 +914,13 @@ wxGraphicsContext* wxGraphicsContext::Create( wxWindow* window )
     return wxGraphicsRenderer::GetDefaultRenderer()->CreateContext(window);
 }
 
+#if wxUSE_IMAGE
+/* static */ wxGraphicsContext* wxGraphicsContext::Create(wxImage& image)
+{
+    return wxGraphicsRenderer::GetDefaultRenderer()->CreateContextFromImage(image);
+}
+#endif // wxUSE_IMAGE
+
 wxGraphicsContext* wxGraphicsContext::Create()
 {
     return wxGraphicsRenderer::GetDefaultRenderer()->CreateMeasuringContext();