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,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9dd17a6c5e84546fb12662c82d919b58c6751226
4
+ data.tar.gz: f91e8608ab6f8d8059316b55765edb344cf43d5f
5
+ SHA512:
6
+ metadata.gz: 438e4f11f305c800e8b89232854a159c79aca51232562751a349f083e276e122fe29f0dac724747892423ea144b571d114619a99d90689a7ea5eed2ea77eec60
7
+ data.tar.gz: 3ec73dba5f84c5d7d6ec66ef976df41ae9a494d8c6548ab96bee154384579fab1675a141f6235cc35bfa0d3cafa05f7bb5765a0e6c94991b012740e4fb29c21b
@@ -0,0 +1,8 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
4
+ Gemfile.lock
5
+ doc/
6
+ .yardoc
7
+ README.html
8
+ .idea/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --format documentation
@@ -0,0 +1,31 @@
1
+ Fidgit changelog
2
+ ================
3
+
4
+ v0.2.3
5
+ ------
6
+
7
+ * Exposed #handle accessor for Slider.
8
+ * Made Slider accept being disabled.
9
+ * Made Slider handle show tip.
10
+
11
+ v0.2.2
12
+ ------
13
+
14
+ * Prevented ToggleButton border colour changing.
15
+ * More careful about stripping out html tags in TextArea.
16
+
17
+ v0.2.1
18
+ ------
19
+
20
+ * Added: Click in ScrollBar gutter to scroll window by height/width of view window.
21
+ * Added: Click and drag to select text in enabled TextArea.
22
+ * Fixed: Color changes on disabling buttons.
23
+
24
+ v0.2.0
25
+ ------
26
+
27
+ * Added editable attribute to TextArea (Allows selection, but not alteration).
28
+ * Added Element#font= and :font option.
29
+ * Added Gosu::Color#colorize to use when using in-line text styling.
30
+ * Managed layout of entities and XML tags (Used by Gosu) in TextArea text better (tags still don't like newlines inside them).
31
+ * Changed license from LGPL to MIT.
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,20 @@
1
+ Copyright (c) 2012 Bil Bas (Spooner)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,154 @@
1
+ Fidgit
2
+ ======
3
+
4
+ Fidgit is a GUI framework built on [Gosu](http://libgosu.org/) and [Chingu](http://ippa.se/chingu)
5
+
6
+
7
+ Description
8
+ -----------
9
+
10
+ The API is inspired by [Shoes](http://shoesrb.com/), but since Shoes is very simplistic, the level of functionality is
11
+ based around [FXRuby](http://www.fxruby.org/) and other GUI APIs.
12
+ Fidgit was originally developed as a part of the Sidney game, but as it got more complex, it was obvious it would be
13
+ useful to separate them.
14
+
15
+ _WARNING: THIS PROJECT IS IN EARLY ALPHA DEVELOPMENT AND THE API IS LIABLE TO CONTINUOUS CHANGE AND IT IS QUITE UNSTABLE!_
16
+
17
+ Read the Yard documentation at [rubydoc.info](http://rubydoc.info/github/Spooner/fidgit/master)
18
+
19
+
20
+ Aim
21
+ ---
22
+
23
+ Fidgit aims to be a toolkit which will provide the building blocks to quickly create a GUI either for a GUI-based game
24
+ or for options screens and menus within a regular Gosu game.
25
+
26
+
27
+ License
28
+ -------
29
+
30
+ MIT (see COPYING.txt)
31
+
32
+
33
+ Requirements
34
+ ------------
35
+
36
+ * Ruby 1.9.2 or higher.
37
+ * Gosu gem 0.7.27.1
38
+ * [Installing Gosu dependencies on Linux](http://code.google.com/p/gosu/wiki/GettingStartedOnLinux) (On Win32 and OS X there are binary gems available)
39
+ * Chingu gem 0.9rc4.
40
+ * Clipboard gem
41
+
42
+
43
+ Example
44
+ -------
45
+
46
+ ```ruby
47
+ # examples/readme_example.rb
48
+ require 'fidgit'
49
+
50
+ class MyGame < Chingu::Window
51
+ def initialize
52
+ super(640, 480, false)
53
+
54
+ # To use the Fidgit features, a Fidgit::GuiState must be active.
55
+ push_game_state MyGuiState
56
+ end
57
+ end
58
+
59
+ class MyGuiState < Fidgit::GuiState
60
+ def initialize
61
+ super
62
+
63
+ # Create a vertically packed section, centred in the window.
64
+ vertical align: :center do
65
+ # Create a label with a dark green background.
66
+ my_label = label "Hello world!", background_color: Gosu::Color.rgb(0, 100, 0)
67
+
68
+ # Create a button that, when clicked, changes the label.
69
+ button("Goodbye", align_h: :center, tip: "Press me and be done with it!") do
70
+ my_label.text = "Goodbye cruel world!"
71
+ end
72
+ end
73
+ end
74
+ end
75
+
76
+ MyGame.new.show
77
+ ```
78
+
79
+
80
+ API
81
+ ---
82
+
83
+ 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.
84
+
85
+ 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.
86
+
87
+ The GuiState itself only accepts #vertical/#horizontal/#grid, but any packer or group accepts any other element method.
88
+
89
+
90
+ GuiState methods
91
+ ----------------
92
+
93
+ * `pack([:vertical|:horizontal|:grid], ...)` - Add a packer to the state (Block has access to public methods).
94
+ * `clear()` - remove any packers added to the state.
95
+ * `menu(...)` - Show a context menu (Block has access to public methods).
96
+ * `item(text, value, ...)` - Item in a menu (Block handles :clicked_left_mouse_button event).
97
+ * `separator(...)` - A horizontal separator between menu items.
98
+ * `message(text, ...)` - Show a message box with button(s) (Block subscribes to a button getting clicked).
99
+ * `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).
100
+
101
+ ### Container methods
102
+
103
+ #### Arrangement managers
104
+
105
+ Fidgit uses automatic packers to manage layout.
106
+
107
+ * `pack([:vertical|:horizontal|:grid], ...)` - Packer that packs its component elements (Block has access to public methods).
108
+ * `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.
109
+ * `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)
110
+
111
+ #### Elements
112
+
113
+ Elements can be placed inside a packer or group.
114
+
115
+ * `button(text, ...)` - Button with text and/or icon (Block handles :clicked_left_mouse_button event).
116
+ * `color_picker(...)` - Red, green and blue sliders and colour indicator (Block handles :changed event).
117
+ * `image_frame(image, ...)` - Wrapper around a Gosu::Image to embed it in the GUI.
118
+ * `label(text, ...)` - Label with text and, optionally, an icon (No block accepted).
119
+ * `slider(...)` - Horizontal slider with handle (Block handles :changed event).
120
+ * `text_area(...)` - An multi-line element, containing editable text (Block handles :changed event).
121
+ * `toggle_button(text, ...)` - Button that can be toggled on/off (Block handles :changed event).
122
+
123
+ ##### Groupable elements
124
+
125
+ 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.
126
+
127
+ * `color_well(color, ...)` - A radio-button used to pick a colour (Block handles :clicked_left_mouse_button event).
128
+ * `radio_button(text, value, ...)` - Button that is part of a group (Block handles :clicked_left_mouse_button event).
129
+
130
+ ##### Compound elements
131
+
132
+ 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.
133
+
134
+ * `combo_box(...)` - Button that has a drop-down menu attached (Block has access to public methods).
135
+ * `item(text, value, ...)` - Add an item to a combo box (Block handles :clicked_left_mouse_button event).
136
+ * `list(...)` - A vertical list of items to select from (Block has access to public methods).
137
+ * `item(text, value, ...)` - Add an item to a combo box (Block handles :clicked_left_mouse_button event).
138
+
139
+
140
+ ##### Alternative GUI frameworks
141
+
142
+ There are two other GUI tool-kits that work with Gosu:
143
+
144
+ * [Rubygoo](http://code.google.com/p/rubygoo/)
145
+ * Additionally supports [Rubygame](http://rubygame.org/) (as well as Gosu).
146
+ * Only simple widgets are implemented.
147
+ * No longer supported.
148
+
149
+ * [GGLib](http://code.google.com/p/gglib/) (Gosu GUI Library)
150
+ * Pretty graphical themes.
151
+ * Only simple widgets are implemented.
152
+ * No longer supported (though author has commented that they would like to pick it up again).
153
+
154
+ 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/) or [wxruby-ruby19](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,216 @@
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
+ :shortcut_color: ?red
36
+ :padding_top: 2
37
+ :padding_right: 4
38
+ :padding_bottom: 2
39
+ :padding_left: 4
40
+
41
+ :disabled:
42
+ :background_color: ?very_dark_gray
43
+ :border_color: ?gray
44
+
45
+ :hover:
46
+ :background_color: ?gray
47
+
48
+ :ColorPicker:
49
+ :indicator_height: 30
50
+
51
+ :ColorWell: # < RadioButton
52
+ :height: 32
53
+ :outline_color: ?gray
54
+ :width: 32
55
+
56
+ :checked:
57
+ :border_color: ?very_dark_gray
58
+
59
+ :ComboBox: # < Button
60
+ :background_color: ?dark_gray
61
+ :border_color: ?white
62
+
63
+ :Composite: # < Container
64
+ :padding_top: 0
65
+ :padding_right: 0
66
+ :padding_bottom: 0
67
+ :padding_left: 0
68
+
69
+ :Container: # < Element
70
+ {}
71
+
72
+ :Element:
73
+ :align_h: :left
74
+ :align_v: :top
75
+ :background_color: ?none
76
+ :background_image: nil
77
+ :border_color: ?none
78
+ :border_thickness: 0
79
+ :color: ?white
80
+ :font_height: 30
81
+ :font_name: :default
82
+ :padding_top: 2
83
+ :padding_right: 4
84
+ :padding_bottom: 2
85
+ :padding_left: 4
86
+
87
+
88
+ :FileBrowser: # < Composite
89
+ :pattern: "*.*"
90
+ :show_extension: true
91
+
92
+ :Grid: # < Packer
93
+ :cell_background_color: ?none
94
+ :cell_border_color: ?none
95
+ :cell_border_thickness: 0
96
+
97
+ :Group: # < Packer
98
+ :padding_top: 0
99
+ :padding_right: 0
100
+ :padding_bottom: 0
101
+ :padding_left: 0
102
+
103
+ :Horizontal: # < Grid
104
+ {}
105
+
106
+ :HorizontalScrollBar: # < ScrollBar
107
+ :height: ?scroll_bar_thickness
108
+
109
+ :ImageFrame: # <Element
110
+ :padding_top: 0
111
+ :padding_right: 0
112
+ :padding_bottom: 0
113
+ :padding_left: 0
114
+
115
+ :Label: # < Element
116
+ :justify: :left
117
+ :icon_position: :left
118
+
119
+ :disabled:
120
+ :color: ?gray
121
+
122
+ :List:
123
+ :background_color: ?light_gray
124
+ :border_color: ?white
125
+
126
+ :List::Item:
127
+ :border_thickness: 0
128
+
129
+ :MainPacker: # < Packer
130
+ :border_thickness: 0
131
+ :padding_top: 0
132
+ :padding_right: 0
133
+ :padding_bottom: 0
134
+ :padding_left: 0
135
+ :spacing_h: 0
136
+ :spacing_v: 0
137
+
138
+ :MenuPane:
139
+ :background_color: ?very_dark_gray
140
+
141
+ :MenuPane::Item: # < Button
142
+ :border_color: ?none
143
+ :border_thickness: 0
144
+
145
+ :MenuPane::Separator: # < Label
146
+ :line_height: 2
147
+ :background_color: ?black
148
+
149
+ :Packer: # < Container
150
+ :spacing_h: 4
151
+ :spacing_v: 4
152
+
153
+ :RadioButton: # < Button
154
+ :checked:
155
+ :border_color: ?blue
156
+
157
+ :ScrollArea: # < Composite
158
+ {}
159
+
160
+ :ScrollBar: # < Composite
161
+ :background_color: ?none
162
+ :border_color: ?none
163
+ :handle_color: ?dark_red
164
+ :rail_color: ?very_dark_gray
165
+ :rail_width: ?scroll_bar_thickness
166
+
167
+ :ScrollWindow: # < Composite
168
+ :scroll_bar_thickness: ?scroll_bar_thickness
169
+ :border_color: ?light_gray
170
+ :border_thickness: 1
171
+
172
+ :Slider: # < Element
173
+ :background_color: ?none
174
+ :border_color: ?dark_gray
175
+ :groove_color: ?light_gray
176
+ :handle_color: ?dark_green
177
+
178
+ :Slider::Handle: # < Element
179
+ :background_color: ?dark_blue
180
+
181
+ :TextArea: # < Composite
182
+ :background_color: ?very_dark_gray
183
+ :border_color: ?light_gray
184
+ :caret_color: ?red
185
+ :caret_period: 500 # In milliseconds
186
+ :line_spacing: 0
187
+ :selection_color: ?dark_gray
188
+
189
+ :focused:
190
+ :border_color: ?green
191
+
192
+ :TextLine: # < Element
193
+ :justify: :left
194
+ :padding_top: 0
195
+ :padding_right: 0
196
+ :padding_bottom: 0
197
+ :padding_left: 0
198
+
199
+ :ToggleButton: # < Button
200
+ :toggled:
201
+ :border_color: ?red
202
+
203
+ :ToolTip: # < Label
204
+ :background_color: ?very_dark_gray
205
+ :font_height: 20
206
+ :border_color: ?white
207
+ :padding_top: 2
208
+ :padding_right: 4
209
+ :padding_bottom: 2
210
+ :padding_left: 4
211
+
212
+ :Vertical: # < Grid
213
+ {}
214
+
215
+ :VerticalScrollBar: # < ScrollBar
216
+ :width: ?scroll_bar_thickness