Skip to content

Commit

Permalink
Merge pull request #225 from cmcaine/master
Browse files Browse the repository at this point in the history
Make `GetKey(win, KEY_ESCAPE) == PRESS` work
  • Loading branch information
SimonDanisch authored Mar 15, 2023
2 parents e8d5815 + 64a3278 commit 6bdd564
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
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

0 comments on commit 6bdd564

Please sign in to comment.