/**************************************************************************************/ /* Rectangle written by Jocelyn DUMAY */ /**************************************************************************************/ /* RECT_New */ /* RECT_Del */ /* ANB_SetClickReflex */ /* ANB_SetCursorMoveInReflex */ /* ANB_SetCursorMoveOutReflex */ /* ANB_GetObject */ /* ANB_ChangeDisplayFlags */ /* ANB_ChangeCoordinates */ /* ANB_GetCoordinates */ /* ANB_GetGraphicalState */ /**************************************************************************************/ /* librairy used: _jint2D _jobj2dlib.pkg */ /**************************************************************************************/ /* les differents types de traits */ var STYLE_NORMAL=1;; /*_______*/ var STYLE_POINTILLE_1=2;; /*-------*/ var STYLE_POINTILLE_2=3;; /*.......*/ var STYLE_POINTILLE_3=4;; /*-.-.-.-*/ var STYLE_POINTILLE_4=5;; /*-..-..-..*/ /* Coin Arrondis ou non*/ var COIN_NORMAL=0;; var COIN_ARRONDI=1;; /* Rectangle RECTObj2D:objet 2D associé RECTBitmap:bitmap representant la ligne RECTLineColor:couleur de la ligne RECTStyleTrait:type du trait RECTCoinsArrondis:rectangle a coins arrondis ou non RECTTransparency:couleur de transparence du bitmap representant le rectangle */ struct RectangleType=[ RECTObj2D:Obj2D, RECTBitmap:ObjBitmap, RECTLineColor:I, RECTStyleTrait:I, RECTCoinsArrondis:I, RECTTransparency:I ]MkRectangleType;; /******************************************************************************************************************/ /* Fonctions Internes au rectangle */ /******************************************************************************************************************/ /* renvoie l'ensemble des points constituants la ligne entre deux points de type [Int2DPoint r1]*/ fun EvalPointsLigne(Point1,Point2)= { let MkInt2DPoint [Point2.iptX-Point1.iptX Point2.iptY-Point1.iptY] -> Vect in let ftoi sqrt ((sqr itof Vect.iptX)+.(sqr itof Vect.iptY)) -> norm in let MkInt2DPoint [Vect.iptX/norm Vect.iptY/norm] -> u in let nil -> res in if u.iptX==0 then { let Point1.iptY -> y in while y!=Point2.iptY+u.iptY do { set res=(MkInt2DPoint [((y-Point1.iptY)*u.iptX/u.iptY+Point1.iptX) y])::res; set y=y+u.iptY; }; res } else { let Point1.iptX -> x in while x!=Point2.iptX+u.iptX do { set res=(MkInt2DPoint [x ((x-Point1.iptX)*u.iptY/u.iptX+Point1.iptY)])::res; set x=x+u.iptX; }; res }; };; /* effectue la translation de vecteur Vect sur la liste de points List */ /* renvoie la liste resultante de type [Int2DPoint r1]*/ fun Translation(Vect,List)= { if List==nil then nil else { let hd List -> Point in { set Point.iptX=Point.iptX+Vect.iptX; set Point.iptY=Point.iptY+Vect.iptY; Point::(Translation Vect tl List); }; }; };; /* ajoute un point a une liste de Points s'il n'est pas present */ fun AddPointToList(Point,List)= if isf_in_list List @EqualityPoint Point then List else Point::List;; /* evalue les points constituant les coins arrondis du rectangle */ /* renvoie une liste de type [Int2DPoint r1] */ fun EvalPointsEllipse(PointHG,PointHD,PointBG,PointBD,a,b)= { let [itof (-a) nil nil nil nil] -> [x infg supg infd supd] in { while x<=.(itof 0) do { set supg=AddPointToList (MkInt2DPoint [(ftoi x) (ftoi (itof (-b))*.(sqrt (itof 1)-.((sqr x)/.(sqr itof a))))]) supg; set infg=AddPointToList (MkInt2DPoint [(ftoi x) (ftoi (itof b)*.(sqrt (itof 1)-.((sqr x)/.(sqr itof a))))]) infg; set x=x+.(atof "0.1") }; set x=(itof 0); while x<=.(itof a) do { set supd=AddPointToList (MkInt2DPoint [(ftoi x) (ftoi (itof (-b))*.(sqrt (itof 1)-.((sqr x)/.(sqr itof a))))]) supd; set infd=AddPointToList (MkInt2DPoint [(ftoi x) (ftoi (itof b)*.(sqrt (itof 1)-.((sqr x)/.(sqr itof a))))]) infd; set x=x+.(atof "0.1") }; set supg=Translation PointHG supg; set infg=Translation PointBG infg; set supd=Translation PointHD supd; set infd=Translation PointBD infd; [supg infg supd infd] }; };; /* affiche sur le bitmap resultante la liste des pixels ListPixels en fonction du type d'affichage */ /* Bitmap:bitmpa resultante TraitColor:couleur du trait Plein:le prochain point est plein si 1 sinon 0 i:indice du point dans l'elemnt de la sequence typeaffichage typeaffichage:sequence d'affichage des points indice:indice de l'element de la sequence a afficher ListPixels:list des pixels a afficher ([Int2DPoint r1]) Renvoie le bitmap resultant */ fun PutPixelAlternative(Bitmap,TraitColor,Plein,i,typeaffichage,indice,ListPixels)= { if ListPixels==nil then [Plein i indice] else { if Plein&&i<(nth_list typeaffichage indice) then let hd ListPixels -> Pix in _PUTpixel16 Bitmap Pix.iptX Pix.iptY TraitColor else nil; if Plein then if (i+1)==(nth_list typeaffichage indice) then PutPixelAlternative Bitmap TraitColor 0 0 typeaffichage (if indice == ((sizelist typeaffichage)-1) then 0 else indice+1) tl ListPixels else PutPixelAlternative Bitmap TraitColor 1 i+1 typeaffichage indice tl ListPixels else if (i+1)==(nth_list typeaffichage indice) then PutPixelAlternative Bitmap TraitColor 1 0 typeaffichage (if indice == ((sizelist typeaffichage)-1) then 0 else indice+1) tl ListPixels else PutPixelAlternative Bitmap TraitColor 0 i+1 typeaffichage indice tl ListPixels }; };; /* affiche sur le bitmap un ensemble de list de pixels de type [[Int2DPoint r1] r1]*/ fun PutAllGroupPixelAlternative(Bitmap,TraitColor,Plein,i,typeaffichage,indice,GroupListPixels)= { if GroupListPixels==nil then nil else { let PutPixelAlternative Bitmap TraitColor Plein i typeaffichage indice hd GroupListPixels -> [Pleinres ires indiceres] in PutAllGroupPixelAlternative Bitmap TraitColor Pleinres ires typeaffichage indiceres tl GroupListPixels }; 0 };; /* cree le bitmap representant le rectangle */ fun CreateBitmapRectangle(Channel,Width,Height,TraitColor,StyleTrait,CoinArrondi)= { let (if TraitColor==(make_rgb 0 0 255) then (make_rgb 0 255 0) else (make_rgb 0 0 255)) -> TransparentColor in let _FILLbitmap (_CRbitmap Channel Width Height) TransparentColor -> BmpRes in if (StyleTrait==STYLE_NORMAL)&&!CoinArrondi then { /* style on ne peut plus normal */ _DRAWline BmpRes 0 0 Width-1 0 DRAW_SOLID 1 TraitColor; _DRAWline BmpRes Width-1 0 Width-1 Height-1 DRAW_SOLID 1 TraitColor; _DRAWline BmpRes 0 Height-1 Width-1 Height-1 DRAW_SOLID 1 TraitColor; _DRAWline BmpRes 0 0 0 Height-1 DRAW_SOLID 1 TraitColor; BmpRes } else { /* style pointille ou arrondi */ let nil -> ListPoints in let (if StyleTrait==STYLE_POINTILLE_1 then (5::3::nil) else if StyleTrait==STYLE_POINTILLE_2 then (2::2::nil) else if StyleTrait==STYLE_POINTILLE_3 then (7::2::2::2::nil) else if StyleTrait==STYLE_POINTILLE_4 then (5::2::2::2::2::2::nil) else nil ) -> listaffichage in let [1 0 0] -> [Plein i indice] in let (if CoinArrondi then (if Width>Height then [Width/4 Height/4] else [Height/4 Width/4]) else [0 0]) -> [a b] in let EvalPointsLigne (MkInt2DPoint [a 0]) (MkInt2DPoint [Width-a-1 0]) -> hs in /* ligne horizontale haute*/ let EvalPointsLigne (MkInt2DPoint [Width-1 b]) (MkInt2DPoint [Width-1 Height-b-1]) -> bd in /*ligne verticale droite*/ let EvalPointsLigne (MkInt2DPoint [a Height-1]) (MkInt2DPoint [Width-a-1 Height-1]) -> hb in /*ligne horizontale basse */ let EvalPointsLigne (MkInt2DPoint [0 b]) (MkInt2DPoint [0 Height-b-1]) -> bg in /* ligne verticale gauche*/ if CoinArrondi then { let EvalPointsEllipse (MkInt2DPoint [a b]) (MkInt2DPoint [Width-a b]) (MkInt2DPoint [a Height-b]) (MkInt2DPoint [Width-a Height-b]) a b -> [supg infg supd infd] in PutAllGroupPixelAlternative BmpRes TraitColor 1 0 listaffichage 0 (hs::supd::bd::infd::hb::infg::bg::supg::nil) } else PutAllGroupPixelAlternative BmpRes TraitColor 1 0 listaffichage 0 (hs::bd::hb::bg::nil); BmpRes }; };; fun DsRectangle(rect)= { set rect.RECTObj2D=nil; _DSbitmap rect.RECTBitmap; set rect.RECTLineColor=nil; set rect.RECTStyleTrait=nil; set rect.RECTCoinsArrondis=nil; set rect.RECTTransparency=nil; set rect=nil; 1 };; fun PaintRectangle(rect)= [rect.RECTBitmap 0 0 obj.O2Dw obj.O2Dh rect.RECTTransparency] ;; fun PaintPartOfRectangle(area,rect)= let SizeRectangle area -> [aw ah] in [ rect.RECTBitmap area.RctHG.iptX area.RctHG.iptY aw ah rect.RECTTransparency ] ;; fun IsMouseOnRectangle(MouseCol,MouseLgn,rect)=0;; /************************************************************************************/ /* Fonctions externes du Rectangle */ /************************************************************************************/ /* Constructeur du Rectangle Channel : canal de construction Container : container auquel appartient le rollover ObjPere : l'objet pere Coordinates : coordonnees de l'objet par rapport au pere RectangleFlags : flags de construction de l'objet Width : largeur Height : hauteur TraitColor : couleur du trait StyleTrait : style du trait (STYLE_NORMAL STYLE_POINTILLE_1 STYLE_POINTILLE_2 STYLE_POINTILLE_3 STYLE_POINTILLE_4 ) CoinArrondi : Rectangle a coins arrondis (COIN_ARRONDI) ou pas COIN_NORMAL */ fun RECT_New( Channel, Container, ObjPere, Coordinates, RectangleFlags, Name, Width, Height, TraitColor, StyleTrait, CoinArrondi)= { if Container !=nil then { let CreateBitmapRectangle Channel Width Height TraitColor StyleTrait CoinArrondi -> bmpglobale in let O2D_NewObject Container ObjPere Name Width Height Coordinates RectangleFlags -> Obj in let MkRectangleType [ Obj bmpglobale TraitColor StyleTrait CoinArrondi TransparentColor bmpglobale Width/2 Height/2 ] -> rect in { /* les methodes */ O2D_CBDsObject Obj rect @DsRectangle; O2D_CBPaint Obj rect @PaintRectangle; O2D_CBPaintPart Obj rect @PaintPartOfRectangle; O2D_CBIsMouseOnDisplayObject Obj rect @IsMouseOnRectangle; rect }; } else { /* le container est vide */ FatalError "RollOver Creation impossible" "Container is nil"; nil }; };; fun RECT_Del(rect)= { O2D_DelObject rect.RECTObj2D; rect };;