/usr/lib/ocaml/lablgl/togl.ml is in liblablgl-ocaml-dev 1:1.05-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 | (* $Id: togl.ml,v 1.23 2006-03-23 00:39:27 garrigue Exp $ *)
open StdLabels
open Tk
open Protocol
let may x name f =
match x with None -> []
| Some a -> [TkToken name; TkToken (f a)]
let cbool x = if x then "1" else "0"
let cint = string_of_int
let id x = x
let togl_options_optionals f =
fun
?accum
?accumalphasize
?accumbluesize
?accumgreensize
?accumredsize
?alpha
?alphasize
?auxbuffers
?bluesize
?depth
?depthsize
?double
?greensize
?height
(* ?ident *)
?overlay
?privatecmap
?redsize
?rgba
?stencil
?stencilsize
?stereo
(* ?time *)
?width
->
f (may accum "-accum" cbool
@ may accumalphasize "-accumalphasize" cint
@ may accumbluesize "-accumbluesize" cint
@ may accumgreensize "-accumgreensize" cint
@ may accumredsize "-accumredsize" cint
@ may alpha "-alpha" cbool
@ may alphasize "-alphasize" cint
@ may auxbuffers "-auxbuffers" cint
@ may bluesize "-bluesize" cint
@ may depth "-depth" cbool
@ may depthsize "-depthsize" cint
@ may double "-double" cbool
@ may greensize "-greensize" cint
@ may height "-height" cint
(* @ may ident "-ident" id *)
@ may overlay "-overlay" cbool
@ may privatecmap "-privatecmap" cbool
@ may redsize "-redsize" cint
@ may rgba "-rgba" cbool
@ may stencil "-stencil" cbool
@ may stencilsize "-stencilsize" cint
@ may stereo "-stereo" cbool
(* @ may time "-time" cint *)
@ may width "-width" cint)
type t
external init : unit -> unit = "ml_Togl_Init"
external _create_func : unit -> unit = "ml_Togl_CreateFunc"
external _display_func : unit -> unit = "ml_Togl_DisplayFunc"
external _reshape_func : unit -> unit = "ml_Togl_ReshapeFunc"
external _destroy_func : unit -> unit = "ml_Togl_DestroyFunc"
external _timer_func : unit -> unit = "ml_Togl_TimerFunc"
external _overlay_display_func : unit -> unit = "ml_Togl_OverlayDisplayFunc"
external _reset_default_callbacks : unit -> unit
= "ml_Togl_ResetDefaultCallbacks"
external _post_redisplay : t -> unit = "ml_Togl_PostRedisplay"
external _swap_buffers : t -> unit = "ml_Togl_SwapBuffers"
external _ident : t -> string = "ml_Togl_Ident"
external _height : t -> int = "ml_Togl_Height"
external _width : t -> int = "ml_Togl_Width"
type font = [
`Fixed_8x13
| `Fixed_9x15
| `Times_10
| `Times_24
| `Helvetica_10
| `Helvetica_12
| `Helvetica_18
| `Xfont of string
]
external _load_bitmap_font : t -> font:font -> GlList.base
= "ml_Togl_LoadBitmapFont"
external _unload_bitmap_font : t -> base:GlList.base -> unit
= "ml_Togl_UnloadBitmapFont"
external _use_layer : t -> num:int -> unit = "ml_Togl_UseLayer"
external _show_overlay : t -> unit = "ml_Togl_ShowOverlay"
external _hide_overlay : t -> unit = "ml_Togl_HideOverlay"
external _post_overlay_redisplay : t -> unit = "ml_Togl_PostOverlayRedisplay"
external _exists_overlay : t -> bool = "ml_Togl_ExistsOverlay"
external _get_overlay_transparent_value : t -> int
= "ml_Togl_GetOverlayTransparentValue"
external _dump_to_eps_file : t -> string -> bool -> unit
= "ml_Togl_DumpToEpsFile"
type w
type widget = w Widget.widget
let togl_table = Hashtbl.create 7
let wrap f (w : widget) =
let togl =
try Hashtbl.find togl_table w
with Not_found -> raise (TkError "Unreferenced togl widget")
in f togl
let render = wrap _post_redisplay
let swap_buffers = wrap _swap_buffers
let height = wrap _height
let width = wrap _width
let load_bitmap_font = wrap _load_bitmap_font
let unload_bitmap_font = wrap _unload_bitmap_font
let use_layer = wrap _use_layer
let show_overlay = wrap _show_overlay
let hide_overlay = wrap _hide_overlay
let overlay_redisplay = wrap _post_overlay_redisplay
let exists_overlay = wrap _exists_overlay
let get_overlay_transparent_value = wrap _get_overlay_transparent_value
let make_current togl =
ignore (tkEval [|TkToken (Widget.name togl); TkToken "makecurrent"|])
let null_func _ = ()
let display_table = Hashtbl.create 7
and reshape_table = Hashtbl.create 7
and overlay_table = Hashtbl.create 7
let cb_of_togl table togl =
try
let key = _ident togl in
let cb = Hashtbl.find table key in
ignore (tkEval [|TkToken key; TkToken "makecurrent"|]);
cb ()
with Not_found -> ()
let create_id = 0
and display_id = 1
and reshape_id = 2
and destroy_id = 3
and timer_id = 4
and overlay_display_id = 5
and render_id = 6
let callback_table =
[|null_func;
cb_of_togl display_table;
cb_of_togl reshape_table;
null_func;
null_func;
cb_of_togl overlay_table;
null_func|]
let () =
Callback.register "togl_callbacks" callback_table;
(* Also export an error-reporting function *)
Callback.register "togl_prerr"
(fun msg -> prerr_string msg; flush stderr)
let callback_func table (w : widget) ~cb =
let key = Widget.name w in
(try Hashtbl.remove table key with Not_found -> ());
Hashtbl.add table key cb
let display_func = callback_func display_table
let reshape_func w ~cb =
make_current w; cb ();
callback_func reshape_table w ~cb
let overlay_display_func = callback_func overlay_table
let dump_to_eps_file ~filename ?(rgba=false) ?render togl =
let render =
match render with Some f -> f
| None ->
try Hashtbl.find display_table (_ident togl)
with Not_found ->
raise (TkError "Togl.dump_to_eps_file : no render function")
in
callback_table.(render_id) <- (fun _ -> render());
_dump_to_eps_file togl filename rgba
let dump_to_eps_file ~filename ?rgba ?render =
wrap (dump_to_eps_file ~filename ?rgba ?render)
let rec timer_func ~ms ~cb =
ignore (Timer.add ~ms ~callback:(fun () -> cb (); timer_func ~ms ~cb))
let configure ?height ?width w =
let options = may height "-height" cint @ may width "-width" cint in
tkEval [|TkToken (Widget.name w); TkTokenList options|]
(*
class widget w t =
val w : widget = w
val t = t
method widget = w
method name = coe w
method configure = configure ?w
method bind = bind w
method redisplay = post_redisplay t
method swap_buffers = swap_buffers t
method width = width t
method height = height t
method load_font = load_bitmap_font t
method unload_font = unload_bitmap_font t
method use_layer = use_layer t
method show_overlay = show_overlay t
method hide_overlay = hide_overlay t
method overlay_redisplay = post_overlay_redisplay t
method exist_overlay = exists_overlay t
method overlay_transparent_value = get_overlay_transparent_value t
method dump_to_eps_file = dump_to_eps_file t
method make_current =
tkEval [|TkToken (Widget.name w); TkToken "makecurrent"|]; ()
end
*)
let ready = ref false
let init_togl () =
init ();
_create_func ();
_display_func ();
_reshape_func ();
_overlay_display_func ();
_destroy_func ();
ready := true
let create ?name =
togl_options_optionals
(fun options parent ->
prerr_endline "Before init";
if not !ready then init_togl ();
prerr_endline "After init";
let w : widget =
Widget.new_atom "togl" ~parent ?name in
let togl = ref None in
callback_table.(create_id) <-
(fun t -> togl := Some t; Hashtbl.add togl_table w t);
callback_table.(destroy_id) <-
(fun t ->
begin try Hashtbl.remove togl_table w with Not_found -> () end;
List.iter [display_table; reshape_table; overlay_table] ~f:
begin fun tbl ->
try Hashtbl.remove tbl (Widget.name w) with Not_found -> ()
end);
prerr_endline "Before create";
let command =
[|TkToken "togl"; TkToken (Widget.name w);
TkToken "-ident"; TkToken (Widget.name w);
TkTokenList options|] in
let _res : string =
try tkEval command
with TkError "invalid command name \"togl\"" ->
raise (TkError "Togl initialization failed")
in
prerr_endline "After create";
match !togl with None -> raise (TkError "Togl widget creation failed")
| Some t -> w)
|