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


Python sdl2.SDL_MOUSEBUTTONDOWN屬性代碼示例

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


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

示例1: on_gui_event

# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import SDL_MOUSEBUTTONDOWN [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

示例2: poll_events

# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import SDL_MOUSEBUTTONDOWN [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

示例3: run

# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import SDL_MOUSEBUTTONDOWN [as 別名]
def run():
    # You know those from the helloworld.py example.
    # Initialize the video subsystem, create a window and make it visible.
    sdl2.ext.init()
    window = sdl2.ext.Window("sdlgfx drawing examples", size=(800, 600))
    window.show()

    # Create a rendering context for the window. The sdlgfx module requires it.
    context = sdl2.ext.Renderer(window)

    # We implement the functionality as it was done in colorpalettes.py and
    # utilise a mapping table to look up the function to be executed, together
    # with the arguments they should receive
    functions = ((draw_lines, (context, 800, 600)),
                 (draw_circles, (context, 800, 600)),
                 (draw_ellipsis, (context, 800, 600)),
                 (draw_rects, (context, 800, 600)),
                 (draw_trigons, (context, 800, 600)),
                 (draw_polygons, (context, 800, 600)),
                 (draw_mixed, (context, 800, 600))
                )

    # A storage variable for the function we are currently on, so that we know
    # which function to execute next.
    curindex = 0
    draw_lines(context, 800, 600)

    # The event loop is nearly the same as we used in colorpalettes.py. If you
    # do not know, what happens here, take a look at colorpalettes.py for a
    # detailed description.
    running = True
    while running:
        events = sdl2.ext.get_events()
        for event in events:
            if event.type == sdl2.SDL_QUIT:
                running = False
                break
            if event.type == sdl2.SDL_MOUSEBUTTONDOWN:
                curindex += 1
                if curindex >= len(functions):
                    curindex = 0
                # In contrast to colorpalettes.py, our mapping table consists
                # of functions and their arguments. Thus, we get the currently
                # requested function and argument tuple and execute the
                # function with the arguments.
                func, args = functions[curindex]
                func(*args)
                break
        context.present()
    sdl2.ext.quit()
    return 0 
開發者ID:marcusva,項目名稱:py-sdl2,代碼行數:53,代碼來源:gfxdrawing.py

示例4: run

# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import SDL_MOUSEBUTTONDOWN [as 別名]
def run():
    # You know those from the helloworld.py example.
    # Initialize the video subsystem, create a window and make it visible.
    sdl2.ext.init()
    window = sdl2.ext.Window("2D drawing primitives", size=(800, 600))
    window.show()

    # As in colorpalettes.py, explicitly acquire the window's surface to
    # draw on.
    windowsurface = window.get_surface()

    # We implement the functionality as it was done in colorpalettes.py and
    # utilise a mapping table to look up the function to be executed, together
    # with the arguments they should receive
    functions = ((draw_lines, (windowsurface, 800, 600)),
                 (draw_rects, (windowsurface, 800, 600))
                 )

    # A storage variable for the function we are currently on, so that we know
    # which function to execute next.
    curindex = 0
    draw_lines(windowsurface, 800, 600)

    # The event loop is nearly the same as we used in colorpalettes.py. If you
    # do not know, what happens here, take a look at colorpalettes.py for a
    # detailled description.
    running = True
    while running:
        events = sdl2.ext.get_events()
        for event in events:
            if event.type == sdl2.SDL_QUIT:
                running = False
                break
            if event.type == sdl2.SDL_MOUSEBUTTONDOWN:
                curindex += 1
                if curindex >= len(functions):
                    curindex = 0
                # In contrast to colorpalettes.py, our mapping table consists
                # of functions and their arguments. Thus, we get the currently
                # requested function and argument tuple and execute the
                # function with the arguments.
                func, args = functions[curindex]
                func(*args)
                break
        window.refresh()
    sdl2.ext.quit()
    return 0 
開發者ID:marcusva,項目名稱:py-sdl2,代碼行數:49,代碼來源:draw.py

示例5: run

# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import SDL_MOUSEBUTTONDOWN [as 別名]
def run():
    # You know those from the helloworld.py example.
    # Initialize the video subsystem, create a window and make it visible.
    sdl2.ext.init()
    window = sdl2.ext.Window("Pixel Access", size=(800, 600))
    window.show()

    # As in colorpalettes.py, explicitly acquire the window's surface to
    # draw on.
    windowsurface = window.get_surface()

    # We implement the functionality as it was done in colorpalettes.py and
    # utilise a mapping table to look up the function to be executed, together
    # with the arguments they should receive
    functions = ((draw_horizontal_stripes, (windowsurface, 300, 500, 200, 400)),
                 (draw_vertical_stripes, (windowsurface, 300, 500, 200, 400)),
                 )

    # A storage variable for the function we are currently on, so that we know
    # which function to execute next.
    curindex = 0
    draw_horizontal_stripes(windowsurface, 300, 500, 200, 400)

    # The event loop is nearly the same as we used in colorpalettes.py. If you
    # do not know, what happens here, take a look at colorpalettes.py for a
    # detailled description.
    running = True
    while running:
        events = sdl2.ext.get_events()
        for event in events:
            if event.type == sdl2.SDL_QUIT:
                running = False
                break
            if event.type == sdl2.SDL_MOUSEBUTTONDOWN:
                curindex += 1
                if curindex >= len(functions):
                    curindex = 0
                # In contrast to colorpalettes.py, our mapping table consists
                # of functions and their arguments. Thus, we get the currently
                # requested function and argument tuple and execute the
                # function with the arguments.
                func, args = functions[curindex]
                func(*args)
                break
        window.refresh()
    sdl2.ext.quit()
    return 0 
開發者ID:marcusva,項目名稱:py-sdl2,代碼行數:49,代碼來源:pixelaccess.py


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