]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/src/_graphics.i
Add a GraphicsContext sample to the demo
[wxWidgets.git] / wxPython / src / _graphics.i
index fd5fce2415578478250cf78fd3fa1785cbe83b41..6df55591bbf10b1a6a48c1fb07020091552d61d6 100644 (file)
@@ -80,11 +80,22 @@ public:
         wxPyEndBlockThreads(blocked);
         return NULL;
     }
-    
+
+    static wxGraphicsContext* CreateFromNative( void *  ) {
+        wxPyBlock_t blocked = wxPyBeginBlockThreads();
+        PyErr_SetString(PyExc_NotImplementedError,
+                        "wxGraphicsContext is not available on this platform.");
+        wxPyEndBlockThreads(blocked);
+        return NULL;
+    }        
+
     wxGraphicsPath * CreatePath() { return NULL; }
     void PushState() {}
     void PopState() {}
     void Clip( const wxRegion & ) {}
+    void Clip( wxDouble, wxDouble, wxDouble, wxDouble ) {}
+    void ResetClip() {}
+    void * GetNativeContext() { return NULL; }
     void Translate( wxDouble  , wxDouble  ) {}
     void Scale( wxDouble  , wxDouble  ) {}
     void Rotate( wxDouble  ) {}
@@ -95,7 +106,7 @@ public:
     void SetRadialGradientBrush( wxDouble , wxDouble , wxDouble , wxDouble , wxDouble ,
         const wxColour &, const wxColour &) {}
     void SetFont( const wxFont & ) {}
-    void SetTextColor( const wxColour & ) {}
+    void SetTextColour( const wxColour & ) {}
     void StrokePath( const wxGraphicsPath * ) {}
     void FillPath( const wxGraphicsPath *, int  ) {}
     void DrawPath( const wxGraphicsPath *, int  ) {}
@@ -135,7 +146,8 @@ public:
     
     virtual ~wxGCDC() {}
 
-    wxGraphicsContext* GetGraphicContext() { return NULL; }
+    wxGraphicsContext* GetGraphicsContext() { return NULL; }
+    void SetGraphicsContext( wxGraphicsContext* ) {}
 };
 
 #endif
@@ -282,16 +294,19 @@ public:
     // wxGraphicsContext()         This is also an ABC, use Create to make an instance...
     virtual ~wxGraphicsContext();
 
+    %newobject Create;
     %nokwargs Create;
-    %pythonAppend Create( const wxWindowDC& dc)
-        "val.__dc = args[0] # save a ref so the other dc will not be deleted before self";
+    %pythonAppend Create
+        "val.__dc = args[0] # save a ref so the dc will not be deleted before self";
     static wxGraphicsContext* Create( const wxWindowDC& dc);
     
     static wxGraphicsContext* Create( wxWindow* window ) ;
 
+    %newobject CreateFromNative;
     static wxGraphicsContext* CreateFromNative( void * context ) ;
 
 
+    %newobject CreatePath;
     // creates a path instance that corresponds to the type of graphics context, ie GDIPlus, cairo, CoreGraphics ...
     DocDeclStr(
         virtual wxGraphicsPath * , CreatePath(),
@@ -387,12 +402,12 @@ public:
         "", "");
     
 
-    // 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
+    // sets the brush to a radial gradient originating at (xo,yc) with color oColour and ends on a circle around (xc,yc) 
+    // with radius r and color cColour
     DocDeclStr(
         virtual void , SetRadialGradientBrush( wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc,
                                                wxDouble radius,
-                                               const wxColour &oColor, const wxColour &cColor),
+                                               const wxColour &oColour, const wxColour &cColour),
         "", "");
     
 
@@ -404,7 +419,7 @@ public:
     
     // sets the text color
     DocDeclStr(
-        virtual void , SetTextColor( const wxColour &col ),
+        virtual void , SetTextColour( const wxColour &col ),
         "", "");
     
 
@@ -441,14 +456,33 @@ public:
         DrawRotatedText);
     
 
-    DocDeclAStr(
+    DocDeclAStrName(
         virtual void , GetTextExtent( const wxString &text,
                                       wxDouble *OUTPUT /*width*/,
                                       wxDouble *OUTPUT /*height*/,
                                       wxDouble *OUTPUT /*descent*/,
                                       wxDouble *OUTPUT /*externalLeading*/ ) const ,
-        "GetTextExtend(self, text) --> (width, height, descent, externalLeading)",
-        "", "");
+        "GetFullTextExtent(self, text) --> (width, height, descent, externalLeading)",
+        "", "",
+        GetFullTextExtent);
+
+    %extend {
+        DocAStr(GetTextExtent,
+                "GetTextExtent(self, text) --> (width, height)",
+                "", "");
+               
+        PyObject* GetTextExtent( const wxString &text )
+        {
+            wxDouble width = 0.0,
+                     height = 0.0;
+            self->GetTextExtent(text, &width, &height, NULL, NULL);
+            // thread wrapers are turned off for this .i file, so no need to acquire GIL...
+            PyObject* rv = PyTuple_New(2);
+            PyTuple_SET_ITEM(rv, 0, PyFloat_FromDouble(width));
+            PyTuple_SET_ITEM(rv, 1, PyFloat_FromDouble(height));
+            return rv;
+        }
+    }
     
 
     %extend {