mirror of
https://github.com/Febbweiss/mopidy-touchscreen.git
synced 2026-03-05 06:35:43 +00:00
Dynamic background fixes and avoid too bright colors
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import random
|
import random
|
||||||
|
import logging
|
||||||
|
|
||||||
change_speed = 2
|
change_speed = 2
|
||||||
|
|
||||||
@@ -7,26 +8,50 @@ class DynamicBackground():
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.current = get_valid_color()
|
self.current = get_valid_color()
|
||||||
self.target = get_valid_color()
|
self.target = get_valid_color()
|
||||||
|
self.auto_mode = True
|
||||||
|
self.target_current_same = False
|
||||||
|
|
||||||
def draw_background(self, surface):
|
def draw_background(self, surface):
|
||||||
same = True
|
if not self.target_current_same:
|
||||||
for x in range(0, 3):
|
for x in range(0, 3):
|
||||||
if abs(self.current[x]-self.target[x]) < change_speed:
|
if abs(self.current[x]-self.target[x]) < change_speed:
|
||||||
self.current[x] = self.target[x]
|
self.current[x] = self.target[x]
|
||||||
else:
|
self.target_current_same = True
|
||||||
if self.current[x] > self.target[x]:
|
else:
|
||||||
self.current[x] -= change_speed
|
self.target_current_same = False
|
||||||
elif self.current[x] < self.target[x]:
|
if self.current[x] > self.target[x]:
|
||||||
self.current[x] += change_speed
|
self.current[x] -= change_speed
|
||||||
if self.current != self.target:
|
elif self.current[x] < self.target[x]:
|
||||||
same = False
|
self.current[x] += change_speed
|
||||||
#if same:
|
if self.auto_mode and self.target_current_same:
|
||||||
# self.target = get_valid_color()
|
self.target = get_valid_color()
|
||||||
|
self.target_current_same = False
|
||||||
surface.fill(self.current)
|
surface.fill(self.current)
|
||||||
|
|
||||||
def set_target_color(self, color):
|
def set_target_color(self, color):
|
||||||
self.target = [color[0], color[1], color[2]]
|
if color is not None:
|
||||||
|
self.target = get_similar_valid_color(color)
|
||||||
|
self.auto_mode = False
|
||||||
|
self.target_current_same = False
|
||||||
|
else:
|
||||||
|
self.auto_mode = True
|
||||||
|
self.target = get_valid_color()
|
||||||
|
self.target_current_same = False
|
||||||
|
|
||||||
|
# It will return the same color if sum is less than 510
|
||||||
|
# Otherwise a darker color will be returned
|
||||||
|
# White text should be seen ok with this background color
|
||||||
|
|
||||||
|
def get_similar_valid_color(color):
|
||||||
|
sum = color[0] + color[1] + color[2]
|
||||||
|
new_color = [0, 0, 0]
|
||||||
|
if sum > 510:
|
||||||
|
rest = (sum - 510)/3 + 1
|
||||||
|
for x in range(0,3):
|
||||||
|
new_color[x] = color[x] - rest
|
||||||
|
return new_color
|
||||||
|
else:
|
||||||
|
return color
|
||||||
|
|
||||||
# Returns an array with 3 integers in range of 0-255
|
# Returns an array with 3 integers in range of 0-255
|
||||||
# The sum of the three integers will be lower than 255*2
|
# The sum of the three integers will be lower than 255*2
|
||||||
|
|||||||
@@ -246,13 +246,8 @@ class MainScreen(BaseScreen):
|
|||||||
self.touch_text_manager.set_touch_object("artist_name", current)
|
self.touch_text_manager.set_touch_object("artist_name", current)
|
||||||
|
|
||||||
def track_playback_ended(self, tl_track, time_position):
|
def track_playback_ended(self, tl_track, time_position):
|
||||||
if self.image is not None:
|
self.background.set_target_color(None)
|
||||||
self.dirty_area.append(pygame.Rect(self.base_size / 2,
|
self.image = None
|
||||||
self.base_size + self.base_size / 2,
|
|
||||||
self.image.get_rect().width,
|
|
||||||
self.image.get_rect().height))
|
|
||||||
self.image = None
|
|
||||||
|
|
||||||
self.track_duration = "00:00"
|
self.track_duration = "00:00"
|
||||||
|
|
||||||
width = self.size[0] - self.base_size
|
width = self.size[0] - self.base_size
|
||||||
|
|||||||
Reference in New Issue
Block a user