Sunday, July 11, 2010

Wall Paper Editor: Pinches

My view structure is complicated enough ( I think because of the number of views I have going around) that the [touches count] isn't always returning the proper number of touches, maybe because one of my fingers isn't moving.  THis resulted in very jerky code.

I added the following log statement to touchesBegan and touchesMoved:

NSLog(@"In touchesBegan count =%d event touches count=%d",[touches count],[[event allTouches] count]);

This told me that I should really be looking at [event allTouches] for much of my behavior. 

I then added the code

touches=[event allTouches];

To my begin and moved events.  This resulted in MUCH smoother movement of stuff.

My scaling is a bit strange, I think because of the multiplication effect, if I have a window with one larger dimension, the multiplication effect from 

// We should be able to scale up evenly this way.
double heightRatio=lastRect.size.height/startRect.size.height;
double widthRatio=lastRect.size.width/startRect.size.width;
double newWidth=imageStartSize.size.width*widthRatio;
double newHeight=imageStartSize.size.height*heightRatio;


Results in a strange scaling pattern.  If one of the imageStartSizes is significantly higher, then the ratio for
that one takes a beating.  Similarly a low starting value results in almost insignificant moves.  

I still want be able to scale both height and width independently, but I need to make it smoother.

Instead of multiplying, I'm going to add:


// We should be able to scale up evenly this way.
double dheight=lastRect.size.height-startRect.size.height;
double dwidth=lastRect.size.width-startRect.size.width;
double newWidth=imageStartSize.size.width+dwidth;
double newHeight=imageStartSize.size.height+dheight;
This results in scaling that is directly proportional to the amount the user moves their fingers on the screen.  You can even get some fun move at a distance effects that might not be intuitive, but works fun.
(The other choice is to make the rectangle directly dependent on the points chosen.  This is probably more standard, and I might try it out later.  But first its time to refactor.

No comments:

Post a Comment