Paint anti-aliased triangle, cross-platform lazarus / 31-LCL ---------------------------------------------------------------------- AlexTP · 2014-05-24 18:25 I want to paint a **filled* triangle on Canvas, anti-aliased, so that if green triangle painted on light BG image, then light greenish pixels appear near trinagle borders. I need it cross platform (Win/Mac/L) w/out BIG libraries. For atTabs Any sample? I know that I may paint big triangle on temp canvas and scale it maybe...i need sample pls ---------------------------------------------------------------------- Graeme · 2014-05-24 18:48 Simply us the AggPas library. It is 100% implemented in Object Pascal and has very high quality anti-aliasing implemented. There are a couple versions of AggPas floating around, but as far as I know the one included with fpGUI Toolkit is the most maintained and used version. You can use the AggPas included in the fpGUI repository without actually using the fpGUI toolkit. AggPas has about 20-30 demos showing various features. Here is a screenshot of a simple demo I put together. Code: [Select]TAgg2D.Triangle (x1, y1, x2, y2, x3, y3 ) ---------------------------------------------------------------------- AlexTP · 2014-05-24 20:31 hmm. I cannot use AggPas: a) too complex to paint a rectangle (some classes needed): Code: [Select]var   b: TfpgWindowBase;   a: TAgg2d; begin   b:= TfpgWindowBase.Create(nil);   ////need to set canvas??? how?   a:= TAgg2d.Create(b);   a.Color:= Color;   a.Triangle(p1.x, p1.y, p2.x, p2.y, p3.x, p3.y);   a.Free;   b.Free; b) too much overhead (300K for 1.8M exe) for simple rectangle painting. My app is light ---------------------------------------------------------------------- Rails · 2014-05-24 21:25 Take a look at the TCairoPaintBox component. It might work for you. You can find it in LuiPack. http://code.google.com/p/luipack/ ---------------------------------------------------------------------- AlexTP · 2014-05-24 21:51 Why CairoPaintbox?? How to use it to paint a triangle? ---------------------------------------------------------------------- circular · 2014-05-24 23:34 If you want it very light, maybe you can consider not using a library at all. Create a memory image (FPImage) and draw the triangle yourself (linear interpolation). ---------------------------------------------------------------------- AlexTP · 2014-05-24 23:47 As I wrote I need pas sample, not advice "create memory image ...etc..." ---------------------------------------------------------------------- taazz · 2014-05-25 00:17 Well no one is going to create an anti aliased routine just to show you a sample the funny thing is that you say anti aliased but you mean alpha blend and on top of that you are demanding a pascal sample I was close to ignore this completely. Anyway here is a color blend function that I found on the net somewhere don't remember where I did not had any reference in my snippets for it. Code: [Select]Function ColorBlend(Const aColor1, aColor2:TColor; Const aAlpha: Byte): TColor; //by chesso Var   vRed, vGreen, vBlue : Byte;   vPrimary, vSecondary : Real; // Primary And Secondary Intensity. Begin   vPrimary := ((aAlpha+1) /$100);   vSecondary := (($100-aAlpha) /$100);   vRed := Trunc(GetRValue(aColor1)*vPrimary);   vGreen := Trunc(GetGValue(aColor1)*vPrimary);   vBlue := Trunc(GetBValue(aColor1)*vPrimary);   vRed := vRed+Trunc(GetRValue(aColor2)*vSecondary);   vGreen := vGreen+Trunc(GetGValue(aColor2)*vSecondary);   vBlue := vBlue+Trunc(GetBValue(aColor2)*vSecondary);   If (vRed > $FF) Then vRed := $FF;   If (vGreen > $FF) Then vGreen := $FF;   If (vBlue > $FF) Then vBlue := $FF;   Result := RGB(vRed, vGreen, vBlue); End; ---------------------------------------------------------------------- AlexTP · 2014-05-25 00:30 Hm- thank- I have this func already- from Torry-net WuLine() sample code http://www.swissdelphicenter.ch/torry/showcode.php?id=1812 Hm I guess no such sample exists, cannot find ... ---------------------------------------------------------------------- taazz · 2014-05-25 00:40 OK is the background a flat color or it can be a image? if the former then use this to calculate the drawing color then draw the triangle if the later then I will do an example a bit later for you. ---------------------------------------------------------------------- AlexTP · 2014-05-25 00:43 BG is flat color. What do u mean "use this to calculate.... etc"? Can u elaborate. WuLine func cannot paint filled triangle ---------------------------------------------------------------------- taazz · 2014-05-25 01:02 Ok I just downloaded the zip from your repository and looked at your code, you use the function DrawTriangleRaw to draw your triangle right? and you pass to it the ATabBg color while your tab is painted using the FColorBg variable correct? then you do something like this in your dopaintto method. Code: [Select]  PR1:= Point(ARect.Right-FTabAngle-1, ARect.Top);   PR2:= Point(ARect.Right+FTabAngle-1, ARect.Bottom-1);   DrawTriangleRaw(C, PR1, PR2, Point(PR1.X, PR2.Y), ColorBlend(ATabBg, FColorbg, 50)); That should give a transparent look, play with the 50 value to find a value best suited for you. ---------------------------------------------------------------------- AlexTP · 2014-05-25 01:13 taaz, This will paint blended entire triangle, pale one. I need another thing.I need to smooth triangle edges. Edges only. Not touch filling ---------------------------------------------------------------------- taazz · 2014-05-25 02:03 well in that case use the wulines you linked earlier to draw the outline then shrink then paint the triangle on top of the lines. ---------------------------------------------------------------------- AlexTP · 2014-05-25 10:13 "then shrink" isn't ok. This won't work for real case ---------------------------------------------------------------------- taazz · 2014-05-25 10:19 Well then don't shrink just paint on top. You only need the antialised pixels around the area. What do you define as real case ? ---------------------------------------------------------------------- AlexTP · 2014-05-25 10:25 I repeat it won't work.Simple trinagle draw over or below the WuLine edge gives not ok edges ---------------------------------------------------------------------- taazz · 2014-05-25 10:33 well for QT just enable the antialized property on canvas, for GTK2 use cairo canvas it is part of lazarus and for windows you have to write gdi+ canvas, of course you can adapt the wulines algorithm to use it on the polygon your self and of course the most cross platform way of all just use aggpas as Graeme suggested. Thats your choices so far.