class GosuNotifications::NotificationManager
Constants
- EDGE_BOTTOM
- EDGE_LEFT
- EDGE_RIGHT
- EDGE_TOP
- MODE_CIRCLE
- MODE_DEFAULT
Attributes
edge[R]
max_visible[R]
mode[R]
notifications[R]
Public Class Methods
new(edge: EDGE_RIGHT, mode: MODE_DEFAULT, window:, max_visible: 1)
click to toggle source
# File lib/gosu_notifications/notification_manager.rb, line 12 def initialize(edge: EDGE_RIGHT, mode: MODE_DEFAULT, window:, max_visible: 1) @edge = edge @mode = mode @window = window @max_visible = max_visible @notifications = [] @drivers = [] @slots = Array.new(max_visible, nil) end
Public Instance Methods
available_slot_index()
click to toggle source
# File lib/gosu_notifications/notification_manager.rb, line 69 def available_slot_index @slots.each_with_index do |slot, i| return i unless slot end return -1 end
create_notification(**args)
click to toggle source
# File lib/gosu_notifications/notification_manager.rb, line 94 def create_notification(**args) notification = Notification.new(host: self, **args) @notifications << notification end
draw()
click to toggle source
# File lib/gosu_notifications/notification_manager.rb, line 23 def draw @drivers.each do |driver| case @edge when :left, :right x = @edge == :right ? @window.width + driver.x : -Notification::WIDTH + driver.x y = driver.y + Notification::HEIGHT / 2 Gosu.translate(x, y + (Notification::HEIGHT + Notification::PADDING) * driver.slot) do driver.draw end when :top, :bottom x = @window.width / 2 - Notification::WIDTH / 2 y = @edge == :top ? driver.y - Notification::HEIGHT : @window.height + driver.y slot_position = (Notification::HEIGHT + Notification::PADDING) * driver.slot slot_position *= -1 if @edge == :bottom Gosu.translate(x, y + slot_position) do driver.draw end end end end
highest_used_slot()
click to toggle source
# File lib/gosu_notifications/notification_manager.rb, line 85 def highest_used_slot _slot = -1 @slots.each_with_index do |slot, i| _slot = i if slot end return _slot end
lowest_used_slot()
click to toggle source
# File lib/gosu_notifications/notification_manager.rb, line 77 def lowest_used_slot @slots.each_with_index do |slot, i| return i if slot end return -1 end
show_next_notification()
click to toggle source
# File lib/gosu_notifications/notification_manager.rb, line 59 def show_next_notification notification = @notifications.sort { |n| n.priority }.reverse.shift return unless notification return if available_slot_index < lowest_used_slot @notifications.delete(notification) @drivers << Driver.new(edge: @edge, mode: @mode, notification: notification, slot: available_slot_index) slot = @slots[available_slot_index] = @drivers.last end
update()
click to toggle source
# File lib/gosu_notifications/notification_manager.rb, line 47 def update show_next_notification if @drivers.size < @max_visible @drivers.each do |driver| if driver.done? @slots[driver.slot] = nil @drivers.delete(driver) end end @drivers.each(&:update) end