Class: Miyako::ChoiceStruct

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

Constant Summary collapse

DIRECTION_LIST =
[:up, :down, :left, :right, :base]

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, #oh=, #ow, #ow=, #ox, #ox=, #oy, #oy=, #part_rect, #rect, #render_d, #render_xy, #render_xy_to, #show, #to_sprite, #to_unit, #update

Constructor Details

#initialize(*params) ⇒ ChoiceStruct

Returns a new instance of ChoiceStruct.


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

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->非描画)


31
32
33
# File 'lib/Miyako/API/choices.rb', line 31

def visible
  @visible
end

Instance Method Details

#arrow(hash) ⇒ Object

方向と移動先とを関連づける

hash

(方向)=>(移動先)の関係を持つハッシュ

ハッシュキーは、:up,:down,:left,:right,:baseの5つ

返却値

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


130
131
132
133
134
135
136
# File 'lib/Miyako/API/choices.rb', line 130

def arrow(hash)
  hash.each{|key, value|
    raise MiakoValueError, "illegal hash key!" unless DIRECTION_LIST.include?(key)
    self[key] = value
  }
  return self
end

#broad_rectObject

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

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

返却値

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


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

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])

47
48
49
50
51
# File 'lib/Miyako/API/choices.rb', line 47

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


83
84
85
86
87
# File 'lib/Miyako/API/choices.rb', line 83

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

#render_srcObject

:nodoc:


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

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


89
90
91
92
93
# File 'lib/Miyako/API/choices.rb', line 89

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

#resetObject


63
64
65
66
# File 'lib/Miyako/API/choices.rb', line 63

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

#startObject


53
54
55
56
# File 'lib/Miyako/API/choices.rb', line 53

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

#stopObject


58
59
60
61
# File 'lib/Miyako/API/choices.rb', line 58

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

#update_animationObject


68
69
70
71
# File 'lib/Miyako/API/choices.rb', line 68

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

#update_layout_positionObject

:nodoc:


41
42
43
44
45
# File 'lib/Miyako/API/choices.rb', line 41

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

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

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

返却値

自分自身を返す


98
99
100
101
102
# File 'lib/Miyako/API/choices.rb', line 98

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