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 GetKey(win, KEY_ESCAPE) == PRESS work #225

Merged
merged 2 commits into from
Mar 15, 2023
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
9 changes: 9 additions & 0 deletions src/glfw3.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@
PRESS = 1
REPEAT = 2
end
# GetKey is defined below to return a Bool, but in the documentation it is
# defined as returning PRESS or RELEASE. In C that doesn't matter, but in
# Julia these are different types and so e.g.
# `GLFW.GetKey(window, GLFW.KEY_ESCAPE)) == GLFW.PRESS` will always return
# false.
#
# This method tells Julia how to compare an Action and a Bool so that code
# calling GetKey as documented will work as expected.
Base.(==)(b::Bool, a::Action) = b == Integer(a)

@enum Key::Cint begin
# Unknown key
Expand Down
4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ println(GLFW.GetVersionString())
# GLFWError uses integer for unrecognized error code
@test isa(GLFW.GLFWError(0xDEADBEEF, "").code, Integer)

# https://github.com/JuliaGL/GLFW.jl/pull/225
@test GLFW.PRESS == true
@test GLFW.RELEASE == false

if !haskey(ENV, "CI") # AppVeyor and Travis CI don't support OpenGL
include("windowclose.jl")
end