當前位置: 首頁>>代碼示例>>Python>>正文


Python sdl2.SDL_Event方法代碼示例

本文整理匯總了Python中sdl2.SDL_Event方法的典型用法代碼示例。如果您正苦於以下問題:Python sdl2.SDL_Event方法的具體用法?Python sdl2.SDL_Event怎麽用?Python sdl2.SDL_Event使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在sdl2的用法示例。


在下文中一共展示了sdl2.SDL_Event方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: run

# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import SDL_Event [as 別名]
def run(self):
        #main loop

        running = True
        event = sdl2.SDL_Event()

        last_ticks = 0

        while running:
            while sdl2.SDL_PollEvent(ctypes.byref(event)) != 0:
                if event.type == sdl2.SDL_QUIT:
                    running = False

            new_ticks = sdl2.SDL_GetTicks()
            if new_ticks - last_ticks > 1000 / 30:
                self.draw()
                last_ticks = new_ticks 
開發者ID:bglgwyng,項目名稱:pyVulkan,代碼行數:19,代碼來源:cube.py

示例2: on_gui_event

# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import SDL_Event [as 別名]
def on_gui_event(gui, data, event):
    """Callback to react to GUI events.

    Parameters
    ----------
    gui : hienoi.gui.GUI
        GUI.
    data : hienoi.application.OnEventData
        Data.
    event : sdl2.SDL_Event
        GUI event.
    """
    if gui.has_view_changed:
        # Passing `None` to the `_set_emitter_position` callback resets the
        # emitter states, which is what we need here otherwise we might end up
        # with crazy values coming out of the navigation actions.
        callback = Callback(_set_emitter_position, args=(None,))
        data.callbacks.particle_simulation.append(callback)
    elif event.type == sdl2.SDL_MOUSEMOTION:
        motion_event = event.motion
        mouse_position = Vector2i(motion_event.x, motion_event.y)
        position = gui.screen_to_world(mouse_position)
        callback = Callback(_set_emitter_position, args=(position,))
        data.callbacks.particle_simulation.append(callback) 
開發者ID:christophercrouzet,項目名稱:hienoi,代碼行數:26,代碼來源:trail.py

示例3: on_gui_event

# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import SDL_Event [as 別名]
def on_gui_event(gui, data, event):
    """Callback to react to GUI events.

    Parameters
    ----------
    gui : hienoi.gui.GUI
        GUI.
    data : hienoi.application.OnEventData
        Data.
    event : sdl2.SDL_Event
        GUI event.
    """
    if event.type == sdl2.SDL_MOUSEBUTTONDOWN:
        button_event = event.button
        if (button_event.button == sdl2.SDL_BUTTON_LEFT
                and gui.navigation_action == NavigationAction.NONE):
            # Create an 'add_particle' callback to be run by the particle
            # simulation object.
            mouse_position = gui.get_mouse_position()
            position = gui.screen_to_world(mouse_position)
            callback = Callback(_add_particle, args=(position,))
            data.callbacks.particle_simulation.append(callback) 
開發者ID:christophercrouzet,項目名稱:hienoi,代碼行數:24,代碼來源:equilibrium.py

示例4: handle_event

# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import SDL_Event [as 別名]
def handle_event(self):
        """Busywait until SDL_Event in keyhandlers is received.
        Then the corresponding value is returned."""
        event = sdl2.SDL_Event()
        while True:
            if sdl2.SDL_WaitEvent(ctypes.byref(event)) == 0:
                raise Exception(sdl2.SDL_GetError())
            if event.type == sdl2.SDL_QUIT:
                self.quit_handler()
                return True
            elif event.type == sdl2.SDL_KEYDOWN:
                key = event.key.keysym.sym
                mod = event.key.keysym.mod
                if mod in (sdl2.KMOD_NUM, sdl2.KMOD_NUM + sdl2.KMOD_LSHIFT,
                           sdl2.KMOD_NUM + sdl2.KMOD_RSHIFT):  # ignore numlock
                    mod -= sdl2.KMOD_NUM
                if (key, mod) in self.key_handlers:
                    return self.key_handlers[(key, mod)] 
