Class: Glimmer::SWT::Custom::Animation
- Inherits:
-
Object
- Object
- Glimmer::SWT::Custom::Animation
show all
- Includes:
- DataBinding::ObservableModel, Properties
- Defined in:
- lib/glimmer/swt/custom/animation.rb
Overview
Represents an animation declaratively
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Properties
attribute_getter, #attribute_getter, attribute_setter, #attribute_setter, normalized_attribute, #normalized_attribute, ruby_attribute_getter, #ruby_attribute_setter, ruby_attribute_setter
Constructor Details
#initialize(parent) ⇒ Animation
TODO consider supporting an async: false option
92
93
94
95
96
97
98
99
100
|
# File 'lib/glimmer/swt/custom/animation.rb', line 92
def initialize(parent)
@parent = parent
@parent.requires_shape_disposal = true
self.started = true
self.frame_index = 0
self.cycle_count_index = 0
@start_number = 0 self.class.swt_display end
|
Instance Attribute Details
#cycle ⇒ Object
Returns the value of attribute cycle.
84
85
86
|
# File 'lib/glimmer/swt/custom/animation.rb', line 84
def cycle
@cycle
end
|
#cycle_count ⇒ Object
Returns the value of attribute cycle_count.
84
85
86
|
# File 'lib/glimmer/swt/custom/animation.rb', line 84
def cycle_count
@cycle_count
end
|
#cycle_count_index ⇒ Object
Returns the value of attribute cycle_count_index.
84
85
86
|
# File 'lib/glimmer/swt/custom/animation.rb', line 84
def cycle_count_index
@cycle_count_index
end
|
#duration ⇒ Object
Returns the value of attribute duration.
84
85
86
|
# File 'lib/glimmer/swt/custom/animation.rb', line 84
def duration
@duration
end
|
#duration_limit ⇒ Object
Returns the value of attribute duration_limit.
84
85
86
|
# File 'lib/glimmer/swt/custom/animation.rb', line 84
def duration_limit
@duration_limit
end
|
#every ⇒ Object
Returns the value of attribute every.
84
85
86
|
# File 'lib/glimmer/swt/custom/animation.rb', line 84
def every
@every
end
|
#finished ⇒ Object
Also known as:
finished?
Returns the value of attribute finished.
84
85
86
|
# File 'lib/glimmer/swt/custom/animation.rb', line 84
def finished
@finished
end
|
#fps ⇒ Object
Also known as:
frame_rate
Returns the value of attribute fps.
84
85
86
|
# File 'lib/glimmer/swt/custom/animation.rb', line 84
def fps
@fps
end
|
#frame_block ⇒ Object
Returns the value of attribute frame_block.
84
85
86
|
# File 'lib/glimmer/swt/custom/animation.rb', line 84
def frame_block
@frame_block
end
|
#frame_count ⇒ Object
Returns the value of attribute frame_count.
84
85
86
|
# File 'lib/glimmer/swt/custom/animation.rb', line 84
def frame_count
@frame_count
end
|
#frame_index ⇒ Object
Also known as:
current_frame_index
Returns the value of attribute frame_index.
84
85
86
|
# File 'lib/glimmer/swt/custom/animation.rb', line 84
def frame_index
@frame_index
end
|
#options ⇒ Object
Returns the value of attribute options.
83
84
85
|
# File 'lib/glimmer/swt/custom/animation.rb', line 83
def options
@options
end
|
#parent ⇒ Object
Returns the value of attribute parent.
83
84
85
|
# File 'lib/glimmer/swt/custom/animation.rb', line 83
def parent
@parent
end
|
#started ⇒ Object
Also known as:
started?
Returns the value of attribute started.
84
85
86
|
# File 'lib/glimmer/swt/custom/animation.rb', line 84
def started
@started
end
|
Class Method Details
.frame_animation_queue(animation) ⇒ Object
71
72
73
|
# File 'lib/glimmer/swt/custom/animation.rb', line 71
def frame_animation_queue(animation)
frame_animation_queues[animation] ||= []
end
|
.frame_animation_queues ⇒ Object
64
65
66
67
68
69
|
# File 'lib/glimmer/swt/custom/animation.rb', line 64
def frame_animation_queues
unless defined? @@frame_animation_queues
@@frame_animation_queues = {}
end
@@frame_animation_queues
end
|
.next_animation ⇒ Object
43
44
45
46
47
48
49
50
|
# File 'lib/glimmer/swt/custom/animation.rb', line 43
def next_animation
animation = nil
while frame_animation_queues.values.reduce(:+)&.any? && (animation.nil? || frame_animation_queue(animation).last.nil?)
animation = frame_animation_queues.keys[next_animation_index]
frame_animation_queues.delete(animation) if frame_animation_queues.values.reduce(:+)&.any? && !animation.nil? && frame_animation_queue(animation).empty?
end
animation
end
|
.next_animation_index ⇒ Object
52
53
54
|
# File 'lib/glimmer/swt/custom/animation.rb', line 52
def next_animation_index
next_schedule_index % frame_animation_queues.keys.size
end
|
.next_schedule_index ⇒ Object
56
57
58
59
60
61
62
|
# File 'lib/glimmer/swt/custom/animation.rb', line 56
def next_schedule_index
unless defined? @@next_schedule_index
@@next_schedule_index = 0
else
@@next_schedule_index += 1
end
end
|
.schedule_frame_animation(animation, &frame_animation_block) ⇒ Object
36
37
38
39
40
41
|
# File 'lib/glimmer/swt/custom/animation.rb', line 36
def schedule_frame_animation(animation, &frame_animation_block)
frame_animation_queue(animation).prepend(frame_animation_block)
swt_display.async_exec do
frame_animation_queue(next_animation)&.pop&.call
end
end
|
.swt_display ⇒ Object
75
76
77
78
79
80
|
# File 'lib/glimmer/swt/custom/animation.rb', line 75
def swt_display
unless defined? @@swt_display
@@swt_display = DisplayProxy.instance.swt_display
end
@@swt_display
end
|
Instance Method Details
#content(&block) ⇒ Object
#cycle_enabled? ⇒ Boolean
212
213
214
|
# File 'lib/glimmer/swt/custom/animation.rb', line 212
def cycle_enabled?
@cycle.is_a?(Array)
end
|
#cycle_limited? ⇒ Boolean
216
217
218
|
# File 'lib/glimmer/swt/custom/animation.rb', line 216
def cycle_limited?
cycle_enabled? && @cycle_count.is_a?(Integer)
end
|
#duration_limited? ⇒ Boolean
220
221
222
|
# File 'lib/glimmer/swt/custom/animation.rb', line 220
def duration_limited?
@duration_limit.is_a?(Numeric) && @duration_limit > 0
end
|
#finite? ⇒ Boolean
161
162
163
|
# File 'lib/glimmer/swt/custom/animation.rb', line 161
def finite?
frame_count_limited? || cycle_limited? || duration_limited?
end
|
#frame_count_limited? ⇒ Boolean
224
225
226
|
# File 'lib/glimmer/swt/custom/animation.rb', line 224
def frame_count_limited?
@frame_count.is_a?(Integer) && @frame_count > 0
end
|
#get_attribute(attribute_name) ⇒ Object
178
179
180
|
# File 'lib/glimmer/swt/custom/animation.rb', line 178
def get_attribute(attribute_name)
send(ruby_attribute_getter(attribute_name))
end
|
#has_attribute?(attribute_name, *args) ⇒ Boolean
170
171
172
|
# File 'lib/glimmer/swt/custom/animation.rb', line 170
def has_attribute?(attribute_name, *args)
respond_to?(ruby_attribute_setter(attribute_name)) && respond_to?(ruby_attribute_getter(attribute_name))
end
|
#infinite? ⇒ Boolean
Also known as:
indefinite?
165
166
167
|
# File 'lib/glimmer/swt/custom/animation.rb', line 165
def infinite?
!finite?
end
|
#post_add_content ⇒ Object
102
103
104
105
106
107
|
# File 'lib/glimmer/swt/custom/animation.rb', line 102
def post_add_content
if @dispose_listener_registration.nil?
@dispose_listener_registration = @parent.on_widget_disposed { stop }
start if started?
end
end
|
#restart ⇒ Object
Restarts an animation (whether indefinite or not and whether stopped or not)
148
149
150
151
152
153
154
155
|
# File 'lib/glimmer/swt/custom/animation.rb', line 148
def restart
@original_start_time = @start_time = Time.now
self.duration = 0
self.frame_index = 0
self.cycle_count_index = 0
stop
start
end
|
#set_attribute(attribute_name, *args) ⇒ Object
174
175
176
|
# File 'lib/glimmer/swt/custom/animation.rb', line 174
def set_attribute(attribute_name, *args)
send(ruby_attribute_setter(attribute_name), *args)
end
|
#start ⇒ Object
Starts an animation that is indefinite or has never been started before (i.e. having ‘started: false` option). Otherwise, resumes a stopped animation that has not been completed.
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
# File 'lib/glimmer/swt/custom/animation.rb', line 117
def start
return if @start_number > 0 && started?
@start_number += 1
@start_time = Time.now
@duration = 0
@original_start_time = @start_time if @duration.nil?
self.finished = false if finished?
self.started = true
Thread.new do
start_number = @start_number
if cycle_count.is_a?(Integer) && cycle.is_a?(Array)
(cycle_count * cycle.length).times do
break unless draw_frame(start_number)
end
else
loop do
break unless draw_frame(start_number)
end
end
end
end
|
#stop ⇒ Object
141
142
143
144
145
|
# File 'lib/glimmer/swt/custom/animation.rb', line 141
def stop
return if stopped?
self.started = false
self.duration = (Time.now - @start_time) + @duration.to_f if duration_limited? && !@start_time.nil?
end
|
#stopped? ⇒ Boolean
157
158
159
|
# File 'lib/glimmer/swt/custom/animation.rb', line 157
def stopped?
!started?
end
|
#surpassed_duration_limit? ⇒ Boolean
228
229
230
|
# File 'lib/glimmer/swt/custom/animation.rb', line 228
def surpassed_duration_limit?
duration_limited? && ((Time.now - @start_time) > @duration_limit)
end
|
#within_duration_limit? ⇒ Boolean
232
233
234
|
# File 'lib/glimmer/swt/custom/animation.rb', line 232
def within_duration_limit?
!surpassed_duration_limit?
end
|