Groups | Search | Server Info | Login | Register
Groups > comp.graphics.misc > #547
| From | Blue-Maned_Hawk <bluemanedhawk@gmail.com> |
|---|---|
| Newsgroups | comp.graphics.misc |
| Subject | Re: Running into problems while trying to scale Cairo surface to take up maximum space at specific aspect ratio |
| Date | 2023-06-11 20:54 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <u65qbu$2rlio$1@bluemanedhawk.eternal-september.org> (permalink) |
| References | <u65kfe$2r139$2@bluemanedhawk.eternal-september.org> <87352xy24e.fsf@bsb.me.uk> |
On 6/11/23 20:07, Ben Bacarisse wrote:
> Blue-Maned_Hawk <bluemanedhawk@gmail.com> writes:
>
> <snip/>
>
>> XResizeWindow(display, window, fmax(width,
>> e.xconfigure.width), fmax(width, e.xconfigure.height));
>
> Surely you wanted fmax(height, e.xconfigure.height) here?
>
Oops, yes. That was an accident.
>> cairo_xlib_surface_set_size(cairo_get_target(root_instance), fmax(width,
>> e.xconfigure.width), fmax(height, e.xconfigure.height));
>
> This case looks odd. What's the intent? Do you want stop the user
> making the window narrower than width or shorted than height?
Yes, i do. I didn't know of any other way to do this.
> If that's
> what you want you should probably limit e.xconfigure.{width,height}, set
> the X window size and then carry on as before because you still need to
> set the offset and scale and offset the source in this case as well.
>
How would i do that?
>> } else {
>>
>> cairo_xlib_surface_set_size(cairo_get_target(root_instance),
>> e.xconfigure.width, e.xconfigure.height);
>> if (e.xconfigure.width >= aspect_ratio *
>> e.xconfigure.height) {
>> cairo_translate(root_instance, (e.xconfigure.width
>> - e.xconfigure.height * aspect_ratio) / 2, 0);
>> cairo_scale(root_instance, (e.xconfigure.height *
>> aspect_ratio) / width, e.xconfigure.height /
>> height);
>
> I'm pretty sure you did not intend to divide two integers here. Both
> e.xconfigure.height and height have integer type.
>
> But there's is a bigger issue. To maintain the aspect ration, the x and y
> scaling should be the same. Once you have decided whether it's the
> window width or the height that will determine the scaling, you should
> calculate the scale factor and use that in both arguments.
>
…oh! You're right! It seems like replacing the cairo_scale() calls
with cairo_scale(root_instance, (double)e.xconfigure.height /
(double)height, (double)e.xconfigure.height / (double)height); and the
corresponding call for the width case has worked! Thank you so much!
>> cairo_push_group(root_instance);
>> cairo_set_source_rgb(root_instance, 0, 0, 0);
>> cairo_paint(root_instance);
>> cairo_set_source_surface(root_instance, surface, 0, 0);
>> cairo_paint(root_instance);
>> cairo_pop_group_to_source(root_instance);
>> cairo_paint(root_instance);
>> cairo_surface_flush(cairo_get_target(root_instance));
>
> Do you realise that this is in the outer for (;;) loop? That's a lot of
> busy work!
>
In the actual application, the screen will be getting updated pretty
much every frame, and the loop will be limited to only run once per frame.
--
⚗︎ | /blu.mɛin.dʰak/ | shortens to "Hawk" | he/him/his/himself/Mr.
bluemanedhawk.github.io
Bitches stole my whole ass ␔🭖᷿᪳𝼗᷍⏧𒒫𐻾ࣛ↉�⃣ quoted-printable, can't
have shit in Thunderbird 😩
Back to comp.graphics.misc | Previous | Next — Previous in thread | Next in thread | Find similar
Running into problems while trying to scale Cairo surface to take up maximum space at specific aspect ratio Blue-Maned_Hawk <bluemanedhawk@gmail.com> - 2023-06-11 19:13 -0400
Re: Running into problems while trying to scale Cairo surface to take up maximum space at specific aspect ratio Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-06-12 01:07 +0100
Re: Running into problems while trying to scale Cairo surface to take up maximum space at specific aspect ratio Blue-Maned_Hawk <bluemanedhawk@gmail.com> - 2023-06-11 20:54 -0400
Re: Running into problems while trying to scale Cairo surface to take up maximum space at specific aspect ratio Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-06-12 12:24 +0100
Re: Running into problems while trying to scale Cairo surface to take up maximum space at specific aspect ratio Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-06-12 14:48 +0100
Re: Running into problems while trying to scale Cairo surface to take up maximum space at specific aspect ratio Blue-Maned_Hawk <bluemanedhawk@gmail.com> - 2023-06-12 14:23 -0400
csiph-web