static void st_entry_style_changed (StWidget *self) { StEntryPrivate *priv = ST_ENTRY_PRIV (self); StThemeNode *theme_node; ClutterColor color; const PangoFontDescription *font; gchar *font_string; gdouble size; theme_node = st_widget_get_theme_node (self); st_theme_node_get_foreground_color (theme_node, &color); clutter_text_set_color (CLUTTER_TEXT (priv->entry), &color); if (st_theme_node_lookup_length (theme_node, "caret-size", TRUE, &size)) clutter_text_set_cursor_size (CLUTTER_TEXT (priv->entry), (int)(.5 + size)); if (st_theme_node_lookup_color (theme_node, "caret-color", TRUE, &color)) clutter_text_set_cursor_color (CLUTTER_TEXT (priv->entry), &color); if (st_theme_node_lookup_color (theme_node, "selection-background-color", TRUE, &color)) clutter_text_set_selection_color (CLUTTER_TEXT (priv->entry), &color); if (st_theme_node_lookup_color (theme_node, "selected-color", TRUE, &color)) clutter_text_set_selected_text_color (CLUTTER_TEXT (priv->entry), &color); font = st_theme_node_get_font (theme_node); font_string = pango_font_description_to_string (font); clutter_text_set_font_name (CLUTTER_TEXT (priv->entry), font_string); g_free (font_string); ST_WIDGET_CLASS (st_entry_parent_class)->style_changed (self); }
void xfdashboard_text_box_set_text_color(XfdashboardTextBox *self, const ClutterColor *inColor) { XfdashboardTextBoxPrivate *priv; ClutterColor selectionColor; g_return_if_fail(XFDASHBOARD_IS_TEXT_BOX(self)); g_return_if_fail(inColor); priv=self->priv; /* Set value if changed */ if(!priv->textColor || !clutter_color_equal(inColor, priv->textColor)) { if(priv->textColor) clutter_color_free(priv->textColor); priv->textColor=clutter_color_copy(inColor); clutter_text_set_color(CLUTTER_TEXT(priv->actorTextBox), priv->textColor); /* Selection text and background color is inverted text color if not set */ if(!priv->selectionColorSet) { selectionColor.red=0xff-priv->textColor->red; selectionColor.green=0xff-priv->textColor->green; selectionColor.blue=0xff-priv->textColor->blue; selectionColor.alpha=priv->textColor->alpha; clutter_text_set_selected_text_color(CLUTTER_TEXT(priv->actorTextBox), &selectionColor); /* Selection color is the same as text color */ clutter_text_set_selection_color(CLUTTER_TEXT(priv->actorTextBox), priv->textColor); } /* Redraw actor in new color */ clutter_actor_queue_redraw(CLUTTER_ACTOR(self)); /* Notify about property change */ g_object_notify_by_pspec(G_OBJECT(self), XfdashboardTextBoxProperties[PROP_TEXT_COLOR]); } }
static ClutterActor * create_entry (const ClutterColor *color, const gchar *text, PangoAttrList *attrs, gunichar password_char, gint max_length) { ClutterActor *retval = clutter_text_new_full (NULL, text, color); ClutterColor selection = { 0, }; ClutterColor selected_text = { 0x00, 0x00, 0xff, 0xff }; clutter_actor_set_reactive (retval, TRUE); clutter_color_darken (color, &selection); clutter_text_set_editable (CLUTTER_TEXT (retval), TRUE); clutter_text_set_selectable (CLUTTER_TEXT (retval), TRUE); clutter_text_set_activatable (CLUTTER_TEXT (retval), TRUE); clutter_text_set_single_line_mode (CLUTTER_TEXT (retval), TRUE); clutter_text_set_password_char (CLUTTER_TEXT (retval), password_char); clutter_text_set_cursor_color (CLUTTER_TEXT (retval), &selection); clutter_text_set_max_length (CLUTTER_TEXT (retval), max_length); clutter_text_set_selected_text_color (CLUTTER_TEXT (retval), &selected_text); clutter_actor_set_background_color (retval, CLUTTER_COLOR_LightGray); if (attrs) clutter_text_set_attributes (CLUTTER_TEXT (retval), attrs); g_signal_connect (retval, "activate", G_CALLBACK (on_entry_activate), NULL); g_signal_connect (retval, "captured-event", G_CALLBACK (on_captured_event), NULL); return retval; }
void xfdashboard_text_box_set_selection_background_color(XfdashboardTextBox *self, const ClutterColor *inColor) { XfdashboardTextBoxPrivate *priv; ClutterColor selectionColor; g_return_if_fail(XFDASHBOARD_IS_TEXT_BOX(self)); priv=self->priv; /* Set value if changed */ if(priv->selectionBackgroundColor!=inColor || (priv->selectionBackgroundColor && inColor && !clutter_color_equal(inColor, priv->selectionBackgroundColor))) { /* Freeze notifications and collect them */ g_object_freeze_notify(G_OBJECT(self)); /* Release old color */ if(priv->selectionBackgroundColor) { clutter_color_free(priv->selectionBackgroundColor); priv->selectionBackgroundColor=NULL; /* Check if any selection color is set */ priv->selectionColorSet=((priv->selectionTextColor && priv->selectionBackgroundColor) ? TRUE : FALSE); /* Notify about property change */ g_object_notify_by_pspec(G_OBJECT(self), XfdashboardTextBoxProperties[PROP_SELECTION_BACKGROUND_COLOR]); } /* Set new color if available */ if(inColor) { priv->selectionBackgroundColor=clutter_color_copy(inColor); clutter_text_set_selection_color(CLUTTER_TEXT(priv->actorTextBox), priv->selectionBackgroundColor); /* Any selection color was set */ priv->selectionColorSet=TRUE; /* Notify about property change */ g_object_notify_by_pspec(G_OBJECT(self), XfdashboardTextBoxProperties[PROP_SELECTION_BACKGROUND_COLOR]); } /* Selection text and background color is inverted text color if not set */ if(!priv->selectionColorSet) { selectionColor.red=0xff-priv->textColor->red; selectionColor.green=0xff-priv->textColor->green; selectionColor.blue=0xff-priv->textColor->blue; selectionColor.alpha=priv->textColor->alpha; clutter_text_set_selected_text_color(CLUTTER_TEXT(priv->actorTextBox), &selectionColor); /* Selection color is the same as text color */ clutter_text_set_selection_color(CLUTTER_TEXT(priv->actorTextBox), priv->textColor); } /* Redraw actor in new color */ clutter_actor_queue_redraw(CLUTTER_ACTOR(self)); /* Thaw notifications and send them now */ g_object_thaw_notify(G_OBJECT(self)); } }
G_MODULE_EXPORT gint test_text_main (gint argc, gchar **argv) { ClutterActor *stage; ClutterActor *text, *text2; ClutterColor text_color = { 0x33, 0xff, 0x33, 0xff }; ClutterColor cursor_color = { 0xff, 0x33, 0x33, 0xff }; ClutterTextBuffer *buffer; if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS) return 1; stage = clutter_stage_new (); clutter_stage_set_title (CLUTTER_STAGE (stage), "Text Editing"); clutter_actor_set_background_color (stage, CLUTTER_COLOR_Black); g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL); buffer = clutter_text_buffer_new_with_text ("·", -1); text = clutter_text_new_with_buffer (buffer); clutter_text_set_font_name (CLUTTER_TEXT (text), FONT); clutter_text_set_color (CLUTTER_TEXT (text), &text_color); clutter_container_add (CLUTTER_CONTAINER (stage), text, NULL); clutter_actor_set_position (text, 40, 30); clutter_actor_set_width (text, 1024); clutter_text_set_line_wrap (CLUTTER_TEXT (text), TRUE); clutter_actor_set_reactive (text, TRUE); clutter_stage_set_key_focus (CLUTTER_STAGE (stage), text); clutter_text_set_editable (CLUTTER_TEXT (text), TRUE); clutter_text_set_selectable (CLUTTER_TEXT (text), TRUE); clutter_text_set_cursor_color (CLUTTER_TEXT (text), &cursor_color); clutter_text_set_selected_text_color (CLUTTER_TEXT (text), CLUTTER_COLOR_Blue); text2 = clutter_text_new_with_buffer (buffer); clutter_text_set_color (CLUTTER_TEXT (text2), &text_color); clutter_container_add (CLUTTER_CONTAINER (stage), text2, NULL); clutter_actor_set_position (text2, 40, 300); clutter_actor_set_width (text2, 1024); clutter_text_set_line_wrap (CLUTTER_TEXT (text2), TRUE); clutter_actor_set_reactive (text2, TRUE); clutter_text_set_editable (CLUTTER_TEXT (text2), TRUE); clutter_text_set_selectable (CLUTTER_TEXT (text2), TRUE); clutter_text_set_cursor_color (CLUTTER_TEXT (text2), &cursor_color); clutter_text_set_selected_text_color (CLUTTER_TEXT (text2), CLUTTER_COLOR_Green); if (argv[1]) { GError *error = NULL; gchar *utf8; g_file_get_contents (argv[1], &utf8, NULL, &error); if (error) { utf8 = g_strconcat ("Unable to open '", argv[1], "':\n", error->message, NULL); g_error_free (error); } clutter_text_set_text (CLUTTER_TEXT (text), utf8); } else clutter_text_set_text (CLUTTER_TEXT (text), runes); clutter_actor_set_size (stage, 1024, 768); clutter_actor_show (stage); clutter_main (); return EXIT_SUCCESS; }