bool GuiButton::onEvent(const GEvent& event) { switch (event.type) { case GEventType::MOUSE_BUTTON_DOWN: m_down = true; // invoke the pre-event handler m_callback.execute(); fireEvent(GEventType::GUI_DOWN); return true; case GEventType::MOUSE_BUTTON_UP: fireEvent(GEventType::GUI_UP); // Only trigger an action if the mouse was still over the control if (m_down && m_rect.contains(event.mousePosition())) { fireEvent(GEventType::GUI_ACTION); } m_down = false; return true; } return false; }
bool WidgetManager::onEvent(const GEvent& event) { const bool motionEvent = (event.type == GEventType::MOUSE_MOTION) || (event.type == GEventType::JOY_AXIS_MOTION) || (event.type == GEventType::JOY_HAT_MOTION) || (event.type == GEventType::JOY_BALL_MOTION); const bool positionalEvent = (event.type == GEventType::MOUSE_BUTTON_CLICK) || (event.type == GEventType::MOUSE_BUTTON_DOWN) || (event.type == GEventType::MOUSE_BUTTON_UP) || (event.type == GEventType::MOUSE_MOTION); beginLock(); { // Deliver positional events in order of widget's depth preference if (positionalEvent) { const Point2& P = event.mousePosition(); // Find the distance at which object believes that it is for this event. By default, this is // the focus array position. Array<SortWrapper<shared_ptr<Widget> > > widgetWithZ; widgetWithZ.resize(m_moduleArray.size()); for (int i = 0; i < m_moduleArray.size(); ++i) { const shared_ptr<Widget>& w = m_moduleArray[i]; SortWrapper<shared_ptr<Widget> >& s = widgetWithZ[i]; s.value = w; s.key = w->positionalEventZ(P); if (isNaN(s.key)) { // The module wishes to use its focus position as a "Depth" if (w == m_focusedModule) { // Focused module gets priority and pretends that it is // higher than the first one s.key = float(m_moduleArray.size()); } else { s.key = float(i); } } // if default key } // for each widget widgetWithZ.sort(SORT_DECREASING); for (int i = 0; i < widgetWithZ.size(); ++i) { if (widgetWithZ[i].value->onEvent(event)) { // End the manager lock began at the top of this method before returning abruptly endLock(); return true; } } } else { // Except for motion events, ensure that the focused module gets each event first if (m_focusedModule && ! motionEvent) { if (m_focusedModule->onEvent(event)) { // End the manager lock began at the top of this method before returning abruptly endLock(); return true; } } for (int i = m_moduleArray.size() - 1; i >=0; --i) { // Don't double-deliver to the focused module if (motionEvent || (m_moduleArray[i] != m_focusedModule)) { if (m_moduleArray[i]->onEvent(event) && ! motionEvent) { // End the manager lock began at the top of this method before returning abruptly endLock(); return true; } } } } } endLock(); return false; }