BOOL WidgetContainer::DoDrag(const EventInputPointer *ev, IWidget *widget) { f32 cX = ev->GetX(); f32 cY = ev->GetY(); u32 j = ev->GetJoystick(); WidgetIterator it = vWidget.begin(); WidgetIterator end = vWidget.end(); IWidget *receiver = NULL; for (; it != end; ++it) { IWidget *w = (*it); ASSERT_NULL(w); /* FIX ME */ w->SetPlayerState(Seed::WidgetStateDrag, j); /* FIX ME */ if (w != widget && w->ContainsPoint(pInput->GetX(), pInput->GetY()) && !w->IsDisabled()) { receiver = w; //break; const EventWidget newEvent(widget, receiver, WidgetEventDrag, j, cX, cY, ev->GetPressed(), ev->GetHold(), ev->GetReleased()); LOG(">DRAG OVER [id: %d]", receiver->GetId()); LOG("\tEstado WIDGET"); widget->SetState(Seed::WidgetStateDrag); widget->OnWidgetDrag(&newEvent); widget->SendOnDrag(&newEvent); LOG("\tEvento"); if (newEvent.IsConsumed()) return TRUE; } } if (!receiver) { const EventWidget newEvent(widget, NULL, WidgetEventDrag, j, cX, cY, ev->GetPressed(), ev->GetHold(), ev->GetReleased()); LOG(">DRAG [id: %d]", widget->GetId()); LOG("\tEstado WIDGET"); widget->SetState(Seed::WidgetStateDrag); widget->OnWidgetDrag(&newEvent); widget->SendOnDrag(&newEvent); LOG("\tEvento"); if (newEvent.IsConsumed()) return TRUE; } return FALSE; }
BOOL WidgetContainer::DoReleaseOut(const EventInputPointer *ev, IWidget *widget) { f32 cX = ev->GetX(); f32 cY = ev->GetY(); u32 j = ev->GetJoystick(); const EventWidget newEvent(widget, NULL, WidgetEventReleasedOut, j, cX, cY, ev->GetPressed(), ev->GetHold(), ev->GetReleased()); u32 count = 0; // count how many players in any PRESSED_* state exists for (u32 i = 0; i < PLATFORM_MAX_INPUT; i++) { eWidgetState s = widget->GetPlayerState(i); if (s == Seed::WidgetStatePressedOver || s == Seed::WidgetStatePressedOut) count++; } LOG("\tRELEASE OUT [id: %d]", widget->GetId()); // if its the only PRESSED_* we can change the state to NONE if (count == 1) { LOG("\tEstado WIDGET"); widget->SetState(Seed::WidgetStateNone); widget->OnWidgetReleaseOut(&newEvent); } LOG("\tEstado PLAYER"); widget->SetPlayerState(Seed::WidgetStateNone, j); widget->SendOnReleaseOut(&newEvent); LOG("\tEvento"); return newEvent.IsConsumed(); }
BOOL WidgetContainer::DoOver(const EventInputPointer *ev, IWidget *widget) { f32 cX = ev->GetX(); f32 cY = ev->GetY(); u32 j = ev->GetJoystick(); //LOG("> OVER [%d, %f, %f]", j, cX, cY); LOG("> ROLL OVER [id: %d]", widget->GetId()); if (widget->GetPlayerState(j) == Seed::WidgetStatePressedOut) { //LOG("- %d OVER - PRESSED OUT", j); LOG("\tEstado PLAYER"); widget->SetPlayerState(Seed::WidgetStatePressedOver, j); widget->SetState(Seed::WidgetStatePressed); } if (widget->GetPlayerState(j) == Seed::WidgetStatePressedOver) { //LOG("- %d OVER - PRESSED OVER", j); return FALSE; } const EventWidget newEvent(widget, NULL, WidgetEventOver, j, cX, cY, ev->GetPressed(), ev->GetHold(), ev->GetReleased()); if (widget->GetState() == Seed::WidgetStateNone) { //LOG("- %d OVER - State == NONE", j); // dispatch event to widget manage its internal state LOG("\tEstado WIDGET"); widget->OnWidgetRollOver(&newEvent); widget->SetState(Seed::WidgetStateOver); } // to guarantee that we will send only one over event by player to widget if (widget->GetPlayerState(j) == Seed::WidgetStateNone) { //LOG("- %d OVER - PlayerState == NONE"); LOG("\tEstado PLAYER"); widget->SetPlayerState(Seed::WidgetStateOver, j); // dispatch event to widget listeners widget->SendOnRollOver(&newEvent); LOG("\tEvento"); if (newEvent.IsConsumed()) return TRUE; } return FALSE; }
BOOL WidgetContainer::DoRelease(const EventInputPointer *ev, IWidget *widget) { f32 cX = ev->GetX(); f32 cY = ev->GetY(); u32 j = ev->GetJoystick(); //LOG("> RELEASE OVER [%d, %f, %f]", j, cX, cY); const EventWidget newEvent(widget, NULL, WidgetEventReleased, j, cX, cY, ev->GetPressed(), ev->GetHold(), ev->GetReleased()); u32 count = 0; // count how many players in PRESSED_OVER exists for (u32 i = 0; i < PLATFORM_MAX_INPUT; i++) { eWidgetState s = widget->GetPlayerState(i); if (s == Seed::WidgetStatePressedOver || s == Seed::WidgetStatePressedOut) count++; } LOG(">RELEASE [id: %d]", widget->GetId()); // if its the only PRESSED_OVER we can change the state to OVER here if (count == 1) { //LOG("- RELEASE OVER SetState OVER"); LOG("\tEstado WIDGET"); #if defined(_IPHONE_) widget->SetState(Seed::WidgetStateOver); #else widget->SetState(Seed::WidgetStateNone); #endif widget->OnWidgetRelease(&newEvent); } LOG("\tEstado PLAYER"); #if defined(_IPHONE_) widget->SetPlayerState(Seed::WidgetStateOver, j); #else widget->SetPlayerState(Seed::WidgetStateNone, j); #endif widget->SendOnRelease(&newEvent); LOG("\tEvento"); return newEvent.IsConsumed(); }
void WidgetContainer::OnInputPointerPress(const EventInputPointer *ev) { ASSERT_NULL(ev); WidgetIterator it = vWidget.begin(); WidgetIterator end = vWidget.end(); f32 cX = ev->GetX(); f32 cY = ev->GetY(); BOOL found = FALSE; for (; it != end; ++it) { IWidget *w = (*it); ASSERT_NULL(w); bEventConsumed = FALSE; if (w->IsDisabled()) continue; if (!w->ContainsPoint(cX, cY)) continue; if (w->GetObjectType() == Seed::ObjectGuiWidgetContainer) { WidgetContainer *wc = reinterpret_cast<WidgetContainer *>(w); wc->OnInputPointerPress(ev); bEventConsumed = wc->IsEventConsumed(); if (bEventConsumed) break; } if (!(w->GetTrigger() & ev->GetPressed())) continue; u32 j = ev->GetJoystick(); //LOG("> PRESS [%d, %f, %f]", j, cX, cY); if (w->GetState() == Seed::WidgetStateDrag) { continue; } found = TRUE; const EventWidget newEvent(w, NULL, WidgetEventPressed, j, cX, cY, ev->GetPressed(), ev->GetHold(), ev->GetReleased()); LOG(">PRESSED_OVER [id: %d]", w->GetId()); // GetState eh o baseado em prioridade a partir de todos os inputs. if (w->GetState() != Seed::WidgetStatePressedOver && w->GetPlayerState(j) != Seed::WidgetStatePressedOver) { // muda apenas o estado interno do widget LOG("\tEstado WIDGET"); w->OnWidgetPress(&newEvent); } w->SetState(Seed::WidgetStatePressed); w->SetPlayerState(Seed::WidgetStatePressedOver, j); LOG("\tEstado PLAYER"); w->SendOnPress(&newEvent); LOG("\tEvento"); //if (newEvent.IsConsumed()) bEventConsumed = newEvent.IsConsumed(); if (bEventConsumed) break; } if (!found) // avoid call { // If no widget have collision, then we try distance based input; f32 maxDist = pConfiguration->GetInputDistanceRadius(); if (maxDist) { IWidget *nearest = this->FindNearestByRadius(maxDist, ev); if (nearest) { IWidget *w = nearest; if (w->GetObjectType() == Seed::ObjectGuiWidgetContainer) { WidgetContainer *wc = reinterpret_cast<WidgetContainer *>(w); wc->OnInputPointerPress(ev); bEventConsumed = wc->IsEventConsumed(); if (bEventConsumed) return; } u32 j = ev->GetJoystick(); const EventWidget newEvent(w, NULL, WidgetEventPressed, j, cX, cY, ev->GetPressed(), ev->GetHold(), ev->GetReleased()); LOG(">PRESSED_OVER [id: %d]", w->GetId()); // GetState eh o baseado em prioridade a partir de todos os inputs. if (w->GetState() != Seed::WidgetStatePressedOver && w->GetPlayerState(j) != Seed::WidgetStatePressedOver) { // muda apenas o estado interno do widget LOG("\tEstado WIDGET"); w->OnWidgetPress(&newEvent); } w->SetState(Seed::WidgetStatePressed); w->SetPlayerState(Seed::WidgetStatePressedOver, j); LOG("\tEstado PLAYER"); w->SendOnPress(&newEvent); LOG("\tEvento"); bEventConsumed = newEvent.IsConsumed(); if (bEventConsumed) return; } } } }
void WidgetContainer::OnInputPointerPress(const EventInputPointer *ev) { ASSERT_NULL(ev); WidgetIterator it = vWidget.begin(); WidgetIterator end = vWidget.end(); for (; it != end; ++it) { IWidget *w = (*it); ASSERT_NULL(w); bEventConsumed = FALSE; if (w->IsDisabled()) continue; f32 cX = ev->GetX(); f32 cY = ev->GetY(); if (!w->ContainsPoint(cX, cY)) continue; if (w->GetObjectType() == Seed::ObjectGuiWidgetContainer) { WidgetContainer *wc = reinterpret_cast<WidgetContainer *>(w); wc->OnInputPointerPress(ev); bEventConsumed = wc->IsEventConsumed(); if (bEventConsumed) break; } if (!(w->GetTrigger() & ev->GetPressed())) continue; u32 j = ev->GetJoystick(); //LOG("> PRESS [%d, %f, %f]", j, cX, cY); if (w->GetState() == Seed::WidgetStateDrag) { continue; } const EventWidget newEvent(w, NULL, WidgetEventPressed, j, cX, cY, ev->GetPressed(), ev->GetHold(), ev->GetReleased()); LOG(">PRESSED_OVER [id: %d]", w->GetId()); // GetState eh o baseado em prioridade a partir de todos os inputs. if (w->GetState() != Seed::WidgetStatePressedOver && w->GetPlayerState(j) != Seed::WidgetStatePressedOver) { // muda apenas o estado interno do widget LOG("\tEstado WIDGET"); w->OnWidgetPress(&newEvent); } w->SetState(Seed::WidgetStatePressed); w->SetPlayerState(Seed::WidgetStatePressedOver, j); LOG("\tEstado PLAYER"); w->SendOnPress(&newEvent); LOG("\tEvento"); //if (newEvent.IsConsumed()) bEventConsumed = newEvent.IsConsumed(); if (bEventConsumed) break; } }