static void get_text_color( GtkWidget * w, const tr_stat * st, GtrColor * setme ) { #if GTK_CHECK_VERSION( 3,0,0 ) static const GdkRGBA red = { 1.0, 0, 0, 0 }; if( st->error ) *setme = red; else if( st->activity == TR_STATUS_STOPPED ) gtk_style_context_get_color( gtk_widget_get_style_context( w ), GTK_STATE_FLAG_INSENSITIVE, setme ); else gtk_style_context_get_color( gtk_widget_get_style_context( w ), GTK_STATE_FLAG_NORMAL, setme ); #else static const GdkColor red = { 0, 65535, 0, 0 }; if( st->error ) *setme = red; else if( st->activity == TR_STATUS_STOPPED ) *setme = gtk_widget_get_style(w)->text[GTK_STATE_INSENSITIVE]; else *setme = gtk_widget_get_style(w)->text[GTK_STATE_NORMAL]; #endif }
static void ig_reload_style (GnmItemGrid *ig) { GocItem *item = GOC_ITEM (ig); GtkStyleContext *context = goc_item_get_style_context (item); GtkBorder border; GtkStateFlags state = GTK_STATE_FLAG_NORMAL; GnmPane *pane = GNM_PANE (item->canvas); gtk_style_context_save (context); gtk_style_context_add_region (context, "function-marker", 0); gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, &ig->function_marker_color); gtk_style_context_get_border_color (context, state, &ig->function_marker_border_color); gtk_style_context_restore (context); gtk_style_context_save (context); gtk_style_context_add_region (context, "pane-divider", 0); gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, &ig->pane_divider_color); gtk_style_context_get_border (context, GTK_STATE_FLAG_NORMAL, &border); ig->pane_divider_width = border.top; /* Hack? */ gtk_style_context_restore (context); /* ---------------------------------------- */ context = gtk_widget_get_style_context (GTK_WIDGET (pane)); gtk_widget_style_get (GTK_WIDGET (pane), "function-indicator-size", &ig->function_marker_size, NULL); }
static void id_cell_data_func (GtkTreeViewColumn *column, GtkCellRenderer *renderer, GtkTreeModel *model, GtkTreeIter *iter, GladeEditorProperty *eprop) { GladeEPropStringList *eprop_string_list = GLADE_EPROP_STRING_LIST (eprop); if (eprop_string_list->with_id) { GtkStyleContext* context = gtk_widget_get_style_context (eprop_string_list->view); GdkRGBA color; guint index; gboolean dummy; gchar *id = NULL; gtk_tree_model_get (eprop_string_list->model, iter, COLUMN_INDEX, &index, COLUMN_DUMMY, &dummy, COLUMN_ID, &id, -1); /* Dummy, no data yet */ if (dummy) { g_object_set (renderer, "editable", FALSE, "text", NULL, NULL); } /* Not dummy, and id already set */ else if (id) { gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, &color); g_object_set (renderer, "style", PANGO_STYLE_NORMAL, "foreground-rgba", &color, "editable", TRUE, "text", id, NULL); } /* Not dummy, but no id yet */ else { gtk_style_context_get_color (context, GTK_STATE_FLAG_INSENSITIVE, &color); g_object_set (renderer, "style", PANGO_STYLE_ITALIC, "foreground-rgba", &color, "editable", TRUE, "text", _("<Enter ID>"), NULL); } g_free (id); } else g_object_set (renderer, "visible", FALSE, NULL); }
static void set_color_from_style (GdkRGBA *color, GtkStyleContext *context, GtkStateFlags state, MetaGtkColorComponent component) { GdkRGBA other; gtk_style_context_set_state (context, state); switch (component) { case META_GTK_COLOR_BG: case META_GTK_COLOR_BASE: meta_color_get_background_color (context, state, color); break; case META_GTK_COLOR_FG: case META_GTK_COLOR_TEXT: gtk_style_context_get_color (context, state, color); break; case META_GTK_COLOR_TEXT_AA: gtk_style_context_get_color (context, state, color); set_color_from_style (&other, context, state, META_GTK_COLOR_BASE); color->red = (color->red + other.red) / 2; color->green = (color->green + other.green) / 2; color->blue = (color->blue + other.blue) / 2; break; case META_GTK_COLOR_MID: meta_color_get_light_color (context, state, color); meta_color_get_dark_color (context, state, &other); color->red = (color->red + other.red) / 2; color->green = (color->green + other.green) / 2; color->blue = (color->blue + other.blue) / 2; break; case META_GTK_COLOR_LIGHT: meta_color_get_light_color (context, state, color); break; case META_GTK_COLOR_DARK: meta_color_get_dark_color (context, state, color); break; case META_GTK_COLOR_LAST: default: g_assert_not_reached (); break; } }
static void get_text_color( GtkWidget * w, const tr_stat * st, GtrColor * setme ) { static const GdkRGBA red = { 1.0, 0, 0, 0 }; if( st->error ) *setme = red; else if( st->activity == TR_STATUS_STOPPED ) gtk_style_context_get_color( gtk_widget_get_style_context( w ), GTK_STATE_FLAG_INSENSITIVE, setme ); else gtk_style_context_get_color( gtk_widget_get_style_context( w ), GTK_STATE_FLAG_NORMAL, setme ); }
static void fg(GtkWidget* widget, GtkStateFlags state, GdkRGBA& gdkRGBA) { GtkStyleContext* sc = gtk_widget_get_style_context(widget); gtk_style_context_get_color(sc, state, &gdkRGBA); if (gdkRGBA.alpha <= 0) { widget = gtk_widget_get_parent(GTK_WIDGET(ContainerWidget())); sc = gtk_widget_get_style_context(widget); gtk_style_context_get_color(sc, state, &gdkRGBA); } }
static void get_text_color(TrgRssCellRenderer * r, GtkWidget * widget, GtrColor * setme) { struct TrgRssCellRendererPrivate *p = r->priv; if (p->uploaded) gtk_style_context_get_color(gtk_widget_get_style_context(widget), GTK_STATE_FLAG_INSENSITIVE, setme); else gtk_style_context_get_color(gtk_widget_get_style_context(widget), GTK_STATE_FLAG_NORMAL, setme); }
static void test_init_of_theme (void) { GtkStyleContext *context; GtkCssProvider *provider; GtkWidgetPath *path; GdkRGBA before, after; char *css; /* Test that a style context actually uses the theme loaded for the * screen it is using. If no screen is set, it's the default one. */ context = gtk_style_context_new (); path = gtk_widget_path_new (); /* Set a path that will have a color set. * (This could actually fail if style classes change, so if this test * fails, make sure to have this path represent something sane.) */ gtk_widget_path_append_type (path, GTK_TYPE_WINDOW); gtk_widget_path_iter_add_class (path, -1, GTK_STYLE_CLASS_BACKGROUND); gtk_style_context_set_path (context, path); gtk_widget_path_free (path); /* Get the color. This should be initialized by the theme and not be * the default. */ gtk_style_context_get_color (context, gtk_style_context_get_state (context), &before); /* Add a style that sets a different color for this widget. * This style has a higher priority than fallback, but a lower * priority than the theme. */ css = g_strdup_printf (".background { color: %s; }", before.alpha < 0.5 ? "black" : "transparent"); provider = gtk_css_provider_new (); gtk_css_provider_load_from_data (provider, css, -1, NULL); gtk_style_context_add_provider (context, GTK_STYLE_PROVIDER (provider), GTK_STYLE_PROVIDER_PRIORITY_FALLBACK + 1); g_object_unref (provider); /* Get the color again. */ gtk_style_context_get_color (context, gtk_style_context_get_state (context), &after); /* Because the style we added does not influence the color, * the before and after colors should be identical. */ g_assert (gdk_rgba_equal (&before, &after)); g_object_unref (context); }
void ev_document_misc_paint_one_page (cairo_t *cr, GtkWidget *widget, GdkRectangle *area, GtkBorder *border, gboolean highlight, gboolean inverted_colors) { GtkStyleContext *context = gtk_widget_get_style_context (widget); GtkStateFlags state = gtk_widget_get_state_flags (widget); GdkRGBA fg, bg, shade_bg; gtk_style_context_save (context); gtk_style_context_get_background_color (context, state, &bg); gtk_style_context_get_color (context, state, &fg); gtk_style_context_get_color (context, state, &shade_bg); gtk_style_context_restore (context); shade_bg.alpha *= 0.5; gdk_cairo_set_source_rgba (cr, highlight ? &fg : &shade_bg); cairo_rectangle (cr, area->x, area->y, area->width - border->right + border->left, area->height - border->bottom + border->top); cairo_rectangle (cr, area->x + area->width - border->right, area->y + border->right - border->left, border->right, area->height - border->right + border->left); cairo_rectangle (cr, area->x + border->bottom - border->top, area->y + area->height - border->bottom, area->width - border->bottom + border->top, border->bottom); cairo_fill (cr); if (inverted_colors) cairo_set_source_rgb (cr, 0, 0, 0); else cairo_set_source_rgb (cr, 1, 1, 1); cairo_rectangle (cr, area->x + border->left, area->y + border->top, area->width - (border->left + border->right), area->height - (border->top + border->bottom)); cairo_fill (cr); }
wxColor DrawingUtils::GetMenuTextColour() { #ifdef __WXGTK__ static bool intitialized(false); static wxColour textColour(wxSystemSettings::GetColour(wxSYS_COLOUR_MENUTEXT)); if( !intitialized ) { // try to get the text colour from a menu GtkWidget *menuBar = gtk_menu_new(); #ifdef __WXGTK3__ GdkRGBA col; GtkStyleContext* context = gtk_widget_get_style_context( menuBar ); gtk_style_context_get_color(context, GTK_STATE_FLAG_NORMAL, &col); textColour = wxColour(col); #else GtkStyle *def = gtk_rc_get_style( menuBar ); if(!def) def = gtk_widget_get_default_style(); if(def) { GdkColor col = def->text[GTK_STATE_NORMAL]; textColour = wxColour(col); } #endif gtk_widget_destroy( menuBar ); intitialized = true; } return textColour; #else return wxSystemSettings::GetColour(wxSYS_COLOUR_MENUTEXT); #endif }
static gboolean gs_review_bar_draw (GtkWidget *widget, cairo_t *cr) { GtkStyleContext *context; gdouble y_offset, bar_height; GdkRGBA color; context = gtk_widget_get_style_context (widget); /* don't fill the complete height (too heavy beside GtkLabel of that height) */ y_offset = floor (0.15 * gtk_widget_get_allocated_height (widget)); bar_height = gtk_widget_get_allocated_height (widget) - (y_offset * 2); gtk_render_background (context, cr, 0, y_offset, gtk_widget_get_allocated_width (widget), bar_height); cairo_rectangle (cr, 0, y_offset, round (GS_REVIEW_BAR (widget)->fraction * gtk_widget_get_allocated_width (widget)), bar_height); gtk_style_context_get_color (context, gtk_widget_get_state_flags (widget), &color); cairo_set_source_rgba (cr, color.red, color.green, color.blue, color.alpha); cairo_fill (cr); return GTK_WIDGET_CLASS (gs_review_bar_parent_class)->draw (widget, cr); }
static gboolean gb_progress_bar_draw (GtkWidget *widget, cairo_t *cr) { GbProgressBarPrivate *priv; GtkStyleContext *context; GbProgressBar *bar = (GbProgressBar *)widget; GtkAllocation allocation; GtkStateType state; GdkRGBA color = { 0 }; g_return_val_if_fail(GB_IS_PROGRESS_BAR(bar), FALSE); priv = bar->priv; if (gtk_widget_is_drawable(widget)) { gtk_widget_get_allocation(widget, &allocation); state = gtk_widget_get_state(widget); context = gtk_widget_get_style_context(widget); gtk_style_context_get_color(context, state, &color); cairo_save(cr); cairo_rectangle(cr, 0, 0, priv->fraction * allocation.width, allocation.height); gdk_cairo_set_source_rgba(cr, &color); cairo_fill(cr); cairo_restore(cr); } return FALSE; }
static void get_prop_color (GtkWidget *w, const gchar *name, const gchar *dv, gboolean silent_fallback, GdkRGBA *out_color) { GdkColor *color = NULL; GtkStyleContext *style_context = gtk_widget_get_style_context (w); gtk_widget_style_get (w, name, &color, NULL); if (color) { copy_to_rgba (color, out_color); gdk_color_free (color); return; } if (dv && gdk_rgba_parse (out_color, dv)) return; if (!silent_fallback) g_warning ("falling back to text color"); gtk_style_context_get_color (style_context, GTK_STATE_FLAG_NORMAL, out_color); }
/* Set the colour of the "valid from" and "valid until" elements on the * Certificate page to red if they are incorrectly in the future or * past. */ static void show_date_state(char* label, void* data, int length) { gchar* labelname = g_strndup(label, strstr(label, ":") - label); GtkLabel* l = GTK_LABEL(gtk_builder_get_object(builder, labelname)); PangoAttrList *attrs = pango_attr_list_new(); PangoAttribute *attr; gboolean* is_invalid = (gboolean*)data; g_free(labelname); if(*is_invalid) { attr = pango_attr_foreground_new(G_MAXUINT16, 0, 0); } else { #if HAVE_GTK == 3 GdkRGBA color; GtkStyleContext *style = gtk_widget_get_style_context(GTK_WIDGET(l)); gtk_style_context_get_color(style, GTK_STATE_FLAG_NORMAL, &color); attr = pango_attr_foreground_new(color.red * G_MAXUINT16, color.green * G_MAXUINT16, color.blue * G_MAXUINT16); #else #if HAVE_GTK == 2 /* In GTK+ 2, there is no GtkStyleContext yet. It * should, in theory, be possible to figure out what the * default foreground color is by using a GTK+ * 2-specific API, but that's too much work and GTK+ 2 * is a minority now anyway, so... */ attr = pango_attr_foreground_new(0, 0, 0); #else /* The configure script only allows GTK+2 or GTK+3. */ #error should not happen #endif #endif } pango_attr_list_insert(attrs, attr); gtk_label_set_attributes(l, attrs); }
static void create_layout (GtkSourceGutterRendererText *renderer, GtkWidget *widget) { PangoLayout *layout; PangoAttribute *attr; GtkStyleContext *context; GdkRGBA color; PangoAttrList *attr_list; layout = gtk_widget_create_pango_layout (widget, NULL); context = gtk_widget_get_style_context (widget); gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, &color); attr = pango_attr_foreground_new (color.red * 65535, color.green * 65535, color.blue * 65535); attr->start_index = 0; attr->end_index = G_MAXINT; attr_list = pango_attr_list_new (); pango_attr_list_insert (attr_list, attr); renderer->priv->fg_attr = attr; renderer->priv->cached_layout = layout; renderer->priv->cached_attr_list = attr_list; }
void LeftMargin::setupMargin(GtkTextView *textView) { if(!mMarginLayout) { GtkWidget *widget = GTK_WIDGET(textView); mMarginLayout = gtk_widget_create_pango_layout(widget, ""); updateTextInfo(textView); pango_layout_set_width(mMarginLayout, mTextWidth); pango_layout_set_alignment(mMarginLayout, PANGO_ALIGN_RIGHT); GtkStyleContext *widgetStyle = gtk_widget_get_style_context(widget); GdkRGBA color; gtk_style_context_get_color(widgetStyle, GTK_STATE_FLAG_NORMAL, &color); mMarginAttr = pango_attr_foreground_new(convertGdkColorToPango(color.red), convertGdkColorToPango(color.green), convertGdkColorToPango(color.blue)); mMarginAttrList = pango_attr_list_new(); mMarginAttr->start_index = 0; mMarginAttr->end_index = G_MAXUINT; pango_attr_list_insert(mMarginAttrList, mMarginAttr); pango_layout_set_attributes(mMarginLayout, mMarginAttrList); } }
void styleContext_getForeColor(GtkStyleContext* a_StyleContext, GdkRGBA* a_ForeColor) { // gtk_style_context_save(a_StyleContext); // gtk_style_context_set_state(a_StyleContext, GTK_STATE_FLAG_NORMAL); gtk_style_context_get_color(a_StyleContext, GTK_STATE_FLAG_NORMAL, a_ForeColor); // gtk_style_context_restore(a_StyleContext); }
static void style_context_changed (GtkStyleContext *style_context, GbTerminalView *self) { GtkStateFlags state; GdkRGBA fg; GdkRGBA bg; g_assert (GTK_IS_STYLE_CONTEXT (style_context)); g_assert (GB_IS_TERMINAL_VIEW (self)); state = gtk_style_context_get_state (style_context); G_GNUC_BEGIN_IGNORE_DEPRECATIONS; gtk_style_context_get_color (style_context, state, &fg); gtk_style_context_get_background_color (style_context, state, &bg); G_GNUC_END_IGNORE_DEPRECATIONS; if (bg.alpha == 0.0) { gdk_rgba_parse (&bg, "#f6f7f8"); } vte_terminal_set_colors (self->terminal_top, &fg, &bg, solarized_palette, G_N_ELEMENTS (solarized_palette)); if (self->terminal_bottom) vte_terminal_set_colors (self->terminal_bottom, &fg, &bg, solarized_palette, G_N_ELEMENTS (solarized_palette)); }
static gboolean sample_draw_callback(GtkWidget *widget, cairo_t *cr, gpointer data) { guint width, height; dt_colorpicker_sample_t *sample = (dt_colorpicker_sample_t *)data; width = gtk_widget_get_allocated_width(widget); height = gtk_widget_get_allocated_height(widget); gdk_cairo_set_source_rgba(cr, &sample->rgb); cairo_rectangle(cr, 0, 0, width, height); cairo_fill (cr); // if the sample is locked we want to add a lock if(sample->locked) { int border = DT_PIXEL_APPLY_DPI(2); int icon_width = width - 2 * border; int icon_height = height - 2 * border; if(icon_width > 0 && icon_height > 0) { GdkRGBA fg_color; gtk_style_context_get_color(gtk_widget_get_style_context(widget), gtk_widget_get_state_flags(widget), &fg_color); gdk_cairo_set_source_rgba(cr, &fg_color); dtgtk_cairo_paint_lock(cr, border, border, icon_width, icon_height, 0); } } return FALSE; }
static gboolean cbDraw(GtkWidget *da, cairo_t *cr) { #ifdef QS_DEBUG static int count = 0; QS_SPEW("%d\n", ++count); #endif if(!x) x = qsDrawX11Context_create(da); #if 1 XSetForeground(x->dsp, x->gc, x->bg.pixel); #else guint width, height; GdkRGBA color; width = gtk_widget_get_allocated_width(da); height = gtk_widget_get_allocated_height(da); cairo_arc(cr, width / 2.0, height / 2.0, MIN (width, height) / 2.0, 0, 2 * G_PI); gtk_style_context_get_color( gtk_widget_get_style_context(da), 0, &color); gdk_cairo_set_source_rgba(cr, &color); cairo_fill (cr); #endif return true; }
/* function to highlight label */ void highlight(GtkWidget *eventbox) { GtkWidget *label, *lighted_eventbox, *lighted_label; GList *child; GtkStyleContext *context; GdkRGBA selected_fg, selected_bg; /* get label from eventbox */ child = gtk_container_get_children(GTK_CONTAINER(eventbox)); label = child->data; /* prepare highlight colors */ context = gtk_widget_get_style_context(label); gtk_style_context_get_color(context, GTK_STATE_FLAG_SELECTED, &selected_fg); gtk_style_context_get_background_color(context, GTK_STATE_FLAG_SELECTED, &selected_bg); /* clearcolor previous highlighted label */ lighted_eventbox = g_object_get_data(G_OBJECT(builder), "lighted_eventbox"); if(lighted_eventbox) { child = gtk_container_get_children(GTK_CONTAINER(lighted_eventbox)); lighted_label = child->data; clearcolor(lighted_label, lighted_eventbox); } /* apply color */ gtk_widget_override_color(label, GTK_STATE_FLAG_NORMAL, &selected_fg); gtk_widget_override_background_color(eventbox, GTK_STATE_FLAG_NORMAL, &selected_bg); /* set current eventbox as lighted */ g_object_set_data(G_OBJECT(builder), "lighted_eventbox", eventbox); }
static gboolean handle_draw_cb (GtkWidget * widget, cairo_t * cr, gpointer user_data) { GstVideoRectangle *r = &anim_state.rect; GtkStyleContext *style; GdkRGBA color; int width, height; width = gtk_widget_get_allocated_width (widget); height = gtk_widget_get_allocated_height (widget); style = gtk_widget_get_style_context (widget); gtk_style_context_get_color (style, 0, &color); gdk_cairo_set_source_rgba (cr, &color); /* we should only redraw outside of the video rect! */ cairo_rectangle (cr, 0, 0, r->x, height); cairo_rectangle (cr, r->x + r->w, 0, width - (r->x + r->w), height); cairo_rectangle (cr, 0, 0, width, r->y); cairo_rectangle (cr, 0, r->y + r->h, width, height - (r->y + r->h)); cairo_fill (cr); if (verbose) { g_print ("draw(%p)\n", widget); } gst_video_overlay_expose (anim_state.overlay); return FALSE; }
gchar * gpk_package_id_format_twoline (GtkStyleContext *style, const gchar *package_id, const gchar *summary) { g_autofree gchar *summary_safe = NULL; GString *string; g_auto(GStrv) split = NULL; g_autofree gchar *color = NULL; const gchar *arch; GdkRGBA inactive; g_return_val_if_fail (package_id != NULL, NULL); /* get style color */ if (style != NULL) { gtk_style_context_get_color (style, GTK_STATE_FLAG_INSENSITIVE, &inactive); color = g_strdup_printf ("#%02x%02x%02x", (guint) (inactive.red * 255.0f), (guint) (inactive.green * 255.0f), (guint) (inactive.blue * 255.0f)); } else { color = g_strdup ("gray"); } /* optional */ split = pk_package_id_split (package_id); if (split == NULL) { g_warning ("could not parse %s", package_id); return NULL; } /* no summary */ if (summary == NULL || summary[0] == '\0') { string = g_string_new (split[PK_PACKAGE_ID_NAME]); if (split[PK_PACKAGE_ID_VERSION][0] != '\0') g_string_append_printf (string, "-%s", split[PK_PACKAGE_ID_VERSION]); arch = gpk_get_pretty_arch (split[PK_PACKAGE_ID_ARCH]); if (arch != NULL) g_string_append_printf (string, " (%s)", arch); return g_string_free (string, FALSE); } /* name and summary */ string = g_string_new (""); summary_safe = g_markup_escape_text (summary, -1); g_string_append_printf (string, "%s\n", summary_safe); g_string_append_printf (string, "<span color=\"%s\">", color); g_string_append (string, split[PK_PACKAGE_ID_NAME]); if (split[PK_PACKAGE_ID_VERSION][0] != '\0') g_string_append_printf (string, "-%s", split[PK_PACKAGE_ID_VERSION]); arch = gpk_get_pretty_arch (split[PK_PACKAGE_ID_ARCH]); if (arch != NULL) g_string_append_printf (string, " (%s)", arch); g_string_append (string, "</span>"); return g_string_free (string, FALSE); }
static void get_text_color(GtkWidget* w, tr_stat const* st, GtrColor* setme) { static GdkRGBA const red = { 1.0, 0, 0, 0 }; if (st->error != 0) { *setme = red; } else if (st->activity == TR_STATUS_STOPPED) { gtk_style_context_get_color(gtk_widget_get_style_context(w), GTK_STATE_FLAG_INSENSITIVE, setme); } else { gtk_style_context_get_color(gtk_widget_get_style_context(w), GTK_STATE_FLAG_NORMAL, setme); } }
/* Draws a rounded rectangle with text inside. */ static gboolean numbers_draw_cb (GtkWidget *widget, cairo_t *ctx, gpointer data) { double x, y, w, h; PangoLayout * layout; gint font_size = gtk_widget_get_font_size (widget); #if (INDICATOR_MESSAGES_HAS_LOZENGE == 1) gboolean is_lozenge = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget), "is-lozenge")); /* let the label handle the drawing if it's not a lozenge */ if (!is_lozenge) return FALSE; #endif if (!GTK_IS_WIDGET (widget)) return FALSE; /* get style + arrow position / dimensions */ double red, green, blue; GtkStyleContext *style = gtk_widget_get_style_context (widget); GdkRGBA color; gtk_style_context_get_color (style, gtk_widget_get_state(widget), &color); red = color.red; green = color.green; blue = color.blue; GtkAllocation allocation; gtk_widget_get_allocation (widget, &allocation); w = allocation.width; h = allocation.height; x = y = 0; layout = gtk_label_get_layout (GTK_LABEL(widget)); PangoRectangle layout_extents; pango_layout_get_extents (layout, NULL, &layout_extents); pango_extents_to_pixels (&layout_extents, NULL); if (layout_extents.width == 0) return TRUE; cairo_set_line_width (ctx, 1.0); cairo_set_fill_rule (ctx, CAIRO_FILL_RULE_EVEN_ODD); /* cairo drawing code */ custom_cairo_rounded_rectangle (ctx, x - font_size/2.0, y, w + font_size, h); cairo_set_source_rgba (ctx, red, green, blue, 0.5); x += (allocation.width - layout_extents.width) / 2.0; y += (allocation.height - layout_extents.height) / 2.0; cairo_move_to (ctx, floor (x), floor (y)); pango_cairo_layout_path (ctx, layout); cairo_fill (ctx); return TRUE; }
static void cell_data_func (GtkTreeViewColumn *column, GtkCellRenderer *renderer, GtkTreeModel *model, GtkTreeIter *iter, GladeEditorProperty *eprop) { GladeEPropStringList *eprop_string_list = GLADE_EPROP_STRING_LIST (eprop); gboolean dummy; GdkRGBA color; gtk_tree_model_get (model, iter, COLUMN_DUMMY, &dummy, -1); if (GTK_IS_CELL_RENDERER_TEXT (renderer)) { GtkStyleContext* context = gtk_widget_get_style_context (eprop_string_list->view); if (dummy) { gtk_style_context_save (context); gtk_style_context_set_state (context, gtk_style_context_get_state (context) | GTK_STATE_FLAG_INSENSITIVE); gtk_style_context_get_color (context, gtk_style_context_get_state (context), &color); gtk_style_context_restore (context); g_object_set (renderer, "style", PANGO_STYLE_ITALIC, "foreground-rgba", &color, NULL); } else { gtk_style_context_get_color (context, gtk_style_context_get_state (context), &color); g_object_set (renderer, "style", PANGO_STYLE_NORMAL, "foreground-rgba", &color, NULL); } } else if (GLADE_IS_CELL_RENDERER_ICON (renderer)) g_object_set (renderer, "visible", !dummy && eprop_string_list->translatable, NULL); }
static gboolean _lib_ratings_draw_callback(GtkWidget *widget, cairo_t *crf, gpointer user_data) { dt_lib_module_t *self = (dt_lib_module_t *)user_data; dt_lib_ratings_t *d = (dt_lib_ratings_t *)self->data; if(!darktable.control->running) return TRUE; GtkAllocation allocation; gtk_widget_get_allocation(widget, &allocation); cairo_surface_t *cst = dt_cairo_image_surface_create(CAIRO_FORMAT_ARGB32, allocation.width, allocation.height); cairo_t *cr = cairo_create(cst); GtkStyleContext *context = gtk_widget_get_style_context(widget); gtk_render_background(context, cr, 0, 0, allocation.width, allocation.height); /* get current style */ GdkRGBA fg_color; gtk_style_context_get_color(context, gtk_widget_get_state_flags(widget), &fg_color); /* lets draw stars */ int x = 0; cairo_set_line_width(cr, 1.5); gdk_cairo_set_source_rgba(cr, &fg_color); d->current = 0; for(int k = 0; k < 5; k++) { /* outline star */ dt_draw_star(cr, STAR_SIZE / 2.0 + x, STAR_SIZE / 2.0, STAR_SIZE / 2.0, STAR_SIZE / 4.0); if(x < d->pointerx) { cairo_fill_preserve(cr); cairo_set_source_rgba(cr, fg_color.red, fg_color.green, fg_color.blue, fg_color.alpha * 0.5); cairo_stroke(cr); gdk_cairo_set_source_rgba(cr, &fg_color); if((k + 1) > d->current) d->current = (k + 1); } else cairo_stroke(cr); x += STAR_SIZE + STAR_SPACING; } /* blit memsurface onto widget*/ cairo_destroy(cr); cairo_set_source_surface(crf, cst, 0, 0); cairo_paint(crf); cairo_surface_destroy(cst); return TRUE; }
static gboolean on_countdown_draw(GtkWidget* pie, cairo_t* cr, WindowData* windata) { GtkAllocation allocation; GtkStyleContext* style; GdkRGBA color; GdkRGBA fg_color; cairo_t* context; cairo_surface_t* surface; double r, g, b; context = gdk_cairo_create(gtk_widget_get_window(GDK_WINDOW(windata->pie_countdown))); #if GTK_CHECK_VERSION(3, 0, 0) style = gtk_widget_get_style_context(windata->win); cairo_set_operator(context, CAIRO_OPERATOR_SOURCE); gtk_widget_get_allocation(pie, &allocation); surface = cairo_surface_create_similar(cairo_get_target(context), CAIRO_CONTENT_COLOR_ALPHA, allocation.width, allocation.height); cairo_set_source_surface (cr, surface, 0, 0); cairo_set_operator(cr, CAIRO_OPERATOR_OVER); #if GTK_CHECK_VERSION (3, 0, 0) gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, &color); gtk_style_context_get_background_color (context, GTK_STATE_FLAG_NORMAL, &fg_color); r = color.red; g = color.green; b = color.blue; cairo_set_source_rgba(cr, r, g, b, BACKGROUND_ALPHA); cairo_paint(cr); if (windata->timeout > 0) { gdouble pct = (gdouble) windata->remaining / (gdouble) windata->timeout; gdk_cairo_set_source_rgba(cr, &fg_color); cairo_move_to(cr, PIE_RADIUS, PIE_RADIUS); cairo_arc_negative(cr, PIE_RADIUS, PIE_RADIUS, PIE_RADIUS, -G_PI_2, -(pct * G_PI * 2) - G_PI_2); cairo_line_to(cr, PIE_RADIUS, PIE_RADIUS); cairo_fill(cr); } cairo_destroy(cr); cairo_set_source_surface(context, surface, 0, 0); cairo_paint(context); cairo_surface_destroy(surface); cairo_destroy(context); return TRUE; }
void decor_update_switcher_property (decor_t *d) { long *data; Display *xdisplay = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); gint nQuad; decor_quad_t quads[N_QUADS_MAX]; unsigned int nOffset = 1; unsigned int frame_type = populate_frame_type (d); unsigned int frame_state = populate_frame_state (d); unsigned int frame_actions = populate_frame_actions (d); GtkStyleContext *context; GdkRGBA fg; long fgColor[4]; nQuad = decor_set_lSrStSbX_window_quads (quads, &d->frame->window_context_active, &d->border_layout, d->border_layout.top.x2 - d->border_layout.top.x1 - d->frame->window_context_active.extents.left - d->frame->window_context_active.extents.right - 32); data = decor_alloc_property (nOffset, WINDOW_DECORATION_TYPE_PIXMAP); decor_quads_to_property (data, nOffset - 1, cairo_xlib_surface_get_drawable (d->surface), &d->frame->win_extents, &d->frame->win_extents, &d->frame->win_extents, &d->frame->win_extents, 0, 0, quads, nQuad, frame_type, frame_state, frame_actions); context = gtk_widget_get_style_context (d->frame->style_window_rgba); gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, &fg); fgColor[0] = fg.red; fgColor[1] = fg.green; fgColor[2] = fg.blue; fgColor[3] = SWITCHER_ALPHA; gdk_error_trap_push (); XChangeProperty (xdisplay, d->prop_xid, win_decor_atom, XA_INTEGER, 32, PropModeReplace, (guchar *) data, PROP_HEADER_SIZE + BASE_PROP_SIZE + QUAD_PROP_SIZE * N_QUADS_MAX); XChangeProperty (xdisplay, d->prop_xid, switcher_fg_atom, XA_INTEGER, 32, PropModeReplace, (guchar *) fgColor, 4); gdk_display_sync (gdk_display_get_default ()); gdk_error_trap_pop_ignored (); free (data); }
static gboolean draw_text_cursor_cb (GtkWidget *widget, cairo_t *cr, gpointer user_data) { GtkEditable *editable = GTK_EDITABLE(widget); GtkStyleContext *stylectxt = gtk_widget_get_style_context (GTK_WIDGET(widget)); gint height = gtk_widget_get_allocated_height (widget); const gchar *text; GdkRGBA *fg_color; GdkRGBA color; gint x_offset; gint cursor_x = 0; // Get the layout x offset gtk_entry_get_layout_offsets (GTK_ENTRY(widget), &x_offset, NULL); // Get the foreground color gdk_rgba_parse (&color, "black"); gtk_style_context_get_color (stylectxt, GTK_STATE_FLAG_NORMAL, &color); fg_color = &color; text = gtk_entry_get_text (GTK_ENTRY (widget)); if ((text != NULL) && (*text != '\0')) { PangoLayout *layout; PangoRectangle strong_pos; gint start_pos, end_pos, cursor_pos, cursor_byte_pos; cursor_pos = gtk_editable_get_position (editable); cursor_byte_pos = g_utf8_offset_to_pointer (text, cursor_pos) - text; gtk_editable_get_selection_bounds (editable, &start_pos, &end_pos); layout = gtk_entry_get_layout (GTK_ENTRY(widget)); pango_layout_get_cursor_pos (layout, cursor_byte_pos, &strong_pos, NULL); cursor_x = x_offset + PANGO_PIXELS (strong_pos.x); } else cursor_x = x_offset; // Now draw a vertical line cairo_set_source_rgb (cr, fg_color->red, fg_color->green, fg_color->blue); cairo_set_line_width (cr, 1.0); cairo_move_to (cr, cursor_x + 0.5, 2); cairo_rel_line_to (cr, 0, height - 4); cairo_stroke (cr); return FALSE; }