Recent

Author Topic: [SOLVED] BGRAGraphic Control - Redraw - Disappearing Bitmap on Scrollbox  (Read 1360 times)

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Now, I decided to put the BGRAGraphicControl inside a Scrollbox.

Now that disappears too.

Tried this code on Scrollbox Paint and Resize events... nothing works.
The same code below works on FormResize if I don't use scrollbox though

Now what?
Code: Pascal  [Select][+][-]
  1. if StartUp = False Then
  2.     if (nb.PageIndex = 1) Or (nb.PageIndex = 2) Then
  3.        begin
  4.           BGRAGraphicControl1.Bitmap.Assign(theBMP.Bitmap);
  5.           BGRAGraphicControl2.Bitmap.Assign(newBMP.Bitmap);
  6.           BGRAGraphicControl2Redraw(Sender,newBMP);
  7.  
  8.        end  

« Last Edit: August 12, 2019, 05:33:32 pm by pixelink »
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

circular

  • Hero Member
  • *****
  • Posts: 4220
    • Personal webpage
Re: BGRAGraphic Control - Redraw - Disappearing Bitmap on Scrollbox
« Reply #1 on: August 11, 2019, 09:54:36 pm »
Hi.

It does not make sense to assign to the Bitmap property or to call the Redraw event yourself. The Redraw event is called automatically by the component itself. If you consider that the Bitmap is to be redrawn you can call DiscardBitmap. This will trigger the Redraw event and invalidate the component so that it will be repainted.

The logic about what is on the component is expected to be in the Redraw event. There the program can decide what you would like to display.

For example, this draws a red ellipse in the middle of a BGRAGraphicControl that is inside a scrollbox:
Code: Delphi  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, BGRAGraphicControl, BGRABitmap;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     BGRAGraphicControl1: TBGRAGraphicControl;
  16.     ScrollBox1: TScrollBox;
  17.     procedure BGRAGraphicControl1Redraw(Sender: TObject; Bitmap: TBGRABitmap);
  18.   private
  19.  
  20.   public
  21.  
  22.   end;
  23.  
  24. var
  25.   Form1: TForm1;
  26.  
  27. implementation
  28.  
  29. uses BGRABitmapTypes;
  30.  
  31. {$R *.lfm}
  32.  
  33. { TForm1 }
  34.  
  35. procedure TForm1.BGRAGraphicControl1Redraw(Sender: TObject; Bitmap: TBGRABitmap);
  36. begin
  37.   Bitmap.FillEllipseAntialias(Bitmap.Width/2-0.5,Bitmap.Height/2-0.5, Bitmap.Width/3,Bitmap.Height/3, CSSRed);
  38. end;
  39.  
  40. end.  
Conscience is the debugger of the mind

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: BGRAGraphic Control - Redraw - Disappearing Bitmap on Scrollbox
« Reply #2 on: August 11, 2019, 10:22:12 pm »
I have tried discard and it didn't work for me
Also, I am not loading images at startup so doing everything on ReDraw doesn't work.
The reason I don'y have everything drawing on the Redraw event is because when I load the test images, it is a onetime thing

Here is how I load/redraw my bitmaps (only pertinent code)

1) Declare my var's

Code: Pascal  [Select][+][-]
  1.  
  2. var
  3.   Form1: TForm1;
  4.   TheImage1: TBGRABitmap;
  5.   TheImage2: TBGRABitmap;
  6.   theBMP: TBGRABitmap;
  7.   newBMP: TBGRABitmap;
  8.   startUp: Boolean = True;
  9.  
  10.  

