2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-03 16:56:54 +00:00

55_InfoPanel.pm: code cleanup

added: item "counter"
changed: reuse standard elements
changed: commandref updated

git-svn-id: https://svn.fhem.de/fhem/trunk@7933 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
betateilchen 2015-02-11 01:04:47 +00:00
parent 4faad0f7fb
commit 883b36c770
2 changed files with 40 additions and 24 deletions

View File

@ -26,14 +26,6 @@ my $useImgTools = 1;
no if $] >= 5.017011, warnings => 'experimental::smartmatch'; no if $] >= 5.017011, warnings => 'experimental::smartmatch';
# we can
# use vars qw(%FW_types); # device types,
# use vars qw($FW_RET); # Returned data (html)
# use vars qw($FW_wname); # Web instance
# use vars qw($FW_subdir); # Sub-path in URL for extensions, e.g. 95_FLOORPLAN
# use vars qw(%FW_pos); # scroll position
# use vars qw($FW_cname); # Current connection name
#sub InfoPanel_Initialize($); #sub InfoPanel_Initialize($);
sub btIP_Define($$); sub btIP_Define($$);
sub btIP_Undef($$); sub btIP_Undef($$);
@ -93,7 +85,6 @@ sub InfoPanel_Initialize($) {
$hash->{DefFn} = "btIP_Define"; $hash->{DefFn} = "btIP_Define";
$hash->{UndefFn} = "btIP_Undef"; $hash->{UndefFn} = "btIP_Undef";
#$hash->{AttrFn} = "btIP_Attr";
$hash->{SetFn} = "btIP_Set"; $hash->{SetFn} = "btIP_Set";
$hash->{NotifyFn} = "btIP_Notify"; $hash->{NotifyFn} = "btIP_Notify";
$hash->{AttrList} = "autoreread:1,0 bgcolor refresh size title"; $hash->{AttrList} = "autoreread:1,0 bgcolor refresh size title";
@ -213,26 +204,23 @@ sub btIP_itemButton {
$id = ($id eq '-') ? createUniqueId() : $id; $id = ($id eq '-') ? createUniqueId() : $id;
my $width = $x2 - $x1; my $width = $x2 - $x1;
my $height = $y2 - $y1; my $height = $y2 - $y1;
my ($r,$g,$b,$a) = btIP_color($params{boxcolor});
$text = AnalyzePerlCommand(undef,$text); $text = AnalyzePerlCommand(undef,$text);
$link = AnalyzePerlCommand(undef,$link); $link = AnalyzePerlCommand(undef,$link);
my $target;
($link,$target) = btIP_findTarget($link); my $oldrgb = $params{rgb};
$params{rgb} = $params{boxcolor};
my $output = "<a id=\”$id\” x=\"$x1\" y=\"$y1\" width=\"$width\" height=\"$height\" ". my $output = btIP_itemRect($id,$x1,$y1,$x2,$y2,$rx,$ry,1,0,$link,%params);
"xlink:href=\"$link\" target=\"$target\" >\n"; $params{rgb} = $oldrgb;
$output .= "<rect id=\”$id\” x=\"$x1\" y=\"$y1\" rx=\"$rx\" ry=\"$ry\" width=\"$width\" height=\"$height\" ".
"style=\"fill:rgb($r,$g,$b); fill-opacity:$a; stroke-width:0;\" />\n";
my $oldhalign = $params{thalign}; my $oldhalign = $params{thalign};
my $oldvalign = $params{tvalign}; my $oldvalign = $params{tvalign};
$params{thalign} = "middle"; $params{thalign} = "middle";
$params{tvalign} = "middle"; $params{tvalign} = "middle";
$output .= btIP_itemText($id."_text",($x1+$x2)/2,($y1+$y2)/2,$text,%params); my $textoutput .= btIP_itemText("${id}_text",($x1+$x2)/2,($y1+$y2)/2,$text,%params);
$params{thalign} = $oldhalign; $params{thalign} = $oldhalign;
$params{tvalign} = $oldvalign; $params{tvalign} = $oldvalign;
$output .= "</a>\n";
$output =~ s/<\/a>/$textoutput<\/a>/;
return $output; return $output;
} }
@ -264,6 +252,12 @@ sub btIP_itemCircle {
return $output; return $output;
} }
sub btIP_itemCounter {
my ($id,$x,$y,%params)= @_;
$id = ($id eq '-') ? createUniqueId() : $id;
return btIP_itemText($id,$x,$y,$defs{$params{name}}{fhem}{counter},%params);
}
sub btIP_itemDate { sub btIP_itemDate {
my ($id,$x,$y,%params)= @_; my ($id,$x,$y,%params)= @_;
$id = ($id eq '-') ? createUniqueId() : $id; $id = ($id eq '-') ? createUniqueId() : $id;
@ -344,7 +338,6 @@ sub btIP_itemImg {
($width,$height,$mimetype,$data) = _btIP_imgData($data,$scale); ($width,$height,$mimetype,$data) = _btIP_imgData($data,$scale);
} }
# $output = "<!-- w: $width h: $height nw: $newWidth nh: $newHeight t: $mimetype -->\n";
$output = "<!-- s: $scale w: $width h: $height t: $mimetype -->\n"; $output = "<!-- s: $scale w: $width h: $height t: $mimetype -->\n";
$output .= "<image id=\"$id\" x=\"$x\" y=\"$y\" width=\"${width}px\" height=\"${height}px\" \nxlink:href=\"$data\" />\n"; $output .= "<image id=\"$id\" x=\"$x\" y=\"$y\" width=\"${width}px\" height=\"${height}px\" \nxlink:href=\"$data\" />\n";
return $output; return $output;
@ -422,7 +415,7 @@ sub btIP_itemPlot {
$svgdata =~ s/<\/svg>/<polyline opacity="0" points="0,0 $newWidth,$newHeight"\/><\/svg>/; $svgdata =~ s/<\/svg>/<polyline opacity="0" points="0,0 $newWidth,$newHeight"\/><\/svg>/;
(undef,undef,undef,$svgdata) = _btIP_imgData($svgdata,1); (undef,undef,undef,$svgdata) = _btIP_imgData($svgdata,1);
$output = "<!-- w: $width h: $height nw: $newWidth nh: $newHeight t: $mimetype -->\n"; $output = "<!-- s: $scale ow: $width oh: $height nw: $newWidth nh: $newHeight t: $mimetype -->\n";
$output .= "<image id=\"$id\" x=\"$x\" y=\"$y\" width=\"${newWidth}px\" height=\"${newHeight}px\" \n"; $output .= "<image id=\"$id\" x=\"$x\" y=\"$y\" width=\"${newWidth}px\" height=\"${newHeight}px\" \n";
$output .= "xlink:href=\"$svgdata\" />\n"; $output .= "xlink:href=\"$svgdata\" />\n";
} else { } else {
@ -454,8 +447,8 @@ sub btIP_itemRect {
my $width = $x2 - $x1; my $width = $x2 - $x1;
my $height = $y2 - $y1; my $height = $y2 - $y1;
my $output = ""; my $output = "";
$output .= "<a xlink:href=\"$link\" target=\"$target\">\n" if($link && length($link)); $output .= "<a id=\”${id}_link\” xlink:href=\"$link\" target=\"$target\">\n" if($link && length($link));
$output .= "<rect id=\”$id\” x=\"$x1\" y=\"$y1\" width=\"$width\" height=\"$height\" rx=\"$rx\" ry=\"$ry\" "; $output .= "<rect id=\”${id}_rect\” x=\"$x1\" y=\"$y1\" width=\"$width\" height=\"$height\" rx=\"$rx\" ry=\"$ry\" ";
if($filled > 0 || $stroked > 0) { if($filled > 0 || $stroked > 0) {
$output .= "style=\""; $output .= "style=\"";
if($filled > 0) { if($filled > 0) {
@ -864,6 +857,14 @@ sub btIP_evalLayout($$@) {
$svg .= btIP_itemCircle($id,$x1,$y1,$r1,$filled,$stroked,$link,%params); $svg .= btIP_itemCircle($id,$x1,$y1,$r1,$filled,$stroked,$link,%params);
} }
when("counter") {
($id,$x,$y)= split("[ \t]+", $def, 3);
($x,$y)= btIP_xy($x,$y,%params);
$params{xx} = $x;
$params{yy} = $y;
$svg .= btIP_itemCounter($id,$x,$y,%params);
}
when("date") { when("date") {
($id,$x,$y)= split("[ \t]+", $def, 3); ($id,$x,$y)= split("[ \t]+", $def, 3);
($x,$y)= btIP_xy($x,$y,%params); ($x,$y)= btIP_xy($x,$y,%params);
@ -1357,6 +1358,14 @@ Please read <a href="http://forum.fhem.de/index.php/topic,32828.0.html" target="
link = URL to be linked to item<br/> link = URL to be linked to item<br/>
</ul></li><br/> </ul></li><br/>
<br/> <br/>
<li><code>counter &lt;id&gt; &lt;x&gt; &lt;y&gt;</code><br/>
<br/>
<ul>print internal counter<br/>
<br/>
id = element id<br/>
x,y = position<br/>
</ul></li><br/>
<br/>
<li><code>date &lt;id&gt; &lt;x&gt; &lt;y&gt;</code><br/> <li><code>date &lt;id&gt; &lt;x&gt; &lt;y&gt;</code><br/>
<br/> <br/>
<ul>print date<br/> <ul>print date<br/>

View File

@ -86,6 +86,13 @@ pt 24
# Format: date <id> <x> <y> # Format: date <id> <x> <y>
# #
date - 50 25 date - 50 25
text - 610 75 "Counter:"
# Internen Zähler ausgeben
# Format: counter <id> <x> <y>
#
counter - 710 75
# Text rechtsbündig ausgeben # Text rechtsbündig ausgeben
@ -272,4 +279,4 @@ textboxalign justify
# #
textbox - 210 50 180 50 "http://www.fhem.de" "Ich bin eine Textbox und wenn man mich anklickt geht es direkt zu www.fhem.de" textbox - 210 50 180 50 "http://www.fhem.de" "Ich bin eine Textbox und wenn man mich anklickt geht es direkt zu www.fhem.de"
# #