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
data/lib/fidgit/elements/list.rb
CHANGED
@@ -1,47 +1,47 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module Fidgit
|
4
|
-
class List < Composite
|
5
|
-
class Item < RadioButton
|
6
|
-
end
|
7
|
-
|
8
|
-
event :changed
|
9
|
-
|
10
|
-
def size; @items.size; end
|
11
|
-
def clear; @items.clear; end
|
12
|
-
|
13
|
-
def initialize(options = {})
|
14
|
-
options = {
|
15
|
-
background_color: default(:background_color),
|
16
|
-
border_color: default(:border_color),
|
17
|
-
}.merge! options
|
18
|
-
|
19
|
-
super options
|
20
|
-
|
21
|
-
group do
|
22
|
-
subscribe :changed do |sender, value|
|
23
|
-
publish :changed, value
|
24
|
-
end
|
25
|
-
|
26
|
-
@items = vertical spacing: 0
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
# @param [String] text
|
31
|
-
# @option options [Gosu::Image] :icon
|
32
|
-
def item(text, value, options = {}, &block)
|
33
|
-
Item.new(text, value, { parent: @items }.merge!(options), &block)
|
34
|
-
end
|
35
|
-
|
36
|
-
protected
|
37
|
-
def layout
|
38
|
-
super
|
39
|
-
if @items
|
40
|
-
max_width = @items.each.to_a.map {|c| c.width }.max || 0
|
41
|
-
@items.each {|c| c.rect.width = max_width }
|
42
|
-
end
|
43
|
-
|
44
|
-
nil
|
45
|
-
end
|
46
|
-
end
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Fidgit
|
4
|
+
class List < Composite
|
5
|
+
class Item < RadioButton
|
6
|
+
end
|
7
|
+
|
8
|
+
event :changed
|
9
|
+
|
10
|
+
def size; @items.size; end
|
11
|
+
def clear; @items.clear; end
|
12
|
+
|
13
|
+
def initialize(options = {})
|
14
|
+
options = {
|
15
|
+
background_color: default(:background_color),
|
16
|
+
border_color: default(:border_color),
|
17
|
+
}.merge! options
|
18
|
+
|
19
|
+
super options
|
20
|
+
|
21
|
+
group do
|
22
|
+
subscribe :changed do |sender, value|
|
23
|
+
publish :changed, value
|
24
|
+
end
|
25
|
+
|
26
|
+
@items = vertical spacing: 0
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# @param [String] text
|
31
|
+
# @option options [Gosu::Image] :icon
|
32
|
+
def item(text, value, options = {}, &block)
|
33
|
+
Item.new(text, value, { parent: @items }.merge!(options), &block)
|
34
|
+
end
|
35
|
+
|
36
|
+
protected
|
37
|
+
def layout
|
38
|
+
super
|
39
|
+
if @items
|
40
|
+
max_width = @items.each.to_a.map {|c| c.width }.max || 0
|
41
|
+
@items.each {|c| c.rect.width = max_width }
|
42
|
+
end
|
43
|
+
|
44
|
+
nil
|
45
|
+
end
|
46
|
+
end
|
47
47
|
end
|
@@ -1,25 +1,25 @@
|
|
1
|
-
require_relative "vertical"
|
2
|
-
|
3
|
-
module Fidgit
|
4
|
-
# Main container that can contains a single "proper" packing element.
|
5
|
-
class MainPacker < Vertical
|
6
|
-
def initialize(options = {})
|
7
|
-
options = {
|
8
|
-
width: $window.width,
|
9
|
-
height: $window.height,
|
10
|
-
}.merge! options
|
11
|
-
|
12
|
-
super options
|
13
|
-
end
|
14
|
-
|
15
|
-
def width; $window.width; end
|
16
|
-
def height; $window.height; end
|
17
|
-
def width=(value); ; end
|
18
|
-
def height=(value); ; end
|
19
|
-
|
20
|
-
def add(element)
|
21
|
-
raise "MainPacker can only contain packing elements" unless element.is_a? Packer
|
22
|
-
super(element)
|
23
|
-
end
|
24
|
-
end
|
1
|
+
require_relative "vertical"
|
2
|
+
|
3
|
+
module Fidgit
|
4
|
+
# Main container that can contains a single "proper" packing element.
|
5
|
+
class MainPacker < Vertical
|
6
|
+
def initialize(options = {})
|
7
|
+
options = {
|
8
|
+
width: $window.width,
|
9
|
+
height: $window.height,
|
10
|
+
}.merge! options
|
11
|
+
|
12
|
+
super options
|
13
|
+
end
|
14
|
+
|
15
|
+
def width; $window.width; end
|
16
|
+
def height; $window.height; end
|
17
|
+
def width=(value); ; end
|
18
|
+
def height=(value); ; end
|
19
|
+
|
20
|
+
def add(element)
|
21
|
+
raise "MainPacker can only contain packing elements" unless element.is_a? Packer
|
22
|
+
super(element)
|
23
|
+
end
|
24
|
+
end
|
25
25
|
end
|
@@ -1,161 +1,161 @@
|
|
1
|
-
module Fidgit
|
2
|
-
class MenuPane < Composite
|
3
|
-
# An item within the menu.
|
4
|
-
class Item < Button
|
5
|
-
attr_reader :value, :shortcut_text
|
6
|
-
|
7
|
-
# @param (see Button#initialize)
|
8
|
-
#
|
9
|
-
# @option (see Button#initialize)
|
10
|
-
# @param [any] value Value if the user picks this item
|
11
|
-
# @option options [String] :shortcut_text ('')
|
12
|
-
def initialize(text, value, options = {})
|
13
|
-
options = {
|
14
|
-
enabled: true,
|
15
|
-
border_color: default(:border_color),
|
16
|
-
shortcut_text: '',
|
17
|
-
}.merge! options
|
18
|
-
|
19
|
-
@value = value
|
20
|
-
@shortcut_text = options[:shortcut_text]
|
21
|
-
|
22
|
-
super(text, options)
|
23
|
-
end
|
24
|
-
|
25
|
-
def draw_foreground
|
26
|
-
super
|
27
|
-
|
28
|
-
unless @shortcut_text.empty?
|
29
|
-
font.draw_rel("#{@shortcut_text}", rect.right - padding_right, y + ((height - font.height) / 2).floor, z, 1, 0, 1, 1, color)
|
30
|
-
end
|
31
|
-
|
32
|
-
nil
|
33
|
-
end
|
34
|
-
|
35
|
-
protected
|
36
|
-
def layout
|
37
|
-
super
|
38
|
-
|
39
|
-
# Ignore layout request when asked before TextLine has been created.
|
40
|
-
rect.width += font.text_width(" #{@shortcut_text}") unless @shortcut_text.empty? or @text.nil?
|
41
|
-
|
42
|
-
nil
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
class Separator < Label
|
47
|
-
# @param (see Item#initialize)
|
48
|
-
#
|
49
|
-
# @option (see Item#initialize)
|
50
|
-
def initialize(options = {})
|
51
|
-
options = {
|
52
|
-
height: default(:line_height),
|
53
|
-
background_color: default(:background_color),
|
54
|
-
padding: 0,
|
55
|
-
}.merge! options
|
56
|
-
|
57
|
-
super '', options
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
extend Forwardable
|
62
|
-
|
63
|
-
def_delegators :@items, :each, :clear, :size, :[]
|
64
|
-
|
65
|
-
event :selected
|
66
|
-
|
67
|
-
def index(value); @items.index find(value); end
|
68
|
-
def x=(value); super(value); recalc; end
|
69
|
-
def y=(value); super(value); recalc; end
|
70
|
-
|
71
|
-
# @option (see Composite#initialize)
|
72
|
-
# @option options [Float] :x (cursor x, if in a GuiState)
|
73
|
-
# @option options [Float] :y (cursor y, if in a GuiState)
|
74
|
-
# @option options [Boolean] :show (true) Whether to show immediately (show later with #show).
|
75
|
-
def initialize(options = {}, &block)
|
76
|
-
options = {
|
77
|
-
background_color: default(:color),
|
78
|
-
z: Float::INFINITY,
|
79
|
-
show: true,
|
80
|
-
}.merge! options
|
81
|
-
|
82
|
-
state = $window.current_game_state
|
83
|
-
if state.is_a? GuiState
|
84
|
-
cursor = $window.current_game_state.cursor
|
85
|
-
options = {
|
86
|
-
x: cursor.x,
|
87
|
-
y: cursor.y,
|
88
|
-
}.merge! options
|
89
|
-
end
|
90
|
-
|
91
|
-
@items = nil
|
92
|
-
|
93
|
-
super(options)
|
94
|
-
|
95
|
-
@items = vertical spacing: 0, padding: 0
|
96
|
-
|
97
|
-
if options[:show] and state.is_a? GuiState
|
98
|
-
show
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
def find(value)
|
103
|
-
@items.find {|c| c.value == value }
|
104
|
-
end
|
105
|
-
|
106
|
-
def separator(options = {})
|
107
|
-
options[:z] = z
|
108
|
-
|
109
|
-
Separator.new({ parent: @items }.merge!(options))
|
110
|
-
end
|
111
|
-
|
112
|
-
def item(text, value, options = {}, &block)
|
113
|
-
options = options.merge({
|
114
|
-
parent: @items,
|
115
|
-
z: z,
|
116
|
-
})
|
117
|
-
item = Item.new(text, value, options, &block)
|
118
|
-
|
119
|
-
item.subscribe :left_mouse_button, method(:item_selected)
|
120
|
-
item.subscribe :right_mouse_button, method(:item_selected)
|
121
|
-
|
122
|
-
item
|
123
|
-
end
|
124
|
-
|
125
|
-
def item_selected(sender, x, y)
|
126
|
-
publish(:selected, sender.value)
|
127
|
-
|
128
|
-
$window.game_state_manager.current_game_state.hide_menu
|
129
|
-
|
130
|
-
nil
|
131
|
-
end
|
132
|
-
|
133
|
-
def show
|
134
|
-
$window.game_state_manager.current_game_state.show_menu self
|
135
|
-
nil
|
136
|
-
end
|
137
|
-
|
138
|
-
protected
|
139
|
-
def layout
|
140
|
-
super
|
141
|
-
|
142
|
-
if @items
|
143
|
-
# Ensure the menu can't go over the edge of the screen. If it can't be avoided, align with top-left edge of screen.
|
144
|
-
rect.x = [[x, $window.width - width - padding_right].min, 0].max
|
145
|
-
rect.y = [[y, $window.height - height - padding_bottom].min, 0].max
|
146
|
-
|
147
|
-
# Move the actual list if the menu has moved to keep on the screen.
|
148
|
-
@items.x = x + padding_left
|
149
|
-
@items.y = y + padding_top
|
150
|
-
|
151
|
-
# Ensure that all items are of the same width.
|
152
|
-
max_width = @items.map(&:width).max || 0
|
153
|
-
@items.each {|c| c.rect.width = max_width }
|
154
|
-
|
155
|
-
@items.recalc # Move all the items inside the packer to correct ones.
|
156
|
-
end
|
157
|
-
|
158
|
-
nil
|
159
|
-
end
|
160
|
-
end
|
1
|
+
module Fidgit
|
2
|
+
class MenuPane < Composite
|
3
|
+
# An item within the menu.
|
4
|
+
class Item < Button
|
5
|
+
attr_reader :value, :shortcut_text
|
6
|
+
|
7
|
+
# @param (see Button#initialize)
|
8
|
+
#
|
9
|
+
# @option (see Button#initialize)
|
10
|
+
# @param [any] value Value if the user picks this item
|
11
|
+
# @option options [String] :shortcut_text ('')
|
12
|
+
def initialize(text, value, options = {})
|
13
|
+
options = {
|
14
|
+
enabled: true,
|
15
|
+
border_color: default(:border_color),
|
16
|
+
shortcut_text: '',
|
17
|
+
}.merge! options
|
18
|
+
|
19
|
+
@value = value
|
20
|
+
@shortcut_text = options[:shortcut_text]
|
21
|
+
|
22
|
+
super(text, options)
|
23
|
+
end
|
24
|
+
|
25
|
+
def draw_foreground
|
26
|
+
super
|
27
|
+
|
28
|
+
unless @shortcut_text.empty?
|
29
|
+
font.draw_rel("#{@shortcut_text}", rect.right - padding_right, y + ((height - font.height) / 2).floor, z, 1, 0, 1, 1, color)
|
30
|
+
end
|
31
|
+
|
32
|
+
nil
|
33
|
+
end
|
34
|
+
|
35
|
+
protected
|
36
|
+
def layout
|
37
|
+
super
|
38
|
+
|
39
|
+
# Ignore layout request when asked before TextLine has been created.
|
40
|
+
rect.width += font.text_width(" #{@shortcut_text}") unless @shortcut_text.empty? or @text.nil?
|
41
|
+
|
42
|
+
nil
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class Separator < Label
|
47
|
+
# @param (see Item#initialize)
|
48
|
+
#
|
49
|
+
# @option (see Item#initialize)
|
50
|
+
def initialize(options = {})
|
51
|
+
options = {
|
52
|
+
height: default(:line_height),
|
53
|
+
background_color: default(:background_color),
|
54
|
+
padding: 0,
|
55
|
+
}.merge! options
|
56
|
+
|
57
|
+
super '', options
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
extend Forwardable
|
62
|
+
|
63
|
+
def_delegators :@items, :each, :clear, :size, :[]
|
64
|
+
|
65
|
+
event :selected
|
66
|
+
|
67
|
+
def index(value); @items.index find(value); end
|
68
|
+
def x=(value); super(value); recalc; end
|
69
|
+
def y=(value); super(value); recalc; end
|
70
|
+
|
71
|
+
# @option (see Composite#initialize)
|
72
|
+
# @option options [Float] :x (cursor x, if in a GuiState)
|
73
|
+
# @option options [Float] :y (cursor y, if in a GuiState)
|
74
|
+
# @option options [Boolean] :show (true) Whether to show immediately (show later with #show).
|
75
|
+
def initialize(options = {}, &block)
|
76
|
+
options = {
|
77
|
+
background_color: default(:color),
|
78
|
+
z: Float::INFINITY,
|
79
|
+
show: true,
|
80
|
+
}.merge! options
|
81
|
+
|
82
|
+
state = $window.current_game_state
|
83
|
+
if state.is_a? GuiState
|
84
|
+
cursor = $window.current_game_state.cursor
|
85
|
+
options = {
|
86
|
+
x: cursor.x,
|
87
|
+
y: cursor.y,
|
88
|
+
}.merge! options
|
89
|
+
end
|
90
|
+
|
91
|
+
@items = nil
|
92
|
+
|
93
|
+
super(options)
|
94
|
+
|
95
|
+
@items = vertical spacing: 0, padding: 0
|
96
|
+
|
97
|
+
if options[:show] and state.is_a? GuiState
|
98
|
+
show
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def find(value)
|
103
|
+
@items.find {|c| c.value == value }
|
104
|
+
end
|
105
|
+
|
106
|
+
def separator(options = {})
|
107
|
+
options[:z] = z
|
108
|
+
|
109
|
+
Separator.new({ parent: @items }.merge!(options))
|
110
|
+
end
|
111
|
+
|
112
|
+
def item(text, value, options = {}, &block)
|
113
|
+
options = options.merge({
|
114
|
+
parent: @items,
|
115
|
+
z: z,
|
116
|
+
})
|
117
|
+
item = Item.new(text, value, options, &block)
|
118
|
+
|
119
|
+
item.subscribe :left_mouse_button, method(:item_selected)
|
120
|
+
item.subscribe :right_mouse_button, method(:item_selected)
|
121
|
+
|
122
|
+
item
|
123
|
+
end
|
124
|
+
|
125
|
+
def item_selected(sender, x, y)
|
126
|
+
publish(:selected, sender.value)
|
127
|
+
|
128
|
+
$window.game_state_manager.current_game_state.hide_menu
|
129
|
+
|
130
|
+
nil
|
131
|
+
end
|
132
|
+
|
133
|
+
def show
|
134
|
+
$window.game_state_manager.current_game_state.show_menu self
|
135
|
+
nil
|
136
|
+
end
|
137
|
+
|
138
|
+
protected
|
139
|
+
def layout
|
140
|
+
super
|
141
|
+
|
142
|
+
if @items
|
143
|
+
# Ensure the menu can't go over the edge of the screen. If it can't be avoided, align with top-left edge of screen.
|
144
|
+
rect.x = [[x, $window.width - width - padding_right].min, 0].max
|
145
|
+
rect.y = [[y, $window.height - height - padding_bottom].min, 0].max
|
146
|
+
|
147
|
+
# Move the actual list if the menu has moved to keep on the screen.
|
148
|
+
@items.x = x + padding_left
|
149
|
+
@items.y = y + padding_top
|
150
|
+
|
151
|
+
# Ensure that all items are of the same width.
|
152
|
+
max_width = @items.map(&:width).max || 0
|
153
|
+
@items.each {|c| c.rect.width = max_width }
|
154
|
+
|
155
|
+
@items.recalc # Move all the items inside the packer to correct ones.
|
156
|
+
end
|
157
|
+
|
158
|
+
nil
|
159
|
+
end
|
160
|
+
end
|
161
161
|
end
|