2) I use Notebook for multiple pages.
When form loads a it displays "loading" button. (this will be where a user creates or loads a project)
When the "Load" button is clicked it loads three images (transparent PNG, and two character PNG's)

FYI... the transparent PNG is to eliminate the Black screen I get if I don't assign a bitmap when the control displays.
This also will be needed once I remove the two other test character PNGs.
i simulate the checkered background (and use the transparent PNG because I will be resizing the actual controls and if I turn off AutoSize, then the checkered look will remain correct.

Eventually a person will be loading more images as pseudo layers

Code: Pascal  [Select][+][-]
  1.  
  2. procedure TForm1.Button1Click(Sender: TObject);
  3. begin
  4.     nb.PageIndex:=1;
  5.  
  6.     theBMP:= TBGRABitmap.Create('transpatentmask.png');
  7.     BGRAGraphicControl1.Bitmap.Assign(theBMP);
  8.     newBMP:= TBGRABitmap.Create('transpatentmask.png');
  9.     BGRAGraphicControl2.Bitmap.Assign(newBMP);
  10.  
  11.     btnDesign.Enabled:=True;
  12.     mnuDesign.Enabled:=True;
  13.  
  14.     TheImage1:= TBGRABitmap.Create('style_01.png');
  15.     TheImage2:= TBGRABitmap.Create('style_02.png');
  16.  
  17.     theBMP.PutImage(0, 0, TheImage1, dmDrawWithTransparency );
  18.     theBMP.PutImage(0, 0, TheImage2, dmDrawWithTransparency );  //dmLinearBlend or dmDrawWithTransparency
  19.  
  20.     BGRAGraphicControl1.Bitmap.Assign(theBMP);
  21.     BGRAGraphicControl1.Refresh;
  22.  
  23. end;
  24.  
  25.  


3) Here is my redraw prod

Code: Pascal  [Select][+][-]
  1.  
  2. procedure TForm1.BGRAGraphicControl1Redraw(Sender: TObject; Bitmap: TBGRABitmap);
  3. begin
  4.   BGRAGraphicControl1.Bitmap.Assign(theBMP.Bitmap);
  5.  
  6.   if assigned(TheImage1) then
  7.   begin
  8.     TheImage1.Draw(Canvas,0,0,false); //true makes it opaque - false makes transparent
  9.  
  10.   end;
  11.  
  12.   if assigned(TheImage2) then
  13.   begin
  14.     TheImage2.Draw(Canvas,0,0,false); //true makes it opaque - false makes transparent
  15.  
  16.   end;
  17.  
  18.   if assigned(theBMP) then
  19.   begin
  20.     theBMP.Draw(Canvas,0,0,false); //true makes it opaque - false makes transparent
  21.  
  22.   end;
  23. end;
  24.  
  25. procedure TForm1.BGRAGraphicControl2Redraw(Sender: TObject; Bitmap: TBGRABitmap
  26.   );
  27. begin
  28.   BGRAGraphicControl2.Refresh;
  29.   //BGRAGraphicControl2Paint(Sender);
  30.  
  31.   if assigned(newBMP) then
  32.   begin
  33.     newBMP.Draw(Canvas,0,0,false); //true makes it opaque - false makes transparen
  34.   end;
  35.  
  36. end;
  37.  
  38.  

4) Here is all my resize code

