/* 2-states button */ var TSB_OFF = 0;; var TSB_ON = 1;; var TSB_MASK = 0b00001;; var TSB_TRANSPARENCY = 0b00010;; struct TSButton=[ TSBObj2D:Obj2D, TSBbitmap:ObjBitmap, TSBbitmapCoord:[[I I] r1], TSBflags:I, TSBstate:I, TSBClickReflex:fun [TSButton I I I] TSButton, TSBCursorMoveInReflex:fun [TSButton I I I] TSButton, TSBCursorMoveOutReflex:fun [TSButton I I I] TSButton ] MkTSButton;; /* le type de creation de bouton */ var NO_CREATION=0;; var AUTO_CREATION=1;; /* presence de texte */ var TEXT_BUTTON=1;; var NO_TEXT_BUTTON=0;; /* les differents etats du bouton */ var STATE_OFF_UNDISPLAYED=0;; var STATE_OFF=1;; var STATE_OFF_PUSHED=2;; var STATE_OFF_PUSHED_OUT=3;; var RECORD_MASK=0;; var RECORD_STATE=1;; var RECORD_TRANSPARENCY=2;; struct RollOverButtonType=[ ROBObj2D:Obj2D, ROBbitmap:ObjBitmap, ROBlistcoordinatesinbitmap:[[I I] r1], ROBmask:I, ROBstate:I, ROBtransparency:I, ROBClickReflex:fun [RollOverButtonType I I I] RollOverButtonType, ROBCursorMoveInReflex:fun [RollOverButtonType I I I] RollOverButtonType, ROBCursorMoveOutReflex:fun [RollOverButtonType I I I] RollOverButtonType ] MkRollOverButtonType;; /****************************************************************************************************************************/ /* Fonctions Intrinseques au RollOverButton */ /****************************************************************************************************************************/ fun CreateRollOverBitmapsFromBmp(Channel,BmpRef,ListCoordinatesInRef,IsThereAMask,TransparencyXcoord,TransparencyYcoord,HighLightUdpCoeff,HighLightOffCoeff)= { let sizelist ListCoordinatesInRef -> taillelist in if (taillelist==1)&&(IsThereAMask) then { FatalError "Cowin AutoCreation""Creation failed because there is the mask is not defined"; nil } else let _GETbitmapSize BmpRef -> [XSizeRef YSizeRef] in let (if taillelist==1 then [XSizeRef YSizeRef] else [XSizeRef YSizeRef/2]) -> [xsize ysize] in let hd ListCoordinatesInRef -> [xBtn yBtn] in let hd tl ListCoordinatesInRef -> [xMask yMask] in let TransparentColor BmpRef TransparencyXcoord TransparencyYcoord -> Transparency in let _CRbitmap _channel xsize (if taillelist==1 then ysize*3 else ysize*4) -> BmpRes in let [ (_CPbitmap16 (_CRbitmap Channel xsize ysize) 0 0 BmpRef xBtn yBtn xsize ysize nil) (_CPbitmap16 (_CRbitmap Channel xsize ysize) 0 0 BmpRef xBtn yBtn xsize ysize nil) nil (if taillelist==1 then (_FILLbitmap (_CRbitmap Channel xsize ysize) 0xFFFFFF) else (_CPbitmap16 (_CRbitmap Channel xsize ysize) 0 0 BmpRef xMask yMask xsize ysize nil) ) (_FILLbitmap (_CRbitmap Channel xsize ysize) Transparency) ] -> [UdpBmp OffBmp PushedBmp MaskBmp Transp] in { /* udp bitmap */ set UdpBmp=_MULbitmap UdpBmp 0 0 xsize ysize HighLightUdpCoeff HighLightUdpCoeff HighLightUdpCoeff nil; set Transp=_SPLUSbitmap Transp 0 0 xsize ysize MaskBmp 0 0; set UdpBmp=_CPbitmap16 UdpBmp 0 0 Transp 0 0 xsize ysize 0xFFFFFF; set Transp=_FILLbitmap Transp Transparency; /* off bitmap */ set OffBmp=_MULbitmap OffBmp 0 0 xsize ysize HighLightOffCoeff HighLightOffCoeff HighLightOffCoeff nil; set Transp=_SPLUSbitmap Transp 0 0 xsize ysize MaskBmp 0 0; set OffBmp=_CPbitmap16 OffBmp 0 0 Transp 0 0 xsize ysize 0xFFFFFF; /* pushed bitmap */ set PushedBmp=(_CPbitmap16 (_FILLbitmap (_CRbitmap _channel xsize ysize) Transparency) 1 1 OffBmp 0 0 xsize ysize nil); /* bitmap res */ set BmpRes=_CPbitmap16 BmpRes 0 0 UdpBmp 0 0 xsize ysize nil; set BmpRes=_CPbitmap16 BmpRes 0 ysize OffBmp 0 0 xsize ysize nil; set BmpRes=_CPbitmap16 BmpRes 0 2*ysize PushedBmp 0 0 xsize ysize nil; if taillelist==2 then set BmpRes=_CPbitmap16 BmpRes 0 3*ysize MaskBmp 0 0 xsize ysize nil else nil; /* destruction des bitmaps temporaires */ _DSbitmap UdpBmp; _DSbitmap OffBmp; _DSbitmap PushedBmp; _DSbitmap Transp; _DSbitmap MaskBmp; [ BmpRes ([0 0]::[0 ysize]::[0 2*ysize]::(if taillelist==2 then [0 3*ysize]::nil else nil) ) ]; }; };; fun RollOverBitmapCoordinatesToUse(rollover)= { nth_list rollover.ROBlistcoordinatesinbitmap ( if (rollover.ROBstate==STATE_OFF_UNDISPLAYED) then 0 else if (rollover.ROBstate==STATE_OFF) then 1 else if (rollover.ROBstate==STATE_OFF_PUSHED) then 2 else if (rollover.ROBstate==STATE_OFF_PUSHED_OUT) then 1 else 0 ) };; /* Methode Paint*/ fun PaintRollOver(rollover)= { let rollover.ROBObj2D -> obj in let RollOverBitmapCoordinatesToUse rollover -> [XInGlobal YInGlobal] in _CPbitmap16 obj.O2DParentContainer.CoWorkingBitmap obj.O2Dx obj.O2Dy rollover.ROBbitmap XInGlobal YInGlobal obj.O2Dw obj.O2Dh rollover.ROBtransparency; 1 };; /* Methode Paint Part */ fun PaintPartOfRollOver(area,rollover)= { if area!=nil then { let rollover.ROBObj2D -> obj in let RollOverBitmapCoordinatesToUse rollover -> [XInGlobal YInGlobal] in let SizeRectangle area -> [areaX areaY] in _CPbitmap16 obj.O2DParentContainer.CoWorkingBitmap area.RctHG.iptX area.RctHG.iptY rollover.ROBbitmap XInGlobal+(area.RctHG.iptX-obj.O2Dx) YInGlobal+(area.RctHG.iptY-obj.O2Dy) areaX areaY rollover.ROBtransparency; 1 } else 0; };; /* Methode IsMouseOnObject */ fun IsMouseOnRollOver(MouseCol,MouseLgn,rollover)= { let rollover.ROBObj2D -> obj in if IsPointInRectangle (MkInt2DPoint [MouseCol MouseLgn]) (O2D_RectangleIncludingObject obj) then { if rollover.ROBmask then { let nth_list rollover.ROBlistcoordinatesinbitmap 3 -> [XInGlobal YInGlobal] in ((_GETpixel16 rollover.ROBbitmap (XInGlobal+MouseCol-obj.O2Dx) (YInGlobal+MouseLgn-obj.O2Dy)) !=0) } else { let RollOverBitmapCoordinatesToUse rollover -> [XInGlobal YInGlobal] in (rollover.ROBtransparency==nil) ||((_GETpixel16 rollover.ROBbitmap (XInGlobal+MouseCol-obj.O2Dx) (YInGlobal+MouseLgn-obj.O2Dy)) !=rollover.ROBtransparency) } } else 0; /* la souris n'est pas sur l'objet */ };; /* Methode Move Out Object*/ fun MoveOutRollOver(mousecol,mouselgn,mousebuttons,rollover)= { set rollover.ROBstate=STATE_OFF_UNDISPLAYED; let rollover.ROBObj2D -> obj in { O2D_RedrawArea obj.O2DParentContainer (O2D_RectangleIncludingObject obj) 1; exec rollover.ROBCursorMoveOutReflex with [rollover mousecol mouselgn mousebuttons]; }; 1 };; /* Methode Move In Object*/ fun MoveInRollOver(mousecol,mouselgn,mousebuttons,rollover)= { if rollover.ROBstate==STATE_OFF then set rollover.ROBstate=STATE_OFF_UNDISPLAYED else set rollover.ROBstate=STATE_OFF; let rollover.ROBObj2D -> obj in { O2D_RedrawArea obj.O2DParentContainer (O2D_RectangleIncludingObject obj) 1; exec rollover.ROBCursorMoveInReflex with [rollover mousecol mouselgn mousebuttons]; }; 1 };; /* Methode Move Out object with button pushed */ fun MoveOutRollOverWithBtnClicked(mousecol,mouselgn,mousebuttons,rollover)= { let rollover.ROBObj2D -> obj in if rollover.ROBstate==STATE_OFF then { set obj.O2DParentContainer.CoHandledObject=nil; nil } else if rollover.ROBstate==STATE_OFF_PUSHED then { set rollover.ROBstate=STATE_OFF_PUSHED_OUT; O2D_RedrawArea obj.O2DParentContainer (O2D_RectangleIncludingObject obj) 1 } else nil; 1 };; /* Methode Move In object with button pushed */ fun MoveInRollOverWithBtnClicked(mousecol,mouselgn,mousebuttons,rollover)= { if rollover.ROBstate==STATE_OFF_PUSHED_OUT then { /* Make the button Pushed */ set rollover.ROBstate=STATE_OFF_PUSHED; let rollover.ROBObj2D -> obj in O2D_RedrawArea obj.O2DParentContainer (O2D_RectangleIncludingObject obj) 1 } else nil;/* The button should not be redrawn */ 1 };; /* Methode Click Out */ fun ClickOutRollOver(mousecol,mouselgn,mousebuttons,rollover)= { let rollover.ROBObj2D -> obj in { set obj.O2DParentContainer.CoUserMoveIsAllowed=0; if rollover.ROBstate==STATE_OFF then { set obj.O2DParentContainer.CoHandledObject=nil; nil } else if rollover.ROBstate==STATE_OFF_PUSHED then { set rollover.ROBstate=STATE_OFF_PUSHED_OUT; O2D_RedrawArea obj.O2DParentContainer (O2D_RectangleIncludingObject obj) 1 } else nil; }; 1 };; /* Methode Click In */ fun ClickInRollOver(mousecol,mouselgn,mousebuttons,rollover)= { if mousebuttons==1 then { set rollover.ROBstate=STATE_OFF_PUSHED; let rollover.ROBObj2D -> obj in O2D_RedrawArea obj.O2DParentContainer (O2D_RectangleIncludingObject obj) 1; } else { exec rollover.ROBClickReflex with [rollover mousecol mouselgn mousebuttons]; nil }; 1 };; /* Methode UnClick In */ fun UnClickInRollOver(mousecol,mouselgn,mousebuttons,rollover)= { if mousebuttons==1 then { set rollover.ROBstate=STATE_OFF; let rollover.ROBObj2D -> obj in O2D_RedrawArea obj.O2DParentContainer (O2D_RectangleIncludingObject obj) 1; exec rollover.ROBClickReflex with [rollover mousecol mouselgn mousebuttons]; } else nil; 1 };; /* Methode UnClick Out */ fun UnClickOutRollOver(mousecol,mouselgn,mousebuttons,rollover)= { set rollover.ROBstate=STATE_OFF_UNDISPLAYED; let rollover.ROBObj2D -> obj in O2D_RedrawArea obj.O2DParentContainer (O2D_RectangleIncludingObject obj) 1; 1 };; fun IsUserClickAllowedInRollOver()= { 0 };; fun IsUserUnClickAllowedInRollOver()= { 0 };; /* Methode destruction object */ fun DsRollOverButton(rollover)= { _DSbitmap rollover.ROBbitmap; set rollover.ROBlistcoordinatesinbitmap=nil; set rollover.ROBmask=nil; set rollover.ROBstate=nil; set rollover.ROBtransparency=nil; set rollover.ROBClickReflex=nil; set rollover.ROBCursorMoveInReflex=nil; set rollover.ROBCursorMoveOutReflex=nil; 1 };; /**************************************************************************************************************************/ /* Fonctions externes du RollOverButton */ /**************************************************************************************************************************/ /* constructeur */ fun TSB_new (channel, container, father, x, y, w, h, flags, name)= if Container!=nil then let O2D_NewObject container father name w h [x y] flags -> obj in let MkTSButton [Obj nil nil flags TSB_OFF nil nil nil] -> button in { /* les methodes */ O2D_CBDsObject Obj button @DsTSButton; O2D_CBPaint Obj button @PaintTSButton; O2D_CBPaintPart Obj button @PaintPartOfTSButton; O2D_CBIsMouseOnDisplayObject Obj button @IsMouseOnTSButton; O2D_CBUserClickAllowed Obj button @IsUserClickAllowedInTSButton; O2D_CBUserUnClickAllowed Obj button @IsUserUnClickAllowedInTSButton; O2D_CBCursorMoveOut Obj button @MoveOutTSButton; O2D_CBCursorMoveIn Obj button @MoveInTSButton; O2D_CBCursorMoveInWithButtonPush Obj button @MoveInTSButtonWithBtnClicked; O2D_CBCursorMoveOutWithButtonPush Obj button @MoveOutTSButtonWithBtnClicked; O2D_CBObjectClickIn Obj button @ClickInTSButton; O2D_CBObjectClickOut Obj button @ClickOutTSButton; /* inutile !!!! */ O2D_CBObjectUnClickIn Obj button @UnClickInTSButton; O2D_CBObjectUnClickOut Obj button @UnClickOutTSButton; /* inutile !!!! */ rollover }; else { /* le container est vide */ FatalError "RollOver Creation impossible" "Container is nil"; nil } ;; fun TSBsetRes (tsb, pack, ListCoordinatesInBitmap, TransparencyCoords)= let (if TransparencyCoords==nil then [(-1) (-1)] else TransparencyCoords) -> [TransparencyXCoord TransparencyYCoord] in let RecuperationRessource Channel Res -> bmp in let getCoordInBitmaps Channel bmp ListCoordinatesInBitmap IsThereAMask TransparencyXCoord TransparencyYCoord -> [bmpglobale listecoords] in let _GETbitmapSize bmpglobale -> [xsize ysize] in 0;; fun ROB_DelRollOver(rollover)= { O2D_DelObject rollover.ROBObj2D; rollover };; fun ROB_SetClickReflex(rollover,ReflexeClick,ParamClick)= if rollover==nil then nil else set rollover.ROBClickReflex=mkfun5 ReflexeClick ParamClick;; fun ROB_SetCursorMoveInReflex(rollover,ReflexeCursorMoveIn,ParamCursorMoveIn)= if rollover==nil then nil else set rollover.ROBCursorMoveInReflex=mkfun5 ReflexeCursorMoveIn ParamCursorMoveIn;; fun ROB_SetCursorMoveOutReflex(rollover,ReflexeCursorMoveOut,ParamCursorMoveOut)= if rollover==nil then nil else set rollover.ROBCursorMoveOutReflex=mkfun5 ReflexeCursorMoveOut ParamCursorMoveOut;; fun ROB_GetObject(rollover)= rollover.ROBObj2D;; fun ROB_ChangeDisplayFlags(rollover,NewFlag,RedrawFlag,RepaintFlag)= O2D_ChangeObjDisplayFlag rollover.ROBObj2D NewFlag RedrawFlag RepaintFlag; rollover;; fun ROB_ChangeCoordinates(rollover,NewCoordinates,RedrawFlag,RepaintFlag)= O2D_ChangeObjCoordinates rollover.ROBObj2D NewCoordinates RedrawFlag RepaintFlag; rollover;; fun ROB_GetCoordinates(rollover)= O2D_GetObjCoordinates rollover.ROBObj2D;;