fidgit 0.2.4 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +7 -7
- data/.rspec +2 -2
- data/CHANGELOG.md +30 -30
- data/Gemfile +3 -3
- data/LICENSE.txt +19 -19
- data/README.textile +139 -139
- data/Rakefile +37 -37
- data/config/default_schema.yml +216 -216
- data/examples/_all_examples.rb +9 -9
- data/examples/align_example.rb +55 -55
- data/examples/button_and_toggle_button_example.rb +37 -37
- data/examples/color_picker_example.rb +16 -16
- data/examples/color_well_example.rb +24 -24
- data/examples/combo_box_example.rb +23 -23
- data/examples/file_dialog_example.rb +41 -41
- data/examples/grid_packer_example.rb +28 -28
- data/examples/helpers/example_window.rb +16 -16
- data/examples/label_example.rb +22 -22
- data/examples/list_example.rb +22 -22
- data/examples/menu_pane_example.rb +26 -26
- data/examples/message_dialog_example.rb +64 -64
- data/examples/radio_button_example.rb +36 -36
- data/examples/readme_example.rb +31 -31
- data/examples/scroll_window_example.rb +48 -48
- data/examples/slider_example.rb +33 -33
- data/examples/splash_example.rb +41 -41
- data/examples/text_area_example.rb +32 -32
- data/fidgit.gemspec +35 -35
- data/lib/fidgit.rb +50 -50
- data/lib/fidgit/chingu_ext/window.rb +5 -5
- data/lib/fidgit/cursor.rb +37 -37
- data/lib/fidgit/elements/button.rb +112 -112
- data/lib/fidgit/elements/color_picker.rb +62 -62
- data/lib/fidgit/elements/color_well.rb +38 -38
- data/lib/fidgit/elements/combo_box.rb +113 -113
- data/lib/fidgit/elements/composite.rb +16 -16
- data/lib/fidgit/elements/container.rb +208 -208
- data/lib/fidgit/elements/element.rb +297 -297
- data/lib/fidgit/elements/file_browser.rb +151 -151
- data/lib/fidgit/elements/grid.rb +226 -226
- data/lib/fidgit/elements/group.rb +64 -64
- data/lib/fidgit/elements/horizontal.rb +11 -11
- data/lib/fidgit/elements/image_frame.rb +64 -64
- data/lib/fidgit/elements/label.rb +84 -84
- data/lib/fidgit/elements/list.rb +46 -46
- data/lib/fidgit/elements/main_packer.rb +24 -24
- data/lib/fidgit/elements/menu_pane.rb +160 -160
- data/lib/fidgit/elements/packer.rb +41 -41
- data/lib/fidgit/elements/radio_button.rb +85 -85
- data/lib/fidgit/elements/scroll_area.rb +67 -67
- data/lib/fidgit/elements/scroll_bar.rb +127 -127
- data/lib/fidgit/elements/scroll_window.rb +82 -82
- data/lib/fidgit/elements/slider.rb +124 -124
- data/lib/fidgit/elements/text_area.rb +493 -493
- data/lib/fidgit/elements/text_line.rb +91 -91
- data/lib/fidgit/elements/toggle_button.rb +66 -66
- data/lib/fidgit/elements/tool_tip.rb +34 -34
- data/lib/fidgit/elements/vertical.rb +11 -11
- data/lib/fidgit/event.rb +158 -158
- data/lib/fidgit/gosu_ext/color.rb +135 -135
- data/lib/fidgit/gosu_ext/gosu_module.rb +24 -24
- data/lib/fidgit/history.rb +90 -90
- data/lib/fidgit/redirector.rb +82 -82
- data/lib/fidgit/schema.rb +123 -123
- data/lib/fidgit/selection.rb +105 -105
- data/lib/fidgit/standard_ext/hash.rb +20 -20
- data/lib/fidgit/states/dialog_state.rb +51 -51
- data/lib/fidgit/states/file_dialog.rb +24 -24
- data/lib/fidgit/states/gui_state.rb +329 -329
- data/lib/fidgit/states/message_dialog.rb +60 -60
- data/lib/fidgit/version.rb +4 -4
- data/lib/fidgit/window.rb +19 -19
- data/spec/fidgit/elements/helpers/helper.rb +2 -2
- data/spec/fidgit/elements/helpers/tex_play_helper.rb +8 -8
- data/spec/fidgit/elements/image_frame_spec.rb +68 -68
- data/spec/fidgit/elements/label_spec.rb +36 -36
- data/spec/fidgit/event_spec.rb +209 -209
- data/spec/fidgit/gosu_ext/color_spec.rb +129 -129
- data/spec/fidgit/gosu_ext/helpers/helper.rb +2 -2
- data/spec/fidgit/helpers/helper.rb +3 -3
- data/spec/fidgit/history_spec.rb +153 -153
- data/spec/fidgit/redirector_spec.rb +77 -77
- data/spec/fidgit/schema_spec.rb +66 -66
- data/spec/fidgit/schema_test.yml +32 -32
- metadata +67 -22
@@ -1,63 +1,63 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module Fidgit
|
4
|
-
class ColorPicker < Composite
|
5
|
-
CHANNELS = [:red, :green, :blue]
|
6
|
-
DEFAULT_CHANNEL_NAMES = CHANNELS.map {|c| c.to_s.capitalize }
|
7
|
-
|
8
|
-
INDICATOR_HEIGHT = 25
|
9
|
-
|
10
|
-
event :changed
|
11
|
-
|
12
|
-
def color; @color.dup; end
|
13
|
-
|
14
|
-
def color=(value)
|
15
|
-
@color = value.dup
|
16
|
-
CHANNELS.each do |channel|
|
17
|
-
@sliders[channel].value = @color.send channel
|
18
|
-
end
|
19
|
-
|
20
|
-
publish :changed, @color.dup
|
21
|
-
|
22
|
-
value
|
23
|
-
end
|
24
|
-
|
25
|
-
# @param (see Composite#initialize)
|
26
|
-
# @option (see Composite#initialize)
|
27
|
-
def initialize(options = {}, &block)
|
28
|
-
options = {
|
29
|
-
padding: 0,
|
30
|
-
spacing: 0,
|
31
|
-
channel_names: DEFAULT_CHANNEL_NAMES,
|
32
|
-
color: default(:color),
|
33
|
-
indicator_height: default(:indicator_height),
|
34
|
-
}.merge! options
|
35
|
-
|
36
|
-
@color = options[:color].dup
|
37
|
-
@indicator_height = options[:indicator_height]
|
38
|
-
|
39
|
-
super(options)
|
40
|
-
|
41
|
-
slider_width = width
|
42
|
-
vertical do
|
43
|
-
@sliders = {}
|
44
|
-
CHANNELS.each_with_index do |channel, i|
|
45
|
-
@sliders[channel] = slider(value: @color.send(channel), range: 0..255, width: slider_width,
|
46
|
-
tip: options[:channel_names][i]) do |sender, value|
|
47
|
-
@color.send "#{channel}=", value
|
48
|
-
@indicator.background_color = @color
|
49
|
-
publish :changed, @color.dup
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
@indicator = label '', background_color: @color, width: slider_width, height: @indicator_height
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
protected
|
58
|
-
# Use block as an event handler.
|
59
|
-
def post_init_block(&block)
|
60
|
-
subscribe :changed, &block
|
61
|
-
end
|
62
|
-
end
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Fidgit
|
4
|
+
class ColorPicker < Composite
|
5
|
+
CHANNELS = [:red, :green, :blue]
|
6
|
+
DEFAULT_CHANNEL_NAMES = CHANNELS.map {|c| c.to_s.capitalize }
|
7
|
+
|
8
|
+
INDICATOR_HEIGHT = 25
|
9
|
+
|
10
|
+
event :changed
|
11
|
+
|
12
|
+
def color; @color.dup; end
|
13
|
+
|
14
|
+
def color=(value)
|
15
|
+
@color = value.dup
|
16
|
+
CHANNELS.each do |channel|
|
17
|
+
@sliders[channel].value = @color.send channel
|
18
|
+
end
|
19
|
+
|
20
|
+
publish :changed, @color.dup
|
21
|
+
|
22
|
+
value
|
23
|
+
end
|
24
|
+
|
25
|
+
# @param (see Composite#initialize)
|
26
|
+
# @option (see Composite#initialize)
|
27
|
+
def initialize(options = {}, &block)
|
28
|
+
options = {
|
29
|
+
padding: 0,
|
30
|
+
spacing: 0,
|
31
|
+
channel_names: DEFAULT_CHANNEL_NAMES,
|
32
|
+
color: default(:color),
|
33
|
+
indicator_height: default(:indicator_height),
|
34
|
+
}.merge! options
|
35
|
+
|
36
|
+
@color = options[:color].dup
|
37
|
+
@indicator_height = options[:indicator_height]
|
38
|
+
|
39
|
+
super(options)
|
40
|
+
|
41
|
+
slider_width = width
|
42
|
+
vertical do
|
43
|
+
@sliders = {}
|
44
|
+
CHANNELS.each_with_index do |channel, i|
|
45
|
+
@sliders[channel] = slider(value: @color.send(channel), range: 0..255, width: slider_width,
|
46
|
+
tip: options[:channel_names][i]) do |sender, value|
|
47
|
+
@color.send "#{channel}=", value
|
48
|
+
@indicator.background_color = @color
|
49
|
+
publish :changed, @color.dup
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
@indicator = label '', background_color: @color, width: slider_width, height: @indicator_height
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
protected
|
58
|
+
# Use block as an event handler.
|
59
|
+
def post_init_block(&block)
|
60
|
+
subscribe :changed, &block
|
61
|
+
end
|
62
|
+
end
|
63
63
|
end
|
@@ -1,39 +1,39 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module Fidgit
|
4
|
-
class ColorWell < RadioButton
|
5
|
-
alias_method :color, :value
|
6
|
-
|
7
|
-
# @param (see RadioButton#initialize)
|
8
|
-
# @option (see RadioButton#initialize)
|
9
|
-
def initialize(options = {}, &block)
|
10
|
-
options = {
|
11
|
-
width: default(:width),
|
12
|
-
height: default(:height),
|
13
|
-
color: default(:color),
|
14
|
-
outline_color: default(:outline_color),
|
15
|
-
checked_border_color: default(:checked, :border_color),
|
16
|
-
}.merge! options
|
17
|
-
|
18
|
-
@outline_color = options[:outline_color].dup
|
19
|
-
|
20
|
-
super('', (options[:color] || options[:value]).dup, options)
|
21
|
-
end
|
22
|
-
|
23
|
-
protected
|
24
|
-
def draw_background
|
25
|
-
super
|
26
|
-
|
27
|
-
draw_frame x + 2, y + 2, width - 4, height - 4, 1, z, @outline_color
|
28
|
-
|
29
|
-
nil
|
30
|
-
end
|
31
|
-
|
32
|
-
protected
|
33
|
-
def draw_foreground
|
34
|
-
draw_rect x + 3, y + 3, width - 6, height - 6, z, value
|
35
|
-
|
36
|
-
nil
|
37
|
-
end
|
38
|
-
end
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Fidgit
|
4
|
+
class ColorWell < RadioButton
|
5
|
+
alias_method :color, :value
|
6
|
+
|
7
|
+
# @param (see RadioButton#initialize)
|
8
|
+
# @option (see RadioButton#initialize)
|
9
|
+
def initialize(options = {}, &block)
|
10
|
+
options = {
|
11
|
+
width: default(:width),
|
12
|
+
height: default(:height),
|
13
|
+
color: default(:color),
|
14
|
+
outline_color: default(:outline_color),
|
15
|
+
checked_border_color: default(:checked, :border_color),
|
16
|
+
}.merge! options
|
17
|
+
|
18
|
+
@outline_color = options[:outline_color].dup
|
19
|
+
|
20
|
+
super('', (options[:color] || options[:value]).dup, options)
|
21
|
+
end
|
22
|
+
|
23
|
+
protected
|
24
|
+
def draw_background
|
25
|
+
super
|
26
|
+
|
27
|
+
draw_frame x + 2, y + 2, width - 4, height - 4, 1, z, @outline_color
|
28
|
+
|
29
|
+
nil
|
30
|
+
end
|
31
|
+
|
32
|
+
protected
|
33
|
+
def draw_foreground
|
34
|
+
draw_rect x + 3, y + 3, width - 6, height - 6, z, value
|
35
|
+
|
36
|
+
nil
|
37
|
+
end
|
38
|
+
end
|
39
39
|
end
|
@@ -1,114 +1,114 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module Fidgit
|
4
|
-
class ComboBox < Button
|
5
|
-
extend Forwardable
|
6
|
-
|
7
|
-
ARROW_IMAGE = "combo_arrow.png"
|
8
|
-
|
9
|
-
def_delegators :@menu, :each
|
10
|
-
|
11
|
-
event :changed
|
12
|
-
|
13
|
-
def index; @menu.index(@value) end
|
14
|
-
def value; @value; end
|
15
|
-
|
16
|
-
def value=(value)
|
17
|
-
if @value != value
|
18
|
-
@value = value
|
19
|
-
item = @menu.find(@value)
|
20
|
-
self.text = item.text
|
21
|
-
self.icon = item.icon
|
22
|
-
publish :changed, @value
|
23
|
-
end
|
24
|
-
|
25
|
-
value
|
26
|
-
end
|
27
|
-
|
28
|
-
def index=(index)
|
29
|
-
if index.between?(0, @menu.size - 1)
|
30
|
-
self.value = @menu[index].value
|
31
|
-
end
|
32
|
-
|
33
|
-
index
|
34
|
-
end
|
35
|
-
|
36
|
-
# @param (see Button#initialize)
|
37
|
-
# @option (see Button#initialize)
|
38
|
-
# @option options [] :value
|
39
|
-
def initialize(options = {}, &block)
|
40
|
-
options = {
|
41
|
-
background_color: default(:background_color),
|
42
|
-
border_color: default(:border_color),
|
43
|
-
}.merge! options
|
44
|
-
|
45
|
-
@value = options[:value]
|
46
|
-
|
47
|
-
@hover_index = 0
|
48
|
-
|
49
|
-
@menu = MenuPane.new(show: false) do
|
50
|
-
subscribe :selected do |widget, value|
|
51
|
-
self.value = value
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
@@arrow ||= Gosu::Image[ARROW_IMAGE]
|
56
|
-
|
57
|
-
super('', options)
|
58
|
-
|
59
|
-
rect.height = [height, font.height + padding_top + padding_bottom].max
|
60
|
-
rect.width = [width, font.height * 4 + padding_left + padding_right].max
|
61
|
-
end
|
62
|
-
|
63
|
-
def item(text, value, options = {}, &block)
|
64
|
-
item = @menu.item(text, value, options, &block)
|
65
|
-
|
66
|
-
# Force text to be updated if the item added has the same value.
|
67
|
-
if item.value == @value
|
68
|
-
self.text = item.text
|
69
|
-
self.icon = item.icon
|
70
|
-
end
|
71
|
-
|
72
|
-
recalc
|
73
|
-
|
74
|
-
item
|
75
|
-
end
|
76
|
-
|
77
|
-
def draw
|
78
|
-
super
|
79
|
-
size = height / @@arrow.width.to_f
|
80
|
-
@@arrow.draw x + width - height, y, z, size, size
|
81
|
-
end
|
82
|
-
|
83
|
-
def clicked_left_mouse_button(sender, x, y)
|
84
|
-
@menu.x = self.x
|
85
|
-
@menu.y = self.y + height + border_thickness
|
86
|
-
$window.game_state_manager.current_game_state.show_menu @menu
|
87
|
-
|
88
|
-
nil
|
89
|
-
end
|
90
|
-
|
91
|
-
def clear
|
92
|
-
self.text = ""
|
93
|
-
self.icon = nil
|
94
|
-
@menu.clear
|
95
|
-
end
|
96
|
-
|
97
|
-
protected
|
98
|
-
def layout
|
99
|
-
super
|
100
|
-
|
101
|
-
# Max width of all items + allow size for the arrow.
|
102
|
-
rect.width = [@menu.width + height, min_width].max
|
103
|
-
|
104
|
-
nil
|
105
|
-
end
|
106
|
-
|
107
|
-
|
108
|
-
protected
|
109
|
-
# Any combo-box passed a block will allow you access to its methods.
|
110
|
-
def post_init_block(&block)
|
111
|
-
with(&block)
|
112
|
-
end
|
113
|
-
end
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Fidgit
|
4
|
+
class ComboBox < Button
|
5
|
+
extend Forwardable
|
6
|
+
|
7
|
+
ARROW_IMAGE = "combo_arrow.png"
|
8
|
+
|
9
|
+
def_delegators :@menu, :each
|
10
|
+
|
11
|
+
event :changed
|
12
|
+
|
13
|
+
def index; @menu.index(@value) end
|
14
|
+
def value; @value; end
|
15
|
+
|
16
|
+
def value=(value)
|
17
|
+
if @value != value
|
18
|
+
@value = value
|
19
|
+
item = @menu.find(@value)
|
20
|
+
self.text = item.text
|
21
|
+
self.icon = item.icon
|
22
|
+
publish :changed, @value
|
23
|
+
end
|
24
|
+
|
25
|
+
value
|
26
|
+
end
|
27
|
+
|
28
|
+
def index=(index)
|
29
|
+
if index.between?(0, @menu.size - 1)
|
30
|
+
self.value = @menu[index].value
|
31
|
+
end
|
32
|
+
|
33
|
+
index
|
34
|
+
end
|
35
|
+
|
36
|
+
# @param (see Button#initialize)
|
37
|
+
# @option (see Button#initialize)
|
38
|
+
# @option options [] :value
|
39
|
+
def initialize(options = {}, &block)
|
40
|
+
options = {
|
41
|
+
background_color: default(:background_color),
|
42
|
+
border_color: default(:border_color),
|
43
|
+
}.merge! options
|
44
|
+
|
45
|
+
@value = options[:value]
|
46
|
+
|
47
|
+
@hover_index = 0
|
48
|
+
|
49
|
+
@menu = MenuPane.new(show: false) do
|
50
|
+
subscribe :selected do |widget, value|
|
51
|
+
self.value = value
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
@@arrow ||= Gosu::Image[ARROW_IMAGE]
|
56
|
+
|
57
|
+
super('', options)
|
58
|
+
|
59
|
+
rect.height = [height, font.height + padding_top + padding_bottom].max
|
60
|
+
rect.width = [width, font.height * 4 + padding_left + padding_right].max
|
61
|
+
end
|
62
|
+
|
63
|
+
def item(text, value, options = {}, &block)
|
64
|
+
item = @menu.item(text, value, options, &block)
|
65
|
+
|
66
|
+
# Force text to be updated if the item added has the same value.
|
67
|
+
if item.value == @value
|
68
|
+
self.text = item.text
|
69
|
+
self.icon = item.icon
|
70
|
+
end
|
71
|
+
|
72
|
+
recalc
|
73
|
+
|
74
|
+
item
|
75
|
+
end
|
76
|
+
|
77
|
+
def draw
|
78
|
+
super
|
79
|
+
size = height / @@arrow.width.to_f
|
80
|
+
@@arrow.draw x + width - height, y, z, size, size
|
81
|
+
end
|
82
|
+
|
83
|
+
def clicked_left_mouse_button(sender, x, y)
|
84
|
+
@menu.x = self.x
|
85
|
+
@menu.y = self.y + height + border_thickness
|
86
|
+
$window.game_state_manager.current_game_state.show_menu @menu
|
87
|
+
|
88
|
+
nil
|
89
|
+
end
|
90
|
+
|
91
|
+
def clear
|
92
|
+
self.text = ""
|
93
|
+
self.icon = nil
|
94
|
+
@menu.clear
|
95
|
+
end
|
96
|
+
|
97
|
+
protected
|
98
|
+
def layout
|
99
|
+
super
|
100
|
+
|
101
|
+
# Max width of all items + allow size for the arrow.
|
102
|
+
rect.width = [@menu.width + height, min_width].max
|
103
|
+
|
104
|
+
nil
|
105
|
+
end
|
106
|
+
|
107
|
+
|
108
|
+
protected
|
109
|
+
# Any combo-box passed a block will allow you access to its methods.
|
110
|
+
def post_init_block(&block)
|
111
|
+
with(&block)
|
112
|
+
end
|
113
|
+
end
|
114
114
|
end
|
@@ -1,17 +1,17 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module Fidgit
|
4
|
-
# A composite element, made up of other elements (but manages them internally).
|
5
|
-
class Composite < Packer
|
6
|
-
DEBUG_BORDER_COLOR = Gosu::Color.rgba(0, 255, 0, 100) # Color to draw an outline in when debugging layout.
|
7
|
-
|
8
|
-
# @param (see Element#initialize)
|
9
|
-
#
|
10
|
-
# @option (see Element#initialize)
|
11
|
-
def initialize(options = {})
|
12
|
-
options[:border_color] = DEBUG_BORDER_COLOR if Fidgit.debug_mode?
|
13
|
-
|
14
|
-
super(options)
|
15
|
-
end
|
16
|
-
end
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Fidgit
|
4
|
+
# A composite element, made up of other elements (but manages them internally).
|
5
|
+
class Composite < Packer
|
6
|
+
DEBUG_BORDER_COLOR = Gosu::Color.rgba(0, 255, 0, 100) # Color to draw an outline in when debugging layout.
|
7
|
+
|
8
|
+
# @param (see Element#initialize)
|
9
|
+
#
|
10
|
+
# @option (see Element#initialize)
|
11
|
+
def initialize(options = {})
|
12
|
+
options[:border_color] = DEBUG_BORDER_COLOR if Fidgit.debug_mode?
|
13
|
+
|
14
|
+
super(options)
|
15
|
+
end
|
16
|
+
end
|
17
17
|
end
|