Title: [commits] (jeffrey) [11396] - More work on bug 6233, calendar face lift
Revision
11396
Author
jeffrey
Date
2006-08-10 20:15:16 -0700 (Thu, 10 Aug 2006)

Log Message

- More work on bug 6233, calendar face lift

Don't use wx's dashed line support on the Mac, it doesn't work as
I'd expect it to. Instead implement using a thin DrawRectangle with a
dashed stipple without anti-aliasing (DrawLine doesn't support
stipples on the Mac)

Modified Paths

Diff

Modified: trunk/chandler/parcels/osaf/framework/blocks/DrawingUtilities.py (11395 => 11396)

--- trunk/chandler/parcels/osaf/framework/blocks/DrawingUtilities.py	2006-08-11 01:58:40 UTC (rev 11395)
+++ trunk/chandler/parcels/osaf/framework/blocks/DrawingUtilities.py	2006-08-11 03:15:16 UTC (rev 11396)
@@ -14,7 +14,10 @@
 
 
 import wx, os, random
+from itertools import izip, cycle
+from struct import pack
 
+
 from colorsys import hsv_to_rgb, rgb_to_hsv
 import Styles
 
@@ -199,10 +202,13 @@
         return vector(map(lambda x,y: x-y, self, other))
 
     def __mul__(self, const):
-	return vector(map(lambda x: x*const, self))
+        return vector(map(lambda x: x*const, self))
     
     def __rmul__(self, other):
-	    return (self*other)
+            return (self*other)
+        
+    def join(self, other):
+        return list.__add__(self, other)
 
 
 class Gradients(object):
@@ -232,6 +238,7 @@
         that particular width of height
         """
         self._gradientCache = {}
+        self._dashCache  = {}
     
     def MakeGradientBrush(self, offset, bitmapWidth, leftColor, rightColor,
                           orientation):
@@ -267,7 +274,6 @@
         # in the bitmap
         offset %= bitmapWidth
 
-        from struct import pack
         bufferX = 0
         imageBuffer = image.GetDataBuffer()
         
@@ -282,7 +288,7 @@
             gradientIndex = (x - offset + bitmapWidth) % bitmapWidth
             
             # now calculate the actual color from the gradient index
-	    hsvVector = left + step * gradientIndex
+            hsvVector = left + step * gradientIndex
             color = rgb2color(*hsv_to_rgb(*hsvVector))
 
             # use the image buffer to write values directly
@@ -316,6 +322,38 @@
             self.hits += 1
         return brush
 
+    def MakeDash(self, offset, pattern, color, orientation):
+        bitmapWidth = sum(pattern)
+        if orientation == "Horizontal":
+            image = wx.EmptyImage(bitmapWidth, 1)
+        else:
+            image = wx.EmptyImage(1, bitmapWidth)
+
+        offset *= 3 # three color bytes per pixel
+        colorAndWidth = izip(cycle([color, (255,255,255)]), pattern)
+
+        bufferX = 0
+        imageBuffer = image.GetDataBuffer()
+        for col, width in colorAndWidth:
+            newBufferX = bufferX + 3 * width
+            imageBuffer[bufferX:newBufferX] = width * pack('BBB', *col)
+            bufferX = newBufferX
+
+        # shift the bytes by offset
+        imageBuffer[:] = imageBuffer[offset:] + imageBuffer[:offset]
+        brush = wx.Brush(wx.WHITE, wx.STIPPLE)
+        brush.SetStipple(wx.BitmapFromImage(image))
+        return brush
+
+    def GetDash(self, offset, pattern, color, orientation):
+        key = (offset % len(pattern), color, orientation)
+        dash = self._dashCache.get(key, None)
+        if dash is None:
+            dash = self.MakeDash(offset, pattern, color, orientation)
+            self._dashCache[key] = dash
+        return dash
+
+
 if __name__ == '__main__':
     
     # Test/example of DrawWrappedText

Modified: trunk/chandler/parcels/osaf/framework/blocks/calendar/CalendarCanvas.py (11395 => 11396)

--- trunk/chandler/parcels/osaf/framework/blocks/calendar/CalendarCanvas.py	2006-08-11 01:58:40 UTC (rev 11395)
+++ trunk/chandler/parcels/osaf/framework/blocks/calendar/CalendarCanvas.py	2006-08-11 03:15:16 UTC (rev 11396)
@@ -415,12 +415,12 @@
                 # may actually be the same boundsRect	
                 hasTopRightRounded = hasBottomRightRounded = False	
                 drawEventText = False	
-                if rectIndex == 0:	
-                    hasTopRightRounded = True	
-                    drawEventText = True	
+                if rectIndex == 0:
+                    hasTopRightRounded = True
+                    drawEventText = True
            
-                if rectIndex == len(self.GetBoundsRects())-1:	
-                    hasBottomRightRounded = True	
+                if rectIndex == len(self.GetBoundsRects())-1:
+                    hasBottomRightRounded = True
            
                 hasLeftRounded = True #always rounding left side
 
@@ -455,7 +455,8 @@
                                         hasLeftRounded,
                                         hasTopRightRounded,
                                         hasBottomRightRounded,
-                                        rightSideCutOff, self.dashedLine())
+                                        rightSideCutOff, self.dashedLine(),
+                                        styles)
                     
     
                 # Shift text to account for rounded corners
@@ -519,7 +520,8 @@
                            hasTopRightRounded=True,
                            hasBottomRightRounded=True,
                            clipRightSide=False,
-                           addDashes = False):
+                           addDashes = False,
+                           styles = None):
         """
         Make a rounded rectangle, optionally specifying if the top and bottom
         right side of the rectangle should have rounded corners.
