Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Adding setPixel method to Shape — Gideros Forum

Adding setPixel method to Shape

ArmandArmand Member
edited February 2014 in General questions
Hi,

I'm new to Gideros. After having worked with Marmalade and MoSync, I abandoned them both and now I'm trying my luck with Gideros. I also tried Titanium SDK, by the way, but this is much more complex to use and didn't run as smoothly as Gideros (although it offers many more interfaces to the native APIs and it uses Eclipse, which I like). So far, so good, and after a little less than 2 weeks I'm starting to get up to speed with my next app. By the way, my next app is not a game app, but I still like to try to use Gideros as an SDK. It seems to do pretty well so far :-)

My question is this:
Since I want good-looking and scalable graphics, I synthesize my own buttons and other GUI elements rather than using bitmaps for them. Synthesizing means that you're free to change colors, texts, sizes and whatsoever without having to re-create your bitmaps over and over again, and your app will always fit to whatever resolution your device will have,
For this to look good, I need sub-pixel graphics. Rendering the buttons to huge (4x4) sizes using the standard shape drawing methods and scaling down would probably work fairly well, but for performance and memory reasons I'd prefer direct sub-pixel rendering. Also, this allows for shaded areas, which is much harder otherwise.

Since the Gideros shape drawing methods are only full-pel-based, there is a lot of aliasing at the edges. I noticed anti-aliasing to be a roadmap item, so maybe I can be of some help creating them.
I now have a properly working Lua class that nicely renders the buttons as I want. (With anti-aliased rounded edges and the like.) The basis function for rendering is a draw-horizontal-line method that uses one or more smoothed pixels (using alpha values) at the end of the line. The number of shaded pixels is a parameter. However, to draw individual pixels with a different color or alpha value, one needs to 'close' the current shape and start drawing a new. Since there is no 'drawPixel' method in the Shape class, I made my own:

function HiResShape:setPixel(x, y, color, alpha)
self:setLineStyle(1, color, alpha)
self:beginPath(Shape.EVEN_ODD)
self:moveTo(x, y)
self:lineTo(x, y)
self:endPath()
end

of course, this is really slow - though acceptable at the moment. Furthermore, it seems to have quite a large impact on memory usage, even if I clear() and nil-out the shape after use. However, I can't point-out the exact cause of the memory drain yet, so I'm not really sure about that...

So, the first feature request I have is a relatively simple one: a Shape:drawPixel(x, y, color, alpha) method that is able to set individual pixels, like the Lua function above. This would significantly speed-up my code, while it is a simple and useful addition.

The second feature request would be a drawHLine method that is capable of drawing shaded edges, but this is of a little lower importance.

Once supplied, the next step would to augment it with other shaded (anti-aliased) drawing primitives like polygon, rect, roundedRect, circle or the like. I now have the Lua source code for a number of those, so they can be ported to C for further speed-up.

What would be the possibilities here? For instance, would it be possible to add my own extensions in C/C++-code?

Regards,

Armand.

Comments

Sign In or Register to comment.