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

Gtk4 port #53

Merged
merged 14 commits into from
Aug 18, 2023
Prev Previous commit
Next Next commit
don't open windows during precompilation
jwahlstrand committed Aug 4, 2023
commit 340dad945182ca43ff676fc987d5efacf32539c6
10 changes: 5 additions & 5 deletions src/graphics_interaction.jl
Original file line number Diff line number Diff line change
@@ -269,8 +269,8 @@ struct Canvas{U}
mouse::MouseHandler{U}
preserved::Vector{Any}

function Canvas{U}(w::Int=-1, h::Int=-1; own::Bool=true) where U
gtkcanvas = GtkCanvas(w, h)
function Canvas{U}(w::Int=-1, h::Int=-1; own::Bool=true, init_back=false) where U
gtkcanvas = GtkCanvas(w, h, init_back)
# Initialize handlers
mouse = MouseHandler{U}(gtkcanvas)
grab_focus(gtkcanvas)
@@ -280,7 +280,7 @@ struct Canvas{U}
canvas
end
end
Canvas{U}(w::Integer, h::Integer=-1; own::Bool=true) where U = Canvas{U}(Int(w)::Int, Int(h)::Int; own=own)
Canvas{U}(w::Integer, h::Integer=-1; own::Bool=true, init_back = false) where U = Canvas{U}(Int(w)::Int, Int(h)::Int; own=own, init_back=init_back)

Base.show(io::IO, canvas::Canvas{U}) where U = print(io, "GtkObservables.Canvas{$U}()")

@@ -292,8 +292,8 @@ width `w` and height `h`. `U` refers to the units for the canvas (for
both drawing and reporting mouse pointer positions), see
[`DeviceUnit`](@ref) and [`UserUnit`](@ref). See also [`GtkObservables.Canvas`](@ref).
"""
canvas(::Type{U}=DeviceUnit, w::Integer=-1, h::Integer=-1) where {U<:CairoUnit} = Canvas{U}(w, h)
canvas(w::Integer, h::Integer) = canvas(DeviceUnit, w, h)
canvas(::Type{U}=DeviceUnit, w::Integer=-1, h::Integer=-1; init_back=false) where {U<:CairoUnit} = Canvas{U}(w, h; init_back=init_back)
canvas(w::Integer, h::Integer; init_back=false) = canvas(DeviceUnit, w, h; init_back=init_back)

"""
draw(f, c::GtkObservables.Canvas, signals...)
12 changes: 3 additions & 9 deletions src/precompile.jl
Original file line number Diff line number Diff line change
@@ -106,13 +106,9 @@ using PrecompileTools
dtw=nothing

# canvas
win=GtkWindow()
try # if we don't have a display, this might fail?
for U in (UserUnit, DeviceUnit)
c = canvas(U, 100, 100)
win[] = widget(c)
show(win)
sleep(1.0) # allow canvas to be realized
c = canvas(U, 100, 100; init_back=true)
fill!(c, RGB(0, 0, 0))
fill!(c, RGBA(1, 1, 1, 1))
lastevent = Ref("nothing")
@@ -128,9 +124,7 @@ using PrecompileTools
stroke(ctx)
end
end
c = canvas(UserUnit)
win[] = widget(c)
sleep(1.0) # allow canvas to be realized
c = canvas(UserUnit, 100, 100; init_back=true)
zr = Observable(ZoomRegion((1:11, 1:20)))
zoomrb = init_zoom_rubberband(c, zr)
zooms = init_zoom_scroll(c, zr)
@@ -156,10 +150,10 @@ using PrecompileTools
# eventscroll(c, UP, UserUnit(8), UserUnit(4), CONTROL))
signal_emit(scrollcontroller(c), "scroll", Bool,
convert(Float64, UserUnit(8)), convert(Float64, UserUnit(4)))
c=nothing
catch
@warn("GtkObservables canvas precompile code failure")
end
destroy(win)
end
end