[pypy-svn] r55002 - in pypy/dist/pypy/rlib/rsdl: . test
arigo at codespeak.net
arigo at codespeak.net
Tue May 20 16:11:38 CEST 2008
Author: arigo
Date: Tue May 20 16:11:36 2008
New Revision: 55002
Modified:
pypy/dist/pypy/rlib/rsdl/RSDL.py
pypy/dist/pypy/rlib/rsdl/RSDL_helper.py
pypy/dist/pypy/rlib/rsdl/test/test_video.py
Log:
Poll and mallocrect().
Modified: pypy/dist/pypy/rlib/rsdl/RSDL.py
==============================================================================
--- pypy/dist/pypy/rlib/rsdl/RSDL.py (original)
+++ pypy/dist/pypy/rlib/rsdl/RSDL.py Tue May 20 16:11:36 2008
@@ -68,7 +68,12 @@
('pixels', rffi.UCHARP)])
PixelFormat = platform.Struct('SDL_PixelFormat',
- [('BytesPerPixel', rffi.INT)])
+ [('BitsPerPixel', rffi.INT),
+ ('BytesPerPixel', rffi.INT),
+ ('Rmask', rffi.INT),
+ ('Gmask', rffi.INT),
+ ('Bmask', rffi.INT),
+ ('Amask', rffi.INT)])
Event = platform.Struct('SDL_Event',
[('type', rffi.INT)])
@@ -158,6 +163,10 @@
[EventPtr],
rffi.INT)
+PollEvent = external('SDL_PollEvent',
+ [EventPtr],
+ rffi.INT)
+
Flip = external('SDL_Flip',
[SurfacePtr],
rffi.INT)
Modified: pypy/dist/pypy/rlib/rsdl/RSDL_helper.py
==============================================================================
--- pypy/dist/pypy/rlib/rsdl/RSDL_helper.py (original)
+++ pypy/dist/pypy/rlib/rsdl/RSDL_helper.py Tue May 20 16:11:36 2008
@@ -93,4 +93,10 @@
else:
raise ValueError("bad BytesPerPixel")
-
+def mallocrect(x, y, w, h):
+ p = lltype.malloc(RSDL.Rect, flavor='raw')
+ rffi.setintfield(p, 'c_x', x)
+ rffi.setintfield(p, 'c_y', y)
+ rffi.setintfield(p, 'c_w', w)
+ rffi.setintfield(p, 'c_h', h)
+ return p
Modified: pypy/dist/pypy/rlib/rsdl/test/test_video.py
==============================================================================
--- pypy/dist/pypy/rlib/rsdl/test/test_video.py (original)
+++ pypy/dist/pypy/rlib/rsdl/test/test_video.py Tue May 20 16:11:36 2008
@@ -76,8 +76,35 @@
print '(event of type %d)' % c_type
finally:
lltype.free(event, flavor='raw')
-
-
+
+ def test_poll(self):
+ if not self.is_interactive:
+ py.test.skip("interactive test only")
+ import time, sys
+ RSDL.EnableUNICODE(1)
+ print
+ print "Keys pressed in the Pygame window give a dot."
+ print " Use Escape or wait 3 seconds to quit."
+ timeout = time.time() + 3
+ event = lltype.malloc(RSDL.Event, flavor='raw')
+ try:
+ while True:
+ # busy polling
+ ok = RSDL.PollEvent(event)
+ ok = rffi.cast(lltype.Signed, ok)
+ assert ok >= 0
+ if ok > 0:
+ c_type = rffi.getintfield(event, 'c_type')
+ if c_type == RSDL.KEYDOWN:
+ sys.stderr.write('.')
+ timeout = time.time() + 3
+ else:
+ if time.time() > timeout:
+ break
+ time.sleep(0.05)
+ finally:
+ lltype.free(event, flavor='raw')
+
def test_mousemove(self):
if not self.is_interactive:
py.test.skip("interactive test only")
@@ -187,16 +214,12 @@
color = RSDL.MapRGB(fmt, 255, 0, 0)
RSDL.FillRect(surface, lltype.nullptr(RSDL.Rect), color)
- paintrect = lltype.malloc(RSDL.Rect, flavor='raw')
- rffi.setintfield(paintrect, 'c_x', 75)
- rffi.setintfield(paintrect, 'c_y', 0)
- rffi.setintfield(paintrect, 'c_w', 150)
- rffi.setintfield(paintrect, 'c_h', 50)
- color = RSDL.MapRGB(fmt, 255, 128, 0)
- RSDL.FillRect(surface, paintrect, color)
-
+ paintrect = RSDL_helper.mallocrect(75, 0, 150, 50)
dstrect = lltype.malloc(RSDL.Rect, flavor='raw')
try:
+ color = RSDL.MapRGB(fmt, 255, 128, 0)
+ RSDL.FillRect(surface, paintrect, color)
+
rffi.setintfield(dstrect, 'c_x', 10)
rffi.setintfield(dstrect, 'c_y', 10)
rffi.setintfield(dstrect, 'c_w', 150)
More information about the Pypy-commit
mailing list