Game Development Community

How to find which gui object is on top?

by Dean · in Torque Game Engine · 07/11/2007 (1:31 pm) · 1 replies

In my code, when i click on two overlapping gui objects, it registers on both. I only want the top control to respond to the mouse click, but I don't know how to actually tell which one is on top. From what I know of the function pushtoback, it seems to depend on the object's order in the objectlist, but I can't find any commands to access the list and get a certain object's index in it.

Or I could just be wrong. anyone know?

#1
07/11/2007 (2:28 pm)
Well, i edited some code and made a new function findindex that does what I want. I hope i just didn't reinvent the wheel though :p


added this to tAlgorithm.h
template <class Iterator, class Value>
S32 findindex(Iterator first, Iterator last, Value value)
{
	S32 index = 0;
   while (first != last && *first != value)
   {
      ++first;
	  index ++;

   }
   return index;
}

added this to simBase.h

S32 findindex( iterator first, iterator last, SimObject *obj)
   { return ::findindex(first, last, obj); }

and here was my usage

S32 index = 0;
SimObject *obj = DDBCtrl;
SimSet::iterator first = DDBCtrl->getParent()->begin();
SimSet::iterator last = DDBCtrl->getParent()->end();

index = DDBCtrl->getParent()->findindex(first, last, obj);