我是 GTK 的新手,正在尝试 Vala 来感受一下。(我使用的是gtk+3.0)
谁能解释为什么 event->is_hint 似乎总是返回 1?从文档中我得到的印象是它应该有助于减少多余的运动事件。
这是一个小的 Vala 样本。motion_notify_event 处理程序永远不会有机会遵循 else 子句。
我是在摸索这个错误,还是犯了一个愚蠢的错误,或者这是一个尚未准备好的 GTK+3 东西?
/* To compile: valac --pkg gtk+-3.0 appname.vala */
using Cairo;
namespace Demo {
public class Scribble : Gtk.DrawingArea {
public Scribble () {
this.add_events ( Gdk.EventMask.POINTER_MOTION_MASK | Gdk.EventMask.POINTER_MOTION_HINT_MASK );
this.set_size_request (100,100);
}
private void draw_circ ( Cairo.Context cr ) {
var y = get_allocated_height () / 2;
var radius = double.min (get_allocated_width () / 2, get_allocated_height () / 2) - 5;
cr.arc (y, y, radius, 0, 2 * Math.PI);
cr.set_source_rgb (1, 1, 1);
cr.fill_preserve ();
cr.set_source_rgb (0, 0, 0);
cr.stroke ();
}
public override bool draw ( Cairo.Context cr ) {
this.draw_circ ( cr);
return false;
}
public override bool motion_notify_event (Gdk.EventMotion event ) {
//Seems event.is_hint is *always* 1
//stdout.printf ( "is_hint: %d\n", event.is_hint );
if (event.is_hint == 1) {
stdout.printf ( "is hint\n" );
Gdk.Event.request_motions(event); //Always 1, so what's the point?
} else {
//Never gets here. Why?
stdout.printf ( "normal motion at: %G, %G\n", event.x, event.y );
}
return true; //false does not change anything either.
}
}
}
int main ( string[] args ) {
Gtk.init ( ref args );
var window = new Gtk.Window ();
var scribble = new Demo.Scribble ();
window.add (scribble);
window.show_all ();
window.destroy.connect (Gtk.main_quit);
Gtk.main ();
return 0;
}