[pygame] vbl

2007-10-14 Thread John Christie

Hi,
	Maybe I posed my previous question wrong.  I am looking to be able  
to track the VBL, vertical blank, vertical retrace, what have you.   
Does anyone have any experience with this in pygame or another package?


Re: [pygame] pygamefont problem

2007-10-14 Thread vwf
On Thu, Oct 11, 2007 at 08:36:07PM -0400, Ethan Glasser-Camp wrote:
> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
> 
> vwf wrote:
> > I think I use old code, but I don't know what is wrong. I include a
> > small programme that works, but displays incorrectly (it is a Q&D cut
> > from my real programme). Any suggestions, or a pointer to an example I
> > can use?
> 
> Hi,
> 
> I've only been playing with pygame for the last few years, but I've
> never even heard of pygamefont, and Google only has three results for
> "PyGameBitmapFont". My advice to you might be to look at other ways
> people using PyOpenGL have been doing fonts recently (I'm not at all
> knowledgeable in this subject).

Hi,

You might be right. This might be a PyOpenGL thing, but the name points
to pygame. I wrote my code years ago (5+), and can't remember where it
came from. I shall ask around in the PyOpenGL group, and maybe I simply
need a complete rewrite.

Thank you all



[pygame] Patch to compile with MSVC7.1, bug fix to set_blocked(), adds event range-checking

2007-10-14 Thread John Popplewell
Hi,

just did a check-out and had trouble compiling with the Microsoft Visual
C++ Toolkit 2003 compiler (version 7.1).

Mainly variables not declared at the top of a block, and a couple of
casts in 'transform.c'.

Also found a minor bug in pygame.event.set_blocked() when type is None,
in 'event.c'.

Whilst I was in there (and looking at the SDL code) I noticed that there
is no range checking on the event values in Pygame or SDL. To prevent
inadvertent trampling of memory, I've added some range checking code
which raises a ValueError().

Patch against latest SVN attached.

Hope it's useful,

regards,
John.
PS the reformatted code looks much better :-)

