/* ----------------------------------------------------------------------------- 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 ----------------------------------------------------------------------------- */ fun deleteOb(inst)= let (V3DgetSessionView c3dXsession) -> viewstr in ( V3DshowCursor viewstr 1; V3DenableMouse viewstr 1; ); 0;; fun cbInputClick(inst, viewstr, id, x, y, btn, pdata, p)= //if ((id == 0) || (id >= 512)) then let p -> [format absclick] in let pdata -> [obj mat _ dvec _ _] in ( if btn != 1 then nil else mutate p <- [_ [x y]]; if (format == 0) then ( if btn == 1 then SendPluginEvent inst "LeftClick" strcatn (itoa x)::" "::(itoa y)::nil nil else if btn == 2 then SendPluginEvent inst "RightClick" strcatn (itoa x)::" "::(itoa y)::nil nil else if btn == 16 then SendPluginEvent inst "MiddleClick" strcatn (itoa x)::" "::(itoa y)::nil nil else nil; ) else if (format == 1) then let dvec -> [dx dy dz] in let if dvec == nil then nil else strcatn (ftoa dx)::" "::(ftoa dy)::" "::(ftoa dz)::nil -> eparam in ( if btn == 1 then SendPluginEvent inst "LeftClick" eparam nil else if btn == 2 then SendPluginEvent inst "RightClick" eparam nil else if btn == 16 then SendPluginEvent inst "MiddleClick" eparam nil else nil; ) else if ((obj != nil) && !((SO3ObjectGetFlags obj) & iNodeFlagScene)) then nil else let SO3ObjectGetName obj -> objname in ( if btn == 1 then SendPluginEvent inst "LeftClick" objname nil else if btn == 2 then SendPluginEvent inst "RightClick" objname nil else if btn == 16 then SendPluginEvent inst "MiddleClick" objname nil else nil; ); ); //else nil; 0;; fun cbInputUnClick(inst, viewstr, id, x, y, btn, pdata, p)= //if ((id == 0) || (id >= 512)) then let p -> [format absclick] in let pdata -> [obj mat _ dvec _ _] in ( if (format == 0) then ( let absclick -> [ox oy] in if (btn != 1) || (ox != x) || (oy != y) then nil else SendPluginEvent inst "AbsoluteClick" strcatn (itoa x)::" "::(itoa y)::nil nil; if btn == 1 then SendPluginEvent inst "LeftUnClick" strcatn (itoa x)::" "::(itoa y)::nil nil else if btn == 2 then SendPluginEvent inst "RightUnClick" strcatn (itoa x)::" "::(itoa y)::nil nil else if btn == 16 then SendPluginEvent inst "MiddleUnClick" strcatn (itoa x)::" "::(itoa y)::nil nil else nil; ) else if (format == 1) then let V3DgetLastMouseData viewstr 0 -> [_ _ _ _ _ _ dvec _ _] in let dvec -> [dx dy dz] in let if dvec == nil then nil else strcatn (ftoa dx)::" "::(ftoa dy)::" "::(ftoa dz)::nil -> eparam in ( let absclick -> [ox oy] in if (btn != 1) || (ox != x) || (oy != y) then nil else SendPluginEvent inst "AbsoluteClick" eparam nil; if btn == 1 then SendPluginEvent inst "LeftUnClick" eparam nil else if btn == 2 then SendPluginEvent inst "RightUnClick" eparam nil else if btn == 16 then SendPluginEvent inst "MiddleUnClick" eparam nil else nil; ) else let V3DgetLastMouseData viewstr 0 -> [_ _ obj _ _ _ _ _ _] in if ((obj != nil) && !((SO3ObjectGetFlags obj) & iNodeFlagScene)) then nil else let SO3ObjectGetName obj -> objname in ( if btn == 1 then SendPluginEvent inst "LeftUnClick" objname nil else if btn == 2 then SendPluginEvent inst "RightUnClick" objname nil else if btn == 16 then SendPluginEvent inst "MiddleUnClick" objname nil else nil; ); ); //else nil; 0;; fun cbDbClick(inst, viewstr, x, y, btn, format)= if (btn != 1) then nil else ( if (format == 0) then SendPluginEvent inst "DbClick" strcatn (itoa x)::" "::(itoa y)::nil nil else if (format == 1) then let V3DgetLastMouseData viewstr 0 -> [_ _ _ _ _ _ dvec _ _] in let dvec -> [dx dy dz] in let if dvec == nil then nil else strcatn (ftoa dx)::" "::(ftoa dy)::" "::(ftoa dz)::nil -> eparam in SendPluginEvent inst "DbClick" eparam nil else let V3DgetLastMouseData viewstr 0 -> [_ _ obj _ _ _ _ _ _] in if ((obj != nil) && !((SO3ObjectGetFlags obj) & iNodeFlagScene)) then nil else let SO3ObjectGetName obj -> objname in SendPluginEvent inst "DbClick" objname nil; ); 0;; fun cbInputUpdate(inst, viewstr, id, x, y, btn, pdata, format)= //if ((id == 0) || (id >= 512)) then let pdata -> [obj _ _ dvec _ _] in ( if (format == 0) then SendPluginEvent inst "MouseMove" strcatn (itoa x)::" "::(itoa y)::nil nil else if (format == 1) then let dvec -> [dx dy dz] in let if dvec == nil then nil else strcatn (ftoa dx)::" "::(ftoa dy)::" "::(ftoa dz)::nil -> eparam in SendPluginEvent inst "MouseMove" eparam nil else if ((obj != nil) && !((SO3ObjectGetFlags obj) & iNodeFlagScene)) then nil else let SO3ObjectGetName obj -> objname in SendPluginEvent inst "MouseMove" objname nil; ); //else nil; 0;; fun cbMouseWheel(inst, viewstr, x, y, delta, btn)= SendPluginEvent inst "MouseWheel" itoa delta nil; 0;; fun cbEnable(inst, from, action, param, rep, format)= let (V3DgetSessionView c3dXsession) -> viewstr in V3DenableMouse viewstr 1; let [format [0 0]] -> p in ( setPluginInstanceCbInputClick inst mkfun8 @cbInputClick p; setPluginInstanceCbInputUnClick inst mkfun8 @cbInputUnClick p; setPluginInstanceCbDbClick inst mkfun6 @cbDbClick format; setPluginInstanceCbInputUpdate inst mkfun8 @cbInputUpdate format; setPluginInstanceCbWheel inst @cbMouseWheel; ); 0;; fun cbDisable(inst, from, action, param, rep)= let (V3DgetSessionView c3dXsession) -> viewstr in V3DenableMouse viewstr 0; setPluginInstanceCbInputClick inst nil; setPluginInstanceCbInputUnClick inst nil; setPluginInstanceCbDbClick inst nil; setPluginInstanceCbInputUpdate inst nil; setPluginInstanceCbWheel inst nil; 0;; fun cbShowCursor(inst, from, action, param, reply)= let (V3DgetSessionView c3dXsession) -> viewstr in let if (!strcmpi param "show") then 1 else if (!strcmpi param "hide") then 0 else (atoi param) -> state in V3DshowCursor viewstr state; 0;; fun cbSendSetPosition(inst, from, action, param, reply)= if param == nil then nil else let strextr param -> lp in let (nth_list (hd lp) 0) -> sx in let (nth_list (hd lp) 1) -> sy in let _GETscreenSize -> [vw vh] in let if (!strcmp "%" (substr sx ((strlen sx) - 1) 1)) then ftoi (((itof vw) /. 100.0) *. (atof (substr sx 0 ((strlen sx) - 1)))) else atoi sx -> px in let if (!strcmp "%" (substr sy ((strlen sy) - 1) 1)) then ftoi (((itof vh) /. 100.0) *. (atof (substr sy 0 ((strlen sy) - 1)))) else atoi sy -> py in let [(if px == nil then 0 else px) (if py == nil then 0 else py)] -> [px py] in _RMTCTRL_MouseMove px py RMTCTRL_ABSOLUTEMOVE; 0;; fun cbSetViewPosition(inst, from, action, param, reply)= if param == nil then nil else let strextr param -> lp in let (nth_list (hd lp) 0) -> sx in let (nth_list (hd lp) 1) -> sy in let V3DgetViewSize (V3DgetSessionView c3dXsession) -> [vw vh] in ( let if (!strcmp "%" (substr sx ((strlen sx) - 1) 1)) then ftoi (((itof vw) /. 100.0) *. (atof (substr sx 0 ((strlen sx) - 1)))) else atoi sx -> px in let if (!strcmp "%" (substr sy ((strlen sy) - 1) 1)) then ftoi (((itof vh) /. 100.0) *. (atof (substr sy 0 ((strlen sy) - 1)))) else atoi sy -> py in let [(if px == nil then 0 else px) (if py == nil then 0 else py)] -> [px py] in V3DsetMousePosition (V3DgetSessionView c3dXsession) px py; ); 0;; fun cbSendMoveCursor(inst, from, action, param, reply)= if param == nil then nil else let strextr param -> lp in let [(if (atoi (nth_list (hd lp) 0)) == nil then 0 else (atoi (nth_list (hd lp) 0))) (if (atoi (nth_list (hd lp) 1)) == nil then 0 else (atoi (nth_list (hd lp) 1)))] -> [px py] in let _GETscreenPos -> [mx my] in _RMTCTRL_MouseMove mx+px my+py RMTCTRL_ABSOLUTEMOVE; 0;; fun cbSendLeftCLick(inst, from, action, param, reply)= _RMTCTRL_MouseClick 1; _RMTCTRL_MouseUnClick 1; /* let (V3DgetSessionView c3dXsession) -> viewstr in let viewstr.V3D_tClickPos -> [posx posy] in ( SO3BufferInjectMouseMove viewstr.V3D_buffer posx posy 0; SO3BufferInjectMouseClick viewstr.V3D_buffer posx posy 1; SO3BufferInjectMouseUnClick viewstr.V3D_buffer posx posy 1; );*/ 0;; fun cbSendRightCLick(inst, from, action, param, reply)= _RMTCTRL_MouseClick 2; _RMTCTRL_MouseUnClick 2; /* let (V3DgetSessionView c3dXsession) -> viewstr in let viewstr.V3D_tClickPos -> [posx posy] in ( SO3BufferInjectMouseMove viewstr.V3D_buffer posx posy 0; SO3BufferInjectMouseClick viewstr.V3D_buffer posx posy 2; SO3BufferInjectMouseUnClick viewstr.V3D_buffer posx posy 2; );*/ 0;; fun cbSendMiddleCLick(inst, from, action, param, reply)= _RMTCTRL_MouseClick 16; _RMTCTRL_MouseUnClick 16; /* let (V3DgetSessionView c3dXsession) -> viewstr in let viewstr.V3D_tClickPos -> [posx posy] in ( SO3BufferInjectMouseMove viewstr.V3D_buffer posx posy 0; SO3BufferInjectMouseClick viewstr.V3D_buffer posx posy 16; SO3BufferInjectMouseUnClick viewstr.V3D_buffer posx posy 16; );*/ 0;; fun cbSendLeftDown(inst, from, action, param, reply)= _RMTCTRL_MouseClick 1; /* let (V3DgetSessionView c3dXsession) -> viewstr in let viewstr.V3D_tClickPos -> [posx posy] in ( SO3BufferInjectMouseMove viewstr.V3D_buffer posx posy 0; SO3BufferInjectMouseClick viewstr.V3D_buffer posx posy 1; );*/ 0;; fun cbSendRightDown(inst, from, action, param, reply)= _RMTCTRL_MouseClick 2; /* let (V3DgetSessionView c3dXsession) -> viewstr in let viewstr.V3D_tClickPos -> [posx posy] in ( SO3BufferInjectMouseMove viewstr.V3D_buffer posx posy 0; SO3BufferInjectMouseClick viewstr.V3D_buffer posx posy 2; );*/ 0;; fun cbSendMiddleDown(inst, from, action, param, reply)= _RMTCTRL_MouseClick 16; /* let (V3DgetSessionView c3dXsession) -> viewstr in let viewstr.V3D_tClickPos -> [posx posy] in ( SO3BufferInjectMouseMove viewstr.V3D_buffer posx posy 0; SO3BufferInjectMouseClick viewstr.V3D_buffer posx posy 16; );*/ 0;; fun cbSendLeftUp(inst, from, action, param, reply)= _RMTCTRL_MouseUnClick 1; /* let (V3DgetSessionView c3dXsession) -> viewstr in let viewstr.V3D_tClickPos -> [posx posy] in ( SO3BufferInjectMouseMove viewstr.V3D_buffer posx posy 0; SO3BufferInjectMouseUnClick viewstr.V3D_buffer posx posy 1; );*/ 0;; fun cbSendRightUp(inst, from, action, param, reply)= _RMTCTRL_MouseUnClick 2; /* let (V3DgetSessionView c3dXsession) -> viewstr in let viewstr.V3D_tClickPos -> [posx posy] in ( SO3BufferInjectMouseMove viewstr.V3D_buffer posx posy 0; SO3BufferInjectMouseUnClick viewstr.V3D_buffer posx posy 2; );*/ 0;; fun cbSendMiddleUp(inst, from, action, param, reply)= _RMTCTRL_MouseUnClick 16; /* let (V3DgetSessionView c3dXsession) -> viewstr in let viewstr.V3D_tClickPos -> [posx posy] in ( SO3BufferInjectMouseMove viewstr.V3D_buffer posx posy 0; SO3BufferInjectMouseUnClick viewstr.V3D_buffer posx posy 16; );*/ 0;; fun cbSendDbCLick(inst, from, action, param, reply)= _RMTCTRL_MouseDClick 1; /* let (V3DgetSessionView c3dXsession) -> viewstr in let viewstr.V3D_tClickPos -> [posx posy] in ( SO3BufferInjectMouseMove viewstr.V3D_buffer posx posy 0; SO3BufferInjectMouseClick viewstr.V3D_buffer posx posy 16; SO3BufferInjectMouseUnClick viewstr.V3D_buffer posx posy 16; );*/ 0;; fun cbGetCameraPositionAndDirection(inst, from, action, param, reply)= let (V3DgetSessionView c3dXsession) -> viewstr in let V3DgetDefaultViewport viewstr -> viewportstr in let SO3ViewportGetCamera viewportstr.V3D_viewport -> camera in let V3DgetLastMouseMove viewstr 0 -> [mx my] in let SO3ViewportGetWorldPosFromPixelPosition viewportstr.V3D_viewport mx my 0.15 -> [src dir] in let src -> [sx sy sz] in let dir -> [dx dy dz] in ( if (dir == nil) then nil else let strcatn (ftoa dx)::" "::(ftoa dy)::" "::(ftoa dz)::nil -> dirparam in SendPluginEvent inst "Direction" dirparam nil; if (src == nil) then nil else let strcatn (ftoa sx)::" "::(ftoa sy)::" "::(ftoa sz)::nil -> srcparam in SendPluginEvent inst "Camera position" srcparam nil; ); 0;; fun newOb(inst)= let atoi (getPluginInstanceParam inst "show") -> show in let if show == nil then 2 else show -> show in let atoi (getPluginInstanceParam inst "format") -> format in let if format == nil then 0 else format -> format in let atoi(getPluginInstanceParam inst "init") -> init in let if init == nil then 1 else init -> init in let (V3DgetSessionView c3dXsession) -> viewstr in ( if (show == 2) then nil else V3DshowCursor viewstr show; if init then cbEnable inst nil nil nil nil format else cbDisable inst nil nil nil nil; PluginRegisterAction inst "Show cursor" @cbShowCursor; PluginRegisterAction inst "Enable" mkfun6 @cbEnable format; PluginRegisterAction inst "Disable" @cbDisable; PluginRegisterAction inst "Set position" @cbSendSetPosition; PluginRegisterAction inst "Set view position" @cbSetViewPosition; PluginRegisterAction inst "Get camera position and direction" @cbGetCameraPositionAndDirection; PluginRegisterAction inst "Move cursor" @cbSendMoveCursor; PluginRegisterAction inst "LeftClick" @cbSendLeftCLick; PluginRegisterAction inst "RightClick" @cbSendRightCLick; PluginRegisterAction inst "MiddleClick" @cbSendMiddleCLick; PluginRegisterAction inst "LeftButtonDown" @cbSendLeftDown; PluginRegisterAction inst "RightButtonDown" @cbSendRightDown; PluginRegisterAction inst "MiddleButtonDown" @cbSendMiddleDown; PluginRegisterAction inst "LeftButtonUp" @cbSendLeftUp; PluginRegisterAction inst "RightButtonUp" @cbSendRightUp; PluginRegisterAction inst "MiddleButtonUp" @cbSendMiddleUp; PluginRegisterAction inst "DbClick" @cbSendDbCLick; setPluginInstanceCbDel inst @deleteOb; ); 0;; fun IniPlug(file)= PlugRegister @newOb nil; setPluginEditor @dynamicedit; 0;;