Buttoner.pm - Make button GIFs via GD
David M. Chess
# 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
1999/08/31 - First release version, 1.00
None currently known; see 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
Buttons are always just rectangles; would be nice to allow rounded-corner buttons, at least.
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.
Sets/changes the text for the button label.
Turns on/off centering of the button label; default is off.
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.
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).
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).
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.
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.)
sets or changes the color to be used for the button label.
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).
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).
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