]>
git.immae.eu Git - perso/Immae/Projets/Python/MusicSampler.git/blob - helpers/rounded_rect.py
4 def __init__(self
, rect
, outer_color
, inner_color
, linewidth
= 2, radius
= 0.4):
5 self
.rect
= pygame
.Rect(rect
)
6 self
.outer_color
= pygame
.Color(*outer_color
)
7 self
.inner_color
= pygame
.Color(*inner_color
)
8 self
.linewidth
= linewidth
12 rectangle
= self
.filledRoundedRect(self
.rect
, self
.outer_color
, self
.radius
)
14 inner_rect
= pygame
.Rect((
15 self
.rect
.left
+ 2 * self
.linewidth
,
16 self
.rect
.top
+ 2 * self
.linewidth
,
17 self
.rect
.right
- 2 * self
.linewidth
,
18 self
.rect
.bottom
- 2 * self
.linewidth
21 inner_rectangle
= self
.filledRoundedRect(inner_rect
, self
.inner_color
, self
.radius
)
23 rectangle
.blit(inner_rectangle
, (self
.linewidth
, self
.linewidth
))
27 def filledRoundedRect(self
, rect
, color
, radius
=0.4):
29 filledRoundedRect(rect,color,radius=0.4)
33 radius : 0 <= radius <= 1
40 rectangle
= pygame
.Surface(rect
.size
,pygame
.SRCALPHA
)
42 circle
= pygame
.Surface([min(rect
.size
)*3]*2,pygame
.SRCALPHA
)
43 pygame
.draw
.ellipse(circle
,(0,0,0),circle
.get_rect(),0)
44 circle
= pygame
.transform
.smoothscale(circle
,[int(min(rect
.size
)*radius
)]*2)
46 radius
= rectangle
.blit(circle
,(0,0))
47 radius
.bottomright
= rect
.bottomright
48 rectangle
.blit(circle
,radius
)
49 radius
.topright
= rect
.topright
50 rectangle
.blit(circle
,radius
)
51 radius
.bottomleft
= rect
.bottomleft
52 rectangle
.blit(circle
,radius
)
54 rectangle
.fill((0,0,0),rect
.inflate(-radius
.w
,0))
55 rectangle
.fill((0,0,0),rect
.inflate(0,-radius
.h
))
57 rectangle
.fill(color
,special_flags
=pygame
.BLEND_RGBA_MAX
)
58 rectangle
.fill((255,255,255,alpha
),special_flags
=pygame
.BLEND_RGBA_MIN
)