home *** CD-ROM | disk | FTP | other *** search
- /* ------------------------------------------------------------------ */
- /* Macro: ASCII2.AML */
- /* Written by: nuText Systems */
- /* */
- /* Description: This macro displays a two-dimensional ASCII chart */
- /* and shows character codes in decimal, hex, octal, */
- /* and binary. The ASCII character at the cursor can */
- /* be entered into the text of the current edit window. */
- /* */
- /* Usage: Use the cursor keys or the mouse to move around the */
- /* chart. Press <enter> or double-click to enter an */
- /* ASCII character into the current edit window. */
- /* ------------------------------------------------------------------ */
-
- include bootpath "define.aml"
-
- forward close
-
- var x
- var y
- var x2
- var asciival
-
- // keep this object resident
- stayresident
- inheritfrom "win"
-
- // create the ascii chart window
- createwindow
- setframe "bn"
- setcolor border_color (color white on gray)
- setcolor border_flash_color (color brightgreen on gray)
- setcolor text_color (color black on gray)
- setcolor north_title_color (color white on magenta)
- settitle "2-D ASCII Chart - press <enter> to select"
- setwinctrl '≡'
- width = 47
- height = 18
- // center the window
- ox = (getvidcols - width) / 2
- oy = (getvidrows - height) / 2
- sizewindow ox oy ox + width oy + height "ad"
- setborder "1i"
- setshadow 2 1
-
- // draw the ascii chart
- while y < 16 do
- while x < 16 do
- writestr (char 32 y * 16 + x 32)
- x = x + 1
- end
- writeline
- x = 0
- y = y + 1
- end
-
- // get last position
- asciival = _ascii2
- x = asciival mod 16
- y = asciival / 16
-
- showcursor 50 99
-
- function draw
- if x2 then
- // clear the bracket cursor
- writestr ' ' '' x2 - 1
- writestr ' ' '' x2 + 1
- end
-
- asciival = y * 16 + x
-
- // write ascii info at the bottom of the chart
- writestr ' char=' + (char asciival) +
- ' dec=' + (pad asciival 3 'r' '0') +
- ' hex=' + (pad (base asciival 16) 2 'r' '0') +
- ' oct=' + (pad (base asciival 8) 3 'r' '0') +
- ' bin=' + (pad (base asciival 2) 8 'r' '0') +
- (copystr ' ' 8)
- (color white on magenta) 1 17
-
- // move the cursor to the appropriate ascii cell
- x2 = x * 3 + 2
- gotoxy x2 y + 1
-
- // write the bracket [ ] cursor
- writestr '[' (color white on gray) x2 - 1
- writestr ']' (color white on gray) x2 + 1
- gotoxy x2 y + 1
- end
-
- draw
-
- function close
- // save current position for next time
- setobj ascii2 asciival 'prf'
- // pass on to 'close' function in win object
- pass
- destroyobject
- end
-
- // mouse click
- function <lbutton>
- pass
- case getregion
- // client area
- when 1
- pass
- if virtorow <= 16 then
- y = (virtorow - 1) mod 16
- end
- x = (virtocol - 1) / 3
- draw
- end
- end
-
- function <ldouble>
- call <enter>
- end
-
- function <move>
- pass
- if (button? 1) and getregion == 1 then
- send <lbutton>
- end
- end
-
- key <esc> close
-
- function "≡"
- close
- end
-
- // enter the ascii character in an edit window and exit
- key <enter>
- close
- queue "write" (char asciival)
- end
-
- // move the cursor around in the chart
- key <left>
- x = if? x (x - 1) 15
- draw
- end
-
- key <right>
- x = (x + 1) mod 16
- draw
- end
-
- key <up>
- y = if? y (y - 1) 15
- draw
- end
-
- key <down>
- y = (y + 1) mod 16
- draw
- end
-
- key <home>
- x = 0
- draw
- end
-
- key <end>
- x = 15
- draw
- end
-
- key <ctrl home>
- y = 0
- draw
- end
-
- key <ctrl end>
- y = 15
- draw
- end
-
-