コード例 #1
0
 def mouseReleaseEvent(self, event):
     if self.show_cursor_until is None:
         # Ignore clicks when cursor is hidden
         return
     InputHandler.add_event(Event.create_mouse_event(
         event, (self.width(), self.height())))
     self.ensure_cursor_visible()
コード例 #2
0
 def mouseReleaseEvent(self, event):
     if self.show_cursor_until is None:
         # Ignore clicks when cursor is hidden
         return
     InputHandler.add_event(
         Event.create_mouse_event(event, (self.width(), self.height())))
     self.ensure_cursor_visible()
コード例 #3
0
    def keyPressEvent(self, event):
        def modifier():
            if macosx:
                # This should correspond to the Cmd key(s) on OS X
                return int(event.modifiers()) & Qt.ControlModifier
            else:
                return int(event.modifiers()) & Qt.AltModifier

        assert isinstance(event, QKeyEvent)
        # print(event.isAutoRepeat(), event.type())
        if event.isAutoRepeat():
            return
        if modifier():
            if event.key() == Qt.Key_Return:
                self.window().set_fullscreen(not self.window().is_fullscreen())
                return
            if event.key() == Qt.Key_Q:
                self.window().close()
                return

        InputHandler.add_event(Event.create_key_event(event))
        text = event.text()
        if text and text in TEXT_WHITE_LIST:
            # We don't want special characters such as return, backspace
            # and escape (etc) to be sent as text events. For now, we use
            # a simple white list.
            InputHandler.add_event({"type": "text", "text": event.text()})
コード例 #4
0
ファイル: window.py プロジェクト: EdwardBetts/fs-uae-launcher
def show():
    global current_menu

    # fade_from is used on init_display, so we initialize this
    # color here. Set alpha to 2.0 to force 1 second of solid
    # color in combination with 2 sec. animation below
    if False and windows and not Settings.fullscreen_menu:
        State.get().fade_from = (1.0, 1.0, 1.0, 2.0)
        State.get().fade_to = (1.0, 1.0, 1.0, 0.0)
    else:
        State.get().fade_from = (0.0, 0.0, 0.0, 2.0)
        State.get().fade_to = (0.0, 0.0, 0.0, 0.0)
    init_display()
    if LIGHTING:
        init_lighting()
    init_textures()
    init_fonts()

    if USE_MENU_TRANSITIONS:
        compile_programs()

    InputHandler.open()

    on_resize((Render.get().display_width, Render.get().display_height))
    image_loader = ImageLoader.get()
    image_loader.start()
    new_menu = create_main_menu()
    State.get().history.append(new_menu)

    for platform_id in PlatformHandler.get_platform_ids():
        if "--" + platform_id in sys.argv:
            platform_menu = ItemMenu()
            platform_menu.parent_menu = new_menu

            platform_item = PlatformItem(platform_id)
            platform_menu.items.append(platform_item)
            # platform_menu.set_selected_index(0, immediate=True)

            new_menu = platform_item.activate(platform_menu)
            print(new_menu)
            State.get().history.append(new_menu)
            break

    set_current_menu(new_menu)
    if len(new_menu) == 1:
        # only n/a item showing, possibly
        if len(AllMenuItem().activate(None)) == 0:
            # no games, initiate game scan
            rescan_games()

    State.get().fade_start = get_current_time()
    State.get().fade_end = get_current_time() + 2.000

    # # make a timer so that update events are sent to modules at least once
    # # every second
    # pygame.time.set_timer(IDLE_EVENT, 1000)

    State.get().start_time = get_current_time()
コード例 #5
0
 def mouseMoveEvent(self, event):
     if self.first_motion_event:
         # Ignore initial motion event, so the cursor is not visible
         # at startup.
         self.first_motion_event = False
         return
     InputHandler.add_event(Event.create_mouse_event(
         event, (self.width(), self.height())))
     self.ensure_cursor_visible()
コード例 #6
0
 def mouseMoveEvent(self, event):
     if self.first_motion_event:
         # Ignore initial motion event, so the cursor is not visible
         # at startup.
         self.first_motion_event = False
         return
     InputHandler.add_event(
         Event.create_mouse_event(event, (self.width(), self.height())))
     self.ensure_cursor_visible()
コード例 #7
0
 def set_blank_cursor(self, blank=True):
     if blank:
         cursor = Qt.BlankCursor
     else:
         cursor = Qt.ArrowCursor
     self.setCursor(cursor)
     if self.gl_widget is not None:
         self.gl_widget.setCursor(cursor)
     if blank:
         # Fool app to think mouse has moved to neutral position,
         # in order to "de-focus" focused item.
         InputHandler.add_event(Event.create_fake_mouse_event(
             "mouse-motion", 960, 540, (self.width(), self.height())))
