Пример #1
0
    def test_get_interactive_components_should_return_all_and_no_more(self):
        """Given a hierarchy of components
        when asked for all interactive components
        then all and no more are returned"""
        # Given
        root = gui.Component()
        child1 = gui.Component()
        child2 = gui.InteractiveComponent(Rectangle(0, 0, 0, 0))
        child11 = gui.Component()
        child12 = gui.InteractiveComponent(Rectangle(0, 0, 0, 0))
        child21 = gui.InteractiveComponent(Rectangle(0, 0, 0, 0))
        child22 = gui.Component()
        child222 = gui.InteractiveComponent(Rectangle(0, 0, 0, 0))

        root.add_subcomponent(child1)
        root.add_subcomponent(child2)
        child1.add_subcomponent(child11)
        child1.add_subcomponent(child12)
        child2.add_subcomponent(child21)
        child2.add_subcomponent(child22)
        child22.add_subcomponent(child222)

        # When
        interactives = gui.GuiState._get_interactive_components(root)

        # Then
        assert len(interactives) == 4
        assert root not in interactives
        assert child1 not in interactives
        assert child2 in interactives
        assert child11 not in interactives
        assert child12 in interactives
        assert child21 in interactives
        assert child22 not in interactives
        assert child222 in interactives
Пример #2
0
    def test_mouse_move_over_shouldnt_activate_nonhard_component(self):
        # Given
        gui_state = gui.GuiState()
        userinput = UserInput()
        userinput.mouse.feed_pos(Vec2D(50, 150))

        component = gui.InteractiveComponent(Rectangle(100, 100, 100, 100))

        hardcomp = gui.InteractiveComponent(Rectangle(100, 300, 100, 100))
        hardcomp.lock_input(True)

        base = gui.Component()
        base.add_subcomponent(component)
        base.add_subcomponent(hardcomp)

        gui_state.set_active(hardcomp)

        assert gui_state.get_active() <> component
        assert gui_state.get_active() == hardcomp

        # When
        userinput.update()
        userinput.mouse.feed_pos(Vec2D(150, 150))
        gui_state.update(userinput, base)

        # Then
        assert gui_state.get_active() <> component
        assert gui_state.get_active() == hardcomp
Пример #3
0
    def test_mouse_still_over_shouldnt_activate_component(self):
        # Given
        gui_state = gui.GuiState()
        userinput = UserInput()
        userinput.mouse.feed_pos(Vec2D(150, 150))

        component1 = gui.InteractiveComponent(Rectangle(100, 100, 100, 100))
        component = gui.InteractiveComponent(Rectangle(100, 100, 100, 100))

        base = gui.Component()
        base.add_subcomponent(component1)
        base.add_subcomponent(component)

        assert gui_state.get_active() <> component

        # When
        userinput.update()
        userinput.mouse.feed_pos(Vec2D(150, 150))
        gui_state.update(userinput, base)

        # Then
        assert gui_state.get_active() <> component
Пример #4
0
 def test_subs(self):
     comp = gui.Component()