Commits

Paweł Wieczorek committed d2c2c84 Draft

UI_Button

Comments (0)

Files changed (3)

 
 let narrow_rect (x,y,w,h) c = (x+c, y+c, w-c-c, h-c-c)
 
+let move_down   (x,y,w,h) c = (x, y + c, w, h)
+let move_up     (x,y,w,h) c = (x, y - c, w, h)
+let move_left   (x,y,w,h) c = (x - c, y, w, h)
+let move_right  (x,y,w,h) c = (x + c, y, w, h)
+
+let set_height  (x,y,w,h) c = (x,y,w,c)
+
 (**************************************************************************
  * Defined colors
  * http://en.wikipedia.org/wiki/List_of_colors
   let border_color      = Color.ash_grey
   let border_light      = Color.white
   let border_dark       = Color.black
-  let button_bg_color   = Color.cadet_grey
+  let button_bg_color   = Color.auro_metal_saurus
   let text_color        = bg_color
 (*  let frame_color      = from_hex 0x6e7f80 *)
 end

src/UI/UI_Button.ml

  *   Copyrights 2012 by Pawel Wieczorek <wieczyk gmail com>
  *)
 
+open Video;;
 open UI;;
+open UI_Frame;;
 
 (**************************************************************************
  * Types
  *)
 
+type button_params =
+  { background_color : color
+  ; text_color       : color
+  }
+
+(**************************************************************************
+ * Constants
+ *)
+
+let default_params =
+  { background_color = UIColor.button_bg_color
+  ; text_color       = UIColor.text_color
+  }
 
 (**************************************************************************
  * 
  *)
 
-let draw_button_ bor_color bg_color text_color text (x, y, w, h) surface =
-    let rc = (x,y,w,h) in
+let mk_frame_params params =
+    let fp = UI_Frame.default_params in
+    {fp with border_size = 1
+    ; UI_Frame.background_color = params.background_color
+    }
+
+let draw_button params text (x, y, w, h) surface =
+    let fparams = mk_frame_params params in
+    draw_frame fparams (x,y,w,h) surface;
     ()
-
-let draw_button text rc surface =
-    draw_button_ UIColor.border_color UIColor.button_bg_color UIColor.text_color text rc surface
-

src/View/MainView.ml

  *)
 
 open View;;
-
+open UI;;
 (**************************************************************************
  * Types
  *)
   let padding_ver = (width - menu_width ) / 2 in
   let padding_hor = (height - menu_height ) / 2 in
   let rc          = (padding_ver, padding_hor, menu_width, menu_height) in
-  UI_Frame.draw_frame UI_Frame.default_params rc surface;
+  let rcb         = set_height (narrow_rect rc 10) 50 in
+  UI_Frame.draw_frame   UI_Frame.default_params rc surface;
+  UI_Button.draw_button UI_Button.default_params "Play" rcb surface;
+  let rcb         = move_down rcb (50+10) in
+  UI_Button.draw_button UI_Button.default_params "Play" rcb surface;
   Continue
 
 let _view_keydown state = function