Scolring - Forum

Entraides et échanges autour de la technologie Scol - Informations and exchanges on the Scol technology

Vous pouvez changer la langue de l'interface une fois inscrit - You can change the language once registered

You are not logged in.

#1 26-Nov-2014 14:50:07

hebdemnobad
Member
From: northamerica
Registered: 20-Apr-2011
Posts: 1,541
Website

encountering scol .exe crash with modified plugit

colleagues:

I`m encountering a crash (scol.exe has stopped working window, os3d editor quits without indicating any error in the editor log window with the my modified plugit on its cbresize callback.  perhaps I am casting from one basic type to another and the compiler is not detecting the illegal cast? is
app data>local>scol voyager > logs  the only place to look for an eror

the crash is happening with the cbresize callback.  all I am doing is setting some struct I (interger) fields to the new ones following computePosSize.

I'm pretty sure my code is to blame but I don't knno where to look.

(I tested the original cbutton with the same configuration no crash there)

Last edited by hebdemnobad (26-Nov-2014 15:06:05)

Offline

#2 26-Nov-2014 15:52:10

iri
Admin. / Scol language & Scol apps developer
From: France
Registered: 22-Feb-2009
Posts: 2,024
Website

Re: encountering scol .exe crash with modified plugit

What changes did you make ?

Offline

#3 26-Nov-2014 16:18:23

hebdemnobad
Member
From: northamerica
Registered: 20-Apr-2011
Posts: 1,541
Website

Re: encountering scol .exe crash with modified plugit

iri wrote:

What changes did you make ?

I added some fields to the button struct, put in some if then tests to prevent multiple fingers from controlling button (it allows only one control), along with creating and destroying the touchpoint widget i add when only one finger is contacting the button.

something is making the button height and width radically increase if and only if percentages are being used instead of pixel height and width...the increase happens in the computepossize function, even though i cannot find anything multiplying the button width and height fields.

Last edited by hebdemnobad (26-Nov-2014 16:33:22)

Offline

#4 26-Nov-2014 16:45:06

hebdemnobad
Member
From: northamerica
Registered: 20-Apr-2011
Posts: 1,541
Website

Re: encountering scol .exe crash with modified plugit

here is the client code fwiw:

/*

-----------------------------------------------------------------------------

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 later153

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



-----------------------------------------------------------------------------

*/



/*******************************************************************************

 Version: 1.0

 Author: Bastien BOURINEAU

 Date: 10/07/2012

 Warning: loading too much bitmaps at start can take long and use uncessary large amount of memory

 *******************************************************************************/



struct PlugButton = [

  PBTN_instance                : PInstance,

  PBTN_bOnMaterial             : I,

  PBTN_Material                : SO3_MATERIAL,

  PBTN_iTechnique              : I,

  PBTN_iPass                   : I,

  PBTN_iTexture                : I,

  

  PBTN_win                     : SO3_WIDGET,

  PBTN_AlphaBuffer             : AlphaBitmap,
  PBTN_throttle_handle_widget  : SO3_WIDGET,

  PBTN_throttle_handle_image   : AlphaBitmap,

  PBTN_iPosX                   : I,

  PBTN_iPosY                   : I,
  PBTN_iRight_Margin           : I,
  PBTN_iBottom_Margin          : I,

  PBTN_iToggleID					 : I,
  PBTN_iWidth                  : I,

  PBTN_iHeight                 : I,

  PBTN_iXcenter 			       : I,
  PBTN_iYcenter 			       : I,  
  PBTN_tPercent                : [I I I I I I I I],

  PBTN_tAlign                  : [I I],

  

  PBTN_bTransparency           : I,

  PBTN_iOpacity                : I,

  PBTN_iTransition             : I,

  PBTN_fTransOpacity           : F,

  

  PBTN_font                    : ObjFont,

  PBTN_sLabel                  : S,

  PBTN_ifColor                 : I,

  

  PBTN_bUrl                    : I,

  PBTN_sPath                   : S,  

  PBTN_iClick                  : I,

  PBTN_bLastCursor             : I,

  PBTN_bShowCursor             : I,

  PBTN_bEnableMouse            : I,

  PBTN_bShow                   : I,

  PBTN_iAvStates               : I,

  PBTN_iState                  : I,

  PBTN_iNbFrames               : I,

  PBTN_iCurFrame               : I,

  PBTN_iTick                   : I,

  PBTN_iLastInputState         : I,

  PBTN_tLastPos                : [I I],

  PBTN_lInputs                 : [[S [I I]] r1],

  PBTN_trmMouseState           : Timer, // to enable the mouse after touch manipulation
  PBTN_listfull					 : I,
  PBTN_widgetcreated				 : I,

  PBTN_httpReq                 : ObjCURL



  ] MkPlugButton;;





var sTmpDownloadPath = "tmp/buttons/";;



var iTexWidth = 512;;

var iTexHeight = 512;;



var sHandCursor = "os3dlib/res/link_cursor.bmp";;

typeof cHandCursor = ObjCursor;;

typeof cPrevCursor = ObjCursor;;



fun restoreTexture(btnstr)=

  V3DremoveWidgetControl (V3DgetDefaultViewport (V3DgetSessionView c3dXsession)) btnstr.PBTN_win;

  SO3WidgetDestroy btnstr.PBTN_win;

  set btnstr.PBTN_win = nil;

  _DSalphaBitmap btnstr.PBTN_AlphaBuffer;

  set btnstr.PBTN_AlphaBuffer = nil;

  

  if (!btnstr.PBTN_bShowCursor || !btnstr.PBTN_bLastCursor || (!V3DgetCursorVisible (V3DgetSessionView c3dXsession))) then nil else

  (

    V3DsetCursor (V3DgetSessionView c3dXsession) cPrevCursor;

      

    set btnstr.PBTN_bLastCursor = 0;

    set cPrevCursor = nil;

  );

  0;;





fun drawLabel(abmp, btnstr)=

  let _GETalphaBitmaps abmp -> [bmp bmp8] in

  let _GETbitmapSize bmp -> [bw bh] in

  let G2DgetStringSize btnstr.PBTN_font btnstr.PBTN_sLabel -> [_ th] in

  (

    _DRAWtext bmp btnstr.PBTN_font (bw / 2) ((bh / 2) - (th / 2)) TD_CENTER btnstr.PBTN_ifColor btnstr.PBTN_sLabel;

    //_DRAWtext8 bmp8 btnstr.PBTN_font (bw / 2) ((bh / 2) - (th / 2)) TD_CENTER 0xffffff btnstr.PBTN_sLabel;

  );

  0;;





fun updateButton(btnstr)=

  if (btnstr.PBTN_win == nil) then nil else

  let _GETalphaBitmapSize btnstr.PBTN_AlphaBuffer -> [bw bh] in

  let bh / (btnstr.PBTN_iAvStates + 1) -> statew in

  let (bw / btnstr.PBTN_iNbFrames) * btnstr.PBTN_iCurFrame -> wpos in

  let if (!btnstr.PBTN_iAvStates) then 0 else statew * btnstr.PBTN_iState -> ypos in

  let G2DcopyAlphaBitmap _channel btnstr.PBTN_AlphaBuffer wpos ypos (bw / btnstr.PBTN_iNbFrames) statew -> cpabmp in

  (

    drawLabel cpabmp btnstr;

    SO3BitmapWidgetBlitAlpha btnstr.PBTN_win cpabmp;

    _DSalphaBitmap cpabmp;

  );

  0;;





fun computePosSize(btnstr, vw, vh)=

  _showconsole;
  _fooS strcatn "view size"::(itoa vw)::nil;
    _fooS strcatn "view heighh"::(itoa vh)::nil;
  let btnstr.PBTN_tPercent -> [px py pw ph xo yo wo ho] in

  let btnstr.PBTN_tAlign -> [ax ay] in

  let if pw then (ftoi (((itof btnstr.PBTN_iWidth) /. 100.0) *. (itof vw))) + wo else btnstr.PBTN_iWidth -> pw in

  let if ph then (ftoi (((itof btnstr.PBTN_iHeight) /. 100.0) *. (itof vh))) + ho else btnstr.PBTN_iHeight -> ph in

  let if px then (ftoi (((itof btnstr.PBTN_iPosX) /. 100.0) *. (itof vw))) + xo else btnstr.PBTN_iPosX -> px in

  let if py then (ftoi (((itof btnstr.PBTN_iPosY) /. 100.0) *. (itof vh))) + yo else btnstr.PBTN_iPosY -> py in

  (  _fooS strcatn "button width"::(itoa pw)::nil;
      _fooS strcatn "button height"::(itoa ph)::nil;
      [px py pw ph]);;





fun cbResizeCtrl(inst, viewstr, vw, vh, btnstr)=

  if btnstr.PBTN_win == nil || btnstr.PBTN_bOnMaterial then nil else

  let computePosSize btnstr vw vh -> [px py pw ph] in
  let  vw -(vw -(pw + px)) -> rightmargin in
  let vh - (vh -(ph + py))-> bottommargin in
  let vh -(vh - ((ph/2) + py)) -> buttonvcenter in

  (

    set btnstr.PBTN_iPosX= px;
    set btnstr.PBTN_iPosY= py;
    set btnstr.PBTN_iHeight  = ph;
    _fooS strcatn "back in resize control fucnction,button width"::(itoa pw)::nil;
      _fooS strcatn "back in resize control fucnction,button height"::(itoa ph)::nil;
    set btnstr.PBTN_iWidth  = pw;
    set btnstr.PBTN_iRight_Margin = rightmargin;
    set btnstr.PBTN_iBottom_Margin = bottommargin; 
    set btnstr.PBTN_iYcenter = buttonvcenter;  
    SO3WidgetSetPosition btnstr.PBTN_win px py;

    SO3WidgetSetSize btnstr.PBTN_win pw ph;

    SendPluginEvent btnstr.PBTN_instance "sendtouchpointdata" strcatn "rezied window"::"\n ":: "new right maring is : ":: (itoa btnstr.PBTN_iRight_Margin):: "new bottom margin is: ":: (itoa btnstr.PBTN_iBottom_Margin)::"new x position is: "::(itoa btnstr.PBTN_iPosX):: "new y position is":: (itoa btnstr.PBTN_iPosY):: "new width is: ":: (itoa pw)::"new height is: ":: (itoa ph)::"new vertical center is:"::(itoa buttonvcenter)::nil nil;       

updateButton btnstr;

  );

  0;;





fun cbMouseIn(widget, btnstr)=

  if(btnstr.PBTN_iState == 3) || (btnstr.PBTN_iClick != 0) then nil else

  (

    set btnstr.PBTN_iState = 1;

    let V3DgetSessionView c3dXsession -> viewstr in

    if (!btnstr.PBTN_bShowCursor || btnstr.PBTN_bLastCursor || (!V3DgetCursorVisible viewstr)) then nil else

    (

      set btnstr.PBTN_bLastCursor = 1;

      let V3DgetCursor viewstr -> pcursor in

      if (pcursor == cHandCursor) then nil else

        set cPrevCursor = pcursor;

      

      V3DsetCursor viewstr cHandCursor;

    );

    

    //update bitmap

    if(btnstr.PBTN_iAvStates <= 0) then nil else

    (

      updateButton btnstr;

      0;

    );

    

    SendPluginEvent btnstr.PBTN_instance "MouseOver" nil nil;

  );

  0;;





fun cbMouseOut(widget, btnstr)=

  if(btnstr.PBTN_iState == 3) then nil else

  (

    if (btnstr.PBTN_iClick != 0) then nil else

    (

      let V3DgetSessionView c3dXsession -> viewstr in

      if (!btnstr.PBTN_bShowCursor || !btnstr.PBTN_bLastCursor || (!V3DgetCursorVisible viewstr)) then nil else

      (

        set btnstr.PBTN_bLastCursor = 0;

        V3DsetCursor viewstr cPrevCursor;

        set cPrevCursor = nil;

      );

    

      set btnstr.PBTN_iState = 0;

      

      //update bitmap

      if(btnstr.PBTN_iAvStates <= 0) then nil else

      (

        updateButton btnstr;

        0;

      );

      

      //SendPluginEvent btnstr.PBTN_instance "Released" nil nil;

      SendPluginEvent btnstr.PBTN_instance "MouseOut" nil nil;

    );

  );

  0;;





fun cbClick(widget, btnstr, x, y, btn)=

  if(btnstr.PBTN_iState == 3) then nil else

  (

    if (btnstr.PBTN_iState == 2) && (btnstr.PBTN_iClick == 0) then nil else

    (

      SendPluginEvent btnstr.PBTN_instance "Pushed" nil nil;

      set btnstr.PBTN_tLastPos = [x y];

    );

    

    set btnstr.PBTN_iClick = btnstr.PBTN_iClick|btn;

    set btnstr.PBTN_iState = 2;

    

    if(btnstr.PBTN_iAvStates <= 1) then nil else

    //update bitmap

    (

      updateButton btnstr;

      0;

    );

  );

  0;;





fun cbUnClick(widget, btnstr, x, y, btn)=

  if (btnstr.PBTN_iState == 3) then nil else

  (

    if (btnstr.PBTN_iState != 2) then nil else

    (

      set btnstr.PBTN_tLastPos = nil;

      SendPluginEvent btnstr.PBTN_instance "Released" nil nil;

      if (SO3WidgetIsMouseOver btnstr.PBTN_win) then nil else

        SendPluginEvent btnstr.PBTN_instance "MouseOut" nil nil;

    );

    

    if (!SO3WidgetIsMouseOver btnstr.PBTN_win) then

    (

      let V3DgetSessionView c3dXsession -> viewstr in

      if (!btnstr.PBTN_bShowCursor || !btnstr.PBTN_bLastCursor || (!V3DgetCursorVisible viewstr)) then nil else

      (

        set btnstr.PBTN_bLastCursor = 0;

        V3DsetCursor viewstr cPrevCursor;

        set cPrevCursor = nil;

      );

      

      SendPluginEvent btnstr.PBTN_instance "MouseOut" nil nil;

      0;

    )

    else

    (

      if btn == 1 then

        SendPluginEvent btnstr.PBTN_instance "LeftClick" nil nil

      else if btn == 2 then

        SendPluginEvent btnstr.PBTN_instance "RightClick" nil nil

      else if btn == 16 then

        SendPluginEvent btnstr.PBTN_instance "MiddleClick" nil nil

      else nil;

      0;

    );

    

    set btnstr.PBTN_iState = if (SO3WidgetIsMouseOver btnstr.PBTN_win) then 1 else 0;



    //update bitmap

    if(btnstr.PBTN_iAvStates <= 0) then nil else

    (

      updateButton btnstr;

      0;

    );

  );

  set btnstr.PBTN_iClick = 0;

  0;;





fun cbMouseMove(widget, btnstr, x, y, btn)=

  if (btnstr.PBTN_iClick == 0) || (btnstr.PBTN_tLastPos == nil) then nil else

  let btnstr.PBTN_tLastPos -> [px py] in

  let (min btnstr.PBTN_iWidth btnstr.PBTN_iHeight) -> msize in

  let (itof (x - px)) /. (itof msize) -> fx in

  let if (fx >. 1.0) then 1.0 else if (fx <. (-.1.0)) then (-.1.0) else fx -> fx in

  let (itof (py - y)) /. (itof msize) -> fy in

  let if (fy >. 1.0) then 1.0 else if (fy <. (-.1.0)) then (-.1.0) else fy -> fy in

  (

    SendPluginEvent btnstr.PBTN_instance "Pushed move" strcatn (ftoa fx)::" "::(ftoa fy)::nil nil;

  );

  0;;





fun cbFocused(widget, btnstr, state)=

  if (state || (btnstr.PBTN_iState != 2) || (btnstr.PBTN_iClick == 0)) then nil else

  (

    addLogMessage "unfocused";

    set btnstr.PBTN_tLastPos = nil;

    SendPluginEvent btnstr.PBTN_instance "Released" nil nil;



    let V3DgetSessionView c3dXsession -> viewstr in

    if (!btnstr.PBTN_bShowCursor || !btnstr.PBTN_bLastCursor || (!V3DgetCursorVisible viewstr)) then nil else

    (

      set btnstr.PBTN_bLastCursor = 0;

      V3DsetCursor viewstr cPrevCursor;

      set cPrevCursor = nil;

    );

    

    SendPluginEvent btnstr.PBTN_instance "MouseOut" nil nil;

    

    set btnstr.PBTN_iClick = 0;

    set btnstr.PBTN_iState = 0;



    //update bitmap

    if(btnstr.PBTN_iAvStates <= 0) then nil else

    (

      updateButton btnstr;

      0;

    );

  );

  0;;





fun createPicture(inst, btnstr)=

  let (V3DgetDefaultViewport (V3DgetSessionView c3dXsession)) -> viewportstr in

  if btnstr.PBTN_win != nil then nil else

  (

    V3DremoveWidgetControl viewportstr btnstr.PBTN_win;

    SO3WidgetDestroy btnstr.PBTN_win;

    if btnstr.PBTN_bOnMaterial then

    (

      set btnstr.PBTN_win = SO3BitmapWidgetCreateOnMaterial (V3DgetSession c3dXsession) btnstr.PBTN_Material (strcat (getPluginInstanceName inst) "_pictureCtrl") btnstr.PBTN_iWidth btnstr.PBTN_iHeight btnstr.PBTN_iTechnique btnstr.PBTN_iPass btnstr.PBTN_iTexture;

    	0;

    )

    else

    (

      let SO3ViewportGetPixelPositionSize viewportstr.V3D_viewport -> [_ _ vw vh] in

      let computePosSize btnstr vw vh -> [px py pw ph] in

        set btnstr.PBTN_win = SO3BitmapWidgetCreate (V3DgetSession c3dXsession) viewportstr.V3D_viewport (strcat (getPluginInstanceName inst) "_pictureCtrl") px py pw ph 101;



      SO3WidgetSetTopOnFocus btnstr.PBTN_win 0;

      SO3WidgetSetForeground btnstr.PBTN_win 1;

      0;

    );

    

    SO3WidgetEnterEventCb btnstr.PBTN_win @cbMouseIn btnstr;

    SO3WidgetExitEventCb btnstr.PBTN_win @cbMouseOut btnstr;

    SO3WidgetMouseDownEventCb btnstr.PBTN_win @cbClick btnstr;

    SO3WidgetMouseUpEventCb btnstr.PBTN_win @cbUnClick btnstr;

    SO3WidgetMouseMoveEventCb btnstr.PBTN_win @cbMouseMove btnstr;

    SO3WidgetFocusEventCb btnstr.PBTN_win @cbFocused btnstr;

    

    V3DaddWidgetControl viewportstr btnstr.PBTN_win;

    SO3WidgetSetKeyboardEnable btnstr.PBTN_win 0;

    SO3WidgetSetMouseEnable btnstr.PBTN_win btnstr.PBTN_bEnableMouse;

    SO3WidgetSetTransparency btnstr.PBTN_win btnstr.PBTN_bTransparency;

    SO3WidgetSetOpacity btnstr.PBTN_win (itof btnstr.PBTN_iOpacity) *. 0.01;

    SO3WidgetSetVisibility btnstr.PBTN_win 0;

  );

  0;;





// button animation is updated at 30 FPS

fun cbControlPreRenderAnim(inst, sessionstr, etime, btnstr)=

  let (set btnstr.PBTN_iTick = btnstr.PBTN_iTick + etime) -> rtick in

  if (rtick < (1000 / 30)) then nil else

  (

    set btnstr.PBTN_iCurFrame = btnstr.PBTN_iCurFrame + 1;

    

    if (btnstr.PBTN_iCurFrame < (btnstr.PBTN_iNbFrames - 1)) then nil else

      set btnstr.PBTN_iCurFrame = 0;

    

    updateButton btnstr;

    set btnstr.PBTN_iTick = 0;

  );

  0;;





fun cbControlPreRenderShow(inst, sessionstr, etime, btnstr)=

  let (itof btnstr.PBTN_iOpacity) /. (itof btnstr.PBTN_iTransition) -> step in

  (

    set btnstr.PBTN_fTransOpacity = btnstr.PBTN_fTransOpacity +. (step *. (itof etime));

    if btnstr.PBTN_fTransOpacity >=. (itof btnstr.PBTN_iOpacity) then

    (

      SO3WidgetSetOpacity btnstr.PBTN_win (itof btnstr.PBTN_iOpacity) *. 0.01;

      

      if (btnstr.PBTN_iNbFrames <= 1) then

        setPluginInstanceCbScenePreRender inst nil

      else

        setPluginInstanceCbScenePreRender btnstr.PBTN_instance mkfun4 @cbControlPreRenderAnim btnstr;

      

      SendPluginEvent btnstr.PBTN_instance "Shown" nil nil;

      0;

    )

    else

    (

      SO3WidgetSetOpacity btnstr.PBTN_win (btnstr.PBTN_fTransOpacity *. 0.01);

      0;

    );

  );

  

  if (btnstr.PBTN_iNbFrames <= 1) then nil else

    cbControlPreRenderAnim inst sessionstr etime btnstr;

  0;;





fun cbControlPreRenderHide(inst, sessionstr, etime, btnstr)=

  let (itof btnstr.PBTN_iOpacity) /. (itof btnstr.PBTN_iTransition) -> step in

  (

    set btnstr.PBTN_fTransOpacity = btnstr.PBTN_fTransOpacity -. (step *. (itof etime));

    if btnstr.PBTN_fTransOpacity <=. 0.0 then

    (

      SO3WidgetSetOpacity btnstr.PBTN_win 0.0;

      setPluginInstanceCbScenePreRender inst nil;

      

      if (btnstr.PBTN_win == nil) then nil else

      (

        V3DremoveWidgetControl (V3DgetDefaultViewport (V3DgetSessionView c3dXsession)) btnstr.PBTN_win;

        SO3WidgetDestroy btnstr.PBTN_win;

        set btnstr.PBTN_win = nil;

        

        _DSalphaBitmap btnstr.PBTN_AlphaBuffer;

        set btnstr.PBTN_AlphaBuffer = nil;

        SendPluginEvent btnstr.PBTN_instance "Hidden" nil nil;

      );

      0;

    )

    else

    (

      SO3WidgetSetOpacity btnstr.PBTN_win (btnstr.PBTN_fTransOpacity *. 0.01);

      0;

    );

  );

  

  if (btnstr.PBTN_iNbFrames <= 1) then nil else

    cbControlPreRenderAnim inst sessionstr etime btnstr;

  0;;





fun cbDownloaded(file, data, btnstr)=

  if data == nil then nil else

  let strcatn sTmpDownloadPath::(getPluginInstanceName btnstr.PBTN_instance)::".tmp"::nil -> tmpfile in

  (

    _storepack data tmpfile;

    let G2DloadAlphaBmp _channel tmpfile -> bmp in

    if bmp == nil then nil else

    (

      if(btnstr.PBTN_iState == 2) then nil else

        set btnstr.PBTN_iState = 0;

      

      _DSalphaBitmap btnstr.PBTN_AlphaBuffer;

      set btnstr.PBTN_AlphaBuffer = bmp;      



      if (!btnstr.PBTN_bShow) then nil else

      (

        createPicture btnstr.PBTN_instance btnstr;

        updateButton btnstr;

        

        if (btnstr.PBTN_iTransition == 0) then

        (

          SO3WidgetSetVisibility btnstr.PBTN_win 1;

          if (btnstr.PBTN_iNbFrames <= 1) then nil else

            setPluginInstanceCbScenePreRender btnstr.PBTN_instance mkfun4 @cbControlPreRenderAnim btnstr;

          

          SendPluginEvent btnstr.PBTN_instance "Shown" nil nil;

          0;

        )

        else

        (

          SO3WidgetSetOpacity btnstr.PBTN_win (btnstr.PBTN_fTransOpacity *. 0.01);

          SO3WidgetSetVisibility btnstr.PBTN_win 1;

          setPluginInstanceCbScenePreRender btnstr.PBTN_instance mkfun4 @cbControlPreRenderShow btnstr;

          0;

        );

      );

    );

  );

  0;;





fun cbChange(inst, from, action, param, reply, btnstr)=

  let if param == nil then btnstr.PBTN_bUrl else strIsUrl param -> isurl in

  let if param == nil then btnstr.PBTN_sPath else param -> url in

  (

    set btnstr.PBTN_bUrl = isurl;

    set btnstr.PBTN_sPath = url;

    

    if (!btnstr.PBTN_bShow) then nil else

    (

      if(btnstr.PBTN_iState == 2) then nil else

        set btnstr.PBTN_iState = 0;

      

      if !btnstr.PBTN_bUrl then

      (

        let G2DloadAlphaBmp _channel btnstr.PBTN_sPath -> bmp in

        if bmp == nil then nil else

        (

          set btnstr.PBTN_AlphaBuffer = bmp;

          createPicture inst btnstr;

          updateButton btnstr;

          SO3WidgetSetVisibility btnstr.PBTN_win 1;

        );

        0;

      )

      else

      (

        if (btnstr.PBTN_httpReq == nil) then nil else

        (

          killHttpRequest btnstr.PBTN_httpReq;

          set btnstr.PBTN_httpReq = nil;

        );

        

        set btnstr.PBTN_httpReq = downloadFile btnstr.PBTN_sPath mkfun3 @cbDownloaded btnstr;

        0;

      );

    );

  );

  0;;





fun cbEnable(inst, from, action, param, reply, btnstr)=

  set btnstr.PBTN_iState = 0;

  0;;





fun cbDisable(inst, from, action, param, reply, btnstr)=

  set btnstr.PBTN_iState = 2;

  0;;





fun cbSetLabel(inst, from, action, param, reply, btnstr)=

  set btnstr.PBTN_sLabel = param;

  updateButton btnstr;

  0;;





fun cbSendLeftClick(inst, from, action, param, reply, btnstr)=

  if (!btnstr.PBTN_bShow) then nil else

    SendPluginEvent btnstr.PBTN_instance "LeftClick" nil nil;

  0;;





fun cbSendRightClick(inst, from, action, param, reply, btnstr)=

  if (!btnstr.PBTN_bShow) then nil else

    SendPluginEvent btnstr.PBTN_instance "RightClick" nil nil;

  0;;





fun cbSendMiddleClick(inst, from, action, param, reply, btnstr)=

  if (!btnstr.PBTN_bShow) then nil else

    SendPluginEvent btnstr.PBTN_instance "MiddleClick" nil nil;

  0;;





fun cbSetState(inst, from, action, param, reply, btnstr)=

  let strtrim param -> param in

  if (!strcmpi param "Active") || ((atoi param) == 1) then

  (

    // active state

    set btnstr.PBTN_iState = 0;

    

    if(btnstr.PBTN_iAvStates <= 0) then nil else

    //update bitmap

    (

      updateButton btnstr;

      0;

    );

    0;

  )

  else if (!strcmpi param "Hover") || ((atoi param) == 2) then

  (

    // hover state

    set btnstr.PBTN_iState = 1;

    

    if(btnstr.PBTN_iAvStates <= 0) then nil else

    //update bitmap

    (

      updateButton btnstr;

      0;

    );

    0;

  )

  else if (!strcmpi param "Down") || ((atoi param) == 3) then

  (

    // hover state

    set btnstr.PBTN_iState = 2;

    

    if(btnstr.PBTN_iAvStates <= 0) then nil else

    //update bitmap

    (

      updateButton btnstr;

      0;

    );

    0;

  )

  else if (!strcmpi param "Disable") || ((atoi param) == 4) then

  (

    // disable state

    set btnstr.PBTN_iState = 3;

    

    if(btnstr.PBTN_iAvStates <= 1) then nil else

    //update bitmap

    (

      updateButton btnstr;

      0;

    );

    0;

  )

  else nil;

  0;;





fun cbShow(inst, from, action, param, reply, btnstr)=

  if (btnstr.PBTN_bShow) then nil else

  (

    if(btnstr.PBTN_iState == 2) then nil else

      set btnstr.PBTN_iState = 0;

    

    if !btnstr.PBTN_bUrl then

    (

      let G2DloadAlphaBmp _channel btnstr.PBTN_sPath -> bmp in

      if bmp == nil then nil else

      (

        set btnstr.PBTN_AlphaBuffer = bmp;

        createPicture inst btnstr;

        updateButton btnstr;

        

        if (btnstr.PBTN_iTransition == 0) then

        (

          SO3WidgetSetVisibility btnstr.PBTN_win 1;

          

          if (btnstr.PBTN_iNbFrames <= 1) then nil else

            setPluginInstanceCbScenePreRender btnstr.PBTN_instance mkfun4 @cbControlPreRenderAnim btnstr;

          

          SendPluginEvent btnstr.PBTN_instance "Shown" nil nil;

          0;

        )

        else

        (

          SO3WidgetSetOpacity btnstr.PBTN_win (btnstr.PBTN_fTransOpacity *. 0.01);

          SO3WidgetSetVisibility btnstr.PBTN_win 1;

          setPluginInstanceCbScenePreRender inst mkfun4 @cbControlPreRenderShow btnstr;

          0;

        );

      );

      0;

    )

    else

    (

      if (btnstr.PBTN_httpReq == nil) then nil else

      (

        killHttpRequest btnstr.PBTN_httpReq;

        set btnstr.PBTN_httpReq = nil;

      );

      

      set btnstr.PBTN_httpReq = downloadFile btnstr.PBTN_sPath mkfun3 @cbDownloaded btnstr;

      0;

    );

    

    set btnstr.PBTN_bShow = 1;

  );

  0;;





fun cbHide(inst, from, action, param, reply, btnstr)=

  if (!btnstr.PBTN_bShow) then nil else

  (

    if (btnstr.PBTN_iTransition == 0) then

    (

      if (btnstr.PBTN_win == nil) then nil else

      (

        setPluginInstanceCbScenePreRender inst nil;

        V3DremoveWidgetControl (V3DgetDefaultViewport (V3DgetSessionView c3dXsession)) btnstr.PBTN_win;

        SO3WidgetDestroy btnstr.PBTN_win;

        set btnstr.PBTN_win = nil;

        

        _DSalphaBitmap btnstr.PBTN_AlphaBuffer;

        set btnstr.PBTN_AlphaBuffer = nil;

        SendPluginEvent btnstr.PBTN_instance "Hidden" nil nil;

      );

      0;

    )

    else

    (

      SO3WidgetSetOpacity btnstr.PBTN_win (btnstr.PBTN_fTransOpacity *. 0.01);

      setPluginInstanceCbScenePreRender inst mkfun4 @cbControlPreRenderHide btnstr;

      0;

    );



    if(btnstr.PBTN_iState == 2) then nil else

      set btnstr.PBTN_iState = 0;

    

    if (!btnstr.PBTN_bShowCursor || !btnstr.PBTN_bLastCursor || (!V3DgetCursorVisible (V3DgetSessionView c3dXsession))) then nil else

    (

      set btnstr.PBTN_bLastCursor = 0;

      V3DsetCursor (V3DgetSessionView c3dXsession) cPrevCursor;

      set cPrevCursor = nil;

    );

    

    set btnstr.PBTN_lInputs = nil;

    set btnstr.PBTN_bShow = 0;

  );

  0;;





fun cbInput(inst, from, action, param, reply, btnstr)=

  if (!btnstr.PBTN_bShow) || (param == nil) || (btnstr.PBTN_win == nil) then nil else

  let strextr param -> lp in

  let atoi (nth_list (hd lp) 0) -> sx in

  let atoi (nth_list (hd lp) 1) -> sy in

  let (V3DgetDefaultViewport (V3DgetSessionView c3dXsession)) -> viewportstr in

  let SO3ViewportGetPixelPositionSize viewportstr.V3D_viewport -> [_ _ vw vh] in

  let computePosSize btnstr vw vh -> [px py pw ph] in

  (

    let switchstr btnstr.PBTN_lInputs from -> icontrol in

    (

      // if not already int the list we add it

      if (icontrol == nil) then

      (

        set btnstr.PBTN_lInputs = [from [sx sy]]::btnstr.PBTN_lInputs;

        0;

      )

      else

      (

        mutate icontrol <- [sx sy];

        0;

      );

    );



    let sizelist btnstr.PBTN_lInputs -> size in

    let 0 -> i in

    let 0 -> over in

    (

      while (i < size) do

      (

        let nth_list btnstr.PBTN_lInputs i -> [n [sx sy]] in

        if ((sx > px) && (sx < (px + pw)) && (sy > py) && (sy < (py + ph))) then

          set over = 1

        else nil;

        

        set i = i + 1;

      );

    

      if (over == 1) then

      (

        if (btnstr.PBTN_iLastInputState) then nil else

        (

          set btnstr.PBTN_iLastInputState = 1;

          cbMouseIn nil btnstr;

        );

        0;

      )

      else if (!btnstr.PBTN_iLastInputState) then nil else

      (

        set btnstr.PBTN_iLastInputState = 0;

        cbMouseOut nil btnstr;

        0;

      );

    );

  );

  0;;





// multi touch

fun cbAddCursor(inst, viewstr, id, sx, sy, btnstr)=
  set btnstr.PBTN_listfull = btnstr.PBTN_listfull +1;
  //if there is more than one control, dont add any more
  if ((hd btnstr.PBTN_lInputs) != nil) then nil else
  (
  let (V3DgetDefaultViewport viewstr) -> viewportstr in
  let sy-btnstr.PBTN_iYcenter -> cursordifference in
  (
  //if touchpoint is too far from the centerline we don't do anything
  if (abs (sy- btnstr.PBTN_iYcenter) > 45) ||(abs (sy- btnstr.PBTN_iYcenter) < -45) then 
  (
 SendPluginEvent btnstr.PBTN_instance "sendtouchpointdata" strcatn "not on center. center is at"::(itoa  btnstr.PBTN_iYcenter)::"the cursor is this far away from center: "::(itoa cursordifference)::"\n "::nil nil;       
  0;
  )
   else
  (
 SendPluginEvent btnstr.PBTN_instance "sendtouchpointdata" strcatn "on center, center is at"::(itoa  btnstr.PBTN_iYcenter)::"the cursor is this far away from center: "::(itoa cursordifference)::"\n "::nil nil;       
 
  	

  if (!btnstr.PBTN_bShow) || (btnstr.PBTN_win == nil) then nil else

  (

    if (btnstr.PBTN_trmMouseState == nil) then nil else

    (

      _deltimer btnstr.PBTN_trmMouseState;

      set btnstr.PBTN_trmMouseState = nil;

    );

    

    //disable mouse

    SO3WidgetEnterEventCb btnstr.PBTN_win nil nil;

    SO3WidgetExitEventCb btnstr.PBTN_win nil nil;

    SO3WidgetMouseDownEventCb btnstr.PBTN_win nil nil;

    SO3WidgetMouseUpEventCb btnstr.PBTN_win nil nil;

    SO3WidgetMouseMoveEventCb btnstr.PBTN_win nil nil;

    SO3WidgetFocusEventCb btnstr.PBTN_win @cbFocused nil;
    

    set btnstr.PBTN_iClick = 0;

    //make this touchpoint the one we want to track with updatecursor, other touchpoints we will ignore with updatecursor
    set btnstr.PBTN_iToggleID = id;
    //place touchpoint image at center vertical and horizontal
   
    set btnstr.PBTN_throttle_handle_widget = SO3BitmapWidgetCreate (V3DgetSession c3dXsession) viewportstr.V3D_viewport (strcatn (getPluginInstanceName btnstr.PBTN_instance)::"_tip"::(itoa id)::nil) ((btnstr.PBTN_iWidth/2)-32) (btnstr.PBTN_iYcenter-32) 64 64 100000;
    SO3WidgetSetTransparency btnstr.PBTN_throttle_handle_widget 1;

    SO3WidgetSetKeyboardEnable btnstr.PBTN_throttle_handle_widget 0;

    SO3WidgetSetMouseEnable btnstr.PBTN_throttle_handle_widget 0;

    SO3WidgetSetForeground btnstr.PBTN_throttle_handle_widget 1;
    SO3BitmapWidgetBlitAlpha btnstr.PBTN_throttle_handle_widget btnstr.PBTN_throttle_handle_image;
    set btnstr.PBTN_widgetcreated	= 1;  
  
    //  let if (!btnstr.PBTN_iAvStates) then 0 else statew * btnstr.PBTN_iState -> ypos in

    let SO3ViewportGetPixelPositionSize viewportstr.V3D_viewport -> [_ _ vw vh] in

    let computePosSize btnstr vw vh -> [px py pw ph] in

    (

      if ((sx > px) && (sx < (px + pw)) && (sy > py) && (sy < (py + ph))) then

      let switchstr btnstr.PBTN_lInputs (itoa id) -> icontrol in

      (

        // if not already int the list we add it

        if (icontrol == nil) then

        (

          set btnstr.PBTN_lInputs = [(itoa id) [sx sy]]::btnstr.PBTN_lInputs;

          0;

        )

        else

        (

          mutate icontrol <- [sx sy];

          0;

        );

        

        if (btnstr.PBTN_iState == 3) || (btnstr.PBTN_iState == 2) then nil else

        (

          set btnstr.PBTN_iState = 1;

          //update bitmap

          if(btnstr.PBTN_iAvStates <= 0) then nil else

          (

            updateButton btnstr;

            0;

          );

          SendPluginEvent btnstr.PBTN_instance "MouseOver" nil nil;

          

          set btnstr.PBTN_iState = 2;      

          //update bitmap

          if(btnstr.PBTN_iAvStates <= 1) then nil else

          (

            updateButton btnstr;

            0;

          );

          SendPluginEvent btnstr.PBTN_instance "Pushed" nil nil;

          set btnstr.PBTN_tLastPos = [sx sy];

        );

      )

      else nil;

    );

  );
  0;
  );
  );

  0;
  );
  0;;
  /*

  PBTN_iPosX                   : I,

  PBTN_iPosY                   : I,
  PBTN_iRight_Margin           : I,
  PBTN_iBottom_Margin

  */

fun cbUpdateCursor(inst, viewstr, id, sx, sy, vx, vy, btnstr)=
	//do nothing if touchpoint being updated is not the one created at the center
if (id != btnstr.PBTN_iToggleID) then nil else
(
  if (sx < btnstr.PBTN_iPosX)   || (sx > btnstr.PBTN_iRight_Margin) || (sy < btnstr.PBTN_iPosY) || (sy > btnstr.PBTN_iBottom_Margin) then 
  (
  	// SendPluginEvent btnstr.PBTN_instance "sendtouchpointdata" strcatn "pushed move"::"\n ":: "right margin is: ":: (itoa btnstr.PBTN_iRight_Margin):: "bottom margin is: ":: (itoa btnstr.PBTN_iBottom_Margin)::"x position is: "::(itoa btnstr.PBTN_iPosX):: "y position is":: (itoa btnstr.PBTN_iPosY):: "xpoint= :"::(itoa sx)::"ypoint is:" :: (itoa sy) :: "\n"::nil nil;       

  SendPluginEvent btnstr.PBTN_instance "sendtouchpointdata" strcatn "cursor outside of button. cursor is at x: "::(itoa sx) ::"cursor is at y: "::(itoa sy):: " it must be between x1:"::(itoa btnstr.PBTN_iPosX):: "and x2:":: (itoa btnstr.PBTN_iRight_Margin):: "and y1: ":: (itoa btnstr.PBTN_iPosY)::" and y2: "::(itoa btnstr.PBTN_iBottom_Margin)::"button width is: "::(itoa btnstr.PBTN_iWidth ):: "\n "::nil nil;
  0;
  )
   else
  (
	

  if (!btnstr.PBTN_bShow) || (btnstr.PBTN_win == nil) then nil else

  (

    let switchstr btnstr.PBTN_lInputs (itoa id) -> icontrol in

    if (icontrol == nil) || (btnstr.PBTN_tLastPos == nil) then nil else

    (

      let icontrol -> [ppx ppy] in
      //don't change value if touchpoint is not moving, we don't want to set speed if finger accidently touches throttle

      if ((ppx == sx) && (ppy == sy)) then nil else

      (

        mutate icontrol <- [sx sy];

        

        let btnstr.PBTN_tLastPos -> [px py] in
        //get difference betwwne screen y coordinate and vertical center
        let sy- btnstr.PBTN_iYcenter  -> iThrottle_difference in
        let (itof iThrottle_difference) /. (itof (btnstr.PBTN_iHeight/2)) ->fy in

        //let (itof (py - sy)) /. (itof btnstr.PBTN_iHeight) -> fy in

        let if (fy >. 1.0) then 1.0 else if (fy <. (-.1.0)) then (-.1.0) else fy -> fy in
          (

          SO3WidgetSetPosition btnstr.PBTN_throttle_handle_widget ((btnstr.PBTN_iWidth/2)-32) (sy-32);
          SendPluginEvent btnstr.PBTN_instance "throttle" (ftoa fy) nil;

          SendPluginEvent btnstr.PBTN_instance "throttle_data" strcatn "throttle amount is"::(ftoa fy) :: "\n"::nil nil; 
          );
          0;      
       );
       0;

    );
    0;

  );

 
  0;
  ); 
0;
);

  0;;





fun cbResetMouse(trm, btnstr)=

  SO3WidgetEnterEventCb btnstr.PBTN_win @cbMouseIn btnstr;

  SO3WidgetExitEventCb btnstr.PBTN_win @cbMouseOut btnstr;

  SO3WidgetMouseDownEventCb btnstr.PBTN_win @cbClick btnstr;

  SO3WidgetMouseUpEventCb btnstr.PBTN_win @cbUnClick btnstr;

  SO3WidgetMouseMoveEventCb btnstr.PBTN_win @cbMouseMove btnstr;

  SO3WidgetFocusEventCb btnstr.PBTN_win @cbFocused btnstr;

  0;;





fun cbRemoveCursor(inst, viewstr, id, btnstr)=
  
  //if there already is a control in the list of controls (I.E.,TL LIST ==NIL) (which is limited to one memeber), then don't trigger release
   if (btnstr.PBTN_throttle_handle_widget==nil)|| (btnstr.PBTN_listfull >1) then nil else
  ( 
 
  SO3WidgetDestroy btnstr.PBTN_throttle_handle_widget;
  //snap widget back to original position

  //SO3WidgetSetPosition btnstr.PBTN_throttle_handle_widget ((btnstr.PBTN_iWidth/2)-32) (btnstr.PBTN_iYcenter-32);
  let switchstr btnstr.PBTN_lInputs (itoa id) -> icontrol in

  if (icontrol == nil) then nil else

  let icontrol -> [sx sy] in

  let (V3DgetDefaultViewport (V3DgetSessionView c3dXsession)) -> viewportstr in

  let SO3ViewportGetPixelPositionSize viewportstr.V3D_viewport -> [_ _ vw vh] in

  let computePosSize btnstr vw vh -> [px py pw ph] in

  (

    let sizelist btnstr.PBTN_lInputs -> size in

    let 0 -> i in

    let 0 -> over in

    (

      while (i < size) do

      (

        let nth_list btnstr.PBTN_lInputs i -> [n [sx sy]] in

        if ((sx > px) && (sx < (px + pw)) && (sy > py) && (sy < (py + ph)) && (strcmp n (itoa id))) then

          set over = 1

        else nil;

        

        set i = i + 1;

      );

    

      if (over == 1) then nil else

      (

        if (btnstr.PBTN_iState == 3) || (btnstr.PBTN_iState == 0) then nil else

        (

          set btnstr.PBTN_iState = 0;          

          if(btnstr.PBTN_iAvStates <= 0) then nil else

          //update bitmap

          (

            updateButton btnstr;

            0;

          );

          

          SendPluginEvent btnstr.PBTN_instance "Released" nil nil;

          SendPluginEvent btnstr.PBTN_instance "MouseOut" nil nil;

          

          if ((sx > px) && (sx < (px + pw)) && (sy > py) && (sy < (py + ph))) then

            SendPluginEvent btnstr.PBTN_instance "LeftClick" nil nil

          else nil;

          

          set btnstr.PBTN_tLastPos = nil;

        );

      );

    );

  );

  

  set btnstr.PBTN_lInputs = remove_sid_from_list btnstr.PBTN_lInputs (itoa id);

      

  //enable mouse again

  if ((sizelist btnstr.PBTN_lInputs) > 0) then nil else

    set btnstr.PBTN_trmMouseState = _rfltimer _starttimer _channel 500 @cbResetMouse btnstr;
  0;
  
  
 
  );
  set btnstr.PBTN_listfull= btnstr.PBTN_listfull-1; 

  0;;





fun cbSetPosition(inst, from, action, param, reply, btnstr)=

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 0 -> xpercent in

    let if (!strcmp "%" (substr sx ((strlen sx) - 1) 1)) then

        (

          set xpercent = 1;

          atoi sx;

        )

        else

          atoi sx

    -> px in

    let 0 -> ypercent in

    let if (!strcmp "%" (substr sy ((strlen sy) - 1) 1)) then

        (

          set ypercent = 1;

          atoi sy;

        )

        else

          atoi sy

    -> py in

    let [(if px == nil then 0 else px) (if py == nil then 0 else py)] -> [px py] in

    (

      mutate btnstr.PBTN_tPercent <- [xpercent ypercent _ _ _ _ _ _];

      set btnstr.PBTN_iPosX = px;

      set btnstr.PBTN_iPosY = py;

      

      let computePosSize btnstr vw vh -> [px py pw ph] in

      (

        SO3WidgetSetPosition btnstr.PBTN_win px py;

        SO3WidgetSetSize btnstr.PBTN_win pw ph;

      );

    );

  );

  0;;





fun cbSetSize(inst, from, action, param, reply, btnstr)=

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 0 -> wpercent in

    let if (!strcmp "%" (substr sx ((strlen sx) - 1) 1)) then

        (

          set wpercent = 1;

          atoi sx;

        )

        else

          atoi sx

    -> px in

    let 0 -> hpercent in

    let if (!strcmp "%" (substr sy ((strlen sy) - 1) 1)) then

        (

          set hpercent = 1;

          atoi sy;

        )

        else

          atoi sy

    -> py in

    let [(if px == nil then 0 else px) (if py == nil then 0 else py)] -> [px py] in

    (

      mutate btnstr.PBTN_tPercent <- [_ _ wpercent hpercent _ _ _ _];

      set btnstr.PBTN_iWidth = px;

      set btnstr.PBTN_iHeight = py;

      

      let computePosSize btnstr vw vh -> [px py pw ph] in

      (

        SO3WidgetSetPosition btnstr.PBTN_win px py;

        SO3WidgetSetSize btnstr.PBTN_win pw ph;

      );

    );

  );

  0;;





fun cbSetOpacity(inst, from, action, param, reply, btnstr)=

  if (param == nil) || (!strcmp "" strtrim param) || ((atoi param) == nil) then nil else

  let atoi param -> opacity in

  (

    set btnstr.PBTN_iOpacity = opacity;

    SO3WidgetSetOpacity btnstr.PBTN_win (itof btnstr.PBTN_iOpacity) *. 0.01;

  );

  0;;





// Destroy instance

fun deleteOb(inst, btnstr)=

  setPluginInstanceCbScenePreRender inst nil;

  

  if (btnstr.PBTN_trmMouseState == nil) then nil else

  (

    _deltimer btnstr.PBTN_trmMouseState;

    set btnstr.PBTN_trmMouseState = nil;

  );

  

  if (btnstr.PBTN_httpReq == nil) then nil else

  (

    killHttpRequest btnstr.PBTN_httpReq;

    set btnstr.PBTN_httpReq = nil;

  );

  

  restoreTexture btnstr;

  0;;





fun cbNewOb(inst)=

  let (getPluginInstanceParam inst "object") -> objname in

  let (getPluginInstanceParam inst "material") -> matname in

  let atoi (getPluginInstanceParam inst "technique") -> technique in

  let if (technique == nil) || (technique < 0) then 0 else technique -> technique in

  let atoi (getPluginInstanceParam inst "pass") -> pass in

  let if (pass == nil) || (pass < 0) then 0 else pass -> pass in

  let atoi (getPluginInstanceParam inst "texture") -> texture in

  let if (texture == nil) || (texture < 0) then 0 else texture -> texture in

  let	 atoi (getPluginInstanceParam inst "istexture") -> istexture in

  let if istexture == nil then 0 else istexture -> istexture in

  

  let (getPluginInstanceParam inst "path") -> path in

  let atoi (getPluginInstanceParam inst "isurl") -> isurl in

  let if isurl == nil then 0 else isurl -> isurl in

  let (getPluginInstanceParam inst "url") -> url in      

  let atoi (getPluginInstanceParam inst "btnstates") -> btnstates in

  let if btnstates == nil then 0 else btnstates -> btnstates in

  

  let atoi (getPluginInstanceParam inst "nbframes") -> nbframes in

  let if (nbframes == nil) || (nbframes < 1) then 1 else nbframes -> nbframes in

  

  let atoi (getPluginInstanceParam inst "xpercent") -> xpercent in

  let if xpercent == nil then 0 else xpercent -> xpercent in

  let atoi (getPluginInstanceParam inst "xalign") -> xalign in

  let if xalign == nil then 0 else xalign -> xalign in

  let atoi (getPluginInstanceParam inst "posx") -> posx in

  let if posx == nil then 0 else posx -> posx in

  let atoi (getPluginInstanceParam inst "ypercent") -> ypercent in

  let if ypercent == nil then 0 else ypercent -> ypercent in

  let atoi (getPluginInstanceParam inst "yalign") -> yalign in

  let if yalign == nil then 0 else yalign -> yalign in

  let atoi (getPluginInstanceParam inst "posy") -> posy in

  let if posy == nil then 0 else posy -> posy in

  let atoi (getPluginInstanceParam inst "wpercent") -> wpercent in

  let if wpercent == nil then 1 else wpercent -> wpercent in

  let atoi (getPluginInstanceParam inst "width") -> width in

  let if width == nil then 100 else width -> width in

  let atoi (getPluginInstanceParam inst "hpercent") -> hpercent in

  let if hpercent == nil then 1 else hpercent -> hpercent in

  let atoi (getPluginInstanceParam inst "xoffset") -> xoffset in

  let if xoffset == nil then 0 else xoffset -> xoffset in

  let atoi (getPluginInstanceParam inst "yoffset") -> yoffset in

  let if yoffset == nil then 0 else yoffset -> yoffset in

  let atoi (getPluginInstanceParam inst "woffset") -> woffset in

  let if woffset == nil then 0 else woffset -> woffset in

  let atoi (getPluginInstanceParam inst "hoffset") -> hoffset in

  let if hoffset == nil then 0 else hoffset -> hoffset in

  let atoi (getPluginInstanceParam inst "height") -> height in

  let if height == nil then 100 else height -> height in

  

  let getPluginInstanceParam inst "fontname" -> fname in

  let if fname == nil then "Arial" else fname -> fname in

  let atoi (getPluginInstanceParam inst "fontcolor") -> fcolor in

  let if fcolor == nil then 0 else fcolor -> fcolor in

  let atoi (getPluginInstanceParam inst "fontsize") -> fsize in

  let if fsize == nil then 12 else fsize -> fsize in

  let atoi (getPluginInstanceParam inst "fontbold") -> fbold in

  let if fbold == nil then 0 else fbold -> fbold in

  let getPluginInstanceParam inst "label" -> label in

  let if label == nil then "" else label -> label in

  let _CRfont _channel fsize 0 FF_PIXEL|(if fbold then FF_WEIGHT else 0) fname -> font in

  

  let atoi (getPluginInstanceParam inst "opacity") -> opacity in

  let if opacity == nil then 100 else opacity -> opacity in

  let atoi (getPluginInstanceParam inst "transition") -> transition in

  let if transition == nil then 0 else transition -> transition in

  

  let atoi (getPluginInstanceParam inst "transparency") -> trans in

  let if (trans == nil) then 0 else trans -> trans in

  

  let atoi (getPluginInstanceParam inst "enablemouse") -> enablemouse in

  let if enablemouse == nil then 1 else enablemouse -> enablemouse in

  

  let atoi (getPluginInstanceParam inst "cursor") -> cursor in

  let if cursor == nil then 1 else cursor -> cursor in

  

  let atoi (getPluginInstanceParam inst "show") -> show in

  let if (show == nil) then 1 else show -> show in

  let if !isurl then path else url -> file in
  let V3DgetSessionView c3dXsession -> viewstr in
  let V3DgetViewPosSize viewstr -> [screenx screeny screen_width screen_height] in
  let  screen_width -(screen_width-(width + posx)) -> rightmargin in
  let screen_height -(screen_height - (height + posy))-> bottommargin in
  let 0 -> xcenter in
  let screen_height -(screen_height - ((height/2) + posy)) -> ycenter in
  let 0 -> toggle_ID in
  let 0 -> listfull in
  let 0 -> widgetcreated in
  //load the touchpoint image
  let G2DloadAlphaBmp _channel strcatn (getPluginDirectory (getInstancePlugin inst))::"/res/tips.png"::nil -> fingtertip_alphabitmap in

  let if !istexture then nil else SO3SceneGetMaterial (V3DgetSession c3dXsession) (getPluginInstanceGroupName inst) matname -> mat in

  let MkPlugButton [inst istexture mat technique pass texture nil nil nil fingtertip_alphabitmap posx posy rightmargin bottommargin toggle_ID width height xcenter ycenter [xpercent ypercent wpercent hpercent xoffset yoffset woffset hoffset] [xalign yalign] trans opacity transition 0.0 font label fcolor isurl file 0 0 cursor enablemouse 0 btnstates 0 nbframes 0 0 0 nil nil nil listfull widgetcreated nil] -> btnstr in

  (

    if btnstr.PBTN_bOnMaterial then nil else

      setPluginInstanceCbResizeView inst mkfun5 @cbResizeCtrl btnstr;

    

    if show then

      cbShow inst nil nil nil nil btnstr

    else

      cbHide inst nil nil nil nil btnstr;

    

    PluginRegisterAction inst "Show" mkfun6 @cbShow btnstr;

    PluginRegisterAction inst "Hide" mkfun6 @cbHide btnstr;

    PluginRegisterAction inst "Change" mkfun6 @cbChange btnstr;

    PluginRegisterAction inst "Enable" mkfun6 @cbEnable btnstr;

    PluginRegisterAction inst "Disable" mkfun6 @cbDisable btnstr;

    PluginRegisterAction inst "Set state" mkfun6 @cbSetState btnstr;

    PluginRegisterAction inst "Set label" mkfun6 @cbSetLabel btnstr;

    PluginRegisterAction inst "Send left click" mkfun6 @cbSendLeftClick btnstr;

    PluginRegisterAction inst "Send right click" mkfun6 @cbSendRightClick btnstr;

    PluginRegisterAction inst "Send middle click" mkfun6 @cbSendMiddleClick btnstr;

    PluginRegisterAction inst "Set position" mkfun6 @cbSetPosition btnstr;

    PluginRegisterAction inst "Set size" mkfun6 @cbSetSize btnstr;

    PluginRegisterAction inst "Set opacity" mkfun6 @cbSetOpacity btnstr;





    setPluginInstanceCbTouchPointAdd inst mkfun6 @cbAddCursor btnstr;

    setPluginInstanceCbTouchPointRemove inst mkfun4 @cbRemoveCursor btnstr;

    setPluginInstanceCbTouchPointUpdate inst mkfun8 @cbUpdateCursor btnstr;



  	setPluginInstanceCbDel inst mkfun2 @deleteOb btnstr;

  	

  	SendPluginEvent btnstr.PBTN_instance "Started" nil nil;

  );

  0;;





fun IniPlug(file) =

  set sHandCursor = strcat APPBASEDIR sHandCursor;

  let _LDbitmap _channel _checkpack sHandCursor -> bmpcursor in

  let _CRcursor _channel bmpcursor 12 6 0x000000 0xffffff -> cursor in

  (

    _DSbitmap bmpcursor;

    set cHandCursor = cursor;

  );

  

  PlugRegister @cbNewOb nil;

  setPluginEditor @dynamicedit;

  0;;

Offline

#5 26-Nov-2014 17:14:41

hebdemnobad
Member
From: northamerica
Registered: 20-Apr-2011
Posts: 1,541
Website

Re: encountering scol .exe crash with modified plugit

for some reason if i set the button width to 10, and check % directly to the right, when the code extracts the btnstr.PBTN_tPercent tuple, the third item of the list turns into 8....hmph

Offline

#6 26-Nov-2014 17:27:27

iri
Admin. / Scol language & Scol apps developer
From: France
Registered: 22-Feb-2009
Posts: 2,024
Website

Re: encountering scol .exe crash with modified plugit

fun computePosSize(btnstr, vw, vh)=
  _showconsole;
  _fooS strcatn "view size"::(itoa vw)::nil;
    _fooS strcatn "view heighh"::(itoa vh)::nil;
 // ....
  _fooS strcatn "button width"::(itoa pw)::nil;
      _fooS strcatn "button height"::(itoa ph)::nil;
  // ....

These entries are in the log file ? If yes, what are the values ?

Offline

#7 26-Nov-2014 17:36:48

hebdemnobad
Member
From: northamerica
Registered: 20-Apr-2011
Posts: 1,541
Website

Re: encountering scol .exe crash with modified plugit

yes here is an example.  this is some simple arithmetic or variable assigement i'm missing...

maximized
view size960
view heighh683
percent width796
button width796
button height717
back in resize control fucnction,button width796
back in resize control fucnction,button height717
_CHANGEobjNodeCoordinates: ObjNode is nil !
_CHANGEobjNodeCoordinates: ObjNode is nil !
maximized
view size837
view heighh105
percent width6662
button width6662
button height752
back in resize control fucnction,button width6662
back in resize control fucnction,button height752
_CHANGEobjNodeCoordinates: ObjNode is nil !
_CHANGEobjNodeCoordinates: ObjNode is nil !
maximized
view size960
view heighh683
percent width63955
button width63955
button height5136
back in resize control fucnction,button width63955
back in resize control fucnction,button height5136

Offline

#8 26-Nov-2014 18:02:50

arkeon
Admin. / Scol language & OpenSpace3D developer
From: Nantes
Registered: 30-Mar-2009
Posts: 5,161
Website

Re: encountering scol .exe crash with modified plugit

whatever you do you should not encounter a crash.

can you make a zip of your plugIT and send it to me with an xos scene that make it crash ?

Offline

#9 26-Nov-2014 18:04:32

hebdemnobad
Member
From: northamerica
Registered: 20-Apr-2011
Posts: 1,541
Website

Re: encountering scol .exe crash with modified plugit

arkeon wrote:

whatever you do you should not encounter a crash.

can you make a zip of your plugIT and send it to me with an xos scene that make it crash ?


for the .xos file, yes i will try to do this tonight my time, thx!

here are the plugit files:
ifam.net/mediaoctopus3d/throttle.zip

Last edited by hebdemnobad (26-Nov-2014 18:05:20)

Offline

#10 26-Nov-2014 18:39:57

arkeon
Admin. / Scol language & OpenSpace3D developer
From: Nantes
Registered: 30-Mar-2009
Posts: 5,161
Website

Re: encountering scol .exe crash with modified plugit

Your size callback and calculation are bad, and you try to create a too huge bitmap size.
Ogre return an exception because of a memory issue.

I added a try catch for this  case to try to prevent the crash but you should correct the code anyway.

Offline

#11 26-Nov-2014 18:46:26

hebdemnobad
Member
From: northamerica
Registered: 20-Apr-2011
Posts: 1,541
Website

Re: encountering scol .exe crash with modified plugit

arkeon wrote:

Your size callback and calculation are bad, and you try to create a too huge bitmap size.
Ogre return an exception because of a memory issue.

I added a try catch for this  case to try to prevent the crash but you should correct the code anyway.

thx, yes i know this....i just cannot find out where the code gremlin is (aside from me).

Offline

#12 26-Nov-2014 19:10:41

arkeon
Admin. / Scol language & OpenSpace3D developer
From: Nantes
Registered: 30-Mar-2009
Posts: 5,161
Website

Re: encountering scol .exe crash with modified plugit

why did you change the resize code ?

Offline

#13 26-Nov-2014 19:13:41

arkeon
Admin. / Scol language & OpenSpace3D developer
From: Nantes
Registered: 30-Mar-2009
Posts: 5,161
Website

Re: encountering scol .exe crash with modified plugit

if you change the values in the resize callback that are definied in the editor, and this values are used to compute the position and size.
So you get an incremental behavior.

if you want to get the current widget pos and size use directly widget functions.
Do not change values that are used to compute the current position.

Offline

#14 26-Nov-2014 19:30:07

hebdemnobad
Member
From: northamerica
Registered: 20-Apr-2011
Posts: 1,541
Website

Re: encountering scol .exe crash with modified plugit

arkeon wrote:

if you change the values in the resize callback that are definied in the editor, and this values are used to compute the position and size.
So you get an incremental behavior.

if you want to get the current widget pos and size use directly widget functions.
Do not change values that are used to compute the current position.

i see, so i use SO3WidgetGetPosition and SO3WidgetGetSize, etc.

this is strange, in your version of the button plugit you don't do this, you get the values from the struct. oh well, i will fix it and won't worry too much about how i broke it.


fun computePosSize(btnstr, vw, vh)=

  let btnstr.PBTN_tPercent -> [px py pw ph xo yo wo ho] in

  let btnstr.PBTN_tAlign -> [ax ay] in

  let if pw then (ftoi (((itof btnstr.PBTN_iWidth) /. 100.0) *. (itof vw))) + wo else btnstr.PBTN_iWidth -> pw in

  let if ph then (ftoi (((itof btnstr.PBTN_iHeight) /. 100.0) *. (itof vh))) + ho else btnstr.PBTN_iHeight -> ph in

  let if px then (ftoi (((itof btnstr.PBTN_iPosX) /. 100.0) *. (itof vw))) + xo else btnstr.PBTN_iPosX -> px in

  let if (ax == 1) then ((vw / 2) - (pw / 2)) + px else if (ax == 2) then (vw - pw) - px  else px -> px in

  let if py then (ftoi (((itof btnstr.PBTN_iPosY) /. 100.0) *. (itof vh))) + yo else btnstr.PBTN_iPosY -> py in

  let if (ay == 1) then ((vh / 2) - (ph / 2)) + py else if (ay == 2) then (vh - ph) - py else py -> py in

    [px py pw ph];;





fun cbResizeCtrl(inst, viewstr, vw, vh, btnstr)=

  if btnstr.PBTN_win == nil || btnstr.PBTN_bOnMaterial then nil else

  let computePosSize btnstr vw vh -> [px py pw ph] in

  (

    SO3WidgetSetPosition btnstr.PBTN_win px py;

    SO3WidgetSetSize btnstr.PBTN_win pw ph;

    updateButton btnstr;

  );

  0;;

Offline

#15 26-Nov-2014 19:31:58

arkeon
Admin. / Scol language & OpenSpace3D developer
From: Nantes
Registered: 30-Mar-2009
Posts: 5,161
Website

Re: encountering scol .exe crash with modified plugit

computePosSize calculate the new position of the widget on resize from the parameters set in the editor.
if you change btnstr.PBTN_iWidth or something else latter or in resize function the values will not be correct anymore.

Offline

#16 26-Nov-2014 19:33:58

iri
Admin. / Scol language & Scol apps developer
From: France
Registered: 22-Feb-2009
Posts: 2,024
Website

Re: encountering scol .exe crash with modified plugit

arkeon wrote:

computePosSize calculate the new position of the widget on resize from the parameters set in the editor.
if you change btnstr.PBTN_iWidth or something else latter or in resize function the values will not be correct anymore.

+1 smile

Offline

#17 26-Nov-2014 19:34:06

hebdemnobad
Member
From: northamerica
Registered: 20-Apr-2011
Posts: 1,541
Website

Re: encountering scol .exe crash with modified plugit

arkeon wrote:

computePosSize calculate the new position of the widget on resize from the parameters set in the editor.
if you change btnstr.PBTN_iWidth or something else latter or in resize function the values will not be correct anymore.

aha, i see....well the only thing i guess i will have to recalculate are the horizontal and vertical centers of the button at each resize event, since i am varying output by offset from the center of the throttle. i know what to do i think. thx.

Offline

#18 26-Nov-2014 20:18:01

hebdemnobad
Member
From: northamerica
Registered: 20-Apr-2011
Posts: 1,541
Website

Re: encountering scol .exe crash with modified plugit

arkeon wrote:

why did you change the resize code ?


I did this in order to revise the horizontal center and offset values that control widget output... as you said, I will get those with the widget methods and set my struct according to the widget properties and not the initial values set in the editor.

Offline

#19 27-Nov-2014 16:08:36

hebdemnobad
Member
From: northamerica
Registered: 20-Apr-2011
Posts: 1,541
Website

Re: encountering scol .exe crash with modified plugit

I removed the setting of PBTN_iWidth and PBTN_iHeight cbResizeCtrl and the button is behaving itself (not incrementing in size). and resizing is resulting in the correct button vertical center values. will do more work later in weekend/early next week, thx guys

Offline

Board footer

Powered by FluxBB