ImageRef Scene::parallelRaytrace(CameraRef camera, RenderOption option) { Rect leftRect(0.0f, 0.0f, camera->width(), floor(camera->height() / 2.0f)); Rect rightRect(0.0f, leftRect.maxY(), camera->width(), camera->height() - leftRect.size.height); p1.scene = this; p1.camera = camera; p1.rect = leftRect; p1.option = option; p1.image = new Image(leftRect.size.width, leftRect.size.height); p2.scene = this; p2.camera = camera; p2.rect = rightRect; p2.option = option; p2.image = new Image(rightRect.size.width, rightRect.size.height); pthread_t thread1, thread2; int iret1, iret2; std::cout << this; iret1 = pthread_create(&thread1, NULL, raytraceThread, &p1); iret2 = pthread_create(&thread2, NULL, raytraceThread, &p2); pthread_join(thread1, NULL); pthread_join(thread2, NULL); ImageRef image = new Image(camera->width(), camera->height()); image->drawImageAtPoint(p1.image, p1.rect.origin); image->drawImageAtPoint(p2.image, p2.rect.origin); delete p1.image; delete p2.image; return image; }
// Diagonally displays new screen starting from center - works on _picRect area // only. Assumes that height of rect is larger than width. void GfxTransitions::diagonalRollFromCenter(bool blackoutFlag) { int16 halfHeight = _picRect.height() / 2; Common::Rect upperRect(_picRect.left + halfHeight - 2, _picRect.top + halfHeight, _picRect.right - halfHeight + 1, _picRect.top + halfHeight + 1); Common::Rect lowerRect(upperRect.left, upperRect.top, upperRect.right, upperRect.bottom); Common::Rect leftRect(upperRect.left, upperRect.top, upperRect.left + 1, lowerRect.bottom); Common::Rect rightRect(upperRect.right, upperRect.top, upperRect.right + 1, lowerRect.bottom); uint32 msecCount = 0; while ((upperRect.top >= _picRect.top) || (lowerRect.bottom <= _picRect.bottom)) { if (upperRect.top < _picRect.top) { upperRect.translate(0, 1); leftRect.top++; rightRect.top++; } if (lowerRect.bottom > _picRect.bottom) { lowerRect.translate(0, -1); leftRect.bottom--; rightRect.bottom--; } if (leftRect.left < _picRect.left) { leftRect.translate(1, 0); upperRect.left++; lowerRect.left++; } if (rightRect.right > _picRect.right) { rightRect.translate(-1, 0); upperRect.right--; lowerRect.right--; } copyRectToScreen(upperRect, blackoutFlag); upperRect.translate(0, -1); upperRect.left--; upperRect.right++; copyRectToScreen(lowerRect, blackoutFlag); lowerRect.translate(0, 1); lowerRect.left--; lowerRect.right++; copyRectToScreen(leftRect, blackoutFlag); leftRect.translate(-1, 0); leftRect.top--; leftRect.bottom++; copyRectToScreen(rightRect, blackoutFlag); rightRect.translate(1, 0); rightRect.top--; rightRect.bottom++; msecCount += 4; if (doCreateFrame(msecCount)) { updateScreenAndWait(msecCount); } } }
void KDoor::drawPreImageEffect(QPainter &painter,const QImage &preImage, const float& frame) { float switchAreaWidth = preImage.width(); float switchAreaHeight = preImage.height(); float halfRectWidth = switchAreaWidth / 2; float halfRectHeight = switchAreaHeight / 2; float m_fIncreasedAngle = 10 * frame / m_fImageMeetScale; float m_fAlpha = (-frame / m_fImageMeetScale) + 1; float m_fPreImageScaleWidth = halfRectWidth * frame / m_fImageMeetScale; float m_fPreImageScaleHeight = halfRectHeight * frame / m_fImageMeetScale; painter.save(); painter.setOpacity(m_fAlpha); //左边的门 QImage leftImage = preImage.copy(0, 0, halfRectWidth, switchAreaHeight); QTransform leftTransform; leftTransform.rotate(-m_fIncreasedAngle, Qt::YAxis); leftImage = leftImage.transformed(leftTransform); QRect leftRect(m_fPreImageScaleWidth, leftImage.rect().y() + m_fPreImageScaleHeight / 2, halfRectWidth - m_fPreImageScaleWidth, leftImage.rect().height() - m_fPreImageScaleHeight); QRect tLeftRect = QRect(preImage.rect().x(), preImage.rect().y(), halfRectWidth - m_fPreImageScaleWidth, preImage.height()); painter.drawImage(tLeftRect, leftImage, leftRect); //右边的门 QImage rightImage = preImage.copy(halfRectWidth, 0, halfRectWidth, switchAreaHeight); QTransform rightTransform; rightTransform.rotate(m_fIncreasedAngle, Qt::YAxis); rightImage = rightImage.transformed(rightTransform); QRect rightRect(0, m_fPreImageScaleHeight / 2, halfRectWidth - m_fPreImageScaleWidth, rightImage.height() - m_fPreImageScaleHeight); QRect tRightRect = QRect(preImage.rect().x() + halfRectWidth + m_fPreImageScaleWidth, preImage.rect().y(), halfRectWidth - m_fPreImageScaleWidth, preImage.rect().height()); painter.drawImage(tRightRect,rightImage,rightRect); painter.restore(); }
// Diagonally displays new screen starting from edges - works on _picRect area // only. Assumes that height of rect is larger than width. void GfxTransitions::diagonalRollToCenter(bool blackoutFlag) { Common::Rect upperRect(_picRect.left, _picRect.top, _picRect.right, _picRect.top + 1); Common::Rect lowerRect(_picRect.left, _picRect.bottom - 1, _picRect.right, _picRect.bottom); Common::Rect leftRect(_picRect.left, _picRect.top, _picRect.left + 1, _picRect.bottom); Common::Rect rightRect(_picRect.right - 1, _picRect.top, _picRect.right, _picRect.bottom); uint32 msecCount = 0; while (upperRect.top < lowerRect.bottom) { copyRectToScreen(upperRect, blackoutFlag); upperRect.translate(0, 1); upperRect.left++; upperRect.right--; copyRectToScreen(lowerRect, blackoutFlag); lowerRect.translate(0, -1); lowerRect.left++; lowerRect.right--; copyRectToScreen(leftRect, blackoutFlag); leftRect.translate(1, 0); copyRectToScreen(rightRect, blackoutFlag); rightRect.translate(-1, 0); msecCount += 4; updateScreenAndWait(msecCount); } }
void CGUIListGroup::UpdateInfo(const CGUIListItem *item) { for (iControls it = m_children.begin(); it != m_children.end(); it++) (*it)->UpdateInfo(item); // now we have to check our overlapping label pairs for (unsigned int i = 0; i < m_children.size(); i++) { if (m_children[i]->GetControlType() == CGUIControl::GUICONTROL_LISTLABEL && m_children[i]->IsVisible()) { CGUIListLabel &label1 = *(CGUIListLabel *)m_children[i]; CRect rect1(label1.GetRenderRect()); for (unsigned int j = i + 1; j < m_children.size(); j++) { if (m_children[j]->GetControlType() == CGUIControl::GUICONTROL_LISTLABEL && m_children[j]->IsVisible()) { // ok, now check if they overlap CGUIListLabel &label2 = *(CGUIListLabel *)m_children[j]; if (!rect1.Intersect(label2.GetRenderRect()).IsEmpty()) { // overlap vertically and horizontally - check alignment CGUIListLabel &left = label1.GetRenderRect().x1 < label2.GetRenderRect().x1 ? label1 : label2; CGUIListLabel &right = label1.GetRenderRect().x1 < label2.GetRenderRect().x1 ? label2 : label1; if ((left.GetLabelInfo().align & 3) == 0 && right.GetLabelInfo().align & XBFONT_RIGHT) { float chopPoint = (left.GetXPosition() + left.GetWidth() + right.GetXPosition() - right.GetWidth()) * 0.5f; // [1 [2...[2 1].|..........1] 2] // [1 [2.....[2 | 1]..1] 2] // [1 [2..........|.[2 1]..1] 2] CRect leftRect(left.GetRenderRect()); CRect rightRect(right.GetRenderRect()); if (rightRect.x1 > chopPoint) chopPoint = rightRect.x1 - 5; else if (leftRect.x2 < chopPoint) chopPoint = leftRect.x2 + 5; leftRect.x2 = chopPoint - 5; rightRect.x1 = chopPoint + 5; left.SetRenderRect(leftRect); right.SetRenderRect(rightRect); } } } } } } }
void MScene::drawForeground(QPainter *painter, const QRectF &rect) { Q_D(MScene); /* Overlay information on the widgets in development mode */ if (MApplication::showBoundingRect() || MApplication::showSize() || MApplication::showPosition() || MApplication::showMargins() || MApplication::showObjectNames() || MApplication::showStyleNames()) { QList<QGraphicsItem *> itemList = items(rect); QList<QGraphicsItem *>::iterator item; painter->setFont(TextFont); int fontHeight = d->metrics.height(); QTransform rotationMatrix; painter->setTransform(rotationMatrix); QList<QGraphicsItem *>::iterator end = itemList.end(); for (item = itemList.begin(); item != end; ++item) { QRectF br = (*item)->boundingRect(); QPolygonF bp = (*item)->mapToScene(br); if (MApplication::showBoundingRect()) { if (!dynamic_cast<MApplicationPage *>(*item)) { // filter out page for clarity painter->setOpacity(BoundingRectOpacity); painter->setPen(d->boundingRectLinePen); painter->setBrush(d->boundingRectFillBrush); painter->drawPolygon(bp); } } if (MApplication::showMargins()) { // Draw content margins QGraphicsLayoutItem *layoutItem = dynamic_cast<QGraphicsLayoutItem *>(*item); if (layoutItem) { qreal left, top, right, bottom; layoutItem->getContentsMargins(&left, &top, &right, &bottom); QRectF outerRect = (*item)->mapRectToScene(br); QRectF innerRect = (*item)->mapRectToScene(br.adjusted(left, top, -right, -bottom)); QRectF leftRect(outerRect.x(), outerRect.y(), innerRect.x() - outerRect.x(), outerRect.height()); QRectF topRect(innerRect.x(), outerRect.y(), innerRect.width(), innerRect.y() - outerRect.y()); QRectF rightRect(innerRect.bottomRight().x(), outerRect.y(), outerRect.bottomRight().x() - innerRect.bottomRight().x(), outerRect.height()); QRectF bottomRect(innerRect.x(), innerRect.bottomRight().y(), innerRect.width(), outerRect.bottomRight().y() - innerRect.bottomRight().y()); painter->setOpacity(0.5); d->fillMarginRectWithPattern(painter, leftRect, leftRect.width()); d->fillMarginRectWithPattern(painter, topRect, topRect.height()); d->fillMarginRectWithPattern(painter, rightRect, rightRect.width()); d->fillMarginRectWithPattern(painter, bottomRect, bottomRect.height()); } painter->setOpacity(1.0); } if (MApplication::showPosition()) { QPointF topLeft = ((*item)->mapToScene(br.topLeft())); QString posStr = QString("(%1, %2)").arg(topLeft.x()).arg(topLeft.y()); painter->setPen(Qt::black); painter->drawText(topLeft += QPointF(5, fontHeight), posStr); painter->setPen(Qt::white); painter->drawText(topLeft -= QPointF(1, 1), posStr); } if (MApplication::showSize()) { QPointF bottomRight = ((*item)->mapToScene(br.bottomRight())); QPointF pos = (*item)->mapToScene(br.topLeft()); QString sizeStr = QString("%1x%2 (%3,%4)").arg(br.width()).arg(br.height()).arg(pos.x()).arg(pos.y()); painter->setPen(Qt::black); painter->drawText(bottomRight -= QPointF(d->metrics.width(sizeStr), 2), sizeStr); painter->setPen(Qt::white); painter->drawText(bottomRight -= QPointF(1, 1), sizeStr); } if (MApplication::showObjectNames()) { d->drawObjectNames(painter, item); } if (MApplication::showStyleNames()) { d->drawStyleNames(painter, item); } } } bool countingFps = MApplication::logFps() || MApplication::showFps(); if (countingFps) { if (d->fps.frameCount < 0) { d->fps.time.restart(); d->fps.frameCount = 0; } ++d->fps.frameCount; int ms = d->fps.time.elapsed(); if (ms > FpsRefreshInterval) { float fps = d->fps.frameCount * 1000.0f / ms; d->fps.time.restart(); d->fps.frameCount = 0; if (MApplication::logFps()) { QTime time = d->fps.time.currentTime(); d->logFpsCounter(&time, fps); } d->fps.fps = fps; } if (MApplication::showFps()) { d->showFpsCounter(painter, d->fps.fps); } // this update call makes repainting work as fast // as possible, and by that prints useful fps numbers QTimer::singleShot(0, this, SLOT(update())); } else { d->fps.frameCount = -1; } if (MApplication::emulateTwoFingerGestures() && d->pinchEmulationEnabled) { static const QPixmap *tapPixmap = MTheme::pixmap("meegotouch-tap"); QPointF pixmapCenterDelta(tapPixmap->width() / 2, tapPixmap->height() / 2); painter->drawPixmap(d->emuPoint1.scenePos() - pixmapCenterDelta, *tapPixmap); painter->drawPixmap(d->emuPoint2.scenePos() - pixmapCenterDelta, *tapPixmap); } }