Class: SDL::Surface

Inherits:
Data
  • Object
show all
Defined in:
ext/sdl/sdl.c

Direct Known Subclasses

Screen

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.load(path) ⇒ Object

// SDL::Surface methods:



470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
# File 'ext/sdl/sdl.c', line 470

static VALUE Surface_s_load(VALUE klass, VALUE path) {
  UNUSED(klass);
  SDL_Surface *surface;

  ExportStringValue(path);

  surface = IMG_Load(RSTRING_PTR(path));

  if (!surface)
    rb_raise(eSDLError, "Couldn't load file %s : %s",
             RSTRING_PTR(path),
             SDL_GetError());

  return TypedData_Wrap_Struct(cSurface, &_Surface_type, surface);
}

Instance Method Details

#[](x, y) ⇒ Object



755
756
757
758
# File 'ext/sdl/sdl.c', line 755

static VALUE Surface_index(VALUE self, VALUE x, VALUE y) {
  rb_raise(eSDLError, "Reading the canvas isn't currently supported");
  return Qnil;
}

#formatObject



704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
# File 'ext/sdl/sdl.c', line 704

static VALUE Surface_format(VALUE self) {
  DEFINE_SELF(Surface, surface, self);
  SDL_PixelFormat* format;
  SDL_Palette* palette;
  SDL_Palette* src = surface->format->palette;

  // TODO: remove this or drop down to SDL_AllocFormat only

  if (src) {
    palette = ALLOC(SDL_Palette);
    palette->ncolors = src->ncolors;
    palette->colors  = ALLOC_N(SDL_Color, (size_t)src->ncolors);
    MEMCPY(palette->colors, src->colors, SDL_Color, (size_t)src->ncolors);
  } else {
    palette = NULL;
  }

  VALUE ret = TypedData_Make_Struct(cPixelFormat, SDL_PixelFormat, &_PixelFormat_type, format);

  *format = *(surface->format);
  format->palette = palette;

  return ret;
}

#hObject



749
750
751
752
753
# File 'ext/sdl/sdl.c', line 749

static VALUE Surface_h(VALUE self) {
  DEFINE_SELF(Surface, surface, self);

  return INT2NUM(surface->h);
}

#make_collision_mapObject

TODO: reimplement and jettison SGE



787
788
789
790
791
792
793
794
795
# File 'ext/sdl/sdl.c', line 787

static VALUE Surface_make_collision_map(VALUE self) {
  DEFINE_SELF(Surface, surface, self);

  sge_cdata * cdata = sge_make_cmap(surface);
  if (!cdata)
    FAILURE("Surface#make_collision_map");

  return TypedData_Wrap_Struct(cCollisionMap, &_CollisionMap_type, cdata);
}

#transform(angle, xscale, yscale, flags) ⇒ Object

TODO: maybe remove? I dunno… could be nice for pre-rendering?



804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
# File 'ext/sdl/sdl.c', line 804

static VALUE Surface_transform(VALUE self, VALUE angle,
                               VALUE xscale, VALUE yscale,
                               VALUE flags) {
  DEFINE_SELF(Surface, surface, self);

  SDL_Surface *result = rotozoomSurfaceXY(surface,
                                          NUM2FLT(angle),
                                          NUM2FLT(xscale),
                                          NUM2FLT(yscale),
                                          SMOOTHING_ON);

  if (!result)
    FAILURE("Surface#transform");

  return TypedData_Wrap_Struct(cSurface, &_Surface_type, result);
}

#wObject



797
798
799
800
801
# File 'ext/sdl/sdl.c', line 797

static VALUE Surface_w(VALUE self) {
  DEFINE_SELF(Surface, surface, self);

  return INT2NUM(surface->w);
}