-
-
Notifications
You must be signed in to change notification settings - Fork 84
Cursor Test
Danielle Foré edited this page Oct 8, 2024
·
1 revision
Short Vala app to test cursor alignment:
// valac --pkg gtk+-3.0 cursor.vala
void main(string[] args) {
new Cursors().run();
}
class Cursors : Gtk.Application {
protected override void activate() {
var w = new Gtk.ApplicationWindow(this);
w.add(new Area());
w.show_all();
}
}
class Area : Gtk.DrawingArea {
public double mx;
public double my;
construct {
add_events(Gdk.EventMask.POINTER_MOTION_MASK|Gdk.EventMask.SCROLL_MASK);
set_size_request(100, 100);
}
public override bool motion_notify_event(Gdk.EventMotion e) {
mx = e.x;
my = e.y;
queue_draw();
return false;
}
public override bool scroll_event (Gdk.EventScroll e) {
switch(e.direction) {
case DOWN: choice = (choice + 1) % choices.length; break;
case UP: choice = (choice + choices.length - 1) % choices.length; break;
}
queue_draw();
return true;
}
public override bool draw(Cairo.Context cr) {
var c = new Gdk.Cursor.from_name(get_display(), choices[choice]);
get_parent_window().set_cursor(c);
int w = get_allocated_width();
int h = get_allocated_height();
cr.set_source_rgb(0,0,1);
cr.move_to(5, 20);
cr.show_text(choices[choice]);
cr.set_source_rgb(1,0,0);
cr.set_line_width(1);
cr.move_to(mx, 0);
cr.line_to(mx, h);
cr.move_to(0, my);
cr.line_to(w, my);
cr.stroke();
return false;
}
int choice = 2;
string[] choices = {
"none",
"default",
"help",
"pointer",
"context-menu",
"progress","wait",
"cell",
"crosshair",
"text","vertical-text",
"alias",
"copy",
"no-drop",
"move",
"not-allowed",
"grab","grabbing",
"all-scroll",
"col-resize","row-resize",
"n-resize","e-resize","s-resize","w-resize",
"ne-resize","nw-resize","sw-resize","se-resize",
"ew-resize","ns-resize","nesw-resize","nwse-resize",
"zoom-in","zoom-out",
};
}