Scrolling in UA



  • I have a folder with a lot of thumbnails.
    I am displaying the thumbnails in a UA with a vertical scrollbar.

    Vertical scrolling is all handled by cinema 4d, I have added no code for scrolling.
    So far so good. For a small number of thumbnails it is working ok, but for more thumbnails the performance is very bad!

    I noticed, after adding some debug statements, that the bad performance seems to be outside DrawMsg().
    DrawMsg() itself seems fast enough, but before anything happens on the screen it takes some time.
    Also when moving the vertical slider, DrawMsg() is called more than once.

    What can I do to increase performance?
    Build my own scrolling functionality?

    Here the basics of DrawMsg()

        def DrawMsg(self, x1, y1, x2, y2, msg):
          
            self.OffScreenOn() 
            self.SetClippingRegion(x1,y1,x2,y2)                    
    
            self.DrawSetPen(c4d.Vector(.4))    
            self.DrawSetTextCol(c4d.Vector(1,1,1), c4d.Vector(.4))   #GeUserArea.DrawSetTextCol(fg, bg)
            self.DrawRectangle(x1, y1, x2, y2)  # Clear UA by Draws the UA rectangle area
    
            # display thumbnails
            ...
            for rows in range(0, self.nrRows):    
                for colums in range(0, self.nrColumns):  
                    ....
                    self.DrawBitmap(self.bmp, x1, y1, self.thumbnailSize, self.thumbnailSize, 0, 0, 500, 500, c4d.BMP_NORMAL)
                
            return
    

    Example of the UA,
    13830059-2d7a-4ffb-bb43-149af4a902e8-image.png



  • Hi @pim, sorry for the delay I would give you some hint, but since I don't have the full code it's hard for me to properly profile and know what really takes time.
    You said, "but before anything happens on the screen it takes some time."
    Maybe this is the loading of 100+++ bitmap into BaseBitmap that takes time. You could maybe parallelize this in C++.
    But without code hard to profile anything.

    Instead of drawing your GeUserArea over and over, just draw everything on a GeClipMap, that you store in your GeUserArea and just draw it every time. This way you can update only the part you need instead of redrawing everything.

    Another idea is to draw only visible bitmap (Draw rectangles instead of bitmaps to conserve the correct size).

    Cheers,
    Maxime.



  • I do understand that without some code it is very hard to answer.
    I will try to put only the code, which I think causes the bad performance, in a test plugin.

    Also, you mention "You could maybe parallelize this in C++" and "just draw everything on a GeClipMap". Do you have some examples for these options?
    Also, I do not understand the option "to draw only visible bitmap". All the thumbnails I draw are rectangles (500x500).



  • Ok, did some test and what I see is that DrawMsg() is called every time the vertical scroll bar is clicked.
    My understanding was that cinema handles this internally.

    But because DrawMsg() is called I draw all thumbnails and thus not taking into account where the vertical scroll bar is located. So if only the lower 25% must be (is) shown, I redraw all thumbnails.

    Can I calculate which part of the UA must be drawn (where is vertical scroll bar and how large is it)?



  • @pim said in Scrolling in UA:

    But because DrawMsg() is called I draw all thumbnails and thus not taking into account where the vertical scroll bar is located. So if only the lower 25% must be (is) shown, I redraw all thumbnails.

    This is exactly what I mean when I said "Another idea is to draw only visible bitmap (Draw rectangles instead of bitmaps to conserve the correct size)."

    Normally only the required part is asked to be redrawn (see x1, y1, x2, y2 argument of DrawMsg) but in your code, it's up to you to not Draw anything if you know there will be nothing displayed.

    Cheers,
    Maxime.



  • Ok, clear. Thank you.


Log in to reply