From: pin Date: Fri, 19 Feb 2010 17:28:17 +0000 (+0000) Subject: Début de refactoring du curseur. X-Git-Url: https://scm.cri.ensmp.fr/git/minwii.git/commitdiff_plain/d8d786898468fe6b6065a626070593cc162f5171?ds=inline Début de refactoring du curseur. git-svn-id: https://svn.cri.ensmp.fr/svn/minwii/trunk@47 fe552daf-6dbe-4428-90eb-1537e0879342 --- diff --git a/src/app/widgets/cursors.py b/src/app/widgets/cursors.py new file mode 100755 index 0000000..2cbe4cc --- /dev/null +++ b/src/app/widgets/cursors.py @@ -0,0 +1,112 @@ +# -*- coding: utf-8 -*- +""" +Curseurs winwii + +$Id$ +$URL$ +""" + +import pygame +import os + + +class WarpingCursor(pygame.sprite.Sprite): + ''' + The class for animating the warping cursor + + durations: + The duration of each image in the animation + centerPosition: + The Position of the center of the cursor + _imagePointer: + A pointer to the current image + _animationOffset: + The time elapsed since when the current image should have been displayed + ''' + #screen = None + #images = None + #durations = None + #centerPosition = None + #_imagePointer = None + #_animationOffset = None + + @staticmethod + def _get_theme_images(name) : + basePath = os.path.abspath(__file__).split(os.path.sep)[:-1] + basePath.append('data') + basePath.append(name) + basePath = os.path.sep.join(basePath) + images = [f for f in os.listdir(basePath) if os.path.splitext(f)[1] == '.png'] + return basePath, images + + + def __init__(self, theme='black', duration=75): + pygame.sprite.Sprite.__init__(self) + imagesPath, images = WarpingCursor._get_theme_images(theme) + flashImage = images.pop(images.index('flash.png')) + images.sort(lambda a, b : cmp(*[int(os.path.splitext(f)[0]) for f in [a, b]])) + + self.images = [] + for img in images : + imagePath = os.path.sep.join([imagesPath, img]) + self.images = pygame.image.load(imagePath).convert_alpha() + + #self.flashImagePath = flashImage + #self.durations = durations + #self.centerPosition = initCenterPosition + #self.flashLength = 100 + #self.flashing = False + #self.image = pygame.image.load(self.images[0]).convert_alpha() + #self._imagePointer = 0 + #self._animationOffset = 0 + #self._flashTimer = 0 + + def update(self, elapsedTime, centerPosition): + ''' + Update the cursor's look and position + + elapsedTime: + The time passed since the previous update + centerPosition: + the new position of the creep + ''' + self._updateImage(elapsedTime) + self.centerPosition = centerPosition + if self.flashing : + self._flashTimer += elapsedTime + if self._flashTimer > self.flashLength: + self.flashing = False + + def _updateImage(self, elapsedTime): + ''' + Update the cursor's image + + elapsedTime: + The time passed since the previous update + ''' + self._animationOffset += elapsedTime + + if self._animationOffset > self.durations[self._imagePointer]: + #New animation offset is computed first, before updating the pointer + self._animationOffset -= self.durations[self._imagePointer] + #point to the next image (restarts from the beginning when it reaches the end) + self._imagePointer = (self._imagePointer + 1) % len(self.images) + + if self.flashing: + self.image = pygame.image.load(self.flashImagePath).convert_alpha() + else : + self.image = pygame.image.load(self.images[self._imagePointer]).convert_alpha() + + def flash(self,flashLength = None): + self._flashTimer = 0 + self.flashing = True + if flashLength: + self.flashlength = flashLength + + def blit(self,surface): + ''' + Draw the circle on surface + ''' + + newPos = (self.centerPosition[0] - self.image.get_width() / 2, self.centerPosition[1] - self.image.get_height() / 2) + surface.blit(self.image, newPos) diff --git a/src/app/widgets/data/black/0.png b/src/app/widgets/data/black/0.png new file mode 100755 index 0000000..d676349 Binary files /dev/null and b/src/app/widgets/data/black/0.png differ diff --git a/src/app/widgets/data/black/1.png b/src/app/widgets/data/black/1.png new file mode 100755 index 0000000..7703e89 Binary files /dev/null and b/src/app/widgets/data/black/1.png differ diff --git a/src/app/widgets/data/black/10.png b/src/app/widgets/data/black/10.png new file mode 100755 index 0000000..6c85004 Binary files /dev/null and b/src/app/widgets/data/black/10.png differ diff --git a/src/app/widgets/data/black/2.png b/src/app/widgets/data/black/2.png new file mode 100755 index 0000000..9eec08e Binary files /dev/null and b/src/app/widgets/data/black/2.png differ diff --git a/src/app/widgets/data/black/3.png b/src/app/widgets/data/black/3.png new file mode 100755 index 0000000..ce93f45 Binary files /dev/null and b/src/app/widgets/data/black/3.png differ diff --git a/src/app/widgets/data/black/4.png b/src/app/widgets/data/black/4.png new file mode 100755 index 0000000..7c9d191 Binary files /dev/null and b/src/app/widgets/data/black/4.png differ diff --git a/src/app/widgets/data/black/5.png b/src/app/widgets/data/black/5.png new file mode 100755 index 0000000..34b149d Binary files /dev/null and b/src/app/widgets/data/black/5.png differ diff --git a/src/app/widgets/data/black/6.png b/src/app/widgets/data/black/6.png new file mode 100755 index 0000000..d118680 Binary files /dev/null and b/src/app/widgets/data/black/6.png differ diff --git a/src/app/widgets/data/black/7.png b/src/app/widgets/data/black/7.png new file mode 100755 index 0000000..68ec2dd Binary files /dev/null and b/src/app/widgets/data/black/7.png differ diff --git a/src/app/widgets/data/black/8.png b/src/app/widgets/data/black/8.png new file mode 100755 index 0000000..c938fe9 Binary files /dev/null and b/src/app/widgets/data/black/8.png differ diff --git a/src/app/widgets/data/black/9.png b/src/app/widgets/data/black/9.png new file mode 100755 index 0000000..e5e4f09 Binary files /dev/null and b/src/app/widgets/data/black/9.png differ diff --git a/src/app/widgets/data/black/cursorBlack.svg b/src/app/widgets/data/black/cursorBlack.svg new file mode 100755 index 0000000..7c3c9b4 --- /dev/null +++ b/src/app/widgets/data/black/cursorBlack.svg @@ -0,0 +1,99 @@ + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/src/app/widgets/data/black/flash.png b/src/app/widgets/data/black/flash.png new file mode 100644 index 0000000..412cbce Binary files /dev/null and b/src/app/widgets/data/black/flash.png differ diff --git a/src/app/widgets/data/blue/0.png b/src/app/widgets/data/blue/0.png new file mode 100644 index 0000000..9535e33 Binary files /dev/null and b/src/app/widgets/data/blue/0.png differ diff --git a/src/app/widgets/data/blue/1.png b/src/app/widgets/data/blue/1.png new file mode 100644 index 0000000..894e8c4 Binary files /dev/null and b/src/app/widgets/data/blue/1.png differ diff --git a/src/app/widgets/data/blue/10.png b/src/app/widgets/data/blue/10.png new file mode 100644 index 0000000..8ef30f7 Binary files /dev/null and b/src/app/widgets/data/blue/10.png differ diff --git a/src/app/widgets/data/blue/2.png b/src/app/widgets/data/blue/2.png new file mode 100644 index 0000000..5dcd4a9 Binary files /dev/null and b/src/app/widgets/data/blue/2.png differ diff --git a/src/app/widgets/data/blue/3.png b/src/app/widgets/data/blue/3.png new file mode 100644 index 0000000..e547688 Binary files /dev/null and b/src/app/widgets/data/blue/3.png differ diff --git a/src/app/widgets/data/blue/4.png b/src/app/widgets/data/blue/4.png new file mode 100644 index 0000000..0fb1d9d Binary files /dev/null and b/src/app/widgets/data/blue/4.png differ diff --git a/src/app/widgets/data/blue/5.png b/src/app/widgets/data/blue/5.png new file mode 100644 index 0000000..6f3b35a Binary files /dev/null and b/src/app/widgets/data/blue/5.png differ diff --git a/src/app/widgets/data/blue/6.png b/src/app/widgets/data/blue/6.png new file mode 100644 index 0000000..7ca3eb6 Binary files /dev/null and b/src/app/widgets/data/blue/6.png differ diff --git a/src/app/widgets/data/blue/7.png b/src/app/widgets/data/blue/7.png new file mode 100644 index 0000000..0a2033b Binary files /dev/null and b/src/app/widgets/data/blue/7.png differ diff --git a/src/app/widgets/data/blue/8.png b/src/app/widgets/data/blue/8.png new file mode 100644 index 0000000..c75055c Binary files /dev/null and b/src/app/widgets/data/blue/8.png differ diff --git a/src/app/widgets/data/blue/9.png b/src/app/widgets/data/blue/9.png new file mode 100644 index 0000000..f013e60 Binary files /dev/null and b/src/app/widgets/data/blue/9.png differ diff --git a/src/app/widgets/data/blue/cursorBlue.svg b/src/app/widgets/data/blue/cursorBlue.svg new file mode 100644 index 0000000..34c72b0 --- /dev/null +++ b/src/app/widgets/data/blue/cursorBlue.svg @@ -0,0 +1,99 @@ + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/src/app/widgets/data/green/0.png b/src/app/widgets/data/green/0.png new file mode 100644 index 0000000..a601813 Binary files /dev/null and b/src/app/widgets/data/green/0.png differ diff --git a/src/app/widgets/data/green/1.png b/src/app/widgets/data/green/1.png new file mode 100644 index 0000000..a0343a6 Binary files /dev/null and b/src/app/widgets/data/green/1.png differ diff --git a/src/app/widgets/data/green/10.png b/src/app/widgets/data/green/10.png new file mode 100644 index 0000000..a57da5e Binary files /dev/null and b/src/app/widgets/data/green/10.png differ diff --git a/src/app/widgets/data/green/2.png b/src/app/widgets/data/green/2.png new file mode 100644 index 0000000..3c611a1 Binary files /dev/null and b/src/app/widgets/data/green/2.png differ diff --git a/src/app/widgets/data/green/3.png b/src/app/widgets/data/green/3.png new file mode 100644 index 0000000..75169da Binary files /dev/null and b/src/app/widgets/data/green/3.png differ diff --git a/src/app/widgets/data/green/4.png b/src/app/widgets/data/green/4.png new file mode 100644 index 0000000..19b9062 Binary files /dev/null and b/src/app/widgets/data/green/4.png differ diff --git a/src/app/widgets/data/green/5.png b/src/app/widgets/data/green/5.png new file mode 100644 index 0000000..f0d521c Binary files /dev/null and b/src/app/widgets/data/green/5.png differ diff --git a/src/app/widgets/data/green/6.png b/src/app/widgets/data/green/6.png new file mode 100644 index 0000000..9732994 Binary files /dev/null and b/src/app/widgets/data/green/6.png differ diff --git a/src/app/widgets/data/green/7.png b/src/app/widgets/data/green/7.png new file mode 100644 index 0000000..8c77ca7 Binary files /dev/null and b/src/app/widgets/data/green/7.png differ diff --git a/src/app/widgets/data/green/8.png b/src/app/widgets/data/green/8.png new file mode 100644 index 0000000..a2a97a7 Binary files /dev/null and b/src/app/widgets/data/green/8.png differ diff --git a/src/app/widgets/data/green/9.png b/src/app/widgets/data/green/9.png new file mode 100644 index 0000000..b950aa1 Binary files /dev/null and b/src/app/widgets/data/green/9.png differ diff --git a/src/app/widgets/data/green/cursorGreen.svg b/src/app/widgets/data/green/cursorGreen.svg new file mode 100644 index 0000000..34e8bc6 --- /dev/null +++ b/src/app/widgets/data/green/cursorGreen.svg @@ -0,0 +1,99 @@ + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/src/app/widgets/data/red/0.png b/src/app/widgets/data/red/0.png new file mode 100644 index 0000000..839bc89 Binary files /dev/null and b/src/app/widgets/data/red/0.png differ diff --git a/src/app/widgets/data/red/1.png b/src/app/widgets/data/red/1.png new file mode 100644 index 0000000..7124ee3 Binary files /dev/null and b/src/app/widgets/data/red/1.png differ diff --git a/src/app/widgets/data/red/10.png b/src/app/widgets/data/red/10.png new file mode 100644 index 0000000..e4323c2 Binary files /dev/null and b/src/app/widgets/data/red/10.png differ diff --git a/src/app/widgets/data/red/2.png b/src/app/widgets/data/red/2.png new file mode 100644 index 0000000..7df10de Binary files /dev/null and b/src/app/widgets/data/red/2.png differ diff --git a/src/app/widgets/data/red/3.png b/src/app/widgets/data/red/3.png new file mode 100644 index 0000000..3088b82 Binary files /dev/null and b/src/app/widgets/data/red/3.png differ diff --git a/src/app/widgets/data/red/4.png b/src/app/widgets/data/red/4.png new file mode 100644 index 0000000..8e7549d Binary files /dev/null and b/src/app/widgets/data/red/4.png differ diff --git a/src/app/widgets/data/red/5.png b/src/app/widgets/data/red/5.png new file mode 100644 index 0000000..a18a1a4 Binary files /dev/null and b/src/app/widgets/data/red/5.png differ diff --git a/src/app/widgets/data/red/6.png b/src/app/widgets/data/red/6.png new file mode 100644 index 0000000..6a6c2af Binary files /dev/null and b/src/app/widgets/data/red/6.png differ diff --git a/src/app/widgets/data/red/7.png b/src/app/widgets/data/red/7.png new file mode 100644 index 0000000..865f580 Binary files /dev/null and b/src/app/widgets/data/red/7.png differ diff --git a/src/app/widgets/data/red/8.png b/src/app/widgets/data/red/8.png new file mode 100644 index 0000000..785a4b1 Binary files /dev/null and b/src/app/widgets/data/red/8.png differ diff --git a/src/app/widgets/data/red/9.png b/src/app/widgets/data/red/9.png new file mode 100644 index 0000000..e4c9758 Binary files /dev/null and b/src/app/widgets/data/red/9.png differ diff --git a/src/app/widgets/data/red/cursorRed.svg b/src/app/widgets/data/red/cursorRed.svg new file mode 100644 index 0000000..54f5fc0 --- /dev/null +++ b/src/app/widgets/data/red/cursorRed.svg @@ -0,0 +1,99 @@ + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/src/app/widgets/playingscreen.py b/src/app/widgets/playingscreen.py index 955a3ab..055ed71 100755 --- a/src/app/widgets/playingscreen.py +++ b/src/app/widgets/playingscreen.py @@ -23,9 +23,9 @@ ON_SATURATION = 1 ON_COLUMN_OVERSIZING = 1.5 -def rename_method(newName) : +def event_handler(eventType) : def doRename(m) : - m.__name__ = newName + m.__name__ = 'eventHandler%s' % eventType return m return doRename @@ -113,7 +113,7 @@ class _PlayingScreenBase(pygame.sprite.OrderedUpdates) : handler = getattr(self, 'eventHandler%s' % event.type, lambda e:None) handler(event) - @rename_method('eventHandler%s' % pygame.KEYDOWN) + @event_handler(pygame.KEYDOWN) def handleKeyDown(self, event) : if event.key == pygame.K_q: self._running = False @@ -121,6 +121,9 @@ class _PlayingScreenBase(pygame.sprite.OrderedUpdates) : if uni.isdigit() and int(uni) <=8 : self.highlightColumn(int(uni)) + + @event_handler(pygame.MOUSEMOTION) + def handleMouseMotion(self, event) :