Commits

Anonymous committed 1ab634b

Added more sdlext.draw examples. Fixed documentation for sdl.base.get_error().

Comments (0)

Files changed (7)

doc/src/sdlbase.xml

     </desc>
   </func>
   <func name="get_error">
-    <call>get_error () -> :exc:`pygame2.Error`</call>
+    <call>get_error () -> str</call>
     <desc>
-      Gets the last :exc:`pygame2.Error` occured.
+      Gets the last SDL error message occured.
 
       SDL maintains an internal error message. This message will usually
       be given to you when a :exc:`pygame2.Error` is raised.

examples/sdlext/draw.py

     import pygame2.sdl.event as event
     import pygame2.sdl.video as video
     import pygame2.sdlext.draw as draw
+    import pygame2.sdl.wm as wm
 except ImportError:
     print ("No pygame2.sdl support")
     sys.exit ()
 blue = pygame2.Color (0, 0, 255)
 
 def draw_rect (screen):
+    wm.set_caption ("draw.rect examples")
     draw.rect (screen, black, pygame2.Rect (20, 20, 100, 100))
     draw.rect (screen, red, pygame2.Rect (160, 100, 160, 60))
     draw.rect (screen, green, pygame2.Rect (180, 190, 180, 200))
     draw.rect (screen, blue, pygame2.Rect (390, 120, 200, 140))
 
 def draw_circle (screen):
+    wm.set_caption ("draw.circle examples")
     draw.circle (screen, black, (100, 100), 50)
     draw.circle (screen, red, (200, 160), 80, 4)
     draw.circle (screen, green, (370, 210), 100, 12)
     draw.circle (screen, blue, (400, 400), 45, 40)
 
 def draw_arc (screen):
+    wm.set_caption ("draw.arc examples")
     draw.arc (screen, black, pygame2.Rect (80, 100, 100, 100), 0, 30)
+    draw.arc (screen, red, pygame2.Rect (70, 200, 300, 150), 4, 70)
+    draw.arc (screen, green, pygame2.Rect (40, 20, 100, 150), 7, 230)
+    draw.arc (screen, blue, pygame2.Rect (400, 80, 200, 300), 10, 360)
 
+def draw_line (screen):
+    wm.set_caption ("draw.line examples")
+    draw.line (screen, black, 4, 40, 17, 320)
+    draw.line (screen, red, 280, 7, 40, 220, 4)
+    draw.line (screen, green, 33, 237, 580, 370, 8)
+    draw.line (screen, blue, 0, 0, 640, 480, 16)
+
+def draw_aaline (screen):
+    wm.set_caption ("draw.aaline examples")
+    draw.aaline (screen, black, 4, 40, 17, 320, True)
+    draw.aaline (screen, red, 280, 7, 40, 220, True)
+    draw.aaline (screen, green, 33, 237, 580, 370, True)
+    draw.aaline (screen, blue, 0, 0, 640, 480, False)
+
+def draw_lines (screen):
+    wm.set_caption ("draw.lines examples")
+    draw.lines (screen, black, ((4, 40), (280, 7), (40, 220),
+                                (33, 237), (580, 370),
+                                (0, 0), (640, 480)), 4)
+def draw_aalines (screen):
+    wm.set_caption ("draw.aalines examples")
+    draw.aalines (screen, black, ((4, 40), (280, 7), (40, 220),
+                                  (33, 237), (580, 370),
+                                  (0, 0), (640, 480)), 4)
+
+def draw_polygon (screen):
+    wm.set_caption ("draw.polygon examples")
+    draw.polygon (screen, black, ((4, 40), (280, 7), (40, 220),
+                                  (33, 237), (580, 370),
+                                  (0, 0), (640, 480)), 4)
+
+def draw_aapolygon (screen):
+    wm.set_caption ("draw.aapolygon examples")
+    draw.aapolygon (screen, black, ((4, 40), (280, 7), (40, 220),
+                                    (33, 237), (580, 370),
+                                    (0, 0), (640, 480)), 4)
+
+def draw_ellipse (screen):
+    wm.set_caption ("draw.ellipse examnples")
+    draw.ellipse (screen, black, pygame2.Rect (20, 20, 100, 100), 4)
+    draw.ellipse (screen, red, pygame2.Rect (160, 100, 160, 60))
+    draw.ellipse (screen, green, pygame2.Rect (180, 190, 180, 200))
+    draw.ellipse (screen, blue, pygame2.Rect (390, 120, 200, 140), 7)
+    
 def run ():
