[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: NSSwitch drawRect bug
From: |
H. Nikolaus Schaller |
Subject: |
Re: NSSwitch drawRect bug |
Date: |
Mon, 14 Aug 2023 12:49:59 +0200 |
Hi all,
> Am 14.08.2023 um 08:55 schrieb Fred Kiefer <fredkiefer@gmx.de>:
>
>
>> Am 14.08.2023 um 08:36 schrieb H. Nikolaus Schaller <hns@goldelico.com>:
>>
>>> Am 13.08.2023 um 22:40 schrieb dr_clow@me.com:
>>>
>>> Nice! Maybe even just drawSwitchInRect:dirtyRect:forState:enabled: Though,
>>> with your way, you could get more information from the control without
>>> having to enlarge method arguments every time we wanted to add something
>>> else.
>>>
>>> So maybe -(void) drawSwitch:(NSSwitch*)switch inRect:(CGRect)rect
>>> dirtyRect:(CGRect)dirtyRect {}
>>
>> I am not sure if passing the dirtyRect is necessary and useful.
>> The idea is that -drawRect: is usually called after setting a clipping rect
>> within -display so that drawing with bounds size is correct but will be
>> clipped away.
>
>
> This is not about correctness, as you wrote the NSView clipping will take
> care of that, this idea is about performance. When we pass on the dirty
> rectangle the drawing will be able to decide which parts actually require a
> redraw. This isn’t important for a small component like an NSSwitch but for
> something like NSMatrix or NSTableView it allows us to speed up drawing a
> lot. We only redraw and compute bits that will be visible.
> In general we should always draw a view within the assigned bounds and use
> the dirty rectangle to speed things up, where this is useful. Somebody should
> go through the NSView subclasses to see where corrections in the code are
> required.
Apple has a good description here:
https://developer.apple.com/documentation/appkit/nsview/1483686-drawrect
The dirty rect is a *hint* for *optimizing* drawing. It is not a bounds
dimension of a view which means that using it for scaling was also wrong. But
there may not only be a single dirty rect, there may be dirty regions.
Hence, the best solution would be if the drawing code for a View or Cell knows
about the view it is drawing into and can use methods like
-getRectsBeingDrawn:count: or -needsToDrawRect: This can easily be done easily
within -drawRect: but not within [GSTheme theme].
So passing the control view seems to be the right thing, until we find that
there is a +focusView in NSView. This should be the view which is currently
being drawn to.
Hence there is no need to pass down neither the dirtyRect nor a controlView to
a method like -drawSwitchInRect:forState:enabled: if it wants to optimize
drawing.
BR, hns