/* ----------------------------------------------------------------------------- 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 PlugDialog = [ PDLG_instance : PInstance, PDLG_dlgstr : VUIDlg, PDLG_lthemeelts : [S r1], PDLG_sTitle : S, PDLG_sText : S, PDLG_sButton1 : S, PDLG_sButton2 : S, PDLG_iAlign : I, PDLG_sPos : S, PDLG_iOpacity : I, PDLG_iFadeSpeed : I ]mkPlugDialog;; fun deleteOb(inst, obstr)= VUIdestroyDialogBox obstr.PDLG_dlgstr; 0;; fun cbClickDlg(dlgstr, state, obstr)= set obstr.PDLG_dlgstr = nil; if (state == 1) then SendPluginEvent obstr.PDLG_instance "Click button 1" nil nil else SendPluginEvent obstr.PDLG_instance "Click button 2" nil nil; SendPluginEvent obstr.PDLG_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 cbSetText(inst, from, action, param, reply, obstr)= set obstr.PDLG_sText = if (param == nil) || (!strcmp (strtrim param) "") then nil else strtrim param; if (obstr.PDLG_dlgstr == nil) then nil else ( VUIsetDialogText obstr.PDLG_dlgstr obstr.PDLG_sText; VUIupdateDialogBoxSize (V3DgetSessionView c3dXsession) obstr.PDLG_dlgstr; ); 0;; fun cbSetTitle(inst, from, action, param, reply, obstr)= set obstr.PDLG_sTitle = if (param == nil) || (!strcmp (strtrim param) "") then nil else strtrim param; if (obstr.PDLG_dlgstr == nil) then nil else ( VUIsetDialogTitle obstr.PDLG_dlgstr obstr.PDLG_sTitle; VUIupdateDialogBoxSize (V3DgetSessionView c3dXsession) obstr.PDLG_dlgstr; ); 0;; fun cbResizeView(inst, viewstr, w, h, obstr)= VUIupdateDialogBoxSize viewstr obstr.PDLG_dlgstr; 0;; fun createDialog(param, obstr, show)= let V3DgetSessionView c3dXsession -> viewstr in let if (strcmpi obstr.PDLG_sTitle "") == 0 then nil else _DMSapplyByGlobalVar obstr.PDLG_sTitle -> title in let if (strcmpi obstr.PDLG_sButton1 "") == 0 then nil else obstr.PDLG_sButton1 -> button1 in let if (strcmpi obstr.PDLG_sButton2 "") == 0 then nil else obstr.PDLG_sButton2 -> button2 in set obstr.PDLG_dlgstr = VUIcreateDialogBoxExt (V3DgetSessionView c3dXsession) (getVUIgroupFromInstance obstr.PDLG_instance) title _DMSapplyByGlobalVar obstr.PDLG_sText button1 button2 obstr.PDLG_iOpacity (V3DgetVrMode viewstr) (mkfun3 @cbClickDlg obstr) (hd obstr.PDLG_lthemeelts); let VUIgetDialogFrame obstr.PDLG_dlgstr -> framestr in let VUIgetElementContainer framestr -> contstr in ( let if (!strcmp "" (strtrim param)) || param == nil then getAlign obstr.PDLG_sPos else getAlign param -> [pos align] in VUIsetContainerPos contstr pos align nil; VUIsetElementTextAlign framestr obstr.PDLG_iAlign|iVUITEXT_VALIGNCENTER; VUIsetContainerClear contstr 0; VUIsetContainerFadeSpeed obstr.PDLG_dlgstr.VUIDLG_container obstr.PDLG_iFadeSpeed; VUIshowContainerBase obstr.PDLG_dlgstr.VUIDLG_container show; ); 0;; fun cbDialogVisibility(contstr, state, obstr)= if (state) then nil else ( VUIdestroyDialogBox obstr.PDLG_dlgstr; setPluginInstanceCbResizeView obstr.PDLG_instance nil; set obstr.PDLG_dlgstr = nil; ); SendPluginEvent obstr.PDLG_instance if (state) then "Shown" else "Hidden" nil nil; 0;; fun cbShow(inst, from, action, param, reply, obstr)= if obstr.PDLG_dlgstr == nil then nil else VUIdestroyDialogBox obstr.PDLG_dlgstr; createDialog param obstr 0; setPluginInstanceCbResizeView inst mkfun5 @cbResizeView obstr; VUIshowContainerExt obstr.PDLG_dlgstr.VUIDLG_container 1 mkfun3 @cbDialogVisibility obstr; 0;; fun cbHide(inst, from, action, param, reply, obstr)= VUIshowContainerExt obstr.PDLG_dlgstr.VUIDLG_container 0 mkfun3 @cbDialogVisibility obstr; 0;; fun cbVrChange(inst, viewstr, state, obstr)= if obstr.PDLG_dlgstr == nil then nil else ( VUIdestroyDialogBox obstr.PDLG_dlgstr; createDialog nil obstr 1; ); 0;; fun cbCameraTeleport(inst, viewstr, camera, obstr)= if obstr.PDLG_dlgstr == nil then nil else ( VUIdestroyDialogBox obstr.PDLG_dlgstr; createDialog nil obstr 1; ); 0;; fun newOb(inst)= let getPluginInstanceParam inst "title" -> title in let if title == nil then "" else title -> title in let getPluginInstanceParam inst "button1" -> button1 in let if button1 == nil then "" else button1 -> button1 in let getPluginInstanceParam inst "button2" -> button2 in let if button2 == nil then "" else button2 -> button2 in let getPluginInstanceParam inst "text" -> text in let if text == nil then "" else text -> text in let loadThemeEltSelectorValues inst "dialogBox"::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 atoi (getPluginInstanceParam inst "textalign") -> textalign in let if (textalign == nil) then 1 else textalign -> textalign in let if (textalign == 0) then iVUITEXT_HALIGNLEFT else if (textalign == 2) then iVUITEXT_HALIGNRIGHT else iVUITEXT_HALIGNCENTER -> textalign 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 mkPlugDialog [inst nil lthemeelts title text button1 button2 textalign (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 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;;