Recent

Author Topic: Label with multiple lines with Orientation ≠ 0  (Read 871 times)

CM630

  • Hero Member
  • *****
  • Posts: 1674
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Label with multiple lines with Orientation ≠ 0
« on: March 17, 2026, 01:03:55 pm »
TLabel does not support multiple lines when Label1.Font.Orientation ≠ 0.
I need a control that supports multiple lines with the following orientations (0; 900; 1800 and 2700). It will not hurt if it supports other angles, too.
It shall also support transparency (preferably adjustable degree of transparency).
There is TChartAxisTitle which is a part of Lazarus, but it does not work standalone.
What else could I use? I prefer something internal in Lazarus.

EDIT1: I tried ZCLabel. Multiline with .Orientation = 900 works even worse than in TLabel.
« Last Edit: March 17, 2026, 02:32:39 pm by CM630 »
Лазар 4,4 32 bit (sometimes 64 bit); FPC3,2,2

wp

  • Hero Member
  • *****
  • Posts: 13482
Re: Label with multiple lines with Orientation ≠ 0
« Reply #1 on: March 17, 2026, 07:56:42 pm »
I remember when I implemented the rotation of TLabel I had enormous trouble to rotate the individual lines, and therefore I disabled linebreaks for non-horizontal text. Both DrawText and TCanvas.TextRect rotate the multiline text such that the lines alignment relative to each other gets lost. To solve this it would be required to calculate the text start points of each line and handle the lines one by one. But for this purpose, one should have access to the individual wrapped strings. In the grid of fpSpreadsheet, this was solved by calculating the line-breaks manually, and this was justified due to the "rich-text" formatting of cell text. But in TLabel, this seems to me some kind of overkill. Any idea?

A hack would be to put the label's caption into a hidden TMemo having the same size as the label, let the memo do the work-breaks and then access the wrapped lines from its Lines property. But this appear too ugly to me...


CM630

  • Hero Member
  • *****
  • Posts: 1674
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: Label with multiple lines with Orientation ≠ 0
« Reply #2 on: March 18, 2026, 08:52:29 am »
I decided to try to use some AI (I have not tried to draw graphics on anything else but Applesoft basic when I was a child) to create a label.
The first issue that I cannot overcome is the transparency.
TGraphicControl is transparent, but stays under other controls.
TCustomControl stays above the other controls but it is not transparent.

CopyRect and BitBlt took me nowhere.
And I am seeking for a multi-platform solution.
Лазар 4,4 32 bit (sometimes 64 bit); FPC3,2,2

jamie

  • Hero Member
  • *****
  • Posts: 7651
Re: Label with multiple lines with Orientation ≠ 0
« Reply #3 on: March 18, 2026, 10:46:24 am »
create a bitmap write on it blit it to the screen using transparent draw
The only true wisdom is knowing you know nothing

CM630

  • Hero Member
  • *****
  • Posts: 1674
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: Label with multiple lines with Orientation ≠ 0
« Reply #4 on: March 18, 2026, 10:52:12 am »
This handles the transparency issue, but:
1. I does not look like multi-platform to me.
2. It does not look properly in design mode.

