fidgit 0.0.2alpha
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +8 -0
- data/.rspec +2 -0
- data/COPYING.txt +674 -0
- data/Gemfile +4 -0
- data/README.textile +138 -0
- data/Rakefile +38 -0
- data/config/default_schema.yml +180 -0
- data/examples/_all_examples.rb +9 -0
- data/examples/align_example.rb +56 -0
- data/examples/button_and_toggle_button_example.rb +27 -0
- data/examples/color_picker_example.rb +17 -0
- data/examples/color_well_example.rb +25 -0
- data/examples/combo_box_example.rb +24 -0
- data/examples/file_dialog_example.rb +42 -0
- data/examples/grid_packer_example.rb +29 -0
- data/examples/helpers/example_window.rb +17 -0
- data/examples/label_example.rb +17 -0
- data/examples/list_example.rb +23 -0
- data/examples/media/images/head_icon.png +0 -0
- data/examples/menu_pane_example.rb +27 -0
- data/examples/message_dialog_example.rb +65 -0
- data/examples/radio_button_example.rb +37 -0
- data/examples/readme_example.rb +32 -0
- data/examples/scroll_window_example.rb +49 -0
- data/examples/slider_example.rb +30 -0
- data/examples/splash_example.rb +42 -0
- data/examples/text_area_example.rb +28 -0
- data/fidgit.gemspec +28 -0
- data/lib/fidgit.rb +4 -0
- data/lib/fidgit/chingu_ext/window.rb +6 -0
- data/lib/fidgit/clipboard.rb +23 -0
- data/lib/fidgit/cursor.rb +38 -0
- data/lib/fidgit/elements/button.rb +68 -0
- data/lib/fidgit/elements/color_picker.rb +63 -0
- data/lib/fidgit/elements/color_well.rb +39 -0
- data/lib/fidgit/elements/combo_box.rb +85 -0
- data/lib/fidgit/elements/composite.rb +17 -0
- data/lib/fidgit/elements/container.rb +187 -0
- data/lib/fidgit/elements/element.rb +252 -0
- data/lib/fidgit/elements/file_browser.rb +152 -0
- data/lib/fidgit/elements/grid_packer.rb +219 -0
- data/lib/fidgit/elements/group.rb +66 -0
- data/lib/fidgit/elements/horizontal_packer.rb +12 -0
- data/lib/fidgit/elements/label.rb +77 -0
- data/lib/fidgit/elements/list.rb +47 -0
- data/lib/fidgit/elements/menu_pane.rb +149 -0
- data/lib/fidgit/elements/packer.rb +42 -0
- data/lib/fidgit/elements/radio_button.rb +86 -0
- data/lib/fidgit/elements/scroll_area.rb +75 -0
- data/lib/fidgit/elements/scroll_bar.rb +114 -0
- data/lib/fidgit/elements/scroll_window.rb +92 -0
- data/lib/fidgit/elements/slider.rb +119 -0
- data/lib/fidgit/elements/text_area.rb +351 -0
- data/lib/fidgit/elements/toggle_button.rb +67 -0
- data/lib/fidgit/elements/tool_tip.rb +35 -0
- data/lib/fidgit/elements/vertical_packer.rb +12 -0
- data/lib/fidgit/event.rb +99 -0
- data/lib/fidgit/gosu_ext/color.rb +123 -0
- data/lib/fidgit/history.rb +85 -0
- data/lib/fidgit/redirector.rb +83 -0
- data/lib/fidgit/schema.rb +123 -0
- data/lib/fidgit/selection.rb +106 -0
- data/lib/fidgit/standard_ext/hash.rb +21 -0
- data/lib/fidgit/states/dialog_state.rb +42 -0
- data/lib/fidgit/states/file_dialog.rb +24 -0
- data/lib/fidgit/states/gui_state.rb +301 -0
- data/lib/fidgit/states/message_dialog.rb +61 -0
- data/lib/fidgit/thumbnail.rb +29 -0
- data/lib/fidgit/version.rb +5 -0
- data/lib/fidgit/window.rb +19 -0
- data/media/images/arrow.png +0 -0
- data/media/images/file_directory.png +0 -0
- data/media/images/file_file.png +0 -0
- data/media/images/pixel.png +0 -0
- data/spec/fidgit/elements/helpers/helper.rb +3 -0
- data/spec/fidgit/elements/label_spec.rb +49 -0
- data/spec/fidgit/event_spec.rb +149 -0
- data/spec/fidgit/gosu_ext/color_spec.rb +130 -0
- data/spec/fidgit/gosu_ext/helpers/helper.rb +3 -0
- data/spec/fidgit/helpers/helper.rb +4 -0
- data/spec/fidgit/helpers/tex_play_helper.rb +9 -0
- data/spec/fidgit/history_spec.rb +144 -0
- data/spec/fidgit/redirector_spec.rb +78 -0
- data/spec/fidgit/schema_spec.rb +67 -0
- data/spec/fidgit/schema_test.yml +32 -0
- data/spec/fidgit/thumbnail_spec.rb +50 -0
- metadata +177 -0
@@ -0,0 +1,17 @@
|
|
1
|
+
require_relative 'helpers/example_window'
|
2
|
+
|
3
|
+
class ExampleState < Fidgit::GuiState
|
4
|
+
def initialize
|
5
|
+
super
|
6
|
+
|
7
|
+
pack :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
|
+
pack :vertical do
|
8
|
+
my_label = label "No color selected."
|
9
|
+
|
10
|
+
group do
|
11
|
+
pack :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
|
+
pack :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_size: 15 })
|
5
|
+
|
6
|
+
class ExampleState < Fidgit::GuiState
|
7
|
+
def initialize
|
8
|
+
super
|
9
|
+
|
10
|
+
container.background_color = Gosu::Color.rgb(50, 50, 50)
|
11
|
+
pack :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
|
+
pack :vertical do
|
12
|
+
label "Grid with #{FIXED_NUM} columns"
|
13
|
+
pack :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_size: rand(15) + 15, border_color: BORDER_COLOR, border_thickness: 1
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
label "Grid with #{FIXED_NUM} rows"
|
20
|
+
pack :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_size: 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,17 @@
|
|
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
|
+
pack :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
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
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
|
+
pack :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
|
Binary file
|
@@ -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
|
+
pack :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: "Ctrl-^-*"
|
14
|
+
separator
|
15
|
+
item "Lentils", :LENTILS, shortcut: "Alt-F15"
|
16
|
+
item "Tepid gruel", :GRUEL, shortcut: "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
|
+
pack :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
|
+
pack :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
|
+
pack :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
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require_relative "../lib/fidgit"
|
2
|
+
|
3
|
+
# Normally, you'd load this from the gem using:
|
4
|
+
# require 'fidgit'
|
5
|
+
|
6
|
+
class MyGame < Chingu::Window
|
7
|
+
def initialize
|
8
|
+
super(640, 480, false)
|
9
|
+
|
10
|
+
# To use the Fidgit features, a Fidgit::GuiState must be active.
|
11
|
+
push_game_state MyGuiState
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class MyGuiState < Fidgit::GuiState
|
16
|
+
def initialize
|
17
|
+
super
|
18
|
+
|
19
|
+
# Create a vertically packed section, centred on the window.
|
20
|
+
pack :vertical, align: :center do
|
21
|
+
# Create a label with a dark green background.
|
22
|
+
my_label = label "Hello world!", background_color: Gosu::Color.rgb(0, 100, 0)
|
23
|
+
|
24
|
+
# Create a button that, when clicked, changes the label text.
|
25
|
+
button("Goodbye", align_h: :center, tip: "Press me and be done with it!") do
|
26
|
+
my_label.text = "Goodbye cruel world!"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
MyGame.new.show
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require_relative 'helpers/example_window'
|
2
|
+
|
3
|
+
# Example for Button and ToggleButton
|
4
|
+
class ExampleState < Fidgit::GuiState
|
5
|
+
HEIGHT = 225
|
6
|
+
WIDTH = 140
|
7
|
+
def initialize
|
8
|
+
super
|
9
|
+
|
10
|
+
pack :vertical do
|
11
|
+
pack :horizontal do
|
12
|
+
[
|
13
|
+
[20, "All cheer the ascendancy of number "], # Should have both scrollers
|
14
|
+
[20, "#"], # Only has v-scroller.
|
15
|
+
[4, "#"], # No scrollers.
|
16
|
+
[4, "All cheer the ascendancy of number "], # Only has h-scroller
|
17
|
+
].each do |num_labels, text|
|
18
|
+
pack :vertical do
|
19
|
+
scroll_window(width: WIDTH, height: HEIGHT, background_color: Gosu::Color.rgb(0, 100, 0)) do
|
20
|
+
pack :vertical do
|
21
|
+
(1..num_labels).each do |i|
|
22
|
+
label "#{text}#{i}!"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
pack :horizontal, padding: 0 do
|
31
|
+
pack :vertical do
|
32
|
+
scroll_window(width: 300, height: 150) do
|
33
|
+
text_area(text: "Hello world! " * 19, width: 284)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
pack :vertical do
|
38
|
+
scroll_window(width: 300, height: 150) do
|
39
|
+
%w[One Two Three Four Five Six].each do |name|
|
40
|
+
toggle_button(name)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
ExampleWindow.new.show
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require_relative 'helpers/example_window'
|
2
|
+
|
3
|
+
class ExampleState < Fidgit::GuiState
|
4
|
+
def initialize
|
5
|
+
super
|
6
|
+
|
7
|
+
pack :vertical do
|
8
|
+
pack :horizontal do
|
9
|
+
# Discrete values (0..100)
|
10
|
+
slider = slider(width: 100, range: 0..5, value: 3) do |sender, value|
|
11
|
+
@discrete_label.text = "Discrete slider is at #{value}"
|
12
|
+
end
|
13
|
+
|
14
|
+
@discrete_label = label "Discrete slider is at #{slider.value}"
|
15
|
+
end
|
16
|
+
|
17
|
+
pack :horizontal do
|
18
|
+
# Continuous values (0.0..1.0)
|
19
|
+
|
20
|
+
slider = slider(width: 100, range: 0.0..100.0, value: 77.2) do |sender, value|
|
21
|
+
@continuous_label.text = "Continuous slider is at #{"%.03f" % value}%"
|
22
|
+
end
|
23
|
+
|
24
|
+
@continuous_label = label "Continuous slider is at #{"%.03f" % slider.value}%"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
ExampleWindow.new.show
|