1. pygame
  2. pygame
  3. pygame

Commits

marcus  committed def6f4e

Added Visual C++ building support.
Added MinGW building instructions.
Added pygame2.sdlext.font module that adds a BitmapFont class for
handling bitmap-based font graphics.
Added pygame2.DLLPATH for Win32 DLL handling.
Added py2exe example setup file under examples/
keyboard.py example uses the BitmapFont class now.
Fixed severa compiler warnings.
Fixed a bug in transform.h that prevented pygame2.sdlext.transform from
building, if M_PI is undefined.
Fixed pygame2.sdlext.scrap linking.
Removed mail adresses from header comments.

  • Participants
  • Parent commits 1669be9
  • Branches pgreloaded

Comments (0)

Files changed (32)

File README.txt

View file
  • Ignore whitespace
 
 1.3 Notes for Windows users
 ---------------------------
-Bulding Pygame2 from its source code is only supported in combination with the
-MinGW compiler suite at the moment.
+Bulding Pygame2 from its source code is supported in combination with the
+MinGW compiler suite or Microsoft Visual C++.
 
-TODO
+Please take a look at the doc/BuildMingGW.txt and doc/BuildVC.txt documents for
+more details about how to configure and install Pygame2 on your Windows
+platform.
 
 1.4 Notes for Mac OS users
 --------------------------

File TODO.txt

View file
  • Ignore whitespace
 * (re)add tests
 * add examples
 * reorganise and add camera module
-* add proper config_win support to make use of VC++
-* add a Point class to make position arguments such as in Surface.blit
-  easier to use
 
 Things to FIX:
 ==============

File config/config_modules.py

View file
  • Ignore whitespace
         sdlcflags = sdlconfig.get_cflags ()
         sdllflags = sdlconfig.get_lflags ()
     else:
-        # TODO: Try to find all necessary things manually.
-        pass
+        d = find_incdir (buildsystem, "SDL.h")
+        if d != None:
+            sdlincdirs = [ d, sdlincpath ]
+            sdllibs = [ "SDL" ]
+            if buildsystem in ("win", "msys"):
+                sdllibs.append ("SDLmain")    
+                sdllibdirs = [ find_libdir (buildsystem, "SDL") ]
+            else:
+                sdllibdirs = [ find_libdir (buildsystem, "libSDL") ]
+            
+            sdlcflags = []
+            sdllflags = []
 
     if cfg.WITH_PNG and not haspng:
         d = find_incdir (buildsystem, "png.h")

File config/config_msys.py

View file
  • Ignore whitespace
 
 def get_sys_libs (module):
     # Gets a list of system libraries to link the module against.
-    if module == "sdl.scrap":
-        return [ "-luser32", "-lgdi32" ]
+    if module == "sdlext.scrap":
+        return [ "user32", "gdi32" ]
 
 def get_install_libs (cfg):
     # Gets the libraries to install for the target platform.

File config/config_unix.py

View file
  • Ignore whitespace
 
 def get_sys_libs (module):
     # Gets a list of system libraries to link the module against.
-    if module == "sdl.scrap":
-        return [ "-lX11" ]
+    if module == "sdlext.scrap":
+        return [ "X11" ]
 
 def get_install_libs (cfg):
     # Gets the libraries to install for the target platform.

File config/config_win.py

View file
  • Ignore whitespace
 import os, glob
 from config import sdlconfig, pkgconfig, helpers, dll
 
+_searchdirs = [ "prebuilt", "..", "..\\.." ]
+_incdirs = [ "", "include" ]
+_libdirs = [ "", "VisualC\\SDL\\Release", "VisualC\\Release", "Release", "lib"]
+
 def _hunt_libs (name, dirs):
     # Used by get_install_libs(). It resolves the dependency libraries
     # and returns them as dict.
                     libs[filename] = 1
     return libs
 
+
 def find_incdir (name):
     # Gets the include directory for the specified header file.
-    # TODO
-    return None
+    for d in _searchdirs:
+        for g in _incdirs:
+            p = os.path.join (d, g)
+            f = os.path.join (p, name)
+            if os.path.isfile (f):
+                return p
 
 def find_libdir (name):
     # Gets the library directory for the specified library file.
-    # TODO
-    return None
+    for d in _searchdirs:
+        for g in _libdirs:
+            p = os.path.join (d, g)
+            f = os.path.join (p, name)
+            if filter (os.path.isfile, glob.glob (f + '*')):
+                return p
 
 def sdl_get_version ():
     # Gets the SDL version.
