2 Copyright 2009 by Hans Baier
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
);
29 cr
.translate (10.0, 10.0);
32 cr
.translate (20.0, 0.0);
35 cr
.translate (20.0, 0.0);
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
);
55 static void save_drawable_to_file (string filename
, DrawingArea drawarea
, int width
, int height
) {
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
) {
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 ();
73 var button
= new
TransportButton();
74 button
.icon_type
= IconType
.STOP
;
76 button
= new
TransportButton();
77 button
.icon_type
= IconType
.PLAY
;
79 button
= new
TransportButton();
80 button
.icon_type
= IconType
.REC
;
82 button
= new
TransportButton();
83 button
.icon_type
= IconType
.FAST_BACKWARD
;
85 button
= new
TransportButton();
86 button
.icon_type
= IconType
.FAST_FORWARD
;
88 button
= new
TransportButton();
89 button
.icon_type
= IconType
.TO_START
;
91 button
= new
TransportButton();
92 button
.icon_type
= IconType
.TO_END
;
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
);
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
);
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
);
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
);
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
);
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
);
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
);
146 hbox
.set_child_packing (button
, false, false, 0, PackType
.END
);
153 window
.destroy
+= Gtk
.main_quit
;
160 } // namespace Prolooks