From 61397c4811139bf715d7a4127decf0d1395a1ff1 Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Thu, 14 Jun 2018 10:55:06 -0500 Subject: [PATCH 1/2] Perform unit conversions manually from cairomatrix --- src/graphics_interaction.jl | 19 +++++++++++++++++-- test/runtests.jl | 4 ++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/graphics_interaction.jl b/src/graphics_interaction.jl index d415b7d..0192d91 100644 --- a/src/graphics_interaction.jl +++ b/src/graphics_interaction.jl @@ -12,6 +12,8 @@ Base.:>{U<:CairoUnit}(x::U, y::U) = Bool(x.val > y.val) Base.abs{U<:CairoUnit}(x::U) = U(abs(x.val)) Base.min{U<:CairoUnit}(x::U, y::U) = U(min(x.val, y.val)) Base.max{U<:CairoUnit}(x::U, y::U) = U(max(x.val, y.val)) +Base.isapprox(x::U, y::U; kwargs...) where U<:CairoUnit = + isapprox(x.val, y.val; kwargs...) # Most of these are for ambiguity resolution Base.convert{T<:CairoUnit}(::Type{T}, x::T) = x Base.convert(::Type{Bool}, x::CairoUnit) = convert(Bool, x.val) @@ -57,7 +59,15 @@ Base.promote_rule{U<:UserUnit,D<:DeviceUnit}(::Type{U}, ::Type{D}) = error("UserUnit and DeviceUnit are incompatible, promotion not defined") function convertunits(::Type{UserUnit}, c, x::DeviceUnit, y::DeviceUnit) - xu, yu = device_to_user(getgc(c), x.val, y.val) + # For some unknown reason, the following doesn't seem to work + # over a remote X connection: + # xu, yu = device_to_user(getgc(c), x.val, y.val) + # So just do the inversion directly (see https://www.cairographics.org/manual/cairo-cairo-matrix-t.html#cairo-matrix-t) + m = Cairo.get_matrix(getgc(c)) + Δx, Δy = x.val - m.x0, y.val - m.y0 + det = m.xx * m.yy - m.yx * m.xy # manually do inverse of 2x2 matrix + xu, yu = (m.yy * Δx - m.xy * Δy)/det, (-m.yx * Δx + m.xx * Δy)/det + UserUnit(xu), UserUnit(yu) end function convertunits(::Type{UserUnit}, c, x::UserUnit, y::UserUnit) @@ -67,7 +77,12 @@ function convertunits(::Type{DeviceUnit}, c, x::DeviceUnit, y::DeviceUnit) x, y end function convertunits(::Type{DeviceUnit}, c, x::UserUnit, y::UserUnit) - xd, yd = user_to_device(getgc(c), x.val, y.val) + # See above + # xd, yd = user_to_device(getgc(c), x.val, y.val) + m = Cairo.get_matrix(getgc(c)) + xd = m.xx * x.val + m.xy * y.val + m.x0 + yd = m.yx * x.val + m.yy * y.val + m.y0 + DeviceUnit(xd), DeviceUnit(yd) end diff --git a/test/runtests.jl b/test/runtests.jl index 4a575f3..c3395b5 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -242,7 +242,7 @@ include("tools.jl") @test value(pb) == 5 pb = progressbar(2:8) @test value(pb) == 2 - + end ## button @@ -348,7 +348,7 @@ end (ZoomRegion((5:10, 3:5)), (UserUnit(5), UserUnit(10))), ((-1:1, 101:110), (UserUnit(110), UserUnit(1)))) set_coordinates(c, coords) - @test GtkReactive.convertunits(UserUnit, c, corner_dev...) == corner_usr + @test all(GtkReactive.convertunits(UserUnit, c, corner_dev...) .≈ corner_usr) @test GtkReactive.convertunits(DeviceUnit, c, corner_dev...) == corner_dev @test GtkReactive.convertunits(UserUnit, c, corner_usr...) == corner_usr @test GtkReactive.convertunits(DeviceUnit, c, corner_usr...) == corner_dev From 038e5632f27448b16028f3e91ac011f22eec3e50 Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Thu, 14 Jun 2018 12:38:51 -0500 Subject: [PATCH 2/2] Fix for Reactive v0.7.0 --- test/runtests.jl | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index c3395b5..9f777ae 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -2,9 +2,13 @@ using GtkReactive, Gtk.ShortNames, IntervalSets, Graphics, Colors, TestImages, FileIO, FixedPointNumbers, RoundingIntegers using Base.Test -if !istaskdone(Reactive.runner_task) +rtask = Reactive.runner_task # starting with Reactive 0.7.0, this became a Ref +if isa(rtask, Base.RefValue) + rtask = rtask[] +end +if !istaskdone(rtask) Reactive.stop() - wait(Reactive.runner_task) + wait(rtask) end include("tools.jl")