Class: Miyako::ChoiceStruct

Inherits:
Struct
  • Object
show all
Includes:
Animation, Layout, SpriteBase
Defined in:
lib/Miyako/API/choices.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Layout

#add_snap_child, #bottom, #bottom!, #center, #center!, #centering, #centering!, #copy_layout, #delete_snap_child, #get_snap_children, #get_snap_sprite, #h, #include_snap_child?, #init_layout, #layout_dispose, #left, #left!, #middle, #middle!, #move, #move!, #move_to, #move_to!, #on_move, #outside_bottom, #outside_bottom!, #outside_left, #outside_left!, #outside_right, #outside_right!, #outside_top, #outside_top!, #pos, #rect, #relative_move_to, #relative_move_to!, #reset_snap, #right, #right!, #segment, #set_layout_size, #set_snap_children, #set_snap_sprite, #size, #snap, #top, #top!, #update_layout, #w, #x, #y

Methods included from Animation

[], []=, anim_hash, reset, start, stop, update, update_animation

Methods included from SpriteBase

#bitmap, #hide, #image_rect, #image_size, #oh, #ow, #ox, #oy, #part_rect, #rect, #render_xy, #render_xy_to, #show, #to_sprite, #to_unit, #update

Constructor Details

#initialize(*params) ⇒ ChoiceStruct

Returns a new instance of ChoiceStruct.



31
32
33
34
35
36
37
# File 'lib/Miyako/API/choices.rb', line 31

def initialize(*params)
  super(*params)
  init_layout
  @visible = true
  tsize = self.broad_rect.size
  set_layout_size(*tsize)
end

Instance Attribute Details

#visibleObject

レンダリングの可否(true->描画 false->非描画)



29
30
31
# File 'lib/Miyako/API/choices.rb', line 29

def visible
  @visible
end

Instance Method Details

#broad_rectObject

選択肢の最大の大きさを矩形で取得する

現在登録しているスプライトから最大の矩形(broad_rect)を求める

返却値

生成された矩形(Rect構造体のインスタンス)



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/Miyako/API/choices.rb', line 105

def broad_rect
  return self[0].rect if (self[1].nil? && self[2].nil?)
  list = [self[0]]
  list << self[1] if (self[1] && self[0] != self[1])
  list << self[2] if self[2]
  xx = []
  yy = []
  list.each{|ch|
    r = ch.rect
    xx << r.x
    yy << r.y
    xx << r.x + r.w
    yy << r.y + r.h
  }
  min_x, max_x = xx.minmax
  min_y, max_y = yy.minmax
  return Rect.new(min_x, min_y, max_x-min_x, max_y-min_y)
end

#process_sprites {|self[0]| ... } ⇒ Object

:nodoc:

Yields:

  • (self[0])


45
46
47
48
49
# File 'lib/Miyako/API/choices.rb', line 45

def process_sprites #:nodoc:
  yield(self[0])
  yield(self[1]) if self[1] && self[0] != self[1]
  yield(self[2]) if self[2]
end

#renderObject



81
82
83
84
85
# File 'lib/Miyako/API/choices.rb', line 81

def render
  return unless @visible
  return unless self[3].call
  render_src.render
end

#render_srcObject

:nodoc:



71
72
73
74
75
76
77
78
79
# File 'lib/Miyako/API/choices.rb', line 71

def render_src #:nodoc:
  sprite = self[0]
  if self[4]
    sprite = self[1] if (self[5] && self[1])
  elsif self[2]
    sprite = self[2]
  end
  return sprite
end

#render_to(dst) ⇒ Object



87
88
89
90
91
# File 'lib/Miyako/API/choices.rb', line 87

def render_to(dst)
  return unless @visible
  return unless self[3].call
  render_src..render_to(dst)
end

#resetObject



61
62
63
64
# File 'lib/Miyako/API/choices.rb', line 61

def reset
  return unless self[3].call
  process_sprites{|spr| spr.reset }
end

#startObject



51
52
53
54
# File 'lib/Miyako/API/choices.rb', line 51

def start
  return unless self[3].call
  process_sprites{|spr| spr.start }
end

#stopObject



56
57
58
59
# File 'lib/Miyako/API/choices.rb', line 56

def stop
  return unless self[3].call
  process_sprites{|spr| spr.stop }
end

#update_animationObject



66
67
68
69
# File 'lib/Miyako/API/choices.rb', line 66

def update_animation
  return unless self[3].call
  process_sprites{|spr| spr.update_animation }
end

#update_layout_positionObject

:nodoc:



39
40
41
42
43
# File 'lib/Miyako/API/choices.rb', line 39

def update_layout_position #:nodoc:
  self[0].move_to!(*@layout.pos)
  self[1].move_to!(*@layout.pos) if self[1] && self[0] != self[1]
  self[2].move_to!(*@layout.pos) if self[2]
end

#update_layout_sizeObject

レイアウト空間の大きさを更新する

新たにスプライトを登録したときに、全体の大きさをレイアウト空間の大きさとして更新する

返却値

自分自身を返す



96
97
98
99
100
# File 'lib/Miyako/API/choices.rb', line 96

def update_layout_size
  trect = self.broad_rect
  set_layout_size(*trect.size)
  self
end