示例#1
0
bool wyNode::hitTest(float x, float y) {
    wyRect rect = getBoundingBoxRelativeToWorld();
    if(m_touchCoffin) {
        wyRect r2 = m_touchCoffin->getBoundingBoxRelativeToWorld();
        rect = wyrIntersect(rect, r2);
    }
    return wyrContains(rect, wyp(x, y));
}
示例#2
0
bool wyPageControl::touchesEnded(wyMotionEvent& e) {
	if(m_scrolling) {
		m_scrolling = false;

		if(!m_flinging) {
			int curIndex = getBestIndex();
			float start = m_vertical ? m_container->getPositionY() : m_container->getPositionX();
			wyPoint loc = wyp(e.x[0], e.y[0]);
			
			// if move is small, check page clicking
			// if move is not small, check fling
			bool clicked = false;
			if(!m_largeMove) {
				int firstIndex = getVisibleFirstIndex();
				int lastIndex = getVisibleLastIndex();
				for(int i = firstIndex; i <= lastIndex; i++) {
					wyNode* page = (wyNode*)wyArrayGet(m_pages, i);
					if(page) {
						wyRect bound = page->getBoundingBoxRelativeToWorld();
						if(wyrContains(bound, loc)) {							
							// normal center of this page
							float center = m_vertical ? (m_height / 2 - getPageCenterY(i)) : (m_width / 2 - getPageCenterX(i));
							
							// if it is current page, check whether it is clicked
							if(curIndex == i) {
								if(fabs(center - start) < DP(10)) {
									clicked = true;
									notifyOnPageClicked(i);
								}
							} 
							
							// if not 
							if(!clicked) {
								m_flinging = true;
								if(m_vertical)
									m_scroller->startScroll(0, start, 0, center - start, 1000);
								else
									m_scroller->startScroll(start, 0, center - start, 0, 1000);	
							}
							
							break;
						}
					}
				}
			} 
			
			// if not clicked, fling
			if(!clicked && !m_flinging) {
				m_flinging = true;
				if(!m_largeMove) {
					int best = getBestIndex();
					float center = m_vertical ? (m_height / 2 - getPageCenterY(best)) : (m_width / 2 - getPageCenterX(best));
					if(m_vertical)
						m_scroller->startScroll(0, start, 0, center - start, 1000);
					else
						m_scroller->startScroll(start, 0, center - start, 0, 1000);	
				} else {
					float start = m_vertical ? m_container->getPositionY() : m_container->getPositionX();
					float end = m_vertical ? (m_height / 2 - getPageCenterY(e.y[0] < m_beginY ? getRightIndex() : getLeftIndex()))
						: (m_width / 2 - getPageCenterX(e.x[0] < m_beginX ? getRightIndex() : getLeftIndex()));
					if(m_vertical)
						m_scroller->startScroll(0, start, 0, end - start, 1000);
					else
						m_scroller->startScroll(start, 0, end - start, 0, 1000);	
				}
				
				return true;	
			}
		}

		return true;
	}

	return false;
}