Recent

Author Topic: Bitmap Pixel Editor  (Read 1159 times)

DreamVB

  • Jr. Member
  • **
  • Posts: 93
    • Memo Pad
Bitmap Pixel Editor
« on: September 10, 2023, 07:43:13 pm »
Hi guys
I made a new project it very basic and is jut used for editing bitmap files, that maybe us full for toolbar bitmaps. anyway, I am hoping to add new features soon but for now take a look. I think it should work on Linux to, but you may need to rearrange the controls cos I was using Ubuntu on VirtualBox, and it seemed to mess up but ran ok only thing I dd notice that will not work is the fill colour works fine on Windows anyway comments welcome.

http://dreamvb.rf.gd/pixeled/
Dream Believe Achieve

wp

  • Hero Member
  • *****
  • Posts: 11482
Re: Bitmap Pixel Editor
« Reply #1 on: September 11, 2023, 12:32:39 am »
I am attaching a fixed version which I tested on Windows 96ppi and 144ppi, macOS and Linux to have a correct layout (except for Linux/gkt3 which does not calculate the form size correctly).

The issue is that the application is not designed in a way that is compatible with different widgetsets and screen resolutions. You place and arrange the controls by simply dropping and moving them with the mouse. This is very convenient but causes overlapping controls when the font size changes on another widgetset or at another screen resolution. You must use the Anchor Editor to anchor the controls to their container and to their neighboring controls so that the layout is able to adjust itself. And you must use AutoSizing so that the control containers can adjust their size automatically. Please read https://wiki.freepascal.org/Anchor_Sides and https://wiki.freepascal.org/Autosize_/_Layout to learn how to use the anchor editor and autosizing. It is a bit stubborn in the beginning, but now that I mastered it I would never miss it. It is one of the most important gems in the Lazarus IDE!

Adjustment to varying screen resolution is handled automatically by the IDE when you check the box "Use LCLScaling" in the project options. In your case, however, it is a bit more difficult because your images do not scale. The button images can handle this when their images are contained in auto-scaled imagelists and are provided in several resolutions. And there is the palette image which is also provided only in a single size. Therefore I had to calculate some sizes manually - this is on the OnActivate event handler of the form.

The drawing panel imgDest should be scaled also manually, but this happens at several places and I did not want to dive into your program so deeply.

I also fixed a memory leak caused by the "nBrush" which is created in FormCreate but was never destroyed.

wp

  • Hero Member
  • *****
  • Posts: 11482
Re: Bitmap Pixel Editor
« Reply #2 on: September 11, 2023, 12:13:00 pm »
Here's an updated version in which I moved all controls (except for the StatusBar) onto a panel. Since the panel can be auto-sized, some of the calculations can be simplified. I tested on Win32 (96ppi and 144ppi), Lazarus (gtk2 and gtk3), Cocoa, and in all cases the application is scaled correctly now (except for the images and the drawing grid as explained in the other post).

DreamVB

  • Jr. Member
  • **
  • Posts: 93
    • Memo Pad
Re: Bitmap Pixel Editor
« Reply #3 on: September 11, 2023, 12:43:06 pm »
Hi, very much thanks wp for the updated I added to my project source and doing some other changes should have a new update in a few days. I never took much notice of the anchor stuff before I just thought everything would be the same in every os since I do not use Linux and only started to work on Virutalbox a few days ago. The code display works a lot better thanks to you know on Linux, only thing I can not get working on Linux is the fill color unless I need to use something else.

Thanks again for the work you done
Dream Believe Achieve

wp

  • Hero Member
  • *****
  • Posts: 11482
Re: Bitmap Pixel Editor
« Reply #4 on: September 11, 2023, 03:33:43 pm »
only thing I can not get working on Linux is the fill color
FloodFill is not implemented on the gtk2/gtk3 canvases. Maybe on qt/qt5/qt6 - I don't have access to these widgetsets ATM. But you can replace the widget FloodFill by the Floodfill implemented by fcl-image:
Code: Pascal  [Select][+][-]
  1. procedure TfrmMain.FloodFill(X, Y: Integer; ANewColor: TColor);
  2. var
  3.   img: TLazIntfImage;
  4.   cnv: TLazCanvas;
  5. begin
  6.   img := imgSrc.Picture.Bitmap.CreateIntfImage;
  7.   try
  8.     cnv := TLazcanvas.Create(img);
  9.     try
  10.       cnv.Brush.FPColor := TColorToFPColor(ANewColor);
  11.       cnv.Brush.Style := bsSolid;
  12.       cnv.FloodFill(X, Y);
  13.       imgSrc.Picture.Bitmap.LoadFromIntfImage(img);
  14.       RenderDest;
  15.     finally
  16.       cnv.Free;
  17.     end;
  18.   finally
  19.     img.Free;
  20.   end;
  21. end;

You need the units IntfGraphics and Lazcanvas in the uses clause, and the TFrmMain.imgDestMouseDown must be modified like this:
Code: Pascal  [Select][+][-]
  1. procedure Tfrmmain.imgDestMouseDown(Sender: TObject; Button: TMouseButton;
  2.   Shift: TShiftState; X, Y: integer);
  3. ...
  4.   if ImgTool = 4 then
  5.   begin
  6. {  imgSrc.Canvas.Brush.Style := bsSolid;
  7.     imgSrc.Canvas.Brush.Color := PixelColor;
  8.     imgSrc.Canvas.FloodFill(OldX, OldY, imgSrc.Canvas.Pixels[oldx, oldy],
  9.       TFillStyle.fsSurface);
  10. }
  11.     FloodFill(OldX, OldY, PixelColor);
  12.   end;  
  13.   ...

 

TinyPortal © 2005-2018