コード例 #1
0
ファイル: pixelarray.py プロジェクト: gdos/pgreloaded.sdl12
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 ()
コード例 #2
0
ファイル: primitives.py プロジェクト: gdos/pgreloaded.sdl12
def draw_texturedpolygon (screen):
    wm.set_caption ("primitives.textured_polygon examples")
    tex = image.load_bmp (pygame2.examples.RESOURCES.get ("logo.bmp"))
    
    primitives.textured_polygon (screen, ((4, 40), (280, 7), (40, 220),
                                          (33, 237), (580, 370), (0, 0),
                                          (640, 480)), tex, 10, 30)
コード例 #3
0
    def test_pygame2_sdl_image_load_bmp(self):

        # __doc__ (as of 2009-05-14) for pygame2.sdl.image.load_bmp:

        # load_bmp (file) -> pygame2.sdl.video.Surface
        # 
        # Loads a BMP file and creates a pygame2.sdl.video.Surface from it.
        # 
        # load_bmp (file) -> pygame2.sdl.video.Surface  Loads a BMP file and
        # creates a pygame2.sdl.video.Surface from it.  Loads a BMP file and
        # creates a pygame2.sdl.video.Surface from it. The file argument can
        # be either a file object or the filename.
        imgdir = os.path.dirname (os.path.abspath (__file__))
        sf = image.load_bmp (os.path.join (imgdir, "test.bmp"))
        self.assertEqual (sf.size, (16, 16))
コード例 #4
0
ファイル: surface_fill.py プロジェクト: gdos/pgreloaded.sdl12
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 ()
コード例 #5
0
ファイル: keyboard.py プロジェクト: gdos/pgreloaded.sdl12
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 ()
コード例 #6
0
    def test_pygame2_sdl_image_save_bmp(self):

        # __doc__ (as of 2009-05-14) for pygame2.sdl.image.save_bmp:

        # save_bmp (surface, file) -> None
        # 
        # Saves a surface to a bitmap file.
        # 
        # save_bmp (surface, file) -> None  Saves a surface to a bitmap file.
        # Saves a pygame2.sdl.video.Surface to the specified file, where file
        # can be a filename or file object.
        imgdir = os.path.dirname (os.path.abspath (__file__))
        sf = image.load_bmp (os.path.join (imgdir, "test.bmp"))
        buf = None
        if sys.version_info[0] >= 3:
            buf = stringio.BytesIO ()
        else:
            buf = stringio.StringIO ()
        self.assertTrue (image.save_bmp (sf, buf) == None)
        self.assertEqual (os.stat (os.path.join (imgdir, "test.bmp")).st_size,
                          len (buf.getvalue ()))
コード例 #7
0
    def test_pygame2_sdl_video_Surface_save(self):

        # __doc__ (as of 2009-05-15) for pygame2.sdl.video.Surface.save:

        # save (file[, type]) -> None
        # 
        # Saves the Surface to a file.
        # 
        # Saves the Surface to a file. The file argument can be either a
        # file name or a file-like object to save the Surface to. The
        # optional type argument is required, if the file type cannot be
        # determined by the suffix.
        # 
        # Currently supported file types (suitable to pass as string for
        # the type argument) are:
        # 
        # * BMP
        # * TGA
        # * PNG
        # * JPEG (JPG)
        # 
        # If no type information is supplied and the file type cannot be
        # determined either, it will use TGA.
        modes = [32, 24, 16, 8]
        for bpp in modes:
            sf1 = video.Surface (16, 16, bpp)
            if bpp == 8:
                sf1.set_palette (CGAPALETTE)
            sf1.fill (pygame2.Color ("red"))
            bufcreat = None
            if sys.version_info[0] >= 3:
                bufcreat = stringio.BytesIO
            else:
                bufcreat = stringio.StringIO
            buf = bufcreat ()
        
            sf1.save (buf, "bmp")
            buf.seek (0)
            sf2 = image.load_bmp (buf).convert (sf1.format)
            self.assertEqual (sf1.size, sf2.size)
            self._cmppixels (sf1, sf2)
        
            buf.seek (0)
            sf2 = sdlimage.load (buf, "bmp").convert (sf1.format)
            self.assertEqual (sf1.size, sf2.size)
            self._cmppixels (sf1, sf2)

            buf = bufcreat ()
            sf1.save (buf, "jpg")
            buf.seek (0)
            sf2 = sdlimage.load (buf, "jpg").convert (sf1.format)
            self.assertEqual (sf1.size, sf2.size)

            buf = bufcreat ()
            sf1.save (buf, "png")
            buf.seek (0)
            sf2 = sdlimage.load (buf, "png").convert (sf1.format)
            self.assertEqual (sf1.size, sf2.size)
            self._cmppixels (sf1, sf2)

            buf = bufcreat ()
            sf1.save (buf, "tga")
            buf.seek (0)
            sf2 = sdlimage.load (buf, "tga").convert (sf1.format)
            self.assertEqual (sf1.size, sf2.size)
            self._cmppixels (sf1, sf2)
コード例 #8
0
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)