gpt4 book ai didi

multi-touch - Multitouch GTK3示例

转载 作者:行者123 更新时间:2023-12-03 17:49:20 26 4
gpt4 key购买 nike

据我所知,GTK +从3.4版开始就添加了多点触摸支持。我还不清楚这是否仅适用于电话/平板电脑等触摸屏,还是适用于Apple风格的触摸板(Ubuntu/Unity和OS X在触摸板上使用多点触摸手势的方式)。

我也很难找到有关如何实现手势以及如何跟踪多点触摸事件的示例。

有没有很好的例子说明如何使用GTK(或类似Clutter的东西)实现多点触摸?

最佳答案

我也找不到示例,因此这是我的知识:

鼠标事件(简介):

使用鼠标时,Gdk传播事件GDK_BUTTON_PRESSGDK_BUTTON_RELEASE(和一些other)。可以将其转换为GtkWidget信号(如button-press-event),然后转换为更高级别的信号(如GtkButtonclicked)(如果适用)。将回调连接到button-press-event信号可以访问GdkEventButton structure。但是,使用clicked可以使您摆脱跟踪(单击和释放)还是仅释放(例如在动态滚动过程中)的跟踪。

触摸事件:

触摸效果略有不同。有4 touch events:

GDK_TOUCH_BEGIN
A new touch event sequence has just started. This event type was added in 3.4.

GDK_TOUCH_UPDATE
A touch event sequence has been updated. This event type was added in 3.4.

GDK_TOUCH_END
A touch event sequence has finished. This event type was added in 3.4.

GDK_TOUCH_CANCEL
A touch event sequence has been canceled. This event type was added in 3.4.



GdkEventTouch structure使用 GdkEventSequence区分手指。在我看来,它只是一个值(无法在源代码中找到定义),但在这里我可能会误会。 GtkWidget具有类似于 button-press-event等的 touch-event信号,该信号也被转换为诸如 clicked的事件。

示例代码(使用gtkmm,但核心方面相同):
#include <gtkmm.h>
#include <iostream>

int main()
{
auto app = Gtk::Application::create();
Gtk::Window window;
window.set_default_size(1024, 768);
app->signal_startup().connect([&]
{
app->add_window(window);
});

window.show();

//code works for me without adding events mask but let's be thorough
window.add_events(Gdk::TOUCH_MASK);
window.signal_touch_event().connect([&](GdkEventTouch* event)->bool
{
std::cout<<"TOUCH EVENT: ";
switch(event->type)
{
case GDK_TOUCH_BEGIN:
std::cout<<"begin ";
break;
case GDK_TOUCH_UPDATE:
std::cout<<"update ";
break;
case GDK_TOUCH_END:
std::cout<<"end ";
break;
case GDK_TOUCH_CANCEL:
std::cout<<"cancel ";
break;
default:
std::cout<<"something else ";
}
std::cout<<event->sequence<<" "
<<gdk_event_get_event_sequence((GdkEvent*)event)<<" "
<<std::endl;
return GDK_EVENT_PROPAGATE;
});
window.signal_event().connect([&](GdkEvent* event)->bool
{
std::cout<<"EVENT: "<<event->type<<std::endl;
return GDK_EVENT_PROPAGATE;
});

app->run();
return 0;
}

触摸板事件:

也有 touchpad & pad eventsstructures,但似乎在 Gtk级别上没有显式处理。必须在 event信号的回调中通过检查 GdkEventType并将其转换为适当的结构来完成。

关于multi-touch - Multitouch GTK3示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12520540/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com