Jump to content
DezsoSajer

Only one TImage32Panel showing texts

Recommended Posts

Hi,

I am creating an indicator of a machine, in the style of a PFD (Primary Flight Display) using the TImage32 library.

I finished the work, and I need 2 of these indicators, so I added the second one to my form (I am using a panel to draw the image).

Strangly, the second one is not showing the texts.

I would like to ask some pointers where I should check the source of the problem.

I swapped the order of creation, and the problem swapped, too. So the first created works, but not 2nd.

Thank you

Screenshot 2022-10-04 170359.png

Share this post


Link to post
Posted (edited)

I'm not sure why you're having problems.

I've attached a very simple test that shows text drawing on 2 TImage32Panel controls.

 

image32.thumb.png.299bce756e87770b5777a2629f89c692.png

 

procedure TForm1.FormCreate(Sender: TObject);
begin
  fc := TFontCache.Create(FontManager.Load('Arial'), dpiAware(20));
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  fc.Free;
end;

procedure TForm1.FormResize(Sender: TObject);
begin
  with Image32Panel1 do
  begin
    Width := self.ClientWidth div 2; //Align = alLeft
    image.SetSize(InnerClientRect.Width,InnerClientRect.Height);
    DrawLine(image, Rectangle(0,0,image.Width, image.Height), 10, clRed32, esPolygon);
    DrawText(Image, Image.Bounds, 'This is Panel1', taCenter, tvaMiddle, fc);
  end;
  with Image32Panel2 do
  begin
    //Align = alClient
    image.SetSize(InnerClientRect.Width,InnerClientRect.Height);
    DrawLine(image, Rectangle(0,0,image.Width, image.Height), 10, clRed32, esPolygon);
    DrawText(Image, Image.Bounds, 'This is Panel2', taCenter, tvaMiddle, fc);
  end;
end;

 

img32_test.zip

Edited by angusj

Share this post


Link to post
Posted (edited)

Hi,

Thanks very much for the project.

I have tested, and it worked on mine PC, too.

However, when I modified it to the same way I have in my project (moved it to a unit and created a class), the same thing happened.

 

ImageTest.png

Main unit:
 

unit main;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls,Unit1;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private

  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  Image32Panel1: testclass;
  Image32Panel2: testclass;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin

  Image32Panel1:=testclass.Create(Self,0);
  Image32Panel2:=testclass.Create(Self,ClientWidth div 2);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  Image32Panel1.Free;
  Image32Panel2.Free;
end;

end.

Class unit

unit Unit1;

interface

uses  System.Classes,Img32.Panels,Img32, Img32.Vector, Img32.Draw, Img32.Text,VCL.Controls;

type testclass=class
  private
    FImagePanel:TImage32Panel;
    fc: TFontCache;
  public
    constructor Create(AOwner:TComponent;LeftPos:integer);
    destructor Destroy;
end;
implementation

{ testclass }

constructor testclass.Create(AOwner:TComponent;LeftPos:integer);
begin
  fc := TFontCache.Create(FontManager.Load('Arial'), dpiAware(20));
  FImagePanel:=TImage32Panel.Create(AOwner);
  FImagePanel.Parent:=AOwner As TWinControl;
  with FImagePanel do
  begin
    Left:=LeftPos;
    Width := FImagePanel.Parent.ClientWidth div 2;
    image.SetSize(InnerClientRect.Width,InnerClientRect.Height);
    DrawLine(image, Rectangle(0,0,image.Width, image.Height), 10,
      clRed32, esPolygon);
    Img32.Text.DrawText(Image, Image.Bounds,
      'This is TImagePanel Panel1', taCenter, tvaMiddle, fc);
  end;
end;

destructor testclass.Destroy;
begin
  FImagePanel.Free;
  fc.Free;
end;

end.

img32_test.zip

Edited by DezsoSajer

Share this post


Link to post
Posted (edited)

Yes, the problem is/was that you were trying to load the same font twice ...

FontManager.Load('Arial')

and this was failing.

Strictly speaking this wasn't a bug but logically it makes sense to return the first loaded font when a fontname is supplied multiple times.

And I've just updated the GitHub repository to address this.

https://github.com/AngusJohnson/Image32

 

Thanks again for the feedback.

 

ps: It's better to raise issues with Image32 here:

https://github.com/AngusJohnson/Image32/issues OR

https://github.com/AngusJohnson/Image32/discussions

 

Edited by angusj

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×