home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DP Tool Club 24
/
CD_ASCQ_24_0995.iso
/
dos
/
tools
/
aurora21
/
calcpad.aml
< prev
next >
Wrap
Text File
|
1995-08-10
|
9KB
|
349 lines
/* ------------------------------------------------------------------ */
/* Macro: CALCPAD.AML */
/* Written by: nuText Systems */
/* */
/* Description: This macro displays a simple calculator pad with */
/* basic arithmetic operations, a memory, and four */
/* display lines. Floating point numbers are not */
/* supported. The number on the bottommost display */
/* line can be entered into the text of the current */
/* edit window. */
/* */
/* Usage: Select this macro from the 'Sample Utility Macros' */
/* menu or from the macro picklist <shift f12>. Numbers */
/* and operations can be entered by using the keyboard */
/* or the mouse. */
/* */
/* If you use this macro regularly, it may be */
/* convenient to assign it to a key. For example: */
/* */
/* object edit */
/* : */
/* key <alt k> */
/* runmac "CALCPAD" */
/* end */
/* ------------------------------------------------------------------ */
include bootpath "define.aml"
// define the colors to use
define
set calc_display_color color darkgray on green
set calc_display_curr_color color black on green
set calc_button_color color black on green
set calc_button_hilite_color color black on brightgreen
set calc_client_color color black on gray
set calc_border_color color white on gray
set calc_control_color color yellow
end
// keep this object resident
stayresident
inheritfrom "win"
// display lines
var line1
var line2
var line3
var line4
// line number of last lbutton click
var line
var bcol
// display operators
var op0
var op1
var op2
var op3
var op4
// numeric base
radix = 10
// clear the calculator display
function cleardisp
line1 = ''
line2 = ''
line3 = ''
line4 = 0
op0 = ' '
op1 = ' '
op2 = ' '
op3 = ' '
op4 = ' '
end
// scroll the display upwards
function scrollup
op0 = op1
line1 = line2
op1 = op2
line2 = line3
op2 = op3
line3 = line4
op3 = op4
line4 = 0
op4 = ' '
end
// perform the operation currently on the display
function result
value = case op3
when '+' line3 + line4
when '-' line3 - line4
when '*' line3 * line4
when '/' line3 / line4
when 'm' line3 mod line4
when '%' (line3 * line4) / 100
end
scrollup
line4 = value
end
// create the calculator window
createwindow
setframe ">b"
setcolor border_color calc_border_color
setcolor text_color calc_client_color
setcolor control_color calc_control_color
setcolor border_flash_color (color brightgreen on gray)
settitle "Calculator"
setwinctrl '≡'
width = 36
height = 15
// center the window
ox = (getvidcols - width) / 2
oy = (getvidrows - height) / 2
sizewindow ox oy ox + width oy + height "ad"
setborder "1i"
setshadow 2 1
// define strings to display in the keypad
keystr = " C % mod / CE 7 8 9 * MR 4 5 6 - MS 1 2 3 + M+ 0 +/- = "
x = 0
y = 0
// draw the keypad
gotoxy 3 7
while y < 5 do
while x < 5 do
writestr keystr [y * 25 + (x * 5) + 1 : 5] calc_button_color
writestr " "
x = x + 1
end
x = 0
y = y + 1
if y < 5 then
writeline
writeline
gotoxy 3
end
end
y = 0
memory = ''
// clear the display
cleardisp
function draw
// draw the calculator display
gotoxy 3 2
writestr op0 + (pad (thousands line1) 32 'r') calc_display_color
gotoxy 3 3
writestr op1 + (pad (thousands line2) 32 'r') calc_display_color
gotoxy 3 4
writestr op2 + (pad (thousands line3) 32 'r') calc_display_color
gotoxy 3 5
writestr (if? op3 == '=' ' ' op3) + (pad (thousands line4) 32 'r')
calc_display_curr_color
end
draw
function close
// call 'close' in object 'win'
pass
destroyobject
end
function "≡"
close
end
// exit the calculator
key <esc>
close
end
// mouse click
function <lbutton>
// first pass on mouse events to the library
pass
case getregion
// client area
// translate mouse click to keypress
when 1
line = virtorow
buttonline = case line
when 7 "cb%m/"
when 9 "e789*"
when 11 "r456-"
when 13 "s123+"
when 15 "z0ti="
otherwise ''
end
if buttonline then
column = virtocol
bcol = if column >= 3 and column <= 7 then 1
elseif column >= 10 and column <= 14 then 2
elseif column >= 17 and column <= 21 then 3
elseif column >= 24 and column <= 28 then 4
elseif column >= 31 and column <= 35 then 5
end
if bcol then
buttonchar = buttonline [bcol]
hilite 5 1 (calc_button_hilite_color) (bcol * 7) - 4 line
// simulate the appropriate keypress
if buttonchar then
queuekey (getkeycode '<'+ buttonchar + '>')
end
end
end
end
end
function <lbuttonup>
if bcol then
hilite 5 1 (calc_button_color) (bcol * 7) - 4 line
bcol = ''
end
pass
end
// clear the display
key <del>
cleardisp
// enter into text
key <ctrl enter>
send "≡"
queue "write" (thousands line4)
// backspace
key <backspace>
line4 = line4 / radix
op4 = ' '
op3 = ' '
draw
end
key <enter>
if op3 <> ' ' then
if op3 == '=' then
op4 = op2
scrollup
line4 = line2
end
op4 = '='
result
draw
end
end
// enter numeric characters
key <char> (c)
if pos c "0123456789" then
if c < radix then
if op3 == '=' then
scrollup
end
positive = line4 >= 0
oldline = line4
line4 = line4 * radix + c
// test for overflow
if positive <> (line4 > 0) then
line4 = oldline
end
draw
end
// operators
elseif pos c "+-*/%m" then
if op3 <> ' ' and op3 <> '=' then
op4 = '='
result
end
op4 = c
scrollup
draw
elseif c == '=' then
send <enter>
// do the current operation
else
case c
when 'c'
cleardisp
// clear the entry line
when 'e'
line4 = 0
op4 = ' '
op3 = ' '
// store
when 's'
memory = line4
// recall
when 'r'
line4 = memory
// store + memory
when 'z'
memory = memory + line4
// change sign
when 'i'
line4 = -line4
op4 = ' '
op3 = ' '
// enter into text
when 't'
send <ctrl enter>
return
// backspace
when 'b'
send <backspace>
// unrecognized key
otherwise
send <otherkey>
end
draw
end
end
// unrecognized key
key <otherkey>
beep 200 70
end