double QwtPlotRescaler::pixelDist( int axis, const QSize &size ) const
{
    const QwtInterval intv = intervalHint( axis );

    double dist = 0.0;
    if ( !intv.isNull() )
    {
        if ( axis == referenceAxis() )
            dist = intv.width();
        else
        {
            const double r = aspectRatio( axis );
            if ( r > 0.0 )
                dist = intv.width() * r;
        }
    }

    if ( dist > 0.0 )
    {
        if ( orientation( axis ) == Qt::Horizontal )
            dist /= size.width();
        else
            dist /= size.height();
    }

    return dist;
}
/*!
  Synchronize an axis scale according to the scale of the reference axis

  \param axis Axis index ( see QwtPlot::AxisId )
  \param reference Interval of the reference axis
  \param size Size of the canvas

  \return New interval for axis
*/
QwtInterval QwtPlotRescaler::syncScale( int axis,
    const QwtInterval& reference, const QSize &size ) const
{
    double dist;
    if ( orientation( referenceAxis() ) == Qt::Horizontal )
        dist = reference.width() / size.width();
    else
        dist = reference.width() / size.height();

    if ( orientation( axis ) == Qt::Horizontal )
        dist *= size.width();
    else
        dist *= size.height();

    dist /= aspectRatio( axis );

    QwtInterval intv;
    if ( rescalePolicy() == Fitting )
        intv = intervalHint( axis );
    else
        intv = interval( axis );

    intv = expandInterval( intv, dist, expandingDirection( axis ) );

    return intv;
}
Example #3
0
void RCViewableTransform::moveToFit(const Eks::BoundingBox &bnds)
  {
  Eks::Vector3D pos = bnds.centre();

  Eks::AxisAlignedBoundingBox bbox(Eks::Frame::XYZ(), bnds);

  Eks::Vector3D across = acrossDirection().normalized();
  Eks::Vector3D up = upDirection().normalized();
  Eks::Vector3D look = lookDirection().normalized();

  float minX, maxX;
  bbox.maximumExtents(across, minX, maxX);

  float minY, maxY;
  bbox.maximumExtents(up, minY, maxY);

  float minZ, maxZ;
  bbox.maximumExtents(look, minZ, maxZ);

  float centreX = pos.dot(across);
  float centreY = pos.dot(up);
  float centreZ = pos.dot(look);

  float axisX = std::max(centreX - minX, maxX - centreX) / aspectRatio();
  float axisY = std::max(centreY - minY, maxY - centreY);
  float minDist = centreZ - minZ;

  moveToFit(pos, lookDirection(), std::max(axisX, axisY), minDist);
  }
