def test_pygame2_sdl_video_PixelFormat_readonly(self):

        # __doc__ (as of 2009-12-08) for pygame2.sdl.video.PixelFormat.readonly:

        # Gets, whether the PixelFormat is read-only (this cannot be
        # changed).
        video.init()

        format = video.PixelFormat()
        self.assertEqual(format.readonly, False)

        surface = video.Surface(1, 1)
        fmt = surface.format
        self.assertEqual(fmt.readonly, True)

        def _setr(format, readonly):
            format.readonly = readonly

        if sys.version_info < (2, 5):
            self.assertRaises(TypeError, _setr, format, True)
            self.assertRaises(TypeError, _setr, format, False)
        else:
            self.assertRaises(AttributeError, _setr, format, True)
            self.assertRaises(AttributeError, _setr, format, False)

        video.quit()
Example #2
0
def run ():
    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 ()

    screen = video.set_mode (640, 480)
    screen.fill (white)
    draw_rect (screen)
    screen.flip ()

    okay = True
    while okay:
        for ev in event.get ():
            if ev.type == sdlconst.QUIT:
                okay = False
            if ev.type == sdlconst.KEYDOWN and ev.key == sdlconst.K_ESCAPE:
                okay = False
            if ev.type == sdlconst.MOUSEBUTTONDOWN:
                curtype += 1
                if curtype >= len (drawtypes):
                    curtype = 0
                screen.fill (white)
                drawtypes[curtype] (screen)
                screen.flip ()
    video.quit ()
Example #3
0
    def test_pygame2_sdl_gl_get_attribute(self):

        # __doc__ (as of 2009-12-14) for pygame2.sdl.gl.get_attribute:

        # get_attribute (attribute) -> int
        # 
        # Gets an OpenGL attribute value.
        # 
        # Gets the current value of the specified OpenGL attribute constant.
        gllib = self._get_gllib ()
        if not gllib:
            return
        
        # No video.
        self.assertRaises (pygame2.Error, gl.get_attribute, constants.GL_DEPTH_SIZE)
        
        video.init ()
        # No GL library
        self.assertRaises (pygame2.Error, gl.get_attribute, constants.GL_DEPTH_SIZE)

        # No screen
        self.assertEquals (gl.load_library (gllib), None)
        self.assertRaises (pygame2.Error, gl.get_attribute, constants.GL_DEPTH_SIZE)
        
        # No OpenGL screen
        screen = video.set_mode (10, 10)
        self.assertEquals (gl.get_attribute (constants.GL_DEPTH_SIZE), 0)
        
        screen = video.set_mode (10, 10, bpp=32, flags=constants.OPENGL)
        self.assertEquals (gl.get_attribute (constants.GL_DEPTH_SIZE), 24)
        video.quit ()
Example #4
0
def run ():
    methods = [ draw_checked, draw_striped, draw_flipped, draw_mixed,
                draw_zoomed, draw_replaced, draw_extracted, draw_extracted2]
    curmethod = -1
    
    video.init ()
    screen = video.set_mode (320, 240, 32)
    screen.fill (black)
    
    surface = image.load_bmp (pygame2.examples.RESOURCES.get ("array.bmp"))
    surface = surface.convert (flags=sdlconst.SRCALPHA)
    screen.blit (surface)
    screen.flip ()

    okay = True
    while okay:
        for ev in event.get ():
            if ev.type == sdlconst.QUIT:
                okay = False
            if ev.type == sdlconst.KEYDOWN and ev.key == sdlconst.K_ESCAPE:
                okay = False
            if ev.type == sdlconst.MOUSEBUTTONDOWN:
                curmethod += 1
                if curmethod >= len (methods):
                    curmethod = 0
                screen.fill (black)
                screen.blit (surface)
                methods[curmethod](screen)
                screen.flip ()
    video.quit ()
