Recent

Author Topic: How to install image library for freepascal on linux?  (Read 12362 times)

Handoko

  • Hero Member
  • *****
  • Posts: 5530
  • My goal: build my own game engine using Lazarus
Re: How to install image library for freepascal on linux?
« Reply #45 on: August 15, 2023, 05:28:24 pm »
Saying that is impossible, actually is wrong.

Programmer + Time + Persistent can make impossible things become possible.

Winning a chess game against a world chess champion is almost impossible. But programmers managed to write program to play chess and defeated Garry Kasparov in 1977.

So the question is, how much effort are you willing to spend to make TEdit to support semi transparent background? Why not just use a TLabel? TLabel does not support background, if you really need a (semi transparent) background, you can use a TPaintBox or you can paint directly on the TImage.Canvas. If you haven't known, you can use TImage.Canvas.TextOut to write text, which is the easiest solution I think.
« Last Edit: August 15, 2023, 07:15:20 pm by Handoko »

lainz

  • Hero Member
  • *****
  • Posts: 4742
  • Web, Desktop & Android developer
    • https://lainz.github.io/
Re: How to install image library for freepascal on linux?
« Reply #46 on: August 15, 2023, 05:42:10 pm »
There is Custom Drawn edit control, that you can  paint as you wish...

barracuda

  • Full Member
  • ***
  • Posts: 133
Re: How to install image library for freepascal on linux?
« Reply #47 on: August 16, 2023, 12:19:06 am »
There is Custom Drawn edit control, that you can  paint as you wish...

It's not clear to me how to get TCDEdit into the Unit

Code: Pascal  [Select][+][-]
  1. interface
  2.  
  3. uses
  4.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, LCLType,
  5.   ExtDlgs, ExtCtrls,
  6.   customdrawndrawers,
  7.   customdrawncontrols;
  8. ...
  9.  
  10.   TForm1 = class(TForm)
  11.     ComboBox1: TComboBox;
  12.     Label1: TLabel;
  13.     Button1: TButton;
  14.     EditFileName: TCDEdit;
  15.  

Or how to bind the event procedures here:
Code: Pascal  [Select][+][-]
  1. EditFileName.OnClick := @MyEditClick;
  2. EditFileName.OnKeyDown := @MyEditKeyDown;

Errors for example:
unit1.pas(174,27) Error: Incompatible types: got "<procedure variable type of procedure(TObject;var Word;TShiftState) of object;Register>" expected "<procedure variable type of procedure(TObject) of object;Register>"

I just cannot make it working. Any idea how to compile it?

When I press F11 I see this error:

Cannot find component of class "TCDEdit".
It is not registered with RegisterClass and no lfm file was found.
A unit is required:
/home/user/FreePascal/ImageViewer2/unit1.pas

jamie

  • Hero Member
  • *****
  • Posts: 7662
The only true wisdom is knowing you know nothing

Handoko

  • Hero Member
  • *****
  • Posts: 5530
  • My goal: build my own game engine using Lazarus
Re: How to install image library for freepascal on linux?
« Reply #49 on: August 16, 2023, 04:43:43 am »
No need to use any third party component.