Example #4
0
void
WorkflowRenderer::startPreview()
{
    if ( m_mainWorkflow->getLengthFrame() <= 0 )
        return ;
    if ( paramsHasChanged( m_width, m_height, m_outputFps, m_aspectRatio ) == true )
    {
        m_width = width();
        m_height = height();
        m_outputFps = outputFps();
        m_aspectRatio = aspectRatio();
    }
    initFilters();

    setupRenderer( m_width, m_height, m_outputFps );

    m_mainWorkflow->setFullSpeedRender( false );
    m_mainWorkflow->startRender( m_width, m_height, m_outputFps );
    m_isRendering = true;
    m_paused = false;
    m_stopping = false;
    m_pts = 0;
    m_audioPts = 0;
    m_sourceRenderer->start();
}
Example #5
0
bool VideoPreview::showConfigDialog(QWidget *parent)
{
    VideoPreviewConfigDialog d(parent);

    d.setVideoFile(videoFile());
    d.setDVDDevice(DVDDevice());
    d.setCols(cols());
    d.setRows(rows());
    d.setInitialStep(initialStep());
    d.setMaxWidth(maxWidth());
    d.setDisplayOSD(displayOSD());
    d.setAspectRatio(aspectRatio());
    d.setFormat(extractFormat());
    d.setSaveLastDirectory(save_last_directory);

    if (d.exec() == QDialog::Accepted) {
        setVideoFile(d.videoFile());
        setDVDDevice(d.DVDDevice());
        setCols(d.cols());
        setRows(d.rows());
        setInitialStep(d.initialStep());
        setMaxWidth(d.maxWidth());
        setDisplayOSD(d.displayOSD());
        setAspectRatio(d.aspectRatio());
        setExtractFormat(d.format());
        save_last_directory = d.saveLastDirectory();

        return true;
    }

    return false;
}
Example #6
0
/// in viewport
void ViewCull::ndc(const Vector3F & cameraP, float & coordx, float & coordy) const
{
	float d = -cameraP.z;
	if(d<1.f) d= 1.f; 
	float h_max = d * hfov();
	float h_min = -h_max;
	float v_max = h_max * aspectRatio();
	float v_min = -v_max;
	coordx = (cameraP.x/m_overscan - h_min) / (h_max - h_min);
	coordy = (cameraP.y/m_overscan/(m_portAspectRatio / aspectRatio() ) - v_min) / (v_max - v_min);
	
	if(coordx < 0.f) coordx = 0.f;
	if(coordx > .999f) coordx = .999f;
	if(coordy < 0.f) coordy = 0.f;
	if(coordy > .999f) coordy = .999f;
}
void OpenCLWaveSimulation::initScene()
{
    if(!m_glslProgram->compileShaderFromFile("render_waves.vert", GLSLShader::VERTEX))
    {
        std::cerr << "Vertex shader failed to compile\n";
        std::cerr << "Build Log: " << m_glslProgram->log() << std::endl;
        exit(1);
    }

    if(!m_glslProgram->compileShaderFromFile("render_waves.frag", GLSLShader::FRAGMENT))
    {
        std::cerr << "Fragment shader failed to compile\n";
        std::cerr << "Build Log: " << m_glslProgram->log() << std::endl;
        exit(1);
    }

    // bindAttribLocation or bindFragDataLocation here
    m_glslProgram->bindAttribLocation(0, "vPos");
    m_glslProgram->bindAttribLocation(1, "vNormal");
    m_glslProgram->bindAttribLocation(2, "vTangent");
    m_glslProgram->bindFragDataLocation(0, "FragColor");

    if(!m_glslProgram->link())
    {
        std::cerr << "Shader program failed to link\n";
        std::cerr << "Link Log: " << m_glslProgram->log() << std::endl;
    }

    m_glslProgram->use();
    m_glslProgram->printActiveAttribs();
    m_glslProgram->printActiveUniforms();
    std::cout << std::endl;

    // init uniforms
    m_modelM = glm::mat4(1.0f);
    m_viewM = glm::lookAt(glm::vec3(0.0f, 0.0f, 5.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f));
    m_projM = glm::perspective(glm::degrees(0.25f * MathUtils::Pi), aspectRatio(), 1.0f, 2048.0f);
    m_worldInvTransposeM = glm::transpose(glm::inverse(glm::mat3(m_modelM)));

    // light, material and camera
    m_materialAmbient  = glm::vec4(0.137f, 0.42f, 0.556f, 1.0f);
    m_materialDiffuse  = glm::vec4(0.137f, 0.42f, 0.556f, 1.0f);
    m_materialSpecular = glm::vec4(0.8f, 0.8f, 0.8f, 96.0f);

    m_lightDir      = glm::vec3(0.0f, -1.0f, 0.1f);
    m_lightAmbient  = glm::vec4(0.2f, 0.2f, 0.2f, 1.0f);
    m_lightDiffuse  = glm::vec4(0.5f, 0.5f, 0.5f, 1.0f);
    m_lightSpecular = glm::vec4(0.5f, 0.5f, 0.5f, 1.0f);

    m_glslProgram->setUniform("materialAmbient", m_materialAmbient);
    m_glslProgram->setUniform("materialDiffuse", m_materialDiffuse);
    m_glslProgram->setUniform("materialSpecular", m_materialSpecular);
    m_glslProgram->setUniform("lightDir", m_lightDir);
    m_glslProgram->setUniform("lightAmbient", m_lightAmbient);
    m_glslProgram->setUniform("lightDiffuse", m_lightDiffuse);
    m_glslProgram->setUniform("lightSpecular", m_lightSpecular);

    buildWaveGrid();
}
/*!
   Update the axes scales

   \param intervals Scale intervals
*/
void QwtPlotRescaler::updateScales(
    QwtInterval intervals[QwtPlot::axisCnt] ) const
{
    if ( d_data->inReplot >= 5 )
    {
        return;
    }

    QwtPlot *plt = const_cast<QwtPlot *>( plot() );

    const bool doReplot = plt->autoReplot();
    plt->setAutoReplot( false );

    for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
    {
        if ( axis == referenceAxis() || aspectRatio( axis ) > 0.0 )
        {
            double v1 = intervals[axis].minValue();
            double v2 = intervals[axis].maxValue();

            if ( plt->axisScaleDiv( axis )->lowerBound() >
                plt->axisScaleDiv( axis )->upperBound() )
            {
                qSwap( v1, v2 );
            }

            if ( d_data->inReplot >= 1 )
            {
                d_data->axisData[axis].scaleDiv = *plt->axisScaleDiv( axis );
            }

            if ( d_data->inReplot >= 2 )
            {
                QList<double> ticks[QwtScaleDiv::NTickTypes];
                for ( int i = 0; i < QwtScaleDiv::NTickTypes; i++ )
                    ticks[i] = d_data->axisData[axis].scaleDiv.ticks( i );

                plt->setAxisScaleDiv( axis, QwtScaleDiv( v1, v2, ticks ) );
            }
            else
            {
                plt->setAxisScale( axis, v1, v2 );
            }
        }
    }

    const bool immediatePaint = 
        plt->canvas()->testPaintAttribute( QwtPlotCanvas::ImmediatePaint );
    plt->canvas()->setPaintAttribute( QwtPlotCanvas::ImmediatePaint, false );

    plt->setAutoReplot( doReplot );

    d_data->inReplot++;
    plt->replot();
    d_data->inReplot--;

    plt->canvas()->setPaintAttribute( 
        QwtPlotCanvas::ImmediatePaint, immediatePaint );
}
osg::Matrix OculusDevice::projectionCenterMatrix() const
{
	osg::Matrix projectionMatrix;
	float halfScreenDistance = vScreenSize() * 0.5f * distortionScale();
	float yFov = (180.0f/3.14159f) * 2.0f * atan(halfScreenDistance / eyeToScreenDistance());
	projectionMatrix.makePerspective(yFov, aspectRatio(), m_nearClip, m_farClip);
	return projectionMatrix;
}
void OpenCLWaveSimulation::onResize(int w, int h)
{
    m_width = w;
    m_height = h;
    glViewport(0, 0, m_width, m_height);
    m_projM = glm::perspective(glm::degrees(0.25f * MathUtils::Pi), aspectRatio(), 1.0f, 2048.0f);

    glutPostRedisplay();
}
Example #11
0
bool
WorkflowRenderer::paramsHasChanged( quint32 width, quint32 height, double fps, QString aspect )
{
    quint32             newWidth = this->width();
    quint32             newHeight = this->height();
    float               newOutputFps = outputFps();
    const QString       newAspectRatio = aspectRatio();

    return ( newWidth != width || newHeight != height ||
         newOutputFps != fps || newAspectRatio != aspect );
}
/*!
   Update the axes scales 

   \param intervals Scale intervals
*/
void QwtPlotRescaler::updateScales(
    QwtDoubleInterval intervals[QwtPlot::axisCnt]) const
{
    if ( d_data->inReplot >= 5 )
    {
        return;
    }

    QwtPlot *plt = (QwtPlot *)plot();

    const bool doReplot = plt->autoReplot();
    plt->setAutoReplot(false);

    for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
    {
        if ( axis == referenceAxis() || aspectRatio(axis) > 0.0 )
        {
            double v1 = intervals[axis].minValue();
            double v2 = intervals[axis].maxValue();

            if ( plt->axisScaleDiv(axis)->lowerBound() >
                plt->axisScaleDiv(axis)->upperBound() )
            {
                qSwap(v1, v2);
            }

            if ( d_data->inReplot >= 1 )
            {
                d_data->axisData[axis].scaleDiv = *plt->axisScaleDiv(axis);
            }

            if ( d_data->inReplot >= 2 )
            {
                QwtValueList ticks[QwtScaleDiv::NTickTypes];
                for ( int i = 0; i < QwtScaleDiv::NTickTypes; i++ )
                    ticks[i] = d_data->axisData[axis].scaleDiv.ticks(i);

                plt->setAxisScaleDiv(axis, QwtScaleDiv(v1, v2, ticks));
            }
            else
            {
                plt->setAxisScale(axis, v1, v2);
            }
        }
    }

    plt->setAutoReplot(doReplot);

    d_data->inReplot++;
    plt->replot();
    d_data->inReplot--;
}
Example #13
0
void Gradient::paint(CGContextRef context)
{
    CGGradientDrawingOptions extendOptions = kCGGradientDrawsBeforeStartLocation | kCGGradientDrawsAfterEndLocation;
    if (!m_radial) {
        CGContextDrawLinearGradient(context, platformGradient(), m_p0, m_p1, extendOptions);
        return;
    }

    bool needScaling = aspectRatio() != 1;
    if (needScaling) {
        CGContextSaveGState(context);
        // Scale from the center of the gradient. We only ever scale non-deprecated gradients,
        // for which m_p0 == m_p1.
        ASSERT(m_p0 == m_p1);
        CGContextTranslateCTM(context, m_p0.x(), m_p0.y());
        CGContextScaleCTM(context, 1, 1 / aspectRatio());
        CGContextTranslateCTM(context, -m_p0.x(), -m_p0.y());
    }

    CGContextDrawRadialGradient(context, platformGradient(), m_p0, m_r0, m_p1, m_r1, extendOptions);

    if (needScaling)
        CGContextRestoreGState(context);
}
Example #14
0
void DkCropToolBar::on_horValBox_valueChanged(double) {

    DkVector diag = DkVector((float)horValBox->value(), (float)verValBox->value());
    emit aspectRatio(diag);

    QString rs = QString::number(horValBox->value()) + ":" + QString::number(verValBox->value());

    int idx = ratioBox->findText(rs);

    if (idx != -1)
        ratioBox->setCurrentIndex(idx);
    else if (horValBox->value() == 0 && verValBox->value() == 0)
        ratioBox->setCurrentIndex(0);
    else
        ratioBox->setCurrentIndex(1);

}
Example #15
0
void
WorkflowRenderer::setupRenderer( quint32 width, quint32 height, double fps )
{
    m_source->setWidth( width );
    m_source->setHeight( height );
    m_source->setFps( fps );
    m_source->setAspectRatio( qPrintable( aspectRatio() ) );
    m_source->setNumberChannels( m_nbChannels );
    m_source->setSampleRate( m_rate );
    m_esHandler->fps = fps;


    delete m_sourceRenderer;
    m_sourceRenderer = m_source->createRenderer( m_eventWatcher );
    m_sourceRenderer->setName( "WorkflowRenderer" );
    m_sourceRenderer->enableMemoryInput( m_esHandler, getLockCallback(), getUnlockCallback() );
    m_sourceRenderer->setOutputWidget( (void *) static_cast< RenderWidget* >( m_renderWidget )->id() );
}
Example #16
0
	void Camera::setup()
	{
			const  Point3d cameraVector = lookAt() - position();

			// Calculate length of vector perpendicular to camera vector.
			const Float d = cameraVector.length();
			const Float f = fov()*.5;
			const Float lenHorizontal = std::sin(f)*(d / std::cos(f)); 
			const Float lenVertical = lenHorizontal / aspectRatio();

			const Point3d tmpDown(math3d::make_vec(0, -1, 0));
			const Point3d perpendicularLeft = norm(cross(cameraVector, tmpDown)) * (lenHorizontal * 0.5);
			const Point3d perpendicularDown = norm(cross(perpendicularLeft, cameraVector))*(lenVertical*0.5);

			topLeft_ = lookAt() + perpendicularLeft - perpendicularDown - position();
			topRight_ = lookAt() - perpendicularLeft - perpendicularDown - position();
			bottomLeft_ = lookAt() + perpendicularLeft + perpendicularDown - position();
			bottomRight_ = lookAt() - perpendicularLeft + perpendicularDown - position();
	}
