changeset 40:835c7c35e4c4

The graphics subsystem now operates entirely in points.
author Andrew Wilson <andrew@humanized.com>
date Sun, 24 Feb 2008 17:24:55 -0600
parents 30686583595d
children c525e6bb4004
files enso/graphics/__init__.py enso/graphics/transparentwindow.py enso/ui/messages/miniwindows.py enso/ui/messages/primarywindow.py enso/ui/messages/windows.py enso/ui/quasimode/layout.py enso/ui/quasimode/linewindows.py enso/ui/quasimode/window.py
diffstat 8 files changed, 90 insertions(+), 56 deletions(-) [+]
line wrap: on
line diff
--- a/enso/graphics/__init__.py	Sun Feb 24 13:23:56 2008 -0600
+++ b/enso/graphics/__init__.py	Sun Feb 24 17:24:55 2008 -0600
@@ -2,4 +2,10 @@
 
 _graphics = enso.providers.getInterface( "graphics" )
 
-getDesktopSize = _graphics.getDesktopSize
+from enso.graphics.measurement import pointsToPixels, pixelsToPoints
+
+def getDesktopSize():
+    width, height = _graphics.getDesktopSize()
+    width = pixelsToPoints( width )
+    height = pixelsToPoints( height )
+    return ( width, height )
--- a/enso/graphics/transparentwindow.py	Sun Feb 24 13:23:56 2008 -0600
+++ b/enso/graphics/transparentwindow.py	Sun Feb 24 17:24:55 2008 -0600
@@ -3,4 +3,62 @@
 _graphics = enso.providers.getInterface( "graphics" )
 
 # Import the TransparentWindow class into our namespace.
-TransparentWindow = _graphics.TransparentWindow
+#TransparentWindow = _graphics.TransparentWindow
+
+from enso.graphics.measurement import pointsToPixels, pixelsToPoints
+from enso.graphics.measurement import convertUserSpaceToPoints
+import cairo
+
+class TransparentWindow( object ):
+    def __init__( self, xPos, yPos, width, height ):
+        # Convert from points to pixels
+        xPos = int( pointsToPixels( xPos ) )
+        yPos = int( pointsToPixels( yPos ) )
+        width = max( int( pointsToPixels( width ) ), 1 )
+        height = max( int( pointsToPixels( height ) ), 1 )
+        
+        self._impl = _graphics.TransparentWindow( xPos, yPos,
+                                                  width, height )
+
+    def makeCairoContext( self ):
+        context = cairo.Context( self._impl.makeCairoSurface() )
+        convertUserSpaceToPoints( context )
+        return context
+
+    def update( self ):
+        return self._impl.update()
+
+    def setOpacity( self, opacity ):
+        return self._impl.setOpacity( opacity )
+
+    def getOpacity( self ):
+        return self._impl.getOpacity()
+
+    def setPosition( self, x, y ):
+        x = int( pointsToPixels( x ))
+        y = int( pointsToPixels( y ))
+        return self._impl.setPosition( x, y )
+
+    def getX( self ):
+        return pixelsToPoints( self._impl.getX() )
+
+    def getY( self ):
+        return pixelsToPoints( self._impl.getY() )
+
+    def setSize( self, width, height ):
+        width = max( int(pointsToPixels(width)), 1 )
+        height = max( int(pointsToPixels(height)), 1 )
+        return self._impl.setSize( width, height )
+
+    def getWidth( self ):
+        return pixelsToPoints( self._impl.getWidth() )
+
+    def getHeight( self ):
+        return pixelsToPoints( self._impl.getHeight() )
+
+    def getMaxWidth( self ):
+        return pixelsToPoints( self._impl.getMaxWidth() )
+
+    def getMaxHeight( self ):
+        return pixelsToPoints( self._impl.getMaxHeight() )
+
--- a/enso/ui/messages/miniwindows.py	Sun Feb 24 13:23:56 2008 -0600
+++ b/enso/ui/messages/miniwindows.py	Sun Feb 24 17:24:55 2008 -0600
@@ -139,9 +139,7 @@
         for index in range( len(self.__visibleMessages) ):
             miniWind = self.__visibleMessages[index]
             size = miniWind.getSize()
-            size = [ pointsToPixels( i ) for i in size ]
             pos = miniWind.getPos()
-            pos = [ pointsToPixels( i ) for i in pos ]
             if ( x > pos[0] and x < (pos[0] + size[0]) ) \
                    and ( y > pos[1] and y < (pos[1] + size[1]) ):
                 # The mouse is inside this miniWindow
@@ -257,10 +255,10 @@
         self.__status = self.EMPTY
 
     def __startAppearing( self, msg ):
-        xPos = pixelsToPoints( graphics.getDesktopSize()[0] )
+        xPos = graphics.getDesktopSize()[0]
         xPos -= MINI_WIND_SIZE[0]
 