Try the code below. It shows how to stretch-drawing image, semi transparent rectangle and write text using only TCanvas.

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, ExtCtrls, StdCtrls, LCLType;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Button1: TButton;
  16.     Image1: TImage;
  17.     procedure Button1Click(Sender: TObject);
  18.   private
  19.     procedure LoadImage;
  20.     procedure DrawCenterRectangle;
  21.     procedure WriteCenterText;
  22.   end;
  23.  
  24. var
  25.   Form1: TForm1;
  26.  
  27. implementation
  28.  
  29. {$R *.lfm}
  30.  
  31. { TForm1 }
  32.  
  33. procedure TForm1.LoadImage;
  34. const
  35.   ImageFile = 'img.png';
  36. var
  37.   Tmp: TPicture;
  38. begin
  39.   Image1.SetBounds(0, 0, Width, Height);
  40.   Image1.Picture.Clear;
  41.   Tmp := TPicture.Create;
  42.   try
  43.     Tmp.LoadFromFile(ImageFile);
  44.     Image1.Canvas.StretchDraw(ClientRect, Tmp.Bitmap);
  45.   finally
  46.     Tmp.Free;
  47.   end;
  48. end;
  49.  
  50. procedure ChangeColor(var Data: Byte);
  51. const
  52.   Shift = 64; // 25% white
  53. var
  54.   Temp: Integer;
  55. begin
  56.   Temp := Data + Shift;
  57.   if (Temp > 255) then Temp := 255
  58.     else
  59.       if (Temp < 0) then Temp := 0;
  60.   Data := Temp;
  61. end;
  62.  
  63. procedure TForm1.DrawCenterRectangle;
  64. const
  65.   BoxWidth  = 100;
  66.   BoxHeight = 20;
  67. var
  68.   ScanData:       PRGBQuad;
  69.   Xstart, Ystart: Integer;
  70.   Xend, Yend:     Integer;
  71.   X, Y:           Integer;
  72. begin
  73.  
  74.   // Calculate Box position
  75.   Xstart := (Width - BoxWidth)   div 2;
  76.   Ystart := (Height - BoxHeight) div 2;
  77.   Xend   := Xstart + BoxWidth;
  78.   Yend   := Ystart + BoxHeight;
  79.  
  80.   // Draw semi transparent rectangle
  81.   Image1.Picture.Bitmap.BeginUpdate;
  82.   for Y := Ystart to (Yend-1) do
  83.   begin
  84.     ScanData := Image1.Picture.Bitmap.ScanLine[Y];
  85.     for X:= 0 to (Image1.Picture.Bitmap.Width-1) do
  86.     begin
  87.       if (X >= Xstart) then
  88.       begin
  89.         ChangeColor(ScanData^.rgbRed);
  90.         ChangeColor(ScanData^.rgbGreen);
  91.         ChangeColor(ScanData^.rgbBlue);
  92.       end;
  93.       Inc(ScanData);
  94.       if X >= Xend then Break;
  95.     end;
  96.   end;
  97.   Image1.Picture.Bitmap.EndUpdate;
  98.  
  99. end;
  100.  
  101. procedure TForm1.WriteCenterText;
  102. const
  103.   Something = 'Hello';
  104. var
  105.   X, Y, W, H: Integer;
  106. begin
  107.   H := Image1.Canvas.TextHeight(Something);
  108.   W := Image1.Canvas.TextWidth(Something);
  109.   X := (Width - W)  div 2;
  110.   Y := (Height - H) div 2;
  111.   Image1.Canvas.Brush.Style := bsClear;
  112.   Image1.Canvas.Font.Color  := clWhite;
  113.   Image1.Canvas.TextOut(X, Y, Something);
  114. end;
  115.  
  116. procedure TForm1.Button1Click(Sender: TObject);
  117. begin
  118.   LoadImage;
  119.   DrawCenterRectangle;
  120.   WriteCenterText;
  121. end;
  122.  
  123. end.

I quickly wrote and tested the code on Linux only, it may contain bugs.

Room for improvements:
- Instead of using Image1, draw directly on Form.Canvas
- Fullscreen and proportional image loading not implemented
« Last Edit: August 16, 2023, 10:54:36 am by Handoko »

barracuda

  • Full Member
  • ***
  • Posts: 133
Re: How to install image library for freepascal on linux?
« Reply #50 on: August 16, 2023, 01:20:31 pm »
See, my system is way too slow. Will I solve one question whole week? It takes like hour to start mint and firefox and lazarus. If any shit happens like stupid VM Player starts to open FF Browser on Win XP while working on mint, everything can crash. I can wait till the night to test one program.

Can you just answer a simple question? I will learn nothing otherwise.

Why when I tried to install a package called CustomDrawn on Lazarus, I cannot add any component to Form. I don't see the components called TCDButton, TCDEdit etc. Is it like, they don't really exist? So it is not enough to use the "use" unit, but it is needed to install the package. I thought it should print some error like unit not defined or something in the way. But I am asking now why I don't see the components when I would like to add them to form.

Also the previous question was... what was wrong with my code.

I am just trying to understand how the things work. If just swapping to completely new code/program, I can learn nothing. It took me like one day to half understand the code, but still not working as I expected. So you can produce like one program one day but my PC and I we are way too slow to grasp it.

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: How to install image library for freepascal on linux?
« Reply #51 on: August 16, 2023, 01:54:34 pm »
What is the benefit to run a virtual machine on a physical machine that is not good enough to run the virtual machine smooth?
Why you make your work more complicated than it needed to be?
Just install Lazarus with its cross compilers on your base machine and be happy using it without any lags or installation problems etc... ?
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