Example #5
0
def run ():
    drawtypes = [ draw_aacircle, draw_circle, draw_filledcircle,
                  draw_box, draw_rectangle,
                  draw_arc,
                  draw_line, draw_aaline, draw_hline, draw_vline, 
                  draw_polygon, draw_aapolygon, draw_filledpolygon,
                  draw_texturedpolygon,
                  draw_ellipse, draw_aaellipse, draw_filledellipse,
                  draw_aatrigon, draw_trigon, draw_filledtrigon,
                  draw_bezier,
                  draw_pie, draw_filledpie, 
                  ]
    curtype = 0
    video.init ()

    screen = video.set_mode (640, 480, 32)
    screen.fill (white)
    drawtypes[0] (screen)
    screen.flip ()

    okay = True
    while okay:
        for ev in event.get ():
            if ev.type == sdlconst.QUIT:
                okay = False
            if ev.type == sdlconst.KEYDOWN and ev.key == sdlconst.K_ESCAPE:
                okay = False
            if ev.type == sdlconst.MOUSEBUTTONDOWN:
                curtype += 1
                if curtype >= len (drawtypes):
                    curtype = 0
                screen.fill (white)
                drawtypes[curtype] (screen)
                screen.flip ()
    video.quit ()
Example #6
0
def run():
    video.init ()
    freetype.init (8)

    font = freetype.Font (pygame2.examples.RESOURCES.get ("sans.ttf"))

    screen = video.set_mode (800, 600)
    screen.fill (colors["grey_light"])

    sf, w, h = font.render("Hello World", colors["red"], colors['grey_dark'],
        ptsize=64, style=ftconstants.STYLE_UNDERLINE|ftconstants.STYLE_ITALIC)
    screen.blit (sf, (32, 32))

    font.render("abcdefghijklm", colors["grey_dark"], colors["green"],
                ptsize=64, dest=(screen, 32, 128))

    font.vertical = True
    font.render("Vertical?", colors["blue"], ptsize=32, dest=(screen, 32, 190))
    font.vertical = False

    font.render("Let's spin!", colors["red"], ptsize=48, rotation=55,
                dest=(screen, 64, 190))

    font.render("All around!", colors["green"], ptsize=48, rotation=-55,
                dest=(screen, 150, 270))

    font.render("and BLEND", pygame2.Color(255, 0, 0, 128), ptsize=64,
                dest=(screen, 250, 220))

    font.render("or BLAND!", pygame2.Color(0, 0xCC, 28, 128), ptsize=64,
                dest=(screen, 258, 237))

    text = "I \u2665 Unicode"
    if sys.version_info[0] < 3:
        text = "I " + unichr(0x2665) + " Unicode"
    font.render(text, pygame2.Color(0, 0xCC, 0xDD), ptsize=64,
                dest=(screen, 298, 320))
    
    text = "\u2665"
    if sys.version_info[0] < 3:
        text = unichr(0x2665)
    font.render(text, colors["grey_light"], colors["red"], ptsize=148,
                dest=(screen, 480, 32))

    font.render("...yes, this is a SDL surface", pygame2.Color(0, 0, 0),
                ptsize=24, style=ftconstants.STYLE_BOLD,
                dest=(screen, 380, 380))

    screen.flip ()

    okay = True
    while okay:
        for ev in event.get ():
            if ev.type == constants.QUIT:
                okay = False
            if ev.type == constants.KEYDOWN and ev.key == constants.K_ESCAPE:
                okay = False
    video.quit ()
