Class: Ray::View
- Inherits:
-
Object
- Object
- Ray::View
- Includes:
- PP
- Defined in:
- ext/view.c,
lib/ray/view.rb,
ext/view.c
Overview
A view is a way to apply some transformations to all the drawables at once, by defining a projection. It also determines the region of the screen where the view will draw.
Class Method Summary collapse
-
.clip(rect, target_size) ⇒ Ray::View
A view that allows to clip rendering to a given region of the target, without scaling.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #center ⇒ Object
-
#center=(center) ⇒ Object
Sets the center of the world.
- #h ⇒ Object
- #h=(val) ⇒ Object
- #initialize(*args) ⇒ Object constructor
- #initialize_copy(orig) ⇒ Object
- #inspect ⇒ Object
- #matrix ⇒ Object
-
#matrix=(mat) ⇒ Object
Sets the projection matrix.
- #pretty_print(q) ⇒ Object
-
#rect ⇒ Ray::Rect
Rect representing the part of the world that can be seen through this view.
- #size ⇒ Object
-
#size=(val) ⇒ Object
Sets the size of the visible world.
-
#unzoom_by(value) ⇒ Object
Decreases zoom (making object appear smaller).
- #viewport ⇒ Object
-
#viewport=(rect) ⇒ Object
Sets the region of the world where rendering will be done.
- #w ⇒ Object
- #w=(val) ⇒ Object
- #x ⇒ Object
- #x=(val) ⇒ Object
- #y ⇒ Object
- #y=(val) ⇒ Object
-
#zoom_by(value) ⇒ Object
Increases zoom (making object appear bigger).
Methods included from PP
Constructor Details
#initialize(center, size, viewport = [0, 0, 1, 1]) ⇒ Object #initialize(matrix) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'ext/view.c', line 38
static
VALUE ray_view_init(int argc, VALUE *argv, VALUE self) {
say_view *view = ray_rb2view(self);
if (argc == 1) {
say_view_set_matrix(view, ray_rb2matrix(argv[0]));
}
else {
VALUE center, size, viewport = Qnil;
rb_scan_args(argc, argv, "21", ¢er, &size, &viewport);
say_view_set_center(view, ray_convert_to_vector2(center));
say_view_set_size(view, ray_convert_to_vector2(size));
if (!NIL_P(viewport)) {
say_view_set_viewport(view, ray_convert_to_rect(viewport));
}
}
return self;
}
|
Class Method Details
.clip(rect, target_size) ⇒ Ray::View
Returns A view that allows to clip rendering to a given region of the target, without scaling.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/ray/view.rb', line 10 def self.clip(rect, target_size) rect, target_size = rect.to_rect, target_size.to_vector2 = Ray::Rect[rect.x / target_size.w, rect.y / target_size.h, rect.w / target_size.w, rect.h / target_size.y] Ray::View.new(rect.center, rect.size, ) end |
Instance Method Details
#==(other) ⇒ Object
21 22 23 |
# File 'lib/ray/view.rb', line 21 def ==(other) other.is_a?(Ray::View) && self.matrix == other.matrix end |
#center ⇒ Object
89 90 91 92 |
# File 'ext/view.c', line 89 static VALUE ray_view_center(VALUE self) { return ray_vector2_to_rb(say_view_get_center(ray_rb2view(self))); } |
#center=(center) ⇒ Object
99 100 101 102 103 104 |
# File 'ext/view.c', line 99
static
VALUE ray_view_set_center(VALUE self, VALUE val) {
rb_check_frozen(self);
say_view_set_center(ray_rb2view(self), ray_convert_to_vector2(val));
return val;
}
|
#h ⇒ Object
54 |
# File 'lib/ray/view.rb', line 54 def h; size.h; end |
#h=(val) ⇒ Object
59 |
# File 'lib/ray/view.rb', line 59 def h=(val); self.size = [w, val]; end |
#initialize_copy(orig) ⇒ Object
60 61 62 63 64 |
# File 'ext/view.c', line 60
static
VALUE ray_view_init_copy(VALUE self, VALUE orig) {
say_view_copy(ray_rb2view(self), ray_rb2view(orig));
return self;
}
|
#inspect ⇒ Object
61 62 63 |
# File 'lib/ray/view.rb', line 61 def inspect "#<#{self.class} center=#{center} size=#{size} viewport=#{}>" end |
#matrix ⇒ Object
133 134 135 136 |
# File 'ext/view.c', line 133 static VALUE ray_view_matrix(VALUE self) { return ray_matrix2rb(say_view_get_matrix(ray_rb2view(self))); } |
#matrix=(mat) ⇒ Object
147 148 149 150 151 152 153 154 155 156 157 |
# File 'ext/view.c', line 147
static
VALUE ray_view_set_matrix(VALUE self, VALUE val) {
rb_check_frozen(self);
if (NIL_P(val))
say_view_set_matrix(ray_rb2view(self), NULL);
else
say_view_set_matrix(ray_rb2view(self), ray_rb2matrix(val));
return val;
}
|
#pretty_print(q) ⇒ Object
65 66 67 |
# File 'lib/ray/view.rb', line 65 def pretty_print(q) pretty_print_attributes q, ["center", "size", "matrix", "viewport"] end |
#rect ⇒ Ray::Rect
Returns Rect representing the part of the world that can be seen through this view.
44 45 46 47 48 49 |
# File 'lib/ray/view.rb', line 44 def rect size = self.size pos = self.center Ray::Rect[pos.x - size.x / 2, pos.y - size.y / 2, size.x, size.y] end |
#size ⇒ Object
69 70 71 72 |
# File 'ext/view.c', line 69 static VALUE ray_view_size(VALUE self) { return ray_vector2_to_rb(say_view_get_size(ray_rb2view(self))); } |
#size=(val) ⇒ Object
79 80 81 82 83 84 |
# File 'ext/view.c', line 79
static
VALUE ray_view_set_size(VALUE self, VALUE val) {
rb_check_frozen(self);
say_view_set_size(ray_rb2view(self), ray_convert_to_vector2(val));
return val;
}
|
#unzoom_by(value) ⇒ Object
Decreases zoom (making object appear smaller).
38 39 40 |
# File 'lib/ray/view.rb', line 38 def unzoom_by(value) self.size *= value end |
#viewport ⇒ Object
109 110 111 112 |
# File 'ext/view.c', line 109 static VALUE (VALUE self) { return ray_rect2rb((ray_rb2view(self))); } |
#viewport=(rect) ⇒ Object
123 124 125 126 127 128 |
# File 'ext/view.c', line 123
static
VALUE ray_view_set_viewport(VALUE self, VALUE val) {
rb_check_frozen(self);
say_view_set_viewport(ray_rb2view(self), ray_convert_to_rect(val));
return val;
}
|
#w ⇒ Object
53 |
# File 'lib/ray/view.rb', line 53 def w; size.w; end |
#w=(val) ⇒ Object
58 |
# File 'lib/ray/view.rb', line 58 def w=(val); self.size = [val, h]; end |
#x ⇒ Object
51 |
# File 'lib/ray/view.rb', line 51 def x; center.x; end |
#x=(val) ⇒ Object
56 |
# File 'lib/ray/view.rb', line 56 def x=(val); self.center = [val, y]; end |
#y ⇒ Object
52 |
# File 'lib/ray/view.rb', line 52 def y; center.y; end |
#y=(val) ⇒ Object
57 |
# File 'lib/ray/view.rb', line 57 def y=(val); self.center = [x, val]; end |
#zoom_by(value) ⇒ Object
Increases zoom (making object appear bigger). The center of the view and its viewport aren’t affected by this.
30 31 32 |
# File 'lib/ray/view.rb', line 30 def zoom_by(value) self.size /= value end |