Roxen.git / server / modules / graphics / gbutton.pike

version» Context lines:

Roxen.git/server/modules/graphics/gbutton.pike:18:   // icon-src -- icon reference   // icon-data -- inline icon data   // align -- left|center|right text alignment   // align-icon -- left|center-before|center-after|right icon alignment   // >Button text</gbutton>   //   // Alignment restriction: when text alignment is either left or right, icons   // must also be aligned left or right.       - constant cvs_version = "$Id: gbutton.pike,v 1.48 2000/05/25 11:49:09 jonasw Exp $"; + constant cvs_version = "$Id: gbutton.pike,v 1.49 2000/06/01 12:19:52 kuntri Exp $";   constant thread_safe = 1;      #include <module.h>   inherit "module";   inherit "roxenlib";         roxen.ImageCache button_cache;      constant module_type = MODULE_PARSER;   constant module_name = "GButton";   constant module_doc =   "Provides the <tt>&lt;gbutton&gt;</tt> tag that is used to draw graphical "   "buttons.";      TAGDOCUMENTATION   #ifdef manual - constant tagdoc=(["gbutton":"","gbutton-url":""]); - /* -  "<table border=0>" + constant imagecache=#"    -  "<tr><td><b>bgcolor</b></td><td>Background color inside and " -  "outside button</td></tr>" + <h2>Image cache attributes</h2> + All examples are made for the &lt;cimg&gt; tag.    -  "<tr><td><b>bordercolor</b></td><td>Button border color</td></tr>" + <attr name='format' value='gif|jpeg|png|avs|gmp|bd|hrz|ilbm|psx|pnm|ps|pvr|tga|tiff|wbf|xbm|xpm' default='gif'> +  The format to encode the image to. The formats available are: + <table> + <tr><td>gif</td><td>Graphics Interchange Format (might be missing in your roxen)</td></tr> + <tr><td>jpeg</td><td>Joint Photography Expert Group image compression</td></tr> + <tr><td>png</td><td>Portable Networks Graphics</td></tr> + <tr><td>avs</td><td></td></tr> + <tr><td>bmp</td><td>Windows BitMaP file</td></tr> + <tr><td>gd</td><td></td></tr> + <tr><td>hrz</td><td>HRZ is (was?) used for amatuer radio slow-scan TV.</td></tr> + <tr><td>ilbm</td><td></td></tr> + <tr><td>pcx</td><td>Zsoft PCX file format (PC / DOS)</td></tr> + <tr><td>pnm</td><td>Portable AnyMap</td></tr> + <tr><td>ps</td><td>Adobe PostScript file</td></tr> + <tr><td>pvr</td><td>Pover VR (dreamcast image)</td></tr> + <tr><td>tga</td><td>TrueVision Targa (PC / DOS)</td></tr> + <tr><td>tiff</td><td>Tag Image File Format</td></tr> + <tr><td>wbf</td><td>WAP Bitmap File</td></tr> + <tr><td>xbm</td><td>XWindows Bitmap File</td></tr> + <tr><td>xpm</td><td>XWindows Pixmap File</td></tr> + </table> + <ex> + <cimg src='internal-roxen-robodog' format='png'/> + </ex> + <ex> + <cimg src='internal-roxen-robodog' format='gif'/> + </ex> + </attr>    -  "<tr><td><b>textcolor</b></td><td>Button text color</td></tr>" +     -  "<tr><td><b>href</b></td><td>Button URL</td></tr>" + <attr name='quant' value='number' default='format dependant'> +  The number of colors to quantizize the image to. + <p> +  Default for gif is 255(+1 transparent), for most other formats +  (except black and white) is it unlimited.</p>    -  "<tr><td><b>alt</b></td><td>Alternative button alt text</td></tr>" + <ex> + <cimg src='internal-roxen-robodog' quant='100'/> + </ex> + <ex> + <cimg src='internal-roxen-robodog' quant='10'/> + </ex> + <ex> + <cimg src='internal-roxen-robodog' quant='2'/> + </ex>    -  "<tr><td><b>border</b></td><td>Image border</td></tr>" + </attr>    -  "<tr><td><b>state</b></td><td>Set to <tt>enabled</tt> or " -  "<tt>disabled</tt> to select button state</td></tr>" + <h1>Color/alpha attributes</h1>    -  "<tr><td><b>textstyle</b></td><td>Set to <tt>normal</tt> or " -  "<tt>condensed</tt> to alter text style.</td></tr>" + <attr name='dither' value='none|random|floyd-steinberg' default='none'> +  Choose the dithering method. + <table> + <tr><td>none</td><td>No dithering is performed at all.</td></tr> + <tr><td>random</td><td>Random scatter dither. Not visually pleasing, but it is useful for very high resolution printing.</td></tr> + <tr><td>floyd-steinberg</td><td>Error diffusion dithering. Usually the best dithering method.</td></tr> + </table>    -  "<tr><td><b>icon-src</b></td><td>Icon reference</td></tr>" + <ex> + <cimg src='internal-roxen-robodog' dither='random' quant='10'/> + </ex> + <ex> + <cimg src='internal-roxen-robodog' dither='floyd-steinberg' quant='10'/> + </ex> + </attr>    -  "<tr><td><b>icon-data</b></td><td>Inline icon data</td></tr>" + <attr name='true-alpha'> +  If present, render a real alpha channel instead of on/off alpha. If +  the file format only supports on/off alpha, the alpha channel is +  dithered using a floyd-steinberg dither.    -  "<tr><td><b>align</b></td><td>Text alignment: " -  "<tt>left|center|right</tt></td></tr>" + <ex> + <cimg src='internal-roxen-robodog' opaque-value='20'/> + </ex> + <ex> + <cimg src='internal-roxen-robodog' opaque-value='20' true-alpha='1'/> + </ex> + </attr>    -  "<tr><td><b>align-icon</b></td><td>Icon alignment: " -  "<tt>left|center-before|center-after|right</tt></td></tr>" + <attr name='background-color' value='color' default='taken from the page'> +  The color to render the image against. + <ex> + <cimg src='internal-roxen-robodog' background-color='black' opaque-value='50'/> + </ex> + </attr>    -  "</table><p>" -  "There are some alignment restrictions: when text alignment is " -  "either <tt>left</tt> or <tt>right</tt>, icons must also be " -  "aligned <tt>left</tt> or <tt>right</tt>." -  */ + <attr name='opaque-value' value='percentage' default='100'> +  The transparency value to use, 100 is fully opaque, and 0 is fully +  transparent. + </attr> +  + <attr name='cs-rgb-hsv' value='0|1' default='0'> +  Perform rgb to hsv colorspace conversion. + <ex> + <cimg src='internal-roxen-robodog' cs-rgb-hsv='1'/> + </ex> + </attr> +  + <attr name='gamma' value='number' default='1.0'> +  Perform gamma adjustment. + <ex> + <cimg src='internal-roxen-robodog' gamma='0.1'/> + </ex> + <ex> + <cimg src='internal-roxen-robodog' gamma='0.5'/> + </ex> + <ex> + <cimg src='internal-roxen-robodog' gamma='1.0'/> + </ex> + <ex> + <cimg src='internal-roxen-robodog' gamma='2.0'/> + </ex> + <ex> + <cimg src='internal-roxen-robodog' gamma='8.0'/> + </ex> + </attr> +  + <attr name='cs-grey' value='0|1' default='0'> +  Perform rgb to greyscale colorspace conversion. + <ex> + <cimg src='internal-roxen-robodog' cs-grey='1'/> + </ex> + </attr> +  + <attr name='cs-invert' value='0|1' default='0'> +  Invert all colors + <ex> + <cimg src='internal-roxen-robodog' cs-invert='1'/> + </ex> + </attr> +  + <attr name='cs-hsv-rgb' value='0|1' default='0'> +  Perform hsv to rgb colorspace conversion. + <ex> + <cimg src='internal-roxen-robodog' cs-hsv-rgb='1'/> + </ex> + <ex> + <cimg src='internal-roxen-robodog' cs-grey='1' cs-hsv-rgb='1' cs-rgb-hsv='1'/> + </ex> + <ex> + <cimg src='internal-roxen-robodog' cs-hsv-rgb='1' cs-invert='1' cs-rgb-hsv='1/> + </ex> + </attr> +  + <h1>Transform attributes</h1> +  + <attr name='rotate-cw' value='degree' default='0'> +  Rotate the image clock-wise. + <ex> + <cimg src='internal-roxen-robodog' rotate-cw='20'/> + </ex> + <ex> + <cimg src='internal-roxen-robodog' rotate-cw='90'/> + </ex> + </attr> +  + <attr name='rotate-ccw' value='degree' default='0'> +  Rotate the image counter clock-wise. + <ex> + <cimg src='internal-roxen-robodog' rotate-ccw='20'/> + </ex> + <ex> + <cimg src='internal-roxen-robodog' rotate-ccw='90'/> + </ex> + </attr> +  + <attr name='rotate-unit' value='rad|deg|ndeg|part' default='deg'> +  Select the unit to use while rotating. +  + <table> + <tr><td>rad</td><td>Radians</td></tr> + <tr><td>deg</td><td>Degrees</td></tr> + <tr><td>ndeg</td><td>'New' degrees (400 for each full rotation)</td></tr> + <tr><td>part</td><td>0 - 1.0 (1.0 == full rotation)</td></tr> + </table> + <ex> + <cimg src='internal-roxen-robodog' rotate-ccw='1.2' rotate-unit='rad'/> + </ex> + <ex> + <cimg src='internal-roxen-robodog' rotate-ccw='20' rotate-unit='deg'/> + </ex> + <ex> + <cimg src='internal-roxen-robodog' rotate-ccw='0.2' rotate-unit='part'/> + </ex> + </attr> +  + <attr name='mirror-x' value='0|1' default='0'> +  Mirror the image around the X-axis. + <ex> + <cimg src='internal-roxen-robodog' mirror-x='1'/> + </ex> + </attr> +  + <attr name='mirror-y' value='0|1' default='0'> +  Mirror the image around the Y-axis. + <ex> + <cimg src='internal-roxen-robodog' mirror-y='1'/> + </ex> + </attr> +  + <attr name='scale' value='fact' default='1.0'> +  Scale fact times. (0.5 -> half size, 2.0 -> double size) + <ex> + <cimg src='internal-roxen-robodog' scale='0.5'/> + </ex> + <ex> + <cimg src='internal-roxen-robodog' scale='1.2'/> + </ex> + </attr> +  + <attr name='scale' value='x,y'> +  Scale to the exact size x,y. If either of X or Y is zero, the image +  is scaled to the specified width or hight, and the value that is zero +  is scaled in proportion to the other value. + <ex> + <cimg src='internal-roxen-robodog' scale='10,40'/> + </ex> + <ex> + <cimg src='internal-roxen-robodog' scale='100,0'/> + </ex> + <ex> + <cimg src='internal-roxen-robodog' scale='0,10'/> + </ex> + <ex> + <cimg src='internal-roxen-robodog' scale='100,10'/> + </ex> + </attr> +  + <attr name='max-width' value='xsize'> +  If width is larger than 'xsize', scale width to 'xsize' while +  keeping aspect. + <ex> + <cimg src='internal-roxen-robodog' max-width='300'/> + </ex> + <ex> + <cimg src='internal-roxen-robodog' max-width='100'/> + </ex> + </attr> +  + <attr name='max-height' value='ysize'> +  If width is larger than 'ysize', scale width to 'ysize' while +  keeping aspect. + <ex> + <cimg src='internal-roxen-robodog' max-height='300'/> + </ex> + <ex> + <cimg src='internal-roxen-robodog' max-height='30'/> + </ex> + </attr> +  + <attr name='x-offset' value='pixels' default='0'> +  Cut n pixels from the beginning of the X scale. + <ex> + <cimg src='internal-roxen-robodog' x-offset='10'/> + </ex> + <ex> + <cimg src='internal-roxen-robodog' x-offset='50'/> + </ex> + </attr> +  + <attr name='y-offset' value='pixels' default='0'> +  Cut n pixels from the beginning of the Y scale. + <ex> + <cimg src='internal-roxen-robodog' y-offset='10'/> + </ex> + <ex> + <cimg src='internal-roxen-robodog' y-offset='30'/> + </ex> + </attr> +  + <attr name='x-size' value='pixels' default='whole image'> +  Keep n pixels from the beginning of the X scale. + <ex> + <cimg src='internal-roxen-robodog' x-size='100'/> + </ex> + </attr> +  + <attr name='y-size' value='pixels' default='whole image'> +  Keep n pixels from the beginning of the Y scale. + <ex> + <cimg src='internal-roxen-robodog' y-size='30'/> + </ex> + <ex> + <cimg src='internal-roxen-robodog' y-size='100'/> + </ex> + </attr> +  + <attr name=crop value='x0,y0-x1,y1' default='whole image'> +  Crop the image by specifying the pixel coordinates. + <ex> + <cimg src='internal-roxen-robodog' crop='50,00-150,20'/> + </ex> + <ex> + <cimg src='internal-roxen-robodog' crop='50,28-150,92'/> + </ex> + <ex> + <cimg src='internal-roxen-robodog' crop='0,0-200,20'/> + </ex> + <ex> + <cimg src='internal-roxen-robodog' crop='0,28-200,92'/> + </ex> + </attr> +  + <h1>Format specific attributes</h1> +  + <attr name='jpeg-quality' value='percentage' default='75'> +  Set the quality on the output jpeg image. + <ex> + <cimg src='internal-roxen-robodog' format='jpeg' jpeg-quality='100'/> + </ex> + <ex> + <cimg src='internal-roxen-robodog' format='jpeg' jpeg-quality='30'/> + </ex> + <ex> + <cimg src='internal-roxen-robodog' format='jpeg' jpeg-quality='1'/> + </ex> + </attr> +  + <attr name='jpeg-optimize' value='0|1' default='1'> +  If 0, do not generate optimal tables. Somewhat faster, but produces +  bigger files. + </attr> +  + <attr name='jpeg-progressive=' value='0|1' default='0'> +  Generate progressive jpeg images. + </attr> +  + <attr name='jpeg-smooth' value='0-100' default='0'> +  Smooth the image while compressing it. This produces smaller files, +  but might undo the effects of dithering. + <ex> + <cimg src='internal-roxen-robodog' format='jpeg' jpeg-quality='10' jpeg-smooth='0'/> + </ex> + <ex> + <cimg src='internal-roxen-robodog' format='jpeg' jpeg-quality='10' jpeg-smooth='100'/> + </ex> + </attr> +  + <attr name='bmp-bpp' value='1,4,8,24' default='24'> +  Force this number of bits per pixel for bmp images. + </attr> +  + <attr name='bmp-windows' value='0|1' default='1'> +  Windows or OS/2 mode, default is 1. (windows mode) + </attr> +  + <attr name='bmp-rle' value='0|1' default='0'> +  RLE 'compress' the BMP image. + </attr> +  + <attr name='gd-alpha_index' value='color' default='0'> +  Color in the colormap to make transparent for GD-images with alpha +  channel. + </attr> +  + <attr name='pcx-raw' value='1|0' default='0'> +  If 1, do not RLE encode the PCX image. + </attr> +  + <attr name='pcx-dpy' value='0-10000000.0' default='75.0'> +  Resolution, in pixels per inch. + </attr> +  + <attr name='pcx-xdpy' value='0-10000000.0' default='75.0'> +  Resolution, in pixels per inch. + </attr> +  + <attr name='pcx-ydpy' value='0-10000000.0' default='75. +  Resolution, in pixels per inch. + </attr> +  + <attr name='pcx-xoffset' value='0-imagexsize-2' default='0'> +  Offset from start of image data to image content for PCX images. +  Unused by most programs. + </attr> +  + <attr name='pcx-yoffset' value='0-imageysize-2' default='0'> +  Offset from start of image data to image content for PCX images. +  Unused by most programs. + </attr> +  + <attr name='tga-raw' value='1|0' default='0'> +  If 1, do not RLE encode the Targa image. + </attr> +  + <attr name='ps-dpi' value='0-10000000.0' default='75.0'> +  Dots per inch for the resulting postscript file. + </attr>"; +  + constant gbuttonattr=#" + <attr name='pagebgcolor' value='color'> +  + </attr> +  + <attr name='bgcolor' value='color'> +  Background color inside and outside button. + <ex> + <gbutton bgcolor='blue'>Background</gbutton> + </ex> + </attr> +  + <attr name='bordercolor' value='color'> +  Button border color. + <ex> + <gbutton bordercolor='red'>Border</gbutton> + </ex> + </attr> +  + <attr name='textcolor' value='color'> +  Button text color + <ex> + <gbutton bordercolor='red' textcolor='green'> Text</gbutton> + </ex> + </attr> +  + <attr name=frame-image value='path'> +  Use this XCF-image as a frame for the button. The image is required +  to have at least the following layers: background, mask and frame. +  More information on how to create frame images can be found in the +  Roxen documentation; Web Site Creator/Graphical tags section. + <ex> + <gbutton frame-image='internal-roxen-tabframe'>foo</gbutton> + </ex> + </attr> +  + <attr name='border_image' value='path'> +  Use this image as border. + </attr> +  + <attr name='alt' value='string'> +  Alternative button and alt text. + </attr> +  + <attr name='href' value='uri'> +  Button URI. + </attr> +  + <attr name='textstyle' value='normal|condensed'> +  Set to <att>normal</att> or <att>condensed</att> to alter text style. + </attr> +  + <attr name='width' value=''> +  Minimum button width. + </attr> +  + <attr name='align' value='left|center|right'> +  Set text alignment. There are some alignment restrictions: when text +  alignment is either <att>left</att> or <att>right</att>, icons must +  also be aligned <att>left</att> or <att>right</att>. + </attr> +  + <attr name='state' value='enabled|disabled'> +  Set to <att>enabled</att> or <att>disabled</att> to select button state. + </attr> +  + <attr name='icon-src' value='URI'> +  Fetch the icon from this URI. + </attr> +  + <attr name='icon-data' value=''> +  Inline icon data. + </attr> +  + <attr name='align-icon' value='left|center-before|center-after|right'> +  Set icon alignment. +  + <table> + <tr><td>left</td><td>Place icon on the left side of the text.</td></tr> + <tr><td>center-before</td><td>Center the icon before the text.Requires the <att>align='center'</att> attribute.</td></tr> + <tr><td>center-after</td><td>Center the icon after the text. Requires the <att>align='center'</att> attribute.</td></tr> + <tr><td>right</td><td>Place icon on the right side of the text.</td></tr> +  + <ex> + <gbutton width='150' align-icon='center-before' icon-src='internal-roxen-help'>Roxen 2.0</gbutton> + </ex> + <ex> + <gbutton width='150' align='center' align-icon='center-after' icon-src='internal-roxen-help'>Roxen 2.0</gbutton> + </ex> + </attr> +  + <attr name='font' value=''> +  + </attr> +  + <attr name='extra-layers' value='[''],[first|last],[selected|unselected],[background|mask|frame|left|right]'> +  + </attr> +  + <attr name='extra-left-layers' value='[''],[first|last],[selected|unselected],[background|mask|frame|left|right]'> +  + </attr> +  + <attr name='extra-right-layers' value='[''],[first|last],[selected|unselected],[background|mask|frame|left|right]'> +  + </attr> +  + <attr name='extra-background-layers' value='[''],[first|last],[selected|unselected],[background|mask|frame|left|right]'> +  + </attr> +  + <attr name='extra-mask-layers' value='[''],[first|last],[selected|unselected],[background|mask|frame|left|right]'> +  + </attr> +  + <attr name='extra-frame-layers' value='[''],[first|last],[selected|unselected],[background|mask|frame|left|right]'> +  + <ex> + <gbutton border_image='gbutton.xcf' alt='foo'>bu</gbutton> + </ex> +  +  + <ex> + <gbutton alt='Edit' bgcolor='#aeaeae' +  extra-background-layers='unselected background,last unselected background,last background' +  extra-frame-layers='unselected frame,last unselected frame,last frame' +  extra-layers='unselected,last unselected,last' +  extra-left-layers='unselected left,last unselected left,last left' +  extra-mask-layers='unselected mask,last unselected mask,last mask' +  extra-right-layers='unselected right,last unselected right,last right' > + </gbutton> + </ex> + </attr> +  + <!-- <table> + <tr><td>A</td><td>B</td><td>C</td></tr> + <tr><td>''</td><td>''</td><td>''</td></tr> + <tr><td>'first'</td><td>'selected'</td><td>'background'</td></tr> + <tr><td>'last'</td><td>'unselected'</td><td>'mask'</td></tr> + <tr><td></td><td></td><td>'frame'</td></tr> + <tr><td></td><td></td><td>'left'</td></tr> + <tr><td></td><td></td><td>'right'</td></tr> + </table> -->"; +  + constant tagdoc=(["gbutton":#"<desc cont><short>Creates graphical buttons.</short> </desc>" +  + +gbuttonattr + +imagecache, +  + "gbutton-url":#"<desc><short>Generates an URI to the button.</short> + <tag>gbutton-url</tag> takes the same attributes as <tag>gbutton</tag> + including the image cache attributes.</desc>" +  + +gbuttonattr + +imagecache, +  ]);   #endif      function TIMER( function f )   {   #if 0    return lambda(mixed ... args) {    int h = gethrtime();    mixed res;    werror("Drawing ... ");    res = f( @args );