colstrom-fidgit 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +8 -0
  3. data/.rspec +2 -0
  4. data/CHANGELOG.md +31 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +20 -0
  7. data/README.md +154 -0
  8. data/Rakefile +38 -0
  9. data/config/default_schema.yml +216 -0
  10. data/examples/_all_examples.rb +9 -0
  11. data/examples/align_example.rb +56 -0
  12. data/examples/button_and_toggle_button_example.rb +38 -0
  13. data/examples/color_picker_example.rb +17 -0
  14. data/examples/color_well_example.rb +25 -0
  15. data/examples/combo_box_example.rb +24 -0
  16. data/examples/file_dialog_example.rb +42 -0
  17. data/examples/grid_packer_example.rb +29 -0
  18. data/examples/helpers/example_window.rb +17 -0
  19. data/examples/label_example.rb +23 -0
  20. data/examples/list_example.rb +23 -0
  21. data/examples/media/images/head_icon.png +0 -0
  22. data/examples/menu_pane_example.rb +27 -0
  23. data/examples/message_dialog_example.rb +65 -0
  24. data/examples/radio_button_example.rb +37 -0
  25. data/examples/readme_example.rb +32 -0
  26. data/examples/scroll_window_example.rb +49 -0
  27. data/examples/slider_example.rb +34 -0
  28. data/examples/splash_example.rb +42 -0
  29. data/examples/text_area_example.rb +33 -0
  30. data/fidgit.gemspec +35 -0
  31. data/lib/fidgit.rb +51 -0
  32. data/lib/fidgit/chingu_ext/window.rb +6 -0
  33. data/lib/fidgit/cursor.rb +38 -0
  34. data/lib/fidgit/elements/button.rb +113 -0
  35. data/lib/fidgit/elements/color_picker.rb +63 -0
  36. data/lib/fidgit/elements/color_well.rb +39 -0
  37. data/lib/fidgit/elements/combo_box.rb +115 -0
  38. data/lib/fidgit/elements/composite.rb +17 -0
  39. data/lib/fidgit/elements/container.rb +210 -0
  40. data/lib/fidgit/elements/element.rb +298 -0
  41. data/lib/fidgit/elements/file_browser.rb +152 -0
  42. data/lib/fidgit/elements/grid.rb +227 -0
  43. data/lib/fidgit/elements/group.rb +64 -0
  44. data/lib/fidgit/elements/horizontal.rb +12 -0
  45. data/lib/fidgit/elements/image_frame.rb +65 -0
  46. data/lib/fidgit/elements/label.rb +85 -0
  47. data/lib/fidgit/elements/list.rb +47 -0
  48. data/lib/fidgit/elements/main_packer.rb +25 -0
  49. data/lib/fidgit/elements/menu_pane.rb +163 -0
  50. data/lib/fidgit/elements/packer.rb +42 -0
  51. data/lib/fidgit/elements/radio_button.rb +86 -0
  52. data/lib/fidgit/elements/scroll_area.rb +68 -0
  53. data/lib/fidgit/elements/scroll_bar.rb +128 -0
  54. data/lib/fidgit/elements/scroll_window.rb +83 -0
  55. data/lib/fidgit/elements/slider.rb +125 -0
  56. data/lib/fidgit/elements/text_area.rb +494 -0
  57. data/lib/fidgit/elements/text_line.rb +92 -0
  58. data/lib/fidgit/elements/toggle_button.rb +67 -0
  59. data/lib/fidgit/elements/tool_tip.rb +35 -0
  60. data/lib/fidgit/elements/vertical.rb +12 -0
  61. data/lib/fidgit/event.rb +159 -0
  62. data/lib/fidgit/gosu_ext/color.rb +136 -0
  63. data/lib/fidgit/gosu_ext/gosu_module.rb +25 -0
  64. data/lib/fidgit/history.rb +91 -0
  65. data/lib/fidgit/redirector.rb +83 -0
  66. data/lib/fidgit/schema.rb +123 -0
  67. data/lib/fidgit/selection.rb +106 -0
  68. data/lib/fidgit/standard_ext/hash.rb +21 -0
  69. data/lib/fidgit/states/dialog_state.rb +52 -0
  70. data/lib/fidgit/states/file_dialog.rb +24 -0
  71. data/lib/fidgit/states/gui_state.rb +331 -0
  72. data/lib/fidgit/states/message_dialog.rb +61 -0
  73. data/lib/fidgit/version.rb +5 -0
  74. data/lib/fidgit/window.rb +19 -0
  75. data/media/images/arrow.png +0 -0
  76. data/media/images/combo_arrow.png +0 -0
  77. data/media/images/file_directory.png +0 -0
  78. data/media/images/file_file.png +0 -0
  79. data/media/images/pixel.png +0 -0
  80. data/spec/fidgit/elements/helpers/helper.rb +3 -0
  81. data/spec/fidgit/elements/helpers/tex_play_helper.rb +9 -0
  82. data/spec/fidgit/elements/image_frame_spec.rb +69 -0
  83. data/spec/fidgit/elements/label_spec.rb +37 -0
  84. data/spec/fidgit/event_spec.rb +210 -0
  85. data/spec/fidgit/gosu_ext/color_spec.rb +130 -0
  86. data/spec/fidgit/gosu_ext/helpers/helper.rb +3 -0
  87. data/spec/fidgit/helpers/helper.rb +4 -0
  88. data/spec/fidgit/history_spec.rb +153 -0
  89. data/spec/fidgit/redirector_spec.rb +78 -0
  90. data/spec/fidgit/schema_spec.rb +67 -0
  91. data/spec/fidgit/schema_test.yml +32 -0
  92. metadata +320 -0