@@ -568,36 +570,57 @@
 
         # finally draw the clipped rounded rect
         dc.DrawRoundedRectangle(x,y,width,height,RADIUS)
+        dash_pattern = [2,1,4,1]
         
-        def drawSides():
-            dc.DrawLine(x, y+RADIUS,  x, y+height-RADIUS)                #left 
-            dc.DrawLine(x+RADIUS, y,  x + width-RADIUS, y)               #top 
-            dc.DrawLine(x+width-1, y+RADIUS, x+width-1, y+height-RADIUS) #right
-            dc.DrawLine(x+RADIUS, y+height-1, x+width-RADIUS, y+height-1)#bottom
+        def drawVertical(brush = None):
+            if brush:
+                dc.SetBrush(brush)
+                dc.DrawRectangle(x, y+RADIUS, 1, height - 2 * RADIUS)
+                dc.DrawRectangle(x+width-1, y+RADIUS, 1, height - 2 * RADIUS)
+            else:
+                dc.DrawLine(x, y+RADIUS,  x, y+height-RADIUS)                #left 
+                dc.DrawLine(x+width-1, y+RADIUS, x+width-1, y+height-RADIUS) #right
 
-            
-        
-        if addDashes:
-            # draw white under dashes
-            dc.SetPen(wx.Pen(wx.WHITE, 1))
-            drawSides()
+        def drawHorizontal(brush = None):
+            if brush:
+                dc.SetBrush(brush)
+                dc.DrawRectangle(x+RADIUS, y, width - 2 * RADIUS, 1)
+                dc.DrawRectangle(x+RADIUS, y+height-1, width - 2 * RADIUS, 1)                
+            else:
+                dc.DrawLine(x+RADIUS, y,  x + width-RADIUS, y)               #top 
+                dc.DrawLine(x+RADIUS, y+height-1, x+width-RADIUS, y+height-1)#bottom
 
-            # draw dashes
-            outlinePen.SetStyle(wx.USER_DASH)
-            outlinePen.SetCap(wx.CAP_BUTT)
-            outlinePen.SetDashes([2,1,4,1])
-            dc.SetPen(outlinePen)
-            drawSides()
+
+        if '__WXMAC__' in wx.PlatformInfo and addDashes:
+            dc.SetAntiAliasing(False)
+            dc.SetPen(wx.Pen(wx.WHITE, 0, wx.TRANSPARENT))
+
+            drawHorizontal(styles.brushes.GetDash(x, dash_pattern, dashColor,
+                                                  'Horizontal'))
+
+            drawVertical(styles.brushes.GetDash(y, dash_pattern, dashColor,
+                                                'Vertical'))
+            # we ought to be storing the result of GetAntiAliasing, but that
+            # appears to always return False, so for now we just assume we're
+            # anti-aliasing
+            dc.SetAntiAliasing(True)
+
+        elif addDashes:
+
             
-        #if not hasLeftRounded:
-            ## vertical line down left side
-            #dc.DrawLine(x, y,  x, y + height)
-        #if not hasBottomRightRounded:
-            ## horizontal line across the bottom
-            #dc.DrawLine(x, y + height-1,  x + width, y + height-1)
-        #if not hasTopRightRounded:
-            ## horizontal line across the top
-            #dc.DrawLine(x, y, x+width, y)
+            if addDashes:
+                # draw white under dashes
+                dc.SetPen(wx.Pen(wx.WHITE, 1))
+                drawHorizontal()
+                drawVertical()
+    
+                # draw dashes
+                outlinePen.SetStyle(wx.USER_DASH)
+                outlinePen.SetCap(wx.CAP_BUTT)
+                outlinePen.SetDashes(dash_pattern)
+                dc.SetPen(outlinePen)
+                drawHorizontal()
+                drawVertical()
 
         if ENABLE_DEVICE_ORIGIN:
             dc.SetDeviceOrigin(oldOriginX, oldOriginY)




_______________________________________________
Commits mailing list
[email protected]
http://lists.osafoundation.org/mailman/listinfo/commits

Reply via email to