Added reaction to closing the window
This commit is contained in:
@@ -778,15 +778,19 @@ class SDL_Visualizer(val width: Int, val height: Int): GameFieldVisualizer, User
|
|||||||
memScoped {
|
memScoped {
|
||||||
val event = alloc<SDL_Event>()
|
val event = alloc<SDL_Event>()
|
||||||
while (SDL_PollEvent(event.ptr.reinterpret()) != 0) {
|
while (SDL_PollEvent(event.ptr.reinterpret()) != 0) {
|
||||||
if (event.type.value == SDL_KEYDOWN) {
|
val eventType = event.type.value
|
||||||
val keyboardEvent = event.ptr.reinterpret<SDL_KeyboardEvent>().pointed
|
when (eventType) {
|
||||||
when (keyboardEvent.keysym.scancode.value) {
|
SDL_QUIT -> commands.add(UserCommand.EXIT)
|
||||||
SDL_SCANCODE_LEFT -> commands.add(UserCommand.LEFT)
|
SDL_KEYDOWN -> {
|
||||||
SDL_SCANCODE_RIGHT -> commands.add(UserCommand.RIGHT)
|
val keyboardEvent = event.ptr.reinterpret<SDL_KeyboardEvent>().pointed
|
||||||
SDL_SCANCODE_DOWN -> commands.add(UserCommand.DOWN)
|
when (keyboardEvent.keysym.scancode.value) {
|
||||||
SDL_SCANCODE_Z -> commands.add(UserCommand.ROTATE)
|
SDL_SCANCODE_LEFT -> commands.add(UserCommand.LEFT)
|
||||||
SDL_SCANCODE_UP -> commands.add(UserCommand.DROP)
|
SDL_SCANCODE_RIGHT -> commands.add(UserCommand.RIGHT)
|
||||||
SDL_SCANCODE_ESCAPE -> commands.add(UserCommand.EXIT)
|
SDL_SCANCODE_DOWN -> commands.add(UserCommand.DOWN)
|
||||||
|
SDL_SCANCODE_Z -> commands.add(UserCommand.ROTATE)
|
||||||
|
SDL_SCANCODE_UP -> commands.add(UserCommand.DROP)
|
||||||
|
SDL_SCANCODE_ESCAPE -> commands.add(UserCommand.EXIT)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user