Commits

Paweł Wieczorek committed 005cdfd Draft

added utility clickMap

Comments (0)

Files changed (2)

src/Util/ClickMap.ml

+(*pp $PP *)
+(**************************************************************************
+ * PixLand
+ *   Copyrights 2012 by Pawel Wieczorek <wieczyk gmail com>
+ *)
+
+(**************************************************************************
+ * Types
+ *)
+
+type rect = int * int * int * int
+
+type 'a clickMap = (rect * 'a) list
+
+(**************************************************************************
+ * Methods
+ *)
+
+let empty = []
+
+let is_empty cmap = List.length cmap == 0
+
+let add_rect rect a cmap = (rect,a) :: cmap
+
+let rem_rect rect cmap = 
+  let p (rect', _) = rect <> rect' in
+  List.filter p cmap
+
+
+let find_clicked (mx,my) cmap = 
+  let in_range a b c = a <= c && c <= b in
+  let p ( (x',y',w',h'), _ ) = 
+    in_range x' w' mx && in_range y' h' my in
+  match List.filter p cmap with
+    | [] -> None
+    | (_,x)::xs -> Some x
+
+

src/Util/ClickMap.mli

+(**************************************************************************
+ * PixLand
+ *   Copyrights 2012 by Pawel Wieczorek <wieczyk gmail com>
+ *)
+
+(**************************************************************************
+ * Types
+ *)
+
+type rect = int * int * int * int
+
+type 'a clickMap
+
+
+(**************************************************************************
+ * 
+ *)
+
+val empty : 'a clickMap
+
+val is_empty : 'a clickMap -> bool
+
+val add_rect : rect -> 'a -> 'a clickMap -> 'a clickMap
+
+val rem_rect : rect -> 'a clickMap  -> 'a clickMap
+
+val find_clicked : int * int -> 'a clickMap -> 'a option