TRon

  • Hero Member
  • *****
  • Posts: 4377
Re: How to install image library for freepascal on linux?
« Reply #52 on: August 16, 2023, 02:11:35 pm »
In addition to KodeZwerg you could also opt for dual-booting.

But honestly I do not quite get it as I used to run VBox on windows XP on a core2duo (e5800) from ages ago and that ran just fine (though not the fastest in any way). It just has to do with your configuration (memory, bios settings) and not expecting to run something like KDE (openbox, xfce or qt are better suited for slow configurations). Puppies are great for the Linux job.
Today is tomorrow's yesterday.

Handoko

  • Hero Member
  • *****
  • Posts: 5530
  • My goal: build my own game engine using Lazarus
Re: How to install image library for freepascal on linux?
« Reply #53 on: August 16, 2023, 02:22:05 pm »
To be able to run a virtual machine smoothly, one needs to have good multicore processor with plenty of RAM. The prices of computer memory have been dropped significantly. A 8 GB DDR3 used RAM costs less than US$ 10 in where I live. Maybe OP needs to add more RAM.

Why when I tried to install a package called CustomDrawn on Lazarus, I cannot add any component to Form. I don't see the components called TCDButton, TCDEdit etc.

I do not use CustomDrawn, but last time I tried it, it was buggy and unmaintained.

I just tried to install the package and it really appeared on the component tab. See the attached screenshot.  If you're having problem finding a component, you can use this shortcut:
Ctrl + Alt + P = find a component

If the component cannot be found, you probably haven't installed it correctly. You can install CustomDrawn package by doing this:
Lazarus main menu > Package > Install/Uninstall Packages > in the right panel panel, select: customdrawn 0.0 > Install Selection > Save and rebuild IDE > wait some minutes then your Lazarus will be restarted.

Also the previous question was... what was wrong with my code.

Which one?

If you meant the TCDEdit error, you probably haven't installed the CustomDrawn package correctly.

If you meant TImage.width=800 issue, the problem probably caused by  Image1.Align := alClient and/or Image1.Stretch  := True. Instead, you should disable the align and use StretchDraw command. You can learn how to use StretchDraw by looking into the demo CenterText.zip I posted recently.


-----

I think the main problem you have is, you're doing thing the hard way.

Lazarus can run on WinXP, Mint and many others. You don't need VirtualBox. Of course you can run Lazarus in a virtual machine, but you will have performance issue, unless you have a high-end machine with plenty of memory.

Writing a text with transparent background is relatively easy. You can put a semi transparent rectangle + TLabel. But you tried to use a TEdit or CustomDrawn control or TJvMemo. You might succeed by using those components, but that will introduce many new problems.

Try the CenterText demo I posted recently. That solves many of your problems. You can forget CustomDrawn, TJvMemo, etc. There you can learn how to draw a semi transparent rectangle, center text, stretching image, etc.
« Last Edit: August 16, 2023, 02:30:03 pm by Handoko »

barracuda

  • Full Member
  • ***
  • Posts: 133
Re: How to install image library for freepascal on linux?
« Reply #54 on: August 16, 2023, 02:35:42 pm »
I cannot add memory to Windows XP, having 2.5GB. I will better close the Firefox to start Linux. It can be slow it I run both. The most stressing factor is when VMWare starts for no reason to open Browser in Windows XP (to open some url). This kills the memory because I cannot run WIN XP Firefox + VM with Firefox and Lazarus together. Do you see the Component of CustomDraw in Display/Components? I do not. I will check the thing you show me on screenshot, if I will find it.

Edit: Using filter I have found only TCustomDrawGrid or CustomDrawGrid, not TCustomDraw ... I thought it will show me the components of TCD...

Now I am reading I can install Lazarus on Windows. Windows XP? Really?

"If you meant the TCDEdit error, you probably haven't installed the CustomDrawn package correctly."
It did not restarted automatically. But after restart I still don't see it in components.

I was trying TEdit or TCDEdit because I want to edit the title of the image manually just after viewing the image.

