RVStyle DrawParaBack

General TRichView support forum. Please post your questions here
Post Reply
standay
Posts: 256
Joined: Fri Jun 18, 2021 3:07 pm

RVStyle DrawParaBack

Post by standay »

Hi Sergey,

I'm trying to set up a slightly different paragraph highlight and can't figure it out.

Here's what I have now, it works fine (call this paragraph highlight):
Image2.png
Image2.png (15.86 KiB) Viewed 5133 times
Here's the relevant code:

Code: Select all

    r := ARect;
    ACanvas.Brush.Color := SRDJournalThemes.EditorActiveLine;
    ACanvas.FillRect(r);
What I want is to add being able to do this (call this line highlight):
Image3.png
Image3.png (15.69 KiB) Viewed 5133 times
Here's that code:

Code: Select all

    r := ARect;
    yoffset := ( Edit.VScrollPos * Edit.VSmallStep );
    CurDItem := TRVEditRVData(Edit.RVData).CaretDrawItemNo;
    Edit.RVData.GetLineVerticalBoundsOrigEx(CurDItem,LineTopY,LineBottomY,CurDItem,CurDItem);
    r.Top := LineTopY - yoffset;
    r.Bottom := LineBottomY - yoffset + 1;
    ACanvas.Brush.Color := SRDJournalThemes.EditorActiveLine;
    ACanvas.FillRect(r);
The problem is when I start typing or turn live spell on and off. The line highlight flickers and even drops out:
Image7.png
Image7.png (11.18 KiB) Viewed 5133 times
It's fine as long as I don't set the rectangle top and bottom and use ARect as it is. Any ideas on why that might be doing that? I've tried all sorts of refresh, invalidate, and other calls to try and get it to work but no joy.

Thanks Sergey

Stan
Sergey Tkachenko
Site Admin
Posts: 17267
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: RVStyle DrawParaBack

Post by Sergey Tkachenko »

Unfortunately, there is a problem.
This event does not have parameters defining the beginning of the coordinates. For a complete repaint, these coordinates are client coordinates, and your code works. But for partial repainting, they are not client coordinates.
So, it's not possible to calculate coordinates in this event.

I'll think how to solve this problem.
I can see two solutions: either adding "hidden" parameters in this event, or adding one more event OnDrawCurrentLineBackground.
standay
Posts: 256
Joined: Fri Jun 18, 2021 3:07 pm

Re: RVStyle DrawParaBack

Post by standay »

Sergey Tkachenko wrote: Mon Oct 17, 2022 7:25 pm Unfortunately, there is a problem.
This event does not have parameters defining the beginning of the coordinates. For a complete repaint, these coordinates are client coordinates, and your code works. But for partial repainting, they are not client coordinates.
So, it's not possible to calculate coordinates in this event.

I'll think how to solve this problem.
I can see two solutions: either adding "hidden" parameters in this event, or adding one more event OnDrawCurrentLineBackground.
Thanks Sergey. Appreciate it.

Stan
standay
Posts: 256
Joined: Fri Jun 18, 2021 3:07 pm

Re: RVStyle DrawParaBack

Post by standay »

Hi Sergey,

I have worked around my issue of trying to highlight a single line using DrawParaBack by using a different approach. Instead of changing the para back to highlight a single line, I used the regular rve onpaint and add a dotted rectangle around the current line like this:

Image15.png
Image15.png (9.39 KiB) Viewed 4807 times

The advantage with this is it works "on top" of paragraphs with background colors and it still works with paragraphs I highlight using DrawParaBack as before. So I don't have to pick one or the other, I can have both. Or none of course!

If you get the para back working though, that would be a plus. If not, this should do.

Stan
Sergey Tkachenko
Site Admin
Posts: 17267
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: RVStyle DrawParaBack

Post by Sergey Tkachenko »

I've implemented OnDrawCurrentLine event.
CurrentLineHighlight.png
CurrentLineHighlight.png (53.52 KiB) Viewed 4366 times
In the next update, it will be called after drawing all content. There will be Prepaint: Boolean parameter, but it will be reserved for future use.

PS: OnPaint can be used, but in VCL/LCL version it may flicker a bit, because it is not double buffered.
standay
Posts: 256
Joined: Fri Jun 18, 2021 3:07 pm

Re: RVStyle DrawParaBack

Post by standay »

Thanks Sergey, looking forward to trying it.

Stan
standay
Posts: 256
Joined: Fri Jun 18, 2021 3:07 pm

Re: RVStyle DrawParaBack

Post by standay »

Hi Sergey,

I have the latest version installed now, and I see the OnDrawCurrentLine. I just did a simple canvas fill and it covers the line as expected, but all the foreground elements are painted over.

So, can you tell me how to use this new procedure to draw the background only? Like DrawParaBack does?

Thanks Sergey

Stan
Sergey Tkachenko
Site Admin
Posts: 17267
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: RVStyle DrawParaBack

Post by Sergey Tkachenko »

In this update, this event is called after all other drawing.
So, it can be used only for drawing borders or semitransparent highlighting
(The example how to do semitransparent highlighting in shown in the help file about this event)
standay
Posts: 256
Joined: Fri Jun 18, 2021 3:07 pm

Re: RVStyle DrawParaBack

Post by standay »

OK, got it. It works as outlined in the help.

Thanks Sergey

Stan
Post Reply