示例#1
0
def main():

    global rtri, rquad, gui_screen
    video_flags = OPENGL | DOUBLEBUF

    pygame.init()
    pygame.display.set_mode((640, 480), video_flags)

    resize((640, 480))
    init()

    # create PanelOverlaySurface
    gui_screen = lamina.LaminaScreenSurface(0.985)

    pointlist = [(200, 200), (400, 200), (400, 400), (200, 400)]
    pygame.draw.polygon(gui_screen.surf, (200, 0, 0), pointlist, 0)
    pointlist1 = [(250, 250), (350, 250), (350, 350), (250, 350)]
    pygame.draw.polygon(gui_screen.surf, (0, 0, 100), pointlist1, 0)
    # draw text on a new Surface
    font = pygame.font.Font(None, 40)
    txt = font.render('Pygame Text', 1, (0, 0, 0), (200, 0, 0))
    gui_screen.surf.blit(txt, (205, 205))

    gui_screen.refresh()
    gui_screen.refreshPosition()

    frames = 0
    ticks = pygame.time.get_ticks()
    clock = pygame.time.Clock()
    while 1:
        event = pygame.event.poll()
        if event.type == QUIT or (event.type == KEYDOWN
                                  and event.key == K_ESCAPE):
            break

        # draw all objects
        draw()

        # update rotation counters
        if triOn:
            rtri += 0.2
        if quadOn:
            rquad += 0.2

        # make changes visible
        pygame.display.flip()
        frames = frames + 1
        sys.stdout.write("fps:  %d\r" % ((frames * 1000) /
                                         (pygame.time.get_ticks() - ticks)))
        clock.tick(60)
示例#2
0
def setup():
    global gui_screen
    video_flags = OPENGL | DOUBLEBUF

    pygame.init()
    pygame.display.set_mode((400, 400), video_flags)

    glShadeModel(GL_SMOOTH)
    glClearColor(0.0, 0.5, 0.0, 0.0)
    glClearDepth(1.0)
    glEnable(GL_DEPTH_TEST)
    glDepthFunc(GL_LEQUAL)
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)

    # create PanelOverlaySurface
    gui_screen = lamina.LaminaScreenSurface()

    # draw text on a new Surface
    font = pygame.font.Font(None, 40)
    txt = font.render('Pygame Text', 1, (0, 0, 0), (200, 0, 0))
    gui_screen.surf.blit(txt, (75, 75))
示例#3
0
def main():
    global rtri, rquad, gui_screen
    video_flags = OPENGL | DOUBLEBUF

    pygame.init()
    pygame.display.set_mode((640, 480), video_flags)
    font = pygame.font.SysFont("default", 18)
    fontBig = pygame.font.SysFont("default", 24)
    fontSub = pygame.font.SysFont("default", 20)
    theme = pgui.Theme('test_theme');

    resize((640, 480))
    init()

    # create PanelOverlaySurface
    #    gui_screen = lamina.LaminaPanelSurface((640,480), (-3.3, 2.5, 6.6, 5))
    gui_screen = lamina.LaminaScreenSurface()

    gui = pgui.App(theme=theme)
    gui._screen = gui_screen.surf

    # func to toggle triangle spin
    def triTog():
        global triOn
        triOn = not triOn

    # func to toggle quad spin
    def quadTog():
        global quadOn
        quadOn = not quadOn

    # func to toggle zoom
    def zoomTog():
        global zoomAngle
        if zoomAngle == 45:
            zoomAngle = 30
        else:
            zoomAngle = 45
        resize((640, 480))
        gui_screen.refreshPosition()
        gui.repaint(gui_screen.surf)

    # create page    # layout using document
    lo = pgui.Container(width=640)

    # create page label
    title = pgui.Label("Lamina Demo : PGU", font=fontBig)
    lo.add(title, 29, 13)

    # create triangle button, connect to triTog handler function,
    #  and install in gui
    btn1 = pgui.Button("Stop/Start Triangle")
    btn1.connect(pgui.CLICK, triTog)
    lo.add(btn1, 120, 440)
    btn2 = pgui.Button("Stop/Start Quad")
    btn2.connect(pgui.CLICK, quadTog)
    lo.add(btn2, 420, 440)
    # create zoom button, connect to zoomTog handler function,
    #  and install in gui    
    btn3 = pgui.Button('Zoom')
    btn3.connect(pgui.CLICK, zoomTog)
    lo.add(btn3, 300, 440)
    gui.init(lo)

    frames = 0
    ticks = pygame.time.get_ticks()
    while 1:
        event = pygame.event.poll()
        if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE):
            break

        # handle gui events and raster updating
        gui.event((event))
        chg = gui.update(gui_screen.surf)
        if chg:
            gui_screen.refresh(chg)

        # draw all objects
        draw()

        # update rotation counters
        if triOn:
            rtri += 0.2
        if quadOn:
            rquad += 0.2

        # make changes visible
        pygame.display.flip()
        frames = frames + 1

    print
    "fps:  %d" % ((frames * 1000) / (pygame.time.get_ticks() - ticks))
