Commits

Paweł Wieczorek committed e2fcab7 Draft

record subviews in mainscreen

  • Participants
  • Parent commits 3eb3b5c

Comments (0)

Files changed (7)

 .
 src
+src/View
+View
+
     src/World.ml\
     \
     src/View.ml\
+    src/View/MainView.mli\
     src/View/MainView.ml\
     src/View/GameView.ml\
     src/System.ml\
     src/Main.ml\
 
 all: native-code
-	echo ${PP}
+	echo ${PPPFLAGS}
 
 include $(OCAMLMAKEFILE)
 (*pp $PP *)
 
+open MainView;;
+
 System.init ()
 ;;
 
 let gameView = GameView.create_view2 (800, 600);;
-let mainView = MainView.create_view gameView;;
+let (mainView, subViews) = MainView.create_view ()
+;;
+subViews.play_view <- gameView;;
 
 System.run mainView;
 System.cleanup ()
   | Image i ->
       let image = Video.load_image i.name in
       let id    = MkImageId !fresh_id_int in
-      i.id <- id;
+      i.id    <- id;
       i.image <- Some image;
       fresh_id_int := succ !fresh_id_int
 
     ; view_keydown : Input.key -> view_action
     }
 
+(**************************************************************************
+ * Constants
+ *)
+
+let dummy_view =
+    { view_draw    = (fun _ -> Continue)
+    ; view_keydown = (fun _ -> Continue)
+    }

src/View/MainView.ml

  * Types
  *)
 
+type subviews =
+    { mutable play_view    : view_handle
+    ; mutable options_view : view_handle
+    }
+
 type state =
-    { mutable number : int
+    { subviews : subviews
     }
 
 (**************************************************************************
   Continue
 
 
-let _view_keydown state otherView = function
+let _view_keydown state = function
   | Sdlkey.KEY_ESCAPE ->
       ShutdownEngine
   | Sdlkey.KEY_F1 ->
-        ChangeView otherView
+        ChangeView state.subviews.play_view
   | _ ->
       Continue
 
  * Creator
  *)
 
-let create_view otherView =
-  let img'    = Video.load_image "main" in
-  let surface = Video._create_image (Video.get_global_surface ()) in
-  let img     = Video.scale_image_to img' surface in
-
-  let fresh_state = { number = 0 } in
-  
-  { view_draw    = _view_draw img fresh_state
-  ; view_keydown = _view_keydown fresh_state otherView
-  }    
+let create_view () =
+  let img'     = Video.load_image "main" in
+  let surface  = Video._create_image (Video.get_global_surface ()) in
+  let img      = Video.scale_image_to img' surface in
+  let fresh_state =
+    { subviews =
+        { play_view    = dummy_view
+        ; options_view = dummy_view
+        }
+    } in
+  let mainView =
+    { view_draw    = _view_draw img fresh_state
+    ; view_keydown = _view_keydown fresh_state 
+    } in
+  (mainView, fresh_state.subviews )

src/View/MainView.mli

 
 open View;;
 
+(**************************************************************************
+ * Types
+ *)
+
+type subviews =
+    { mutable play_view    : view_handle
+    ; mutable options_view : view_handle
+    }
+
+
  
 (**************************************************************************
  * Creator
  *)
 
-val create_view : view_handle -> view_handle
+val create_view : unit -> view_handle * subviews