1 # -*- coding: utf-8 -*-
3 bande qui compose le clavier minwii
10 import minwii
.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
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
) :
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
))
46 sur
.blit(toneName
, toneRect
)
51 # état on : surface dégradée avec nom de la note avec largeur agrandie
52 topRgba
= hls_to_rgba_8bits(hue
, ON_TOP_LUMINANCE
, ON_SATURATION
, ON_COLUMN_ALPHA
)
53 bottomRgba
= hls_to_rgba_8bits(hue
, ON_BOTTOM_LUMINANCE
, ON_SATURATION
, ON_COLUMN_ALPHA
)
54 onWidth
= rect
.width
* ON_COLUMN_OVERSIZING
55 onLeft
= rect
.centerx
- onWidth
/ 2
56 rectOn
= pygame
.Rect((onLeft
, 0),
57 (onWidth
, rect
.height
))
58 self
.surOn
= gradients
.vertical(rectOn
.size
, topRgba
, bottomRgba
)
59 w
, h
= rectOn
.w
, rectOn
.h
60 toneRect
= pygame
.Rect(((w
- tw
) / 2, h
- th
), (tw
, th
))
61 self
.surOn
.blit(toneName
, toneRect
)
64 self
.image
= self
.surOff
67 def update(self
, state
, syllabus
='') :
68 group
= self
.groups()[0]
69 if state
== self
.state
:
73 group
.change_layer(self
, FOREGROUND_LAYER
)
78 renderedSyl
= LYRICS_FONT
.render(syllabus
, True, FONT_COLOR
)
79 sw
, sh
, = renderedSyl
.get_size()
80 w
, h
= self
.rectOn
.w
, self
.rectOn
.h
82 if sw
> self
.rectOn
.w
:
83 sur
= pygame
.transform
.scale(sur
, (sw
, h
))
84 rect
= rect
.inflate(sw
- w
, 0)
87 screenWidth
= group
.dispWidth
90 elif rect
.right
> screenWidth
:
91 rect
.right
= screenWidth
93 sylRect
= pygame
.Rect(((w
- sw
) / 2, (h
- sh
) / 2), (sw
, sh
))
94 sur
.blit(renderedSyl
, sylRect
)
99 group
.change_layer(self
, BACKGROUND_LAYER
)
100 self
.image
= self
.surOff
101 self
.rect
= self
.rectOff
106 evt
= pygame
.event
.Event(events
.COLSTATECHANGE
, column
=self
, state
=state
, syllabus
=syllabus
)
107 pygame
.event
.post(evt
)