Okay I seem to have worked it out, here is the affected part of win32/
__init__:
@Win32EventHandler(WM_SIZING)
def _event_sizing(self, msg, wParam, lParam):
rect = cast(lParam, POINTER(RECT)).contents
width, height = self.get_size()
if self._aspect_ratio:
widthRatio, heightRatio = self._aspect_ratio
widthRatio = float(widthRatio)
if wParam in (WMSZ_LEFT, WMSZ_RIGHT, WMSZ_RIGHT +
WMSZ_BOTTOM):
height = int(heightRatio * width/widthRatio)
rect.bottom = rect.top + self._client_to_window_size
(width, height)[1]
elif wParam in (WMSZ_TOP, WMSZ_BOTTOM, WMSZ_RIGHT +
WMSZ_TOP):
width = int(widthRatio * height/heightRatio)
rect.right = rect.left + self._client_to_window_size
(width, height)[0]
elif wParam in (WMSZ_LEFT + WMSZ_TOP, WMSZ_LEFT +
WMSZ_BOTTOM):
width = int(widthRatio * height/heightRatio)
rect.left = rect.right - self._client_to_window_size
(width, height)[0]
lParam = pointer(rect)
self.switch_to()
self.dispatch_event('on_resize', width, height)
from pyglet import app
if app.event_loop is not None:
app.event_loop._idle_chance()
return 1
and I have added:
def set_aspect_ratio(self, widthRatio, heightRatio):
self._aspect_ratio = widthRatio, heightRatio
So window.set_aspect_ratio(4,3) gives smooth resizing. Now I just
need the same for xlib and carbon...
On Mar 19, 11:29 pm, tazg <[email protected]> wrote:
> I just found this:
>
> http://www.vcskicks.com/maintain-aspect-ratio.php
>
> It intercepts the resize message instead of just responding to the
> event, so there is no flickering... but I don't have the knowledge to
> incorporate this into pyglet. Would it be possible?
>
> On Mar 19, 10:44 pm, Alex Holkner <[email protected]> wrote:
>
> > On Fri, Mar 20, 2009 at 1:35 PM, tazg <[email protected]> wrote:
>
> > > I have a resizable window that I want to keep its aspect ratio, so I'm
> > > doing this:
>
> > > def on_resize(width, height):
> > > window.width = height * 4/3
>
> > > This works but it seems to still draw the window with the original
> > > size first, so you can see the border flickering between 2 positions
> > > which looks terrible. Any way to fix that?
>
> > Only X11 provides an API to restrict a window's aspect ratio (which
> > pyglet doesn't expose) -- I think it would be very difficult to get
> > this working well on Windows or OS X.
>
> > Alex.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pyglet-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/pyglet-users?hl=en
-~----------~----~----~----~------~----~------~--~---