/* Tree Editor - aout.99 - par Sylvain Huet */ /* add localisation (must define "loc" function) - may 2001 - by macfly */ var file1="locked/etc/tree.folder.bmp";; var file2="locked/etc/tree.folder.bmp";; var SEL_TEXTURE=1;; var SEL_M3D=2;; var SIZEBMP=256;; fun flaginsert()=TREE_INSERT_SORT;; fun conc(p,q)= if p == nil then q else (hd p)::conc tl p q;; fun getpos(win)= let _GETwindowPositionSize win ->[x y w h] in let (w-15)>>1 -> w2 in [[5 5 w-10 20] [5 30 w2 h-65-SIZEBMP] [w2+10 30 w2 h-35] [10 h-25 60 20] [80 h-25 60 20] [5 h-30-SIZEBMP SIZEBMP SIZEBMP]];; fun lastname(s)= let strfind "/" s 0 -> j in if j==nil then s else lastname substr s j+1 strlen s;; struct BookEdit=[chBook:Chn,winBook:ObjWin,trBook:ObjTree, lBook:[[ObjTreeItem ObjTreeItem S] r1],curpathBook:S, endBook:fun [S] I,flagBook:I, bannerBook:ObjText,liBook:ObjList, okBook:ObjButton,cancelBook:ObjButton, lbBook:ObjBitmapList,iopenBook:BitmapIndex,icloseBook:BitmapIndex, bmpBook:ObjBitmap,srfBook:ObjSurface,s3dBook:S3d,targetBook:H3d,timerBook:Timer] mkBook;; var TREE_BROWSE=1;; /* Tree management */ fun bytreeitem(a,i)= let a->[j _ _] in i==j;; fun byfather(a,i)= let a->[_ j _] in i==j;; fun bytreepath(a,i)= let a->[_ _ j] in !strcmpi i j;; fun createnode(b,pere,text,path)= let _ADDtreeChild b.trBook pere flaginsert text -> node in (_SETtreeItemBitmap b.trBook node b.iopenBook b.icloseBook; set b.lBook=[node pere path]::b.lBook; node);; fun closenode(b,node)= let search_in_list b.lBook @byfather node -> z in if z==nil then 0 else let z->[n _ _] in (closenode b n; _DStreeItem b.trBook n; set b.lBook=remove_from_list b.lBook z; closenode b node);; proto opennode=fun[BookEdit ObjTreeItem I] I;; fun addsubdir(x,z)=let z->[b node flag] in let createnode b node lastname x x ->newnode in if flag then opennode b newnode flag-1 else 0;; fun opennode(b,node,flag)= closenode b node; let search_in_list b.lBook @bytreeitem node -> [_ _ path] in if path==nil then nil else apply_on_list _listofsubdir path @addsubdir [b node flag];; fun initree(b,root)= let createnode b nil root root ->node in (_SELtreeItem b.trBook node);; /* List management */ fun filtfile(b,x)= if b.flagBook==SEL_TEXTURE then if (!strcmp substr x (strlen x)-4 4 ".bmp") ||(!strcmp substr x (strlen x)-4 4 ".jpg") ||(!strcmp substr x (strlen x)-5 5 ".jpeg") then 1 else 0 else if b.flagBook==SEL_M3D then if (!strcmp substr x (strlen x)-4 4 ".m3d") then 1 else 0 else 1;; fun filtlist(b,l)= if l==nil then nil else if filtfile b hd l then (hd l)::filtlist b tl l else filtlist b tl l;; fun mystrcmp(a,b)=strcmp a b;; fun addlist(x,b)=_ADDlist b.liBook 1000 lastname x;; fun updatel(b,path)= _RSTlist b.liBook; set b.curpathBook= if 0==strlen path then path else strcat path "/"; apply_on_list (quicksort filtlist b _listoffiles path @mystrcmp) @addlist b;; fun ldbitmap(bmp,p)= _FILLbitmap bmp 0; if p==nil then nil else let _LDbitmap _channel p -> imagebmp in let if imagebmp==nil then _LDjpeg _channel p else imagebmp -> image in if image==nil then nil else let _GETbitmapSize image -> [w h] in (_SCPbitmap bmp 0 0 SIZEBMP SIZEBMP image 0 0 w-1 h-1 nil; _DSbitmap image; 0);; fun targetcam(session,c,h)= let M3getFather session c -> f in let M3getObjVec session c -> src in let M3calcPosRef session h f -> [dst _] in let M3angularTarget src dst -> [an bn _] in M3setObjAng session c [an bn 0];; fun clock(a,z)= let z->[b cam shell1 i] in (mutate z<-[_ _ _ i+1]; M3rotateObjExt b.s3dBook shell1 [100 0 0]; let M3getObjAng b.s3dBook shell1 ->[x _ _] in M3setObjAng b.s3dBook shell1 [x ftoi (itof 5000)*.cos((itof i)/.(itof 100)) 0]; targetcam b.s3dBook cam b.targetBook; MX3render b.s3dBook b.srfBook cam 0 0 0xa08000; let getpos b.winBook ->[_ _ _ _ _ [x y _ _]] in _BLTsurface b.winBook x y b.srfBook 0 0 SIZEBMP SIZEBMP);; fun getRadius(session,h,shell)= let M3getRadius session h->r in if r==nil then nil else let M3convVec session h shell [r 0 0] -> [x y z] in ftoi sqrt (sqr itof x)+.(sqr itof y)+.(sqr itof z);; fun compareradius(session,h1,h2,shell)= let getRadius session h1 shell->r1 in let getRadius session h2 shell->r2 in if r1==nil then h2 else if r2==nil then h1 else if r1>r2 then h1 else h2;; fun maxradius(session,h,shell)= if h==nil then nil else compareradius session h compareradius session (maxradius session M3getBrother session h shell) (maxradius session M3getFirstSon session h shell) shell shell;; fun ld3d(b,file)= M3destroy b.s3dBook; set b.s3dBook=nil; _deltimer b.timerBook; set b.timerBook=nil; set b.s3dBook = MX3create _channel 1024 1024 1024 1024 1024*1024; if b.s3dBook==nil then nil else let M3createShell b.s3dBook -> shell in let M3createShell b.s3dBook -> shell1 in ( M3link b.s3dBook shell1 shell; M3loadString b.s3dBook "camera camera {\n0 0 0 0 0 0\n50 50 50 50\n10 10000 10000\n}\n" shell; let M3getObj b.s3dBook "camera" ->cam in ( M3load b.s3dBook file shell1; if (M3getAnimLength b.s3dBook shell1) == 0 then nil else M3setAnimKey b.s3dBook shell1 0; M3recursFillMatObj b.s3dBook shell; let set b.targetBook=maxradius b.s3dBook shell1 shell -> target in let getRadius b.s3dBook target shell -> r in M3setObjVec b.s3dBook cam [0 0 (3*-if r==nil then 1 else r)>>1]; M3setCamera b.s3dBook cam [[SIZEBMP>>1 SIZEBMP>>1] [SIZEBMP>>1 SIZEBMP>>1] [10 100000 100000]]; set b.timerBook=_rfltimer _starttimer b.chBook 20 @clock [b cam shell1 0] ) ); 0 ;; fun _paint(a,b)= if b.flagBook==SEL_TEXTURE then let getpos b.winBook ->[_ _ _ _ _ [x y _ _]] in _BLTbitmap b.winBook b.bmpBook x y else nil;; fun _sel(a,b,i,s)= let strcat b.curpathBook s ->file in (_SETtext b.bannerBook file; if b.flagBook==SEL_TEXTURE then ldbitmap b.bmpBook _checkpack file else if b.flagBook==SEL_M3D then ld3d b file else nil; _paint nil b);; fun selini(b,file,i)= let strfind "/" file i ->j in if j==nil then let lastname file -> f in (_SSELlist b.liBook f; _sel nil b nil f; 0) else let search_in_list b.lBook @bytreepath substr file 0 j ->[n _ _] in if n==nil then nil else (_SELtreeItem b.trBook n; selini b file j+1);; /* event management*/ fun _click(a,b,node)= opennode b node 1; _SETtreeItemState b.trBook node 1; let search_in_list b.lBook @bytreeitem node -> [_ _ path] in updatel b path; 0;; fun delres(b)= _DSbitmap b.bmpBook; _DSsurface b.srfBook; M3destroy b.s3dBook; _deltimer b.timerBook;; fun _ok(x,b)= let _GETtext b.bannerBook -> file in (_DSwindow b.winBook; delres b; exec b.endBook with [file]);; fun _cancel(x,b)= _DSwindow b.winBook; delres b; exec b.endBook with [nil];; fun _destroy(x,b)= delres b; exec b.endBook with [nil];; fun _resize(a,b,x,y)= if (x<200) || (y<120) then nil else let getpos b.winBook ->[[bnx bny bnw bnh] [trx try trw trh] [lix liy liw lih] [box boy bow boh] [bcx bcy bcw bch] _] in (_SIZEtext b.bannerBook bnw bnh bnx bny; _SIZEtree b.trBook trw trh trx try; _SIZElist b.liBook liw lih lix liy; _SIZEbutton b.okBook bow boh box boy; _SIZEbutton b.cancelBook bcw bch bcx bcy) ;; fun iniseltexture(b)= set b.bmpBook=_CRbitmap b.chBook SIZEBMP SIZEBMP; 0;; fun iniselm3d(b)= set b.srfBook=_CRsurface b.chBook SIZEBMP SIZEBMP; 0;; fun inibook(ch,father,w,h,title,end,root,flag,file)= let _CRwindow ch father 100 100 w h WN_MENU+WN_MINBOX+WN_SIZEBOX title -> win in let getpos win ->[[bnx bny bnw bnh] [trx try trw trh] [lix liy liw lih] [box boy bow boh] [bcx bcy bcw bch] _] in let _CRtext ch win bnx bny bnw bnh ET_BORDER file -> banner in let _CRtree ch win trx try trw trh TV_DOWN|TV_VSCROLL|TV_BUTTON -> tr in let _CRlist ch win lix liy liw lih LB_DOWN+LB_VSCROLL -> li in let _CRbutton ch win box boy bow boh 0 loc "OK" -> ok in let _CRbutton ch win bcx bcy bcw bch 0 loc "CANCEL" -> cancel in let _CRbitmapList ch 16 16 -> lb in let mkBook [ch win tr nil nil end flag banner li ok cancel lb nil nil nil nil nil nil nil] -> b in (_CBwinDestroy win @_destroy b; _CBwinSize win @_resize b; _CBwinPaint win @_paint b; _CBtreeSelect tr @_click b; _CBlistClick li @_sel b; _CBbutton ok @_ok b; _CBbutton cancel @_cancel b; set b.iopenBook=_ADDbitmapList lb _LDbitmap ch _checkpack file1; set b.icloseBook=_ADDbitmapList lb _LDbitmap ch _checkpack file2; _SETtreeBitmaps tr lb; if flag==SEL_TEXTURE then iniseltexture b else if flag==SEL_M3D then iniselm3d b else nil; initree b root; selini b file strlen root; b );; fun _destroyevent(s)=_closemachine;; fun main()= inibook _channel nil 600 500 "Book Editor" @_destroyevent "" SEL_M3D nil;;