/* ----------------------------------------------------------------------------- This source file is part of OpenSpace3D For the latest info, see http://www.openspace3d.com Copyright (c) 2012 I-maginer This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA, or go to http://www.gnu.org/copyleft/lesser.txt ----------------------------------------------------------------------------- */ struct PlugDGNValue = [ PDLGNV_fValue : F, PDLGNV_sLabel : S, PDLGNV_floatstr : VUIFloat ] mkPlugDGNValue;; struct PlugDialogNum = [ PDLGN_instance : PInstance, PDLGN_dlgstr : VUIDlg, PDLGN_lValues : [PlugDGNValue r1], PDLGN_lthemeelts : [S r1], PDLGN_sTitle : S, PDLGN_fMinValue : F, PDLGN_fMaxValue : F, PDLGN_fStep : F, PDLGN_iDec : I, PDLGN_sPos : S, PDLGN_iOpacity : I, PDLGN_iFadeSpeed : I ] mkPlugDialogNum;; fun deleteOb(inst, obstr)= VUIdestroyDialogBox obstr.PDLGN_dlgstr; 0;; fun cbClickDlg(dlgstr, state, obstr)= set obstr.PDLGN_dlgstr = nil; let sizelist obstr.PDLGN_lValues -> nbval in let 0 -> i in while (i < nbval) do ( let nth_list obstr.PDLGN_lValues i -> valuestr in set valuestr.PDLGNV_floatstr = nil; set i = i + 1; ); SendPluginEvent obstr.PDLGN_instance "Click Ok" nil nil; SendPluginEvent obstr.PDLGN_instance "Hidden" nil nil; 0;; fun getAlign(param)= let [1 1] -> align in let [0.0 0.0] -> pos in let strextr param -> lp in let hd lp -> lp in let 0 -> nb in ( while ((lp != nil) && (nb < 2)) do ( let hd lp -> flag in if (!strcmpi flag "top") then ( mutate align <- [_ 0]; mutate pos <- [_ 10.0]; ) else if (!strcmpi flag "bottom") then ( mutate align <- [_ 2]; mutate pos <- [_ 10.0]; ) else if (!strcmpi flag "left") then ( mutate align <- [0 _]; mutate pos <- [10.0 _]; ) else if (!strcmpi flag "right") then ( mutate align <- [2 _]; mutate pos <- [10.0 _]; ) else nil; set lp = tl lp; set nb = nb + 1; ); [pos align]; );; fun cbGetValue(inst, from, action, param, reply, obstr)= let nil -> evparam in ( let sizelist obstr.PDLGN_lValues -> nbval in let 0 -> i in while (i < nbval) do ( let nth_list obstr.PDLGN_lValues i -> valuestr in let G2DgetFtoA valuestr.PDLGNV_fValue obstr.PDLGN_iDec -> avalue in set evparam = avalue::evparam; set i = i + 1; ); SendPluginEvent inst "Value" (strcatnSep (revertlist evparam) " ") nil; ); 0;; fun cbSetValue(inst, from, action, param, reply, obstr)= let (strtrim param) -> param in let hd (strextr param) -> lparams in let 0 -> i in while (lparams != nil) do ( let atof (hd lparams) -> fvalue in if (fvalue == nil) then nil else ( let nth_list obstr.PDLGN_lValues i -> valuestr in let minf (maxf fvalue obstr.PDLGN_fMinValue) obstr.PDLGN_fMaxValue -> fvalue in ( set valuestr.PDLGNV_fValue = fvalue; if (valuestr.PDLGNV_floatstr == nil) then nil else VUIsetFloatValue valuestr.PDLGNV_floatstr valuestr.PDLGNV_fValue; ); ); set lparams = tl lparams; set i = i + 1; ); let nil -> evparam in ( let sizelist obstr.PDLGN_lValues -> nbval in let 0 -> i in while (i < nbval) do ( let nth_list obstr.PDLGN_lValues i -> valuestr in let G2DgetFtoA valuestr.PDLGNV_fValue obstr.PDLGN_iDec -> avalue in set evparam = avalue::evparam; set i = i + 1; ); SendPluginEvent inst "Modified" (strcatnSep (revertlist evparam) " ") nil; ); 0;; fun updateDialogSize(obstr)= let V3DgetSessionView c3dXsession -> viewstr in ( let VUIgetThemeDef (getThemeFromInstance obstr.PDLGN_instance) "dialogBox" -> defstr in let VUIgetThemeFont defstr "label" -> lbfontstr in let sizelist obstr.PDLGN_lValues -> nbval in let if (strcmpi obstr.PDLGN_sTitle "") == 0 then nil else obstr.PDLGN_sTitle -> title in let let 350 -> minw in ( let 0 -> i in while (i < nbval) do ( let nth_list obstr.PDLGN_lValues i -> valuestr in let if ((valuestr.PDLGNV_sLabel == nil) || (!strcmp "" valuestr.PDLGNV_sLabel)) then 0 else 1 -> haslabel in let if haslabel then let VUIgetTextSize VUIgetFontFromInterface lbfontstr valuestr.PDLGNV_sLabel 0 iVUITEXT_HALIGNLEFT|iVUITEXT_VALIGNTOP -> [tw th] in [tw + 10 th + 10] else [0 0] -> [tw th] in if ((tw == 0) || ((minw - tw) > 200)) then nil else set minw = tw + 200; set i = i + 1; ); minw; ) -> sw in let 35 + (nbval * 40) -> sh in let VUIgetViewSize viewstr -> [cvw cvh] in let VUIcomputeDialogBoxSize viewstr (getThemeFromInstance obstr.PDLGN_instance) (VUIgetElementText obstr.PDLGN_dlgstr.VUIDLG_title) (VUIgetElementText obstr.PDLGN_dlgstr.VUIDLG_frame) (if (obstr.PDLGN_dlgstr.VUIDLG_okBtn == nil && obstr.PDLGN_dlgstr.VUIDLG_cancelBtn == nil) then 0 else 1) -> [tlw tlh _ _ btnh] in let if (obstr.PDLGN_dlgstr.VUIDLG_title != nil) then let obstr.PDLGN_dlgstr.VUIDLG_title.VUIE_vSize -> [tw th] in [(ftoi tw) (ftoi th)] else [0 0] -> [tlw tlh] in let if (cvh <= 0) then 1 else if (viewstr.V3D_bVRmode) then 1080 else cvh -> cvh in let [(cvw - 20 - 30) (cvh - 30 - btnh - tlh)] -> [maxvw maxvh] in let [(min (max (max sw tlw) 200) maxvw) (min (max sh 70) maxvh)] -> [ttw tth] in let [ttw + 30 tth + btnh + tlh] -> [nw nh] in ( VUIsetElementSize obstr.PDLGN_dlgstr.VUIDLG_title [100.0 (itof tlh)] nil; VUIsetElementSize obstr.PDLGN_dlgstr.VUIDLG_frame nil [1 1 (-20) (-(10 + tlh + 10 + btnh))]; VUIsetElementPos obstr.PDLGN_dlgstr.VUIDLG_frame [0.0 (itof (10 + tlh))] nil nil; VUIsetContainerSize obstr.PDLGN_dlgstr.VUIDLG_container [(itof nw) (itof nh)] nil; ); ); 0;; fun cbDlgThemeUpdate(constr, obstr)= updateDialogSize obstr;; fun cbSetTitle(inst, from, action, param, reply, obstr)= set obstr.PDLGN_sTitle = if (param == nil) || (!strcmp (strtrim param) "") then nil else strtrim param; if (obstr.PDLGN_dlgstr == nil) then nil else ( VUIsetDialogTitle obstr.PDLGN_dlgstr obstr.PDLGN_sTitle; updateDialogSize obstr; ); 0;; fun cbChangeValue(floatstr, value, state, p)= let p -> [obstr valuestr] in ( set valuestr.PDLGNV_fValue = value; let nil -> evparam in ( let sizelist obstr.PDLGN_lValues -> nbval in let 0 -> i in while (i < nbval) do ( let nth_list obstr.PDLGN_lValues i -> valuestr in let G2DgetFtoA valuestr.PDLGNV_fValue obstr.PDLGN_iDec -> avalue in set evparam = avalue::evparam; set i = i + 1; ); SendPluginEvent obstr.PDLGN_instance "Modified" (strcatnSep (revertlist evparam) " ") nil; ); ); 0;; fun createDialog(param, obstr, show)= let V3DgetSessionView c3dXsession -> viewstr in let VUIgetThemeDef (getThemeFromInstance obstr.PDLGN_instance) (hd obstr.PDLGN_lthemeelts) -> defstr in let VUIgetThemeFont defstr "label" -> lbfontstr in let sizelist obstr.PDLGN_lValues -> nbval in let if (strcmpi obstr.PDLGN_sTitle "") == 0 then nil else obstr.PDLGN_sTitle -> title in let let 350 -> minw in ( let 0 -> i in while (i < nbval) do ( let nth_list obstr.PDLGN_lValues i -> valuestr in let if ((valuestr.PDLGNV_sLabel == nil) || (!strcmp "" valuestr.PDLGNV_sLabel)) then 0 else 1 -> haslabel in let if haslabel then let VUIgetTextSize VUIgetFontFromInterface lbfontstr valuestr.PDLGNV_sLabel 0 iVUITEXT_HALIGNLEFT|iVUITEXT_VALIGNTOP -> [tw th] in [tw + 10 th + 10] else [0 0] -> [tw th] in if ((tw == 0) || ((minw - tw) > 200)) then nil else set minw = tw + 200; set i = i + 1; ); minw; ) -> minwidth in let 35 + (nbval * 40) -> height in let VUIcreateDialogExt (V3DgetSessionView c3dXsession) obstr.PDLGN_instance.INST_groupstr.GRP_project.PRJ_vuiGroup [minwidth height] title (loc "OS3DDNUMBER_C0001") nil obstr.PDLGN_iOpacity (V3DgetVrMode viewstr) (mkfun3 @cbClickDlg obstr) (hd obstr.PDLGN_lthemeelts) -> dlgstr in let VUIgetDialogFrame dlgstr -> framestr in let VUIgetElementContainer framestr -> contstr in ( let 0 -> i in while (i < nbval) do ( let nth_list obstr.PDLGN_lValues i -> valuestr in let if ((valuestr.PDLGNV_sLabel == nil) || (!strcmp "" valuestr.PDLGNV_sLabel)) then 0 else 1 -> haslabel in let if haslabel then let VUIgetTextSize VUIgetFontFromInterface lbfontstr valuestr.PDLGNV_sLabel 0 iVUITEXT_HALIGNLEFT|iVUITEXT_VALIGNTOP -> [tw th] in [(VUIcreateFrame contstr framestr [0.0 (itof (10 + (i * 40)))] [(itof (tw + 10)) 0.0] [0 0 0 0 0 0 0 0] [0 0]) [tw + 10 th + 10]] else [nil [0 0]] -> [labelstr [tw th]] in let VUIcreateFloatExt contstr framestr [0.0 (itof (10 + (i * 40)))] [100.0 35.0] [0 0 1 0 0 0 (if tw == 0 then 0 else -tw) 0] [(if haslabel then 2 else 1) (if haslabel then 0 else 1)] [5 5] obstr.PDLGN_fMinValue obstr.PDLGN_fMaxValue obstr.PDLGN_fStep obstr.PDLGN_iDec valuestr.PDLGNV_fValue (hd tl obstr.PDLGN_lthemeelts) -> floatstr in ( if (labelstr == nil) then nil else VUIsetElementText labelstr lbfontstr valuestr.PDLGNV_sLabel [0 0] [tw 0] [5 5] iVUITEXT_HALIGNLEFT|iVUITEXT_VALIGNTOP VUI_TextAutoHeight 1; VUIsetFloatCbChange floatstr mkfun4 @cbChangeValue [obstr valuestr]; set valuestr.PDLGNV_floatstr = floatstr; ); set i = i + 1; ); let if (!strcmp "" (strtrim param)) || param == nil then getAlign obstr.PDLGN_sPos else getAlign param -> [pos align] in VUIsetContainerPos contstr pos align nil; set obstr.PDLGN_dlgstr = dlgstr; VUIsetContainerThemeCallback contstr mkfun2 @cbDlgThemeUpdate obstr; VUIsetContainerClear contstr 0; VUIsetContainerFadeSpeed obstr.PDLGN_dlgstr.VUIDLG_container obstr.PDLGN_iFadeSpeed; VUIshowContainerBase obstr.PDLGN_dlgstr.VUIDLG_container show; ); 0;; fun cbVrChange(inst, viewstr, state, obstr)= if obstr.PDLGN_dlgstr == nil then nil else ( VUIdestroyDialogBox obstr.PDLGN_dlgstr; createDialog nil obstr 1; ); 0;; fun cbCameraTeleport(inst, viewstr, camera, obstr)= if obstr.PDLGN_dlgstr == nil then nil else ( VUIdestroyDialogBox obstr.PDLGN_dlgstr; createDialog nil obstr 1; ); 0;; fun cbDialogVisibility(contstr, state, obstr)= if (state) then nil else ( VUIdestroyDialogBox obstr.PDLGN_dlgstr; set obstr.PDLGN_dlgstr = nil; let sizelist obstr.PDLGN_lValues -> nbval in let 0 -> i in while (i < nbval) do ( let nth_list obstr.PDLGN_lValues i -> valuestr in set valuestr.PDLGNV_floatstr = nil; set i = i + 1; ); ); SendPluginEvent obstr.PDLGN_instance if (state) then "Shown" else "Hidden" nil nil; 0;; fun cbShow(inst, from, action, param, reply, obstr)= if obstr.PDLGN_dlgstr == nil then nil else VUIdestroyDialogBox obstr.PDLGN_dlgstr; createDialog param obstr 0; VUIshowContainerExt obstr.PDLGN_dlgstr.VUIDLG_container 1 mkfun3 @cbDialogVisibility obstr; 0;; fun cbHide(inst, from, action, param, reply, obstr)= VUIshowContainerExt obstr.PDLGN_dlgstr.VUIDLG_container 0 mkfun3 @cbDialogVisibility obstr; 0;; fun loadLabelsList(inst, defval)= let 0 -> i in let nil -> llist in let nil -> label in ( while ((set label = getPluginInstanceParam inst (strcat "label_" (itoa i))) != nil) do ( set i = i + 1; set llist = (mkPlugDGNValue [defval label nil])::llist; ); revertlist llist; );; fun newOb(inst)= let getPluginInstanceParam inst "title" -> title in let if title == nil then "" else title -> title in let atof getPluginInstanceParam inst "value" -> value in let if value == nil then 0.0 else value -> value in let atof getPluginInstanceParam inst "minvalue" -> minvalue in let if minvalue == nil then 0.0 else minvalue -> minvalue in let atof getPluginInstanceParam inst "maxvalue" -> maxvalue in let if maxvalue == nil then 100.0 else maxvalue -> maxvalue in let atof getPluginInstanceParam inst "step" -> step in let if step == nil then 1.0 else step -> step in let atoi getPluginInstanceParam inst "dec" -> dec in let if dec == nil then 2 else dec -> dec in let loadThemeEltSelectorValues inst "dialogBox"::"float"::nil -> lthemeelts in let atoi (getPluginInstanceParam inst "valign") -> valign in let if valign == nil then 1 else valign -> valign in let atoi (getPluginInstanceParam inst "halign") -> halign in let if halign == nil then 1 else halign -> halign in let atoi (getPluginInstanceParam inst "opacity") -> opacity in let if (opacity == nil) then 100 else opacity -> opacity in let atoi (getPluginInstanceParam inst "fadespeed") -> fadespeed in let if (fadespeed == nil) then 0 else fadespeed -> fadespeed in let atoi (getPluginInstanceParam inst "show") -> show in let if (show == nil) then 1 else show -> show in let loadLabelsList inst value -> llabels in let if (llabels == nil) then (mkPlugDGNValue [value nil nil])::nil else llabels -> llabels in let if (valign == 0) then "top" else if (valign == 2) then "bottom" else "center" -> vpos in let if (halign == 0) then "left" else if (halign == 2) then "right" else "center" -> hpos in let mkPlugDialogNum [inst nil llabels lthemeelts title minvalue maxvalue step dec (strcatn vpos::" "::hpos::nil) opacity fadespeed] -> obstr in ( if !show then nil else cbShow inst nil nil nil nil obstr; PluginRegisterAction inst "Show" mkfun6 @cbShow obstr; PluginRegisterAction inst "Hide" mkfun6 @cbHide obstr; PluginRegisterAction inst "Set title" mkfun6 @cbSetTitle obstr; PluginRegisterAction inst "Set value" mkfun6 @cbSetValue obstr; PluginRegisterAction inst "Get value" mkfun6 @cbGetValue obstr; setPluginInstanceCbVrModeChanged inst mkfun4 @cbVrChange obstr; setPluginInstanceCbCameraTeleport inst mkfun4 @cbCameraTeleport obstr; setPluginInstanceCbDel inst mkfun2 @deleteOb obstr; ); 0;; fun IniPlug(file)= VUIsetEnable c3dXsession 1; PlugRegister @newOb nil; setPluginEditor @dynamicedit; 0;;