Edit2:
I see the TCustomDraw is ready for install, not installed. I dunno why it is not installed. I noticed it just now.
« Last Edit: August 16, 2023, 02:53:26 pm by barracuda »

Handoko

  • Hero Member
  • *****
  • Posts: 5530
  • My goal: build my own game engine using Lazarus
Re: How to install image library for freepascal on linux?
« Reply #55 on: August 16, 2023, 04:02:08 pm »
Done.

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, ExtCtrls, StdCtrls, LCLType;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Button1: TButton;
  16.     Edit1: TEdit;
  17.     Image1: TImage;
  18.     procedure Button1Click(Sender: TObject);
  19.     procedure Edit1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
  20.     procedure FormCreate(Sender: TObject);
  21.     procedure Image1DblClick(Sender: TObject);
  22.   private
  23.     Title: string;
  24.     Clickable: TRect;
  25.     procedure LoadImage;
  26.     procedure CalculateClickable;
  27.     procedure DrawCenterRectangle;
  28.     procedure WriteCenterText;
  29.   end;
  30.  
  31. var
  32.   Form1: TForm1;
  33.  
  34. implementation
  35.  
  36. {$R *.lfm}
  37.  
  38. { TForm1 }
  39.  
  40. procedure TForm1.LoadImage;
  41. const
  42.   ImageFile = 'img.png';
  43. var
  44.   Tmp: TPicture;
  45. begin
  46.   Image1.SetBounds(0, 0, Width, Height);
  47.   Image1.Picture.Clear;
  48.   Tmp := TPicture.Create;
  49.   try
  50.     Tmp.LoadFromFile(ImageFile);
  51.     Image1.Canvas.StretchDraw(ClientRect, Tmp.Bitmap);
  52.   finally
  53.     Tmp.Free;
  54.   end;
  55. end;
  56.  
  57. procedure TForm1.CalculateClickable;
  58. var
  59.   W, H: Integer;
  60. begin
  61.   H := Image1.Canvas.TextHeight(Title);
  62.   W := Image1.Canvas.TextWidth(Title);
  63.   Clickable.Left   := (Width - W)  div 2;
  64.   Clickable.Top    := (Height - H) div 2;
  65.   Clickable.Width  := W;
  66.   Clickable.Height := H;
  67.   Clickable.Inflate(2, 0);
  68. end;
  69.  
  70. procedure ChangeColor(var Data: Byte);
  71. const
  72.   Shift = 128; // 50% white
  73. var
  74.   Temp: Integer;
  75. begin
  76.   Temp := Data + Shift;
  77.   if (Temp > 255) then Temp := 255
  78.     else
  79.       if (Temp < 0) then Temp := 0;
  80.   Data := Temp;
  81. end;
  82.  
  83. procedure TForm1.DrawCenterRectangle;
  84. const
  85.   BoxWidth  = 100;
  86.   BoxHeight = 20;
  87. var
  88.   ScanData:       PRGBQuad;
  89.   X, Y:           Integer;
  90. begin
  91.  
  92.   // Draw semi transparent rectangle
  93.   Image1.Picture.Bitmap.BeginUpdate;
  94.   for Y := Clickable.Top to Clickable.Bottom do
  95.   begin
  96.     ScanData := Image1.Picture.Bitmap.ScanLine[Y];
  97.     for X:= 0 to (Image1.Picture.Bitmap.Width-1) do
  98.     begin
  99.       if (X >= Clickable.Left) then
  100.       begin
  101.         ChangeColor(ScanData^.rgbRed);
  102.         ChangeColor(ScanData^.rgbGreen);
  103.         ChangeColor(ScanData^.rgbBlue);
  104.       end;
  105.       Inc(ScanData);
  106.       if X >= Clickable.Right then Break;
  107.     end;
  108.   end;
  109.   Image1.Picture.Bitmap.EndUpdate;
  110.  
  111. end;
  112.  
  113. procedure TForm1.WriteCenterText;
  114. begin
  115.   Image1.Canvas.Brush.Style := bsClear;
  116.   Image1.Canvas.Font.Color  := clBlack;
  117.   Image1.Canvas.TextOut(Clickable.Left+2, Clickable.Top, Title);
  118. end;
  119.  
  120. procedure TForm1.Button1Click(Sender: TObject);
  121. begin
  122.   LoadImage;
  123.   CalculateClickable;
  124.   DrawCenterRectangle;
  125.   WriteCenterText;
  126. end;
  127.  
  128. procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState
  129.   );
  130. begin
  131.   case Key of
  132.     VK_ESCAPE:
  133.       begin
  134.         Button1.Visible := True;
  135.         Edit1.Visible   := False;
  136.       end;
  137.     VK_RETURN:
  138.       begin
  139.         if Edit1.Text <> '' then
  140.         begin
  141.           Title := Edit1.Text;
  142.           CalculateClickable;
  143.           LoadImage;
  144.           CalculateClickable;
  145.           DrawCenterRectangle;
  146.           WriteCenterText;
  147.         end;
  148.         Button1.Visible := True;
  149.         Edit1.Visible   := False;
  150.       end;
  151.   end;
  152. end;
  153.  
  154. procedure TForm1.FormCreate(Sender: TObject);
  155. begin
  156.   Title         := 'Double click here';
  157.   Edit1.Visible := False;
  158. end;
  159.  
  160. procedure TForm1.Image1DblClick(Sender: TObject);
  161. var
  162.   MouseXY: TPoint;
  163. begin
  164.   MouseXY := ScreenToClient(Mouse.CursorPos);
  165.   if not(Clickable.Contains(MouseXY)) then Exit;
  166.   Button1.Visible := False;
  167.   Edit1.Left      := Clickable.Left;
  168.   Edit1.Top       := Clickable.Top;
  169.   Edit1.Width     := Clickable.Width;
  170.   Edit1.Text      := Title;
  171.   Edit1.Visible   := True;
  172.   Edit1.SetFocus;
  173.   Edit1.SelectAll;
  174. end;
  175.  
  176. end.

