|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
constant cvs_version = "$Id: gbutton.pike,v 1.14 2000/02/03 18:18:57 per Exp $"; |
constant thread_safe = 1; |
|
#include <module.h> |
inherit "module"; |
inherit "roxenlib"; |
|
|
roxen.ImageCache button_cache; |
Image.Image button_border; |
Image.Image button_mask; |
|
|
|
#define IMAGE_SPC 5 |
|
|
array register_module() |
{ |
return( ({ MODULE_PARSER, |
"GButton", |
"Provides the <tt><gbutton>Title</gbutton></tt> " |
"tag for drawing graphical buttons.", |
0, 1 }) ); |
} |
|
|
TAGDOCUMENTATION |
#if manual |
constant tagdoc=(["gbutton":"","gbutton-url":""]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif |
|
void start() |
{ |
button_cache = roxen.ImageCache("gbutton", draw_button); |
} |
|
|
mapping query_tag_callers() |
{ |
return ([ ]); |
} |
|
|
mapping query_container_callers() |
{ |
return ([ "gbutton" : tag_button, "gbutton-url" : tag_button ]); |
} |
|
|
object(Image.Image)|mapping draw_button(mapping args, string text, object id) |
{ |
Image.Image text_img, b, tmp, button; |
int req_width, b_width, b_height, t_width, i_width, icn_x, txt_x; |
mapping icon; |
object button_font = resolve_font( args->font ); |
|
|
if (!button_border) |
{ |
button_border = roxen.load_image("roxen-images/gbutton_border.gif", id); |
button_mask = roxen.load_image("roxen-images/gbutton_mask.gif", id); |
} |
|
|
if (!args->dim) |
{ |
b = button_border->clone()->grey()-> |
modify_by_intensity(1, 1, 1, args->bo, args->bob ); |
} |
else |
{ |
array dim_bg; |
array dim_bo; |
|
array hsv = Image.Color( @args->bg )->hsv( ); |
hsv[-1] = min( hsv[-1]+70, 255 ); |
|
dim_bg = (array)Image.Color.hsv( @hsv ); |
|
hsv[-1] = max( hsv[-1]-140, 0 ); |
dim_bo = (array)Image.Color.hsv( @hsv ); |
|
b = button_border->grey()-> |
modify_by_intensity(1, 1, 1, dim_bo, dim_bg); |
} |
b_width = b->xsize(); |
b_height = b->ysize(); |
|
|
if (args->icn) |
icon = roxen.low_load_image(args->icn, id); |
else if (args->icd) |
icon = roxen.low_decode_image(args->icd); |
i_width = icon && (icon->img->xsize() + IMAGE_SPC); |
|
|
if (sizeof(text)) { |
text_img = button_font->write(text)->scale(0, b_height - IMAGE_SPC); |
if (args->cnd) |
text_img = text_img->scale((int) round(text_img->xsize() * 0.8), |
text_img->ysize()); |
t_width = text_img->xsize(); |
} |
|
|
req_width = t_width + b_width + i_width; |
if (args->wi && (req_width < args->wi)) |
req_width = args->wi; |
switch (lower_case(args->al)) { |
case "left": |
|
switch (lower_case(args->ica)) { |
case "left": |
icn_x = b_width / 2; |
txt_x = icn_x + i_width; |
break; |
default: |
case "right": |
txt_x = b_width / 2; |
icn_x = req_width - b_width / 2 - i_width + IMAGE_SPC; |
break; |
} |
break; |
|
default: |
case "center": |
case "middle": |
|
switch (lower_case(args->ica)) { |
case "left": |
icn_x = b_width / 2; |
txt_x = icn_x + i_width + |
(req_width - icn_x - i_width - b_width / 2 - t_width) / 2; |
break; |
default: |
case "center": |
case "center_before": |
icn_x = (req_width - i_width - t_width) / 2; |
txt_x = icn_x + i_width; |
break; |
case "center_after": |
txt_x = (req_width - i_width - t_width) / 2; |
icn_x = txt_x + t_width + IMAGE_SPC; |
break; |
case "right": |
icn_x = req_width - b_width / 2 - i_width + IMAGE_SPC; |
txt_x = b_width / 2 + (icn_x - IMAGE_SPC - b_width / 2 - t_width) / 2; |
break; |
} |
break; |
|
case "right": |
|
switch (lower_case(args->ica)) { |
default: |
case "left": |
icn_x = b_width / 2; |
txt_x = req_width - b_width / 2 - t_width; |
break; |
case "right": |
icn_x = req_width - b_width / 2 - i_width + IMAGE_SPC; |
txt_x = icn_x - IMAGE_SPC - t_width; |
break; |
} |
break; |
} |
button = Image.Image(req_width, b_height, args->bg); |
|
|
tmp = b->copy(0, 0, b_width / 2 - 1, b_height - 1); |
button->paste_mask(tmp, button_mask->copy(0, 0, |
b_width / 2 - 1, b_height - 1)); |
tmp = b->copy(b_width / 2, 0, b_width - 1, b_height - 1); |
button->paste_mask(tmp, button_mask->copy(b_width / 2, 0, |
b_width - 1, b_height - 1), |
req_width - b_width / 2, 0); |
|
|
tmp = button->copy(b_width / 2 - 1, 0, b_width / 2 - 1, b_height - 1); |
for (int offset = b_width / 2; offset <= req_width - b_width / 2; offset++) |
button->paste(tmp, offset, 0); |
|
|
if (icon) { |
int icn_y = (b_height - icon->img->ysize()) / 2; |
|
if (!icon->alpha) |
icon->alpha = icon->img->clone()->clear(({255,255,255})); |
if (args->dim) |
icon->alpha *= 0.3; |
button->paste_mask(icon->img, icon->alpha, icn_x, icn_y); |
} |
|
|
if (args->dim) |
for (int i = 0; i < 3; i++) |
args->txt[i] = (args->txt[i] + args->bg[i]) / 2; |
if(text_img) |
button->paste_alpha_color(text_img, args->txt, txt_x, 2); |
|
return button; |
} |
|
|
mapping find_internal(string f, RequestID id) |
{ |
return button_cache->http_file_answer(f, id); |
} |
|
|
string tag_button(string tag, mapping args, string contents, RequestID id) |
{ |
mapping new_args = ([ |
"bg" : parse_color(args->bgcolor || id->misc->defines->theme_bgcolor || |
id->misc->defines->bgcolor || "#eeeeee"), |
"txt" : parse_color(args->textcolor || id->misc->defines->theme_bgcolor || |
id->misc->defines->fgcolor || "#000000"), |
"cnd" : args->condensed || |
(lower_case(args->textstyle || "") == "condensed"), |
"wi" : (int) args->width, |
"al" : args->align || "left", |
"dim" : args->dim || |
(< "dim", "disabled" >)[lower_case(args->state || "")], |
"icn" : args->icon_src && fix_relative(args->icon_src, id), |
"icd" : args->icon_data, |
"ica" : args->align_icon || "left", |
"font": (args->font||roxen->query("default_font")), |
]); |
|
array hsv = Image.Color( @new_args->bg )->hsv( ); |
hsv[-1] = min( hsv[-1]+70, 255 ); |
hsv[1] = max( hsv[1]-20, 0 ); |
new_args->bob = (array)Image.Color.hsv( @hsv ); |
hsv[-1] = max( hsv[-1]-140, 0 ); |
new_args->bo = (array)Image.Color.hsv( @hsv ); |
|
if(args->bordercolor) |
new_args->bo=parse_color(args->bordercolor); |
|
if(args->borderbottom) |
new_args->bob=parse_color(args->borderbottom); |
|
new_args->quant = args->quant || 128; |
foreach(glob("*-*", indices(args)), string n) |
new_args[n] = args[n]; |
|
string img_src = |
query_internal_location() + |
button_cache->store( ({ new_args, contents }), id); |
|
if( tag == "gbutton-url" ) |
return img_src; |
|
mapping img_attrs = ([ "src" : img_src, |
"alt" : args->alt || contents, |
"border" : args->border, |
"hspace" : args->hspace, |
"vspace" : args->vspace ]); |
|
if (mapping size = button_cache->metadata(new_args, id, 1)) { |
|
|
img_attrs->width = size->xsize; |
img_attrs->height = size->ysize; |
} |
|
|
if (args->href && !new_args->dim) { |
mapping a_attrs = ([ "href" : args->href ]); |
if (args->target) |
a_attrs->target = args->target; |
return make_container("a", a_attrs, make_tag("img", img_attrs)); |
} else |
return make_tag("img", img_attrs); |
} |
|
|