Class Joyau::Buffer
In: Drawable.cpp
Parent: Object

Buffers can be displayed on the screen. The screen itself is a Buffer, which can be accessed.

You can modify a buffer by multiple ways, like drawing drawables on it, or modifying directly its pixels (really fun effects can be created this way!).

For the first method, consider using +Joyau::draw+ which makes your job much more easier.

A buffer’s width cannot be greater than 512. Same for the width. Also, multiple pixel formats are usable. PF_8888 looks better, but takes much more memory than PF_4444, so be carefull.

Methods

[]   []=   actual   clear   default   draw   h   lock   move   new   pos=   resize   rotate   save   screen   setPos   set_actual   to_sprite   unlock   w   x   x=   y   y=   zoom  

Constants

PF_4444 = PF_4444   Pixel format for 8 bits colors.
PF_5650 = PF_5650   Pixel format for 16 bits colors.
PF_8888 = PF_8888   Pixel format for 32 bits colors.

Public Class methods

Returns the actual buffer.

[Source]

/*
  Returns the actual buffer.
*/
VALUE Buffer_getActual(VALUE self) 

Returns the default buffer.

[Source]

/*
  Returns the default buffer.
*/
VALUE Buffer_getDefault(VALUE self) 

A buffer can be created from a drawable or from another buffer. It’ll simply contain the Drawable (after the creation, the two objects aren’t related at all).

Another way is to specify the buffer’s dimension, and at your option, the pixel format (by default, 16 bits colors are used).

[Source]

/*
  call-seq: new(drawable)
            new(buffer)
            new(w, h)
            new(w, h, pixel_format)

  A buffer can be created from a drawable or from another buffer. It'll
  simply contain the Drawable (after the creation, the two objects aren't
  related at all).

  Another way is to specify the buffer's dimension, and at your option, the
  pixel format (by default, 16 bits colors are used).
*/
VALUE wrap<Buffer>(int argc, VALUE *argv, VALUE info)
{
   VALUE arg1, arg2, arg3;
   rb_scan_args(argc, argv, "12", &arg1, &arg2, &arg3);

   Buffer *ptr = NULL;

   try {
      if (NIL_P(arg2)) {
         if (rb_obj_is_kind_of(arg1, getClass("Drawable")) == Qtrue) {
            RubyDrawable drawable(arg1);
            ptr = new Buffer(drawable);
         }
         else if (rb_obj_is_kind_of(arg1, getClass("Buffer")) == Qtrue) {
            ptr = new Buffer(getRef<Buffer>(arg1));
         }
         else {
            rb_raise(rb_eTypeError, "Buffer or Drawable expected.");
         }
      }
      else {
         if (NIL_P(arg2))
            rb_raise(rb_eArgError, "Another argument was expected.");
         if (NIL_P(arg3))
            arg3 = INT2FIX(OSL_PF_5650);
         ptr = new Buffer(FIX2INT(arg1), FIX2INT(arg2), FIX2INT(arg3));
      }
   }
   catch (const RubyException &e) {
      e.rbRaise();
   }
   
   VALUE tdata = Data_Wrap_Struct(info, 0, wrapped_free<Buffer>, ptr);
   return tdata;
}

Returns the buffer representing the screen. Use it only for reading.

[Source]

/*
  Returns the buffer representing the screen.
  Use it only for reading.
*/
VALUE Buffer_getScreen(VALUE self) 

Public Instance methods

Returns the color of a pixel.

[Source]

/*
  call-seq: [x, y]

  Returns the color of a pixel.
*/
VALUE Buffer_getPixel(VALUE self, VALUE x, VALUE y) 

Sets the color of a pixel.

[Source]

/*
  call-seq: [x, y] = col
    
  Sets the color of a pixel.
*/
VALUE Buffer_setPixel(VALUE self, VALUE x, VALUE y, VALUE col) 

Clears the buffer in a given color.

[Source]

/*
  call-seq: clear(color)

  Clears the buffer in a given color.
 */
VALUE Buffer_clear(VALUE self, VALUE color) 

