Ticket #2143: 0001-added-MEDIUM_ICON_SIZE-to-Ring.patch

File 0001-added-MEDIUM_ICON_SIZE-to-Ring.patch, 6.2 KB (added by walter, 14 years ago)

adds MEDIUM_ICON_SIZE to Ring

  • src/jarabe/desktop/favoriteslayout.py

    From 2a8111a1c3a84d4ccb688384bee2d18053277e74 Mon Sep 17 00:00:00 2001
    From: Walter Bender <walter@sugarlabs.org>
    Date: Mon, 9 Aug 2010 02:46:32 -0400
    Subject: [PATCH] added MEDIUM_ICON_SIZE to Ring
    
    ---
     src/jarabe/desktop/favoriteslayout.py |   96 ++++++++++++++++++++++++++-------
     1 files changed, 77 insertions(+), 19 deletions(-)
    
    diff --git a/src/jarabe/desktop/favoriteslayout.py b/src/jarabe/desktop/favoriteslayout.py
    index 85e1b59..195d140 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 = (style.STANDARD_ICON_SIZE + style.SMALL_ICON_SIZE) / 2
    3537
    3638class FavoritesLayout(gobject.GObject, hippo.CanvasLayout):
    3739    """Base class of the different layout types."""
    class RingLayout(FavoritesLayout): 
    201203    def __init__(self):
    202204        FavoritesLayout.__init__(self)
    203205        self._locked_children = {}
     206        self._spiral = False
     207        self._radius = _MINIMUM_RADIUS
     208        self._orientation = math.pi
     209        self._icon_size = style.MEDIUM_ICON_SIZE
     210        self._count = -1
    204211
    205212    def append(self, icon, locked=False):
    206213        FavoritesLayout.append(self, icon, locked)
    class RingLayout(FavoritesLayout): 
    221228            self._locked_children[child] = (x, y)
    222229
    223230    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'
     231        """ Determine if we are drawing a ring with MEDIUM- or STANDARD-size
     232        icons or a spiral with STANDARD-, INTERMEDIATE-, or SMALL-size
     233        icons."""
     234        self._spiral = True
     235        distance = style.MEDIUM_ICON_SIZE + style.DEFAULT_SPACING
    229236        radius = children_count * distance / (2 * math.pi)
    230         # limit computed radius to reasonable bounds.
    231237        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
     238        if radius < _MAXIMUM_RADIUS:
     239            self._spiral = False
     240            self._icon_size = style.MEDIUM_ICON_SIZE
     241        if self._spiral:
     242            distance = style.STANDARD_ICON_SIZE + style.DEFAULT_SPACING
     243            radius = children_count * distance / (2 * math.pi)
     244            radius = max(radius, _MINIMUM_RADIUS)
     245            if radius < _MAXIMUM_RADIUS:
     246                self._spiral = False
     247                self._icon_size = style.STANDARD_ICON_SIZE
     248            else:
     249                self._spiral = True
     250                radius = _MAXIMUM_RADIUS
     251
     252        # If there are fewer children, try increasing icon_size.
     253        if self._count > children_count:
     254            if self._icon_size == style.SMALL_ICON_SIZE:
     255                self._icon_size = _INTERMEDIATE
     256            elif self._icon_size == _INTERMEDIATE:
     257                self._icon_size = style.STANDARD_ICON_SIZE
     258            elif self._icon_size == style.STANDARD_ICON_SIZE:
     259                self._icon_size = style.MEDIUM_ICON_SIZE
     260        self._count = children_count
     261
     262        # If the radius exceeds the minimun, try decreasing icon_size.
     263        if self._radius < _MINIMUM_RADIUS:
     264            if self._icon_size == style.STANDARD_ICON_SIZE:
     265                self._icon_size = _INTERMEDIATE
     266            elif self._icon_size == _INTERMEDIATE:
     267                self._icon_size = style.SMALL_ICON_SIZE
     268
     269        return radius, self._icon_size
     270
     271    def _calculate_xy(self, icon_size, width, height):
     272        """ Convert r, o to x, y """
     273        x = -math.sin(self._orientation) * self._radius
     274        y = math.cos(self._orientation) * self._radius
     275        self._calculate_new_radius_orientation(icon_size +\
     276                                                   style.DEFAULT_SPACING)
     277
     278        x = int(x) + (width - icon_size) / 2
     279        y = int(y) + (height - icon_size - (style.GRID_CELL_SIZE / 2) ) / 2
     280        return x, y
     281
     282    def _calculate_new_radius_orientation(self, icon_size):
     283        """ Based upon current radius, calculate new increments """
     284        circumference = self._radius * 2 * math.pi
     285        n = circumference / icon_size
     286        self._orientation += 2 * math.pi / n
     287        self._radius -= float(icon_size) / n
    241288
    242289    def _calculate_position(self, radius, icon_size, index, children_count,
    243290                            sin=math.sin, cos=math.cos):
     291        """ Try fitting a circle or a spiral """
     292
    244293        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
     294        if not self._spiral:
     295            angle = index * (2 * math.pi / children_count) - math.pi / 2
     296            x = radius * cos(angle) + (width - icon_size) / 2
     297            y = radius * sin(angle) + (height - icon_size -
     298                                       (style.GRID_CELL_SIZE/2) ) / 2
     299        else:
     300            min_width_, box_width = self.box.get_width_request()
     301            min_height_, box_height = self.box.get_height_request(box_width)
     302            if index == 0:
     303                self._radius = _MAXIMUM_RADIUS
     304                self._orientation = math.pi
     305            x, y = self._calculate_xy(icon_size, width, height)
     306               
    249307        return x, y
    250308
    251309    def _get_children_in_ring(self):