Commits

Anonymous committed 6900ed9

Removed use of temporary surface buffers to reduce memory usage. No new surfaces added either. 2 full surfaces + screen.

  • Participants
  • Parent commits a242212

Comments (0)

Files changed (1)

symbian/app/launcher/pygame_launcher.py

     def tweenEaseInBack(self, t, b, c, d, s=1.7158):
         t /= d
         return c * (t) * t * ((s + 1) * t - s) + b;
-
+    
+    def easeNone(self, t, b, c, d, s=1.7158):
+        v = c*t/d + b;
+        return v
+        
     def _slide_and_replace(self, direction, surf, surfold, surfnew, v):
         
         r = surf.get_rect()
         # Scale full or only partial if scaling larger
         use_subsurf = (v < 0)
         if use_subsurf:
-            # Full size - exceeding size
+            # Full size - exceeding size and scale that instead of full surface
             if w > r.width:
                 w -= ( w - r.width ) * 2
             if h > r.height:
         self.rect = self.surface.get_rect()
         
         #: The logo
-        self.img_logo, r = load_image("logo.jpg")
-        
-        # Position the logo on middle of the screen.
-        c = self.rect.center
-        self.img_pos = [ c[0] - r.w / 2, c[1] - r.h / 2 ]
-        
-        #: Make alpha the same size as the image
-        #self.alpha = make_surface(r.size, )
+        self.img_logo, self.img_size = load_image("logo.jpg")
         
         self.alphaval = 0.
         self.alphaprev = -1
-        self.alphadir = - 1. # per second
+        self.alphadir = - 2. # per second
         
+        self.updateAlphaValue()
+        # Position the logo on middle of the screen.
+        self.draw()
+        
+    def draw(self):
+        c = self.rect.center
+        r = self.img_size
+        self.img_pos = [ c[0] - r.w / 2, c[1] - r.h / 2 ]
+
         self.surface.fill(BLACK)
         self.surface.blit(self.img_logo, self.img_pos)
         self.surface.set_alpha(10)
         
     def updateAlphaValue(self):
         """ Update the visibility of the logo """
-        min = 6.
-        max = 12.
+        min = 12.
+        max = 24.
         
         s = self.sysdata.ticdiff / 1000.
         
         if self.alphaval < min:
             self.alphaval = min
             self.alphadir = - self.alphadir
+            
         return self.alphaval
     
     def update(self):
         self.surface.set_alpha(self.updateAlphaValue())
-        #print a
-        #a = self.alphaval
-        #self.surface.fill(BLACK)
-        #self.surface.blit(self.img_logo, self.img_pos)
-        #self.surface.fill( (a,a,a), None, BLEND_RGB_MULT )
         
 class TextField(pygame.sprite.Sprite):
     """ Handles text rendering and updating when necessary """
         # Create text contents
         DrawUtils.drawRectWithText(surf, size, TITLE_BG, TITLE_STROKE,
                                     textsurf=None)
-        #text = textwrap.dedent(text)
+        
         font = self.sysdata.getFontSmall()
         
         lines = text.split("\n")
     def __init__(self):
         
         if sys.platform == "symbian_s60":
-            size = pygame.display.list_modes(16)[0]
-            self.screen = pygame.display.set_mode(size, )
+            modes = pygame.display.list_modes(16)
+            print "Available display modes:", modes
+            size = modes[0]
+            self.screen = pygame.display.set_mode(size, 0, 16)
         else:
             self.screen = pygame.display.set_mode(DISPLAY_SIZE, 0, 16) 
         
         self.sysdata.screen = self.screen
         
         self.mainbg = Background(self.sysdata)
