Class: Gosu::TexChunk

Inherits:
ImageData show all
Defined in:
lib/gosu_android/graphics/texChunk.rb

Instance Method Summary collapse

Methods inherited from ImageData

#gl_tex_info

Constructor Details

#initialize(graphics, queues, texture, x, y, w, h, padding) ⇒ TexChunk

Returns a new instance of TexChunk.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/gosu_android/graphics/texChunk.rb', line 6

def initialize(graphics, queues, texture, x, y, w, h, padding)
  @graphics = graphics
  @queues = queues
  @texture = texture
  #Define object destructor
  ObjectSpace.define_finalizer(self, Proc.new{@texture.finalize})
  @x = x
  @y = y
  @w = w
  @h = h
  @padding = padding
  @info = GLTexInfo.new
  @info.tex_name = @texture.tex_name
  #Force float division
  @info.left = @x.to_f / @texture.size
  @info.top = @y.to_f / @texture.size
  @info.right = (@x.to_f + @w) / @texture.size
  @info.bottom = (@y.to_f + @h) / @texture.size
end

Instance Method Details

#draw(x1, y1, c1, x2, y2, c2, x3, y3, c3, x4, y4, c4, z, mode) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/gosu_android/graphics/texChunk.rb', line 38

def draw( x1,  y1,  c1, x2,  y2,  c2, x3,  y3,  c3, x4,  y4,  c4, z, mode)
  op = @queues.op_pool.newDrawOp
  op.render_state.tex_name = @info.tex_name
  op.render_state.mode = mode

  if Gosu::reorder_coordinates_if_necessary(x1, y1, x2, y2, x3, y3, c3, x4, y4, c4)
    x3, y3, c3, x4, y4, c4 = x4, y4,c4, x3, y3, c3
  end
  op.vertices_or_block_index = 4
  op.vertices[0].set(x1, y1, c1)
  op.vertices[1].set(x2, y2, c2)
  op.vertices[2].set(x3, y3, c3)
  op.vertices[3].set(x4, y4, c4)

  op.left = @info.left
  op.top = @info.top
  op.right = @info.right
  op.bottom = @info.bottom

  op.z = z
  @queues.schedule_draw_op(op)
end

#finalizeObject



26
27
28
# File 'lib/gosu_android/graphics/texChunk.rb', line 26

def finalize
  @texture.free(@x - @padding, @y - @padding)
end

#glTexInfoObject



61
62
63
# File 'lib/gosu_android/graphics/texChunk.rb', line 61

def glTexInfo
  @info
end

#heightObject



34
35
36
# File 'lib/gosu_android/graphics/texChunk.rb', line 34

def height
  @h
end

#to_bitmapObject



65
# File 'lib/gosu_android/graphics/texChunk.rb', line 65

def to_bitmap; end

#widthObject



30
31
32
# File 'lib/gosu_android/graphics/texChunk.rb', line 30

def width
  @w
end