shoes-core 4.0.0.pre8 → 4.0.0.pre9
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.
- checksums.yaml +4 -4
- data/bin/shoes-picker +1 -0
- data/lib/shoes.rb +1 -0
- data/lib/shoes/animation.rb +1 -0
- data/lib/shoes/app.rb +7 -1
- data/lib/shoes/arc.rb +2 -3
- data/lib/shoes/arrow.rb +2 -3
- data/lib/shoes/background.rb +2 -2
- data/lib/shoes/border.rb +2 -2
- data/lib/shoes/builtin_methods.rb +2 -2
- data/lib/shoes/button.rb +2 -2
- data/lib/shoes/check_button.rb +2 -2
- data/lib/shoes/color.rb +1 -0
- data/lib/shoes/color/dsl.rb +1 -0
- data/lib/shoes/color/dsl_helpers.rb +1 -0
- data/lib/shoes/color/hex_converter.rb +1 -0
- data/lib/shoes/common/art_element.rb +6 -9
- data/lib/shoes/common/attachable.rb +1 -0
- data/lib/shoes/common/background_element.rb +2 -11
- data/lib/shoes/common/changeable.rb +1 -0
- data/lib/shoes/common/clickable.rb +1 -0
- data/lib/shoes/common/fill.rb +1 -0
- data/lib/shoes/common/hover.rb +2 -1
- data/lib/shoes/common/inspect.rb +1 -0
- data/lib/shoes/common/link_finder.rb +1 -0
- data/lib/shoes/common/positioning.rb +1 -0
- data/lib/shoes/common/registration.rb +1 -0
- data/lib/shoes/common/remove.rb +1 -0
- data/lib/shoes/common/rotate.rb +1 -0
- data/lib/shoes/common/safely_evaluate.rb +13 -0
- data/lib/shoes/common/state.rb +4 -10
- data/lib/shoes/common/stroke.rb +1 -0
- data/lib/shoes/common/style.rb +13 -3
- data/lib/shoes/common/style_normalizer.rb +1 -0
- data/lib/shoes/common/translate.rb +1 -0
- data/lib/shoes/common/ui_element.rb +67 -5
- data/lib/shoes/common/visibility.rb +7 -6
- data/lib/shoes/configuration.rb +5 -16
- data/lib/shoes/console.rb +91 -0
- data/lib/shoes/core.rb +1 -1
- data/lib/shoes/core/version.rb +1 -1
- data/lib/shoes/dialog.rb +1 -0
- data/lib/shoes/dimension.rb +1 -0
- data/lib/shoes/dimensions.rb +1 -0
- data/lib/shoes/download.rb +1 -0
- data/lib/shoes/dsl.rb +28 -588
- data/lib/shoes/dsl/animate.rb +51 -0
- data/lib/shoes/dsl/art.rb +256 -0
- data/lib/shoes/dsl/element.rb +56 -0
- data/lib/shoes/dsl/interaction.rb +76 -0
- data/lib/shoes/dsl/media.rb +38 -0
- data/lib/shoes/dsl/setup.rb +42 -0
- data/lib/shoes/dsl/style.rb +81 -0
- data/lib/shoes/dsl/text.rb +50 -0
- data/lib/shoes/file_not_found_error.rb +1 -0
- data/lib/shoes/font.rb +2 -1
- data/lib/shoes/gradient.rb +1 -0
- data/lib/shoes/image.rb +2 -2
- data/lib/shoes/image_pattern.rb +1 -0
- data/lib/shoes/input_box.rb +11 -2
- data/lib/shoes/internal_app.rb +16 -3
- data/lib/shoes/key_event.rb +1 -0
- data/lib/shoes/line.rb +2 -3
- data/lib/shoes/link.rb +2 -0
- data/lib/shoes/list_box.rb +3 -3
- data/lib/shoes/logger_collection.rb +38 -0
- data/lib/shoes/mock.rb +1 -0
- data/lib/shoes/mock/animation.rb +1 -0
- data/lib/shoes/mock/app.rb +1 -0
- data/lib/shoes/mock/arc.rb +1 -0
- data/lib/shoes/mock/arrow.rb +1 -0
- data/lib/shoes/mock/background.rb +1 -0
- data/lib/shoes/mock/border.rb +1 -0
- data/lib/shoes/mock/button.rb +1 -0
- data/lib/shoes/mock/check.rb +1 -0
- data/lib/shoes/mock/clickable.rb +1 -0
- data/lib/shoes/mock/common_methods.rb +1 -0
- data/lib/shoes/mock/dialog.rb +1 -0
- data/lib/shoes/mock/download.rb +1 -0
- data/lib/shoes/mock/font.rb +1 -0
- data/lib/shoes/mock/image.rb +1 -0
- data/lib/shoes/mock/image_pattern.rb +1 -0
- data/lib/shoes/mock/input_box.rb +4 -0
- data/lib/shoes/mock/keypress.rb +1 -0
- data/lib/shoes/mock/keyrelease.rb +1 -0
- data/lib/shoes/mock/line.rb +1 -0
- data/lib/shoes/mock/link.rb +1 -0
- data/lib/shoes/mock/list_box.rb +1 -0
- data/lib/shoes/mock/oval.rb +1 -0
- data/lib/shoes/mock/packager.rb +3 -0
- data/lib/shoes/mock/progress.rb +1 -0
- data/lib/shoes/mock/radio.rb +1 -0
- data/lib/shoes/mock/rect.rb +1 -0
- data/lib/shoes/mock/shape.rb +1 -0
- data/lib/shoes/mock/slot.rb +1 -0
- data/lib/shoes/mock/sound.rb +1 -0
- data/lib/shoes/mock/star.rb +1 -0
- data/lib/shoes/mock/text_block.rb +1 -0
- data/lib/shoes/mock/timer.rb +1 -0
- data/lib/shoes/not_implemented_error.rb +1 -0
- data/lib/shoes/oval.rb +2 -3
- data/lib/shoes/packager.rb +13 -0
- data/lib/shoes/point.rb +1 -0
- data/lib/shoes/progress.rb +2 -3
- data/lib/shoes/radio.rb +1 -0
- data/lib/shoes/rect.rb +2 -3
- data/lib/shoes/renamed_delegate.rb +1 -0
- data/lib/shoes/shape.rb +2 -4
- data/lib/shoes/slot.rb +3 -3
- data/lib/shoes/slot_contents.rb +1 -0
- data/lib/shoes/sound.rb +1 -0
- data/lib/shoes/span.rb +1 -0
- data/lib/shoes/standard_logger.rb +14 -0
- data/lib/shoes/star.rb +2 -3
- data/lib/shoes/text.rb +1 -0
- data/lib/shoes/text_block.rb +4 -4
- data/lib/shoes/text_block_dimensions.rb +1 -0
- data/lib/shoes/timer.rb +1 -0
- data/lib/shoes/ui/cli.rb +5 -0
- data/lib/shoes/ui/picker.rb +2 -1
- data/lib/shoes/url.rb +1 -0
- data/lib/shoes/version.rb +1 -1
- data/lib/shoes/widget.rb +1 -0
- data/lib/shoes/window.rb +1 -0
- metadata +14 -5
- data/lib/shoes/common/initialization.rb +0 -71
- data/lib/shoes/logger.rb +0 -65
- data/lib/shoes/logger/ruby.rb +0 -15
@@ -1,10 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
class Shoes
|
2
3
|
module Common
|
3
4
|
module Visibility
|
4
5
|
# Hides the element, so that it can't be seen. See also #show and #toggle.
|
5
6
|
def hide
|
6
|
-
style
|
7
|
-
|
7
|
+
style(hidden: true)
|
8
|
+
self
|
8
9
|
end
|
9
10
|
|
10
11
|
def hidden?
|
@@ -19,15 +20,15 @@ class Shoes
|
|
19
20
|
|
20
21
|
# Reveals the element, if it is hidden. See also #hide and #toggle.
|
21
22
|
def show
|
22
|
-
style
|
23
|
-
|
23
|
+
style(hidden: false)
|
24
|
+
self
|
24
25
|
end
|
25
26
|
|
26
27
|
# Hides an element if it is shown. Or shows the element, if it is hidden.
|
27
28
|
# See also #hide and #show.
|
28
29
|
def toggle
|
29
|
-
style
|
30
|
-
|
30
|
+
style(hidden: !style[:hidden])
|
31
|
+
self
|
31
32
|
end
|
32
33
|
|
33
34
|
private
|
data/lib/shoes/configuration.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
class Shoes
|
2
3
|
class Configuration
|
3
4
|
class << self
|
4
|
-
|
5
|
-
|
6
|
-
|
5
|
+
attr_writer :fail_fast
|
6
|
+
|
7
|
+
def fail_fast
|
8
|
+
@fail_fast ||= ENV["SHOES_FAIL_FAST"]
|
7
9
|
end
|
8
10
|
|
9
11
|
def backend
|
@@ -71,19 +73,6 @@ class Shoes
|
|
71
73
|
klass = backend_class(shoes_object)
|
72
74
|
klass.respond_to?(:create) ? klass.method(:create) : klass.method(:new)
|
73
75
|
end
|
74
|
-
|
75
|
-
def logger=(value)
|
76
|
-
@logger = value
|
77
|
-
@logger_instance = nil
|
78
|
-
end
|
79
|
-
|
80
|
-
def logger
|
81
|
-
@logger ||= :ruby
|
82
|
-
end
|
83
|
-
|
84
|
-
def logger_instance
|
85
|
-
@logger_instance ||= Shoes::Logger.get(logger).new
|
86
|
-
end
|
87
76
|
end
|
88
77
|
end
|
89
78
|
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
class Shoes
|
3
|
+
class Console
|
4
|
+
def initialize
|
5
|
+
@messages = []
|
6
|
+
end
|
7
|
+
|
8
|
+
def show
|
9
|
+
if showing?
|
10
|
+
@app.focus
|
11
|
+
else
|
12
|
+
create_app
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def showing?
|
17
|
+
@app && @app.open?
|
18
|
+
end
|
19
|
+
|
20
|
+
def create_app
|
21
|
+
# Capture messages for access inside our app block
|
22
|
+
messages = @messages
|
23
|
+
|
24
|
+
@app = Shoes.app do
|
25
|
+
@messages = messages
|
26
|
+
@message_stacks = []
|
27
|
+
|
28
|
+
stack do
|
29
|
+
flow do
|
30
|
+
background black
|
31
|
+
stack do
|
32
|
+
tagline "Shoes Console", stroke: white
|
33
|
+
end
|
34
|
+
|
35
|
+
button "Clear", margin: 6, width: 80, height: 40, right: 10 do
|
36
|
+
@messages.clear
|
37
|
+
|
38
|
+
@message_stacks.each(&:remove)
|
39
|
+
@message_stacks.clear
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
@messages.each_with_index do |(type, message), index|
|
46
|
+
add_message_stack(type, message, index)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def debug(message)
|
51
|
+
add_message(:debug, message)
|
52
|
+
end
|
53
|
+
|
54
|
+
def info(message)
|
55
|
+
add_message(:info, message)
|
56
|
+
end
|
57
|
+
|
58
|
+
def warn(message)
|
59
|
+
add_message(:warn, message)
|
60
|
+
end
|
61
|
+
|
62
|
+
def error(message)
|
63
|
+
add_message(:error, message)
|
64
|
+
end
|
65
|
+
|
66
|
+
def add_message(type, message)
|
67
|
+
@messages << [type, message]
|
68
|
+
add_message_stack(type, message, @messages.count - 1)
|
69
|
+
end
|
70
|
+
|
71
|
+
def add_message_stack(type, message, index = nil)
|
72
|
+
return unless @app && @app.open?
|
73
|
+
|
74
|
+
@app.instance_exec do
|
75
|
+
append do
|
76
|
+
@message_stacks << stack do
|
77
|
+
background "#f1f5e1" if index.even?
|
78
|
+
background rgb(220, 220, 220) if index.odd?
|
79
|
+
para type, stroke: blue
|
80
|
+
flow do
|
81
|
+
stack margin: 4 do
|
82
|
+
s = message.to_s
|
83
|
+
para s, margin: 4, margin_top: 0
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
data/lib/shoes/core.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
require 'shoes/dsl'
|
data/lib/shoes/core/version.rb
CHANGED
data/lib/shoes/dialog.rb
CHANGED
data/lib/shoes/dimension.rb
CHANGED
data/lib/shoes/dimensions.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
# Dimensions is a central class that most Shoes classes use to represent their
|
2
3
|
# dimensions, e.g. where they are and how much space they are taking up there.
|
3
4
|
# All the different position types might be confusing. So here is a little list:
|
data/lib/shoes/download.rb
CHANGED
data/lib/shoes/dsl.rb
CHANGED
@@ -1,16 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'delegate'
|
2
3
|
require 'fileutils'
|
3
4
|
require 'forwardable'
|
4
5
|
require 'pathname'
|
5
6
|
require 'tmpdir'
|
6
7
|
require 'shoes/common/registration'
|
8
|
+
require 'shoes/dsl/setup'
|
7
9
|
|
8
10
|
class Shoes
|
9
11
|
PI = Math::PI
|
10
12
|
TWO_PI = 2 * PI
|
11
13
|
HALF_PI = 0.5 * PI
|
12
14
|
DIR = Pathname.new(__FILE__).parent.parent.parent.to_s
|
13
|
-
LOG = []
|
14
15
|
LEFT_MOUSE_BUTTON = 1
|
15
16
|
MIDDLE_MOUSE_BUTTON = 2
|
16
17
|
RIGHT_MOUSE_BUTTON = 3
|
@@ -18,45 +19,16 @@ class Shoes
|
|
18
19
|
extend Common::Registration
|
19
20
|
|
20
21
|
class << self
|
21
|
-
def
|
22
|
-
Shoes.
|
23
|
-
end
|
24
|
-
|
25
|
-
# To ease the upgrade path from Shoes 3 we warn users they need to install
|
26
|
-
# and require gems themselves.
|
27
|
-
#
|
28
|
-
# @example
|
29
|
-
# Shoes.setup do
|
30
|
-
# gem 'bluecloth =2.0.6'
|
31
|
-
# gem 'metaid'
|
32
|
-
# end
|
33
|
-
#
|
34
|
-
# @param block [Proc] The block that describes the gems that are needed
|
35
|
-
# @deprecated
|
36
|
-
def setup(&block)
|
37
|
-
$stderr.puts "WARN: The Shoes.setup method is deprecated, you need to install gems yourself." \
|
38
|
-
"You can do this using the 'gem install' command or bundler and a Gemfile."
|
39
|
-
DeprecatedShoesGemSetup.new.instance_eval(&block)
|
22
|
+
def console
|
23
|
+
@console ||= Shoes::Console.new
|
40
24
|
end
|
41
25
|
|
42
|
-
|
43
|
-
|
44
|
-
# @param name [String|Symbol] The name, such as :swt or :mock
|
45
|
-
# @return The backend
|
46
|
-
def load_backend(name)
|
47
|
-
require "shoes/#{name.to_s.downcase}"
|
48
|
-
Shoes.const_get(name.to_s.capitalize)
|
49
|
-
rescue LoadError => e
|
50
|
-
raise LoadError, "Couldn't load backend Shoes::#{name.capitalize}'. Error: #{e.message}\n#{e.backtrace.join("\n")}"
|
51
|
-
end
|
52
|
-
end
|
26
|
+
def logger
|
27
|
+
return @logger if @logger
|
53
28
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
install_cmd = 'gem install ' + name
|
58
|
-
install_cmd += " --version \"#{version}\"" if version
|
59
|
-
$stderr.puts "WARN: To use the '#{name}' gem, install it with '#{install_cmd}', and put 'require \"#{name}\"' at the top of your Shoes program."
|
29
|
+
@logger ||= Shoes::LoggerCollection.new
|
30
|
+
@logger << Shoes::StandardLogger.new
|
31
|
+
@logger << console
|
60
32
|
end
|
61
33
|
end
|
62
34
|
end
|
@@ -75,16 +47,24 @@ require 'shoes/text_block_dimensions'
|
|
75
47
|
|
76
48
|
require 'shoes/color'
|
77
49
|
|
50
|
+
require 'shoes/dsl/animate'
|
51
|
+
require 'shoes/dsl/art'
|
52
|
+
require 'shoes/dsl/element'
|
53
|
+
require 'shoes/dsl/style'
|
54
|
+
require 'shoes/dsl/interaction'
|
55
|
+
require 'shoes/dsl/media'
|
56
|
+
require 'shoes/dsl/text'
|
57
|
+
|
78
58
|
require 'shoes/common/attachable'
|
79
59
|
require 'shoes/common/changeable'
|
80
60
|
require 'shoes/common/clickable'
|
81
61
|
require 'shoes/common/fill'
|
82
62
|
require 'shoes/common/hover'
|
83
|
-
require 'shoes/common/initialization'
|
84
63
|
require 'shoes/common/link_finder'
|
85
64
|
require 'shoes/common/positioning'
|
86
65
|
require 'shoes/common/remove'
|
87
66
|
require 'shoes/common/rotate'
|
67
|
+
require 'shoes/common/safely_evaluate'
|
88
68
|
require 'shoes/common/state'
|
89
69
|
require 'shoes/common/stroke'
|
90
70
|
require 'shoes/common/style'
|
@@ -98,8 +78,10 @@ require 'shoes/common/background_element'
|
|
98
78
|
|
99
79
|
require 'shoes/builtin_methods'
|
100
80
|
require 'shoes/check_button'
|
81
|
+
require 'shoes/logger_collection'
|
101
82
|
require 'shoes/text'
|
102
83
|
require 'shoes/span'
|
84
|
+
require 'shoes/standard_logger'
|
103
85
|
require 'shoes/input_box'
|
104
86
|
|
105
87
|
# please keep this list tidy and alphabetically sorted
|
@@ -110,6 +92,7 @@ require 'shoes/background'
|
|
110
92
|
require 'shoes/border'
|
111
93
|
require 'shoes/button'
|
112
94
|
require 'shoes/configuration'
|
95
|
+
require 'shoes/console'
|
113
96
|
require 'shoes/color'
|
114
97
|
require 'shoes/dialog'
|
115
98
|
require 'shoes/download'
|
@@ -121,7 +104,6 @@ require 'shoes/key_event'
|
|
121
104
|
require 'shoes/line'
|
122
105
|
require 'shoes/link'
|
123
106
|
require 'shoes/list_box'
|
124
|
-
require 'shoes/logger'
|
125
107
|
require 'shoes/oval'
|
126
108
|
require 'shoes/point'
|
127
109
|
require 'shoes/progress'
|
@@ -152,561 +134,19 @@ class Shoes
|
|
152
134
|
module DSL
|
153
135
|
include Color::DSLHelpers
|
154
136
|
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
# @example
|
163
|
-
# style Para, :text_size => 42, :stroke => green
|
164
|
-
#
|
165
|
-
# @overload style(styles)
|
166
|
-
# Set default style for all elements
|
167
|
-
# @param [Hash] styles default style for all elements
|
168
|
-
# @example
|
169
|
-
# style :stroke => alicewhite, :fill => black
|
170
|
-
#
|
171
|
-
# @overload style()
|
172
|
-
# @return [Hash] the default style for all elements
|
173
|
-
def style(klass_or_styles = nil, styles = {})
|
174
|
-
if klass_or_styles.kind_of? Class
|
175
|
-
klass = klass_or_styles
|
176
|
-
@__app__.element_styles[klass] = styles
|
177
|
-
else
|
178
|
-
@__app__.style(klass_or_styles)
|
179
|
-
end
|
180
|
-
end
|
137
|
+
include DSL::Animate
|
138
|
+
include DSL::Art
|
139
|
+
include DSL::Element
|
140
|
+
include DSL::Style
|
141
|
+
include DSL::Interaction
|
142
|
+
include DSL::Media
|
143
|
+
include DSL::Text
|
181
144
|
|
182
145
|
private
|
183
146
|
|
184
|
-
def style_normalizer
|
185
|
-
@style_normalizer ||= Common::StyleNormalizer.new
|
186
|
-
end
|
187
|
-
|
188
|
-
def pop_style(opts)
|
189
|
-
opts.last.class == Hash ? opts.pop : {}
|
190
|
-
end
|
191
|
-
|
192
|
-
# Default styles for elements of klass
|
193
|
-
def style_for_element(klass, styles = {})
|
194
|
-
@__app__.element_styles.fetch(klass, {}).merge(styles)
|
195
|
-
end
|
196
|
-
|
197
|
-
def normalize_style_for_element(clazz, texts)
|
198
|
-
style = style_normalizer.normalize(pop_style(texts))
|
199
|
-
style_for_element(clazz, style)
|
200
|
-
end
|
201
|
-
|
202
147
|
def create(element, *args, &blk)
|
203
148
|
element.new(@__app__, @__app__.current_slot, *args, &blk)
|
204
149
|
end
|
205
|
-
|
206
|
-
public
|
207
|
-
|
208
|
-
def image(path, styles = {}, &blk)
|
209
|
-
create Shoes::Image, path, styles, blk
|
210
|
-
end
|
211
|
-
|
212
|
-
def border(color, styles = {})
|
213
|
-
create Shoes::Border, pattern(color), styles
|
214
|
-
end
|
215
|
-
|
216
|
-
def background(color, styles = {})
|
217
|
-
create Shoes::Background, pattern(color), style_normalizer.normalize(styles)
|
218
|
-
end
|
219
|
-
|
220
|
-
def edit_line(*args, &blk)
|
221
|
-
style = pop_style(args)
|
222
|
-
text = args.first || ''
|
223
|
-
create Shoes::EditLine, text, style, blk
|
224
|
-
end
|
225
|
-
|
226
|
-
def edit_box(*args, &blk)
|
227
|
-
style = pop_style(args)
|
228
|
-
text = args.first || ''
|
229
|
-
create Shoes::EditBox, text, style, blk
|
230
|
-
end
|
231
|
-
|
232
|
-
def progress(opts = {}, &blk)
|
233
|
-
create Shoes::Progress, opts, blk
|
234
|
-
end
|
235
|
-
|
236
|
-
def check(opts = {}, &blk)
|
237
|
-
create Shoes::Check, opts, blk
|
238
|
-
end
|
239
|
-
|
240
|
-
def radio(*args, &blk)
|
241
|
-
style = pop_style(args)
|
242
|
-
group = args.first
|
243
|
-
create Shoes::Radio, group, style, blk
|
244
|
-
end
|
245
|
-
|
246
|
-
def list_box(opts = {}, &blk)
|
247
|
-
create Shoes::ListBox, opts, blk
|
248
|
-
end
|
249
|
-
|
250
|
-
def flow(opts = {}, &blk)
|
251
|
-
create Shoes::Flow, opts, blk
|
252
|
-
end
|
253
|
-
|
254
|
-
def stack(opts = {}, &blk)
|
255
|
-
create Shoes::Stack, opts, blk
|
256
|
-
end
|
257
|
-
|
258
|
-
def button(text = nil, opts = {}, &blk)
|
259
|
-
create Shoes::Button, text, opts, blk
|
260
|
-
end
|
261
|
-
|
262
|
-
# Creates an animation that runs the given block of code.
|
263
|
-
#
|
264
|
-
# @overload animate &blk
|
265
|
-
# @param [Proc] blk Code to run for each animation frame
|
266
|
-
# @return [Shoes::Animation]
|
267
|
-
# Defaults to framerate of 24 frames per second
|
268
|
-
# @example
|
269
|
-
# # 24 frames per second
|
270
|
-
# animate do
|
271
|
-
# # animation code
|
272
|
-
# end
|
273
|
-
# @overload animate(framerate, &blk)
|
274
|
-
# @param [Integer] framerate Frames per second
|
275
|
-
# @param [Proc] blk Code to run for each animation frame
|
276
|
-
# @return [Shoes::Animation]
|
277
|
-
# @example
|
278
|
-
# # 10 frames per second
|
279
|
-
# animate 10 do
|
280
|
-
# # animation code
|
281
|
-
# end
|
282
|
-
# @overload animate(opts = {}, &blk)
|
283
|
-
# @param [Hash] opts Animation options
|
284
|
-
# @param [Proc] blk Code to run for each animation frame
|
285
|
-
# @option opts [Integer] :framerate Frames per second
|
286
|
-
# @return [Shoes::Animation]
|
287
|
-
# @example
|
288
|
-
# # 10 frames per second
|
289
|
-
# animate :framerate => 10 do
|
290
|
-
# # animation code
|
291
|
-
# end
|
292
|
-
#
|
293
|
-
def animate(opts = {}, &blk)
|
294
|
-
opts = { framerate: opts } unless opts.is_a? Hash
|
295
|
-
Shoes::Animation.new @__app__, opts, blk
|
296
|
-
end
|
297
|
-
|
298
|
-
def every(n = 1, &blk)
|
299
|
-
animate 1.0 / n, &blk
|
300
|
-
end
|
301
|
-
|
302
|
-
def timer(n = 1, &blk)
|
303
|
-
n *= 1000
|
304
|
-
Timer.new @__app__, n, &blk
|
305
|
-
end
|
306
|
-
|
307
|
-
# similar controls as Shoes::Video (#video)
|
308
|
-
def sound(soundfile, opts = {}, &blk)
|
309
|
-
Shoes::Sound.new @__app__, soundfile, opts, &blk
|
310
|
-
end
|
311
|
-
|
312
|
-
# Creates an arrow
|
313
|
-
#
|
314
|
-
# @overload arrow(left, top, width, opts)
|
315
|
-
# Creates an arrow centered at (left, top)
|
316
|
-
# @param [Integer] left the x-coordinate of the element center
|
317
|
-
# @param [Integer] top the y-coordinate of the element center
|
318
|
-
# @param [Integer] width the width of the arrow
|
319
|
-
# @param [Hash] opts Arrow style options
|
320
|
-
# @option opts [Integer] rotate (false)
|
321
|
-
# @overload arrow(opts)
|
322
|
-
# Creates an arrow using values from the opts Hash.
|
323
|
-
# @param [Hash] opts
|
324
|
-
# @option styles [Integer] left (0) the x-coordinate of the top-left corner
|
325
|
-
# @option styles [Integer] top (0) the y-coordinate of the top-left corner
|
326
|
-
# @option styles [Integer] width (0) the width
|
327
|
-
# @option styles [Integer] rotate (false)
|
328
|
-
def arrow(*args, &blk)
|
329
|
-
opts = style_normalizer.normalize pop_style(args)
|
330
|
-
|
331
|
-
left, top, width, *leftovers = args
|
332
|
-
|
333
|
-
message = <<EOS
|
334
|
-
Too many arguments. Must be one of:
|
335
|
-
- arrow(left, top, width, [opts])
|
336
|
-
- arrow(left, top, [opts])
|
337
|
-
- arrow(left, [opts])
|
338
|
-
- arrow([opts])
|
339
|
-
EOS
|
340
|
-
raise ArgumentError, message if leftovers.any?
|
341
|
-
|
342
|
-
create Shoes::Arrow, left, top, width, opts, blk
|
343
|
-
end
|
344
|
-
|
345
|
-
# Creates an arc at (left, top)
|
346
|
-
#
|
347
|
-
# @param [Integer] left the x-coordinate of the top-left corner
|
348
|
-
# @param [Integer] top the y-coordinate of the top-left corner
|
349
|
-
# @param [Integer] width width of the arc's ellipse
|
350
|
-
# @param [Integer] height height of the arc's ellipse
|
351
|
-
# @param [Float] angle1 angle in radians marking the beginning of the arc segment
|
352
|
-
# @param [Float] angle2 angle in radians marking the end of the arc segment
|
353
|
-
# @param [Hash] opts Arc style options
|
354
|
-
# @option opts [Boolean] wedge (false)
|
355
|
-
# @option opts [Boolean] center (false) is (left, top) the center of the rectangle?
|
356
|
-
def arc(*args, &blk)
|
357
|
-
opts = style_normalizer.normalize pop_style(args)
|
358
|
-
|
359
|
-
left, top, width, height, angle1, angle2, *leftovers = args
|
360
|
-
|
361
|
-
message = <<EOS
|
362
|
-
Too many arguments. Must be one of:
|
363
|
-
- arc(left, top, width, height, angle1, angle2, [opts])
|
364
|
-
- arc(left, top, width, height, angle1, [opts])
|
365
|
-
- arc(left, top, width, height, [opts])
|
366
|
-
- arc(left, top, width, [opts])
|
367
|
-
- arc(left, top, [opts])
|
368
|
-
- arc(left, [opts])
|
369
|
-
- arc([opts])
|
370
|
-
EOS
|
371
|
-
raise ArgumentError, message if leftovers.any?
|
372
|
-
|
373
|
-
create Shoes::Arc, left, top, width, height, angle1, angle2, opts, blk
|
374
|
-
end
|
375
|
-
|
376
|
-
# Draws a line from point A (x1,y1) to point B (x2,y2)
|
377
|
-
#
|
378
|
-
# @param [Integer] x1 The x-value of point A
|
379
|
-
# @param [Integer] y1 The y-value of point A
|
380
|
-
# @param [Integer] x2 The x-value of point B
|
381
|
-
# @param [Integer] y2 The y-value of point B
|
382
|
-
# @param [Hash] opts Style options
|
383
|
-
def line(*args, &blk)
|
384
|
-
opts = style_normalizer.normalize pop_style(args)
|
385
|
-
|
386
|
-
x1, y1, x2, y2, *leftovers = args
|
387
|
-
|
388
|
-
message = <<EOS
|
389
|
-
Too many arguments. Must be one of:
|
390
|
-
- line(x1, y1, x2, y2, [opts])
|
391
|
-
- line(x1, y1, x2, [opts])
|
392
|
-
- line(x1, y1, [opts])
|
393
|
-
- line(x1, [opts])
|
394
|
-
- line([opts])
|
395
|
-
EOS
|
396
|
-
raise ArgumentError, message if leftovers.any?
|
397
|
-
|
398
|
-
create Shoes::Line, x1, y1, x2, y2, opts, blk
|
399
|
-
end
|
400
|
-
|
401
|
-
# Creates an oval at (left, top)
|
402
|
-
#
|
403
|
-
# @overload oval(left, top, diameter)
|
404
|
-
# Creates a circle at (left, top), with the given diameter
|
405
|
-
# @param [Integer] left the x-coordinate of the top-left corner
|
406
|
-
# @param [Integer] top the y-coordinate of the top-left corner
|
407
|
-
# @param [Integer] diameter the diameter
|
408
|
-
# @overload oval(left, top, width, height)
|
409
|
-
# Creates an oval at (left, top), with the given width and height
|
410
|
-
# @param [Integer] left the x-coordinate of the top-left corner
|
411
|
-
# @param [Integer] top the y-coordinate of the top-left corner
|
412
|
-
# @param [Integer] width the width
|
413
|
-
# @param [Integer] height the height
|
414
|
-
# @overload oval(styles)
|
415
|
-
# Creates an oval using values from the styles Hash.
|
416
|
-
# @param [Hash] styles
|
417
|
-
# @option styles [Integer] left (0) the x-coordinate of the top-left corner
|
418
|
-
# @option styles [Integer] top (0) the y-coordinate of the top-left corner
|
419
|
-
# @option styles [Integer] width (0) the width
|
420
|
-
# @option styles [Integer] height (0) the height
|
421
|
-
# @option styles [Integer] top (0) the y-coordinate of the top-left corner
|
422
|
-
# @option styles [Boolean] center (false) is (left, top) the center of the oval
|
423
|
-
def oval(*args, &blk)
|
424
|
-
opts = style_normalizer.normalize pop_style(args)
|
425
|
-
|
426
|
-
left, top, width, height, *leftovers = args
|
427
|
-
|
428
|
-
message = <<EOS
|
429
|
-
Wrong number of arguments. Must be one of:
|
430
|
-
- oval(left, top, width, height, [opts])
|
431
|
-
- oval(left, top, diameter, [opts])
|
432
|
-
- oval(left, top, [opts])
|
433
|
-
- oval(left, [opts])
|
434
|
-
- oval(styles)
|
435
|
-
EOS
|
436
|
-
raise ArgumentError, message if leftovers.any?
|
437
|
-
|
438
|
-
create Shoes::Oval, left, top, width, height, opts, blk
|
439
|
-
end
|
440
|
-
|
441
|
-
# Creates a rectangle
|
442
|
-
#
|
443
|
-
# @overload rect(left, top, side, styles)
|
444
|
-
# Creates a square at (left, top), with sides of the given length
|
445
|
-
# @param [Integer] left the x-coordinate of the top-left corner
|
446
|
-
# @param [Integer] top the y-coordinate of the top-left corner
|
447
|
-
# @param [Integer] side the length of a side
|
448
|
-
# @overload rect(left, top, width, height, rounded = 0, styles)
|
449
|
-
# Creates a rectangle at (left, top), with the given width and height
|
450
|
-
# @param [Integer] left the x-coordinate of the top-left corner
|
451
|
-
# @param [Integer] top the y-coordinate of the top-left corner
|
452
|
-
# @param [Integer] width the width
|
453
|
-
# @param [Integer] height the height
|
454
|
-
# @overload rect(styles)
|
455
|
-
# Creates a rectangle using values from the styles Hash.
|
456
|
-
# @param [Hash] styles
|
457
|
-
# @option styles [Integer] left (0) the x-coordinate of the top-left corner
|
458
|
-
# @option styles [Integer] top (0) the y-coordinate of the top-left corner
|
459
|
-
# @option styles [Integer] width (0) the width
|
460
|
-
# @option styles [Integer] height (0) the height
|
461
|
-
# @option styles [Integer] top (0) the y-coordinate of the top-left corner
|
462
|
-
# @option styles [Boolean] center (false) is (left, top) the center of the rectangle?
|
463
|
-
def rect(*args, &blk)
|
464
|
-
opts = style_normalizer.normalize pop_style(args)
|
465
|
-
|
466
|
-
left, top, width, height, curve, *leftovers = args
|
467
|
-
opts[:curve] = curve if curve
|
468
|
-
|
469
|
-
message = <<EOS
|
470
|
-
Wrong number of arguments. Must be one of:
|
471
|
-
- rect(left, top, width, height, curve, [opts])
|
472
|
-
- rect(left, top, width, height, [opts])
|
473
|
-
- rect(left, top, side, [opts])
|
474
|
-
- rect(left, top, [opts])
|
475
|
-
- rect(left, [opts])
|
476
|
-
- rect(styles)
|
477
|
-
EOS
|
478
|
-
|
479
|
-
raise ArgumentError, message if leftovers.any?
|
480
|
-
|
481
|
-
create Shoes::Rect, left, top, width, height, style.merge(opts), blk
|
482
|
-
end
|
483
|
-
|
484
|
-
# Creates a new Shoes::Star object
|
485
|
-
#
|
486
|
-
# @overload star(left, top, styles, &block)
|
487
|
-
# Creates a star at (left, top) with the given style
|
488
|
-
# @param [Integer] left the x-coordinate of the top-left corner
|
489
|
-
# @param [Integer] top the y-coordinate of the top-left corner
|
490
|
-
# @param [Hash] styles optional, additional styling for the element
|
491
|
-
# @overload star(left, top, points, styles, &block)
|
492
|
-
# Creates a star at (left, top) with the given style
|
493
|
-
# @param [Integer] left the x-coordinate of the top-left corner
|
494
|
-
# @param [Integer] top the y-coordinate of the top-left corner
|
495
|
-
# @param [Integer] points count of points on the star
|
496
|
-
# @param [Hash] styles optional, additional styling for the element
|
497
|
-
# @overload star(left, top, points, outer, styles, &block)
|
498
|
-
# Creates a star at (left, top) with the given style
|
499
|
-
# @param [Integer] left the x-coordinate of the top-left corner
|
500
|
-
# @param [Integer] top the y-coordinate of the top-left corner
|
501
|
-
# @param [Integer] points count of points on the star
|
502
|
-
# @param [Integer] outer outer radius of star
|
503
|
-
# @param [Hash] styles optional, additional styling for the element
|
504
|
-
# @overload star(left, top, points, outer, inner, styles, &block)
|
505
|
-
# Creates a star at (left, top) with the given style
|
506
|
-
# @param [Integer] left the x-coordinate of the top-left corner
|
507
|
-
# @param [Integer] top the y-coordinate of the top-left corner
|
508
|
-
# @param [Integer] points count of points on the star
|
509
|
-
# @param [Integer] outer outer radius of star
|
510
|
-
# @param [Integer] inner inner radius of star
|
511
|
-
# @param [Hash] styles optional, additional styling for the element
|
512
|
-
def star(*args, &blk)
|
513
|
-
styles = style_normalizer.normalize pop_style(args)
|
514
|
-
|
515
|
-
left, top, points, outer, inner, *leftovers = args
|
516
|
-
|
517
|
-
message = <<EOS
|
518
|
-
Wrong number of arguments. Must be one of:
|
519
|
-
- star([styles])
|
520
|
-
- star(left, [styles])
|
521
|
-
- star(left, top, [styles])
|
522
|
-
- star(left, top, points, [styles])
|
523
|
-
- star(left, top, points, outer, [styles])
|
524
|
-
- star(left, top, points, outer, inner, [styles])
|
525
|
-
EOS
|
526
|
-
raise ArgumentError, message if leftovers.any?
|
527
|
-
|
528
|
-
create Shoes::Star, left, top, points, outer, inner, styles, blk
|
529
|
-
end
|
530
|
-
|
531
|
-
# Creates a new Shoes::Shape object
|
532
|
-
#
|
533
|
-
# @overload shape(left, top, styles, &block)
|
534
|
-
# Creates a shape at (left, top) with the given style
|
535
|
-
# @param [Integer] left the x-coordinate of the top-left corner
|
536
|
-
# @param [Integer] top the y-coordinate of the top-left corner
|
537
|
-
# @overload shape(left, top)
|
538
|
-
# Creates a shape at (left, top, &block)
|
539
|
-
# @param [Integer] left the x-coordinate of the top-left corner
|
540
|
-
# @param [Integer] top the y-coordinate of the top-left corner
|
541
|
-
# @overload shape(styles, &block)
|
542
|
-
# Creates a shape at (0, 0)
|
543
|
-
# @option styles [Integer] left (0) the x-coordinate of the top-left corner
|
544
|
-
# @option styles [Integer] top (0) the y-coordinate of the top-left corner
|
545
|
-
def shape(*args, &blk)
|
546
|
-
opts = style_normalizer.normalize pop_style(args)
|
547
|
-
|
548
|
-
left, top, *leftovers = args
|
549
|
-
|
550
|
-
message = <<EOS
|
551
|
-
Wrong number of arguments. Must be one of:
|
552
|
-
- shape(left, top, [opts])
|
553
|
-
- shape(left, [opts])
|
554
|
-
- shape([opts])
|
555
|
-
EOS
|
556
|
-
|
557
|
-
raise ArgumentError, message if leftovers.any?
|
558
|
-
|
559
|
-
create Shoes::Shape, left, top, opts, blk
|
560
|
-
end
|
561
|
-
|
562
|
-
# Define app-level setter methods
|
563
|
-
PATTERN_APP_STYLES = [:fill, :stroke].freeze
|
564
|
-
OTHER_APP_STYLES = [:cap, :rotate, :strokewidth, :transform].freeze
|
565
|
-
|
566
|
-
PATTERN_APP_STYLES.each do |style|
|
567
|
-
define_method style do |val|
|
568
|
-
@__app__.style[style] = pattern(val)
|
569
|
-
end
|
570
|
-
end
|
571
|
-
|
572
|
-
OTHER_APP_STYLES.each do |style|
|
573
|
-
define_method style do |val|
|
574
|
-
@__app__.style[style] = val
|
575
|
-
end
|
576
|
-
end
|
577
|
-
|
578
|
-
def translate(left, top)
|
579
|
-
@__app__.style[:translate] = [left, top]
|
580
|
-
end
|
581
|
-
|
582
|
-
def nostroke
|
583
|
-
@__app__.style[:stroke] = nil
|
584
|
-
end
|
585
|
-
|
586
|
-
def nofill
|
587
|
-
@__app__.style[:fill] = nil
|
588
|
-
end
|
589
|
-
|
590
|
-
%w(banner title subtitle tagline caption para inscription).each do |method|
|
591
|
-
define_method method do |*texts|
|
592
|
-
styles = pop_style(texts)
|
593
|
-
klass = Shoes.const_get(method.capitalize)
|
594
|
-
create klass, texts, styles
|
595
|
-
end
|
596
|
-
end
|
597
|
-
|
598
|
-
TEXT_STYLES = {
|
599
|
-
code: { font: "Lucida Console" },
|
600
|
-
del: { strikethrough: true },
|
601
|
-
em: { emphasis: true },
|
602
|
-
ins: { underline: true },
|
603
|
-
sub: { rise: -10, size_modifier: 0.8 },
|
604
|
-
sup: { rise: 10, size_modifier: 0.8 },
|
605
|
-
strong: { weight: true },
|
606
|
-
}.freeze
|
607
|
-
|
608
|
-
TEXT_STYLES.keys.each do |method|
|
609
|
-
define_method method do |*texts|
|
610
|
-
styles = style_normalizer.normalize(pop_style(texts))
|
611
|
-
styles = TEXT_STYLES[method].merge(styles)
|
612
|
-
Shoes::Span.new texts, styles
|
613
|
-
end
|
614
|
-
end
|
615
|
-
|
616
|
-
def fg(*texts, color)
|
617
|
-
Shoes::Span.new texts, stroke: pattern(color)
|
618
|
-
end
|
619
|
-
|
620
|
-
def bg(*texts, color)
|
621
|
-
Shoes::Span.new texts, fill: pattern(color)
|
622
|
-
end
|
623
|
-
|
624
|
-
def link(*texts, &blk)
|
625
|
-
opts = normalize_style_for_element(Shoes::Link, texts)
|
626
|
-
Shoes::Link.new @__app__, texts, opts, blk
|
627
|
-
end
|
628
|
-
|
629
|
-
def span(*texts)
|
630
|
-
opts = normalize_style_for_element(Shoes::Span, texts)
|
631
|
-
Shoes::Span.new texts, opts
|
632
|
-
end
|
633
|
-
|
634
|
-
def mouse
|
635
|
-
[@__app__.mouse_button, @__app__.mouse_pos[0], @__app__.mouse_pos[1]]
|
636
|
-
end
|
637
|
-
|
638
|
-
def motion(&blk)
|
639
|
-
@__app__.mouse_motion << blk
|
640
|
-
end
|
641
|
-
|
642
|
-
def resize(&blk)
|
643
|
-
@__app__.add_resize_callback blk
|
644
|
-
end
|
645
|
-
|
646
|
-
# hover and leave just delegate to the current slot as hover and leave
|
647
|
-
# are just defined for slots but self is always the app.
|
648
|
-
def hover(&blk)
|
649
|
-
@__app__.current_slot.hover(&blk)
|
650
|
-
end
|
651
|
-
|
652
|
-
def leave(&blk)
|
653
|
-
@__app__.current_slot.leave(&blk)
|
654
|
-
end
|
655
|
-
|
656
|
-
def keypress(&blk)
|
657
|
-
Shoes::Keypress.new @__app__, &blk
|
658
|
-
end
|
659
|
-
|
660
|
-
def keyrelease(&blk)
|
661
|
-
Shoes::Keyrelease.new @__app__, &blk
|
662
|
-
end
|
663
|
-
|
664
|
-
def append
|
665
|
-
yield if block_given?
|
666
|
-
end
|
667
|
-
|
668
|
-
def visit(url)
|
669
|
-
match_data = nil
|
670
|
-
url_data = Shoes::URL.urls.find { |page, _| match_data = page.match url }
|
671
|
-
return unless url_data
|
672
|
-
action_proc = url_data[1]
|
673
|
-
url_argument = match_data[1]
|
674
|
-
clear do
|
675
|
-
@__app__.location = url
|
676
|
-
action_proc.call self, url_argument
|
677
|
-
end
|
678
|
-
end
|
679
|
-
|
680
|
-
def scroll_top
|
681
|
-
@__app__.scroll_top
|
682
|
-
end
|
683
|
-
|
684
|
-
def scroll_top=(n)
|
685
|
-
@__app__.scroll_top = n
|
686
|
-
end
|
687
|
-
|
688
|
-
def clipboard
|
689
|
-
@__app__.clipboard
|
690
|
-
end
|
691
|
-
|
692
|
-
def clipboard=(str)
|
693
|
-
@__app__.clipboard = str
|
694
|
-
end
|
695
|
-
|
696
|
-
def download(name, args = {}, &blk)
|
697
|
-
create(Shoes::Download, name, args, &blk).tap(&:start)
|
698
|
-
end
|
699
|
-
|
700
|
-
def gutter
|
701
|
-
@__app__.gutter
|
702
|
-
end
|
703
|
-
|
704
|
-
def video(*_args)
|
705
|
-
raise Shoes::NotImplementedError,
|
706
|
-
'Sorry video support has been cut from shoes 4!' \
|
707
|
-
' Check out github issue #113 for any changes/updates or if you' \
|
708
|
-
' want to help :)'
|
709
|
-
end
|
710
150
|
end
|
711
151
|
end
|
712
152
|
|