]> git.plutz.net Git - confetti/blobdiff - templates/therapy.html.sh
enable closed shape drawing for haptic improvements
[confetti] / templates / therapy.html.sh
index 05c50fd157f8338afa524c325cfbc568048703d2..63216ad703ced7ce40ca7120f70d4362e2932c3a 100755 (executable)
@@ -33,8 +33,13 @@ t_session_note(){
     *)    c7=checked;;
   esac
 
+if [ "$note_n" -eq 1 -o -n "${tpy[session${session_n}_note${note_n}]}" ]; then
+  printf '<input class="trailbtn" type="checkbox" checked="checked">'
+else
+  printf '<input class="trailbtn" type="checkbox">'
+fi
 cat <<EOF
-  <fieldset class=note>
+  <fieldset class="note trailbox">
     <input class=color type=radio name="$color" value="#888" id=${color}_000 $c0><label for=${color}_000></label>
     <input class=color type=radio name="$color" value="#00A" id=${color}_001 $c1><label for=${color}_001></label>
     <input class=color type=radio name="$color" value="#0A0" id=${color}_010 $c2><label for=${color}_010></label>
@@ -54,16 +59,8 @@ t_session(){
   sid=session${session_n}
 
   if [ "$tpy[${sid}_sigset]" = pos ]; then
-    sig=neg
-    sigcheck=checked
-  elif [ "$tpy[${sid}_sigset]" = neg ]; then
-    sig=pos
-    unset sigcheck
-  elif [ "$tpy[${sid}_signature]" = pos ]; then
-    sig=neg
     sigcheck=checked
   else
-    sig=pos
     unset sigcheck
   fi
 
@@ -76,19 +73,13 @@ cat <<EOF
  --><input class="date" name="${sid}_date" value="${tpy[${sid}_date]}" placeholder="$(l10n date)"><!--
  --><span class=therapist>${tpy[${sid}_therapist]}</span><!--
  --><input class="therapist" name="${sid}_therapist" value="${tpy[${sid}_therapist]}" placeholder="$(l10n therapist)"><!--
- --><span class=signature><input type=checkbox name="${sid}_signature" value=pos $sigcheck><button type=submit name=${sid}_sigset value=$sig></button></span>
+ --><span class=signature><input type="checkbox" name="${sid}_sigset" value="pos" $sigcheck></span>
   </label>
   <div class=tab>
     <img class="dotmark ov" src="/therapies/${id%.tpy}_${sid}.png" alt="">
-    $(n=1; while [ -n "${tpy[${sid}_note${n}]+x}" ]; do
-      t_session_note $session_n $n
-      n=$(($n+1))
-    done
-    printf '<button type=submit name=%s_note%s value="">+</button>' "$sid" "$n"
-    )
+    $( for n in {1..50}; do t_session_note $session_n $n; done )
 
     <button class=delete type=submit name=delete_session value=${session_n}>$(l10n delete_session)</button>
-    <button type=submit>$(l10n save)</button>
   </div>
 EOF
 }
@@ -200,69 +191,108 @@ cat <<EOF
   <canvas id="canvas" class="dotmark ov" width="${bg_dim%x*}" height="${bg_dim#*x}"></canvas>
 
   <input type=hidden id=image_serialize name=imagedata value="">
-  <span id="jsdebug" style="display: none; position: fixed; right:0; bottom:0">Debug</span>
 
-  <script><!--
-  body = document.body
-  canvas = document.getElementById("canvas")
-  dbg = document.getElementById("jsdebug")
-  image = canvas.getContext("2d")
-  mouse = 0
-  image_serialize=""
-  data=document.getElementById("image_serialize")
-
-  function setcol(c) {
-    image.strokeStyle = c
-    if ( c == "#FFF" ) image.lineWidth = 32
-    else image.lineWidth = 4
-    image_serialize += " stroke " + c + " stroke-width " + image.lineWidth
-  }
+  <button type="submit">$(l10n save)</button>
+</form>
 
