/* ----------------------------------------------------------------------------- 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 PlugDlgTextInput = [ PDTI_instance : PInstance, PDTI_dlgstr : VUIDlg, PDTI_editstr : VUIelement, PDTI_lthemeelts : [S r1], PDTI_sTitle : S, PDTI_sOkButton : S, PDTI_sCancelButton : S, PDTI_sText : S, PDTI_sPos : S, PDTI_iOpacity : I, PDTI_iFadeSpeed : I, PDTI_bMultiline : I ] mkPlugDlgTextInput;; fun deleteOb(inst, obstr)= VUIdestroyDialogBox obstr.PDTI_dlgstr; 0;; fun updateDialogSize(obstr)= let V3DgetSessionView c3dXsession -> viewstr in ( VUIupdateDialogBoxSize viewstr obstr.PDTI_dlgstr; let 500 -> sw in let if obstr.PDTI_bMultiline then [200 100 1] else [70 40 0] -> [sh textheight texthratio] in let VUIgetViewSize viewstr -> [cvw cvh] in let VUIcomputeDialogBoxSize viewstr (getThemeFromInstance obstr.PDTI_instance) (VUIgetElementText obstr.PDTI_dlgstr.VUIDLG_title) (VUIgetElementText obstr.PDTI_dlgstr.VUIDLG_frame) (if (obstr.PDTI_dlgstr.VUIDLG_okBtn == nil && obstr.PDTI_dlgstr.VUIDLG_cancelBtn == nil) then 0 else 1) -> [tlw tlh _ _ btnh] 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.PDTI_dlgstr.VUIDLG_title [100.0 (itof tlh)] nil; VUIsetElementSize obstr.PDTI_dlgstr.VUIDLG_frame nil [1 1 (-20) (-(10 + tlh + 10 + btnh))]; VUIsetElementPos obstr.PDTI_dlgstr.VUIDLG_frame [0.0 (itof (10 + tlh))] nil nil; VUIsetContainerSize obstr.PDTI_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.PDTI_sTitle = if (param == nil) || (!strcmp (strtrim param) "") then nil else strtrim param; if (obstr.PDTI_dlgstr == nil) then nil else ( VUIsetDialogTitle obstr.PDTI_dlgstr obstr.PDTI_sTitle; updateDialogSize obstr; ); 0;; fun cbSetText(inst, from, action, param, reply, obstr)= set obstr.PDTI_sText = if (param == nil) || (!strcmp (strtrim param) "") then nil else param; if (obstr.PDTI_dlgstr == nil) then nil else VUIsetElementTextContent obstr.PDTI_editstr obstr.PDTI_sText; 0;; fun cbClickDlg(dlgstr, state, obstr)= set obstr.PDTI_dlgstr = nil; if (!state) then nil else let VUIgetElementText obstr.PDTI_editstr -> text in SendPluginEvent obstr.PDTI_instance "Input text" text nil; SendPluginEvent obstr.PDTI_instance "Hidden" nil nil; 0;; fun cbValidate(eltstr, text, state, obstr)= if (!state) then nil else ( VUIdestroyDialogBox obstr.PDTI_dlgstr; cbClickDlg obstr.PDTI_dlgstr 1 obstr; ); 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 createDialog(param, obstr, show)= let V3DgetSessionView c3dXsession -> viewstr in let if (strcmpi obstr.PDTI_sTitle "") == 0 then nil else obstr.PDTI_sTitle -> title in let if (strcmp obstr.PDTI_sOkButton "") == 0 then loc "OS3DDTEXTINPUT_C0001" else obstr.PDTI_sOkButton -> okbutton in let if (strcmp obstr.PDTI_sCancelButton "") == 0 then nil else obstr.PDTI_sCancelButton -> cancelbutton in let 500 -> width in let if obstr.PDTI_bMultiline then [200 100 1] else [70 40 0] -> [height textheight texthratio] in let if obstr.PDTI_bMultiline then obstr.PDTI_sText else strcatnSep (lineextr obstr.PDTI_sText) " " -> text in let if text == nil then "" else text -> text in let VUIcreateDialogExt viewstr obstr.PDTI_instance.INST_groupstr.GRP_project.PRJ_vuiGroup [width height] title okbutton cancelbutton obstr.PDTI_iOpacity (V3DgetVrMode viewstr) (mkfun3 @cbClickDlg obstr) (hd obstr.PDTI_lthemeelts) -> dlgstr in let VUIgetDialogFrame dlgstr -> framestr in let VUIgetElementContainer framestr -> contstr in let VUIcreateEditTextExt contstr framestr [0.0 0.0] [100.0 (itof textheight)] [0 0 1 texthratio 0 0 0 0] [1 1] nil [10 5] text obstr.PDTI_bMultiline (hd tl obstr.PDTI_lthemeelts) -> editstr in ( VUIsetElementCbValidate editstr mkfun4 @cbValidate obstr; let if (!strcmp "" (strtrim param)) || param == nil then getAlign obstr.PDTI_sPos else getAlign param -> [pos align] in VUIsetContainerPos contstr pos align nil; set obstr.PDTI_dlgstr = dlgstr; set obstr.PDTI_editstr = editstr; VUIsetContainerThemeCallback contstr mkfun2 @cbDlgThemeUpdate obstr; VUIsetContainerClear contstr 0; VUIsetContainerFadeSpeed obstr.PDTI_dlgstr.VUIDLG_container obstr.PDTI_iFadeSpeed; VUIshowContainerBase obstr.PDTI_dlgstr.VUIDLG_container show; ); 0;; fun cbVrChange(inst, viewstr, state, obstr)= if obstr.PDTI_dlgstr == nil then nil else ( VUIdestroyDialogBox obstr.PDTI_dlgstr; createDialog nil obstr 1; ); 0;; fun cbCameraTeleport(inst, viewstr, camera, obstr)= if obstr.PDTI_dlgstr == nil then nil else ( VUIdestroyDialogBox obstr.PDTI_dlgstr; createDialog nil obstr 1; ); 0;; fun cbDialogVisibility(contstr, state, obstr)= if (state) then nil else ( VUIdestroyDialogBox obstr.PDTI_dlgstr; set obstr.PDTI_dlgstr = nil; ); SendPluginEvent obstr.PDTI_instance if (state) then "Shown" else "Hidden" nil nil; 0;; fun cbShow(inst, from, action, param, reply, obstr)= if obstr.PDTI_dlgstr == nil then nil else VUIdestroyDialogBox obstr.PDTI_dlgstr; createDialog param obstr 0; VUIshowContainerExt obstr.PDTI_dlgstr.VUIDLG_container 1 mkfun3 @cbDialogVisibility obstr; 0;; fun cbHide(inst, from, action, param, reply, obstr)= VUIshowContainerExt obstr.PDTI_dlgstr.VUIDLG_container 0 mkfun3 @cbDialogVisibility obstr; 0;; fun newOb(inst)= let getPluginInstanceParam inst "title" -> title in let if title == nil then "" else title -> title in let getPluginInstanceParam inst "okbtn" -> okbtn in let if (okbtn == nil) then "" else okbtn -> okbtn in let getPluginInstanceParam inst "cancelbtn" -> cancelbtn in let if (cancelbtn == nil) then "" else cancelbtn -> cancelbtn in let atoi (getPluginInstanceParam inst "multiline") -> multiline in let if (multiline == nil) then 0 else multiline -> multiline in let getPluginInstanceParam inst "text" -> text in let if (text == nil) then "" else text -> text in let loadThemeEltSelectorValues inst "dialogBox"::"common/editText"::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 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 mkPlugDlgTextInput [inst nil nil lthemeelts title okbtn cancelbtn text (strcatn vpos::" "::hpos::nil) opacity fadespeed multiline] -> 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 text" mkfun6 @cbSetText 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;;