Commits

aholkner  committed 5b83052

Cleaned up some TODO, FIXME and XXX markers.

  • Participants
  • Parent commits 64444a9
  • Branches ctypes-soc

Comments (0)

Files changed (9)

         - requires PyObjC
  - Added SDL.endian submodule
  - Pitch calculated correctly for returning SDL_Surface.pixels
+ - SDL_WM_SetCaption and SDL_WM_GetCaption accept and return Unicode strings.
+ - Removed SDL_opengl.h from SDL.constants
+ - Added SDL_CreateCursor.
 
 SDL-ctypes 0.04
 ---------------

File SDL/audio.py

 __version__ = '$Id: $'
 
 from ctypes import *
+import sys
 
 import SDL.array
 import SDL.constants
                 ('_callback', _SDL_AudioSpec_fn),
                 ('_userdata', c_void_p)]
 
-# TODO Fix AUDIO_U16SYS and AUDIO_S16SYS in constants.py
+if sys.byteorder == 'little':
+    AUDIO_U16SYS = SDL.constants.AUDIO_U16LSB
+    AUDIO_S16SYS = SDL.constants.AUDIO_S16LSB
+else:
+    AUDIO_U16SYS = SDL.constants.AUDIO_U16MSB
+    AUDIO_S16SYS = SDL.constants.AUDIO_S16MSB
 
 _SDL_AudioCVT_p = POINTER('SDL_AudioCVT')
 
     for full audio volume.  Note this does not change hardware volume.
     This is provided for convenience -- you can mix your own audio data.
 
-    :note: TODO It is not clear whether this function can handle 16 bit
-        audio data.
+    :note: SDL-ctypes doesn't know the current play format, so you must
+        always pass in byte buffers (SDL_array or sequence) to this function,
+        rather than of the native data type.
 
     :Parameters:
      - `dst`: `SDL_array`

File SDL/constants.py

 __docformat__ = 'restructuredtext'
 __version__ = '$Id: $'
 
+import sys
+
 # enum SDLKey {
 
 #  The keyboard syms have been cleverly chosen to map to ASCII 
 #Constants from SDL_mutex.h:
 SDL_MUTEX_TIMEDOUT = 0x00000001
 
-#Constants from SDL_ttf.h:
-SDL_TTF_MAJOR_VERSION = 0x00000002
-SDL_TTF_MINOR_VERSION = 0x00000000
-SDL_TTF_PATCHLEVEL = 0x00000007
-UNICODE_BOM_NATIVE = 0x0000feff
-UNICODE_BOM_SWAPPED = 0x0000fffe
-TTF_STYLE_NORMAL = 0x00000000
-TTF_STYLE_BOLD = 0x00000001
-TTF_STYLE_ITALIC = 0x00000002
-TTF_STYLE_UNDERLINE = 0x00000004
-
 #Constants from SDL_video.h:
 SDL_ALPHA_OPAQUE = 0x000000ff
 SDL_ALPHA_TRANSPARENT = 0x00000000
 SDL_APPINPUTFOCUS = 0x00000002
 SDL_APPACTIVE = 0x00000004
 
-#Constants from SDL_opengl.h:
-WIN32_LEAN_AND_MEAN = 0x00000001
-
 #Constants from SDL_joystick.h:
 SDL_HAT_CENTERED = 0x00000000
 SDL_HAT_UP = 0x00000001
 RW_SEEK_CUR = 0x00000001
 RW_SEEK_END = 0x00000002
 
