Class: Lotu::TextBox

Inherits:
Actor show all
Defined in:
lib/lotu/text_box.rb

Instance Attribute Summary

Attributes inherited from Actor

#angle, #center_x, #center_y, #color, #factor_x, #factor_y, #height, #image, #mode, #parent, #width, #x, #y, #z

Instance Method Summary collapse

Methods inherited from Actor

#adjust_width_and_height, #calc_zoom, #die, #draw_box, #draw_debug, #dt, #factor=, #parse_options, #rand_color, #set_gosu_image, #set_image

Methods included from Behavior

#behave_like, #inherited

Methods included from Helpers::Util

#class_debug_info, #instance_debug_info, #parse_cli_options

Constructor Details

#initialize(opts = {}) ⇒ TextBox

Returns a new instance of TextBox.



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/lotu/text_box.rb', line 5

def initialize(opts={})
  default_opts = {
    :size => 20
  }
  opts = default_opts.merge!(opts)
  super(opts)
  #TODO puede especificar a quién watchear y sus opciones de
  #dibujado en los parámetros
  @watch_list = []
  @size = opts[:size]
  @attached_to = opts[:attach_to]
  @hiding = false
end

Instance Method Details

#attach_to(actor) ⇒ Object



36
37
38
# File 'lib/lotu/text_box.rb', line 36

def attach_to(actor)
  @attached_to = actor
end

#drawObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/lotu/text_box.rb', line 48

def draw
  return if @hiding
  pos_y = 0
  @watch_list.each do |watched, opts|
    my_size = opts[:size] || @size
    my_color = opts[:color] || @color
    if watched.kind_of?(Proc)
      my_text = watched.call.to_s
    else
      my_text = watched.to_s
    end

    if my_text.is_a?(String)
      $lotu.default_font[my_size].draw(my_text, @x, @y + pos_y, @z, @factor_x, @factor_y, my_color)
      pos_y += my_size
    else
      my_text.each do |line|
        $lotu.default_font[my_size].draw(line, @x, @y + pos_y, @z, @factor_x, @factor_y, my_color)
        pos_y += my_size
      end
    end
  end
end

#hide!Object



19
20
21
# File 'lib/lotu/text_box.rb', line 19

def hide!
  @hiding = true
end

#show!Object



23
24
25
# File 'lib/lotu/text_box.rb', line 23

def show!
  @hiding = false
end

#toggle!Object



27
28
29
# File 'lib/lotu/text_box.rb', line 27

def toggle!
  @hiding = !@hiding
end

#updateObject



40
41
42
43
44
45
46
# File 'lib/lotu/text_box.rb', line 40

def update
  return if @hiding
  unless @attached_to.nil?
    @x = @attached_to.x + @attached_to.image.width / 2
    @y = @attached_to.y - @attached_to.image.height / 2
  end
end

#watch(subject, opts = {}) ⇒ Object Also known as: text



31
32
33
# File 'lib/lotu/text_box.rb', line 31

def watch(subject, opts={})
  @watch_list << [subject, opts]
end