Page 1 of 1
RVStyle DrawParaBack
Posted: Sun Oct 16, 2022 4:52 pm
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 (15.86 KiB) Viewed 11015 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 (15.69 KiB) Viewed 11015 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 (11.18 KiB) Viewed 11015 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
Re: RVStyle DrawParaBack
Posted: Mon Oct 17, 2022 7:25 pm
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.
Re: RVStyle DrawParaBack
Posted: Mon Oct 17, 2022 8:58 pm
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
Re: RVStyle DrawParaBack
Posted: Wed Oct 19, 2022 6:27 pm
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 (9.39 KiB) Viewed 10689 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
Re: RVStyle DrawParaBack
Posted: Wed Oct 26, 2022 10:53 am
by Sergey Tkachenko
I've implemented OnDrawCurrentLine event.
- CurrentLineHighlight.png (53.52 KiB) Viewed 10248 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.
Re: RVStyle DrawParaBack
Posted: Wed Oct 26, 2022 4:22 pm
by standay
Thanks Sergey, looking forward to trying it.
Stan
Re: RVStyle DrawParaBack
Posted: Fri Oct 28, 2022 7:41 pm
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
Re: RVStyle DrawParaBack
Posted: Sat Oct 29, 2022 9:12 am
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)
Re: RVStyle DrawParaBack
Posted: Sat Oct 29, 2022 1:10 pm
by standay
OK, got it. It works as outlined in the help.
Thanks Sergey
Stan