bool PullToRefreshTrait::OnPreviewTouchMoved(Control& source, const TouchEventInfo& touchEventInfo) { if(_captured) { int offset; if(_direction == PULL_TO_REFRESH_DIRECTION_TOP) offset = (touchEventInfo.GetCurrentPosition() - _touchDownPoint).y; else offset = -(touchEventInfo.GetCurrentPosition() - _touchDownPoint).y; float progress = (float)offset / (float)PULL_TO_REFRESH_OFFSET_LIMIT; if(progress > 1.0f) { progress = 1.0f; } Canvas *canvas = _progressControl->GetCanvasN(); int doneSize = (int)(canvas->GetBoundsF().width * progress); int undoneSize = canvas->GetBounds().width - doneSize; if(undoneSize < 0) { undoneSize = 0; } Rectangle progressRectangle = canvas->GetBounds(); progressRectangle.width -= undoneSize; progressRectangle.x += undoneSize / 2; canvas->SetCompositeMode(COMPOSITE_MODE_OVERLAY); canvas->FillRectangle(Color(0x569cdd, false), progressRectangle); delete canvas; } return false; }
bool PullToRefreshTrait::OnPreviewTouchReleased(Control& source, const TouchEventInfo& touchEventInfo) { if(_captured) { if(_direction == PULL_TO_REFRESH_DIRECTION_TOP) { if((touchEventInfo.GetCurrentPosition() - _touchDownPoint).y > PULL_TO_REFRESH_OFFSET_LIMIT) { _refreshable->OnRefresh(); } } else { if((touchEventInfo.GetCurrentPosition() - _touchDownPoint).y < -PULL_TO_REFRESH_OFFSET_LIMIT) { _refreshable->OnRefresh(); } } _progressControl->RequestRedraw(true); } return false; }
// IPropagatedTouchEventListener bool PullToRefreshTrait::OnPreviewTouchPressed(Control& source, const TouchEventInfo& touchEventInfo) { _touchDownPoint = touchEventInfo.GetCurrentPosition(); if(_direction == PULL_TO_REFRESH_DIRECTION_TOP) { _captured = _tableView->GetCurrentScrollPosition() == 0; } else { _captured = _tableView->GetBottomDrawnItemIndex() == (_tableView->GetItemCount() - 1); } return false; }
void CCEGLView::OnTouchReleased(const Control& source, const Point& currentPosition, const TouchEventInfo & touchInfo) { int id = (int)touchInfo.GetPointId(); float x = (float)touchInfo.GetCurrentPosition().x; float y = (float)touchInfo.GetCurrentPosition().y; if (!m_bNotHVGA) { x = x * 2 / 3; y = y * 2 / 3; } onTouchesEnd(&id, &x, &y, 1); CCLOG("OnTouchReleased id = %d,x = %f,y = %f", id, x, y); }
void CCEGLView::OnTouchPressed(const Control& source, const Point& currentPosition, const TouchEventInfo & touchInfo) { int id = (int)touchInfo.GetPointId(); float x = (float)touchInfo.GetCurrentPosition().x; float y = (float)touchInfo.GetCurrentPosition().y; CCLOG("OnTouchPressed id = %d,x = %f,y = %f, count = %d", id, x, y, s_mapTouches.GetCount()); if (!m_bNotHVGA) { x = x * 2 / 3; y = y * 2 / 3; } onTouchesBegin(&id, &x, &y, 1); }