Add Graphics.loop_at_exit function
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@13869 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02master
parent
0425a7246b
commit
c77d5ac9c3
|
@ -212,6 +212,18 @@ let read_key () =
|
|||
let key_pressed () =
|
||||
let e = wait_next_event [Poll] in e.keypressed
|
||||
|
||||
let loop_at_exit events handler =
|
||||
let events = List.filter (fun e -> e <> Poll) events in
|
||||
at_exit (fun _ ->
|
||||
try
|
||||
while true do
|
||||
let e = wait_next_event events in
|
||||
handler e
|
||||
done
|
||||
with Exit -> close_graph ()
|
||||
| e -> close_graph (); raise e
|
||||
)
|
||||
|
||||
(*** Sound *)
|
||||
|
||||
external sound : int -> int -> unit = "caml_gr_sound"
|
||||
|
|
|
@ -303,6 +303,14 @@ external wait_next_event : event list -> status = "caml_gr_wait_event"
|
|||
are queued, and dequeued one by one when the [Key_pressed]
|
||||
event is specified. *)
|
||||
|
||||
val loop_at_exit : event list -> (status -> unit) -> unit
|
||||
(** Loop before exiting the program, the list given as argument is the
|
||||
list of handlers and the events on which these handlers are called.
|
||||
To exit cleanly the loop, the handler should raise Exit. Any other
|
||||
exception will be propagated outside of the loop.
|
||||
@since 4.01
|
||||
*)
|
||||
|
||||
(** {6 Mouse and keyboard polling} *)
|
||||
|
||||
val mouse_pos : unit -> int * int
|
||||
|
|
Loading…
Reference in New Issue