Example #7
0
    def test_pygame2_sdl_video_get_info(self):

        # __doc__ (as of 2009-05-31) for pygame2.sdl.video.get_info:

        # get_info () -> dict
        # 
        # Gets information about the video hardware.
        # 
        # Gets information about the video hardware. The returned dictionary
        # contains the following entries.
        # 
        # +------------------+---------------------------------------------+
        # | Entry            | Meaning                                     |
        # +==================+=============================================+
        # | hw_available     | Is it possible to create hardware surfaces? |
        # +------------------+---------------------------------------------+
        # | wm_available     | Is a window manager available?              |
        # +------------------+---------------------------------------------+
        # | blit_hw          | Are hardware to hardware blits accelerated? |
        # +------------------+---------------------------------------------+
        # | blit_hw_CC       | Are hardware to hardware colorkey blits     |
        # |                  | accelerated?                                |
        # +------------------+---------------------------------------------+
        # | blit_hw_A        | Are hardware to hardware alpha blits        |
        # |                  | accelerated?                                |
        # +------------------+---------------------------------------------+
        # | blit_sw          | Are software to hardware blits accelerated? |
        # +------------------+---------------------------------------------+
        # | blit_sw_CC       | Are software to hardware colorkey blits     |
        # |                  | accelerated?                                |
        # +------------------+---------------------------------------------+
        # | blit_sw_A        | Are software to hardware alpha blits        |
        # |                  | accelerated?                                |
        # +------------------+---------------------------------------------+
        # | blit_fill        | Are color fills accelerated?                |
        # +------------------+---------------------------------------------+
        # | video_mem        | Total amount of video memory in Kilobytes   |
        # +------------------+---------------------------------------------+
        # | vfmt             | Pixel format of the video device            |
        # +------------------+---------------------------------------------+
        self.assertRaises (pygame2.Error, video.get_info)
        video.init ()
        info = video.get_info ()
        self.assertTrue (type (info) == dict)
        self.assertTrue (type (info["hw_available"]) == bool)
        self.assertTrue (type (info["wm_available"]) == bool)
        self.assertTrue (type (info["blit_hw"]) == bool)
        self.assertTrue (type (info["blit_hw_CC"]) == bool)
        self.assertTrue (type (info["blit_hw_A"]) == bool)
        self.assertTrue (type (info["blit_sw"]) == bool)
        self.assertTrue (type (info["blit_sw_CC"]) == bool)
        self.assertTrue (type (info["blit_sw_A"]) == bool)
        self.assertTrue (type (info["blit_fill"]) == bool)
        self.assertTrue (type (info["video_mem"]) == int)
        self.assertTrue (type (info["vfmt"]) == video.PixelFormat)
        video.quit ()
Example #8
0
def run ():
    black = pygame2.Color (0, 0, 0)
    white = pygame2.Color (255, 255, 255)
    green = pygame2.Color (0, 255, 0)
    red = pygame2.Color (255, 0, 0)
    
    curcolor = black
    pressed = False
    lastpos = 0, 0
    
    video.init ()
    screen = video.set_mode (640, 480)
    
    screen.fill (white)
    screen.flip ()

    wm.set_caption ("Mouse demo")

    okay = True
    while okay:
        for ev in event.get ():
            if ev.type == sdlconst.QUIT:
                okay = False
            if ev.type == sdlconst.KEYDOWN and ev.key == sdlconst.K_ESCAPE:
                okay = False
            if ev.type == sdlconst.MOUSEMOTION:
                if pressed:
                    x, y = ev.pos
                    lastpos = ev.pos
                    screen.fill (curcolor, pygame2.Rect (x - 2, y - 2, 5, 5))
                    screen.flip ()
            elif ev.type == sdlconst.MOUSEBUTTONDOWN:
                if ev.button == 1:
                    pressed = True
                elif ev.button == 4:
                    x, y = lastpos[0], lastpos[1] - 2
                    screen.fill (green, pygame2.Rect (x - 2, y - 2, 5, 5))
                    lastpos = x, y
                    screen.flip ()
                elif ev.button == 5:
                    x, y = lastpos[0], lastpos[1] + 2
                    screen.fill (red, pygame2.Rect (x - 2, y - 2, 5, 5))
                    lastpos = x, y
                    screen.flip ()
            elif ev.type == sdlconst.MOUSEBUTTONUP:
                if ev.button == 1:
                    pressed = False
                elif ev.button == 3:
                    if curcolor == white:
                        curcolor = black
                        screen.fill (white)
                    else:
                        curcolor = white
                        screen.fill (black)
                    screen.flip ()
    video.quit ()
