使用Win2D绘制可编辑和可选择的形状吗? [英] Drawing editable and selectable shapes with Win2D?
问题描述
在将Shapes
添加到Canvas
-controls之前,我已经使用过System.Windows.Shapes
.
它们可以像对象一样使用,并且在我编辑字段时视觉效果会发生变化.我还可以为点击等添加事件处理程序.
I've used System.Windows.Shapes
before to add Shapes
to Canvas
-controls.
They can be used like objects and the visuals change as I edit the fields. I can also add event handlers for clicks etc.
我将需要使用Win2D
的这种功能.有什么简单的方法吗?
I'd need this kind of functionality by using Win2D
. Is there any easy way?
我正在尝试创建一个像这样的简单应用程序:
I'm trying to create a simple app like this:
- 用户可以在画布上绘制形状
- 可以通过单击选择形状并突出显示形状
- 可以对选定的形状进行操作(颜色,不透明度,宽度,高度,位置等)
- 形状可以彼此叠加(Z索引)
我猜一种方法是用Draw
方法创建自定义的Shape
类.然后,我只操作对象-更改将通过Draw
方法反映到视觉效果.在每个画布无效时,将再次绘制对象.
I guess one way would be to create custom Shape
classes with Draw
-methods. I'd then only manipulate the object - and the changes would reflect to visuals thru the Draw
-method. On each canvas invalidation, the objects would be drawn again.
有什么想法吗?
推荐答案
Win2D可以帮助您进行命中测试.对于具有填充颜色的几何,请使用 CanvasGeometry.FillContainsPoint(...),对于仅具有轮廓/笔触的几何,请使用 CanvasGeometry.StrokeContainsPoint(.. .).使用这两种方法,您将获得准确的命中测试.对于非矩形形状(包括旋转的矩形),使用边界是不准确的.
Win2D can help you with hit-testing. With geometries that have a fill color, then use CanvasGeometry.FillContainsPoint(...) and for geometries that only have an outline/stroke, use CanvasGeometry.StrokeContainsPoint(...). Using these two methods, you'll get accurate hit-testing. Using bounds is not accurate for non-rectangular shapes, including rotated rectangles.
对于z索引,您必须跟踪几何顺序,并从上到下浏览列表,直到PointerPoint
达到目标为止.
For z-indexing, then you have to keep track of the order of your geometries and go through the list from top to bottom until the PointerPoint
has hit something.
如果几何列表太大,并且发现有滞后,则可以先使用边界开始命中测试,如果失败,则继续进行下一项(如果命中),然后使用上述方法获得准确的结果.阅读.
If your list of geometries is too large and you notice a lag, then you can start hit-testing using bounds first and if it fails, continue to next item, if it hits, then use the above methods to get an accurate reading.
这篇关于使用Win2D绘制可编辑和可选择的形状吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!