是否有任何方法可以在按钮中循环,直到释放按钮?

发布于 2025-02-12 13:38:37 字数 474 浏览 1 评论 0原文

因此,我在这里专门使用GTKMM。

我正在从事的工作: 我正在实现一个功能,在该功能中,当我在某个窗口中按特定窗口时,参数会增加/减小,具体取决于鼠标是否向左/右移动。

需要做什么: 为了以某种方式循环按钮按下回调方法 - (这样做,因为每次迭代都会存储光标位置的新值,并将其与Inital位置进行比较,以确定wheter增加值或减小值) - 直到释放按钮为止。但是,发送的事件保持不变,因此我不能例如检查事件类型是否变为gtk_button_release。我还尝试使用一个标志,该标志在按钮发布回电中设置为false,但是由于执行被卡在现在的无限循环中,因此发行回调甚至没有被调用。

想法 我认为解决方案可能与信号有关。

更新: GTK具有两个功能,可以做我在这里说的,gtk_events_pending()和gtk_main_iteration()。事实证明,事件内有一个无限的循环被认为是一种不良练习,最好使用其他方法,例如使用GDKeventMotion或其他类型。

So im using gtkmm specifically here.

What I'm working on:
I'm implementing a feature in which when I press in a certain window a parameter is increased/decreased depending on if the mouse moves left/right.

What needs to be done:
To be able to somehow loop in the button press callback method -(doing so as each iteration would store the new value of the cursor position and compare it to the inital position to determine wheter increase value or decrease)- until the button is released.However the event which is sent remains the same so I cant just for example check to see if the events type becomes GTK_BUTTON_RELEASE. I have also tried to use a flag which is set to false in the button release call back, however the release callback isnt even called as the execution is stuck in the now infinite loop.

Thoughts
Im thinking maybe the solution could be a certain something to do with signals.

Update:
Gtk has two functions for doing what I was saying here exactly which are , gtk_events_pending(), and gtk_main_iteration(). Hever turns out having a limitless loop inside an event is considered a bad practise and its better to use other methods like here for example using GdkEventMotion, or other types.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文