Class: LifeGame::SideBar

Inherits:
Gtk::VBox
  • Object
show all
Defined in:
lib/kaki-lifegame.rb

Constant Summary collapse

MGN =
3
140

Instance Method Summary collapse

Constructor Details

#initialize(field_area, main_window) ⇒ SideBar

Returns a new instance of SideBar.



370
371
372
373
374
375
376
377
378
379
380
381
382
383
# 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

Instance Method Details

#change_window_size(size) ⇒ Object



570
571
572
# 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) ⇒ Object



574
575
576
# 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) ⇒ Object



578
579
580
581
582
583
584
585
586
587
588
589
# 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_box1Object



385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
# 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_box2Object



422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
# 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_box3Object



457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
# 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_box4Object



497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
# 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_box5Object



516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
# 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_box6Object



543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
# 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