-        yPos = pixelsToPoints( graphics.getDesktopSize()[1] )
+        yPos = graphics.getDesktopSize()[1]
         # Move up for each visible message, including this one.
         numVisible = len( self.__visibleMessages ) + 1
         yPos -= ( MINI_WIND_SIZE[1] * numVisible )
@@ -327,7 +325,7 @@
         # So pychecker doesn't complain
         dummy = msPassed
 
-        distancePer = pixelsToPoints( 1 )
+        distancePer = 1
         msg = self.__visibleMessages[ self.__changingIndex ]
         if msg.isFinishedVanishing:
             self.__stopVanishing()
--- a/enso/ui/messages/primarywindow.py	Sun Feb 24 13:23:56 2008 -0600
+++ b/enso/ui/messages/primarywindow.py	Sun Feb 24 17:24:55 2008 -0600
@@ -44,7 +44,6 @@
 
 from enso import graphics
 from enso.graphics import xmltextlayout
-from enso.graphics.measurement import pixelsToPoints
 from enso.graphics.measurement import inchesToPoints
 from enso.ui.graphics import drawRoundedRect, ALL_CORNERS
 from enso.utils.xml_tools import escapeXml
@@ -119,10 +118,10 @@
         # Instantiate the underlying MessageWindow to the
         # maxsize suggested by the module constants.
         width = min( PRIM_MSG_WIDTH,
-                     pixelsToPoints(graphics.getDesktopSize()[0])-1 )
+                     graphics.getDesktopSize()[0]-1 )
 
         height = min( MAX_MSG_HEIGHT,
-                      pixelsToPoints(graphics.getDesktopSize()[1])-1 )
+                      graphics.getDesktopSize()[1]-1 )
 
         maxSize = ( width, height )
         MessageWindow.__init__( self, maxSize )
@@ -211,8 +210,6 @@
         """
         
         desksize = graphics.getDesktopSize()
-        # getDesktopSize() returns pixels; we work in points.
-        desksize = [ pixelsToPoints(a) for a in desksize ]
 
         xPos = ( desksize[0] - self.getSize()[0] ) / 2
         # Set the height based on the "maximum" height, so that the
--- a/enso/ui/messages/windows.py	Sun Feb 24 13:23:56 2008 -0600
+++ b/enso/ui/messages/windows.py	Sun Feb 24 17:24:55 2008 -0600
@@ -45,9 +45,6 @@
 from enso import graphics
 from enso.graphics.transparentwindow import TransparentWindow
 
-from enso.graphics.measurement import pointsToPixels
-from enso.graphics.measurement import convertUserSpaceToPoints
-
 
 # ----------------------------------------------------------------------------
 # Generic Message Window
@@ -78,19 +75,16 @@
         Cairo Context objects, once and for all.
         """
         
-        width = int( pointsToPixels(self.__maxSize[0]) + 1)
-        height = int( pointsToPixels(self.__maxSize[1]) + 1)
+        width = self.__maxSize[0]
+        height = self.__maxSize[1]
 
-        xPos = int(round(pointsToPixels(self.__currPos[0])))
-        yPos = int(round(pointsToPixels(self.__currPos[1])))
+        xPos = self.__currPos[0]
+        yPos = self.__currPos[1]
 
         # The following are protected to allow subclasses access
         # to them.
         self._wind = TransparentWindow( xPos, yPos, width, height )
-        self._context = cairo.Context( self._wind.makeCairoSurface() )
-
-        # We work in points, not pixels
-        convertUserSpaceToPoints( self._context )
+        self._context = self._wind.makeCairoContext()
 
 
     def getSize( self ):
@@ -119,10 +113,7 @@
         self.__currSize = width, height
 
         if self._wind != None:
-            # Windows work in pixels, not points.
-            width = pointsToPixels( width )
-            height = pointsToPixels( height )
-            self._wind.setSize( int(width), int(height) )
+            self._wind.setSize( width, height )
 
 
     def setPos( self, xPos, yPos ):
@@ -131,15 +122,12 @@
         should be in points.
         """
 
-        assert pointsToPixels( xPos ) <= graphics.getDesktopSize()[0]
-        assert pointsToPixels( yPos ) <= graphics.getDesktopSize()[1]
+        assert xPos <= graphics.getDesktopSize()[0]
+        assert yPos <= graphics.getDesktopSize()[1]
 
         self.__currPos = xPos, yPos
         if self._wind != None:
-            # Windows work in pixels, not points.
-            xPos = pointsToPixels( xPos )
-            yPos = pointsToPixels( yPos )
-            self._wind.setPosition( int(xPos), int(yPos) )
+            self._wind.setPosition( xPos, yPos )
 
             
     def hide( self ):
--- a/enso/ui/quasimode/layout.py	Sun Feb 24 13:23:56 2008 -0600
+++ b/enso/ui/quasimode/layout.py	Sun Feb 24 17:24:55 2008 -0600
@@ -42,7 +42,6 @@
 
 from enso import graphics
 from enso.graphics import xmltextlayout
-from enso.graphics.measurement import pixelsToPoints
 from enso.utils.xml_tools import escapeXml
 
 
@@ -143,7 +142,7 @@
     styles should be a style registry.
     """
 