@@ -0,0 +1,9 @@
1
+ # Run all examples, one after the other
2
+ require_relative 'helpers/example_window'
3
+
4
+
5
+ examples = Dir.glob(File.join(File.dirname(__FILE__), "*.rb")) - [__FILE__]
6
+ examples.each_with_index do |file_name, index|
7
+ ENV['FIDGIT_EXAMPLES_TEXT'] = "[#{index + 1} of #{examples.size + 1}]"
8
+ `ruby #{file_name}`
9
+ end
@@ -0,0 +1,56 @@
1
+ require_relative 'helpers/example_window'
2
+
3
+ # Change font and labels in the schema.
4
+ Fidgit::Element.schema.merge_elements!(Element: { font_height: 24 }, Label: { background_color: "?dark_blue" })
5
+
6
+ class ExampleState < Fidgit::GuiState
7
+ ROW_BACKGROUND = Gosu::Color.rgb(0, 100, 0)
8
+ CELL_BACKGROUND = Gosu::Color.rgb(100, 0, 0)
9
+ OUTER_BACKGROUND = Gosu::Color.rgb(100, 0, 100)
10
+
11
+ def initialize
12
+ super
13
+
14
+ vertical align: :center, background_color: OUTER_BACKGROUND do
15
+ label "h => align_h, v => align_v", align_h: :center
16
+
17
+ grid num_columns: 4, align: :center, cell_background_color: CELL_BACKGROUND, background_color: ROW_BACKGROUND do
18
+ label "xxx"
19
+ label "h fill", align_h: :fill
20
+ label "h right", align_h: :right
21
+ label "h center", align_h: :center
22
+
23
+
24
+ vertical do
25
+ label "xxx"
26
+ label "xxx"
27
+ end
28
+ label "v fill", align_v: :fill
29
+ label "v center", align_v: :center
30
+ label "v bottom", align_v: :bottom
31
+
32
+ vertical align_h: :center do
33
+ label "h center"
34
+ label "h center"
35
+ end
36
+ label "top right", align: [:top, :left]
37
+ label "bottom left", align_h: :left, align_v: :bottom
38
+ label "h/v fill", align: :fill
39
+
40
+ label ""
41
+ label "bottom right", align_h: :right, align_v: :bottom
42
+ label "bottom center", align_h: :center, align_v: :bottom
43
+ vertical align_h: :right do
44
+ label "h right"
45
+ label "h right"
46
+ end
47
+
48
+ label "Blah, bleh!"
49
+ label "Yada, yada, yada"
50
+ label "Bazingo by jingo!"
51
+ end
52
+ end
53
+ end
54
+ end
55
+
56
+ ExampleWindow.new.show
@@ -0,0 +1,38 @@
1
+ require_relative 'helpers/example_window'
2
+
3
+ # Example for Button and ToggleButton
4
+ class ExampleState < Fidgit::GuiState
5
+ def initialize
6
+ super
7
+
8
+ vertical do
9
+ my_label = label "Label", tip: "I'm a label"
10
+
11
+ buttons = []
12
+
13
+ # A plain button, with some text on it.
14
+ buttons << button("Button", tip: "I'm a button; press me!", shortcut: :auto) do
15
+ my_label.text = "Pressed the button!"
16
+ end
17
+
18
+ # Buttons with icons in each possible positions.
19
+ [:left, :right, :top, :bottom].each do |position|
20
+ buttons << button("Icon at #{position}", icon: Gosu::Image["head_icon.png"], icon_position: position, icon_options: { factor: 2 }, tip: "I'm a button; press me!", shortcut: :auto) do
21
+ my_label.text = "Pressed the button (icon to #{position})!"
22
+ end
23
+ end
24
+
25
+ # A toggling button.
26
+ buttons << toggle_button("ToggleButton", tip: "I'm a button that toggles", shortcut: :o) do |sender, value|
27
+ my_label.text = "Turned the toggle button #{value ? "on" : "off"}!"
28
+ end
29
+
30
+ # A toggle-button that controls whether all the other buttons are enabled.
31
+ toggle_button("Enable other two buttons", value: true) do |sender, value|
32
+ buttons.each {|button| button.enabled = value }
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ ExampleWindow.new.show
@@ -0,0 +1,17 @@
1
+ require_relative 'helpers/example_window'
2
+
3
+ class ExampleState < Fidgit::GuiState
4
+ def initialize
5
+ super
6
+
7
+ vertical do
8
+ my_label = label 'No color picked'
9
+
10
+ color_picker(width: 100) do |sender, color|
11
+ my_label.text = color.to_s
12
+ end
13
+ end
14
+ end
15
+ end
16
+
17
+ ExampleWindow.new.show
@@ -0,0 +1,25 @@
1
+ require_relative 'helpers/example_window'
2
+
3
+ class ExampleState < Fidgit::GuiState
4
+ def initialize
5
+ super
6
+
7
+ vertical do
8
+ my_label = label "No color selected."
9
+
10
+ group do
11
+ grid num_columns: 15, padding: 0, spacing: 4 do
12
+ 150.times do
13
+ color_well(color: Gosu::Color.rgb(rand(255), rand(255), rand(255)))
14
+ end
15
+ end
16
+
17
+ subscribe :changed do |sender, color|
18
+ my_label.text = color.to_s
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ ExampleWindow.new.show
@@ -0,0 +1,24 @@
1
+ require_relative 'helpers/example_window'
2
+
3
+ # Example for Button and ToggleButton
4
+ class ExampleState < Fidgit::GuiState
5
+ def initialize
6
+ super
7
+
8
+ vertical do
9
+ my_label = label "Label", tip: "I'm a label"
10
+
11
+ combo_box(value: 1, tip: "I'm a combo box; press me and make a selection!") do
12
+ subscribe :changed do |sender, value|
13
+ my_label.text = "Chose #{value}!"
14
+ end
15
+
16
+ item "One", 1
17
+ item "Two", 2
18
+ item "Three", 3
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+ ExampleWindow.new.show
@@ -0,0 +1,42 @@
1
+ require_relative 'helpers/example_window'
2
+
3
+
4
+ Fidgit::Element.schema.merge_elements!(Element: { font_height: 15 })
5
+
6
+ class ExampleState < Fidgit::GuiState
7
+ def initialize
8
+ super
9
+
10
+ container.background_color = Gosu::Color.rgb(50, 50, 50)
11
+ vertical align: :center do
12
+ full_base_directory = ''
13
+ restricted_base_directory = File.expand_path(File.join(__FILE__, '..', '..'))
14
+ directory = File.join(restricted_base_directory, 'media', 'images')
15
+
16
+ my_label = label "No files are actually loaded or saved by this example"
17
+ button("Load...(limited path access)") do
18
+ file_dialog(:open, base_directory: restricted_base_directory, directory: directory, pattern: "*.png") do |result, file|
19
+ case result
20
+ when :open
21
+ my_label.text = "Loaded #{file}"
22
+ when :cancel
23
+ my_label.text = "Loading cancelled"
24
+ end
25
+ end
26
+ end
27
+
28
+ button("Save...(unrestricted path access)") do
29
+ file_dialog(:save, base_directory: full_base_directory, directory: directory, pattern: "*.png") do |result, file|
30
+ case result
31
+ when :save
32
+ my_label.text = "Saved #{file}"
33
+ when :cancel
34
+ my_label.text = "Save cancelled"
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+ ExampleWindow.new.show
@@ -0,0 +1,29 @@
1
+ require_relative 'helpers/example_window'
2
+
3
+ class ExampleState < Fidgit::GuiState
4
+ BORDER_COLOR = Gosu::Color.rgb(255, 0, 0)
5
+ FIXED_NUM = 5
6
+ NUM_CELLS = 17
7
+
8
+ def initialize
9
+ super
10
+
11
+ vertical do
12
+ label "Grid with #{FIXED_NUM} columns"
13
+ grid num_columns: FIXED_NUM, border_color: BORDER_COLOR, cell_border_color: Gosu::Color.rgba(0, 255, 0, 255), cell_border_thickness: 1 do
14
+ NUM_CELLS.times do |i|
15
+ label "Cell #{i}", font_height: rand(15) + 15, border_color: BORDER_COLOR, border_thickness: 1
16
+ end
17
+ end
18
+
19
+ label "Grid with #{FIXED_NUM} rows"
20
+ grid num_rows: FIXED_NUM, border_color: BORDER_COLOR, cell_background_color: Gosu::Color.rgba(0, 100, 100, 255) do
21
+ NUM_CELLS.times do |i|
22
+ label "Cell #{i}", font_height: rand(15) + 15, border_color: BORDER_COLOR, border_thickness: 1
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ ExampleWindow.new.show
@@ -0,0 +1,17 @@
1
+ require_relative '../../lib/fidgit'
2
+
3
+ media_dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'media'))
4
+ Gosu::Image.autoload_dirs << File.join(media_dir, 'images')
5
+ Gosu::Sample.autoload_dirs << File.join(media_dir, 'samples')
6
+ Gosu::Font.autoload_dirs << File.join(media_dir, 'fonts')
7
+
8
+ class ExampleWindow < Chingu::Window
9
+ def initialize(options = {})
10
+ super(640, 480, false)
11
+
12
+ on_input(:escape) { close }
13
+
14
+ caption = "#{File.basename($0).chomp(".rb").tr('_', ' ')} #{ENV['FIDGIT_EXAMPLES_TEXT']}"
15
+ push_game_state ExampleState
16
+ end
17
+ end
@@ -0,0 +1,23 @@
1
+ require_relative 'helpers/example_window'
2
+
3
+ # Labels can have text and/or icons.
4
+ class ExampleState < Fidgit::GuiState
5
+ def initialize
6
+ super
7
+
8
+ vertical background_color: Gosu::Color.rgb(255, 0, 0) do
9
+ label "Hello!", tip: 'A label with text'
10
+ label "Hello!", icon: Gosu::Image["head_icon.png"], tip: 'A label with text & icon'
11
+ label '', icon: Gosu::Image["head_icon.png"], tip: 'A label with just icon'
12
+ label '', background_color: Gosu::Color.rgb(0, 255, 0), tip: 'No text or icon'
13
+ end
14
+
15
+ vertical do
16
+ label ":left justification", width: 400, background_color: Gosu::Color.rgb(0, 100, 0), justify: :left, tip: 'A label with text'
17
+ label ":right justification", width: 400, background_color: Gosu::Color.rgb(0, 100, 0), justify: :right, tip: 'A label with text'
18
+ label ":center justification", width: 400, background_color: Gosu::Color.rgb(0, 100, 0), justify: :center, tip: 'A label with text'
19
+ end
20
+ end
21
+ end
22
+
23
+ ExampleWindow.new.show
@@ -0,0 +1,23 @@
1
+ require_relative 'helpers/example_window'
2
+
3
+ # Labels can have text and/or icons.
4
+ class ExampleState < Fidgit::GuiState
5
+ def initialize
6
+ super
7
+
8
+ vertical do
9
+ my_label = label "No clicky"
10
+
11
+ list do
12
+ item "chunky bacon", :CHUNKYBACON, tip: "You prefer Chunky Bacon, don't you?"
13
+ item "lentils", :LENTILS, tip: "Lentils? Well, I suppose someone has to like them"
14
+
15
+ subscribe :changed do |sender, value|
16
+ my_label.text = "I like #{value} more than anything in the world!"
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ ExampleWindow.new.show
@@ -0,0 +1,27 @@
1
+ require_relative 'helpers/example_window'
2
+
3
+ # Labels can have text and/or icons.
4
+ class ExampleState < Fidgit::GuiState
5
+ def initialize
6
+ super
7
+
8
+ vertical do
9
+ my_label = label "Right click to open context menu"
10
+
11
+ my_label.subscribe :released_right_mouse_button do
12
+ menu do
13
+ item "Chunky bacon", :CHUNKY_BACON, shortcut_text: "Ctrl-^-*"
14
+ separator
15
+ item "Lentils", :LENTILS, shortcut_text: "Alt-F15"
16
+ item "Tepid gruel", :GRUEL, shortcut_text: "CenterMeta"
17
+
18
+ subscribe :selected do |sender, value|
19
+ my_label.text = "I like #{value} more than anything. Mmmm!"
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+ ExampleWindow.new.show
@@ -0,0 +1,65 @@
1
+ require_relative 'helpers/example_window'
2
+
3
+ # Example for Button and ToggleButton
4
+ class ExampleState < Fidgit::GuiState
5
+ def initialize
6
+ super
7
+
8
+ vertical do
9
+ my_label = label "Why not open a dialog? You know you want to!", tip: "I'm a label"
10
+
11
+ button("Open an ok message dialog") do
12
+ message "System shutdown immanent"
13
+ end
14
+
15
+ button("Open an ok/cancel message dialog") do
16
+ message("Really 'rm -rf .'?", type: :ok_cancel) do |result|
17
+ my_label.text = case result
18
+ when :ok then "All your base are belong to us!"
19
+ when :cancel then "Cancelled"
20
+ end
21
+ end
22
+ end
23
+
24
+ button("Open a yes/no message dialog") do
25
+ message("Do you like any sorts of cheese? Even Government cheese counts, you know!", type: :yes_no, yes_text: "Yay!", no_text: "Nay!") do |result|
26
+ my_label.text = case result
27
+ when :yes then "You like cheese"
28
+ when :no then "You don't like cheese"
29
+ end
30
+ end
31
+ end
32
+
33
+ button("Open a yes/no/cancel message dialog") do
34
+ message("Do you know what you are doing?", type: :yes_no_cancel) do |result|
35
+ my_label.text = case result
36
+ when :yes then "I'm not convinced you know what you are doing"
37
+ when :no then "At least you are aware of your own shortcomings"
38
+ when :cancel then "Don't avoid the question!"
39
+ end
40
+ end
41
+ end
42
+
43
+ button("Open quit/cancel message dialog") do
44
+ message("Really leave us?", type: :quit_cancel) do |result|
45
+ my_label.text = case result
46
+ when :quit then "Quit! Bye!"
47
+ when :cancel then "Oh, you are staying? Yay!"
48
+ end
49
+ end
50
+ end
51
+
52
+ button("Open quit/save/cancel message dialog") do
53
+ message("You have unsaved data.\nSave before quitting?", type: :quit_save_cancel) do |result|
54
+ my_label.text = case result
55
+ when :quit then "File discarded and quit"
56
+ when :save then "File saved and quit"
57
+ when :cancel then "Nothing happened. You should be more committed"
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
64
+
65
+ ExampleWindow.new.show
@@ -0,0 +1,37 @@
1
+ require_relative 'helpers/example_window'
2
+
3
+ class ExampleState < Fidgit::GuiState
4
+ def initialize
5
+ super
6
+
7
+ vertical do
8
+ my_label = label "No button selected"
9
+
10
+ button("Deselect") do
11
+ @group.value = nil
12
+ end
13
+
14
+ button("Select #7") do
15
+ @group.value = 7
16
+ end
17
+
18
+ @group = group do
19
+ grid num_columns: 5, padding: 0 do
20
+ 15.times do |i|
21
+ radio_button "##{i}", i, width: 60
22
+ end
23
+ end
24
+
25
+ subscribe :changed do |sender, value|
26
+ my_label.text = if value
27
+ "Button #{value.to_s} selected"
28
+ else
29
+ "No button selected"
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+ ExampleWindow.new.show