Skip to content
This repository has been archived by the owner on Jul 14, 2021. It is now read-only.

fix ranged pick_native #173

Merged
merged 1 commit into from
Mar 29, 2021
Merged
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
10 changes: 7 additions & 3 deletions src/screen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -418,24 +418,28 @@ end
function pick_native(screen::Screen, xy::Vec{2, Float64}, range::Float64)
isopen(screen) || return SelectionID{Int}(0, 0)
window_size = widths(screen)
w, h = window_size
if !((1.0 <= xy[1] <= w) && (1.0 <= xy[2] <= h))
return SelectionID{Int}(0, 0)
end

fb = screen.framebuffer
buff = fb.buffers[:objectid]
glBindFramebuffer(GL_FRAMEBUFFER, fb.id[1])
glReadBuffer(GL_COLOR_ATTACHMENT1)

w, h = window_size
x0, y0 = max.(1, floor.(Int, xy .- range))
x1, y1 = min.([w, h], floor.(Int, xy .+ range))
dx = x1 - x0; dy = y1 - y0
sid = Matrix{SelectionID{UInt32}}(undef, dx, dy)
glReadPixels(x0, y0, dx, dy, buff.format, buff.pixeltype, sid)

min_dist = range^2 # squared distance
min_dist = range^2
id = SelectionID{Int}(0, 0)
x, y = xy .+ 1 .- Vec2f0(x0, y0)
for i in 1:dx, j in 1:dy
d = (x-i)^2 + (y-j)^2
if (d < min_dist) && (sid[i, j][2] < 0x3f800000)
if (d < min_dist) && (sid[i, j][1] > 0x00000000) && (sid[i, j][2] < 0x3f800000)
min_dist = d
id = convert(SelectionID{Int}, sid[i, j])
end
Expand Down