1 # -*- coding: utf-8 -*-
3 bande qui compose le clavier minwii
10 import minwii
.gradients
as gradients
11 from minwii
.globals import BACKGROUND_LAYER
12 from minwii
.globals import FOREGROUND_LAYER
13 from minwii
.globals import hls_to_rgba_8bits
14 from minwii
.config
import OFF_LUMINANCE
15 from minwii
.config
import OFF_SATURATION
16 from minwii
.config
import ON_TOP_LUMINANCE
17 from minwii
.config
import ON_BOTTOM_LUMINANCE
18 from minwii
.config
import ON_SATURATION
19 from minwii
.config
import ON_COLUMN_OVERSIZING
20 from minwii
.config
import ON_COLUMN_ALPHA
21 from minwii
.config
import LYRICS_FONT
, NOTES_FONT
22 from minwii
.config
import FONT_COLOR
23 import minwii
.events
as events
26 class Column(pygame
.sprite
.DirtySprite
) :
27 ''' colonne utilisée pour l'affichage d'une touche du clavier de jeu.
30 def __init__(self
, group
, index
, hue
, rect
, tone
, displayNote
=True) :
31 pygame
.sprite
.DirtySprite
.__init
__(self
, group
)
37 toneName
= NOTES_FONT
.render(tone
.nom
, True, FONT_COLOR
)
39 # état off : surface unie et nom de l'intonation
40 sur
= pygame
.surface
.Surface(rect
.size
)
41 rgba
= hls_to_rgba_8bits(hue
, OFF_LUMINANCE
, OFF_SATURATION
)
44 tw
, th
, = toneName
.get_size()
45 toneRect
= pygame
.Rect(((w
- tw
) / 2, h
- th
), (tw
, th
))
47 sur
.blit(toneName
, toneRect
)
52 # état on : surface dégradée avec nom de la note avec largeur agrandie
53 topRgba
= hls_to_rgba_8bits(hue
, ON_TOP_LUMINANCE
, ON_SATURATION
, ON_COLUMN_ALPHA
)
54 bottomRgba
= hls_to_rgba_8bits(hue
, ON_BOTTOM_LUMINANCE
, ON_SATURATION
, ON_COLUMN_ALPHA
)
55 onWidth
= rect
.width
* ON_COLUMN_OVERSIZING
56 onLeft
= rect
.centerx
- onWidth
/ 2
57 rectOn
= pygame
.Rect((onLeft
, 0),
58 (onWidth
, rect
.height
))
59 self
.surOn
= gradients
.vertical(rectOn
.size
, topRgba
, bottomRgba
)
60 w
, h
= rectOn
.w
, rectOn
.h
61 toneRect
= pygame
.Rect(((w
- tw
) / 2, h
- th
), (tw
, th
))
63 self
.surOn
.blit(toneName
, toneRect
)
66 self
.image
= self
.surOff
69 def update(self
, state
, syllabus
='') :
70 group
= self
.groups()[0]
71 if state
== self
.state
:
75 group
.change_layer(self
, FOREGROUND_LAYER
)
80 renderedSyl
= LYRICS_FONT
.render(syllabus
, True, FONT_COLOR
)
81 sw
, sh
, = renderedSyl
.get_size()
82 w
, h
= self
.rectOn
.w
, self
.rectOn
.h
84 if sw
> self
.rectOn
.w
:
85 sur
= pygame
.transform
.scale(sur
, (sw
, h
))
86 rect
= rect
.inflate(sw
- w
, 0)
89 screenWidth
= group
.dispWidth
92 elif rect
.right
> screenWidth
:
93 rect
.right
= screenWidth
95 sylRect
= pygame
.Rect(((w
- sw
) / 2, (h
- sh
) / 2), (sw
, sh
))
96 sur
.blit(renderedSyl
, sylRect
)
101 group
.change_layer(self
, BACKGROUND_LAYER
)
102 self
.image
= self
.surOff
103 self
.rect
= self
.rectOff
108 evt
= pygame
.event
.Event(events
.COLSTATECHANGE
, column
=self
, state
=state
, syllabus
=syllabus
)
109 pygame
.event
.post(evt
)