added value tweaking (v1) + polished display for buttons
This commit is contained in:
parent
c53fd564a2
commit
ad821ca28f
10
csts.ml
10
csts.ml
|
@ -12,11 +12,19 @@ let default_rect = {
|
|||
h = 0 ;
|
||||
} ;;
|
||||
|
||||
(* graphing constants *)
|
||||
let __width__ = 1200
|
||||
and __height__ = 900 ;;
|
||||
let open_string = " 1200x900" ;;
|
||||
|
||||
(* camera *)
|
||||
let camx = ref 0
|
||||
and camy = ref 0 ;;
|
||||
|
||||
let sleep_d = 0.01 ;;
|
||||
(* time step *)
|
||||
let sleep_d = 0.01 ;;
|
||||
|
||||
(* math *)
|
||||
let difficulty = ref 1 ;;
|
||||
let calc_length = ref 3 ;;
|
||||
let time_to_ans = ref 10 ;;
|
BIN
drawing.cmi
BIN
drawing.cmi
Binary file not shown.
BIN
drawing.cmx
BIN
drawing.cmx
Binary file not shown.
|
@ -129,6 +129,13 @@ let draw_letter x y c len = match c with
|
|||
|
||||
let draw_string x0 y s len =
|
||||
let cur_x = ref x0 in
|
||||
for i = 0 to String.length s -1 do
|
||||
draw_letter !cur_x y s.[i] len;
|
||||
cur_x := !cur_x + (len*10/7)
|
||||
done;;
|
||||
|
||||
let draw_string_centered x0 y s len =
|
||||
let cur_x = ref (x0 - (len*10/7)*(int_of_float ((float_of_int (String.length s)) /. 2.))) in
|
||||
for i = 0 to String.length s -1 do
|
||||
draw_letter !cur_x y s.[i] len;
|
||||
cur_x := !cur_x + (len*10/7)
|
||||
|
|
BIN
dynamic.cmx
BIN
dynamic.cmx
Binary file not shown.
74
menus.ml
74
menus.ml
|
@ -119,6 +119,13 @@ let build_interface (title : string) (red : int) (green : int) (blue : int) (but
|
|||
Dynamic.dyn_add arr_interfaces res ;
|
||||
incr current_interface_index ;;
|
||||
|
||||
let build_tweak (ptr : int ref) (m : int) (mx : int) (st : int) = {
|
||||
ptr = ptr ;
|
||||
min = m;
|
||||
max = mx ;
|
||||
pad = st ;
|
||||
} ;;
|
||||
|
||||
(* --------------------------------------------------------------------------------------------------------------------------------------------- *)
|
||||
let current_it_id = ref 0 ;;
|
||||
(* --------------------------------------------------------------------------------------------------------------------------------------------- *)
|
||||
|
@ -135,7 +142,15 @@ let add_button_to_current (b_id : int) =
|
|||
(* --------------------------------------------------------------------------------------------------------------------------------------------- *)
|
||||
(* printing *)
|
||||
|
||||
let is_within (r : Csts.rect) (x : int) (y : int) =
|
||||
r.x <= x && r.y < y && x <= r.x + r.w && y <= r.y + r.h ;;
|
||||
|
||||
let print_button (b : button) =
|
||||
let (mx, my) = mouse_pos () in
|
||||
if is_within b.pos mx my then begin
|
||||
set_color (rgb 0 0 255) ;
|
||||
fill_rect (b.pos.x-6) (b.pos.y-6) (b.pos.w+12) (b.pos.h+12) ;
|
||||
end;
|
||||
set_color (rgb b.red b.green b.blue) ;
|
||||
fill_rect b.pos.x b.pos.y b.pos.w b.pos.h ;
|
||||
set_color (rgb (255 - b.red) (255 - b.green) (255 - b.blue)) ;
|
||||
|
@ -154,15 +169,35 @@ let print_current_interface () =
|
|||
(* --------------------------------------------------------------------------------------------------------------------------------------------- *)
|
||||
(* actions *)
|
||||
|
||||
let is_within (r : Csts.rect) (x : int) (y : int) =
|
||||
r.x <= x && r.y < y && x <= r.x + r.w && y <= r.y + r.h ;;
|
||||
let get1char () =
|
||||
if key_pressed () then
|
||||
read_key ()
|
||||
else
|
||||
'@' ;;
|
||||
|
||||
let move_interface (b : button) = match b.actn with
|
||||
| Nothing -> ()
|
||||
| Tweak (vc) -> begin
|
||||
| Tweak val_ptr -> begin
|
||||
let halted = ref false in
|
||||
set_line_width 3 ;
|
||||
while not !halted do
|
||||
(* todo *)()
|
||||
auto_synchronize false ;
|
||||
set_color black ;
|
||||
fill_rect (3*Csts.__width__/10) (3*Csts.__height__/10) (2*Csts.__width__/5) (2*Csts.__height__/5) ;
|
||||
set_color white ;
|
||||
Drawing.draw_string_centered (Csts.__width__/2) (13*Csts.__height__/20) b.text 20 ;
|
||||
Drawing.draw_integer (5+Csts.__width__/2) (Csts.__height__/2) !(val_ptr.ptr) 40 ;
|
||||
Drawing.draw_string (5+3*Csts.__width__/10) (11*Csts.__height__/20) "Min" 20 ;
|
||||
Drawing.draw_integer_alignedleft (5+3*Csts.__width__/10) (Csts.__height__/2) val_ptr.min 18 ;
|
||||
Drawing.draw_string (7*Csts.__width__/10-5-3*20*10/7) (11*Csts.__height__/20) "Max" 20 ;
|
||||
Drawing.draw_integer_alignedleft (7*Csts.__width__/10-5-3*20*10/7) (Csts.__height__/2) val_ptr.max 18 ;
|
||||
auto_synchronize true ;
|
||||
Unix.sleepf Csts.sleep_d ;
|
||||
match get1char () with
|
||||
| '+' -> val_ptr.ptr := min val_ptr.max (!(val_ptr.ptr) + val_ptr.pad)
|
||||
| '-' -> val_ptr.ptr := max val_ptr.min (!(val_ptr.ptr) - val_ptr.pad)
|
||||
| '\n' | ' ' -> halted := true
|
||||
| _ -> ()
|
||||
done
|
||||
end
|
||||
| Warp ne -> if ne = -1 then raise MenuExit else current_it_id := ne ;;
|
||||
|
@ -176,16 +211,25 @@ let action_on_button (mox : int) (moy : int) (b : button) =
|
|||
else
|
||||
false ;;
|
||||
|
||||
let stall = ref false ;;
|
||||
|
||||
let action_on_interface () =
|
||||
if button_down () then begin
|
||||
let (mox, moy) = mouse_pos () in
|
||||
let rec aux = function
|
||||
| [] -> ()
|
||||
| b::t ->
|
||||
if action_on_button mox moy b then () else aux t
|
||||
in
|
||||
aux (Dynamic.dyn_mem arr_interfaces !current_it_id).bts
|
||||
end ;;
|
||||
if !stall then
|
||||
()
|
||||
else begin
|
||||
stall := true ;
|
||||
let (mox, moy) = mouse_pos () in
|
||||
let rec aux = function
|
||||
| [] -> ()
|
||||
| b::t ->
|
||||
if action_on_button mox moy b then () else aux t
|
||||
in
|
||||
aux (Dynamic.dyn_mem arr_interfaces !current_it_id).bts
|
||||
end
|
||||
end
|
||||
else
|
||||
stall := false ;;
|
||||
|
||||
(* --------------------------------------------------------------------------------------------------------------------------------------------- *)
|
||||
(* Define the menu there *)
|
||||
|
@ -195,9 +239,9 @@ build_empty_interface "Options " 32 32 32 ;;
|
|||
|
||||
build_button "Options" {x = Csts.__width__/2 - 150; y = 160; w = 300; h = 100} 255 32 255 (Warp 1) ;;
|
||||
build_button "Exit" {x = Csts.__width__/2 - 150; y = 50; w = 300; h = 100} 1 1 1 (Warp (-1)) ;;
|
||||
build_button "Operations" {x = Csts.__width__/2 - 150; y = 380; w = 300; h = 100} 255 32 32 Nothing ;;
|
||||
build_button "Time" {x = Csts.__width__/2 - 150; y = 270; w = 300; h = 100} 32 255 32 Nothing ;;
|
||||
build_button "Difficulty" {x = Csts.__width__/2 - 150; y = 160; w = 300; h = 100} 32 32 255 Nothing ;;
|
||||
build_button "Length" {x = Csts.__width__/2 - 150; y = 380; w = 300; h = 100} 255 32 32 (Tweak (build_tweak Csts.calc_length 2 20 1)) ;;
|
||||
build_button "Time" {x = Csts.__width__/2 - 150; y = 270; w = 300; h = 100} 32 255 32 (Tweak (build_tweak Csts.time_to_ans 3 30 1)) ;;
|
||||
build_button "Difficulty" {x = Csts.__width__/2 - 150; y = 160; w = 300; h = 100} 32 32 255 (Tweak (build_tweak Csts.difficulty 1 10 1)) ;;
|
||||
build_button "Back" {x = Csts.__width__/2 - 150; y = 50; w = 300; h = 100} 32 32 32 (Warp 0) ;;
|
||||
|
||||
(*Printf.printf "(B : %d ; I : %d)\n" arr_buttons.len arr_interfaces.len ;;*)
|
||||
|
|
Loading…
Reference in New Issue