;created by Roger Lamb
;lambroger@cox-internet.com
;March 12, 2003 using Mirc 6.03
dialog calculator_layout {
;properties for the whole layout
title "Calculator"
size -1 -1 140 108
;end of properties for the whole layout
;output box: use read_display, store_display and clear_display functions
edit "",40,1 1 139 20,right read
;hidden storage box: use read_storage, store_storage and clear_storage functions
edit "",41,1 1 139 20,right read hide
;hidden memory box: use read_memory, store_memory and clear_memory functions
edit "",42,1 1 139 20,right read hide
;1st row
button "7",7,1 22 20 20,default
button "8",8,21 22 20 20,default
button "9",9,41 22 20 20,default
;2nd row
button "4",4,1 42 20 20,default
button "5",5,21 42 20 20,default
button "6",6,41 42 20 20,default
;3rd row
button "1",1,1 62 20 20,default
button "2",2,21 62 20 20,default
button "3",3,41 62 20 20,default
;4th row
button "0",10,21 82 20 20,default
;functions
button ".",11,71 82 20 20,default
button "=",12,91 82 20 20,default
button "+",13,71 22 20 20,default
button "-",14,71 42 20 20,default
button "*",15,91 42 20 20,default
button "/",16,91 22 20 20,default
button "CE",17,1 82 20 20,default
button "AC",18,41 82 20 20,default
button "M+",19,115 62 22 20,default
button "M-",20,115 82 22 20,default
button "MR",21,115 42 22 20,default
button "MC",22,115 22 22 20,default
button "-+",23,71 62 20 20,default
text "",24,96 65 12 12,center
;backwards compat only, controls hidden
button "",99,400 400 1 1,ok
button "",100,400 400 1 1,cancel
}
;ie /calc not $calc
alias calc {
if ( %calculator_active ) {
dialog -v calculator
return
}
dialog -m calculator calculator_layout
}
menu * {
-
Tools
.Calculator: /calc
}
;display access functions
alias read_display {
return $did(calculator,40)
}
alias clear_display {
did -r calculator 40
}
alias store_display {
did -o calculator 40 1 $1
}
;storage access functions
alias read_storage {
return $did(calculator,41)
}
alias clear_storage {
did -r calculator 41
}
alias store_storage {
did -o calculator 41 1 $1
}
;memory access functiosn
alias read_memory {
return $did(calculator,42)
}
alias clear_memory {
did -r calculator 42
did -r calculator 24
}
alias store_memory {
did -o calculator 42 1 $1
did -o calculator 24 1 M
}
alias read_data {
;ensure there is data
if ( ( !$read_display() ) && ( $read_display() != 3 ) ) return 0
return $read_display()
}
on 1:dialog:calculator:init:*: {
set %calculator_active 1
set %calculator_equal 12
set %calculator_add 13
set %calculator_subtract 14
set %calculator_multiply 15
set %calculator_divide 16
set %calculator_clear_entry 17
set %calculator_all_clear 18
set %calculator_memory_add 19
set %calculator_memory_sub 20
set %calculator_memory_recall 21
set %calculator_memory_clear 22
set %calculator_sign 23
}
on 1:dialog:calculator:close:*: {
unset %calculator*
}
on 1:dialog:calculator:sclick:*: {
var %id = $did
;insert numbers and leave the routine
if ( %id <= 10 ) {
;check if a wipe has been requested
if ( %wipe_me ) {
$clear_display()
unset %wipe_me
}
$store_display( $read_display() $+ $right(%id,1) )
return
}
if ( %id == 11 ) {
if ( . isin $read_display() ) return
;check if a wipe has been requested
if ( %wipe_me ) {
$clear_display()
unset %wipe_me
}
$store_display( $read_display() $+ . )
return
}
;ok if we get here, then it's because one of the
;function buttons were pressed
var %function = %id
;determine which function was accessed
if ( %function == %calculator_clear_entry ) {
$clear_display()
return
}
if ( %function == %calculator_sign ) {
$store_display($calc( $read_display() * -1 ))
return
}
if ( %function == %calculator_memory_recall ) {
$store_display($read_memory())
return
}
if ( %last_function && $read_display() && $read_storage() ) || ( %function == %calculator_equal ) {
if ( %last_function == %calculator_multiply ) $store_display($calc( $read_storage() * $read_display() ))
elseif ( %last_function == %calculator_add ) $store_display($calc( $read_storage() + $read_display() ))
elseif ( %last_function == %calculator_subtract ) $store_display($calc( $read_storage - $read_display() ))
elseif ( %last_function == %calculator_divide ) $store_display($calc( $read_storage / $read_display() ))
; $clear_storage()
unset %last_function
}
if ( %function == %calculator_all_clear ) {
$clear_display()
$clear_storage()
$clear_memory()
unset %last_function
unset %wipe_me
return
}
if ( %function == %calculator_memory_clear ) {
$clear_memory()
return
}
if ( %function == %calculator_memory_sub ) {
$store_memory($calc( $read_memory() - $read_display() ))
set %wipe_me 1
return
}
if ( %function == %calculator_memory_add ) {
$store_memory($calc( $read_memory() + $read_display() ))
set %wipe_me 1
return
}
;ok it was a math key
;store old value into hidden box
$store_storage( $read_display() )
;set last function
set %last_function %id
;set wipe flag for numbers
set %wipe_me 1
}