diff --git a/fhem/CHANGED b/fhem/CHANGED index bf527d918..a8100a679 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,8 +1,10 @@ # Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Do not insert empty lines here, update check depends on it. - SVN + - feature: new layout commands moveto, moveby and relative positioning + in 02_RSS.pm (Betateilchen & Boris) - feature: FHEMWEB column attribute - - feature: new command halign, valign, condition in 02_RSS.pm + - feature: new layout commands halign, valign, condition in 02_RSS.pm (Betateilchen & Boris) - bugfix: PRESENCE: Fix nonworking initialization in mode "lan-bluetooth" - bugfix: fhem.pl: write-select to avoid blocking in inform/Event Monitor diff --git a/fhem/FHEM/02_RSS.pm b/fhem/FHEM/02_RSS.pm index 3aadaa371..2a00b9114 100644 --- a/fhem/FHEM/02_RSS.pm +++ b/fhem/FHEM/02_RSS.pm @@ -211,10 +211,23 @@ RSS_returnRSS($) { ################## sub -RSS_xy($$$) { - my ($S,$x,$y)= @_; - if($x<=1) { $x*= $S->width; } - if($y<=1) { $y*= $S->height; } +RSS_xy { + my ($S,$x,$y,%params)= @_; + #Debug "RSS_xy on enter: (x,y)= ($x,$y)"; + + $x = $params{x} if($x eq 'x'); + $y = $params{y} if($y eq 'y'); + + #$x = AnalyzePerlCommand(undef, $x); + #$y = AnalyzePerlCommand(undef, $y); + + if((-1 < $x) && ($x < 1)) { $x*= $S->width; } + if((-1 < $y) && ($y < 1)) { $y*= $S->height; } + + $params{x} = $x; + $params{y} = $y; + + #Debug "RSS_xy on exit: (x,y)= ($x,$y)"; return($x,$y); } @@ -231,7 +244,7 @@ RSS_itemText { return unless(defined($text)); if($params{useTextAlign}) { - ($x,$y)= RSS_xy($S,$x,$y); + ($x,$y)= RSS_xy($S,$x,$y,%params); my $align = GD::Text::Align->new($S, color => RSS_color($S, $params{rgb}), valign => $params{tvalign}, @@ -241,7 +254,7 @@ RSS_itemText { $align->set_text($text); $align->draw($x, $y, 0); } else { - ($x,$y)= RSS_xy($S,$x,$y); + ($x,$y)= RSS_xy($S,$x,$y,%params); $S->stringFT(RSS_color($S,$params{rgb}),$params{font},$params{pt},0,$x,$y,$text); } } @@ -314,7 +327,7 @@ RSS_itemImg { } else { return; } - ($x,$y)= RSS_xy($S,$x,$y); + ($x,$y)= RSS_xy($S,$x,$y,%params); eval { my ($width,$height)= $I->getBounds(); @@ -351,8 +364,8 @@ RSS_itemImg { sub RSS_itemLine { my ($S,$x1,$y1,$x2,$y2,$th,%params)= @_; - ($x1,$y1)= RSS_xy($S,$x1,$y1); - ($x2,$y2)= RSS_xy($S,$x2,$y2); + ($x1,$y1)= RSS_xy($S,$x1,$y1,%params); + ($x2,$y2)= RSS_xy($S,$x2,$y2,%params); $S->setThickness($th); $S->line($x1,$y1,$x2,$y2,RSS_color($S,$params{rgb})); } @@ -370,7 +383,7 @@ RSS_evalLayout($$@) { $params{rgb}= "ffffff"; $params{halign} = 'left'; $params{valign} = 'base'; - $params{condition} = '1'; + $params{condition} = 1; # we need two pairs of align parameters # due to different default values for text and img $params{useTextAlign}= $defs{$name}{fhem}{useTextAlign}; @@ -378,6 +391,9 @@ RSS_evalLayout($$@) { $params{ivalign} = 'top'; $params{thalign} = 'left'; $params{tvalign} = 'base'; + $params{x}= 0; + $params{y}= 0; + my ($x,$y,$x1,$y1,$x2,$y2,$scale,$text,$imgtype,$srctype,$arg,$format); @@ -395,9 +411,16 @@ RSS_evalLayout($$@) { #Debug "$name: evaluating >$line<"; # split line into command and definition my ($cmd, $def)= split("[ \t]+", $line, 2); - ##Debug, "CMD= \"$cmd\", DEF= \"$def\""; - $params{condition} = AnalyzePerlCommand(undef, $def) if($cmd eq 'condition'); + #Debug "CMD= \"$cmd\", DEF= \"$def\""; + + # separate condition handling + if($cmd eq 'condition') { + $params{condition} = AnalyzePerlCommand(undef, $def); + next; + } next unless($params{condition}); + + if($cmd eq "rgb") { $def= "\"$def\"" if(length($def) == 6 && $def =~ /[[:xdigit:]]{6}/); $params{rgb}= AnalyzePerlCommand(undef, $def); @@ -405,6 +428,16 @@ RSS_evalLayout($$@) { $params{font}= $def; } elsif($cmd eq "pt") { $params{pt}= $def; + } elsif($cmd eq "moveto") { + my ($tox,$toy)= split('[ \t]+', $def, 2); + my ($x,$y)= RSS_xy($S, $tox,$toy); + $params{x} = $x; + $params{y} = $y; + } elsif($cmd eq "moveby") { + my ($byx,$byy)= split('[ \t]+', $def, 2); + my ($x,$y)= RSS_xy($S, $byx,$byy); + $params{x} += $x; + $params{y} += $y; } elsif($cmd ~~ @cmd_halign) { my $d = AnalyzePerlCommand(undef, $def); if($d ~~ @valid_halign) { @@ -443,6 +476,7 @@ RSS_evalLayout($$@) { ($x,$y,$scale,$imgtype,$srctype,$arg)= split("[ \t]+", $def,6); my $arg= AnalyzePerlCommand(undef, $arg); RSS_itemImg($S,$x,$y,$scale,$imgtype,$srctype,$arg,%params); + } elsif($cmd eq 'condition') { } else { Log3 $name, 1, "$name: Illegal command $cmd in layout definition."; } @@ -697,13 +731,30 @@ RSS_CGI(){ Everything after a # is treated as a comment and ignored. You can fold long lines by putting a \ at the end.
- Layout control commands
- Notes:
- (1) Use double quotes to quote literal text if perl specials are allowed.
- (2) Text alignment requires the Perl module GD::Text::Align to be installed. Debian-based systems can install it with apt-get install libgd-text-perl
.
+ General notes
+
apt-get install libgd-text-perl
.
+ Notes on coordinates
+
x
and y
evaluate to the most recently used x- and y-coordinate. See also moveto and moveby below.+ + Layout control commands
+
Arial
) or the full path to a TrueType font
(e.g. /usr/share/fonts/truetype/arial.ttf
),
@@ -719,7 +770,8 @@ RSS_CGI(){
{ <perl special> }
instead of the literal alignment control word.{ <perl special> }
instead of the literal alignment control word.{ <perl special> }
for <text> to fully
access device readings and do some programming on the fly. See below for examples.This is how a layout definition might look like:
font /usr/share/fonts/truetype/arial.ttf # must be a TrueType font
@@ -760,6 +811,8 @@ RSS_CGI(){
time 0.10 0.90
pt 24
text 0.10 0.95 { ReadingsVal("MyWeather","temperature","?"). "C" }
+ moveby 0 -25
+ text x y "Another text"
img 20 530 0.5 png file { "/usr/share/fhem/www/images/weather/" . ReadingsVal("MyWeather","icon","") . ".png" }