使用 SurfaceView 进行多点触控绘图

发布于 2024-11-15 21:50:39 字数 344 浏览 1 评论 0原文

过去,我编写了一个可以通过两次触摸来绘制线条的应用程序。我所做的是创建两个向量,一个用于指针 ID 0,另一个用于指针 ID 1(因此其他任何内容都会被忽略)。我将缓冲要在 onTouch 方法中绘制的点,然后在表面绘制方法中绘制两条单独的线。我同步了代码的这些部分,以便 UI 线程和图形线程不会互相干扰。这很好用。

现在我想做的是相同的,但触摸次数不受限制。由于我有无限的触摸,并且屏幕上有任意数量的活动指针 ID,因此我无法简单地为多个触摸创建向量,因为我不知道有多少个触摸。

使用不同的指针 ID 来缓冲多个触摸以便我可以绘制它们的好方法是什么?

也许有一个多点触控绘图应用程序可供我用作参考?

谢谢,

In the past, I wrote an app that would draw lines with two touches. What I did was create two vectors, one for pointer ID 0 and one for Pointer ID 1 (thus anything else gets ignored). I would buffer up the points to draw in my onTouch method, and then draw the lines for the two separate lines in my surface draw method. I synched these parts of the code so that the UI thread and graphics thread wouldn't puke on each other. This worked fine.

Now what I want to do is the same, but with an unlimited number of touches. Since I have unlimited touches, and any random number of pointer IDs active on the screen, I won't be able to simply make vectors for multiple touches since I don't know how many touches there are.

What is a good way to buffer up multiple touches, with various pointer IDs so that I can draw them?

Perhaps there is an multitouch draw app out there that I can use as a reference?

Thanks,

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浴红衣 2024-11-22 21:50:39

一种解决方案是使用以整数作为键(pointerId)、以路径作为对象的映射。在触摸侧,在 TOUCH_DOWN 上开始一条路径,将其添加到地图中,然后每次移动时访问它。在上面,您可以将其从地图中删除并将其“提交”到通用路径列表中,独立于初始pointerId(或者您可以将原始pointerId与路径一起存储)。

因此,基本上,在绘制路径时,将路径保留在使用 pointId 索引的地图中,一旦完成,只需将它们保留在全局列表中即可。

One solution could be to use a map with integers as keys (the pointerIds) and paths as objects. On the touch side, start a path on TOUCH_DOWN, add it to the map, and then access it each time on the move. On the up, you can remove it from the map and "commit" it to a general purpose list of paths, independently from the initial pointerId (or you can store the original pointerId with the path).

So basically, while they are being drawn, keep the paths in a map indexed using the pointerId, and once they are finished, just keep them in a global list.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文