Code: Pascal  [Select][+][-]
  1.  
  2. procedure TForm1.FormResize(Sender: TObject);
  3. begin
  4.   if StartUp = False Then
  5.     if (nb.PageIndex = 1) Or (nb.PageIndex = 2) Then
  6.        begin
  7.           BGRAGraphicControl1.Bitmap.Assign(theBMP.Bitmap);
  8.           BGRAGraphicControl2.Bitmap.Assign(newBMP.Bitmap);
  9.           BGRAGraphicControl2Redraw(Sender,newBMP);
  10.           //BGRAGraphicControl2.DiscardBitmap;
  11.        end
  12. end;
  13.  
  14. procedure TForm1.FormDestroy(Sender: TObject);
  15. begin
  16.   TheImage1.Free;
  17.   TheImage2.Free;
  18.   theBMP.Free;
  19.   newBMP.Free;
  20. end;
  21.  
  22. procedure TForm1.ScrollBox3Resize(Sender: TObject);
  23. begin
  24.     if StartUp = False Then
  25.     if (nb.PageIndex = 1) Or (nb.PageIndex = 2) Then
  26.        begin
  27.           //BGRAGraphicControl1.Bitmap.Assign(theBMP.Bitmap);
  28.           //BGRAGraphicControl2.Bitmap.Assign(newBMP.Bitmap);
  29.           BGRAGraphicControl2Redraw(Sender,newBMP);
  30.  
  31.        end
  32. end;
  33.  
  34. procedure TForm1.ScrollBox3Paint(Sender: TObject);
  35. begin
  36.     if StartUp = False Then
  37.     if (nb.PageIndex = 1) Or (nb.PageIndex = 2) Then
  38.        begin
  39.           BGRAGraphicControl1.Bitmap.Assign(theBMP.Bitmap);
  40.           BGRAGraphicControl2.Bitmap.Assign(newBMP.Bitmap);
  41.           BGRAGraphicControl2Redraw(Sender,newBMP);
  42.  
  43.        end
  44. end;
  45. end.
  46.  
  47.  
« Last Edit: August 11, 2019, 11:03:14 pm by pixelink »
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: BGRAGraphic Control - Redraw - Disappearing Bitmap on Scrollbox
« Reply #3 on: August 11, 2019, 10:39:38 pm »
Here is the actual project

On this project... only the "Design" page uses a scrollbox that has a BGRAGraphicControl on it
« Last Edit: August 11, 2019, 10:47:15 pm by pixelink »
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

lainz

  • Hero Member
  • *****
  • Posts: 4468
    • https://lainz.github.io/
Re: BGRAGraphic Control - Redraw - Disappearing Bitmap on Scrollbox
« Reply #4 on: August 12, 2019, 12:26:09 am »
I think we need to remove the Bitmap property and OnPaint event, so is not misused, what do you think @circular?

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: BGRAGraphic Control - Redraw - Disappearing Bitmap on Scrollbox
« Reply #5 on: August 12, 2019, 02:03:41 am »
Solved it.

I put "BGRAGraphicControl1.Bitmap.Assign(theBMP);" on the redraw event.
I had it in the show event of the form
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

circular

  • Hero Member
  • *****
  • Posts: 4220
    • Personal webpage
Well, yes you need to define the content within the Redraw event.

But you are supposed to use the Bitmap parameter. Also not calling Draw event in this event.

I am confused about what you are trying to do. Simply display an image in the control?

Then it is much simpler than that. For example you can do this:
Code: Delphi  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, BGRAGraphicControl, BGRABitmap, BCTypes;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     BGRAGraphicControl1: TBGRAGraphicControl;
  16.     procedure BGRAGraphicControl1Redraw(Sender: TObject; Bitmap: TBGRABitmap);
  17.     procedure FormCreate(Sender: TObject);
  18.   private
  19.  
  20.   public
  21.     myImage: TBGRAbitmap;
  22.   end;
  23.  
  24. var
  25.   Form1: TForm1;
  26.  
  27. implementation
  28.  
  29. {$R *.lfm}
  30.  
  31. uses BGRABitmapTypes;
  32.  
  33. { TForm1 }
  34.  
  35. procedure TForm1.FormCreate(Sender: TObject);
  36. begin
  37.   myImage := TBGRABitmap.Create('style_01.png');
  38. end;
  39.  
  40. procedure TForm1.BGRAGraphicControl1Redraw(Sender: TObject; Bitmap: TBGRABitmap);
  41. begin
  42.   //Bitmap.FillTransparent;
  43.   Bitmap.PutImage(0,0,myImage, dmDrawWithTransparency);
  44. end;
  45.  
  46. end.

To have the component fully transparent by default, set the property ColorOpacity to zero, BevelInner and BevelOuter to bvNone and Caption to an empty string. Alternatively you can call Bitmap.FillTransparent at the beginning of the Redraw event.

Conscience is the debugger of the mind

 

TinyPortal © 2005-2018