[gnome-games] Add a new display mode - face-to-face. This is useful when using a handheld when on a flat surface



commit c99d534ee8fe793e873c9b247bf11be1b083bd1d
Author: Robert Ancell <robert ancell gmail com>
Date:   Mon May 4 12:16:03 2009 +1000

    Add a new display mode - face-to-face.  This is useful when using a handheld when on a flat surface (Chris Burkhardt, Robert Ancell, 570823)
---
 glchess/data/glchess.schemas.in         |    2 +-
 glchess/src/lib/display.py              |    8 ++--
 glchess/src/lib/gtkui/dialogs.py        |    4 +-
 glchess/src/lib/scene/__init__.py       |    3 +-
 glchess/src/lib/scene/cairo/__init__.py |   91 ++++++++++++++-----------------
 glchess/src/lib/scene/opengl/opengl.py  |    2 +-
 6 files changed, 52 insertions(+), 58 deletions(-)

diff --git a/glchess/data/glchess.schemas.in b/glchess/data/glchess.schemas.in
index abf4819..d57ded1 100644
--- a/glchess/data/glchess.schemas.in
+++ b/glchess/data/glchess.schemas.in
@@ -201,7 +201,7 @@
       <default>human</default>
       <locale name="C">
         <short>The board side to display</short>
-        <long>The side of the board that is in the foreground, either 'white', 'black', 'current' (the current player) or 'human' (the side of the current human player)</long>
+        <long>The side of the board that is in the foreground, either 'white', 'black', 'current' (the current player), 'human' (the side of the current human player) or 'facetoface' (suitable for players on each side of screen, e.g. handhelds)</long>
       </locale>
     </schema>
 
diff --git a/glchess/src/lib/display.py b/glchess/src/lib/display.py
index c743d4b..72d3d7b 100644
--- a/glchess/src/lib/display.py
+++ b/glchess/src/lib/display.py
@@ -270,8 +270,8 @@ class Splashscreen(ui.ViewFeedback):
             rotation = 180.0
         else:
             rotation = 0.0
-        self.cairoScene.controller.setBoardRotation(rotation, animate)
-        self.scene.controller.setBoardRotation(rotation, animate)
+        self.cairoScene.controller.setBoardRotation(rotation, boardView == 'facetoface', animate)
+        self.scene.controller.setBoardRotation(rotation, boardView == 'facetoface', animate)
 
     def onRedraw(self):
         """Called by scene.SceneFeedback"""
@@ -431,7 +431,7 @@ class View(ui.ViewFeedback):
         
         # Decide if we should face this angle
         boardView = config.get('board_view')
-        if boardView == 'white':
+        if boardView == 'white' or boardView == 'facetoface':
             rotation = 0.0
         elif boardView == 'black':
             rotation = 180.0
@@ -439,7 +439,7 @@ class View(ui.ViewFeedback):
             if not isinstance(p, player.HumanPlayer):
                 return
 
-        self.scene.controller.setBoardRotation(rotation, animate)
+        self.scene.controller.setBoardRotation(rotation, boardView == 'facetoface', animate)
 
     def _pieceMoved(self, piece):
         """
diff --git a/glchess/src/lib/gtkui/dialogs.py b/glchess/src/lib/gtkui/dialogs.py
index 13d854d..f6010da 100644
--- a/glchess/src/lib/gtkui/dialogs.py
+++ b/glchess/src/lib/gtkui/dialogs.py
@@ -605,7 +605,9 @@ class GtkPreferencesDialog:
                      # Translators: Board Side Combo: Camera will face human player's side
                      ('human', _('Human Side')),
                      # Translators: Board Side Combo: Camera will face current player's side
-                     ('current', _('Current Player'))]
+                     ('current', _('Current Player')),
+                     # Translators: Board Side Combo: Board will be drawn suitable for players on each side of screen, e.g. handhelds
+                     ('facetoface', _('Face to Face'))]
         for (key, label) in view_list:
             iter = boardModel.append()
             boardModel.set(iter, 0, label, 1, key)
diff --git a/glchess/src/lib/scene/__init__.py b/glchess/src/lib/scene/__init__.py
index 39552c1..e6c9223 100644
--- a/glchess/src/lib/scene/__init__.py
+++ b/glchess/src/lib/scene/__init__.py
@@ -97,10 +97,11 @@ class Scene:
         """
         pass
     
-    def setBoardRotation(self, angle, animate):
+    def setBoardRotation(self, angle, faceToFace = False, animate = True):
         """Set the rotation on the board.
         
         'angle' is the angle the board should be drawn at in degress (float, [0.0, 360.0]).
+        'faceToFace' is True if the top pieces should be drawn upside down.
         'animate' is True if the rotation shoule be animated.
         """
         pass
diff --git a/glchess/src/lib/scene/cairo/__init__.py b/glchess/src/lib/scene/cairo/__init__.py
index 71afed6..ae0a242 100644
--- a/glchess/src/lib/scene/cairo/__init__.py
+++ b/glchess/src/lib/scene/cairo/__init__.py
@@ -26,29 +26,18 @@ PIECE_COLOUR         = (0.0, 0.0, 0.0)
 class ChessPiece(glchess.scene.ChessPiece):
     """
     """
