/* OSButton : One State Button */ /* les types de bouton */ var OSB_FULL =0b01010000;; var OSB_NOCREATION =0b00000000;; var OSB_AUTO =0b00010000;; var OSB_TEXT =0b00100000;; var OSB_MASK =0b01000000;; var OSB_OFF = 0;; var OSB_ON = 1;; var OSB_ON_OUT = 2;; struct OSButton=[ OSBObj2D : Obj2D, OSBbitmap : ObjBitmap, OSBflags : I, OSBtransp : I, OSBstate : I, OSBcoords : [[I I I I] r1], OSBclick : fun [OSButton I I I] OSButton ] MkOSButton;; /* internal */ fun autoBmp (channel, bmp, flags)= let _GETbitmapSize bmp -> [wref href] in if flags&OSB_MASK then let _CRbitmap _channel wref 3*href/2 -> newbmp in { /* copy the off state */ _CPbitmap16 newbmp 0 0 bmp 0 0 wref href/2 nil; /* create the on state */ _CPbitmap16 newbmp 2 2+href/2 bmp 0 0 wref-2 (href/2)-2 nil; _DRAWline newbmp 0 href/2 wref href/2 DRAW_SOLID 1 0x000000; _DRAWline newbmp 0 href/2 0 href DRAW_SOLID 1 0x000000; _DRAWline newbmp wref href/2 wref href DRAW_SOLID 1 0xffffff; _DRAWline newbmp wref href 0 href DRAW_SOLID 1 0xffffff; /* copy the mask */ _CPbitmap16 newbmp 0 href bmp 0 href/2 wref href/2 nil; [newbmp [0 0 wref (href/2)]::[0 href/2 wref href]::[0 href wref 3*href/2]::nil] } else let _CRbitmap _channel wref 2*href -> newbmp in { /* copy the off state */ _CPbitmap16 newbmp 0 0 bmp 0 0 wref href/2 nil; /* create the on state */ _CPbitmap16 newbmp 2 2+href/2 bmp 0 0 wref-2 (href/2)-2 nil; _DRAWline newbmp 0 href/2 wref href/2 DRAW_SOLID 1 0x000000; _DRAWline newbmp 0 href/2 0 href DRAW_SOLID 1 0x000000; _DRAWline newbmp wref href/2 wref href DRAW_SOLID 1 0xffffff; _DRAWline newbmp wref href 0 href DRAW_SOLID 1 0xffffff; [newbmp [0 0 wref (href/2)]::[0 href/2 wref href]::nil] };; fun rectInBmp (button)= { nth_list button.OSBcoords if button.OSBstate==OSB_OFF then 0 else if button.OSBstate==OSB_ON then 1 else if button.OSBstate==OSB_ON_OUT then 0 else 0 };; /* Methode Paint*/ fun paintOSB (button)= let button.OSBObj2D -> obj in let rectInBmp button -> [x y w h] in _CPbitmap16 obj.O2DParentContainer.CoWorkingBitmap obj.O2Dx obj.O2Dy button.OSBbitmap x y w h button.OSBtransp; 1;; /* Methode Paint Part */ fun paintPartOSB (area, button)= if area!=nil then let button.OSBObj2D -> obj in let rectInBmp button -> [x y w h] in let SizeRectangle area -> [aw ah] in { _CPbitmap16 obj.O2DParentContainer.CoWorkingBitmap area.RctHG.iptX area.RctHG.iptY button.OSBbitmap x+(area.RctHG.iptX-obj.O2Dx) y+(area.RctHG.iptY-obj.O2Dy) aw ah button.OSBtransp; 1 } else 0;; /* Methode IsMouseOnObject */ fun isMouseOnOSB (mx, my, button)= let button.OSBObj2D -> obj in /* ------- il n'est pas normal d'avoir à traiter ici la question de savoir si la souris ------- est dans le rectangle de l'objet !!!! */ if IsPointInRectangle (MkInt2DPoint [mx my]) (O2D_RectangleIncludingObject obj) then if button.OSBflags & OSB_MASK then let nth_list button.OSBcoords 3 -> [x y w h] in (_GETpixel16 button.OSBbitmap (x+mx-obj.O2Dx) (y+my-obj.O2Dy)) != 0 else let rectInBmp button -> [x y w h] in (button.OSBtransp==nil) || ((_GETpixel16 button.OSBbitmap (x+mx-obj.O2Dx) (y+my-obj.O2Dy)) != button.OSBtransp) else 0 /* la souris n'est pas sur l'objet */ ;; /* Methode Move Out Object*/ fun moveOutOSB (mx, my, mb, button)= { set button.OSBstate=if button.OSBstate==OSB_ON then OSB_ON_OUT else OSB_OFF; O2D_RedrawArea button.OSBObj2D.O2DParentContainer (O2D_RectangleIncludingObject button.OSBObj2D) 1; 1 };; /* Methode Move In Object*/ fun moveInOSB (mx, my, mb, button)= if button.OSBstate==OSB_ON_OUT then set button.OSBstate=OSB_ON else set button.OSBstate=OSB_OFF; O2D_RedrawArea button.OSBObj2D.O2DParentContainer (O2D_RectangleIncludingObject button.OSBObj2D) 1; 1;; /* Methode Click In */ fun clickInOSB (mx, my, mb, button)= if mb==1 then { set button.OSBstate=OSB_ON; O2D_RedrawArea button.OSBObj2D.O2DParentContainer (O2D_RectangleIncludingObject button.OSBObj2D) 1; } else nil; 1;; /* Methode UnClick In */ fun unClickInOSB (mx, my, mb, button)= { if mb==1 then { set button.OSBstate=OSB_OFF; O2D_RedrawArea button.OSBObj2D.O2DParentContainer (O2D_RectangleIncludingObject button.OSBObj2D) 1; exec button.OSBclick with [button mx my mb]; } else nil; 1 };; /* Methode UnClick Out */ fun unClickOutOSB (mx, my, mb, button)= { set button.OSBstate=OSB_OFF; O2D_RedrawArea button.OSBObj2D.O2DParentContainer (O2D_RectangleIncludingObject button.OSBObj2D) 1; 1 };; /* Methode destruction object */ fun DsOSB (button)= { _DSbitmap button.OSBbitmap; set button.OSBcoords=nil; set button.OSBflags=nil; set button.OSBstate=nil; set button.OSBtransp=nil; set button.OSBclick=nil; 1 };; /*************************************************************************************/ /* One State Button */ /*************************************************************************************/ /* constructeur */ fun OSB_newOSButton (channel, container, father, coord, flags, name, pack, coordt)= if container!=nil then let _LDbitmap channel pack -> bmp in if bmp==nil then nil else let if flags&OSB_AUTO then autoBmp channel bmp flags else let _GETbitmapSize bmp -> [wref href] in [ bmp if flags&OSB_MASK then [0 0 wref (href/2)]::[0 href/2 wref href]::[0 href wref 3*href/2]::nil else [0 0 wref (href/2)]::[0 href/2 wref href]::nil ] -> [bmpg l] in let _GETbitmapSize bmpg -> [rw rh] in let O2D_NewObject container father name rw rh/sizelist l coord flags -> obj in let coordt -> [xt yt] in let MkOSButton [obj bmpg flags (if coordt != nil then _GETpixel16 bmpg xt yt else nil) OSB_OFF l nil] -> button in { /* les methodes */ O2D_CBDsObject obj button @DsOSB; O2D_CBPaint obj button @paintOSB; O2D_CBPaintPart obj button @paintPartOSB; O2D_CBIsMouseOnDisplayObject obj button @isMouseOnOSB; O2D_CBCursorMoveOut obj button @moveOutOSB; O2D_CBCursorMoveIn obj button @moveInOSB; O2D_CBObjectClickIn obj button @clickInOSB; O2D_CBObjectUnClickIn obj button @unClickInOSB; O2D_CBObjectUnClickOut obj button @unClickOutOSB; button } else nil;; fun OSB_Destroy (button)= O2D_DelObject button.OSBObj2D; 1;; fun OSB_CBclick (button, func, param)= if button==nil then nil else set button.OSBclick = mkfun5 func param;; fun OSB_GetObject (button)= button.OSBObj2D;; fun OSB_ChangeDisplayFlags (button, NewFlag, RedrawFlag, RepaintFlag)= O2D_ChangeObjDisplayFlag button.OSBObj2D NewFlag RedrawFlag RepaintFlag; button;; fun OSB_ChangeCoordinates (button, NewCoordinates, RedrawFlag, RepaintFlag)= O2D_ChangeObjCoordinates button.OSBObj2D NewCoordinates RedrawFlag RepaintFlag; button;; fun OSB_GetCoordinates (button)= O2D_GetObjCoordinates button.OSBObj2D;; fun OSB_GetGraphicalState (button)= let button.OSBObj2D -> obj in let rectInBmp button -> [x y w h] in [x y w h button.OSBtransp];;