To make it easier to understand, I do not include the code for proportional stretching, I believe you can add it yourself.

- Title (line #23) can be edited by double clicking the area defined by Clickable (line #24)
- Stretching the image is done by the StretchDraw command, see line #51
- To change the position of the image (for example centering), you need to change the line #46
- To do proportional stretching, you need the change the Width and/or Height in the line #46
- To change the transparency of the rectangle, see line #72
- Double click the rectangle, a TEdit will appear, see line #160
- To conform the editing, press Enter, see line #137
« Last Edit: August 16, 2023, 05:01:30 pm by Handoko »

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: How to install image library for freepascal on linux?
« Reply #56 on: August 16, 2023, 05:43:24 pm »
This does not work on Windows.
Code: Pascal  [Select][+][-]
  1.   H := Image1.Canvas.TextHeight(Title);
  2.   W := Image1.Canvas.TextWidth(Title);
a quick fix:
Code: Pascal  [Select][+][-]
  1.   Image1.Canvas.GetTextSize(Title, W, H);

The rectangle drawing does not work either.
No quick fix by me.
When I make window bigger no rectangle(s) appear at all.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

barracuda

  • Full Member
  • ***
  • Posts: 133
Re: How to install image library for freepascal on linux?
« Reply #57 on: August 16, 2023, 06:35:37 pm »
What is the benefit to run a virtual machine on a physical machine that is not good enough to run the virtual machine smooth?
Why you make your work more complicated than it needed to be?
Just install Lazarus with its cross compilers on your base machine and be happy using it without any lags or installation problems etc... ?

My VM just crashed.

I just stopped using Windows. I used it only for few programs. OK I can try it, but then it wont be able to work in Linux. So what's the point? My Images which I downloaded are on linux. My idea was to run the viewer and then for renaming to call a shell script. Why should I install these things on Windows when I try to learn linux and move to linux. So I installed linux and I have to start it to download images from Firefox and then to run the terminal, bash or commands, then I have to run the viewer and rename files. And yes, I will move the files to NTFS disks to free Home partion anyway, but I cannot work in Firefox on Win XP.

Handoko

  • Hero Member
  • *****
  • Posts: 5530
  • My goal: build my own game engine using Lazarus
Re: How to install image library for freepascal on linux?
« Reply #58 on: August 16, 2023, 07:18:15 pm »
Thank you KodeZwerg for reporting the bugs.

The bugs has been fixed in CenterText3. Tested on Ubuntu Mate 23.04 and Win7. Those issues were caused by how Windows and Linux treat PixelFormat.

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, ExtCtrls, StdCtrls, LCLType;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Button1: TButton;
  16.     Edit1: TEdit;
  17.     Image1: TImage;
  18.     procedure Button1Click(Sender: TObject);
  19.     procedure Edit1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
  20.     procedure FormCreate(Sender: TObject);
  21.     procedure Image1DblClick(Sender: TObject);
  22.   private
  23.     Title: string;
  24.     Clickable: TRect;
  25.     procedure LoadImage;
  26.     procedure CalculateClickable;
  27.     procedure DrawCenterRectangle;
  28.     procedure WriteCenterText;
  29.   end;
  30.  
  31. var
  32.   Form1: TForm1;
  33.  
  34. implementation
  35.  
  36. {$R *.lfm}
  37.  
  38. { TForm1 }
  39.  
  40. procedure TForm1.LoadImage;
  41. const
  42.   ImageFile = 'img.png';
  43. var
  44.   Tmp: TPicture;
  45. begin
  46.   Image1.SetBounds(0, 0, Width, Height);
  47.   Tmp := TPicture.Create;
  48.   try
  49.     Tmp.LoadFromFile(ImageFile);
  50.     Image1.Canvas.StretchDraw(ClientRect, Tmp.Bitmap);
  51.   finally
  52.     Tmp.Free;
  53.   end;
  54. end;
  55.  
  56. procedure TForm1.CalculateClickable;
  57. var
  58.   W, H: Integer;
  59. begin
  60.   Image1.Canvas.GetTextSize(Title, W, H);
  61.   Clickable.Left   := (Width - W)  div 2;
  62.   Clickable.Top    := (Height - H) div 2;
  63.   Clickable.Width  := W;
  64.   Clickable.Height := H;
  65.   Clickable.Inflate(2, 0);
  66. end;
  67.  
  68. procedure ChangeColor(var Data: Byte);
  69. const
  70.   Shift = 128; // 50% white
  71. var
  72.   Temp: Integer;
  73. begin
  74.   Temp := Data + Shift;
  75.   if (Temp > 255) then Temp := 255
  76.     else
  77.       if (Temp < 0) then Temp := 0;
  78.   Data := Temp;
  79. end;
  80.  
  81. procedure TForm1.DrawCenterRectangle;
  82. const
  83.   BoxWidth  = 100;
  84.   BoxHeight = 20;
  85. var
  86.   ScanData:  Pointer;
  87.   Data24bit: PRGBTriple absolute ScanData;
  88.   Data32bit: PRGBQuad   absolute ScanData;
  89.   X, Y:       Integer;
  90. begin
  91.   Image1.Picture.Bitmap.BeginUpdate;
  92.   for Y := Clickable.Top to Clickable.Bottom do
  93.   begin
  94. {$ifdef Windows}
  95.   case Image1.Picture.Bitmap.PixelFormat of
  96.     pf24bit:
  97.       ScanData := Image1.Picture.Bitmap.ScanLine[Y] + Clickable.Left * 3;
  98.     pf32bit:
  99.       ScanData := Image1.Picture.Bitmap.ScanLine[Y] + Clickable.Left * 3;
  100.   end;
  101. {$endif}
  102. {$ifdef Linux}
  103.     ScanData := Image1.Picture.Bitmap.ScanLine[Y] + Clickable.Left * 4;
  104. {$endif}
  105.     for X:= 0 to Clickable.Width do
  106.     begin
  107.       case Image1.Picture.Bitmap.PixelFormat of
  108.         pf24bit:
  109.           begin
  110.             begin
  111.               ChangeColor(Data24bit^.rgbtRed);
  112.               ChangeColor(Data24bit^.rgbtGreen);
  113.               ChangeColor(Data24bit^.rgbtBlue);
  114.             end;
  115. {$ifdef Windows}
  116.             Inc(ScanData, 3);
  117. {$endif}
  118. {$ifdef Linux}
  119.             Inc(ScanData, 4);
  120. {$endif}
  121.           end;
  122.         pf32bit:
  123.           begin
  124.             begin
  125.               ChangeColor(Data32bit^.rgbRed);
  126.               ChangeColor(Data32bit^.rgbGreen);
  127.               ChangeColor(Data32bit^.rgbBlue);
  128.             end;
  129.             Inc(ScanData, 4);
  130.           end;
  131.       end;
  132.     end;
  133.   end;
  134.   Image1.Picture.Bitmap.EndUpdate;
  135. end;
  136.  
  137. procedure TForm1.WriteCenterText;
  138. begin
  139.   Image1.Canvas.Brush.Style := bsClear;
  140.   Image1.Canvas.Font.Color  := clBlack;
  141.   Image1.Canvas.TextOut(Clickable.Left+2, Clickable.Top, Title);
  142. end;
  143.  
  144. procedure TForm1.Button1Click(Sender: TObject);
  145. begin
  146.   LoadImage;
  147.   CalculateClickable;
  148.   DrawCenterRectangle;
  149.   WriteCenterText;
  150. end;
  151.  
  152. procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState
  153.   );
  154. begin
  155.   case Key of
  156.     VK_ESCAPE:
  157.       begin
  158.         Button1.Visible := True;
  159.         Edit1.Visible   := False;
  160.       end;
  161.     VK_RETURN:
  162.       begin
  163.         if Edit1.Text <> '' then
  164.         begin
  165.           Title := Edit1.Text;
  166.           CalculateClickable;
  167.           LoadImage;
  168.           CalculateClickable;
  169.           DrawCenterRectangle;
  170.           WriteCenterText;
  171.         end;
  172.         Button1.Visible := True;
  173.         Edit1.Visible   := False;
  174.       end;
  175.   end;
  176. end;
  177.  
  178. procedure TForm1.FormCreate(Sender: TObject);
  179. begin
  180.   Title         := 'Double click here';
  181.   Edit1.Visible := False;
  182. end;
  183.  
  184. procedure TForm1.Image1DblClick(Sender: TObject);
  185. var
  186.   MouseXY: TPoint;
  187. begin
  188.   MouseXY := ScreenToClient(Mouse.CursorPos);
  189.   if not(Clickable.Contains(MouseXY)) then Exit;
  190.   Button1.Visible := False;
  191.   Edit1.Left      := Clickable.Left;
  192.   Edit1.Top       := Clickable.Top;
  193.   Edit1.Width     := Clickable.Width;
  194.   Edit1.Text      := Title;
  195.   Edit1.Visible   := True;
  196.   Edit1.SetFocus;
  197.   Edit1.SelectAll;
  198. end;
  199.  
  200. end.

