changeset 51:525fb0abcb4d

Renamed enso.ui.graphics to enso.graphics.rounded_rect.
author Atul Varma <varmaa@toolness.com>
date Mon, 25 Feb 2008 19:06:26 -0600
parents 51181fe08fea
children e17afea9bc07
files enso/graphics/rounded_rect.py enso/ui/graphics.py enso/ui/messages/miniwindows.py enso/ui/messages/primarywindow.py enso/ui/quasimode/linewindows.py
diffstat 5 files changed, 126 insertions(+), 136 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/enso/graphics/rounded_rect.py	Mon Feb 25 19:06:26 2008 -0600
@@ -0,0 +1,107 @@
+# Copyright (c) 2008, Humanized, Inc.
+# All rights reserved.
+# 
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+#    1. Redistributions of source code must retain the above copyright
+#       notice, this list of conditions and the following disclaimer.
+#
+#    2. Redistributions in binary form must reproduce the above copyright
+#       notice, this list of conditions and the following disclaimer in the
+#       documentation and/or other materials provided with the distribution.
+#
+#    3. Neither the name of Enso nor the names of its contributors may
+#       be used to endorse or promote products derived from this
+#       software without specific prior written permission.
+# 
+# THIS SOFTWARE IS PROVIDED BY Humanized, Inc. ``AS IS'' AND ANY
+# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL Humanized, Inc. BE LIABLE FOR ANY
+# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+# ----------------------------------------------------------------------------
+#
+#   enso.graphics.rounded_rect
+#
+# ----------------------------------------------------------------------------
+
+"""
+    Functions and constants for drawing rounded rectangles.
+"""
+
+# ----------------------------------------------------------------------------
+# Constants
+# ----------------------------------------------------------------------------
+
+LOWER_RIGHT = 0
+UPPER_RIGHT = 1
+LOWER_LEFT = 2
+UPPER_LEFT = 3
+ALL_CORNERS = [ LOWER_RIGHT, UPPER_RIGHT, LOWER_LEFT, UPPER_LEFT ]
+
+# The radius of a corner of a rounded rectangle, in points.
+CORNER_RADIUS = 5
+
+
+# ----------------------------------------------------------------------------
+# Public Functions
+# ----------------------------------------------------------------------------
+
+def drawRoundedRect( context, rect, softenedCorners ):
+    """
+    Draws a rectangle where each corner in softenedCorners has a
+    CORNER_RADIUS-unit radius arc instead of a corner.
+    """
+    
+    PI = 3.1415926535
+    context.new_path()
+
+    xPos,yPos,width,height = rect
+
+    if LOWER_RIGHT in softenedCorners:
+        context.arc( xPos+width-CORNER_RADIUS,
+                     yPos+height-CORNER_RADIUS,
+                     CORNER_RADIUS,
+                     0,
+                     .5*PI )
+    else:
+        context.move_to( xPos+width, yPos+height-CORNER_RADIUS )
+        context.line_to( xPos+width, yPos+height )
+    context.line_to( xPos+CORNER_RADIUS, yPos+height )
+
+    if LOWER_LEFT in softenedCorners:
+        context.arc( xPos+CORNER_RADIUS,
+                     yPos+height-CORNER_RADIUS,
+                     CORNER_RADIUS,
+                     .5*PI,
+                     PI )
+    else:
+        context.line_to( xPos, yPos+height )
+    context.line_to( xPos, yPos+CORNER_RADIUS )
+
+    if UPPER_LEFT in softenedCorners:
+        context.arc( xPos+CORNER_RADIUS,
+                     yPos+CORNER_RADIUS,
+                     CORNER_RADIUS,
+                     PI,
+                     1.5*PI )
+    else:
+        context.line_to( xPos, yPos )
+    context.line_to( xPos+width-CORNER_RADIUS, yPos )
+
+    if UPPER_RIGHT in softenedCorners:
+        context.arc( xPos+width-CORNER_RADIUS,
+                     yPos+CORNER_RADIUS,
+                     CORNER_RADIUS,
+                     1.5*PI,
+                     2*PI )
+    else:
+        context.line_to( xPos+width, yPos )
+    context.line_to( xPos+width, yPos+height-CORNER_RADIUS )
--- a/enso/ui/graphics.py	Mon Feb 25 12:39:19 2008 -0600
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,115 +0,0 @@
-# Copyright (c) 2008, Humanized, Inc.
-# All rights reserved.
-# 
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions are met:
-#
-#    1. Redistributions of source code must retain the above copyright
-#       notice, this list of conditions and the following disclaimer.
-#
-#    2. Redistributions in binary form must reproduce the above copyright
-#       notice, this list of conditions and the following disclaimer in the
-#       documentation and/or other materials provided with the distribution.
-#
-#    3. Neither the name of Enso nor the names of its contributors may
-#       be used to endorse or promote products derived from this
-#       software without specific prior written permission.
-# 
-# THIS SOFTWARE IS PROVIDED BY Humanized, Inc. ``AS IS'' AND ANY
-# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-# DISCLAIMED. IN NO EVENT SHALL Humanized, Inc. BE LIABLE FOR ANY
-# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-# ----------------------------------------------------------------------------
-#
-#   enso.ui.graphics
-#
-# ----------------------------------------------------------------------------
-
-"""
-    Graphics utility functions specific to the enso.ui package.
-"""
-
-# ----------------------------------------------------------------------------
-# Imports
-# ----------------------------------------------------------------------------
-
-from enso.graphics.transparentwindow import TransparentWindow
-from enso.graphics.measurement import convertUserSpaceToPoints
-
-
-# ----------------------------------------------------------------------------
-# Constants
-# ----------------------------------------------------------------------------
-
-LOWER_RIGHT = 0
-UPPER_RIGHT = 1
-LOWER_LEFT = 2
-UPPER_LEFT = 3
-ALL_CORNERS = [ LOWER_RIGHT, UPPER_RIGHT, LOWER_LEFT, UPPER_LEFT ]
-_emptyContext = None
-
-# The radius of a corner of a rounded rectangle, in points.
-CORNER_RADIUS = 5
-
-# ----------------------------------------------------------------------------
-# Public Functions
-# ----------------------------------------------------------------------------
-
-def drawRoundedRect( context, rect, softenedCorners ):
-    """
-    Draws a rectangle where each corner in softenedCorners has a
-    CORNER_RADIUS-unit radius arc instead of a corner.
-    """
-    
-    PI = 3.1415926535
-    context.new_path()
-
-    xPos,yPos,width,height = rect
-
-    if LOWER_RIGHT in softenedCorners:
-        context.arc( xPos+width-CORNER_RADIUS,
-                     yPos+height-CORNER_RADIUS,
-                     CORNER_RADIUS,
-                     0,
-                     .5*PI )
-    else:
-        context.move_to( xPos+width, yPos+height-CORNER_RADIUS )
-        context.line_to( xPos+width, yPos+height )
-    context.line_to( xPos+CORNER_RADIUS, yPos+height )
-
-    if LOWER_LEFT in softenedCorners:
-        context.arc( xPos+CORNER_RADIUS,
-                     yPos+height-CORNER_RADIUS,
-                     CORNER_RADIUS,
-                     .5*PI,
-                     PI )
-    else:
-        context.line_to( xPos, yPos+height )
-    context.line_to( xPos, yPos+CORNER_RADIUS )
-
-    if UPPER_LEFT in softenedCorners:
-        context.arc( xPos+CORNER_RADIUS,
-                     yPos+CORNER_RADIUS,
-                     CORNER_RADIUS,
-                     PI,
-                     1.5*PI )
-    else:
-        context.line_to( xPos, yPos )
-    context.line_to( xPos+width-CORNER_RADIUS, yPos )
-
-    if UPPER_RIGHT in softenedCorners:
-        context.arc( xPos+width-CORNER_RADIUS,
-                     yPos+CORNER_RADIUS,
-                     CORNER_RADIUS,
-                     1.5*PI,
-                     2*PI )
-    else:
-        context.line_to( xPos+width, yPos )
-    context.line_to( xPos+width, yPos+height-CORNER_RADIUS )
--- a/enso/ui/messages/miniwindows.py	Mon Feb 25 12:39:19 2008 -0600
+++ b/enso/ui/messages/miniwindows.py	Mon Feb 25 19:06:26 2008 -0600
@@ -47,7 +47,7 @@
 from enso import config
 from enso import graphics
 from enso.graphics.measurement import pointsToPixels, pixelsToPoints