Code: Pascal  [Select][+][-]
  1. unit CustomControl1;
  2.  
  3. {$mode ObjFPC}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs,
  9.   LCLIntf, LCLType, LMessages, Types;
  10.  
  11. type
  12.   TCustomControl1 = class(TCustomControl)
  13.   private
  14.     procedure CMTextChanged(var Message: TLMessage); message CM_TEXTCHANGED;
  15.     procedure CMFontChanged(var Message: TLMessage); message CM_FONTCHANGED;
  16.     procedure WMMove(var Message: TLMessage); message LM_MOVE;
  17.     function GetTextSize: TSize;
  18.   protected
  19.     procedure Paint; override;
  20.     procedure Resize; override;
  21.   public
  22.     constructor Create(AOwner: TComponent); override;
  23.   published
  24.     property Text;
  25.     property Font;
  26.     property Align;
  27.     property Anchors;
  28.     property Visible;
  29.     property OnClick;
  30.     property OnDblClick;
  31.   end;
  32.  
  33. procedure Register;
  34.  
  35. implementation
  36.  
  37. constructor TCustomControl1.Create(AOwner: TComponent);
  38. begin
  39.   inherited Create(AOwner);
  40.   ControlStyle := ControlStyle - [csOpaque];
  41.   Width := 100;
  42.   Height := 50;
  43.   DoubleBuffered := False;
  44. end;
  45.  
  46. procedure TCustomControl1.CMTextChanged(var Message: TLMessage);
  47. begin
  48.   Invalidate;
  49. end;
  50.  
  51. procedure TCustomControl1.CMFontChanged(var Message: TLMessage);
  52. begin
  53.   Invalidate;
  54. end;
  55.  
  56. procedure TCustomControl1.WMMove(var Message: TLMessage);
  57. begin
  58.   inherited;
  59.   Invalidate;
  60. end;
  61.  
  62. procedure TCustomControl1.Resize;
  63. begin
  64.   inherited Resize;
  65.   Invalidate;
  66. end;
  67.  
  68. procedure TCustomControl1.Paint;
  69. var
  70.   i: Integer;
  71.   R: TRect;
  72. begin
  73.   if Parent = nil then Exit;
  74.  
  75.   Parent.Perform(LM_ERASEBKGND, Canvas.Handle, 0);
  76.  
  77.   for i := 0 to Parent.ControlCount - 1 do
  78.   begin
  79.     if (Parent.Controls[i] = Self) then Break;
  80.  
  81.     if Parent.Controls[i].Visible then
  82.     begin
  83.       R := Parent.Controls[i].BoundsRect;
  84.       SaveDC(Canvas.Handle);
  85.       try
  86.         // shift coordinate system
  87.         SetWindowOrgEx(Canvas.Handle, Left-Parent.Controls[i].left , Top-Parent.Controls[i].top, nil);
  88.  
  89.         Parent.Controls[i].Perform(LM_PAINT, Canvas.Handle, 0);
  90.       finally
  91.         RestoreDC(Canvas.Handle, -1);
  92.       end;
  93.     end;
  94.   end;
  95.  
  96.   Brush.Style := bsClear;
  97.   Canvas.TextOut(10, 10, Text);
  98. end;
  99.  
  100. procedure Register;
  101. begin
  102.   RegisterComponents('Additional', [TCustomControl1]);
  103. end;
  104.  
  105. end.


create a bitmap write on it blit it to the screen using transparent draw
Thanks for the advice, but as I said I have never drawn a graphic on a non 8-bit computer, at least not until 2 or 3 weeks ago, when I uses AI to draw a zig-zag.
This does not mean that I will not draw another line until I die, but graphics are completely out of my scope.

EDIT: The sample does not work in Linux.
If I get it right I shall copy what is under the Label into the canvas of the label.

ControlStyle - [csOpaque] + [csParentBackground]; does not help.
« Last Edit: March 18, 2026, 02:29:59 pm by CM630 »
Лазар 4,4 32 bit (sometimes 64 bit); FPC3,2,2

jamie

  • Hero Member
  • *****
  • Posts: 7651
Re: Label with multiple lines with Orientation ≠ 0
« Reply #5 on: March 19, 2026, 01:12:52 am »
Load the BRGABitmap package and the BGRA-CONTROLS package.

there sits a control "BCLeaEngrave" control that you can print an any angle and it allows you to do shadowing, fuzzy text etc.

Jamie
The only true wisdom is knowing you know nothing

wp

  • Hero Member
  • *****
  • Posts: 13482
Re: Label with multiple lines with Orientation ≠ 0
« Reply #6 on: March 19, 2026, 11:36:48 am »
Here is code to wrap some text into multiple lines and to draw it as rotated lines on a canvas. Now the alignment of the individual lines is correct. Maybe this should be added to TCustomLabel. Since only the text is drawn the output is transparent (in the sense that the background shines through).
« Last Edit: March 19, 2026, 03:06:14 pm by wp »

CM630

  • Hero Member
  • *****
  • Posts: 1674
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: Label with multiple lines with Orientation ≠ 0
« Reply #7 on: March 19, 2026, 02:50:46 pm »
Thanks for the assistance.
Meanwhile I found a better way to handle the issue (without and external label).

...Maybe this should be added to TCustomLabel...)
+1, the current situation is not very nice.
The transparency issue is not solved, but labels will be more complete than now.
« Last Edit: March 20, 2026, 08:01:48 am by CM630 »
Лазар 4,4 32 bit (sometimes 64 bit); FPC3,2,2

 

TinyPortal © 2005-2018