From bdbcec57f7d83187b9f31adb41182bf1068e4267 Mon Sep 17 00:00:00 2001 From: Julius Krumbiegel Date: Sat, 28 Mar 2020 13:41:12 +0100 Subject: [PATCH 1/4] fix projection (for subscenes as well) --- src/utils.jl | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/utils.jl b/src/utils.jl index 3ba7118..2864c8e 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -1,15 +1,31 @@ +topparent(x::Scene) = isnothing(x.parent) ? x : topparent(x.parent) + function project_position(scene, point, model) p4d = to_ndim(Vec4f0, to_ndim(Vec3f0, point, 0f0), 1f0) + clip = scene.camera.projectionview[] * model * p4d - p = (clip / clip[4])[Vec(1, 2)] - p = collect((p .+ 1) ./ 2) - w, h = scene.camera.resolution[] + + # p_m1_p1 is in scene-relative -1 to 1 space + p_m1_p1 = (clip / clip[4])[Vec(1, 2)] + + # p_0_1 is in scene-relative 0 to 1 space + p_0_1 = collect((p_m1_p1 .+ 1) ./ 2) + + subarea = scene.px_area[] + rootarea = topparent(scene).px_area[] + + p_subscene = p_0_1 .* subarea.widths .+ subarea.origin + + @assert rootarea.origin == Point2f0(0, 0) + p_0_1_root = p_subscene ./ rootarea.widths + + w, h = rootarea.widths if w > h - p[2:2:end] .*= (h / w) + p_0_1_root[2:2:end] .*= (h / w) else - p[1:2:end] .*= (w / h) + p_0_1_root[1:2:end] .*= (w / h) end - return Vec2f0(p) + return Vec2f0(p_0_1_root) end project_scale(scene::Scene, s::Number) = project_scale(scene, Vec2f0(s)) From 89acca13d91d7e394d5ea809e4112830b5bb3fd8 Mon Sep 17 00:00:00 2001 From: Julius Krumbiegel Date: Sat, 28 Mar 2020 13:41:36 +0100 Subject: [PATCH 2/4] comment out crashing line --- src/primitives.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/primitives.jl b/src/primitives.jl index cd682c7..b62da5d 100644 --- a/src/primitives.jl +++ b/src/primitives.jl @@ -223,7 +223,7 @@ end Plots a 3D mesh. """ function draw(scene::Scene, plot::Mesh) - @get_attribute(plot, (interpolate,shading,colormap,colorrange)) + # @get_attribute(plot, (interpolate,shading,colormap,colorrange)) end From e9323bb72914152bca20eec7f08344d2d1f5ceed Mon Sep 17 00:00:00 2001 From: Julius Krumbiegel Date: Sat, 28 Mar 2020 13:42:02 +0100 Subject: [PATCH 3/4] fix visibility issues with non-combined plots --- src/primitives.jl | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/primitives.jl b/src/primitives.jl index b62da5d..6367e57 100644 --- a/src/primitives.jl +++ b/src/primitives.jl @@ -258,11 +258,21 @@ function gr_draw(scene::Scene) end # The main method - this draws all plots and child scenes function draw(scene::Scene) - foreach(plot-> draw(scene, plot), scene.plots) - foreach(child-> draw(child), scene.children) + for plot in scene.plots + if plot.visible[] + draw(scene, plot) + end + end + for child in scene.children + draw(child) + end end # The lower level method. This dispatches on primitives, meaning that # we have some guarantees about their attributes. function draw(scene::Scene, primitive::AbstractPlotting.Combined) - foreach(x-> draw(scene, x), filter(x -> x.visible[], primitive.plots)) + for p in primitive.plots + if p.visible[] + draw(scene, p) + end + end end From 41fd246204df6ade1bb4f47a652da8b31c5dfbc8 Mon Sep 17 00:00:00 2001 From: Julius Krumbiegel Date: Sat, 28 Mar 2020 13:42:54 +0100 Subject: [PATCH 4/4] hack text layouting into text display method for standard Text needs my AbstractPlotting layout_text rework --- src/primitives.jl | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/primitives.jl b/src/primitives.jl index 6367e57..7089b5f 100644 --- a/src/primitives.jl +++ b/src/primitives.jl @@ -76,13 +76,35 @@ function draw(scene::Scene, plot::AbstractPlotting.Text) @get_attribute(plot, (textsize, color, font, align, rotation, model)) txt = to_value(plot[1]) position = plot.attributes[:position][] + + # hack layouting into the process here + if position isa Point + position, _ = AbstractPlotting.layout_text( + txt, position, textsize, + font, align, rotation, model + ) + end + + # hardcode this against abstractplotting madness + # all textsizes in the vector are different, one for each glyph, which + # has to do with the texture atlas + # 20 is just the default makielayout fontsize + textsize = 20f0 + + plotwindow_width = topparent(scene).px_area[].widths[1] + N = length(txt) broadcast_foreach(1:N, position, textsize, color, font, rotation) do i, p, ts, cc, f, r pos = project_position(scene, p, model) chup = r * Vec2f0(0, 1) GR.setcharup(chup[1], chup[2]) - GR.settextfontprec(233, 3) - GR.setcharheight(0.018) # ts ??? + + # helvetica in string mode seems to work relatively well for some reason + GR.settextfontprec(105, 0) + # GR.setcharheight(0.018) # ts ??? + + # convert textsize to plotwindow_width percentage + GR.setcharheight(textsize / plotwindow_width * 0.666) # why 2/3ds? window size seems always too large GR.settextcolorind(Int(GR.inqcolorfromrgb(cc.r, cc.g, cc.b))) GR.settransparency(cc.alpha) GR.settextalign(1, 4)