예제 #1
0
class MainWindow(pyglet.window.Window):
    def __init__(self,*args, **kwargs):
        #kwargs['width'] = SCREEN_X
        #kwargs['height'] = SCREEN_Y
        kwargs['fullscreen'] = False
        kwargs['resizable'] = True
        pyglet.window.Window.__init__(self, *args, **kwargs)
        self.set_exclusive_keyboard(False)
        pyglet.clock.schedule(self.update)
        gl.glEnable(gl.GL_BLEND)
        gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
        gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST)
        gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_NEAREST)
        
        self.states = []
        
        self.viewport = FixedResolutionViewport(self, 
            640, 480, filtered=False)
    
    def push_state(self,state):
        state.parent = self
        if len(self.states):
            self.states[-1].deactivate()
        self.states.append(state)
        self.states[-1].activate()
    def pop_state(self,state=None):
        self.states[-1].deactivate()
        self.states.pop(-1)
        if state != None:
            state.parent = self
            self.states.append(state)
        if len(self.states):
            self.states[-1].activate()
        else:
            quit()
            
    def __getattr__(self,attr):
        if hasattr(self.states[-1],attr):
            print "here"
            return getattr(self.states[-1],attr)
        raise AttributeError
            
    def on_draw(self):
        self.viewport.begin()
        self.states[-1].on_draw()
        self.viewport.end()
        
    def on_key_press(self,symbol,modifiers):
        if symbol == FULLSCREEN_KEY:
            self.set_fullscreen(not self.fullscreen)
        if len(self.states) and hasattr(self.states[-1],"on_key_press"):
            self.states[-1].on_key_press(symbol,modifiers)
            
    def update(self,dt):
        if len(self.states) and hasattr(self.states[-1],"update"):
            self.states[-1].update(dt)
예제 #2
0
 def __init__(self,*args, **kwargs):
     #kwargs['width'] = SCREEN_X
     #kwargs['height'] = SCREEN_Y
     kwargs['fullscreen'] = False
     kwargs['resizable'] = True
     pyglet.window.Window.__init__(self, *args, **kwargs)
     self.set_exclusive_keyboard(False)
     pyglet.clock.schedule(self.update)
     gl.glEnable(gl.GL_BLEND)
     gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
     gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST)
     gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_NEAREST)
     
     self.states = []
     
     self.viewport = FixedResolutionViewport(self, 
         640, 480, filtered=False)