示例#1
0
 def test_full_rebuild_on_size_change_large_shadow(
         self, _init_pygame, default_ui_manager: UIManager):
     shape = RectDrawableShape(containing_rect=pygame.Rect(0, 0, 2, 2),
                               theming_parameters={
                                   'text':
                                   'test',
                                   'font':
                                   default_ui_manager.get_theme().get_font(
                                       object_ids=[], element_ids=[]),
                                   'shadow_width':
                                   1,
                                   'border_width':
                                   0,
                                   'normal_border':
                                   pygame.Color('#FFFFFF'),
                                   'normal_bg':
                                   pygame.Color('#000000'),
                                   'text_horiz_alignment':
                                   'center',
                                   'text_vert_alignment':
                                   'center'
                               },
                               states=['normal'],
                               manager=default_ui_manager)
     shape.full_rebuild_on_size_change()
 def test_creation_with_gradients(self, _init_pygame,
                                  default_ui_manager: UIManager):
     EllipseDrawableShape(containing_rect=pygame.Rect(0, 0, 100, 100),
                          theming_parameters={
                              'text':
                              'test',
                              'font':
                              default_ui_manager.get_theme().get_font(
                                  object_ids=[], element_ids=[]),
                              'shadow_width':
                              2,
                              'border_width':
                              2,
                              'normal_border':
                              ColourGradient(0, pygame.Color('#000000'),
                                             pygame.Color('#FFFFFF')),
                              'normal_bg':
                              ColourGradient(0, pygame.Color('#000000'),
                                             pygame.Color('#FFFFFF')),
                              'shape_corner_radius':
                              2,
                              'text_horiz_alignment':
                              'center',
                              'text_vert_alignment':
                              'center'
                          },
                          states=['normal'],
                          manager=default_ui_manager)
示例#3
0
    def test_set_dimensions(self, _init_pygame, default_ui_manager: UIManager):
        shape = RectDrawableShape(containing_rect=pygame.Rect(0, 0, 100, 100),
                                  theming_parameters={
                                      'text':
                                      'test',
                                      'font':
                                      default_ui_manager.get_theme().get_font(
                                          object_ids=[], element_ids=[]),
                                      'shadow_width':
                                      0,
                                      'border_width':
                                      0,
                                      'normal_border':
                                      pygame.Color('#FFFFFF'),
                                      'normal_bg':
                                      pygame.Color('#000000'),
                                      'text_horiz_alignment':
                                      'center',
                                      'text_vert_alignment':
                                      'center'
                                  },
                                  states=['normal'],
                                  manager=default_ui_manager)

        shape.set_dimensions((50, 50))
        assert shape.containing_rect.width == 50
 def test_creation_with_filled_bar_no_gradients_at_all(
         self, _init_pygame, default_ui_manager: UIManager):
     RoundedRectangleShape(containing_rect=pygame.Rect(0, 0, 100, 100),
                           theming_parameters={
                               'text':
                               'test',
                               'font':
                               default_ui_manager.get_theme().get_font(
                                   object_ids=[], element_ids=[]),
                               'shadow_width':
                               2,
                               'border_width':
                               1,
                               'normal_border':
                               pygame.Color('#FFFFFF'),
                               'normal_bg':
                               pygame.Color('#FFFFFF'),
                               'filled_bar':
                               pygame.Color('#000000'),
                               'filled_bar_width':
                               50,
                               'shape_corner_radius':
                               2,
                               'text_horiz_alignment':
                               'center',
                               'text_vert_alignment':
                               'center'
                           },
                           states=['normal'],
                           manager=default_ui_manager)
示例#5
0
 def test_get_theme(self, _init_pygame, default_ui_manager,
                    _display_surface_return_none):
     """
     Can we get the theme? Serves as a test of the theme being successfully created.
     """
     theme = default_ui_manager.get_theme()
     assert (type(theme) == UIAppearanceTheme)
示例#6
0
    def test_compute_aligned_text_rect(self, _init_pygame, default_ui_manager: UIManager):
        shape = DrawableShape(containing_rect=pygame.Rect(0, 0, 100, 100),
                              theming_parameters={'text': 'doop doop',
                                                  'font': default_ui_manager.get_theme().get_font([]),
                                                  'shadow_width': 0,
                                                  'border_width': 0},
                              states=['normal', 'hovered'], manager=default_ui_manager)

        shape.theming['text_horiz_alignment'] = 'left'
        shape.theming['text_vert_alignment'] = 'top'
        shape.theming['text_horiz_alignment_padding'] = 5
        shape.theming['text_vert_alignment_padding'] = 5
        shape.compute_aligned_text_rect()
        assert shape.aligned_text_rect.x == 5
        assert shape.aligned_text_rect.y == 5

        shape.theming['text_horiz_alignment'] = 'center'
        shape.theming['text_vert_alignment'] = 'center'
        shape.theming['text_horiz_alignment_padding'] = 5
        shape.theming['text_vert_alignment_padding'] = 5
        shape.compute_aligned_text_rect()
        assert shape.aligned_text_rect.x == 14
        assert shape.aligned_text_rect.y == 41

        shape.theming['text_horiz_alignment'] = 'right'
        shape.theming['text_vert_alignment'] = 'bottom'
        shape.theming['text_horiz_alignment_padding'] = 5
        shape.theming['text_vert_alignment_padding'] = 5
        shape.compute_aligned_text_rect()
        assert shape.aligned_text_rect.right == 95
        assert shape.aligned_text_rect.bottom == 95
    def test_compute_aligned_text_rect_bottom_right(
            self, _init_pygame, default_ui_manager: UIManager):
        shape = DrawableShape(containing_rect=pygame.Rect(0, 0, 100, 100),
                              theming_parameters={
                                  'text':
                                  'test',
                                  'font':
                                  default_ui_manager.get_theme().get_font(
                                      object_ids=[], element_ids=[]),
                                  'shadow_width':
                                  0,
                                  'border_width':
                                  0,
                                  'text_horiz_alignment':
                                  'right',
                                  'text_vert_alignment':
                                  'bottom',
                                  'text_horiz_alignment_padding':
                                  0,
                                  'text_vert_alignment_padding':
                                  0
                              },
                              states=['normal'],
                              manager=default_ui_manager)

        shape.compute_aligned_text_rect()
 def test_creation(self, _init_pygame, default_ui_manager: UIManager):
     EllipseDrawableShape(containing_rect=pygame.Rect(0, 0, 100, 100),
                          theming_parameters={'text': 'test',
                                              'font': default_ui_manager.get_theme().get_font([]),
                                              'shadow_width': 0,
                                              'border_width': 0,
                                              'normal_border': pygame.Color('#FFFFFF'),
                                              'normal_bg': pygame.Color('#000000'),
                                              'text_horiz_alignment': 'center',
                                              'text_vert_alignment': 'center'},
                          states=['normal'], manager=default_ui_manager)
示例#9
0
    def test_rebuild_images_and_text(self, _init_pygame, default_ui_manager: UIManager):
        shape = DrawableShape(containing_rect=pygame.Rect(0, 0, 100, 100),
                              theming_parameters={'text': 'doop doop',
                                                  'font': default_ui_manager.get_theme().get_font([]),
                                                  'shadow_width': 0,
                                                  'border_width': 0,
                                                  'normal_image': pygame.image.load('tests/data/images/splat.png'),
                                                  'text_shadow': pygame.Color(0,0,0,255)},
                              states=['normal'], manager=default_ui_manager)

        shape.theming['text_horiz_alignment'] = 'left'
        shape.theming['text_vert_alignment'] = 'top'
        shape.theming['text_horiz_alignment_padding'] = 5
        shape.theming['text_vert_alignment_padding'] = 5

        shape.compute_aligned_text_rect()
        shape.rebuild_images_and_text('normal_image', 'normal', 'normal_text')
示例#10
0
    def test_update(self, _init_pygame, default_ui_manager: UIManager):
        """
        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
示例#11
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