class LifeGame::SideBar

Constants

MGN

Public Class Methods

new(field_area, main_window) click to toggle source
Calls superclass method
# File lib/kaki-lifegame.rb, line 370
def initialize(field_area, main_window)
  super()
  set_size_request(SideBar_W, field_area.areah)
  @farea = field_area
  @mainw = main_window
  @edit_mode = true
  
  set_box1
  set_box2
  set_box3
  set_box4
  set_box5
  set_box6
end

Public Instance Methods

change_window_size(size) click to toggle source
# File lib/kaki-lifegame.rb, line 570
def change_window_size(size)
  main_window_change(@farea.change_window_size(size))
end
main_window_change(is_change) click to toggle source
# File lib/kaki-lifegame.rb, line 574
def main_window_change(is_change)
  @mainw.set_size_request(@farea.areaw + SideBar_W, @farea.areah) if is_change
end
select_file(title, mode) click to toggle source
# File lib/kaki-lifegame.rb, line 578
def select_file(title, mode)
  file_name = nil
  dialog = Gtk::FileChooserDialog.new(title,
    nil, mode, nil,
    [Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_CANCEL],
    [Gtk::Stock::OPEN  , Gtk::Dialog::RESPONSE_ACCEPT])
  if dialog.run == Gtk::Dialog::RESPONSE_ACCEPT
    file_name = dialog.filename
  end
  dialog.destroy
  file_name
end
set_box1() click to toggle source
# File lib/kaki-lifegame.rb, line 385
def set_box1
  start_bt = Gtk::Button.new("開始")
  stop_bt  = Gtk::Button.new("停止")
  step_bt  = Gtk::Button.new("1ステップ進める")
  back_bt  = Gtk::Button.new("1ステップ戻る")
  
  start_bt.signal_connect("clicked") do
    @edit_mode = false
    @farea.time_goes = true
  end
  
  stop_bt.signal_connect("clicked") do
    @edit_mode = true
    @farea.time_goes = false
  end
  
  step_bt.signal_connect("clicked") do
    @farea.go_on_one_step if @edit_mode
  end
  
  back_bt.signal_connect("clicked") do
    @farea.back if @edit_mode
  end
  
  l = Gtk::Label.new("")
  @farea.label1 = l
  
  box = Gtk::VBox.new
  pack_start(box, false, false, 0)
  box.pack_start(start_bt, false, false, MGN)
  box.pack_start(stop_bt , false, false, MGN)
  box.pack_start(step_bt , false, false, MGN)
  box.pack_start(back_bt , false, false, MGN)
  box.pack_start(l, false, false, MGN)
  box.pack_start(Gtk::HSeparator.new, false, false, 5)
end
set_box2() click to toggle source
# File lib/kaki-lifegame.rb, line 422
def set_box2
  arrow1 = Gtk::Arrow.new(Gtk::Arrow::LEFT , Gtk::SHADOW_IN)
  arrow2 = Gtk::Arrow.new(Gtk::Arrow::RIGHT, Gtk::SHADOW_IN)
  
  l1 = Gtk::Label.new("ウェイト")
  left_arrow_bt  = Gtk::Button.new
  right_arrow_bt = Gtk::Button.new
  l2 = Gtk::Label.new("")
  
  @farea.label2 = l2
  @farea.show_wait_time
  
  left_arrow_bt.signal_connect("clicked") do
    @farea.slower
  end
  
  right_arrow_bt.signal_connect("clicked") do
    @farea.faster
  end
  
  left_arrow_bt .add(arrow1)
  right_arrow_bt.add(arrow2)
  
  small_box = Gtk::HBox.new
  small_box.pack_start(left_arrow_bt , true, true, 1)
  small_box.pack_start(right_arrow_bt, true, true, 1)
  
  box = Gtk::VBox.new
  pack_start(box, false, false, 0)
  box.pack_start(l1       , false, false, MGN)
  box.pack_start(small_box, false, false, MGN)
  box.pack_start(l2       , false, false, MGN)
  box.pack_start(Gtk::HSeparator.new, false, false, 5)
