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 FONT
22 from config
import FONT_COLOR
25 class Column(pygame
.sprite
.DirtySprite
) :
27 def __init__(self
, group
, hue
, rect
, tone
, atBorder
) :
28 pygame
.sprite
.DirtySprite
.__init
__(self
, group
)
33 toneName
= FONT
.render(tone
.nom
, True, FONT_COLOR
)
35 # état off : surface unie et nom de l'intonation
36 sur
= pygame
.surface
.Surface(rect
.size
)
37 rgba
= hls_to_rgba_8bits(hue
, OFF_LUMINANCE
, OFF_SATURATION
)
40 tw
, th
, = toneName
.get_size()
41 toneRect
= pygame
.Rect(((w
- tw
) / 2, h
- th
), (tw
, th
))
42 sur
.blit(toneName
, toneRect
)
47 # état on : surface dégradée avec nom de la note avec largeur agrandie
48 topRgba
= hls_to_rgba_8bits(hue
, ON_TOP_LUMINANCE
, ON_SATURATION
, ON_COLUMN_ALPHA
)
49 bottomRgba
= hls_to_rgba_8bits(hue
, ON_BOTTOM_LUMINANCE
, ON_SATURATION
, ON_COLUMN_ALPHA
)
50 onWidth
= rect
.width
* ON_COLUMN_OVERSIZING
51 onLeft
= rect
.centerx
- onWidth
/ 2
52 rectOn
= pygame
.Rect((onLeft
, 0),
53 (onWidth
, rect
.height
))
55 self
.atBorder
= atBorder
57 setattr(rectOn
, self
.atBorder
, getattr(rect
, self
.atBorder
))
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
))
62 self
.surOn
.blit(toneName
, toneRect
)
65 self
.image
= self
.surOff
68 def update(self
, state
, syllabus
='') :
69 group
= self
.groups()[0]
70 if state
== self
.state
:
74 group
.change_layer(self
, FOREGROUND_LAYER
)
79 renderedSyl
= FONT
.render(syllabus
, True, FONT_COLOR
)
80 sw
, sh
, = renderedSyl
.get_size()
81 w
, h
= self
.rectOn
.w
, self
.rectOn
.h
83 if sw
> self
.rectOn
.w
:
84 sur
= pygame
.transform
.scale(sur
, (sw
, h
))
85 rect
= rect
.inflate(sw
- w
, 0)
87 setattr(rect
, self
.atBorder
, getattr(self
.rectOn
, self
.atBorder
))
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