If no arguments are given, the buffer is drawn. If either a buffer or a drawable is given, then it is drawn on the buffer.

[Source]

/*
  call-seq: draw
            draw(object)

  If no arguments are given, the buffer is drawn. If either a buffer or
  a drawable is given, then it is drawn on the buffer.
*/
VALUE Buffer_draw(int argc, VALUE *argv, VALUE self) 

Returns the buffer’s width.

[Source]

/*
  Returns the buffer's width.
*/
VALUE Buffer_getH(VALUE self) 

Locks the buffer. Once the buffer is locked, you can modify its pixels. If a block is given, then it is executed, and the buffer is unlocked after having executed the block.

Examples:

  buf.lock
  buf[0, 0] = 0
  buf.unlock

  buf.lock do
    buf[0, 0] = 0
  end

[Source]

/*
  call-seq: lock
            lock { ... } 

  Locks the buffer. Once the buffer is locked, you can modify its pixels.
  If a block is given, then it is executed, and the buffer is unlocked after
  having executed the block.

  Examples:
    buf.lock
    buf[0, 0] = 0
    buf.unlock

    buf.lock do
      buf[0, 0] = 0
    end
*/
VALUE Buffer_lock(int argc, VALUE *argv, VALUE self) 

Moves the buffer.

[Source]

/*
  call-seq: move(x, y)

  Moves the buffer.
*/
VALUE Buffer_move(VALUE self, VALUE x, VALUE y) 
pos=(...)

Alias for setPos

Resizes the buffer. Be carefull, this is rather slow: a buffer is created, and the old one is drawn on it before being destroyed.

[Source]

/*
  call-seq: resize(w, h)

  Resizes the buffer. Be carefull, this is rather slow: a buffer is
  created, and the old one is drawn on it before being destroyed.
*/
VALUE Buffer_resize(VALUE self, VALUE w, VALUE h) 

Rotates the buffer.

[Source]

/*
  call-seq: rotate(angle)

  Rotates the buffer.
*/
VALUE Buffer_rotate(VALUE self, VALUE angle) 

Saves the buffer

[Source]

/*
  call-seq: save(filename)

  Saves the buffer 
*/
VALUE Buffer_save(VALUE self, VALUE filename) 

Sets the buffer’s position.

[Source]

/*
  call-seq: setPos(x, y)
            setPos(point)

  Sets the buffer's position.
*/
VALUE Buffer_setPos(int argc, VALUE *argv, VALUE self) 

Changes the actual drawbuffer (+Joyau::draw+ can do this automatically).

[Source]

/*
  Changes the actual drawbuffer (+Joyau::draw+ can do this automatically).
*/
VALUE Buffer_setActual(VALUE self) 

Converts the buffer in a Sprite.

[Source]

/*
  Converts the buffer in a Sprite.
*/
VALUE Buffer_to_sprite(VALUE self) 

Unlocks the buffer. Call it when you’ve finished to modify your image.

[Source]

/*
  call-seq: unlock

  Unlocks the buffer. Call it when you've finished to modify your image.
*/
VALUE Buffer_unlock(VALUE self) 

Returns the buffer’s width.

[Source]

/*
  Returns the buffer's width.
*/
VALUE Buffer_getW(VALUE self) 

Returns the buffer’s abscissa.

[Source]

/*
  Returns the buffer's abscissa.
*/
VALUE Buffer_getX(VALUE self) 

Sets the buffer’s abscissa.

[Source]

/*
  call-seq: x=(val)

  Sets the buffer's abscissa.
*/
VALUE Buffer_setX(VALUE self, VALUE x) 

Returns the buffer’s ordinate.

[Source]

/*
  Returns the buffer's ordinate.
*/
VALUE Buffer_getY(VALUE self) 

Sets the buffer’s ordinate.

[Source]

/*
  call-seq: y=(val)

  Sets the buffer's ordinate.
*/
VALUE Buffer_setY(VALUE self, VALUE y) 

Zooms on the buffer.

[Source]

/*
  call-seq: zoom(level)

  Zooms on the buffer.
*/
VALUE Buffer_zoom(VALUE self, VALUE level) 

[Validate]