On Mon, 10 Oct 2016, Mattias Gaertner via Lazarus wrote:
On Mon, 10 Oct 2016 10:21:48 +0100
Graeme Geldenhuys via Lazarus <lazarus@lists.lazarus-ide.org> wrote:
Hi,
Working on a visual report designer for the upcoming fpReport. We use
Canvas.DrawFocusRect() to draw a selection rectangle around a reporting
element (eg: a memo). We can drag that rectangle around in the report
designer (which itself is a custom widget). We call the
Canvas.DrawFocusRect() from within the MouseMove event. It seems to work
fine under LCL-GTK2, but could this be problematic on other platforms,
as painting outside the Paint event can normally have undefined results.
Some widgetsets like Carbon can only paint during the Paint event.
Or has LCL somehow resolved the issues of painting outside the Paint event?
No.
If you want to optimize for mini changes like the focusrect you might
want to use a bitmap.
Please explain ?
On a side note:
The Paint() event for the report designer can potentially have very
lengthy code, so we definitely don't want to repaint everything simply
because we are dragging a focus rectangle around on the canvas. So if we
must, we can obviously work around this by using various states in the
Paint method.
You need to optimize the Paint event anyway.
You don't need to draw everything when using InvalidateRect instead
of Control.Invalidate.
And in Paint use Canvas.GetClipRect or lclintf's GetClipRGN to avoid
unnecessary calculations.
So, if I understand you correctly, when I want to draw a focus rect, I must
(roughly):
- calculate the focusrect,
- Call canvas.invalidaterect() with the focusrect
- in the paint event, check ClipRect (which should equal the focusrect)
- and redraw anything that intersects with the cliprect ?
Correct ?
Michael.
--
_______________________________________________
Lazarus mailing list
Lazarus@lists.lazarus-ide.org
http://lists.lazarus-ide.org/listinfo/lazarus