aboutsummaryrefslogtreecommitdiff
path: root/helpers/key.py
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2016-06-19 21:31:54 +0200
committerIsmaël Bouya <ismael.bouya@normalesup.org>2016-06-19 21:31:54 +0200
commitb86db9f1679c855c2d39a0b116f846d271271a2c (patch)
tree3795bc88bd0fafda718248541d14b2529a1bd406 /helpers/key.py
parentba9ea93a0f52178d24a606fddc2acc5dc85b7ff2 (diff)
downloadMusicSampler-b86db9f1679c855c2d39a0b116f846d271271a2c.tar.gz
MusicSampler-b86db9f1679c855c2d39a0b116f846d271271a2c.tar.zst
MusicSampler-b86db9f1679c855c2d39a0b116f846d271271a2c.zip
Add pirate example config.yml + description
Diffstat (limited to 'helpers/key.py')
-rw-r--r--helpers/key.py38
1 files changed, 33 insertions, 5 deletions
diff --git a/helpers/key.py b/helpers/key.py
index 6997e70..9a6cb3b 100644
--- a/helpers/key.py
+++ b/helpers/key.py
@@ -18,7 +18,8 @@ class Key:
18 lighter_outer_color = (200, 200, 200) 18 lighter_outer_color = (200, 200, 200)
19 default_inner_color = (255, 255, 255) 19 default_inner_color = (255, 255, 255)
20 mapped_inner_color = ( 0, 255, 0) 20 mapped_inner_color = ( 0, 255, 0)
21 mapped_unready_inner_color = (255, 165, 0) 21 mapped_unready_inner_color = ( 0, 255, 0, 100)
22 #mapped_unready_inner_color = (255, 165, 0)
22 23
23 def __init__(self, mapping, draw_lock, key_name, key_sym, top, left, width = 48, height = 48, disabled = False): 24 def __init__(self, mapping, draw_lock, key_name, key_sym, top, left, width = 48, height = 48, disabled = False):
24 self.draw_lock = draw_lock 25 self.draw_lock = draw_lock
@@ -50,13 +51,16 @@ class Key:
50 51
51 self.inner_color = self.default_inner_color 52 self.inner_color = self.default_inner_color
52 self.actions = [] 53 self.actions = []
54 self.description = []
55 self.custom_color = None
56 self.custom_unready_color = None
53 57
54 def square(self, all_actions_ready): 58 def square(self, all_actions_ready):
55 if self.has_actions(): 59 if self.has_actions():
56 if all_actions_ready: 60 if all_actions_ready:
57 self.inner_color = self.mapped_inner_color 61 self.inner_color = self.custom_color or self.mapped_inner_color
58 else: 62 else:
59 self.inner_color = self.mapped_unready_inner_color 63 self.inner_color = self.custom_unready_color or self.mapped_unready_inner_color
60 64
61 return RoundedRect((0, 0, self.width, self.height), 65 return RoundedRect((0, 0, self.width, self.height),
62 self.outer_color, self.inner_color, self.linewidth) 66 self.outer_color, self.inner_color, self.linewidth)
@@ -67,6 +71,14 @@ class Key:
67 position[1] - self.position[1] 71 position[1] - self.position[1]
68 ) 72 )
69 73
74 def set_description(self, description):
75 self.description = description
76
77 def set_color(self, color):
78 self.custom_color = tuple(color)
79 color.append(100)
80 self.custom_unready_color = tuple(color)
81
70 def draw(self, background_surface): 82 def draw(self, background_surface):
71 self.draw_lock.acquire() 83 self.draw_lock.acquire()
72 all_actions_ready = self.all_actions_ready() 84 all_actions_ready = self.all_actions_ready()
@@ -75,11 +87,27 @@ class Key:
75 87
76 if getattr(sys, 'frozen', False): 88 if getattr(sys, 'frozen', False):
77 police = pygame.font.Font(sys._MEIPASS + "/Ubuntu-Regular.ttf", 14) 89 police = pygame.font.Font(sys._MEIPASS + "/Ubuntu-Regular.ttf", 14)
90 text_police = pygame.font.Font(sys._MEIPASS + "/Ubuntu-Regular.ttf", 10)
78 else: 91 else:
79 police = pygame.font.Font("Ubuntu-Regular.ttf", 14) 92 police = pygame.font.Font("Ubuntu-Regular.ttf", 14)
93 text_police = pygame.font.Font("Ubuntu-Regular.ttf", 10)
80 94
95 police.set_bold(True)
81 text = police.render(self.key_sym, True, (0,0,0)) 96 text = police.render(self.key_sym, True, (0,0,0))
82 self.surface.blit(text, (5,5)) 97 self.surface.blit(text, (5,5))
98
99 is_first_line = True
100 offset = 11 + text_police.get_linesize()
101 first_line_offset = 18
102 for description in self.description:
103 text = text_police.render(description, True, (0,0,0))
104 if is_first_line:
105 self.surface.blit(text, (first_line_offset, 9))
106 is_first_line = False
107 else:
108 self.surface.blit(text, (5, offset))
109 offset += text_police.get_linesize()
110
83 background_surface.blit(self.surface, self.position) 111 background_surface.blit(self.surface, self.position)
84 self.draw_lock.release() 112 self.draw_lock.release()
85 113
@@ -114,8 +142,8 @@ class Key:
114 142
115 def list_actions(self, screen): 143 def list_actions(self, screen):
116 action_descriptions = [action.description() for action in self.actions] 144 action_descriptions = [action.description() for action in self.actions]
117 print("actions linked to key {}:".format(self.key_sym)) 145 #print("actions linked to key {}:".format(self.key_sym))
118 print("\t" + "\n\t".join(action_descriptions)) 146 #print("\t" + "\n\t".join(action_descriptions))
119 self.draw_lock.acquire() 147 self.draw_lock.acquire()
120 surface = pygame.Surface((800, 250)).convert() 148 surface = pygame.Surface((800, 250)).convert()
121 surface.fill((250, 250, 250)) 149 surface.fill((250, 250, 250))