/* ----------------------------------------------------------------------------- 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 ----------------------------------------------------------------------------- */ typeof sPreviousDir = S;; fun deleteOb(inst, p)= let p -> [inst filePrefix dateFormat usedialog only3d hideoverlay withalpha currentSize width height hideunit dlgstr] in VUIdestroyDialogBox dlgstr; 0;; fun proceedScreenShot(inst, wfile, only3d, width, height, hideoverlay, withalpha, usedialog)= if (wfile == nil) then nil else ( let _WtoP wfile -> pfile in let _PtoScol pfile -> sfile in let if (sfile == nil) then _PtoS pfile else sfile -> sfile in if (only3d) then ( //let V3DgetSessionView c3dXsession -> viewstr in //(SO3BufferWriteContent viewstr.V3D_buffer (_getmodifypack file)) let V3DgetDefaultViewport (V3DgetSessionView c3dXsession) -> viewportstr in if (SO3ViewportWriteContent viewportstr.V3D_viewport wfile width height !hideoverlay withalpha) == nil then nil else SendPluginEvent inst "Saved" sfile nil; if ((_platform != SCOL_PLATFORM_ANDROID) || (!usedialog)) then nil else _shareaction "image/png" nil pfile "Share screenshot to"; 0; ) else ( let _GETscreenSize -> [sw sh] in let _FILLbitmap _CRbitmap _channel sw sh 0x0 -> bmp in let _CAPTUREscreen bmp 0 0 sw sh 0 -> bmp in ( _SAVEjpeg bmp wfile 90; _DSbitmap bmp; SendPluginEvent inst "Saved" sfile nil; ); if ((_platform != SCOL_PLATFORM_ANDROID) || (!usedialog)) then nil else _shareaction "image/jpeg" nil pfile "Share screenshot to"; 0; ); ); 0;; fun cbScreenshotTrm(trm, p)= _deltimer trm; let p -> [inst wfile only3d width height hideoverlay withalpha usedialog] in proceedScreenShot inst wfile only3d width height hideoverlay withalpha usedialog; 0;; fun cbDlgSaveScreenShot(dlg, p, wfile)= let p -> [inst only3d width height hideoverlay withalpha usedialog] in if (wfile == nil) then nil else ( SendPluginEvent inst "Init screenshot" nil nil; _rfltimer _starttimer _channel 100 @cbScreenshotTrm [inst wfile only3d width height hideoverlay withalpha usedialog]; ); 0;; fun cbTakeShot(inst, from, action, param, rep, p)= let p -> [_ filePrefix dateFormat usedialog only3d hideoverlay withalpha currentSize dwidth dheight hideunit dlgstr] in let V3DgetSessionView c3dXsession -> viewstr in let V3DgetDefaultViewport viewstr -> viewportstr in let V3DgetViewportSize viewstr viewportstr -> [_ _ vw vh] in let if (!strcmpi param "auto") then [vw vh] else if ((param == nil) && !currentSize) then [dwidth dheight] else let strextr param -> lp in let atoi (nth_list (hd lp) 0) -> width in let atoi (nth_list (hd lp) 1) -> height in [if width != nil then width else (if currentSize then vw else dwidth) if height != nil then height else (if currentSize then vh else dheight)] -> [width height] in let (localtime time) -> [seconds minutes hours day month year wd yd] in let if dateFormat == 0 then (strtrim strreplace (strreplace (ctime time) " " "_") ":" "-") else if dateFormat == 1 then strcatn (itoa year)::(if month < 10 then "0" else "")::(itoa month)::(if day < 10 then "0" else "")::(itoa day)::"_"::(if hours < 10 then "0" else "")::(itoa hours)::(if minutes < 10 then "0" else "")::(itoa minutes)::(if seconds < 10 then "0" else "")::(itoa seconds)::nil else itoa abs time -> formateddate in let strcatn filePrefix::formateddate::(if only3d then ".png" else ".jpg")::nil -> file in ( if (hideunit) then SendPluginEvent inst "Hide unit scale" nil nil else SendPluginEvent inst "Show unit scale" nil nil; if (usedialog) then ( if (_platform != SCOL_PLATFORM_ANDROID) then let getPathFile file nil -> [dir fname] in ( if (sPreviousDir != nil) then nil else set sPreviousDir = dir; let _DLGSaveFile _channel DMSwin sPreviousDir fname "PNG format\0*.png\0JPG format\0*.jpg\0All\0*.*\0\0" -> dlg in ( //for devices with no _DLGSaveFile implementation if (dlg != nil) then ( _DLGrflsave dlg @cbDlgSaveScreenShot [inst only3d width height hideoverlay withalpha usedialog]; 0; ) else ( SendPluginEvent inst "Init screenshot" nil nil; _rfltimer _starttimer _channel 100 @cbScreenshotTrm [inst (_getmodifypack file) only3d width height hideoverlay withalpha usedialog]; 0; ); ); ) else ( SendPluginEvent inst "Init screenshot" nil nil; _rfltimer _starttimer _channel 100 @cbScreenshotTrm [inst (_getmodifypack file) only3d width height hideoverlay withalpha usedialog]; 0; ); 0; ) else ( SendPluginEvent inst "Init screenshot" nil nil; _rfltimer _starttimer _channel 100 @cbScreenshotTrm [inst (_getmodifypack file) only3d width height hideoverlay withalpha usedialog]; 0; ); ); 0;; fun cbSetSize(inst, from, action, param, reply, p)= let p -> [_ filePrefix dateFormat usedialog only3d hideoverlay withalpha currentSize dwidth dheight hideunit dlgstr] in if (!strcmpi param "auto") then mutate p <- [_ _ _ _ _ _ _ 1 _ _ _ _] else let strextr param -> lp in let atoi (nth_list (hd lp) 0) -> width in let atoi (nth_list (hd lp) 1) -> height in mutate p <- [_ _ _ _ _ _ _ _ (if (width == nil) then dwidth else width) (if (height == nil) then dheight else height) _ _]; 0;; fun cbSetAlpha(inst, from, action, param, reply, p)= let XMLgetBoolValue param 0 -> state in mutate p <- [_ _ _ _ _ _ state _ _ _ _ _]; 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 cbClickDlg(dlgstr, state, p)= if (!state) then nil else let p -> [inst filePrefix dateFormat usedialog only3d hideoverlay withalpha currentSize width height hideunit dlgstr] in cbTakeShot inst nil nil nil nil p; mutate p <- [_ _ _ _ _ _ _ _ _ _ _ nil]; 0;; fun cbChangeValue(floatstr, coef, state, np)= let np -> [p mode] in if (mode == 1) then mutate p <- [_ _ _ _ _ _ _ _ (ftoi coef) _ _ _] else mutate p <- [_ _ _ _ _ _ _ _ _ (ftoi coef) _ _]; 0;; fun cbCheckTrans(eltstr, state, p)= mutate p <- [_ _ _ _ _ _ state _ _ _ _ _]; 0;; fun cbCheckUnit(eltstr, state, p)= mutate p <- [_ _ _ _ _ _ _ _ _ _ state _]; 0;; fun cbShowInterface(inst, from, action, param, reply, p)= let p -> [_ filePrefix dateFormat usedialog only3d hideoverlay withalpha currentSize width height hideunit dlgstr] in ( if (dlgstr == nil) then nil else VUIdestroyDialogBox dlgstr; let V3DgetSessionView c3dXsession -> viewstr in let VUIcreateDialogExt (V3DgetSessionView c3dXsession) inst.INST_groupstr.GRP_project.PRJ_vuiGroup [350 190] (loc "OS3DSCREENSHOT_C0001") (loc "OS3DSCREENSHOT_C0002") (loc "OS3DSCREENSHOT_C0003") 95 (V3DgetVrMode viewstr) (mkfun3 @cbClickDlg p) "dialogBox" -> dlgstr in let VUIgetDialogFrame dlgstr -> framestr in let VUIgetElementContainer framestr -> contstr in let VUIgetThemeDef (getThemeFromInstance inst) "common" -> cdefstr in let VUIgetThemeDef (getThemeFromInstance inst) "dialogBox" -> defstr in let VUIgetThemeFont cdefstr "check" -> lbcfontstr in let VUIgetThemeFont defstr "label" -> lbfontstr in let VUIcreateButton contstr framestr [0.0 10.0] [24.0 24.0] [0 0 0 0 0 0 0 0] [0 0] -> transstr in let VUIcreateFrame contstr framestr [35.0 5.0] [100.0 0.0] [0 0 1 0 0 0 (-45) 0] [0 0] -> ltrans in let VUIcreateButton contstr framestr [0.0 50.0] [24.0 24.0] [0 0 0 0 0 0 0 0] [0 0] -> unitstr in let VUIcreateFrame contstr framestr [35.0 45.0] [100.0 0.0] [0 0 1 0 0 0 (-45) 0] [0 0] -> lunit in let VUIcreateFrame contstr framestr [0.0 90.0] [70.0 0.0] [0 0 0 0 0 0 0 0] [0 0] -> lwidth in let VUIcreateFrame contstr framestr [0.0 130.0] [70.0 0.0] [0 0 0 0 0 0 0 0] [0 0] -> lheight in let VUIcreateFloat contstr framestr [40.0 90.0] [100.0 35.0] [0 0 1 0 0 0 (-60) 0] [1 0] [5 5] 32.0 10000.0 100.0 0 (itof width) -> wfloatstr in let VUIcreateFloat contstr framestr [40.0 130.0] [100.0 35.0] [0 0 1 0 0 0 (-60) 0] [1 0] [5 5] 32.0 10000.0 100.0 0 (itof height) -> hfloatstr in ( VUIsetElementTheme transstr cdefstr "check"; VUIsetElementTheme unitstr cdefstr "check"; VUIsetElementCheckState transstr withalpha; VUIsetElementCheckState unitstr hideunit; VUIsetElementCbCheck transstr mkfun3 @cbCheckTrans p; VUIsetElementCbCheck unitstr mkfun3 @cbCheckUnit p; VUIsetElementText ltrans lbcfontstr (loc "OS3DSCREENSHOT_C0004") [0 0] [0 0] [5 5] iVUITEXT_HALIGNLEFT|iVUITEXT_VALIGNTOP VUI_TextAutoHeight 1; VUIsetElementText lunit lbcfontstr (loc "OS3DSCREENSHOT_C0005") [0 0] [0 0] [5 5] iVUITEXT_HALIGNLEFT|iVUITEXT_VALIGNTOP VUI_TextAutoHeight 1; VUIsetElementText lwidth lbfontstr (loc "OS3DSCREENSHOT_C0006") [0 0] [0 0] [5 5] iVUITEXT_HALIGNLEFT|iVUITEXT_VALIGNTOP VUI_TextAutoHeight 1; VUIsetElementText lheight lbfontstr (loc "OS3DSCREENSHOT_C0007") [0 0] [0 0] [5 5] iVUITEXT_HALIGNLEFT|iVUITEXT_VALIGNTOP VUI_TextAutoHeight 1; VUIsetFloatCbChange wfloatstr mkfun4 @cbChangeValue [p 1]; VUIsetFloatCbChange hfloatstr mkfun4 @cbChangeValue [p 2]; if (!strcmp "" (strtrim param)) || param == nil then nil else let getAlign param -> [pos align] in VUIsetContainerPos contstr pos align nil; VUIsetContainerClear contstr 0; VUIshowDialog dlgstr 1; mutate p <- [_ _ _ _ _ _ _ _ _ _ _ dlgstr]; ); //SendPluginEvent inst "Shown" nil nil; ); 0;; fun newOb(inst)= let (getPluginInstanceParam inst "filePrefix") -> filePrefix in let if filePrefix == nil then "screenshots/" else filePrefix -> filePrefix in let atoi (getPluginInstanceParam inst "dateFormat") -> dateFormat in let if dateFormat == nil then 0 else dateFormat -> dateFormat in let atoi (getPluginInstanceParam inst "useFileDialog") -> usedialog in let if (usedialog == nil) then 0 else usedialog -> usedialog in let atoi (getPluginInstanceParam inst "only3d") -> only3d in let if (only3d == nil) then 1 else only3d -> only3d in let atoi (getPluginInstanceParam inst "hideOverlay") -> hideoverlay in let if (hideoverlay == nil) then 0 else hideoverlay -> hideoverlay in let atoi (getPluginInstanceParam inst "withAlpha") -> withalpha in let if (withalpha == nil) then 0 else withalpha -> withalpha in let atoi (getPluginInstanceParam inst "currentSize") -> currentSize in let if (currentSize == nil) then 1 else currentSize -> currentSize in let atoi (getPluginInstanceParam inst "width") -> width in let if (width == nil) then 1280 else width -> width in let atoi (getPluginInstanceParam inst "height") -> height in let if (height == nil) then 720 else height -> height in let [inst filePrefix dateFormat usedialog only3d hideoverlay withalpha currentSize width height 0 nil] -> p in ( PluginRegisterAction inst "Take shot" mkfun6 @cbTakeShot p; PluginRegisterAction inst "Set size" mkfun6 @cbSetSize p; PluginRegisterAction inst "Set alpha" mkfun6 @cbSetAlpha p; PluginRegisterAction inst "Open interface" mkfun6 @cbShowInterface p; setPluginInstanceCbDel inst mkfun2 @deleteOb p; ); 0;; fun IniPlug(file)= PlugRegister @newOb nil; setPluginEditor @dynamicedit; 0;;