private ProfileEventData.ProfileContext.Event GetEventFromMousePosition(int x, int y) { if (x < 0 || x > ClientSize.Width) { return(null); } int contextmaxy = (int)m_YOffset; int contextStart = (int)m_YOffset; FindEventContext findContext = new FindEventContext(); int width = ClientSize.Width; findContext.Time = ConvertXToTime(x); // find which context it's in foreach (ProfileEventData.ProfileContext context in m_Data.Contexts.Values) { if (context.Heads.Count == 0) { continue; } contextmaxy += TitleHeight; contextmaxy += ((context.MaxLevel + 1) * EventHeight); if (y < contextmaxy) { findContext.TargetDepth = ((y - contextStart) - TitleHeight) / (EventHeight); foreach (ProfileEventData.ProfileContext.Event profileEvent in context.Heads) { ProfileEventData.ProfileContext.Event foundEvent = GetEventFromMousePositionInContext(findContext, profileEvent); if (foundEvent != null) { return(foundEvent); } } } contextStart = contextmaxy; } return(null); }
private ProfileEventData.ProfileContext.Event GetEventFromMousePositionInContext(FindEventContext findContext, ProfileEventData.ProfileContext.Event profileEvent) { if (findContext.Time >= profileEvent.Time && findContext.Time <= profileEvent.EndTime) { // could be in this one, if the depth is good if (findContext.TargetDepth == profileEvent.Level) { return(profileEvent); } // depth isn't correct, search the childs if (profileEvent.Child != null) { ProfileEventData.ProfileContext.Event child = profileEvent.Child; while (child != null) { profileEvent = GetEventFromMousePositionInContext(findContext, child); if (profileEvent != null) { return(profileEvent); } child = child.Sibling; } } } return(null); }