mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2025-01-14 06:10:21 +00:00
gtk: Use the new apis
It is not perfect, since PangoRenderer, GtkTextAppearance and GtkTextTag all carry colors as PangoColor or GdkRGBA. But at least, we get glowing foreground colors.
This commit is contained in:
parent
e323d2a93e
commit
6f1a4e5bb9
@ -28,6 +28,8 @@
|
||||
#include "gtkwidgetprivate.h"
|
||||
#include "gtkcsscolorvalueprivate.h"
|
||||
#include "gdk/gdkrgbaprivate.h"
|
||||
#include "gdk/gdkcolorprivate.h"
|
||||
#include "gdk/gdkcairoprivate.h"
|
||||
#include "gtkcssshadowvalueprivate.h"
|
||||
|
||||
#include <math.h>
|
||||
@ -58,23 +60,26 @@ gsk_pango_renderer_set_shape_handler (GskPangoRenderer *crenderer,
|
||||
static void
|
||||
get_color (GskPangoRenderer *crenderer,
|
||||
PangoRenderPart part,
|
||||
GdkRGBA *rgba)
|
||||
GdkColor *out_color)
|
||||
{
|
||||
const PangoColor *color = pango_renderer_get_color ((PangoRenderer *) (crenderer), part);
|
||||
const guint16 a = pango_renderer_get_alpha ((PangoRenderer *) (crenderer), part);
|
||||
|
||||
if (color)
|
||||
{
|
||||
rgba->red = color->red / 65535.;
|
||||
rgba->green = color->green / 65535.;
|
||||
rgba->blue = color->blue / 65535.;
|
||||
rgba->alpha = a ? a / 65535. : crenderer->fg_color.alpha;
|
||||
gdk_color_init (out_color, GDK_COLOR_STATE_SRGB,
|
||||
(float[]) {
|
||||
color->red / 65535.,
|
||||
color->green / 65535.,
|
||||
color->blue / 65535.,
|
||||
a ? a / 65535. : crenderer->fg_color.alpha,
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
gdk_color_to_float (&crenderer->fg_color, GDK_COLOR_STATE_SRGB, (float *) rgba);
|
||||
gdk_color_init_copy (out_color, &crenderer->fg_color);
|
||||
if (a)
|
||||
rgba->alpha = a / 65535.;
|
||||
out_color->alpha = a / 65535.;
|
||||
}
|
||||
}
|
||||
|
||||
@ -83,10 +88,11 @@ set_color (GskPangoRenderer *crenderer,
|
||||
PangoRenderPart part,
|
||||
cairo_t *cr)
|
||||
{
|
||||
GdkRGBA rgba = { 0, 0, 0, 1 };
|
||||
GdkColor color;
|
||||
|
||||
get_color (crenderer, part, &rgba);
|
||||
gdk_cairo_set_source_rgba (cr, &rgba);
|
||||
get_color (crenderer, part, &color);
|
||||
gdk_cairo_set_source_color (cr, GDK_COLOR_STATE_SRGB, &color);
|
||||
gdk_color_finish (&color);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -97,7 +103,7 @@ gsk_pango_renderer_draw_glyph_item (PangoRenderer *renderer,
|
||||
int y)
|
||||
{
|
||||
GskPangoRenderer *crenderer = (GskPangoRenderer *) (renderer);
|
||||
GdkRGBA color;
|
||||
GdkColor color;
|
||||
gboolean has_shadow = FALSE;
|
||||
|
||||
if (crenderer->shadow_style)
|
||||
@ -106,12 +112,14 @@ gsk_pango_renderer_draw_glyph_item (PangoRenderer *renderer,
|
||||
|
||||
get_color (crenderer, PANGO_RENDER_PART_FOREGROUND, &color);
|
||||
|
||||
gtk_snapshot_append_text (crenderer->snapshot,
|
||||
glyph_item->item->analysis.font,
|
||||
glyph_item->glyphs,
|
||||
&color,
|
||||
(float) x / PANGO_SCALE,
|
||||
(float) y / PANGO_SCALE);
|
||||
gtk_snapshot_append_text2 (crenderer->snapshot,
|
||||
glyph_item->item->analysis.font,
|
||||
glyph_item->glyphs,
|
||||
&color,
|
||||
(float) x / PANGO_SCALE,
|
||||
(float) y / PANGO_SCALE);
|
||||
|
||||
gdk_color_finish (&color);
|
||||
|
||||
if (has_shadow)
|
||||
gtk_snapshot_pop (crenderer->snapshot);
|
||||
@ -126,16 +134,18 @@ gsk_pango_renderer_draw_rectangle (PangoRenderer *renderer,
|
||||
int height)
|
||||
{
|
||||
GskPangoRenderer *crenderer = (GskPangoRenderer *) (renderer);
|
||||
GdkRGBA rgba;
|
||||
GdkColor color;
|
||||
|
||||
get_color (crenderer, part, &rgba);
|
||||
get_color (crenderer, part, &color);
|
||||
|
||||
gtk_snapshot_append_color (crenderer->snapshot,
|
||||
&rgba,
|
||||
&GRAPHENE_RECT_INIT ((double)x / PANGO_SCALE,
|
||||
(double)y / PANGO_SCALE,
|
||||
(double)width / PANGO_SCALE,
|
||||
(double)height / PANGO_SCALE));
|
||||
gtk_snapshot_append_color2 (crenderer->snapshot,
|
||||
&color,
|
||||
&GRAPHENE_RECT_INIT ((double)x / PANGO_SCALE,
|
||||
(double)y / PANGO_SCALE,
|
||||
(double)width / PANGO_SCALE,
|
||||
(double)height / PANGO_SCALE));
|
||||
|
||||
gdk_color_finish (&color);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -189,7 +199,7 @@ gsk_pango_renderer_draw_error_underline (PangoRenderer *renderer,
|
||||
{
|
||||
GskPangoRenderer *crenderer = (GskPangoRenderer *) (renderer);
|
||||
double xx, yy, ww, hh;
|
||||
GdkRGBA rgba;
|
||||
GdkColor color;
|
||||
GskRoundedRect dot;
|
||||
|
||||
xx = (double)x / PANGO_SCALE;
|
||||
@ -197,7 +207,7 @@ gsk_pango_renderer_draw_error_underline (PangoRenderer *renderer,
|
||||
ww = (double)width / PANGO_SCALE;
|
||||
hh = (double)height / PANGO_SCALE;
|
||||
|
||||
get_color (crenderer, PANGO_RENDER_PART_UNDERLINE, &rgba);
|
||||
get_color (crenderer, PANGO_RENDER_PART_UNDERLINE, &color);
|
||||
|
||||
gtk_snapshot_push_repeat (crenderer->snapshot,
|
||||
&GRAPHENE_RECT_INIT (xx, yy, ww, hh),
|
||||
@ -208,11 +218,13 @@ gsk_pango_renderer_draw_error_underline (PangoRenderer *renderer,
|
||||
hh / 2);
|
||||
|
||||
gtk_snapshot_push_rounded_clip (crenderer->snapshot, &dot);
|
||||
gtk_snapshot_append_color (crenderer->snapshot, &rgba, &dot.bounds);
|
||||
gtk_snapshot_append_color2 (crenderer->snapshot, &color, &dot.bounds);
|
||||
gtk_snapshot_pop (crenderer->snapshot);
|
||||
gtk_snapshot_append_color (crenderer->snapshot,
|
||||
&GDK_RGBA_TRANSPARENT,
|
||||
&GRAPHENE_RECT_INIT (xx, yy, 1.5 * hh, hh));
|
||||
gtk_snapshot_append_color2 (crenderer->snapshot,
|
||||
&GDK_COLOR_SRGB (0, 0, 0, 0),
|
||||
&GRAPHENE_RECT_INIT (xx, yy, 1.5 * hh, hh));
|
||||
|
||||
gdk_color_finish (&color);
|
||||
|
||||
gtk_snapshot_pop (crenderer->snapshot);
|
||||
}
|
||||
|
@ -22,7 +22,7 @@
|
||||
#include "gtkcsscolorvalueprivate.h"
|
||||
#include "gtkcssshadowvalueprivate.h"
|
||||
#include "gtkpangoprivate.h"
|
||||
#include "gtksnapshot.h"
|
||||
#include "gtksnapshotprivate.h"
|
||||
#include "gtktypebuiltins.h"
|
||||
#include "gtksettings.h"
|
||||
|
||||
@ -35,7 +35,7 @@ gtk_css_style_snapshot_layout (GtkCssBoxes *boxes,
|
||||
PangoLayout *layout)
|
||||
{
|
||||
GtkCssStyle *style;
|
||||
const GdkRGBA *color;
|
||||
GdkColor color;
|
||||
gboolean has_shadow;
|
||||
|
||||
gtk_snapshot_push_debug (snapshot, "Layout");
|
||||
@ -47,11 +47,11 @@ gtk_css_style_snapshot_layout (GtkCssBoxes *boxes,
|
||||
}
|
||||
|
||||
style = boxes->style;
|
||||
color = gtk_css_color_value_get_rgba (style->used->color);
|
||||
gtk_css_color_to_color (gtk_css_color_value_get_color (style->used->color), &color);
|
||||
|
||||
has_shadow = gtk_css_shadow_value_push_snapshot (style->used->text_shadow, snapshot);
|
||||
|
||||
gtk_snapshot_append_layout (snapshot, layout, color);
|
||||
gtk_snapshot_append_layout2 (snapshot, layout, &color);
|
||||
|
||||
if (has_shadow)
|
||||
gtk_snapshot_pop (snapshot);
|
||||
@ -59,6 +59,8 @@ gtk_css_style_snapshot_layout (GtkCssBoxes *boxes,
|
||||
if (x != 0 || y != 0)
|
||||
gtk_snapshot_restore (snapshot);
|
||||
|
||||
gdk_color_finish (&color);
|
||||
|
||||
gtk_snapshot_pop (snapshot);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user