PDA

View Full Version : Hillegass chapter 18 pg 260 problem and question




John Baughman
Jul 19, 2009, 07:36 PM
in the SetImage mthod we added...


downPoint = NSZeroPoint;
currentPoint.x = downPoint.x + imageSize.width;
currentPoint.y = downPoint.y + imageSize.height;

Why do we add the width and height to downPoint x and y. downPoint will always be 0/0 so why to why can't you just apply the width and size directly...


downPoint = NSZeroPoint;
currentPoint.x = imageSize.width;
currentPoint.y = imageSize.height;


Problem: For some reason I cannot get currentPoint.x to be anything but zero. currntPoint.y gets a value but not currentPoint.x. Result is the image cannot be seen when it is opened. Clicking anywhere immediately makes it visible as a straight vertical line, then you can resize it. The width of my image is 128, so I tried assigning 128 directly and it still does not work.

Thanks for any help.

John

OK, I am wrong. currentPointer.x is getting the set. I was using NSLog to look at the value being set and apparently not doing that correctly. I can see it being set properly to 128 in the debugger.

Now the question is why doesn't the picture display when first opened?

I found the bug. I had the height parameter of NSmakeRect maxY=minY instead of maxY-minY.

Still curious as to why we are adding the height and width of the image to zero to set the points of the current rectangle.



Cinder6
Jul 19, 2009, 10:06 PM
I don't think there's any reason to add them.

wlh99
Jul 20, 2009, 03:10 PM
I found the bug. I had the height parameter of NSmakeRect maxY=minY instead of maxY-minY.

Still curious as to why we are adding the height and width of the image to zero to set the points of the current rectangle.

Would that be the line the author tells you to double check because many people mistype it? I just did that exercise last night and wondered about his comment.