summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJacques Garrigue <garrigue at math.nagoya-u.ac.jp>2000-04-12 09:53:09 +0000
committerJacques Garrigue <garrigue at math.nagoya-u.ac.jp>2000-04-12 09:53:09 +0000
commit84baddf830a019ae05869b73ca28fdd8bb2f42e7 (patch)
treed459e80d70724dca1db600a50db060a73a0b1898
parent070f6559f3b11da304fbb4005582cd308767771c (diff)
tilde syntax
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@3063 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
-rw-r--r--otherlibs/labltk/example/calc.ml28
-rw-r--r--otherlibs/labltk/example/clock.ml68
-rw-r--r--otherlibs/labltk/example/demo.ml96
-rw-r--r--otherlibs/labltk/example/eyes.ml22
-rw-r--r--otherlibs/labltk/example/hello.ml2
-rw-r--r--otherlibs/labltk/example/tetris.ml246
6 files changed, 231 insertions, 231 deletions
diff --git a/otherlibs/labltk/example/calc.ml b/otherlibs/labltk/example/calc.ml
index 18d0c7936..be8f557e3 100644
--- a/otherlibs/labltk/example/calc.ml
+++ b/otherlibs/labltk/example/calc.ml
@@ -24,7 +24,7 @@
open Tk
-let mem_string elt:c s =
+let mem_string ~elt:c s =
try
for i = 0 to String.length s -1 do
if s.[i] = c then raise Exit
@@ -56,7 +56,7 @@ class calc () = object (calc)
if displaying then
(calc#set "0."; displaying <- false)
else
- if not (mem_string elt:'.' calc#get) then calc#insert s
+ if not (mem_string ~elt:'.' calc#get) then calc#insert s
| '+'|'-'|'*'|'/' as c ->
displaying <- true;
begin match op with
@@ -91,36 +91,36 @@ let m =
(* The physical calculator. Inherits from the abstract one *)
-class calculator :parent = object
+class calculator ~parent = object
inherit calc () as calc
- val label = Label.create anchor:`E relief:`Sunken padx:10 parent
+ val label = Label.create ~anchor:`E ~relief:`Sunken ~padx:10 parent
val frame = Frame.create parent
initializer
let buttons =
- Array.map f:
- (List.map f:
+ Array.map ~f:
+ (List.map ~f:
(fun text ->
- Button.create :text command:(fun () -> calc#command text) frame))
+ Button.create ~text ~command:(fun () -> calc#command text) frame))
m
in
- Label.configure textvariable:variable label;
+ Label.configure ~textvariable:variable label;
calc#set "0";
- bind events:[`KeyPress] fields:[`Char]
- action:(fun ev -> calc#command ev.ev_Char)
+ bind ~events:[`KeyPress] ~fields:[`Char]
+ ~action:(fun ev -> calc#command ev.ev_Char)
parent;
for i = 0 to Array.length m - 1 do
- Grid.configure row:i buttons.(i)
+ Grid.configure ~row:i buttons.(i)
done;
- pack side:`Top fill:`X [label];
- pack side:`Bottom fill:`Both expand:true [frame];
+ pack ~side:`Top ~fill:`X [label];
+ pack ~side:`Bottom ~fill:`Both ~expand:true [frame];
end
(* Finally start everything *)
let top = openTk ()
-let applet = new calculator parent:top
+let applet = new calculator ~parent:top
let _ = mainLoop ()
diff --git a/otherlibs/labltk/example/clock.ml b/otherlibs/labltk/example/clock.ml
index f1fce00db..58b0a0fae 100644
--- a/otherlibs/labltk/example/clock.ml
+++ b/otherlibs/labltk/example/clock.ml
@@ -32,10 +32,10 @@ let pi = acos (-1.)
* initialize with [#init]
*)
-class clock :parent = object (self)
+class clock ~parent = object (self)
(* Instance variables *)
- val canvas = Canvas.create width:100 height:100 parent
+ val canvas = Canvas.create ~width:100 ~height:100 parent
val mutable height = 100
val mutable width = 100
val mutable rflag = -1
@@ -46,84 +46,84 @@ class clock :parent = object (self)
initializer
(* Create the oval border *)
- Canvas.create_oval x1:1 y1:1 x2:(width - 2) y2:(height - 2)
- tags:["cadran"] width:3 outline:`Yellow fill:`White
+ Canvas.create_oval ~x1:1 ~y1:1 ~x2:(width - 2) ~y2:(height - 2)
+ ~tags:["cadran"] ~width:3 ~outline:`Yellow ~fill:`White
canvas;
(* Draw the figures *)
self#draw_figures;
(* Create the arrows with dummy position *)
- Canvas.create_line xys:[self#x 0.; self#y 0.; self#x 0.; self#y 0.]
- tags:["hours"] fill:`Red
+ Canvas.create_line ~xys:[self#x 0.; self#y 0.; self#x 0.; self#y 0.]
+ ~tags:["hours"] ~fill:`Red
canvas;
- Canvas.create_line xys:[self#x 0.; self#y 0.; self#x 0.; self#y 0.]
- tags:["minutes"] fill:`Blue
+ Canvas.create_line ~xys:[self#x 0.; self#y 0.; self#x 0.; self#y 0.]
+ ~tags:["minutes"] ~fill:`Blue
canvas;
- Canvas.create_line xys:[self#x 0.; self#y 0.; self#x 0.; self#y 0.]
- tags:["seconds"] fill:`Black
+ Canvas.create_line ~xys:[self#x 0.; self#y 0.; self#x 0.; self#y 0.]
+ ~tags:["seconds"] ~fill:`Black
canvas;
(* Setup a timer every second *)
let rec timer () =
self#draw_arrows (Unix.localtime (Unix.time ()));
- Timer.add ms:1000 callback:timer; ()
+ Timer.add ~ms:1000 ~callback:timer; ()
in timer ();
(* Redraw when configured (changes size) *)
- bind events:[`Configure]
- action:(fun _ ->
+ bind ~events:[`Configure]
+ ~action:(fun _ ->
width <- Winfo.width canvas;
height <- Winfo.height canvas;
self#redraw)
canvas;
(* Change direction with right button *)
- bind events:[`ButtonPressDetail 3]
- action:(fun _ -> rflag <- -rflag; self#redraw)
+ bind ~events:[`ButtonPressDetail 3]
+ ~action:(fun _ -> rflag <- -rflag; self#redraw)
canvas;
(* Pack, expanding in both directions *)
- pack fill:`Both expand:true [canvas]
+ pack ~fill:`Both ~expand:true [canvas]
(* Redraw everything *)
method redraw =
- Canvas.coords_set :canvas
- coords:[ 1; 1; width - 2; height - 2 ]
+ Canvas.coords_set ~canvas
+ ~coords:[ 1; 1; width - 2; height - 2 ]
(`Tag "cadran");
self#draw_figures;
self#draw_arrows (Unix.localtime (Unix.time ()))
(* Delete and redraw the figures *)
method draw_figures =
- Canvas.delete :canvas [`Tag "figures"];
+ Canvas.delete ~canvas [`Tag "figures"];
for i = 1 to 12 do
let angle = float (rflag * i - 3) *. pi /. 6. in
Canvas.create_text
- x:(self#x (0.8 *. cos angle)) y:(self#y (0.8 *. sin angle))
- tags:["figures"]
- text:(string_of_int i) font:"variable"
- anchor:`Center
+ ~x:(self#x (0.8 *. cos angle)) ~y:(self#y (0.8 *. sin angle))
+ ~tags:["figures"]
+ ~text:(string_of_int i) ~font:"variable"
+ ~anchor:`Center
canvas
done
(* Resize and reposition the arrows *)
method draw_arrows tm =
- Canvas.configure_line :canvas
- width:(min width height / 40)
+ Canvas.configure_line ~canvas
+ ~width:(min width height / 40)
(`Tag "hours");
let hangle =
float (rflag * (tm.Unix.tm_hour * 60 + tm.Unix.tm_min) - 180)
*. pi /. 360. in
- Canvas.coords_set :canvas
- coords:[ self#x 0.; self#y 0.;
+ Canvas.coords_set ~canvas
+ ~coords:[ self#x 0.; self#y 0.;
self#x (cos hangle /. 2.); self#y (sin hangle /. 2.) ]
(`Tag "hours");
- Canvas.configure_line :canvas
- width:(min width height / 50)
+ Canvas.configure_line ~canvas
+ ~width:(min width height / 50)
(`Tag "minutes");
let mangle = float (rflag * tm.Unix.tm_min - 15) *. pi /. 30. in
- Canvas.coords_set :canvas
- coords:[ self#x 0.; self#y 0.;
+ Canvas.coords_set ~canvas
+ ~coords:[ self#x 0.; self#y 0.;
self#x (cos mangle /. 1.5); self#y (sin mangle /. 1.5) ]
(`Tag "minutes");
let sangle = float (rflag * tm.Unix.tm_sec - 15) *. pi /. 30. in
- Canvas.coords_set :canvas
- coords:[ self#x 0.; self#y 0.;
+ Canvas.coords_set ~canvas
+ ~coords:[ self#x 0.; self#y 0.;
self#x (cos sangle /. 1.25); self#y (sin sangle /. 1.25) ]
(`Tag "seconds")
end
@@ -133,7 +133,7 @@ let top = openTk ()
(* Create a clock on the main window *)
let clock =
- new clock parent:top
+ new clock ~parent:top
(* Wait for events *)
let _ = mainLoop ()
diff --git a/otherlibs/labltk/example/demo.ml b/otherlibs/labltk/example/demo.ml
index 70fd5e437..343f45684 100644
--- a/otherlibs/labltk/example/demo.ml
+++ b/otherlibs/labltk/example/demo.ml
@@ -25,138 +25,138 @@ let _ =
(* Initialize Tk *)
let top = openTk () in
(* Title setting *)
-Wm.title_set top title:"LablTk demo";
+Wm.title_set top ~title:"LablTk demo";
(* Base frame *)
let base = Frame.create top in
pack [base];
(* Menu bar *)
-let bar = Frame.create base borderwidth: 2 relief: `Raised in
-pack [bar] fill: `X;
+let bar = Frame.create base ~borderwidth: 2 ~relief: `Raised in
+pack [bar] ~fill: `X;
(* Menu and Menubutton *)
- let meb = Menubutton.create bar text: "Menu" in
+ let meb = Menubutton.create bar ~text: "Menu" in
let men = Menu.create meb in
- Menu.add_command men label: "Quit" command: (fun () -> closeTk (); exit 0);
- Menubutton.configure meb menu: men;
+ Menu.add_command men ~label: "Quit" ~command: (fun () -> closeTk (); exit 0);
+ Menubutton.configure meb ~menu: men;
(* Frames *)
let base2 = Frame.create base in
let left = Frame.create base2 in
let right = Frame.create base2 in
pack [base2];
- pack [left; right] side: `Left;
+ pack [left; right] ~side: `Left;
(* Widgets on left and right *)
(* Button *)
- let but = Button.create left text: "Welcome to LablTk" in
+ let but = Button.create left ~text: "Welcome to LablTk" in
(* Canvas *)
- let can = Canvas.create left width: 100
- height: 100 borderwidth: 1 relief: `Sunken
+ let can = Canvas.create left ~width: 100
+ ~height: 100 ~borderwidth: 1 ~relief: `Sunken
in
- Canvas.create_oval can x1: 10 y1: 10
- x2: 90 y2: 90
- fill:`Red;
+ Canvas.create_oval can ~x1: 10 ~y1: 10
+ ~x2: 90 ~y2: 90
+ ~fill:`Red;
(* Check button *)
- let che = Checkbutton.create left text: "Check" in
+ let che = Checkbutton.create left ~text: "Check" in
(* Entry *)
- let ent = Entry.create left width: 10 in
+ let ent = Entry.create left ~width: 10 in
(* Label *)
- let lab = Label.create left text: "Welcome to LablTk" in
+ let lab = Label.create left ~text: "Welcome to LablTk" in
(* Listbox *)
let lis = Listbox.create left in
- Listbox.insert lis index: `End texts: ["This"; "is"; "Listbox"];
+ Listbox.insert lis ~index: `End ~texts: ["This"; "is"; "Listbox"];
(* Message *)
let mes = Message.create left
- text: "Hello this is a message widget with very long text, but ..." in
+ ~text: "Hello this is a message widget with very long text, but ..." in
(* Radio buttons *)
let tv = Textvariable.create () in
Textvariable.set tv "One";
let radf = Frame.create right in
let rads = List.map
- f:(fun t -> Radiobutton.create radf text: t value: t variable: tv)
+ ~f:(fun t -> Radiobutton.create radf ~text: t ~value: t ~variable: tv)
["One"; "Two"; "Three"] in
(* Scale *)
- let sca = Scale.create right label: "Scale" length: 100
- showvalue: true in
+ let sca = Scale.create right ~label: "Scale" ~length: 100
+ ~showvalue: true in
(* Text and scrollbar *)
let texf = Frame.create right in
(* Text *)
- let tex = Text.create texf width: 20 height: 8 in
- Text.insert tex text: "This is a text widget." index: (`End,[])
- tags: [];
+ let tex = Text.create texf ~width: 20 ~height: 8 in
+ Text.insert tex ~text: "This is a text widget." ~index: (`End,[])
+ ~tags: [];
(* Scrollbar *)
let scr = Scrollbar.create texf in
(* Text and Scrollbar widget link *)
let scroll_link sb tx =
- Text.configure tx yscrollcommand: (Scrollbar.set sb);
- Scrollbar.configure sb command: (Text.yview tx) in
+ Text.configure tx ~yscrollcommand: (Scrollbar.set sb);
+ Scrollbar.configure sb ~command: (Text.yview tx) in
scroll_link scr tex;
- pack [scr] side: `Right fill: `Y;
- pack [tex] side: `Left fill: `Both expand: true;
+ pack [scr] ~side: `Right ~fill: `Y;
+ pack [tex] ~side: `Left ~fill: `Both ~expand: true;
(* Pack them *)
- pack [meb] side: `Left;
+ pack [meb] ~side: `Left;
pack [coe but; coe can; coe che; coe ent; coe lab; coe lis; coe mes];
pack [coe radf; coe sca; coe texf];
pack rads;
(* Toplevel *)
let top2 = Toplevel.create top in
- Wm.title_set top2 title:"LablTk demo control";
+ Wm.title_set top2 ~title:"LablTk demo control";
let defcol = `Color "#dfdfdf" in
let selcol = `Color "#ffdfdf" in
let buttons =
- List.map f:(fun (w, t, c, a) ->
- let b = Button.create top2 text:t command:c in
- bind b events: [`Enter] action:(fun _ -> a selcol);
- bind b events: [`Leave] action:(fun _ -> a defcol);
+ List.map ~f:(fun (w, t, c, a) ->
+ let b = Button.create top2 ~text:t ~command:c in
+ bind b ~events: [`Enter] ~action:(fun _ -> a selcol);
+ bind b ~events: [`Leave] ~action:(fun _ -> a defcol);
b)
[coe bar, "Frame", (fun () -> ()),
- (fun background -> Frame.configure bar :background);
+ (fun background -> Frame.configure bar ~background);
coe meb, "Menubutton", (fun () -> ()),
- (fun background -> Menubutton.configure meb :background);
+ (fun background -> Menubutton.configure meb ~background);
coe but, "Button", (fun () -> ()),
- (fun background -> Button.configure but :background);
+ (fun background -> Button.configure but ~background);
coe can, "Canvas", (fun () -> ()),
- (fun background -> Canvas.configure can :background);
+ (fun background -> Canvas.configure can ~background);
coe che, "CheckButton", (fun () -> ()),
- (fun background -> Checkbutton.configure che :background);
+ (fun background -> Checkbutton.configure che ~background);
coe ent, "Entry", (fun () -> ()),
- (fun background -> Entry.configure ent :background);
+ (fun background -> Entry.configure ent ~background);
coe lab, "Label", (fun () -> ()),
- (fun background -> Label.configure lab :background);
+ (fun background -> Label.configure lab ~background);
coe lis, "Listbox", (fun () -> ()),
- (fun background -> Listbox.configure lis :background);
+ (fun background -> Listbox.configure lis ~background);
coe mes, "Message", (fun () -> ()),
- (fun background -> Message.configure mes :background);
+ (fun background -> Message.configure mes ~background);
coe radf, "Radiobox", (fun () -> ()),
(fun background ->
- List.iter rads f:(fun b -> Radiobutton.configure b :background));
+ List.iter rads ~f:(fun b -> Radiobutton.configure b ~background));
coe sca, "Scale", (fun () -> ()),
- (fun background -> Scale.configure sca :background);
+ (fun background -> Scale.configure sca ~background);
coe tex, "Text", (fun () -> ()),
- (fun background -> Text.configure tex :background);
+ (fun background -> Text.configure tex ~background);
coe scr, "Scrollbar", (fun () -> ()),
- (fun background -> Scrollbar.configure scr :background)
+ (fun background -> Scrollbar.configure scr ~background)
]
in
- pack buttons fill: `X;
+ pack buttons ~fill: `X;
(* Main Loop *)
Printexc.print mainLoop ()
diff --git a/otherlibs/labltk/example/eyes.ml b/otherlibs/labltk/example/eyes.ml
index eaa335809..7aeb1d583 100644
--- a/otherlibs/labltk/example/eyes.ml
+++ b/otherlibs/labltk/example/eyes.ml
@@ -20,23 +20,23 @@ let _ =
let top = openTk () in
let fw = Frame.create top in
pack [fw];
- let c = Canvas.create width: 200 height: 200 fw in
+ let c = Canvas.create ~width: 200 ~height: 200 fw in
let create_eye cx cy wx wy ewx ewy bnd =
let o2 = Canvas.create_oval
- x1:(cx - wx) y1:(cy - wy)
- x2:(cx + wx) y2:(cy + wy)
- outline: `Black width: 7
- fill: `White
+ ~x1:(cx - wx) ~y1:(cy - wy)
+ ~x2:(cx + wx) ~y2:(cy + wy)
+ ~outline: `Black ~width: 7
+ ~fill: `White
c
and o = Canvas.create_oval
- x1:(cx - ewx) y1:(cy - ewy)
- x2:(cx + ewx) y2:(cy + ewy)
- fill:`Black
+ ~x1:(cx - ewx) ~y1:(cy - ewy)
+ ~x2:(cx + ewx) ~y2:(cy + ewy)
+ ~fill:`Black
c in
let curx = ref cx
and cury = ref cy in
- bind events:[`Motion] extend:true fields:[`MouseX; `MouseY]
- action:(fun e ->
+ bind ~events:[`Motion] ~extend:true ~fields:[`MouseX; `MouseY]
+ ~action:(fun e ->
let nx, ny =
let xdiff = e.ev_MouseX - cx
and ydiff = e.ev_MouseY - cy in
@@ -48,7 +48,7 @@ let _ =
else
e.ev_MouseX, e.ev_MouseY
in
- Canvas.move canvas:c x: (nx - !curx) y: (ny - !cury) o;
+ Canvas.move ~canvas:c ~x: (nx - !curx) ~y: (ny - !cury) o;
curx := nx;
cury := ny)
c
diff --git a/otherlibs/labltk/example/hello.ml b/otherlibs/labltk/example/hello.ml
index 47d0201d1..603f62a8a 100644
--- a/otherlibs/labltk/example/hello.ml
+++ b/otherlibs/labltk/example/hello.ml
@@ -25,7 +25,7 @@ let top = openTk ()
(* create a button on top *)
(* Button.create : use of create function defined in button.ml *)
(* But you shouldn't open Button module for other widget class modules use *)
-let b = Button.create text: "Hello, LablTk!" top
+let b = Button.create ~text: "Hello, LablTk!" top
(* Lack of toplevel expressions in lsl, you must use dummy let exp. *)
let _ = pack [coe b]
diff --git a/otherlibs/labltk/example/tetris.ml b/otherlibs/labltk/example/tetris.ml
index 5e40c7d76..613c616f6 100644
--- a/otherlibs/labltk/example/tetris.ml
+++ b/otherlibs/labltk/example/tetris.ml
@@ -205,43 +205,43 @@ let line_full = int_of_string "0b1111111111111111"
let decode_block dvec =
let btoi d = int_of_string ("0b"^d) in
- Array.map f:btoi dvec
+ Array.map ~f:btoi dvec
-class cell t1 t2 t3 :canvas :x :y = object
+class cell t1 t2 t3 ~canvas ~x ~y = object
val mutable color = 0
method get = color
- method set color:col =
+ method set ~color:col =
if color = col then () else
if color <> 0 & col = 0 then begin
- Canvas.move t1 :canvas
- x:(- block_size * (x + 1) -10 - cell_border * 2)
- y:(- block_size * (y + 1) -10 - cell_border * 2);
- Canvas.move t2 :canvas
- x:(- block_size * (x + 1) -10 - cell_border * 2)
- y:(- block_size * (y + 1) -10 - cell_border * 2);
- Canvas.move t3 :canvas
- x:(- block_size * (x + 1) -10 - cell_border * 2)
- y:(- block_size * (y + 1) -10 - cell_border * 2)
+ Canvas.move t1 ~canvas
+ ~x:(- block_size * (x + 1) -10 - cell_border * 2)
+ ~y:(- block_size * (y + 1) -10 - cell_border * 2);
+ Canvas.move t2 ~canvas
+ ~x:(- block_size * (x + 1) -10 - cell_border * 2)
+ ~y:(- block_size * (y + 1) -10 - cell_border * 2);
+ Canvas.move t3 ~canvas
+ ~x:(- block_size * (x + 1) -10 - cell_border * 2)
+ ~y:(- block_size * (y + 1) -10 - cell_border * 2)
end else begin
- Canvas.configure_rectangle t2 :canvas
- fill: colors.(col - 1)
- outline: colors.(col - 1);
- Canvas.configure_rectangle t1 :canvas
- fill: `Black
- outline: `Black;
- Canvas.configure_rectangle t3 :canvas
- fill: (`Color "light gray")
- outline: (`Color "light gray");
+ Canvas.configure_rectangle t2 ~canvas
+ ~fill: colors.(col - 1)
+ ~outline: colors.(col - 1);
+ Canvas.configure_rectangle t1 ~canvas
+ ~fill: `Black
+ ~outline: `Black;
+ Canvas.configure_rectangle t3 ~canvas
+ ~fill: (`Color "light gray")
+ ~outline: (`Color "light gray");
if color = 0 & col <> 0 then begin
- Canvas.move t1 :canvas
- x: (block_size * (x+1)+10+ cell_border*2)
- y: (block_size * (y+1)+10+ cell_border*2);
- Canvas.move t2 :canvas
- x: (block_size * (x+1)+10+ cell_border*2)
- y: (block_size * (y+1)+10+ cell_border*2);
- Canvas.move t3 :canvas
- x: (block_size * (x+1)+10+ cell_border*2)
- y: (block_size * (y+1)+10+ cell_border*2)
+ Canvas.move t1 ~canvas
+ ~x: (block_size * (x+1)+10+ cell_border*2)
+ ~y: (block_size * (y+1)+10+ cell_border*2);
+ Canvas.move t2 ~canvas
+ ~x: (block_size * (x+1)+10+ cell_border*2)
+ ~y: (block_size * (y+1)+10+ cell_border*2);
+ Canvas.move t3 ~canvas
+ ~x: (block_size * (x+1)+10+ cell_border*2)
+ ~y: (block_size * (y+1)+10+ cell_border*2)
end
end;
color <- col
@@ -249,13 +249,13 @@ end
let cell_get (c, cf) x y = cf.(y).(x) #get
-let cell_set (c, cf) :x :y :color =
+let cell_set (c, cf) ~x ~y ~color =
if x >= 0 & y >= 0 & Array.length cf > y & Array.length cf.(y) > x then
let cur = cf.(y).(x) in
- if cur#get = color then () else cur#set :color
+ if cur#get = color then () else cur#set ~color
-let create_base_matrix :cols :rows =
- let m = Array.create_matrix dimx:rows dimy:cols (0,0) in
+let create_base_matrix ~cols ~rows =
+ let m = Array.create_matrix ~dimx:rows ~dimy:cols (0,0) in
for x = 0 to cols - 1 do for y = 0 to rows - 1 do
m.(y).(x) <- (x,y)
done done;
@@ -267,81 +267,81 @@ let init fw =
and levv = Textvariable.create ()
and namev = Textvariable.create ()
in
- let f = Frame.create fw borderwidth: 2 in
- let c = Canvas.create f width: (block_size * 10)
- height: (block_size * 20)
- borderwidth: cell_border
- relief: `Sunken
- background: `Black
+ let f = Frame.create fw ~borderwidth: 2 in
+ let c = Canvas.create f ~width: (block_size * 10)
+ ~height: (block_size * 20)
+ ~borderwidth: cell_border
+ ~relief: `Sunken
+ ~background: `Black
and r = Frame.create f
and r' = Frame.create f in
- let nl = Label.create r text: "Next" font: "variable" in
- let nc = Canvas.create r width: (block_size * 4)
- height: (block_size * 4)
- borderwidth: cell_border
- relief: `Sunken
- background: `Black in
- let scl = Label.create r text: "Score" font: "variable" in
- let sc = Label.create r textvariable: scorev font: "variable" in
- let lnl = Label.create r text: "Lines" font: "variable" in
- let ln = Label.create r textvariable: linev font: "variable" in
- let levl = Label.create r text: "Level" font: "variable" in
- let lev = Label.create r textvariable: levv font: "variable" in
- let newg = Button.create r text: "New Game" font: "variable" in
+ let nl = Label.create r ~text: "Next" ~font: "variable" in
+ let nc = Canvas.create r ~width: (block_size * 4)
+ ~height: (block_size * 4)
+ ~borderwidth: cell_border
+ ~relief: `Sunken
+ ~background: `Black in
+ let scl = Label.create r ~text: "Score" ~font: "variable" in
+ let sc = Label.create r ~textvariable: scorev ~font: "variable" in
+ let lnl = Label.create r ~text: "Lines" ~font: "variable" in
+ let ln = Label.create r ~textvariable: linev ~font: "variable" in
+ let levl = Label.create r ~text: "Level" ~font: "variable" in
+ let lev = Label.create r ~textvariable: levv ~font: "variable" in
+ let newg = Button.create r ~text: "New Game" ~font: "variable" in
pack [f];
- pack [coe c; coe r; coe r'] side: `Left fill: `Y;
- pack [coe nl; coe nc] side: `Top;
+ pack [coe c; coe r; coe r'] ~side: `Left ~fill: `Y;
+ pack [coe nl; coe nc] ~side: `Top;
pack [coe scl; coe sc; coe lnl; coe ln; coe levl; coe lev; coe newg]
- side: `Top;
+ ~side: `Top;
- let cells_src = create_base_matrix cols:field_width rows:field_height in
+ let cells_src = create_base_matrix ~cols:field_width ~rows:field_height in
let cells =
- Array.map cells_src f:
- (Array.map f:
+ Array.map cells_src ~f:
+ (Array.map ~f:
begin fun (x,y) ->
let t1 =
Canvas.create_rectangle c
- x1:(-block_size - 8) y1:(-block_size - 8)
- x2:(-9) y2:(-9)
+ ~x1:(-block_size - 8) ~y1:(-block_size - 8)
+ ~x2:(-9) ~y2:(-9)
and t2 =
Canvas.create_rectangle c
- x1:(-block_size - 10) y1:(-block_size - 10)
- x2:(-11) y2:(-11)
+ ~x1:(-block_size - 10) ~y1:(-block_size - 10)
+ ~x2:(-11) ~y2:(-11)
and t3 =
Canvas.create_rectangle c
- x1:(-block_size - 12) y1:(-block_size - 12)
- x2:(-13) y2:(-13)
+ ~x1:(-block_size - 12) ~y1:(-block_size - 12)
+ ~x2:(-13) ~y2:(-13)
in
- Canvas.raise canvas:c t1;
- Canvas.raise canvas:c t2;
- Canvas.lower canvas:c t3;
- new cell canvas:c :x :y t1 t2 t3
+ Canvas.raise ~canvas:c t1;
+ Canvas.raise ~canvas:c t2;
+ Canvas.lower ~canvas:c t3;
+ new cell ~canvas:c ~x ~y t1 t2 t3
end)
in
- let nexts_src = create_base_matrix cols:4 rows:4 in
+ let nexts_src = create_base_matrix ~cols:4 ~rows:4 in
let nexts =
- Array.map nexts_src f:
- (Array.map f:
+ Array.map nexts_src ~f:
+ (Array.map ~f:
begin fun (x,y) ->
let t1 =
Canvas.create_rectangle nc
- x1:(-block_size - 8) y1:(-block_size - 8)
- x2:(-9) y2:(-9)
+ ~x1:(-block_size - 8) ~y1:(-block_size - 8)
+ ~x2:(-9) ~y2:(-9)
and t2 =
Canvas.create_rectangle nc
- x1:(-block_size - 10) y1:(-block_size - 10)
- x2:(-11) y2:(-11)
+ ~x1:(-block_size - 10) ~y1:(-block_size - 10)
+ ~x2:(-11) ~y2:(-11)
and t3 =
Canvas.create_rectangle nc
- x1:(-block_size - 12) y1:(-block_size - 12)
- x2:(-13) y2:(-13)
+ ~x1:(-block_size - 12) ~y1:(-block_size - 12)
+ ~x2:(-13) ~y2:(-13)
in
- Canvas.raise canvas:nc t1;
- Canvas.raise canvas:nc t2;
- Canvas.lower canvas:nc t3;
- new cell canvas:nc :x :y t1 t2 t3
+ Canvas.raise ~canvas:nc t1;
+ Canvas.raise ~canvas:nc t2;
+ Canvas.lower ~canvas:nc t3;
+ new cell ~canvas:nc ~x ~y t1 t2 t3
end)
in
let game_over () = ()
@@ -352,13 +352,13 @@ let init fw =
newg, (c, cells), (nc, nexts), scorev, linev, levv, game_over
-let draw_block field :color :block :x :y =
+let draw_block field ~color ~block ~x ~y =
for iy = 0 to 3 do
let base = ref 1 in
let xd = block.(iy) in
for ix = 0 to 3 do
if xd land !base <> 0 then
- cell_set field x:(ix + x) y:(iy + y) :color;
+ cell_set field ~x:(ix + x) ~y:(iy + y) ~color;
base := !base lsl 1
done
done
@@ -372,8 +372,8 @@ let remove_timer () =
None -> ()
| Some t -> Timer.remove t (* ; prerr_endline "removed!" *)
-let do_after ms:milli do:f =
- timer_ref := Some (Timer.add ms: milli callback: f)
+let do_after ~ms ~callback =
+ timer_ref := Some (Timer.add ~ms ~callback)
let copy_block c =
{ pattern= !c.pattern;
@@ -388,13 +388,13 @@ let _ =
let lb = Label.create top
and fw = Frame.create top
in
- let set_message s = Label.configure lb text:s in
- pack [coe lb; coe fw] side: `Top;
+ let set_message s = Label.configure lb ~text:s in
+ pack [coe lb; coe fw] ~side: `Top;
let score = ref 0 in
let line = ref 0 in
let level = ref 0 in
let time = ref 1000 in
- let blocks = List.map f:(List.map f:decode_block) blocks in
+ let blocks = List.map ~f:(List.map ~f:decode_block) blocks in
let field = Array.create 26 0 in
let widgets, button, cell_field, next_field, scorev, linev, levv, game_over
= init fw in
@@ -407,27 +407,27 @@ let _ =
field.(23) <- line_full;
for i = 0 to 19 do
for j = 0 to 9 do
- cell_set cell_field x:j y:i color:0
+ cell_set cell_field ~x:j ~y:i ~color:0
done
done;
for i = 0 to 3 do
for j = 0 to 3 do
- cell_set next_field x:j y:i color:0
+ cell_set next_field ~x:j ~y:i ~color:0
done
done
in
let draw_falling_block fb =
- draw_block cell_field color: fb.bcolor
- block: (List.nth fb.pattern fb.d)
- x: (fb.x - 3)
- y: (fb.y - 3)
+ draw_block cell_field ~color: fb.bcolor
+ ~block: (List.nth fb.pattern fb.d)
+ ~x: (fb.x - 3)
+ ~y: (fb.y - 3)
and erase_falling_block fb =
- draw_block cell_field color: 0
- block: (List.nth fb.pattern fb.d)
- x: (fb.x - 3)
- y: (fb.y - 3)
+ draw_block cell_field ~color: 0
+ ~block: (List.nth fb.pattern fb.d)
+ ~x: (fb.x - 3)
+ ~y: (fb.y - 3)
in
let stone fb =
@@ -449,7 +449,7 @@ let _ =
incr l;
field.(i + fb.y) <- line_empty;
for j = 0 to 9 do
- cell_set cell_field x:j y:(i + fb.y - 3) color:0
+ cell_set cell_field ~x:j ~y:(i + fb.y - 3) ~color:0
done
end
done;
@@ -467,8 +467,8 @@ let _ =
done;
field.(!cur) <- field.(!eye);
for j = 0 to 9 do
- cell_set cell_field x:j y:(!cur-3)
- color:(cell_get cell_field j (!eye-3))
+ cell_set cell_field ~x:j ~y:(!cur-3)
+ ~color:(cell_get cell_field j (!eye-3))
done;
decr eye;
decr cur
@@ -477,7 +477,7 @@ let _ =
for i = 3 to !cur do
field.(i) <- line_empty;
for j = 0 to 9 do
- cell_set cell_field x:j y:(i-3) color:0
+ cell_set cell_field ~x:j ~y:(i-3) ~color:0
done
done
in
@@ -488,14 +488,14 @@ let _ =
in
let draw_next () =
- draw_block next_field color: (!next+1)
- block: (List.hd (List.nth blocks !next))
- x: 0 y: 0
+ draw_block next_field ~color: (!next+1)
+ ~block: (List.hd (List.nth blocks !next))
+ ~x: 0 ~y: 0
and erase_next () =
- draw_block next_field color: 0
- block: (List.hd (List.nth blocks !next))
- x: 0 y: 0
+ draw_block next_field ~color: 0
+ ~block: (List.hd (List.nth blocks !next))
+ ~x: 0 ~y: 0
in
let set_nextblock () =
@@ -548,15 +548,15 @@ let _ =
let image_load =
let i = Canvas.create_image canvas
- x: (block_size * 5 + block_size / 2)
- y: (block_size * 10 + block_size / 2)
- anchor: `Center in
- Canvas.lower :canvas i;
+ ~x: (block_size * 5 + block_size / 2)
+ ~y: (block_size * 10 + block_size / 2)
+ ~anchor: `Center in
+ Canvas.lower ~canvas i;
let img = Imagephoto.create () in
fun file ->
try
- Imagephoto.configure img file: file;
- Canvas.configure_image :canvas i image: img
+ Imagephoto.configure img ~file: file;
+ Canvas.configure_image ~canvas i ~image: img
with
_ ->
begin
@@ -603,7 +603,7 @@ let _ =
begin
time := 1100 - (!level / 4 * 300) - ((!level mod 4) * 200);
if !time < 60 - !level * 3 then time := 60 - !level * 3;
- do_after ms:stop_a_bit do:loop
+ do_after ~ms:stop_a_bit ~callback:loop
end
and loop () =
@@ -613,15 +613,15 @@ let _ =
begin
!current.alive <- false;
stone !current;
- do_after ms:stop_a_bit do:
+ do_after ~ms:stop_a_bit ~callback:
begin fun () ->
let l = clear !current in
if l > 0 then
- do_after ms:stop_a_bit do:
+ do_after ~ms:stop_a_bit ~callback:
begin fun () ->
fall_lines ();
add_score l;
- do_after ms:stop_a_bit do:newblock
+ do_after ~ms:stop_a_bit ~callback:newblock
end
else
newblock ()
@@ -632,12 +632,12 @@ let _ =
erase_falling_block !current;
draw_falling_block m;
current := m;
- do_after ms:!time do:loop
+ do_after ~ms:!time ~callback:loop
end
in
let bind_game w =
- bind w events:[`KeyPress] fields:[`KeySymString] action:
+ bind w ~events:[`KeyPress] ~fields:[`KeySymString] ~action:
begin fun e ->
match e.ev_KeySymString with
| "h" ->
@@ -696,12 +696,12 @@ let _ =
set_message "Welcome to TETRIS";
set_nextblock ();
draw_falling_block !current;
- do_after ms:!time do:loop
+ do_after ~ms:!time ~callback:loop
in
(* As an applet, it was required... *)
(* List.iter f: bind_game widgets; *)
bind_game top;
- Button.configure button command: game_init;
+ Button.configure button ~command: game_init;
game_init ()
let _ = Printexc.print mainLoop ()