/**************************************************************************************/ /* Animated Button written by Marc Bariley */ /**************************************************************************************/ /* ANB_New */ /* ANB_Del */ /* ANB_SetClickReflex */ /* ANB_SetCursorMoveInReflex */ /* ANB_SetCursorMoveOutReflex */ /* ANB_GetObject */ /* ANB_ChangeDisplayFlags */ /* ANB_ChangeCoordinates */ /* ANB_GetCoordinates */ /* ANB_GetGraphicalState */ /**************************************************************************************/ /* librairy used: _jint2D _jobj2dlib.pkg */ /**************************************************************************************/ /* les differents etats du bouton */ var ANB_STATE_ON = 0b00001;; /* on */ var ANB_STATE_MOVING = 0b00010;; /* highlight */ var ANB_STATE_OFF = 0b00100;; /* off */ var ANB_STATE_FINISHING = 0b01000;; /* en train de terminer l'anim */ /************************************************************************************************************************/ /* Fonctions Internes du AnimButton */ /************************************************************************************************************************/ /* renvoie les coordonnees de l'etat du bouton dans la bitmap globale */ fun rectInBmpANB (button)= let button.ANBObj2D -> obj in [ button.ANBstep*button.ANBframeW if button.ANBstate == ANB_STATE_ON then obj.O2Dh else 0 obj.O2Dw obj.O2Dh ] ;; /* Methode Paint*/ fun PaintANB (button)= let rectInBmpANB button -> [xg yg wg hg] in [button.ANBbitmap xg yg wg hg button.ANBtransp];; /* Methode Paint Part */ fun PaintPartOfANB (area, button)= let rectInBmpANB button -> [xg yg wg hg] in let IntersectionRectangle MkRectangle2D [MkInt2DPoint[xg yg] MkInt2DPoint[xg+wg yg+hg]] MoveRectangleBy area MkInt2DPoint[xg yg] -> rect in let SizeRectangle rect -> [rw rh] in [ button.ANBbitmap rect.RctHG.iptX rect.RctHG.iptY rw rh button.ANBtransp ] ;; /* Methode IsMouseOnObject */ fun IsMouseOnANB (mx, my, button)= let button.ANBObj2D -> obj in if button.ANBflags & ANB_MASK then let _GETbitmapSize button.ANBbitmap -> [wb hb] in (_GETpixel16 button.ANBbitmap (wb-button.ANBframeW+mx-obj.O2Dx) (my-obj.O2Dy)) != 0 else (button.ANBtransp==nil) || let rectInBmpANB button -> [xg yg wg hg] in (_GETpixel16 button.ANBbitmap (xg+mx-obj.O2Dx) (yg+my-obj.O2Dy)) != button.ANBtransp ;; /* anim */ fun rflTimerANB (t, button)= if (button.ANBstep==(button.ANBframes-1)) && (button.ANBstate&ANB_STATE_FINISHING) then { _deltimer button.ANBtimer; set button.ANBtimer=nil; set button.ANBstate = ANB_STATE_OFF; set button.ANBstep = 0; button } else if button.ANBstate & ANB_STATE_ON then { _deltimer button.ANBtimer; set button.ANBtimer=nil; button } else { set button.ANBstep = mod (button.ANBstep+1) button.ANBframes; button }; O2D_RedrawObj button.ANBObj2D ;; /* Methode Move Out Object*/ fun MoveOutANB (mx, my, mb, button)= set button.ANBstate = ANB_STATE_FINISHING; exec button.ANBCursorMoveOutReflex with [button mx my mb]; 1;; /* Methode Move In Object*/ fun MoveInANB (mx, my, mb, button)= if button.ANBstate&ANB_STATE_FINISHING then nil else if button.ANBtimer == nil then set button.ANBtimer = _rfltimer _starttimer _channel button.ANBrate @rflTimerANB button else nil; set button.ANBstate = ANB_STATE_MOVING; exec button.ANBCursorMoveInReflex with [button mx my mb]; 1;; /* Methode Move Out object with button pushed */ fun MoveOutPushedANB (mx, my, mb, button)= set button.ANBstate = ANB_STATE_OFF; _deltimer button.ANBtimer; set button.ANBtimer=nil; let button.ANBObj2D -> obj in O2D_RedrawArea obj.O2DParentContainer (O2D_RectangleIncludingObject obj) 1; 1;; /* Methode Move In object with button pushed */ fun MoveInPushedANB (mx, my, mb, button)= set button.ANBstate = ANB_STATE_ON; let button.ANBObj2D -> obj in O2D_RedrawArea obj.O2DParentContainer (O2D_RectangleIncludingObject obj) 1; 1;; /* Methode Click In */ fun ClickInANB (mx, my, mb, button)= _SETfocus button.ANBObj2D.O2DParentContainer.CoObjWin; if mb==1 then { set button.ANBstate = ANB_STATE_ON; let button.ANBObj2D -> obj in O2D_RedrawArea obj.O2DParentContainer (O2D_RectangleIncludingObject obj) 1; } else nil; 1;; /* Methode UnClick In */ fun UnClickInANB (mx, my, mb, button)= if mb==1 then { set button.ANBstate = ANB_STATE_MOVING; if button.ANBtimer==nil then set button.ANBtimer = _rfltimer _starttimer _channel button.ANBrate @rflTimerANB button else nil; exec button.ANBClickReflex with [button mx my mb]; } else nil; 1;; /* Methode UnClick Out */ fun UnClickOutANB (mx, my, mb, button)= set button.ANBstate = ANB_STATE_FINISHING; if button.ANBtimer==nil then set button.ANBtimer = _rfltimer _starttimer _channel button.ANBrate @rflTimerANB button else nil; 1;; /* Methode ClickOut */ fun ClickOutANB (mx, my, mb, button)= if button.ANBstate & ANB_STATE_FINISHING then nil else if button.ANBstep==0 then { set button.ANBstate = ANB_STATE_OFF; _deltimer button.ANBtimer; set button.ANBtimer=nil; } else { set button.ANBstate = ANB_STATE_FINISHING; if button.ANBtimer==nil then set button.ANBtimer = _rfltimer _starttimer _channel button.ANBrate @rflTimerANB button else nil; }; 1;; fun IsUserClickAllowedInANB()= 0;; fun IsUserUnClickAllowedInANB()= 0;; /* Methode destruction object */ fun DsANB (button)= _deltimer button.ANBtimer; _DSbitmap button.ANBbitmap; set button.ANBbitmap=nil; set button.ANBtimer = nil; set button.ANBClickReflex = nil; set button.ANBCursorMoveInReflex = nil; set button.ANBCursorMoveOutReflex = nil; 1;; /************************************************************************************/ /* Fonctions externes du AnimButton */ /************************************************************************************/ /* Constructeur du AnimButton channel : canal de construction cont : container auquel appartient le rollover parent : l'objet pere coord : coordonnees de l'objet par rapport au pere name : nom de l'objet bmp : ressource pour construire l'objet (bitmap) nframes : nombre de frames dans la bitmap de reference, sans mask tcoord : coordonnees de la couleur de transparence flag : flag de construction (O2D_ENABLE, O2D_DISABLE, O2D_HIDE, ANB_MASK) rate : espace de temps entre chaque pas de l'anim en ms */ fun ANB_New (channel, cont, parent, coord, name, bmp, nframes, tcoord, flag, rate)= if (channel==nil) || (cont==nil) || (coord==nil) || (name==nil) || (bmp==nil) || (nframes==nil) || (rate==nil) then nil else let _GETbitmapSize bmp -> [w h] in let w/(if flag&ANB_MASK then nframes+1 else nframes) -> framew in let O2D_NewObject cont parent name framew h/2 coord flag -> obj in if obj==nil then nil else let MkAnimButton [ obj bmp nframes framew if tcoord==nil then nil else let tcoord -> [tx ty] in _GETpixel16 bmp tx ty flag ANB_STATE_OFF 0 rate nil nil nil nil] -> button in { /* les methodes */ O2D_CBDsObject obj button @DsANB; O2D_CBPaint obj button @PaintANB; O2D_CBPaintPart obj button @PaintPartOfANB; O2D_CBIsMouseOnDisplayObject obj button @IsMouseOnANB; O2D_CBUserClickAllowed obj button @IsUserClickAllowedInANB; O2D_CBUserUnClickAllowed obj button @IsUserUnClickAllowedInANB; O2D_CBCursorMoveOut obj button @MoveOutANB; O2D_CBCursorMoveIn obj button @MoveInANB; O2D_CBObjectClickIn obj button @ClickInANB; O2D_CBObjectClickOut obj button @ClickOutANB; O2D_CBCursorMoveInWithButtonPush obj button @MoveInPushedANB; O2D_CBCursorMoveOutWithButtonPush obj button @MoveOutPushedANB; O2D_CBObjectUnClickIn obj button @UnClickInANB; O2D_CBObjectUnClickOut obj button @UnClickOutANB; button };; fun ANB_Del (button)= O2D_DelObject button.ANBObj2D; button;; fun ANB_SetClickReflex (button, func, param)= if button==nil then nil else set button.ANBClickReflex = mkfun5 func param; button;; fun ANB_SetCursorMoveInReflex (button, func, param)= if button==nil then nil else set button.ANBCursorMoveInReflex = mkfun5 func param; button;; fun ANB_SetCursorMoveOutReflex (button, func, param)= if button==nil then nil else set button.ANBCursorMoveOutReflex = mkfun5 func param; button;; fun ANB_GetObject (button)= button.ANBObj2D;; fun ANB_ChangeDisplayFlags (button, newFlag, redrawFlag, repaintFlag)= if newFlag & O2D_HIDE then { _deltimer button.ANBtimer; set button.ANBtimer=nil; set button.ANBstate = ANB_STATE_OFF; set button.ANBstep = 0; } else nil; O2D_ChangeObjDisplayFlag button.ANBObj2D newFlag redrawFlag repaintFlag; button;; fun ANB_GetDisplayFlags (button)= button.ANBObj2D.O2DFlags;; fun ANB_ChangeCoordinates (button, newCoords, redrawFlag, repaintFlag)= O2D_ChangeObjCoordinates button.ANBObj2D newCoords redrawFlag repaintFlag; button;; fun ANB_GetCoordinates (button)= O2D_GetObjCoordinates button.ANBObj2D;; fun ANB_GetGraphicalState (button)= let rectInBmpANB button -> [xg yg wg hg] in [button.ANBbitmap xg yg wg hg button.ANBtransp];;