[Slim-Checkins] r9676 - /branches/6.5/server/Slim/Buttons/Block.pm

adrian at svn.slimdevices.com adrian at svn.slimdevices.com
Wed Sep 13 15:38:46 PDT 2006


Author: adrian
Date: Wed Sep 13 15:38:44 2006
New Revision: 9676

URL: http://svn.slimdevices.com?rev=9676&view=rev
Log:
Bug: N/A
Description: merge from trunk -r 9527:9528 & 9668:9669

Modified:
    branches/6.5/server/Slim/Buttons/Block.pm

Modified: branches/6.5/server/Slim/Buttons/Block.pm
URL: http://svn.slimdevices.com/branches/6.5/server/Slim/Buttons/Block.pm?rev=9676&r1=9675&r2=9676&view=diff
==============================================================================
--- branches/6.5/server/Slim/Buttons/Block.pm (original)
+++ branches/6.5/server/Slim/Buttons/Block.pm Wed Sep 13 15:38:44 2006
@@ -47,9 +47,9 @@
 
 =cut
 
-# Don't do this at compile time - not at run time
 sub init {
-	Slim::Buttons::Common::addMode('block',getFunctions(),\&setMode);
+
+	Slim::Buttons::Common::addMode('block', getFunctions(), \&setMode, \&exitMode);
 }
 
 # Each button on the remote has a function:
@@ -59,54 +59,75 @@
 
 sub setMode {
 	my $client = shift;
+
+	# store current lines function so it can be replaced when block mode is popped
+	# this is required as popping block mode does not call the setMode of the previous mode
+	$client->modeParam('oldLines', $client->lines );
+
 	$client->lines(\&lines);
-	$client->modeParam('modeUpdateInterval', $ticklength) unless ($client->blocklines()->{'static'});
-}
-
-=head2 block( $client, $line1)
-
-Starts the block mode on the specified client.  The required $line argument is a reference to 
-a display hash for any information required on the screen while blocking.
-
-=cut
+
+	if (!$client->blocklines()->{'static'}) {
+
+		$client->modeParam('modeUpdateInterval', $ticklength);
+	}
+}
+
+sub exitMode {
+	my $client = shift;
+
+	# restore previous lines and display screen
+	$client->lines( $client->modeParam('oldLines') );
+	$client->update();
+}
+
+=head2 block( $client, $line1 )
+
+Starts the block mode on the specified client. The required $line argument is
+a reference to a display hash for any information required on the screen while
+blocking.
+
+=cut
+
 sub block {
 	my $client = shift;
-	my $line1 = shift;
-
-	my $parts;
-	if (ref($line1) eq 'HASH') {
-		$parts = $line1;
-	} else {
-		my $line2 = shift;
-		$parts = $client->parseLines([$line1,$line2]);
+	my $line1  = shift;
+
+	my $parts  = $line1;
+
+	if (ref($line1) ne 'HASH') {
+
+		$parts = $client->parseLines([$line1, shift]);
 	}
 
 	my $blockName = shift;  # associate name with blocked mode
-	my $static = shift;     # turn off animation
+	my $static    = shift;  # turn off animation
 
 	$client->blocklines( { 'static' => $static, 'parts' => $parts, 'ticks' => 0 } );
 
 	my $screen2mode = $client->param('screen2');
 
-	Slim::Buttons::Common::pushMode($client,'block');
+	Slim::Buttons::Common::pushMode($client, 'block');
+
 	$client->modeParam('block.name', $blockName);
 	$client->modeParam('screen2', $screen2mode);
 
-	if (defined $parts) {
+	if (ref($parts) eq 'HASH') {
+
 		$client->showBriefly($parts);
 	}
 }
 
-=head2 unblock( $client)
+=head2 unblock( $client )
 
 Releases the provided client from block mode. 
 
 =cut
+
 sub unblock {
 	my $client = shift;
-	
+
 	Slim::Buttons::ScreenSaver::wakeup($client);
-	
+
 	if (Slim::Buttons::Common::mode($client) eq 'block') {
 		Slim::Buttons::Common::popMode($client);
 	}
@@ -121,75 +142,84 @@
 	my $parts = $bdata->{'parts'};
 	my $screen1;
 
-	if ($bdata->{'static'}) { return $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 (!defined $bdata->{'pos'}) {
 
 		$bdata->{'parts'} = $parts = Storable::dclone($parts);
 
 		$screen1 = $parts->{'screen1'} ? $parts->{'screen1'} : $parts;
 		
 		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 $vfd   = $client->display->vfdmodel(); 
 			my $model = $vfd eq 'graphic-320x32' ? 'SB2' : 'SBG';
-			my $font = "blockanimate$model.1";
+			my $font  = "blockanimate$model.1";
 			my $chars = Slim::Display::Lib::Fonts::fontchars($font);
 
-			$bdata->{'vfd'} = $vfd;
+			$bdata->{'vfd'}   = $vfd;
 			$bdata->{'chars'} = $chars ? $chars - 1 : ($font = undef);
-			
-			if ($screen1->{'fonts'} && $screen1->{'fonts'}->{"$vfd"}) {
-				if (ref $screen1->{'fonts'}->{"$vfd"} ne 'HASH') {
+
+			if ($screen1->{'fonts'} && $screen1->{'fonts'}->{$vfd}) {
+
+				if (ref $screen1->{'fonts'}->{$vfd} ne 'HASH') {
+
 					# expand font definition so we can redefine one component only
-					my $basefont = $screen1->{'fonts'}->{"$vfd"};
-					my $sfonts = $screen1->{'fonts'}->{"$vfd"} = {};
+					my $basefont = $screen1->{'fonts'}->{$vfd};
+					my $sfonts   = $screen1->{'fonts'}->{$vfd} = {};
+
 					foreach my $c (qw(line overlay center)) {
+
 						foreach my $l (0..$client->display->renderCache()->{'maxLine'}) {
-							$sfonts->{"$c"}[$l] = $basefont . "." . ( $l + 1 );
+							$sfonts->{$c}[$l] = $basefont . "." . ( $l + 1 );
 						}
 					}
 				}
+
 			} elsif ($client->display->linesPerScreen == 1) {
+
 				# clear overlay so animation is seen
 				$screen1->{'overlay'}[1] = undef;
 			}
-			
-			$screen1->{'fonts'}->{"$vfd"}->{'overlay'}[0] = $font;
-			
+
+			$screen1->{'fonts'}->{$vfd}->{'overlay'}[0] = $font;
 		}
-		
+
 		$bdata->{'pos'} = -1;
-		
+
 	} else {
-		
+
 		$screen1 = $parts->{'screen1'} ? $parts->{'screen1'} : $parts;
-
-	}
-	
+	}
+
 	if ($bdata->{'chars'}) {
-		
+
 		my $pos = ($bdata->{'pos'} + 1) % $bdata->{'chars'};
 		my $vfd = $bdata->{'vfd'};
+
 		$bdata->{'pos'} = $pos;
 		$screen1->{'overlay'}[0] = chr($pos + 1);
-		
+
 	} else {
 		
 		my $pos = int(Time::HiRes::time() / $ticklength) % (@tickchars);
 		
 		$screen1->{overlay}[0] = $tickchars[$pos];
-		
-	}
-
-	return($parts);
+	}
+
+	return ($parts);
 }
 
 =head1 SEE ALSO



More information about the checkins mailing list