Re: Drawing from upper left
Re: Drawing from upper left
- Subject: Re: Drawing from upper left
- From: Wagner Truppel <email@hidden>
- Date: Tue, 26 Jun 2007 16:10:11 +0200
Hi Ken,
you could do all your logic using the bottom-left origin, but from
your message it appears that you prefer to use the upper-left origin.
That's perfectly fine, too, but then it seems to me that the simplest
approach is to have *all* your custom views return YES to -(BOOL)
isFlipped. Then you can think in terms of upper-left origins and not
have to deal with converting anything yourself.
Alternatively, you can work with non-flipped views and *still* think
in terms of upper-left origins if you proceed as follows: do all your
"thinking" and processing using the upper-left paradigm but when it
comes time to actually perform any drawing inside of any of your
custom views, replace every y coordinate by (H - y) where H is the
height of the view in question. The x coordinates are not, and should
never be, affected.
Here's an example to clarify the alternative procedure I just
suggested. Say you have two rectangles, A and B. In the default
coordinate system (bottom-left origin), the bottom edges of these
rectangles have y coordinates yA and yB. In the flipped system (upper-
left origin), the same edges have y coordinates yA' = H - yA and yB'
= H - yB, but the relative position of the two edges remains the
same, so the rectangles are drawn as shown below regardless of
whether the view is flipped or not.
|--------------------------------------|
| | | |
| | | |
| ------------- | H - yA |
| | | | | |
| | A | | | |
| | | | | |
| -------------... | .......... |
| | |
| ------------- H - yB | H
| | | | |
| | B | | | |
| | | | yA |
| -------------....... | |
| | | |
| yB | |
| | | |
|--------------------------------------|
When you return YES to -(BOOL)isFlipped, the view takes care of this
transformation for you, but if you're having trouble using isFlipped
and/or prefer not to use it, then just do all the logic *as if* you
were flipped and then perform the transformation above at the last
moment before drawing. *DON'T* do both, however, that is, don't
return YES to -(BOOL)isFlipped and do the transformation yourself.
Hope this helps.
Wagner
Subject: Drawing from upper left
From: Ken Tozier <email@hidden>
Date: Tue, 26 Jun 2007 08:51:13 -0400
Hi
I'm trying to create a few nested custom views:
- A wrapping thumbnail matrix similar to iPhoto's which will live in
- A collapsible view like items in Spotlight's "show all" results
window which will live in
- A scrolling list (also like Spotlight's "show all.") that knows
how to redraw itself in response to subviews expanding or collapsing
The stumbling block for me (I've been struggling with this for
months) has been getting these nested views to either draw from the
upper left corner or appear to draw from there.
I've tried flipped views but the combination of flipping,
unflipping all subviews so that they are right side up along with
transforms scaling and moving the thumbnails into position became
ridiculously complex.
I tried using the translateOriginToPoint method but that
necessitated writing special functions for all setFrame/setBounds
functions in all subclasses to convert the y offset to a negative
number.
I tried setting the resize masks but the collapsible requirement
wreaks havoc on the positioning of the items
I'd post some code but it's a fused blob of spaghetti at the moment
with all the failed attempts to draw from the top-left. What I'd
like is the simplest, cleanest way to draw custom views
programatically so that they either: are drawn from the upper left,
or appear to be drawn from there.
Any GUI masters point me in the right direction?
Many thanks
Ken
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden