/* ----------------------------------------------------------------------------- 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 MenuUnit = [ MU_button : VUIBtnMenu, MU_subMenu : VUISubMenu, MU_parentstr : MenuUnit, MU_sLabel : S, MU_sId : S, MU_sEvent : S, MU_iDepth : I, MU_iNumber : I, MU_iMode : I, MU_bIsUrl : I, MU_sPath : S, MU_iStates : I, MU_iNbFrames : I, MU_iNbFps : I, MU_bUnfold : I, MU_bIsCheckable : I, MU_bCheckInit : I, MU_lChildren : [MenuUnit r1] ]mkMenuUnit;; struct PlugMenu = [ PMN_instance : PInstance, PMN_contstr : VUIcontainer, PMN_menustr : VUImenu, PMN_lthemeelts : [S r1], PMN_posstr : InterfacePos, PMN_lMenu : [MenuUnit r1], PMN_iMenuPos : I, PMN_tMargin : [I I], PMN_tLevelOffset : [I I] ]mkPlugMenu;; fun deleteOb(inst, obstr)= VUIdestroyContainer obstr.PMN_contstr; 0;; fun cbHide(inst, from, action, param, reply, obstr)= VUIshowContainer obstr.PMN_contstr 0; SendPluginEvent inst "Hidden" nil nil; 0;; fun cbShow(inst, from, action, param, reply, obstr)= VUIshowContainer obstr.PMN_contstr 1; SendPluginEvent inst "Shown" nil nil; 0;; fun cbSubMenuSelect(smenustr, p)= let p -> [inst menuunit] in ( if menuunit.MU_bIsCheckable then ( if smenustr.VUIMS_iCheckState then SendPluginEvent inst (strcat menuunit.MU_sEvent " checked") nil nil else SendPluginEvent inst (strcat menuunit.MU_sEvent " unchecked") nil nil; ) else SendPluginEvent inst menuunit.MU_sEvent nil nil; ); 0;; fun cbCheckSubmenu(inst, from, action, param, reply, menuunit)= set menuunit.MU_subMenu.VUIMS_iCheckState = 1; 0;; fun cbUncheckSubmenu(inst, from, action, param, reply, menuunit)= set menuunit.MU_subMenu.VUIMS_iCheckState = 0; 0;; fun cbMenuButtonSelect(bmenustr, p)= let p -> [inst menuunit] in ( if !menuunit.MU_bUnfold then nil else ( let menuunit.MU_button.VUIMB_list.VUIL_lListElts -> lListelem in while (lListelem != nil) do ( VUIunfoldListElement (hd lListelem) 1; set lListelem = tl lListelem; ); ); SendPluginEvent inst menuunit.MU_sEvent nil nil; ); 0;; fun createSubMenu(inst, menuunit)= if menuunit.MU_lChildren == nil then nil else ( let sizelist menuunit.MU_lChildren -> size in let 0 -> i in while i < size do ( let nth_list menuunit.MU_lChildren i -> child in ( set child.MU_sEvent = strcatn menuunit.MU_sEvent::" > "::child.MU_sId::nil; set child.MU_subMenu = VUIaddSubMenu menuunit.MU_button menuunit.MU_subMenu child.MU_sLabel child.MU_bIsCheckable; VUIsetCbSubMenu child.MU_subMenu mkfun2 @cbSubMenuSelect [inst child]; if !(child.MU_bIsCheckable) then nil else ( set child.MU_subMenu.VUIMS_iCheckState = child.MU_bCheckInit; PluginRegisterAction inst (strcat child.MU_sEvent " check") mkfun6 @cbCheckSubmenu child; PluginRegisterAction inst (strcat child.MU_sEvent " uncheck") mkfun6 @cbUncheckSubmenu child; ); createSubMenu inst child; ); set i = i + 1; ); ); 0;; fun createMenu(inst, obstr)= set obstr.PMN_contstr = crInterfacePosContainer inst obstr.PMN_posstr c3dXsession; VUIsetContainerBackground obstr.PMN_contstr nil nil nil /*0xFF0000FF*/ nil nil nil nil nil; set obstr.PMN_menustr = VUIcreateMenuExt obstr.PMN_contstr nil [0.0 0.0] [100.0 100.0] [0 0 1 1 0 0 0 0] [0 0] obstr.PMN_tMargin obstr.PMN_tLevelOffset obstr.PMN_iMenuPos (hd obstr.PMN_lthemeelts); let sizelist obstr.PMN_lMenu -> size in let 0 -> i in while (i < size) do ( let nth_list obstr.PMN_lMenu i -> menuunit in let _checkpack menuunit.MU_sPath -> file in ( set menuunit.MU_sEvent = menuunit.MU_sId; if menuunit.MU_iMode == 0 then ( set menuunit.MU_button = VUIaddMenuButton obstr.PMN_menustr [0.0 0.0] menuunit.MU_sLabel 0 0; if (file == nil) then nil else VUIsetElementResource menuunit.MU_button.VUIMB_element nil nil nil file VUI_ResSplited menuunit.MU_iStates (1 + menuunit.MU_bIsCheckable) menuunit.MU_iNbFrames menuunit.MU_iNbFps; 0; ) else ( set menuunit.MU_button = VUIaddMenuButton obstr.PMN_menustr [0.0 0.0] menuunit.MU_sLabel 1 0; if (file == nil) then nil else VUIsetElementResource menuunit.MU_button.VUIMB_element nil nil nil file VUI_ResStreched menuunit.MU_iStates (1 + menuunit.MU_bIsCheckable) menuunit.MU_iNbFrames menuunit.MU_iNbFps; let VUIgetElementResource menuunit.MU_button.VUIMB_element -> resstr in let VUIgetResourceVisualSize resstr -> [rw rh] in VUIsetElementSize menuunit.MU_button.VUIMB_element [(itof rw) (itof rh)] nil; 0; ); VUIsetCbMenuButton menuunit.MU_button mkfun2 @cbMenuButtonSelect [inst menuunit]; createSubMenu inst menuunit; ); set i = i + 1; ); 0;; fun loadMenuUnit(inst, parent, menu, lchildren, suffix)= if menu.MU_iDepth !=1 then nil else ( let (getPluginInstanceParam inst strcat "path" suffix) -> path in let if (strcmp path "") == 0 then nil else path -> path in let atoi (getPluginInstanceParam inst strcat "mode" suffix) -> mode in let if mode == nil then 0 else mode -> mode in let atoi (getPluginInstanceParam inst strcat "isurl" suffix) -> isurl in let if isurl == nil then 0 else isurl -> isurl in let (getPluginInstanceParam inst strcat "url" suffix) -> url in let if (strcmp url "") == 0 then nil else url -> url in let if !isurl then path else url -> file in let atoi (getPluginInstanceParam inst strcat "btnstates" suffix) -> btnstates in let if btnstates == nil then 0 else btnstates -> btnstates in let atoi (getPluginInstanceParam inst strcat "nbframes" suffix) -> nbframes in let if (nbframes == nil) || (nbframes < 1) then 1 else nbframes -> nbframes in let atoi (getPluginInstanceParam inst strcat "nbfps" suffix) -> nbfps in let if (nbfps == nil) || (nbfps < 0) then 0 else nbfps -> nbfps in let atoi (getPluginInstanceParam inst strcat "unfold" suffix) -> unfold in let if (unfold == nil) then 0 else unfold -> unfold in ( set menu.MU_iMode = mode; set menu.MU_bIsUrl = isurl; set menu.MU_sPath = file; set menu.MU_iStates = btnstates; set menu.MU_iNbFrames = nbframes; set menu.MU_iNbFps = nbfps; set menu.MU_bUnfold = unfold; ); ); let (getPluginInstanceParam inst strcat "id" suffix) -> id in let atoi (getPluginInstanceParam inst strcat "ischeckable" suffix) -> ischeckable in let if (ischeckable == nil) then 0 else ischeckable -> ischeckable in let atoi (getPluginInstanceParam inst strcat "checkinit" suffix) -> checkinit in let if (checkinit == nil) then 0 else checkinit -> checkinit in ( set menu.MU_sId = id; set menu.MU_parentstr = parent; set menu.MU_lChildren = lchildren; set menu.MU_bIsCheckable = ischeckable; set menu.MU_bCheckInit = checkinit; ); 0;; fun loadMenuList(inst, parent, type, suffix)= let if suffix == nil then "" else suffix -> suffix in let if type == nil then 1 else type -> type in let nil -> lmenu in let 0 -> i in let 0 -> end in ( while end != 1 do ( let (strcatn suffix::"_"::(itoa i)::nil) -> newsuffix in let getPluginInstanceParam inst strcat "item" newsuffix -> label in ( if label == nil then set end = 1 else ( let mkMenuUnit [nil nil nil label nil nil type i nil nil nil nil nil nil nil nil nil nil] -> newMenu in let loadMenuList inst newMenu (type + 1) newsuffix -> lchildren in ( loadMenuUnit inst parent newMenu lchildren newsuffix; set lmenu = newMenu::lmenu; ); 0; ); ); set i = i + 1; ); revertlist lmenu; );; fun newOb(inst)= let loadInterfacePos inst c3dXsession -> posstr in let loadMenuList inst nil nil nil -> lmenu in let atoi (getPluginInstanceParam inst "menupos") -> menupos in let if (menupos == nil) then 0 else menupos -> menupos in let atoi (getPluginInstanceParam inst "xmargin") -> xmargin in let if (xmargin == nil) then 5 else xmargin -> xmargin in let atoi (getPluginInstanceParam inst "ymargin") -> ymargin in let if (ymargin == nil) then 5 else ymargin -> ymargin in let atoi (getPluginInstanceParam inst "levelxoffset") -> levelxoffset in let if (levelxoffset == nil) then 10 else levelxoffset -> levelxoffset in let atoi (getPluginInstanceParam inst "levelyoffset") -> levelyoffset in let if (levelyoffset == nil) then 0 else levelyoffset -> levelyoffset in let loadThemeEltSelectorValues inst "menu"::nil -> lthemeelts in let atoi (getPluginInstanceParam inst "show") -> show in let if (show == nil) then 1 else show -> show in let mkPlugMenu [inst nil nil lthemeelts posstr lmenu menupos [xmargin ymargin] [levelxoffset levelyoffset]] -> obstr in ( createMenu inst obstr; if !show then nil else cbShow inst nil nil nil nil obstr; PluginRegisterAction inst "Show" mkfun6 @cbShow obstr; PluginRegisterAction inst "Hide" mkfun6 @cbHide obstr; setPluginInstanceCbDel inst mkfun2 @deleteOb obstr; ); 0;; fun IniPlug(file)= VUIsetEnable c3dXsession 1; PlugRegister @newOb nil; setPluginEditor @dynamicedit; 0;;