コード例 #8
0
 def set_blank_cursor(self, blank=True):
     if blank:
         cursor = Qt.BlankCursor
     else:
         cursor = Qt.ArrowCursor
     self.setCursor(cursor)
     if self.gl_widget is not None:
         self.gl_widget.setCursor(cursor)
     if blank:
         # Fool app to think mouse has moved to neutral position,
         # in order to "de-focus" focused item.
         InputHandler.add_event(
             Event.create_fake_mouse_event("mouse-motion", 960, 540,
                                           (self.width(), self.height())))
コード例 #9
0
    def update_state(self):
        if self.state == STATE_STARTING:
            self.gc_runner = GameCenterRunner(controller=self.controller)
            # prepare will unpack the game and prepare game files
            self.gc_runner.prepare()
            self.state = STATE_PREPARING
            self.throbber.throbber_start_time = 0

        elif self.state == STATE_PREPARING:
            if self.gc_runner.error:
                pass
            elif self.gc_runner.done:
                self.wait_run_time = State.get().time
                FadeDialog(self.wait_run_time).show()
                self.state = STATE_WAITRUN

        elif self.state == STATE_WAITRUN:
            if State.get().time - self.wait_run_time > FADE_TIME:
                set_ingame_status()
                self.gc_runner.run()
                self.state = STATE_RUNNING

        elif self.state == STATE_RUNNING:
            InputHandler.set_inhibited(True)
            if self.gc_runner.error:
                pass
            elif self.gc_runner.done:
                self.state = STATE_STOPPING

        elif self.state == STATE_STOPPING:
            InputHandler.set_inhibited(False)
            State.get().history.pop()
            State.get().history.pop()
            State.get().history.pop()
            set_current_menu(State.get().history[-1])
            back_to_menu_from_game()
            Dialog.get_current().close()

            from arcade.glui.window import main_window

            main_window.restore_window_if_necessary()

        elif self.state == STATE_ABORTING:
            pass
コード例 #10
0
ファイル: window.py プロジェクト: EdwardBetts/fs-uae-launcher
def default_input_func(button):
    if button == "LEFT":
        State.get().navigatable.go_left()
    elif button == "RIGHT":
        State.get().navigatable.go_right()
    elif button == "UP":
        State.get().navigatable.go_up()
    elif button == "DOWN":
        State.get().navigatable.go_down()
    elif button == "SKIP_LEFT":
        State.get().navigatable.go_left(10)
    elif button == "SKIP_RIGHT":
        State.get().navigatable.go_right(10)
    elif button == "PRIMARY":

        # global char_buffer
        # char_buffer = ""

        State.get().navigatable.activate()

    elif button == "BACK":
        print("-- button is BACK -- ")
        if State.get().config_menu:
            State.get().config_menu = None
            set_current_menu(State.get().current_menu)
            set_items_brightness(0.66, duration=0.500)
        elif State.get().current_game is None and current_menu.search_text:
            InputHandler.get_button()  # clear OK status
            character_press("BACKSPACE")
        elif State.get().current_game:
            State.get().current_game = None
            # game_fade_animation = AnimateValueBezier(
            #     (MenuGameTransition, "value"),
            #     1.0, State.get().time,
            #     1.0, State.get().time + 0.133,
            #     0.0, State.get().time + 0.133,
            #     0.0, State.get().time + 0.400)

        # elif can_navigate and current_menu.parent_menu:
        # elif can_navigate and len(State.get().history) > 1:
        elif len(State.get().history) > 1:
            go_back()
    elif button == "QUIT":
        State.get().quit = True
コード例 #11
0
    def update_state(self):
        if self.state == STATE_STARTING:
            self.gc_runner = GameCenterRunner(controller=self.controller)
            # prepare will unpack the game and prepare game files
            self.gc_runner.prepare()
            self.state = STATE_PREPARING
            self.throbber.throbber_start_time = 0

        elif self.state == STATE_PREPARING:
            if self.gc_runner.error:
                pass
            elif self.gc_runner.done:
                self.wait_run_time = State.get().time
                FadeDialog(self.wait_run_time).show()
                self.state = STATE_WAITRUN

        elif self.state == STATE_WAITRUN:
            if State.get().time - self.wait_run_time > FADE_TIME:
                set_ingame_status()
                self.gc_runner.run()
                self.state = STATE_RUNNING

        elif self.state == STATE_RUNNING:
            InputHandler.set_inhibited(True)
            if self.gc_runner.error:
                pass
            elif self.gc_runner.done:
                self.state = STATE_STOPPING

        elif self.state == STATE_STOPPING:
            InputHandler.set_inhibited(False)
            State.get().history.pop()
            State.get().history.pop()
            State.get().history.pop()
            set_current_menu(State.get().history[-1])
            back_to_menu_from_game()
            Dialog.get_current().close()

            from arcade.glui.window import main_window

            main_window.restore_window_if_necessary()

        elif self.state == STATE_ABORTING:
            pass
