-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDocumentArea.vala
81 lines (62 loc) · 2 KB
/
DocumentArea.vala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using Gtk;
using Gdk;
using Pango;
using Cairo;
public class DocumentArea : DrawingArea {
private Gdk.Window drawableArea;
private Cursor cursor;
private Cairo.Context cfm;
public Pango.Layout layout;
private GC gc;
int width = 800;
int height = 600;
public DocumentArea () {
set_size_request(width, height);
modify_bg(StateType.NORMAL, get_background_color());
add_events(Gdk.EventMask.BUTTON_PRESS_MASK
| Gdk.EventMask.BUTTON_RELEASE_MASK
| Gdk.EventMask.POINTER_MOTION_MASK);
button_release_event.connect(selected_callback);
expose_event.connect(exposed_callback);
}
public void set_cursor() {
drawableArea = get_window();
cursor = new Cursor(CursorType.XTERM);
if (drawableArea != null) {
drawableArea.set_cursor(cursor);
} else {
stderr.printf("null window\n");
}
}
public void add_pango_layout() {
gc = new GC(drawableArea);
gc.set_background(get_background_color());
string hello = "Hello world!";
layout.set_text(hello, -1);
cairo_update_layout(cfm, layout);
draw_layout(drawableArea, gc, 5, 5, layout);
}
private bool selected_callback() {
stderr.printf("click!\n");
return true;
}
private bool exposed_callback() {
cfm = Gdk.cairo_create(window);
layout = cairo_create_layout(cfm);
initialize_pango_layout();
add_pango_layout();
return true;
}
private Gdk.Color get_background_color () {
Gdk.Color bg;
Gdk.Color.parse("#FFF", out bg);
return bg;
}
private void initialize_pango_layout() {
var fontDesc = new FontDescription();
fontDesc.set_family("Sans");
fontDesc.set_size((int) 14 * Pango.SCALE);
layout.set_font_description(fontDesc);
layout.context_changed();
}
}