From 898cc352cb6624da41e4befd97a07c99243433a4 Mon Sep 17 00:00:00 2001 From: pin Date: Mon, 22 Mar 2010 16:50:50 +0000 Subject: [PATCH] =?utf8?q?=C3=89cran=20de=20s=C3=A9lection=20des=20instrum?= =?utf8?q?ents=20beaucoup=20plus=20beau.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit git-svn-id: https://svn.cri.ensmp.fr/svn/minwii/trunk@105 fe552daf-6dbe-4428-90eb-1537e0879342 --- src/app/minwii.py | 13 +++--- src/app/widgets/instrumentselector.py | 67 +++++++++++++++++++-------- 2 files changed, 54 insertions(+), 26 deletions(-) diff --git a/src/app/minwii.py b/src/app/minwii.py index 6f277a7..56047ad 100755 --- a/src/app/minwii.py +++ b/src/app/minwii.py @@ -20,20 +20,21 @@ from config import SONG_FILE_PATH class MinWii(object): def __init__(self) : - app = Desktop() - synth = Synth() + #app = Desktop() + #synth = Synth() while True : - home = Home(songPath=SONG_FILE_PATH) - home.connect(QUIT, app.quit) - app.run(home) - app.close(home) + #home = Home(songPath=SONG_FILE_PATH) + #home.connect(QUIT, app.quit) + #app.run(home) + #app.close(home) selector = InstrumentSelector() selector.run() selector.stop() pygame.event.clear() EventDispatcher.reset() + break song = musicXml2Song(home.songFile, printNotes=True) synth.program_select(0, 0, 0) diff --git a/src/app/widgets/instrumentselector.py b/src/app/widgets/instrumentselector.py index 70654f6..6935e03 100755 --- a/src/app/widgets/instrumentselector.py +++ b/src/app/widgets/instrumentselector.py @@ -27,6 +27,7 @@ class InstrumentSelector(pygame.sprite.LayeredDirty, EventHandlerMixin) : #self._initRects() self._initTiles() self._initCursor() + self._inflatedTile = None def _initTiles(self) : screen = pygame.display.get_surface() @@ -69,8 +70,8 @@ class InstrumentSelector(pygame.sprite.LayeredDirty, EventHandlerMixin) : if event.key == pygame.K_q: self.stop() - #@event_handler(pygame.MOUSEMOTION) - @event_handler(pygame.MOUSEBUTTONDOWN) + @event_handler(pygame.MOUSEMOTION) + #@event_handler(pygame.MOUSEBUTTONDOWN) def onMouseMove(self, event) : for tile in reversed(self.sprites()[:-1]) : if tile.rect.collidepoint(*event.pos) : @@ -78,8 +79,16 @@ class InstrumentSelector(pygame.sprite.LayeredDirty, EventHandlerMixin) : break def raiseTileOver(self, tile) : - self.change_layer(tile, FOREGROUND_LAYER) - tile.inflate(tile.coords) + if not tile.inflated : + self.change_layer(tile, FOREGROUND_LAYER) + tile.inflate(tile.coords) + + if self._inflatedTile : + self._inflatedTile.deflate() + self.change_layer(self._inflatedTile, BACKGROUND_LAYER) + + self._inflatedTile = tile + @@ -94,19 +103,32 @@ class InstrumentTile(pygame.sprite.DirtySprite) : return os.path.sep.join(imagePath) BORDER = 10 - INFLATE_ZOOM = 0.25 + INFLATE_ZOOM = 0.4 def __init__(self, name, group, rect, coords) : pygame.sprite.DirtySprite.__init__(self, group) + self.inflated = False self.name = name self.rect = rect + self._baseRect = rect.copy() self.coords = coords - - + imagePath = InstrumentTile._get_instrument_image(name) + self._img = pygame.image.load(imagePath) + self.update() + + + def update(self) : innerWidth, innerHeight = [l-self.BORDER*2 for l in self.rect.size] + innerSize = innerWidth, innerHeight - imagePath = InstrumentTile._get_instrument_image(name) - img = pygame.image.load(imagePath) + border = pygame.Surface(self.rect.size) + border.fill((0,0,0,255)) + + bg = pygame.Surface(innerSize) + bg.fill((255,255,255,255)) + bgRect = pygame.Rect((self.BORDER, self.BORDER), innerSize) + + img = self._img iWidth, iHeight = img.get_size() imgRatio = float(iWidth) / iHeight @@ -118,31 +140,36 @@ class InstrumentTile(pygame.sprite.DirtySprite) : ih = innerHeight iw = int(round(innerHeight * imgRatio)) - position = ((innerWidth - iw) / 2 + self.BORDER, (innerHeight - ih) / 2 + self.BORDER) - + imgPosition = ((innerWidth - iw) / 2, (innerHeight - ih) / 2) + imgRect = pygame.Rect(imgPosition, (iw, ih)) img = pygame.transform.smoothscale(img, (iw, ih)) - bg = pygame.Surface(self.rect.size) - bg.fill((255,255,255,255)) - bg.blit(img, pygame.Rect(position, (iw, ih))) - - self.image = bg + bg.blit(img, imgRect) + border.blit(bg, bgRect) + self.image = border + def inflate(self, refPoint) : + self.inflated = True keep = {} for name in REF_POINTS[refPoint] : keep[name] = getattr(self.rect, name) self.rect.inflate_ip(*[l*self.INFLATE_ZOOM for l in self.rect.size]) - img = pygame.transform.smoothscale(self.image, self.rect.size) - self.image = img - for k, v in keep.items() : setattr(self.rect, k, v) + self.update() self.dirty = 1 - + + + def deflate(self) : + self.inflated = False + self.rect = self._baseRect.copy() + self.update() + self.dirty = 1 + REF_POINTS = { -- 2.20.1