Ejemplo n.º 1
0
	void updateScroll(){
		bool vBar = _scrollBar && _scrollBar->isVisible(),
			vNode = _scrollNode && _scrollNode->isVisible();
		if(!vBar || !vNode){
			return;
		}
		bool vert = getDirection() == kCCScrollViewDirectionVertical;
		CCPoint p, cp = getContentOffset();
		CCSize vs = getViewSize(),
			cs = getContentSize();
		float rate = 1 - (vert? fabsf(cp.y) / (cs.height - vs.height) : fabsf(cp.x) / (cs.width - vs.width));
		if(vBar){
			CCSize ss = _scrollBar->getPreferredSize();
			p = _scrollBar->getPosition();
			if(vert){	p.y = cs.height - (cs.height - ss.height) * rate - ss.height - _scrollTrackDelta;
			}else{		p.x = cs.width - (cs.width - ss.width) * rate - ss.width - _scrollTrackDelta;
			}
			_scrollBar->setPosition(p);
		}
		if(vNode){
			p = _scrollNode->getPosition();
			if(vert){	p.y = cp.y + vs.height * rate;
			}else{		p.x = cp.x + vs.width * rate;
			}
			_scrollNode->setPosition(p);
		}
		if(_scrollTrack){
			p = _scrollTrack->getPosition();
			if(vert){	p.y = fabsf(cp.y);
			}else{		p.x = fabsf(cp.x);
			}
			_scrollTrack->setPosition(p);
		}
//CCLog("LuaTableView.updateScroll ss=%d,%d vh=%d cy=%d ch=%d y=%d", (int)ss.width, (int)ss.height, (int)vs.height, (int)p.y, (int)cs.height, (int)_scrollBar->getPositionY());
	}
Ejemplo n.º 2
0
	void resetScroll(){
		if(!_scrollBar){ return;}
		CCSize vs = getViewSize(), cs = getContentSize();
		bool vert = getDirection() == kCCScrollViewDirectionVertical;
		bool v = vert? vs.height < cs.height : vs.width < cs.height;
		_scrollBar->setVisible(v);
		CCPoint p = ccp(0, 0), ap = vert? ccp(1,0) : CCPointZero;
		if(v){
			CCSize s = _scrollBar->getPreferredSize(),
				st = _scrollTrack? _scrollTrack->getPreferredSize() : CCSizeZero;
			if(vert){
				p.x = vs.width + _scrollOffset - (st.width > 0? (st.width - s.width) / 2 : 0);
				_scrollTrackDelta = st.height > 0? (st.height - s.height) / 2 : 0;
				s.height = vs.height / cs.height * vs.height - _scrollTrackDelta * 2;
			}else{
				p.y = vs.height + _scrollOffset - (st.height > 0? (st.height - s.height) / 2 : 0);
				_scrollTrackDelta = st.width > 0? (st.width - s.width) / 2 : 0;
				s.width = vs.width / cs.width * vs.width - _scrollTrackDelta * 2;
			}
			_scrollBar->setAnchorPoint(ap);
			_scrollBar->setPreferredSize(s);
			_scrollBar->setPosition(p);
//CCLog("LuaTableView vScroll.size=%d,%d vh=%d ch=%d", (int)s.width, (int)s.height, (int)vs.height, (int)cs.height);
		}
		if(_scrollTrack){
			_scrollTrack->setVisible(v);
			if(v){
				CCSize s = _scrollTrack->getPreferredSize();
				if(vert){
					p.x = vs.width + _scrollOffset;
					s.height = vs.height;
				}else{
					p.y = vs.height + _scrollOffset;
					s.width = vs.width;
				}
				_scrollTrack->setAnchorPoint(ap);
				_scrollTrack->setPreferredSize(s);
				_scrollTrack->setPosition(p);
			}
		}
//CCLog("LuaTableView reload vscr=%x visible=%d", _scroller, _scrollBar->isVisible());
		updateScroll();
	}