Class: Glimmer::SWT::Custom::Animation
- Inherits:
-
Object
- Object
- Glimmer::SWT::Custom::Animation
show all
- Includes:
- 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_setter, #normalized_attribute, #ruby_attribute_setter
Constructor Details
#initialize(parent) ⇒ Animation
TODO consider supporting an async: false option
85
86
87
88
89
90
91
92
|
# File 'lib/glimmer/swt/custom/animation.rb', line 85
def initialize(parent)
@parent = parent
@started = true
@frame_index = 0
@cycle_count_index = 0
@start_number = 0 self.class.swt_display end
|
Instance Attribute Details
#cycle ⇒ Object
Returns the value of attribute cycle.
79
80
81
|
# File 'lib/glimmer/swt/custom/animation.rb', line 79
def cycle
@cycle
end
|
#cycle_count ⇒ Object
Returns the value of attribute cycle_count.
81
82
83
|
# File 'lib/glimmer/swt/custom/animation.rb', line 81
def cycle_count
@cycle_count
end
|
#duration_limit ⇒ Object
Returns the value of attribute duration_limit.
81
82
83
|
# File 'lib/glimmer/swt/custom/animation.rb', line 81
def duration_limit
@duration_limit
end
|
#every ⇒ Object
Returns the value of attribute every.
81
82
83
|
# File 'lib/glimmer/swt/custom/animation.rb', line 81
def every
@every
end
|
#frame_block ⇒ Object
Returns the value of attribute frame_block.
81
82
83
|
# File 'lib/glimmer/swt/custom/animation.rb', line 81
def frame_block
@frame_block
end
|
#frame_count ⇒ Object
Returns the value of attribute frame_count.
81
82
83
|
# File 'lib/glimmer/swt/custom/animation.rb', line 81
def frame_count
@frame_count
end
|
#frame_index ⇒ Object
Also known as:
current_frame_index
Returns the value of attribute frame_index.
79
80
81
|
# File 'lib/glimmer/swt/custom/animation.rb', line 79
def frame_index
@frame_index
end
|
#options ⇒ Object
Returns the value of attribute options.
79
80
81
|
# File 'lib/glimmer/swt/custom/animation.rb', line 79
def options
@options
end
|
#parent ⇒ Object
Returns the value of attribute parent.
79
80
81
|
# File 'lib/glimmer/swt/custom/animation.rb', line 79
def parent
@parent
end
|
#started ⇒ Object
Also known as:
started?
Returns the value of attribute started.
81
82
83
|
# File 'lib/glimmer/swt/custom/animation.rb', line 81
def started
@started
end
|
Class Method Details
.frame_animation_queue(animation) ⇒ Object
67
68
69
|
# File 'lib/glimmer/swt/custom/animation.rb', line 67
def frame_animation_queue(animation)
frame_animation_queues[animation] ||= []
end
|
.frame_animation_queues ⇒ Object
60
61
62
63
64
65
|
# File 'lib/glimmer/swt/custom/animation.rb', line 60
def frame_animation_queues
unless defined? @@frame_animation_queues
@@frame_animation_queues = {}
end
@@frame_animation_queues
end
|
.next_animation ⇒ Object
39
40
41
42
43
44
45
46
|
# File 'lib/glimmer/swt/custom/animation.rb', line 39
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
48
49
50
|
# File 'lib/glimmer/swt/custom/animation.rb', line 48
def next_animation_index
next_schedule_index % frame_animation_queues.keys.size
end
|
.next_schedule_index ⇒ Object
52
53
54
55
56
57
58
|
# File 'lib/glimmer/swt/custom/animation.rb', line 52
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
32
33
34
35
36
37
|
# File 'lib/glimmer/swt/custom/animation.rb', line 32
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
71
72
73
74
75
76
|
# File 'lib/glimmer/swt/custom/animation.rb', line 71
def swt_display
unless defined? @@swt_display
@@swt_display = DisplayProxy.instance.swt_display
end
@@swt_display
end
|
Instance Method Details
#cycle_enabled? ⇒ Boolean
176
177
178
|
# File 'lib/glimmer/swt/custom/animation.rb', line 176
def cycle_enabled?
@cycle.is_a?(Array)
end
|
#cycle_limited? ⇒ Boolean
180
181
182
|
# File 'lib/glimmer/swt/custom/animation.rb', line 180
def cycle_limited?
cycle_enabled? && @cycle_count.is_a?(Integer)
end
|
#duration_limited? ⇒ Boolean
184
185
186
|
# File 'lib/glimmer/swt/custom/animation.rb', line 184
def duration_limited?
@duration_limit.is_a?(Integer)
end
|
#finite? ⇒ Boolean
143
144
145
|
# File 'lib/glimmer/swt/custom/animation.rb', line 143
def finite?
frame_count_limited? || cycle_limited? || duration_limited?
end
|
#frame_count_limited? ⇒ Boolean
188
189
190
|
# File 'lib/glimmer/swt/custom/animation.rb', line 188
def frame_count_limited?
@frame_count.is_a?(Integer)
end
|
#get_attribute(attribute_name) ⇒ Object
160
161
162
|
# File 'lib/glimmer/swt/custom/animation.rb', line 160
def get_attribute(attribute_name)
send(ruby_attribute_getter(attribute_name))
end
|
#has_attribute?(attribute_name, *args) ⇒ Boolean
152
153
154
|
# File 'lib/glimmer/swt/custom/animation.rb', line 152
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?
147
148
149
|
# File 'lib/glimmer/swt/custom/animation.rb', line 147
def infinite?
!finite?
end
|
#post_add_content ⇒ Object
94
95
96
97
|
# File 'lib/glimmer/swt/custom/animation.rb', line 94
def post_add_content
@parent.on_widget_disposed { stop }
start if started?
end
|
#restart ⇒ Object
Restarts an animation (whether indefinite or not and whether stopped or not)
130
131
132
133
134
135
136
137
|
# File 'lib/glimmer/swt/custom/animation.rb', line 130
def restart
@original_start_time = @start_time = nil
@duration = nil
@frame_index = 0
@cycle_count_index = 0
stop
start
end
|
#set_attribute(attribute_name, *args) ⇒ Object
156
157
158
|
# File 'lib/glimmer/swt/custom/animation.rb', line 156
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.
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
# File 'lib/glimmer/swt/custom/animation.rb', line 101
def start
return if @start_number > 0 && started?
@start_number += 1
@started = true
@start_time = Time.now
@original_start_time = @start_time if @duration.nil?
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
123
124
125
126
127
|
# File 'lib/glimmer/swt/custom/animation.rb', line 123
def stop
return if stopped?
@started = false
@duration = (Time.now - @start_time) + @duration.to_f if duration_limited? && !@start_time.nil?
end
|
#stopped? ⇒ Boolean
139
140
141
|
# File 'lib/glimmer/swt/custom/animation.rb', line 139
def stopped?
!started?
end
|
#surpassed_duration_limit? ⇒ Boolean
192
193
194
|
# File 'lib/glimmer/swt/custom/animation.rb', line 192
def surpassed_duration_limit?
duration_limited? && ((Time.now - @start_time) > (@duration_limit - @duration.to_f))
end
|
#within_duration_limit? ⇒ Boolean
196
197
198
|
# File 'lib/glimmer/swt/custom/animation.rb', line 196
def within_duration_limit?
!surpassed_duration_limit?
end
|