Commit 677941dc authored by Benjamin Otte's avatar Benjamin Otte

gtk-demo: Add animated pixbufs example

parent c5551e55
......@@ -18,6 +18,7 @@ demos = \
css_accordion.c \
css_basics.c \
css_multiplebgs.c \
css_pixbufs.c \
dialog.c \
drawingarea.c \
editable_cells.c \
......@@ -118,6 +119,7 @@ RESOURCES= application.ui \
css_accordion.css \
css_basics.css \
css_multiplebgs.css \
css_pixbufs.css \
cssview.css \
fancy.css \
/* CSS Theming/Animated backgrounds
* This demo is done in honour of the Pixbufs demo further down. It is done exclusively
* with CSS as the background of the window.
#include <gtk/gtk.h>
static GtkWidget *window = NULL;
static void
show_parsing_error (GtkCssProvider *provider,
GtkCssSection *section,
const GError *error,
GtkTextBuffer *buffer)
GtkTextIter start, end;
const char *tag_name;
gtk_text_buffer_get_iter_at_line_index (buffer,
gtk_css_section_get_start_line (section),
gtk_css_section_get_start_position (section));
gtk_text_buffer_get_iter_at_line_index (buffer,
gtk_css_section_get_end_line (section),
gtk_css_section_get_end_position (section));
tag_name = "warning";
tag_name = "error";
gtk_text_buffer_apply_tag_by_name (buffer, tag_name, &start, &end);
static void
css_text_changed (GtkTextBuffer *buffer,
GtkCssProvider *provider)
GtkTextIter start, end;
char *text;
gtk_text_buffer_get_start_iter (buffer, &start);
gtk_text_buffer_get_end_iter (buffer, &end);
gtk_text_buffer_remove_all_tags (buffer, &start, &end);
text = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
gtk_css_provider_load_from_data (provider, text, -1, NULL);
g_free (text);
gtk_style_context_reset_widgets (gdk_screen_get_default ());
static void
apply_css (GtkWidget *widget, GtkStyleProvider *provider)
gtk_style_context_add_provider (gtk_widget_get_style_context (widget), provider, G_MAXUINT);
if (GTK_IS_CONTAINER (widget))
gtk_container_forall (GTK_CONTAINER (widget), (GtkCallback) apply_css, provider);
GtkWidget *
do_css_pixbufs (GtkWidget *do_widget)
if (!window)
GtkWidget *paned, *container, *child;
GtkStyleProvider *provider;
GtkTextBuffer *text;
GBytes *bytes;
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (do_widget));
gtk_window_set_default_size (GTK_WINDOW (window), 400, 300);
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed), &window);
paned = gtk_paned_new (GTK_ORIENTATION_VERTICAL);
gtk_container_add (GTK_CONTAINER (window), paned);
/* Need a filler so we get a handle */
child = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_container_add (GTK_CONTAINER (paned), child);
text = gtk_text_buffer_new (NULL);
gtk_text_buffer_create_tag (text,
gtk_text_buffer_create_tag (text,
provider = GTK_STYLE_PROVIDER (gtk_css_provider_new ());
container = gtk_scrolled_window_new (NULL, NULL);
gtk_container_add (GTK_CONTAINER (paned), container);
child = gtk_text_view_new_with_buffer (text);
gtk_container_add (GTK_CONTAINER (container), child);
g_signal_connect (text,
G_CALLBACK (css_text_changed),
bytes = g_resources_lookup_data ("/css_pixbufs/gtk.css", 0, NULL);
gtk_text_buffer_set_text (text, g_bytes_get_data (bytes, NULL), g_bytes_get_size (bytes));
g_signal_connect (provider,
G_CALLBACK (show_parsing_error),
gtk_text_view_get_buffer (GTK_TEXT_VIEW (child)));
apply_css (window, provider);
if (!gtk_widget_get_visible (window))
gtk_widget_show_all (window);
gtk_widget_destroy (window);
window = NULL;
return window;
......@@ -64,3 +64,13 @@ GtkWindow {
background-repeat: no-repeat, no-repeat, no-repeat, no-repeat, no-repeat, no-repeat, no-repeat, no-repeat, repeat;
animation: move-the-image infinite linear 3s, size-the-image infinite alternate ease-in-out 0.75s;
/* Make the text editor has a nice style */
.view, .scrollbar, .pane-separator {
color: black;
background-color: rgba(255,255,255,0.5);
.view:selected {
background-color: rgba(127,127,255,0.5);
......@@ -27,4 +27,16 @@
<gresource prefix="/theming_style_classes">
<file preprocess="xml-stripblanks">theming.ui</file>
<gresource prefix="/css_pixbufs">
<file alias="gtk.css">css_pixbufs.css</file>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment