Date: 04/27/00
- Next message: Kristian Koehntopp: "[phplib-dev] Simulspam"
- Previous message: Kristian Köhntopp: "[phplib-dev] Re: Fwd: failure notice"
- Next in thread: uw: "[phplib-dev] cvs commit"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
From: uw
Date: Thu Apr 27 19:30:24 2000
Modified files:
php-lib/php/form/assistant_gifimage.inc
Log message:
- added graphical buttons with autosize feature
Index: php-lib/php/form/assistant_gifimage.inc
diff -u php-lib/php/form/assistant_gifimage.inc:1.1 php-lib/php/form/assistant_gifimage.inc:1.2
--- php-lib/php/form/assistant_gifimage.inc:1.1 Thu Apr 27 18:16:57 2000
+++ php-lib/php/form/assistant_gifimage.inc Thu Apr 27 19:30:23 2000
@@ -4,44 +4,78 @@
/**
* Path to the ttf font
* <email protected> string $font
+ * <email protected> private
*/
var $font = "/home/www/servers/ulf.dev.netuse.de/fonts/arial.ttf";
/**
* Font size of a tab
* <email protected> int $fsize
+ * <email protected> private
*/
var $fsize = 11;
/**
* Directory used for cached the the images
* <email protected> string $cache_dir
+ * <email protected> private
*/
var $cache_dir = "$DOCUMENT_ROOT/images/tmp/";
/**
* URL used in the src attribute of <input type="image">
* <email protected> string $cache_url
+ * <email protected> private
*/
var $cache_url = "images/tmp";
/**
+ * See button_width!
+ * <email protected> boolean $button_autosize
+ * <email protected> private
+ * <email protected> button_width, button_height
+ */
+ var $flag_button_autosize = true;
+
+ /**
+ * Width of a button. If flag_button_autosize is set,
+ * the width of the generate image is the width of
+ * the label plus button_width.
+ * <email protected> int $button_width
+ * <email protected> private
+ * <email protected> button_height
+ */
+ var $button_width = 10;
+
+ /**
+ * Height of a button, see button_width
+ * <email protected> int $button_height
+ * <email protected> private
+ * <email protected> button_width
+ */
+ var $button_height = 9;
+
+ /**
* Width of a tab
* <email protected> int $width
+ * <email protected> tab_height
+ * <email protected> private
*/
- var $width = 105;
+ var $tab_width = 105;
/**
* Height of a tab
* <email protected> int $height
+ * <email protected> private
*/
- var $height = 18;
+ var $tab_height = 18;
/**
* global default color. Colors can be defines as
* an array of rgb values [0-255] or as an html
* color (#ffffff)
* <email protected> string|array $default_color
+ * <email protected> private
*/
var $default_color = "";
@@ -49,12 +83,14 @@
/**
* Render 3D tabs?
* <email protected> boolean $flag_3d
+ * <email protected> private
*/
var $flag_3d = true;
/**
* background color used in the template
* <email protected> array $tab_bgcolor
+ * <email protected> private
*/
var $tab_bgcolor = array (
"error" => "",
@@ -65,6 +101,7 @@
/**
* Colors used to render the tab (image only)
* <email protected> array $tab_color
+ * <email protected> private
*/
var $tab_color = array(
"label" => array(
@@ -84,25 +121,29 @@
"dark" => array(0, 0, 0)
)
);
+
/**
- * border attribute of the tabs
- * <email protected> int $tab_border
+ * Colors used to render a button
+ * <email protected> array $button_color
+ * <email protected> private
*/
- var $tab_border = 1;
+ var $button_color = array(
+ "label" => array(244, 255, 255),
+
+ "bgcolor" => "#006699",
+
+ "3d" => array(
+ "bright" => array(152, 209, 254),
+ "dark" => array(0, 0, 0)
+ )
+ );
/**
- * return a reset button
- * <email protected> string $label
- * <email protected> string $hmtl
+ * border attribute of the tabs
+ * <email protected> int $tab_border
* <email protected> private
- */
- function getResetButton($label) {
- if (""==(string)$label) {
- $this->setError(16, "assistant -> getResetButton(), illegal function call");
- return "";
- }
- return sprintf('<input type="reset" value="%s">', $label);
- } // end getResetButton
+ */
+ var $tab_border = 1;
/**
* return a submit button
@@ -111,66 +152,116 @@
* <email protected> string $name
* <email protected> string $html
* <email protected> private
+ * <email protected> createButton()
*/
function getButton($label, $value, $name="") {
if (""==(string)$label || (""==(string)$value && ""==(string)$name)) {
- $this->setError(15, "assistent -> getButton(), illegal function call");
+ $this->setError(15, "assistant_gifimage -> getButton(), illegal function call");
return "";
}
+
+ $imgname = md5(sprintf("%s:%s%s", $label, $value, $name));
+ $file = sprintf("%s/%s.gif", $this->cache_dir, $imgname);
+ $url = sprintf("%s/%s.gif", $this->cache_url, $imgname);
+
+ if (!file_exists($this->cache_dir) || !is_dir($this->cache_dir)) {
+ $ok = <email protected>($this->cache_dir, 0755);
+ if (false == $ok) {
+ $this->setError(52, "assistant_gifimage -> getButton(), can't create cache directory.");
+ return "";
+ }
+ }
+ if (!file_exists($file)) {
+ $ok = $this->createButton($file, $label, $value, $name);
+ if (false == $ok)
+ return "";
+ }
+
+ $size = <email protected>($file);
+
if (""==$name)
$name = sprintf("%s_%d", $this->buttonname, $value);
-
- $html = sprintf('<input type="submit" value="%s" name="%s">',
- $label,
- $name
+
+ $html = sprintf('<input type="image" name="%s" value="%s" src="%s" %s border="%s" alt="%s">',
+ $name,
+ $value,
+ $url,
+ $size[3],
+ $this->tab_border,
+ $label
);
- return $html;
+ return $html;
} // end func getButton
-
- /**
- * You're allowed to define colors eigther
- * as an array of rgb [0-255] values or as
- * an html color (#00ff00). This method
- * translates the color into an html color if
- * neccessary. If no color is given
- * $this->defaul_color is used
- * <email protected> string|array $color
- * <email protected> string $color
- * <email protected> GDColor()
- */
- function HTMLColor($value) {
- if (""==$value)
- $value = $this->default_color;
- if (""==$value)
- return "";
-
- if (!is_array($value))
- return $value;
-
- return sprintf('#%02x%02x%02x', $value[0], $value[1], $value[2]);
- } // end func gHTMLColor
/**
- * Similar to HTMLColor. GDColors must be an array
- * <email protected> string|array $color
- * <email protected> array $color
- * <email protected> HTMLColor()
+ * Creates a graphical button
+ * <email protected> string $file
+ * <email protected> string $label
+ * <email protected> string $value
+ * <email protected> string $name = ""
+ * <email protected> private
+ * <email protected> boolean $ok
+ * <email protected> getButton()
*/
- function GDColor($value) {
- if (""==$value)
- $value = $this->default_color;
+ function createButton($file, $label, $value, $name="") {
- if (is_array($value))
- return $value;
-
- $hex = array (
- 0 => HexDec(substr($value, 1, 2)),
- 1 => HexDec(substr($value, 3, 2)),
- 2 => HexDec(substr($value, 5, 2))
- );
- return $hex;
- } // end func GDColor
+ if (true == $this->flag_button_autosize) {
+
+ $im = <email protected>(500, 100);
+ if (false == $im) {
+ $this->setError(53, "assistant_gifimage -> createButton(), can't create an image.");
+ return false;
+ }
+ $pos = ImageTTFBBox($this->fsize, 0, $this->font, $label);
+ $width = abs($pos[0]) + abs($pos[2]) + $this->button_width;
+ $height = abs($pos[1]) + abs($pos[7]) + $this->button_height;
+
+ } else {
+
+ $width = $this->button_width;
+ $height = $this->button_height;
+
+ }
+
+ $im = <email protected>($width, $height);
+ if ( false == $im) {
+ $this->setError(53, "assistant_gifimage -> createButton(), can't create an image.");
+ return false;
+ }
+
+ $col = $this->GDColor($this->button_color["label"]);
+ $tx = ImageColorAllocate($im, $col[0], $col[1], $col[2]);
+
+ $col = $this->GDColor($this->button_color["bgcolor"]);
+ $bg = ImageColorAllocate($im, $col[0], $col[1], $col[2]);
+
+ ImageFilledRectangle($im, 0, 0, $width, $height, $bg);
+
+ if (true == $this->flag_3d) {
+
+ $col = $this->GDColor($this->button_color["3d"]["bright"]);
+ $white = ImageColorAllocate($im, $col[0], $col[1], $col[2]);
+
+ $col = $this->GDColor($this->button_color["3d"]["dark"]);
+ $black = ImageColorAllocate($im, $col[0], $col[1], $col[3]);
+
+ ImageLine($im, 0, 0, ($width)-0, 0, $white);
+ ImageLine($im, $width, 0, $width, $height, $black);
+ ImageLine($im, 0, ($height)-1, $width, ($height)-1, $black);
+ ImageLine($im, 0, 0, 0, ($height)-1, $black);
+ }
+
+ $pos = ImageTTFBBox($this->fsize, 0, $this->font, $label);
+ $x = (int)($width-($pos[2]-$pos[0]))/2 ;
+ $y = (int)($height-($pos[7]-$pos[1]))/2 -1;
+
+ ImageTTFText($im, $this->fsize, 0, $x, $y, $tx, $this->font, $label);
+ ImageGif($im, $file);
+ ImageDestroy($im);
+
+ return true;
+ } // end func createTab
/**
* Generate a graphical tab
@@ -238,7 +329,7 @@
*/
function createTab($file, $label, $value, $optional, $error) {
- $im = <email protected>($this->width, $this->height);
+ $im = <email protected>($this->tab_width, $this->tab_height);
if ( false == $im) {
$this->setError(50, "assistant_gifimage -> createTab(), can't create an image.");
return false;
@@ -259,7 +350,7 @@
$col = $this->GDColor($this->tab_color["bgcolor"][$k]);
$bg = ImageColorAllocate($im, $col[0], $col[1], $col[2]);
- ImageFilledRectangle($im, 0, 0, $this->width, $this->height, $bg);
+ ImageFilledRectangle($im, 0, 0, $this->tab_width, $this->tab_height, $bg);
if (true == $this->flag_3d) {
@@ -269,16 +360,16 @@
$col = $this->GDColor($this->tab_color["3d"]["dark"]);
$black = ImageColorAllocate($im, $col[0], $col[1], $col[3]);
- ImageLine($im, 0, 0, ($this->width)-0, 0, $white);
- ImageLine($im, $this->width, 0, $this->width, $this->height, $black);
- ImageLine($im, 0, ($this->height)-1, $this->width, ($this->height)-1, $black);
- ImageLine($im, 0, 0, 0, ($this->height)-1, $black);
+ ImageLine($im, 0, 0, ($this->tab_width)-0, 0, $white);
+ ImageLine($im, $this->tab_width, 0, $this->tab_width, $this->tab_height, $black);
+ ImageLine($im, 0, ($this->tab_height)-1, $this->tab_width, ($this->tab_height)-1, $black);
+ ImageLine($im, 0, 0, 0, ($this->tab_height)-1, $black);
}
$pos = ImageTTFBBox($this->fsize, 0, $this->font, $label);
- $x = (int)($this->width-($pos[2]-$pos[0]))/2 ;
- $y = (int)($this->height-($pos[7]-$pos[1]))/2 -1;
+ $x = (int)($this->tab_width-($pos[2]-$pos[0]))/2 ;
+ $y = (int)($this->tab_height-($pos[7]-$pos[1]))/2 -1;
ImageTTFText($im, $this->fsize, 0, $x, $y, $tx, $this->font, $label);
ImageGif($im, $file);
@@ -286,6 +377,52 @@
return true;
} // end func createTab
+
+ /**
+ * You're allowed to define colors eigther
+ * as an array of rgb [0-255] values or as
+ * an html color (#00ff00). This method
+ * translates the color into an html color if
+ * neccessary. If no color is given
+ * $this->defaul_color is used
+ * <email protected> string|array $color
+ * <email protected> string $color
+ * <email protected> private
+ * <email protected> GDColor()
+ */
+ function HTMLColor($value) {
+ if (""==$value)
+ $value = $this->default_color;
+ if (""==$value)
+ return "";
+
+ if (!is_array($value))
+ return $value;
+
+ return sprintf('#%02x%02x%02x', $value[0], $value[1], $value[2]);
+ } // end func HTMLColor
+
+ /**
+ * Similar to HTMLColor. GDColors must be an array
+ * <email protected> string|array $color
+ * <email protected> array $color
+ * <email protected> private
+ * <email protected> HTMLColor()
+ */
+ function GDColor($value) {
+ if (""==$value)
+ $value = $this->default_color;
+
+ if (is_array($value))
+ return $value;
+
+ $hex = array (
+ 0 => HexDec(substr($value, 1, 2)),
+ 1 => HexDec(substr($value, 3, 2)),
+ 2 => HexDec(substr($value, 5, 2))
+ );
+ return $hex;
+ } // end func GDColor
} // end class assistant_gifimage
?>
---------------------------------------------------------------------
To unsubscribe, e-mail: phplib-dev-unsubscribe <email protected>
For additional commands, e-mail: phplib-dev-help <email protected>
- Next message: Kristian Koehntopp: "[phplib-dev] Simulspam"
- Previous message: Kristian Köhntopp: "[phplib-dev] Re: Fwd: failure notice"
- Next in thread: uw: "[phplib-dev] cvs commit"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

