Recent

Author Topic: [DONE - SEMI-SOLVED] GBRAGraphicControl + Scrollbox = Poor Re-drawing  (Read 413 times)

pixelink

  • Hero Member
  • *****
  • Posts: 1118
    • Pixelink Media
I have a GBRAGraphicControl I am using for a canvas.
The form is just going to be a preview of a ticket layout.

The only way i can get my graphics to draw is to put the drawing initial code in a Timer @ 1000 when the app first starts
No drawing will be done by the user, when the form shows. (its based on the main form and their settings.
Drawing on the canvas is working fine

The problem is...
1) every time I resize the form it flickers a lot.
2) When ever I scroll with scrollbar on ScrollBox control, not all of the canvas redraw correctly, leaving remnants on the canvas.

How should I deal with this situation.

MY DRAWING CODE

Code: Pascal  [Select]
  1.  
  2. procedure TForm4.FormCloseQuery(Sender: TObject; var CanClose: boolean);
  3. begin
  4.   MyBitmap.Free;
  5.   myImage.Free;
  6. end;
  7.  
  8. procedure TForm4.FormResize(Sender: TObject);
  9. begin
  10.   loadTemplate(Sender);
  11. end;
  12.  
  13. procedure TForm4.Timer1Timer(Sender: TObject);
  14. begin
  15.     loadTemplate(Sender);
  16. end;  
  17.  
  18. procedure TForm4.loadTemplate(Sender: TObject);
  19. begin
  20.   // if bitmap already Create-ed then start fresh
  21.   if MyBitmap <> nil then
  22.         MyBitmap.Destroy;
  23.  
  24.   // create bmp object
  25.   MyBitmap := TBitmap.Create;
  26.  
  27.   //setup default page
  28.   MyCanvas.Width:=720;
  29.   MyCanvas.height:=935;
  30.   MyBitmap.SetSize(720, 935);
  31.   MyBitmap.Canvas.FillRect(0,0,MyBitmap.Width,MyBitmap.Height);
  32.  
  33.   // call paint function
  34.   MyCanvasPaint(Sender);
  35. end;
  36.  
  37.  
  38. procedure TForm4.MyCanvasPaint(Sender: TObject);
  39. var
  40.   textarea: TRect;
  41.   mytext: string;
  42.   mytextstyle: TTextStyle;
  43.  
  44. begin
  45.   // make sure canvas is same size as bmp
  46.   // this is here in case we dynamically adjust page size
  47.   if MyCanvas.Width<>MyBitmap.Width then begin
  48.     MyCanvas.Width:=MyBitmap.Width;
  49.     Exit;
  50.   end;
  51.   if MyCanvas.Height<>MyBitmap.Height then begin
  52.     MyCanvas.Height:=MyBitmap.Height;
  53.     Exit;
  54.   end;
  55.  
  56.   // Background - line around page
  57.   MyBitmap.Canvas.Brush.Color := clWhite;
  58.   MyBitmap.Canvas.Pen.Color := clSilver;
  59.   MyBitmap.Canvas.Rectangle(5, 5, 715, 930);
  60.  
  61.   // set report title
  62.   MyBitmap.Canvas.Font.Name:='Arial';
  63.   MyBitmap.Canvas.Font.Size:=24;
  64.   MyBitmap.Canvas.Font.Style := [fsBold];
  65.   MyBitmap.Canvas.Font.Color:=clBlack;
  66.   MyBitmap.Canvas.Brush.Color := clNone;
  67.   MyBitmap.Canvas.TextOut(180,  50, 'This is the Report Title');
  68.  
  69.   // rectangle  header line
  70.   MyBitmap.Canvas.Brush.Color:=clRed;
  71.   MyBitmap.Canvas.Pen.Color := clNone;
  72.   MyBitmap.Canvas.Pen.Style := psSolid;
  73.   MyBitmap.Canvas.Rectangle(Bounds(50, 100, 620, 4));
  74.  
  75.   // paragraph of text
  76.   mytext:='This is a sentence where I can contain it in a rectangle and even have it be multi-line. '
  77.                         + 'This is a sentence where I can contain it in a rectangle and even have it be multi-line.';
  78.   textarea:=Rect(50,140,620,200);
  79.   {reset font styles}
  80.   MyBitmap.Canvas.Font.Style := [];
  81.   {set new font style}
  82.   MyBitmap.Canvas.Font.Name := 'Times New Roman';
  83.   MyBitmap.Canvas.Font.Size:=14;
  84.   MyBitmap.Canvas.Font.Style := [fsItalic];
  85.   MyBitmap.Canvas.Font.Color:=clBlue;
  86.   mytextstyle := MyBitmap.Canvas.TextStyle;
  87.   mytextstyle.Wordbreak:=True;
  88.   mytextstyle.SingleLine:=False;
  89.  
  90.   //load image
  91.   myImage:= TBitmap.Create;
  92.   myImage.LoadFromFile(BMP_FNAME);
  93.   MyBitmap.Canvas.Draw(50, 240, myImage);
  94.  
  95.   // render bmp
  96.   MyBitmap.Canvas.TextRect(textarea, 50 {lf for txtarea}, 140 {top for txtarea}, mytext, mytextstyle);
  97.   MyCanvas.Canvas.Draw(0,0,MyBitmap);
  98.  
  99. end;
  100.                              
  101.  
  102.  
