From 4e554a248ac04a8058027cb84788bc63ec856a66 Mon Sep 17 00:00:00 2001 From: Ander <9and3r@gmail.com> Date: Fri, 9 Jan 2015 22:43:55 +0100 Subject: [PATCH] Background image --- mopidy_touchscreen/dynamic_background.py | 17 +++++++++++++++-- mopidy_touchscreen/main_screen.py | 2 +- mopidy_touchscreen/screen_manager.py | 4 +++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/mopidy_touchscreen/dynamic_background.py b/mopidy_touchscreen/dynamic_background.py index 253246a..0c031b2 100644 --- a/mopidy_touchscreen/dynamic_background.py +++ b/mopidy_touchscreen/dynamic_background.py @@ -2,11 +2,15 @@ import random change_speed = 2 +import pygame + class DynamicBackground(): - def __init__(self): + def __init__(self, size): + self.size = size self.current = get_valid_color() self.target = get_valid_color() + self.surface = None def draw_background(self, surface): same = True @@ -23,9 +27,18 @@ class DynamicBackground(): #if same: # self.target = get_valid_color() surface.fill(self.current) + if self.surface is not None: + surface.blit(self.surface,(0,0)) - def set_target_color(self, color): + def set_target_color(self, color, surface): self.target = [color[0], color[1], color[2]] + #irudi = pygame.Surface(surface.get_size()) + #pygame.transform.laplacian(surface, irudi) + irudi = surface + target = pygame.Surface(self.size) + pygame.transform.smoothscale(irudi, self.size, target) + target.set_alpha(80) + self.surface = target # Returns an array with 3 integers in range of 0-255 diff --git a/mopidy_touchscreen/main_screen.py b/mopidy_touchscreen/main_screen.py index b64287d..c9bbf95 100644 --- a/mopidy_touchscreen/main_screen.py +++ b/mopidy_touchscreen/main_screen.py @@ -278,7 +278,7 @@ class MainScreen(BaseScreen): self.get_cover_folder() + self.get_image_file_name()).convert(), (size, size)) - self.background.set_target_color(pygame.transform.average_color(image)) + self.background.set_target_color(pygame.transform.average_color(image), image) self.image = image diff --git a/mopidy_touchscreen/screen_manager.py b/mopidy_touchscreen/screen_manager.py index b478a02..69d9ddf 100644 --- a/mopidy_touchscreen/screen_manager.py +++ b/mopidy_touchscreen/screen_manager.py @@ -29,13 +29,15 @@ class ScreenManager(): self.core = core self.cache = cache self.fonts = {} - self.background = DynamicBackground() + self.background = DynamicBackground(size) self.current_screen = library_index self.init_manager(size) def init_manager(self, size): self.size = size + self.background = DynamicBackground(self.size) + self.current_screen = 0 self.base_size = self.size[1] / 8 font = resource_filename( Requirement.parse("mopidy-touchscreen"),