コード例 #12
0
    def __init__(self, item, controller):
        Menu.__init__(self)
        # self.top_menu_transition = 0.0
        self.items.append(item)
        if self.use_game_center_item():
            self.top.left.append(GameCenterItem())
        # self.top.left.append(HomeItem())
        # self.top.left.append(MenuItem(item.title))
        self.top.set_selected_index(
            len(self.top.left) + len(self.top.right) - 1
        )

        self.controller = controller
        assert isinstance(self.controller, GameDriver)
        self.first_shown_at = 0

        # controller must now initialize input ports
        # self.controller.init_input()

        # for input in self.controller.inputs:
        #     input["device_id"] = None

        # get all available input devices
        # self.devices, info = InputDevice.get_input_devices(
        #     "", 0, 100, version=2)

        device_manager = InputHandler.get_device_manager()
        # self.devices = DeviceManager.instance().get_devices()
        self.devices = device_manager.get_devices()

        self.device_list_version = InputDevices.device_list_version
        self.device_data = DeviceDataDict()
        # [{"index": 0} for x in self.devices]
        for device in self.devices:
            self.device_data[device.id] = {"port": 0, "device": device}
            self.check_device(self.device_data[device.id])
        # FIXME: Make InputHandler / InputDevice set variables
        # etc and self detect when to reinit?
        # InputHandler.reinit_joysticks()

        # calling activate to try to set the active input device
        # to the first input port, if possible
        # self.activate()
        self.set_defaults()
コード例 #13
0
    def __init__(self, item, controller):
        Menu.__init__(self)
        # self.top_menu_transition = 0.0
        self.items.append(item)
        if self.use_game_center_item():
            self.top.left.append(GameCenterItem())
        # self.top.left.append(HomeItem())
        # self.top.left.append(MenuItem(item.title))
        self.top.set_selected_index(
            len(self.top.left) + len(self.top.right) - 1
        )

        self.controller = controller
        assert isinstance(self.controller, GameDriver)
        self.first_shown_at = 0

        # controller must now initialize input ports
        # self.controller.init_input()

        # for input in self.controller.inputs:
        #     input["device_id"] = None

        # get all available input devices
        # self.devices, info = InputDevice.get_input_devices(
        #     "", 0, 100, version=2)

        device_manager = InputHandler.get_device_manager()
        # self.devices = DeviceManager.instance().get_devices()
        self.devices = device_manager.get_devices()

        self.device_list_version = InputDevices.device_list_version
        self.device_data = DeviceDataDict()
        # [{"index": 0} for x in self.devices]
        for device in self.devices:
            self.device_data[device.id] = {"port": 0, "device": device}
            self.check_device(self.device_data[device.id])
        # FIXME: Make InputHandler / InputDevice set variables
        # etc and self detect when to reinit?
        # InputHandler.reinit_joysticks()

        # calling activate to try to set the active input device
        # to the first input port, if possible
        # self.activate()
        self.set_defaults()
コード例 #14
0
 def active(self):
     """Check whether the user interface is active or not. If not active,
     we do not want to force regular/timed refresh event."""
     state = State.get()
     # print("state.game_running", state.game_running)
     if state.game_running:
         # print("inactive")
         return False
     # print(state.idle_from)
     # if state.idle_from and state.idle_from < get_current_time():
     # print(InputHandler.peek_button())
     if not InputHandler.peek_button():
         if not state.dirty:
             if not AnimationSystem.is_active():
                 self.idle_counter += 1
                 if self.idle_counter < 16:
                     # We render 1 frame per second when "idling". We need
                     # to "render" regularly, because some state is updated
                     # during the render phase.
                     return False
     self.idle_counter = 0
     return True
コード例 #15
0
 def active(self):
     """Check whether the user interface is active or not. If not active,
     we do not want to force regular/timed refresh event."""
     state = State.get()
     # print("state.game_running", state.game_running)
     if state.game_running:
         # print("inactive")
         return False
     # print(state.idle_from)
     # if state.idle_from and state.idle_from < get_current_time():
     # print(InputHandler.peek_button())
     if not InputHandler.peek_button():
         if not state.dirty:
             if not AnimationSystem.is_active():
                 self.idle_counter += 1
                 if self.idle_counter < 16:
                     # We render 1 frame per second when "idling". We need
                     # to "render" regularly, because some state is updated
                     # during the render phase.
                     return False
     self.idle_counter = 0
     return True
