/* ----------------------------------------------------------------------------- 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)= 0;; struct CountStr = [ PCOUNT_top : I, PCOUNT_value : I ] MkCountStr;; fun cbGetValue(inst, from, action, param, reply, varstr)= SendPluginEvent inst "Value" (itoa varstr.PCOUNT_value) nil; 0;; fun cbSetValue(inst, from, action, param, reply, varstr)= if ((atoi param) == nil) then nil else ( let (atoi param) -> p in let if ((p < varstr.PCOUNT_top) && (varstr.PCOUNT_top > 0)) || ((p > varstr.PCOUNT_top) && (varstr.PCOUNT_top < 0)) then p else varstr.PCOUNT_top -> p in let if ((varstr.PCOUNT_top > 0) && (p < 0)) || ((varstr.PCOUNT_top < 0) && (p > 0)) then 0 else p -> p in if (p == varstr.PCOUNT_value) then nil else ( set varstr.PCOUNT_value = p; if ((varstr.PCOUNT_value < varstr.PCOUNT_top) && (varstr.PCOUNT_top > 0)) || ((varstr.PCOUNT_value > varstr.PCOUNT_top) && (varstr.PCOUNT_top < 0)) then nil else SendPluginEvent inst "Top" (itoa varstr.PCOUNT_value) nil; if (varstr.PCOUNT_value != 0) then nil else SendPluginEvent inst "Begin" (itoa varstr.PCOUNT_value) nil; SendPluginEvent inst "Modified" (itoa varstr.PCOUNT_value) nil; ); ); 0;; fun cbIncrement(inst, from, action, param, reply, varstr)= let if ((atoi param) == nil) then 1 else (atoi param) -> p in let varstr.PCOUNT_value + p -> p in let if ((p < varstr.PCOUNT_top) && (varstr.PCOUNT_top > 0)) || ((p > varstr.PCOUNT_top) && (varstr.PCOUNT_top < 0)) then p else varstr.PCOUNT_top -> p in let if ((varstr.PCOUNT_top > 0) && (p < 0)) || ((varstr.PCOUNT_top < 0) && (p > 0)) then 0 else p -> p in if (p == varstr.PCOUNT_value) then nil else ( set varstr.PCOUNT_value = p; if ((varstr.PCOUNT_value < varstr.PCOUNT_top) && (varstr.PCOUNT_top > 0)) || ((varstr.PCOUNT_value > varstr.PCOUNT_top) && (varstr.PCOUNT_top < 0)) then nil else SendPluginEvent inst "Top" (itoa varstr.PCOUNT_value) nil; if (varstr.PCOUNT_value != 0) then nil else SendPluginEvent inst "Begin" (itoa varstr.PCOUNT_value) nil; SendPluginEvent inst "Modified" (itoa varstr.PCOUNT_value) nil; ); 0;; fun cbDecrement(inst, from, action, param, reply, varstr)= let if ((atoi param) == nil) then 1 else (atoi param) -> p in let varstr.PCOUNT_value - p -> p in let if ((p < varstr.PCOUNT_top) && (varstr.PCOUNT_top > 0)) || ((p > varstr.PCOUNT_top) && (varstr.PCOUNT_top < 0)) then p else varstr.PCOUNT_top -> p in let if ((varstr.PCOUNT_top > 0) && (p < 0)) || ((varstr.PCOUNT_top < 0) && (p > 0)) then 0 else p -> p in if (p == varstr.PCOUNT_value) then nil else ( set varstr.PCOUNT_value = p; if ((varstr.PCOUNT_value < varstr.PCOUNT_top) && (varstr.PCOUNT_top > 0)) || ((varstr.PCOUNT_value > varstr.PCOUNT_top) && (varstr.PCOUNT_top < 0)) then nil else SendPluginEvent inst "Top" (itoa varstr.PCOUNT_value) nil; if (varstr.PCOUNT_value != 0) then nil else SendPluginEvent inst "Begin" (itoa varstr.PCOUNT_value) nil; SendPluginEvent inst "Modified" (itoa varstr.PCOUNT_value) nil; ); 0;; fun cbReset(inst, from, action, param, reply, varstr)= set varstr.PCOUNT_value = 0; SendPluginEvent inst "Modified" (itoa varstr.PCOUNT_value) nil; 0;; fun newOb(inst)= let (getPluginInstanceParam inst "value") -> value in let MkCountStr [(atoi value) 0] -> varstr in ( PluginRegisterAction inst "SetValue" mkfun6 @cbSetValue varstr; PluginRegisterAction inst "GetValue" mkfun6 @cbGetValue varstr; PluginRegisterAction inst "Increment" mkfun6 @cbIncrement varstr; PluginRegisterAction inst "Decrement" mkfun6 @cbDecrement varstr; PluginRegisterAction inst "Reset" mkfun6 @cbReset varstr; setPluginInstanceCbDel inst @deleteOb; ); 0;; fun IniPlug(file)= PlugRegister @newOb nil; setPluginEditor @dynamicedit; 0;;