class GosuNotifications::Notification

Constants

BACKGROUND_COLOR
EASE_IN_OUT_TRANSITION
EDGE_COLOR
EDGE_WIDTH
HEIGHT
ICON_COLOR
ICON_SIZE
LINEAR_TRANSITION
PADDING
PRIORITY_HIGH
PRIORITY_LOW
PRIORITY_MEDIUM
TAGLINE_COLOR
TAGLINE_FONT
TAGLINE_SIZE
TIME_TO_LIVE
TITLE_COLOR
TITLE_FONT
TITLE_SIZE
TRANSITION_DURATION
TTL_LONG
TTL_MEDIUM
TTL_SHORT
WIDTH

Attributes

icon[R]
priority[R]
tagline[R]
time_to_live[R]
title[R]
transition_duration[R]
transition_type[R]

Public Class Methods

new( host:, priority:, title:, title_color: TITLE_COLOR, tagline: "", tagline_color: TAGLINE_COLOR, icon: nil, icon_color: ICON_COLOR, edge_color: EDGE_COLOR, background_color: BACKGROUND_COLOR, time_to_live: TIME_TO_LIVE, transition_duration: TRANSITION_DURATION, transition_type: EASE_IN_OUT_TRANSITION ) click to toggle source
# File lib/gosu_notifications/notification.rb, line 35
def initialize(
  host:, priority:, title:, title_color: TITLE_COLOR, tagline: "", tagline_color: TAGLINE_COLOR, icon: nil, icon_color: ICON_COLOR,
  edge_color: EDGE_COLOR, background_color: BACKGROUND_COLOR, time_to_live: TIME_TO_LIVE, transition_duration: TRANSITION_DURATION,
  transition_type: EASE_IN_OUT_TRANSITION
)
  @host = host

  @priority = priority
  @title = title
  @title_color = title_color
  @tagline = tagline
  @tagline_color = tagline_color
  @icon = icon
  @icon_color = icon_color
  @edge_color = edge_color
  @background_color = background_color
  @time_to_live = time_to_live
  @transition_duration = transition_duration
  @transition_type = transition_type

  @icon_scale = ICON_SIZE.to_f / @icon.width if @icon
end

Public Instance Methods

draw() click to toggle source
# File lib/gosu_notifications/notification.rb, line 58
def draw
  Gosu.draw_rect(0, 0, WIDTH, HEIGHT, @background_color)

  if @host.edge == :top
    Gosu.draw_rect(0, HEIGHT - EDGE_WIDTH, WIDTH, EDGE_WIDTH, @edge_color)
    @icon.draw(EDGE_WIDTH + PADDING, PADDING, 0, @icon_scale, @icon_scale, @icon_color) if @icon

  elsif @host.edge == :bottom
    Gosu.draw_rect(0, 0, WIDTH, EDGE_WIDTH, @edge_color)
    @icon.draw(EDGE_WIDTH + PADDING, PADDING, 0, @icon_scale, @icon_scale, @icon_color) if @icon

  elsif @host.edge == :right
    Gosu.draw_rect(0, 0, EDGE_WIDTH, HEIGHT, @edge_color)
    @icon.draw(EDGE_WIDTH + PADDING, PADDING, 0, @icon_scale, @icon_scale, @icon_color) if @icon

  else
    Gosu.draw_rect(WIDTH - EDGE_WIDTH, 0, EDGE_WIDTH, HEIGHT, @edge_color)
    @icon.draw(PADDING, PADDING, 0, @icon_scale, @icon_scale, @icon_color) if @icon
  end

  icon_space = @icon ? ICON_SIZE + PADDING : 0
  TITLE_FONT.draw_text(@title, PADDING + EDGE_WIDTH + icon_space, PADDING, 0, 1, 1, @title_color)
  TAGLINE_FONT.draw_text(@tagline, PADDING + EDGE_WIDTH + icon_space, PADDING + TITLE_FONT.height, 0, 1, 1, @tagline_color)
end