Circle with antialising for RadioButton component lazarus / 39-Graphics ---------------------------------------------------------------------- vercetti · 2023-09-21 11:08 Hi guys. I'm trying to make my own crossplatform Radio Button component. It inherited from TCustomControl. I have a problem with painting circle. Using Canvas.Ellipse(Rect) i've got ugly circle. Adding "Canvas.AntialiasingMode := amOn;" doesn't change anything. Is there an any way to make antialised circle without using third parties libraries ? ---------------------------------------------------------------------- KodeZwerg · 2023-09-21 11:46 Your code is very confusing, I get a lot of errors with your provided code, so I show mine. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure DrawAntiAliasedCircleOnPanel(const AImage: TImage);var  Bitmap: TBitmap;  Radius, CenterX, CenterY: Double;begin  Bitmap := TBitmap.Create;  try    Bitmap.Width := AImage.ClientWidth;    Bitmap.Height := AImage.ClientHeight;     SetStretchBltMode(Bitmap.Canvas.Handle, HALFTONE);    SetBrushOrgEx(Bitmap.Canvas.Handle, 0, 0, nil);     Bitmap.Canvas.Pen.Width := 1;    Bitmap.Canvas.Pen.Style := psSolid;  Bitmap.Canvas.Pen.Color := clWhite;     Bitmap.Canvas.Brush.Style := bsSolid;    Bitmap.Canvas.Brush.Color := clBlack;     Radius := Min(Bitmap.Width, Bitmap.Height) / 2;     CenterX := Bitmap.Width / 2;    CenterY := Bitmap.Height / 2;     Bitmap.Canvas.Ellipse(Round(CenterX - Radius), Round(CenterY - Radius), Round(CenterX + Radius), Round(CenterY + Radius));    AImage.Picture.Assign(Bitmap);  finally    Bitmap.Free;  end;end; ---------------------------------------------------------------------- vercetti · 2023-09-21 12:45 Thanks, but result is almost the same. It looks like a Bresenham's algorithm, there are no smooth color transitions here. It looks great when the circle is big, but not for small (filled)circle for RadioButton. In theory this can be drawn using the Xiaolin Wu's algorithm. But maybe there are other solutions. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i SetBrushOrgEx(Bitmap.Canvas.Handle, 0, 0, nil);Does WinGdi work on Linux ? Or i confusing something ? I need something like this. ---------------------------------------------------------------------- paweld · 2023-09-21 13:08 use BGRABitmap. It is multiplatform. You can download from: https://github.com/bgrabitmap/bgrabitmap or install from OPMCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses  BGRABitmap, BGRABitmapTypes; procedure TForm1.Button1Click(Sender: TObject);var  bmp: TBGRABitmap;begin  bmp := TBGRABitmap.Create(40, 40, clBlack);  bmp.EllipseAntialias(19, 19, 7, 7, clWhite, 1);  bmp.EllipseAntialias(19, 19, 4, 4, clSkyBlue, 0, clSkyBlue);  bmp.Draw(Canvas, 0, 0);  bmp.Free;end; ---------------------------------------------------------------------- lainz · 2023-09-21 23:57 Try BGRAControls. We have high dpi / retina SVG radio button. ---------------------------------------------------------------------- wp · 2023-09-22 00:03 "Poor man's" anti-aliasing: Draw the image at double size and then stretch-draw it back to original size. Here is a version using a LazIntfImage und the FPBaseInterpolation which results in nicer results than the standard TCanvas.StretchDraw. No extra libraries required, everything needed comes with FPC/Lazarus: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses  LclIntf, FPImage, FPCanvas, IntfGraphics, LazCanvas; function CreateRadioButtonBitmap(ASize: Integer; Checked: Boolean): TBitmap;var  img1, img2: TLazIntfImage;  canvas1, canvas2: TLazCanvas;  R: TRect;  i, n: Integer;begin  Result := TBitmap.Create;  Result.PixelFormat := pf32Bit;  Result.SetSize(ASize, ASize);   img1 := Result.CreateIntfImage;  try    img1.Width := 2*ASize;    img1.Height := 2*ASize;    canvas1 := TLazCanvas.Create(img1);    try      canvas1.Clear;      R := Rect(0, 0, img1.Width-1, img1.Height-1);      canvas1.Pen.Width := 1;      canvas1.Pen.FPColor := colGray;      canvas1.Brush.Style := bsClear;    canvas1.Brush.FPColor := colWhite;      n := ASize div 8;      for i:= 1 to n do      begin        if i = n then          canvas1.Brush.Style := bsSolid;        canvas1.Ellipse(R);        InflateRect(R, -1, -1);      end;      if Checked then      begin      InflateRect(R, -ASize div 4, -ASize div 4);          canvas1.Brush.Style := bsSolid;        canvas1.Brush.FPColor := colBlue;        canvas1.Ellipse(R);      end;    finally      canvas1.Free;    end;     img2 := Result.CreateIntfImage;    try      canvas2 := TLazCanvas.Create(img2);      try        canvas2.Interpolation := TFPBaseInterpolation.Create;        try        canvas2.StretchDraw(0, 0, ASize, ASize, img1);          Result.LoadFromIntfImage(img2);        finally          canvas2.Interpolation.Free;        end;      finally        canvas2.Free;      end;    finally      img2.Free;    end;  finally  img1.Free;  end;end;         procedure TForm1.FormCreate(Sender: TObject);begin  RadioBtnChecked_Bmp := CreateRadioButtonBitmap(16, true);  RadioBtnUnchecked_Bmp := CreateRadioButtonBitmap(16, false);end; procedure TForm1.FormDestroy(Sender: TObject);begin  RadioBtnChecked_Bmp.Free;  RadioBtnUnchecked_Bmp.Free;end; procedure TForm1.FormPaint(Sender: TObject);begin  Canvas.Draw(10, 10, RadioBtnChecked_bmp);  Canvas.Draw(10, 50, RadioBtnUnchecked_bmp);end; ---------------------------------------------------------------------- 440bx · 2023-09-22 07:54 @wp, First, the following is totally off topic.  A number of years ago you attached a little program that used SetWindowRgn to create a window in the shape of a Bugs Bunny image.  I know I downloaded it but, I've lost it in a sea of other source code and I've tried to locate the post you attached it to,  to no avail. I am hereby asking that if you can locate the post with that attachment, I would be very grateful if you would post its address so I can download it again. Thank you in advance. ---------------------------------------------------------------------- balazsszekely · 2023-09-22 08:11 @440bx QuoteA number of years ago you attached a little program that used SetWindowRgn to create a window in the shape of a Bugs Bunny image.  It was me who posted the program with the bunny.  Today I made it cross platform, you can find the attachment in the following post: htt ps://forum.lazarus.freepascal.org/index.php/topic,64677.msg492064.html #msg492064 PS: I will try to locate the original post. ---------------------------------------------------------------------- TRon · 2023-09-22 08:19 Quote from: GetMem on September 22, 2023, 10:11:53 amPS: I will try to locate the original post. Here seems to be something hopping around ? Not sure if that was the one you two had in mind though. ---------------------------------------------------------------------- balazsszekely · 2023-09-22 08:30 Quote from: TRon on September 22, 2023, 10:19:09 amQuote from: GetMem on September 22, 2023, 10:11:53 amPS: I will try to locate the original post. Here seems to be something hopping around ? Not sure if that was the one you two had in mind though. Yes. Thank you @TRon! That's the original one with alphablendig . In the meantime I found the other one, with CreateRectRgn/SetWindowRgn: h ttps://forum.lazarus.freepascal.org/index.php/topic,44577.msg313713.ht ml#msg313713 , but is windows only(PS: apparently it no longer works with the current version of laz/fpc) . The cross platform version is here: https://forum.lazarus.freepascal.org/index.php/topic,64677.msg49 2064.html#msg492064 ---------------------------------------------------------------------- 440bx · 2023-09-22 08:46 Quote from: GetMem on September 22, 2023, 10:11:53 am@440bx QuoteA number of years ago you attached a little program that used SetWindowRgn to create a window in the shape of a Bugs Bunny image.  It was me who posted the program with the bunny.  Today I made it cross platform, you can find the attachment in the following post: htt ps://forum.lazarus.freepascal.org/index.php/topic,64677.msg492064.html #msg492064 PS: I will try to locate the original post. Thank you GetMem, my apologies for the mistaken credit.  Looks like what they say is true, memory does not get better with age ... chuckle. Thank you for the updated/cross-platform version.  It would be wonderful if you could locate the original post but... no rush... take your time... I don't want to impose and, thank you again. ETA: I think I found the old one, the one you mentioned in your reply to TRon. ---------------------------------------------------------------------- Fibonacci · 2023-09-22 09:47 Quote from: GetMem on September 22, 2023, 10:30:58 amPS: apparently it no longer works with the current version of laz/fpc It compiled and works. Multiplatform version on the left. Windows version on the right, much better. Old example windows-only with button looks like multiplatform version, not great. Versions multiplatform + old windows cut window shape by color, newer windows version uses transparency of the PNG, looks better. Maybe its little offtopic, but thanks, maybe I will use it for splash window for some of my projects ---------------------------------------------------------------------- cdbc · 2023-09-22 10:18 Hi Cool it works on Linux Qt5 too, but takes short of 3 minutes to show form... Regards Benny ---------------------------------------------------------------------- balazsszekely · 2023-09-22 11:03 @Fibonacci Yes I agree. If you are on windows, the version with transparency looks much better. The cross platform version with regions also can be improoved. @cdbc On my linux mint machine with qt5 the application loads in 1-2 seconds. I don" t know why is so slow at your side. Did you try to debug it? Alternatively run the application outside the IDE. PS: We should move the discussion to another thread. This one is about circles and anti aliasing. ---------------------------------------------------------------------- cdbc · 2023-09-22 11:56 Hi I just "LazBuild" it and clicked in "Dolphin", waited... thought [Nah, doesn't work] and forgot about it, and suddenly there it was, like a troll from a box  Building it pulls in practically all of GTK... Maybe that's why. Regards Benny ---------------------------------------------------------------------- zeljko · 2023-09-22 15:21 Qt5 and Qt6 shows form instantly here.