Class: Ray::Target

Inherits:
Object
  • Object
show all
Defined in:
lib/ray/target.rb,
lib/ray/turtle.rb,
ext/target.c

Direct Known Subclasses

ImageTarget, Window

Instance Method Summary collapse

Instance Method Details

#[](x, y) ⇒ Ray::Color

Returns Color of the pixel at that position.

Parameters:

  • x (Integer)
  • y (Integer)

Returns:

  • (Ray::Color)

    Color of the pixel at that position



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

Clears the target in a given color. Should usually be called before drawing anything in a new frame.

Parameters:

  • color (Ray::Color)

    Color to clear the target with.



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;
}

#clipRay::Rect

Returns Part of the target that’s used by the view.

Returns:

  • (Ray::Rect)

    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_viewRay::View

Returns Default view of the target.

Returns:



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

Draws an object on the target.

Parameters:



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_currentObject

Makes a target become the current one. Not useful unless using OpenGL directly.

Raises:

  • If a context could not be created or made current. Would often mean the target was not initialized properly (e.g. window is not open)



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

Returns An image containing the pixels of that rect.

Parameters:

Returns:

  • (Ray::Image)

    An image containing the pixels of that rect.



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);
}

#shaderRay::Shader

Returns Shader used when drawing on this target.

Returns:

  • (Ray::Shader)

    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

#sizeRay::Vector2

Returns Size of the target, in pixels.

Returns:



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_imageRay::Image

Returns An image containing all the pixels of the target.

Returns:

  • (Ray::Image)

    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.

Returns:



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

#viewRay::View

Returns View currently used.

Returns:



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

Returns Viewport to set in the view.

Parameters:

Returns:

  • (Ray::Rect)

    Viewport to set in the view



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

Parameters:

Yields:

  • a block where the view has been changed



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