Help needed for NSView's "drawRect" that can redraw given areas only


I’m developing a preview plugin like “Text Preview” in Glyphs3.
BTW, when I redraw a full window with “setNeedsDisplay_(True)” while editing a glyph, there is a lag or delay in an editing window in case I have to redraw lots of characters.
For instance, if there is a text “Good morning!” in a preview window and I’m editing ‘o’, I want to redraw ‘o’ characters only without redrawing a full window.

I have tried some methods in below urls but I couldn’t find a way.

can anyone help me how I can redraw some areas(boxes) only not a full window.

Thanks in advance,

That’s difficult to answer without seeing the code. Is the code for your plugin publicly available? Otherwise, sende me a private message on this forum and I’ll have a look.

I have sent you two messages.(one with codes, one without codes.)
Many thanks to you!!

You can use setNeedsDisplayInRect_(). So if you observe that on letter needs redrawing, find out what area it was using and invalidate that area. Then the drawRect_ will have that same rect as an argument. Then you only draw whatever is in that rect.

All that bookkeeping can expensive, too. So just redrawing everything might be actually quicker.
And if you have an “o” and an “ö” (that uses the “o” as a component) in your view, you need to redraw both. That makes the bookkeeping much more complicated.

As you wrote, ‘bookkeeping’ is very complicated. But, I will let the designers choose it or not.

Of course, I already have tested setNeedsDisplayInRect_(). But I have not solved it yet. Anyway, I’ll try it again.

What isn’t working?

Background is cleared…;
I’ll check the ‘Rect’ values again.


What do you mean by that? Can you post a screenshot?

And can you explain what you are trying to do? Maybe we can incorporate it into one of the existing previews?