-    width = pixelsToPoints( graphics.getDesktopSize()[0] )
+    width = graphics.getDesktopSize()[0]
     styles.update(
         "document",
         font_size = "%fpt" % size,
--- a/enso/ui/quasimode/linewindows.py	Sun Feb 24 13:23:56 2008 -0600
+++ b/enso/ui/quasimode/linewindows.py	Sun Feb 24 17:24:55 2008 -0600
@@ -76,10 +76,8 @@
 
         xPos, yPos = position
         self.__window = TransparentWindow( xPos, yPos, width, height )
-        self.__context = cairo.Context( self.__window.makeCairoSurface() )
+        self.__context = self.__window.makeCairoContext()
         
-        convertUserSpaceToPoints( self.__context )
-
 
     def getHeight( self ):
         """
@@ -98,7 +96,7 @@
         """
 
         width = document.ragWidth + layout.L_MARGIN + layout.R_MARGIN
-        height = pixelsToPoints( self.__window.getMaxHeight() )
+        height = self.__window.getMaxHeight()
         cr = self.__context
 
         # Clear the areas where the corners of the rounded rectangle will be.
@@ -135,15 +133,10 @@
                        document.shrinkOffset,
                        self.__context )
 
-        pixelWidth = int(pointsToPixels( width ))
-        pixelWidth = max( 1, pixelWidth )
-        pixelWidth = min( self.__window.getMaxWidth(), pixelWidth )
+        width = min( self.__window.getMaxWidth(), width )
+        height = min( self.__window.getMaxHeight(), height )
 
-        pixelHeight = int(pointsToPixels( height ))
-        pixelHeight = max( 1, pixelHeight )
-        pixelHeight = min( self.__window.getMaxHeight(), pixelHeight )
-
-        self.__window.setSize( pixelWidth, pixelHeight )
+        self.__window.setSize( width, height )
         self.__window.update()
 
 
@@ -157,15 +150,12 @@
 
         self.__window.setSize( 1, 1 )
 
-        width = pixelsToPoints( 1 )
-        height = pixelsToPoints( 1 )
-
         # Frankly, I don't know why this works, but after this
         # function, the resulting window is totally clear. I find it
         # odd, since the alpha value is not being set.  It is a
         # wierdness of Cairo. -- Andrew
 
-        self.__context.rectangle( 0, 0, width, height )
+        self.__context.rectangle( 0, 0, 1, 1 )
         self.__context.set_source_rgb( 0, 0, 0 )
         self.__context.paint()
 
--- a/enso/ui/quasimode/window.py	Sun Feb 24 13:23:56 2008 -0600
+++ b/enso/ui/quasimode/window.py	Sun Feb 24 17:24:55 2008 -0600
@@ -62,8 +62,6 @@
 
 import time
 
-from enso.graphics.measurement import pointsToPixels
-
 from enso.ui.quasimode.linewindows import TextWindow
 from enso.ui.quasimode.layout import QuasimodeLayout
 from enso.ui.quasimode.layout import HEIGHT_FACTOR
@@ -98,14 +96,14 @@
         # that window is.  Use a "top" variable to know how far down
         # the screen the top of the next window should start.
 
-        height = int( pointsToPixels( DESCRIPTION_SCALE[-1] )*HEIGHT_FACTOR )
+        height = DESCRIPTION_SCALE[-1]*HEIGHT_FACTOR
         self.__descriptionWindow = TextWindow(
             height = height,
             position = [ 0, 0 ],
             )
         top = height
         
-        height = int( pointsToPixels( AUTOCOMPLETE_SCALE[-1] )*HEIGHT_FACTOR )
+        height = AUTOCOMPLETE_SCALE[-1]*HEIGHT_FACTOR
         self.__userTextWindow = TextWindow(
             height = height,
             position = [ 0, top ],
@@ -114,7 +112,7 @@
     
         self.__suggestionWindows = []
         for i in range( config.QUASIMODE_MAX_SUGGESTIONS ):
-            height = int( pointsToPixels( SUGGESTION_SCALE[-1] )*HEIGHT_FACTOR )
+            height = SUGGESTION_SCALE[-1]*HEIGHT_FACTOR
             self.__suggestionWindows.append( TextWindow(
                 height = height,
                 position = [ 0, top ],