gosu_notifications 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +66 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/examples/demo.rb +78 -0
- data/gosu_notifications.gemspec +27 -0
- data/lib/gosu_notifications.rb +3 -0
- data/lib/gosu_notifications/notification.rb +83 -0
- data/lib/gosu_notifications/notification_manager.rb +242 -0
- data/lib/gosu_notifications/version.rb +3 -0
- metadata +58 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0a443fe622fac7958ecc6218e2f049f9f9925aa9d4de33ee6c5ee10467efad52
|
4
|
+
data.tar.gz: bcee1f7c47b77bc95515106e72e2206b8136052a4cf1f547d228d7eb2e71ad08
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: eac68c7a6ef62ea9f66fa5c879fed59b2ef0365301c2d2719dc78de6975c030aee47cb2961c215bb928d424ec4b7b0b3a361d063977fa616ad3417253e15e73b
|
7
|
+
data.tar.gz: a236213ac2242b63a3ae3ecb59bf8825f797c58b2f71b4035bcaf6d1c6ce7950aa635299e052c1b3667f821dd291ba469c4ee8cda0d82a1ecb1303520a2eaa72
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 cyberarm
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
# GosuNotifications
|
2
|
+
|
3
|
+
A simple notifications system for Gosu
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem "gosu_notifications"
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install gosu_notifications
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
require "gosu"
|
25
|
+
require "gosu_notifications"
|
26
|
+
|
27
|
+
class Window < Gosu::Window
|
28
|
+
def initialize
|
29
|
+
super 640, 480, false
|
30
|
+
|
31
|
+
@notification_manager = GosuNotifications::NotificationManager.new(window: self)
|
32
|
+
end
|
33
|
+
|
34
|
+
def draw
|
35
|
+
@notification_manager.draw
|
36
|
+
end
|
37
|
+
|
38
|
+
def update
|
39
|
+
@notification_manager.update
|
40
|
+
end
|
41
|
+
|
42
|
+
def button_down(id)
|
43
|
+
@notification_manager.create_notification(
|
44
|
+
title: "A Button Has Been Pressed",
|
45
|
+
tagline: "#{id}"
|
46
|
+
)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
Window.new.show
|
51
|
+
```
|
52
|
+
|
53
|
+
## Development
|
54
|
+
|
55
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
56
|
+
|
57
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
58
|
+
|
59
|
+
## Contributing
|
60
|
+
|
61
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/gosu_notifications.
|
62
|
+
|
63
|
+
|
64
|
+
## License
|
65
|
+
|
66
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "gosu_notifications"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/examples/demo.rb
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
require "gosu"
|
2
|
+
require "gosu_notifications"
|
3
|
+
|
4
|
+
class Window < Gosu::Window
|
5
|
+
def initialize
|
6
|
+
super 640, 480, false
|
7
|
+
self.caption = "Gosu Notifications Demo"
|
8
|
+
|
9
|
+
@notification_manager = GosuNotifications::Manager.new(window: self, max_visible: 5)
|
10
|
+
@notification_manager_mouse = GosuNotifications::Manager.new(edge: :bottom, mode: GosuNotifications::Manager::MODE_CIRCLE, window: self, max_visible: 1)
|
11
|
+
@font = Gosu::Font.new(22)
|
12
|
+
@text = "Press a Button"
|
13
|
+
|
14
|
+
@icon = generate_icon
|
15
|
+
end
|
16
|
+
|
17
|
+
def draw
|
18
|
+
@font.draw_text(@text, width / 2 - @font.text_width(@text) / 2, height / 2 - @font.height / 2, 0)
|
19
|
+
@notification_manager.draw
|
20
|
+
@notification_manager_mouse.draw
|
21
|
+
end
|
22
|
+
|
23
|
+
def update
|
24
|
+
@notification_manager.update
|
25
|
+
@notification_manager_mouse.update
|
26
|
+
end
|
27
|
+
|
28
|
+
def needs_cursor?
|
29
|
+
true
|
30
|
+
end
|
31
|
+
|
32
|
+
def button_down(id)
|
33
|
+
if [ Gosu::MS_LEFT, Gosu::MS_MIDDLE, Gosu::MS_RIGHT ].include?(id)
|
34
|
+
@notification_manager_mouse.create_notification(
|
35
|
+
priority: GosuNotifications::Notification::PRIORITY_HIGH,
|
36
|
+
title: "Mouse Button Pressed",
|
37
|
+
|
38
|
+
tagline: "Gosu::#{button_id_to_constant(id)} -> #{id}",
|
39
|
+
transition_duration: 1_000,
|
40
|
+
time_to_live: 500,
|
41
|
+
edge_color: 0xaaff8844,
|
42
|
+
background_color: 0xaa884422,
|
43
|
+
title_color: 0xaaf8fffef,
|
44
|
+
tagline_color: 0xaae4e4e4,
|
45
|
+
icon: @icon,
|
46
|
+
)
|
47
|
+
else
|
48
|
+
@notification_manager.create_notification(
|
49
|
+
priority: GosuNotifications::Notification::PRIORITY_HIGH,
|
50
|
+
title: "A Button Has Been Pressed",
|
51
|
+
tagline: "Gosu::#{button_id_to_constant(id)} -> #{id}",
|
52
|
+
transition_duration: 1_000,
|
53
|
+
time_to_live: 500,
|
54
|
+
edge_color: 0xaaffff88,
|
55
|
+
background_color: 0xaa222f2f
|
56
|
+
)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def generate_icon
|
61
|
+
Gosu.render(64, 64) do
|
62
|
+
Gosu.rotate(45, 32, 32) do
|
63
|
+
Gosu.draw_rect(16, 16, 64 - 32, 64 - 32, 0xff008855)
|
64
|
+
Gosu.draw_rect(30, 0, 4, 64, 0xffffffff)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def button_id_to_constant(id)
|
70
|
+
Gosu.constants.each do |constant|
|
71
|
+
if Gosu.const_get(constant) == id
|
72
|
+
return constant
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
Window.new.show
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require_relative 'lib/gosu_notifications/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "gosu_notifications"
|
5
|
+
spec.version = GosuNotifications::VERSION
|
6
|
+
spec.authors = ["cyberarm"]
|
7
|
+
spec.email = ["matthewlikesrobots@gmail.com"]
|
8
|
+
|
9
|
+
spec.summary = "A simple notifications system for Gosu"
|
10
|
+
spec.description = "A simple notifications system for Gosu "
|
11
|
+
spec.homepage = "https://github.com/cyberarm/gosu_notifications"
|
12
|
+
spec.license = "MIT"
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
14
|
+
|
15
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
16
|
+
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
|
19
|
+
# Specify which files should be added to the gem when it is released.
|
20
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
21
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
22
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
23
|
+
end
|
24
|
+
spec.bindir = "exe"
|
25
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
26
|
+
spec.require_paths = ["lib"]
|
27
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module GosuNotifications
|
2
|
+
class Notification
|
3
|
+
WIDTH = 500
|
4
|
+
HEIGHT = 64
|
5
|
+
EDGE_WIDTH = 8
|
6
|
+
TRANSITION_DURATION = 750
|
7
|
+
PADDING = 8
|
8
|
+
|
9
|
+
TTL_LONG = 5_000
|
10
|
+
TTL_MEDIUM = 3_250
|
11
|
+
TTL_SHORT = 1_500
|
12
|
+
TIME_TO_LIVE = TTL_MEDIUM
|
13
|
+
|
14
|
+
BACKGROUND_COLOR = Gosu::Color.new(0xaa313533)
|
15
|
+
EDGE_COLOR = Gosu::Color.new(0xaa010101)
|
16
|
+
ICON_COLOR = Gosu::Color.new(0xddffffff)
|
17
|
+
TITLE_COLOR = Gosu::Color.new(0xddffffff)
|
18
|
+
TAGLINE_COLOR = Gosu::Color.new(0xddaaaaaa)
|
19
|
+
|
20
|
+
TITLE_SIZE = 28
|
21
|
+
TAGLINE_SIZE = 18
|
22
|
+
ICON_SIZE = HEIGHT - PADDING * 2
|
23
|
+
|
24
|
+
TITLE_FONT = Gosu::Font.new(TITLE_SIZE, bold: true)
|
25
|
+
TAGLINE_FONT = Gosu::Font.new(TAGLINE_SIZE)
|
26
|
+
|
27
|
+
PRIORITY_HIGH = 1.0
|
28
|
+
PRIORITY_MEDIUM = 0.5
|
29
|
+
PRIORITY_LOW = 0.0
|
30
|
+
|
31
|
+
LINEAR_TRANSITION = :linear
|
32
|
+
EASE_IN_OUT_TRANSITION = :ease_in_out
|
33
|
+
|
34
|
+
attr_reader :priority, :title, :tagline, :icon, :time_to_live, :transition_duration, :transition_type
|
35
|
+
def initialize(
|
36
|
+
host:, priority:, title:, title_color: TITLE_COLOR, tagline: "", tagline_color: TAGLINE_COLOR, icon: nil, icon_color: ICON_COLOR,
|
37
|
+
edge_color: EDGE_COLOR, background_color: BACKGROUND_COLOR, time_to_live: TIME_TO_LIVE, transition_duration: TRANSITION_DURATION,
|
38
|
+
transition_type: EASE_IN_OUT_TRANSITION
|
39
|
+
)
|
40
|
+
@host = host
|
41
|
+
|
42
|
+
@priority = priority
|
43
|
+
@title = title
|
44
|
+
@title_color = title_color
|
45
|
+
@tagline = tagline
|
46
|
+
@tagline_color = tagline_color
|
47
|
+
@icon = icon
|
48
|
+
@icon_color = icon_color
|
49
|
+
@edge_color = edge_color
|
50
|
+
@background_color = background_color
|
51
|
+
@time_to_live = time_to_live
|
52
|
+
@transition_duration = transition_duration
|
53
|
+
@transition_type = transition_type
|
54
|
+
|
55
|
+
@icon_scale = ICON_SIZE.to_f / @icon.width if @icon
|
56
|
+
end
|
57
|
+
|
58
|
+
def draw
|
59
|
+
Gosu.draw_rect(0, 0, WIDTH, HEIGHT, @background_color)
|
60
|
+
|
61
|
+
if @host.edge == :top
|
62
|
+
Gosu.draw_rect(0, HEIGHT - EDGE_WIDTH, WIDTH, EDGE_WIDTH, @edge_color)
|
63
|
+
@icon.draw(EDGE_WIDTH + PADDING, PADDING, 0, @icon_scale, @icon_scale, @icon_color) if @icon
|
64
|
+
|
65
|
+
elsif @host.edge == :bottom
|
66
|
+
Gosu.draw_rect(0, 0, WIDTH, EDGE_WIDTH, @edge_color)
|
67
|
+
@icon.draw(EDGE_WIDTH + PADDING, PADDING, 0, @icon_scale, @icon_scale, @icon_color) if @icon
|
68
|
+
|
69
|
+
elsif @host.edge == :right
|
70
|
+
Gosu.draw_rect(0, 0, EDGE_WIDTH, HEIGHT, @edge_color)
|
71
|
+
@icon.draw(EDGE_WIDTH + PADDING, PADDING, 0, @icon_scale, @icon_scale, @icon_color) if @icon
|
72
|
+
|
73
|
+
else
|
74
|
+
Gosu.draw_rect(WIDTH - EDGE_WIDTH, 0, EDGE_WIDTH, HEIGHT, @edge_color)
|
75
|
+
@icon.draw(PADDING, PADDING, 0, @icon_scale, @icon_scale, @icon_color) if @icon
|
76
|
+
end
|
77
|
+
|
78
|
+
icon_space = @icon ? ICON_SIZE + PADDING : 0
|
79
|
+
TITLE_FONT.draw_text(@title, PADDING + EDGE_WIDTH + icon_space, PADDING, 0, 1, 1, @title_color)
|
80
|
+
TAGLINE_FONT.draw_text(@tagline, PADDING + EDGE_WIDTH + icon_space, PADDING + TITLE_FONT.height, 0, 1, 1, @tagline_color)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,242 @@
|
|
1
|
+
module GosuNotifications
|
2
|
+
class NotificationManager
|
3
|
+
EDGE_TOP = :top
|
4
|
+
EDGE_BOTTOM = :bottom
|
5
|
+
EDGE_RIGHT = :right
|
6
|
+
EDGE_LEFT = :left
|
7
|
+
|
8
|
+
MODE_DEFAULT = :slide
|
9
|
+
MODE_CIRCLE = :circle
|
10
|
+
|
11
|
+
attr_reader :edge, :mode, :max_visible, :notifications
|
12
|
+
def initialize(edge: EDGE_RIGHT, mode: MODE_DEFAULT, window:, max_visible: 1)
|
13
|
+
@edge = edge
|
14
|
+
@mode = mode
|
15
|
+
@window = window
|
16
|
+
@max_visible = max_visible
|
17
|
+
|
18
|
+
@notifications = []
|
19
|
+
@drivers = []
|
20
|
+
@slots = Array.new(max_visible, nil)
|
21
|
+
end
|
22
|
+
|
23
|
+
def draw
|
24
|
+
@drivers.each do |driver|
|
25
|
+
case @edge
|
26
|
+
when :left, :right
|
27
|
+
x = @edge == :right ? @window.width + driver.x : -Notification::WIDTH + driver.x
|
28
|
+
y = driver.y + Notification::HEIGHT / 2
|
29
|
+
|
30
|
+
Gosu.translate(x, y + (Notification::HEIGHT + Notification::PADDING) * driver.slot) do
|
31
|
+
driver.draw
|
32
|
+
end
|
33
|
+
|
34
|
+
when :top, :bottom
|
35
|
+
x = @window.width / 2 - Notification::WIDTH / 2
|
36
|
+
y = @edge == :top ? driver.y - Notification::HEIGHT : @window.height + driver.y
|
37
|
+
slot_position = (Notification::HEIGHT + Notification::PADDING) * driver.slot
|
38
|
+
slot_position *= -1 if @edge == :bottom
|
39
|
+
|
40
|
+
Gosu.translate(x, y + slot_position) do
|
41
|
+
driver.draw
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def update
|
48
|
+
show_next_notification if @drivers.size < @max_visible
|
49
|
+
@drivers.each do |driver|
|
50
|
+
if driver.done?
|
51
|
+
@slots[driver.slot] = nil
|
52
|
+
@drivers.delete(driver)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
@drivers.each(&:update)
|
57
|
+
end
|
58
|
+
|
59
|
+
def show_next_notification
|
60
|
+
notification = @notifications.sort { |n| n.priority }.reverse.shift
|
61
|
+
return unless notification
|
62
|
+
return if available_slot_index < lowest_used_slot
|
63
|
+
@notifications.delete(notification)
|
64
|
+
|
65
|
+
@drivers << Driver.new(edge: @edge, mode: @mode, notification: notification, slot: available_slot_index)
|
66
|
+
slot = @slots[available_slot_index] = @drivers.last
|
67
|
+
end
|
68
|
+
|
69
|
+
def available_slot_index
|
70
|
+
@slots.each_with_index do |slot, i|
|
71
|
+
return i unless slot
|
72
|
+
end
|
73
|
+
|
74
|
+
return -1
|
75
|
+
end
|
76
|
+
|
77
|
+
def lowest_used_slot
|
78
|
+
@slots.each_with_index do |slot, i|
|
79
|
+
return i if slot
|
80
|
+
end
|
81
|
+
|
82
|
+
return -1
|
83
|
+
end
|
84
|
+
|
85
|
+
def highest_used_slot
|
86
|
+
_slot = -1
|
87
|
+
@slots.each_with_index do |slot, i|
|
88
|
+
_slot = i if slot
|
89
|
+
end
|
90
|
+
|
91
|
+
return _slot
|
92
|
+
end
|
93
|
+
|
94
|
+
def create_notification(**args)
|
95
|
+
notification = Notification.new(host: self, **args)
|
96
|
+
@notifications << notification
|
97
|
+
end
|
98
|
+
|
99
|
+
class Driver
|
100
|
+
attr_reader :x, :y, :notification, :slot
|
101
|
+
def initialize(edge:, mode:, notification:, slot:)
|
102
|
+
@edge = edge
|
103
|
+
@mode = mode
|
104
|
+
@notification = notification
|
105
|
+
@slot = slot
|
106
|
+
|
107
|
+
@x, @y = 0, 0
|
108
|
+
@delta = Gosu.milliseconds
|
109
|
+
@accumulator = 0.0
|
110
|
+
|
111
|
+
@born_at = Gosu.milliseconds
|
112
|
+
@duration_completed_at = Float::INFINITY
|
113
|
+
@transition_completed_at = Float::INFINITY
|
114
|
+
end
|
115
|
+
|
116
|
+
def transition_in_complete?
|
117
|
+
Gosu.milliseconds - @born_at >= @notification.transition_duration
|
118
|
+
end
|
119
|
+
|
120
|
+
def duration_completed?
|
121
|
+
Gosu.milliseconds - @transition_completed_at >= @notification.time_to_live
|
122
|
+
end
|
123
|
+
|
124
|
+
def done?
|
125
|
+
Gosu.milliseconds - @duration_completed_at >= @notification.transition_duration
|
126
|
+
end
|
127
|
+
|
128
|
+
def draw
|
129
|
+
ratio = 0.0
|
130
|
+
|
131
|
+
if not transition_in_complete?
|
132
|
+
ratio = animation_ratio
|
133
|
+
elsif transition_in_complete? and not duration_completed?
|
134
|
+
ratio = 1.0
|
135
|
+
elsif duration_completed?
|
136
|
+
ratio = 1.0 - animation_ratio
|
137
|
+
end
|
138
|
+
|
139
|
+
case @mode
|
140
|
+
when MODE_DEFAULT
|
141
|
+
Gosu.clip_to(0, 0, Notification::WIDTH, Notification::HEIGHT * ratio) do
|
142
|
+
@notification.draw
|
143
|
+
end
|
144
|
+
when MODE_CIRCLE
|
145
|
+
half = Notification::WIDTH / 2
|
146
|
+
|
147
|
+
Gosu.clip_to(half - (half * ratio), 0, Notification::WIDTH * ratio, Notification::HEIGHT) do
|
148
|
+
@notification.draw
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
def update
|
154
|
+
case @mode
|
155
|
+
when MODE_DEFAULT
|
156
|
+
update_default
|
157
|
+
when MODE_CIRCLE
|
158
|
+
update_circle
|
159
|
+
end
|
160
|
+
|
161
|
+
@accumulator += Gosu.milliseconds - @delta
|
162
|
+
@delta = Gosu.milliseconds
|
163
|
+
end
|
164
|
+
|
165
|
+
|
166
|
+
def update_default
|
167
|
+
case @edge
|
168
|
+
when :left, :right
|
169
|
+
if not transition_in_complete? # Slide In
|
170
|
+
@x = @edge == :right ? -x_offset : x_offset
|
171
|
+
elsif transition_in_complete? and not duration_completed?
|
172
|
+
@x = @edge == :right ? -Notification::WIDTH : Notification::WIDTH if @x.abs != Notification::WIDTH
|
173
|
+
@transition_completed_at = Gosu.milliseconds if @transition_completed_at == Float::INFINITY
|
174
|
+
@accumulator = 0.0
|
175
|
+
elsif duration_completed? # Slide Out
|
176
|
+
@x = @edge == :right ? x_offset - Notification::WIDTH : Notification::WIDTH - x_offset
|
177
|
+
@x = 0 if @edge == :left and @x <= 0
|
178
|
+
@x = 0 if @edge == :right and @x >= 0
|
179
|
+
@duration_completed_at = Gosu.milliseconds if @duration_completed_at == Float::INFINITY
|
180
|
+
end
|
181
|
+
|
182
|
+
when :top, :bottom
|
183
|
+
if not transition_in_complete? # Slide In
|
184
|
+
@y = @edge == :top ? y_offset : -y_offset
|
185
|
+
elsif transition_in_complete? and not duration_completed?
|
186
|
+
@y = @edge == :top ? Notification::HEIGHT : -Notification::HEIGHT if @x.abs != Notification::HEIGHT
|
187
|
+
@transition_completed_at = Gosu.milliseconds if @transition_completed_at == Float::INFINITY
|
188
|
+
@accumulator = 0.0
|
189
|
+
elsif duration_completed? # Slide Out
|
190
|
+
@y = @edge == :top ? Notification::HEIGHT - y_offset : y_offset - Notification::HEIGHT
|
191
|
+
@y = 0 if @edge == :top and @y <= 0
|
192
|
+
@y = 0 if @edge == :bottom and @y >= 0
|
193
|
+
@duration_completed_at = Gosu.milliseconds if @duration_completed_at == Float::INFINITY
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
def update_circle
|
199
|
+
case @edge
|
200
|
+
when :top, :bottom
|
201
|
+
@y = @edge == :top ? Notification::HEIGHT : -Notification::HEIGHT
|
202
|
+
when :left, :right
|
203
|
+
@x = @edge == :right ? -Notification::WIDTH : Notification::WIDTH
|
204
|
+
end
|
205
|
+
|
206
|
+
if transition_in_complete? and not duration_completed?
|
207
|
+
@transition_completed_at = Gosu.milliseconds if @transition_completed_at == Float::INFINITY
|
208
|
+
@accumulator = 0.0
|
209
|
+
elsif duration_completed?
|
210
|
+
@duration_completed_at = Gosu.milliseconds if @duration_completed_at == Float::INFINITY
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
def animation_ratio
|
215
|
+
x = (@accumulator / @notification.transition_duration)
|
216
|
+
|
217
|
+
case @notification.transition_type
|
218
|
+
when Notification::LINEAR_TRANSITION
|
219
|
+
x.clamp(0.0, 1.0)
|
220
|
+
when Notification::EASE_IN_OUT_TRANSITION # https://easings.net/#easeInOutQuint
|
221
|
+
(x < 0.5 ? 16 * x * x * x * x * x : 1 - ((-2 * x + 2) ** 5) / 2).clamp(0.0, 1.0)
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
def x_offset
|
226
|
+
if not transition_in_complete? or duration_completed?
|
227
|
+
Notification::WIDTH * animation_ratio
|
228
|
+
else
|
229
|
+
0
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
def y_offset
|
234
|
+
if not transition_in_complete? or duration_completed?
|
235
|
+
Notification::HEIGHT * animation_ratio
|
236
|
+
else
|
237
|
+
0
|
238
|
+
end
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
242
|
+
end
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gosu_notifications
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- cyberarm
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-08-22 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: 'A simple notifications system for Gosu '
|
14
|
+
email:
|
15
|
+
- matthewlikesrobots@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".gitignore"
|
21
|
+
- Gemfile
|
22
|
+
- LICENSE.txt
|
23
|
+
- README.md
|
24
|
+
- Rakefile
|
25
|
+
- bin/console
|
26
|
+
- bin/setup
|
27
|
+
- examples/demo.rb
|
28
|
+
- gosu_notifications.gemspec
|
29
|
+
- lib/gosu_notifications.rb
|
30
|
+
- lib/gosu_notifications/notification.rb
|
31
|
+
- lib/gosu_notifications/notification_manager.rb
|
32
|
+
- lib/gosu_notifications/version.rb
|
33
|
+
homepage: https://github.com/cyberarm/gosu_notifications
|
34
|
+
licenses:
|
35
|
+
- MIT
|
36
|
+
metadata:
|
37
|
+
allowed_push_host: https://rubygems.org
|
38
|
+
homepage_uri: https://github.com/cyberarm/gosu_notifications
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.3.0
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
requirements: []
|
54
|
+
rubygems_version: 3.1.4
|
55
|
+
signing_key:
|
56
|
+
specification_version: 4
|
57
|
+
summary: A simple notifications system for Gosu
|
58
|
+
test_files: []
|