X-Git-Url: https://svn.cri.ensmp.fr/git/minwii.git/blobdiff_plain/2b9d34e4fd258c988ccb7796d918fdf40f4d9937..fdafbd41faa31dc4d3ffccbe8583db770f08d546:/src/app/widgets/playingscreen.py diff --git a/src/app/widgets/playingscreen.py b/src/app/widgets/playingscreen.py index f65d8e5..1bf002c 100755 --- a/src/app/widgets/playingscreen.py +++ b/src/app/widgets/playingscreen.py @@ -7,8 +7,17 @@ $Id$ $URL$ """ import pygame +from colorsys import hls_to_rgb +from gradients import gradients # TODO : positionner cette constance en fonction de la résolution d'affichage +# externaliser la conf. BORDER = 5 # 5px +FIRST_HUE = 0.6 +OFF_LUMINANCE = 0.1 +OFF_SATURATION = 1 +ON_TOP_LUMINANCE = 0.9 +ON_BOTTOM_LUMINANCE = 0.6 +ON_SATURATION = 1 class _PlayingScreenBase(object) : def __init__(self, distinctNotes=[]) : @@ -17,6 +26,7 @@ class _PlayingScreenBase(object) : triées du plus grave au plus aigu. """ self.distinctNotes = distinctNotes + self.keyboardLength = 0 self.keyboardRects = [] self._initRects() self.drawColumns() @@ -28,9 +38,9 @@ class _PlayingScreenBase(object) : """ ambitus = self.distinctNotes[-1].midi - self.distinctNotes[0].midi if ambitus <= 12 : - keyboardLength = 8 + self.keyboardLength = 8 else : - keyboardLength = 11 + self.keyboardLength = 11 screen = pygame.display.get_surface() @@ -38,15 +48,22 @@ class _PlayingScreenBase(object) : dispWidth = screen.get_width() - 2 * BORDER dispHeight = screen.get_height() - 2 * BORDER - columnWidth = int(round(float(dispWidth) / keyboardLength)) + columnWidth = int(round(float(dispWidth) / self.keyboardLength)) rects = [] - for i in range(keyboardLength) : + for i in range(self.keyboardLength) : upperLeftCorner = (i*columnWidth + BORDER, BORDER) rect = pygame.Rect(upperLeftCorner, (columnWidth, dispHeight)) rects.append(rect) self.keyboardRects = rects + + def _initColumns(self) : + + hueStep = FIRST_HUE / (self.keyboardLength - 1) + for i, rect in enumerate(self.keyboardRects) : + hue = FIRST_HUE - hueStep * i + c = Column(hue) def drawColumns(self) : @@ -59,12 +76,22 @@ class _PlayingScreenBase(object) : class SongPlayingScreen(_PlayingScreenBase) : def __init__(self, song) : - super(SongPlayingScreen, self).__init__(song.) + super(SongPlayingScreen, self).__init__(song.distinctNotes) self.song = song class Column(pygame.sprite.Sprite) : - def __init__(self, color) : - pass \ No newline at end of file + def __init__(self, hue, rect) : + pygame.sprite.Sprite.__init__(self) + sur = Surface(rect.size) + rgba = hls_to_rgb(hue, OFF_LUMINANCE, OFF_SATURATION) + (255,) + sur.fill(rgba) + self.stateOff = sur + + topRgba = hls_to_rgb(hue, ON_TOP_LUMINANCE, ON_SATURATION) + (255,) + bottomRgba = hls_to_rgb(hue, ON_BOTTOM_LUMINANCE, ON_SATURATION) + (255,) + size = rect.inflate(2*rect.width,0).size + self.stateOn = gradients.vertical(size, topRgba, bottomRgba) + \ No newline at end of file