class GosuNotifications::NotificationManager::Driver
Attributes
notification[R]
slot[R]
x[R]
y[R]
Public Class Methods
new(edge:, mode:, notification:, slot:)
click to toggle source
# File lib/gosu_notifications/notification_manager.rb, line 101 def initialize(edge:, mode:, notification:, slot:) @edge = edge @mode = mode @notification = notification @slot = slot @x, @y = 0, 0 @delta = Gosu.milliseconds @accumulator = 0.0 @born_at = Gosu.milliseconds @duration_completed_at = Float::INFINITY @transition_completed_at = Float::INFINITY end
Public Instance Methods
animation_ratio()
click to toggle source
# File lib/gosu_notifications/notification_manager.rb, line 214 def animation_ratio x = (@accumulator / @notification.transition_duration) case @notification.transition_type when Notification::LINEAR_TRANSITION x.clamp(0.0, 1.0) when Notification::EASE_IN_OUT_TRANSITION # https://easings.net/#easeInOutQuint (x < 0.5 ? 16 * x * x * x * x * x : 1 - ((-2 * x + 2) ** 5) / 2).clamp(0.0, 1.0) end end
done?()
click to toggle source
# File lib/gosu_notifications/notification_manager.rb, line 124 def done? Gosu.milliseconds - @duration_completed_at >= @notification.transition_duration end
draw()
click to toggle source
# File lib/gosu_notifications/notification_manager.rb, line 128 def draw ratio = 0.0 if not transition_in_complete? ratio = animation_ratio elsif transition_in_complete? and not duration_completed? ratio = 1.0 elsif duration_completed? ratio = 1.0 - animation_ratio end case @mode when MODE_DEFAULT Gosu.clip_to(0, 0, Notification::WIDTH, Notification::HEIGHT * ratio) do @notification.draw end when MODE_CIRCLE half = Notification::WIDTH / 2 Gosu.clip_to(half - (half * ratio), 0, Notification::WIDTH * ratio, Notification::HEIGHT) do @notification.draw end end end
duration_completed?()
click to toggle source
# File lib/gosu_notifications/notification_manager.rb, line 120 def duration_completed? Gosu.milliseconds - @transition_completed_at >= @notification.time_to_live end
transition_in_complete?()
click to toggle source
# File lib/gosu_notifications/notification_manager.rb, line 116 def transition_in_complete? Gosu.milliseconds - @born_at >= @notification.transition_duration end
update()
click to toggle source
# File lib/gosu_notifications/notification_manager.rb, line 153 def update case @mode when MODE_DEFAULT update_default when MODE_CIRCLE update_circle end @accumulator += Gosu.milliseconds - @delta @delta = Gosu.milliseconds end
update_circle()
click to toggle source
# File lib/gosu_notifications/notification_manager.rb, line 198 def update_circle case @edge when :top, :bottom @y = @edge == :top ? Notification::HEIGHT : -Notification::HEIGHT when :left, :right @x = @edge == :right ? -Notification::WIDTH : Notification::WIDTH end if transition_in_complete? and not duration_completed? @transition_completed_at = Gosu.milliseconds if @transition_completed_at == Float::INFINITY @accumulator = 0.0 elsif duration_completed? @duration_completed_at = Gosu.milliseconds if @duration_completed_at == Float::INFINITY end end
update_default()
click to toggle source
# File lib/gosu_notifications/notification_manager.rb, line 166 def update_default case @edge when :left, :right if not transition_in_complete? # Slide In @x = @edge == :right ? -x_offset : x_offset elsif transition_in_complete? and not duration_completed? @x = @edge == :right ? -Notification::WIDTH : Notification::WIDTH if @x.abs != Notification::WIDTH @transition_completed_at = Gosu.milliseconds if @transition_completed_at == Float::INFINITY @accumulator = 0.0 elsif duration_completed? # Slide Out @x = @edge == :right ? x_offset - Notification::WIDTH : Notification::WIDTH - x_offset @x = 0 if @edge == :left and @x <= 0 @x = 0 if @edge == :right and @x >= 0 @duration_completed_at = Gosu.milliseconds if @duration_completed_at == Float::INFINITY end when :top, :bottom if not transition_in_complete? # Slide In @y = @edge == :top ? y_offset : -y_offset elsif transition_in_complete? and not duration_completed? @y = @edge == :top ? Notification::HEIGHT : -Notification::HEIGHT if @x.abs != Notification::HEIGHT @transition_completed_at = Gosu.milliseconds if @transition_completed_at == Float::INFINITY @accumulator = 0.0 elsif duration_completed? # Slide Out @y = @edge == :top ? Notification::HEIGHT - y_offset : y_offset - Notification::HEIGHT @y = 0 if @edge == :top and @y <= 0 @y = 0 if @edge == :bottom and @y >= 0 @duration_completed_at = Gosu.milliseconds if @duration_completed_at == Float::INFINITY end end end
x_offset()
click to toggle source
# File lib/gosu_notifications/notification_manager.rb, line 225 def x_offset if not transition_in_complete? or duration_completed? Notification::WIDTH * animation_ratio else 0 end end
y_offset()
click to toggle source
# File lib/gosu_notifications/notification_manager.rb, line 233 def y_offset if not transition_in_complete? or duration_completed? Notification::HEIGHT * animation_ratio else 0 end end