Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2019-10

Showing selection on drawing under Cocoa

4 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

C Western

Is there an easy way of indicating a selection on a plot in Cocoa? I have a plot that is relatively time consuming to plot (particularly under Cocoa), and I want to be able to indicate the area selected with a mouse. On other widget sets I can xor a rectangle and do this quickly in the mouse event handler, but this is not possible under Cocoa because you can only plot during a paint event, so I have to invalidate the selected area and redraw the entire plot just to show a selection.

Am I missing something? How does the Cocoa toolkit expect this to be done?

Colin

Reply by email

Dmitry Boyarintsev
to C Western

On Wed, Oct 16, 2019 at 4:33 PM C Western via lazarus <

wrote: Am I missing something? How does the Cocoa toolkit expect this to be done?

I'm see 3 ways of doing that.
1) you just invalidate the needed rectangle lines (or the entire selected area) and do xor drawing on paint event.

2) you might want to try to play with "focusRing" settings of NSView. That requires Cocoa level access to the view. Not cross platform, obviously.

3) instead of drawing into the view itself, you might want to create a semi-transparent window or a control, to be at the top of the hierarchy. and draw a focus as an overlay. Obviously you want this window or control to ignore any keyboard or mouse events (not to interfere with underlying controls).
The solution can be cross platform.

Approach #1 seems to be the easiest at this point.

thanks,
Dmitry
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20191016/9e0652d7/attachment.html>

Reply by email

C Western
to Dmitry Boyarintsev
Dmitry Boyarintsev wrote 10 lines
On Wed, Oct 16, 2019 at 4:33 PM C Western via lazarus < <mailto:>> wrote: Am I missing something? How does the Cocoa toolkit expect this to be done? I'm see 3 ways of doing that. 1) you just invalidate the needed rectangle lines (or the entire selected area) and do xor drawing  on paint event.

I hadn't thought of that possibility at all - thank you! (It obviously requires some work on the paint handler, but this is likely to be the most straightforward.)

Colin

Reply by email

C Western
to C Western
C Western wrote 17 lines
On 17/10/2019 03:44, Dmitry Boyarintsev via lazarus wrote: > On Wed, Oct 16, 2019 at 4:33 PM C Western via lazarus > < > <mailto:>> wrote: > >     Am I missing something? How does the Cocoa toolkit expect this to >     be done? > > I'm see 3 ways of doing that. > 1) you just invalidate the needed rectangle lines (or the entire > selected area) and do xor drawing  on paint event. I hadn't thought of that possibility at all - thank you! (It obviously requires some work on the paint handler, but this is likely to be the most straightforward.)

Sadly this doesn't work on Cocoa; it works fine under windows, but for Cocoa (and all the other widgetsets I tried) calling invalidate erases the contents of the rectangle, and I couldn't find any way to turn off this behavior. Unless this is possible, I will have to try a transparent window.

Colin

Reply by email