Background transition

This commit is contained in:
9and3r
2015-07-12 11:21:58 +02:00
parent 61d1f40d9b
commit 9828f10c31
2 changed files with 32 additions and 15 deletions

View File

@@ -12,13 +12,23 @@ class DynamicBackground:
self.surface = pygame.Surface(self.size).convert()
self.surface.fill((145, 16, 16))
self.surface_image = pygame.Surface(self.size).convert()
self.surface_image.fill((145, 16, 16))
self.surface_image_last = pygame.Surface(self.size).convert()
self.update = True
self.screen_change_percent = 100
def draw_background(self):
if self.image_loaded:
return self.surface_image.copy()
else:
return self.surface.copy()
if self.screen_change_percent < 255:
self.surface.fill((0, 0, 0))
self.surface_image_last.set_alpha(
255 - self.screen_change_percent)
self.surface_image.set_alpha(self.screen_change_percent)
self.surface.blit(self.surface_image_last, (0, 0))
self.surface.blit(self.surface_image, (0, 0))
self.screen_change_percent += 5
self.update = True
return self.surface.copy()
def should_update(self):
if self.update:
@@ -31,14 +41,13 @@ class DynamicBackground:
if image is not None:
image_size = get_aspect_scale_size(image, self.size)
target = pygame.transform.smoothscale(image, image_size)
self.surface_image.fill((0, 0, 0))
self.surface_image_last = self.surface_image.copy()
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.screen_change_percent = 0
self.image_loaded = True
else:
self.image_loaded = False
self.update = True

View File

@@ -85,15 +85,28 @@ class MainScreen(BaseScreen):
def update(self, screen, update_type, rects):
if update_type == BaseScreen.update_all:
screen.blit(self.top_bar, (0, 0))
self.update_progress(screen, rects)
self.touch_text_manager.render(screen)
if self.image is not None:
screen.blit(self.image, (
self.base_size / 2, self.base_size +
self.base_size / 2))
elif update_type == BaseScreen.update_partial \
if update_type == BaseScreen.update_partial \
and self.track is not None:
if self.progress_show:
progress = self.update_progress(screen, rects)
if progress is not None:
progress.render(screen)
rects.append(progress.rect_in_pos)
for key in self.update_keys:
object = self.touch_text_manager.get_object(key)
object.update()
object.render(screen)
rects.append(object.rect_in_pos)
def update_progress(self, screen, rects):
if self.progress_show:
track_pos_millis = self.core.playback.time_position.get()
new_track_pos = track_pos_millis / 1000
@@ -106,13 +119,8 @@ class MainScreen(BaseScreen):
time.strftime('%M:%S', time.gmtime(
self.current_track_pos)) +
"/" + self.track_duration)
progress.render(screen)
rects.append(progress.rect_in_pos)
for key in self.update_keys:
object = self.touch_text_manager.get_object(key)
object.update()
object.render(screen)
rects.append(object.rect_in_pos)
return progress
return None
def track_started(self, track):
self.update_keys = []