home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
AmigActive 6
/
AACD06.ISO
/
AACD
/
Graphics
/
picFX
/
e-source
/
varlist.e
< prev
Wrap
Text File
|
1999-12-27
|
6KB
|
178 lines
OPT MODULE,PREPROCESS
/***************************************************************
** custom VariableList private subclass of List class **
****************************************************************
** **
** Handles the list of the available global variables **
***************************************************************/
MODULE 'amigalib/boopsi','amigalib/lists',
'exec/lists','exec/nodes',
'intuition/classes','intuition/classusr',
'muimaster','libraries/mui','mui/muicustomclass',
'utility/hooks','tools/installhook'
ENUM MUIA_VariableList_Dummy=$FCB92000
EXPORT ENUM MUIM_VariableList_AddVar=$FCB92800, -> Add an empty variable to the list
MUIM_VariableList_GetVar, -> get the value of the variable (name,address)
MUIM_VariableList_SetVar, -> reaction to a change to the string objects
MUIM_VariableList_UpdateStr, -> dis/enable the name & value gadgets depending if something is active or not.
MUIM_VariableList_Fields -> sets the [name,value] field addresses -> ugly way of doing
EXPORT CONST MUIV_VariableList_SetVar_Name=0,
MUIV_VariableList_SetVar_Value=1
OBJECT variableList_data
name,value -> the attached stringobjects
ENDOBJECT
OBJECT variable/* OF ln*/
name
value:LONG -> Currently, this is *always* a 32bit float value
ENDOBJECT
OBJECT muip_fields
id
name
value
ENDOBJECT
OBJECT muip_getVar
id
name
address:PTR TO LONG
ENDOBJECT
OBJECT muip_setVar
id
type
string
ENDOBJECT
EXPORT DEF varlist_mcc:PTR TO iclass,
cl_varlist:PTR TO mui_customclass
EXPORT DEF vl_displayhook:PTR TO hook,
vl_constructhook:PTR TO hook,
vl_destructhook:PTR TO hook
EXPORT PROC ccc()
cl_varlist:=eMui_CreateCustomClass(NIL,MUIC_List ,NIL,SIZEOF variableList_data,{variableList_dispatcher})
varlist_mcc:=cl_varlist.mcc_class -> (MMmrrrhh!)
NEW vl_displayhook
NEW vl_constructhook
NEW vl_destructhook
installhook(vl_displayhook,{variableList_displayer})
installhook(vl_constructhook,{variableList_constructor})
installhook(vl_destructhook,{variableList_destructor})
ENDPROC
EXPORT PROC dcc()
IF cl_varlist THEN Mui_DeleteCustomClass(cl_varlist)
ENDPROC
PROC variableList_displayer(dest:PTR TO LONG,entry:PTR TO variable)
dest[0]:=String(StrLen(entry.name))
StrCopy(dest[0],entry.name)
dest[1]:=String(8)
RealF(dest[1],entry.value,8)
ENDPROC NIL
/*(a2,a1,a0)*/
PROC variableList_constructor(p,h,d) IS d -> This does nothing -> what is the order of the variables??
/*(a2,a1)*/
PROC variableList_destructor(p,d:PTR TO variable)
END d
ENDPROC
PROC variableList_dispatcher(cl:PTR TO iclass,obj:PTR TO object,msg:PTR TO msg)
DEF methodid
methodid:=msg.methodid
SELECT methodid
CASE OM_NEW ; RETURN variableList_new(cl,obj,msg)
CASE MUIM_VariableList_AddVar ; RETURN variableList_addVar(cl,obj,msg)
CASE MUIM_VariableList_Fields ; RETURN variableList_fields(cl,obj,msg)
CASE MUIM_VariableList_SetVar ; RETURN variableList_setVar(cl,obj,msg)
CASE MUIM_VariableList_UpdateStr;RETURN variableList_updateStr(cl,obj,msg)
ENDSELECT
ENDPROC doSuperMethodA(cl,obj,msg)
PROC variableList_new(cl:PTR TO iclass,obj:PTR TO object,msg:PTR TO msg)
DEF lh:PTR TO lh,data:PTR TO variableList_data
IF (obj:=doSuperMethodA(cl,obj,msg)) = FALSE THEN RETURN FALSE
data:=INST_DATA(cl,obj)
data.name:=NIL
data.value:=NIL
ENDPROC obj
PROC variableList_addVar(cl:PTR TO iclass,obj:PTR TO object,msg:PTR TO msg)
DEF data:PTR TO variableList_data,variable:PTR TO variable
NEW variable
variable.name:=String(2);StrCopy(variable.name,'z')
variable.value:=0.0
doMethodA(obj,[MUIM_List_InsertSingle,variable,MUIV_List_Insert_Bottom])
set(obj,MUIA_List_Active,MUIV_List_Active_Bottom)
ENDPROC
PROC variableList_fields(cl:PTR TO iclass,obj:PTR TO object,msg:PTR TO muip_fields)
DEF data:PTR TO variableList_data
data:=INST_DATA(cl,obj)
data.name:=msg.name
data.value:=msg.value
ENDPROC
PROC variableList_setVar(cl:PTR TO iclass,obj:PTR TO object,msg:PTR TO muip_setVar)
DEF variable:PTR TO variable
doMethodA(obj,[MUIM_List_GetEntry,MUIV_List_GetEntry_Active,{variable}])
IF variable=MUIV_List_Active_Off THEN RETURN -> this should not happen, but we never know ;-)
IF msg.type=MUIV_VariableList_SetVar_Name
DisposeLink(variable.name)
variable.name:=String(StrLen(msg.string))
StrCopy(variable.name,msg.string)
ELSE -> Value
variable.value:=RealVal(msg.string)
ENDIF
doMethodA(obj,[MUIM_List_Redraw,MUIV_List_Redraw_Active])
ENDPROC
PROC variableList_updateStr(cl:PTR TO iclass,obj:PTR TO object,msg:PTR TO msg)
DEF data:PTR TO variableList_data,var:PTR TO variable,str:PTR TO CHAR
data:=INST_DATA(cl,obj)
IF data.name=NIL THEN RETURN
doMethodA(obj,[MUIM_List_GetEntry,MUIV_List_GetEntry_Active,{var}])
IF var=NIL
set(data.name,MUIA_Disabled,MUI_TRUE)
set(data.value,MUIA_Disabled,MUI_TRUE)
ELSEIF var
str:=String(8)
RealF(str,var.value,8)
set(data.name,MUIA_Disabled,FALSE)
set(data.value,MUIA_Disabled,FALSE)
set(data.name,MUIA_String_Contents,var.name)
set(data.value,MUIA_String_Contents,str)
ENDIF
ENDPROC
/*getvariable(source,len,list) returns the value of the variable whose name is taken from source
(len char long)
list is the VariableListObject containing the data.*/
EXPORT PROC getvariable(source,len,list)
DEF i,count,var:PTR TO variable
i:=0
get(list,MUIA_List_Entries,{count}) -> count now contains the number before which we must stop.
WHILE i < count
doMethodA(list,[MUIM_List_GetEntry,i,{var}])
IF StrCmp(var.name,source,len) AND (StrLen(var.name)=len)THEN
RETURN var.value
i++
ENDWHILE
ENDPROC -1 -> in case of failure