/*bubble plugin - DMS2 - Jan 00 - by Gaetan Guentin & Dugh */ /*rev July 00 - by Sebastien DENEUX*/ /*rev May 01 - Julien ZORKO */ typeof class=S;; var EventPeriod = 1000;; var BubbleCpt = 0;; /* Compteur de secondes pour les bulles: pour afficher */ var BeforeTime = 1000;; /* Nombre de secondes avant que la bulle s'affiche */ var TimeToWait = 5000;; /* Nombre de secondes pendant lesquelles la bulle est affichée */ var MustShow = -1;; typeof BubbleFont = ObjFont;; typeof BubbleText = [S r1];; typeof BubbleSpacing = I;; var BubbleFontSize = 18;; var BubbleFontColor = 0;; var BubbleFontName = "Arial";; var BubbleStretch = 0;; var bgnd = 0;; typeof BubbleImage = ObjBitmap;; typeof NomImage = P;; var dx = 0;; var dy = -20;; var tx = 0;; var ty = 0;; var TranspCol = 0x0000FF;; var IsTransp = 0;; typeof TypeFic = fun [Chn P] ObjBitmap;; var lastTick = 0;; fun RechargeImage()=M3filter exec TypeFic with [_channel NomImage] "A0000ff46";; /* CustomLineExtr */ fun CustomLineExtr (s) = let strfind "\\n" s 0 -> pos in ( if pos == nil then s::nil else (substr s 0 pos)::( CustomLineExtr substr s (pos+3) ((strlen s)-pos-3) ) ) ;; /* Draw Multi Line Text on bitmap */ fun DrawMultiLineText (bmp, font, x, y, flag, fontColor, lines, spacing) = if lines == nil then 0 else let lines -> [first next] in ( _DRAWtext bmp font x y flag fontColor first; DrawMultiLineText bmp font x y+spacing flag fontColor next spacing ) ;; /******************************************************************************* Draw Multi Line Text on surface *******************************************************************************/ fun SDrawMultiLineText (surface, font, x, y, flag, fontColor, lines, spacing) = if lines == nil then 0 else let lines -> [first next] in ( _SDRAWtext surface font x y flag fontColor first; SDrawMultiLineText surface font x y+spacing flag fontColor next spacing ) ;; /*Affiche la bulle sur la bitmap de rendu*/ fun ShowBubble(objSurface)= let _GETcursorPos w3d.V3dwin -> [PosX PosY] in let getView3dSize w3d -> [winX winY] in if bgnd then { let PosX+dx -> Xpos in let PosY+dy -> Ypos in let if (Xpos < 0) then 0 else if (Xpos + tx) > winX then (winX - tx) else Xpos -> resultX in let if (Ypos < 0) then 0 else if (Ypos + ty) > winY then (winY - ty) else Ypos -> resultY in _Bitmap2Surface objSurface resultX resultY BubbleImage 0 0 tx ty make_rgb 0 0 255; nil; } else SDrawMultiLineText objSurface BubbleFont PosX+dx PosY+dy 0 BubbleFontColor BubbleText BubbleSpacing; 0 ;; /*Callback appelee pour chaque frame du rendu*/ fun BubblePostrender(ob, l)= if MustShow == -1 then nil else let _GETcursorPos w3d.V3dwin -> [PosX PosY] in let getView3dSize w3d -> [winX winY] in /* on sort de la fenêtre 3d */ if (MustShow == 1) && ((PosX > winX) || (PosX <0) || (PosY > winY) || (PosY <0)) then nil else let (_tickcount - BubbleCpt) -> diffCpt in { if diffCpt > TimeToWait then set MustShow = 0 else nil; if (MustShow == 1) && (diffCpt > BeforeTime) then /*Si une bulle doit être affichée*/ let l -> [objSurface [ width height]] in { ShowBubble objSurface; 0} else if MustShow == 0 then { /* image a détruire */ _DSbitmap BubbleImage; set BubbleImage = RechargeImage; set BubbleCpt = 0; set MustShow = -1; 0} else nil};; /* MaxStringListSize */ fun MaxStringListSize (font, list, w, h) = if list == nil then [w h] else let list -> [first next] in let _GETstringSize font first -> [ww hh] in let if ww>w then ww else w -> mw in let if hh>h then hh else h -> mh in MaxStringListSize font next mw mh ;; /* Draw bubble into buffer */ fun DrawBubble (text) = set BubbleText = CustomLineExtr text; let MaxStringListSize BubbleFont BubbleText 0 0 -> [bw spacing]in ( set BubbleSpacing = spacing; if bgnd then let RechargeImage -> bmp in let _GETbitmapSize bmp -> [w h] in ( if BubbleStretch then let [bw+6 6+spacing*(sizelist BubbleText)] -> [bw bh] in let _CRbitmap _channel bw bh -> bubbleBmp in let _SCPbitmap bubbleBmp 0 0 bw-1 bh-1 bmp 0 0 w-1 h-1 TranspCol -> bubbleBmp in ( set tx = bw; set ty = bh; _DSbitmap BubbleImage; _DSbitmap bmp; set BubbleImage = bubbleBmp ) else ( set tx = w; set ty = h; _DSbitmap BubbleImage; set BubbleImage = bmp ); DrawMultiLineText BubbleImage BubbleFont 3 3 TD_LEFT BubbleFontColor BubbleText BubbleSpacing ) else nil ); set MustShow = 1; set BubbleCpt = _tickcount ;; /*Callback correspondant à l'action ShowBubble*/ fun CBShowBubbleAction (Ob, cli, action, param, reply)= let strextr param -> l in let hd switchstr l "ref" -> text in let hd switchstr l "userParam" -> code in /*FIN MODIF PB*/ ( /* _fooS strcat "###code = " code; _fooS strcat "###ref = " text; */ if param != nil then if !strcmp code "0" then /* lien invisible ou avatar devant */ { /*_fooS "#### code 0";*/ if MustShow == 1 then set MustShow = 0 else nil; } else if (!strcmp code "1") then /* lien visible */ DrawBubble text else if !strcmp code "2" then /* avatar */ DrawBubble text else /* pas de lien */ { if MustShow then set MustShow = 0 else nil; } else { set BubbleCpt = 0; set MustShow = -1; } ) ;; fun CBfinDownload(file, o)= if file == nil then set bgnd = 0 else { set NomImage = _checkpack file; let _LDjpeg _channel NomImage -> background in { if background == nil then {set background = _LDbitmap _channel NomImage; set TypeFic = @_LDbitmap; } else set TypeFic = @_LDjpeg; set BubbleImage = background; let _GETbitmapSize BubbleImage -> [x y] in if x == nil then nil else {set tx = x; set ty = y}; if background == nil then set bgnd = 0 else set bgnd = 1; } }; let hd UgetParam ObUi o "Transparency" -> tr in if tr == nil then nil else {set TranspCol = atoi tr; set IsTransp = 1}; let hd UgetParam ObUi o "x" -> x in if x == nil then nil else set dx = atoi x; let hd UgetParam ObUi o "y" -> y in if y == nil then nil else set dy = atoi y; ObCbPostRenderPriority o @BubblePostrender 100; ObRegisterAction o strcat ObName o ".showBubble" @CBShowBubbleAction; 0 ;; fun newOb(o)= let hd UgetParam ObUi o "BeforeTime" -> Time in if Time==nil then nil else set BeforeTime = atoi Time; set TimeToWait = BeforeTime + let hd UgetParam o.uiOb "Time" -> Time in if Time == nil then TimeToWait else atoi Time; let hd UgetParam ObUi o "Font" -> fontName in let UgetParam ObUi o "FontColor" -> [R [G [B _]]] in let hd UgetParam ObUi o "FontSize" -> fontSize in let atoi hd UgetParam ObUi o "Stretch" -> bubbleStretch in let if (R == nil) || (G == nil) || (B == nil) then nil else make_rgb atoi R atoi G atoi B -> fontColor in ( if bubbleStretch==nil then nil else set BubbleStretch = bubbleStretch; if fontSize==nil then nil else set BubbleFontSize = atoi fontSize; if fontName==nil then nil else set BubbleFontName = fontName; if fontColor==nil then nil else set BubbleFontColor = fontColor; set BubbleFont = _CRfont _channel BubbleFontSize 0 0 BubbleFontName ); let hd UgetParam ObUi o "Background" -> file in _RSCdownload this file file (mkfun2 @CBfinDownload o) 1; 0;; fun IniPlug(file)= set class=getInfo strextr _getpack _checkpack file "name"; set BubbleFontColor = make_rgb 255 255 0; set TranspCol = make_rgb 0 0 255; PlugRegister class @newOb nil; 0;;