Draw on specific layers from currentTab.layers

I’m trying to do something where I draw over a layer in Edit view if that layer meets certain conditions.
As a simple example, let’s say my Edit window has:

ABCDEB

and I have a list like [ ['B', 'C'], ['E'] ], I would like to draw stuff on BC and E in the Edit view (but not the last B).
I have been playing around with callbacks and DRAWINACTIVE, but I have no idea how to target only some elements of currentTab.layers to draw over.

I did found this topic, but to be honest it kind of lacked any concrete pointer to get me started. Could you give me any advice on where to look to move forward?
Thanks!

Probably the best option is to use the foregroundInViewCoords() method. Then access self.controller.allLayers(). and self.controller.graphicView().layoutManager().cachedGlyphsPosition()
then you have all layers and all its positions. (this assumes you are in a Reporter).

That would be in a Palette plugin (that one). Basically I want to highlight layers in the Edit view that are filled in the Search field. The plugin allows for chained search-replace, and optionally only search in selectedLayers if textRange > 0.

You can do the same in DRAWBACKGROUND. It is only called once. You just need to figure out the proper position of the other layers by subtracting everything from self.controller.selectedLayerOrigin

I see. I think this can get me started. Thanks Georg!

I manage to get things to work using DRAWBACKGROUND. One drawback though, is that the method is called on an active layer, so nothing gets displayed if the cursor is at the end of a line… How could I cover this case?

There is a callback missing for this. I’ll see if I can find a good place for it.

1 Like

That would be great!
I managed to get everything working as intended:


but it would be nice to be able to see search matches as you’re typing, which is currently not possible as it implies that the cursor is always at the end.

You can add another letter at the end after the cursor when you type.

1 Like

I sure can, but I can’t expect a user to figure that out :wink:

In relation to this topic, I’m also noticing serious performance issues when displaying search matches highlighting on an Edit Tab with a lot of content, serious enough for me to add an option to deactivate highlighting, and even considering to remove it altogether.

In that case, its because everything is calculated relatively to the active glyphs, so basically every action in the Edit tab triggers recalculation. I feel that it would have been so much more straightforward, both to code and to process if I had a callback that allowed me to draw stuff with absolute positioning in the Edit view.
edit: I realise that changing the origin point from the active glyph to another place, doesn’t change the fact that it would need to recalculate positions on zoom/scroll/content change, but my guess would be that being able to calculate from a constant origin point (ex: 0,0 from first glyph) would result in simpler code and better performances?

Is that something I can do with a reporter plugin, and, would it be a good idea to implement it that way, and to access that reporter plugin from my palette plugin? (But even if this is possible, that would mean two plugins for a user to access one functionality and that’s not ideal either…)