/**************************************************************************************/ /* Two-States Button written by Marc Bariley */ /**************************************************************************************/ /* TSB_New */ /* TSB_Del */ /* TSB_SetClickReflex */ /* TSB_SetCursorMoveInReflex */ /* TSB_SetCursorMoveOutReflex */ /* TSB_GetObject */ /* TSB_ChangeDisplayFlags */ /* TSB_ChangeCoordinates */ /* TSB_GetCoordinates */ /**************************************************************************************/ /* librairy used: _jint2D _jobj2dlib.pkg */ /**************************************************************************************/ /* var TSB_MASK = 0b00001000000000;; var TSB_TRANSPARENCY = 0b00010000000000;; struct TSButton=[ TSBObj2D:Obj2D, TSBbitmap:ObjBitmap, TSBflags:I, TSBstate:I, TSBtransp : I, TSBClickReflex:fun [TSButton I I I I] TSButton, TSBCursorMoveInReflex:fun [TSButton I I I] TSButton, TSBCursorMoveOutReflex:fun [TSButton I I I] TSButton, TSBdestroyReflex : fun [] I ] MkTSButton;; */ /* les differents etats du bouton */ var TSB_STATE_OFF = 0b000001;; var TSB_STATE_RO = 0b000010;; var TSB_STATE_PUSHED = 0b000100;; /*********************************************************************************/ /* Fonctions Intrinseques au bouton deux états */ /*********************************************************************************/ /* renvoie les coordonnees de l'etat du bouton dans la bitmap globale */ fun rectInBmpTSB (button)= let button.TSBObj2D -> obj in let obj.O2Dw -> w in let obj.O2Dh -> h in if button.TSBstate & TSB_STATE_OFF then if button.TSBstate & TSB_STATE_RO then [0 h w h] else if button.TSBstate & TSB_STATE_PUSHED then [0 2*h w h] else [0 0 w h] else if button.TSBstate & TSB_STATE_RO then [0 3*h w h] else if button.TSBstate & TSB_STATE_PUSHED then [0 2*h w h] else [0 4*h w h] ;; /* Methode Paint*/ fun PaintTSB (button)= let rectInBmpTSB button -> [xg yg wg hg] in [button.TSBbitmap xg yg wg hg button.TSBtransp];; /* Methode Paint Part */ fun PaintPartOfTSB (area, button)= let rectInBmpTSB 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.TSBbitmap rect.RctHG.iptX rect.RctHG.iptY rw rh button.TSBtransp ] ;; /* Methode IsMouseOnObject */ fun IsMouseOnTSB (mx, my, button)= let button.TSBObj2D -> obj in if button.TSBflags & TSB_MASK then let _GETbitmapSize button.TSBbitmap -> [wb hb] in (_GETpixel16 button.TSBbitmap (mx-obj.O2Dx) (hb-obj.O2Dh+my-obj.O2Dy)) != 0 else (button.TSBtransp==nil) || let rectInBmpTSB button -> [xg yg wg hg] in (_GETpixel16 button.TSBbitmap (xg+mx-obj.O2Dx) (yg+my-obj.O2Dy)) != button.TSBtransp ;; /* Methode Move Out Object*/ fun MoveOutTSB (mx, my, mb, button)= set button.TSBstate = button.TSBstate &~TSB_STATE_PUSHED &~ TSB_STATE_RO; let button.TSBObj2D -> obj in { O2D_RedrawArea obj.O2DParentContainer (O2D_RectangleIncludingObject obj) 1; exec button.TSBCursorMoveOutReflex with [button mx my mb]; }; 1;; /* Methode Move In Object*/ fun MoveInTSB (mx, my, mb, button)= set button.TSBstate = button.TSBstate | TSB_STATE_RO; let button.TSBObj2D -> obj in { O2D_RedrawArea obj.O2DParentContainer (O2D_RectangleIncludingObject obj) 1; exec button.TSBCursorMoveInReflex with [button mx my mb]; }; 1;; /* Methode Move Out object with button pushed */ fun MoveOutPushedTSB (mx, my, mb, button)= set button.TSBstate = button.TSBstate & ~TSB_STATE_PUSHED; let button.TSBObj2D -> obj in O2D_RedrawArea obj.O2DParentContainer (O2D_RectangleIncludingObject obj) 1; 1;; /* Methode Move In object with button pushed */ fun MoveInPushedTSB (mx, my, mb, button)= set button.TSBstate = button.TSBstate | TSB_STATE_PUSHED; let button.TSBObj2D -> obj in O2D_RedrawArea obj.O2DParentContainer (O2D_RectangleIncludingObject obj) 1; 1;; /* Methode Click Out */ fun ClickOutTSB (mx, my, mb, button)= set button.TSBstate = button.TSBstate &~ TSB_STATE_PUSHED &~TSB_STATE_RO; let button.TSBObj2D -> obj in O2D_RedrawArea obj.O2DParentContainer (O2D_RectangleIncludingObject obj) 1; 1;; /* Methode Click In */ fun ClickInTSB (mx, my, mb, button)= if mb==1 then { set button.TSBstate = button.TSBstate | TSB_STATE_PUSHED &~TSB_STATE_RO; let button.TSBObj2D -> obj in O2D_RedrawArea obj.O2DParentContainer (O2D_RectangleIncludingObject obj) 1; } else nil; 1;; /* Methode UnClick In */ fun UnClickInTSB (mx, my, mb, button)= if mb==1 then { if button.TSBstate & TSB_STATE_OFF then set button.TSBstate = button.TSBstate &~ TSB_STATE_OFF &~ TSB_STATE_PUSHED else set button.TSBstate = button.TSBstate | TSB_STATE_OFF &~ TSB_STATE_PUSHED; let button.TSBObj2D -> obj in O2D_RedrawArea obj.O2DParentContainer (O2D_RectangleIncludingObject obj) 1; exec button.TSBClickReflex with [button mx my mb button.TSBstate]; } else nil; 1;; /* Methode UnClick Out */ fun UnClickOutTSB (mx, my, mb, button)= set button.TSBstate = button.TSBstate &~TSB_STATE_PUSHED; let button.TSBObj2D -> obj in O2D_RedrawArea obj.O2DParentContainer (O2D_RectangleIncludingObject obj) 1; 1;; fun IsUserClickAllowedInTSB()= 0;; fun IsUserUnClickAllowedInTSB()= 0;; /* Methode destruction object */ fun DsTSB(button)= _DSbitmap button.TSBbitmap; set button.TSBbitmap=nil; set button.TSBClickReflex=nil; set button.TSBCursorMoveInReflex=nil; set button.TSBCursorMoveOutReflex=nil; exec button.TSBdestroyReflex with []; 1 ;; /**************************************************************************************/ /* Fonctions externes du bouton deux états */ /**************************************************************************************/ /* constructeur 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) flag : flag de construction (O2D_ENABLE, O2D_HIDE, TSB_MASK) tcoord : coordonnees de la couleur de transparence */ fun TSB_New (channel, cont, parent, coord, name, bmp, flag, tcoord)= if (channel==nil) || (cont==nil) || (coord==nil) || (name==nil) || (bmp==nil) then nil else let _GETbitmapSize bmp -> [w h] in let O2D_NewObject cont parent name w h/(if flag&TSB_MASK then 6 else 5) coord flag -> obj in if obj==nil then nil else let if tcoord != nil then let tcoord -> [tx ty] in _GETpixel16 bmp tx ty else nil -> transp in let MkTSButton [obj bmp flag TSB_STATE_OFF transp nil nil nil nil] -> button in { /* les methodes */ O2D_CBDsObject obj button @DsTSB; O2D_CBPaint obj button @PaintTSB; O2D_CBPaintPart obj button @PaintPartOfTSB; O2D_CBIsMouseOnDisplayObject obj button @IsMouseOnTSB; O2D_CBUserClickAllowed obj button @IsUserClickAllowedInTSB; O2D_CBUserUnClickAllowed obj button @IsUserUnClickAllowedInTSB; O2D_CBCursorMoveOut obj button @MoveOutTSB; O2D_CBCursorMoveIn obj button @MoveInTSB; O2D_CBCursorMoveInWithButtonPush obj button @MoveInPushedTSB; O2D_CBCursorMoveOutWithButtonPush obj button @MoveOutPushedTSB; O2D_CBObjectClickIn obj button @ClickInTSB; O2D_CBObjectClickOut obj button @ClickOutTSB; O2D_CBObjectUnClickIn obj button @UnClickInTSB; O2D_CBObjectUnClickOut obj button @UnClickOutTSB; button };; fun TSB_Del (button)= O2D_DelObject button.TSBObj2D; button;; fun TSB_SetClickReflex (button,ReflexeClick,ParamClick)= if button==nil then nil else set button.TSBClickReflex=mkfun6 ReflexeClick ParamClick; button;; fun TSB_SetCursorMoveInReflex (button, ReflexeCursorMoveIn,ParamCursorMoveIn)= if button==nil then nil else set button.TSBCursorMoveInReflex=mkfun5 ReflexeCursorMoveIn ParamCursorMoveIn; button;; fun TSB_SetCursorMoveOutReflex(button,ReflexeCursorMoveOut,ParamCursorMoveOut)= if button==nil then nil else set button.TSBCursorMoveOutReflex=mkfun5 ReflexeCursorMoveOut ParamCursorMoveOut; button;; fun TSB_SetDestroyReflex(button,Reflexe,Param)= if button==nil then nil else set button.TSBdestroyReflex=mkfun1 Reflexe Param; button;; fun TSB_GetObject(button)= button.TSBObj2D;; fun TSB_ChangeDisplayFlags (button, NewFlag,RedrawFlag,RepaintFlag)= O2D_ChangeObjDisplayFlag button.TSBObj2D NewFlag RedrawFlag RepaintFlag; button;; fun TSB_ChangeCoordinates(button,NewCoordinates,RedrawFlag,RepaintFlag)= O2D_ChangeObjCoordinates button.TSBObj2D NewCoordinates RedrawFlag RepaintFlag; button;; fun TSB_GetCoordinates(button)= O2D_GetObjCoordinates button.TSBObj2D;; fun TSB_SetState (button, state)= set button.TSBstate = state; let button.TSBObj2D -> obj in O2D_RedrawArea obj.O2DParentContainer (O2D_RectangleIncludingObject obj) 1; button;; fun TSB_GetState (button)= button.TSBstate;;