Roxen.git
/
server
/
modules
/
graphics
/
gbutton.pike
version
»
Context lines:
10
20
40
80
file
none
3
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.
2
1999/11/15
15
:
02
:
06
jonasw Exp $";
+
constant cvs_version = "$Id: gbutton.pike,v 1.
3
1999/11/15
16
:
30
:
33
jonasw Exp $";
constant thread_safe = 1; #include <module.h> inherit "module"; inherit "roxenlib"; roxen.ImageCache button_cache; object button_font = resolve_font("haru 32"); object button_border; object button_mask;
-
+
// Distance between icon image and text
+
#define IMAGE_SPC 5
+
+
array register_module() { return( ({ MODULE_PARSER, "GButton", "Provides the <tt><gbutton>Title</gbutton></tt> " "tag for drawing graphical buttons. Arguments:<p>" "<table border=0>" "<tr><td><b>bgcolor</b></td><td>Background color inside and " "outside button</td></tr>"
Roxen.git/server/modules/graphics/gbutton.pike:124:
modify_by_intensity(1, 1, 1, dim_bo, dim_bg); } b_width = b->xsize(); b_height = b->ysize(); // Get icon 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() +
4
);
+
i_width = icon && (icon->img->xsize() +
IMAGE_SPC
);
// Generate text
-
text_img = button_font->write(text)->scale(0, b_height -
4
);
+
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(); // Compute text and icon placement 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": // Allow icon alignment: left, right 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 +
4
;
+
icn_x = req_width - b_width / 2 - i_width +
IMAGE_SPC
;
break; } break; default: case "center": case "middle": // Allow icon alignment: left, center, center_before, center_after, right switch (lower_case(args->ica)) { case "left":
Roxen.git/server/modules/graphics/gbutton.pike:171:
(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 +
4
;
+
icn_x = txt_x + t_width +
IMAGE_SPC
;
break; case "right":
-
icn_x = req_width - b_width / 2 - i_width +
4
;
-
txt_x = b_width / 2 + (icn_x -
4
- b_width / 2 - t_width) / 2;
+
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": // Allow icon alignment: left, 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 +
4
;
-
txt_x = icn_x -
4
- t_width;
+
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); // Paste left and right edge of border 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));
Roxen.git/server/modules/graphics/gbutton.pike:259:
"txt" : parse_color(args->textcolor || "#000000"), // Text color "cnd" : args->condensed, // Condensed text "wi" : (int) args->width, // Min button width "al" : args->align || "left", // Text alignment "dim" : args->dim, // Button dimming "icn" : args->icon_src && fix_relative(args->icon_src, id), // Icon URL "icd" : args->icon_data, // Inline icon data "ica" : args->align_icon || "left" // Icon alignment ]);
+
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); mapping img_attrs = ([ "src" : img_src, "alt" : args->alt || contents,
-
"border" : args->border ]);
+
"border" : args->border
,
+
"hspace" : args->hspace,
+
"vspace" : args->vspace
]);
if (mapping size = button_cache->metadata(new_args, id, 1)) { // Image in cache (1 above prevents generation on-the-fly, i.e. // first image will lack sizes). img_attrs->width = size->xsize; img_attrs->height = size->ysize; } // Make button clickable if not dimmed if (args->href && !args->dim) return make_container("a", ([ "href" : args->href ]), make_tag("img", img_attrs)); else return make_tag("img", img_attrs); }