-from enso.ui.graphics import UPPER_LEFT, drawRoundedRect
+from enso.graphics import rounded_rect
 from enso.ui.messages.windows import MessageWindow, computeWidth
 from enso.ui.messages.primarywindow import layoutMessageXml
 from enso.ui.messages import Message
@@ -415,12 +415,12 @@
         
         cr = self._context
         if self.__isRounded:
-            corners = [UPPER_LEFT]
+            corners = [rounded_rect.UPPER_LEFT]
         else:
             corners = []
             
         cr.set_source_rgba( *MINI_BG_COLOR )
-        drawRoundedRect(
+        rounded_rect.drawRoundedRect(
             context = cr,
             rect = ( 0, 0, width, height),
             softenedCorners = corners,
--- a/enso/ui/messages/primarywindow.py	Mon Feb 25 12:39:19 2008 -0600
+++ b/enso/ui/messages/primarywindow.py	Mon Feb 25 19:06:26 2008 -0600
@@ -45,7 +45,7 @@
 from enso import graphics
 from enso.graphics import xmltextlayout
 from enso.graphics.measurement import inchesToPoints
-from enso.ui.graphics import drawRoundedRect, ALL_CORNERS
+from enso.graphics import rounded_rect
 from enso.utils.xml_tools import escapeXml
 from enso.ui.messages.windows import MessageWindow, computeWidth
 
@@ -360,10 +360,10 @@
         self.__position()
         
         cr = self._context
-        drawRoundedRect(
+        rounded_rect.drawRoundedRect(
             context = cr,
             rect = ( 0, 0, width, height ),
-            softenedCorners = ALL_CORNERS,
+            softenedCorners = rounded_rect.ALL_CORNERS,
             )
         cr.set_source_rgba( *MSG_BGCOLOR )
         cr.fill_preserve()
--- a/enso/ui/quasimode/linewindows.py	Mon Feb 25 12:39:19 2008 -0600
+++ b/enso/ui/quasimode/linewindows.py	Mon Feb 25 19:06:26 2008 -0600
@@ -47,9 +47,7 @@
 from enso.graphics.measurement import pointsToPixels, pixelsToPoints
 from enso.graphics.measurement import convertUserSpaceToPoints
 from enso.graphics.transparentwindow import TransparentWindow
-from enso.ui.graphics import drawRoundedRect
-from enso.ui.graphics import LOWER_RIGHT, UPPER_RIGHT
-from enso.ui.graphics import CORNER_RADIUS
+from enso.graphics import rounded_rect
 from enso.ui.quasimode import layout
 
 
@@ -104,27 +102,27 @@
         cr.save()
         cr.set_source_rgba( 0, 0, 0, 0 )
         cr.set_operator( cairo.OPERATOR_SOURCE )
-        cr.rectangle( width-CORNER_RADIUS,
-                      height-CORNER_RADIUS,
-                      CORNER_RADIUS,
-                      CORNER_RADIUS )
-        cr.rectangle( width-CORNER_RADIUS,
+        cr.rectangle( width - rounded_rect.CORNER_RADIUS,
+                      height - rounded_rect.CORNER_RADIUS,
+                      rounded_rect.CORNER_RADIUS,
+                      rounded_rect.CORNER_RADIUS )
+        cr.rectangle( width - rounded_rect.CORNER_RADIUS,
                       0,
-                      CORNER_RADIUS,
-                      CORNER_RADIUS )
+                      rounded_rect.CORNER_RADIUS,
+                      rounded_rect.CORNER_RADIUS )
         cr.paint()
 
         # Draw the background rounded rectangle.
         corners = []
         if document.roundUpperRight:
-            corners.append( UPPER_RIGHT )
+            corners.append( rounded_rect.UPPER_RIGHT )
         if document.roundLowerRight:
-            corners.append( LOWER_RIGHT )
+            corners.append( rounded_rect.LOWER_RIGHT )
 
         cr.set_source_rgba( *document.background )
-        drawRoundedRect( context = cr,
-                         rect = ( 0, 0, width, height ), 
-                         softenedCorners = corners )
+        rounded_rect.drawRoundedRect( context = cr,
+                                      rect = ( 0, 0, width, height ), 
+                                      softenedCorners = corners )
         cr.fill_preserve()
         cr.restore()