Page 1 of 1

RVStyle1DrawParaBack

Posted: Wed Aug 18, 2021 7:53 pm
by standay
Sergey,

I am trying to do some drawing on the background using RVStyle1DrawParaBack. But I can't get it to work. I'm trying to just draw a color in the background but only in the current para. I need a way to restrict it to just the para with the cursor in it, otherwise it draws it in every para. I have tried a lot of stuff this afternoon and can't get it to do what I'm after!

Here's what I have:

Code: Select all

 ACanvas.Brush.Color := Sender.Color;
  ACanvas.FillRect(ARect);

  if not EditorActiveLine1.Checked then exit;

  //Note: setting RVStyle1.ParaStyles LineSpacing to 105% helps with the "look"
  //of the highlight area.

  //Note: I originally used "if Sender.ItemNo = RichViewEdit1.CurItemNo then..."
  //but that failed when I put a tab into the line. No idea why. But using the
  //line number from each item worked better, but not 100%:
  if rve.GetLineNo(Sender.ItemNo,0) = rve.GetLineNo(rve.CurItemNo,0) then
  begin
    //ACanvas.Brush.Color := clGrayText;
    //ACanvas.FillRect(r);
    //ColorBlend looks better as it is alpha blended:
    ColorBlend(ACanvas, ARect, clGrayText , 70);
  end;
I need to know if the ParaNo in RVStyle1DrawParaBack is = to the current item para but it always seems to be 0.

Any advice appreciated.

Edit: What I have above does work most of the time. I had a file with some odd formatting that gave me some trouble. I'll keep testing it but if you have any ideas please let me know.

Stan

Re: RVStyle1DrawParaBack

Posted: Thu Aug 19, 2021 10:22 am
by Sergey Tkachenko
ParaNo is not a position in the document, but index in RVStyle1.ParaStyles collection.

Position of the drawn paragraph can be get in (Sender.RVData, Sender.ItemNo). This is a position of the last item in the drawn paragraph.

A related demo project:
https://www.trichview.com/forums/viewtopic.php?f=3&t=60

Re: RVStyle1DrawParaBack

Posted: Thu Aug 19, 2021 5:50 pm
by standay
Hi Sergey,

Thanks, that did work. Here's how I set mine up for 1 rve:

Code: Select all

  i := Sender.ItemNo;
  if Sender.RVData=rve.RVData then
    j := rve.CurItemNo;
  repeat
    MakeRed := i=j;
    if MakeRed then
      break;
    dec(i);
  until TCustomRVData(Sender.RVData).IsFromNewLine(i+1);
  if MakeRed then begin
    //Canvas.Brush.Style := bsSolid;
    //Canvas.Brush.Color := $CCCCFF;
    //Canvas.FillRect(ARect);
    ColorBlend(ACanvas, ARect, SRDJournalThemes.EditorActiveLine , 225); //alpha blend
  end;
I actually saw that demo a while ago, but it didn't make sense to me at the time. I've done a lot more experimentation with the rve since then!

Thanks