projects
/
minwii.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
log++ qq bugfixes.
[minwii.git]
/
src
/
app
/
widgets
/
instrumentselector.py
diff --git
a/src/app/widgets/instrumentselector.py
b/src/app/widgets/instrumentselector.py
index
6935e03
..
6861643
100755
(executable)
--- a/
src/app/widgets/instrumentselector.py
+++ b/
src/app/widgets/instrumentselector.py
@@
-10,6
+10,7
@@
import pygame
from eventutils import event_handler, EventDispatcher, EventHandlerMixin
from cursors import WarpingCursor
from config import FRAMERATE
from eventutils import event_handler, EventDispatcher, EventHandlerMixin
from cursors import WarpingCursor
from config import FRAMERATE
+from config import INSTRUMENTS
from globals import BACKGROUND_LAYER
from globals import FOREGROUND_LAYER
from globals import CURSOR_LAYER
from globals import BACKGROUND_LAYER
from globals import FOREGROUND_LAYER
from globals import CURSOR_LAYER
@@
-20,7
+21,7
@@
class InstrumentSelector(pygame.sprite.LayeredDirty, EventHandlerMixin) :
rows = 3
cols = 3
rows = 3
cols = 3
- instruments =
['accordeon', 'celesta', 'flute', 'guitare', 'orgue', 'piano', 'tuba', 'violon', 'violoncelle']
+ instruments =
INSTRUMENTS
def __init__(self) :
super(InstrumentSelector, self).__init__()
def __init__(self) :
super(InstrumentSelector, self).__init__()
@@
-28,6
+29,7
@@
class InstrumentSelector(pygame.sprite.LayeredDirty, EventHandlerMixin) :
self._initTiles()
self._initCursor()
self._inflatedTile = None
self._initTiles()
self._initCursor()
self._inflatedTile = None
+ self.selectedInstrument = None
def _initTiles(self) :
screen = pygame.display.get_surface()
def _initTiles(self) :
screen = pygame.display.get_surface()
@@
-35,11
+37,14
@@
class InstrumentSelector(pygame.sprite.LayeredDirty, EventHandlerMixin) :
tileHeight = int(round(float(screen.get_height()) / self.rows))
self.tiles = []
tileHeight = int(round(float(screen.get_height()) / self.rows))
self.tiles = []
- instrus =
self.instruments[:]
+ instrus =
list(self.instruments[:])
for y in range(self.cols) :
for x in range(self.rows) :
upperLeftCorner = (x * tileWidth, y * tileHeight)
rect = pygame.Rect(upperLeftCorner, (tileWidth, tileHeight))
for y in range(self.cols) :
for x in range(self.rows) :
upperLeftCorner = (x * tileWidth, y * tileHeight)
rect = pygame.Rect(upperLeftCorner, (tileWidth, tileHeight))
+ # !!! s'il y avait plus de 3x3 tuiles !!!, il faudrait alors
+ # changer le tuple (x,y) qui concerne le point d'application de l'homotétie.
+ # Cf. InstrumentTile.inflate
tile = InstrumentTile(instrus.pop(0), self, rect, (x,y))
self.add(tile, layer=BACKGROUND_LAYER)
self.tiles.append(tile)
tile = InstrumentTile(instrus.pop(0), self, rect, (x,y))
self.add(tile, layer=BACKGROUND_LAYER)
self.tiles.append(tile)
@@
-71,7
+76,6
@@
class InstrumentSelector(pygame.sprite.LayeredDirty, EventHandlerMixin) :
self.stop()
@event_handler(pygame.MOUSEMOTION)
self.stop()
@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) :
def onMouseMove(self, event) :
for tile in reversed(self.sprites()[:-1]) :
if tile.rect.collidepoint(*event.pos) :
@@
-89,6
+93,13
@@
class InstrumentSelector(pygame.sprite.LayeredDirty, EventHandlerMixin) :
self._inflatedTile = tile
self._inflatedTile = tile
+ @event_handler(pygame.MOUSEBUTTONDOWN)
+ def selectInstrument(self, event) :
+ for tile in reversed(self.sprites()[:-1]) :
+ if tile.rect.collidepoint(*event.pos) :
+ self.selectedInstrument = tile.instrumentDescription
+ self.stop()
+ break
@@
-105,14
+116,14
@@
class InstrumentTile(pygame.sprite.DirtySprite) :
BORDER = 10
INFLATE_ZOOM = 0.4
BORDER = 10
INFLATE_ZOOM = 0.4
- def __init__(self,
name
, group, rect, coords) :
+ def __init__(self,
instrumentDescription
, group, rect, coords) :
pygame.sprite.DirtySprite.__init__(self, group)
self.inflated = False
pygame.sprite.DirtySprite.__init__(self, group)
self.inflated = False
- self.
name = name
+ self.
instrumentDescription = instrumentDescription
self.rect = rect
self._baseRect = rect.copy()
self.coords = coords
self.rect = rect
self._baseRect = rect.copy()
self.coords = coords
- imagePath = InstrumentTile._get_instrument_image(
name
)
+ imagePath = InstrumentTile._get_instrument_image(
instrumentDescription['name']
)
self._img = pygame.image.load(imagePath)
self.update()
self._img = pygame.image.load(imagePath)
self.update()
@@
-122,7
+133,7
@@
class InstrumentTile(pygame.sprite.DirtySprite) :
innerSize = innerWidth, innerHeight
border = pygame.Surface(self.rect.size)
innerSize = innerWidth, innerHeight
border = pygame.Surface(self.rect.size)
- border.fill((0
,0,0
,255))
+ border.fill((0
xdd,0xdd,0xdd
,255))
bg = pygame.Surface(innerSize)
bg.fill((255,255,255,255))
bg = pygame.Surface(innerSize)
bg.fill((255,255,255,255))