(* ===================================================== *)
(*      Apprentissage de la programmation avec OCaml     *)
(*      Catherine Dubois & Valérie Ménissier-Morain      *)
(*                Éditions Hermès Sciences               *)
(*                        Mars 2004                      *)
(* ===================================================== *)
(* Fichier MLSRC/CC/CC_temps/pause.ml                    *)
(* ===================================================== *)

open Representation;;
open Graphics;;
open Affichage_base;;
open Affichage_jeu;;

let masquer_zone_de_jeu () =
  set_color grey;
  fill_rect 0 0 (size_x()-largeur_cartouche) (size_y());;

let dessiner_bouton () =
  set_font "-*-helvetica-bold-r-*-*-24-*";
  let (w,h) = text_size "PAUSE" in
  let
 eh = (size_x()-largeur_cartouche-w-h)/2 in
  let
 ev = (size_y()-2*h)/2 in
  set_color background;
  fill_rect eh ev (w+h) (2*h);
  set_color foreground;
  draw_rect eh ev (w+h) (2*h);
  moveto (eh+h/2) (ev+h/2);
  draw_string "PAUSE";
  (eh,ev,w+h,2*h);;

let détecter_reprise x y w h =
  let clic_ok = ref false in
  while not
 !clic_ok do
    let s = wait_next_event [Button_down] in
    clic_ok := s.mouse_x > x && s.mouse_x < x+w
            && s.mouse_y > y && s.mouse_y < y+h
  done;
  while button_down () do () done;;

let pause () =
  let temps = Unix.gettimeofday () -. état.temps_référence in
  masquer_zone_de_jeu ();
  let (x,y,w,h)=dessiner_bouton () in
  détecter_reprise x y w h;
  état.temps_référence <-
    Unix.gettimeofday () -. temps;
  set_color background;
  fill_rect 0 0 (size_x()-largeur_cartouche) (size_y());
  dessiner_zone_de_jeu ();
  match état.sélection with
  | None -> ()
  | Some (c,l) -> dessiner_sélection (coordonnées_pièce (c,l));;

Ce document a été traduit de LATEX par HEVEA.