Example #9
0
def run ():
    video.init ()
    freetype.init ()

    font = freetype.Font (pygame2.examples.RESOURCES.get ("sans.ttf"))

    fpsmanager = sdlgfx.FPSmanager (2)

    screen = video.set_mode (640, 480)
    wm.set_caption ("FPSmanager example")
    screenrect = pygame2.Rect (640, 480)
    screen.fill (black)
    screen.flip ()

    okay = True
    while okay:
        for ev in event.get ():
            if ev.type == sdlconst.QUIT:
                okay = False
            if ev.type == sdlconst.KEYDOWN:
                framerate = fpsmanager.framerate
                if ev.key == sdlconst.K_ESCAPE:
                    okay = False
                elif ev.key in (sdlconst.K_PLUS, sdlconst.K_KP_PLUS):
                    framerate = min (framerate + 1, gfxconst.FPS_UPPER_LIMIT)
                    fpsmanager.framerate = framerate
                elif ev.key in (sdlconst.K_MINUS, sdlconst.K_KP_MINUS):
                    framerate = max (framerate - 1, gfxconst.FPS_LOWER_LIMIT)
                    fpsmanager.framerate = framerate

        screen.fill (black)

        prev = time.time ()
        fpsmanager.delay ()
        last = time.time ()

        millis = ((last - prev) * 1000)
        fpstext = "FPS: %d" % fpsmanager.framerate
        timetext = "time (ms) passed since last update: %.3f" % millis
                   
        surfacef, w, h = font.render (fpstext, white, ptsize=28)
        surfacet, w2, h2 = font.render (timetext, white, ptsize=28)
        blitrect = pygame2.Rect (w, h)
        blitrect.center = screenrect.centerx, screenrect.centery - h
        screen.blit (surfacef, blitrect.topleft)
        blitrect = pygame2.Rect (w2, h2)
        blitrect.center = screenrect.centerx, screenrect.centery + h
        screen.blit (surfacet, blitrect.topleft)
        screen.flip ()
    
    video.quit ()
Example #10
0
    def test_pygame2_sdl_video_was_init(self):

        # __doc__ (as of 2009-05-31) for pygame2.sdl.video.was_init:

        # was_init () -> bool
        # 
        # Returns, whether the video subsystem of the SDL library is
        # initialized.
        video.quit ()
        self.assertEqual (video.was_init (), False)
        video.init ()
        self.assertEqual (video.was_init (), True)
        video.quit ()
        self.assertEqual (video.was_init (), False)
Example #11
0
    def test_pygame2_sdl_video_get_drivername(self):

        # __doc__ (as of 2009-05-31) for pygame2.sdl.video.get_drivername:

        # get_drivername () -> str
        # 
        # Gets the name of the video driver.
        # 
        # Gets the name of the video driver or None, if the video system has
        # not been initialised or it could not be determined.
        self.assertTrue (video.get_drivername () == None)
        video.init ()
        self.assertTrue (video.get_drivername () != None)
        video.quit ()
        self.assertTrue (video.get_drivername () == None)
Example #12
0
def run ():
    filltypes = [ fill_solid, fill_rgba,
                  fill_min, fill_rgba_min,
                  fill_max, fill_rgba_max,
                  fill_add, fill_rgba_add,
                  fill_sub, fill_rgba_sub,
                  fill_mult, fill_rgba_mult,
                  fill_and, fill_rgba_and,
                  fill_or, fill_rgba_or,
                  fill_xor, fill_rgba_xor,
                  fill_diff, fill_rgba_diff,
                  fill_screen, fill_rgba_screen,
                  fill_avg, fill_rgba_avg,
                  ]
    curtype = 0
    video.init ()
    
    screen = video.set_mode (760, 300, 32)
    surface = image.load_bmp (pygame2.examples.RESOURCES.get ("logo.bmp"))
    surface = surface.convert (flags=sdlconst.SRCALPHA)
    
    color = white
    screen.fill (color)
    screen.blit (surface, (40, 50))
    screen.flip ()

    okay = True
    while okay:
        for ev in event.get ():
            if ev.type == sdlconst.QUIT:
                okay = False
            if ev.type == sdlconst.KEYDOWN and ev.key == sdlconst.K_ESCAPE:
                okay = False
            if ev.type == sdlconst.MOUSEBUTTONDOWN:
                curtype += 1
                if curtype >= len (filltypes):
                    curtype = 0
                    if color == black:
                        color = white
                    else:
                        color = black

                screen.fill (color)
                screen.blit (surface, (40, 50))
                filltypes[curtype] (screen)
                screen.flip ()
    video.quit ()
