//-------------------------------------------------------------------------------- void CRowColumnView::layoutViewsEqualSize () { CPoint maxSize; getMaxChildViewSize (maxSize); if (style == kRowStyle) maxSize.x = getViewSize ().getWidth () - (margin.right + margin.left); else maxSize.y = getViewSize ().getHeight () - (margin.top + margin.bottom); CPoint location = margin.getTopLeft (); ViewIterator it (this); while (*it) { CView* view = *it; CRect viewSize = view->getViewSize (); viewSize.originize (); viewSize.offset (location.x, location.y); switch (layoutStyle) { case kStretchEqualy: { viewSize.setWidth (maxSize.x); viewSize.setHeight (maxSize.y); break; } case kCenterEqualy: { CCoord diffX = (maxSize.x - viewSize.getWidth ()) / 2.; CCoord diffY = (maxSize.y - viewSize.getHeight ()) / 2.; viewSize.offset (diffX, diffY); break; } case kRightBottomEqualy: { CCoord diffX = maxSize.x - viewSize.getWidth (); CCoord diffY = maxSize.y - viewSize.getHeight (); viewSize.offset (diffX, diffY); break; } default: break; } resizeSubView (view, viewSize); if (style == kRowStyle) { location.y += spacing; location.y += viewSize.getHeight (); } else { location.x += spacing; location.x += viewSize.getWidth (); } it++; } }
Vec2f UIViewport::getCorrectedViewSize(void) const { if(getViewSize() != Vec2f(-1,-1)) { return getViewSize(); } else { return getViewComponent()->getPreferredScrollableViewportSize(); } }
//------------------------------------------------------------------------ bool CTextButton::getFocusPath (CGraphicsPath& outPath) { CRect r (getViewSize ()); CCoord focusWidth = getFrame ()->getFocusWidth (); r.inset (-focusWidth, -focusWidth); outPath.addRoundRect (r, roundRadius); outPath.closeSubpath (); r = getViewSize (); r.inset (frameWidth / 2., frameWidth / 2.); outPath.addRoundRect (r, roundRadius); return true; }
//----------------------------------------------------------------------------- void CSegmentButton::drawRect (CDrawContext* pContext, const CRect& dirtyRect) { bool isHorizontal = style == kHorizontal; SharedPointer<CGraphicsPath> path; if (gradient || gradientHighlighted || (getFrameWidth () > 0. && getFrameColor ().alpha != 0)) { CRect r (getViewSize ()); r.inset (getFrameWidth () / 2., getFrameWidth () / 2.); path = owned (pContext->createGraphicsPath ()); path->addRoundRect (r, getRoundRadius ()); } pContext->setDrawMode (kAntiAliasing); bool drawLines = getFrameWidth () > 0. && getFrameColor ().alpha != 0; if (drawLines) { pContext->setLineStyle (kLineSolid); pContext->setLineWidth (getFrameWidth ()); pContext->setFrameColor (getFrameColor ()); } if (gradient) { pContext->fillLinearGradient (path, *gradient, getViewSize ().getTopLeft (), getViewSize ().getBottomLeft ()); } uint32_t selectedIndex = getSelectedSegment (); for (uint32_t index = 0; index < segments.size (); ++index) { Segment& segment = segments[index]; if (!dirtyRect.rectOverlap (segment.rect)) continue; CRect oldClip; pContext->getClipRect (oldClip); CRect clipRect (segment.rect); clipRect.bound (oldClip); pContext->setClipRect (clipRect); bool selected = selectedIndex == index; if (selected && gradientHighlighted) pContext->fillLinearGradient (path, *gradientHighlighted, segment.rect.getTopLeft (), segment.rect.getBottomLeft ()); if (selected && segment.backgroundHighlighted) segment.backgroundHighlighted->draw (pContext, segment.rect); else if (segment.background) segment.background->draw (pContext, segment.rect); CDrawMethods::drawIconAndText (pContext, selected ? segment.iconHighlighted : segment.icon, segment.iconPosition, textAlignment, textMargin, segment.rect, segment.name, font, selected ? textColorHighlighted : textColor); pContext->setClipRect (oldClip); if (drawLines && index > 0 && index < segments.size ()) { path->beginSubpath (segment.rect.getTopLeft ()); path->addLine (isHorizontal ? segment.rect.getBottomLeft () : segment.rect.getTopRight ()); } } if (drawLines) pContext->drawGraphicsPath (path, CDrawContext::kPathStroked); setDirty (false); }
/** * @param src rect which to scroll * @param distance point of distance */ void CFrame::scrollRect (const CRect& src, const CPoint& distance) { CRect rect (src); rect.offset (getViewSize ().left, getViewSize ().top); if (platformFrame) { if (platformFrame->scrollRect (src, distance)) return; } invalidRect (src); }
//------------------------------------------------------------------------ float CSlider::calculateDelta (const CPoint& where, CRect* handleRect) const { CCoord result; if (style & kHorizontal) result = getViewSize ().left + offsetHandle.x; else result = getViewSize ().top + offsetHandle.y; if (getMode () != kFreeClickMode) { float normValue = getValueNormalized (); if (style & kRight || style & kBottom) normValue = 1.f - normValue; CCoord actualPos; CRect rect; actualPos = result + (int32_t)(normValue * rangeHandle); if (style & kHorizontal) { if (handleRect) { handleRect->left = actualPos; handleRect->top = getViewSize ().top + offsetHandle.y; handleRect->right = handleRect->left + widthOfSlider; handleRect->bottom = handleRect->top + heightOfSlider; } result += where.x - actualPos; } else { if (handleRect) { handleRect->left = getViewSize ().left + offsetHandle.x; handleRect->top = actualPos; handleRect->right = handleRect->left + widthOfSlider; handleRect->bottom = handleRect->top + heightOfSlider; } result += where.y - actualPos; } } else { if (style & kHorizontal) result += widthOfSlider / 2 - 1; else result += heightOfSlider / 2 - 1; } return (float)result; }
//----------------------------------------------------------------------------- void CScrollView::setContainerSize (const CRect& cs, bool keepVisibleArea) { CRect oldSize (containerSize); containerSize = cs; if (sc) { sc->setContainerSize (cs); } if (style & kAutoHideScrollbars) recalculateSubViews (); if (vsb) { CRect oldScrollSize = vsb->getScrollSize (oldScrollSize); float oldValue = vsb->getValue (); vsb->setScrollSize (cs); if (cs.getHeight () <= getViewSize ().getHeight ()) vsb->setValue (0); else if (sc && keepVisibleArea && oldScrollSize.getHeight () != cs.getHeight ()) { CRect vSize = sc->getViewSize (vSize); float newValue = (float)(oldValue * ((float)(oldScrollSize.getHeight () - vSize.getHeight ()) / ((float)cs.getHeight () - vSize.getHeight ()))); if (newValue > 1.f) newValue = 1.f; else if (newValue < 0.f) newValue = 0.f; vsb->setValue (newValue); } valueChanged (vsb); } if (hsb) { CRect oldScrollSize = hsb->getScrollSize (oldScrollSize); float oldValue = hsb->getValue (); hsb->setScrollSize (cs); if (cs.getWidth () <= getViewSize ().getWidth ()) hsb->setValue (0); else if (sc && keepVisibleArea && oldScrollSize.getWidth () != cs.getWidth ()) { CRect vSize = sc->getViewSize (vSize); float newValue = (float)(oldValue * ((float)(oldScrollSize.getWidth () - vSize.getWidth ()) / ((float)cs.getWidth () - vSize.getWidth ()))); if (newValue > 1.f) newValue = 1.f; else if (newValue < 0.f) newValue = 0.f; hsb->setValue (newValue); } valueChanged (hsb); } }
CMouseEventResult CWaveDisplay::onMouseMoved(CPoint& where, const CButtonState& buttons) { if (buttons.isLeftButton() && getViewSize().pointInside(where)) this->where = where; return CMouseEventResult::kMouseEventHandled; }
void LuaTableView::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? abs(cp.y) / (cs.height - vs.height) : abs(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 = abs(cp.y); }else{ p.x = abs(cp.x); } _scrollTrack->setPosition(p); } //CCLog("LTV.up 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()); }
//------------------------------------------------------------------------ bool CCheckBox::sizeToFit () { if (title == 0) return false; IFontPainter* painter = font ? font->getFontPainter () : 0; if (painter) { CRect fitSize (getViewSize ()); if (getDrawBackground ()) { fitSize.setWidth (getDrawBackground ()->getWidth ()); fitSize.setHeight (getDrawBackground ()->getHeight () / 6); } else { fitSize.setWidth (fitSize.getHeight ()); } fitSize.right += kCheckBoxTitleMargin; fitSize.right += painter->getStringWidth (0, title, true); setViewSize (fitSize); setMouseableArea (fitSize); return true; } return false; }
//------------------------------------------------------------------------ CMouseEventResult CKickButton::onMouseMoved (CPoint& where, const CButtonState& buttons) { if (isEditing ()) { if (where.h >= getViewSize ().left && where.v >= getViewSize ().top && where.h <= getViewSize ().right && where.v <= getViewSize ().bottom) value = getMax (); else value = getMin (); if (isDirty ()) invalid (); return kMouseEventHandled; } return kMouseEventNotHandled; }
//----------------------------------------------------------------------------- void CScrollbar::doStepping () { CRect scrollerRect = getScrollerRect (); if (timer) { if (!getViewSize ().pointInside (startPoint) || scrollerRect.pointInside (startPoint)) return; } bool dir = (direction == kHorizontal && startPoint.x < scrollerRect.left) || (direction == kVertical && startPoint.y < scrollerRect.top); float newValue; if (direction == kHorizontal) { if (dir) newValue = value - (float)scrollerLength / (float)scrollerArea.getWidth (); else newValue = value + (float)scrollerLength / (float)scrollerArea.getWidth (); } else { if (dir) newValue = value - (float)scrollerLength / (float)scrollerArea.getHeight (); else newValue = value + (float)scrollerLength / (float)scrollerArea.getHeight (); } if (newValue < 0.f) newValue = 0.f; if (newValue > 1.f) newValue = 1.f; if (newValue != value) { value = newValue; valueChanged (); invalid (); } }
void WXTableView::navigateCellByIdx(unsigned int idx, CCPoint delta, bool animated) { unsigned int cellsCount = _dataSource->numberOfCellsInTableView(this); if (idx<0 || idx>=cellsCount) { return; } CCSize cellSize = _dataSource->tableCellSizeForIndex(this, 0);//先cell固定大小吧 CCSize viewSize = getViewSize(); int offsetX = 0; int offsetY = 0; CCPoint maxInset, minInset; maxInset = this->maxContainerOffset(); minInset = this->minContainerOffset(); switch (this->getDirection()) { case ScrollView::Direction::HORIZONTAL: { offsetX = minInset.x + idx * cellSize.width + delta.x; offsetX = MAX(offsetX, minInset.x); offsetX = MIN(offsetX, maxInset.x); } break; default://最底下的cell所在位置为(0,0) { offsetY = minInset.y + idx * cellSize.height + delta.y; offsetY = MAX(offsetY, minInset.y); offsetY = MIN(offsetY, maxInset.y); } break; } setContentOffset(ccp(offsetX, offsetY), animated); }
//---------------------------------------------------------------------------------------------------- CRect UISearchTextField::getClearMarkRect () const { CRect r (getViewSize ()); r.left = r.right - getHeight (); r.inset (2, 2); return r; }
void CCCGameScrollView::adjustScrollView( const cocos2d::CCPoint &oBegin, const cocos2d::CCPoint &oEnd) { int nPage = 0; int nAdjustPage = 0; if (m_eDirection == kCCScrollViewDirectionHorizontal) { nPage = abs(oBegin.x / (int)m_CellSize.width); int nDis = oEnd.x - oBegin.x; if (nDis < -getViewSize().width / 5) { nAdjustPage = nPage + 1; } else if (nDis > getViewSize().width / 5) { nAdjustPage = nPage - 1; } else { nAdjustPage = nPage; } } else { nPage = abs(oBegin.y / (int)m_CellSize.height); int nDis = oEnd.y - oBegin.y; if (nDis < -getViewSize().height / 5) { nAdjustPage = nPage - 1; } else if (nDis > getViewSize().height / 5) { nAdjustPage = nPage + 1; } else { nAdjustPage = nPage; } } nAdjustPage = MIN(nAdjustPage, m_nPageCount - 1); nAdjustPage = MAX(nAdjustPage, 0); scrollToPage(nAdjustPage); }
//----------------------------------------------------------------------------- void CGradientView::setViewSize (const CRect& rect, bool invalid) { if (rect != getViewSize ()) { CView::setViewSize (rect, invalid); path = 0; } }
//----------------------------------------------------------------------------------------------- void CDataBrowser::setViewSize (const CRect& size, bool invalid) { if (getViewSize () != size) { CScrollView::setViewSize (size, invalid); recalculateLayout (true); } }
//------------------------------------------------------------------------ CRect CTextEdit::platformGetSize () const { CRect rect = getViewSize (); CPoint p (0, 0); localToFrame (p); rect.offset (p.x, p.y); return rect; }
Status MovieExporter::generateImageSequence( const Object* obj, std::function<void(float)> progress ) { int frameStart = mDesc.startFrame; int frameEnd = mDesc.endFrame; QSize exportSize = mDesc.exportSize; bool transparency = false; QString strCameraName = mDesc.strCameraName; auto cameraLayer = (LayerCamera*)obj->findLayerByName( strCameraName, Layer::CAMERA ); if ( cameraLayer == nullptr ) { cameraLayer = obj->getLayersByType< LayerCamera >().front(); } for ( int currentFrame = frameStart; currentFrame <= frameEnd; currentFrame++ ) { if ( mCanceled ) { return Status::CANCELED; } QImage imageToExport( exportSize, QImage::Format_ARGB32_Premultiplied ); QColor bgColor = Qt::white; if ( transparency ) { bgColor.setAlpha( 0 ); } imageToExport.fill( bgColor ); QPainter painter( &imageToExport ); QTransform view = cameraLayer->getViewAtFrame( currentFrame ); QSize camSize = cameraLayer->getViewSize(); QTransform centralizeCamera; centralizeCamera.translate( camSize.width() / 2, camSize.height() / 2 ); painter.setWorldTransform( view * centralizeCamera ); painter.setWindow( QRect( 0, 0, camSize.width(), camSize.height() ) ); obj->paintImage( painter, currentFrame, false, true ); QString imageFileWithFrameNumber = QString().sprintf( IMAGE_FILENAME, currentFrame ); QString strImgPath = mTempWorkDir + imageFileWithFrameNumber; bool bSave = imageToExport.save( strImgPath ); Q_ASSERT( bSave ); qDebug() << "Save img to: " << strImgPath; float fProgressValue = ( currentFrame / (float)( frameEnd - frameStart ) ); progress( 0.1f + ( fProgressValue * 0.99f ) ); } return Status::OK; }
//------------------------------------------------------------------------ void CTextLabel::setViewSize (const CRect& rect, bool invalid) { CRect current (getViewSize ()); CParamDisplay::setViewSize (rect, invalid); if (textTruncateMode != kTruncateNone && current.getWidth () != getWidth ()) { calculateTruncatedText (); } }
FloatCoord Gui::convertIntToRelative(const IntCoord& _coord, WidgetPtr _parent) { const FloatSize& size = getViewSize(); if (null == _parent) { return FloatCoord(_coord.left / size.width, _coord.top / size.height, _coord.width / size.width, _coord.height / size.height); } const IntCoord& coord = _parent->getClientCoord(); return FloatCoord(1.*_coord.left / coord.width, 1.*_coord.top / coord.height, 1.*_coord.width / coord.width, 1.*_coord.height / coord.height); }
IntCoord Gui::convertRelativeToInt(const FloatCoord& _coord, WidgetPtr _parent) { const FloatSize& size = getViewSize(); if (null == _parent) { return IntCoord(_coord.left * size.width, _coord.top * size.height, _coord.width * size.width, _coord.height * size.height); } const IntCoord& coord = _parent->getClientCoord(); return IntCoord(_coord.left * coord.width, _coord.top * coord.height, _coord.width * coord.width, _coord.height * coord.height); }
//------------------------------------------------------------------------ CSlider::CSlider (const CRect &rect, IControlListener* listener, int32_t tag, int32_t iMinPos, int32_t iMaxPos, CBitmap* handle, CBitmap* background, const CPoint& offset, const int32_t style) : CControl (rect, listener, tag, background) , offset (offset) , pHandle (handle) , style (style) , minPos (iMinPos) , mode (kFreeClickMode) , drawStyle (0) { setDrawTransparentHandle (true); if (pHandle) { pHandle->remember (); widthOfSlider = pHandle->getWidth (); heightOfSlider = pHandle->getHeight (); } else { widthOfSlider = 1; heightOfSlider = 1; } widthControl = getViewSize ().getWidth (); heightControl = getViewSize ().getHeight (); if (style & kHorizontal) { minPos = iMinPos - getViewSize ().left; rangeHandle = (CCoord)iMaxPos - iMinPos; } else { minPos = iMinPos - getViewSize ().top; rangeHandle = (CCoord)iMaxPos - iMinPos; } CPoint p (0, 0); setOffsetHandle (p); zoomFactor = 10.f; setWantsFocus (true); }
//----------------------------------------------------------------------------- void CTabView::alignTabs (TabAlignment alignment) { CCoord allTabsWidth; CCoord viewWidth; CCoord offset = 0; CRect ts (tabSize.left, tabSize.top, tabSize.getWidth (), tabSize.getHeight () / 2); if (tabPosition == kPositionTop || tabPosition == kPositionBottom) { allTabsWidth = tabSize.getWidth () * numberOfChilds; viewWidth = getViewSize ().getWidth (); } else { allTabsWidth = (tabSize.getHeight () / 2) * numberOfChilds; viewWidth = getViewSize ().getHeight (); } if (alignment == kAlignCenter) offset = (viewWidth - allTabsWidth) / 2; else if (alignment == kAlignLeft) offset = 0; else if (alignment == kAlignRight) offset = viewWidth - allTabsWidth; if (tabPosition == kPositionTop) ts.offset (offset, 0); else if (tabPosition == kPositionBottom) ts.offset (offset, 0); else if (tabPosition == kPositionLeft) ts.offset (0, offset); else if (tabPosition == kPositionRight) ts.offset (0, offset); CTabChildView* v = firstChild; while (v) { v->button->setViewSize (ts); v->button->setMouseableArea (ts); if (tabPosition == kPositionTop || tabPosition == kPositionBottom) ts.offset (tabSize.getWidth (), 0); else ts.offset (0, tabSize.getHeight () / 2); v = v->next; } setDirty (true); invalid (); }
//---------------------------------------------------------------------------------------------------- void UIColorSlider::setViewSize (const CRect& rect, bool invalid) { bool different = rect != getViewSize (); CSlider::setViewSize (rect, invalid); if (different) { setHandle (0); setBackground (0); } }
/** * repositions the frame * @param x x coordinate * @param y y coordinate * @return true on success */ bool CFrame::setPosition (CCoord x, CCoord y) { if (platformFrame) { CRect rect (getViewSize ()); size.offset (x - size.left, y - size.top); return platformFrame->setSize (rect); } return false; }
//------------------------------------------------------------------------ void CSlider::setViewSize (const CRect& rect, bool invalid) { CControl::setViewSize (rect, invalid); if (style & kHorizontal) { minPos = rect.left - getViewSize ().left; rangeHandle = rect.getWidth () - (widthOfSlider + offsetHandle.x * 2); } else { minPos = rect.top - getViewSize ().top; rangeHandle = rect.getHeight () - (heightOfSlider + offsetHandle.y * 2); } widthControl = rect.getWidth (); heightControl = rect.getHeight (); setOffsetHandle (offsetHandle); }
//----------------------------------------------------------------------------- bool CSegmentButton::getFocusPath (CGraphicsPath& outPath) { CRect r (getViewSize ()); r.inset (getFrameWidth () / 2., getFrameWidth () / 2.); outPath.addRoundRect (r, getRoundRadius ()); CCoord focusWidth = getFrame ()->getFocusWidth (); r.extend (focusWidth, focusWidth); outPath.addRoundRect (r, getRoundRadius ()); return true; }
//------------------------------------------------------------------------ CRect UISearchTextField::platformGetSize () const { CRect rect = getViewSize (); CRect cmr = getClearMarkRect (); rect.right = cmr.left; CPoint p (0, 0); localToFrame (p); rect.offset (p.x, p.y); return rect; }
//----------------------------------------------------------------------------- void CShadowViewContainer::setViewSize (const CRect& rect, bool invalid) { if (getViewSize () != rect) { bool diffSize = (getWidth () != rect.getWidth () || getHeight () != rect.getHeight ()); CViewContainer::setViewSize (rect, invalid); if (diffSize) invalidateShadow (); } }