diff --git a/CHANGELOG.md b/CHANGELOG.md index ae47a6e15..fc590ff7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,14 @@ # Javis.jl - Changelog +## Unreleased +- bugfix in `@JLayer` when dimensions are not defined explicitly + ## v0.6.1 (7th of August 2021) - Add shorthands for basic shapes - New functions `JBox, JCircle, JEllipse, JLine, JPoly, JRect, JStar, @JShape` - added support for `rescale_factor` keyword in `render` function - Docstring improvements to `translate` - ## v0.6.0 (3rd of August 2021) - Added layers see `@JLayer` diff --git a/src/Javis.jl b/src/Javis.jl index 41e0c3414..12e1f1a52 100644 --- a/src/Javis.jl +++ b/src/Javis.jl @@ -133,6 +133,14 @@ function centered_point(pos::Point, width::Int, height::Int) Point(pos.x - width / 2, pos.y - height / 2) end +""" + preprocess_frames!(video::Video) + +""" +function preprocess_frames!(video::Video) + return preprocess_frames!([video.objects..., flatten(video.layers)...]) +end + """ preprocess_frames!(objects::Vector{<:AbstractObject}) @@ -241,13 +249,8 @@ function render( rescale_factor = 1.0, ) layers = video.layers - layer_flat = flatten(layers) objects = video.objects - if isempty(layers) - frames = preprocess_frames!(objects) - else - frames = preprocess_frames!([objects..., layer_flat...]) - end + frames = preprocess_frames!(video) if liveview if isdefined(Main, :IJulia) && Main.IJulia.inited diff --git a/src/layers.jl b/src/layers.jl index c459cd518..b76cf8095 100644 --- a/src/layers.jl +++ b/src/layers.jl @@ -107,8 +107,8 @@ Returns an expression that creates a layer and pushes the objects defined within function to_layer_m( frames, body; - width = CURRENT_VIDEO[1].width, - height = CURRENT_VIDEO[1].height, + width = nothing, # will be set to CURRENT_VIDEO[1].width inside Javis.Layer + height = nothing, position = Point(0, 0), transparent = QuoteNode(:transparent), ) diff --git a/src/structs/Layer.jl b/src/structs/Layer.jl index 8f143255c..116a41d61 100644 --- a/src/structs/Layer.jl +++ b/src/structs/Layer.jl @@ -38,8 +38,8 @@ const CURRENT_LAYER = Array{Layer,1}() # for width, height and position defaults are defined in the to_layer_m function function Layer( frames, - width::Int, - height::Int, + width, + height, position::Point; layer_objects::Vector{AbstractObject} = AbstractObject[], actions::Vector{AbstractAction} = AbstractAction[], @@ -48,6 +48,13 @@ function Layer( mat = nothing, layer_cache::LayerCache = LayerCache(), ) + if width === nothing + width = CURRENT_VIDEO[1].width + end + if height === nothing + height = CURRENT_VIDEO[1].height + end + layer = Layer( frames, width, diff --git a/test/layers.jl b/test/layers.jl index 2fe333b58..b11a0fe83 100644 --- a/test/layers.jl +++ b/test/layers.jl @@ -1,14 +1,9 @@ -vid = Video(600, 600) -video = Video(600, 600) - @testset "Layers Feature" begin function ground(args...) background("white") sethue("black") end - Background(1:80, ground) - function object_layer(p = O, color = "black") @JShape begin sethue(color) @@ -28,6 +23,9 @@ video = Video(600, 600) line(p1, p2, :stroke) end + video = Video(600, 600) + Background(1:80, ground) + path_of_red = Point[] path_of_blue = Point[] @@ -102,33 +100,31 @@ video = Video(600, 600) pob = Object(5:41, (args...) -> path!(path_of_blue, pos(ball2), "blue")) layer_objects = [ball1, ball2, conn, por, pob] - @testset "Layer macro" begin - @test l1.frames.frames == l2.frames.frames == l3.frames.frames - @test l1.width == l2.width == l3.width == 600 - @test l1.height == l2.height == l3.height == 600 - @test l1.position == l2.position == l3.position == Point(0, 0) - @test length(l1.layer_objects) == - length(l2.layer_objects) == - length(l3.layer_objects) == - length(layer_objects) + 2 - @test length(l1.actions) == - length(l2.actions) == - length(l3.actions) == - length(layer_actions) - @test l1.current_setting.opacity == - l2.current_setting.opacity == - l3.current_setting.opacity == - 1.0 - @test l1.current_setting.scale == - l2.current_setting.scale == - l3.current_setting.scale == - Javis.Scale(1.0, 1.0) - @test l1.current_setting.rotation_angle == - l2.current_setting.rotation_angle == - l3.current_setting.rotation_angle == - 0.0 - @test l1.image_matrix == l2.image_matrix == l3.image_matrix == nothing - end + @test l1.frames.frames == l2.frames.frames == l3.frames.frames + @test l1.width == l2.width == l3.width == 600 + @test l1.height == l2.height == l3.height == 600 + @test l1.position == l2.position == l3.position == Point(0, 0) + @test length(l1.layer_objects) == + length(l2.layer_objects) == + length(l3.layer_objects) == + length(layer_objects) + 2 + @test length(l1.actions) == + length(l2.actions) == + length(l3.actions) == + length(layer_actions) + @test l1.current_setting.opacity == + l2.current_setting.opacity == + l3.current_setting.opacity == + 1.0 + @test l1.current_setting.scale == + l2.current_setting.scale == + l3.current_setting.scale == + Javis.Scale(1.0, 1.0) + @test l1.current_setting.rotation_angle == + l2.current_setting.rotation_angle == + l3.current_setting.rotation_angle == + 0.0 + @test l1.image_matrix == l2.image_matrix == l3.image_matrix == nothing # remove duplicate layers after above testing video.layers = [l1] @@ -177,7 +173,7 @@ video = Video(600, 600) rm("layer_test.gif") - Javis.CURRENT_VIDEO[1] = vid + vid = Video(600, 600) Background(1:20, ground) # test @JLayer multiple dispatch @@ -216,6 +212,6 @@ video = Video(600, 600) act!(l5, Action(opacity_anim, setopacity())) + Javis.preprocess_frames!([vid.objects..., Javis.flatten(vid.layers)...]) @test_throws ErrorException Javis.get_layer_frame(vid, l5, 6) - end