Recent

Author Topic: Deleting TextOnPic  (Read 360 times)

Profi_Noob

  • Newbie
  • Posts: 1
Deleting TextOnPic
« on: February 21, 2021, 09:31:44 pm »
Hey there.
My program includes a highscore list. Since I want a transparent background, I'm using the TextOnPic code from https://forum.lazarus.freepascal.org/index.php?topic=38143.0

Now the problem. The txt that contains the data can get extended if a new highscore is made. But if I go back to the highscore list without restarting the program, the old list get's overlaid with the updated list. Is there a way to delete the previous list or a better way to display the highscores?

Greetings

speter

  • Full Member
  • ***
  • Posts: 188
Re: Deleting TextOnPic
« Reply #1 on: February 22, 2021, 01:42:00 am »
If you are drawing on a canvas (like a tpaintbox) I think you could include another paintbox on top of the first - draw the highscore material on the "upper" canvas - and redraw that canvas if the scores change. Similar to the layers in a paint program...

I also think you could use this idea if the main canvas is on an image.

cheers
S.
I climbed mighty mountains, and saw that they were actually tiny foothills. :)

Laz 2.0.10 / FPC 3.2.0 / Windows 10 (64bit)

Handoko

  • Hero Member
  • *****
  • Posts: 4195
  • My goal: build my own game engine using Lazarus
Re: Deleting TextOnPic
« Reply #2 on: February 22, 2021, 02:26:27 am »
Since I want a transparent background, I'm using the TextOnPic ...

The TextOnPic basically is just a TImage and a TLabel. You don't need to use it, instead you can just drop a TImage and then a TLabel above it. So you can change the text whenever you like. You cannot change the text using TextOnPic because it will create a new TLabel every time you call the function.

Alternatively, you can draw on the canvas directly. Not too hard but you need to code everything yourself. But you can have more control about it.

I'm not fully sure what you want, but if you want to have some change-able text above an image, try this:

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;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Button1: TButton;
  16.     Image1: TImage;
  17.     Label1: TLabel;
  18.     Timer1: TTimer;
  19.     procedure Button1Click(Sender: TObject);
  20.     procedure FormCreate(Sender: TObject);
  21.     procedure Timer1Timer(Sender: TObject);
  22.   end;
  23.  
  24. var
  25.   Form1: TForm1;
  26.  
  27. implementation
  28.  
  29. {$R *.lfm}
  30.  
  31. { TForm1 }
  32.  
  33. procedure TForm1.Button1Click(Sender: TObject);
  34. const
  35.   PictureAlreadyLoaded: Boolean = False;
  36. begin
  37.   if not(PictureAlreadyLoaded) then
  38.   begin
  39.     Image1.Picture.LoadFromFile('project1.ico');
  40.     PictureAlreadyLoaded := True;
  41.   end;
  42.   Timer1.Enabled := not(Timer1.Enabled);
  43.   Label1.Visible := True;
  44. end;
  45.  
  46. procedure TForm1.FormCreate(Sender: TObject);
  47. begin
  48.   Timer1.Enabled    := False;
  49.   Timer1.Interval   := 30;
  50.   Label1.Font.Size  := 25;
  51.   Label1.Font.Color := clWhite;
  52.   Label1.Visible    := False;
  53. end;
  54.  
  55. procedure TForm1.Timer1Timer(Sender: TObject);
  56. const
  57.   XDirection: Integer = 1;
  58. begin
  59.   Label1.Caption := TimeToStr(Now);
  60.   case XDirection > 0 of
  61.     True:  if (Label1.Left+150) > Width then XDirection := -1;
  62.     False: if Label1.Left < 20 then XDirection := 1;
  63.   end;
  64.   Label1.Left := Label1.Left + XDirection;
  65. end;
  66.  
  67. end.
« Last Edit: February 22, 2021, 02:57:00 am by Handoko »

 

TinyPortal © 2005-2018