cyberarm_engine 0.24.3 → 0.24.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +8 -8
- data/.rubocop.yml +7 -7
- data/.travis.yml +5 -5
- data/Gemfile +6 -6
- data/Gemfile.lock +24 -0
- data/LICENSE.txt +21 -21
- data/README.md +74 -74
- data/Rakefile +10 -10
- data/assets/shaders/fragment/g_buffer.glsl +30 -30
- data/assets/shaders/fragment/lighting.glsl +115 -69
- data/assets/shaders/include/light_struct.glsl +11 -11
- data/assets/shaders/include/material_struct.glsl +16 -16
- data/assets/shaders/vertex/g_buffer.glsl +28 -28
- data/assets/shaders/vertex/lighting.glsl +24 -24
- data/bin/console +14 -14
- data/bin/setup +8 -8
- data/cyberarm_engine.gemspec +36 -36
- data/lib/cyberarm_engine/animator.rb +219 -219
- data/lib/cyberarm_engine/background.rb +180 -179
- data/lib/cyberarm_engine/background_image.rb +93 -93
- data/lib/cyberarm_engine/background_nine_slice.rb +142 -142
- data/lib/cyberarm_engine/bounding_box.rb +150 -150
- data/lib/cyberarm_engine/builtin/intro_state.rb +130 -130
- data/lib/cyberarm_engine/cache/download_manager.rb +123 -123
- data/lib/cyberarm_engine/cache.rb +4 -4
- data/lib/cyberarm_engine/common.rb +128 -128
- data/lib/cyberarm_engine/config_file.rb +46 -46
- data/lib/cyberarm_engine/console/command.rb +157 -157
- data/lib/cyberarm_engine/console/commands/help_command.rb +43 -43
- data/lib/cyberarm_engine/console/subcommand.rb +99 -99
- data/lib/cyberarm_engine/console.rb +248 -248
- data/lib/cyberarm_engine/game_object.rb +244 -244
- data/lib/cyberarm_engine/game_state.rb +124 -124
- data/lib/cyberarm_engine/gosu_ext/draw_arc.rb +97 -97
- data/lib/cyberarm_engine/gosu_ext/draw_circle.rb +30 -30
- data/lib/cyberarm_engine/gosu_ext/draw_path.rb +17 -17
- data/lib/cyberarm_engine/model/material.rb +21 -21
- data/lib/cyberarm_engine/model/{model_object.rb → mesh.rb} +131 -131
- data/lib/cyberarm_engine/model/parser.rb +74 -74
- data/lib/cyberarm_engine/model/parsers/collada_parser.rb +138 -138
- data/lib/cyberarm_engine/model/parsers/wavefront_parser.rb +154 -154
- data/lib/cyberarm_engine/model.rb +216 -213
- data/lib/cyberarm_engine/model_cache.rb +31 -31
- data/lib/cyberarm_engine/notification.rb +82 -82
- data/lib/cyberarm_engine/notification_manager.rb +241 -241
- data/lib/cyberarm_engine/opengl/light.rb +52 -50
- data/lib/cyberarm_engine/opengl/orthographic_camera.rb +46 -46
- data/lib/cyberarm_engine/opengl/perspective_camera.rb +41 -38
- data/lib/cyberarm_engine/opengl/renderer/bounding_box_renderer.rb +249 -249
- data/lib/cyberarm_engine/opengl/renderer/g_buffer.rb +167 -165
- data/lib/cyberarm_engine/opengl/renderer/opengl_renderer.rb +307 -304
- data/lib/cyberarm_engine/opengl/renderer/renderer.rb +33 -33
- data/lib/cyberarm_engine/opengl/shader.rb +408 -406
- data/lib/cyberarm_engine/opengl/texture.rb +69 -69
- data/lib/cyberarm_engine/opengl.rb +53 -40
- data/lib/cyberarm_engine/ray.rb +56 -56
- data/lib/cyberarm_engine/stats.rb +200 -200
- data/lib/cyberarm_engine/text.rb +260 -260
- data/lib/cyberarm_engine/timer.rb +23 -23
- data/lib/cyberarm_engine/transform.rb +296 -296
- data/lib/cyberarm_engine/trees/aabb_node.rb +126 -0
- data/lib/cyberarm_engine/trees/aabb_tree.rb +55 -0
- data/lib/cyberarm_engine/trees/aabb_tree_debug.rb +29 -0
- data/lib/cyberarm_engine/ui/border_canvas.rb +102 -102
- data/lib/cyberarm_engine/ui/dsl.rb +142 -142
- data/lib/cyberarm_engine/ui/element.rb +662 -662
- data/lib/cyberarm_engine/ui/elements/button.rb +100 -100
- data/lib/cyberarm_engine/ui/elements/check_box.rb +54 -54
- data/lib/cyberarm_engine/ui/elements/container.rb +404 -410
- data/lib/cyberarm_engine/ui/elements/edit_box.rb +179 -179
- data/lib/cyberarm_engine/ui/elements/edit_line.rb +297 -297
- data/lib/cyberarm_engine/ui/elements/flow.rb +15 -15
- data/lib/cyberarm_engine/ui/elements/image.rb +72 -72
- data/lib/cyberarm_engine/ui/elements/list_box.rb +79 -79
- data/lib/cyberarm_engine/ui/elements/menu.rb +27 -27
- data/lib/cyberarm_engine/ui/elements/menu_item.rb +6 -6
- data/lib/cyberarm_engine/ui/elements/progress.rb +93 -93
- data/lib/cyberarm_engine/ui/elements/radio.rb +6 -6
- data/lib/cyberarm_engine/ui/elements/slider.rb +107 -107
- data/lib/cyberarm_engine/ui/elements/stack.rb +11 -11
- data/lib/cyberarm_engine/ui/elements/text_block.rb +216 -216
- data/lib/cyberarm_engine/ui/elements/toggle_button.rb +67 -67
- data/lib/cyberarm_engine/ui/event.rb +54 -54
- data/lib/cyberarm_engine/ui/gui_state.rb +321 -321
- data/lib/cyberarm_engine/ui/style.rb +50 -50
- data/lib/cyberarm_engine/ui/theme.rb +225 -225
- data/lib/cyberarm_engine/vector.rb +312 -312
- data/lib/cyberarm_engine/version.rb +4 -4
- data/lib/cyberarm_engine/window.rb +195 -195
- data/lib/cyberarm_engine.rb +70 -78
- data/mrbgem.rake +29 -29
- metadata +8 -7
@@ -1,213 +1,216 @@
|
|
1
|
-
module CyberarmEngine
|
2
|
-
class Model
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
@
|
14
|
-
|
15
|
-
@
|
16
|
-
|
17
|
-
@
|
18
|
-
@
|
19
|
-
|
20
|
-
@
|
21
|
-
@
|
22
|
-
@
|
23
|
-
@
|
24
|
-
@
|
25
|
-
@
|
26
|
-
|
27
|
-
@
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
bounding_box.
|
69
|
-
bounding_box.
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
bounding_box.
|
79
|
-
bounding_box.
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
@vertex_array_id =
|
90
|
-
|
91
|
-
|
92
|
-
@
|
93
|
-
|
94
|
-
|
95
|
-
@positions_buffer_id =
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
@colors_buffer_id =
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
@normals_buffer_id =
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
@uvs_buffer_id =
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
glBindBuffer(GL_ARRAY_BUFFER, @
|
131
|
-
glBufferData(GL_ARRAY_BUFFER,
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
#
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
#
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
face.vertices.
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
end
|
1
|
+
module CyberarmEngine
|
2
|
+
class Model
|
3
|
+
include OpenGL
|
4
|
+
include CyberarmEngine
|
5
|
+
|
6
|
+
attr_accessor :objects, :materials, :vertices, :uvs, :texures, :normals, :faces, :colors, :bones, :material_file,
|
7
|
+
:current_material, :current_object, :vertex_count, :smoothing
|
8
|
+
attr_reader :position, :bounding_box, :textured_material, :file_path, :positions_buffer_id, :colors_buffer_id,
|
9
|
+
:normals_buffer_id, :uvs_buffer_id, :textures_buffer_id, :vertex_array_id, :aabb_tree,
|
10
|
+
:vertices_count
|
11
|
+
|
12
|
+
def initialize(file_path:)
|
13
|
+
@file_path = file_path
|
14
|
+
|
15
|
+
@material_file = nil
|
16
|
+
@current_object = nil
|
17
|
+
@current_material = nil
|
18
|
+
@vertex_count = 0
|
19
|
+
|
20
|
+
@objects = []
|
21
|
+
@materials = {}
|
22
|
+
@vertices = []
|
23
|
+
@colors = []
|
24
|
+
@uvs = []
|
25
|
+
@normals = []
|
26
|
+
@faces = []
|
27
|
+
@bones = []
|
28
|
+
@smoothing = 0
|
29
|
+
|
30
|
+
@vertices_count = 0
|
31
|
+
|
32
|
+
@bounding_box = BoundingBox.new
|
33
|
+
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_millisecond)
|
34
|
+
|
35
|
+
type = File.basename(file_path).split(".").last.to_sym
|
36
|
+
parser = Model::Parser.find(type)
|
37
|
+
raise "Unsupported model type '.#{type}', supported models are: #{Model::Parser.supported_formats}" unless parser
|
38
|
+
|
39
|
+
parse(parser)
|
40
|
+
|
41
|
+
@vertices_count = @vertices.size
|
42
|
+
|
43
|
+
@has_texture = false
|
44
|
+
|
45
|
+
@materials.each do |_key, material|
|
46
|
+
@has_texture = true if material.texture_id
|
47
|
+
end
|
48
|
+
|
49
|
+
allocate_gl_objects
|
50
|
+
populate_vertex_buffer
|
51
|
+
configure_vao
|
52
|
+
|
53
|
+
@objects.each { |o| @vertex_count += o.vertices.size }
|
54
|
+
|
55
|
+
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_millisecond)
|
56
|
+
build_collision_tree
|
57
|
+
puts " Building mesh collision tree took #{((Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_millisecond) - start_time) / 1000.0).round(2)} seconds"
|
58
|
+
end
|
59
|
+
|
60
|
+
def parse(parser)
|
61
|
+
parser.new(self).parse
|
62
|
+
end
|
63
|
+
|
64
|
+
def calculate_bounding_box(vertices, bounding_box)
|
65
|
+
unless bounding_box.min.x.is_a?(Float)
|
66
|
+
vertex = vertices.last
|
67
|
+
bounding_box.min.x = vertex.x
|
68
|
+
bounding_box.min.y = vertex.y
|
69
|
+
bounding_box.min.z = vertex.z
|
70
|
+
|
71
|
+
bounding_box.max.x = vertex.x
|
72
|
+
bounding_box.max.y = vertex.y
|
73
|
+
bounding_box.max.z = vertex.z
|
74
|
+
end
|
75
|
+
|
76
|
+
vertices.each do |vertex|
|
77
|
+
bounding_box.min.x = vertex.x if vertex.x <= bounding_box.min.x
|
78
|
+
bounding_box.min.y = vertex.y if vertex.y <= bounding_box.min.y
|
79
|
+
bounding_box.min.z = vertex.z if vertex.z <= bounding_box.min.z
|
80
|
+
|
81
|
+
bounding_box.max.x = vertex.x if vertex.x >= bounding_box.max.x
|
82
|
+
bounding_box.max.y = vertex.y if vertex.y >= bounding_box.max.y
|
83
|
+
bounding_box.max.z = vertex.z if vertex.z >= bounding_box.max.z
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def allocate_gl_objects
|
88
|
+
# Allocate arrays for future use
|
89
|
+
@vertex_array_id = nil
|
90
|
+
buffer = " " * 4
|
91
|
+
glGenVertexArrays(1, buffer)
|
92
|
+
@vertex_array_id = buffer.unpack1("L2")
|
93
|
+
|
94
|
+
# Allocate buffers for future use
|
95
|
+
@positions_buffer_id = nil
|
96
|
+
buffer = " " * 4
|
97
|
+
glGenBuffers(1, buffer)
|
98
|
+
@positions_buffer_id = buffer.unpack1("L2")
|
99
|
+
|
100
|
+
@colors_buffer_id = nil
|
101
|
+
buffer = " " * 4
|
102
|
+
glGenBuffers(1, buffer)
|
103
|
+
@colors_buffer_id = buffer.unpack1("L2")
|
104
|
+
|
105
|
+
@normals_buffer_id = nil
|
106
|
+
buffer = " " * 4
|
107
|
+
glGenBuffers(1, buffer)
|
108
|
+
@normals_buffer_id = buffer.unpack1("L2")
|
109
|
+
|
110
|
+
@uvs_buffer_id = nil
|
111
|
+
buffer = " " * 4
|
112
|
+
glGenBuffers(1, buffer)
|
113
|
+
@uvs_buffer_id = buffer.unpack1("L2")
|
114
|
+
end
|
115
|
+
|
116
|
+
def populate_vertex_buffer
|
117
|
+
pos = []
|
118
|
+
colors = []
|
119
|
+
norms = []
|
120
|
+
uvs = []
|
121
|
+
|
122
|
+
@faces.each do |face|
|
123
|
+
pos << face.vertices.map { |vert| [vert.x, vert.y, vert.z] }
|
124
|
+
colors << face.colors.map { |color| [color.red, color.green, color.blue] }
|
125
|
+
norms << face.normals.map { |vert| [vert.x, vert.y, vert.z, vert.weight] }
|
126
|
+
|
127
|
+
uvs << face.uvs.map { |vert| [vert.x, vert.y, vert.z] } if has_texture?
|
128
|
+
end
|
129
|
+
|
130
|
+
glBindBuffer(GL_ARRAY_BUFFER, @positions_buffer_id)
|
131
|
+
glBufferData(GL_ARRAY_BUFFER, pos.flatten.size * Fiddle::SIZEOF_FLOAT, pos.flatten.pack("f*"), GL_STATIC_DRAW)
|
132
|
+
|
133
|
+
glBindBuffer(GL_ARRAY_BUFFER, @colors_buffer_id)
|
134
|
+
glBufferData(GL_ARRAY_BUFFER, colors.flatten.size * Fiddle::SIZEOF_FLOAT, colors.flatten.pack("f*"),
|
135
|
+
GL_STATIC_DRAW)
|
136
|
+
|
137
|
+
glBindBuffer(GL_ARRAY_BUFFER, @normals_buffer_id)
|
138
|
+
glBufferData(GL_ARRAY_BUFFER, norms.flatten.size * Fiddle::SIZEOF_FLOAT, norms.flatten.pack("f*"), GL_STATIC_DRAW)
|
139
|
+
|
140
|
+
if has_texture?
|
141
|
+
glBindBuffer(GL_ARRAY_BUFFER, @uvs_buffer_id)
|
142
|
+
glBufferData(GL_ARRAY_BUFFER, uvs.flatten.size * Fiddle::SIZEOF_FLOAT, uvs.flatten.pack("f*"), GL_STATIC_DRAW)
|
143
|
+
end
|
144
|
+
|
145
|
+
glBindBuffer(GL_ARRAY_BUFFER, 0)
|
146
|
+
end
|
147
|
+
|
148
|
+
def configure_vao
|
149
|
+
glBindVertexArray(@vertex_array_id)
|
150
|
+
gl_error?
|
151
|
+
|
152
|
+
# index, size, type, normalized, stride, pointer
|
153
|
+
# vertices (positions)
|
154
|
+
glBindBuffer(GL_ARRAY_BUFFER, @positions_buffer_id)
|
155
|
+
gl_error?
|
156
|
+
|
157
|
+
# in_position
|
158
|
+
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, nil)
|
159
|
+
gl_error?
|
160
|
+
# colors
|
161
|
+
glBindBuffer(GL_ARRAY_BUFFER, @colors_buffer_id)
|
162
|
+
# in_color
|
163
|
+
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, nil)
|
164
|
+
gl_error?
|
165
|
+
# normals
|
166
|
+
glBindBuffer(GL_ARRAY_BUFFER, @normals_buffer_id)
|
167
|
+
# in_normal
|
168
|
+
glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, 0, nil)
|
169
|
+
gl_error?
|
170
|
+
|
171
|
+
if has_texture?
|
172
|
+
# uvs
|
173
|
+
glBindBuffer(GL_ARRAY_BUFFER, @uvs_buffer_id)
|
174
|
+
# in_uv
|
175
|
+
glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, 0, nil)
|
176
|
+
gl_error?
|
177
|
+
end
|
178
|
+
|
179
|
+
glBindBuffer(GL_ARRAY_BUFFER, 0)
|
180
|
+
glBindVertexArray(0)
|
181
|
+
end
|
182
|
+
|
183
|
+
def build_collision_tree
|
184
|
+
@aabb_tree = AABBTree.new
|
185
|
+
|
186
|
+
@faces.each do |face|
|
187
|
+
box = BoundingBox.new
|
188
|
+
box.min = face.vertices.first.dup
|
189
|
+
box.max = face.vertices.first.dup
|
190
|
+
|
191
|
+
face.vertices.each do |vertex|
|
192
|
+
if vertex.sum < box.min.sum
|
193
|
+
box.min = vertex.dup
|
194
|
+
elsif vertex.sum > box.max.sum
|
195
|
+
box.max = vertex.dup
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
# FIXME: Handle negatives
|
200
|
+
box.min *= 1.5
|
201
|
+
box.max *= 1.5
|
202
|
+
@aabb_tree.insert(face, box)
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
def has_texture?
|
207
|
+
@has_texture
|
208
|
+
end
|
209
|
+
|
210
|
+
def release_gl_resources
|
211
|
+
if @vertex_array_id
|
212
|
+
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
@@ -1,31 +1,31 @@
|
|
1
|
-
module CyberarmEngine
|
2
|
-
module ModelCache
|
3
|
-
CACHE = {}
|
4
|
-
|
5
|
-
def self.find_or_cache(manifest:)
|
6
|
-
model_file = manifest.file_path + "/model/#{manifest.model}"
|
7
|
-
|
8
|
-
type = File.basename(model_file).split(".").last.to_sym
|
9
|
-
|
10
|
-
if model = load_model_from_cache(type, model_file)
|
11
|
-
model
|
12
|
-
else
|
13
|
-
model = CyberarmEngine::Model.new(file_path: model_file)
|
14
|
-
cache_model(type, model_file, model)
|
15
|
-
|
16
|
-
model
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.load_model_from_cache(type, model_file)
|
21
|
-
return CACHE[type][model_file] if CACHE[type].is_a?(Hash) && (CACHE[type][model_file])
|
22
|
-
|
23
|
-
false
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.cache_model(type, model_file, model)
|
27
|
-
CACHE[type] = {} unless CACHE[type].is_a?(Hash)
|
28
|
-
CACHE[type][model_file] = model
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
1
|
+
module CyberarmEngine
|
2
|
+
module ModelCache
|
3
|
+
CACHE = {}
|
4
|
+
|
5
|
+
def self.find_or_cache(manifest:)
|
6
|
+
model_file = manifest.file_path + "/model/#{manifest.model}"
|
7
|
+
|
8
|
+
type = File.basename(model_file).split(".").last.to_sym
|
9
|
+
|
10
|
+
if model = load_model_from_cache(type, model_file)
|
11
|
+
model
|
12
|
+
else
|
13
|
+
model = CyberarmEngine::Model.new(file_path: model_file)
|
14
|
+
cache_model(type, model_file, model)
|
15
|
+
|
16
|
+
model
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.load_model_from_cache(type, model_file)
|
21
|
+
return CACHE[type][model_file] if CACHE[type].is_a?(Hash) && (CACHE[type][model_file])
|
22
|
+
|
23
|
+
false
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.cache_model(type, model_file, model)
|
27
|
+
CACHE[type] = {} unless CACHE[type].is_a?(Hash)
|
28
|
+
CACHE[type][model_file] = model
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -1,83 +1,83 @@
|
|
1
|
-
module CyberarmEngine
|
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
|
1
|
+
module CyberarmEngine
|
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
83
|
end
|