diff --git a/csts.cmi b/csts.cmi index 138cc2c..a0fb49c 100644 Binary files a/csts.cmi and b/csts.cmi differ diff --git a/csts.cmx b/csts.cmx index 9adfd61..07e0755 100644 Binary files a/csts.cmx and b/csts.cmx differ diff --git a/csts.ml b/csts.ml index 4e01fb2..79d6855 100644 --- a/csts.ml +++ b/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 ;; \ No newline at end of file +(* time step *) +let sleep_d = 0.01 ;; + +(* math *) +let difficulty = ref 1 ;; +let calc_length = ref 3 ;; +let time_to_ans = ref 10 ;; \ No newline at end of file diff --git a/csts.o b/csts.o index 4e94ba8..0dad598 100644 Binary files a/csts.o and b/csts.o differ diff --git a/drawing.cmi b/drawing.cmi index b12852f..35ff7c0 100644 Binary files a/drawing.cmi and b/drawing.cmi differ diff --git a/drawing.cmx b/drawing.cmx index ba67b8b..c0210e0 100644 Binary files a/drawing.cmx and b/drawing.cmx differ diff --git a/drawing.ml b/drawing.ml index 6621796..df6418b 100644 --- a/drawing.ml +++ b/drawing.ml @@ -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) diff --git a/drawing.o b/drawing.o index d964567..0105c31 100644 Binary files a/drawing.o and b/drawing.o differ diff --git a/dynamic.cmx b/dynamic.cmx index a5e9210..ac45574 100644 Binary files a/dynamic.cmx and b/dynamic.cmx differ diff --git a/dynamic.o b/dynamic.o index 188c60e..eb90e3c 100644 Binary files a/dynamic.o and b/dynamic.o differ diff --git a/main.cmi b/main.cmi index ba264c0..3636734 100644 Binary files a/main.cmi and b/main.cmi differ diff --git a/main.cmx b/main.cmx index f281aa9..6878c9b 100644 Binary files a/main.cmx and b/main.cmx differ diff --git a/main.o b/main.o index 739d2db..1db3669 100644 Binary files a/main.o and b/main.o differ diff --git a/math b/math index 0483fec..0817605 100755 Binary files a/math and b/math differ diff --git a/math.cmx b/math.cmx index 991ac27..6a06f1e 100644 Binary files a/math.cmx and b/math.cmx differ diff --git a/math.o b/math.o index a2203e2..987d55b 100644 Binary files a/math.o and b/math.o differ diff --git a/menus.cmi b/menus.cmi index ff93623..2e6c492 100644 Binary files a/menus.cmi and b/menus.cmi differ diff --git a/menus.cmx b/menus.cmx index 4fd46eb..d2dd277 100644 Binary files a/menus.cmx and b/menus.cmx differ diff --git a/menus.ml b/menus.ml index 305b364..2959e86 100644 --- a/menus.ml +++ b/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 ;;*) diff --git a/menus.o b/menus.o index 893524c..499d44d 100644 Binary files a/menus.o and b/menus.o differ