about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-06-28 10:50:50 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-06-28 10:50:50 -0700
commit65be4e4cc8fa9397d4b12f86ffa4ee37c48553fe (patch)
tree57d8e22bda557fa963b4cd5eb08451203681c212
parentdd0846dc4efffbf1467af457d84c70f5a86a8583 (diff)
downloadmu-65be4e4cc8fa9397d4b12f86ffa4ee37c48553fe.tar.gz
1672 - begin support for multiple editors at once
-rw-r--r--050scenario.cc2
-rw-r--r--edit.mu47
2 files changed, 44 insertions, 5 deletions
diff --git a/050scenario.cc b/050scenario.cc
index 5ca64b48..5010aa86 100644
--- a/050scenario.cc
+++ b/050scenario.cc
@@ -132,7 +132,7 @@ const scenario* Current_scenario = NULL;
 void run_mu_scenario(const scenario& s) {
   Current_scenario = &s;
   bool not_already_inside_test = !Trace_stream;
-//?   cerr << s.name << '\n'; //? 5
+//?   cerr << s.name << '\n'; //? 6
   if (not_already_inside_test) {
     Trace_file = s.name;
     Trace_stream = new trace_stream;
diff --git a/edit.mu b/edit.mu
index 6046f454..c38002e5 100644
--- a/edit.mu
+++ b/edit.mu
@@ -48,6 +48,9 @@ container editor-data [
   # raw screen coordinates of cursor
   cursor-row:number
   cursor-column:number
+
+  # pointer to another editor, responsible for a different area of screen
+  next-editor:address:editor-data
 ]
 
 # editor:address, screen:address <- new-editor s:address:array:character, screen:address, top:number, left:number, bottom:number
@@ -80,6 +83,8 @@ recipe new-editor [
   x:address:number <- get-address result:address:editor-data/deref, cursor-row:offset
   x:address:number/deref <- copy top:number
   x:address:number <- get-address result:address:editor-data/deref, cursor-column:offset
+#?   $print left:number, [ 
+#? ] #? 1
   x:address:number/deref <- copy left:number
   d:address:address:duplex-list <- get-address result:address:editor-data/deref, data:offset
   d:address:address:duplex-list/deref <- push-duplex 167:literal/§, 0:literal/tail
@@ -356,7 +361,7 @@ scenario editor-initializes-empty-text [
   ]
 ]
 
-## handling events from the keyboard and mouse
+## handling events from the keyboard, mouse, touch screen, ...
 
 recipe event-loop [
   default-space:address:array:location <- new location:type, 30:literal
@@ -369,10 +374,11 @@ recipe event-loop [
     loop-unless found?:boolean
     break-if quit?:boolean  # only in tests
     trace [app], [next-event]
-    # mouse clicks
+    # 'touch' event
     {
       t:address:touch-event <- maybe-convert e:event, touch:variant
       break-unless t:address:touch-event
+#?       $print [aaa: touch] #? 1
       editor:address:editor-data <- move-cursor-in-editor editor:address:editor-data, t:address:touch-event/deref
       loop +next-event:label
     }
@@ -457,16 +463,24 @@ recipe move-cursor-in-editor [
   click-column:number <- get t:touch-event, column:offset
   left:number <- get editor:address:editor-data/deref, left:offset
   too-far-left?:boolean <- lesser-than click-column:number, left:number
-  reply-if too-far-left?:boolean, editor:address:editor-data/same-as-ingredient:0
+  jump-if too-far-left?:boolean, +try-next:label
   right:number <- get editor:address:editor-data/deref, right:offset
   too-far-right?:boolean <- greater-than click-column:number, right:number
-  reply-if too-far-right?:boolean, editor:address:editor-data/same-as-ingredient:0
+  jump-if too-far-right?:boolean, +try-next:label
   # update cursor
   cursor-row:address:number <- get-address editor:address:editor-data/deref, cursor-row:offset
   cursor-row:address:number/deref <- get t:touch-event, row:offset
   cursor-column:address:number <- get-address editor:address:editor-data/deref, cursor-column:offset
   cursor-column:address:number/deref <- get t:touch-event, column:offset
   render editor:address:editor-data
+  +try-next
+  {
+    next-editor:address:editor-data <- get editor:address:editor-data/deref, next-editor:offset
+#?     $print next-editor:address:editor-data, [ 
+#? ] #? 1
+    break-unless next-editor:address:editor-data
+    move-cursor-in-editor next-editor:address:editor-data, t:touch-event
+  }
   reply editor:address:editor-data/same-as-ingredient:0
 ]
 
@@ -1003,6 +1017,31 @@ d]
   ]
 ]
 
+scenario point-at-multiple-editors [
+  assume-screen 10:literal/width, 5:literal/height
+  # initialize an editor covering left half of screen
+  1:address:array:character <- new [abc]
+  2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0:literal/top, 0:literal/left, 5:literal/right
+  3:address:array:character <- new [def]
+  # chain new editor to it, covering the right half of the screen
+  4:address:address:editor-data <- get-address 2:address:editor-data/deref, next-editor:offset
+  4:address:address:editor-data/deref <- new-editor 3:address:array:character, screen:address, 0:literal/top, 5:literal/left, 10:literal/right
+  # type one letter in each of them
+  assume-console [
+    left-click 0, 1
+    left-click 0, 8
+  ]
+  run [
+    event-loop screen:address, console:address, 2:address:editor-data
+    5:number <- get 2:address:editor-data/deref, cursor-column:offset
+    6:number <- get 4:address:address:editor-data/deref/deref, cursor-column:offset
+  ]
+  memory-should-contain [
+    5 <- 1
+    6 <- 8
+  ]
+]
+
 ## helpers for drawing editor borders
 
 recipe draw-box [