-#Constants from SDL_sound.h:
-SOUND_VER_MAJOR = 0x00000001
-SOUND_VER_MINOR = 0x00000000
-SOUND_VER_PATCH = 0x00000001
-
-#Constants from SDL_mixer.h:
-SDL_MIXER_MAJOR_VERSION = 0x00000001
-SDL_MIXER_MINOR_VERSION = 0x00000002
-SDL_MIXER_PATCHLEVEL = 0x00000006
-MIX_CHANNELS = 0x00000008
-MIX_DEFAULT_FREQUENCY = 0x00005622
-MIX_DEFAULT_CHANNELS = 0x00000002
-MIX_MAX_VOLUME = 0x00000080
-
 #Constants from SDL_timer.h:
 SDL_TIMESLICE = 0x0000000a
 TIMER_RESOLUTION = 0x0000000a
 # From SDL_mixer.h (inserted manually)
 MIX_CHANNELS            = 8
 MIX_DEFAULT_FREQUENCY   = 22050
-MIX_DEFAULT_FORMAT      = AUDIO_S16LSB  # TODO endianness
-MID_DEFAULT_CHANNELS    = 2
 MIX_MAX_VOLUME          = 128
 MIX_CHANNEL_POST        = -2
 MIX_EFFECTSMAXSPEED     = 'MIX_EFFECTSMAXSPEED'
+MIX_DEFAULT_CHANNELS    = 2
 
-
+if sys.byteorder == 'little':
+    MIX_DEFAULT_FORMAT  = AUDIO_S16LSB 
+else:
+    MIX_DEFAULT_FORMAT  = AUDIO_S16MSB

File SDL/events.py

         return filter(e.contents.specialize())
     _SDL_SetEventFilter(_SDL_EventFilter(f))
 
-_SDL_GetEventFilter = SDL.dll.private_function('SDL_GetEventFilter',
-    arg_types=[],
-    return_type=_SDL_EventFilter)
-
-# XXX this doesn't need to be wrapped specially
-def SDL_GetEventFilter():
+SDL_GetEventFilter = SDL.dll.function('SDL_GetEventFilter',
     '''Return the current event filter.
 
     This can be used to "chain" filters.  If there is no event filter set,
     this function returns None.
 
     :rtype: function
-    '''
-    return _SDL_GetEventFilter()
+    ''',
+    args=[],
+    arg_types=[],
+    return_type=_SDL_EventFilter)
 
 SDL_EventState = SDL.dll.function('SDL_EventState',
     '''Ignore or enable the processing of certain events.
     :Parameters:
         `type` : int
             Type of event, e.g. `SDL_KEYDOWN`, `SDL_MOUSEMOTION`, etc.
-            (TODO: documented list of these?)
+            (see `SDL_Event`)
         `state` : int
             One of `SDL_IGNORE`, `SDL_ENABLE` or `SDL_QUERY`
 

File SDL/mouse.py

     arg_types=[c_ushort, c_ushort],
     return_type=None)
 
