--
--	occSDLhelpers.occ: helper code for occSDL wrapper
--	Copyright (C) 2007  University of Kent
--
--	This library is free software; you can redistribute it and/or
--	modify it under the terms of the GNU Lesser 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
--	Lesser General Public License for more details.
--
--	You should have received a copy of the GNU Lesser General Public
--	License along with this library.  If not, see
--	<http://www.gnu.org/licenses/>.
--

--** @module occSDL

#INCLUDE "occSDL.inc"
#INCLUDE "occSDLhelpers.inc"

--{{{  PROC occ.SDL.zero.terminate
--* Zero-terminate a string.
-- This works around a bug in SWIG: strings passed to C functions aren't
-- currently terminated properly.
PROC occ.SDL.zero.terminate (VAL []BYTE in, RESULT MOBILE []BYTE out)
  SEQ
    out := MOBILE [(SIZE in) + 1]BYTE
    [out FOR SIZE in] := in
    out[SIZE in] := '*#00'
:
--}}}
--{{{  PROC occ.SDL.set.rect
--* Set the values in an SDL.Rect structure.
PROC occ.SDL.set.rect (SDL.Rect rect, VAL INT x, y, w, h)
  SEQ
    set.SDL.Rect.x (INT16 x, rect)
    set.SDL.Rect.y (INT16 y, rect)
    set.SDL.Rect.w (INT16 w, rect)
    set.SDL.Rect.h (INT16 h, rect)
:
--}}}
--{{{  PROC occ.SDL.blit
--* Blit a rectangle from one surface to another.
PROC occ.SDL.blit (SDL.Surface from, VAL INT from.x, from.y, w, h,
                   SDL.Surface to, VAL INT to.x, to.y)
  INT result:
  SDL.Rect rect1, rect2:
  SEQ
    create.SDL.Rect (rect1)
    create.SDL.Rect (rect2)
    occ.SDL.set.rect (rect1, from.x, from.y, w, h)
    occ.SDL.set.rect (rect2, to.x, to.y, 0, 0)
    SDL.BlitSurface (result, from, rect1, to, rect2)
    ASSERT (result = 0)
    delete.SDL.Rect (rect1)
    delete.SDL.Rect (rect2)
:
--}}}
--{{{  PROC occ.SDL.blit.raster
--* Blit a rectangle from a raster onto a surface.
PROC occ.SDL.blit.raster (VAL [][]INT raster, VAL INT from.x, from.y, w, h,
                          SDL.Surface surface, VAL INT to.x, to.y)
  SDL.Surface src:
  SEQ
    occ.SDL.make.surface (raster, src)
    ASSERT (src <> 0)
    occ.SDL.blit (src, from.x, from.y, w, h, surface, to.x, to.y)
    SDL.FreeSurface (src)
:
--}}}