- Title (line #23) can be edited by double clicking the area defined by Clickable (line #24)
- Stretching the image is done by the StretchDraw command, see line #50
- To change the position of the image (for example centering), you need to change the line #46
- To do proportional stretching, you need the change the Width and/or Height in the line #46
- To change the transparency of the rectangle, see line #70
- Double click the rectangle, a TEdit will appear, see line #184
- To conform the editing, press Enter, see line #161

Bug fixes:
- Line #60, suggested by KodeZwerg to make it runs correctly on Windows
- Line #94..104, Linux always uses 4 bytes per pixel for StretchDrawed images even on pf24bit
- Line #115..120, Linux always uses 4 bytes per pixel for StretchDrawed images even on pf24bit

~edit~
Line #99 should be:  ...  + Clickable.Left * 4;
« Last Edit: August 16, 2023, 08:50:05 pm by Handoko »

barracuda

  • Full Member
  • ***
  • Posts: 133
Re: How to install image library for freepascal on linux?
« Reply #59 on: August 16, 2023, 07:39:34 pm »
So on WinXP, the Lazarus 2.2.6 installed. I found the Debugger config on C: and fpc config on P: but the problem is that the Lazarus reports the the fpc config is missing. It is not. It is there with the fpc.exe in correct directory where is Lazarus installed.

Quote
On Win XP I've installed Lazarus 2.2.6 fpc 3.2.2.
I got some errors missing configuration file for fpc. A project is using target OS=win32 and CPU=i386
system.ppu for this system was not found in folder bin of fpc. Make sure fpc is correctly install for this target and that fpc.cfg contains correct directories.

Next error is Cannot find component TACSVolueQuery. Its not registered with RegisterClass and lfm file not found. This is needed by unit ... some path out of Lazarus install folder, some audio demo program.

Next problem is I need to configure it to black background.


 

TinyPortal © 2005-2018