On Sun, May 31, 2009 at 1:55 PM, Joe Wreschnig <joe.wresch...@gmail.com> wrote: > > On Fri, May 29, 2009 at 4:11 PM, dasacc22<dasac...@gmail.com> wrote: >> >> Hey lynx, that subtexturing and stretching reminds me of png 9 patch. >> >> http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch > > Wow, I hadn't seen NinePatch before. That's a really cool way of > encoding that information. > > I wrote a basic pyglet-using implementation at > http://code.google.com/p/layer/source/browse/layer/layer/cirno.py, > which will cut up the image you give it based on NinePatch rules. You > can invoke it as a command line program with a filename and --write to > make it write out the cut PNGs, or just use it in your program and > pull the resulting images out of it. It's not very well tested, but it > works on a set of NinePatch tiles I made. > > I'd like to also have some way to render it, but doing that in a > generally useful way is actually pretty tricky. You have to use an FBO > on a texture or a custom sprite class with independent X/Y scaling > (which is what I use). Or maybe someone else has a clever idea how to > do that without adding more dependencies.
Rendering a NinePatch is actually quite simple, you just draw 9 quads with the appropriate texture coordinates. I hacked your NinePatch code to demonstrate this: http://code.google.com/p/pyglet/source/browse/trunk/experimental/ninepatch.py. More work is needed to: - Draw the image as part of a batch instead of in immediate mode (very easy -- follow Sprite's example) - Arbitrary number of stretchy regions, as allowed by Android - Tiling the stretchy region instead of stretching it (I imagine this would be more useful for decorative borders, etc). Alex. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "pyglet-users" group. To post to this group, send email to pyglet-users@googlegroups.com To unsubscribe from this group, send email to pyglet-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/pyglet-users?hl=en -~----------~----~----~----~------~----~------~--~---