![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
| |
| | #1 (permalink) |
| | Intersection of two UIElements Hi, I've been looking for the answer to this question for a while. I would like to know if two UIElements intersect on the screen. These UIElements are in the same container but they have their margins specified in different ways (i.e. one is center aligned and one is left aligned) and have had various transformations applied to them. So calculating if they intersect is reasonably complex. Does anyone know of a way to accomplish this. Any help would be hugely appreciated. Cheers, Brian |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Intersection of two UIElements I dont think I can provide 100% of the answer... but here I go... You can ask any visual for a GeneralTranform that tranforms coordinates or bounds to another visual's coordinate system... You could ask both your UIElements for a tranform to their common ancestor and intersects the 2 rects... This can be done using the methods: Visual.TransformToAncestor() Visual.TransformToDescendant() Visual.TransformToVisual() Unfortunatly... I'm not sure how this applies to UIElements with Layout or Render Transforms... You would have to try by yourself. You could always test for the 4 corners of your elements, to see if they are inside the other element?!? brian@sweetapp.com wrote: > Hi, > > I've been looking for the answer to this question for a while. > > I would like to know if two UIElements intersect on the screen. These > UIElements are in the same container but they have their margins > specified in different ways (i.e. one is center aligned and one is left > aligned) and have had various transformations applied to them. So > calculating if they intersect is reasonably complex. > > Does anyone know of a way to accomplish this. Any help would be hugely > appreciated. > > Cheers, > Brian |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Intersection of two UIElements Marcus wrote: > I dont think I can provide 100% of the answer... but here I go... > > You can ask any visual for a GeneralTranform that tranforms coordinates > or bounds to another visual's coordinate system... > > You could ask both your UIElements for a tranform to their common > ancestor and intersects the 2 rects... > > This can be done using the methods: > > Visual.TransformToAncestor() > Visual.TransformToDescendant() > Visual.TransformToVisual() > > Unfortunatly... I'm not sure how this applies to UIElements with Layout > or Render Transforms... You would have to try by yourself. These seem to be taken into account. My method to get the container-oriented bounds of the ui_element is (Python syntax): def get_play_rect(self): t = self.ui_element.TransformToVisual(self.play_area) return t.TransformBounds( Rect( 0, 0, self.ui_element.ActualWidth, self.ui_element.ActualHeight)) My actual collision detection code (for my pong clone) looks like this: if ball.get_play_rect().IntersectsWith(left_paddle.get_play_rect()): if ball.dx < 0: ball.x_bounce() I'll make the complete code available when it is done. > You could always test for the 4 corners of your elements, to see if > they are inside the other element?!? Well, two elements could intersect but not have any corners inside the other. Thanks very much for your help! Cheers, Brian |
My System Specs![]() |