Class: SDL2::Point

Inherits:
Struct
  • Object
show all
Defined in:
lib/sdl2/point.rb

Class Method Summary collapse

Methods inherited from Struct

#==, create, #free, #initialize, release, #to_s, #update_members

Methods included from StructHelper

#member_readers, #member_writers

Constructor Details

This class inherits a constructor from SDL2::Struct

Class Method Details

.cast(something) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/sdl2/point.rb', line 10

def self.cast(something)
  if something.kind_of?(Array) and something.count == 2
    something.map!(&:to_i) 
    result = Point.new
    result.x, result.y = something
    return result
  else      
    return super
  end
end

.cast_array(somethings, count_something = nil) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/sdl2/point.rb', line 21

def self.cast_array(somethings, count_something = nil)
  
  # Convert Ruby arrays into Struct Arrays.
  if somethings.kind_of? Array 
    count_something = somethings.count if count_something.nil?
    
    raise "count_something > somethings.count" if count_something > somethings.count
    
    pointer = FFI::MemoryPointer.new(self, count_something)
    
    count_something.times do |idx|
      pointer[idx].update_members(somethings[idx])
    end
    
    somethings = pointer
  
    # If it is already a structure, then it is an array of 1, unless
    # someone defined a count, in which case we assume they know what they
    # are doing.
  elsif somethings.kind_of? self
        count_something = 1 if count_something.nil?
        
  else
    raise "#{self} cannot cast array from #{somethings.inspect}"
  end
  
  return somethings, count_something
end