From cb412c929228704c15124400e484fee4d672106e Mon Sep 17 00:00:00 2001 From: trigg Date: Mon, 3 Apr 2023 19:50:25 +0100 Subject: [PATCH] - Added option to hide avatars --- .gitignore | 1 + discover_overlay/discover_overlay.py | 1 + discover_overlay/glade/settings.glade | 36 ++++++++++++++++- discover_overlay/settings_window.py | 3 ++ discover_overlay/voice_overlay.py | 57 +++++++++++++++++---------- 5 files changed, 75 insertions(+), 23 deletions(-) diff --git a/.gitignore b/.gitignore index f607872..6db20c2 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ env __pycache__ venv .idea +discover_overlay/glade/settings.glade~ diff --git a/discover_overlay/discover_overlay.py b/discover_overlay/discover_overlay.py index 5b216d1..15532ba 100755 --- a/discover_overlay/discover_overlay.py +++ b/discover_overlay/discover_overlay.py @@ -272,6 +272,7 @@ class Discover: config.getint("main", "border_width", fallback=2)) self.voice_overlay.set_icon_transparency(config.getfloat( "main", "icon_transparency", fallback=1.0)) + self.voice_overlay.set_show_avatar(config.getboolean("main", "show_avatar", fallback=True)) self.voice_overlay.set_fancy_border(config.getboolean("main", "fancy_border", fallback=True)) self.voice_overlay.set_show_dummy(config.getboolean("main", diff --git a/discover_overlay/glade/settings.glade b/discover_overlay/glade/settings.glade index 65f8ef0..2daa2e0 100644 --- a/discover_overlay/glade/settings.glade +++ b/discover_overlay/glade/settings.glade @@ -136,7 +136,7 @@ 1 8 - + 0 360 0 @@ -701,7 +701,7 @@ - + voice_advanced_grid True @@ -1357,6 +1357,38 @@ 7 + + + voice_avatar_label + True + False + Show Avatar + + + 0 + 8 + + + + + voice_avatar + True + True + False + True + + + + 1 + 8 + + + + + + + + diff --git a/discover_overlay/settings_window.py b/discover_overlay/settings_window.py index 557fb86..32a8b00 100644 --- a/discover_overlay/settings_window.py +++ b/discover_overlay/settings_window.py @@ -906,6 +906,9 @@ class MainSettingsWindow(): self.config_set("main", "dummy_count", "%s" % (int(button.get_value()))) + def voice_show_avatar_changed(self, button): + self.config_set("main", "show_avatar", "%s" % (button.get_active())) + def text_enable_changed(self, button): self.config_set("text", "enabled", "%s" % (button.get_active())) diff --git a/discover_overlay/voice_overlay.py b/discover_overlay/voice_overlay.py index eb8db1e..b89e622 100644 --- a/discover_overlay/voice_overlay.py +++ b/discover_overlay/voice_overlay.py @@ -67,6 +67,7 @@ class VoiceOverlayWindow(OverlayWindow): 'lastspoken': random.randint(2000, 2100) if speaking else random.randint(10, 30), 'friendlyname': name, }) + self.show_avatar = True self.avatar_size = 48 self.nick_length = 32 self.text_pad = 6 @@ -154,6 +155,10 @@ class VoiceOverlayWindow(OverlayWindow): self.show_connection = show_connection self.needsredraw = True + def set_show_avatar(self, show_avatar): + self.show_avatar = show_avatar + self.needsredraw = True + def set_show_title(self, show_title): self.show_title = show_title self.needsredraw = True @@ -511,7 +516,8 @@ class VoiceOverlayWindow(OverlayWindow): users_to_draw.remove(self_user) users_to_draw.insert(0, self_user) - avatar_size = self.avatar_size + avatar_size = self.avatar_size if self.show_avatar else 0 + line_height = self.avatar_size avatars_per_row = sys.maxsize # Calculate height needed to show overlay @@ -525,7 +531,7 @@ class VoiceOverlayWindow(OverlayWindow): doTitle = True if self.horizontal: - needed_width = (len(users_to_draw) * self.avatar_size) + \ + needed_width = (len(users_to_draw) * line_height) + \ (len(users_to_draw) + 1) * self.icon_spacing if needed_width > width: @@ -550,7 +556,7 @@ class VoiceOverlayWindow(OverlayWindow): row.append(users_to_draw.pop(0)) rows_to_draw.append(row) for row in rows_to_draw: - needed_width = (len(row) * (avatar_size + self.icon_spacing)) + needed_width = (len(row) * (line_height + self.icon_spacing)) current_x = 0 + self.horz_edge_padding if self.align_vert == 1: current_x = (width / 2) - (needed_width) / 2 @@ -562,18 +568,18 @@ class VoiceOverlayWindow(OverlayWindow): if doTitle: doTitle = False text_width = self.draw_title( - context, current_x, current_y, avatar_size) + context, current_x, current_y, avatar_size, line_height) elif doConnection: text_width = self.draw_connection( - context, current_x, current_y, avatar_size) + context, current_x, current_y, avatar_size, line_height) doConnection = False else: self.draw_avatar(context, user, current_x, - current_y, avatar_size) + current_y, avatar_size, line_height) current_x += avatar_size + self.icon_spacing current_y += offset_y else: - needed_height = ((len(users_to_draw)+0) * self.avatar_size) + \ + needed_height = ((len(users_to_draw)+0) * line_height) + \ (len(users_to_draw) + 1) * self.icon_spacing if needed_height > height: @@ -593,6 +599,7 @@ class VoiceOverlayWindow(OverlayWindow): offset_x_mult = -1 current_x = self.width - avatar_size - self.horz_edge_padding + # Choose where to start drawing current_y = 0 + self.vert_edge_padding if self.align_vert == 1: @@ -607,7 +614,7 @@ class VoiceOverlayWindow(OverlayWindow): col.append(users_to_draw.pop(0)) cols_to_draw.append(col) for col in cols_to_draw: - needed_height = (len(col) * (avatar_size + self.icon_spacing)) + needed_height = (len(col) * (line_height + self.icon_spacing)) current_y = 0 + self.vert_edge_padding if self.align_vert == 1: current_y = (height/2) - (needed_height / 2) @@ -619,26 +626,26 @@ class VoiceOverlayWindow(OverlayWindow): if doTitle: # Draw header text_width = self.draw_title( - context, current_x, current_y, avatar_size) + context, current_x, current_y, avatar_size, line_height) largest_text_width = max( text_width, largest_text_width) - current_y += avatar_size + self.icon_spacing + current_y += line_height + self.icon_spacing doTitle = False elif doConnection: # Draw header text_width = self.draw_connection( - context, current_x, current_y, avatar_size) + context, current_x, current_y, avatar_size, line_height) largest_text_width = max( text_width, largest_text_width) - current_y += avatar_size + self.icon_spacing + current_y += line_height + self.icon_spacing doConnection = False else: text_width = self.draw_avatar( - context, user, current_x, current_y, avatar_size) + context, user, current_x, current_y, avatar_size, line_height) largest_text_width = max( text_width, largest_text_width) - current_y += avatar_size + self.icon_spacing + current_y += line_height + self.icon_spacing if largest_text_width > 0: largest_text_width += self.text_pad else: @@ -670,7 +677,7 @@ class VoiceOverlayWindow(OverlayWindow): if identifier in self.avatars: del self.avatars[identifier] - def draw_title(self, context, pos_x, pos_y, avatar_size): + def draw_title(self, context, pos_x, pos_y, avatar_size, line_height): """ Draw title at given Y position. Includes both text and image based on settings """ @@ -686,6 +693,7 @@ class VoiceOverlayWindow(OverlayWindow): self.text_col, self.norm_col, avatar_size, + line_height, self.title_font ) if self.channel_icon: @@ -710,7 +718,7 @@ class VoiceOverlayWindow(OverlayWindow): _("VOICE_CONNECTING") _("VOICE_CONNECTED") - def draw_connection(self, context, pos_x, pos_y, avatar_size): + def draw_connection(self, context, pos_x, pos_y, avatar_size, line_height): """ Draw title at given Y position. Includes both text and image based on settings """ @@ -723,18 +731,19 @@ class VoiceOverlayWindow(OverlayWindow): self.text_col, self.norm_col, avatar_size, + line_height, self.text_font ) self.blank_avatar(context, pos_x, pos_y, avatar_size) self.draw_connection_icon(context, pos_x, pos_y, avatar_size) return tw - def draw_avatar(self, context, user, pos_x, pos_y, avatar_size): + def draw_avatar(self, context, user, pos_x, pos_y, avatar_size, line_height): """ Draw avatar at given Y position. Includes both text and image based on settings """ # Ensure pixbuf for avatar - if user["id"] not in self.avatars and user["avatar"]: + if user["id"] not in self.avatars and user["avatar"] and avatar_size>0: url = "https://cdn.discordapp.com/avatars/%s/%s.png" % ( user['id'], user['avatar']) get_surface(self.recv_avatar, url, user["id"], @@ -778,6 +787,7 @@ class VoiceOverlayWindow(OverlayWindow): fg_col, bg_col, avatar_size, + line_height, self.text_font ) self.draw_avatar_pix(context, pix, mask, pos_x, @@ -790,7 +800,7 @@ class VoiceOverlayWindow(OverlayWindow): self.mute_bg_col, avatar_size) return tw - def draw_text(self, context, string, pos_x, pos_y, tx_col, bg_col, avatar_size, font): + def draw_text(self, context, string, pos_x, pos_y, tx_col, bg_col, avatar_size, line_height, font): """ Draw username & background at given position """ @@ -812,7 +822,7 @@ class VoiceOverlayWindow(OverlayWindow): text_width = logical_rect.width self.col(tx_col) - height_offset = (avatar_size / 2) - (text_height / 2) + height_offset = (line_height / 2) - (text_height / 2) text_y_offset = height_offset + self.text_baseline_adj if self.align_right: @@ -868,7 +878,8 @@ class VoiceOverlayWindow(OverlayWindow): """ Draw avatar image at given position """ - + if not self.show_avatar: + return # Empty the space for this self.blank_avatar(context, pos_x, pos_y, avatar_size) @@ -941,6 +952,8 @@ class VoiceOverlayWindow(OverlayWindow): """ Draw Mute logo """ + if avatar_size <= 0: + return context.save() context.translate(pos_x, pos_y) context.scale(avatar_size, avatar_size) @@ -1008,6 +1021,8 @@ class VoiceOverlayWindow(OverlayWindow): """ Draw deaf logo """ + if avatar_size <= 0: + return context.save() context.translate(pos_x, pos_y) context.scale(avatar_size, avatar_size)