開發者ID:kampffrosch94,項目名稱:pyAoEM,代碼行數:20,代碼來源:input_.py

示例5: _loopForEvents

# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import SDL_Event [as 別名]
def _loopForEvents(self):
		event = sdl2.SDL_Event()

		sdl2.SDL_StartTextInput()
		while self.is_running:
			# Look at the event queue
			while sdl2.SDL_PollEvent(ctypes.byref(event)) != 0:
				self.onEvent(event)

			# Look for layout changes
			if self.need_update:
				# Rebuilt only what is needed
				for i in self.indices_to_be_built:
					self.buildElement(i)
				self.indices_to_be_built = []

				# Draw the elements
				self._refresh()
				self.need_update = False
			sdl2.SDL_Delay(1) 
開發者ID:Romaingin,項目名稱:Antlia,代碼行數:22,代碼來源:renderer.py

示例6: poll_events

# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import SDL_Event [as 別名]
def poll_events(self, scene_state, data=None):
        """Process each event in the queue.

        Parameters
        ----------
        scene_state : hienoi.renderer.SceneState
            Scene state.
        data : object
            Data to pass back and forth between the caller and the function set
            for the 'on event' callback.
        """
        self._has_view_changed = False

        event = sdl2.SDL_Event()
        while sdl2.SDL_PollEvent(ctypes.byref(event)) != 0:
            event_type = event.type
            if event_type == sdl2.SDL_QUIT:
                self._on_quit_event(event.quit)
            elif event_type == sdl2.SDL_WINDOWEVENT:
                self._on_window_event(event.window)
            elif event_type == sdl2.SDL_KEYDOWN:
                self._on_key_down_event(event.key, scene_state)
            elif event_type == sdl2.SDL_KEYUP:
                self._on_key_up_event(event.key)
            elif event_type == sdl2.SDL_MOUSEBUTTONDOWN:
                self._on_mouse_button_down_event(event.button)
            elif event_type == sdl2.SDL_MOUSEBUTTONUP:
                self._on_mouse_button_up_event(event.button)
            elif event_type == sdl2.SDL_MOUSEWHEEL:
                self._on_mouse_wheel_event(event.wheel)
            elif event_type == sdl2.SDL_MOUSEMOTION:
                self._on_mouse_motion_event(event.motion)

            if self._on_event_callback:
                self._on_event_callback(self, data, event)

            if self.quit:
                break 
開發者ID:christophercrouzet,項目名稱:hienoi,代碼行數:40,代碼來源:gui.py

示例7: run

# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import SDL_Event [as 別名]
def run():
    sdl2.SDL_Init(sdl2.SDL_INIT_VIDEO)
    window = sdl2.SDL_CreateWindow(b"Hello World",
                                   sdl2.SDL_WINDOWPOS_CENTERED,
                                   sdl2.SDL_WINDOWPOS_CENTERED,
                                   592, 460, sdl2.SDL_WINDOW_SHOWN)
    fname = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                         "resources", "hello.bmp")
    image = sdl2.SDL_LoadBMP(fname.encode("utf-8"))
    windowsurface = sdl2.SDL_GetWindowSurface(window)
    sdl2.SDL_BlitSurface(image, None, windowsurface, None)
    sdl2.SDL_UpdateWindowSurface(window)
    sdl2.SDL_FreeSurface(image)

    running = True
    event = sdl2.SDL_Event()
    while running:
        while sdl2.SDL_PollEvent(ctypes.byref(event)) != 0:
            if event.type == sdl2.SDL_QUIT:
                running = False
                break
        sdl2.SDL_Delay(10)

    sdl2.SDL_DestroyWindow(window)
    sdl2.SDL_Quit()
    return 0 
