Class: Ray::Target
- Inherits:
-
Object
- Object
- Ray::Target
- Includes:
- PP
- Defined in:
- lib/ray/target.rb,
lib/ray/turtle.rb,
ext/target.c
Direct Known Subclasses
Manipulating views collapse
-
#with_view(view) { ... } ⇒ Object
Changes the view temporarily.
Instance Method Summary collapse
-
#[](x, y) ⇒ Ray::Color
Color of the pixel at a given position.
-
#clear(color) ⇒ Object
Clears the target in a given color.
-
#clip ⇒ Ray::Rect
Clipping rectangle when using the current 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.
- #pretty_print(q, other_attr = []) ⇒ Object
-
#rect(rect) ⇒ Ray::Image
Colors of pixels present in a rect.
-
#shader ⇒ Ray::Shader
Shader used when drawing on this target.
-
#size ⇒ Ray::Vector2
Size of the target, in pixels.
-
#to_image ⇒ Ray::Image
Colors of all the pixels in the target.
-
#turtle { ... } ⇒ Ray::Turtle
Creates a turtle operating on the receiver.
- #view ⇒ Object
-
#view=(view) ⇒ Object
Sets the view used by the target.
-
#viewport_for(rect) ⇒ Ray::Rect
Viewport for a view to make it draw on a given rect.
Methods included from PP
Instance Method Details
#[](x, y) ⇒ Ray::Color
162 163 164 165 166 167 |
# File 'ext/target.c', line 162
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
128 129 130 131 132 |
# File 'ext/target.c', line 128
static
VALUE ray_target_clear(VALUE self, VALUE color) {
say_target_clear(ray_rb2target(self), ray_rb2col(color));
return self;
}
|
#clip ⇒ Ray::Rect
Clipping rectangle when using the current view
85 86 87 88 |
# File 'ext/target.c', line 85 static VALUE ray_target_clip(VALUE self) { return ray_rect2rb(say_target_get_clip(ray_rb2target(self))); } |
#default_view ⇒ Ray::View
Default view of the target
The default view is made so that no scaling will be performed. It has the following properties:
-
size
is the size of the target; -
center
is the center of the target (half of the target); -
viewport
is the whole target (that is, [0, 0, 1, 1]).
63 64 65 66 67 68 |
# File 'ext/target.c', line 63 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
139 140 141 142 143 144 145 146 147 148 |
# File 'ext/target.c', line 139
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
This method is only used when using low-level OpenGL access. Calling #draw will cause this method to be called anyway (and custom drawables also allow OpenGL calls)
113 114 115 116 117 118 |
# File 'ext/target.c', line 113
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;
}
|
#pretty_print(q, other_attr = []) ⇒ Object
39 40 41 |
# File 'lib/ray/target.rb', line 39 def pretty_print(q, other_attr = []) pretty_print_attributes q, ["view", "shader", "size"] + other_attr end |
#rect(rect) ⇒ Ray::Image
175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'ext/target.c', line 175
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
Shader used when drawing on this target
Notice this method will always return the same object, and that modifying this object will modify the shader used internally be the target.
11 12 13 |
# File 'lib/ray/target.rb', line 11 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
Colors of all the pixels in the target
194 195 196 197 198 199 200 201 202 203 204 |
# File 'ext/target.c', line 194
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 { ... } ⇒ Ray::Turtle
Creates a turtle operating on the receiver
If a block is passed, it is instance-evaluated (self becoming the turtle) and the receiver gets updated automatically.
222 223 224 225 226 227 228 229 230 |
# File 'lib/ray/turtle.rb', line 222 def turtle(&block) turtle = Ray::Turtle.new(self) if block turtle.instance_eval(&block) update end turtle end |
#view ⇒ Object
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=(view) ⇒ Object
43 44 45 46 47 48 |
# File 'ext/target.c', line 43
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
97 98 99 100 101 |
# File 'ext/target.c', line 97
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
Changes the view temporarily
29 30 31 32 33 34 35 |
# File 'lib/ray/target.rb', line 29 def with_view(view) old_view = self.view self.view = view yield self ensure self.view = old_view end |