fidgit 0.0.2alpha

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. data/.gitignore +8 -0
  2. data/.rspec +2 -0
  3. data/COPYING.txt +674 -0
  4. data/Gemfile +4 -0
  5. data/README.textile +138 -0
  6. data/Rakefile +38 -0
  7. data/config/default_schema.yml +180 -0
  8. data/examples/_all_examples.rb +9 -0
  9. data/examples/align_example.rb +56 -0
  10. data/examples/button_and_toggle_button_example.rb +27 -0
  11. data/examples/color_picker_example.rb +17 -0
  12. data/examples/color_well_example.rb +25 -0
  13. data/examples/combo_box_example.rb +24 -0
  14. data/examples/file_dialog_example.rb +42 -0
  15. data/examples/grid_packer_example.rb +29 -0
  16. data/examples/helpers/example_window.rb +17 -0
  17. data/examples/label_example.rb +17 -0
  18. data/examples/list_example.rb +23 -0
  19. data/examples/media/images/head_icon.png +0 -0
  20. data/examples/menu_pane_example.rb +27 -0
  21. data/examples/message_dialog_example.rb +65 -0
  22. data/examples/radio_button_example.rb +37 -0
  23. data/examples/readme_example.rb +32 -0
  24. data/examples/scroll_window_example.rb +49 -0
  25. data/examples/slider_example.rb +30 -0
  26. data/examples/splash_example.rb +42 -0
  27. data/examples/text_area_example.rb +28 -0
  28. data/fidgit.gemspec +28 -0
  29. data/lib/fidgit.rb +4 -0
  30. data/lib/fidgit/chingu_ext/window.rb +6 -0
  31. data/lib/fidgit/clipboard.rb +23 -0
  32. data/lib/fidgit/cursor.rb +38 -0
  33. data/lib/fidgit/elements/button.rb +68 -0
  34. data/lib/fidgit/elements/color_picker.rb +63 -0
  35. data/lib/fidgit/elements/color_well.rb +39 -0
  36. data/lib/fidgit/elements/combo_box.rb +85 -0
  37. data/lib/fidgit/elements/composite.rb +17 -0
  38. data/lib/fidgit/elements/container.rb +187 -0
  39. data/lib/fidgit/elements/element.rb +252 -0
  40. data/lib/fidgit/elements/file_browser.rb +152 -0
  41. data/lib/fidgit/elements/grid_packer.rb +219 -0
  42. data/lib/fidgit/elements/group.rb +66 -0
  43. data/lib/fidgit/elements/horizontal_packer.rb +12 -0
  44. data/lib/fidgit/elements/label.rb +77 -0
  45. data/lib/fidgit/elements/list.rb +47 -0
  46. data/lib/fidgit/elements/menu_pane.rb +149 -0
  47. data/lib/fidgit/elements/packer.rb +42 -0
  48. data/lib/fidgit/elements/radio_button.rb +86 -0
  49. data/lib/fidgit/elements/scroll_area.rb +75 -0
  50. data/lib/fidgit/elements/scroll_bar.rb +114 -0
  51. data/lib/fidgit/elements/scroll_window.rb +92 -0
  52. data/lib/fidgit/elements/slider.rb +119 -0
  53. data/lib/fidgit/elements/text_area.rb +351 -0
  54. data/lib/fidgit/elements/toggle_button.rb +67 -0
  55. data/lib/fidgit/elements/tool_tip.rb +35 -0
  56. data/lib/fidgit/elements/vertical_packer.rb +12 -0
  57. data/lib/fidgit/event.rb +99 -0
  58. data/lib/fidgit/gosu_ext/color.rb +123 -0
  59. data/lib/fidgit/history.rb +85 -0
  60. data/lib/fidgit/redirector.rb +83 -0
  61. data/lib/fidgit/schema.rb +123 -0
  62. data/lib/fidgit/selection.rb +106 -0
  63. data/lib/fidgit/standard_ext/hash.rb +21 -0
  64. data/lib/fidgit/states/dialog_state.rb +42 -0
  65. data/lib/fidgit/states/file_dialog.rb +24 -0
  66. data/lib/fidgit/states/gui_state.rb +301 -0
  67. data/lib/fidgit/states/message_dialog.rb +61 -0
  68. data/lib/fidgit/thumbnail.rb +29 -0
  69. data/lib/fidgit/version.rb +5 -0
  70. data/lib/fidgit/window.rb +19 -0
  71. data/media/images/arrow.png +0 -0
  72. data/media/images/file_directory.png +0 -0
  73. data/media/images/file_file.png +0 -0
  74. data/media/images/pixel.png +0 -0
  75. data/spec/fidgit/elements/helpers/helper.rb +3 -0
  76. data/spec/fidgit/elements/label_spec.rb +49 -0
  77. data/spec/fidgit/event_spec.rb +149 -0
  78. data/spec/fidgit/gosu_ext/color_spec.rb +130 -0
  79. data/spec/fidgit/gosu_ext/helpers/helper.rb +3 -0
  80. data/spec/fidgit/helpers/helper.rb +4 -0
  81. data/spec/fidgit/helpers/tex_play_helper.rb +9 -0
  82. data/spec/fidgit/history_spec.rb +144 -0
  83. data/spec/fidgit/redirector_spec.rb +78 -0
  84. data/spec/fidgit/schema_spec.rb +67 -0
  85. data/spec/fidgit/schema_test.yml +32 -0
  86. data/spec/fidgit/thumbnail_spec.rb +50 -0
  87. metadata +177 -0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in fidgit.gemspec
