diff --git a/etg/gdicmn.py b/etg/gdicmn.py index 4edd9433..f0815314 100644 --- a/etg/gdicmn.py +++ b/etg/gdicmn.py @@ -332,6 +332,31 @@ def run(): module.find('wxTheColourDatabase').ignore() + #----------------------------------------------------------------- + module.addCppFunction('PyObject*', 'IntersectRect', '(wxRect* r1, wxRect* r2)', + doc="""\ + Calculate and return the intersection of r1 and r2. Returns None if there + is no intersection.""", + body="""\ + wxRegion reg1(*r1); + wxRegion reg2(*r2); + wxRect dest(0,0,0,0); + PyObject* obj; + + reg1.Intersect(reg2); + dest = reg1.GetBox(); + + wxPyThreadBlocker blocker; + if (dest != wxRect(0,0,0,0)) { + wxRect* newRect = new wxRect(dest); + obj = wxPyConstructObject((void*)newRect, wxT("wxRect"), true); + return obj; + } + Py_INCREF(Py_None); + return Py_None; + """ + ) + #----------------------------------------------------------------- tools.doCommonTweaks(module) tools.runGenerators(module) diff --git a/unittests/test_gdicmn.py b/unittests/test_gdicmn.py index 02baa376..3c9a5db4 100644 --- a/unittests/test_gdicmn.py +++ b/unittests/test_gdicmn.py @@ -1,7 +1,7 @@ import imp_unittest, unittest +import wtc import wx - #--------------------------------------------------------------------------- class Point(unittest.TestCase): @@ -294,7 +294,23 @@ class Rect(unittest.TestCase): #--------------------------------------------------------------------------- + +class intersectRect_Tests(wtc.WidgetTestCase): + def test_intersectRect01(self): + r1 = wx.Rect(0,0,10,10) + r2 = wx.Rect(50,50,10,10) + r3 = wx.IntersectRect(r1, r2) + self.assertEqual(r3, None) + def test_intersectRect02(self): + r1 = wx.Rect(0,0,55,55) + r2 = wx.Rect(50,50,10,10) + r3 = wx.IntersectRect(r1, r2) + self.assertEqual(r3, wx.Rect(50,50,5,5)) + + + +#--------------------------------------------------------------------------- if __name__ == '__main__': unittest.main()