The Big Commit (tm): Remove Cairo.Color and most of Gdk.Color usage from libprolooks
[libprolooks.git] / demos / GlossGradientDemo.vala
blob3ff46161fb3062390aa8699e3a712e1ce9276add
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, 55);
16 draw.connect(on_draw);
19 /* Widget is asked to draw itself */
20 public bool on_draw (Cairo.Context cr) {
21 Gtk.Allocation allocation;
22 get_allocation(out allocation);
24 set_source_color_string(cr, "#EDEDED");
25 set_source_color(cr, gdk_color_to_rgba(style.bg[(int)Gtk.StateType.NORMAL]));
26 cr.rectangle(0, 0, allocation.width, allocation.height);
27 cr.fill();
29 double padding = 5.0;
30 double glossbar_height = allocation.height - 2 * padding;
31 double glossbar_width = (allocation.width - 2 * padding) / 5.0 ;
33 Cairo.Pattern gloss_red = gloss_gradient_pattern(0.0, padding, 0.0, glossbar_height + padding, rgba_from_string("#D84212"), 50);
34 Cairo.Pattern gloss_green = gloss_gradient_pattern(0.0, padding, 0.0, glossbar_height + padding, rgba_from_string("#237000"), 50);
35 Cairo.Pattern gloss_blue = gloss_gradient_pattern(0.0, padding, 0.0, glossbar_height + padding, rgba_from_string("#0081FF"), 50);
36 Cairo.Pattern gloss_violet = gloss_gradient_pattern(0.0, padding, 0.0, glossbar_height + padding, rgba_from_string("#9331AB"), 50);
37 Cairo.Pattern gloss_gray = gloss_gradient_pattern(0.0, padding, 0.0, glossbar_height + padding, rgba_from_string("#5B5B57"), 50);
39 cr.rectangle(padding, padding, glossbar_width, glossbar_height);
40 cr.set_source(gloss_blue);
41 cr.fill();
43 cr.rectangle(padding + glossbar_width, padding, glossbar_width, glossbar_height);
44 cr.set_source(gloss_red);
45 cr.fill();
47 cr.rectangle(padding + 2.0 * glossbar_width, padding, glossbar_width, glossbar_height);
48 cr.set_source(gloss_green);
49 cr.fill();
51 cr.rectangle(padding + 3.0 * glossbar_width, padding, glossbar_width, glossbar_height);
52 cr.set_source(gloss_violet);
53 cr.fill();
55 cr.rectangle(padding + 4.0 * glossbar_width, padding, glossbar_width, glossbar_height);
56 cr.set_source(gloss_gray);
57 cr.fill();
59 return false;
63 static int main (string[] args) {
64 Gtk.init (ref args);
65 var window = new Window (WindowType.TOPLEVEL);
67 var glossDemo = new GlossDemo();
69 window.add (glossDemo);
70 window.destroy.connect(Gtk.main_quit);
71 window.show_all ();
72 Gtk.main ();
73 return 0;
75 } // namespace Prolooks