Ticket #2143: 0001-spiral-from-outside-to-inside-with-max-MINIMUM-fix.patch
File 0001-spiral-from-outside-to-inside-with-max-MINIMUM-fix.patch, 5.4 KB (added by walter, 14 years ago) |
---|
-
src/jarabe/desktop/favoriteslayout.py
From e5f88f4af504570aeca62a3cac1e487b696ec78f Mon Sep 17 00:00:00 2001 From: Walter Bender <walter@sugarlabs.org> Date: Sun, 8 Aug 2010 13:23:35 -0400 Subject: [PATCH] spiral from outside to inside with max MINIMUM fix --- src/jarabe/desktop/favoriteslayout.py | 82 +++++++++++++++++++++++++------- 1 files changed, 64 insertions(+), 18 deletions(-) diff --git a/src/jarabe/desktop/favoriteslayout.py b/src/jarabe/desktop/favoriteslayout.py index 85e1b59..6c4bfcd 100644
a b 1 1 # Copyright (C) 2008 One Laptop Per Child 2 # Copyright (C) 2010 Sugar Labs 2 3 # 3 4 # This program is free software; you can redistribute it and/or modify 4 5 # it under the terms of the GNU General Public License as published by … … _logger = logging.getLogger('FavoritesLayout') 32 33 33 34 _CELL_SIZE = 4 34 35 _BASE_SCALE = 1000 36 _INTERMEDIATE = (style.STANDARD_ICON_SIZE + style.SMALL_ICON_SIZE) / 2 35 37 36 38 class FavoritesLayout(gobject.GObject, hippo.CanvasLayout): 37 39 """Base class of the different layout types.""" … … class RingLayout(FavoritesLayout): 201 203 def __init__(self): 202 204 FavoritesLayout.__init__(self) 203 205 self._locked_children = {} 206 self._spiral = False 207 self._radius = _MINIMUM_RADIUS 208 self._orientation = math.pi 209 self._icon_size = style.STANDARD_ICON_SIZE 210 self._count = -1 204 211 205 212 def append(self, icon, locked=False): 206 213 FavoritesLayout.append(self, icon, locked) … … class RingLayout(FavoritesLayout): 221 228 self._locked_children[child] = (x, y) 222 229 223 230 def _calculate_radius_and_icon_size(self, children_count): 224 # what's the radius required without downscaling?231 """ determine if we are drawing a circle or a spiral """ 225 232 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' 233 229 234 radius = children_count * distance / (2 * math.pi) 230 # limit computed radius to reasonable bounds.231 235 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 236 if radius < _MAXIMUM_RADIUS: 237 self._spiral = False 238 self._icon_size = style.STANDARD_ICON_SIZE 239 else: 240 self._spiral = True 241 radius = _MAXIMUM_RADIUS 242 243 # If there are fewer children, try increasing icon_size. 244 if self._count > children_count: 245 if self._icon_size == style.SMALL_ICON_SIZE: 246 self._icon_size = _INTERMEDIATE 247 elif self._icon_size == _INTERMEDIATE: 248 self._icon_size = style.STANDARD_ICON_SIZE 249 self._count = children_count 250 251 if self._radius < _MINIMUM_RADIUS: 252 if self._icon_size == style.STANDARD_ICON_SIZE: 253 self._icon_size = _INTERMEDIATE 254 elif self._icon_size == _INTERMEDIATE: 255 self._icon_size = style.SMALL_ICON_SIZE 256 257 return radius, self._icon_size 258 259 def _calculate_xy(self, icon_size, width, height): 260 """ Convert r, o to x, y """ 261 x = -math.sin(self._orientation) * self._radius 262 y = math.cos(self._orientation) * self._radius 263 self._calculate_new_radius_orientation(icon_size +\ 264 style.DEFAULT_SPACING) 265 266 x = int(x) + (width - icon_size) / 2 267 y = int(y) + (height - icon_size - (style.GRID_CELL_SIZE / 2) ) / 2 268 return x, y 269 270 def _calculate_new_radius_orientation(self, icon_size): 271 """ Based upon current radius, calculate new increments """ 272 circumference = self._radius * 2 * math.pi 273 n = circumference / icon_size 274 self._orientation += 2 * math.pi / n 275 self._radius -= float(icon_size) / n 241 276 242 277 def _calculate_position(self, radius, icon_size, index, children_count, 243 278 sin=math.sin, cos=math.cos): 279 """ Try fitting a circle or a spiral """ 280 244 281 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 282 if not self._spiral: 283 angle = index * (2 * math.pi / children_count) - math.pi / 2 284 x = radius * cos(angle) + (width - icon_size) / 2 285 y = radius * sin(angle) + (height - icon_size - 286 (style.GRID_CELL_SIZE/2) ) / 2 287 else: 288 min_width_, box_width = self.box.get_width_request() 289 min_height_, box_height = self.box.get_height_request(box_width) 290 if index == 0: 291 self._radius = _MAXIMUM_RADIUS 292 self._orientation = math.pi 293 x, y = self._calculate_xy(icon_size, width, height) 294 249 295 return x, y 250 296 251 297 def _get_children_in_ring(self):