home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Graphics / picFX / e-source / varlist.e < prev   
Text File  |  1999-12-27  |  6KB  |  178 lines

  1. OPT MODULE,PREPROCESS
  2. /***************************************************************
  3. ** custom VariableList private subclass of List class         **
  4. ****************************************************************
  5. **                                                            **
  6. ** Handles the list of the available global variables         **
  7. ***************************************************************/
  8.  
  9. MODULE 'amigalib/boopsi','amigalib/lists',
  10.        'exec/lists','exec/nodes',
  11.        'intuition/classes','intuition/classusr',
  12.        'muimaster','libraries/mui','mui/muicustomclass',
  13.        'utility/hooks','tools/installhook'
  14.  
  15. ENUM MUIA_VariableList_Dummy=$FCB92000
  16.  
  17.  
  18. EXPORT ENUM MUIM_VariableList_AddVar=$FCB92800, -> Add an empty variable to the list
  19.             MUIM_VariableList_GetVar, -> get the value of the variable (name,address)
  20.             MUIM_VariableList_SetVar, -> reaction to a change to the string objects
  21.             MUIM_VariableList_UpdateStr, -> dis/enable the name & value gadgets depending if something is active or not.
  22.             MUIM_VariableList_Fields -> sets the [name,value] field addresses -> ugly way of doing
  23.  
  24. EXPORT CONST MUIV_VariableList_SetVar_Name=0,
  25.     MUIV_VariableList_SetVar_Value=1
  26.  
  27. OBJECT variableList_data
  28.     name,value -> the attached stringobjects
  29. ENDOBJECT            
  30. OBJECT variable/* OF ln*/
  31.     name
  32.     value:LONG -> Currently, this is *always* a 32bit float value
  33. ENDOBJECT
  34.  
  35. OBJECT muip_fields
  36.     id
  37.     name
  38.     value
  39. ENDOBJECT
  40.  
  41. OBJECT muip_getVar
  42.     id
  43.     name
  44.     address:PTR TO LONG
  45. ENDOBJECT
  46. OBJECT muip_setVar
  47.     id
  48.     type
  49.     string
  50. ENDOBJECT
  51.  
  52. EXPORT DEF varlist_mcc:PTR TO iclass,
  53.            cl_varlist:PTR TO mui_customclass
  54. EXPORT DEF vl_displayhook:PTR TO hook,
  55.            vl_constructhook:PTR TO hook,
  56.            vl_destructhook:PTR TO hook
  57.  
  58. EXPORT PROC ccc()
  59.     cl_varlist:=eMui_CreateCustomClass(NIL,MUIC_List ,NIL,SIZEOF variableList_data,{variableList_dispatcher})
  60.     varlist_mcc:=cl_varlist.mcc_class -> (MMmrrrhh!)
  61.     NEW vl_displayhook
  62.     NEW vl_constructhook
  63.     NEW vl_destructhook
  64.     installhook(vl_displayhook,{variableList_displayer})
  65.     installhook(vl_constructhook,{variableList_constructor})
  66.     installhook(vl_destructhook,{variableList_destructor})
  67. ENDPROC
  68.  
  69. EXPORT PROC dcc()
  70.     IF cl_varlist THEN Mui_DeleteCustomClass(cl_varlist)
  71. ENDPROC
  72.  
  73. PROC variableList_displayer(dest:PTR TO LONG,entry:PTR TO variable)
  74.     dest[0]:=String(StrLen(entry.name))
  75.     StrCopy(dest[0],entry.name)
  76.     dest[1]:=String(8)
  77.     RealF(dest[1],entry.value,8)
  78. ENDPROC NIL
  79.  
  80. /*(a2,a1,a0)*/
  81. PROC variableList_constructor(p,h,d) IS d -> This does nothing -> what is the order of the variables??
  82. /*(a2,a1)*/
  83. PROC variableList_destructor(p,d:PTR TO variable)
  84.     END d
  85. ENDPROC
  86.  
  87. PROC variableList_dispatcher(cl:PTR TO iclass,obj:PTR TO object,msg:PTR TO msg)
  88. DEF methodid
  89.     methodid:=msg.methodid
  90.     SELECT methodid
  91.     CASE OM_NEW                    ; RETURN variableList_new(cl,obj,msg)
  92.     CASE MUIM_VariableList_AddVar  ; RETURN variableList_addVar(cl,obj,msg)
  93.     CASE MUIM_VariableList_Fields  ; RETURN variableList_fields(cl,obj,msg)
  94.     CASE MUIM_VariableList_SetVar  ; RETURN variableList_setVar(cl,obj,msg)
  95.     CASE MUIM_VariableList_UpdateStr;RETURN variableList_updateStr(cl,obj,msg)
  96.     ENDSELECT
  97. ENDPROC doSuperMethodA(cl,obj,msg)
  98.  
  99. PROC variableList_new(cl:PTR TO iclass,obj:PTR TO object,msg:PTR TO msg)
  100. DEF lh:PTR TO lh,data:PTR TO variableList_data
  101.     IF (obj:=doSuperMethodA(cl,obj,msg)) = FALSE THEN RETURN FALSE
  102.     data:=INST_DATA(cl,obj)
  103.     data.name:=NIL
  104.     data.value:=NIL
  105. ENDPROC obj
  106.  
  107. PROC variableList_addVar(cl:PTR TO iclass,obj:PTR TO object,msg:PTR TO msg)
  108. DEF data:PTR TO variableList_data,variable:PTR TO variable
  109.     NEW variable
  110.     variable.name:=String(2);StrCopy(variable.name,'z')
  111.     variable.value:=0.0
  112.     doMethodA(obj,[MUIM_List_InsertSingle,variable,MUIV_List_Insert_Bottom])
  113.     set(obj,MUIA_List_Active,MUIV_List_Active_Bottom)
  114. ENDPROC
  115.  
  116. PROC variableList_fields(cl:PTR TO iclass,obj:PTR TO object,msg:PTR TO muip_fields)
  117. DEF data:PTR TO variableList_data
  118.     data:=INST_DATA(cl,obj)
  119.     data.name:=msg.name
  120.     data.value:=msg.value
  121. ENDPROC
  122.  
  123. PROC variableList_setVar(cl:PTR TO iclass,obj:PTR TO object,msg:PTR TO muip_setVar)
  124. DEF variable:PTR TO variable
  125.  
  126.     doMethodA(obj,[MUIM_List_GetEntry,MUIV_List_GetEntry_Active,{variable}])
  127.     IF variable=MUIV_List_Active_Off THEN RETURN -> this should not happen, but we never know ;-)
  128.  
  129.     IF msg.type=MUIV_VariableList_SetVar_Name
  130.         DisposeLink(variable.name)
  131.         variable.name:=String(StrLen(msg.string))
  132.         StrCopy(variable.name,msg.string)
  133.     ELSE -> Value
  134.         variable.value:=RealVal(msg.string)
  135.     ENDIF
  136.     doMethodA(obj,[MUIM_List_Redraw,MUIV_List_Redraw_Active])
  137. ENDPROC
  138.  
  139. PROC variableList_updateStr(cl:PTR TO iclass,obj:PTR TO object,msg:PTR TO msg)
  140. DEF data:PTR TO variableList_data,var:PTR TO variable,str:PTR TO CHAR
  141.     data:=INST_DATA(cl,obj)
  142.  
  143.     IF data.name=NIL THEN RETURN
  144.  
  145.     doMethodA(obj,[MUIM_List_GetEntry,MUIV_List_GetEntry_Active,{var}])
  146.  
  147.     IF var=NIL
  148.         set(data.name,MUIA_Disabled,MUI_TRUE)
  149.         set(data.value,MUIA_Disabled,MUI_TRUE)
  150.     ELSEIF var
  151.         str:=String(8)
  152.         RealF(str,var.value,8)
  153.  
  154.         set(data.name,MUIA_Disabled,FALSE)
  155.         set(data.value,MUIA_Disabled,FALSE)
  156.  
  157.         set(data.name,MUIA_String_Contents,var.name)
  158.         set(data.value,MUIA_String_Contents,str)
  159.     ENDIF
  160. ENDPROC
  161.  
  162. /*getvariable(source,len,list) returns the value of the variable whose name is taken from source
  163. (len char long)
  164. list is the VariableListObject containing the data.*/
  165.  
  166. EXPORT PROC getvariable(source,len,list)
  167. DEF i,count,var:PTR TO variable
  168.     i:=0
  169.     get(list,MUIA_List_Entries,{count}) -> count now contains the number before which we must stop.
  170.  
  171.     WHILE i < count
  172.         doMethodA(list,[MUIM_List_GetEntry,i,{var}])
  173.         IF StrCmp(var.name,source,len) AND (StrLen(var.name)=len)THEN
  174.             RETURN var.value
  175.         i++
  176.     ENDWHILE
  177. ENDPROC -1 -> in case of failure
  178.