4
+ gemspec
@@ -0,0 +1,138 @@
1
+ h1. Fidgit
2
+
3
+ Fidgit is a GUI framework built on "Gosu":http://libgosu.org/ and "Chingu":http://ippa.se/chingu
4
+
5
+
6
+ h2. Description
7
+
8
+ The API is inspired by "Shoes":http://shoesrb.com/, but since Shoes is very simplistic, the level of functionality is
9
+ based around "FXRuby":http://www.fxruby.org/ and other GUI APIs.
10
+ Fidgit was originally developed as a part of the Sidney game, but as it got more complex, it was obvious it would be
11
+ useful to separate them.
12
+
13
+ _WARNING: THIS PROJECT IS IN EARLY ALPHA DEVELOPMENT AND THE API IS LIABLE TO CONTINUOUS CHANGE AND IT IS QUITE UNSTABLE!_
14
+
15
+ Read the Yard documentation at "rubydoc.info":http://rubydoc.info/github/Spooner/fidgit/master
16
+
17
+ h2. Aim
18
+
19
+ Fidgit aims to be a toolkit which will provide the building blocks to quickly create a GUI either for a GUI-based game
20
+ or for options screens and menus within a regular Gosu game.
21
+
22
+ h2. License
23
+
24
+ GPL v3 (see COPYING.txt)
25
+
26
+ h2. Requirements
27
+
28
+ * Ruby 1.9.2 (sorry, I'm lazy!).
29
+ * Gosu gem 0.7.27.1 ("gem install gosu")
30
+ ** "Installing Gosu dependencies on Linux":http://code.google.com/p/gosu/wiki/GettingStartedOnLinux (On Win32 and OS X there are binary gems available)
31
+ * Chingu gem 0.9rc4 ("gem install chingu --pre").
32
+
33
+ h2. Example
34
+
35
+ <pre># examples/readme_example.rb
36
+ require 'fidgit'
37
+
38
+ class MyGame < Chingu::Window
39
+ def initialize
40
+ super(640, 480, false)
41
+
42
+ # To use the Fidgit features, a Fidgit::GuiState must be active.
43
+ push_game_state MyGuiState
44
+ end
45
+ end
46
+
47
+ class MyGuiState < Fidgit::GuiState
48
+ def initialize
49
+ super
50
+
51
+ # Create a vertically packed section, centred in the window.
52
+ pack :vertical, align: :center do
53
+ # Create a label with a dark green background.
54
+ my_label = label "Hello world!", background_color: Gosu::Color.rgb(0, 100, 0)
55
+
56
+ # Create a button that, when clicked, changes the label.
57
+ button("Goodbye", align_h: :center, tip: "Press me and be done with it!") do
58
+ my_label.text = "Goodbye cruel world!"
59
+ end
60
+ end
61
+ end
62
+ end
63
+
64
+ MyGame.new.show
65
+ </pre>
66
+
67
+
68
+ h2. API
69
+
70
+ As well as a cursor and tool-tips that are managed by the GuiState for you, there are several elements you can use inside your GuiState.
71
+
72
+ Elements are best added by using simple methods (listed below). Most of these method accept a block, some offering access to public methods of the element and others being default event handlers.
73
+
74
+ The GuiState itself only accepts #pack, but any packer or group accepts any other element method.
75
+
76
+ h3. GuiState methods
77
+
78
+ * _pack([:vertical|:horizontal|:grid], ...)_ - Add a packer to the state (Block has access to public methods).
79
+ * _clear()_ - remove any packers added to the state.
80
+ * _menu(...)_ - Show a context menu (Block has access to public methods).
81
+ ** _item(text, value, ...)_ - Item in a menu (Block handles :clicked_left_mouse_button event).
82
+ ** _separator(...)_ - A horizontal separator between menu items.
83
+ * _message(text, ...)_ - Show a message box with button(s) (Block subscribes to a button getting clicked).
84
+ * _file_dialog([:open, :save], ...)_ - Open a file dialog to load or save a file (Block is passed the button pressed and the file path set).
85
+
86
+ h3. Container methods
87
+
88
+ h4. Arrangement managers
89
+
90
+ Fidgit uses automatic packers to manage layout.
91
+
92
+ * _pack([:vertical|:horizontal|:grid], ...)_ - Packer that packs its component elements (Block has access to public methods).
93
+ * _group(...)_ - Manages any groupable elements put inside it, such as radio-buttons (Block has access to public methods). Best to subscribe to :changed event handler.
94
+ * _scroll_window(...)_ - A window having content larger than what is shown, scrolled with scroll-bars (Block has access to public methods of the contents packer)
95
+
96
+ h4. Elements
97
+
98
+ Elements can be placed inside a packer or group.
99
+
100
+ * _button(text, ...)_ - Button with text and/or icon (Block handles :clicked_left_mouse_button event).
101
+ * _color_picker(...)_ - Red, green and blue sliders and colour indicator (Block handles :changed event).
102
+ * _label(text, ...)_ - Label with text and, optionally, an icon (No block accepted).
103
+ * _slider(...)_ - Horizontal slider with handle (Block handles :changed event).
104
+ * _text_area(...)_ - An multi-line element, containing editable text (Block handles :changed event).
105
+ * _toggle_button(text, ...)_ - Button that can be toggled on/off (Block handles :changed event).
106
+
107
+ h5. Groupable elements
108
+
109
+ These should be placed within a group (directly or indirectly) and only one of them will be selected. The group manages which one is selected.
110
+
111
+ * _color_well(color, ...)_ - A radio-button used to pick a colour (Block handles :clicked_left_mouse_button event).
112
+ * _radio_button(text, value, ...)_ - Button that is part of a group (Block handles :clicked_left_mouse_button event).
113
+
114
+ h5. Compound elements
115
+
116
+ These elements contain items, which can easily be added from within a block passed to them. One can subscribe to the :changed event, which is usually easier than managing each item separately.
117
+
118
+ * _combo_box(...)_ - Button that has a drop-down menu attached (Block has access to public methods).
119
+ ** _item(text, value, ...)_ - Add an item to a combo box (Block handles :clicked_left_mouse_button event).
120
+ * _list(...)_ - A vertical list of items to select from (Block has access to public methods).
121
+ ** _item(text, value, ...)_ - Add an item to a combo box (Block handles :clicked_left_mouse_button event).
122
+
123
+
124
+ h2. Alternative GUI frameworks
125
+
126
+ There are two other GUI tool-kits that work with Gosu:
127
+
128
+ * "Rubygoo":http://code.google.com/p/rubygoo/
129
+ ** Additionally supports "Rubygame":http://rubygame.org/ (as well as Gosu).
130
+ ** Only simple widgets are implemented.
131
+ ** No longer supported.
132
+
133
+ * "GGLib":http://code.google.com/p/gglib/ (Gosu GUI Library)
134
+ ** Pretty graphical themes.
135
+ ** Only simple widgets are implemented.
136
+ ** No longer supported (though author has commented that they would like to pick it up again).
137
+
138
+ Remember that if you primarily want a GUI for your GUI application, not just a GUI in your Gosu game, consider using a dedicated GUI tool-kit, such as "Shoes":http://shoesrb.com/, "FXRuby":http://www.fxruby.org/ or "wxRuby":http://wxruby.rubyforge.org/
@@ -0,0 +1,38 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'yard'
5
+ require 'redcloth'
6
+
7
+ README_HTML = "README.html"
8
+ README_TEXTILE = "README.textile"
9
+
10
+ class EventHandlesHandler < YARD::Handlers::Ruby::Base
11
+ handles method_call(:handles)
12
+
13
+ def process
14
+ klass = statement.parent.parent.jump(:const)[0]
15
+ name = statement.method_name(true)
16
+ params = statement.parameters(false).dup
17
+ puts "Processing Event method: #{klass}.#{name} :#{params[0].jump(:ident)[0]}"
18
+ end
19
+ end
20
+
21
+
22
+ YARD::Rake::YardocTask.new
23
+ task :yard => README_HTML
24
+
25
+ desc "Convert readme to HTML"
26
+ file README_HTML => :readme
27
+ task :readme => README_TEXTILE do
28
+ puts "Converting readme to HTML"
29
+ File.open(README_HTML, "w") do |file|
30
+ file.write RedCloth.new(File.read(README_TEXTILE)).to_html
31
+ end
32
+ end
33
+
34
+ # Specs
35
+ desc "Run rspec 2.0"
36
+ task :rspec do
37
+ system "rspec spec"
38
+ end
@@ -0,0 +1,180 @@
1
+ # Default schema for Fidgit
2
+ ---
3
+
4
+ # Define all constant values here. For colours, use [R, G, B] or [R, G, B, A].
5
+ # Reference constants with ?constant_name
6
+ :constants:
7
+ # General constants (strings and numbers).
8
+ :scroll_bar_thickness: 12
9
+
10
+ # Gosu::Color constants
11
+ :none: [0, 0, 0, 0]
12
+
13
+ :black: [0, 0, 0]
14
+ :white: [255, 255, 255]
15
+
16
+ :very_dark_gray: [50, 50, 50]
17
+ :dark_gray: [100, 100, 100]
18
+ :gray: [150, 150, 150]
19
+ :light_gray: [200, 200, 200]
20
+
21
+ :red: [255, 0, 0]
22
+ :green: [0, 0, 255]
23
+ :blue: [0, 0, 255]
24
+
25
+ :dark_red: [100, 0, 0]
26
+ :dark_green: [0, 100, 0]
27
+ :dark_blue: [0, 0, 100]
28
+
29
+ # Default element attributes.
30
+ :elements:
31
+ :Button: # < Label
32
+ :background_color: ?dark_gray
33
+ :border_color: ?light_gray
34
+ :border_thickness: 2
35
+
36
+ :disabled:
37
+ :background_color: ?very_dark_gray
38
+ :border_color: ?gray
39
+
40
+ :hover:
41
+ :background_color: ?gray
42
+
43
+ :ColorPicker:
44
+ :indicator_height: 30
45
+
46
+ :ColorWell: # < RadioButton
47
+ :height: 32
48
+ :outline_color: ?gray
49
+ :width: 32
50
+
51
+ :checked:
52
+ :border_color: ?very_dark_gray
53
+
54
+ :ComboBox: # < Button
55
+ :background_color: ?dark_gray
56
+ :border_color: ?white
57
+
58
+ :Composite: # < Container
59
+ :padding_top: 0
60
+ :padding_right: 0
61
+ :padding_bottom: 0
62
+ :padding_left: 0
63
+
64
+ :Container: # < Element
65
+ :nothing: nil
66
+
67
+ :Element:
68
+ :align_h: :left
69
+ :align_v: :top
70
+ :background_color: ?none
71
+ :background_image: nil
72
+ :border_color: ?none
73
+ :border_thickness: 0
74
+ :color: ?white
75
+ :font_size: 30
76
+ :font_name: ''
77
+ :padding_top: 2
78
+ :padding_right: 4
79
+ :padding_bottom: 2
80
+ :padding_left: 4
81
+
82
+ :FileBrowser: # < Composite
83
+ :pattern: *.*
84
+ :show_extension: true
85
+
86
+ :GridPacker: # < Packer
87
+ :cell_background_color: ?none
88
+ :cell_border_color: ?none
89
+ :cell_border_thickness: 0
90
+
91
+ :Group: # < Packer
92
+ :padding_top: 0
93
+ :padding_right: 0
94
+ :padding_bottom: 0
95
+ :padding_left: 0
96
+
97
+ :HorizontalPacker: # < GridPacker
98
+ :nothing: nil
99
+
100
+ :HorizontalScrollBar: # < ScrollBar
101
+ :height: ?scroll_bar_thickness
102
+
103
+ :Label: # < Element
104
+ :disabled:
105
+ :color: ?light_gray
106
+
107
+ :List:
108
+ :background_color: ?light_gray
109
+ :border_color: ?white
110
+
111
+ :List::Item:
112
+ :border_thickness: 0
113
+
114
+ :MenuPane:
115
+ :background_color: ?very_dark_gray
116
+
117
+ :MenuPane::Item: # < Button
118
+ :border_color: ?none
119
+ :border_thickness: 0
120
+
121
+ :MenuPane::Separator: # < Label
122
+ :line_height: 2
123
+ :background_color: ?black
124
+
125
+ :Packer: # < Container
126
+ :spacing_h: 4
127
+ :spacing_v: 4
128
+
129
+ :RadioButton: # < Button
130
+ :checked:
131
+ :border_color: ?blue
132
+
133
+ :ScrollArea: # < Composite
134
+ :nothing: nil
135
+
136
+ :ScrollBar: # < Composite
137
+ :background_color: ?none
138
+ :border_color: ?none
139
+ :handle_color: ?dark_red
140
+ :rail_color: ?very_dark_gray
141
+ :rail_width: ?scroll_bar_thickness
142
+
143
+ :ScrollWindow: # < Composite
144
+ :scroll_bar_thickness: ?scroll_bar_thickness
145
+ :border_color: ?light_gray
146
+ :border_thickness: 1
147
+
148
+ :Slider: # < Element
149
+ :background_color: ?none
150
+ :border_color: ?dark_gray
151
+ :groove_color: ?light_gray
152
+ :handle_color: ?dark_green
153
+
154
+ :Slider::Handle: # < Element
155
+ :background_color: ?dark_blue
156
+
157
+ :TextArea: # < Composite
158
+ :background_color: ?very_dark_gray
159
+ :border_color: ?light_gray
160
+ :caret_color: ?red
161
+ :caret_period: 500 # In milliseconds
162
+ :line_spacing: 0
163
+ :selection_color: ?dark_gray
164
+
165
+ :focused:
166
+ :border_color: ?green
167
+
168
+ :ToggleButton: # < Button
169
+ :toggled:
170
+ :border_color: ?red
171
+
172
+ :ToolTip: # < Label
173
+ :background_color: ?very_dark_gray
174
+ :border_color: ?white
175
+
176
+ :VerticalPacker: # < GridPacker
177
+ :nothing: nil
178
+
179
+ :VerticalScrollBar: # < ScrollBar
180
+ :width: ?scroll_bar_thickness
@@ -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_size: 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
+ pack :vertical, align: :center, background_color: OUTER_BACKGROUND do
15
+ label "h => align_h, v => align_v", align_h: :center
16
+
17
+ pack :grid, num_columns: 4, align: :center, cell_background_color: CELL_BACKGROUND, background_color: ROW_BACKGROUND, align_h: :fill 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
+ pack :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
+ pack :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
+ pack :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,27 @@
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
+ my_button = button("Button", tip: "I'm a button; press me!") do
12
+ my_label.text = "Pressed the button!"
13
+ end
14
+
15
+ my_toggle_button = toggle_button("ToggleButton", tip: "I'm a button that toggles") do |sender, value|
16
+ my_label.text = "Turned the toggle button #{value ? "on" : "off"}!"
17
+ end
18
+
19
+ toggle_button("Enable other two buttons", value: true) do |sender, value|
20
+ my_button.enabled = value
21
+ my_toggle_button.enabled = value
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+ ExampleWindow.new.show