projects
/
minwii.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Écran de sélection des instruments beaucoup plus beau.
[minwii.git]
/
src
/
app
/
widgets
/
instrumentselector.py
diff --git
a/src/app/widgets/instrumentselector.py
b/src/app/widgets/instrumentselector.py
index
70654f6
..
6935e03
100755
(executable)
--- 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._initRects()
self._initTiles()
self._initCursor()
+ self._inflatedTile = None
def _initTiles(self) :
screen = pygame.display.get_surface()
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()
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) :
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) :
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
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)
def __init__(self, name, group, rect, coords) :
pygame.sprite.DirtySprite.__init__(self, group)
+ self.inflated = False
self.name = name
self.rect = rect
self.name = name
self.rect = rect
+ self._baseRect = rect.copy()
self.coords = coords
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]
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
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))
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))
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) :
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])
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)
for k, v in keep.items() :
setattr(self.rect, k, v)
+ self.update()
self.dirty = 1
self.dirty = 1
-
+
+
+ def deflate(self) :
+ self.inflated = False
+ self.rect = self._baseRect.copy()
+ self.update()
+ self.dirty = 1
+
REF_POINTS = {
REF_POINTS = {