/***************************************************************/ /* */ /* PBLOADING.PKG */ /* */ /* plug-in PhotoPaintBall */ /* client - circular loading bar for download of resources */ /* */ /* version 5 : Loïc Berthelot, janv 2001 */ /* */ /* nouvelle version 4.5 : Loïc Berthelot nov 2000 */ /* */ /* Photo3 Plugin - DMS - march 00 - by Sylvain HUET */ /* */ /***************************************************************/ /***************************************************************/ /* */ /* */ /* DATA STRUCT : */ /* struct LOADING */ /* typeof ldg : LOADING */ /* typeof colorWhite : I */ /* typeof colorBlack : I */ /* */ /* */ /* INTERNAL BODY : */ /* loading_polToCart : fun [F F] [F F] */ /* loading_cartToPol : fun [F F] [F F] */ /* loading_makeLine : fun [F] I */ /* loading_init : fun [...] I */ /* */ /* */ /* EXTERNAL BODY : */ /* loading_destroy : fun [] I */ /* loading_step : fun [I] */ /* loading_render : fun [Ob u0] I */ /* loading_start : fun [] I */ /* */ /* */ /***************************************************************/ /**************************************************************************/ /* */ /* D A T A S T R U C T */ /* */ /**************************************************************************/ struct LOADING = [ source_LDG : AlphaBitmap, alpha_LDG : ObjBitmap8, bmp_LDG : ObjBitmap, PI_LDG : F, /* cste PI */ dblPI_LDG : F, /* 2 * PI */ INCR_LDG : F, /* PI /. 360 */ r1_LDG : I, /* radius 1 */ r2_LDG : I, /* radius 2 */ w_LDG : I, /* image width */ h_LDG : I, /* image height */ halfW_LDG : I, /* width / 2 */ halfH_LDG : I, /* half / 2 */ cx_LDG : I, /* x center */ cy_LDG : I, /* y center */ ce_LDG : I, /* outline thickness */ fe_LDG : I, /* inline thickness */ alphaColor_LDG : I, /* color for alpha drawing */ /* <=> transparency rate */ transparencyColor_LDG : I, /* transparency color for bliting on surface */ curTeta_LDG : F /* angle counter */ ] mkLOADING;; typeof ldg = LOADING;; typeof colorWhite = I;; typeof colorBlack = I;; /**************************************************************************/ /* */ /* I N T E R N A L B O D Y */ /* */ /**************************************************************************/ /*****************************************/ /* loading_polToCart [F F] [F F] */ /* coord polaires --> coord cartésiennes */ /* */ /* by g. Leblond, CryoNetworks */ /*****************************************/ fun loading_polToCart (pol) = let pol -> [r teta] in [(r*.(cos teta)) (r*.(sin teta))];; /*****************************************/ /* loading_cartToPol [F F] [F F] */ /* coord cartésiennes --> coord polaires */ /* */ /* by g. Leblond, CryoNetworks */ /*****************************************/ fun loading_cartToPol (cart) = let cart->[x y] in let (sqrt ((sqr x)+.(sqr y)))->r in [r ( if (y>=.(itof 0)) then (acos (x/.r)) else -.(acos (x/.r)) )];; /*******************************************/ /* loading_makeLine [F] I */ /* */ /* draw a line of the filled circle, on */ /* the alpha channel */ /* <==> make the same line from the bitmap */ /* circle appears. */ /* */ /*******************************************/ fun loading_makeLine (teta) = let loading_polToCart [(itof (ldg.r1_LDG+1)) teta] -> [x1 y1] in let [(ftoi x1)+ldg.cx_LDG (ftoi y1)+ldg.cy_LDG] -> [x1 y1] in let loading_polToCart [(itof (ldg.r2_LDG-1)) teta] -> [x2 y2] in let [(ftoi x2)+ldg.cx_LDG (ftoi y2)+ldg.cy_LDG] -> [x2 y2] in _DRAWline8 ldg.alpha_LDG x1 y1 x2 y2 DRAW_SOLID ldg.fe_LDG ldg.alphaColor_LDG; 1;; /*********************************************************/ /* loading_init [...] I */ /* */ /* initialization of the loading bar */ /*********************************************************/ fun loading_init (centercoord, r, e, w, h, fln, ac, tc) = /* colors initialization */ set colorWhite = make_rgb 255 255 255; set colorBlack = make_rgb 0 0 0; let centercoord -> [cx cy] in let r -> [r1 r2] in let e -> [ce fe] in ( /* set data structs */ set ldg.PI_LDG = atof "3.1415"; set ldg.dblPI_LDG = (itof 2) *. ldg.PI_LDG; set ldg.INCR_LDG = ldg.dblPI_LDG /. (atof "360.0"); set ldg.w_LDG = w; set ldg.h_LDG = h; set ldg.halfW_LDG = w/2; set ldg.halfH_LDG = h/2; set ldg.cx_LDG = cx; set ldg.cy_LDG = cy; set ldg.r1_LDG = r1; set ldg.r2_LDG = r2; set ldg.ce_LDG = ce; set ldg.fe_LDG = fe; set ldg.alphaColor_LDG = ac; set ldg.transparencyColor_LDG = tc; set ldg.curTeta_LDG = (itof 0); set ldg.source_LDG = _LDalphaBitmap _channel (_checkpack fln); let _GETalphaBitmaps ldg.source_LDG -> [bmp msk] in /* construct alpha palette */ let mktab 768 0 -> palette in let 0 -> i in let 0 -> c in let while (i < 768) do ( set palette.(i) = c; set palette.(i+1) = c; set palette.(i+2) = c; set i = i+3; set c = c+1; ) -> tmp in let _SETbitmapPalette msk palette -> tmp in ( /* draw the empty circle */ _FILLbitmap8 msk colorBlack; /* write a "loading" texte into the alpha ch */ let _CRfont _channel 22 0 FF_WEIGHT "Arial" -> lfont in let _GETstringSize lfont "LOADING" -> [sw sh] in ( _DRAWtext8 msk lfont (cx-(sw/2)) (cy-(sh/2)) TD_LEFT|TD_TOP ldg.alphaColor_LDG "LOADING"; _DSfont lfont; ); _DRAWcircle8 msk cx cy r1 DRAW_SOLID ce colorWhite DRAW_INVISIBLE nil; _DRAWcircle8 msk cx cy r2 DRAW_SOLID ce colorWhite DRAW_INVISIBLE nil; _DRAWcircle bmp cx cy r1 DRAW_SOLID ce colorBlack DRAW_INVISIBLE nil; _DRAWcircle bmp cx cy r2 DRAW_SOLID ce colorBlack DRAW_INVISIBLE nil; set ldg.bmp_LDG = _CRbitmap _channel w h; _FILLbitmap ldg.bmp_LDG ldg.transparencyColor_LDG; set ldg.alpha_LDG = msk; ); );; /**************************************************************************/ /* */ /* E X T E R N A L B O D Y */ /* */ /**************************************************************************/ /********************************************/ /* loading_destroy [] I */ /* */ /* free loading resources */ /********************************************/ fun loading_destroy () = if (ldg != nil) then ( _DSalphaBitmap ldg.source_LDG; _DSbitmap ldg.bmp_LDG; set ldg = nil; ) else nil; 1;; /*****************************************/ /* loading_step [I] */ /* */ /* draw the loading circle, from */ /* the last percentage to the percentage */ /* given as parameter */ /* */ /*****************************************/ fun loading_step (percent) = let ((itof percent) *. ldg.dblPI_LDG) /. (itof 100) -> teta in let ldg.curTeta_LDG -> i in ( if (i <. teta) then ( while (i <=. teta) do ( loading_makeLine (-.i); set i = i +. ldg.INCR_LDG; ); set ldg.curTeta_LDG = teta; _CPalphaBitmap ldg.bmp_LDG 0 0 ldg.source_LDG 0 0 ldg.w_LDG ldg.h_LDG; ) else nil; 1; );; /********************************************/ /* loading_render [Ob u0] I */ /* */ /* postrender callback when during */ /* resources download. */ /* make a circular load bar appear */ /********************************************/ fun loading_render (o, z) = let z -> [d [x y]] in let _GETsurfaceSize d -> [dW dH] in ( /* get percentage of resources downloaded */ let (pbParams.nbLoadedRessources_PBP * 100) / pbParams.nbRessources_PBP -> percent in loading_step percent; /* apply on 3d surface */ _Bitmap2Surface d ((dW/2) - ldg.halfW_LDG) ((dH/2) - ldg.halfH_LDG) ldg.bmp_LDG 0 0 ldg.w_LDG ldg.h_LDG ldg.transparencyColor_LDG; ); 0;; /*********************************************************/ /* loading_start [] I */ /* */ /* start initialization of the loading bar */ /*********************************************************/ fun loading_start () = set ldg = mkLOADING [ nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil ]; loading_init [80 80] /* cx cy */ [61 78] /* r1 r2 */ [2 2] /* ce fe */ 158 158 /* w h */ (strcat pbItemsPath "loading.png") /* alpha bitmap filename */ 0xFFFFFF (make_rgb 0 0 255); 1;;