Skip to content

Commit

Permalink
Background blur
Browse files Browse the repository at this point in the history
  • Loading branch information
9and3r committed Jul 12, 2015
1 parent ca7f010 commit 61d1f40
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 13 deletions.
32 changes: 27 additions & 5 deletions mopidy_touchscreen/graphic_utils/background_manager.py
@@ -1,5 +1,6 @@
import pygame


change_speed = 2


Expand Down Expand Up @@ -30,12 +31,12 @@ def set_background_image(self, image):
if image is not None:
image_size = get_aspect_scale_size(image, self.size)
target = pygame.transform.smoothscale(image, image_size)
target.set_alpha(150)
self.image_loaded = True
self.surface_image.fill((0, 0, 0))
pos = ((self.size[0] - image_size[0])/2,
(self.size[1] - image_size[1])/2)
self.surface_image.blit(target, pos)
pos = (int((self.size[0] - image_size[0])/2),
(int(self.size[1] - image_size[1])/2))
self.surface_image.blit(blur_surf_times(
target, self.size[0]/40, 10), pos)
self.image_loaded = True
else:
self.image_loaded = False
self.update = True
Expand All @@ -51,3 +52,24 @@ def get_aspect_scale_size(img, new_size):
aspect = aspect_y
new_size = (int(aspect*size[0]), int(aspect*size[1]))
return new_size


def blur_surf_times(surface, amt, times):
for i in range(times):
surface = blur_surf(surface, amt)
return surface


# http://www.akeric.com/blog/?p=720
def blur_surf(surface, amt):
"""
Blur the given surface by the given 'amount'. Only values 1 and greater
are valid. Value 1 = no blur.
"""

scale = 1.0/float(amt)
surf_size = surface.get_size()
scale_size = (int(surf_size[0]*scale), int(surf_size[1]*scale))
surf = pygame.transform.smoothscale(surface, scale_size)
surf = pygame.transform.smoothscale(surf, surf_size)
return surf
2 changes: 1 addition & 1 deletion mopidy_touchscreen/screen_manager.py
Expand Up @@ -49,9 +49,9 @@ def __init__(self, size, core, cache, resolution_factor):

def init_manager(self, size):
self.size = size
self.base_size = self.size[1] / self.resolution_factor

self.background = DynamicBackground(self.size)
self.base_size = self.size[1] / self.resolution_factor
font = resource_filename(
Requirement.parse("mopidy-touchscreen"),
"mopidy_touchscreen/icomoon.ttf")
Expand Down
14 changes: 7 additions & 7 deletions mopidy_touchscreen/screens/main_screen.py
Expand Up @@ -103,7 +103,7 @@ def update(self, screen, update_type, rects):
progress.set_value(track_pos_millis)
self.current_track_pos = new_track_pos
progress.set_text(
time.strftime('%M:%S', time.gmtime(
time.strftime('%M:%S', time.gmtime(
self.current_track_pos)) +
"/" + self.track_duration)
progress.render(screen)
Expand Down Expand Up @@ -139,16 +139,16 @@ def track_started(self, track):

# Progress
progress = Progressbar(self.fonts['base'],
time.strftime('%M:%S', time.gmtime(
0)) + "/" + time.strftime(
time.strftime('%M:%S', time.gmtime(
0)) + "/" + time.strftime(
'%M:%S', time.gmtime(0)),
(size_1, self.size[1] - self.base_size * 2),
(
(size_1, self.size[1] - self.base_size * 2),
(
self.size[0] - size_1 - size_2,
self.base_size),
track.length, False)
track.length, False)
self.touch_text_manager.set_touch_object("time_progress",
progress)
progress)
self.progress_show = True
else:
self.progress_show = False
Expand Down

0 comments on commit 61d1f40

Please sign in to comment.