1 # -*- coding: utf-8 -*-
3 Écran de sélection de l'instrument
9 from eventutils
import event_handler
, EventDispatcher
, EventHandlerMixin
10 from cursors
import WarpingCursor
11 from config
import FRAMERATE
12 from globals import BACKGROUND_LAYER
13 from globals import CURSOR_LAYER
14 from globals import hls_to_rgba_8bits
17 class InstrumentSelector(pygame
.sprite
.LayeredDirty
, EventHandlerMixin
) :
23 super(InstrumentSelector
, self
).__init
__()
28 def _initRects(self
) :
29 screen
= pygame
.display
.get_surface()
30 tileWidth
= int(round(float(screen
.get_width()) / self
.cols
))
31 tileHeight
= int(round(float(screen
.get_height()) / self
.rows
))
34 for y
in range(self
.cols
) :
35 for x
in range(self
.rows
) :
36 upperLeftCorner
= (y
* tileWidth
, x
* tileHeight
)
37 rect
= pygame
.Rect(upperLeftCorner
, (tileWidth
, tileHeight
))
41 def _initTiles(self
) :
42 for rect
in self
.rects
:
43 tile
= InstrumentTile(self
, rect
)
44 self
.add(tile
, layer
=BACKGROUND_LAYER
)
48 def _initCursor(self
) :
49 self
.cursor
= WarpingCursor(blinkMode
=True)
50 self
.add(self
.cursor
, layer
=CURSOR_LAYER
)
55 clock
= pygame
.time
.Clock()
57 pygame
.mouse
.set_visible(False)
59 EventDispatcher
.dispatchEvents()
60 dirty
= self
.draw(pygame
.display
.get_surface())
61 pygame
.display
.update(dirty
)
66 pygame
.mouse
.set_visible(True)
67 self
.cursor
._stopBlink
()
69 @event_handler(pygame
.KEYDOWN
)
70 def handleKeyDown(self
, event
) :
71 if event
.key
== pygame
.K_q
:
75 class InstrumentTile(pygame
.sprite
.DirtySprite
) :
77 def __init__(self
, group
, rect
) :
78 pygame
.sprite
.DirtySprite
.__init
__(self
, group
)
80 self
.image
= pygame
.Surface(rect
.size
)
81 self
.image
.fill((0,255,255,64))