« Last Edit: May 18, 2019, 01:45:51 pm by pixelink »
Can't Type - Forgetful - Had Stroke = Forgive this old man!

Pixelink Media
LAZ 2.02 • Win10 • 16G RAM • Nivida GForce RTX 2060

pixelink

  • Hero Member
  • *****
  • Posts: 1118
    • Pixelink Media
Re: GBRAGraphicControl + Scrollbox = Poor Re-drawing
« Reply #1 on: May 16, 2019, 08:04:17 pm »
Okay.. this is a weird behavior i am just noticing.

If I scroll down to the bottom of the page, and re-fresh the paint event, it actually redraws my graphics only on the visible part of the screen, and that's normal except for one thing, the Top of the page drawing is drawing further down on the canvas (visible area on screen).

Example... if I draw graphics at 50, 50 location to begin with, then scroll down, refresh paint event, all the graphics are redrawn for example at 50, 150 location.

That is why I am seeing overlaid drawings, because location "50,50" is really being draw (at 50,150) in the visible area on the canvas based on ONLY the visible area on the screen. Make sense??
« Last Edit: May 16, 2019, 08:06:42 pm by pixelink »
Can't Type - Forgetful - Had Stroke = Forgive this old man!

Pixelink Media
LAZ 2.02 • Win10 • 16G RAM • Nivida GForce RTX 2060

circular

  • Hero Member
  • *****
  • Posts: 2954
    • Personal webpage
Re: GBRAGraphicControl + Scrollbox = Poor Re-drawing
« Reply #2 on: May 16, 2019, 10:21:29 pm »
One way to deal with that is to handle the scrolling yourself:
- use a separate scrollbar
- when scrolled, call RedrawBitmap of TBGRAGraphicControl or TBGRAVirtualScreen
- in the RedrawBitmap event, draw with the appropriate offset
Conscience is the debugger of the mind

pixelink

  • Hero Member
  • *****
  • Posts: 1118
    • Pixelink Media
Re: GBRAGraphicControl + Scrollbox = Poor Re-drawing
« Reply #3 on: May 17, 2019, 03:02:10 pm »
One way to deal with that is to handle the scrolling yourself:
- use a separate scrollbar
- when scrolled, call RedrawBitmap of TBGRAGraphicControl or TBGRAVirtualScreen
- in the RedrawBitmap event, draw with the appropriate offset

I am going try and build this with custom scrollbars just to test it.
Can't Type - Forgetful - Had Stroke = Forgive this old man!

Pixelink Media
LAZ 2.02 • Win10 • 16G RAM • Nivida GForce RTX 2060

pixelink

  • Hero Member
  • *****
  • Posts: 1118
    • Pixelink Media
Re: GBRAGraphicControl + Scrollbox = Poor Re-drawing
« Reply #4 on: May 18, 2019, 12:05:03 am »
One way to deal with that is to handle the scrolling yourself:
- use a separate scrollbar
- when scrolled, call RedrawBitmap of TBGRAGraphicControl or TBGRAVirtualScreen
- in the RedrawBitmap event, draw with the appropriate offset

Okay. got a crude scrollbar working, so it looks like you are right, the Scrollbox doesn't like my canvas.

Now, time to build a scrollbar system...
New thread...
https://forum.lazarus.freepascal.org/index.php/topic,45452.0.html
Can't Type - Forgetful - Had Stroke = Forgive this old man!

Pixelink Media
LAZ 2.02 • Win10 • 16G RAM • Nivida GForce RTX 2060