コード例 #16
0
 def timer(self):
     InputHandler.update()
コード例 #17
0
 def timer(self):
     InputHandler.update()
コード例 #18
0
ファイル: window.py プロジェクト: EdwardBetts/fs-uae-launcher
def main_loop_iteration(
        input_func=default_input_func, render_func=default_render_func):
    state = State.get()

    # if State.get().currently_ingame:
    #     print("currently ingame")
    #     #return False

    # print("main loop iteration")
    # time.sleep(0.1)
    # stop_loop = False

    # if State.get().idle_from and State.get().idle_from < get_current_time():
    #     #print(State.get().idle_from)
    #     if not Render.get().dirty:
    #         #print("waiting for events...")
    #         events = [pygame.event.wait()]
    #     else:
    #         events = pygame.event.get()
    # else:
    #     events = pygame.event.get()

    state.time = get_current_time()

    # Main.process()

    # t = State.get().time

    # if len(char_buffer) > 2 and t - char_buffer_last_updated > 0.5:
    # print(current_menu, isinstance(current_menu, ItemMenu))
    # if isinstance(current_menu, ItemMenu):
    #
    #    # if len(char_buffer) > 2 and t - char_buffer_last_updated > 0.5:
    #    if len(char_buffer) > 2:
    #        create_search_results_menu(char_buffer)
    #    if len(char_buffer) <= 2:
    #        # collapse search menu
    #
    #        if hasattr(current_menu, "search_text"):
    #            print("setting current_menu (something with search)")
    #            set_current_menu(current_menu.parent_menu)

    if state.hide_mouse_time and state.time > state.hide_mouse_time:
        if Mouse.focus:
            # keep cursor visible if mouse has focus
            pass
        else:
            state.hide_mouse_time = 0
            Mouse.set_visible(False)

    for event in InputHandler.pop_all_text_events():
        if event["type"] == "text":
            # if key was handled as a virtual button, only allow this
            # character if already started typing something, or else
            # navigating with X-Arcade may start searching for games
            if InputHandler.peek_button():
                if len(current_menu.search_text) > 0:
                    character_press(event["text"])
                    # reset InputHandler so that virtual button
                    # is not processed, since we handled this press
                    # as a char
                    InputHandler.get_button()
            else:
                character_press(event["text"])

    AnimationSystem.update()
    NotificationRender.update()

    # if idle_events_only:
    #     # do not update State.get().idle_from
    #     pass
    # elif len(events) > 0:
    #     #print(events)
    #     if IDLE:
    #         State.get().idle_from = State.get().time + IDLE
    #         #print(State.get().idle_from)

    if Render.get().dirty or ALWAYS_RENDER:
        if Render.get().non_dirty_state:
            print("must start rendering again...")
        Render.get().non_dirty_state = False
        render_func()
    else:
        # if not Render.get().non_dirty_state:
        #     print("pause rendering!")
        # Render.get().non_dirty_state = True
        Render.get().dirty = True

    button = InputHandler.get_button()
    if button:
        print("InputHandler.get_button", button, InputHandler.last_device)
        GameCenter.register_user_activity()
        if input_func:
            input_func(button)
        Render.get().dirty = True
    if InputHandler.repeat_info:
        Render.get().dirty = True

    # if IDLE:
    if AnimationSystem.is_active():
        # State.get().idle_from = None
        Render.get().dirty = True
        # elif State.get().idle_from is None:
        #     State.get().idle_from = State.get().time + IDLE
    if not IDLE:
        Render.get().dirty = True
    # except KeyboardInterrupt:
    #     print "KeyboardInterrupt"
    #     return
    # return stop_loop

    if not Render.get().display_sync:
        t = time.time()
        diff = t - Render.get().display_last_iteration
        # print(diff)
        frame_time = 1 / 60.0
        if diff < frame_time:
            # FIXME: use real refresh rate / frame time
            sleep_time = frame_time - diff
            time.sleep(sleep_time)
        Render.get().display_last_iteration = t

    return state.quit
コード例 #19
0
 def keyReleaseEvent(self, event):
     assert isinstance(event, QKeyEvent)
     # print(QKeyEvent, event.isAutoRepeat(), event.type())
     if event.isAutoRepeat():
         return
     InputHandler.add_event(Event.create_key_event(event))