67bff7 | 1999-11-15 | Jonas Wallden | |
|
d69ba5 | 2001-09-03 | Martin Nilsson | |
|
67bff7 | 1999-11-15 | Jonas Wallden | |
|
f94ec5 | 2003-12-29 | Henrik Grubbström (Grubba) | |
|
67bff7 | 1999-11-15 | Jonas Wallden | |
|
8ac512 | 2003-12-15 | Jonas Wallden | |
|
67bff7 | 1999-11-15 | Jonas Wallden | |
|
0b9194 | 1999-11-16 | Jonas Wallden | |
|
dc7375 | 2000-05-25 | Jonas Wallden | |
|
67bff7 | 1999-11-15 | Jonas Wallden | |
|
dc7375 | 2000-05-25 | Jonas Wallden | |
|
6cf7e5 | 2000-08-07 | Jonas Wallden | |
|
67bff7 | 1999-11-15 | Jonas Wallden | |
|
ae839a | 2003-12-29 | Henrik Grubbström (Grubba) | | constant cvs_version = "$Id: gbutton.pike,v 1.106 2003/12/29 09:53:28 grubba Exp $";
|
67bff7 | 1999-11-15 | Jonas Wallden | | constant thread_safe = 1;
#include <module.h>
inherit "module";
roxen.ImageCache button_cache;
|
4afee2 | 2001-04-03 | Per Hedbor | | int do_ext;
|
67bff7 | 1999-11-15 | Jonas Wallden | |
|
b3281f | 2000-09-10 | Martin Nilsson | | constant module_type = MODULE_TAG;
|
bc0fa0 | 2001-03-08 | Per Hedbor | | constant module_name = "Graphics: GButton";
|
76fd09 | 2000-04-06 | Mattias Wingstedt | | constant module_doc =
"Provides the <tt><gbutton></tt> tag that is used to draw graphical "
"buttons.";
|
2e0a35 | 1999-12-09 | Martin Nilsson | |
|
9d86b5 | 2001-03-30 | Johan Sundström | | void create()
{
defvar("ext", Variable.Flag(0, VAR_MORE,
"Append format to generated images",
"Append the image format (.gif, .png, "
".jpg, etc) to the generated images. "
"This is not necessary, but might seem "
"nicer, especially to people who try "
"to mirror your site."));
}
|
739058 | 2000-06-01 | Martin Nilsson | | mapping tagdocumentation() {
Stdio.File file=Stdio.File();
if(!file->open(__FILE__,"r")) return 0;
string doc=compile_string("#define manual\n"+file->read())->gbuttonattr;
string imagecache=button_cache->documentation();
|
67bff7 | 1999-11-15 | Jonas Wallden | |
|
9b0365 | 2001-03-07 | Kenneth Johansson | | return ([
|
ce8fb0 | 2001-09-21 | Johan Sundström | | "gbutton":#"<desc type='cont'><p><short>
|
9b0365 | 2001-03-07 | Kenneth Johansson | | Creates graphical buttons.</short></p>
</desc>"
|
67bff7 | 1999-11-15 | Jonas Wallden | |
|
739058 | 2000-06-01 | Martin Nilsson | | +doc
+imagecache,
|
67bff7 | 1999-11-15 | Jonas Wallden | |
|
ce8fb0 | 2001-09-21 | Johan Sundström | | "gbutton-url":#"<desc type='cont'><p><short>
|
9b0365 | 2001-03-07 | Kenneth Johansson | | Generates an URI to the button.</short> <tag>gbutton-url</tag> takes
the same attributes as <xref href='gbutton.tag' /> including the
image cache attributes.</p>
</desc>"
|
67bff7 | 1999-11-15 | Jonas Wallden | |
|
739058 | 2000-06-01 | Martin Nilsson | | +doc
+imagecache,
]);
}
|
67bff7 | 1999-11-15 | Jonas Wallden | |
|
739058 | 2000-06-01 | Martin Nilsson | | #ifdef manual
constant gbuttonattr=#"
|
9b0365 | 2001-03-07 | Kenneth Johansson | | <attr name='pagebgcolor' value='color'><p></p>
|
739058 | 2000-06-01 | Martin Nilsson | |
</attr>
|
9b0365 | 2001-03-07 | Kenneth Johansson | | <attr name='bgcolor' value='color'><p>
Background color inside and outside button.</p>
|
739058 | 2000-06-01 | Martin Nilsson | | <ex>
<gbutton bgcolor='lightblue'>Background</gbutton>
</ex>
</attr>
|
67bff7 | 1999-11-15 | Jonas Wallden | |
|
27758e | 2001-07-20 | Johan Sundström | | <attr name='textcolor' value='color'>
<p>Button text color.</p>
<ex><gbutton textcolor='#ff6600'>Text</gbutton></ex>
|
739058 | 2000-06-01 | Martin Nilsson | | </attr>
|
67bff7 | 1999-11-15 | Jonas Wallden | |
|
9b0365 | 2001-03-07 | Kenneth Johansson | | <attr name='frame-image' value='path'><p>
|
739058 | 2000-06-01 | Martin Nilsson | | Use this XCF-image as a frame for the button. The image is required
|
27758e | 2001-07-20 | Johan Sundström | | to have at least the following layers: background, mask and frame.</p>
|
7dfc6a | 2001-07-20 | Johan Sundström | | "+#"
|
739058 | 2000-06-01 | Martin Nilsson | | </attr>
|
67bff7 | 1999-11-15 | Jonas Wallden | |
|
9b0365 | 2001-03-07 | Kenneth Johansson | | <attr name='alt' value='string'><p>
Alternative button and alt text.</p>
|
739058 | 2000-06-01 | Martin Nilsson | | </attr>
|
8ac512 | 2003-12-15 | Jonas Wallden | | <attr name='title' value='string'><p>
Button tooltip.</p>
</attr>
|
9b0365 | 2001-03-07 | Kenneth Johansson | | <attr name='href' value='uri'><p>
Button URI.</p>
|
739058 | 2000-06-01 | Martin Nilsson | | </attr>
|
f94ec5 | 2003-12-29 | Henrik Grubbström (Grubba) | | <attr name='target' value='string'><p>
Button target frame.</p>
</attr>
|
9b0365 | 2001-03-07 | Kenneth Johansson | | <attr name='textstyle' value='normal|condensed'><p>
|
7dfc6a | 2001-07-20 | Johan Sundström | | Set to <i>normal</i> or <i>condensed</i> to alter text style.</p>
|
739058 | 2000-06-01 | Martin Nilsson | | </attr>
|
9b0365 | 2001-03-07 | Kenneth Johansson | | <attr name='width' value=''><p>
Minimum button width.</p>
|
739058 | 2000-06-01 | Martin Nilsson | | </attr>
|
9b0365 | 2001-03-07 | Kenneth Johansson | | <attr name='align' value='left|center|right'><p>
|
739058 | 2000-06-01 | Martin Nilsson | | Set text alignment. There are some alignment restrictions: when text
|
7dfc6a | 2001-07-20 | Johan Sundström | | alignment is either <i>left</i> or <i>right</i>, icons must
also be aligned <i>left</i> or <i>right</i>.</p>
|
739058 | 2000-06-01 | Martin Nilsson | | </attr>
|
ee3b80 | 2003-10-30 | Anders Johansson | | <attr name='img-align' value=''><p>
Alignment passed on to the resulting <tag>img</tag>.</p>
</attr>
|
9b0365 | 2001-03-07 | Kenneth Johansson | | <attr name='state' value='enabled|disabled'><p>
|
7dfc6a | 2001-07-20 | Johan Sundström | | Set to <i>enabled</i> or <i>disabled</i> to select button state.</p>
|
739058 | 2000-06-01 | Martin Nilsson | | </attr>
|
9b0365 | 2001-03-07 | Kenneth Johansson | | <attr name='icon-src' value='URI'><p>
Fetch the icon from this URI.</p>
|
739058 | 2000-06-01 | Martin Nilsson | | </attr>
|
9b0365 | 2001-03-07 | Kenneth Johansson | | <attr name='icon-data' value=''><p>
Inline icon data.</p>
|
739058 | 2000-06-01 | Martin Nilsson | | </attr>
|
9b0365 | 2001-03-07 | Kenneth Johansson | | <attr name='align-icon' value='left|center-before|center-after|right'><p>
Set icon alignment.</p>
|
739058 | 2000-06-01 | Martin Nilsson | |
|
9b0365 | 2001-03-07 | Kenneth Johansson | | <xtable>
|
0186dc | 2001-03-28 | Kenneth Johansson | | <row><c><p>left</p></c><c><p>Place icon on the left side of the text.</p></c></row>
|
7dfc6a | 2001-07-20 | Johan Sundström | | <row><c><p>center-before</p></c><c><p>Center the icon before the text. Requires the <i>align='center'</i> attribute.</p></c></row>
<row><c><p>center-after</p></c><c><p>Center the icon after the text. Requires the <i>align='center'</i> attribute.</p></c></row>
|
0186dc | 2001-03-28 | Kenneth Johansson | | <row><c><p>right</p></c><c><p>Place icon on the right side of the text.</p></c></row>
|
9b0365 | 2001-03-07 | Kenneth Johansson | | </xtable>
|
739058 | 2000-06-01 | Martin Nilsson | |
<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'
|
7dfc6a | 2001-07-20 | Johan Sundström | | icon-src='/internal-roxen-help'>Roxen 2.0</gbutton>
|
739058 | 2000-06-01 | Martin Nilsson | | </ex>
</attr>
|
9b0365 | 2001-03-07 | Kenneth Johansson | | <attr name='valign-icon' value='above|middle|below'><p>
|
6363fa | 2000-08-15 | Jonas Wallden | | Set icon vertical alignment. Requires three horizontal guidelines in the
|
7dfc6a | 2001-07-20 | Johan Sundström | | frame image. If set to <i>above</i> the icon is placed between the first
|
6363fa | 2000-08-15 | Jonas Wallden | | and second guidelines and the text between the second and third ones. If
|
7dfc6a | 2001-07-20 | Johan Sundström | | set to <i>below</i> the placement is reversed. Default value is
<i>middle</i>.</p>
|
739058 | 2000-06-01 | Martin Nilsson | | </attr>
|
7dfc6a | 2001-07-20 | Johan Sundström | | <attr name='font' value='fontname'><p></p></attr>";
|
2e0a35 | 1999-12-09 | Martin Nilsson | | #endif
|
67bff7 | 1999-11-15 | Jonas Wallden | |
|
8a9862 | 2000-04-04 | Per Hedbor | | function TIMER( function f )
{
#if 0
return lambda(mixed ... args) {
int h = gethrtime();
mixed res;
werror("Drawing ... ");
res = f( @args );
werror(" %.1fms\n", (gethrtime()-h)/1000000.0 );
return res;
};
#endif
return f;
}
|
67bff7 | 1999-11-15 | Jonas Wallden | | void start()
{
|
8a9862 | 2000-04-04 | Per Hedbor | | button_cache = roxen.ImageCache("gbutton", TIMER(draw_button));
|
4afee2 | 2001-04-03 | Per Hedbor | | do_ext = query("ext");
|
67bff7 | 1999-11-15 | Jonas Wallden | | }
|
f04981 | 2000-07-24 | Martin Nilsson | | string status() {
array s=button_cache->status();
|
482ba7 | 2000-12-30 | Per Hedbor | | return sprintf("<b>Images in cache:</b> %d images<br />\n"
"<b>Cache size:</b> %s",
s[0], Roxen.sizetostring(s[1]));
|
f04981 | 2000-07-24 | Martin Nilsson | | }
mapping(string:function) query_action_buttons() {
return ([ "Clear cache":flush_cache ]);
}
void flush_cache() {
button_cache->flush();
}
|
fde908 | 2000-02-08 | Per Hedbor | | Image.Layer layer_slice( Image.Layer l, int from, int to )
{
return Image.Layer( ([
"image":l->image()->copy( from,0, to-1, l->ysize()-1 ),
"alpha":l->alpha()->copy( from,0, to-1, l->ysize()-1 ),
]) );
}
Image.Layer stretch_layer( Image.Layer o, int x1, int x2, int w )
{
Image.Layer l, m, r;
int leftovers = w - (x1 + (o->xsize()-x2) );
object oo = o;
l = layer_slice( o, 0, x1 );
|
3ef645 | 2000-02-08 | Jonas Wallden | | m = layer_slice( o, x1+1, x2-1 );
|
fde908 | 2000-02-08 | Per Hedbor | | r = layer_slice( o, x2, o->xsize() );
m->set_image( m->image()->scale( leftovers, l->ysize() ),
m->alpha()->scale( leftovers, l->ysize() ));
l->set_offset( 0,0 );
m->set_offset( x1,0 );
r->set_offset( w-r->xsize(),0 );
o = Image.lay( ({ l, m, r }) );
|
e0fda7 | 2000-04-04 | Marcus Comstedt | | o->set_mode( oo->mode() );
o->set_alpha_value( oo->alpha_value() );
|
fde908 | 2000-02-08 | Per Hedbor | | return o;
}
|
67bff7 | 1999-11-15 | Jonas Wallden | |
|
6a613a | 2002-06-17 | Anders Johansson | | array(Image.Layer)|mapping draw_button(mapping args, string text, object id)
|
67bff7 | 1999-11-15 | Jonas Wallden | | {
|
fde908 | 2000-02-08 | Per Hedbor | | Image.Image text_img;
|
67bff7 | 1999-11-15 | Jonas Wallden | | mapping icon;
|
fde908 | 2000-02-08 | Per Hedbor | |
Image.Layer background;
Image.Layer frame;
Image.Layer mask;
|
6cf7e5 | 2000-08-07 | Jonas Wallden | | int left, right, top, middle, bottom;
|
2bf484 | 2000-12-21 | Per Hedbor | | int req_width, noframe;
|
716975 | 2000-02-02 | Per Hedbor | |
|
3d3a47 | 2000-02-08 | Per Hedbor | | mapping ll = ([]);
|
13b35c | 2003-07-04 | Jonas Wallden | |
mapping opts = ([ "crop_to_bounds" : 1 ]);
|
fff48a | 2000-02-21 | Per Hedbor | | void set_image( array layers )
|
e76d2c | 2000-02-03 | Per Hedbor | | {
|
fff48a | 2000-02-21 | Per Hedbor | | foreach( layers||({}), object l )
|
fde908 | 2000-02-08 | Per Hedbor | | {
|
e2a3de | 2000-10-17 | Per Hedbor | | if(!l->get_misc_value( "name" ) )
|
fff48a | 2000-02-21 | Per Hedbor | | continue;
|
e2a3de | 2000-10-17 | Per Hedbor | |
|
fff48a | 2000-02-21 | Per Hedbor | | ll[lower_case(l->get_misc_value( "name" ))] = l;
switch( lower_case(l->get_misc_value( "name" )) )
|
fde908 | 2000-02-08 | Per Hedbor | | {
case "background": background = l; break;
case "frame": frame = l; break;
case "mask": mask = l; break;
}
}
|
fff48a | 2000-02-21 | Per Hedbor | | };
|
5dac1c | 2000-01-10 | Martin Nilsson | |
|
fff48a | 2000-02-21 | Per Hedbor | | if( args->border_image )
|
6a613a | 2002-06-17 | Anders Johansson | | {
|
233ab5 | 2003-06-30 | Jonas Wallden | | array(Image.Layer)|mapping tmp;
#if constant(Sitebuilder)
if (Sitebuilder.sb_start_use_imagecache) {
Sitebuilder.sb_start_use_imagecache(args, id);
|
13b35c | 2003-07-04 | Jonas Wallden | | tmp = roxen.load_layers(args->border_image, id, opts);
|
233ab5 | 2003-06-30 | Jonas Wallden | | Sitebuilder.sb_end_use_imagecache(args, id);
} else
#endif
{
|
13b35c | 2003-07-04 | Jonas Wallden | | tmp = roxen.load_layers(args->border_image, id, opts);
|
233ab5 | 2003-06-30 | Jonas Wallden | | }
|
6a613a | 2002-06-17 | Anders Johansson | | if (mappingp(tmp))
if (tmp->error == 401)
return tmp;
else
report_debug("GButton: Failed to load frame image: %O\n",
args->border_image);
set_image( tmp );
}
|
fff48a | 2000-02-21 | Per Hedbor | |
|
2bf484 | 2000-12-21 | Per Hedbor | |
|
fff48a | 2000-02-21 | Per Hedbor | |
|
2bf484 | 2000-12-21 | Per Hedbor | | if ( !frame && !background && !mask )
|
e2a3de | 2000-10-17 | Per Hedbor | | {
|
76dcb7 | 2000-10-18 | Martin Stjernholm | | string data = Stdio.read_file("roxen-images/gbutton.xcf");
if (!data)
error ("Failed to load default frame image "
"(roxen-images/gbutton.xcf): " + strerror (errno()));
mixed err = catch {
set_image(Image.XCF.decode_layers(data));
|
e2a3de | 2000-10-17 | Per Hedbor | | };
if( !frame )
|
76dcb7 | 2000-10-18 | Martin Stjernholm | | if (err) {
catch (err[0] = "Failed to decode default frame image "
"(roxen-images/gbutton.xcf): " + err[0]);
throw (err);
}
else
error("Failed to decode default frame image "
"(roxen-images/gbutton.xcf).\n");
|
e2a3de | 2000-10-17 | Per Hedbor | | }
|
fff48a | 2000-02-21 | Per Hedbor | |
|
2bf484 | 2000-12-21 | Per Hedbor | | if( !frame )
{
noframe = 1;
frame = background || mask;
}
|
fff48a | 2000-02-21 | Per Hedbor | |
int x0 = frame->xoffset();
int y0 = frame->yoffset();
if( x0 || y0 )
foreach( values( ll ), object l )
{
int x = l->xoffset();
int y = l->yoffset();
l->set_offset( x-x0, y-y0 );
}
|
716975 | 2000-02-02 | Per Hedbor | |
|
fde908 | 2000-02-08 | Per Hedbor | | if( !mask )
mask = frame;
|
e76d2c | 2000-02-03 | Per Hedbor | |
|
fde908 | 2000-02-08 | Per Hedbor | | array x = ({});
array y = ({});
|
2bf484 | 2000-12-21 | Per Hedbor | |
|
fde908 | 2000-02-08 | Per Hedbor | | foreach( frame->get_misc_value( "image_guides" ), object g )
|
2bf484 | 2000-12-21 | Per Hedbor | | if( g->vertical )
x += ({ g->pos - x0 });
else
y += ({ g->pos - y0 });
|
fff48a | 2000-02-21 | Per Hedbor | |
sort( y );
sort( x );
|
e76d2c | 2000-02-03 | Per Hedbor | |
|
fde908 | 2000-02-08 | Per Hedbor | | if(sizeof( x ) < 2)
x = ({ 5, frame->xsize()-5 });
|
fff48a | 2000-02-21 | Per Hedbor | |
|
fde908 | 2000-02-08 | Per Hedbor | | if(sizeof( y ) < 2)
y = ({ 2, frame->ysize()-2 });
|
e76d2c | 2000-02-03 | Per Hedbor | |
|
6cf7e5 | 2000-08-07 | Jonas Wallden | | left = x[0]; right = x[-1]; top = y[0]; middle = y[1]; bottom = y[-1];
|
fde908 | 2000-02-08 | Per Hedbor | | right = frame->xsize()-right;
|
6cf7e5 | 2000-08-07 | Jonas Wallden | |
int text_height;
switch (args->icva) {
case "above":
text_height = bottom - middle;
break;
case "below":
text_height = middle - top;
break;
default:
case "middle":
text_height = bottom - top;
break;
}
|
716975 | 2000-02-02 | Per Hedbor | |
|
67bff7 | 1999-11-15 | Jonas Wallden | |
if (args->icn)
icon = roxen.low_load_image(args->icn, id);
else if (args->icd)
icon = roxen.low_decode_image(args->icd);
|
fde908 | 2000-02-08 | Per Hedbor | |
int i_width = icon && icon->img->xsize();
|
6cf7e5 | 2000-08-07 | Jonas Wallden | | int i_height = icon && icon->img->ysize();
|
4e63f1 | 2000-05-24 | Jonas Wallden | | int i_spc = i_width && sizeof(text) && 5;
|
716975 | 2000-02-02 | Per Hedbor | |
|
67bff7 | 1999-11-15 | Jonas Wallden | |
|
fde908 | 2000-02-08 | Per Hedbor | | if (sizeof(text))
{
|
c19bfd | 2003-12-18 | Jonas Wallden | | int min_font_size = 0;
int max_font_size = text_height * 2;
do {
int try_font_size = (max_font_size + min_font_size + 1) / 2;
Font button_font = resolve_font(args->font + " " + try_font_size);
|
300d98 | 2000-12-11 | Per Hedbor | | text_img = button_font->write(text);
|
c19bfd | 2003-12-18 | Jonas Wallden | | int real_height = text_img->ysize();
if (real_height > try_font_size * 2)
break;
if (real_height == text_height)
break;
if (real_height > text_height)
max_font_size = try_font_size - 1;
else {
if (min_font_size == max_font_size)
break;
min_font_size = try_font_size;
}
} while (max_font_size - min_font_size >= 0);
|
300d98 | 2000-12-11 | Per Hedbor | |
|
e59f91 | 2000-12-11 | Per Hedbor | | if( abs(text_img->ysize() - text_height)>2 )
|
1597b4 | 2000-12-11 | Martin Nilsson | | text_img = text_img->scale(0, text_height );
|
300d98 | 2000-12-11 | Per Hedbor | | else
{
int o = text_img->ysize() - text_height;
top -= o;
middle -= o/2;
}
|
3c24b6 | 2000-01-19 | Fredrik Noring | | if (args->cnd)
text_img = text_img->scale((int) round(text_img->xsize() * 0.8),
text_img->ysize());
|
f53720 | 2002-04-15 | Jonas Wallden | | } else
text_height = 0;
|
716975 | 2000-02-02 | Per Hedbor | |
|
fde908 | 2000-02-08 | Per Hedbor | | int t_width = text_img && text_img->xsize();
|
6cf7e5 | 2000-08-07 | Jonas Wallden | |
req_width = t_width + left + right;
if ((args->icva || "middle") == "middle")
req_width += i_width + i_spc;
|
67bff7 | 1999-11-15 | Jonas Wallden | | if (args->wi && (req_width < args->wi))
req_width = args->wi;
|
fde908 | 2000-02-08 | Per Hedbor | |
|
6cf7e5 | 2000-08-07 | Jonas Wallden | | int icn_x, icn_y, txt_x, txt_y;
switch (args->icva) {
case "above":
case "below":
icn_x = left + (req_width - right - left - i_width) / 2;
txt_x = left + (req_width - right - left - t_width) / 2;
|
f53720 | 2002-04-15 | Jonas Wallden | | if (args->icva == "above" || !text_height) {
|
6cf7e5 | 2000-08-07 | Jonas Wallden | | txt_y = middle;
|
f53720 | 2002-04-15 | Jonas Wallden | | icn_y = top + ((text_height ? middle : bottom) - top - i_height) / 2;
|
6cf7e5 | 2000-08-07 | Jonas Wallden | | } else {
txt_y = top;
icn_y = middle + (bottom - middle - i_height) / 2;
|
67bff7 | 1999-11-15 | Jonas Wallden | | }
break;
default:
case "middle":
|
6cf7e5 | 2000-08-07 | Jonas Wallden | |
icn_y = icon && (frame->ysize() - icon->img->ysize()) / 2;
txt_y = top;
switch (args->al)
|
fde908 | 2000-02-08 | Per Hedbor | | {
|
6cf7e5 | 2000-08-07 | Jonas Wallden | | case "left":
switch (args->ica)
{
case "left":
icn_x = left;
txt_x = icn_x + i_width + i_spc;
break;
default:
case "right":
txt_x = left;
icn_x = req_width - right - i_width;
break;
}
|
67bff7 | 1999-11-15 | Jonas Wallden | | break;
|
6cf7e5 | 2000-08-07 | Jonas Wallden | | default:
case "center":
case "middle":
switch (args->ica)
{
case "left":
icn_x = left;
txt_x = (req_width - right - left - i_width - i_spc - t_width) / 2;
txt_x += icn_x + i_width + i_spc;
break;
default:
case "center":
case "center_before":
case "center-before":
icn_x = (req_width - i_width - i_spc - t_width) / 2;
txt_x = icn_x + i_width + i_spc;
break;
case "center_after":
case "center-after":
txt_x = (req_width - i_width - i_spc - t_width) / 2;
icn_x = txt_x + t_width + i_spc;
break;
case "right":
icn_x = req_width - right - i_width;
|
6f0207 | 2002-09-05 | Jonas Wallden | | txt_x = left + (icn_x - i_spc - t_width - left) / 2;
|
6cf7e5 | 2000-08-07 | Jonas Wallden | | break;
}
break;
case "right":
switch (args->ica)
{
default:
case "left":
icn_x = left;
txt_x = req_width - right - t_width;
break;
case "right":
icn_x = req_width - right - i_width;
txt_x = icn_x - i_spc - t_width;
break;
}
break;
|
67bff7 | 1999-11-15 | Jonas Wallden | | }
break;
}
|
f6ea61 | 2000-02-07 | Per Hedbor | |
|
5321c0 | 2000-02-08 | Per Hedbor | | if( args->extra_frame_layers )
{
|
8a9862 | 2000-04-04 | Per Hedbor | | array l = ({ });
|
5321c0 | 2000-02-08 | Per Hedbor | | foreach( args->extra_frame_layers/",", string q )
l += ({ ll[q] });
l-=({ 0 });
|
8a9862 | 2000-04-04 | Per Hedbor | | if( sizeof( l ) )
|
2bf484 | 2000-12-21 | Per Hedbor | | frame = Image.lay( l+(noframe?({}):({frame})) );
|
5321c0 | 2000-02-08 | Per Hedbor | | }
|
f6ea61 | 2000-02-07 | Per Hedbor | |
|
5321c0 | 2000-02-08 | Per Hedbor | | if( args->extra_mask_layers )
{
array l = ({ });
foreach( args->extra_mask_layers/",", string q )
l += ({ ll[q] });
l-=({ 0 });
if( sizeof( l ) )
|
fff48a | 2000-02-21 | Per Hedbor | | {
if( mask )
l = ({ mask })+l;
|
5321c0 | 2000-02-08 | Per Hedbor | | mask = Image.lay( l );
|
fff48a | 2000-02-21 | Per Hedbor | | }
|
5321c0 | 2000-02-08 | Per Hedbor | | }
right = frame->xsize()-right;
if (mask != frame)
|
e95d46 | 2000-12-16 | Per Hedbor | | {
Image.Image i = mask->image();
Image.Image m = mask->alpha();
int x0 = -mask->xoffset();
int y0 = -mask->yoffset();
int x1 = frame->xsize()-1+x0;
int y1 = frame->ysize()-1+y0;
i = i->copy(x0,y0, x1,y1);
if( m )
m = m->copy(x0,y0, x1,y1);
mask->set_image( i, m );
|
5321c0 | 2000-02-08 | Per Hedbor | | mask = stretch_layer( mask, left, right, req_width );
|
e95d46 | 2000-12-16 | Per Hedbor | | }
|
2bf484 | 2000-12-21 | Per Hedbor | | if( frame != background )
frame = stretch_layer( frame, left, right, req_width );
|
e0fda7 | 2000-04-04 | Marcus Comstedt | | array(Image.Layer) button_layers = ({
Image.Layer( Image.Image(req_width, frame->ysize(), args->bg),
|
e95d46 | 2000-12-16 | Per Hedbor | | mask->alpha()->copy(0,0,req_width-1,frame->ysize()-1)),
|
e0fda7 | 2000-04-04 | Marcus Comstedt | | });
|
8a9862 | 2000-04-04 | Per Hedbor | |
if( args->extra_background_layers || background)
|
fde908 | 2000-02-08 | Per Hedbor | | {
|
8a9862 | 2000-04-04 | Per Hedbor | | array l = ({ background });
foreach( (args->extra_background_layers||"")/","-({""}), string q )
l += ({ ll[q] });
l-=({ 0 });
foreach( l, object ll )
{
if( args->dim )
ll->set_alpha_value( 0.3 );
button_layers += ({ stretch_layer( ll, left, right, req_width ) });
}
|
fde908 | 2000-02-08 | Per Hedbor | | }
|
12493c | 2000-02-22 | Per Hedbor | |
|
2bf484 | 2000-12-21 | Per Hedbor | | if( !noframe )
{
button_layers += ({ frame });
frame->set_mode( "value" );
}
|
12493c | 2000-02-22 | Per Hedbor | |
if( args->dim )
{
|
1ac32d | 2000-02-10 | Jonas Wallden | |
int bg_value = Image.Color(@args->bg)->hsv()[2];
int dim_high, dim_low;
if (bg_value < 128) {
dim_low = max(bg_value - 64, 0);
dim_high = dim_low + 128;
} else {
dim_high = min(bg_value + 64, 255);
dim_low = dim_high - 128;
}
|
12493c | 2000-02-22 | Per Hedbor | | frame->set_image(frame->image()->
modify_by_intensity( 1, 1, 1,
({ dim_low, dim_low, dim_low }),
({ dim_high, dim_high, dim_high })),
frame->alpha());
|
1ac32d | 2000-02-10 | Jonas Wallden | | }
|
1a5442 | 2000-02-21 | Per Hedbor | |
|
fde908 | 2000-02-08 | Per Hedbor | |
if (icon)
|
1a5442 | 2000-02-21 | Per Hedbor | | button_layers += ({
Image.Layer( ([
|
12493c | 2000-02-22 | Per Hedbor | | "alpha_value":(args->dim ? 0.3 : 1.0),
|
1a5442 | 2000-02-21 | Per Hedbor | | "image":icon->img,
|
12493c | 2000-02-22 | Per Hedbor | | "alpha":icon->alpha,
|
1a5442 | 2000-02-21 | Per Hedbor | | "xoffset":icn_x,
|
6cf7e5 | 2000-08-07 | Jonas Wallden | | "yoffset":icn_y
|
1a5442 | 2000-02-21 | Per Hedbor | | ]) )});
|
f6ea61 | 2000-02-07 | Per Hedbor | |
|
67bff7 | 1999-11-15 | Jonas Wallden | |
|
3c24b6 | 2000-01-19 | Fredrik Noring | | if(text_img)
|
2bf484 | 2000-12-21 | Per Hedbor | | {
float ta = args->txtalpha?args->txtalpha:1.0;
button_layers +=
({
Image.Layer(([
"mode":args->txtmode,
"image":text_img->color(0,0,0)->invert()->color(@args->txt),
"alpha":(text_img*(args->dim?0.5*ta:ta)),
"xoffset":txt_x,
"yoffset":txt_y,
]))
});
}
|
716975 | 2000-02-02 | Per Hedbor | |
|
fff48a | 2000-02-21 | Per Hedbor | |
|
5321c0 | 2000-02-08 | Per Hedbor | | if( args->extra_layers )
{
|
1a5442 | 2000-02-21 | Per Hedbor | | array q = map(args->extra_layers/",",
lambda(string q) { return ll[q]; } )-({0});
|
8a9862 | 2000-04-04 | Per Hedbor | | foreach( q, object ll )
{
if( args->dim )
ll->set_alpha_value( 0.3 );
button_layers += ({stretch_layer(ll,left,right,req_width)});
|
e95d46 | 2000-12-16 | Per Hedbor | | button_layers[-1]->set_offset( 0,
button_layers[0]->ysize()-
button_layers[-1]->ysize() );
|
8a9862 | 2000-04-04 | Per Hedbor | | }
|
5321c0 | 2000-02-08 | Per Hedbor | | }
|
1a5442 | 2000-02-21 | Per Hedbor | | button_layers -= ({ 0 });
|
fff48a | 2000-02-21 | Per Hedbor | |
if( args->extra_left_layers )
{
array l = ({ });
foreach( args->extra_left_layers/",", string q )
l += ({ ll[q] });
l-=({ 0 });
|
e95d46 | 2000-12-16 | Per Hedbor | | l->set_offset( 0, 0 );
|
fff48a | 2000-02-21 | Per Hedbor | | if( sizeof( l ) )
{
object q = Image.lay( l );
|
1a5442 | 2000-02-21 | Per Hedbor | | foreach( button_layers, object b )
{
int x = b->xoffset();
int y = b->yoffset();
b->set_offset( x+q->xsize(), y );
}
|
e95d46 | 2000-12-16 | Per Hedbor | | q->set_offset( 0, button_layers[0]->ysize()-q->ysize() );
|
1a5442 | 2000-02-21 | Per Hedbor | | button_layers += ({ q });
|
fff48a | 2000-02-21 | Per Hedbor | | }
}
if( args->extra_right_layers )
{
array l = ({ });
foreach( args->extra_right_layers/",", string q )
l += ({ ll[q] });
l-=({ 0 });
|
e95d46 | 2000-12-16 | Per Hedbor | | l->set_offset( 0, 0 );
|
fff48a | 2000-02-21 | Per Hedbor | | if( sizeof( l ) )
{
object q = Image.lay( l );
|
a76b0a | 2000-02-22 | Per Hedbor | | q->set_offset( button_layers[0]->xsize()+
|
e95d46 | 2000-12-16 | Per Hedbor | | button_layers[0]->xoffset(),
button_layers[0]->ysize()-q->ysize());
|
1a5442 | 2000-02-21 | Per Hedbor | | button_layers += ({ q });
|
fff48a | 2000-02-21 | Per Hedbor | | }
}
|
5321c0 | 2000-02-08 | Per Hedbor | |
|
fcb951 | 2000-09-19 | Per Hedbor | |
|
d12333 | 2000-11-17 | Anders Johansson | | if (args->format == "png")
return ({ Image.Layer(([ "fill":args->pagebg, ])) }) + button_layers;
else
return button_layers;
|
fcb951 | 2000-09-19 | Per Hedbor | |
|
67bff7 | 1999-11-15 | Jonas Wallden | | }
mapping find_internal(string f, RequestID id)
{
|
4afee2 | 2001-04-03 | Per Hedbor | |
return button_cache->http_file_answer( (f/".")[0], id );
|
67bff7 | 1999-11-15 | Jonas Wallden | | }
|
350dfa | 2001-02-02 | Per Hedbor | | int get_file_stat( string f, RequestID id )
{
|
4805d9 | 2001-08-03 | Jonas Wallden | | int res;
|
b3b095 | 2003-09-22 | Jonas Wallden | | mapping stat_cache;
|
500e39 | 2001-08-23 | Jonas Wallden | |
|
b3b095 | 2003-09-22 | Jonas Wallden | | if (stat_cache = id->misc->gbutton_statcache) {
if (!id->misc->persistent_cache_crawler)
if (res = stat_cache[f])
return (res > 0) && res;
} else
stat_cache = id->misc->gbutton_statcache = ([ ]);
|
500e39 | 2001-08-23 | Jonas Wallden | |
|
2483e5 | 2002-08-28 | Anders Johansson | | int was_internal = id->misc->internal_get;
id->misc->internal_get = 1;
|
b3b095 | 2003-09-22 | Jonas Wallden | | res = stat_cache[ f ] = (id->conf->stat_file( f,id ) ||
file_stat( f ) ||
({ 0,0,0,0 }) )[ST_MTIME] || -1;
|
2483e5 | 2002-08-28 | Anders Johansson | | if (!was_internal)
m_delete(id->misc, "internal_get");
|
4805d9 | 2001-08-03 | Jonas Wallden | | return (res > 0) && res;
|
350dfa | 2001-02-02 | Per Hedbor | | }
|
67bff7 | 1999-11-15 | Jonas Wallden | |
|
c421c6 | 2000-03-14 | Martin Nilsson | | class ButtonFrame {
inherit RXML.Frame;
|
f29b14 | 2000-03-24 | Per Hedbor | | array mk_url(RequestID id)
{
|
350dfa | 2001-02-02 | Per Hedbor | |
|
6cf7e5 | 2000-08-07 | Jonas Wallden | | string fi = (args["frame-image"] ||
id->misc->defines["gbutton-frame-image"]);
|
c421c6 | 2000-03-14 | Martin Nilsson | | if( fi )
|
bf956c | 2000-05-01 | Martin Nilsson | | fi = Roxen.fix_relative( fi, id );
|
dc7375 | 2000-05-25 | Jonas Wallden | |
|
350dfa | 2001-02-02 | Per Hedbor | | args->icon_src = args["icon-src"] || args->icon_src;
args->icon_data = args["icon-data"] || args->icon_data;
args->align_icon = args["align-icon"] || args->align_icon;
|
6cf7e5 | 2000-08-07 | Jonas Wallden | | args->valign_icon = args["valign-icon"] || args->valign_icon;
|
dc7375 | 2000-05-25 | Jonas Wallden | | m_delete(args, "icon-src");
m_delete(args, "icon-data");
m_delete(args, "align-icon");
|
350dfa | 2001-02-02 | Per Hedbor | | mapping new_args =
([
"pagebg" :parse_color(args->pagebgcolor ||
id->misc->defines->theme_bgcolor ||
id->misc->defines->bgcolor ||
args->bgcolor ||
"#eeeeee"),
"bg" : parse_color(args->bgcolor ||
|
c421c6 | 2000-03-14 | Martin Nilsson | | id->misc->defines->theme_bgcolor ||
id->misc->defines->bgcolor ||
|
350dfa | 2001-02-02 | Per Hedbor | | "#eeeeee"),
"txt" : parse_color(args->textcolor ||
id->misc->defines->theme_bgcolor ||
id->misc->defines->fgcolor ||
"#000000"),
"txtalpha": (args->textalpha?(float)args->textalpha:1.0),
"txtmode": (args->textmode||"normal"),
"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 &&
Roxen.fix_relative(args->icon_src, id),
"icd" : args->icon_data,
"ica" : lower_case(args->align_icon || "left"),
"icva": lower_case(args->valign_icon || "middle"),
"font": (args->font||id->misc->defines->font||
roxen->query("default_font")),
|
f850ff | 2001-07-09 | Martin Nilsson | | "fontkey": roxen->fonts->verify_font(args->font||id->misc->defines->font),
|
350dfa | 2001-02-02 | Per Hedbor | | "border_image":fi,
"extra_layers":args["extra-layers"],
"extra_left_layers":args["extra-left-layers"],
"extra_right_layers":args["extra-right-layers"],
"extra_background_layers":args["extra-background-layers"],
"extra_mask_layers":args["extra-mask-layers"],
"extra_frame_layers":args["extra-frame-layers"],
"scale":args["scale"],
"format":args["format"],
"gamma":args["gamma"],
"crop":args["crop"],
]);
|
233ab5 | 2003-06-30 | Jonas Wallden | | if( fi ) {
|
350dfa | 2001-02-02 | Per Hedbor | | new_args->stat = get_file_stat( fi, id );
|
233ab5 | 2003-06-30 | Jonas Wallden | | #if constant(Sitebuilder)
if (Sitebuilder.sb_prepare_imagecache)
new_args = Sitebuilder.sb_prepare_imagecache(new_args, fi, id);
#endif
}
|
e4b4b7 | 2000-11-21 | Per Hedbor | |
|
c421c6 | 2000-03-14 | Martin Nilsson | | new_args->quant = args->quant || 128;
foreach(glob("*-*", indices(args)), string n)
new_args[n] = args[n];
|
350dfa | 2001-02-02 | Per Hedbor | |
string fn;
|
c421c6 | 2000-03-14 | Martin Nilsson | | string img_src =
|
db053e | 2000-12-05 | Martin Nilsson | | query_absolute_internal_location(id) +
|
5c323e | 2001-10-09 | Martin Nilsson | | button_cache->store( ({ new_args, (string)content }), id);
|
9d86b5 | 2001-03-30 | Johan Sundström | |
|
4afee2 | 2001-04-03 | Per Hedbor | | if(do_ext)
|
9d86b5 | 2001-03-30 | Johan Sundström | | img_src += "." + (new_args->format || "gif");
|
350dfa | 2001-02-02 | Per Hedbor | |
|
c421c6 | 2000-03-14 | Martin Nilsson | | return ({ img_src, new_args });
}
}
class TagGButtonURL {
inherit RXML.Tag;
constant name = "gbutton-url";
|
1b2d74 | 2001-10-08 | Anders Johansson | | constant flags = RXML.FLAG_DONT_REPORT_ERRORS;
|
c421c6 | 2000-03-14 | Martin Nilsson | | RXML.Type content_type = RXML.t_text(RXML.PXml);
class Frame {
inherit ButtonFrame;
array do_return(RequestID id) {
result=mk_url(id)[0];
return 0;
}
|
67bff7 | 1999-11-15 | Jonas Wallden | | }
|
c421c6 | 2000-03-14 | Martin Nilsson | | }
|
5dac1c | 2000-01-10 | Martin Nilsson | |
|
25d176 | 2000-08-12 | Martin Stjernholm | | class TagGButton {
|
c421c6 | 2000-03-14 | Martin Nilsson | | inherit RXML.Tag;
constant name = "gbutton";
|
1b2d74 | 2001-10-08 | Anders Johansson | | constant flags = RXML.FLAG_DONT_REPORT_ERRORS;
|
c421c6 | 2000-03-14 | Martin Nilsson | | RXML.Type content_type = RXML.t_text(RXML.PXml);
class Frame {
inherit ButtonFrame;
array do_return(RequestID id) {
|
dc7375 | 2000-05-25 | Jonas Wallden | |
string img_align = args["img-align"];
|
8ac512 | 2003-12-15 | Jonas Wallden | | string title = args->title;
|
dc7375 | 2000-05-25 | Jonas Wallden | | m_delete(args, "img-align");
|
c421c6 | 2000-03-14 | Martin Nilsson | | [string img_src, mapping new_args]=mk_url(id);
mapping img_attrs = ([ "src" : img_src,
|
5c323e | 2001-10-09 | Martin Nilsson | | "alt" : args->alt || (string)content,
|
c421c6 | 2000-03-14 | Martin Nilsson | | "border" : args->border,
"hspace" : args->hspace,
"vspace" : args->vspace ]);
|
dc7375 | 2000-05-25 | Jonas Wallden | | if (img_align)
img_attrs->align = img_align;
|
8ac512 | 2003-12-15 | Jonas Wallden | | if (title)
img_attrs->title = title;
|
cf5b11 | 2003-10-16 | Anders Johansson | | int no_draw = !id->misc->generate_images;
|
5c323e | 2001-10-09 | Martin Nilsson | | if (mapping size = button_cache->metadata( ({ new_args, (string)content }),
|
cf5b11 | 2003-10-16 | Anders Johansson | | id, no_draw)) {
|
c421c6 | 2000-03-14 | Martin Nilsson | |
img_attrs->width = size->xsize;
img_attrs->height = size->ysize;
}
|
0023a6 | 2000-08-22 | Martin Nilsson | | result = Roxen.make_tag("img", img_attrs, !args->noxml);
|
dbc272 | 2000-03-24 | Johan Sundström | |
|
c421c6 | 2000-03-14 | Martin Nilsson | |
|
dbc272 | 2000-03-24 | Johan Sundström | | if(args->href && !new_args->dim)
{
|
f94ec5 | 2003-12-29 | Henrik Grubbström (Grubba) | | mapping a_attrs = ([ "href" : args->href,
]);
|
dbc272 | 2000-03-24 | Johan Sundström | |
foreach(indices(args), string arg)
|
6cf7e5 | 2000-08-07 | Jonas Wallden | | if(has_value("target/onmousedown/onmouseup/onclick/ondblclick/"
"onmouseout/onmouseover/onkeypress/onkeyup/"
"onkeydown" / "/", lower_case(arg)))
|
dbc272 | 2000-03-24 | Johan Sundström | | a_attrs[arg] = args[arg];
|
bf956c | 2000-05-01 | Martin Nilsson | | result = Roxen.make_container("a", a_attrs, result);
|
dbc272 | 2000-03-24 | Johan Sundström | | }
|
c421c6 | 2000-03-14 | Martin Nilsson | |
return 0;
}
}
|
67bff7 | 1999-11-15 | Jonas Wallden | | }
|