end
set_box3() click to toggle source
# File lib/kaki-lifegame.rb, line 457
def set_box3
  scatter_bt = Gtk::Button.new("ばらまく")
  grid_bt    = Gtk::Button.new("格子")
  green_bt   = Gtk::Button.new("緑色")
  orange_bt  = Gtk::Button.new("橙色")
  clear_bt   = Gtk::Button.new("全クリア")
  
  scatter_bt.signal_connect("clicked") do
    @farea.scatter if @edit_mode
  end
  
  grid_bt.signal_connect("clicked") do
    @farea.grid if @edit_mode
  end
  
  green_bt.signal_connect("clicked") do
    @farea.set_cell_color(:green) if @edit_mode
  end
  
  orange_bt.signal_connect("clicked") do
    @farea.set_cell_color(:orange) if @edit_mode
  end
  
  clear_bt.signal_connect("clicked") do
    @farea.clear if @edit_mode
  end
  
  small_box = Gtk::HBox.new
  small_box.pack_start(green_bt , true, true, 1)
  small_box.pack_start(orange_bt, true, true, 1)
  
  box = Gtk::VBox.new
  pack_start(box, false, false, 0)
  box.pack_start(scatter_bt, false, false, MGN)
  box.pack_start(grid_bt   , false, false, MGN)
  box.pack_start(small_box , false, false, MGN)
  box.pack_start(clear_bt  , false, false, MGN)
  box.pack_start(Gtk::HSeparator.new, false, false, 5)
end
set_box4() click to toggle source
# File lib/kaki-lifegame.rb, line 497
def set_box4
  preserve_bt = Gtk::Button.new("一時保存")
  restore_bt  = Gtk::Button.new("復帰")
  
  preserve_bt.signal_connect("clicked") do
    @farea.preserve if @edit_mode
  end
  
  restore_bt.signal_connect("clicked") do
    @farea.restore if @edit_mode
  end
  
  box = Gtk::VBox.new
  pack_start(box, false, false, 0)
  box.pack_start(preserve_bt, false, false, MGN)
  box.pack_start(restore_bt , false, false, MGN)
  box.pack_start(Gtk::HSeparator.new, false, false, 5)
end
set_box5() click to toggle source
# File lib/kaki-lifegame.rb, line 516
def set_box5
  save_bt = Gtk::Button.new("ファイルに保存")
  load_bt = Gtk::Button.new("ファイルの読み込み")
  
  save_bt.signal_connect("clicked") do
    if @edit_mode
      file_name = select_file("Save File", Gtk::FileChooser::ACTION_SAVE)
      @farea.save_file(file_name) if file_name
    end
  end
  
  load_bt.signal_connect("clicked") do
    if @edit_mode
      file_name = select_file("Load File", Gtk::FileChooser::ACTION_OPEN)
      if file_name
        main_window_change(@farea.load_file(file_name))
      end
    end
  end
  
  box = Gtk::VBox.new
  pack_start(box, false, false, 0)
  box.pack_start(save_bt, false, false, MGN)
  box.pack_start(load_bt, false, false, MGN)
  box.pack_start(Gtk::HSeparator.new, false, false, MGN)
end
set_box6() click to toggle source
# File lib/kaki-lifegame.rb, line 543
def set_box6
  large_bt = Gtk::Button.new("大")
  small_bt = Gtk::Button.new("小")
  close_bt = Gtk::Button.new("終了")
  
  large_bt.signal_connect("clicked") do
    change_window_size(:large) if @edit_mode
  end
  
  small_bt.signal_connect("clicked") do
    change_window_size(:small) if @edit_mode
  end
  
  close_bt.signal_connect("clicked") do
    Gtk.main_quit if @edit_mode
  end
  
  small_box = Gtk::HBox.new
  small_box.pack_start(large_bt, true, true, 1)
  small_box.pack_start(small_bt, true, true, 1)
  
  box = Gtk::VBox.new
  pack_start(box, false, false, 0)
  box.pack_start(small_box, false, false, MGN)
  box.pack_start(close_bt , false, false, MGN)
end