typeof display=ObjWin;; typeof list=ObjListTab;; typeof bitmap=ObjBitmap;; typeof image=ObjBitmap;; typeof status=ObjText;; typeof session=S3d;; typeof camera =H3d;; typeof shell =H3d;; var m3d_tape_size=200000;; var distance=0;; var angle_x=0;; var angle_y=0;; var schnauzer_path= "Tools/Schnauzer/";; var file_path ="";; var win_width = 400;; var win_height = 300;; var win_x = 200;; var win_y = 150;; var list_width = 150;; var display_border = 4;; var status_height = 22;; var folder_prefix = "+ ";; var file_prefix = " ";; var file_type = 0;; /* * image loader */ fun image_render()= _FILLbitmap bitmap 0; let _GETbitmapSize bitmap -> [w h] in let _GETbitmapSize image -> [iw ih] in if (iw>w || ih>h) then { let (itof w) /. (itof iw) -> ratiox in let (itof h) /. (itof ih) -> ratioy in let if (ratiox >. ratioy) then ratioy else ratiox -> ratio in let ftoi (itof iw) *. ratio -> ww in let ftoi (itof ih) *. ratio -> hh in let (w-ww)/2 -> posx in let (h-hh)/2 -> posy in _SCPbitmap bitmap posx posy posx+ww-1 posy+hh-1 image 0 0 iw-1 ih-1 nil; nil } else _CPbitmap16 bitmap (w-iw)/2 (h-ih)/2 image 0 0 iw ih nil;; fun schnauzer_load_img(name,ext)= let _checkpack strcat strcat file_path (if (!strcmp file_path "") then "" else "/") name -> path in let _LDbitmap _channel path -> bmp in let if (bmp==nil) then _LDjpeg _channel path else bmp -> bmp in if (bmp==nil) then nil else { set file_type=2; if (image==nil) then nil else _DSbitmap image; set image=bmp; image_render; _BLTbitmap display bitmap 0 0; let _GETbitmapSize image-> [w h] in _SETtext status strcatn ext::" "::(itoa w)::" x "::(itoa h)::nil; };; /* * M3D loader */ fun m3d_render(cam)= /* update camera parameters if needed */ if (cam==0) then nil else { let _GETbitmapSize bitmap -> [w h] in let M3getCamera session camera -> [[d _] [x _] z] in M3setCamera session camera [[d*(w>>1)/x d*(w>>1)/x] [w>>1 h>>1] z]; }; M3scanline session bitmap camera 0 0 0;; fun schnauzer_load_m3d(name)= let strcat strcat file_path (if (!strcmp file_path "") then "" else "/") name -> path in { if (session==nil) then M3destroy session else nil; set session=M3create _channel 1024 1024 1024 1024 m3d_tape_size; if (session==nil) then nil else { set file_type=1; set angle_x=0; set angle_y=0; set shell = M3createShell session; M3load session strcat schnauzer_path "camera.m3d" shell; M3load session path shell; set camera=M3getObj session "camera"; let M3getObjVec session camera -> [x y z] in set distance=(-z); M3recursFillMatObj session shell; m3d_render 1; _BLTbitmap display bitmap 0 0; _SETtext status strcatn "memory free : "::(itoa M3freeMemory session)::"/"::(itoa m3d_tape_size)::nil; }; };; fun schnauzer_load(name)= let substr name (strlen name)-3 3 -> ext in if (!strcmpi ext "bmp") then { schnauzer_load_img name "BMP"; 0 } else if (!strcmpi ext "jpg") then { schnauzer_load_img name "JPEG"; 0 } else if (!strcmpi ext "m3d") then { schnauzer_load_m3d name; 0 } else nil;; /* * list management */ fun listcat (p, q)= if (p==nil) then q else let p -> [h nxt] in h::listcat nxt q;; fun rdividelist (cmpfun, x, l, a1, a2)= if l==nil then [a1 a2] else let l -> [h nxt] in if (exec cmpfun with [x h]) < 0 then rdividelist cmpfun x nxt [h a1] a2 else rdividelist cmpfun x nxt a1 [h a2];; fun rquicksort (cmpfun, list)= if (list==nil) then nil else let list->[h nxt] in let rdividelist cmpfun h nxt nil nil -> [l1 l2] in listcat rquicksort cmpfun l1 h::rquicksort cmpfun l2;; fun alpha_test(a,b)=1-strcmpi a b;; fun alpha_sort(l)=rquicksort @alpha_test l;; fun strip_parent_folder(s)= let strfind "/" s 0 -> pos in if (pos==nil) then s else strip_parent_folder substr s pos+1 (strlen s)-pos-1;; fun update_list_items(l,s)= if (l==nil) then 0 else let l -> [h t] in { _ADDlistTabItem list 1234 9999 strcat s strip_parent_folder h; update_list_items t s; };; fun update_list()= let _listofsubdir file_path -> folders in let _listoffiles file_path -> files in { set folders=alpha_sort folders; set files=alpha_sort files; _RSTlistTab list; if (strcmp file_path "") then set folders=".."::folders else nil; update_list_items folders folder_prefix; update_list_items files file_prefix; };; fun change_folder(cd)= if (!strcmp cd "..") then { let (strlen strip_parent_folder file_path) + 1 -> pos in set file_path=substr file_path 0 (strlen file_path)-pos; } else if (!strcmp file_path "") then set file_path=cd else set file_path=strcat strcat file_path "/" cd;; fun on_select(obj,u,line)= if (!strcmpi folder_prefix substr name 0 (strlen folder_prefix)) then { set name=substr name (strlen folder_prefix) (strlen name)-(strlen folder_prefix); change_folder name; _fooS strcat "cd " name; update_list; } else { set name=substr name (strlen file_prefix) (strlen name)-(strlen file_prefix); schnauzer_load name; };; /* * INI management */ fun load_ini_parse(l)= if (l==nil) then 0 else let l -> [line next] in let line -> [param x] in let x -> [value _] in { if (!strcmpi param "posx") then set win_x=atoi value else if (!strcmpi param "posy") then set win_y=atoi value else if (!strcmpi param "width") then set win_width=atoi value else if (!strcmpi param "height") then set win_height=atoi value else if (!strcmpi param "path") then {set file_path=if (value==nil) then "" else value; 0} else 0; load_ini_parse next; };; fun load_ini()= let _getpack _checkpack strcat schnauzer_path "schnauzer.ini" -> ini in if (ini==nil) then nil else load_ini_parse strextr ini;; fun save_ini()= _storepack strbuild ("posx"::(itoa win_x)::nil):: ("posy"::(itoa win_y)::nil):: ("width"::(itoa win_width)::nil):: ("height"::(itoa win_height)::nil):: ("path"::file_path::nil)::nil strcat schnauzer_path "schnauzer.ini";; /* * mouse management */ var old_x=0;; var old_y=0;; fun calc_camera()= let (itof angle_x) /. (itof 10430) -> ax in let (itof angle_y) /. (itof 10430) -> ay in let ftoi ((itof distance) *. (sin ax) *. (cos ay)) -> x in let 0 - ftoi ((itof distance) *. (cos ax) *. (cos ay)) -> z in let ftoi ((itof distance) *. (sin ay)) -> y in let [x y z] -> pos in { M3setObjVec session camera pos; let M3angularTarget [x y z] [0 0 0] -> vector in M3setObjAng session camera vector; };; fun on_mouse(win,u,x,y,button)= if (button==1) then { set angle_x=angle_x-(x-old_x)<<7; set angle_y=angle_y+(y-old_y)<<7; calc_camera; m3d_render 1; _BLTbitmap display bitmap 0 0; } else if (button==2) then { set distance=distance+(y-old_y)<<2; calc_camera; m3d_render 1; _BLTbitmap display bitmap 0 0; } else nil; set old_x=x; set old_y=y;; /* * main window management */ fun on_resize(win,u,w,h)= set win_width=w; set win_height=h; _POSITIONlist list 0 0 list_width h; let w-list_width-2*display_border -> d_width in let h-2*display_border-status_height -> d_height in { _POSITIONwindow display list_width+display_border display_border d_width d_height; _POSITIONtext status list_width+display_border h-status_height w-list_width-2*display_border+2 status_height-2; if (bitmap==nil) then nil else _DSbitmap bitmap; set bitmap=_CRbitmap _channel d_width d_height; if (file_type==1) then { m3d_render 1; 0 } else if (file_type==2) then { image_render; 0 } else nil; };; fun on_move(win,u,x,y)= set win_x=x; set win_y=y;; fun on_repaint(win,u)=_BLTbitmap win bitmap 0 0;; fun on_destroy(win,u)=save_ini; _closemachine;; fun main()= load_ini; let _CRwindow _channel nil win_x win_y win_width win_height WN_MENU+WN_MINBOX+WN_MAXBOX+WN_SIZEBOX+WN_HIDDEN "M3D Schnauzer" -> win in { _SETwindowMinSize win 340 150; _CBwinMove win @on_move nil; _CBwinSize win @on_resize nil; _CBwinDestroy win @on_destroy nil; set list=_CRlistTab _channel win 0 0 10 win_height LV_DOWN|LV_SINGLESEL; _CBlistTabSelect list @on_select nil; _CBlistTabDClick list @on_dclic nil; update_list; set display=_CRwindow _channel win 10 10 10 10 WN_CHILD "display"; _CBwinPaint display @on_repaint nil; _CBcursorMove display @on_mouse nil; set status=_CRtext _channel win 10 10 10 10 ET_ALIGN_CENTER+ET_DOWN "Select file to view"; on_resize win nil win_width win_height; _SHOWwindow win WINDOW_UNHIDDEN; };;