Esempio n. 1
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
Esempio n. 2
0
    def test_has_moved_returns_true_when_moved(self):
        # Given
        mouse = Mouse()
        mouse.feed_pos(Vec2D(33, 44))

        # When
        mouse.update()
        mouse.feed_pos(Vec2D(55, 44))

        # Then
        assert mouse.has_moved()
Esempio n. 3
0
    def test_mouse_move_over_should_activate_component(self):
        # Given
        gui_state = gui.GuiState()
        userinput = UserInput()
        userinput.mouse.feed_pos(Vec2D(50, 150))

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

        assert gui_state.get_active() <> component

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

        # Then
        assert gui_state.get_active() == component
Esempio n. 4
0
    def test_only_one_selected(self):
        # Given
        rb = gui.Radiobuttons()
        rb.append(gui.Checkbox(Rectangle(100, 100, 50, 50), False))
        rb.append(gui.Checkbox(Rectangle(100, 200, 50, 50), False))
        rb.append(gui.Checkbox(Rectangle(100, 300, 50, 50), False))
        userinput = UserInput()
        guistate = gui.GuiState()

        # When select checkbox 0
        userinput.mouse.feed_pos(Vec2D(110, 110))
        userinput.mouse.feed_down(Mouse.LEFT)
        rb.tick(userinput, guistate)

        # Then
        assert rb[0].is_selected()
        assert not rb[1].is_selected()
        assert not rb[2].is_selected()
        assert rb.get_selected() is rb[0]
        assert rb.get_selected_index() == 0

        # And when select checkbox 2
        userinput.mouse.feed_pos(Vec2D(110, 310))
        userinput.mouse.feed_down(Mouse.LEFT)
        rb.tick(userinput, guistate)

        # Then
        assert not rb[0].is_selected()
        assert not rb[1].is_selected()
        assert rb[2].is_selected()
        assert rb.get_selected() is rb[2]
        assert rb.get_selected_index() == 2

        # And when select checkbox 1
        userinput.mouse.feed_pos(Vec2D(110, 210))
        userinput.mouse.feed_down(Mouse.LEFT)
        rb.tick(userinput, guistate)

        # Then
        assert not rb[0].is_selected()
        assert rb[1].is_selected()
        assert not rb[2].is_selected()
        assert rb.get_selected() is rb[1]
        assert rb.get_selected_index() == 1
Esempio n. 5
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
Esempio n. 6
0
    def test_not_clicked_when_mousepress_outside(self):
        """Given a button
            when mouse clicks outside
            then button shouldn't return clicked state"""
        # Given
        button = gui.Button(Rectangle(100, 100, 50, 50))
        userinput = UserInput()
        guistate = gui.GuiState()
        assert not button.went_down()

        # When
        userinput.mouse.feed_pos(Vec2D(110, 90))
        userinput.mouse.feed_down(Mouse.LEFT)
        button.tick(userinput, guistate)

        # Then
        assert not button.went_down()
Esempio n. 7
0
    def test_clicked_when_mousepress_inside(self):
        # Given
        checkbox = gui.Checkbox(Rectangle(100, 100, 50, 50), False)
        userinput = UserInput()
        guistate = gui.GuiState()
        assert not checkbox.is_selected()

        # When
        userinput.mouse.feed_pos(Vec2D(110, 110))
        userinput.mouse.feed_down(Mouse.LEFT)
        checkbox.tick(userinput, guistate)

        # Then
        assert checkbox.went_down()
        assert checkbox.is_selected()

        # And when
        checkbox.tick(userinput, guistate)

        # Then
        assert not checkbox.is_selected()
Esempio n. 8
0
    def test_pos(self):
        mouse = Mouse()

        mouse.feed_pos(Vec2D(123, 321))
        assert mouse.pos == Vec2D(123, 321)