From: pin Date: Tue, 23 Feb 2010 13:10:52 +0000 (+0000) Subject: modification de la boucle principale pour mettre à jour l'affichage un respectant... X-Git-Url: https://scm.cri.ensmp.fr/git/minwii.git/commitdiff_plain/1949ce08d8bd0e485280de3039c1c103522d7c2d?ds=sidebyside modification de la boucle principale pour mettre à jour l'affichage un respectant mieux les guidelines de pygame. git-svn-id: https://svn.cri.ensmp.fr/svn/minwii/trunk@54 fe552daf-6dbe-4428-90eb-1537e0879342 --- diff --git a/src/app/widgets/cursors.py b/src/app/widgets/cursors.py index 6b0d6e8..3ac9c43 100755 --- a/src/app/widgets/cursors.py +++ b/src/app/widgets/cursors.py @@ -10,7 +10,7 @@ import pygame import os from eventutils import EventHandlerMixin, event_handler from itertools import cycle -from pygame.locals import MOUSEBUTTONDOWN, MOUSEBUTTONUP, USEREVENT +from pygame.locals import USEREVENT TIMEOUT = USEREVENT + 1 class WarpingCursor(pygame.sprite.Sprite, EventHandlerMixin): @@ -30,6 +30,7 @@ class WarpingCursor(pygame.sprite.Sprite, EventHandlerMixin): def __init__(self, theme='black', duration=75, blink=True): pygame.sprite.Sprite.__init__(self) + pygame.mouse.set_visible(False) imagesPath, images = WarpingCursor._get_theme_images(theme) flashImage = images.pop(images.index('flash.png')) flashImagePath = os.path.sep.join([imagesPath, flashImage]) @@ -49,7 +50,6 @@ class WarpingCursor(pygame.sprite.Sprite, EventHandlerMixin): self.image = self.images[0] self.rect = pygame.Rect((0,0), (self.width, self.height)) - self.update() self.blink = blink if blink : @@ -67,19 +67,20 @@ class WarpingCursor(pygame.sprite.Sprite, EventHandlerMixin): def loadNext(self, event) : if self.blink : self.image = self.iterator.next() - self.update() - @event_handler(MOUSEBUTTONDOWN) + @event_handler(pygame.MOUSEBUTTONDOWN) def flashOn(self, event) : self.blink=False self.image = self.flashImage - self.update() - @event_handler(MOUSEBUTTONUP) + @event_handler(pygame.MOUSEBUTTONUP) def flashOff(self, event) : self.blink = True self.loadNext(event) - - def update(self) : - surface = pygame.display.get_surface() - surface.blit(self.image, self.rect) + + @event_handler(pygame.MOUSEMOTION) + def move(self, event) : + x, y = event.rel + self.rect.centerx += x + self.rect.centery += y + #self.rect.move_ip(*rel) diff --git a/src/app/widgets/playingscreen.py b/src/app/widgets/playingscreen.py index 248f0bb..146e549 100755 --- a/src/app/widgets/playingscreen.py +++ b/src/app/widgets/playingscreen.py @@ -15,7 +15,7 @@ from math import floor import types # TODO : positionner cette constance en fonction de la résolution d'affichage # externaliser la conf. -BORDER = 5 # 5px +BORDER = 0 # 5px FIRST_HUE = 0.6 OFF_LUMINANCE = 0.2 OFF_SATURATION = 1 @@ -32,7 +32,6 @@ class _PlayingScreenBase(pygame.sprite.OrderedUpdates, EventHandlerMixin) : distinctNotes : notes disctinctes présentes dans la chanson triées du plus grave au plus aigu. """ - print '__init__ _PlayingScreenBase' super(_PlayingScreenBase, self).__init__() self.distinctNotes = distinctNotes self.keyboardLength = 0 @@ -82,7 +81,7 @@ class _PlayingScreenBase(pygame.sprite.OrderedUpdates, EventHandlerMixin) : def _initCursor(self) : self.cursor = WarpingCursor() - #self.add(self.cursor) + self.add(self.cursor) def highlightColumn(self, index) : @@ -93,9 +92,11 @@ class _PlayingScreenBase(pygame.sprite.OrderedUpdates, EventHandlerMixin) : def run(self): self._running = True clock = pygame.time.Clock() + pygame.display.flip() while self._running : - pygame.display.flip() EventDispatcher.dispatchEvents() + dirty = self.draw(pygame.display.get_surface()) + pygame.display.update(dirty) clock.tick(50) @event_handler(pygame.KEYDOWN) @@ -122,7 +123,6 @@ class SongPlayingScreen(_PlayingScreenBase) : class SongPlayingScreenTest(_PlayingScreenBase) : def __init__(self) : - print '__init__ SongPlayingScreenTest' class C:pass o = C() o.midi=1