[Slim-Checkins] r8840 - in /trunk/server/Slim: Buttons/Block.pm Display/Lib/Fonts.pm

adrian at svn.slimdevices.com adrian at svn.slimdevices.com
Sun Aug 6 12:13:50 PDT 2006


Author: adrian
Date: Sun Aug  6 12:13:48 2006
New Revision: 8840

URL: http://svn.slimdevices.com?rev=8840&view=rev
Log:
Bug: N/A
Description: Support custom font for the animated symbol shown while
in block mode.  Cycles through all characters in one of following fonts:
SB2 - blockanimateSB2.1, SBG - blockanimateSBG.1
If font file is not present will show old spinning '-'

Modified:
    trunk/server/Slim/Buttons/Block.pm
    trunk/server/Slim/Display/Lib/Fonts.pm

Modified: trunk/server/Slim/Buttons/Block.pm
URL: http://svn.slimdevices.com/trunk/server/Slim/Buttons/Block.pm?rev=8840&r1=8839&r2=8840&view=diff
==============================================================================
--- trunk/server/Slim/Buttons/Block.pm (original)
+++ trunk/server/Slim/Buttons/Block.pm Sun Aug  6 12:13:48 2006
@@ -6,15 +6,14 @@
 # version 2.
 
 use strict;
-use File::Spec::Functions qw(:ALL);
-use File::Spec::Functions qw(updir);
 use Slim::Utils::Timers;
 use Slim::Utils::Misc;
 use Slim::Buttons::Common;
 
-my $ticklength = .25;            # length of each tick, seconds
-my $tickdelay  = .5;              # wait half a second before starting the display update
+my $ticklength = .2;            # length of each tick, seconds
+my $tickdelay  =  2;            # number of updates before animation appears
 my @tickchars  = ('|','/','-','\\');
+
 our %functions  = ();
 
 # Don't do this at compile time - not at run time
@@ -30,6 +29,7 @@
 sub setMode {
 	my $client = shift;
 	$client->lines(\&lines);
+	$client->modeParam('modeUpdateInterval', $ticklength) unless ($client->blocklines()->{'static'});
 }
 
 sub block {
@@ -44,8 +44,10 @@
 		$parts = $client->parseLines([$line1,$line2]);
 	}
 
-	my $blockName = shift;     # associate name with blocked mode
-	my $staticDisplay = shift; # turn off animation
+	my $blockName = shift;  # associate name with blocked mode
+	my $static = shift;     # turn off animation
+
+	$client->blocklines( { 'static' => $static, 'parts' => $parts, 'ticks' => 0 } );
 
 	Slim::Buttons::Common::pushMode($client,'block');
 	$client->modeParam('block.name', $blockName);
@@ -53,50 +55,79 @@
 	if (defined $parts) {
 		$client->showBriefly($parts);
 	}
-
-	if ($staticDisplay) {
-		# turn off animation to suppress animation characters if updated is called whilst in this mode
-		$parts->{static} = 1;
-	} else {
-		# animate after .5 sec
-		Slim::Utils::Timers::setTimer($client, Time::HiRes::time()+$tickdelay, \&updateBlockedStatus);
-	}
-
-	$client->blocklines($parts);
-}
-
-sub updateBlockedStatus {
-	my $client = shift || die;
-
-	$client->update();
-
-	Slim::Utils::Timers::setTimer($client, Time::HiRes::time()+$ticklength, \&updateBlockedStatus);
 }
 
 sub unblock {
 	my $client = shift;
-	Slim::Utils::Timers::killTimers($client, \&updateBlockedStatus);
 	Slim::Buttons::ScreenSaver::wakeup($client);
 	if (Slim::Buttons::Common::mode($client) eq 'block') {
 		Slim::Buttons::Common::popMode($client);
 	}
 }
 
+# Display blocked lines with animation in overlay [unless static display specified]
+
 sub lines {
 	my $client = shift;
-	
-	my $pos = int(Time::HiRes::time() / $ticklength) % (@tickchars);
 
-	my $parts = $client->blocklines();
-	
-	if (!$parts->{static}) {
-		if (!defined($parts->{fonts}) && $client->linesPerScreen == 1) {
-			$parts->{overlay}[1] = $tickchars[$pos];
-		} else {
-			$parts->{overlay}[0] = $tickchars[$pos];
+	my $bdata = $client->blocklines();
+	my $parts = $bdata->{'parts'};
+
+	if ($bdata->{'static'}) { return $parts };
+
+	if ($bdata->{'ticks'} < $tickdelay) {
+		$bdata->{'ticks'}++;
+		return $parts;
+	}
+
+	# create state for graphics animation if it does not exist - do it here so only done when animation starts
+	unless (defined $bdata->{'pos'}) {
+		
+		if ($client->display->isa('Slim::Display::Graphics')) {
+			# For graphics players animation cycles through characters in one of the following fonts:
+			# SB2 - blockanimateSB2.1, SBG - blockanimateSBG.1
+			my $vfd = $client->display->vfdmodel(); 
+			my $model = $vfd eq 'graphic-320x32' ? 'SB2' : 'SBG';
+			my $font = "blockanimate$model.1";
+			my $chars = Slim::Display::Lib::Fonts::fontchars($font);
+
+			$bdata->{'vfd'} = $vfd;
+			$bdata->{'chars'} = $chars ? $chars - 1 : ($font = undef);
+			
+			if ($parts->{'fonts'} && $parts->{'fonts'}->{"$vfd"} && ref $parts->{'fonts'}->{"$vfd"} ne 'HASH') {
+				# expand font definition so we can redefine one component only
+				my $basefont = $parts->{'fonts'}->{"$vfd"};
+				my $sfonts = $parts->{'fonts'}->{"$vfd"} = {};
+				foreach my $c (qw(line overlay center)) {
+					foreach my $l (0..$client->display->renderCache()->{'maxLine'}) {
+						$sfonts->{"$c"}[$l] = $basefont . "." . ( $l + 1 );
+					}
+				}
+			}
+			
+			$parts->{'fonts'}->{"$vfd"}->{'overlay'}[0] = $font;
+			
 		}
+		
+		$bdata->{'pos'} = -1;
+		
 	}
 	
+	if ($bdata->{'chars'}) {
+		
+		my $pos = ($bdata->{'pos'} + 1) % $bdata->{'chars'};
+		my $vfd = $bdata->{'vfd'};
+		$bdata->{'pos'} = $pos;
+		$parts->{'overlay'}[0] = chr($pos + 1);
+		
+	} else {
+		
+		my $pos = int(Time::HiRes::time() / $ticklength) % (@tickchars);
+		
+		$parts->{overlay}[0] = $tickchars[$pos];
+		
+	}
+
 	return($parts);
 }
 

Modified: trunk/server/Slim/Display/Lib/Fonts.pm
URL: http://svn.slimdevices.com/trunk/server/Slim/Display/Lib/Fonts.pm?rev=8840&r1=8839&r2=8840&view=diff
==============================================================================
--- trunk/server/Slim/Display/Lib/Fonts.pm (original)
+++ trunk/server/Slim/Display/Lib/Fonts.pm Sun Aug  6 12:13:48 2006
@@ -164,6 +164,12 @@
 sub fontheight {
 	my $fontname = shift;
 	return $fontheight->{$fontname};
+}
+
+sub fontchars {
+	my $fontname = shift;
+	my $font = $fonts->{$fontname} || return 0;
+	return scalar(@$font);
 }
 
 # extent returns the number of rows high a font is rendered (useful for vertical scrolling)



More information about the checkins mailing list