NAME

Buttoner.pm - Make button GIFs via GD


AUTHOR

 David M. Chess


SYNOPSIS

    use Buttoner;

    # create a simple button and save as a GIF
    $button = new Buttoner::Button(120,30,"Push Here");
    print OUTH $button->gif();

    # Exercising more control...
    $button = new Buttoner::Button(140,40,"Continue",0,128,0);
    $button->setCenterText(1);               # Center the text
    $button->setEdgeWidth(2);                # Mess with the shape
    $button->setBlur(1);                     #  and fuzz it a little
    print GIFNORMAL $button->gif();          # Save that
    $button->setTextColor(255,0,0);          # Red-text version
    print GIFACTIVE $button->gif();          # Save that
    $button->setPressed(1);                  # Pressed-button version
    $button->setTextStyle("raise");          #  with "raised" text
    print GIFPUSHED $button->gif();          # and save that


HISTORY

  1999/08/31 - First release version, 1.00


BUGS

None currently known; see Plans and Limitations


PLANS AND LIMITATIONS

The text font is always gdGiantFont which, despite the name, is a mere 9x15 pels. Should use a smaller font for teensy buttons, and (to begin with) use copyResized() to fake a larger font for larger buttons. Ideally, should access the system fonts and use those instead of the gdFont(s).

Buttons are always just rectangles; would be nice to allow rounded-corner buttons, at least.


Creating a new object


new(width,height,text,red,green,blue)

returns a new button instance, of the given height and width, the given text label, and the given RGB color. Defaults will be provided for any missing arguments; the default is something like (200,50,``Hello, sailor!'',128,128,128). Methods exist to change all these before or between rendering.


Adjusting its appearance


Buttoner::Button::setText("your message here")

Sets/changes the text for the button label.


Buttoner::Button::setCenterText(boolean)

Turns on/off centering of the button label; default is off.


Buttoner::Button::setEdgeWidth(new_width)

Sets the width, in pels, of the vaguely-3D-looking border around the button. Setting this to zero produces a ``flat'' button. Default is like four or something.


Buttoner::Button::setPressed(boolean)

Turns on/off the display of the button in ``pressed'' state. Press and unpressed states assume, of course, that the button is lit from the upper left. Default is off (false).


Buttoner::Button::setBlur(level)

Specifies the blur level of the button; default is zero. The button image is blurred (softened) before the text is applied; the text doesn't get blurred. Images with non-zero blur take somewhat longer to produce, and will tend to be larger (because they use more colors).


Buttoner::Button::setContrast(level)

Specifies the contrast level (a number between 0 and 2ish) of the brightened and shadowed colors used for the quasi-3D effects. The default is 0.5. A contrast of 0 produces a flat button; a contrast of 1 makes the colors considerably brighter/darker.


Buttoner::Button::setColor(red,green,blue)

sets or changes the button's main color, which is used on the face of the button. (And used at rendering time, along with the contrast, to derive the other colors used in the quasi-3D effects.)


Buttoner::Button::setTextColor(red,green,blue)

sets or changes the color to be used for the button label.


Buttoner::Button::setTextStyle(stylename)

sets or changes the style of the button label. Valid choices are ``incise'' (the default; looks vaguely recessed into the face of the button), ``raise'' (looks vaguely raised), and ``flat'' (just sitting there).


Rendering a button


Buttoner::Button::gif()

returns, as a potentially rather long binary string, a GIF-format representation of the button with the current appearance settings, for writing to a file, piping to a display program, or whatever. This method may be called multiple times, with appearance-adjusting calls in between, to render different versions of the ``same'' button (see SYNPOSIS).


Copyright

This code is hereby dedicated to the Public Domain. Anyone in the world can do anything they want with it, for all of me. Of course, anyone who sticks their own name on it and tries to submit it to CPAN or sell it for big bucks or anything, will just be making a fool of themself...

David M. Chess, 1999