Ticket #2143: 0001-looser-spiral-more-intermediate-sizes.patch

File 0001-looser-spiral-more-intermediate-sizes.patch, 7.1 KB (added by walter, 14 years ago)

looser spiral and more intermediate icon-size transitions

  • src/jarabe/desktop/favoriteslayout.py

    From efc1852f32138730520a190ab572285f67266320 Mon Sep 17 00:00:00 2001
    From: Walter Bender <walter@sugarlabs.org>
    Date: Mon, 9 Aug 2010 11:44:06 -0400
    Subject: [PATCH] looser spiral; more intermediate sizes
    
    ---
     src/jarabe/desktop/favoriteslayout.py |  112 +++++++++++++++++++++++++++------
     1 files changed, 93 insertions(+), 19 deletions(-)
    
    diff --git a/src/jarabe/desktop/favoriteslayout.py b/src/jarabe/desktop/favoriteslayout.py
    index 85e1b59..e560194 100644
    a b  
    11# Copyright (C) 2008 One Laptop Per Child
     2# Copyright (C) 2010 Sugar Labs
    23#
    34# This program is free software; you can redistribute it and/or modify
    45# it under the terms of the GNU General Public License as published by
    _logger = logging.getLogger('FavoritesLayout') 
    3233
    3334_CELL_SIZE = 4
    3435_BASE_SCALE = 1000
     36_INTERMEDIATE_B = (style.STANDARD_ICON_SIZE + style.SMALL_ICON_SIZE) / 2
     37_INTERMEDIATE_A = (style.STANDARD_ICON_SIZE + _INTERMEDIATE_B) / 2
     38_INTERMEDIATE_C = (_INTERMEDIATE_B + style.SMALL_ICON_SIZE) / 2
    3539
    3640class FavoritesLayout(gobject.GObject, hippo.CanvasLayout):
    3741    """Base class of the different layout types."""
    class RingLayout(FavoritesLayout): 
    201205    def __init__(self):
    202206        FavoritesLayout.__init__(self)
    203207        self._locked_children = {}
     208        self._spiral = False
     209        self._radius = _MINIMUM_RADIUS
     210        self._orientation = math.pi
     211        self._icon_size = style.MEDIUM_ICON_SIZE
     212        self._count = -1
     213        print style.MEDIUM_ICON_SIZE, style.STANDARD_ICON_SIZE, \
     214              _INTERMEDIATE_A, _INTERMEDIATE_B, _INTERMEDIATE_C, \
     215              style.SMALL_ICON_SIZE
    204216
    205217    def append(self, icon, locked=False):
    206218        FavoritesLayout.append(self, icon, locked)
    class RingLayout(FavoritesLayout): 
    221233            self._locked_children[child] = (x, y)
    222234
    223235    def _calculate_radius_and_icon_size(self, children_count):
    224         # what's the radius required without downscaling?
    225         distance = style.STANDARD_ICON_SIZE + style.DEFAULT_SPACING
    226         icon_size = style.STANDARD_ICON_SIZE
    227         # circumference is 2*pi*r; we want this to be at least
    228         # 'children_count * distance'
     236        """ Determine if we are drawing a ring with MEDIUM- or STANDARD-size
     237        icons or a spiral with STANDARD-, INTERMEDIATE-, or SMALL-size
     238        icons."""
     239        self._spiral = True
     240        distance = style.MEDIUM_ICON_SIZE + style.DEFAULT_SPACING
    229241        radius = children_count * distance / (2 * math.pi)
    230         # limit computed radius to reasonable bounds.
    231242        radius = max(radius, _MINIMUM_RADIUS)
    232         radius = min(radius, _MAXIMUM_RADIUS)
    233         # recompute icon size from limited radius
    234         if children_count > 0:
    235             icon_size = (2 * math.pi * radius / children_count) \
    236                         - style.DEFAULT_SPACING
    237         # limit adjusted icon size.
    238         icon_size = max(icon_size, style.SMALL_ICON_SIZE)
    239         icon_size = min(icon_size, style.MEDIUM_ICON_SIZE)
    240         return radius, icon_size
     243        if radius < _MAXIMUM_RADIUS:
     244            self._spiral = False
     245            self._icon_size = style.MEDIUM_ICON_SIZE
     246        if self._spiral:
     247            distance = style.STANDARD_ICON_SIZE + style.DEFAULT_SPACING
     248            radius = children_count * distance / (2 * math.pi)
     249            radius = max(radius, _MINIMUM_RADIUS)
     250            if radius < _MAXIMUM_RADIUS:
     251                self._spiral = False
     252                self._icon_size = style.STANDARD_ICON_SIZE
     253            else:
     254                self._spiral = True
     255                radius = _MAXIMUM_RADIUS
     256
     257        # If there are fewer children, try increasing icon_size.
     258        if self._count > children_count:
     259            if self._icon_size == style.SMALL_ICON_SIZE:
     260                self._icon_size = _INTERMEDIATE_C
     261            elif self._icon_size == _INTERMEDIATE_C:
     262                self._icon_size = _INTERMEDIATE_B
     263            elif self._icon_size == _INTERMEDIATE_B:
     264                self._icon_size = _INTERMEDIATE_A
     265            elif self._icon_size == _INTERMEDIATE_A:
     266                self._icon_size = style.STANDARD_ICON_SIZE
     267            elif self._icon_size == style.STANDARD_ICON_SIZE:
     268                self._icon_size = style.MEDIUM_ICON_SIZE
     269        self._count = children_count
     270
     271        # If the radius exceeds the minimun, try decreasing icon_size.
     272        if self._radius < _MINIMUM_RADIUS:
     273            if self._icon_size == style.MEDIUM_ICON_SIZE:
     274                self._icon_size = style.STANDARD_ICON_SIZE
     275            elif self._icon_size == style.STANDARD_ICON_SIZE:
     276                self._icon_size = _INTERMEDIATE_A
     277            elif self._icon_size == _INTERMEDIATE_A:
     278                self._icon_size = _INTERMEDIATE_B
     279            elif self._icon_size == _INTERMEDIATE_B:
     280                self._icon_size = _INTERMEDIATE_C
     281            elif self._icon_size == _INTERMEDIATE_C:
     282                self._icon_size = style.SMALL_ICON_SIZE
     283            print ">>>>>>>>>>>>>> setting icon sixe to %d" % (self._icon_size)
     284
     285        return radius, self._icon_size
     286
     287    def _calculate_xy(self, icon_size, width, height):
     288        """ Convert r, o to x, y """
     289        x = -math.sin(self._orientation) * self._radius
     290        y = math.cos(self._orientation) * self._radius
     291        self._calculate_new_radius_orientation(icon_size +\
     292                                                   style.DEFAULT_SPACING)
     293
     294        x = int(x) + (width - icon_size) / 2
     295        y = int(y) + (height - icon_size - (style.GRID_CELL_SIZE / 2) ) / 2
     296        return x, y
     297
     298    def _calculate_new_radius_orientation(self, icon_size):
     299        """ Based upon current radius, calculate new increments """
     300        circumference = self._radius * 2 * math.pi
     301        n = circumference / icon_size
     302        self._orientation += 2 * math.pi / n
     303        self._radius -= float(icon_size + style.DEFAULT_SPACING) / n
    241304
    242305    def _calculate_position(self, radius, icon_size, index, children_count,
    243306                            sin=math.sin, cos=math.cos):
     307        """ Try fitting a circle or a spiral """
     308
    244309        width, height = self.box.get_allocation()
    245         angle = index * (2 * math.pi / children_count) - math.pi / 2
    246         x = radius * cos(angle) + (width - icon_size) / 2
    247         y = radius * sin(angle) + (height - icon_size -
    248                                    (style.GRID_CELL_SIZE/2) ) / 2
     310        if not self._spiral:
     311            angle = index * (2 * math.pi / children_count) - math.pi / 2
     312            x = radius * cos(angle) + (width - icon_size) / 2
     313            y = radius * sin(angle) + (height - icon_size -
     314                                       (style.GRID_CELL_SIZE/2) ) / 2
     315        else:
     316            min_width_, box_width = self.box.get_width_request()
     317            min_height_, box_height = self.box.get_height_request(box_width)
     318            if index == 0:
     319                self._radius = _MAXIMUM_RADIUS
     320                self._orientation = math.pi
     321            x, y = self._calculate_xy(icon_size, width, height)
     322               
    249323        return x, y
    250324
    251325    def _get_children_in_ring(self):