计算显示的 VisualBrush 视觉效果的数量

发布于 2024-11-02 10:58:58 字数 1162 浏览 4 评论 0原文

我正在 WPF 中开发 CAD 程序,并且正在寻找一种方法来计算渲染特定画笔时显示的控件数量。

假设我有一个椭圆

<椭圆x:名称=“椭圆”Canvas.Top=“25”Canvas.Left=“50”宽度=“400”高度=“250”描边=“深蓝色”StrokeThickness=“5”/>

我用后面代码中的 VisualBrush 填充它:

        VisualBrush tileCounter = new VisualBrush();

        Rectangle rect = new Rectangle() { Width = 10, Height = 10, Fill = Brushes.Blue, Stroke = Brushes.BlueViolet, StrokeThickness = 1 };

        tileCounter.Visual = rect;
        tileCounter.TileMode = TileMode.Tile;
        tileCounter.Stretch = Stretch.None;
        tileCounter.Viewport = new Rect(0, 0, 10, 10);
        tileCounter.ViewportUnits = BrushMappingMode.Absolute;

        Ellipse.Fill = tileCounter;

有没有办法让 VisualBrush 报告它已渲染的矩形形状的实例数作为椭圆的填充?或者是否可以进行代码更改,以使用 FillBackground 从父级单独引用每个视觉效果?

我目前正在开发一个工具来绘制具有任意数量边的图形,这些边是 LineSegmentArcSegmentQuadraticBezierSegment 并且画笔是用户使用输入的高度、宽度和网格大小定义的网格。用户还可以重新调整网格。这使得简单的数学解决方案极难实现,因此 WPF 解决方案会更好。

我的最终目标是获取它尝试渲染的视觉效果总数,然后获取整个填充中每个视觉效果的渲染量。

I am working on a CAD program in WPF and I'm looking for a way to count the number of controls displayed when a particular brush is rendered.

So say I have an Ellipse:


<Ellipse x:Name="Ellipse" Canvas.Top="25" Canvas.Left="50" Width="400" Height="250" Stroke="DarkBlue" StrokeThickness="5" />

And I fill it with a VisualBrush from code behind:

        VisualBrush tileCounter = new VisualBrush();

        Rectangle rect = new Rectangle() { Width = 10, Height = 10, Fill = Brushes.Blue, Stroke = Brushes.BlueViolet, StrokeThickness = 1 };

        tileCounter.Visual = rect;
        tileCounter.TileMode = TileMode.Tile;
        tileCounter.Stretch = Stretch.None;
        tileCounter.Viewport = new Rect(0, 0, 10, 10);
        tileCounter.ViewportUnits = BrushMappingMode.Absolute;

        Ellipse.Fill = tileCounter;

Is there any way to get the VisualBrush to report back how many instances of the rectangle shape it has rendered as the fill of the Ellipse? Or are there code changes I could make to reference each visual individually from the parent using the Fill or Background?

I am currently working on a tool to draw figures that have any number of sides that are LineSegment, ArcSegment, or QuadraticBezierSegment and the brush is a grid that the user defines with entered hight, width, and grid size. The grid is also able to be realigned by the user. This makes simple mathematical solutions extremely hard to pull off and so a WPF solution would be preferable.

My ultimate goal is to get total number of visuals it attempts to render and then how much of each visual is rendered across the entire fill.

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

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

发布评论

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

评论(1

素衣风尘叹 2024-11-09 10:58:58

我很遗憾地告诉你,但我认为你必须走数学路线。

虽然我不完全同意,但我确信我会假设 wpf 绘制该 rect 一次,然后缓存结果,否则该 Visualbrush 将无法执行。所以本质上它实际上只是一个纹理,你无法知道已经完全或部分绘制了多少块瓷砖。

I'm sorry to tell you but I think you have to go the mathematical route.

Though I'm not entirely, sure I'd assume wpf is drawing that rect once and then caching the result, otherwise that visualbrush would not be performant. So essentially it really is only a texture, nothing where you could be aware of how many tiles have been drawn entirely or partially.

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