home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-perl-addon-1.4.9-installer.exe / Dashboard.pm < prev    next >
Encoding:
Perl POD Document  |  2002-06-14  |  19.2 KB  |  878 lines

  1. package GD::Dashboard;
  2.  
  3. use strict;
  4. #use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
  5.  
  6. $GD::Dashboard::VERSION = '0.04';
  7.  
  8.  
  9. # Preloaded methods go here.
  10.  
  11.  
  12. #
  13. # Constructor options:
  14. #
  15. # FNAME
  16. # QUALITY
  17. #
  18. sub new
  19. {
  20.    my $proto = shift;
  21.  
  22.    my $self = {
  23.       METERS  => {},
  24.       FNAME => '',
  25.       QUALITY => 100
  26.    };
  27.  
  28.  
  29.    # load in options supplied to new()
  30.    for (my $x = 0; $x <= $#_; $x += 2)
  31.    {
  32.       my $opt = uc($_[$x]);
  33.  
  34.       defined($_[($x + 1)]) or die "Dashboard->new() called with odd number of option parameters - should be of the form option => value";
  35.       $self->{$opt} = $_[($x + 1)];
  36.    }
  37.  
  38.    bless($self);
  39.    return $self;
  40. }
  41.  
  42. #
  43. # There can be many meters on a graphic.  To specify them,
  44. # you create a new meter, then pass it to this function,
  45. # along with its name.  All meters will be referred to by
  46. # name.
  47. #
  48. sub add_meter
  49. {
  50.    my ($self,$name,$meter) = @_;
  51.    $self->{METERS}->{$name} = $meter;
  52. }
  53.  
  54. #
  55. # Why would you want to use get_meter?  A couple of reasons.
  56. # First, you might have called add_meter(new Dashboard::Gauge()).
  57. # Second, if you have multiple dash layouts, you have probably
  58. # written the code so that you don't have access to the original
  59. # meter variables at the point where you need to set them.
  60. #
  61. sub get_meter
  62. {
  63.    my ($self,$name) = @_;
  64.    $self->{METERS}->{$name};
  65. }
  66.  
  67. sub gdimage
  68. {
  69.    my ($self) = @_;
  70.    my ($aref) = $self->{METERS};
  71.    my $fname = $self->{FNAME};
  72.  
  73.    if (!defined($fname) || $fname eq '')
  74.    {
  75.       warn("GD::Dashboard::gdimage(): You must set FNAME in constructor first!") ;
  76.       return undef;
  77.    }
  78.  
  79.    # Get canvas from specified background graphics
  80.    my $im;
  81.  
  82.    if ($self->{FNAME} =~ /png$/ )
  83.    {
  84.       $im = GD::Image->newFromPng($self->{FNAME});
  85.    }
  86.    else
  87.    {
  88.       $im = GD::Image->newFromJpeg($self->{FNAME});
  89.    }
  90.  
  91.    # Draw all my meters
  92.    for my $m (keys(%{$aref}))
  93.    {
  94.       my $m2 = $aref->{$m};
  95.       $m2->write_gdimagehandle($im);
  96.    }
  97.  
  98.    $im;
  99. }
  100.  
  101. sub png
  102. {
  103.    my ($self) = @_;
  104.  
  105.    my $im = $self->gdimage;
  106.  
  107.    return $im->png();
  108. }
  109.  
  110. sub jpeg
  111. {
  112.    my ($self) = @_;
  113.  
  114.    my $im = $self->gdimage;
  115.  
  116.    return $im->jpeg($self->{QUALITY});
  117. }
  118.  
  119. #
  120. # Is anything wrong with me using this filehandle (HG1) ?
  121. #
  122. sub write_jpeg
  123. {
  124.    my ($self,$fname) = @_;
  125.  
  126.    open (HG1,'>'.$fname);
  127.    binmode HG1;
  128.    print HG1 $self->jpeg();
  129.    close HG1;
  130. }
  131.  
  132. sub write_png
  133. {
  134.    my ($self,$fname) = @_;
  135.  
  136.    open (HG1,'>'.$fname);
  137.    binmode HG1;
  138.    print HG1 $self->png();
  139.    close HG1;
  140. }
  141.  
  142. package GD::Dashboard::Base;
  143.  
  144. # insert base class for meters here.....
  145.  
  146. # All meters should support:
  147. #      MIN => 0,
  148. #      MAX => 100,
  149. #      VAL => 50,
  150. #      NX => 0,
  151. #      NY => 0,
  152. #      QUALITY => 100,
  153.  
  154. sub jpeg
  155. {
  156. }
  157.  
  158. sub write_jpeg
  159. {
  160. }
  161.  
  162. package GD::Dashboard::Gauge;
  163.  
  164. use GD;
  165.  
  166.  
  167. #
  168. # Constructor Options
  169. #
  170. # MIN
  171. # MAX
  172. # VAL
  173. # NX
  174. # NY
  175. # NLEN
  176. # NWIDTH
  177. # NA1
  178. # NA2
  179. # NCOLOR
  180. # QUALITY
  181. # FNAME
  182. # COUNTERCLOCKWISE
  183. #
  184. sub new
  185. {
  186.    my $proto = shift;
  187.  
  188.    my $self = {
  189.       FNAME => '',
  190.       MIN => 0,
  191.       MAX => 100,
  192.       VAL => 50,
  193.       NX => 0,
  194.       NY => 0,
  195.       NLEN => 0,
  196.       NWIDTH=>2,
  197.       NA1=>0,
  198.       NA2=>0,
  199.       NCOLOR => [ 0, 0, 255 ],
  200.       QUALITY => 100,
  201.       COUNTERCLOCKWISE => 0
  202.    };
  203.  
  204.  
  205.    # load in options supplied to new()
  206.    for (my $x = 0; $x <= $#_; $x += 2)
  207.    {
  208.       my $opt = uc($_[$x]);
  209.  
  210.       defined($_[($x + 1)]) or die "Dashboard::Gauge->new() called with odd number of option parameters - should be of the form option => value";
  211.       $self->{$opt} = $_[($x + 1)];
  212.    }
  213.  
  214.    bless($self);
  215.    return $self;
  216. }
  217.  
  218. sub write_gdimagehandle
  219. {
  220.    my ($self,$im) = @_;
  221.    $self->_draw_needle($im);
  222. }
  223.  
  224. #sub jpeg
  225. #{
  226. #   my ($self) = @_;
  227. #
  228. #   my $im = GD::Image->newFromJpeg($self->{FNAME});
  229. #
  230. #   $self->write_gdimagehandle($im);
  231. #
  232. #   return $im->jpeg(100);
  233. #}
  234. #
  235. #sub write_jpeg
  236. #{
  237. #   my ($self,$fname) = @_;
  238. #
  239. #   open (HG1,'>'.$fname);
  240. #   binmode HG1;
  241. #   print HG1 $self->jpeg();
  242. #   close HG1;
  243. #}
  244.  
  245. sub set_reading
  246. {
  247.    my ($self,$val) = @_;
  248.  
  249.    warn "Warning: set_reading called with value less than minimum." if $val < $self->{MIN};
  250.    warn "Warning: set_reading called with value greater than maximum." if $val > $self->{MAX};
  251.  
  252.    $self->{VAL} = $val;
  253. }
  254.  
  255.  
  256. sub _draw_needle
  257. {
  258.    my ($self,$im) = @_;
  259.    my ($x,$y);
  260.    my $pi = 3.141592;
  261.  
  262.    # Must compute x,y coords for tip of needle.
  263.    # Angle system for GD is in degrees, 0 is straight up,
  264.    # and they increase clockwise.  Sigh.  Angle system
  265.    # for perl is in radians, 0 is as it is defined
  266.    # traditionally in math, angles increase counterclockwise.
  267.    #
  268.  
  269.    my $norm =  ($self->{VAL}-$self->{MIN}) / ($self->{MAX} - $self->{MIN} );
  270.    my $angle_width;
  271.  
  272.    if ( $self->{NA1} > $self->{NA2} )
  273.    {
  274.       if ($self->{COUNTERCLOCKWISE})
  275.       {
  276.          $angle_width = (2*$pi) - ($self->{NA1}-$self->{NA2}) ;
  277.       }
  278.       else
  279.       {
  280.          $angle_width =($self->{NA1}-$self->{NA2}) ;
  281.       }
  282.    }
  283.    else
  284.    {
  285.       if ($self->{COUNTERCLOCKWISE})
  286.       {
  287.          $angle_width = ($self->{NA2}-$self->{NA1}) ;
  288.       }
  289.       else
  290.       {
  291.          $angle_width = (2*$pi - ($self->{NA2}-$self->{NA1}) );
  292.       }
  293.    }
  294.  
  295.    my $angle;
  296.    if ($self->{COUNTERCLOCKWISE}==1)
  297.    {
  298.       $angle = $self->{NA1} + $norm * $angle_width;
  299.    }
  300.    else
  301.    {
  302.       $angle = $self->{NA1} - $norm * $angle_width;
  303.    }
  304.  
  305.    $x = $self->{NX} + $self->{NLEN} * cos($angle);
  306.    $y = $self->{NY} - $self->{NLEN} * sin($angle);
  307.  
  308.    # To draw a line with a width other than 1, you actually need
  309.    # to create an image brush.  Sigh.
  310.    #
  311.       my $brush = _prepare_brush($self->{NWIDTH}, $self->{NCOLOR});
  312.       $im->setBrush($brush);
  313.  
  314.    # draw the needle!
  315.    #
  316.       $im->line($self->{NX},$self->{NY},$x,$y,gdBrushed);
  317.  
  318.    # how to clean up the brush?
  319. }
  320.  
  321.  
  322.  
  323. #####################
  324. #
  325. # Private functions
  326. #
  327. #####################
  328.  
  329. ##  set the gdBrush object to trick GD into drawing fat lines
  330. sub _prepare_brush
  331. {
  332.   my ($radius, $ref_color) = @_;
  333.   my (@rgb, $brush, $white, $newcolor);
  334.  
  335.   # get the rgb values for the desired color
  336. #  @rgb = (0,0,255);
  337. #  @rgb = (255,0,128);
  338.    @rgb = @{$ref_color};
  339.   # create the new image
  340.   $brush = GD::Image->new ($radius*2, $radius*2);
  341.  
  342.   # get the colors, make the background transparent
  343. #  $white = $brush->colorAllocate (255,255,255);
  344.   $white = $brush->colorAllocate (0,0,0);
  345.   $newcolor = $brush->colorAllocate (@rgb);
  346.   $brush->transparent ($white);
  347.  
  348.   # draw the circle
  349.   $brush->arc ($radius-1, $radius-1, $radius, $radius, 0, 360, $newcolor);
  350.  
  351.   # set the new image as the main object's brush
  352.   return $brush;
  353. }
  354.  
  355.  
  356.  
  357. package GD::Dashboard::WarningLight;
  358.  
  359. #
  360. # TRANSPARENT
  361. # NX
  362. # NY
  363. # FNAME
  364. # VAL
  365. #
  366. sub new
  367. {
  368.    my $proto = shift;
  369.  
  370.    my $self = {
  371.       VAL => 0,       # 0=off, 1=on
  372.       NX => 0,
  373.       NY => 0,
  374.       FNAME => ''
  375.    };
  376.  
  377.  
  378.    # load in options supplied to new()
  379.    for (my $x = 0; $x <= $#_; $x += 2)
  380.    {
  381.       my $opt = uc($_[$x]);
  382.  
  383.       defined($_[($x + 1)]) or die "Dashboard::WarningLight->new() called with odd number of option parameters - should be of the form option => value";
  384.       $self->{$opt} = $_[($x + 1)];
  385.    }
  386.  
  387.    bless($self);
  388.    return $self;
  389. }
  390.  
  391. sub write_gdimagehandle
  392. {
  393.    my ($self,$im) = @_;
  394.  
  395.    if ($self->{VAL} == 1)
  396.    {
  397.       # load the current image
  398.       my $im2 = GD::Image->newFromJpeg($self->{FNAME});
  399.       my ($w,$h) = $im2->getBounds();
  400.  
  401.       if (defined($self->{TRANSPARENT}))
  402.       {
  403.          my $white = $im2->colorClosest(255,255,255);  #TODO this should be a param
  404.          $im2->transparent($white);
  405.       }
  406.       $im->copy($im2,$self->{NX},$self->{NY},0,0,$w,$h);
  407.    }
  408. }
  409.  
  410.  
  411. sub set_reading
  412. {
  413.    my ($self,$val) = @_;
  414.  
  415.    $self->{VAL} = $val;
  416. }
  417.  
  418. package GD::Dashboard::HorizontalBar;
  419.  
  420. # Options:
  421. #   TRANSPARENT = [ r,g,b ]
  422. #   SPACING = N
  423. #   MIN
  424. #   MAX
  425. #
  426. sub new
  427. {
  428.    my $proto = shift;
  429.  
  430.    my $self = {
  431.       MIN => 0,
  432.       MAX => 100,
  433.       VAL => 50,
  434.       NX => 0,
  435.       NY => 0,
  436.       QUALITY => 100,
  437.       DIRECTION=>0,
  438.       BARS=>[],
  439.       SPACING => 0
  440.    };
  441.  
  442.  
  443.    # load in options supplied to new()
  444.    for (my $x = 0; $x <= $#_; $x += 2)
  445.    {
  446.       my $opt = uc($_[$x]);
  447.  
  448.       defined($_[($x + 1)]) or die "Dashboard::HorizontalBar->new() called with odd number of option parameters - should be of the form option => value";
  449.       $self->{$opt} = $_[($x + 1)];
  450.    }
  451.  
  452.    bless($self);
  453.    return $self;
  454. }
  455.  
  456. sub add_bars
  457. {
  458.    my ($self,$cnt,$fname,$fnameoff) = @_;
  459.    if (!defined($fnameoff)) { $fnameoff = ''; }
  460.    push @{$self->{BARS}}, { CNT=>$cnt,FNAME=>$fname,FNAME_OFF=>$fnameoff} ;
  461. }
  462.  
  463. sub set_reading
  464. {
  465.    my ($self,$val) = @_;
  466.  
  467. #   warn "Warning: set_reading called with value less than minimum." if $val < $self->{MIN};
  468. #   warn "Warning: set_reading called with value greater than maximum." if $val > $self->{MAX};
  469.  
  470.    $self->{VAL} = $val;
  471. }
  472.  
  473. sub write_gdimagehandle
  474. {
  475.    my ($self,$im) = @_;
  476.  
  477.    # How many bars do we have?
  478.    my $barcnt = 0;
  479.    for my $href (@{$self->{BARS}}) { $barcnt += $href->{CNT}; }
  480.  
  481.    # How many must we display?
  482.    my $norm =  $self->{VAL} / ($self->{MIN} + $self->{MAX} );
  483.    my $disp = int ($barcnt * $norm);
  484.  
  485.    # OK copy the graphics as necessary
  486.    my $x = $self->{NX};
  487.    for my $href (@{$self->{BARS}})
  488.    {
  489.       # load the current image
  490.       my $im2 = GD::Image->newFromJpeg($href->{FNAME});
  491.  
  492.       if (defined($self->{TRANSPARENT}))
  493.       {
  494.          my $white = $im2->colorClosest(255,255,255);  #TODO this should be a param
  495.          $im2->transparent($white);
  496.       }
  497.  
  498.       my ($w,$h) = $im2->getBounds();
  499.  
  500.  
  501.       my $cnt = $href->{CNT};
  502.       while ($disp>0 && $cnt>0)
  503.       {
  504.          $im->copy($im2,$x,$self->{NY},0,0,$w,$h);
  505.          $x += $w + $self->{SPACING};
  506.          $disp--;
  507.          $barcnt--;
  508.          $cnt--;
  509.       }
  510.  
  511.       # Now load up dark image and use it if necessary
  512.       my $fn2 = $href->{FNAME_OFF};
  513.       if (defined($fn2) && $fn2 ne '')
  514.       {
  515.          my $im3 = GD::Image->newFromJpeg($fn2);
  516.  
  517.          if (defined($self->{TRANSPARENT}))
  518.          {
  519.             my $wt = $im2->colorClosest(255,255,255);  #TODO this should be a param
  520.             $im3->transparent($wt);
  521.          }
  522.          my ($w,$h) = $im2->getBounds();
  523.  
  524.          while ($cnt>0)
  525.          {
  526.             $im->copy($im3,$x,$self->{NY},0,0,$w,$h);
  527.             $x += $w + $self->{SPACING};
  528.             $cnt--;
  529.          }
  530.       }
  531.    }
  532.  
  533.  
  534. }
  535.  
  536.  
  537.  
  538.  
  539.  
  540. # Autoload methods go after =cut, and are processed by the autosplit program.
  541.  
  542. 1;
  543. __END__
  544.  
  545. =head1 NAME
  546.  
  547. GD::Dashboard - Perl module to create JPEG graphics of meters and dials
  548.  
  549. =head1 SYNOPSIS
  550.  
  551.    my $dash = new GD::Dashboard();
  552.  
  553.    my $g1 = new GD::Dashboard::Gauge(
  554.                       MIN=>0,
  555.                       MAX=>$empcnt,
  556.                       VAL=>$nopwp_cnt,
  557.                       NA1=>3.14/2+0.85,
  558.                       NA2=>3.14/2-0.85,
  559.                       NX=>51,NY=>77,NLEN=>50
  560.             );
  561.  
  562.    $dash->add_meter('RPM', $g1);
  563.    $dash->write_jpeg('dash.jpg');
  564.  
  565. The Dashboard module aims at providing users with a quick and
  566. easy way to create dashboard or cockpit like JPGs to display
  567. key information.
  568.  
  569. Dashboard supports the following instruments:
  570.  
  571.   * Gauges with needles
  572.   * Bar type gauges
  573.   * Warning Lights
  574.  
  575. Dashboard is built on top of GD.pm, Licoln Stein's interface
  576. to the GD library.
  577.  
  578. =head1 Classes
  579.  
  580. The dashboard module contains several classes.  These classes
  581. typically represent either a dashboard or an instrument on
  582. the dashboard.  The Dashboard object serves as a collection
  583. for the instruments.
  584.  
  585. =head2 Dashboard
  586.  
  587. The Dashboard object serves as the collection object that contains
  588. the various instruments in the display.  You can add instruments
  589. to the dashboard, access instruments through it, or tell it to draw
  590. itself.
  591.  
  592.    my $dash = new Dashboard();
  593.    $dash->add_meter('RPM', $g1);
  594.    $dash->add_meter('Speedo', $g2);
  595.    $dash->write_jpeg('dash.jpg');
  596.  
  597. =over 4
  598.  
  599. =item *
  600. FNAME
  601.  
  602. This is the name of a JPG file to use for the background.  This
  603. graphic will typically have one or more gauges on it, upon which
  604. this module will draw needles or other indicators.
  605.  
  606. =item *
  607. QUALITY
  608.  
  609. The quality of the output JPEG, from 1 (low) to 100 (high).  Defaults to
  610. 100.  This value is passed directly to GD.
  611.  
  612. =back 4
  613.  
  614. =head3 add_meter(name, meter)
  615.  
  616. Adds a meter to the dash.  Create the meter using one of the
  617. new() constructors first.  You can add Gauges, HorizontalBars, and
  618. WarningLights.  The name is used by the get_meter()
  619. function if you need to access the meter later.
  620.  
  621. =head3 get_meter()
  622.  
  623. Gets a meter by name.  When adding a meter, you must give it a name.
  624. You can then use get_meter to get the meter object.  This is useful
  625. when you want to change a setting later, such as the meter's value.
  626.  
  627. =head3 jpeg()
  628.  
  629. Returns a JPG as a scalar value.
  630.  
  631. =head3 write_jpeg(fname)
  632.  
  633. Draws the dashboard to a jpg file given by fname.
  634.  
  635. =head3 png()
  636.  
  637. Returns a PNG as a scalar value.
  638.  
  639. =head3 write_png(fname)
  640.  
  641. Draws the dashboard to a PNG file given by fname.
  642.  
  643. =head2 Dashboard::Gauge
  644.  
  645. This class describes a typical dashboard gauge; that is, an
  646. instrument that has a needle that rotates.  The needle may
  647. rotate clockwise or counterclockwise.  This gauge is similar
  648. to a car speedometer or and airspeed indicator.
  649.  
  650. =head3 new()
  651.  
  652. Most gauge configuration is done in the constructor.  Here is a sample
  653. for the gauge included with this package (m1.jpg):
  654.  
  655.    my $g1 = new GD::Dashboard::Gauge(FNAME=>base_path().'\icons\m1.jpg',
  656.                       MIN=>0,
  657.                       MAX=>$empcnt,
  658.                       VAL=>$nopwp_cnt,
  659.                       NA1=>3.14/2+0.85,
  660.                       NA2=>3.14/2-0.85,
  661.                       NX=>51,NY=>77,NLEN=>50
  662.             );
  663.  
  664. =over 4
  665.  
  666. =item *
  667. VAL
  668.  
  669. This indicates where the needle is pointing.  Generally it should
  670. be somewhere between MIN and MAX.
  671.  
  672. =item *
  673. MIN
  674.  
  675. This is the minimum VAL is ever expected to reach.  It corresponds
  676. to a needle position of NA1.  Lower values are not truncated; however,
  677. they will generate warnings.
  678.  
  679. =item *
  680. MAX
  681.  
  682. This is the maximum VAL is ever expected to reach.  It corresponds
  683. to a needle position of NA2.  Higher values are not truncated; however,
  684. they will generate warnings.
  685.  
  686. =item *
  687. NX
  688.  
  689. This is the X coordinate of the base of the needle.
  690.  
  691. =item *
  692. NY
  693.  
  694. This is the Y coordinate of the base of the needle.
  695.  
  696. =item *
  697. NLEN
  698.  
  699. This is the length of the needle to draw.
  700.  
  701. =item *
  702. NWIDTH
  703.  
  704. This is the width of the needle.
  705.  
  706. =item *
  707. NA1
  708.  
  709. NA1 and NA2 are potentially the most confusing parameters.  They
  710. represent the angle of the needle at its MIN and MAX points.  NA1
  711. is the angle that corresponds to VAL=MIN, while NA2 is VAL=MAX.  The
  712. angle is expressed in radians, the same way you would express an angle
  713. to one of perl's trigonometric functions.
  714.  
  715. =item *
  716. NA2
  717.  
  718. See NA1.
  719.  
  720. =item *
  721. NCOLOR
  722.  
  723. This is the color of the needle.  This value should be passed as a
  724. reference to an array of RGB values.
  725.  
  726. =item *
  727. COUNTERCLOCKWISE
  728.  
  729. Set to 1 if needle moves from MIN to MAX in a counterclockwise direction.
  730. Otherwise you can ignore it.
  731.  
  732. =back 4
  733.  
  734. =head2 Dashboard::HorizontalBar
  735.  
  736. This class describes an LED bargraph display of the type often
  737. found in a graphical equalizer or, on some cars, the oil condition
  738. indicator.  It may be all one color, or it may use different colors
  739. in different ranges.
  740.  
  741. The graph goes from left to right and consists of a number of bars, meant
  742. to represent LEDs.  Bars can be identical or you can configure different
  743. bars, for example to have the last couple of bars be red instead of green.
  744.  
  745.    my $m1 = new GD::Dashboard::HorizontalBar(
  746.                   NX => 235,
  747.                   NY => 348,
  748.                   SPACING => 1
  749.                   );
  750.    $m1->add_bars(20,base_path().'\icons\barlight_on.jpg','\icons\barlight_off.jpg');
  751.    $dash->add_meter('m1',$m1);
  752.  
  753. =head3 new()
  754.  
  755. =over 4
  756.  
  757. =item *
  758. MIN = N
  759. The value representing zero bars illuminated.  Defaults to 0.
  760.  
  761. =item *
  762. MAX = N
  763. The value representing all bars illuminated.  Defaults to 100.
  764.  
  765. =item *
  766. VAL = N
  767. The value to display.  Number of bars illuminated will be
  768. val / (max-min) percent of total.
  769.  
  770. =item *
  771.    TRANSPARENT = [ r,g,b ]
  772.  
  773. This is currently not implemented correctly.  If you pass any array
  774. reference to this parameter, WHITE will be transparent.  This allows
  775. you to have non-rectangular bars.  Email me if the white bit is a problem.
  776.  
  777. =item *
  778.    SPACING = N
  779.  
  780. If you would like bars to be separated by a number of pixles, specify
  781. the number in this parameter.
  782.  
  783. =back 4
  784.  
  785. =head3 add_bars(count, fname, fnameoff)
  786.  
  787. Call this for each different group of bars you would like to add.  Count
  788. is the number of bars.  Fname is the path to a JPG that represents the
  789. bars in their ON state.  Fnameoff is an optional filename to a JPG
  790. that represents the bar in the off state (these are often just built
  791. into the dashboard background, however).
  792.  
  793. =head3 set_reading(val)
  794.  
  795. Sets the number of bars that are illuminated.  So if you have 20 bars
  796. defined, 'val' should be between 0 and 20 inclusive.
  797.  
  798. =head2 Dashboard::WarningLight
  799.  
  800. This behaves like a warning light on a car dashboard.  It can be turned
  801. on or off.  When VAL is 0, this gauge has basically no effect.  When
  802. VAL is 1, it draws another graphic on the dashboard (this would typically
  803. be the warning light on graphic).  Consequently, the dashboard graphic
  804. should contain the warning light in its "off" state.
  805.  
  806. =head3 new()
  807.  
  808. Most configuration of the warning light is done via the constructor.
  809.  
  810. =over 4
  811.  
  812. =item *
  813. FNAME
  814.  
  815. This is a JPG file that will be drawn at NX,NY when the warning light
  816. is turned on.
  817.  
  818. =item *
  819. VAL
  820.  
  821. This can be 0 or 1.  A value of 1 turns the warning light on, i.e., it
  822. causes the graphic FNAME to be drawn at NX,NY.
  823.  
  824. =item *
  825. NX
  826.  
  827. X position of lower right of graphic FNAME.
  828.  
  829. =item *
  830. NY
  831.  
  832. Y position of lower right of graphic FNAME.
  833.  
  834. =item *
  835. TRANSPARENT
  836.  
  837. Currently, set this to 1 to make WHITE transparent.  I probably
  838. should make this take an RGB array ref.  Email me if you want it.
  839.  
  840. =back 4
  841.  
  842. =head3 set_reading(val)
  843.  
  844. Sets the VAL parameter.  This can be 0 (warning light off) or 1 (warning
  845. light on).
  846.  
  847. =head1 NOTES
  848.  
  849. This is the first release.  There are a few things on my mind for 0.02.
  850. First, PNG support would be easy to add in.  I don't use it so I haven't
  851. added it (yet).  Email if you want it.  Second, all of the meters are
  852. probably going to derive from a base class.  Haven't had time to change
  853. it yet.
  854.  
  855. Eventually I should pay more attention to the needle drawing in the
  856. Gauge class.  If your art is really good, the needles bring it down :(
  857.  
  858. I'm sure the docs could be better.
  859.  
  860. =head1 AUTHOR
  861.  
  862. David Ferrance (dave@ferrance.com)
  863.  
  864. =head1 LICENSE
  865.  
  866. Dashboard: A module for creating dashboard graphics.
  867.  
  868. Copyright (C) 2002 David Ferrance (dave@ferrance.com).  All Rights Reserved.
  869.  
  870. This module is free software. It may be used, redistributed and/or modified under the same terms as perl itself.
  871.  
  872. Sample graphics provided by rabia@rabia.com.  This module isn't worth much
  873. without a good graphics person to provide you with sweet dashboard layouts.
  874.  
  875.  
  876. =cut
  877.  
  878.