Index: src/transform.c
===
--- src/transform.c (revision 1052)
+++ src/transform.c (working copy)
@@ -987,13 +987,13 @@
 }
 else
 {
+int xfrac = 0x1 - xcounter;
 /* write out a destination pixel */
 *dstpix++ = (Uint8) (((accumulate[0] + ((srcpix[0] * xcounter) 
>> 16)) * xrecip) >> 16);
 *dstpix++ = (Uint8) (((accumulate[1] + ((srcpix[1] * xcounter) 
>> 16)) * xrecip) >> 16);
 *dstpix++ = (Uint8) (((accumulate[2] + ((srcpix[2] * xcounter) 
>> 16)) * xrecip) >> 16);
 *dstpix++ = (Uint8) (((accumulate[3] + ((srcpix[3] * xcounter) 
>> 16)) * xrecip) >> 16);
 /* reload the accumulator with the remainder of this pixel */
-int xfrac = 0x1 - xcounter;
 accumulate[0] = (Uint16) ((*srcpix++ * xfrac) >> 16);
 accumulate[1] = (Uint16) ((*srcpix++ * xfrac) >> 16);
 accumulate[2] = (Uint16) ((*srcpix++ * xfrac) >> 16);
@@ -1180,15 +1180,15 @@
 int srcdiff = srcpitch - (width * 4);
 int dstdiff = dstpitch - (width * 4);
 int x, y;
+int yspace = 0x1 * srcheight / dstheight; /* must be > 1 */
+int yrecip = (int) ((long long) 0x1 / yspace);
+int ycounter = yspace;
 
 /* allocate and clear a memory area for storing the accumulator line */
 templine = (Uint16 *) malloc(dstpitch * 2);
 if (templine == NULL) return;
 memset(templine, 0, dstpitch * 2);
 
-int yspace = 0x1 * srcheight / dstheight; /* must be > 1 */
-int yrecip = (int) ((long long) 0x1 / yspace);
-int ycounter = yspace;
 for (y = 0; y < srcheight; y++)
 {
 Uint16 *accumulate = templine;
@@ -1205,6 +1205,7 @@
 }
 else
 {
+int yfrac = 0x1 - ycounter;
 /* write out a destination line */
 for (x = 0; x < width; x++)
 {
@@ -1217,7 +1218,6 @@
 /* reload the accumulator with the remainder of this line */
 accumulate = templine;
 srcpix -= 4 * width;
-int yfrac = 0x1 - ycounter;
 for (x = 0; x < width; x++)
 {
 *accumulate++ = (Uint16) ((*srcpix++ * yfrac) >> 16);
@@ -1241,15 +1241,15 @@
 int srcdiff = srcpitch - (width * 4);
 int dstdiff = dstpitch - (width * 4);
 int x, y;
+int yspace = 0x4000 * srcheight / dstheight; /* must be > 1 */
+int yrecip = (int) ((long long) 0x04000 / yspace);
+long long One64 = 0x4000400040004000ULL;
 
 /* allocate and clear a memory area for storing the accumulator line */
 templine = (Uint16 *) malloc(dstpitch * 2);
 if (templine == NULL) return;
 memset(templine, 0, dstpitch * 2);
 
-int yspace = 0x4000 * srcheight / dstheight; /* must be > 1 */
-int yrecip = (int) ((long long) 0x04000 / yspace);
-long long One64 = 0x4000400040004000ULL;
 #if defined(__GNUC__) && defined(__x86_64__)
 long long srcdiff64 = srcdiff;
 long long dstdiff64 = dstdiff;
@@ -1439,11 +1439,11 @@
 int dstdiff = dstpitch - (dstwidth * 4);
 int *xidx0, *xmult0, *xmult1;
 int x, y;
+int factorwidth = 4;
 
 /* Allocate memory for factors */
 xidx0 = malloc(dstwidth * 4);
 if (xidx0 == NULL) return;
-int factorwidth = 4;
 xmult0 = (int *) malloc(dstwidth * factorwidth);
 xmult1 = (int *) malloc(dstwidth * factorwidth);
 if (xmult0 == NULL || xmult1 == NULL)
@@ -1490,11 +1490,11 @@
 int dstdiff = dstpitch - (dstwidth * 4);
 int *xidx0, *xmult0, *xmult1;
 int x, y;
+int factorwidth = 8;
 
 /* Allocate memory for factors */
 xidx0 = malloc(dstwidth * 4);
 if (xidx0 == NULL) return;
-int factorwidth = 8;
 xmult0 = (int *) malloc(dstwidth * factorwidth);
 xmult1 = (int *) malloc(dstwidth * factorwidth);
 if (xmult0 == NULL || xmult1 == NULL)
@@ -1507,9 +1507,9 @@
 /* Create multiplier factors and starting indices and put them in arrays */
 for (x = 0; x < dstwidth; x++)
 {
-xidx0[x] = x * (srcwidth - 1) / dstwidth;
 int xm1 = 0x100 * ((x * (srcwidth - 1)) % dstwidth) / dstwidth;
 int xm0 = 0x100 - 

Re: [pygame] libpng problem on OS X (intel)

2007-10-14 Thread Nathan
On 10/14/07, René Dudfield <[EMAIL PROTECTED]> wrote:
> Looks like the libpng you have might be broken?

And now I've reinstalled libsdl_image, and that doesn't help either.  :-(


Re: [pygame] libpng problem on OS X (intel)

2007-10-14 Thread Nathan
On 10/14/07, René Dudfield <[EMAIL PROTECTED]> wrote:
> Looks like the libpng you have might be broken?

Yes, that was my first thought.  So I upgraded to the latest version
of libpng and reinstalled pygame as well.  Unfortunately, the error
stayed the same.

~ Nathan


Re: [pygame] libpng problem on OS X (intel)

2007-10-14 Thread René Dudfield
Looks like the libpng you have might be broken?


On 10/15/07, Nathan <[EMAIL PROTECTED]> wrote:
> I haven't actively done anything with my pygame project
> "nathancheckers" since my daughter was born over a year ago.  I've got
> a MacBook Pro (core 2 duo, 2GB RAM) and I use MacPorts to install
> pygame and stuff like that.  I checked when I fiirst got it, and
> nathancheckers seemed to run fine at the time.  Now it fails with the
> following error, which I can't figure out.
>
> $ ./nathancheckers.py
> Traceback (most recent call last):
>   File "./nathancheckers.py", line 26, in ?
> from nc_display import *
>   File "/Users/nathan/nathancheckers/tags/1.5/nc_display.py", line 82, in ?
> set_theme()
>   File "/Users/nathan/nathancheckers/tags/1.5/nc_display.py", line 33,
> in set_theme
> global g_board;g_board= l(j('themes',theme,'g_board.png'))
> pygame.error: Failed loading libpng12.dylib: dlopen(libpng12.dylib,
> 2): image not found
>
> I've manually checked that the image it wants still exists in the same
> location it always had.  I've upgraded MacPorts and everything in it
> (including libpng and pygame) to the latest versions.  The .dylib file
> exists:
>
> $ locate libpng12.dylib
> /opt/local/lib/libpng12.dylib
>
> Any ideas?  nathancheckers is open source.  You can download the full
> source and everything here (the "linux" download is the full source
> tarball):
>
> http://www.stocksfam.com/nathancheckers/
>
> Any ideas???
>


[pygame] libpng problem on OS X (intel)

2007-10-14 Thread Nathan
I haven't actively done anything with my pygame project
"nathancheckers" since my daughter was born over a year ago.  I've got
a MacBook Pro (core 2 duo, 2GB RAM) and I use MacPorts to install
pygame and stuff like that.  I checked when I fiirst got it, and
nathancheckers seemed to run fine at the time.  Now it fails with the
following error, which I can't figure out.

$ ./nathancheckers.py
Traceback (most recent call last):
  File "./nathancheckers.py", line 26, in ?
from nc_display import *
  File "/Users/nathan/nathancheckers/tags/1.5/nc_display.py", line 82, in ?
set_theme()
  File "/Users/nathan/nathancheckers/tags/1.5/nc_display.py", line 33,
in set_theme
global g_board;g_board= l(j('themes',theme,'g_board.png'))
pygame.error: Failed loading libpng12.dylib: dlopen(libpng12.dylib,
2): image not found

I've manually checked that the image it wants still exists in the same
location it always had.  I've upgraded MacPorts and everything in it
(including libpng and pygame) to the latest versions.  The .dylib file
exists:

$ locate libpng12.dylib
/opt/local/lib/libpng12.dylib

Any ideas?  nathancheckers is open source.  You can download the full
source and everything here (the "linux" download is the full source
tarball):

http://www.stocksfam.com/nathancheckers/

Any ideas???


Re: [pygame] Partially Transparent Color-Dynamic Rectangles

2007-10-14 Thread Ian Mallett
On 10/14/07, Luke Paireepinart <[EMAIL PROTECTED]> wrote:
>
> Ian Mallett wrote:
> > Yes, but then everything behind it is brighter when it shouldn't be...
> What do you mean by this?

When you have an opaque bar of a solid color ("pygame.draw.rect(surface,
(255,0,0), (rect), 1)") then it looks red.  If you put it over a black
background, the pixels look darker.  If I compensate by making all the
pixels there somewhat lighter, lighter colored objects, such as asteroids
will look wrong.  Anyway, after I looked at the somewhat darker rectangle
for a while, it began looking right.  It was just a change from the
(255,0,0) bar to something like (150,0,0), which is how it should be.

> The color you're using is a brighter color, so if you're alpha blending
> it then it'll make everything you're blending that's darker than it
> brighter.
> >   the solution is to use a more neutral background.
> Do you mean a brighter background?
>
Yes.

Ian


Windows installer for latest SVN version; was Re: [pygame] maximize broken..

2007-10-14 Thread Lenard Lindstrom

inhahe wrote:


maybe it does in a more current version of pygame. you mentioned a
more current version has width and height in pygame.display.Info().
mine doesn't. but mine is 1.7.1release, and that's the latest
available for download on the webpage, do you mean i'd have to get the
SVN and try to compile it for windows myself?

  


Here is a Windows installer for the latest SVN version of Pygame 
1.8.0rc3 for Python 2.5.1 .


http://www3.telus.net/len_l/pygame-1.8.0rc3.win32-py2.5.exe

The md5 sum is :

66a88022a288e53da5ce1d85f2031d5e *pygame-1.8.0rc3.win32-py2.5.exe

It has all the dependencies and is built around SDL 1.2.12 : Details can 
be found at the MinGw build section of the Pygame wiki. The client area 
does appear to line up with the window when maximized, though the bottom 
is hidden if the task bar set to auto-hide.


--
Lenard Lindstrom
<[EMAIL PROTECTED]>



Re: [pygame] Future of pygame?

2007-10-14 Thread Luke Paireepinart

Mark Wexler wrote:

Hello. I'm a big fan of pygame, in fact I've been using it in the past
three years in a class I teach in which students learn how to create
and program psychology experiments--so I'd like to thank the
developers for doing such a good job. However, my co-instructors and I
are a little bit worried about the future of the library, since there
hasn't been a new release in a couple of years, and we can't really
find any information on the developers' future plans. It's important
for us to teach our students something they'll continue to be able to
use. So could some of the people working on pygame give us some idea
of where pygame is going in the next couple of years?

Thanks a lot,
Mark Wexler

  

Mark -
As far as I know, the main issue is with SDL.
We're waiting for an official 1.3 release, because Pygame is based on 
SDL, so once 1.3 comes out, all

of its new features can be added into Pygame.
I believe pygame 1.8 is near completion, and some binaries of it have 
been posted to this list numerous times.

I think 1.8 is still based on SDL 1.2, however.
I'll let someone more knowledgeable than I on the issue elaborate.


Re: [pygame] Partially Transparent Color-Dynamic Rectangles

2007-10-14 Thread Luke Paireepinart

Ian Mallett wrote:



On 10/14/07, *Luke Paireepinart* <[EMAIL PROTECTED] 
> wrote:


Increase the RGB values before you fill the surface.  < RGB =
closer to
white = brighter.

Yes, but then everything behind it is brighter when it shouldn't be...

What do you mean by this?
The color you're using is a brighter color, so if you're alpha blending 
it then it'll make everything you're blending that's darker than it 
brighter.

  the solution is to use a more neutral background.

Do you mean a brighter background?


Re: [pygame] maximize broken..

2007-10-14 Thread John Popplewell
On Sun, Oct 14, 2007 at 07:03:49PM -0400, inhahe wrote:
> oh.. yes, it's doing the same thing when i hit the maximize button.
> i'm not sure it was doing that before. i do call set_mode with the
> value of event.size. here's my code
> 
> elif event.type == pygame.VIDEORESIZE:
>   print 1
>   print event
>   screen = pygame.display.set_mode(event.size, pygame.RESIZABLE)
>   screen.fill(background)
>   pygame.display.flip()
>   for control in controls:
> if control.visible: control.show()
Hi,

I'm not sure you should be doing so much in VIDEORESIZE, I wouldn't, but
I don't know if that's anything to do with your problem.

> if i take out pygame.RESIZABLE, it's the same problem except that half
> the title bar is above the monitor and therefore the top of the screen
> actually shows (and the bottom is still too high- the whole thing is
> just too high, whereas without pygame.RESIZABLE the title bar is in
> the right place and only the Surface is too high)
> 
> maximizing just doesn't work right..
> 
> maybe it does in a more current version of pygame. you mentioned a
> more current version has width and height in pygame.display.Info().
> mine doesn't. but mine is 1.7.1release, and that's the latest
> available for download on the webpage, do you mean i'd have to get the
> SVN and try to compile it for windows myself?

Possibly, I'm using an (old-ish) SVN version myself.

Did you try the minimal example I posted before?
Does it have the same problem?

If it has the same problem, try updating SDL.dll, otherwise it sounds
like a problem with your app.

You might have some luck just replacing the version of 'SDL.dll' in the
pygame directory with the latest from the SDL website.

http://www.libsdl.org/release/SDL-1.2.12-win32.zip

Put it somewhere like C:\Python24\Lib\site-packages\pygame\
(depends on your Python version and where you installed it)

I'd rename the version you've already got first - I usually use
'original-SDL.dll' - just in case :-)

It *should* be a drop-in replacement, but I've not tried it.

It definitely fixes some window positioning bugs like the ones you are
describing,

cheers,
John.

> 
> 
> 
> On 10/14/07, John Popplewell <[EMAIL PROTECTED]> wrote:
> > On Sun, Oct 14, 2007 at 10:01:32AM -0400, inhahe wrote:
> > > hmm, I'm having a problem with this.  when i maximize, the title
> > > bar goes into the right place, etc., but the actual viewing space
> > > is a little too far up.  it stops, with no border, a few pixels
> > > above the taskbar, and starts a few pixels above the title bar but
> > > behind it so stuff is covered up by the title bar.  is there any
> > > solution to this?
> > >
> > Does it work correctly when you click the maximize button manually?
> > The call to SDL_Maximize() is equivalent.
> >
> > To make resizing work you, you have to handle the Pygame VIDEORESIZE
> > event and ultimately call pygame.display.set_mode() with the value
> > of event.size.
> >
> > I sometimes find it all a bit tricky to get right, what with
> > potentially having to recreate all your surfaces again,
> >
> > cheers, John.
> >
> > > On 10/14/07, John Popplewell <[EMAIL PROTECTED]> wrote:
> > > > On Sun, Oct 14, 2007 at 04:55:14AM +, Richard wrote:
> > > > > How do I maximize the pygame window or start it maximized? not
> > > > > fullscreen, just maximized.  by code, not by clicking on the
> > > > > maximize button.  i can't find a way to do this. if there's
> > > > > really not a way to do it, that's kind of disappointing.
> > > > Hi,
> > > >
> > > > you can't using a built-in Pygame function. There is iconify()
> > > > but no corresponding restore() or maximize(). It is a limitation
> > > > of the underlying SDL library, which is being fixed in SDL-1.3
> > > > (or SDL-2).
> > > >
> > > > For now, I use the ctypes module to call the platform-specific
> > > > functions:
> > > >
> > > > 
> > > >
> > > > regards, John.
> > > >
> > > >
> >


[pygame] Future of pygame?

2007-10-14 Thread Mark Wexler
Hello. I'm a big fan of pygame, in fact I've been using it in the past
three years in a class I teach in which students learn how to create
and program psychology experiments--so I'd like to thank the
developers for doing such a good job. However, my co-instructors and I
are a little bit worried about the future of the library, since there
hasn't been a new release in a couple of years, and we can't really
find any information on the developers' future plans. It's important
for us to teach our students something they'll continue to be able to
use. So could some of the people working on pygame give us some idea
of where pygame is going in the next couple of years?

Thanks a lot,
Mark Wexler


Re: [pygame] maximize broken..

2007-10-14 Thread inhahe
oh.. yes, it's doing the same thing when i hit the maximize button.
i'm not sure it was doing that before. i do call set_mode with the
value of event.size. here's my code

elif event.type == pygame.VIDEORESIZE:
  print 1
  print event
  screen = pygame.display.set_mode(event.size, pygame.RESIZABLE)
  screen.fill(background)
  pygame.display.flip()
  for control in controls:
if control.visible: control.show()

if i take out pygame.RESIZABLE, it's the same problem except that half
the title bar is above the monitor and therefore the top of the screen
actually shows (and the bottom is still too high- the whole thing is
just too high, whereas without pygame.RESIZABLE the title bar is in
the right place and only the Surface is too high)

maximizing just doesn't work right..

maybe it does in a more current version of pygame. you mentioned a
more current version has width and height in pygame.display.Info().
mine doesn't. but mine is 1.7.1release, and that's the latest
available for download on the webpage, do you mean i'd have to get the
SVN and try to compile it for windows myself?



On 10/14/07, John Popplewell <[EMAIL PROTECTED]> wrote:
> On Sun, Oct 14, 2007 at 10:01:32AM -0400, inhahe wrote:
> > hmm, I'm having a problem with this.  when i maximize, the title bar
> > goes into the right place, etc., but the actual viewing space is a
> > little too far up.  it stops, with no border, a few pixels above the
> > taskbar, and starts a few pixels above the title bar but behind it so
> > stuff is covered up by the title bar.  is there any solution to this?
> >
> Does it work correctly when you click the maximize button manually?
> The call to SDL_Maximize() is equivalent.
>
> To make resizing work you, you have to handle the Pygame VIDEORESIZE
> event and ultimately call pygame.display.set_mode() with the value of
> event.size.
>
> I sometimes find it all a bit tricky to get right, what with potentially
> having to recreate all your surfaces again,
>
> cheers,
> John.
>
> > On 10/14/07, John Popplewell <[EMAIL PROTECTED]> wrote:
> > > On Sun, Oct 14, 2007 at 04:55:14AM +, Richard wrote:
> > > > How do I maximize the pygame window or start it maximized? not 
> > > > fullscreen, just
> > > > maximized.  by code, not by clicking on the maximize button.  i can't 
> > > > find a way
> > > > to do this. if there's really not a way to do it, that's kind of 
> > > > disappointing.
> > > Hi,
> > >
> > > you can't using a built-in Pygame function. There is iconify() but no
> > > corresponding restore() or maximize(). It is a limitation of the
> > > underlying SDL library, which is being fixed in SDL-1.3 (or SDL-2).
> > >
> > > For now, I use the ctypes module to call the platform-specific
> > > functions:
> > >
> > > 
> > >
> > > regards,
> > > John.
> > >
> > >
>


Re: [pygame] Partially Transparent Color-Dynamic Rectangles

2007-10-14 Thread Ian Mallett
On 10/14/07, Luke Paireepinart <[EMAIL PROTECTED]> wrote:

> Increase the RGB values before you fill the surface.  < RGB = closer to
> white = brighter.

Yes, but then everything behind it is brighter when it shouldn't be...  the
solution is to use a more neutral background.  It looks better now that the
bars have solid borders.
Ian


Re: [pygame] Partially Transparent Color-Dynamic Rectangles

2007-10-14 Thread Luke Paireepinart

Ian Mallett wrote:

I also added the surface.set_alpha() function.

Since the bars are against a dark background, they look too dark.  Is 
there a way to increase the brightness of all the pixels or something, 
but still show the transparency?
Increase the RGB values before you fill the surface.  < RGB = closer to 
white = brighter.



Ian




Re: [pygame] how do I maximize the window?

2007-10-14 Thread John Popplewell
Hi,

here's a minimal example that works for me. Pressing 'm' toggles between
maximized and restored. It shows a dark red background with a single pixel wide
yellow border to show the new screen area.

##

import pygame

from pygame.locals  import *
from ctypes import windll

user32  = windll.user32
ShowWindow  = user32.ShowWindow
IsZoomed= user32.IsZoomed

SW_MAXIMIZE =   3
SW_RESTORE  =   9

def getSDLWindow():
return pygame.display.get_wm_info()['window']

def SDL_Maximize():
return ShowWindow(getSDLWindow(), SW_MAXIMIZE)

def SDL_Restore():
return ShowWindow(getSDLWindow(), SW_RESTORE)

def SDL_IsMaximized():
return IsZoomed(getSDLWindow())

def run():
video_flags = RESIZABLE
size = (640, 480)
screen = pygame.display.set_mode(size, video_flags)
while 1:
for event in pygame.event.get():
if event.type == QUIT:
return
elif event.type in (KEYUP, KEYDOWN):
if event.type == KEYDOWN:
if event.key == K_ESCAPE:
return
elif event.key == K_m:
if SDL_IsMaximized():
SDL_Restore()
else:
SDL_Maximize()
elif event.type == pygame.VIDEORESIZE:
size = event.size
screen = pygame.display.set_mode(size, video_flags)
elif event.type == pygame.VIDEOEXPOSE:
screen.fill((80, 0, 0))
screen.fill((255, 255, 0), pygame.Rect(0, 0, size[0]-1, 1))
screen.fill((255, 255, 0), pygame.Rect(0, size[1]-1, size[0], 
1))
screen.fill((255, 255, 0), pygame.Rect(0, 0, 1, size[1]-1))
screen.fill((255, 255, 0), pygame.Rect(size[0]-1, 0, 1, 
size[1]))
pygame.display.flip()
pygame.time.wait(1)

def main():
pygame.init()
run()
pygame.quit()

if __name__ == "__main__":
main()

##

If you are still having problems, what version of Pygame and SDL are you using?

Some window sizing anomalies were fixed (when they reworked the code) in the
latest version of SDL (1.2.12).

Hope that helps,

cheers,
John.



Re: [pygame] how do I maximize the window?

2007-10-14 Thread John Popplewell
On Sun, Oct 14, 2007 at 10:01:32AM -0400, inhahe wrote:
> hmm, I'm having a problem with this.  when i maximize, the title bar
> goes into the right place, etc., but the actual viewing space is a
> little too far up.  it stops, with no border, a few pixels above the
> taskbar, and starts a few pixels above the title bar but behind it so
> stuff is covered up by the title bar.  is there any solution to this?
> 
Does it work correctly when you click the maximize button manually?
The call to SDL_Maximize() is equivalent.

To make resizing work you, you have to handle the Pygame VIDEORESIZE
event and ultimately call pygame.display.set_mode() with the value of
event.size.

I sometimes find it all a bit tricky to get right, what with potentially
having to recreate all your surfaces again,

cheers,
John.

> On 10/14/07, John Popplewell <[EMAIL PROTECTED]> wrote:
> > On Sun, Oct 14, 2007 at 04:55:14AM +, Richard wrote:
> > > How do I maximize the pygame window or start it maximized? not 
> > > fullscreen, just
> > > maximized.  by code, not by clicking on the maximize button.  i can't 
> > > find a way
> > > to do this. if there's really not a way to do it, that's kind of 
> > > disappointing.
> > Hi,
> >
> > you can't using a built-in Pygame function. There is iconify() but no
> > corresponding restore() or maximize(). It is a limitation of the
> > underlying SDL library, which is being fixed in SDL-1.3 (or SDL-2).
> >
> > For now, I use the ctypes module to call the platform-specific
> > functions:
> >
> > 
> >
> > regards,
> > John.
> >
> >


Re: [pygame] problems with maximizing the window

2007-10-14 Thread John Popplewell
On Sun, Oct 14, 2007 at 10:10:39AM -0400, inhahe wrote:
> I just noticed another thing. i tried using pygame.NOFRAME on the off
> chance that that would help, figuring maybe it's miscalculating the
> size of the title bar and would be smart enough to know when there
> isn't one, but when NOFRAME is in effect, SDL_Maximize() does nothing.
Hi,

that's because if you use the NOFRAME flag, the window is created
without the WS_MAXIMIZEBOX window-style and consequently can't be
maximized.

You'd have to get the desktop size (or work-area) yourself and set the
window size.

If you are using a later version of Pygame you can use this:

info = pygame.display.Info()
self.desktop_size = (info.current_w, info.current_h)

to get the desktop size,

cheers,
John.



Re: [pygame] problems with maximizing the window

2007-10-14 Thread inhahe
I just noticed another thing. i tried using pygame.NOFRAME on the off
chance that that would help, figuring maybe it's miscalculating the
size of the title bar and would be smart enough to know when there
isn't one, but when NOFRAME is in effect, SDL_Maximize() does nothing.

On 10/14/07, inhahe <[EMAIL PROTECTED]> wrote:
> hmm, I'm having a problem with this.  when i maximize, the title bar
> goes into the right place, etc., but the actual viewing space is a
> little too far up.  it stops, with no border, a few pixels above the
> taskbar, and starts a few pixels above the title bar but behind it so
> stuff is covered up by the title bar.  is there any solution to this?


Re: [pygame] how do I maximize the window?

2007-10-14 Thread inhahe
hmm, I'm having a problem with this.  when i maximize, the title bar
goes into the right place, etc., but the actual viewing space is a
little too far up.  it stops, with no border, a few pixels above the
taskbar, and starts a few pixels above the title bar but behind it so
stuff is covered up by the title bar.  is there any solution to this?

On 10/14/07, John Popplewell <[EMAIL PROTECTED]> wrote:
> On Sun, Oct 14, 2007 at 04:55:14AM +, Richard wrote:
> > How do I maximize the pygame window or start it maximized? not fullscreen, 
> > just
> > maximized.  by code, not by clicking on the maximize button.  i can't find 
> > a way
> > to do this. if there's really not a way to do it, that's kind of 
> > disappointing.
> Hi,
>
> you can't using a built-in Pygame function. There is iconify() but no
> corresponding restore() or maximize(). It is a limitation of the
> underlying SDL library, which is being fixed in SDL-1.3 (or SDL-2).
>
> For now, I use the ctypes module to call the platform-specific
> functions:
>
> import sys
> import pygame
>
> if sys.platform == "win32":
> from ctypes import windll, Structure, c_long, c_ulong, sizeof, byref
>
> SW_HIDE =   0
> SW_SHOWNORMAL   =   1
> SW_NORMAL   =   1
> SW_SHOWMINIMIZED=   2
> SW_SHOWMAXIMIZED=   3
> SW_MAXIMIZE =   3
> SW_SHOWNOACTIVATE   =   4
> SW_SHOW =   5
> SW_MINIMIZE =   6
> SW_SHOWMINNOACTIVE  =   7
> SW_SHOWNA   =   8
> SW_RESTORE  =   9
> SW_SHOWDEFAULT  =   10
> SW_FORCEMINIMIZE=   11
> SW_MAX  =   11
>
> SWP_NOSIZE  =   0x0001
> SWP_NOMOVE  =   0x0002
> SWP_NOZORDER=   0x0004
> SWP_NOREDRAW=   0x0008
> SWP_NOACTIVATE  =   0x0010
> SWP_FRAMECHANGED=   0x0020
> SWP_SHOWWINDOW  =   0x0040
> SWP_HIDEWINDOW  =   0x0080
> SWP_NOCOPYBITS  =   0x0100
> SWP_NOOWNERZORDER   =   0x0200
> SWP_NOSENDCHANGING  =   0x0400
> SWP_DRAWFRAME   =   SWP_FRAMECHANGED
> SWP_NOREPOSITION=   SWP_NOOWNERZORDER
>
> HWND_TOP=   0
> HWND_BOTTOM =   1
> HWND_TOPMOST=  -1
> HWND_NOTOPMOST  =  -2
>
> user32  = windll.user32
> IsIconic= user32.IsIconic
> IsZoomed= user32.IsZoomed
> ShowWindow  = user32.ShowWindow
> GetWindowRect   = user32.GetWindowRect
> SetWindowPos= user32.SetWindowPos
> GetForegroundWindow = user32.GetForegroundWindow
> SetForegroundWindow = user32.SetForegroundWindow
>
> class RECT(Structure):
> _fields_ = [
> ('left',c_long),
> ('top', c_long),
> ('right',   c_long),
> ('bottom',  c_long),
> ]
> def width(self):  return self.right  - self.left
> def height(self): return self.bottom - self.top
>
>
> def getSDLWindow():
> return pygame.display.get_wm_info()['window']
>
> def SDL_IsIconic():
> return IsIconic(getSDLWindow())
>
> def SDL_IsMaximized():
> return IsZoomed(getSDLWindow())
>
> def SDL_Minimize():
> return ShowWindow(getSDLWindow(), SW_MINIMIZE)
>
> def SDL_Maximize():
> return ShowWindow(getSDLWindow(), SW_MAXIMIZE)
>
> def SDL_Restore():
> return ShowWindow(getSDLWindow(), SW_RESTORE)
>
> def SDL_Show(state):
> state = (SW_HIDE, SW_SHOW)[bool(state)]
> return ShowWindow(getSDLWindow(), state)
>
> def SDL_Activate():
> hWnd = getSDLWindow()
> if GetForegroundWindow() != hWnd:
>SetForegroundWindow(hWnd)
>
> def SDL_GetWindowPos():
> rc = RECT()
> GetWindowRect(getSDLWindow(), byref(rc))
> return rc.left, rc.top
>
> def SDL_SetWindowPos(x, y):
> return SetWindowPos(getSDLWindow(), 0, x, y, 0, 0, 
> SWP_NOZORDER|SWP_NOSIZE)
>
> def SDL_AlwaysOnTop(state):
> zorder = (HWND_NOTOPMOST, HWND_TOPMOST)[state]
> return SetWindowPos(getSDLWindow(), zorder, 0, 0, 0, 0, 
> SWP_NOMOVE|SWP_NOSIZE)
>
> else:
> def SDL_IsIconic():
> return 0
>
> def SDL_IsMaximized():
> return 0
>
> def SDL_Minimize():
> return 0
>
> def SDL_Maximize():
> return 0
>
> def SDL_Restore():
> return 0
>
> def SDL_Show(state):
> return 0
>
> def SDL_Activate():
> pass
>
> def SDL_GetWindowPos():
> return (-1, -1)
>
> def SDL_SetWindowPos(x, y):
> return 0
>
> def SDL_AlwaysOnTop(state):
> return 0
>
>
> I don't have any code for X, but I don't believe it's much more
> complicated.
>
> Equivalent functions could be added to Pygame with support for other
> Windowing systems,
>
> regards,
> John.
>
>


Re: [pygame] how do I maximize the window?

2007-10-14 Thread John Popplewell
On Sun, Oct 14, 2007 at 04:55:14AM +, Richard wrote:
> How do I maximize the pygame window or start it maximized? not fullscreen, 
> just
> maximized.  by code, not by clicking on the maximize button.  i can't find a 
> way
> to do this. if there's really not a way to do it, that's kind of 
> disappointing.
Hi,

you can't using a built-in Pygame function. There is iconify() but no
corresponding restore() or maximize(). It is a limitation of the
underlying SDL library, which is being fixed in SDL-1.3 (or SDL-2).

For now, I use the ctypes module to call the platform-specific
functions:

import sys
import pygame

if sys.platform == "win32":
from ctypes import windll, Structure, c_long, c_ulong, sizeof, byref

SW_HIDE =   0
SW_SHOWNORMAL   =   1
SW_NORMAL   =   1
SW_SHOWMINIMIZED=   2
SW_SHOWMAXIMIZED=   3
SW_MAXIMIZE =   3
SW_SHOWNOACTIVATE   =   4
SW_SHOW =   5
SW_MINIMIZE =   6
SW_SHOWMINNOACTIVE  =   7
SW_SHOWNA   =   8
SW_RESTORE  =   9
SW_SHOWDEFAULT  =   10
SW_FORCEMINIMIZE=   11
SW_MAX  =   11

SWP_NOSIZE  =   0x0001
SWP_NOMOVE  =   0x0002
SWP_NOZORDER=   0x0004
SWP_NOREDRAW=   0x0008
SWP_NOACTIVATE  =   0x0010
SWP_FRAMECHANGED=   0x0020
SWP_SHOWWINDOW  =   0x0040
SWP_HIDEWINDOW  =   0x0080
SWP_NOCOPYBITS  =   0x0100
SWP_NOOWNERZORDER   =   0x0200
SWP_NOSENDCHANGING  =   0x0400
SWP_DRAWFRAME   =   SWP_FRAMECHANGED
SWP_NOREPOSITION=   SWP_NOOWNERZORDER

HWND_TOP=   0
HWND_BOTTOM =   1
HWND_TOPMOST=  -1
HWND_NOTOPMOST  =  -2

user32  = windll.user32
IsIconic= user32.IsIconic
IsZoomed= user32.IsZoomed
ShowWindow  = user32.ShowWindow
GetWindowRect   = user32.GetWindowRect
SetWindowPos= user32.SetWindowPos
GetForegroundWindow = user32.GetForegroundWindow
SetForegroundWindow = user32.SetForegroundWindow

class RECT(Structure):
_fields_ = [
('left',c_long),
('top', c_long),
('right',   c_long),
('bottom',  c_long),
]
def width(self):  return self.right  - self.left
def height(self): return self.bottom - self.top


def getSDLWindow():
return pygame.display.get_wm_info()['window']

def SDL_IsIconic():
return IsIconic(getSDLWindow())

def SDL_IsMaximized():
return IsZoomed(getSDLWindow())

def SDL_Minimize():
return ShowWindow(getSDLWindow(), SW_MINIMIZE)

def SDL_Maximize():
return ShowWindow(getSDLWindow(), SW_MAXIMIZE)

def SDL_Restore():
return ShowWindow(getSDLWindow(), SW_RESTORE)

def SDL_Show(state):
state = (SW_HIDE, SW_SHOW)[bool(state)]
return ShowWindow(getSDLWindow(), state)

def SDL_Activate():
hWnd = getSDLWindow()
if GetForegroundWindow() != hWnd:
   SetForegroundWindow(hWnd)

def SDL_GetWindowPos():
rc = RECT()
GetWindowRect(getSDLWindow(), byref(rc))
return rc.left, rc.top

def SDL_SetWindowPos(x, y):
return SetWindowPos(getSDLWindow(), 0, x, y, 0, 0, 
SWP_NOZORDER|SWP_NOSIZE)

def SDL_AlwaysOnTop(state):
zorder = (HWND_NOTOPMOST, HWND_TOPMOST)[state]
return SetWindowPos(getSDLWindow(), zorder, 0, 0, 0, 0, 
SWP_NOMOVE|SWP_NOSIZE)

else:
def SDL_IsIconic():
return 0

def SDL_IsMaximized():
return 0

def SDL_Minimize():
return 0

def SDL_Maximize():
return 0

def SDL_Restore():
return 0

def SDL_Show(state):
return 0

def SDL_Activate():
pass

def SDL_GetWindowPos():
return (-1, -1)

def SDL_SetWindowPos(x, y):
return 0

def SDL_AlwaysOnTop(state):
return 0


I don't have any code for X, but I don't believe it's much more
complicated.

Equivalent functions could be added to Pygame with support for other
Windowing systems,

regards,
John.