Move html textarea's selection colour chooser to plot_style.h, as it could be used elsewhere.

This commit is contained in:
Michael Drake 2013-02-11 00:41:22 +00:00
parent e4e2917787
commit 99fc8d3f0d
2 changed files with 10 additions and 7 deletions

View File

@ -64,6 +64,14 @@
(((((c0 >> 8) & 0xff) + ((c1 >> 8) & 0xff)) >> 1) << 8) | \
(((( c0 & 0xff) + ( c1 & 0xff)) >> 1) << 0)
/* Choose either black or white, depending on which is furthest from the
* percieved lightness of the supplied colour, c0. */
#define colour_to_bw_furthest(c0) \
((((((c0 & 0x0000ff) * 77) >> 8) + \
(((c0 & 0x00ff00) * 151) >> 16) + \
(((c0 & 0xff0000) * 28) >> 24)) > \
(0xff / 2)) ? 0x000000 : 0xffffff)
/* get a bitmap pixel (image/bitmap.h) into a plot colour */
#define pixel_to_colour(b) \
b[0] | (b[1] << 8) | (b[2] << 16) | (b[3] << 24)

View File

@ -266,14 +266,9 @@ bool box_textarea_create_textarea(html_content *html,
ta_setup.text = fstyle;
ta_setup.text.background = NS_TRANSPARENT;
/* Make selected text either black or white, as gives greatest contrast
* with background colour. (Calc lightness of background colour and
* choose the one the lightness is furthest from.) */
ta_setup.selected_text =
(((((fstyle.foreground & 0x0000ff) ) * 19) / 64 +
(((fstyle.foreground & 0x00ff00) >> 8) * 38) / 64 +
(((fstyle.foreground & 0xff0000) >> 16) * 7) / 64) >
(0xff / 2)) ? 0x000000 : 0xffffff;
* with background colour. */
ta_setup.selected_bg = fstyle.foreground;
ta_setup.selected_text = colour_to_bw_furthest(ta_setup.selected_bg);
/* Hand reference to dom text over to gadget */
gadget->data.text.initial = dom_text;