I am trying to build an application that requires the user to draw something.
To do so, I create a canvas (a pygame.Surface object) on which the drawing are registered, and then I blit it onto the window. I'd like the canvas to be infinite, so that when the user scrolls he can continue drawing (of course only a small part of the canvas is blited onto the window). But, actually, Surface in pygame requires a finite width and height and, most importantly, it's not that big! (I think that's because it actually locks the space in memory).
So, I tried to create chunks: every chunk has given fixed size (like, twice the screen size), and to each chunk is allocated a certain Surface. Chunks are created dynamically, on demand, and it overall works pretty well.
My problem is that when I try to draw lines that cross onto multiple chunks, it requires a great effort to compute onto which chunks that line should actually be drawn, and in what pieces it should be broken. I didn't even try to draw rectangles because it really was a pain to make the 'draw-a-line' function work.
That's when I thought that what I was doing was fundamentally wrong: instead of trying to rewrite all of pygame.draw and pygame.gfxdraw functions so that they basically do a per-chunk work, I should really overload the pygame.Surface (say, create a MySurface class child of Surface) so whenever a pixel is modified, I internally chose to which chunk it belongs and actually change it on that chunk, and pass that new Surface object to the pygame functions.
I've searched a lot at the pygame doc, but there it isn't explained how to do that. I don't even know what methods of a Surface object are internally called when I blit/draw onto it! I also google it and I didn't find anyone trying to do that kind of stuff (maybe I'm going the wrong way?).
So, my question(s) is: is this the right approach? And, if yes, how should I realize it?
I don't post code because what I need is more an explanation on where to find the doc of what I try to do more than a code review.