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.
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. |
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).
/* 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.
/* Returns the buffer representing the screen. Use it only for reading. */ VALUE Buffer_getScreen(VALUE self)
Returns the color of a pixel.
/* 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.
/* 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.
/* 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.
/* 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)
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
/* 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.
/* call-seq: move(x, y) Moves the buffer. */ VALUE Buffer_move(VALUE self, VALUE x, VALUE y)
Resizes the buffer. Be carefull, this is rather slow: a buffer is created, and the old one is drawn on it before being destroyed.
/* 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.
/* call-seq: rotate(angle) Rotates the buffer. */ VALUE Buffer_rotate(VALUE self, VALUE angle)
Saves the buffer
/* call-seq: save(filename) Saves the buffer */ VALUE Buffer_save(VALUE self, VALUE filename)
Sets the buffer’s position.
/* 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).
/* Changes the actual drawbuffer (+Joyau::draw+ can do this automatically). */ VALUE Buffer_setActual(VALUE self)
Unlocks the buffer. Call it when you’ve finished to modify your image.
/* call-seq: unlock Unlocks the buffer. Call it when you've finished to modify your image. */ VALUE Buffer_unlock(VALUE self)
Sets the buffer’s abscissa.
/* call-seq: x=(val) Sets the buffer's abscissa. */ VALUE Buffer_setX(VALUE self, VALUE x)
Sets the buffer’s ordinate.
/* call-seq: y=(val) Sets the buffer's ordinate. */ VALUE Buffer_setY(VALUE self, VALUE y)