added glade icons
[libprolooks.git] / prolooks / TransportButtonDemo.vala
blobe7a4e7501e6f7c0329f0713fcfb39cf44ea6d455
1 /*
2 Copyright 2009 by Hans Baier
3 License: LGPLv2+
4 */
6 using Gtk;
7 using Gdk;
9 namespace Prolooks {
11 public class TransportButtons : TransportButton {
13 public TransportButtons () {
14 // Set favored widget size
15 set_size_request (280, 40);
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 cr.translate (10.0, 10.0);
30 paint_stop_icon (cr);
32 cr.translate (20.0, 0.0);
33 paint_play_icon (cr);
35 cr.translate (20.0, 0.0);
36 paint_rec_icon (cr);
38 cr.translate (20.0, 0.0);
39 paint_fast_forward_icon (cr);
41 cr.translate (20.0, 0.0);
42 paint_fast_to_end_icon (cr);
44 cr.translate (20.0, 0.0);
45 paint_fast_backward_icon (cr);
47 cr.translate (20.0, 0.0);
48 paint_fast_to_start_icon (cr);
51 return false;
55 static void save_drawable_to_file (string filename, DrawingArea drawarea, int width, int height) {
56 try {
57 Gdk.Pixbuf pixbuf = new Pixbuf (Gdk.Colorspace.RGB, true, drawarea.get_visual ().bits_per_rgb, width, height);
58 pixbuf_get_from_drawable (pixbuf, drawarea.window, null, 0, 0, 0, 0, width, height);
59 pixbuf.save (filename + ".png", "png");
60 } catch (GLib.Error e) {
61 critical ("Trying to save the image gave me that: %s", e.message);
65 static int main (string[] args) {
66 Gtk.init (ref args);
67 var window = new Gtk.Window (Gtk.WindowType.TOPLEVEL);
68 var vbox = new Gtk.VBox (false, 0);
69 var hbox = new Gtk.HBox (false, 0);
70 var widget = new TransportButtons ();
71 vbox.add (widget);
73 var button = new TransportButton();
74 button.icon_type = IconType.STOP;
75 hbox.add (button);
76 button = new TransportButton();
77 button.icon_type = IconType.PLAY;
78 hbox.add (button);
79 button = new TransportButton();
80 button.icon_type = IconType.REC;
81 hbox.add (button);
82 button = new TransportButton();
83 button.icon_type = IconType.FAST_BACKWARD;
84 hbox.add (button);
85 button = new TransportButton();
86 button.icon_type = IconType.FAST_FORWARD;
87 hbox.add (button);
88 button = new TransportButton();
89 button.icon_type = IconType.TO_START;
90 hbox.add (button);
91 button = new TransportButton();
92 button.icon_type = IconType.TO_END;
93 hbox.add (button);
95 vbox.add (hbox);
97 int[] sizes = {16, 22, 24, 28, 32, 48};
98 foreach (var size in sizes) {
99 hbox = new Gtk.HBox (true, 100);
101 button = new TransportButton();
102 button.icon_type = IconType.STOP;
103 button.set_size_request (size, size);
104 hbox.add (button);
105 hbox.set_child_packing (button, false, false, 0, PackType.END);
107 button = new TransportButton();
108 button.icon_type = IconType.PLAY;
109 button.set_size_request (size, size);
110 hbox.add (button);
111 button.event_after += (button) => {
112 int min_width, min_height;
113 button.get_size_request (out min_width, out min_height);
114 save_drawable_to_file ("/tmp/play" + min_width.to_string (), button, min_width, min_height);
116 hbox.set_child_packing (button, false, false, 0, PackType.END);
118 button = new TransportButton();
119 button.icon_type = IconType.REC;
120 button.set_size_request (size, size);
121 hbox.add (button);
122 hbox.set_child_packing (button, false, false, 0, PackType.END);
124 button = new TransportButton();
125 button.icon_type = IconType.FAST_BACKWARD;
126 button.set_size_request (size, size);
127 hbox.add (button);
128 hbox.set_child_packing (button, false, false, 0, PackType.END);
130 button = new TransportButton();
131 button.icon_type = IconType.FAST_FORWARD;
132 button.set_size_request (size, size);
133 hbox.add (button);
134 hbox.set_child_packing (button, false, false, 0, PackType.END);
136 button = new TransportButton();
137 button.icon_type = IconType.TO_START;
138 button.set_size_request (size, size);
139 hbox.add (button);
140 hbox.set_child_packing (button, false, false, 0, PackType.END);
142 button = new TransportButton();
143 button.icon_type = IconType.TO_END;
144 button.set_size_request (size, size);
145 hbox.add (button);
146 hbox.set_child_packing (button, false, false, 0, PackType.END);
148 vbox.add (hbox);
151 window.add (vbox);
153 window.destroy += Gtk.main_quit;
154 window.show_all ();
155 Gtk.main ();
156 return 0;
160 } // namespace Prolooks