Example #13
0
def run ():
    white = pygame2.Color (255, 255, 255)
    black = pygame2.Color (0, 0, 0)

    fontmap = [ "0123456789",
                "ABCDEFGHIJ",
                "KLMNOPQRST",
                "UVWXYZ    ",
                "abcdefghij",
                "klmnopqrst",
                "uvwxyz    ",
                ",;.:!?-+()" ]

    video.init ()

    imgfont = image.load_bmp (pygame2.examples.RESOURCES.get ("font.bmp"))
    bmpfont = BitmapFont (imgfont, (32, 32), fontmap)
    
    screen = video.set_mode (640, 480)
    screen.fill (white)
    
    center = (320 - bmpfont.surface.w / 2, 10)
    screen.blit (bmpfont.surface, center)
    screen.flip ()

    wm.set_caption ("Keyboard demo")

    x = 0, 0
    pos = (310, 300)
    area = pygame2.Rect (300, 290, 50, 50)

    okay = True
    while okay:
        for ev in event.get ():
            if ev.type == sdlconst.QUIT:
                okay = False
            if ev.type == sdlconst.KEYDOWN:
                if ev.key == sdlconst.K_ESCAPE:
                    okay = False
                elif bmpfont.contains (ev.unicode):
                    screen.fill (white)
                    screen.fill (black, area)
                    screen.blit (bmpfont.surface, center)
                    bmpfont.render_on (screen, ev.unicode, pos)
                    screen.flip ()
    video.quit ()
Example #14
0
    def test_pygame2_sdl_video_get_videosurface(self):

        # __doc__ (as of 2009-05-31) for pygame2.sdl.video.get_videosurface:

        # get_videosurface () -> Surface
        # 
        # Gets the current display surface or None, if there is no such Surface.
        self.assertRaises (pygame2.Error, video.get_videosurface)
        video.init ()
        self.assertTrue (video.get_videosurface () == None)
        video.quit ()
        self.assertRaises (pygame2.Error, video.get_videosurface)
        video.init ()
        video.set_mode (1, 1)
        self.assertTrue (type (video.get_videosurface ()) == video.Surface)
        video.quit ()
        self.assertRaises (pygame2.Error, video.get_videosurface)
Example #15
0
    def test_pygame2_mask_from_threshold(self):
        __tags__ = [ "sdl" ]

        # __doc__ (as of 2008-11-03) for pygame2.mask.from_threshold:

        # pygame2.mask.from_threshold (surface, color[, threshold, thressurface]) -> Mask
        # 
        # Creates a mask by thresholding surfaces.
        # 
        # This is a more featureful method of getting a Mask from a
        # Surface.  If supplied with only one Surface, all pixels within the
        # threshold of the supplied *color* are set in the Mask. If given
        # the optional *thressurface*, all pixels in *surface* that are
        # within the *threshold* of the corresponding pixel in
        # *thressurface* are set in the Mask.

        video.init ()
        a = [16, 24, 32]
        
        for i in a:
            surf = video.Surface (70, 70, i)
            surf.fill (pygame2.Color (100,50,200), pygame2.Rect (20,20,20,20))
            mask = pygame2.mask.from_threshold (surf,
                                                pygame2.Color (100,50,200,255),
                                                pygame2.Color (10,10,10,255))
            
            self.assertEqual (mask.count, 400)
            self.assertEqual (mask.get_bounding_rects (),
                              [pygame2.Rect (20, 20, 20, 20)])
            
        for i in a:
            surf = video.Surface (70, 70, i)
            surf2 = video.Surface (70,70, i)
            surf.fill (pygame2.Color (100, 100, 100))
            surf2.fill (pygame2.Color (150, 150, 150))
            surf2.fill (pygame2.Color (100, 100, 100),
                        pygame2.Rect (40, 40, 10, 10))
            mask = pygame2.mask.from_threshold(surf, pygame2.Color (0, 0, 0, 0),
                                               pygame2.Color (10, 10, 10, 255),
                                               surf2)
            
            self.assertEqual (mask.count, 100)
            self.assertEqual (mask.get_bounding_rects(),
                              [pygame2.Rect (40, 40, 10, 10)])
        video.quit ()
