1996-03-12 10:00:39 -08:00
|
|
|
(***********************************************************************)
|
|
|
|
(* *)
|
1996-04-30 07:53:58 -07:00
|
|
|
(* Objective Caml *)
|
1996-03-12 10:00:39 -08:00
|
|
|
(* *)
|
|
|
|
(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
|
|
|
|
(* *)
|
1996-04-30 07:53:58 -07:00
|
|
|
(* Copyright 1996 Institut National de Recherche en Informatique et *)
|
1999-11-17 10:59:06 -08:00
|
|
|
(* en Automatique. All rights reserved. This file is distributed *)
|
|
|
|
(* under the terms of the GNU Library General Public License. *)
|
1996-03-12 10:00:39 -08:00
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
|
|
|
(* $Id$ *)
|
|
|
|
|
|
|
|
exception Graphic_failure of string
|
|
|
|
|
|
|
|
(* Initializations *)
|
|
|
|
|
1996-11-08 06:47:07 -08:00
|
|
|
let _ =
|
|
|
|
Callback.register_exception "Graphics.Graphic_failure" (Graphic_failure "")
|
1996-03-12 10:00:39 -08:00
|
|
|
|
|
|
|
external raw_open_graph: string -> unit = "gr_open_graph"
|
|
|
|
external raw_close_graph: unit -> unit = "gr_close_graph"
|
|
|
|
external sigio_signal: unit -> int = "gr_sigio_signal"
|
|
|
|
external sigio_handler: int -> unit = "gr_sigio_handler"
|
|
|
|
|
1996-10-07 07:03:20 -07:00
|
|
|
let unix_open_graph arg =
|
1998-11-12 06:51:27 -08:00
|
|
|
Sys.set_signal (sigio_signal()) (Sys.Signal_handle sigio_handler);
|
1996-03-12 10:00:39 -08:00
|
|
|
raw_open_graph arg
|
1996-11-07 03:00:46 -08:00
|
|
|
|
1996-10-07 07:03:20 -07:00
|
|
|
let unix_close_graph () =
|
1998-11-12 06:51:27 -08:00
|
|
|
Sys.set_signal (sigio_signal()) Sys.Signal_ignore;
|
1996-03-12 10:00:39 -08:00
|
|
|
raw_close_graph ()
|
1996-11-07 03:00:46 -08:00
|
|
|
|
1996-10-24 07:17:18 -07:00
|
|
|
let (open_graph, close_graph) =
|
1996-11-07 03:00:46 -08:00
|
|
|
match Sys.os_type with
|
1996-10-24 07:17:18 -07:00
|
|
|
| "Unix" -> (unix_open_graph, unix_close_graph)
|
|
|
|
| "Win32" -> (raw_open_graph, raw_close_graph)
|
|
|
|
| "MacOS" -> (raw_open_graph, raw_close_graph)
|
1996-11-07 03:00:46 -08:00
|
|
|
| _ -> invalid_arg ("Graphics: unknown OS type: " ^ Sys.os_type)
|
1996-03-12 10:00:39 -08:00
|
|
|
|
|
|
|
external clear_graph : unit -> unit = "gr_clear_graph"
|
|
|
|
external size_x : unit -> int = "gr_size_x"
|
|
|
|
external size_y : unit -> int = "gr_size_y"
|
|
|
|
|
2000-02-08 06:26:12 -08:00
|
|
|
(* Double-buffering *)
|
|
|
|
|
2000-02-23 06:26:58 -08:00
|
|
|
external auto_flush : bool -> unit = "gr_auto_flush"
|
2000-02-08 06:26:12 -08:00
|
|
|
external flush : unit -> unit = "gr_flush"
|
|
|
|
|
1996-03-12 10:00:39 -08:00
|
|
|
(* Colors *)
|
|
|
|
|
|
|
|
type color = int
|
|
|
|
|
|
|
|
let rgb r g b = (r lsl 16) + (g lsl 8) + b
|
|
|
|
|
|
|
|
external set_color : color -> unit = "gr_set_color"
|
|
|
|
|
|
|
|
let black = 0x000000
|
|
|
|
and white = 0xFFFFFF
|
|
|
|
and red = 0xFF0000
|
|
|
|
and green = 0x00FF00
|
|
|
|
and blue = 0x0000FF
|
|
|
|
and yellow = 0xFFFF00
|
|
|
|
and cyan = 0x00FFFF
|
|
|
|
and magenta = 0xFF00FF
|
|
|
|
|
|
|
|
let background = white
|
|
|
|
and foreground = black
|
|
|
|
|
|
|
|
(* Drawing *)
|
|
|
|
|
|
|
|
external plot : int -> int -> unit = "gr_plot"
|
|
|
|
external point_color : int -> int -> color = "gr_point_color"
|
|
|
|
external moveto : int -> int -> unit = "gr_moveto"
|
|
|
|
external current_point : unit -> int * int = "gr_current_point"
|
|
|
|
external lineto : int -> int -> unit = "gr_lineto"
|
|
|
|
external draw_arc : int -> int -> int -> int -> int -> int -> unit
|
|
|
|
= "gr_draw_arc" "gr_draw_arc_nat"
|
|
|
|
let draw_ellipse x y rx ry = draw_arc x y rx ry 0 360
|
|
|
|
let draw_circle x y r = draw_arc x y r r 0 360
|
|
|
|
external set_line_width : int -> unit = "gr_set_line_width"
|
|
|
|
|
|
|
|
external fill_rect : int -> int -> int -> int -> unit = "gr_fill_rect"
|
|
|
|
external fill_poly : (int * int) array -> unit = "gr_fill_poly"
|
|
|
|
external fill_arc : int -> int -> int -> int -> int -> int -> unit
|
|
|
|
= "gr_fill_arc" "gr_fill_arc_nat"
|
|
|
|
let fill_ellipse x y rx ry = fill_arc x y rx ry 0 360
|
|
|
|
let fill_circle x y r = fill_arc x y r r 0 360
|
|
|
|
|
|
|
|
(* Text *)
|
|
|
|
|
|
|
|
external draw_char : char -> unit = "gr_draw_char"
|
|
|
|
external draw_string : string -> unit = "gr_draw_string"
|
|
|
|
external set_font : string -> unit = "gr_set_font"
|
1998-09-23 10:28:10 -07:00
|
|
|
external set_text_size : int -> unit = "gr_set_text_size"
|
1996-03-12 10:00:39 -08:00
|
|
|
external text_size : string -> int * int = "gr_text_size"
|
|
|
|
|
|
|
|
(* Images *)
|
|
|
|
|
|
|
|
type image
|
|
|
|
|
|
|
|
let transp = -1
|
|
|
|
|
|
|
|
external make_image : color array array -> image = "gr_make_image"
|
|
|
|
external dump_image : image -> color array array = "gr_dump_image"
|
|
|
|
external draw_image : image -> int -> int -> unit = "gr_draw_image"
|
|
|
|
external create_image : int -> int -> image = "gr_create_image"
|
|
|
|
external blit_image : image -> int -> int -> unit = "gr_blit_image"
|
|
|
|
|
|
|
|
let get_image x y w h =
|
|
|
|
let image = create_image w h in
|
|
|
|
blit_image image x y;
|
|
|
|
image
|
|
|
|
|
|
|
|
(* Events *)
|
|
|
|
|
|
|
|
type status =
|
|
|
|
{ mouse_x : int;
|
|
|
|
mouse_y : int;
|
|
|
|
button : bool;
|
|
|
|
keypressed : bool;
|
|
|
|
key : char }
|
|
|
|
|
|
|
|
type event =
|
|
|
|
Button_down
|
|
|
|
| Button_up
|
|
|
|
| Key_pressed
|
|
|
|
| Mouse_motion
|
|
|
|
| Poll
|
|
|
|
|
|
|
|
external wait_next_event : event list -> status = "gr_wait_event"
|
|
|
|
|
|
|
|
let mouse_pos () =
|
|
|
|
let e = wait_next_event [Poll] in (e.mouse_x, e.mouse_y)
|
|
|
|
|
|
|
|
let button_down () =
|
|
|
|
let e = wait_next_event [Poll] in e.button
|
|
|
|
|
|
|
|
let read_key () =
|
|
|
|
let e = wait_next_event [Key_pressed] in e.key
|
|
|
|
|
|
|
|
let key_pressed () =
|
|
|
|
let e = wait_next_event [Poll] in e.keypressed
|
|
|
|
|
|
|
|
(*** Sound *)
|
|
|
|
|
|
|
|
external sound : int -> int -> unit = "gr_sound"
|