Chris and FloatCanvas Users,

Awhile back I messaged about the development of a Bounding Box HitMap 
system for the FloatCanvas. Here is an update. The HitTest() function of 
the FloatCanvas, in addition to identifying which objects bounding boxes 
contain the hitpoint, should determine which is on top by referencing 
the self._ForeDrawList and self._DrawList (in that order) through a 
python list index. I have attached the code below in case anyone else is 
interested or can give me pointers on how to improve this code. I will 
eventually have to develop a Z index which I believe can be attached to 
the FloatCanvas Object, but at first I would imagine each Z index will 
contain many objects, and ultimately the order will get determined by 
the _DrawList and _ForeDrawList once again.

def HitTest(self, event, HitEvent):
        """ Hit Test Function for BoundingBox Based HitMap System"""
        if self.HitDict:
            #Get Mouse Event Position
            xy = event.GetPosition()
            xy = self.PixelToWorld( xy ) #Convert to the correct coords
            objects = [] #Create object list for holding multiple objects
            object_index_list = [] #Create list for holding the indexes
            # check if there are any objects in the dict for this event
            for key2 in self.HitDict[HitEvent].keys():
                bb =  self.HitDict[HitEvent][key2].BoundingBox
                if xy[0] >= bb[0,0] and xy[0] <= bb[1,0] and xy[1] <= 
bb[1,1] and xy[1] >= bb[0,1]:
                    Object = self.HitDict[HitEvent][key2]
                    objects.append([Object,xy])
                    try:
                        #First try the foreground index and add the 
length of the background index
                        #to account for the two 'layers' that already 
exist in the code
                        index = self._ForeDrawList.index(Object) + 
len(self._DrawList)
                    except:
                        index = self._DrawList.index(Object) #Now check 
background if not found in foreground
                    object_index_list.append(index) #append the index found
                 
            for index,item in enumerate(objects):
                print item[0].Name,object_index_list[index]
            if len(objects) > 0: #If no objects then do nothing
                #Get the highest index object
                highest_object_array = 
objects[object_index_list.index(max(object_index_list))] 
                #Unpack Array
                highest_object = highest_object_array[0]
                highest_xy = highest_object_array[1]
                #Assign Hit Coords and do CallBackFunction
                highest_object.HitCoords = self.PixelToWorld( highest_xy )
                highest_object.HitCoordsPixel = highest_xy
                highest_object.CallBackFuncs[HitEvent](highest_object)
                return True
            else:
                return False

-- 
Benjamin Jessup
Mechanical Engineering Consultant
ABZ, Inc.

4451 Brookfield Corporate Dr. Suite 107
Chantilly, VA 20151
Office: (703)-631-7401
Fax: (703)-631-5282
Email: [email protected]

_______________________________________________
FloatCanvas mailing list
[email protected]
http://paulmcnett.com/cgi-bin/mailman/listinfo/floatcanvas

Reply via email to