pike.git / src / post_modules / SDL / SDL.cmod

version» Context lines:

pike.git/src/post_modules/SDL/SDL.cmod:1:   /* -*- c -*-   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information.   */      #include "global.h"   #include "stralloc.h" + #include "pike_compiler.h"   #include "pike_macros.h"   #include "program.h"   #include "program_id.h"   #include "operators.h"   #include "fdlib.h"   #include "fd_control.h"   #include "backend.h"   #include "module_support.h"   #include "array.h"   #include "builtin_functions.h"
pike.git/src/post_modules/SDL/SDL.cmod:58:   static struct object *image_make_rgb_color(INT32 r,INT32 g,INT32 b)   {    struct color_struct *cs;    struct object *color;    if (r<0) r=0; else if (r>COLORMAX) r=COLORMAX;    if (g<0) g=0; else if (g>COLORMAX) g=COLORMAX;    if (b<0) b=0; else if (b>COLORMAX) b=COLORMAX;       color = clone_object(image_color_program,0);    -  cs=(struct color_struct*) -  get_storage(color, image_color_program); +  cs= get_storage(color, image_color_program);       cs->rgb.r=(COLORTYPE)r;    cs->rgb.g=(COLORTYPE)g;    cs->rgb.b=(COLORTYPE)b;    RGB_TO_RGBL(cs->rgbl,cs->rgb);    return color;   }         /* SDL needs this defined in it its own way */
pike.git/src/post_modules/SDL/SDL.cmod:90:   # elif defined(HAVE_SDL_MIXER_H)   # include <SDL_mixer.h>   # endif   #endif      #include "constants.h"      #define THIS_OBJ Pike_interpreter.frame_pointer->current_object   #define RET_THIS() do { pop_n_elems(args); ref_push_object(THIS_OBJ); return; } while(0)    - /* Fall back to a normal index on this object, in case -  * someone inherited us. */ -  #define OBJ_INDEX() do { \ -  struct svalue res; \ -  object_index_no_free2 (&res, Pike_fp->current_object, 0, Pike_sp-1); \ -  pop_stack(); \ -  *Pike_sp++ = res; \ -  } while(0) \ -  -  +    #define CHECK_CLASS(o, name, arg)\    if(o->prog != PIKE_CONCAT(name, _program)) { \    Pike_error("Invalid class for argument %d\n", arg); \    }      /* Subsystem init (or rather quit) generations.    * This is needed to detect whether a subsystem has been exited    * since an object was created.    */   static int timer_generation;
pike.git/src/post_modules/SDL/SDL.cmod:160:    *! @seealso    *! @[SDL.quit()], @[SDL.init_sub_system()], @[SDL.quit_sub_system()]    *!    */   PIKEFUN void init(int flags) {    if( SDL_Init(flags) == -1) {    Pike_error("SDL Initialization failed: %s\n", SDL_GetError());    }   }    - /*! @decl void|string get_error() + /*! @decl string get_error()    *!    *! Get the last internal SDL error.    *! @returns    *! The error string, or zero if there was no error.    */ - PIKEFUN void|string get_error() { + PIKEFUN string get_error() {    const char *err = SDL_GetError();    pop_n_elems(args);    if(err != NULL) {    push_text(err);    } else {    push_int(0);    }   }      /*! @decl void init_sub_system(int flags)
pike.git/src/post_modules/SDL/SDL.cmod:362:    */   PIKECLASS Rect {    CVAR SDL_Rect rect;       INIT {    THIS->rect.x = THIS->rect.y = 0;    THIS->rect.w = THIS->rect.h = 0;    }   #define CHECK_I16_ARG(fun, n, x) do { \    if ((x) < -32768 || (x) > 32767) \ -  SIMPLE_BAD_ARG_ERROR((fun), (n), "int(-32768..32767)"); \ +  SIMPLE_ARG_TYPE_ERROR((fun), (n), "int(-32768..32767)"); \   } while(0)   #define CHECK_U16_ARG(fun, n, x) do { \    if ((x) < 0 || (x) > 65535) \ -  SIMPLE_BAD_ARG_ERROR((fun), (n), "int(0..65535)"); \ +  SIMPLE_ARG_TYPE_ERROR((fun), (n), "int(0..65535)"); \   } while(0)       /*! @decl void create()    *! @decl void create(int(-32768..32767) x, int(-32768..32767) y)    *! @decl void create(int(-32768..32767) x, int(-32768..32767) y, @    *! int(0..65535) w, int(0..65535) h)    *!    *! Create a new @[Rect].    *!    *! @param x
pike.git/src/post_modules/SDL/SDL.cmod:455:    {    CHECK_U16_ARG("`w=", 1, value);    THIS->rect.w = value;    }    PIKEFUN int(0..65535) `h=(int(0..65535) value)    {    CHECK_U16_ARG("`h=", 1, value);    THIS->rect.h = value;    }    -  /*! @decl mixed cast(string type) +  /*! @decl array|mapping cast(string type)    *!    *! It is possible to cast a Rect object to an @tt{array@} or    *! to a @tt{mapping@}. The array will have the values in the    *! order x, y, w, h and the mapping will have the values    *! associated with the corresponding names.    */ -  PIKEFUN mixed cast( string type ) +  PIKEFUN array|mapping cast( string type ) +  flags ID_PROTECTED;    { -  struct pike_string *array_t; -  struct pike_string *mapping_t; -  REF_MAKE_CONST_STRING( array_t, "array" ); -  REF_MAKE_CONST_STRING( mapping_t, "mapping" ); -  -  if( type == array_t ) +  pop_stack(); /* type as at least one more reference. */ +  if( type == literal_array_string )    { -  pop_n_elems( args ); +     push_int(THIS->rect.x);    push_int(THIS->rect.y);    push_int(THIS->rect.w);    push_int(THIS->rect.h);    f_aggregate(4); -  return; -  } else if( type == mapping_t ) { -  pop_n_elems( args ); -  push_text("x"); +  } else if( type == literal_mapping_string ) { +  push_static_text("x");    push_int(THIS->rect.x); -  push_text("y"); +  push_static_text("y");    push_int(THIS->rect.y); -  push_text("w"); +  push_static_text("w");    push_int(THIS->rect.w); -  push_text("h"); +  push_static_text("h");    push_int(THIS->rect.h);    f_aggregate_mapping(8); -  return; +     } -  -  Pike_error("Cannot cast to %S\n", type); +  else +  push_undefined();    }   }   /*! @endclass Rect */      /*! @class Keysym    *!    *! The Keysym class is used to report key presses and releases. It's    *! available from the @[SDL.Event] class for keyboard events.    */   PIKECLASS Keysym {
pike.git/src/post_modules/SDL/SDL.cmod:562:    *! enable it unless its needed.    */    PIKEFUN int `unicode()    {    push_int(THIS->keysym.unicode);    }   }      /*! @endclass Keysym */    + #undef CHECK_INIT   #define CHECK_INIT() if(THIS->fmt == NULL) { Pike_error("PixelFormat unitialized!\n"); }      #if !defined(SDL_ALPHA_OPAQUE) || !SDL_ALPHA_OPAQUE   /* SDL 1.1.4 and earlier had inverted alpha.    * This was changed in 1.1.5, when also    * SDL_ALPHA_{OPAQUE,TRANSPARENT} were added.    */   #define CONVERT_ALPHA(X) (255-(X))   #else   #define CONVERT_ALPHA(X) (X)
pike.git/src/post_modules/SDL/SDL.cmod:868:    *! The alpha value of the pixel in the range 0-255.    *! @endmapping    *!    *! @seealso    *! @[map_rgb()], @[map_rgba()], @[get_rgb()]    */    PIKEFUN mapping(string:object|int) get_rgba(int pixel) {    Uint8 r, g, b, a;    SDL_GetRGBA((Uint32)pixel, THIS->fmt, &r, &g, &b, &a);    pop_n_elems(args); -  push_text("color"); +  push_static_text("color");    push_object(image_make_rgb_color(r, g, b)); -  push_text("alpha"); +  push_static_text("alpha");    push_int(CONVERT_ALPHA(a));    f_aggregate_mapping(4);    }   }   /*! @endclass PixelFormat */   #undef CHECK_INIT         #define CHECK_INIT() if((THIS->generation != video_generation) || (THIS->vidinfo == NULL)) { Pike_error("VideoInfo unitialized!\n"); }   
pike.git/src/post_modules/SDL/SDL.cmod:1423:    rgb_group rgb;    if((THIS->generation == video_generation) && (THIS->_s != NULL)) {    SDL_FreeSurface(THIS->_s);    THIS->_s = NULL;    }    // if(image_program != NULL) {    CHECK_CLASS(image, image, 1);    // }    if(_flags) {    if(TYPEOF(*_flags) != PIKE_T_INT) { -  SIMPLE_BAD_ARG_ERROR("set_image",2,"int|void"); +  SIMPLE_ARG_TYPE_ERROR("set_image",2,"int|void");    }    flags = _flags->u.integer;    }    i = ((struct image *)(image->storage));    if(i->alpha) {    flags &= SDL_SRCALPHA;    }    THIS->_s =    SDL_CreateRGBSurface(flags, i->xsize, i->ysize, 32,    0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff);
pike.git/src/post_modules/SDL/SDL.cmod:1472:    if((THIS->generation == video_generation) && (THIS->_s != NULL)) {    SDL_FreeSurface(THIS->_s);    THIS->_s = NULL;    }       CHECK_CLASS(image, image, 1);    CHECK_CLASS(alpha, image, 2);       if(_flags) {    if(TYPEOF(*_flags) != PIKE_T_INT) { -  SIMPLE_BAD_ARG_ERROR("set_image",3,"int|void"); +  SIMPLE_ARG_TYPE_ERROR("set_image",3,"int|void");    }    flags = _flags->u.integer;    }    i = ((struct image *)(image->storage));    a = ((struct image *)(alpha->storage));       THIS->_s =    SDL_CreateRGBSurface(flags, i->xsize, i->ysize, 32,    0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff);    if(!THIS->_s) {
pike.git/src/post_modules/SDL/SDL.cmod:1793:      /*! @decl int set_gamma(float red, float green, float blue)    *!    *! @fixme    *! Document this function    */   PIKEFUN int set_gamma(float red, float green, float blue) {    RETURN SDL_SetGamma(red, green, blue);   }    - /*! @decl void|object get_video_surface() + /*! @decl object get_video_surface()    *!    *! Returns the current display surface.    *!    *! If SDL is doing format conversion on the display surface, this method    *! returns the publicly visible surface, not the real video surface.    *!    *! @returns    *! The current display surface, or 0 if there is no display surface.    *!    *! @seealso    *! @[SDL.set_video_mode()]    */ - PIKEFUN void|object get_video_surface() + PIKEFUN object get_video_surface()   {    SDL_Surface *screen = SDL_GetVideoSurface();    if(screen != NULL) {    struct object *surface = clone_object( Surface_program, 0 );    /* to avoid freeing when the new Surface class is destroyed */    screen->refcount ++;    OBJ2_SURFACE(surface)->_s = screen;    push_object(surface);    return;    }    push_int(0);   }    - /*! @decl void|object get_video_info() + /*! @decl object get_video_info()    *!    *! @returns    *! Returns an @[SDL.VideoInfo] object, which holds information about the video    *! hardware, or 0 if the video device has not yet been initialized (with a    *! call to @[SDL.init()]).    */ - PIKEFUN void|object get_video_info() + PIKEFUN object get_video_info()   {    const SDL_VideoInfo *vidinfo = SDL_GetVideoInfo();    if(vidinfo != NULL) {    struct object *viptr = clone_object( VideoInfo_program, 0 );    /* to avoid freeing when the new Surface class is destroyed */    OBJ2_VIDEOINFO(viptr)->vidinfo = vidinfo;    push_object(viptr);    return;    }    push_int(0);
pike.git/src/post_modules/SDL/SDL.cmod:2050:    }    if(_dstrect) {    CHECK_CLASS(_dstrect, Rect, 4);    dstrect = &(OBJ2_RECT(_dstrect)->rect);    }       RETURN SDL_BlitSurface(OBJ2_SURFACE(src)->_s, srcrect,    OBJ2_SURFACE(dst)->_s, dstrect);   }    - /*! @decl void|string video_driver_name() + /*! @decl string video_driver_name()    *!    *! Obtains the name of the video driver. This is a simple one-word identifier    *! such as 'x11' or 'windib'.    *!    *! @returns    *! The name of the video driver, or 0 if video has not yet been initialized    *! (with a call to @[SDL.init()]).    */ - PIKEFUN void|string video_driver_name() { + PIKEFUN string video_driver_name() {    char tmp[256];    tmp[0] = 0;    SDL_VideoDriverName(tmp, 255);    if(!*tmp) {    push_int(0);    return;    }    push_text(tmp);   }   
pike.git/src/post_modules/SDL/SDL.cmod:2944:    *!    *! @returns    *! The @[SDL.Music] object.    */    PIKEFUN object play(int|void _loops) {    int loops = -1;    if(_loops) {    if(TYPEOF(*_loops) == PIKE_T_INT) {    loops = _loops->u.integer;    } else { -  SIMPLE_BAD_ARG_ERROR("Music.play", 1, "void|int"); +  SIMPLE_ARG_TYPE_ERROR("play", 1, "void|int");    }    }    Mix_PlayMusic(THIS->music, loops);    RET_THIS();    }       /*! @decl object fade_in(int ms, int|void loops)    *!    *! Fades the music in over the given number of milliseconds.    *! Playback is repeated @tt{loops@} number of times.
pike.git/src/post_modules/SDL/SDL.cmod:2983:    *!    *! @seealso    *! @[fade_out()], @[fading()]    */    PIKEFUN object fade_in(int ms, int|void _loops) {    int loops = -1;    if(_loops) {    if(TYPEOF(*_loops) == PIKE_T_INT) {    loops = _loops->u.integer;    } else { -  SIMPLE_BAD_ARG_ERROR("Music.fade_in", 2, "void|int"); +  SIMPLE_ARG_TYPE_ERROR("fade_in", 2, "void|int");    }    }    Mix_FadeInMusic(THIS->music, loops, ms);    RET_THIS();    }       /*! @decl object fade_out(int ms)    *!    *! Fades the music out over the given number of milliseconds.    *!