開發者ID:marcusva,項目名稱:py-sdl2,代碼行數:28,代碼來源:sdl2hello.py

示例8: quit

# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import SDL_Event [as 別名]
def quit(self, exception=None):
        sdl2.SDL_PumpEvents()
        sdl2.SDL_FlushEvents(sdl2.SDL_FIRSTEVENT, sdl2.SDL_LASTEVENT)
        event = sdl2.SDL_Event()
        event.type = sdl2.SDL_QUIT
        self.poll_safe(event) 
開發者ID:cecton,項目名稱:pysdl2-sdl2ui,代碼行數:8,代碼來源:app.py

示例9: _poll_events

# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import SDL_Event [as 別名]
def _poll_events(self):
        event = sdl2.SDL_Event()
        while sdl2.SDL_PollEvent(ctypes.byref(event)) != 0:
            self.poll(event) 
開發者ID:cecton,項目名稱:pysdl2-sdl2ui,代碼行數:6,代碼來源:app.py

示例10: reload

# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import SDL_Event [as 別名]
def reload(self):
        sdl2.SDL_QuitSubSystem(sdl2.SDL_INIT_JOYSTICK)
        self.joysticks.clear()
        sdl2.SDL_InitSubSystem(sdl2.SDL_INIT_JOYSTICK)
        sdl2.SDL_PumpEvents()
        event = sdl2.SDL_Event()
        while sdl2.SDL_PeepEvents(
                ctypes.byref(event),
                1,
                sdl2.SDL_GETEVENT,
                sdl2.SDL_JOYDEVICEADDED,
                sdl2.SDL_JOYDEVICEADDED) != 0:
            self.added(event) 
開發者ID:cecton,項目名稱:pysdl2-sdl2ui,代碼行數:15,代碼來源:joystick.py

示例11: run

# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import SDL_Event [as 別名]
def run():
    if sdl2.SDL_Init(sdl2.SDL_INIT_VIDEO) != 0:
        print(sdl2.SDL_GetError())
        return -1

    window = sdl2.SDL_CreateWindow(b"OpenGL demo",
                                   sdl2.SDL_WINDOWPOS_UNDEFINED,
                                   sdl2.SDL_WINDOWPOS_UNDEFINED, 800, 600,
                                   sdl2.SDL_WINDOW_OPENGL)
    if not window:
        print(sdl2.SDL_GetError())
        return -1

    context = sdl2.SDL_GL_CreateContext(window)

    GL.glMatrixMode(GL.GL_PROJECTION | GL.GL_MODELVIEW)
    GL.glLoadIdentity()
    GL.glOrtho(-400, 400, 300, -300, 0, 1)

    x = 0.0
    y = 30.0

    event = sdl2.SDL_Event()
    running = True
    while running:
        while sdl2.SDL_PollEvent(ctypes.byref(event)) != 0:
            if event.type == sdl2.SDL_QUIT:
                running = False

        GL.glClearColor(0, 0, 0, 1)
        GL.glClear(GL.GL_COLOR_BUFFER_BIT)
        GL.glRotatef(10.0, 0.0, 0.0, 1.0)
        GL.glBegin(GL.GL_TRIANGLES)
        GL.glColor3f(1.0, 0.0, 0.0)
        GL.glVertex2f(x, y + 90.0)
        GL.glColor3f(0.0, 1.0, 0.0)
        GL.glVertex2f(x + 90.0, y - 90.0)
        GL.glColor3f(0.0, 0.0, 1.0)
        GL.glVertex2f(x - 90.0, y - 90.0)
        GL.glEnd()

        sdl2.SDL_GL_SwapWindow(window)
        sdl2.SDL_Delay(10)
    sdl2.SDL_GL_DeleteContext(context)
    sdl2.SDL_DestroyWindow(window)
    sdl2.SDL_Quit()
    return 0 
開發者ID:marcusva,項目名稱:py-sdl2,代碼行數:49,代碼來源:opengl.py


注:本文中的sdl2.SDL_Event方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。