/*!
   Adjust the plot axes scales

   \param oldSize Previous size of the canvas
   \param newSize New size of the canvas
*/
void QwtPlotRescaler::rescale(
    const QSize &oldSize, const QSize &newSize ) const
{
    if ( newSize.isEmpty() )
        return;

    QwtInterval intervals[QwtPlot::axisCnt];
    for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
        intervals[axis] = interval( axis );

    const int refAxis = referenceAxis();
    intervals[refAxis] = expandScale( refAxis, oldSize, newSize );

    for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
    {
        if ( aspectRatio( axis ) > 0.0 && axis != refAxis )
            intervals[axis] = syncScale( axis, intervals[refAxis], newSize );
    }

    updateScales( intervals );
}
int LimitSqueezeTaskbarLayout::optimumCapacity() const {
	const QRectF effectiveRect(effectiveGeometry());
	const QList<TaskbarItem*> & items = this->items();
	const int N                 = items.size();
	const bool isVertical       = orientation() == Qt::Vertical;
	const qreal availableHeight = isVertical ? effectiveRect.width()  : effectiveRect.height();
	const qreal availableWidth  = isVertical ? effectiveRect.height() : effectiveRect.width();
	const qreal spacing         = this->spacing();
	qreal thisRowWidth          = 0;
	int numberGrouped           = 0;
	
#define CELL_HEIGHT(ROWS) (((availableHeight + spacing) / ((qreal) (ROWS))) - spacing)

	int cellHeight = CELL_HEIGHT(m_rows);
	int cellWidth  = cellHeight * aspectRatio();
	
	for (int i =0; i < items.size(); i++) {
		thisRowWidth += this->spacing() + itemAt(i)->task()->taskCount() * (cellWidth +
			(itemAt(i)->isExpanded()) * expandedWidth());
		
		if (itemAt(i)->task()->type() == Task::GroupItem) {
			++ numberGrouped;
		}
	}

	qreal compression = (m_rows * availableWidth) / thisRowWidth;
	// group when there is not enough place
	if ((compression < (m_squeezeRatio + (m_preferGrouping ? 0.1 : 0.0)) && (m_rows == maximumRows() || m_preferGrouping))
		// stay grouped when number of rows grows
		|| ( m_rows > minimumRows() && m_preferGrouping )
		// should prevent ungrouping when nubmer of rows is changed (not perfeect)
		|| (m_rows == maximumRows() - 1 && numberGrouped > 0 && m_preferGrouping == 0 && compression < m_squeezeRatio)
		) {
		return N - 1; //now it is the right size
	}
	else {
		return N + 10;
	}
}
Example #19
0
void AtkinsPageLayout::addLayoutItem(int key, const QSizeF& size)
{
    double relativeArea = absoluteArea(size) / absoluteArea(d->pageRect.size());
    addLayoutItem(key, aspectRatio(size), relativeArea);
}
void LimitSqueezeTaskbarLayout::doLayout() {
	// I think this way the loops can be optimized by the compiler.
	// (lifting out the comparison and making two loops; TODO: find out whether this is true):
	const bool isVertical = orientation() == Qt::Vertical;

	const QList<TaskbarItem*>& items = this->items();
	const int N = items.size();

	// if there is nothing to layout fill in some dummy data and leave
	if (N == 0) {
		stopAnimation();

		QRectF rect(geometry());
		m_rows = 1;

		if (isVertical) {
			m_cellHeight = rect.width();
		}
		else {
			m_cellHeight = rect.height();
		}

		QSizeF newPreferredSize(qMin(10.0, rect.width()), qMin(10.0, rect.height()));

		if (newPreferredSize != m_preferredSize) {
			m_preferredSize = newPreferredSize;
			emit sizeHintChanged(Qt::PreferredSize);
		}

		return;
	}

	const QRectF effectiveRect(effectiveGeometry());
	const qreal availableWidth  = isVertical ? effectiveRect.height() : effectiveRect.width();
	const qreal availableHeight = isVertical ? effectiveRect.width()  : effectiveRect.height();
	const qreal spacing         = this->spacing();

	int rows = minimumRows() - 1;

	qreal cellHeight = 0.0;
	qreal cellWidth  = 0.0;

	QList<RowInfo> rowInfos;
	
	qreal maxPreferredRowWidth   = 0.0;
	qreal compression            = 1.0;
	qreal thisRowWidth           = 0.0;
	int   expandedHoverItemCount = 0;   // if there is some icon expanded by mouse
	int   expandedItemCount      = 0;
	
	for (int index = 0; index < N; ++ index) {
		// icon is hovered by mouse
		if (itemAt(index)->isExpandedByHover()) {
			++ expandedHoverItemCount;
		}

		if (itemAt(index)->isExpanded()) {
			++ expandedItemCount;
		}
	}

	// determine the number of rows
	while (rows < maximumRows()) {
		++ rows;
		cellHeight = CELL_HEIGHT(rows);
		cellWidth  = cellHeight * aspectRatio();
		thisRowWidth = N * (cellWidth + spacing) +
			(expandedItemCount - expandedHoverItemCount) * expandedWidth(); // suppress the expansion by hover
		compression = qMin((rows * availableWidth) / thisRowWidth, 1.0);
		
		if (rows * availableWidth > (thisRowWidth - N * cellWidth) * m_squeezeRatio + N * cellWidth / (rows + 1)) {
			break;
		}
	}

	// distribution of items, determine:
	//  * the preferred size each single row
	//  * spacings of each row (can be derived of number of elements in row)
	//  * the start and end index of each row
	//  * the maximal preferred row width (as the preferred width for sizeHint)

	int startIndex = 0;
	int endIndex   = 0;
	int index      = 0;
	for (int row = 0; row < rows && endIndex < N; ++ row) {
		startIndex = endIndex;
		
		expandedHoverItemCount = 0;
		expandedItemCount      = 0;
		// determine number of items in one row
		for (index = startIndex; index < N; ++ index) {
			if (itemAt(index)->isExpandedByHover()) {
				++ expandedHoverItemCount;
			}

			if (itemAt(index)->isExpanded()) {
				++ expandedItemCount;
			}

			thisRowWidth = (index - startIndex) * (cellWidth + spacing) +
				(expandedItemCount - expandedHoverItemCount) * expandedWidth();
			// the 0.9 is here to prefer higher rows
			if (availableWidth < compression * thisRowWidth * 0.9) {
				break;
			}
		}

		if (row + 1 == rows) {
			endIndex = N;
		}
		else {
			if (startIndex == index) { // prevents empty rows
				++ index;
			}
			
			endIndex = qMin(N, index);
		}
		
		qreal rowSpacing = spacing * (endIndex - startIndex);
		thisRowWidth = 0.0;
		qreal thisRowMinWidth = 0.0;
		
		for (int index = startIndex; index < endIndex; ++ index) {
			thisRowWidth    += cellWidth + items[index]->expansion;
			thisRowMinWidth += cellWidth;
		}

		if (thisRowWidth + rowSpacing > maxPreferredRowWidth) {
			maxPreferredRowWidth = thisRowWidth + rowSpacing;
		}

		if (startIndex != endIndex) {
			rowInfos.append(RowInfo(thisRowWidth, thisRowMinWidth, startIndex, endIndex));
		}
	}

	// if we assumed expanded there still might be empty row
	// therefore just scale up the layout (maybe do only this and not the other way of row removal)
	rows = qMax(minimumRows(), rowInfos.size());
	
	cellHeight = CELL_HEIGHT(rows);
	updateLayout(rows, cellWidth, cellHeight, availableWidth, maxPreferredRowWidth, rowInfos, effectiveRect);
	
	m_rows = rows;
	m_compresion = compression;
#undef CELL_HEIGHT
}
Example #21
0
SkShader* Gradient::shader()
{
    if (m_gradient)
        return m_gradient.get();

    sortStopsIfNecessary();
    ASSERT(m_stopsSorted);

    size_t countUsed = totalStopsNeeded(m_stops.data(), m_stops.size());
    ASSERT(countUsed >= 2);
    ASSERT(countUsed >= m_stops.size());

    // FIXME: Why is all this manual pointer math needed?!
    SkAutoMalloc storage(countUsed * (sizeof(SkColor) + sizeof(SkScalar)));
    SkColor* colors = (SkColor*)storage.get();
    SkScalar* pos = (SkScalar*)(colors + countUsed);

    fillStops(m_stops.data(), m_stops.size(), pos, colors);

    SkShader::TileMode tile = SkShader::kClamp_TileMode;
    switch (m_spreadMethod) {
    case SpreadMethodReflect:
        tile = SkShader::kMirror_TileMode;
        break;
    case SpreadMethodRepeat:
        tile = SkShader::kRepeat_TileMode;
        break;
    case SpreadMethodPad:
        tile = SkShader::kClamp_TileMode;
        break;
    }

    uint32_t shouldDrawInPMColorSpace = m_drawInPMColorSpace ? SkGradientShader::kInterpolateColorsInPremul_Flag : 0;
    if (m_radial) {
        // Since the two-point radial gradient is slower than the plain radial,
        // only use it if we have to.
        if (m_p0 == m_p1 && m_r0 <= 0.0f) {
            m_gradient = adoptRef(SkGradientShader::CreateRadial(m_p1, m_r1, colors, pos, static_cast<int>(countUsed), tile, 0, shouldDrawInPMColorSpace));
        } else {
            // The radii we give to Skia must be positive. If we're given a
            // negative radius, ask for zero instead.
            SkScalar radius0 = m_r0 >= 0.0f ? WebCoreFloatToSkScalar(m_r0) : 0;
            SkScalar radius1 = m_r1 >= 0.0f ? WebCoreFloatToSkScalar(m_r1) : 0;
            m_gradient = adoptRef(SkGradientShader::CreateTwoPointConical(m_p0, radius0, m_p1, radius1, colors, pos, static_cast<int>(countUsed), tile, 0, shouldDrawInPMColorSpace));
        }

        if (aspectRatio() != 1) {
            // CSS3 elliptical gradients: apply the elliptical scaling at the
            // gradient center point.
            m_gradientSpaceTransformation.translate(m_p0.x(), m_p0.y());
            m_gradientSpaceTransformation.scale(1, 1 / aspectRatio());
            m_gradientSpaceTransformation.translate(-m_p0.x(), -m_p0.y());
            ASSERT(m_p0 == m_p1);
        }
    } else {
        SkPoint pts[2] = { m_p0, m_p1 };
        m_gradient = adoptRef(SkGradientShader::CreateLinear(pts, colors, pos, static_cast<int>(countUsed), tile, 0, shouldDrawInPMColorSpace));
    }

    if (!m_gradient) {
        // use last color, since our "geometry" was degenerate (e.g. radius==0)
        m_gradient = adoptRef(new SkColorShader(colors[countUsed - 1]));
    } else {
        m_gradient->setLocalMatrix(affineTransformToSkMatrix(m_gradientSpaceTransformation));
    }
    return m_gradient.get();
}
Example #22
0
AtkinsPageLayout::AtkinsPageLayout(const QRectF& pageRect)
                : d(new Private)
{
    d->pageRect = pageRect;
    d->tree     = new LayoutTree(aspectRatio(d->pageRect.size()), absoluteArea(d->pageRect.size()));
}
osg::Vec2f OculusDevice::scaleIn() const
{
	return osg::Vec2f(2.0f, 2.0f/aspectRatio());
}
osg::Vec2f OculusDevice::scale() const
{
	float scaleFactor = 1.0f/distortionScale();
	return osg::Vec2f(0.5*scaleFactor, 0.5f*scaleFactor*aspectRatio());
}
sk_sp<SkShader> Gradient::createShader()
{
    sortStopsIfNecessary();
    ASSERT(m_stopsSorted);

    size_t countUsed = totalStopsNeeded(m_stops.data(), m_stops.size());
    ASSERT(countUsed >= 2);
    ASSERT(countUsed >= m_stops.size());

    ColorStopOffsetVector pos(countUsed);
    ColorStopColorVector colors(countUsed);
    fillStops(m_stops.data(), m_stops.size(), pos, colors);

    SkShader::TileMode tile = SkShader::kClamp_TileMode;
    switch (m_spreadMethod) {
    case SpreadMethodReflect:
        tile = SkShader::kMirror_TileMode;
        break;
    case SpreadMethodRepeat:
        tile = SkShader::kRepeat_TileMode;
        break;
    case SpreadMethodPad:
        tile = SkShader::kClamp_TileMode;
        break;
    }

    sk_sp<SkShader> shader;
    uint32_t shouldDrawInPMColorSpace = m_drawInPMColorSpace ? SkGradientShader::kInterpolateColorsInPremul_Flag : 0;
    if (m_radial) {
        if (aspectRatio() != 1) {
            // CSS3 elliptical gradients: apply the elliptical scaling at the
            // gradient center point.
            m_gradientSpaceTransformation.translate(m_p0.x(), m_p0.y());
            m_gradientSpaceTransformation.scale(1, 1 / aspectRatio());
            m_gradientSpaceTransformation.translate(-m_p0.x(), -m_p0.y());
            ASSERT(m_p0 == m_p1);
        }
        SkMatrix localMatrix = affineTransformToSkMatrix(m_gradientSpaceTransformation);

        // Since the two-point radial gradient is slower than the plain radial,
        // only use it if we have to.
        if (m_p0 == m_p1 && m_r0 <= 0.0f) {
            shader = SkGradientShader::MakeRadial(m_p1.data(), m_r1, colors.data(), pos.data(), static_cast<int>(countUsed), tile, shouldDrawInPMColorSpace, &localMatrix);
        } else {
            // The radii we give to Skia must be positive. If we're given a
            // negative radius, ask for zero instead.
            SkScalar radius0 = m_r0 >= 0.0f ? WebCoreFloatToSkScalar(m_r0) : 0;
            SkScalar radius1 = m_r1 >= 0.0f ? WebCoreFloatToSkScalar(m_r1) : 0;
            shader = SkGradientShader::MakeTwoPointConical(m_p0.data(), radius0, m_p1.data(), radius1, colors.data(), pos.data(), static_cast<int>(countUsed), tile, shouldDrawInPMColorSpace, &localMatrix);
        }
    } else {
        SkPoint pts[2] = { m_p0.data(), m_p1.data() };
        SkMatrix localMatrix = affineTransformToSkMatrix(m_gradientSpaceTransformation);
        shader = SkGradientShader::MakeLinear(pts, colors.data(), pos.data(), static_cast<int>(countUsed), tile, shouldDrawInPMColorSpace, &localMatrix);
    }

    if (!shader) {
        // use last color, since our "geometry" was degenerate (e.g. radius==0)
        shader = SkShader::MakeColorShader(colors[countUsed - 1]);
    }

    return shader;
}
void ObjLoaderDemo::onResize()
{
    RenderCore::onResize();

    mCam.SetLens(0.25f*MathHelper::Pi, aspectRatio(), 1.f, 1000.f);
}
void LightingDemo2::onResize()
{
    RenderCore::onResize();

    mCam.SetLens(0.25f*MathHelper::Pi, aspectRatio(), 1.f, 1000.f);
}
Example #28
0
SkShader* Gradient::platformGradient()
{
    if (m_gradient)
        return m_gradient;

    sortStopsIfNecessary();
    ASSERT(m_stopsSorted);

    size_t countUsed = totalStopsNeeded(m_stops.data(), m_stops.size());
    ASSERT(countUsed >= 2);
    ASSERT(countUsed >= m_stops.size());

    // FIXME: Why is all this manual pointer math needed?!
    SkAutoMalloc storage(countUsed * (sizeof(SkColor) + sizeof(SkScalar)));
    SkColor* colors = (SkColor*)storage.get();
    SkScalar* pos = (SkScalar*)(colors + countUsed);

    fillStops(m_stops.data(), m_stops.size(), pos, colors);

    SkShader::TileMode tile = SkShader::kClamp_TileMode;
    switch (m_spreadMethod) {
    case SpreadMethodReflect:
        tile = SkShader::kMirror_TileMode;
        break;
    case SpreadMethodRepeat:
        tile = SkShader::kRepeat_TileMode;
        break;
    case SpreadMethodPad:
        tile = SkShader::kClamp_TileMode;
        break;
    }

    if (m_radial) {
        // Since the two-point radial gradient is slower than the plain radial,
        // only use it if we have to.
        if (m_p0 == m_p1 && m_r0 <= 0.0f) {
            // The radius we give to Skia must be positive (and non-zero).  If
            // we're given a zero radius, just ask for a very small radius so
            // Skia will still return an object.
            SkScalar radius = m_r1 > 0 ? WebCoreFloatToSkScalar(m_r1) : WebCoreFloatToSkScalar(FLT_EPSILON);
            m_gradient = SkGradientShader::CreateRadial(m_p1, radius, colors, pos, static_cast<int>(countUsed), tile);
        } else {
            // The radii we give to Skia must be positive.  If we're given a 
            // negative radius, ask for zero instead.
            SkScalar radius0 = m_r0 >= 0.0f ? WebCoreFloatToSkScalar(m_r0) : 0;
            SkScalar radius1 = m_r1 >= 0.0f ? WebCoreFloatToSkScalar(m_r1) : 0;
            m_gradient = SkGradientShader::CreateTwoPointRadial(m_p0, radius0, m_p1, radius1, colors, pos, static_cast<int>(countUsed), tile);
        }

        if (aspectRatio() != 1) {
            // CSS3 elliptical gradients: apply the elliptical scaling at the
            // gradient center point.
            m_gradientSpaceTransformation.translate(m_p0.x(), m_p0.y());
            m_gradientSpaceTransformation.scale(1, 1 / aspectRatio());
            m_gradientSpaceTransformation.translate(-m_p0.x(), -m_p0.y());
            ASSERT(m_p0 == m_p1);
        }
    } else {
        SkPoint pts[2] = { m_p0, m_p1 };
        m_gradient = SkGradientShader::CreateLinear(pts, colors, pos, static_cast<int>(countUsed), tile);
    }

    ASSERT(m_gradient);
    SkMatrix matrix = m_gradientSpaceTransformation;
    m_gradient->setLocalMatrix(matrix);
    return m_gradient;
}
Example #29
0
void Settings::writeSettings()
{
    setValue(KEY_LANGUAGE, language());

    setValue(KEY_SESSION_AUTOPLAY, sessionAutoplay());
    setValue(KEY_SESSION_CHANNEL, sessionChannel());
    setValue(KEY_SESSION_REMEMBER_VOLUME, sessionRememberVolume());
    setValue(KEY_SESSION_VOLUME, sessionVolume());

    if (globalConfig && globalConfig->disableSettings("channels")) {
        remove("channels");
    } else {
        setValue(KEY_PLAYLIST, playlist());
        setValue(KEY_PLAYLIST_UPDATE, playlistUpdate());
        setValue(KEY_PLAYLIST_UPDATE_URL, playlistUpdateUrl());
        setValue(KEY_RADIO_CATEGORY, radioCategory());
        setValue(KEY_HD_CATEGORY, hdCategory());
        setValue(KEY_UDPXY, udpxy());
        setValue(KEY_UDPXY_URL, udpxyUrl());
        setValue(KEY_UDPXY_PORT, udpxyPort());
    }

    if (globalConfig && globalConfig->disableSettings("gui")) {
        remove("gui");
    } else {
        setValue(KEY_WIDTH, width());
        setValue(KEY_HEIGHT, height());
        setValue(KEY_POS_X, posX());
        setValue(KEY_POS_Y, posY());

        setValue(KEY_OSD, osd());
        setValue(KEY_TRAY_ENABLED, trayEnabled());
        setValue(KEY_HIDE_TO_TRAY, hideToTray());
        setValue(KEY_MOUSE_WHEEL, mouseWheel());
        setValue(KEY_REMEMBER_GUI_SESSION, rememberGuiSession());
        setValue(KEY_ICONS, icons());
    }

    if (globalConfig && globalConfig->disableSettings("backend")) {
        remove("backend");
    } else {
        setValue(KEY_VOUT, vout());
        setValue(KEY_AOUT, aout());
        setValue(KEY_YUV_TO_RGB, yuvToRgb());
        setValue(KEY_SPDIF, spdif());

        setValue(KEY_REMEMBER_VIDEO_SETTINGS, rememberVideoSettings());
        setValue(KEY_REMEMBER_VIDEO_PER_CHANNEL, rememberVideoPerChannel());
        setValue(KEY_ASPECT_RATIO, aspectRatio());
        setValue(KEY_CROP_RATIO, cropRatio());
        setValue(KEY_DEINTERLACING, deinterlacing());
        setValue(KEY_AUDIO_LANGUAGE, audioLanguage());
        setValue(KEY_SUBTITLE_LANGUAGE, subtitleLanguage());

        setValue(KEY_MUTE_ON_MINIMIZE, muteOnMinimize());
        setValue(KEY_TELETEXT, teletext());
    }

    if (globalConfig && globalConfig->disableSettings("recorder")) {
        remove("recorder");
    } else {
        setValue(KEY_RECORDER_DIRECTORY, recorderDirectory());
        setValue(KEY_SNAPSHOTS_DIRECTORY, snapshotsDirectory());
    }

    if (globalConfig && globalConfig->disableSettings("xmltv")) {
        remove("xmltv");
    } else {
        setValue(KEY_XMLTV_UPDATE, xmltvUpdate());
        setValue(KEY_XMLTV_UPDATE_LOCATION, xmltvUpdateLocation());
        setValue(KEY_XMLTV_UPDATE_REMOTE, xmltvUpdateRemote());
    }

    sync();
}