about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-06-08 12:25:25 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-06-08 12:25:25 -0700
commit9fae66572d2fd3ddce43348a5c480aaa64791635 (patch)
tree5a2163c71741f427baa9d242a83c79444e824ae1
parentb1ce29ddee9d95d7efa668c26de07b0b3ab48dea (diff)
downloadmu-9fae66572d2fd3ddce43348a5c480aaa64791635.tar.gz
1545 - sketching out a simple editor widget
-rw-r--r--070display.cc22
-rw-r--r--071print.mu28
-rw-r--r--edit.mu81
3 files changed, 131 insertions, 0 deletions
diff --git a/070display.cc b/070display.cc
index 74440b7c..61d7c0bc 100644
--- a/070display.cc
+++ b/070display.cc
@@ -197,6 +197,28 @@ case MOVE_CURSOR_LEFT_ON_DISPLAY: {
   break;
 }
 
+:(before "End Primitive Recipe Declarations")
+DISPLAY_WIDTH,
+:(before "End Primitive Recipe Numbers")
+Recipe_number["display-width"] = DISPLAY_WIDTH;
+:(before "End Primitive Recipe Implementations")
+case DISPLAY_WIDTH: {
+  products.resize(1);
+  products.at(0).push_back(tb_width());
+  break;
+}
+
+:(before "End Primitive Recipe Declarations")
+DISPLAY_HEIGHT,
+:(before "End Primitive Recipe Numbers")
+Recipe_number["display-height"] = DISPLAY_HEIGHT;
+:(before "End Primitive Recipe Implementations")
+case DISPLAY_HEIGHT: {
+  products.resize(1);
+  products.at(0).push_back(tb_height());
+  break;
+}
+
 //:: Keyboard management
 
 :(before "End Primitive Recipe Declarations")
diff --git a/071print.mu b/071print.mu
index db7c97d1..6eb72853 100644
--- a/071print.mu
+++ b/071print.mu
@@ -416,6 +416,34 @@ recipe cursor-to-next-line [
   reply x:address:screen/same-as-ingredient:0
 ]
 
+recipe screen-width [
+  default-space:address:array:location <- new location:type, 30:literal
+  x:address:screen <- next-ingredient
+  # if x exists, move cursor in fake screen
+  {
+    break-unless x:address:screen
+    width:number <- get x:address:screen/deref, num-columns:offset
+    reply width:number
+  }
+  # otherwise, real screen
+  width:number <- display-width
+  reply width:number
+]
+
+recipe screen-height [
+  default-space:address:array:location <- new location:type, 30:literal
+  x:address:screen <- next-ingredient
+  # if x exists, move cursor in fake screen
+  {
+    break-unless x:address:screen
+    height:number <- get x:address:screen/deref, num-rows:offset
+    reply height:number
+  }
+  # otherwise, real screen
+  height:number <- display-height
+  reply height:number
+]
+
 recipe print-string [
   default-space:address:array:location <- new location:type, 30:literal
   x:address:screen <- next-ingredient
diff --git a/edit.mu b/edit.mu
new file mode 100644
index 00000000..687a1661
--- /dev/null
+++ b/edit.mu
@@ -0,0 +1,81 @@
+recipe main [
+  default-space:address:array:location <- new location:type, 30:literal
+  switch-to-display
+  draw-bounding-box 0:literal/screen, 5:literal, 5:literal, 30:literal, 45:literal
+  wait-for-key-from-keyboard
+  return-to-console
+]
+
+recipe draw-bounding-box [
+  default-space:address:array:location <- new location:type, 30:literal
+  screen:address <- next-ingredient
+  top:number <- next-ingredient
+  {
+    out?:boolean <- lesser-than top:number, 0:literal
+    break-unless out?:boolean
+    top:number <- copy 0:literal
+  }
+  left:number <- next-ingredient
+  {
+    out?:boolean <- lesser-than left:number, 0:literal
+    break-unless out?:boolean
+    left:number <- copy 0:literal
+  }
+  bottom:number <- next-ingredient
+  {
+    height:number <- screen-height screen:address
+    out?:boolean <- greater-or-equal bottom:number, height:number
+    break-unless out?:boolean
+    bottom:number <- subtract height:number, 1:literal
+  }
+  right:number <- next-ingredient
+  {
+    width:number <- screen-width screen:address
+    out?:boolean <- greater-or-equal right:number, width:number
+    break-unless out?:boolean
+    right:number <- subtract width:number, 1:literal
+  }
+#?   print-integer screen:address, bottom:number
+#?   print-character screen:address, 32:literal/space
+#?   print-integer screen:address, right:number
+  # top border
+  move-cursor screen:address, top:number, left:number
+  print-character screen:address, 9484:literal/down-right, 245:literal/grey
+  x:number <- add left:number, 1:literal  # exclude corner
+  {
+    continue?:boolean <- lesser-than x:number, right:number
+    break-unless continue?:boolean
+    print-character screen:address, 9472:literal/horizontal, 245:literal/grey
+    x:number <- add x:number, 1:literal
+    loop
+  }
+  print-character screen:address, 9488:literal/down-left, 245:literal/grey
+  # bottom border
+  move-cursor screen:address, bottom:number, left:number
+  print-character screen:address, 9492:literal/up-right, 245:literal/grey
+  x:number <- add left:number, 1:literal  # exclude corner
+  {
+    continue?:boolean <- lesser-than x:number, right:number
+    break-unless continue?:boolean
+    print-character screen:address, 9472:literal/horizontal, 245:literal/grey
+    x:number <- add x:number, 1:literal
+    loop
+  }
+  print-character screen:address, 9496:literal/up-left, 245:literal/grey
+  # left and right borders
+  x:number <- add top:number, 1:literal  # exclude corner
+  {
+    continue?:boolean <- lesser-than x:number, bottom:number
+    break-unless continue?:boolean
+    move-cursor screen:address, x:number, left:number
+    print-character screen:address, 9474:literal/vertical, 245:literal/grey
+    move-cursor screen:address, x:number, right:number
+    print-character screen:address, 9474:literal/vertical, 245:literal/grey
+    x:number <- add x:number, 1:literal
+    loop
+  }
+  # position cursor inside box
+  move-cursor screen:address, top:number, left:number
+  cursor-down screen:address
+  cursor-right screen:address
+]