Allow text drawing to use the alpha channel.
We pass alpha channel information to the current text drawing code and use it if it is available. The previous behavior of using full opacity for RGB format colors is preserved.
This commit is contained in:
parent
1c4100ce5d
commit
a5d4c7c9ab
@ -29,6 +29,7 @@ static xcb_visualtype_t *root_visual_type;
|
|||||||
static double pango_font_red;
|
static double pango_font_red;
|
||||||
static double pango_font_green;
|
static double pango_font_green;
|
||||||
static double pango_font_blue;
|
static double pango_font_blue;
|
||||||
|
static double pango_font_alpha;
|
||||||
|
|
||||||
/* Necessary to track whether the dpi changes and trigger a LOG() message,
|
/* Necessary to track whether the dpi changes and trigger a LOG() message,
|
||||||
* which is more easily visible to users. */
|
* which is more easily visible to users. */
|
||||||
@ -123,7 +124,8 @@ static void draw_text_pango(const char *text, size_t text_len,
|
|||||||
pango_layout_set_text(layout, text, text_len);
|
pango_layout_set_text(layout, text, text_len);
|
||||||
|
|
||||||
/* Do the drawing */
|
/* Do the drawing */
|
||||||
cairo_set_source_rgb(cr, pango_font_red, pango_font_green, pango_font_blue);
|
cairo_set_source_rgba(cr, pango_font_red, pango_font_green, pango_font_blue, pango_font_alpha);
|
||||||
|
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
|
||||||
pango_cairo_update_layout(cr, layout);
|
pango_cairo_update_layout(cr, layout);
|
||||||
pango_layout_get_pixel_size(layout, NULL, &height);
|
pango_layout_get_pixel_size(layout, NULL, &height);
|
||||||
/* Center the piece of text vertically if its height is smaller than the
|
/* Center the piece of text vertically if its height is smaller than the
|
||||||
@ -332,6 +334,7 @@ void set_font_colors(xcb_gcontext_t gc, uint32_t foreground, uint32_t background
|
|||||||
pango_font_red = ((foreground >> 16) & 0xff) / 255.0;
|
pango_font_red = ((foreground >> 16) & 0xff) / 255.0;
|
||||||
pango_font_green = ((foreground >> 8) & 0xff) / 255.0;
|
pango_font_green = ((foreground >> 8) & 0xff) / 255.0;
|
||||||
pango_font_blue = (foreground & 0xff) / 255.0;
|
pango_font_blue = (foreground & 0xff) / 255.0;
|
||||||
|
pango_font_alpha = ((foreground >> 24) & 0xff) / 255.0;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
*/
|
*/
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "libi3.h"
|
#include "libi3.h"
|
||||||
|
|
||||||
@ -25,14 +26,23 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
uint32_t get_colorpixel(const char *hex) {
|
uint32_t get_colorpixel(const char *hex) {
|
||||||
char strgroups[3][3] = {{hex[1], hex[2], '\0'},
|
char alpha[2];
|
||||||
|
if (strlen(hex) == strlen("#rrggbbaa")) {
|
||||||
|
alpha[0] = hex[7];
|
||||||
|
alpha[1] = hex[8];
|
||||||
|
} else {
|
||||||
|
alpha[0] = alpha[1] = 'F';
|
||||||
|
}
|
||||||
|
|
||||||
|
char strgroups[4][3] = {
|
||||||
|
{hex[1], hex[2], '\0'},
|
||||||
{hex[3], hex[4], '\0'},
|
{hex[3], hex[4], '\0'},
|
||||||
{hex[5], hex[6], '\0'}};
|
{hex[5], hex[6], '\0'},
|
||||||
|
{alpha[0], alpha[1], '\0'}};
|
||||||
uint8_t r = strtol(strgroups[0], NULL, 16);
|
uint8_t r = strtol(strgroups[0], NULL, 16);
|
||||||
uint8_t g = strtol(strgroups[1], NULL, 16);
|
uint8_t g = strtol(strgroups[1], NULL, 16);
|
||||||
uint8_t b = strtol(strgroups[2], NULL, 16);
|
uint8_t b = strtol(strgroups[2], NULL, 16);
|
||||||
|
uint8_t a = strtol(strgroups[3], NULL, 16);
|
||||||
|
|
||||||
/* We set the first 8 bits high to have 100% opacity in case of a 32 bit
|
return (a << 24) | (r << 16 | g << 8 | b);
|
||||||
* color depth visual. */
|
|
||||||
return (0xFF << 24) | (r << 16 | g << 8 | b);
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user