5 draw_cb_checks (GtkWidget *widget, cairo_t *cr)
7 GtkStyleContext *context;
9 context = gtk_widget_get_style_context (widget);
11 gtk_style_context_save (context);
13 gtk_style_context_add_class (context, "check");
14 gtk_style_context_set_state (context, 0);
15 gtk_render_check (context, cr, 12, 12, 12, 12);
16 gtk_style_context_set_state (context, GTK_STATE_FLAG_ACTIVE);
17 gtk_render_check (context, cr, 36, 12, 12, 12);
18 gtk_style_context_set_state (context, GTK_STATE_FLAG_INCONSISTENT);
19 gtk_render_check (context, cr, 60, 12, 12, 12);
20 gtk_style_context_set_state (context, GTK_STATE_FLAG_INSENSITIVE);
21 gtk_render_check (context, cr, 84, 12, 12, 12);
23 gtk_style_context_restore (context);
30 draw_cb_options (GtkWidget *widget, cairo_t *cr)
32 GtkStyleContext *context;
34 context = gtk_widget_get_style_context (widget);
36 gtk_style_context_save (context);
38 gtk_style_context_add_class (context, "radio");
39 gtk_style_context_set_state (context, 0);
40 gtk_render_option (context, cr, 12, 12, 12, 12);
41 gtk_style_context_set_state (context, GTK_STATE_FLAG_ACTIVE);
42 gtk_render_option (context, cr, 36, 12, 12, 12);
43 gtk_style_context_set_state (context, GTK_STATE_FLAG_INCONSISTENT);
44 gtk_render_option (context, cr, 60, 12, 12, 12);
45 gtk_style_context_set_state (context, GTK_STATE_FLAG_INSENSITIVE);
46 gtk_render_option (context, cr, 84, 12, 12, 12);
48 gtk_style_context_restore (context);
54 draw_cb_arrows (GtkWidget *widget, cairo_t *cr)
56 GtkStyleContext *context;
58 context = gtk_widget_get_style_context (widget);
60 gtk_style_context_save (context);
62 gtk_style_context_set_state (context, 0);
63 gtk_render_arrow (context, cr, 0, 12, 12, 12);
64 gtk_render_arrow (context, cr, G_PI/2, 36, 12, 12);
65 gtk_render_arrow (context, cr, G_PI, 60, 12, 12);
66 gtk_render_arrow (context, cr, G_PI*3/2, 84, 12, 12);
68 gtk_style_context_restore (context);
74 draw_cb_expanders (GtkWidget *widget, cairo_t *cr)
76 GtkStyleContext *context;
78 context = gtk_widget_get_style_context (widget);
80 gtk_style_context_save (context);
82 gtk_style_context_add_class (context, "expander");
83 gtk_style_context_set_state (context, 0);
84 gtk_render_expander (context, cr, 12, 12, 12, 12);
85 gtk_style_context_set_state (context, GTK_STATE_FLAG_PRELIGHT);
86 gtk_render_expander (context, cr, 36, 12, 12, 12);
87 gtk_style_context_set_state (context, GTK_STATE_FLAG_ACTIVE);
88 gtk_render_expander (context, cr, 60, 12, 12, 12);
89 gtk_style_context_set_state (context, GTK_STATE_FLAG_PRELIGHT | GTK_STATE_FLAG_ACTIVE);
90 gtk_render_expander (context, cr, 84, 12, 12, 12);
92 gtk_style_context_restore (context);
98 draw_cb_background (GtkWidget *widget, cairo_t *cr)
100 GtkStyleContext *context;
102 context = gtk_widget_get_style_context (widget);
104 gtk_style_context_save (context);
106 gtk_style_context_add_class (context, "background");
107 gtk_style_context_set_junction_sides (context, 0);
108 gtk_render_background (context, cr, 12, 12, 100, 100);
109 gtk_style_context_remove_class (context, "background");
111 gtk_style_context_restore (context);
117 draw_cb_frame (GtkWidget *widget, cairo_t *cr)
119 GtkStyleContext *context;
121 context = gtk_widget_get_style_context (widget);
123 gtk_style_context_save (context);
125 gtk_style_context_add_class (context, "frame1");
126 gtk_style_context_set_junction_sides (context, 0);
127 gtk_render_frame (context, cr, 12, 12, 50, 50);
128 gtk_style_context_remove_class (context, "frame1");
130 gtk_style_context_add_class (context, "frame2");
131 gtk_render_frame (context, cr, 74, 12, 50, 50);
132 gtk_style_context_remove_class (context, "frame2");
134 gtk_style_context_add_class (context, "frame3");
135 gtk_style_context_set_junction_sides (context, GTK_JUNCTION_RIGHT);
136 gtk_render_frame (context, cr, 12, 74, 56, 50);
137 gtk_style_context_set_junction_sides (context, GTK_JUNCTION_LEFT);
138 gtk_render_frame (context, cr, 68, 74, 56, 50);
139 gtk_style_context_remove_class (context, "frame3");
141 gtk_style_context_restore (context);
146 /* FIXME: this doesn't work */
148 draw_cb_activity (GtkWidget *widget, cairo_t *cr)
150 GtkStyleContext *context;
153 context = gtk_widget_get_style_context (widget);
154 gtk_style_context_save (context);
156 path = gtk_widget_path_new ();
157 gtk_widget_path_append_type (path, GTK_TYPE_SPINNER);
158 gtk_widget_path_iter_add_class (path, 0, "spinner");
159 gtk_style_context_set_path (context, path);
160 gtk_widget_path_free (path);
162 gtk_style_context_set_state (context, GTK_STATE_FLAG_ACTIVE);
163 gtk_render_activity (context, cr, 12, 12, 12, 12);
165 gtk_style_context_restore (context);
171 draw_cb_slider (GtkWidget *widget, cairo_t *cr)
173 GtkStyleContext *context;
176 context = gtk_widget_get_style_context (widget);
177 gtk_style_context_save (context);
179 path = gtk_widget_path_new ();
180 gtk_widget_path_append_type (path, GTK_TYPE_SCALE);
181 gtk_widget_path_iter_add_class (path, 0, "slider");
182 gtk_widget_path_iter_add_class (path, 0, "scale");
183 gtk_style_context_set_path (context, path);
184 gtk_widget_path_free (path);
186 gtk_render_slider (context, cr, 12, 22, 30, 10, GTK_ORIENTATION_HORIZONTAL);
187 gtk_render_slider (context, cr, 54, 12, 10, 30, GTK_ORIENTATION_VERTICAL);
189 gtk_style_context_restore (context);
195 draw_cb_focus (GtkWidget *widget, cairo_t *cr)
197 GtkStyleContext *context;
199 context = gtk_widget_get_style_context (widget);
201 gtk_style_context_save (context);
203 gtk_render_focus (context, cr, 12, 12, 50, 50);
205 gtk_style_context_restore (context);
211 draw_cb_extension (GtkWidget *widget, cairo_t *cr)
213 GtkStyleContext *context;
215 context = gtk_widget_get_style_context (widget);
217 gtk_style_context_save (context);
219 gtk_style_context_add_class (context, "notebook");
220 gtk_style_context_add_region (context, GTK_STYLE_REGION_TAB, 0);
222 gtk_style_context_set_state (context, 0);
223 gtk_render_extension (context, cr, 26, 12, 24, 12, GTK_POS_BOTTOM);
224 gtk_render_extension (context, cr, 12, 26, 12, 24, GTK_POS_RIGHT);
225 gtk_render_extension (context, cr, 26, 52, 24, 12, GTK_POS_TOP);
226 gtk_render_extension (context, cr, 52, 26, 12, 24, GTK_POS_LEFT);
228 gtk_style_context_restore (context);
234 draw_cb_frame_gap (GtkWidget *widget, cairo_t *cr)
236 GtkStyleContext *context;
238 context = gtk_widget_get_style_context (widget);
240 gtk_style_context_save (context);
242 gtk_style_context_add_class (context, "frame");
243 gtk_style_context_set_junction_sides (context, 0);
244 gtk_render_frame_gap (context, cr, 12, 12, 50, 50, GTK_POS_TOP, 15, 35);
245 gtk_style_context_remove_class (context, "frame");
247 gtk_style_context_restore (context);
253 draw_cb_handles (GtkWidget *widget, cairo_t *cr)
255 GtkStyleContext *context;
257 context = gtk_widget_get_style_context (widget);
258 gtk_style_context_save (context);
260 gtk_style_context_add_class (context, "paned");
261 gtk_render_handle (context, cr, 12, 22, 20, 10);
262 gtk_render_handle (context, cr, 44, 12, 10, 20);
263 gtk_style_context_remove_class (context, "paned");
265 gtk_style_context_add_class (context, "grip");
266 gtk_style_context_set_junction_sides (context, GTK_JUNCTION_CORNER_BOTTOMLEFT);
267 gtk_render_handle (context, cr, 12, 48, 12, 12);
269 gtk_style_context_set_junction_sides (context, GTK_JUNCTION_CORNER_BOTTOMRIGHT);
270 gtk_render_handle (context, cr, 40, 48, 12, 12);
272 gtk_style_context_restore (context);
280 draw_cb (GtkWidget *widget, cairo_t *cr)
282 if (strcmp (what, "check") == 0)
283 return draw_cb_checks (widget, cr);
284 else if (strcmp (what, "option") == 0)
285 return draw_cb_options (widget, cr);
286 else if (strcmp (what, "arrow") == 0)
287 return draw_cb_arrows (widget, cr);
288 else if (strcmp (what, "expander") == 0)
289 return draw_cb_expanders (widget, cr);
290 else if (strcmp (what, "background") == 0)
291 return draw_cb_background (widget, cr);
292 else if (strcmp (what, "frame") == 0)
293 return draw_cb_frame (widget, cr);
294 else if (strcmp (what, "activity") == 0)
295 return draw_cb_activity (widget, cr);
296 else if (strcmp (what, "slider") == 0)
297 return draw_cb_slider (widget, cr);
298 else if (strcmp (what, "focus") == 0)
299 return draw_cb_focus (widget, cr);
300 else if (strcmp (what, "extension") == 0)
301 return draw_cb_extension (widget, cr);
302 else if (strcmp (what, "frame-gap") == 0)
303 return draw_cb_frame_gap (widget, cr);
304 else if (strcmp (what, "handle") == 0)
305 return draw_cb_handles (widget, cr);
310 int main (int argc, char *argv[])
314 GtkStyleContext *context;
315 GtkStyleProvider *provider;
317 gtk_init (&argc, &argv);
324 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
325 gtk_window_set_has_resize_grip (GTK_WINDOW (window), FALSE);
326 ebox = gtk_event_box_new ();
327 gtk_event_box_set_visible_window (GTK_EVENT_BOX (ebox), TRUE);
328 gtk_container_add (GTK_CONTAINER (window), ebox);
329 gtk_widget_set_name (ebox, "ebox");
331 context = gtk_widget_get_style_context (ebox);
332 provider = (GtkStyleProvider *)gtk_css_provider_new ();
333 gtk_css_provider_load_from_data (GTK_CSS_PROVIDER (provider),
335 " border-image: url('gradient1.png') 10 10 10 10 stretch;\n"
338 " border-style: solid;\n"
339 " border-color: rgb(255,0,0);\n"
340 " border-width: 10;\n"
341 " border-radius: 10;\n"
344 " border-style: solid;\n"
345 " border-color: rgb(0,0,0);\n"
346 " border-width: 2;\n"
347 " border-radius: 10;\n"
350 " border-radius: 10;\n"
351 " border-width: 0;\n"
352 " background-image: -gtk-gradient (linear, left top, right bottom, from(#ff00ff), to(#aabbcc));\n"
355 " border-style: solid;\n"
356 " border-width: 1;\n"
357 " border-radius: 0;\n"
359 gtk_style_context_add_provider (context, provider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
361 g_signal_connect_after (ebox, "draw", G_CALLBACK (draw_cb), NULL);
363 gtk_widget_show_all (window);
367 gtk_style_context_remove_provider (context, provider);