我在 Gtk Fixed 项目上移动控件时遇到问题,代码抖动移动,而且通常很慢。我已经尝试找到正确的方法来做到这一点,但是都揭示了相同的结果。
我认为相关的代码是:
view.button_press_event.connect( (bp) => {
view.set_data("in_motion", true);
int pointX = 0; int pointY = 0;
fixed.get_pointer(out pointX, out pointY);
int origX = 0; int origY = 0;
view.translate_coordinates(fixed, 0,0, out origX, out origY);
view.set_data("startx", origX + origX);
view.set_data("starty", origY + origY);
view.set_data("startsx", pointX);
view.set_data("startsy", pointY);
view.is_focus = true;
view.has_focus = true;
return false;
});
view.button_release_event.connect( (bp) => {
view.set_data("in_motion", false);
return false;
});
view.motion_notify_event.connect( (me) => {
// TODO: Make this less glitchy somehow
if(view.get_data<bool>("in_motion") == true){
int x = view.get_data<int>("startx") + (int)me.x - view.get_data<int>("startsx");
int y = view.get_data<int>("starty") + (int)me.y - view.get_data<int>("startsy");
((Fixed)view.parent).move(view, x,y );
}
return false;
});
(其余的在https://github.com/kennydude/diagramatic/blob/master/diagram.vala上)