Class: Ray::Target
- Inherits:
-
Object
- Object
- Ray::Target
- Defined in:
- lib/ray/target.rb,
lib/ray/turtle.rb,
ext/target.c
Direct Known Subclasses
Instance Method Summary collapse
- #[](x, y) ⇒ Ray::Color
-
#clear(color) ⇒ Object
Clears the target in a given color.
-
#clip ⇒ Ray::Rect
Part of the target that’s used by the view.
-
#default_view ⇒ Ray::View
Default view of the target.
-
#draw(obj) ⇒ Object
Draws an object on the target.
-
#make_current ⇒ Object
Makes a target become the current one.
- #rect(rect) ⇒ Ray::Image
-
#shader ⇒ Ray::Shader
Shader used when drawing on this target.
-
#size ⇒ Ray::Vector2
Size of the target, in pixels.
-
#to_image ⇒ Ray::Image
An image containing all the pixels of the target.
-
#turtle(&block) ⇒ Ray::Turtle
Creates a turtle operating on the receiver.
-
#view ⇒ Ray::View
View currently used.
- #view=(val) ⇒ Object
- #viewport_for(rect) ⇒ Ray::Rect
- #with_view(view) { ... } ⇒ Object
Instance Method Details
#[](x, y) ⇒ Ray::Color
121 122 123 124 125 126 |
# File 'ext/target.c', line 121
static
VALUE ray_target_get(VALUE self, VALUE x, VALUE y) {
return ray_col2rb(say_target_get(ray_rb2target(self),
NUM2ULONG(x),
NUM2ULONG(y)));
}
|
#clear(color) ⇒ Object
92 93 94 95 96 |
# File 'ext/target.c', line 92
static
VALUE ray_target_clear(VALUE self, VALUE color) {
say_target_clear(ray_rb2target(self), ray_rb2col(color));
return self;
}
|
#clip ⇒ Ray::Rect
Returns Part of the target that’s used by the view.
55 56 57 58 |
# File 'ext/target.c', line 55 static VALUE ray_target_clip(VALUE self) { return ray_rect2rb(say_target_get_clip(ray_rb2target(self))); } |
#default_view ⇒ Ray::View
Returns Default view of the target.
43 44 45 46 47 |
# File 'ext/target.c', line 43 static VALUE ray_target_default_view(VALUE self) { say_view *view = say_target_get_default_view(ray_rb2target(self)); return Data_Wrap_Struct(rb_path2class("Ray::View"), NULL, say_view_free, view); } |
#draw(obj) ⇒ Object
103 104 105 106 107 108 109 110 111 112 |
# File 'ext/target.c', line 103
static
VALUE ray_target_draw(VALUE self, VALUE obj) {
if (RAY_IS_A(obj, rb_path2class("Ray::BufferRenderer"))) {
say_target_draw_buffer(ray_rb2target(self),
ray_rb2buf_renderer(obj));
}
else
say_target_draw(ray_rb2target(self), ray_rb2drawable(obj));
return self;
}
|
#make_current ⇒ Object
Makes a target become the current one. Not useful unless using OpenGL directly.
78 79 80 81 82 83 |
# File 'ext/target.c', line 78
static
VALUE ray_target_make_current(VALUE self) {
if (!say_target_make_current(ray_rb2target(self)))
rb_raise(rb_eRuntimeError, "%s", say_error_get_last());
return self;
}
|
#rect(rect) ⇒ Ray::Image
133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'ext/target.c', line 133
static
VALUE ray_target_rect(VALUE self, VALUE rect) {
say_rect c_rect = ray_convert_to_rect(rect);
say_image *image = say_target_get_rect(ray_rb2target(self),
c_rect.x, c_rect.y,
c_rect.w, c_rect.h);
if (!image) {
rb_raise(rb_eRuntimeError, "%s", say_error_get_last());
}
return Data_Wrap_Struct(rb_path2class("Ray::Image"), NULL, say_image_free,
image);
}
|
#shader ⇒ Ray::Shader
Returns Shader used when drawing on this target.
4 5 6 |
# File 'lib/ray/target.rb', line 4 def shader @shader ||= simple_shader # must always remain the same object end |
#size ⇒ Ray::Vector2
Returns Size of the target, in pixels.
23 24 25 26 |
# File 'ext/target.c', line 23 static VALUE ray_target_size(VALUE self) { return ray_vector2_to_rb(say_target_get_size(ray_rb2target(self))); } |
#to_image ⇒ Ray::Image
Returns An image containing all the pixels of the target.
151 152 153 154 155 156 157 158 159 160 161 |
# File 'ext/target.c', line 151
static
VALUE ray_target_to_image(VALUE self) {
say_image *image = say_target_to_image(ray_rb2target(self));
if (!image) {
rb_raise(rb_eRuntimeError, "%s", say_error_get_last());
}
return Data_Wrap_Struct(rb_path2class("Ray::Image"), NULL, say_image_free,
image);
}
|
#turtle(&block) ⇒ Ray::Turtle
Creates a turtle operating on the receiver. Instance evaluates the block it is given if any.
216 217 218 219 220 221 222 223 224 |
# File 'lib/ray/turtle.rb', line 216 def turtle(&block) turtle = Ray::Turtle.new(self) if block turtle.instance_eval(&block) update end turtle end |
#view ⇒ Ray::View
Returns View currently used.
29 30 31 32 |
# File 'ext/target.c', line 29 static VALUE ray_target_view(VALUE self) { return ray_view2rb(say_target_get_view(ray_rb2target(self))); } |
#view=(val) ⇒ Object
34 35 36 37 38 39 |
# File 'ext/target.c', line 34
static
VALUE ray_target_set_view(VALUE self, VALUE val) {
rb_check_frozen(self);
say_target_set_view(ray_rb2target(self), ray_rb2view(val));
return val;
}
|
#viewport_for(rect) ⇒ Ray::Rect
65 66 67 68 69 |
# File 'ext/target.c', line 65
static
VALUE ray_target_viewport_for(VALUE self, VALUE rect) {
return ray_rect2rb(say_target_get_viewport_for(ray_rb2target(self),
ray_convert_to_rect(rect)));
}
|
#with_view(view) { ... } ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/ray/target.rb', line 10 def with_view(view) old_view = self.view self.view = view yield self ensure self.view = old_view end |