示例#4
0
def main():
    global rtri, rquad, gui_screen
    video_flags = OPENGL | DOUBLEBUF

    pygame.init()
    pygame.display.set_mode((640, 480), video_flags)

    resize((640, 480))
    init()

    # create PanelOverlaySurface
    #    gui_screen = lamina.LaminaPanelSurface((640,480), (-3.3, 2.5, 6.6, 5))
    gui_screen = lamina.LaminaScreenSurface()

    gui = Renderer()
    # the following is a workaround that may not be necessary
    #  by the time you read this.  We assign to the private attribute
    #  _screen to bypass drawing the background
    gui._screen = gui_screen.surf

    # if you are using a newer version of Ocemp GUI, use something like
    #  this instead.  The 0 alpha will make the background transparent.
    # gui.color = (0,0,0,0)
    # gui.screen = gui_screen.surf

    # func to toggle triangle spin
    def triTog():
        global triOn
        triOn = not triOn

    # func to toggle quad spin
    def quadTog():
        global quadOn
        quadOn = not quadOn

    # create page label
    lbl = Label('Lamina Demo : Ocemp')
    lbl.position = 29, 13
    gui.add_widget(lbl)
    # create triangle button, connect to triTog handler function,
    #  and install in gui
    btn1 = Button('Stop/Start Triangle')
    btn1.connect_signal(SIG_CLICKED, triTog)
    btn1.position = 120, 440
    gui.add_widget(btn1)
    # create quad button, connect to quadTog handler function,
    #  and install in gui    
    btn2 = Button('Stop/Start Quad')
    btn2.connect_signal(SIG_CLICKED, quadTog)
    btn2.position = 420, 440
    gui.add_widget(btn2)

    frames = 0
    ticks = pygame.time.get_ticks()
    while 1:
        event = pygame.event.poll()
        if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE):
            break

        # handle gui events and raster updating
        gui.distribute_events((event))
        gui.update()
        dirty = gui.redraw(gui_screen.surf)
        if dirty:
            gui_screen.refresh(dirty)

        # draw all objects
        draw()

        # update rotation counters
        if triOn:
            rtri += 0.2
        if quadOn:
            rquad += 0.2

        # make changes visible
        pygame.display.flip()
        frames = frames + 1

    print
    "fps:  %d" % ((frames * 1000) / (pygame.time.get_ticks() - ticks))
示例#5
0
def main():
    global rtri, rquad, gui_screen
    global font, fofixFont, fps, mode
    fps = 0
    #video_flags = OPENGL|DOUBLEBUF
    video_flags = DOUBLEBUF | OPENGL | HWPALETTE | HWSURFACE

    pygame.init()
    pygame.display.set_mode((640, 480), video_flags)

    resize((640, 480))
    init()

    # create PanelOverlaySurface
    gui_screen = lamina.LaminaScreenSurface(0.985)

    pointlist = [(200, 200), (400, 200), (400, 400), (200, 400)]
    pygame.draw.polygon(gui_screen.surf, (200, 0, 0), pointlist, 0)
    pointlist1 = [(250, 250), (350, 250), (350, 350), (250, 350)]
    pygame.draw.polygon(gui_screen.surf, (0, 0, 100), pointlist1, 0)

    # draw text on a new Surface
    font = pygame.font.Font(None, 40)
    txt = font.render('Pygame Text', 1, (0, 0, 0), (200, 0, 0))
    gui_screen.surf.blit(txt, (205, 205))
    gui_screen.refresh()
    gui_screen.refreshPosition()

    frames = 0
    ticks = pygame.time.get_ticks()
    clock = pygame.time.Clock()
    while 1:
        event = pygame.event.poll()
        if event.type == QUIT or (event.type == KEYDOWN
                                  and event.key == K_ESCAPE):
            break
        elif event.type == KEYDOWN and (event.key == K_RIGHT
                                        or event.key == K_LEFT):
            mode = (mode + 1) % 3

        ticksDiff = pygame.time.get_ticks() - ticks
        if ticksDiff > 200 and mode == 0:
            gui_screen.refresh()

        # draw all objects
        draw()

        # update rotation counters
        if triOn:
            rtri += 0.2
        if quadOn:
            rquad += 0.2

        # make changes visible
        pygame.display.flip()
        frames = frames + 1
        if (ticksDiff > 200):
            fps = ((frames * 1000) / (ticksDiff))
            ticks = pygame.time.get_ticks()
            frames = 0
            print "mode: %s, %.2f fps" % (mode, fps)