Class: LifeGame::SideBar
- Inherits:
-
Gtk::VBox
- Object
- Gtk::VBox
- LifeGame::SideBar
- Defined in:
- lib/kaki-lifegame.rb
Instance Method Summary collapse
-
#initialize(field_area) ⇒ SideBar
constructor
A new instance of SideBar.
- #select_file(title, mode) ⇒ Object
- #set_box1 ⇒ Object
- #set_box2 ⇒ Object
- #set_box3 ⇒ Object
- #set_box4 ⇒ Object
- #set_box5 ⇒ Object
Constructor Details
#initialize(field_area) ⇒ SideBar
Returns a new instance of SideBar.
257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/kaki-lifegame.rb', line 257 def initialize(field_area) super() set_size_request(130, FieldArea::AreaH) @farea = field_area @edit_mode = true set_box1 set_box2 set_box3 set_box4 set_box5 end |
Instance Method Details
#select_file(title, mode) ⇒ Object
397 398 399 400 401 402 403 404 405 406 407 408 |
# File 'lib/kaki-lifegame.rb', line 397 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 ⇒ Object
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 |
# File 'lib/kaki-lifegame.rb', line 270 def set_box1 start_bt = Gtk::Button.new("開始") stop_bt = Gtk::Button.new("停止") step_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 l = Gtk::Label.new("") @farea.label = l box = Gtk::VBox.new pack_start(box, false, false, 0) box.pack_start(start_bt, false, false, 5) box.pack_start(stop_bt , false, false, 5) box.pack_start(step_bt , false, false, 5) box.pack_start(l, false, false, 5) box.pack_start(Gtk::HSeparator.new, false, false, 10) end |
#set_box2 ⇒ Object
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 |
# File 'lib/kaki-lifegame.rb', line 301 def set_box2 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, 5) box.pack_start(grid_bt , false, false, 5) box.pack_start(small_box , false, false, 5) box.pack_start(clear_bt , false, false, 5) box.pack_start(Gtk::HSeparator.new, false, false, 10) end |
#set_box3 ⇒ Object
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 |
# File 'lib/kaki-lifegame.rb', line 341 def set_box3 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, 5) box.pack_start(restore_bt, false, false, 5) box.pack_start(Gtk::HSeparator.new, false, false, 10) end |
#set_box4 ⇒ Object
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 |
# File 'lib/kaki-lifegame.rb', line 360 def set_box4 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) @farea.load_file(file_name) if file_name end end box = Gtk::VBox.new pack_start(box, false, false, 0) box.pack_start(save_bt, false, false, 5) box.pack_start(load_bt, false, false, 5) box.pack_start(Gtk::HSeparator.new, false, false, 10) end |
#set_box5 ⇒ Object
385 386 387 388 389 390 391 392 393 394 395 |
# File 'lib/kaki-lifegame.rb', line 385 def set_box5 close_bt = Gtk::Button.new("終了") close_bt.signal_connect("clicked") do Gtk.main_quit if @edit_mode end box = Gtk::VBox.new pack_start(box, false, false, 0) box.pack_start(close_bt, false, false, 5) end |