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

Make all backends support Screen() constructor #4561

Merged
merged 2 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [Unreleased]

- Added empty constructor to all backends for `Screen` allowing `display(Makie.current_backend().Screen(), fig)` [#4561](https://github.com/MakieOrg/Makie.jl/pull/4561).
- Added `subsup` and `left_subsup` functions that offer stacked sub- and superscripts for `rich` text which means this style can be used with arbitrary fonts and is not limited to fonts supported by MathTeXEngine.jl [#4489](https://github.com/MakieOrg/Makie.jl/pull/4489).
- Added the `jitter_width` and `side_nudge` attributes to the `raincloud` plot definition, so that they can be used as kwargs [#4517]https://github.com/MakieOrg/Makie.jl/pull/4517)
- Expand PlotList plots to expose their child plots to the legend interface, allowing `axislegend`show plots within PlotSpecs as individual entries. [#4546](https://github.com/MakieOrg/Makie.jl/pull/4546)
Expand Down
6 changes: 4 additions & 2 deletions CairoMakie/src/display.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ function Base.display(screen::Screen, scene::Scene; connect=false)
return screen
end

function Base.display(screen::Screen{IMAGE}, scene::Scene; connect=false)
function Base.display(screen::Screen{IMAGE}, scene::Scene; connect=false, screen_config...)
config = Makie.merge_screen_config(ScreenConfig, Dict{Symbol,Any}(screen_config))
screen = Makie.apply_screen_config!(screen, config, scene)
path = joinpath(mktempdir(), "display.png")
Makie.push_screen!(scene, screen)
cairo_draw(screen, scene)
Expand Down Expand Up @@ -80,7 +82,7 @@ function Makie.backend_show(screen::Screen{SVG}, io::IO, ::MIME"image/svg+xml",
# xlink:href="someid" (but not xlink:href="data:someothercontent" which is how image data is attached)
# url(#someid)
svg = replace(svg, r"((?:(?:id|xlink:href)=\"(?!data:)[^\"]+)|url\(#[^)]+)" => SubstitutionString("\\1-$salt"))

print(io, svg)
return screen
end
Expand Down
33 changes: 32 additions & 1 deletion CairoMakie/src/screen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,31 @@ mutable struct Screen{SurfaceRenderType} <: Makie.MakieScreen
antialias::Int # cairo_antialias_t
visible::Bool
config::ScreenConfig

function Screen()
return new{IMAGE}()
end
function Screen{SurfaceRenderType}(
scene::Scene,
surface::Cairo.CairoSurface,
context::Cairo.CairoContext,
device_scaling_factor::Float64,
antialias::Int,
visible::Bool,
config::ScreenConfig
) where {SurfaceRenderType}

return new{SurfaceRenderType}(
scene,
surface,
context,
device_scaling_factor,
antialias,
visible,
config,
)
end

end

function Base.empty!(screen::Screen)
Expand All @@ -192,6 +217,7 @@ end
Base.close(screen::Screen) = empty!(screen)

function destroy!(screen::Screen)
isdefined(screen, :surface) || return
Cairo.destroy(screen.surface)
Cairo.destroy(screen.context)
end
Expand All @@ -200,7 +226,10 @@ function Base.isopen(screen::Screen)
return !(screen.surface.ptr == C_NULL || screen.context.ptr == C_NULL)
end

Base.size(screen::Screen) = round.(Int, (screen.surface.width, screen.surface.height))
function Base.size(screen::Screen)
isdefined(screen, :surface) || return (0, 0)
round.(Int, (screen.surface.width, screen.surface.height))
end
# we render the scene directly, since we have
# no screen dependent state like in e.g. opengl
Base.insert!(screen::Screen, scene::Scene, plot) = nothing
Expand Down Expand Up @@ -267,6 +296,7 @@ function Makie.apply_screen_config!(
destroy!(old_screen)
end
apply_config!(screen, config)
screen.scene = scene
return screen
end

Expand All @@ -275,6 +305,7 @@ function Makie.apply_screen_config!(screen::Screen, config::ScreenConfig, scene:
Makie.apply_screen_config!(screen, config, scene, nothing, MIME"image/png"())
end


function Screen(scene::Scene; screen_config...)
config = Makie.merge_screen_config(ScreenConfig, Dict{Symbol, Any}(screen_config))
return Screen(scene, config)
Expand Down
6 changes: 6 additions & 0 deletions WGLMakie/src/display.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ mutable struct Screen <: Makie.MakieScreen
end
end

function Screen(; config...)
config = Makie.merge_screen_config(ScreenConfig, Dict{Symbol,Any}(config))
return Screen(nothing, config)
end


function scene_already_displayed(screen::Screen, scene=screen.scene)
scene === nothing && return false
screen.scene === scene || return false
Expand Down
Loading