重新绘制时放大杂乱开罗纹理

发布于 2024-09-08 07:46:40 字数 1128 浏览 2 评论 0原文

我正在使用 python-clutter 1.0

我的问题以挑战的形式

编写代码以允许通过按一个键放大到 CairoTexture actor,分步进行,以便在每个 actor 上都可以重新绘制(由 cairo),以便图像保持高分辨率,但仍按预期缩放,无需重新调整演员的大小。

想想像 Inkscape 这样的东西以及如何放大矢量;矢量如何在任何放大倍数下保持干净。将一条路径(比如一堆 cairo line_to 命令)放到 CairoTexture actor 上,然后允许相同的技巧发生。

更多细节

我的目标是一个使用演员组的小型 SVG 编辑器。每个演员都致力于一条道路。我使用 SomeGroup.set_depth(z) 进行“缩放”,然后使 z 变大/变小。到目前为止一切都很好。然而,演员距离摄像机越近,纹理拉伸得越多,以适应他们新的外观尺寸。

我似乎无法找到一种方法让混乱同时做到这两点:

  1. 将演员的实际尺寸保持静态(即它开始时的样子)。
  2. 将其底层表面换成更大的表面(放大时),然后我可以重新-将路径绘制到(并使用开罗矩阵来执行上下文的缩放。)

如果我使用 set_sizeset_surface_size,演员会变得更大 这不是有意的。我只希望它的表面(底层数据)变得更大。

(我不确定这个术语,也许是 mipmapping?)

换句话说:多边形越来越大,增加其纹理数组的大小,以便它可以映射到更大的多边形。

我什至尝试通过保留第二个表面(使用 pycairo)将其重新创建为演员的表观尺寸(get_transformed_size),然后使用 clutter 的 set_from_rgb_data 来绕过混乱。 并将其指向我的第二个表面,强制重新调整表面的大小,但不调整演员的尺寸。

这样做的问题是:a) 杂乱忽略了新的尺寸,只绘制到旧的宽度/高度;b) RGBA 与 ARGB32 的情况会导致颜色崩溃。

我对任何替代想法持开放态度,我希望我站在树林里错过所有的树木!

\d

I am using python-clutter 1.0

My question in the form of a challenge

Write code to allow zooming up to a CairoTexture actor, by pressing a key, in steps such that at each the actor can be re-drawn (by cairo) so that the image remains high-res but still scales as expected, without re-sizing the actor.

Think of something like Inkscape and how you can zoom into the vectors; how the vectors remain clean at any magnification. Put a path (bunch of cairo line_to commands, say) onto an CairoTexture actor and then allow the same trick to happen.

More detail

I am aiming at a small SVG editor which uses groups of actors. Each actor is devoted to one path. I 'zoom' by using SomeGroup.set_depth(z) and then make z bigger/smaller. All fine so far. However, the closer the actor(s) get to the camera, the more the texture is stretched to fit their new apparent size.

I can't seem to find a way to get Clutter to do both:

  1. Leave the actor's actual size static (i.e. what it started as.)
  2. Swap-out its underlying surface for larger ones (on zooming in) that I can then re-draw the path onto (and use a cairo matrix to perform the scaling of the context.)

If I use set_size or set_surface_size, the actor gets larger which is not intended. I only want it's surface (underlying data) to get larger.

(I'm not sure of the terminology for this, mipmapping perhaps? )

Put another way: a polygon is getting larger, increase the size of its texture array so that it can map onto the larger polygon.

I have even tried an end-run around clutter by keeping a second surface (using pycairo) that I re-create to the apparent size of the actor (get_transformed_size) and then I use clutter's set_from_rgb_data and point it at my second surface, forcing a re-size of the surface but not of the actor's dimensions.

The problem with this is that a)clutter ignores the new size and only draws into the old width/height and b)the RGBA vs ARGB32 thing kind of causes a colour meltdown.

I'm open to any alternative ideas, I hope I'm standing in the woods missing all the trees!

\d

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

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

发布评论

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

评论(1

私藏温柔 2024-09-15 07:46:40

好吧,尽管我进行了所有测试和修改,但它一直就在我眼皮子底下。

感谢 Neil 在杂乱项目列表中的贡献,以下是独家新闻:

CT = SomeCairoTextureActor()

# record the old height, once:
old_width, old_height = CT.get_size()

Start a loop:
# Do stuff to the depth of CT (or it's parent)
...

# Get the apparent width and height (absolute size in pixels)
appr_w,appr_h = CT.get_transformed_size()

# Make the new surface to the new size
CT.set_surface_size( appr_w, appr_h )

# Crunch the actor back down to old size 
# but leave the texture surface something other!
CT.set_size(old_width, old_height)

loop back again

表面尺寸和尺寸
演员不必是同一个人。这
表面尺寸只是默认的
演员的首选尺寸。你可以
只需覆盖首选尺寸
设置演员的尺寸。如果
演员的尺寸不同
表面尺寸然后纹理将
被压扁以适应演员的尺寸
(我认为这就是你想要的)。

很高兴把这个小谜团搁置一旁。谢谢杂乱清单!

\d

Well, despite all my tests and hacks, it was right under my nose all along.

Thanks to Neil on the clutter-project list, here's the scoop:

CT = SomeCairoTextureActor()

# record the old height, once:
old_width, old_height = CT.get_size()

Start a loop:
# Do stuff to the depth of CT (or it's parent)
...

# Get the apparent width and height (absolute size in pixels)
appr_w,appr_h = CT.get_transformed_size()

# Make the new surface to the new size
CT.set_surface_size( appr_w, appr_h )

# Crunch the actor back down to old size 
# but leave the texture surface something other!
CT.set_size(old_width, old_height)

loop back again

The surface size and the size of the
actor don't have to be the same. The
surface size is just by default the
preferred size of the actor. You can
override the preferred size by just
setting the size on the actor. If the
size of the actor is different from
the surface size then the texture will
be squished to fit in the actor size
(which I think is what you want).

Nice to put this little mystery to bed. Thanks clutter list!

\d

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