Class: CyberarmEngine::Notification

Inherits:
Object
  • Object
show all
Defined in:
lib/cyberarm_engine/notification.rb

Constant Summary collapse

WIDTH =
500
HEIGHT =
64
EDGE_WIDTH =
8
TRANSITION_DURATION =
750
PADDING =
8
TTL_LONG =
5_000
TTL_MEDIUM =
3_250
TTL_SHORT =
1_500
TIME_TO_LIVE =
TTL_MEDIUM
BACKGROUND_COLOR =
Gosu::Color.new(0xaa313533)
EDGE_COLOR =
Gosu::Color.new(0xaa010101)
ICON_COLOR =
Gosu::Color.new(0xddffffff)
TITLE_COLOR =
Gosu::Color.new(0xddffffff)
TAGLINE_COLOR =
Gosu::Color.new(0xddaaaaaa)
TITLE_SIZE =
28
TAGLINE_SIZE =
18
ICON_SIZE =
HEIGHT - PADDING * 2
TITLE_FONT =
Gosu::Font.new(TITLE_SIZE, bold: true)
TAGLINE_FONT =
Gosu::Font.new(TAGLINE_SIZE)
PRIORITY_HIGH =
1.0
PRIORITY_MEDIUM =
0.5
PRIORITY_LOW =
0.0
LINEAR_TRANSITION =
:linear
EASE_IN_OUT_TRANSITION =
:ease_in_out

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#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) ⇒ Notification

Returns a new instance of Notification.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/cyberarm_engine/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

Instance Attribute Details

#iconObject (readonly)

Returns the value of attribute icon.



34
35
36
# File 'lib/cyberarm_engine/notification.rb', line 34

def icon
  @icon
end

#priorityObject (readonly)

Returns the value of attribute priority.



34
35
36
# File 'lib/cyberarm_engine/notification.rb', line 34

def priority
  @priority
end

#taglineObject (readonly)

Returns the value of attribute tagline.



34
35
36
# File 'lib/cyberarm_engine/notification.rb', line 34

def tagline
  @tagline
end

#time_to_liveObject (readonly)

Returns the value of attribute time_to_live.



34
35
36
# File 'lib/cyberarm_engine/notification.rb', line 34

def time_to_live
  @time_to_live
end

#titleObject (readonly)

Returns the value of attribute title.



34
35
36
# File 'lib/cyberarm_engine/notification.rb', line 34

def title
  @title
end

#transition_durationObject (readonly)

Returns the value of attribute transition_duration.



34
35
36
# File 'lib/cyberarm_engine/notification.rb', line 34

def transition_duration
  @transition_duration
end

#transition_typeObject (readonly)

Returns the value of attribute transition_type.



34
35
36
# File 'lib/cyberarm_engine/notification.rb', line 34

def transition_type
  @transition_type
end

Instance Method Details

#drawObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/cyberarm_engine/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