[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Sc-devel] relative coordinates in SCCompositeView ?
Hi James,
On Jan 19, 2008, at 11:17 PM, James Harkins wrote:
I have almost got FlowView working with relative-origin composite
views, but there is still a bug in SCCompositeView that I can't
work around.
w = SCWindow.new("test", Rect(50, 50, 500, 500)).front;
//w.view.background_(Color.black);
f = SCCompositeView(w, Rect(50, 50, 150, 200)).background_(Color.red
(alpha: 0.3))
.relativeOrigin_(true);
g = SCCompositeView(w, Rect(10, 10, 100, 100)).background_
(Color.blue(alpha: 0.3))
.relativeOrigin_(true);
SCStaticText(g, Rect(10, 10, 50, 20)).background_
(Color.white).string_("hello");
"g" should draw relative to its parent's origin (f = (50, 50)) but
instead it draws as if it had absolute coordinates. (svnx tells me
I'm using the latest sources, no diffs in source directories.)
in your code above f is not a parent of g. (g is a child of w) If it
is then it does draw relative.
w = SCWindow.new("test", Rect(50, 50, 500, 500)).front;
//w.view.background_(Color.black);
f = SCCompositeView(w, Rect(50, 50, 150, 200)).background_(Color.red
(alpha: 0.3))
.relativeOrigin_(true);
g = SCCompositeView(f, Rect(10, 10, 100, 100)).background_(Color.blue
(alpha: 0.3))
.relativeOrigin_(true);
SCStaticText(g, Rect(10, 10, 50, 20)).background_(Color.white).string_
("hello");
I'm afraid I'm not following the cocoa code quite well, so I don't
understand how cocoa determines the physical drawing coordinates
from the relative widgets.
In fact there are tow coordinates stored, one is relatve and is
called mBounds, the other one is absolute and is stored in
mLayout.mBounds and is accessible through SCView::getDrawBounds() in
the c++ code.
As far as I can see, the only way to do it reliably is to iterate
over the parents until you get to a container view that is not set
for relative origin (or the window's top view, which by definition
is pinned to (0, 0)). It looks like, in this example, "g" does not
take "f"'s origin into account.
It does take f into account. The method below could be replaced by a
simple property call and might be indeed useful sometime.
I haven't committed it yet, but I'm planning to adding in my
library a method to get the physical bounds of any view -- would
this be valuable to have in the main library?
absoluteBounds {
var bounds = this.bounds;
this.getParents.do({ |parent|
(parent.tryPerform(\relativeOrigin) == true).if({
bounds = bounds.moveBy(parent.bounds.left, parent.bounds.top)
}, {
^bounds
});
});
^bounds
}
Sorry to dump more work on you Jan -- but we're very nearly there I
think.
... hope so.
Jan
hjh
: H. James Harkins
: jamshark70@xxxxxxxxxxxxxxxxx
: http://www.dewdrop-world.net
.::!:.:.......:.::........:..!.::.::...:..:...:.:.:.:..:
"Come said the Muse,
Sing me a song no poet has yet chanted,
Sing me the universal." -- Whitman
_______________________________________________
Sc-devel mailing list
Sc-devel@xxxxxxxxxxxxxxx
http://lists.create.ucsb.edu/mailman/listinfo/sc-devel