home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 24 / CD_ASCQ_24_0995.iso / dos / tools / aurora21 / ascii2.aml < prev    next >
Text File  |  1995-08-10  |  4KB  |  181 lines

  1. /* ------------------------------------------------------------------ */
  2. /* Macro:        ASCII2.AML                                           */
  3. /* Written by:   nuText Systems                                       */
  4. /*                                                                    */
  5. /* Description:  This macro displays a two-dimensional ASCII chart    */
  6. /*               and shows character codes in decimal, hex, octal,    */
  7. /*               and binary. The ASCII character at the cursor can    */
  8. /*               be entered into the text of the current edit window. */
  9. /*                                                                    */
  10. /* Usage:        Use the cursor keys or the mouse to move around the  */
  11. /*               chart. Press <enter> or double-click to enter an     */
  12. /*               ASCII character into the current edit window.        */
  13. /* ------------------------------------------------------------------ */
  14.  
  15.   include bootpath "define.aml"
  16.  
  17.   forward close
  18.  
  19.   var x
  20.   var y
  21.   var x2
  22.   var asciival
  23.  
  24.   // keep this object resident
  25.   stayresident
  26.   inheritfrom "win"
  27.  
  28.   // create the ascii chart window
  29.   createwindow
  30.   setframe "bn"
  31.   setcolor  border_color        (color white on gray)
  32.   setcolor  border_flash_color  (color brightgreen on gray)
  33.   setcolor  text_color          (color black on gray)
  34.   setcolor  north_title_color   (color white on magenta)
  35.   settitle "2-D ASCII Chart - press <enter> to select"
  36.   setwinctrl '≡'
  37.   width = 47
  38.   height = 18
  39.   // center the window
  40.   ox = (getvidcols - width) / 2
  41.   oy = (getvidrows - height) / 2
  42.   sizewindow ox oy ox + width oy + height "ad"
  43.   setborder "1i"
  44.   setshadow 2 1
  45.  
  46.   // draw the ascii chart
  47.   while y < 16 do
  48.     while x < 16 do
  49.       writestr (char 32 y * 16 + x 32)
  50.       x = x + 1
  51.     end
  52.     writeline
  53.     x = 0
  54.     y = y + 1
  55.   end
  56.  
  57.   // get last position
  58.   asciival = _ascii2
  59.   x = asciival mod 16
  60.   y = asciival / 16
  61.  
  62.   showcursor 50 99
  63.  
  64.   function draw
  65.     if x2 then
  66.       // clear the bracket cursor
  67.       writestr ' ' '' x2 - 1
  68.       writestr ' ' '' x2 + 1
  69.     end
  70.  
  71.     asciival = y * 16 + x
  72.  
  73.     // write ascii info at the bottom of the chart
  74.     writestr ' char=' + (char asciival) +
  75.              '  dec=' + (pad asciival 3 'r' '0') +
  76.              '  hex=' + (pad (base asciival 16) 2 'r' '0') +
  77.              '  oct=' + (pad (base asciival 8)  3 'r' '0') +
  78.              '  bin=' + (pad (base asciival 2)  8 'r' '0') +
  79.              (copystr ' ' 8)
  80.              (color white on magenta) 1 17
  81.  
  82.     // move the cursor to the appropriate ascii cell
  83.     x2 = x * 3 + 2
  84.     gotoxy x2 y + 1
  85.  
  86.     // write the bracket [ ] cursor
  87.     writestr '[' (color white on gray) x2 - 1
  88.     writestr ']' (color white on gray) x2 + 1
  89.     gotoxy x2 y + 1
  90.   end
  91.  
  92.   draw
  93.  
  94.   function close
  95.     // save current position for next time
  96.     setobj ascii2 asciival 'prf'
  97.     // pass on to 'close' function in win object
  98.     pass
  99.     destroyobject
  100.   end
  101.  
  102.   // mouse click
  103.   function <lbutton>
  104.     pass
  105.     case getregion
  106.       // client area
  107.       when 1
  108.         pass
  109.         if virtorow <= 16 then
  110.           y = (virtorow - 1) mod 16
  111.         end
  112.         x = (virtocol - 1) / 3
  113.         draw
  114.     end
  115.   end
  116.  
  117.   function <ldouble>
  118.     call <enter>
  119.   end
  120.  
  121.   function <move>
  122.     pass
  123.     if (button? 1) and getregion == 1 then
  124.       send <lbutton>
  125.     end
  126.   end
  127.  
  128.   key <esc>  close
  129.  
  130.   function "≡"
  131.     close
  132.   end
  133.  
  134.   // enter the ascii character in an edit window and exit
  135.   key <enter>
  136.     close
  137.     queue "write" (char asciival)
  138.   end
  139.  
  140.   // move the cursor around in the chart
  141.   key <left>
  142.     x = if? x (x - 1) 15
  143.     draw
  144.   end
  145.  
  146.   key <right>
  147.     x = (x + 1) mod 16
  148.     draw
  149.   end
  150.  
  151.   key <up>
  152.     y = if? y (y - 1) 15
  153.     draw
  154.   end
  155.  
  156.   key <down>
  157.     y = (y + 1) mod 16
  158.     draw
  159.   end
  160.  
  161.   key <home>
  162.     x = 0
  163.     draw
  164.   end
  165.  
  166.   key <end>
  167.     x = 15
  168.     draw
  169.   end
  170.  
  171.   key <ctrl home>
  172.     y = 0
  173.     draw
  174.   end
  175.  
  176.   key <ctrl end>
  177.     y = 15
  178.     draw
  179.   end
  180.  
  181.