Example #16
0
def run ():
    blittypes = [ blit_solid, blit_min, blit_max, blit_add, blit_sub,
                  blit_mult, blit_and, blit_or, blit_xor, blit_diff,
                  blit_screen, blit_avg,
                  blit_rgba, blit_rgba_min, blit_rgba_max, blit_rgba_add,
                  blit_rgba_sub, blit_rgba_mult, blit_rgba_and, blit_rgba_or,
                  blit_rgba_xor, blit_rgba_diff, blit_rgba_screen,
                  blit_rgba_avg ]
    curtype = 0
    video.init ()
    screen = video.set_mode (640, 480, 32)
    color = white
    imgdir = os.path.dirname (os.path.abspath (__file__))
    logo = None
    if hassdlimage:
        logo = image.load (pygame2.examples.RESOURCES.get ("logo.gif"))
    else:
        logo = image.load_bmp (pygame2.examples.RESOURCES.get ("logo.bmp"))
    
    screen.fill (color)
    screen.blit (logo, (-10, 140))
    blit_solid (screen)
    screen.flip ()

    okay = True
    while okay:
        for ev in event.get ():
            if ev.type == sdlconst.QUIT:
                okay = False
            if ev.type == sdlconst.KEYDOWN and ev.key == sdlconst.K_ESCAPE:
                okay = False
            if ev.type == sdlconst.MOUSEBUTTONDOWN:
                curtype += 1
                if curtype >= len (blittypes):
                    curtype = 0
                    if color == black:
                        color = white
                    else:
                        color = black

                screen.fill (color)
                screen.blit (logo, (-10, 140))
                blittypes[curtype] (screen)
                screen.flip ()
    video.quit ()
Example #17
0
    def test_pygame2_sdl_video_init(self):

        # __doc__ (as of 2009-05-31) for pygame2.sdl.video.init:

        # init () -> None
        # 
        # Initializes the video subsystem of the SDL library.
        self.assertEqual (video.init (), None)
        video.quit ()
Example #18
0
    def test_pygame2_mask_from_surface(self):
        __tags__ = [ "sdl" ]

        # __doc__ (as of 2008-11-03) for pygame2.mask.from_surface:

        # pygame2.mask.from_surface (surface, threshold) -> Mask
        # 
        # Returns a Mask from the given pygame2.sdl.video.Surface.
        # 
        # Makes the transparent parts of the Surface not set, and the
        # opaque parts set. The alpha of each pixel is checked to see
        # if it is greater than the given threshold. If the Surface is
        # color keyed, then threshold is not used.  This requires
        # pygame2 to be built with SDL support enabled.
        # 
        # This requires pygame2 to be built with SDL support enabled.
        video.init ()
        
        mask_from_surface = pygame2.mask.from_surface

        surf = video.Surface(70, 70, 32, sdlconst.SRCALPHA)
        surf.fill(pygame2.Color(255,255,255,255))

        amask = mask_from_surface (surf)

        self.assertEqual(amask.get_at(0,0), 1)
        self.assertEqual(amask.get_at(66,1), 1)
        self.assertEqual(amask.get_at(69,1), 1)

        surf.set_at(0,0, pygame2.Color(255,255,255,127))
        surf.set_at(1,0, pygame2.Color(255,255,255,128))
        surf.set_at(2,0, pygame2.Color(255,255,255,0))
        surf.set_at(3,0, pygame2.Color(255,255,255,255))

        amask = mask_from_surface(surf)
        self.assertEqual(amask.get_at(0,0), 0)
        self.assertEqual(amask.get_at(1,0), 1)
        self.assertEqual(amask.get_at(2,0), 0)
        self.assertEqual(amask.get_at(3,0), 1)

        surf.fill(pygame2.Color(255,255,255,0))
        amask = mask_from_surface(surf)
        self.assertEqual(amask.get_at(0, 0), 0)
        video.quit ()
Example #19
0
    def test_pygame2_sdl_gl_load_library(self):

        # __doc__ (as of 2009-12-14) for pygame2.sdl.gl.load_library:

        # load_library (libraryname) -> None
        # 
        # Loads the desired OpenGL library.
        # 
        # Loads the desired OpenGL library specified by the passed full qualified
        # path. This must be called before any first call to
        # pygame2.sdl.video.set_mode to have any effect.
        self.assertRaises (pygame2.Error, gl.load_library, "invalid_opengl_lib")
        gllib = self._get_gllib ()
        if not gllib:
            return
        self.assertRaises (pygame2.Error, gl.load_library, gllib)

        video.init ()
        self.assertRaises (pygame2.Error, gl.load_library, "invalid_opengl_lib")
        self.assertEquals (gl.load_library (gllib), None)
        video.quit ()
Example #20
0
    def test_pygame2_sdl_video_is_mode_ok(self):

        # __doc__ (as of 2009-05-31) for pygame2.sdl.video.is_mode_ok:

        # is_mode_ok (width, height[, bpp, flags]) -> bool
        # is_mode_ok (size[, bpp, flags]) -> bool
        # 
        # Checks, whether the requested video mode is supported.
        # 
        # Checks, whether the video mode is supported for the passed size,
        # bit depth and flags. If the bit depth (bpp) argument is omitted,
        # the current screen bit depth will be used.
        # 
        # The optional flags argument is the same as for set_mode.
        self.assertRaises (pygame2.Error, video.is_mode_ok)
        video.init ()
        modes = video.list_modes ()
        for r in modes:
            self.assertTrue (video.is_mode_ok (r.size) == True)
        video.quit ()
        self.assertRaises (pygame2.Error, video.is_mode_ok)
Example #21
0
    def test_pygame2_sdl_video_set_gamma(self):

        # __doc__ (as of 2009-05-31) for pygame2.sdl.video.set_gamma:

        # set_gamma (red, green, blue) -> None
        # 
        # Sets the gamma values for all three color channels.
        # 
        # Sets the gamma values for all three color channels. In case
        # adjusting the gamma is not supported, an exception will be raised.
        video.init ()
        try:
            video.set_gamma (1, 1, 1)
        except pygame2.Error:
            video.quit ()
            return
        self.assertTrue (video.set_gamma (0, 0, 0) == None)
        self.assertTrue (video.set_gamma (1, 1, 1) == None)
        self.assertTrue (video.set_gamma (10, 1, 1) == None)
        self.assertTrue (video.set_gamma (10, 12.88, 3.385) == None)
        self.assertTrue (video.set_gamma (-10, -12.88, -3.385) == None)
        video.quit ()
Example #22
0
def run():
    video.init()

    surface = None
    if hassdlimage:
        surface = image.load(pygame2.examples.RESOURCES.get("logo.gif"))
    else:
        surface = image.load_bmp(pygame2.examples.RESOURCES.get("logo.bmp"))

    screen = video.set_mode(surface.w + 10, surface.h + 10)
    screen.fill(pygame2.Color(255, 255, 255))
    screen.blit(surface, (5, 5))
    screen.flip()

    okay = True
    while okay:
        for ev in event.get():
            if ev.type == constants.QUIT:
                okay = False
            if ev.type == constants.KEYDOWN and ev.key == constants.K_ESCAPE:
                okay = False
    video.quit()
Example #23
0
    def test_pygame2_sdl_video_list_modes(self):

        # __doc__ (as of 2009-05-31) for pygame2.sdl.video.list_modes:

        # list_modes ([, format, flags]) -> [rect, rect, ...]
        # 
        # Returns the supported modes for a specific format and flags.
        # 
        # Returns the supported modes for a specific format and flags.
        # The optional format argument must be a PixelFormat
        # instance with the desired mode information. The optional flags
        # argument is the same as for set_mode.
        # 
        # If both, the format and flags are omitted, all supported screen
        # resolutions for all supported formats and flags are returned.
        self.assertRaises (pygame2.Error, video.list_modes)
        video.init ()
        modes = video.list_modes()
        self.assertTrue (type (modes) == list)
        for r in modes:
            self.assertTrue (type (r) == pygame2.Rect)
        video.quit ()
        self.assertRaises (pygame2.Error, video.list_modes)
Example #24
0
    def test_pygame2_sdl_video_get_gammaramp(self):

        # __doc__ (as of 2009-05-31) for pygame2.sdl.video.get_gammaramp:

        # get_gammaramp () -> (int, int, ...), (int, int, ...), (int, int, ...)
        # 
        # Gets the color gamma lookup tables for the display.
        # 
        # Gets the color gamma lookup table for the display. This will
        # return three tuples for the red, green and blue gamma values. Each
        # tuple contains 256 values.
        video.init ()
        r, g, b = video.get_gammaramp ()
        self.assertTrue (len (r) == 256)
        self.assertTrue (len (g) == 256)
        self.assertTrue (len (b) == 256)
        for v in r:
            self.assertTrue (type (v) == int)
        for v in g:
            self.assertTrue (type (v) == int)
        for v in b:
            self.assertTrue (type (v) == int)
        video.quit ()
Example #25
0
    def test_pygame2_sdl_gl_set_attribute(self):

        # __doc__ (as of 2009-12-14) for pygame2.sdl.gl.set_attribute:

        # set_attribute (attribute, value) -> None
        # 
        # Sets an OpenGL attribute value.
        # 
        # Sets the value of the specified OpenGL attribute.
        gllib = self._get_gllib ()
        if not gllib:
            return
        
        # No video.
        self.assertRaises (pygame2.Error, gl.set_attribute, constants.GL_RED_SIZE, 1)
        
        video.init ()

        self.assertEquals (gl.load_library (gllib), None)
        
        # No OpenGL screen
        screen = video.set_mode (10, 10)
        self.assertEquals (gl.set_attribute (constants.GL_RED_SIZE, 1), None)
        self.assertEquals (gl.get_attribute (constants.GL_RED_SIZE), 0)
Example #26
0
 def setUp (self):
     video.init ()
Example #27
0
def run ():
    freetype.init ()
    video.init ()
    sdlmixer.init ()
    sdlmixer.open_audio (sdlmixerconst.DEFAULT_FREQUENCY,
                         sdlmixerconst.DEFAULT_FORMAT,
                         sdlmixerconst.DEFAULT_CHANNELS,
                         1024)
    print ("Detected decoders: %s" % sdlmixer.get_decoders ())

    sound = sdlmixer.Chunk (pygame2.examples.RESOURCES.get ("house_lo.wav"))
    channel_sound = sdlmixer.Channel (1)

    font = freetype.Font (pygame2.examples.RESOURCES.get ("sans.ttf"))
    surfaces = get_help (font)

    screen = video.set_mode (640, 480)
    wm.set_caption ("SDL_mixer sound example")

    screenrect = pygame2.Rect (640, 480)
    screen.fill (black)
    yoff = 100
    for (sf, w, h) in surfaces:
        screen.blit (sf, (100, yoff))
        yoff += h + 10
    screen.flip ()

    okay = True
    while okay:
        for ev in event.get ():
            if ev.type == sdlconst.QUIT:
                okay = False
            if ev.type == sdlconst.KEYDOWN:
                # play, pause, resume
                if ev.key == sdlconst.K_SPACE:
                    if channel_sound.paused:
			print ("Resuming")
                        channel_sound.resume ()
                    elif channel_sound.playing:
			print ("Pausing")
                        channel_sound.pause ()
                    else:
			print ("Starting")
                        channel_sound.play (sound, -1)
                if ev.key == sdlconst.K_ESCAPE:
                    # exit the application
                    okay = False
                elif ev.key in (sdlconst.K_PLUS, sdlconst.K_KP_PLUS):
                    # increase volume
                    channel_sound.volume = min (channel_sound.volume + 1,
                                                sdlmixerconst.MAX_VOLUME)
                    print ("Volume is now: %d" % channel_sound.volume)
                elif ev.key in (sdlconst.K_MINUS, sdlconst.K_KP_MINUS):
                    # decrease volume
                    channel_sound.volume = max (channel_sound.volume - 1, 0)
                    print ("Volume is now: %d" % channel_sound.volume)

        screen.flip ()

    freetype.quit ()
    video.quit ()
    sdlmixer.close_audio ()
    sdlmixer.quit ()
Example #28
0
 def setUp(self):
     if sys.version.startswith("3.1"):
         self.assertIsInstance = \
             lambda x, t: self.assertTrue(isinstance(x, t))
     video.init()
Example #29
0
 def test_quit(self):
     video.quit()
     video.quit()
     video.quit()
     video.init()
import sys
import time
import pygame2
import pygame2.sdl.constants as constants
import pygame2.sdl.image as image
import pygame2.sdl.video as video
video.init()
img = image.load_bmp("c:\\test.bmp")
screen = video.set_mode(img.width, img.height)
screen.fill(pygame2.Color(255, 255, 255))
screen.blit(img, (0, 0))
screen.flip()
time.sleep(10)