Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - Intersection of two UIElements

 
 
Old 07-30-2006   #1 (permalink)
brian@sweetapp.com


 
 

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 SpecsSystem Spec
Old 07-31-2006   #2 (permalink)
Marcus


 
 

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 SpecsSystem Spec
Old 08-01-2006   #3 (permalink)
brian@sweetapp.com


 
 

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 SpecsSystem Spec
 

Thread Tools



Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46