The Big Commit (tm): Remove Cairo.Color and most of Gdk.Color usage from libprolooks
[libprolooks.git] / demos / DisplayDemo.vala
blob7b9d528b2d5bd808b4a50ad7dbe83747fb065fa7
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 protected override bool draw_contents(Cairo.Context cr) {
17 string str = "123| 45| 67890";
18 text(cr, str, 20, 20, 20);
19 Cairo.TextExtents ext = Cairo.TextExtents();
20 cr.text_extents (str, out ext);
22 RGBA line_color = RGBA();
23 line_color.parse (text_color_default);
24 set_source_color (cr, line_color, 0.5);
26 cr.move_to (20, 20 + ext.y_bearing);
27 cr.rel_line_to (0, ext.height);
28 cr.stroke();
30 cr.move_to (20 + ext.x_advance + ext.x_bearing, 20 + ext.y_bearing);
31 cr.rel_line_to (0, ext.height);
32 cr.stroke();
34 cr.move_to (3, 29);
35 cr.rel_line_to (width - 20, 0);
36 cr.stroke();
37 return false;
40 private bool orig_size = true;
42 public void toggle_size() {
43 stdout.printf("orig_size: %d\n", (int)orig_size);
44 int new_width, new_height;
45 if (orig_size) {
46 new_width = 291;
47 new_height = 49;
48 orig_size = false;
49 } else {
50 new_width = 383;
51 new_height = 72;
52 orig_size = true;
55 set_size_request (new_width, new_height);
58 public void toggle_matrix (ToggleButton button) {
59 show_matrix = button.active;
62 public void toggle_glass_rim (ToggleButton button) {
63 show_glass_rim = button.active;
67 static int main (string[] args) {
68 Gtk.init (ref args);
70 var window = new Gtk.Window (Gtk.WindowType.TOPLEVEL);
71 var vbox = new Box(Gtk.Orientation.VERTICAL, 2);
72 var resize_button = new Button.with_label("Resize");
73 var matrix_button = new ToggleButton.with_label("Show Matrix");
74 var glass_rim_button = new ToggleButton.with_label("Show glass rim");
75 var alignment = new Gtk.Alignment (0.5f, 0.5f, 0.5f, 0.5f);
76 TestDisplay display = new TestDisplay ();
78 alignment.bottom_padding = 10;
79 alignment.top_padding = 10;
80 alignment.left_padding = 10;
81 alignment.right_padding = 10;
82 alignment.add (display);
83 alignment.set_size_request(display.width + 20, display.height + 20);
85 resize_button.pressed.connect(display.toggle_size);
86 resize_button.set_size_request(100, 25);
88 matrix_button.active = true;
89 matrix_button.toggled.connect(display.toggle_matrix);
91 glass_rim_button.active = true;
92 glass_rim_button.toggled.connect(display.toggle_glass_rim);
94 vbox.add (alignment);
95 vbox.add (resize_button);
96 vbox.add (matrix_button);
97 vbox.add (glass_rim_button);
100 window.add (vbox);
101 window.destroy.connect(Gtk.main_quit);
102 window.show_all ();
103 Gtk.main ();
104 return 0;
108 } // namespace prolooks