-    # TODO
-    return None
-
+    # TODO: Is there some way to detect the correct version?
+    return "Unknown"
 
 def get_sys_libs (module):
     # Gets a list of system libraries to link the module against.
-    if module == "sdl.scrap":
-        return [ "-luser32", "-lgdi32" ]
+    if module == "sdlext.scrap":
+        return [ "user32", "gdi32" ]
 
 def get_install_libs (cfg):
     # Gets the libraries to install for the target platform.
-    # TODO
-    return []
+    libraries = {}
+    values = {}
+    dirs = []
+    
+    for d in _searchdirs:
+        for g in _libdirs:
+            dirs.append (os.path.join (d, g))
+    
+    if cfg.WITH_SDL:
+        libraries.update (_hunt_libs ("SDL", dirs))
+    if cfg.WITH_SDL_MIXER:
+        libraries.update (_hunt_libs ("SDL_mixer", dirs))
+    if cfg.WITH_SDL_IMAGE:
+        libraries.update (_hunt_libs ("SDL_image", dirs))
+    if cfg.WITH_SDL_TTF:
+        libraries.update (_hunt_libs ("SDL_ttf", dirs))
+    if cfg.WITH_SDL_GFX:
+        libraries.update (_hunt_libs ("SDL_gfx", dirs))
+    if cfg.WITH_PNG:
+        libraries.update (_hunt_libs ("png", dirs))
+    if cfg.WITH_JPEG:
+        libraries.update (_hunt_libs ("jpeg", dirs))
+    return libraries.keys ()

File doc/BuildMinGW.txt

View file
  • Ignore whitespace