-        self.bg = BackgroundTransparent(self.sysdata)
+        self.bg     = BackgroundTransparent(self.sysdata)
+        self.bganim = self.mainbg#BackgroundTransparent(self.sysdata)
         
         items = [("Applications", self.mhApplications, ()),
                  # TODO: Disabled settings for now...
         
         #: Updated by foreground event
         self.is_foreground = True
-        
-    def initialize(self):
-        pass
-    
+         
     def run(self):
-        """ Main application loop """
-        self.initialize()       
-        
+        """ Main application loop """ 
         # From black
-        black = make_surface(self.screen.get_size(), )
-        self.sprites.update()
-        self.screen.blit(self.bg.surface, (0, 0))
+        def anim():
+            self.bganim.surface.fill(BLACK)
+            #black = make_surface(self.screen.get_size())
+            self.sprites.update()
+            self.screen.blit(self.bganim.surface, (0, 0))
             
-        # Start the tween animation
-        e = Effects(self.screen, self.clock, black, self.bg.surface )
-        
-        # Blocks for the duration of the animation
-        e.do( [
-               (e.effectFadeTo, e.tweenEaseOutSine),
-               #(e.effectSlideRightReplace, e.tweenEaseInBack),
-               ], 0.5)
-        
-        self.sysdata.tics = pygame.time.get_ticks()
+            # Start the tween animation
+            e = Effects(self.screen, self.clock, self.bganim.surface, self.bg.surface )
+            
+            # Blocks for the duration of the animation
+            e.do( [
+                   (e.effectFadeTo, e.tweenEaseOutSine),
+                   #(e.effectSlideRightReplace, e.tweenEaseInBack),
+                   ], 0.5)
+            
+            self.sysdata.tics = pygame.time.get_ticks()
+            
+            # Restore alpha
+            self.mainbg.surface.set_alpha(255)
+            self.mainbg.draw()
+        anim()
         
         eventhandler = self.handleEvent
         while self.running:
             self.bg.surface.set_alpha(96) # This creates a nice fade effect for menu items
             self.screen.blit(self.bg.surface, (0, 0))
             
-            
             pygame.display.flip()
             
             if self.is_foreground:
         
         if app_path is None:
             # Restore pygame launcher menu
-            
             self.__handle_transition_animation(self.focused, self._main_menu, effect=1)
             
             self.focused.clear()
             return
         
         # Start the tween animation
-        blacksurf = make_surface(self.screen.get_size(), )
-        blacksurf.fill(BLACK)
-        e = Effects(self.screen, self.clock, self.focused.bg.surface, blacksurf,
+        #self.bganim.surface.fill(BLACK)
+        self.bganim.surface.set_alpha(255)
+        self.bg.surface.set_alpha(96)
+        e = Effects(self.screen, self.clock, self.focused.bg.surface, self.bganim.surface,
                     render_callback=None)
 
         # Blocks for the duration of the animation
-        effect = e.effectZoomOut
-        e.do((effect, e.tweenEaseInBack), 0.75)
+        effect =  [
+           (e.effectZoomOut, e.tweenEaseInBack),
+        ]
+        
+        e.do(effect, 0.5)
+        
+        # Fade the logo
+        self.bg.surface.fill(BLACK)
+        e = Effects(self.screen, self.clock, self.bganim.surface, self.bg.surface )
+        
+        # Blocks for the duration of the animation
+        e.do( [
+               (e.effectFadeTo, e.easeNone),
+               ], 0.5)
         
         # Remove so it won't flash at the end
         self.sprites.remove(self.focused)
         self.running = 0
     
     def __handle_transition_animation(self, menu1, menu2, effect):
-        bg1 = BackgroundTransparent(self.sysdata)
-        bg2 = BackgroundTransparent(self.sysdata)
-        menu1.bg = bg1
-        menu2.bg = bg2
         
-        def render_callback(surf): 
-            menu1.update()
-            menu2.update()
+        # We use the mainbg as temporary buffer during animation
+        self.mainbg.surface.set_alpha(255)
         
+        menu2.bg = self.bganim
+        menu1.update()
+        menu2.update()
+        
+        bg1 = menu1.bg
+        bg2 = menu2.bg
+        
+        # This makes the logo appear from behind
+        bg2.surface.set_alpha(96)
+        
+        #def render_callback(s):
+            # Make the logo appear on both
+            #menu2.bg.surface.fill(WHITE)
         # Start the tween animation
-        e = Effects(self.screen, self.clock, bg1.surface, bg2.surface,
-                    render_callback=render_callback)
+        e = Effects(self.screen, self.clock, bg1.surface, bg2.surface)#, render_callback)
         
         # Blocks for the duration of the animation
         effect = [e.effectSlideLeftReplace, e.effectSlideRightReplace, e.effectFadeTo][effect]
         menu2.bg = self.bg
         menu2.update()
         
-        bg1.surface.blit(bg2.surface, (0, 0))
+        # Restore the background logo
+        self.mainbg.draw()
         
     def mhApplications(self):
         """ Menu handler for 'Applications' item """
         self.sprites.remove(self.focused)
         
         # Create tween effect for transition
-        background = Background(self.sysdata)
-        
+        background = self.bganim
         menu = Menu(background, self.sysdata,
                         title="Applications",
                         items=items,
                         cancel_callback=(self.mhLaunchApplication, (None,)),
                         )
-        menu.textcache.max_size = 24
+        menu.textcache.max_size = 12
         menu.update()
+        
         self.__handle_transition_animation(self.focused, menu, effect=0)
         
         self.focused = menu
         """ Menu handler for exit item """
         self.running = 0
         
-        # Fade to black
-        black = make_surface(self.screen.get_size(), )
-        
+        # Fade to logo and then to black
         # Start the tween animation
-        e = Effects(self.screen, self.clock, self.bg.surface, black )
+        e = Effects(self.screen, self.clock, self.bg.surface, self.bganim.surface )
         
         # Blocks for the duration of the animation
         e.do( [
-               (e.effectFadeTo, e.tweenEaseOutSine),
-               (e.effectZoomOut, lambda t, b, c, d, s=3.70158:e.tweenEaseInBack(t,0,0.5,d,s)),
+               (e.effectFadeTo, e.easeNone),
+               ], 0.5)
+        
+        self.bg.surface.fill(BLACK)
+        e = Effects(self.screen, self.clock, self.bganim.surface, self.bg.surface )
+        
+        # Blocks for the duration of the animation
+        e.do( [
+               (e.effectFadeTo, e.easeNone),
                ], 0.5)
         
         self.focused = None
         """ Menu handler for settings item """
         
         self.sprites.remove(self.focused)
-        tf = TextField(self.bg, self.sysdata,
+        tf = TextField(self.bganim, self.sysdata,
                         exit_callback=self._exit_to_main,
                         title="Settings",
                         text="Begone! Nothing to see here!",
         
     def _exit_to_main(self):
         """ Callback to exit back to main menu """
-        
         self.__handle_transition_animation(self.focused, self._main_menu, effect=1)
         
         self.sprites.remove(self.focused)
         """
         
         self.sprites.remove(self.focused)
-        self.focused = TextField(self.bg.surface, self.sysdata,
+        self.focused = TextField(self.bganim, self.sysdata,
                         exit_callback=self._exit_to_main,
                         title="About",
                         text=text,