31266c8d59a241fe6f2daa3e71bb05332fb5473b
1 # -*- coding: utf-8 -*-
3 bande qui compose le clavier minwii
9 from gradients
import gradients
10 from math
import floor
11 from globals import BACKGROUND_LAYER
12 from globals import FOREGROUND_LAYER
13 from globals import hls_to_rgba_8bits
14 from config
import OFF_LUMINANCE
15 from config
import OFF_SATURATION
16 from config
import ON_TOP_LUMINANCE
17 from config
import ON_BOTTOM_LUMINANCE
18 from config
import ON_SATURATION
19 from config
import ON_COLUMN_OVERSIZING
20 from config
import ON_COLUMN_ALPHA
21 from config
import LYRICS_FONT
, NOTES_FONT
22 from config
import FONT_COLOR
26 class Column(pygame
.sprite
.DirtySprite
) :
28 def __init__(self
, group
, hue
, rect
, tone
) :
29 pygame
.sprite
.DirtySprite
.__init
__(self
, group
)
34 toneName
= NOTES_FONT
.render(tone
.nom
, True, FONT_COLOR
)
36 # état off : surface unie et nom de l'intonation
37 sur
= pygame
.surface
.Surface(rect
.size
)
38 rgba
= hls_to_rgba_8bits(hue
, OFF_LUMINANCE
, OFF_SATURATION
)
41 tw
, th
, = toneName
.get_size()
42 toneRect
= pygame
.Rect(((w
- tw
) / 2, h
- th
), (tw
, th
))
43 sur
.blit(toneName
, toneRect
)
48 # état on : surface dégradée avec nom de la note avec largeur agrandie
49 topRgba
= hls_to_rgba_8bits(hue
, ON_TOP_LUMINANCE
, ON_SATURATION
, ON_COLUMN_ALPHA
)
50 bottomRgba
= hls_to_rgba_8bits(hue
, ON_BOTTOM_LUMINANCE
, ON_SATURATION
, ON_COLUMN_ALPHA
)
51 onWidth
= rect
.width
* ON_COLUMN_OVERSIZING
52 onLeft
= rect
.centerx
- onWidth
/ 2
53 rectOn
= pygame
.Rect((onLeft
, 0),
54 (onWidth
, rect
.height
))
55 self
.surOn
= gradients
.vertical(rectOn
.size
, topRgba
, bottomRgba
)
56 w
, h
= rectOn
.w
, rectOn
.h
57 toneRect
= pygame
.Rect(((w
- tw
) / 2, h
- th
), (tw
, th
))
58 self
.surOn
.blit(toneName
, toneRect
)
61 self
.image
= self
.surOff
64 def update(self
, state
, syllabus
='') :
65 group
= self
.groups()[0]
66 if state
== self
.state
:
70 group
.change_layer(self
, FOREGROUND_LAYER
)
75 renderedSyl
= LYRICS_FONT
.render(syllabus
, True, FONT_COLOR
)
76 sw
, sh
, = renderedSyl
.get_size()
77 w
, h
= self
.rectOn
.w
, self
.rectOn
.h
79 if sw
> self
.rectOn
.w
:
80 sur
= pygame
.transform
.scale(sur
, (sw
, h
))
81 rect
= rect
.inflate(sw
- w
, 0)
84 screenWidth
= group
.dispWidth
87 elif rect
.right
> screenWidth
:
88 rect
.right
= screenWidth
90 sylRect
= pygame
.Rect(((w
- sw
) / 2, (h
- sh
) / 2), (sw
, sh
))
91 sur
.blit(renderedSyl
, sylRect
)
96 group
.change_layer(self
, BACKGROUND_LAYER
)
97 self
.image
= self
.surOff
98 self
.rect
= self
.rectOff
103 evt
= pygame
.event
.Event(events
.COLSTATECHANGE
, col
=self
, state
=state
, syllabus
=syllabus
)
104 pygame
.event
.post(evt
)