+Building Pygame2 using MinGW
+----------------------------
+Using MinGW on Win32 platforms is probably the most comfortable way to build
+and install Pygame2, thanks to a handy script, that will do most of the work
+for you.
+
+NOTE: At http://pygame.org/wiki/MingW you can find more information and details
+      about the build and installation process.
+
+Setting up MSYS and MinGW
+-------------------------
+First of all, you have to make sure, you have an up to date and working MinGW
+and MSYS installation running. If you have not, install both of them first.
+Visit http://mingw.org/ and follow their instructions to install and configure
+anything.
+The following setup has been tested to work well on several Win32
+installations:
+
+* MinGW 5.1.4 installer (or newer)
+  http://sourceforge.net/project/showfiles.php?group_id=2435&package_id=240780
+
+  On installing, make sure you install the C compiler, C++ compiler and win32api
+  packages. This is usually done by checking the options "MinGW base" and
+  "g++ Compiler".
+
+* Msys 1.0.10 installer (or newer)
+  http://sourceforge.net/project/showfiles.php?group_id=2435&package_id=24963
+
+  Simply follow the installation instructions. In the post install step, make
+  sure you set up your MinGW/MSYS environment properly.
+
+* Msys DTK 1.0.1 installer (or newer)
+  http://sourceforge.net/project/showfiles.php?group_id=2435&package_id=67879
+
+  Simply follow the installation instructions.
+
+If anything went right, MSYS and MinGW should be set up correctly now. Now it's
+time to get the dependencies.
+
+Building the dependencies
+-------------------------
+NOTE: The following list of dependencies might not be the most actual one.
+      Please check the README.txt file in the top source directory for the
+      most actual dependency list!
+
+Make sure, you have at least one of the following Python versions installed:
+* Python 2.4, 2.5, 2.6, 3.0 (http://www.python.org)
+
+To build anything, you will have to download the following additional source
+packages:
+
+* SDL >= 1.2.10              (http://www.libsdl.org)
+* SDL_mixer >= 1.2.8         (http://www.libsdl.org/projects/SDL_mixer/)
+* SDL_ttf >= 2.0.9           (http://www.libsdl.org/projects/SDL_ttf/)
+* SDL_image >= 1.2.6         (http://www.libsdl.org/projects/SDL_image/)
+* SDL_gfx >= 2.0.17          (http://www.ferzkopp.net/Software/SDL_gfx-2.0/)
+* libpng >= 1.2.24           (http://www.libpng.org)
+* libjpeg >= 6b              (http://www.ijg.org/)
+* zlib >= 1.2.3              (http://www.zlib.net)
+* tiff >= 3.8.2              (http://libtiff.org)
+* libvorbis >= 1.2.0  	     (http://www.vorbis.com)
+* libogg >= 1.1.3            (http://www.vorbis.com)
+* freetype >= 2.3.5          (http://www.freetype.org)
+* FLAC >= 1.2.1              (http://flac.sourceforge.net)
+
+Once you downloaded all source packages, unpack them and put them all into a
+common directory, where the msys_build_deps.py script can find them.
+The script will search the directory where it resides, the parent directory of
+it and a directory named 'deps' for the unpacked sources.
+NOTE: At this point, we strongly recommend a directory named 'deps' that is
+      created under the Pygame2 source directory.
+
+Once anything's unpacked, move the Pygame2 source directory to your MSYS home
+directory (in a default installation this would be C:\msys\1.0\home\%USERNAME%).
+Start the Msys shell and change to the Pygame2 source directory:
+
+    cd pgreloaded
+
+Now start the msys_build_deps.py script:
+
+    python msys_build_deps.py --all
+
+This will start to build all necessary dependencies and takes some time to
+finish. Now is a good time to get yourself another cup of coffee and read
+the newspaper.
+
+Building Pygame2
+----------------
+Now that all dependencies are built and installed, you can proceed to build
+and install Pygame2 itself. Simply type:
+
+    python setup.py build --compiler=mingw32 install
+
+This will build and install Pygame2 in one step.

File doc/BuildVC.txt

View file
  • Ignore whitespace
+Building Pygame2 using Microsoft Visual C++
+-------------------------------------------
+

File doc/create_cref.py

View file
  • Ignore whitespace
     lines = text.split ("\n")
     for l in lines:
         newtext += l.strip () + "\\n"
-    return newtext.strip("\\n")
+    newtext = newtext.strip ("\\n")
+    if len (newtext) > 2040:
+        # Split once after 2040 characters to avoid
+        # problems with the Visual C++ 2048 character limit
+        newtext = newtext[:2040] + "\"\"" + newtext[2040:]
+    return newtext
 
 def create_cref (dom, buf):
     module = dom.getElementsByTagName ("module")[0]

File examples/keyboard.py

View file
  • Ignore whitespace
     import pygame2.sdl.mouse as mouse
     import pygame2.sdl.image as image
     import pygame2.sdl.wm as wm
+    from pygame2.sdlext.font import BitmapFont
 except ImportError:
     print ("No pygame2.sdl support")
     sys.exit ()
 white = pygame2.Color (255, 255, 255)
 black = pygame2.Color (0, 0, 0)
 
-def create_mapping ():
-    fontmap = [ u"0123456789",
-                u"ABCDEFGHIJ",
-                u"KLMNOPQRST",
-                u"UVWXYZ \xc4\xd6\xdc",
-                u"abcdefghij",
-                u"klmnopqrst",
-                u"uvwxyz \xe4\xf6\xfc",
-                u",;.:!?-+()" ]
-    fontimgmap = {}
-    x, y = 0, 0
-    for line in fontmap:
-        x = 0
-        for c in line:
-            fontimgmap[c] = pygame2.Rect (x, y, 32, 32)
-            x += 32
-        y += 33
-    print fontimgmap
-    return fontimgmap
+fontmap = [ u"0123456789",
+            u"ABCDEFGHIJ",
+            u"KLMNOPQRST",
+            u"UVWXYZ \xc4\xd6\xdc",
+            u"abcdefghij",
+            u"klmnopqrst",
+            u"uvwxyz \xe4\xf6\xfc",
+            u",;.:!?-+()" ]
 
 def run ():
     
     video.init ()
-    
-    fontimgmap = create_mapping ()
-    font_surface = image.load_bmp ("font.bmp")
+
+    bmpfont = BitmapFont (image.load_bmp ("font.bmp"), (32, 32), fontmap)
     
     screen = video.set_mode (640, 480)
     screen.fill (white)
     
-    center = (320 - font_surface.w / 2, 10)
-    screen.blit (font_surface, center)
+    center = (320 - bmpfont.surface.w / 2, 10)
+    screen.blit (bmpfont.surface, center)
     screen.flip ()
 
     wm.set_caption ("Keyboard demo")
             if ev.type == sdlconst.KEYDOWN:
                 if ev.key == sdlconst.K_ESCAPE:
                     sys.exit ()
-                elif fontimgmap.has_key (ev.unicode):
+                elif bmpfont.contains (ev.unicode):
                     screen.fill (white)
                     screen.fill (black, area)
-                    screen.blit (font_surface, center)
-                    screen.blit (font_surface, pos, fontimgmap[ev.unicode])
+                    screen.blit (bmpfont.surface, center)
+                    bmpfont.render_on (screen, ev.unicode, pos)
                     screen.flip ()
                     
 

File examples/py2exe_setup.py

View file
  • Ignore whitespace
+from distutils.core import setup
+import os, py2exe
+import pygame2
+
+# This will include the necessary pygame2 DLL dependencies, that are available.
+# By default they will be taken from the pygame2.dll module directory.
+#
+# If you have your own SDL.dll, SDL_mixer.dll, ... to ship, remove the line
+# below.
+os.environ['PATH'] += ";%s" % pygame2.DLLPATH
+
+
+setup (windows = ['hello_world.py'], 
+       options = { "py2exe": { "bundle_files" : 1 }},
+       data_files = [ ('.', ["logo.gif"]), ('.', ["logo.bmp"]) ]
+)

File lib/__init__.py

View file
  • Ignore whitespace
 path = os.path.dirname (os.path.abspath (__file__))
 os.environ['PATH'] += ";%s;%s" % (path,  os.path.join (path, "dll"))
 
+DLLPATH = os.path.join (path, "dll")
+
 from pygame2.base import *

File lib/colordict.py

View file
  • Ignore whitespace
 ##    License along with this library; if not, write to the Free
 ##    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 ##
-##    Pete Shinners
-##    pete@shinners.org
 
 THECOLORS = {
 'gray17' : (43, 43, 43, 255) ,

File lib/font.py

View file
  • Ignore whitespace
 ##    License along with this library; if not, write to the Free
 ##    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 ##
-##    Pete Shinners
-##    pete@shinners.org
 
 "font, used to find system fonts"
 

File lib/sdl/cursors.py

View file
  • Ignore whitespace
 ##    License along with this library; if not, write to the Free
 ##    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 ##
-##    Pete Shinners
-##    pete@shinners.org
 
 """
 Set of cursor resources available for use. These cursors come in a

File lib/sdlext/font.py

View file
  • Ignore whitespace
+##    pygame - Python Game Library
+##    Copyright (C) 2008 Marcus von Appen
+##
+##    This library is free software; you can redistribute it and/or
+##    modify it under the terms of the GNU Library General Public
+##    License as published by the Free Software Foundation; either
+##    version 2 of the License, or (at your option) any later version.
+##
+##    This library is distributed in the hope that it will be useful,
+##    but WITHOUT ANY WARRANTY; without even the implied warranty of
+##    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+##    Library General Public License for more details.
+##
+##    You should have received a copy of the GNU Library General Public
+##    License along with this library; if not, write to the Free
+##    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+##
+
+"""
+"""
+
+from pygame2 import Rect, FRect, Color
+from pygame2.sdl.video import Surface
+
+DEFAULTMAP = [ u"0123456789",
+               u"ABCDEFGHIJ",
+               u"KLMNOPQRST",
+               u"UVWXYZ    ",
+               u"abcdefghij",
+               u"klmnopqrst",
+               u"uvwxyz    ",
+               u",;.:!?+-()" ]
+
+class BitmapFont (object):
+    """BitmapFont (surface, size, mapping=None) -> BitmapFont
+    
+    Creates a BitmapFont suitable for bitmap to character mappings.
+    
+    The BitmapFont class  
+    """
+    def __init__ (self, surface, size, mapping=None):
+        if mapping is None:
+            self.mapping = list (DEFAULTMAP)
+        else:
+            self.mapping = mapping
+
+        self.offsets = {}
+        self.surface = surface
+        
+        if isinstance (size, Rect) or isinstance (size, FRect):
+            self.size = size.size
+        else:
+            self.size = size[0], size[1]
+
+        self._calculate_offsets ()
+    
+    def _calculate_offsets (self):
+        """
+        """
+        self.offsets = {}
+        offsets = self.offsets
+        x, y = 0, 0
+        w, h = self.size
+        for line in self.mapping:
+            x = 0
+            for c in line:
+                offsets[c] = Rect (x, y, w, h)
+                x += w
+            y += h
+
+    def render (self, text):
+        """
+        """
+        x, y = 0, 0
+        tw, th = 0, 0
+        w, h = self.size
+            
+        lines = text.split ('\n')
+        for line in lines:
+            tw = max (tw, sum ([w for c in line]))
+            th += h
+        
+        surface = Surface (tw, th)
+        blit = surface.blit
+        fontsf = self.surface
+        offsets = self.offsets
+        for line in lines:
+            for c in line:
+                blit (fontsf, (x, y), offsets[c])
+                x += w
+            y += h
+        return surface
+
+    def render_on (self, surface, text, offset=(0, 0)):
+        """
+        """
+        x, y = offset
+        w, h = self.size
+            
+        lines = text.split ('\n')
+        blit = surface.blit
+        fontsf = self.surface
+        offsets = self.offsets
+        for line in lines:
+            for c in line:
+                blit (fontsf, (x, y), offsets[c])
+                x += w
+            y += h
+        return Rect (offset, (x + w, y + h))
+    
+    def contains (self, c):
+        """
+        """
+        return c in self.offsets
+    
+    def can_render (self, text):
+        """
+        """
+        lines = text.split ('\n')
+        has_key = self.offsets.has_key
+        for line in lines:
+            for c in line:
+                if not has_key (c):
+                    return False
+        return True

File lib/sdlext/numpysurfarray.py

View file
  • Ignore whitespace
 ##    License along with this library; if not, write to the Free
 ##    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 ##
-##    Marcus von Appen
-##    mva@sysfault.org
 
 """pygame module for accessing surface pixel data using numpy
 

File lib/sdlext/surfarray.py

View file
  • Ignore whitespace
 ##    License along with this library; if not, write to the Free
 ##    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 ##
-##    Marcus von Appen
-##    mva@sysfault.org
 
 """pygame module for accessing surface pixel data using array interfaces
 

File lib/sdlmixer/numpysndarray.py

View file
  • Ignore whitespace
 ##    License along with this library; if not, write to the Free
 ##    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 ##
-##    Marcus von Appen
-##    mva@sysfault.org
 
 """pygame module for accessing sound sample data using numpy
 

File lib/sdlmixer/sndarray.py

View file
  • Ignore whitespace
 ##    License along with this library; if not, write to the Free
 ##    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 ##
-##    Marcus von Appen
-##    mva@sysfault.org
 
 """pygame module for accessing sound sample data
 

File lib/sprite/__init__.py

View file
  • Ignore whitespace
 ##    License along with this library; if not, write to the Free
 ##    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 ##
-##    Pete Shinners
-##    pete@shinners.org
 
 """pygame module with basic game object classes
 

File lib/sprite/collision.py

View file
  • Ignore whitespace
 ##    License along with this library; if not, write to the Free
 ##    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 ##
-##    Pete Shinners
-##    pete@shinners.org
 
 # some different collision detection functions that could be used.
 

File lib/sprite/groups.py

View file
  • Ignore whitespace
 ##    License along with this library; if not, write to the Free
 ##    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 ##
-##    Pete Shinners
-##    pete@shinners.org
 
 from pygame2.sprite.sprites import Sprite
 

File lib/sprite/layeredgroups.py

View file
  • Ignore whitespace
 ##    License along with this library; if not, write to the Free
 ##    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 ##
-##    Pete Shinners
-##    pete@shinners.org
 
 try:
     from pygame2.sdl.time import get_ticks

File lib/sprite/rendergroups.py

View file
  • Ignore whitespace
 ##    License along with this library; if not, write to the Free
 ##    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 ##
-##    Pete Shinners
-##    pete@shinners.org
 
 from pygame2.sprite.groups import Group
 

File lib/sprite/sprites.py

View file
  • Ignore whitespace
 ##    License along with this library; if not, write to the Free
 ##    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 ##
-##    Pete Shinners
-##    pete@shinners.org
 
 class Sprite(object):
     """simple base class for visible game objects

File src/base/basemod.c

View file
  • Ignore whitespace
     }
     else if (PySequence_Check (obj) && PySequence_Size (obj) >= 2)
     {
-        if (!IntFromSeqIndex (obj, 0, (int)w))
+        if (!IntFromSeqIndex (obj, 0, (int*)w))
             goto failed;
-        if (!IntFromSeqIndex (obj, 1, (int)h))
+        if (!IntFromSeqIndex (obj, 1, (int*)h))
             goto failed;
         return 1;
     }

File src/sdl/event.c

View file
  • Ignore whitespace
     case SDL_ACTIVEEVENT:
         if (!_get_item (dict, "gain", &val))
             return 0;
-        event->active.gain = PyInt_AsLong (val);
+        event->active.gain = (Uint8) PyInt_AsLong (val);
         if (event->active.gain == (Uint8)-1 && PyErr_Occurred ())
             return 0;
         if (!_get_item (dict, "state", &val))
             return 0;
-        event->active.state = PyInt_AsLong (val);
+        event->active.state = (Uint8) PyInt_AsLong (val);
         if (event->active.state == (Uint8)-1 && PyErr_Occurred ())
             return 0;
         break;
     case SDL_KEYUP:
         if (!_get_item (dict, "state", &val))
             return 0;
-        event->key.state = PyInt_AsLong (val);
+        event->key.state = (Uint8) PyInt_AsLong (val);
         if (event->key.state == (Uint8)-1 && PyErr_Occurred ())
             return 0;
         if (!_get_item (dict, "scancode", &val))
             return 0;
-        event->key.keysym.scancode = PyInt_AsLong (val);
+        event->key.keysym.scancode = (Uint8) PyInt_AsLong (val);
         if (event->key.keysym.scancode == (Uint8)-1 && PyErr_Occurred ())
             return 0;
         if (!_get_item (dict, "key", &val))
             return 0;
         if (!_get_item (dict, "unicode", &val))
             return 0;
-        event->key.keysym.unicode = PyInt_AsLong (val);
+        event->key.keysym.unicode = (Uint16) PyInt_AsLong (val);
         if (event->key.keysym.unicode == (Uint16)-1 && PyErr_Occurred ())
             return 0;
         break;
     case SDL_MOUSEMOTION:
         if (!_get_item (dict, "state", &val))
             return 0;
-        event->motion.state = PyInt_AsLong (val);
+        event->motion.state = (Uint8) PyInt_AsLong (val);
         if (event->motion.state == (Uint8)-1 && PyErr_Occurred ())
             return 0;
         if (!_get_item (dict, "x", &val))
             return 0;
-        event->motion.x = PyInt_AsLong (val);
+        event->motion.x = (Uint16) PyInt_AsLong (val);
         if (event->motion.x == (Uint16)-1 && PyErr_Occurred ())
             return 0;
         if (!_get_item (dict, "y", &val))
             return 0;
-        event->motion.y = PyInt_AsLong (val);
+        event->motion.y = (Uint16) PyInt_AsLong (val);
         if (event->motion.y == (Uint16)-1 && PyErr_Occurred ())
             return 0;
         if (!_get_item (dict, "xrel", &val))
             return 0;
-        event->motion.xrel = PyInt_AsLong (val);
+        event->motion.xrel = (Sint16) PyInt_AsLong (val);
         if (event->motion.xrel == -1 && PyErr_Occurred ())
             return 0;
         if (!_get_item (dict, "yrel", &val))
             return 0;
-        event->motion.yrel = PyInt_AsLong (val);
+        event->motion.yrel = (Sint16) PyInt_AsLong (val);
         if (event->motion.yrel == -1 && PyErr_Occurred ())
             return 0;
         if (!_get_item (dict, "buttons", &tuple))
     case SDL_MOUSEBUTTONUP:
         if (!_get_item (dict, "button", &val))
             return 0;
-        event->button.button = PyInt_AsLong (val);
+        event->button.button = (Uint8) PyInt_AsLong (val);
         if (event->button.button == (Uint8)-1 && PyErr_Occurred ())
             return 0;
         if (!_get_item (dict, "x", &val))
             return 0;
-        event->button.x = PyInt_AsLong (val);
+        event->button.x = (Uint16) PyInt_AsLong (val);
         if (event->button.x == (Uint16)-1 && PyErr_Occurred ())
             return 0;
         if (!_get_item (dict, "y", &val))
             return 0;
-        event->button.y = PyInt_AsLong (val);
+        event->button.y = (Uint16) PyInt_AsLong (val);
         if (event->button.y == (Uint16)-1 && PyErr_Occurred ())
             return 0;
         if (!_get_item (dict, "state", &val))
             return 0;
-        event->button.state = PyInt_AsLong (val);
+        event->button.state = (Uint8) PyInt_AsLong (val);
         if (event->button.state == (Uint8)-1 && PyErr_Occurred ())
             return 0;
         break;
     case SDL_JOYAXISMOTION:
         if (!_get_item (dict, "which", &val))
             return 0;
-        event->jaxis.which = PyInt_AsLong (val);
+        event->jaxis.which = (Uint8) PyInt_AsLong (val);
         if (event->jaxis.which == (Uint8)-1 && PyErr_Occurred ())
             return 0;
         if (!_get_item (dict, "axis", &val))
             return 0;
-        event->jaxis.axis = PyInt_AsLong (val);
+        event->jaxis.axis = (Uint8) PyInt_AsLong (val);
         if (event->jaxis.axis == (Uint8)-1 && PyErr_Occurred ())
             return 0;
         if (!_get_item (dict, "value", &val))
             return 0;
-        event->jaxis.value = PyInt_AsLong (val);
+        event->jaxis.value = (Sint16) PyInt_AsLong (val);
         if (event->jaxis.value == -1 && PyErr_Occurred ())
             return 0;
         break;
     case SDL_JOYBALLMOTION:
         if (!_get_item (dict, "which", &val))
             return 0;
-        event->jball.which = PyInt_AsLong (val);
+        event->jball.which = (Uint8) PyInt_AsLong (val);
         if (event->jball.which == (Uint8)-1 && PyErr_Occurred ())
             return 0;
         if (!_get_item (dict, "ball", &val))
             return 0;
-        event->jball.ball = PyInt_AsLong (val);
+        event->jball.ball = (Uint8) PyInt_AsLong (val);
         if (event->jball.ball == (Uint8)-1 && PyErr_Occurred ())
             return 0;
         if (!_get_item (dict, "xrel", &val))
             return 0;
-        event->jball.xrel = PyInt_AsLong (val);
+        event->jball.xrel = (Sint16) PyInt_AsLong (val);
         if (event->jball.xrel == -1 && PyErr_Occurred ())
             return 0;
         if (!_get_item (dict, "yrel", &val))
             return 0;
-        event->jball.yrel = PyInt_AsLong (val);
+        event->jball.yrel = (Sint16) PyInt_AsLong (val);
         if (event->jball.yrel == -1 && PyErr_Occurred ())
             return 0;
         break;
     case SDL_JOYHATMOTION:
         if (!_get_item (dict, "which", &val))
             return 0;
-        event->jhat.which = PyInt_AsLong (val);
+        event->jhat.which = (Uint8) PyInt_AsLong (val);
         if (event->jhat.which == (Uint8)-1 && PyErr_Occurred ())
             return 0;
         if (!_get_item (dict, "hat", &val))
             return 0;
-        event->jhat.hat = PyInt_AsLong (val);
+        event->jhat.hat = (Uint8) PyInt_AsLong (val);
         if (event->jhat.hat == (Uint8)-1 && PyErr_Occurred ())
             return 0;
         if (!_get_item (dict, "value", &val))
             return 0;
-        event->jhat.value = PyInt_AsLong (val);
+        event->jhat.value = (Uint8) PyInt_AsLong (val);
         if (event->jhat.value == (Uint8)-1 && PyErr_Occurred ())
             return 0;
         break;
     case SDL_JOYBUTTONUP:
         if (!_get_item (dict, "which", &val))
             return 0;
-        event->jbutton.which = PyInt_AsLong (val);
+        event->jbutton.which = (Uint8) PyInt_AsLong (val);
         if (event->jbutton.which == (Uint8)-1 && PyErr_Occurred ())
             return 0;
         if (!_get_item (dict, "button", &val))
             return 0;
-        event->jbutton.button = PyInt_AsLong (val);
+        event->jbutton.button = (Uint8) PyInt_AsLong (val);
         if (event->jbutton.button == (Uint8)-1 && PyErr_Occurred ())
             return 0;
         if (!_get_item (dict, "state", &val))
             return 0;
-        event->jbutton.state = PyInt_AsLong (val);
+        event->jbutton.state = (Uint8) PyInt_AsLong (val);
         if (event->jbutton.state == (Uint8)-1 && PyErr_Occurred ())
             return 0;
         break;

File src/sdl/surface.c

View file
  • Ignore whitespace
     Uint32 rmask, gmask, bmask, amask;
     SDL_Surface *surface;
     PyObject *masks = NULL;
+    
+    static char *keys[] = { "width", "height", "depth", "flags", "masks",
+                            NULL };
 
     ASSERT_VIDEO_INIT (-1);
 
-    static char *keys[] = { "width", "height", "depth", "flags", "masks",
-                            NULL };
     if (!PyArg_ParseTupleAndKeywords (args, kwds, "ii|ilO", keys, &width,
             &height, &depth, &flags, &masks))
     {

File src/sdl/videomod.c

View file
  • Ignore whitespace
         PyErr_Clear ();
         if (!PyArg_ParseTuple (args, "Oil:is_mode_ok", &size, &bpp, &flags))
             return NULL;
-        if (!SizeFromObject (size, &width, &height))
+        if (!SizeFromObject (size, (pgint32*)&width, (pgint32*)&height))
             return NULL;
     }
 
         PyErr_Clear ();
         if (!PyArg_ParseTuple (args, "0|il:set_mode", &size, &bpp, &flags))
             return NULL;
-        if (!SizeFromObject (size, &width, &height))
+        if (!SizeFromObject (size, (pgint32*)&width, (pgint32*)&height))
             return NULL;
     }
 

File src/sdlext/pixelarray_methods.c

View file
  • Ignore whitespace
 }
 
 static int
-_get_weights (PyObject *weights, float *wr, float *wg, float *wb)
+_get_weights (PyObject *weights, double *wr, double *wg, double *wb)
 {
     int success = 1;
-    float rgb[3] = { 0 };
+    double rgb[3] = { 0 };
     
     if (!weights)
     {
                 PyObject *num = NULL;
                 if ((num = PyNumber_Float (item)) != NULL)
                 {
-                    rgb[i] = (float) PyFloat_AsDouble (num);
+                    rgb[i] = PyFloat_AsDouble (num);
                     Py_DECREF (num);
                 }
                 else if ((num = PyNumber_Int (item)) != NULL)
                 {
-                    rgb[i] = (float) PyInt_AsLong (num);
+                    rgb[i] = (double) PyInt_AsLong (num);
                     if (rgb[i] == -1 && PyErr_Occurred ())
                         success = 0;
                     Py_DECREF (num);
                 }
                 else if ((num = PyNumber_Long (item)) != NULL)
                 {
-                    rgb[i] = (float) PyLong_AsLong (num);
+                    rgb[i] = (double) PyLong_AsLong (num);
                     if (PyErr_Occurred () &&
                         PyErr_ExceptionMatches (PyExc_OverflowError))
                         success = 0;
     
     if (success)
     {
-        float sum = 0;
+        double sum = 0;
         
         *wr = rgb[0];
         *wg = rgb[1];
     Uint32 rcolor;
     Uint8 r1, g1, b1, r2, g2, b2, a2;
     SDL_Surface *surface;
-    float distance = 0;
-    float wr, wg, wb;
+    double distance = 0;
+    double wr, wg, wb;
 
     Uint32 x = 0;
     Uint32 y = 0;
 
     static char *keys[] = { "color", "repcolor", "distance", "weights", NULL };
     
-    if (!PyArg_ParseTupleAndKeywords (args, kwds, "OO|fO", keys, &delcolor,
+    if (!PyArg_ParseTupleAndKeywords (args, kwds, "OO|dO", keys, &delcolor,
             &replcolor, &distance, &weights))
         return NULL;
 
     Uint32 white;
     Uint32 black;
     SDL_Surface *surface;
-    float distance = 0;
-    float wr, wg, wb;
+    double distance = 0;
+    double wr, wg, wb;
     Uint8 r1, g1, b1, r2, g2, b2, a2;
 
     Uint32 x = 0;
 
     static char *keys[] = { "color", "distance", "weights", NULL };
 
-    if (!PyArg_ParseTupleAndKeywords (args, kwds, "O|fO", keys, &excolor,
+    if (!PyArg_ParseTupleAndKeywords (args, kwds, "O|dO", keys, &excolor,
             &distance, &weights))
         return NULL;
 
     SDL_Surface *surface2 = NULL;
     Uint32 black;
     Uint32 white;
-    float distance = 0;
+    double distance = 0;
     Uint8 r1, g1, b1, a1, r2, g2, b2, a2;
-    float wr, wg, wb;
+    double wr, wg, wb;
 
     Uint32 x = 0;
     Uint32 y = 0;
 
     static char *keys[] = { "array", "distance", "weights", NULL };
 
-    if (!PyArg_ParseTupleAndKeywords (args, kwds, "O|fO", keys, &newarray,
+    if (!PyArg_ParseTupleAndKeywords (args, kwds, "O|dO", keys, &newarray,
             &distance, &weights))
         return NULL;
 

File src/sdlext/transform.h

View file
  • Ignore whitespace
 #include <SDL.h>
 
 #ifndef M_PI
-#define 3.14159265358979323846
+#define M_PI 3.1415926535897932384626433832795
 #endif
+
 #define DEG2RAD(x) ((x) * M_PI / 180.0f)
 
 #define LOCK_SURFACE(x,ret)                                             \