drawing with a finger in iOS
Ben Rubinstein
benr_mc at cogapp.com
Wed Oct 26 09:53:03 EDT 2011
On 26/10/2011 04:00, Andre Garzia wrote:
> I know the paint tools are not supported in iOS but did anyone here
> succeeded in making some paintbrush of sorts for iOS?
I did this for a little prototype (where I wanted to be able to analyse
hand-drawn lines drawn on top of a background) and it was very easy and had
good performance (at least on my iPhone4, it never went beyond prototype so
never got tried elsewhere).
I had a drawing area, and outside it controls for line colour/size and erase
area - so I think analogous to what you want for a signature area.
My method was to have a 'working image' representing the drawing area,
translucent over a background; underneath a transparent button that gets the
events; between the two a normally hidden polygon to display the line
interactively as the user moves their finger.
On mousedown (cough, I've not yet adapted to the new world of touch events -
but it works fine) set the points of the line to the mouseloc, show the line.
On mouseMove, append the mouseloc to the points of the line. On mouseUp, I
hide some extraneous stuff, make the 'working image' opaque, take a snapshot
of that area (hence compositing the existing drawing with the newly drawn
line) and then hide the line and replace the working image with that snapshot,
and adjust the transparency back again.
Changing brush colour and thickness is just a matter of changing the
properties of the line.
So in short, each touch is handled as it happens by adjusting the points of a
line object; at the end of the touch, this is composited into a bitmap,
accumulating all the pixels. It seems perfectly responsive and robust.
I think it's a fabulous demo of the power of livecode: you can make a working
iOS paint app with a couple of dozen lines of code.
Ben
More information about the use-livecode
mailing list