Recent

Author Topic: [SOLVED] tachart legend colorbar  (Read 2073 times)

apeoperaio

  • Full Member
  • ***
  • Posts: 158
[SOLVED] tachart legend colorbar
« on: September 11, 2014, 11:15:02 am »
I posted an analogous message on the forum (Programming »  LCL). Since the problem was not solved I try to post on the correct forum place.

I checked the legend demo but I got black squares instead of the text on the legend (Lazarus 1.2.5 r45573M FPC 2.6.4 i386-win32-win32/win64). See attached image.

The modifications to TAChart  (and the demo too, in order to have a legend colorbar) have been merged to 1.2.4:

r44583    TAChart   Add event OnDrawLegend to TChart
r44588    TAChart   add code to legenddemo to demonstrate the ownerdrawn legend, fix some layout issues.


« Last Edit: October 22, 2014, 01:05:50 pm by apeoperaio »

wp

  • Hero Member
  • *****
  • Posts: 6336
Re: tachart legend colorbar
« Reply #1 on: September 11, 2014, 01:37:07 pm »
Yes it is a good idea to post questions on TAChart in its own board.

I don't see the issue on trunk, but I do see it on 1.2.4. By chance, your issue was fixed along with modifications for supporting BiDiMode which have not yet been backported to the release version. There is a merge-request now for 1.2.6.

In the meantime you can do this:
  • Open tadrawercanvas.pas (in tachart folder)
  • Find the procedure TADrawerCanvas.SimpleTextOut() and replace the entire procedure by the following procedure
  • Save
  • Recompile TAChartLazarusPkg
  • I tested with 1.2.4 which compiles the modification, and the demo runs fine.
Code: [Select]
procedure TCanvasDrawer.SimpleTextOut(AX, AY: Integer; const AText: String);

  procedure DrawSimpleText(ACanvas: TCanvas; x, y: Integer; const txt: String);
  // add right-to-left mode. Cannot use TextOut since it does not respect TextStyle
  var
    r: TRect;
    ts: TTextStyle;
  begin
    ts := ACanvas.TextStyle;
    ts.RightToLeft := false; //FRightToLeft;  -- wp: removed here because variable is unknown in 1.2.4
    ts.Clipping := false;
    r := Bounds(x, y, 1, 1);
    ACanvas.TextRect(r, x, y, txt, ts);
  end;

  procedure DrawXorText;
  var
    bmp: TBitmap;
    p, ext, bmpSize: TPoint;
    a: Double;
  begin
    ext := GetCanvas.TextExtent(AText);
    a := OrientToRad(GetCanvas.Font.Orientation);
    bmpSize := MeasureRotatedRect(ext, a);
    p := bmpSize div 2 - RotatePoint(ext div 2, -a);

    bmp := TBitmap.Create;
    try
      bmp.SetSize(bmpSize.X, bmpSize.Y);
      bmp.Canvas.Brush.Style := bsClear;
      bmp.Canvas.Font := GetCanvas.Font;
      bmp.Canvas.Font.Color := clWhite;
      DrawSimpleText(bmp.Canvas, p.X, p.Y, AText);
      bmp.Canvas.Pen.Color := clWhite;
      BitBlt(
        GetCanvas.Handle, AX - p.X, AY - p.Y, bmpSize.X, bmpSize.Y,
        bmp.Canvas.Handle, 0, 0, SRCINVERT);
    finally
      bmp.Free;
    end;
  end;

begin
  if FXor then
    DrawXorText
  else
    DrawSimpleText(GetCanvas, AX, AY, AText);
end;

Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

apeoperaio

  • Full Member
  • ***
  • Posts: 158
[SOLVED] Re: tachart legend colorbar
« Reply #2 on: September 12, 2014, 12:38:35 pm »
thanks!
« Last Edit: October 22, 2014, 01:05:00 pm by apeoperaio »