Chris,
Thanks for the help. When I am done refactoring the code for the
HitTest(), I will apply the same changes to my MouseOver() method
(posted below - This one is much uglier). I also need to make changes to
FloatCanvas._RaiseMouseEvent() but am not really sure what. So far, not
having updated it, the only problem seems to come when panning the
floatcanvas and the mouse goes ontop of another object, which causes the
view to pan back to the starting point.
As far as speed goes I can not yet tell a difference between these
methods and the original color Hitmap.
I will also put together a small demo for the
FloatCanvas.EditableTextBox() but it required some additional methods to
be added to FloatCanvas.ScaledTextBox() but I think I can just overwrite
the ScaledTextBox class with the methods I added so as to comply with
the original FC installation.
def MouseOverTest(self, event):
##fixme: Can this be cleaned up?
if (self.HitDict and
(self.HitDict[EVT_FC_ENTER_OBJECT ] or
self.HitDict[EVT_FC_LEAVE_OBJECT ] )
):
#Get Mouse event, hit position
xy = event.GetPosition()
xy = self.PixelToWorld( xy )
#Initialize a few values
OldObject = self.ObjectUnderMouse
ObjectCallbackCalled = False
ObjectNoAction = True
objects = [] #Create object list for holding multiple objects
object_index_list = [] #Create list for holding the indexes
for key in self.HitDict[ EVT_FC_ENTER_OBJECT ].keys():
Object = self.HitDict[ EVT_FC_ENTER_OBJECT][key]
bb = self.HitDict[EVT_FC_ENTER_OBJECT][key].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[EVT_FC_ENTER_OBJECT][key]
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)
object_index_list.append(index) #append the index found
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))]
Object = highest_object_array[0]
xy = highest_object_array[1]
if (OldObject is None):
try:
Object.CallBackFuncs[EVT_FC_ENTER_OBJECT](Object)
ObjectCallbackCalled = True
ObjectNoAction = False
except KeyError:
pass # this means the enter event isn't bound
for that object
elif OldObject == Object: # the mouse is still on the
same object
pass
## Is the mouse on a differnt object as it was...
elif not (Object == OldObject):
# call the leave object callback
try:
OldObject.CallBackFuncs[EVT_FC_LEAVE_OBJECT](OldObject)
ObjectCallbackCalled = True
ObjectNoAction = False
except KeyError:
pass # this means the leave event isn't bound
for that object
try:
Object.CallBackFuncs[EVT_FC_ENTER_OBJECT](Object)
ObjectCallbackCalled = True
ObjectNoAction = False
except KeyError:
pass # this means the enter event isn't bound
for that object
## set the new object under mouse
self.ObjectUnderMouse = Object
objects = [] #Create object list for holding multiple objects
object_index_list = [] #Create list for holding the indexes
for key in self.HitDict[ EVT_FC_LEAVE_OBJECT ]:
Object = self.HitDict[ EVT_FC_LEAVE_OBJECT][key]
bb = self.HitDict[EVT_FC_LEAVE_OBJECT][key].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]:
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)
object_index_list.append(index) #append the index found
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))]
self.ObjectUnderMouse = highest_object_array[0]
ObjectNoAction = False
if ObjectNoAction == True:
# no objects under mouse bound to mouse-over events
self.ObjectUnderMouse = None
if OldObject:
try:
OldObject.CallBackFuncs[EVT_FC_LEAVE_OBJECT](OldObject)
ObjectCallbackCalled = True
except KeyError:
pass # this means the leave event isn't bound
for that object
return ObjectCallbackCalled
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