-# TODO: SDL_CreateCursor
+_SDL_CreateCursor = SDL.dll.private_function('SDL_CreateCursor',
+    arg_types=[POINTER(c_ubyte), POINTER(c_ubyte), c_int, c_int, c_int, c_int],
+    return_type=POINTER(SDL_Cursor),
+    dereference_return=True,
+    require_return=True)
+
+def SDL_CreateCursor(data, mask, w, h, hot_x, hot_y):
+    '''Create a cursor using the specified data and mask.
+
+    The cursor width must be a multiple of 8 bits.  Mask and cursor
+    data may be given as either SDL_array byte buffers or as a sequence
+    of bytes; in either case the data is in MSB order.
+
+    The cursor is created in black and white according to the following:
+
+    ==== ==== =========================================
+    data mask resulting pixel on screen
+    ==== ==== =========================================
+    0    1    White
+    1    1    Black
+    0    0    Transparent
+    1    0    Inverted color if possible, black if not.
+    ==== ==== =========================================
+
+    Cursors created with this function must be freed with `SDL_FreeCursor`.
+
+    :Parameters:
+     - `data`: `SDL_array`
+     - `mask`: `SDL_array`
+     - `w`: int
+     - `h`: int
+     - `hot_x`: int
+     - `hot_y`: int
+
+    :rtype: `SDL_Cursor`
+    '''
+    data = SDL.array.to_ctypes(data, len(data), c_ubyte)
+    mask = SDL.array.to_ctypes(mask, len(mask), c_ubyte)
+    return _SDL_CreateCursor(data, mask, w, h, hot_x, hot_y)
 
 SDL_SetCursor = SDL.dll.function('SDL_SetCursor',
     '''Set the currently active cursor to the specified one.
      - `font`: ``TTF_Font``
 
     :rtype: int
-    :return: TODO Undocumented.
+    :return: non-zero if monospaced, otherwise zero.
     ''',
     args=['font'],
     arg_types=[_TTF_Font],
     '''Check if the TTF engine is initialized.
 
     :rtype: int
-    :return: XXX Undocumented.
+    :return: non-zero if initialized, otherwise zero.
     ''',
     args=[],
     arg_types=[],

File SDL/video.py

      - `surface`: `SDL_Surface`
      - `rect`: `SDL_Rect` or None
 
-    :return: True if blitting will not be entirely clipped, otherwise
-             False. (TODO: convert int to bool)
+    :rtype: int
+    :return: non-zero if blitting will not be entirely clipped, otherwise
+             zero.
     ''',
     args=['surface', 'rect'],
     arg_types=[POINTER(SDL_Surface), POINTER(SDL_Rect)],
 # SDL_GL_UpdateRects, SDL_GL_Lock and SDL_GL_Unlock not implemented (marked
 # private in SDL_video.h)
 
-SDL_WM_SetCaption = SDL.dll.function('SDL_WM_SetCaption',
+_SDL_WM_SetCaption = SDL.dll.private_function('SDL_WM_SetCaption',
+    arg_types=[c_char_p, c_char_p],
+    return_type=None)
+
+def SDL_WM_SetCaption(title, icon):
     '''Set the title and icon text of the display window.
 
-    Strings are UTF-8 encoded (TODO: accept unicode strings) since 1.2.10.
+    Unicode strings are also accepted since 1.2.10.
 
     :Parameters:
      - `title`: string
      - `icon`: string
-    ''',
-    args=['title', 'icon'],
-    arg_types=[c_char_p, c_char_p],
-    return_type=None)
+    '''
+    _SDL_WM_SetCaption(title.encode('utf-8'), icon.encode('utf-8'))
+
 
 _SDL_WM_GetCaption = SDL.dll.private_function('SDL_WM_GetCaption',
     arg_types=[POINTER(c_char_p), POINTER(c_char_p)],
     '''Get the title and icon text of the display window.
 
     :rtype: (string, string)
-    :return: a tuple (title, icon) where each element is a UTF-8 encoded
-             string (TODO: return unicode strings).
+    :return: a tuple (title, icon) where each element is a Unicode string
     '''
     title, icon = c_char_p(), c_char_p()
     _SDL_WM_GetCaption(byref(title), byref(icon))
-    return title.value, icon.value
+    return title.value.decode('utf-8'), icon.value.decode('utf-8')
 
 _SDL_WM_SetIcon = SDL.dll.private_function('SDL_WM_SetIcon',
     arg_types=[POINTER(SDL_Surface), POINTER(c_ubyte)],

File support/make_constants.py

             else:
                 num = int(num)
             name = match.groups()[0]
-            if name[:3] != 'GL_':
-                defines.append('%s = 0x%08x\n' % (name, num))
+            defines.append('%s = 0x%08x\n' % (name, num))
         except ValueError:
             pass
     return defines 
     for file in os.listdir(include_dir):
         if file[-2:] == '.h':
             if file[:10] == 'SDL_config' or \
-               file in ('SDL_platform.h',):
+               file in ('SDL_platform.h','SDL_opengl.h'):
                 continue
             defines = get_file_defines(os.path.join(include_dir, file))
             if defines:

File support/prep_doc.py

     print >> f, '__docformat__ = "restructuredtext"'
     for child_name in dir(module):
         # Ignore privates
-        if child_name[:2] == '__':
+        if child_name[0] == '_':
             continue
         
         child = getattr(module, child_name)