-    scene       = None
-    name        = None
-    
-    # Co-ordinate being moved to
-    coord       = None
-    
-    targetPos   = None
-    
-    # Current position
-    pos         = None
-    moving      = False
 
-    # Delete once moved to location
-    delete      = False
-    
     def __init__(self, scene, name, coord, feedback):
         """
         """
         self.scene = scene
         self.feedback = feedback
         self.name = name
-        self.coord = coord
-        self.pos = self.__coordToLocation(coord)
+        self.coord = coord # Co-ordinate being moved to
+        self.pos = self.__coordToLocation(coord) # Current position
+        self.targetPos   = None
+        self.moving = False
+        self.delete = False # Delete once moved to location
         
     def __coordToLocation(self, coord):
         """
@@ -138,6 +127,7 @@ class ChessPiece(glchess.scene.ChessPiece):
     def render(self, context):
         """
         """
+        offset = 0
         matrix = context.get_matrix()
         x = (self.pos[0] - 4) * self.scene.squareSize
         y = (3 - self.pos[1]) * self.scene.squareSize
@@ -145,37 +135,33 @@ class ChessPiece(glchess.scene.ChessPiece):
         context.translate(self.scene.squareSize / 2, self.scene.squareSize / 2)
         context.rotate(-self.scene.angle)
         context.translate(-self.scene.squareSize / 2, -self.scene.squareSize / 2)
-        pieces.piece(self.name, context, self.scene.pieceSize, 0, 0)
+
+        # If Face to Face mode is enabled, we rotate the black player's pieces by 180 degrees
+        if self.scene.faceToFace and self.name.find('black') != -1:
+            context.rotate(math.pi)
+            offset -= self.scene.pieceSize
+        pieces.piece(self.name, context, self.scene.pieceSize, offset, offset)
         context.fill()
         context.set_matrix(matrix)
 
 class Scene(glchess.scene.Scene):
     """
-    """
-    feedback    = None
-    
-    pieces      = None
-    highlights  = None
-    
-    angle       = 0.0
-    targetAngle = 0.0
-    
-    animating     = False
-    redrawStatic  = True
-
-    showNumbering = False
-    
-    _animationQueue = None
-    
+    """    
     BORDER = 6.0
     PIECE_BORDER = 2.0
 
     def __init__(self, feedback):
         """Constructor for a Cairo scene"""
-        self.feedback = feedback
-        self.highlight = {}
-        self.pieces = []
+        self.feedback        = feedback
+        self.highlight       = {}
+        self.pieces          = []
         self._animationQueue = []
+        self.angle           = 0.0
+        self.targetAngle     = 0.0
+        self.animating       = False
+        self.redrawStatic    = True
+        self.showNumbering   = False
+        self.faceToFace      = False
     
     def addChessPiece(self, chessSet, name, coord, feedback):
         """Add a chess piece model into the scene.
@@ -233,24 +219,32 @@ class Scene(glchess.scene.Scene):
         self.redrawStatic = True
         self.feedback.onRedraw()
 
-    def setBoardRotation(self, angle, animate = True):
+    def setBoardRotation(self, angle, faceToFace = False, animate = True):
         """Extends glchess.scene.Scene"""
         # Convert from degrees to radians
         a = angle * math.pi / 180.0
         
-        if self.angle == a:
-            return
-        self.targetAngle = a
+        redraw = False
+
+        if self.faceToFace != faceToFace:
+            redraw = True
+            self.faceToFace = faceToFace
         
-        if not animate:
-            self.angle = a
-            self.feedback.onRedraw()
-            return
+        if self.angle == a:
+            animate = False
+        else:
+            self.targetAngle = a
+            if not animate:
+                self.angle = a
+                redraw = True
 
-        # Start animation
-        if self.animating is False:
+        # Start animation or redraw now
+        if animate and self.animating is False:
             self.animating = True
-            self.feedback.startAnimation()            
+            self.feedback.startAnimation()
+        elif redraw:
+            self.redrawStatic = True
+            self.feedback.onRedraw()
 
     def animate(self, timeStep):
         """Extends glchess.scene.Scene"""
@@ -470,6 +464,3 @@ class Scene(glchess.scene.Scene):
         file = chr(ord('1') + file)
 
         return rank + file
-
-    # Private methods
-    
diff --git a/glchess/src/lib/scene/opengl/opengl.py b/glchess/src/lib/scene/opengl/opengl.py
index de66eab..fdf0a1b 100644
--- a/glchess/src/lib/scene/opengl/opengl.py
+++ b/glchess/src/lib/scene/opengl/opengl.py
@@ -311,7 +311,7 @@ class Scene(glchess.scene.Scene):
         glViewport(0, 0, self.viewportWidth, self.viewportHeight)
         self.feedback.onRedraw()
 
-    def setBoardRotation(self, angle, animate = True):
+    def setBoardRotation(self, angle, faceToFace = False, animate = True):
         """Set the rotation on the board.
         
         'angle' is the angle the board should be drawn at in degress (float, [0.0, 360.0]).



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]