Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Beta 0.20 #2831

Closed
wants to merge 106 commits into from
Closed
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
106 commits
Select commit Hold shift + click to select a range
a5cd052
Do not plot faces with NaN points in meshes
asinghvi17 Jan 15, 2023
079c553
Update NEWS.md
asinghvi17 Jan 15, 2023
d817155
Skip NaN faces in the other mesh methods also
asinghvi17 Jan 16, 2023
ce2a22b
Add NaN-aware normal calculation code
asinghvi17 Jan 16, 2023
5440a23
Apply nan code only to surfaces, not meshes
asinghvi17 Jan 16, 2023
dd60f10
Add a test
asinghvi17 Jan 16, 2023
5978840
Fix typo
asinghvi17 Jan 16, 2023
9b14ec3
Move functionality from CairoMakie to Makie
asinghvi17 Jan 16, 2023
c6725f6
Finally fix tests
asinghvi17 Jan 16, 2023
3313da0
Complete the switch to Makie
asinghvi17 Jan 16, 2023
fd93548
simplify orthogonal_vector and avoid triangles in surface
ffreyer Jan 17, 2023
9402fce
Add a better test
asinghvi17 Jan 19, 2023
4c2e4b4
fix test
ffreyer Jan 24, 2023
8fb0706
Merge branch 'master' into as/cairomakie_surface_nan
asinghvi17 Jan 27, 2023
d6452c9
Merge branch 'master' into as/cairomakie_surface_nan
SimonDanisch Jan 27, 2023
db0e400
fix NaN value rendering in GLMakie
ffreyer Jan 28, 2023
2af2845
fix WGLMakie surfaces
ffreyer Jan 28, 2023
7ef034c
fix the wrong uv instead
ffreyer Jan 29, 2023
8e00d10
simplify test
ffreyer Jan 29, 2023
aa551be
Merge branch 'master' into as/cairomakie_surface_nan
ffreyer Jan 29, 2023
8e79b41
use texelFetch for normal calc
ffreyer Jan 29, 2023
066f0b7
switch back to translation zoom, cleanup/reorganize
ffreyer Mar 12, 2023
e4b056a
fix typo
ffreyer Mar 12, 2023
6cbca9e
add example
ffreyer Mar 12, 2023
b54c0ae
remove enable translation/rotation/zoom
ffreyer Mar 12, 2023
3e07289
update test values
ffreyer Mar 12, 2023
11313dc
cleanup docstring
ffreyer Mar 12, 2023
4de5fa3
switch back rotation order to avoid change in upvector
ffreyer Mar 12, 2023
ae7f89a
fix docstring [skip ci]
ffreyer Mar 12, 2023
d31d905
update docs
ffreyer Mar 12, 2023
8185a96
update tests
ffreyer Mar 13, 2023
d82fb0e
Merge branch 'master' into as/cairomakie_surface_nan
ffreyer Mar 14, 2023
7682d0b
Merge branch 'master' into as/cairomakie_surface_nan
asinghvi17 Mar 15, 2023
3c22c47
fix zoom and switch back to more extreme near/far
ffreyer Mar 15, 2023
6786f96
tweak default zoom some more
ffreyer Mar 15, 2023
5274295
Add update_cam! with angles
ffreyer Mar 16, 2023
4fee98b
Merge branch 'master' into ff/camera
ffreyer Mar 19, 2023
c890d34
update NEWS
ffreyer Mar 19, 2023
d6639fc
bring back perspective zoom_shift_lookat
ffreyer Mar 19, 2023
becc8cd
add center in orbital update_cam!
ffreyer Mar 19, 2023
f264360
bring back fov controls
ffreyer Mar 19, 2023
87e7254
deprecate old_cam [skip ci]
ffreyer Mar 19, 2023
6594406
fix whitespace?
ffreyer Mar 28, 2023
ed48aa6
Merge branch 'master' into ff/camera
ffreyer Mar 28, 2023
43e6428
cleanup news
ffreyer Mar 28, 2023
598ad24
Merge branch 'master' into as/cairomakie_surface_nan
asinghvi17 Mar 29, 2023
4e44a6b
Merge branch 'master' into as/cairomakie_surface_nan
SimonDanisch Mar 29, 2023
4f52baf
squash merge jw/gl_linux_hidpi
jkrumbiegel Mar 31, 2023
2b33093
squash merge jk/html-png-display
jkrumbiegel Mar 31, 2023
e146732
Merge branch 'master' into beta-0.20
jkrumbiegel Mar 31, 2023
dfc0cf3
Merge branch 'master' into beta-0.20
jkrumbiegel Mar 31, 2023
918a5c9
new figure size and related theming adjustments
jkrumbiegel Mar 31, 2023
2807baf
move html backend show out of cairomakie
jkrumbiegel Mar 31, 2023
74d8ed8
move WEB_MIMES constant from WGLMakie into Makie
jkrumbiegel Mar 31, 2023
effdd00
use strings again
jkrumbiegel Mar 31, 2023
4195e29
fix test
jkrumbiegel Mar 31, 2023
ef3859e
smaller colorbar ticks
jkrumbiegel Mar 31, 2023
625bf06
adjust more theming gaps
jkrumbiegel Apr 1, 2023
f9edbe3
padding adjust
jkrumbiegel Apr 1, 2023
37a5eb1
fix size of docs example
jkrumbiegel Apr 1, 2023
b9daec8
make toggle smaller
jkrumbiegel Apr 1, 2023
a25dfcc
make colorbar thinner
jkrumbiegel Apr 1, 2023
f2897c7
smaller colorbar
jkrumbiegel Apr 1, 2023
232af7c
adjust legend doc example
jkrumbiegel Apr 2, 2023
91055d8
fix intervalslider and example
jkrumbiegel Apr 2, 2023
b33c222
more docs fixes, axis legend padding
jkrumbiegel Apr 2, 2023
79fad8a
improve faq example
jkrumbiegel Apr 2, 2023
093af51
fix test value
jkrumbiegel Apr 5, 2023
0aa4b02
bump all versions
jkrumbiegel Apr 5, 2023
1e7eb98
Merge branch 'master' into beta-0.20
jkrumbiegel Apr 5, 2023
338441e
Merge branch 'master' into as/cairomakie_surface_nan
SimonDanisch Apr 5, 2023
2e64e8b
fix wglmakie
SimonDanisch Apr 5, 2023
3f8fe43
stringify web mimes for set
jkrumbiegel Apr 8, 2023
a72abbd
Merge branch 'master' into ff/camera
SimonDanisch Apr 19, 2023
78ee1e5
improve default controls/hotkeys
ffreyer Apr 19, 2023
a7e819b
add on-click refocus of camera
ffreyer Apr 21, 2023
d51ed11
DataInspector fixes
ffreyer Apr 23, 2023
fdc3666
fix wrong tooltip in volumeslices
ffreyer Apr 23, 2023
6945b97
fix line indicator in band
ffreyer Apr 23, 2023
1053b3a
update NEWS
ffreyer Apr 23, 2023
10aff36
update docs
ffreyer Apr 23, 2023
6972303
Merge branch 'master' into ff/camera
SimonDanisch Apr 25, 2023
64f7730
consider transforms when centering on plot object
ffreyer May 5, 2023
fd9a04d
Merge branch 'master' into ff/camera
ffreyer Jun 12, 2023
fc4fcd5
fix type error in cam2d!
ffreyer Jun 12, 2023
a26e6a1
check other ray_at_cursor methods
ffreyer Jun 12, 2023
381eb82
Merge branch 'master' into ff/camera
ffreyer Jun 22, 2023
2b32ed8
merge master
SimonDanisch Jun 29, 2023
ac64b9d
Update Project.toml
SimonDanisch Jul 3, 2023
d89aac0
Merge branch 'master' into ff/camera
ffreyer Jul 4, 2023
001542e
avoid centering on unrelated plots
ffreyer Jul 4, 2023
34e9072
Merge branch 'master' into ff/camera
ffreyer Jul 4, 2023
98c1096
fix test errors
ffreyer Jul 4, 2023
2a0da7e
Merge branch 'master' into as/cairomakie_surface_nan
ffreyer Jul 11, 2023
ae7e21d
Merge branch 'master' into beta-0.20
ffreyer Jul 12, 2023
9b7ed17
fix Makie version
ffreyer Jul 12, 2023
9c7f253
fix ubuntu test error
ffreyer Jul 12, 2023
558e682
Merge branch 'as/cairomakie_surface_nan' into beta-0.20
ffreyer Jul 12, 2023
e804e21
remove yield
ffreyer Jul 12, 2023
ea78111
try colorbuffer() to fix test error
ffreyer Jul 12, 2023
9d34002
try fixing line AA scaling
ffreyer Jul 12, 2023
01b1589
Merge branch 'master' into ff/camera
ffreyer Jul 12, 2023
173b645
Merge branch 'ff/camera' into beta-0.20
ffreyer Jul 12, 2023
3f924d5
Merge branch 'master' into beta-0.20 & fix NEWS
ffreyer Jul 13, 2023
f0579ac
Merge branch 'master' into beta-0.20
SimonDanisch Jul 31, 2023
cd71e69
fix incorrect merge
SimonDanisch Jul 31, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/glmakie.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: julia-actions/cache@v1
- run: sudo apt-get update && sudo apt-get install -y xorg-dev mesa-utils xvfb libgl1 freeglut3-dev libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev libxext-dev
- run: sudo apt-get update && sudo apt-get install -y xorg-dev mesa-utils xvfb libgl1 freeglut3-dev libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev libxext-dev xsettingsd x11-xserver-utils
- name: Install Julia dependencies
shell: julia --project=monorepo {0}
run: |
Expand Down
5 changes: 3 additions & 2 deletions CairoMakie/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "CairoMakie"
uuid = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
author = ["Simon Danisch <sdanisch@gmail.com>"]
version = "0.10.6"
version = "0.11.0"

[deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
Expand All @@ -23,7 +23,7 @@ FFTW = "1"
FileIO = "1.1"
FreeType = "3, 4.0"
GeometryBasics = "0.4.1"
Makie = "=0.19.6"
Makie = "=0.20.0"
PrecompileTools = "1.0"
julia = "1.3"

Expand All @@ -33,3 +33,4 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test", "Pkg"]

1 change: 1 addition & 0 deletions CairoMakie/src/display.jl
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ end

const DISABLED_MIMES = Set{String}()
const SUPPORTED_MIMES = Set([
map(x->string(x()), Makie.WEB_MIMES)...,
"image/svg+xml",
"application/pdf",
"application/postscript",
Expand Down
17 changes: 10 additions & 7 deletions CairoMakie/src/screen.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Base.Docs: doc

@enum RenderType SVG IMAGE PDF EPS
@enum RenderType SVG IMAGE PDF EPS HTML

Base.convert(::Type{RenderType}, ::MIME{SYM}) where SYM = mime_to_rendertype(SYM)
function Base.convert(::Type{RenderType}, type::String)
Expand All @@ -12,6 +12,8 @@ function Base.convert(::Type{RenderType}, type::String)
return PDF
elseif type == "eps"
return EPS
elseif type in ("html", "text/html", "application/vnd.webio.application+html", "application/prs.juno.plotpane+html", "juliavscode/html")
return HTML
else
error("Unsupported cairo render type: $type")
end
Expand All @@ -22,6 +24,7 @@ function to_mime(type::RenderType)
type == SVG && return MIME("image/svg+xml")
type == PDF && return MIME("application/pdf")
type == EPS && return MIME("application/postscript")
type == HTML && return MIME("text/html")
return MIME("image/png")
end

Expand All @@ -35,6 +38,8 @@ function mime_to_rendertype(mime::Symbol)::RenderType
return PDF
elseif mime == Symbol("application/postscript")
return EPS
elseif mime in (Symbol("text/html"), Symbol("text/html"), Symbol("application/vnd.webio.application+html"), Symbol("application/prs.juno.plotpane+html"), Symbol("juliavscode/html"))
return HTML
else
error("Unsupported mime: $mime")
end
Expand All @@ -55,7 +60,7 @@ function surface_from_output_type(type::RenderType, io, w, h)
return Cairo.CairoPDFSurface(io, w, h)
elseif type === EPS
return Cairo.CairoEPSSurface(io, w, h)
elseif type === IMAGE
elseif type === IMAGE || type === HTML
img = fill(ARGB32(0, 0, 0, 0), w, h)
return Cairo.CairoImageSurface(img)
else
Expand All @@ -76,8 +81,8 @@ end
to_cairo_antialias(aa::Int) = aa

"""
* `px_per_unit = 1.0`: see [figure size docs](https://docs.makie.org/stable/documentation/figure_size/).
* `pt_per_unit = 0.75`: see [figure size docs](https://docs.makie.org/stable/documentation/figure_size/).
* `px_per_unit = 2.0`: see [figure docs](https://docs.makie.org/stable/documentation/figure_size/).
* `pt_per_unit = 0.75`: see [figure docs](https://docs.makie.org/stable/documentation/figure_size/).
* `antialias::Union{Symbol, Int} = :best`: antialias modus Cairo uses to draw. Applicable options: `[:best => Cairo.ANTIALIAS_BEST, :good => Cairo.ANTIALIAS_GOOD, :subpixel => Cairo.ANTIALIAS_SUBPIXEL, :none => Cairo.ANTIALIAS_NONE]`.
* `visible::Bool`: if true, a browser/image viewer will open to display rendered output.
"""
Expand Down Expand Up @@ -120,9 +125,7 @@ function activate!(; inline=LAST_INLINE[], type="png", screen_config...)
# So, if we want to prefer the png mime, we disable the mimes that are usually higher up in the stack.
disable_mime!("svg", "pdf")
elseif type == "svg"
# SVG is usually pretty high up the priority, so we can just enable all mimes
# If we implement html display for CairoMakie, we might need to disable that.
disable_mime!()
disable_mime!("text/html", "application/vnd.webio.application+html", "application/prs.juno.plotpane+html", "juliavscode/html")
else
enable_only_mime!(type)
end
Expand Down
4 changes: 2 additions & 2 deletions CairoMakie/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ include(joinpath(@__DIR__, "rasterization_tests.jl"))
fig = scatter(1:4, figure=(; resolution=(800, 800)))
save("test.pdf", fig)
save("test.png", fig)
@test size(load("test.png")) == (800, 800)
@test size(load("test.png")) == (1600, 1600)
rm("test.pdf")
rm("test.png")
end
Expand Down Expand Up @@ -193,7 +193,7 @@ excludes = Set([
functions = [:volume, :volume!, :uv_mesh]

@testset "refimages" begin
CairoMakie.activate!(type = "png")
CairoMakie.activate!(type = "png", px_per_unit = 1)
ReferenceTests.mark_broken_tests(excludes, functions=functions)
recorded_files, recording_dir = @include_reference_tests "refimages.jl"
missing_images, scores = ReferenceTests.record_comparison(recording_dir)
Expand Down
6 changes: 3 additions & 3 deletions GLMakie/Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "GLMakie"
uuid = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a"
version = "0.8.6"
version = "0.9.0"

[deps]
ColorTypes = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
Expand All @@ -27,9 +27,9 @@ Colors = "0.11, 0.12"
FileIO = "1.6"
FixedPointNumbers = "0.7, 0.8"
FreeTypeAbstraction = "0.10"
GLFW = "3"
GLFW = "3.3"
GeometryBasics = "0.4.1"
Makie = "=0.19.6"
Makie = "=0.20.0"
MeshIO = "0.4"
ModernGL = "1"
Observables = "0.5.1"
Expand Down
12 changes: 8 additions & 4 deletions GLMakie/assets/shader/distance_shape.frag
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ uniform float stroke_width;
uniform float glow_width;
uniform int shape; // shape is a uniform for now. Making them a in && using them for control flow is expected to kill performance
uniform vec2 resolution;
uniform float px_per_unit;
uniform bool transparent_picking;

flat in float f_viewport_from_u_scale;
Expand Down Expand Up @@ -130,7 +131,9 @@ void stroke(vec4 strokecolor, float signed_distance, float width, inout vec4 col

void glow(vec4 glowcolor, float signed_distance, float inside, inout vec4 color){
if (glow_width > 0.0){
float outside = (abs(signed_distance)-stroke_width)/glow_width;
float s_stroke_width = px_per_unit * stroke_width;
float s_glow_width = px_per_unit * glow_width;
float outside = (abs(signed_distance)-s_stroke_width)/s_glow_width;
float alpha = 1-outside;
color = mix(vec4(glowcolor.rgb, glowcolor.a*alpha), color, inside);
}
Expand Down Expand Up @@ -180,13 +183,14 @@ void main(){
// See notes in geometry shader where f_viewport_from_u_scale is computed.
signed_distance *= f_viewport_from_u_scale;

float inside_start = max(-stroke_width, 0.0);
float s_stroke_width = px_per_unit * stroke_width;
float inside_start = max(-s_stroke_width, 0.0);
float inside = aastep(inside_start, signed_distance);
vec4 final_color = f_bg_color;

fill(f_color, image, tex_uv, inside, final_color);
stroke(f_stroke_color, signed_distance, -stroke_width, final_color);
glow(f_glow_color, signed_distance, aastep(-stroke_width, signed_distance), final_color);
stroke(f_stroke_color, signed_distance, -s_stroke_width, final_color);
glow(f_glow_color, signed_distance, aastep(-s_stroke_width, signed_distance), final_color);
// TODO: In 3D, we should arguably discard fragments outside the sprite
// But note that this may interfere with object picking.
// if (final_color == f_bg_color)
Expand Down
3 changes: 2 additions & 1 deletion GLMakie/assets/shader/sprites.geom
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ uniform float stroke_width;
uniform float glow_width;
uniform int shape; // for RECTANGLE hack below
uniform vec2 resolution;
uniform float px_per_unit;
uniform float depth_shift;

in int g_primitive_index[];
Expand Down Expand Up @@ -140,7 +141,7 @@ void main(void)
0.0, 1.0/vclip.w, 0.0, 0.0,
0.0, 0.0, 1.0/vclip.w, 0.0,
-vclip.xyz/(vclip.w*vclip.w), 0.0);
mat2 dxyv_dxys = diagm(0.5*resolution) * mat2(d_ndc_d_clip*trans);
mat2 dxyv_dxys = diagm(0.5*px_per_unit*resolution) * mat2(d_ndc_d_clip*trans);
// Now, our buffer size is expressed in viewport pixels but we get back to
// the sprite coordinate system using the scale factor of the
// transformation (for isotropic transformations). For anisotropic
Expand Down
2 changes: 1 addition & 1 deletion GLMakie/src/display.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ function Base.display(screen::Screen, scene::Scene; connect=true)
return screen
end

Makie.backend_showable(::Type{Screen}, ::Union{MIME"image/jpeg", MIME"image/png"}) = true
Makie.backend_showable(::Type{Screen}, ::Union{MIME"image/jpeg", MIME"image/png", Makie.WEB_MIMES...}) = true
1 change: 1 addition & 0 deletions GLMakie/src/drawing_primitives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ function cached_robj!(robj_func, screen, scene, x::AbstractPlot)
gl_attributes[:ambient] = ambientlight.color
end
gl_attributes[:track_updates] = screen.config.render_on_demand
gl_attributes[:px_per_unit] = screen.px_per_unit

robj = robj_func(gl_attributes)

Expand Down
114 changes: 49 additions & 65 deletions GLMakie/src/events.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,50 +37,50 @@ function Makie.disconnect!(window::GLFW.Window, ::typeof(window_open))
GLFW.SetWindowCloseCallback(window, nothing)
end

function window_position(window::GLFW.Window)
xy = GLFW.GetWindowPos(window)
(xy.x, xy.y)
end
function Makie.window_area(scene::Scene, screen::Screen)
disconnect!(screen, window_area)

struct WindowAreaUpdater
window::GLFW.Window
dpi::Observable{Float64}
area::Observable{GeometryBasics.HyperRectangle{2, Int64}}
end
# TODO: Figure out which monitor the window is on and react to DPI changes
monitor = GLFW.GetPrimaryMonitor()
props = MonitorProperties(monitor)
scene.events.window_dpi[] = minimum(props.dpi)

function windowsizecb(window, width::Cint, height::Cint)
area = scene.events.window_area
sf = screen.scalefactor[]

function (x::WindowAreaUpdater)(::Nothing)
ShaderAbstractions.switch_context!(x.window)
rect = x.area[]
# TODO put back window position, but right now it makes more trouble than it helps#
# x, y = GLFW.GetWindowPos(window)
# if minimum(rect) != Vec(x, y)
# event[] = Recti(x, y, framebuffer_size(window))
# end
w, h = GLFW.GetFramebufferSize(x.window)
if Vec(w, h) != widths(rect)
monitor = GLFW.GetPrimaryMonitor()
props = MonitorProperties(monitor)
# dpi of a monitor should be the same in x y direction.
# if not, minimum seems to be a fair default
x.dpi[] = minimum(props.dpi)
x.area[] = Recti(minimum(rect), w, h)
ShaderAbstractions.switch_context!(window)
winscale = sf / (@static Sys.isapple() ? scale_factor(window) : 1)
winw, winh = round.(Int, (width, height) ./ winscale)
if Vec(winw, winh) != widths(area[])
area[] = Recti(minimum(area[]), winw, winh)
end
return
end
return
end
# TODO put back window position, but right now it makes more trouble than it helps
#function windowposcb(window, x::Cint, y::Cint)
# area = scene.events.window_area
# ShaderAbstractions.switch_context!(window)
# winscale = screen.scalefactor[] / (@static Sys.isapple() ? scale_factor(window) : 1)
# xs, ys = round.(Int, (x, y) ./ winscale)
# if Vec(xs, ys) != minimum(area[])
# area[] = Recti(xs, ys, widths(area[]))
# end
# return
#end

function Makie.window_area(scene::Scene, screen::Screen)
disconnect!(screen, window_area)

updater = WindowAreaUpdater(
to_native(screen), scene.events.window_dpi, scene.events.window_area
)
on(updater, screen.render_tick)
window = to_native(screen)
GLFW.SetWindowSizeCallback(window, (win, w, h) -> windowsizecb(win, w, h))
#GLFW.SetWindowPosCallback(window, (win, x, y) -> windowposcb(win, x, y))

windowsizecb(window, Cint.(window_size(window))...)
return
end

function Makie.disconnect!(screen::Screen, ::typeof(window_area))
filter!(p -> !isa(p[2], WindowAreaUpdater), screen.render_tick.listeners)
window = to_native(screen)
#GLFW.SetWindowPosCallback(window, nothing)
GLFW.SetWindowSizeCallback(window, nothing)
return
end
function Makie.disconnect!(::GLFW.Window, ::typeof(window_area))
Expand Down Expand Up @@ -168,44 +168,28 @@ function Makie.disconnect!(window::GLFW.Window, ::typeof(unicode_input))
GLFW.SetCharCallback(window, nothing)
end

# TODO memoise? Or to bug ridden for the small performance gain?
function retina_scaling_factor(w, fb)
(w[1] == 0 || w[2] == 0) && return (1.0, 1.0)
fb ./ w
end

# TODO both of these methods are slow!
# ~90µs, ~80µs
# This is too slow for events that may happen 100x per frame
function framebuffer_size(window::GLFW.Window)
wh = GLFW.GetFramebufferSize(window)
(wh.width, wh.height)
end
function window_size(window::GLFW.Window)
wh = GLFW.GetWindowSize(window)
(wh.width, wh.height)
end
function retina_scaling_factor(window::GLFW.Window)
w, fb = window_size(window), framebuffer_size(window)
retina_scaling_factor(w, fb)
end

function correct_mouse(window::GLFW.Window, w, h)
ws, fb = window_size(window), framebuffer_size(window)
s = retina_scaling_factor(ws, fb)
(w * s[1], fb[2] - (h * s[2]))
function correct_mouse(screen::Screen, w, h)
nw = to_native(screen)
sf = screen.scalefactor[] / (@static Sys.isapple() ? scale_factor(nw) : 1)
_, winh = window_size(nw)
@static if Sys.isapple()
return w, (winh / sf) - h
else
return w / sf, (winh - h) / sf
end
end

struct MousePositionUpdater
window::GLFW.Window
screen::Screen
mouseposition::Observable{Tuple{Float64, Float64}}
hasfocus::Observable{Bool}
end

function (p::MousePositionUpdater)(::Nothing)
!p.hasfocus[] && return
x, y = GLFW.GetCursorPos(p.window)
pos = correct_mouse(p.window, x, y)
nw = to_native(p.screen)
x, y = GLFW.GetCursorPos(nw)
pos = correct_mouse(p.screen, x, y)
if pos != p.mouseposition[]
@print_error p.mouseposition[] = pos
# notify!(e.mouseposition)
Expand All @@ -222,7 +206,7 @@ which is not in scene coordinates, with the upper left window corner being 0
function Makie.mouse_position(scene::Scene, screen::Screen)
disconnect!(screen, mouse_position)
updater = MousePositionUpdater(
to_native(screen), scene.events.mouseposition, scene.events.hasfocus
screen, scene.events.mouseposition, scene.events.hasfocus
)
on(updater, screen.render_tick)
return
Expand Down
Loading
Loading