2 Copyright 2009 by Hans Baier
11 public class TestDisplay
: DisplayBase
{
12 public TestDisplay() {
13 set_size_request (width
, height
);
16 protected override bool draw_contents(Cairo
.Context cr
, Gdk
.EventExpose event
) {
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
);
23 Color
.parse (text_color_default
, out line_color
);
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
);
30 cr
.move_to (20 + ext
.x_advance
+ ext
.x_bearing
, 20 + ext
.y_bearing
);
31 cr
.rel_line_to (0, ext
.height
);
35 cr
.rel_line_to (width
- 20, 0);
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
;
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
) {
70 var window
= new Gtk
.Window (Gtk
.WindowType
.TOPLEVEL
);
71 var vbox
= new
VBox(false, 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
+= display
.toggle_size
;
86 resize_button
.set_size_request(100, 25);
88 matrix_button
.active
= true;
89 matrix_button
.toggled
+= display
.toggle_matrix
;
91 glass_rim_button
.active
= true;
92 glass_rim_button
.toggled
+= display
.toggle_glass_rim
;
95 vbox
.add (resize_button
);
96 vbox
.add (matrix_button
);
97 vbox
.add (glass_rim_button
);
101 window
.destroy
+= Gtk
.main_quit
;
108 } // namespace prolooks