Knob: instantiate SimpleKnobImageSource by default
[libprolooks.git] / prolooks / DisplayDemo.vala
blob1cfb7e14172af3d71c3f3a5b797204f4a4d0ae8b
1 /*
2 Copyright 2009 by Hans Baier
3 License: LGPLv2+
4 */
6 using Gtk;
7 using Gdk;
9 namespace Prolooks {
11 public class TestDisplay : DisplayBase {
12 public TestDisplay() {
13 set_size_request (width, height);
16 /* Mouse button got pressed over widget */
17 public override bool button_press_event (Gdk.EventButton event) {
18 stdout.printf("Button %u pressed on (%f,%f)\n", event.button, event.x, event.y );
19 return false;
22 /* Mouse button got released */
23 public override bool button_release_event (Gdk.EventButton event) {
24 stdout.printf("Button %u released over (%f,%f)\n", event.button, event.x, event.y );
25 return false;
28 /* Mouse pointer moved over widget */
29 public override bool motion_notify_event (Gdk.EventMotion event) {
30 stdout.printf("Motion over (%f,%f)\n", event.x, event.y );
31 return false;
34 protected override bool draw_contents(Cairo.Context cr, Gdk.EventExpose event) {
35 string str = "123| 45| 67890";
36 text(cr, str, 20, 20, 20);
37 Cairo.TextExtents ext = Cairo.TextExtents();
38 cr.text_extents (str, ref ext);
40 Color line_color;
41 Color.parse (text_color_default, out line_color);
42 set_source_color (cr, line_color, 0.5);
44 cr.move_to (20, 20 + ext.y_bearing);
45 cr.rel_line_to (0, ext.height);
46 cr.stroke();
48 cr.move_to (20 + ext.x_advance + ext.x_bearing, 20 + ext.y_bearing);
49 cr.rel_line_to (0, ext.height);
50 cr.stroke();
52 cr.move_to (3, 29);
53 cr.rel_line_to (width - 20, 0);
54 cr.stroke();
55 return false;
58 private bool orig_size = true;
60 public void toggle_size() {
61 stdout.printf("orig_size: %d\n", (int)orig_size);
62 if (orig_size) {
63 width = 291;
64 height = 49;
65 orig_size = false;
66 } else {
67 width = 383;
68 height = 72;
69 orig_size = true;
72 set_size_request (width, height);
75 static int main (string[] args) {
76 Gtk.init (ref args);
78 var window = new Gtk.Window (Gtk.WindowType.TOPLEVEL);
79 var vbox = new VBox(false, 2);
80 var resize_button = new Button.with_label("Resize");
81 var alignment = new Gtk.Alignment (0.5f, 0.5f, 0.5f, 0.5f);
82 TestDisplay display = new TestDisplay ();
84 alignment.bottom_padding = 10;
85 alignment.top_padding = 10;
86 alignment.left_padding = 10;
87 alignment.right_padding = 10;
88 alignment.add (display);
89 alignment.set_size_request(display.width + 20, display.height + 20);
91 resize_button.pressed += display.toggle_size;
92 resize_button.set_size_request(100, 25);
94 vbox.add (alignment);
95 vbox.add (resize_button);
97 window.add (vbox);
98 window.destroy += Gtk.main_quit;
99 window.show_all ();
100 Gtk.main ();
101 return 0;
105 } // namespace prolooks