add glossy gradient function, courtesy http://cocoawithlove.com/2008/09/drawing-gloss...
[libprolooks.git] / prolooks / GlossGradientDemo.vala
blob7572379a82274ed46bf5a946434cc11cd03c9db8
1 /*
2 Copyright 2009 by Hans Baier
3 License: LGPLv2+
4 */
6 using Gtk;
8 namespace Prolooks {
10 public class GlossDemo : DrawingArea {
12 public GlossDemo () {
14 // Set favored widget size
15 set_size_request (500, 100);
18 /* Widget is asked to draw itself */
19 public override bool expose_event (Gdk.EventExpose event) {
21 // Create a Cairo context
22 var cr = Gdk.cairo_create (this.window);
24 // Set clipping area in order to avoid unnecessary drawing
25 cr.rectangle (event.area.x, event.area.y,
26 event.area.width, event.area.height);
27 cr.clip ();
29 set_source_color_string(cr, "#EDEDED");
30 set_source_color(cr, style.bg[(int)Gtk.StateType.NORMAL]);
31 cr.rectangle(0, 0, allocation.width, allocation.height);
32 cr.fill();
34 double padding = 5.0;
35 double glossbar_height = allocation.height - 2 * padding;
36 double glossbar_width = (allocation.width - 2 * padding) / 5.0 ;
38 Cairo.Pattern gloss_red = gloss_gradient_pattern(0.0, padding, 0.0, glossbar_height, cairo_color_from_string("#D84212"));
39 Cairo.Pattern gloss_green = gloss_gradient_pattern(0.0, padding, 0.0, glossbar_height, cairo_color_from_string("#237000"));
40 Cairo.Pattern gloss_blue = gloss_gradient_pattern(0.0, padding, 0.0, glossbar_height, cairo_color_from_string("#0081FF"));
41 Cairo.Pattern gloss_violet = gloss_gradient_pattern(0.0, padding, 0.0, glossbar_height, cairo_color_from_string("#9331AB"));
42 Cairo.Pattern gloss_gray = gloss_gradient_pattern(0.0, padding, 0.0, glossbar_height, cairo_color_from_string("#5B5B57"));
44 cr.rectangle(padding, padding, glossbar_width, glossbar_height);
45 cr.set_source(gloss_blue);
46 cr.fill();
48 cr.rectangle(padding + glossbar_width, padding, glossbar_width, glossbar_height);
49 cr.set_source(gloss_red);
50 cr.fill();
52 cr.rectangle(padding + 2.0 * glossbar_width, padding, glossbar_width, glossbar_height);
53 cr.set_source(gloss_green);
54 cr.fill();
56 cr.rectangle(padding + 3.0 * glossbar_width, padding, glossbar_width, glossbar_height);
57 cr.set_source(gloss_violet);
58 cr.fill();
60 cr.rectangle(padding + 4.0 * glossbar_width, padding, glossbar_width, glossbar_height);
61 cr.set_source(gloss_gray);
62 cr.fill();
64 return false;
68 static int main (string[] args) {
69 int i, j;
70 Gtk.init (ref args);
71 var window = new Window (WindowType.TOPLEVEL);
73 var glossDemo = new GlossDemo();
75 window.add (glossDemo);
76 window.destroy += Gtk.main_quit;
77 window.show_all ();
78 Gtk.main ();
79 return 0;
83 } // namespace Prolooks