Ejemplo n.º 1
0
    def test_check_hover(self, _init_pygame, default_ui_manager: UIManager,
                         _display_surface_return_none: None):
        window = UIWindow(pygame.Rect(100, 100, 200, 200),
                          window_display_title="Test Window",
                          manager=default_ui_manager,
                          resizable=True)

        default_ui_manager.mouse_position = (window.rect.left +
                                             window.shadow_width,
                                             window.rect.centery)
        window.resizing_mode_active = False
        window.check_hover(0.05, False)
        assert window.edge_hovering[0]

        default_ui_manager.mouse_position = (window.rect.right -
                                             window.shadow_width,
                                             window.rect.centery)
        window.resizing_mode_active = False
        window.check_hover(0.05, False)
        assert window.edge_hovering[2]

        default_ui_manager.mouse_position = (window.rect.centerx,
                                             window.rect.top +
                                             window.shadow_width)
        window.resizing_mode_active = False
        window.check_hover(0.05, False)
        assert window.edge_hovering[1]

        default_ui_manager.mouse_position = (window.rect.centerx,
                                             window.rect.bottom -
                                             window.shadow_width)
        window.resizing_mode_active = False
        window.check_hover(0.05, False)
        assert window.edge_hovering[3]

        default_ui_manager.mouse_position = (800, 800)
        window.resizing_mode_active = True
        assert window.check_hover(0.05, False)
        window.resizing_mode_active = False

        window.is_blocking = True
        assert window.check_hover(0.05, False)
        window.is_blocking = False

        assert not window.check_hover(0.05, False)
Ejemplo n.º 2
0
    def test_update(self, _init_pygame, default_ui_manager: UIManager,
                    _display_surface_return_none):
        """
        Test update does store button shapes in the long term cache
        """
        button = UIButton(relative_rect=pygame.Rect(100, 100, 150, 30), text="Test", manager=default_ui_manager)
        default_ui_manager.theme_update_acc = 5.0
        default_ui_manager.get_theme()._theme_file_last_modified = None
        starting_long_term_cache_size = len(default_ui_manager.ui_theme.shape_cache.cache_long_term_lookup)
        default_ui_manager.update(0.01)
        long_term_cache_size_after_update = len(default_ui_manager.ui_theme.shape_cache.cache_long_term_lookup)

        button.hovered = True
        button.select()
        default_ui_manager.update(0.01)

        assert long_term_cache_size_after_update > starting_long_term_cache_size

        window = UIWindow(pygame.Rect(100, 100, 200, 200), window_display_title="Test Window",
                          manager=default_ui_manager, element_id='test_window',
                          resizable=True)

        default_ui_manager.mouse_position = (window.rect.left + window.shadow_width,
                                             window.rect.top + window.shadow_width)
        window.resizing_mode_active = False
        window.check_hover(0.05, False)
        assert window.edge_hovering[0]
        assert window.edge_hovering[1]
        window.resizing_mode_active = True
        window.start_resize_rect = pygame.Rect(100, 100, 200, 200)

        default_ui_manager.update(0.05)
        assert default_ui_manager._active_cursor == default_ui_manager.resizing_window_cursors['xy']

        default_ui_manager.mouse_position = (window.rect.right - window.shadow_width,
                                             window.rect.top + window.shadow_width)
        window.resizing_mode_active = False
        window.check_hover(0.05, False)
        assert window.edge_hovering[2]
        assert window.edge_hovering[1]
        window.resizing_mode_active = True
        window.start_resize_rect = pygame.Rect(100, 100, 200, 200)

        default_ui_manager.update(0.05)
        assert default_ui_manager._active_cursor == default_ui_manager.resizing_window_cursors['yx']

        default_ui_manager.mouse_position = (window.rect.left + window.shadow_width,
                                             window.rect.centery)
        window.resizing_mode_active = False
        window.check_hover(0.05, False)
        assert window.edge_hovering[0]
        window.resizing_mode_active = True
        window.start_resize_rect = pygame.Rect(100, 100, 200, 200)

        default_ui_manager.update(0.05)
        assert default_ui_manager._active_cursor == default_ui_manager.resizing_window_cursors['xl']

        default_ui_manager.mouse_position = (window.rect.right - window.shadow_width,
                                             window.rect.centery)
        window.resizing_mode_active = False
        window.check_hover(0.05, False)
        assert window.edge_hovering[2]
        window.resizing_mode_active = True
        window.start_resize_rect = pygame.Rect(100, 100, 200, 200)

        default_ui_manager.update(0.05)
        assert default_ui_manager._active_cursor == default_ui_manager.resizing_window_cursors['xr']

        default_ui_manager.mouse_position = (window.rect.centerx,
                                             window.rect.top + window.shadow_width)
        window.resizing_mode_active = False
        window.check_hover(0.05, False)
        assert window.edge_hovering[1]
        window.resizing_mode_active = True
        window.start_resize_rect = pygame.Rect(100, 100, 200, 200)

        default_ui_manager.update(0.05)
        assert default_ui_manager._active_cursor == default_ui_manager.resizing_window_cursors['yt']

        default_ui_manager.mouse_position = (window.rect.centerx,
                                             window.rect.bottom - window.shadow_width)
        window.resizing_mode_active = False
        window.check_hover(0.05, False)
        assert window.edge_hovering[3]
        window.resizing_mode_active = True
        window.start_resize_rect = pygame.Rect(100, 100, 200, 200)

        default_ui_manager.update(0.05)
        assert default_ui_manager._active_cursor == default_ui_manager.resizing_window_cursors['yb']

        window.resizing_mode_active = False
        window.check_hover(0.05, False)

        default_ui_manager.update(0.05)
        assert default_ui_manager._active_cursor == default_ui_manager.active_user_cursor