-    drawtypes = [ draw_rect, draw_circle, draw_arc ]
+    drawtypes = [ draw_rect, draw_circle, draw_arc, draw_line, draw_aaline,
+                  draw_lines, draw_aalines, draw_polygon, draw_aapolygon,
+                  draw_ellipse ]
     curtype = 0
     video.init ()
 

src/base/basemod.c

         return 1;
     }
 failed:
-    PyErr_SetString (PyExc_TypeError,
-        "object must be a Rect, FRect or 2-value sequence");
+    if (!PyErr_Occurred ())
+        PyErr_SetString (PyExc_TypeError,
+            "object must be a Rect, FRect or 2-value sequence");
     return 0;
 }
 
         return 1;
     }
 failed:
-    PyErr_SetString (PyExc_TypeError,
-        "object must be a Rect, FRect or 2-value sequence");
+    if (!PyErr_Occurred ())
+        PyErr_SetString (PyExc_TypeError,
+            "object must be a Rect, FRect or 2-value sequence");
     return 0;
 }
 
         return 1;
     }
 failed:
-    PyErr_Clear ();
-    PyErr_SetString (PyExc_TypeError,
-        "object must be a Rect, FRect or 2-value sequence");
+    if (!PyErr_Occurred ())
+        PyErr_SetString (PyExc_TypeError,
+            "object must be a Rect, FRect or 2-value sequence");
     return 0;
 }
 
         return 1;
     }
 failed:
-    PyErr_Clear ();
-    PyErr_SetString (PyExc_TypeError,
-        "object must be a Rect, FRect or 2-value sequence");
+    if (!PyErr_Occurred ())
+        PyErr_SetString (PyExc_TypeError,
+            "object must be a Rect, FRect or 2-value sequence");
     return 0;
 }
 

src/sdlext/draw.c

 
         if (_clipaaline (cliprect, xa, ya, xb, yb, pts))
         {
-            printf ("pts: %f, %f, %f, %f\n", pts[0],pts[1],pts[2],pts[3]);
             _drawaaline (surface, color, (int)pts[0], (int)pts[1], (int)pts[2],
                 (int)pts[3], blendargs);
             anydrawn = 1;

src/sdlext/drawmod.c

     PyObject *surfobj, *colorobj, *rectobj;
     SDL_Surface* surface;
     Uint32 color;
-    int width = 1, loop;
+    int width = 0, loop;
     pgint16 l, t, r, b;
     pguint16 w, h;
     SDL_Rect rect;

test/pgunittest.py

     from pygame2.test.pgtestutils import *
 except:
     from pgtestutils import *
-
 #
 # pygame specific enhancement END
 #

test/sdl_base_test.py

 
         # __doc__ (as of 2009-04-01) for pygame2.sdl.base.get_error:
 
-        # get_error () -> pygame2.Error
+        # get_error () -> str
         # 
-        # Gets the last :exc:pygame2.base.Error occured.
+        # Gets the last SDL error message occured.
         # 
         # SDL maintains an internal error message. This message will
         # usually be given to you when a :exc:pygame2.base.Error is
         # raised. You will rarely need to call this function.
-        self.assertEqual (len (base.get_error ()), 0)
+        self.assert_ (type (base.get_error ()), str)
 
     def test_pygame2_sdl_base_get_version(self):