-  setcol("$tpy[color]")
-
-  function draw(x, y) {
-    if ( mouse == 1){
-      if ( body.clientWidth >= 800 ){
-        sx=Math.floor(cscaleW * (x - canvas.offsetLeft))
-        sy=Math.floor(cscaleH * (y - canvas.offsetTop))
-      } else { 
-        sx=Math.floor(cscaleW * (x - canvas.offsetLeft + window.pageXOffset))
-        sy=Math.floor(cscaleH * (y - canvas.offsetTop + window.pageYOffset))
-      }
-      image.lineTo( sx, sy )
-      image.stroke()
-
-      image_serialize += " " + sx + "," + sy
-    }
+<span id="jsdebug" style="display: none; position: fixed; right:0; bottom:0">Debug</span>
+
+<script><!--
+body = document.body
+dbg = document.getElementById("jsdebug")
+canvas = document.getElementById("canvas")
+data=document.getElementById("image_serialize")
+
+image = canvas.getContext("2d")
+mouse = 0
+image_serialize=""
+
+// start and current coordinates of a draw
+// serves for tracking, whether path ends close to its beginning
+stx=0, sty=0
+cux=0, cuy=0
+
+function setcol(c) {
+  this.c = c
+  image.strokeStyle = c
+  image.fillStyle =  c
+  if ( c == "#FFF" ) image.lineWidth = 32
+  else image.lineWidth = 4
+  data.value += " stroke " + c + " stroke-width " + image.lineWidth
+}
+
+setcol("$tpy[color]")
+
+function relX(x){
+  if ( body.clientWidth >= 800 ){
+    return Math.floor(cscaleW * (x - canvas.offsetLeft))
+  } else { 
+    return Math.floor(cscaleW * (x - canvas.offsetLeft + window.pageXOffset))
   }
+}
+function relY(y){
+  if ( body.clientWidth >= 800 ){
+    return Math.floor(cscaleH * (y - canvas.offsetTop))
+  } else { 
+    return Math.floor(cscaleH * (y - canvas.offsetTop + window.pageYOffset))
+  }
+}
 
-  function drawstart(x, y) {
-    mouse = 1
+function draw(x, y) {
+  if ( mouse == 1){
+    cux=relX(x), cuy=relY(y)
 
-    cscaleW = canvas.width / canvas.clientWidth
-    cscaleH = canvas.height / canvas.clientHeight
+    image.lineTo( cux, cuy )
+    image.stroke()
 
-    image_serialize += " polyline"
-    image.beginPath()
-    draw(x, y)
-  }
-  function drawstop() {
-   mouse = 0
-   image.closePath()
-   dbg.innerHTML = image_serialize
-   data.value = image_serialize
+    image_serialize += " " + cux + "," + cuy
   }
+}
 
-  window.addEventListener( 'mouseup',   function()   { drawstop() } )
-  canvas.addEventListener( 'mousedown', function(e)  { drawstart(e.clientX, e.clientY) } )
-  canvas.addEventListener( 'mousemove', function(e)  {      draw(e.clientX, e.clientY) } )
+function drawstart(x, y) {
+  mouse = 1
 
-  window.addEventListener( 'touchend',   function()  { drawstop() } )
-  canvas.addEventListener( 'touchstart', function(e) { drawstart(e.touches[0].clientX, e.touches[0].clientY) } )
-  canvas.addEventListener( 'touchmove',  function(e) { e.preventDefault(); draw(e.touches[0].clientX, e.touches[0].clientY) } )
+  cscaleW = canvas.width / canvas.clientWidth
+  cscaleH = canvas.height / canvas.clientHeight
 
-  --></script>
-</form>
+  stx=relX(x), sty=relY(y)
+
+  image.beginPath()
+  draw(x, y)  // why must this not use relative Coords ???
+
+  image_serialize = " polyline"
+}
+
+function drawstop() {
+  // if path ends close to beginning ( < 50 px); then close path and fill
+  if ( mouse == 1 && Math.sqrt( Math.pow(stx - cux, 2) + Math.pow(sty - cuy, 2)) <= 50 ){
+    image.lineTo( stx, sty )
+    image.stroke()
+
+    image.globalAlpha = .5
+    image.fill()
+    image.globalAlpha = 1
+
+    image_serialize += " " + stx + "," + sty
+    data.value += " fill " + c + "8" + image_serialize
+  } else if (mouse == 1)  {
+    data.value += " fill #0000 " + image_serialize
+  }
+  dbg.innerHTML = " stx: " + stx + " cux: " + cux + " sty: " + sty + " cuy: " + cuy
+  image.closePath()
+  image_serialize = ""
+  mouse = 0
+}
+
+window.addEventListener( 'mouseup',   function()   { drawstop() } )
+canvas.addEventListener( 'mousedown', function(e)  { drawstart(e.clientX, e.clientY) } )
+canvas.addEventListener( 'mousemove', function(e)  {      draw(e.clientX, e.clientY) } )
 
+window.addEventListener( 'touchend',   function()  { drawstop() } )
+canvas.addEventListener( 'touchstart', function(e) { drawstart(e.touches[0].clientX, e.touches[0].clientY) } )
+canvas.addEventListener( 'touchmove',  function(e) { e.preventDefault(); draw(e.touches[0].clientX, e.touches[0].clientY) } )
+--></script>
 EOF
 # vi:set filetype=html: