void LogisticsDialog::render()
{
	float color = 0x7f000000;
	if (enterAnim.isAnimating() && !enterAnim.isDone())
	{
		float time	= enterAnim.getCurrentTime();
		float endTime = enterAnim.getMaxTime();
		if (endTime)
		{
			color = interpolateColor(0x00000000, 0x7f000000, time / endTime);
		}
	}
	else if (exitAnim.isAnimating() && !exitAnim.isDone())
	{
		float time	= exitAnim.getCurrentTime();
		float endTime = exitAnim.getMaxTime();
		if (endTime)
		{
			color = interpolateColor(0x7f000000, 0x00000000, time / endTime);
		}
	}
	RECT rect = {0, 0, Environment.screenWidth, Environment.screenHeight};
	drawRect(rect, color);
	float xOffset = 0;
	float yOffset = 0;
	if (enterAnim.isAnimating())
	{
		xOffset = enterAnim.getXDelta();
		yOffset = enterAnim.getYDelta();
	}
	else if (exitAnim.isAnimating())
	{
		xOffset = exitAnim.getXDelta();
		yOffset = exitAnim.getYDelta();
	}
	LogisticsScreen::render((int32_t)xOffset, (int32_t)yOffset);
}
FILTER* interpolateBevel(FILTER* filter1,FILTER* filter2, float ratio, interpolation_t* inter)
			{
				FILTER_BEVEL*f1 = (FILTER_BEVEL*)filter1;
				FILTER_BEVEL*f2 = (FILTER_BEVEL*)filter2;
    if (!f1)
    	f1 = noBevel;
    if (!f2)
    	f2 = noBevel;
    if(!memcmp(&f1->shadow,&f2->shadow,sizeof(RGBA)) &&
					!memcmp(&f1->highlight,&f2->highlight,sizeof(RGBA)) && 
					f1->blurx == f2->blurx && f1->blury == f2->blury && f1->angle == f2->angle && f1->strength == f2->strength && f1->distance == f2->distance)
		return copyFilter(filter1);
				FILTER_BEVEL*f = (FILTER_BEVEL*)swf_NewFilter(FILTERTYPE_BEVEL);
				memcpy(f, f1, sizeof(FILTER_BEVEL));
				f->shadow = interpolateColor(f1->shadow, f2->shadow, ratio, inter);
				f->highlight = interpolateColor(f1->highlight, f2->highlight, ratio, inter);
    f->blurx= interpolateScalar(f1->blurx, (f2->blurx), ratio, inter);
    f->blury= interpolateScalar(f1->blury, (f2->blury), ratio, inter);
    f->passes= interpolateScalar(f1->passes, (f2->passes), ratio, inter);
    f->angle= interpolateScalar(f1->angle, (f2->angle), ratio, inter);
    f->distance= interpolateScalar(f1->distance, (f2->distance), ratio, inter);
    f->strength= interpolateScalar(f1->strength, (f2->strength), ratio, inter);
    if (f1 == noBevel)
    {
    	if (f2 != noBevel)
    	    matchBevelFlags(f, f2);
    }
    else
    	if (f2 == noBevel)
	    matchBevelFlags(f, f1);
	else
	    if (ratio > 0.5)
    		matchBevelFlags(f, f2);
	    else
    		matchBevelFlags(f, f1);
				return (FILTER*)f;
}
Esempio n. 3
0
QVector<qreal> ColorGradient::bitsF(uint length) const
{
    if (!isValid())
        return QVector<qreal>();
        
    auto bits = QVector<qreal>{};
    for (auto i = 0u; i < length; ++i)
    {
        qreal position = (qreal)i / length;
        auto color = interpolateColor(position);
        bits << color.redF() << color.greenF() << color.blueF() << color.alphaF();
    }
    
    return bits;
}
Esempio n. 4
0
QVector<uchar> ColorGradient::bits(uint length) const
{
    if (!isValid())
        return QVector<uchar>();
        
    auto bits = QVector<uchar>{};
    for (auto i = 0u; i < length; ++i)
    {
        const auto position = static_cast<qreal>(i) / length;
        const auto color = interpolateColor(position);
        bits << color.red() << color.green() << color.blue() << color.alpha();
    }
    
    return bits;
}
Esempio n. 5
0
QImage ColorGradient::image(uint width) const
{
    if (!isValid())
        return QImage();

    auto image = QImage{static_cast<int>(width), 1, QImage::Format_ARGB32};

    for (auto i = 0u; i < width; ++i)
    {
        const auto position = static_cast<qreal>(i) / width;
        image.setPixel(i, 0, interpolateColor(position).rgba());
    }

    return image;
}
GRADIENT* interpolateNodes(GRADIENT* g1, GRADIENT* g2, float fraction, interpolation_t* inter)
{
    if (g1->num != g2->num)
    	syntaxerror("Internal error: gradients are not equal in size");

    int i;
    GRADIENT* g = (GRADIENT*) malloc(sizeof(GRADIENT));
    g->ratios = rfx_calloc(16*sizeof(U8));
    g->rgba = rfx_calloc(16*sizeof(RGBA));
    g->num = g1->num;
    for (i = 0; i < g->num; i++)
    {
    	g->ratios[i] = interpolateScalar(g1->ratios[i], g2->ratios[i], fraction, inter);
    	g->rgba[i] = interpolateColor(g1->rgba[i], g2->rgba[i], fraction, inter);
    }
    return g;
}
void insertNode(GRADIENT* g, int pos)
{
    memmove(&g->ratios[pos + 1], &g->ratios[pos], (g->num - pos) * sizeof(U8));
    memmove(&g->rgba[pos + 1], &g->rgba[pos], (g->num - pos) * sizeof(RGBA));
    if (pos == 0)
    {
    	g->ratios[0] = g->ratios[1] / 2;
    	g->rgba[0] = g->rgba[1];
    }
    else
    	if (pos == g->num)
    	{
    	    g->ratios[pos] = (255 + g->ratios[g->num - 1]) / 2;
    	    g->rgba[pos] = g->rgba[pos - 1];
    	}
    	else
    	{
	    g->ratios[pos] = (g->ratios[pos - 1] + g->ratios[pos + 1]) / 2;
	    g->rgba[pos] = interpolateColor(g->rgba[pos - 1], g->rgba[pos + 1], 0.5, 0);
    	}
    g->num++;
}
FILTER* interpolateDropshadow(FILTER* filter1,FILTER* filter2, float ratio, interpolation_t* inter)
		{
			FILTER_DROPSHADOW*f1 = (FILTER_DROPSHADOW*)filter1;
			FILTER_DROPSHADOW*f2 = (FILTER_DROPSHADOW*)filter2;
    if (!f1)
    	f1 = noDropshadow;
    if (!f2)
    	f2 = noDropshadow;
    if(!memcmp(&f1->color,&f2->color,sizeof(RGBA)) && f1->strength == f2->strength &&
				f1->blurx == f2->blurx && f1->blury == f2->blury && 
				f1->angle == f2->angle && f1->distance == f2->distance)
		return copyFilter(filter1);
			FILTER_DROPSHADOW*f = (FILTER_DROPSHADOW*)swf_NewFilter(FILTERTYPE_DROPSHADOW);
			memcpy(f, f1, sizeof(FILTER_DROPSHADOW));
			f->color = interpolateColor(f1->color, f2->color, ratio, inter);
    f->blurx= interpolateScalar(f1->blurx, (f2->blurx), ratio, inter);
    f->blury= interpolateScalar(f1->blury, (f2->blury), ratio, inter);
    f->passes= interpolateScalar(f1->passes, (f2->passes), ratio, inter);
    f->angle= interpolateScalar(f1->angle, (f2->angle), ratio, inter);
    f->distance= interpolateScalar(f1->distance, (f2->distance), ratio, inter);
    f->strength= interpolateScalar(f1->strength, (f2->strength), ratio, inter);
    if (f1 == noDropshadow)
    {
    	if (f2 != noDropshadow)
    	    matchDropshadowFlags(f, f2);
		}
		else
    	if (f2 == noDropshadow)
	    matchDropshadowFlags(f, f1);
	else
	    if (ratio > 0.5)
    		matchDropshadowFlags(f, f2);
	    else
    		matchDropshadowFlags(f, f1);
    return (FILTER*)f;
}
void LogisticsScreen::render(int32_t xOffset, int32_t yOffset)
{
	if(!isShowing())
		return;
	int32_t i;
	for(i = 0; i < rectCount; i++)
	{
		if(!rects[i].bOutline &&
				((rects[i].getColor() & 0xff000000) == 0xff000000))
		{
			rects[i].move(xOffset, yOffset);
			rects[i].render();
			rects[i].move(-xOffset, -yOffset);
		}
	}
	for(i = 0; i < staticCount; i++)
	{
		statics[i].move(xOffset, yOffset);
		statics[i].render();
		statics[i].move(-xOffset, -yOffset);
	}
	for(i = 0; i < rectCount; i++)
	{
		if(rects[i].bOutline)
		{
			rects[i].move(xOffset, yOffset);
			rects[i].render();
			rects[i].move(-xOffset, -yOffset);
		}
	}
	// transparencies after statics
	for(i = 0; i < rectCount; i++)
	{
		if((rects[i].getColor() & 0xff000000) != 0xff000000)
		{
			rects[i].move(xOffset, yOffset);
			rects[i].render();
			rects[i].move(-xOffset, -yOffset);
		}
	}
	for(i = 0; i < buttonCount; i++)
	{
		buttons[i].move(xOffset, yOffset);
		buttons[i].render();
		buttons[i].move(-xOffset, -yOffset);
	}
	for(i = 0; i < textCount; i++)
	{
		textObjects[i].move(xOffset, yOffset);
		textObjects[i].render();
		textObjects[i].move(-xOffset, -yOffset);
	}
	for(i = 0; i < editCount; i++)
	{
		edits[i].move(xOffset, yOffset);
		edits[i].render();
		edits[i].move(-xOffset, -yOffset);
	}
	for(i = 0; i < animObjectsCount; i++)
	{
		animObjects[i].move(xOffset, yOffset);
		animObjects[i].render();
		animObjects[i].move(-xOffset, -yOffset);
	}
	if(fadeOutTime)
	{
		fadeTime += frameLength;
		int32_t color = interpolateColor(0, 0xff000000, fadeTime / fadeOutTime);
		RECT rect = { 0, 0, Environment.screenWidth, Environment.screenHeight };
		drawRect(rect, color);
	}
	else if(fadeInTime && fadeInTime > fadeTime)
	{
		fadeTime += frameLength;
		int32_t color = interpolateColor(0xff000000, 0, fadeTime / fadeInTime);
		RECT rect = { 0, 0, Environment.screenWidth, Environment.screenHeight };
		drawRect(rect, color);
	}
}
Esempio n. 10
0
void MainMenu::render()
{

	if (introMovie)
	{
		introMovie->render();
		return;
	}
	if ( bDrawMechlopedia && (fadeTime > fadeOutTime || !fadeOutTime) )
	{
		mechlopedia->render();
		return;
	}

	
	if ( bOptions )
	{
		optionsScreenWrapper->render();
		return;
	}

	//DO NOT play the splash screen animation in software.
	// WOW does it beat up the framerate!
	float xDelta = 0.f;
	float yDelta = 0.f;  
	long color = 0xff000000;

	if (Environment.Renderer != 3)
	{

		if ( beginAnim.isAnimating() && !beginAnim.isDone() )
		{
			xDelta = beginAnim.getXDelta();
			yDelta = beginAnim.getYDelta();

			float time = beginAnim.getCurrentTime();
			float endTime = beginAnim.getMaxTime();
			if ( endTime )
			{
				color = interpolateColor( 0x00000000, 0x7f000000, time/endTime );

			}
		}

		else if (endAnim.isAnimating() /*&& !endAnim.isDone()*/)
		{
			xDelta = endAnim.getXDelta();
			yDelta = endAnim.getYDelta();

			float time = endAnim.getCurrentTime();
			float endTime = endAnim.getMaxTime();
			if ( endTime && (time <= endTime))
			{
				color = interpolateColor( 0x7f000000, 0x00000000, time/endTime );
			}
		}

		GUI_RECT rect = { 0, 0, Environment.screenWidth, Environment.screenHeight };
		drawRect( rect, color );

		if ( bDrawBackground )
		{
			background.render();
			intro.render();
			if ( !intro.animObjects[0].isDone() && !introOver && !bHostLeftDlg )
				return;


		}
	}
	else
	{
		GUI_RECT rect = { 0, 0, Environment.screenWidth, Environment.screenHeight };
		drawRect( rect, color );
	}

	if ( !xDelta && !yDelta )
	{
		drawShadowText( 0xffc66600, 0xff000000, textObjects[1].font.getTempHandle(), 
			textObjects[1].globalX(), textObjects[1].globalTop(),
			textObjects[1].globalRight(), textObjects[1].globalBottom(),
			true, textObjects[1].text, false, textObjects[1].font.getSize(), 1, 1 );
	}

	textObjects[1].showGUIWindow( false );

	
	if ( (!bSave && !bLoad && !bLoadSingle && !bLoadCampaign) || (!endAnim.isDone() && endResult != RESTART ) )	
		LogisticsScreen::render( xDelta, yDelta );
	else if ( bLoadSingle )
		singleLoadDlg.render();
	else
		LogisticsSaveDialog::instance()->render();
 
	if ( promptToQuit || promptToDisconnect )
	{
		LogisticsOKDialog::instance()->render();
	}
	if ( bLegal )
	{
		LogisticsLegalDialog::instance()->render();
	}
	if ( bHostLeftDlg )
	{
		LogisticsOneButtonDialog::instance()->render();
	}



	
}
void VelocityLimitedMarker::publishMarkers( double vel_x_desired, 
                                            double vel_x_actual, 
                                            double vel_y_desired, 
                                            double vel_y_actual, 
                                            double vel_theta_desired,
                                            double vel_theta_actual)
{
    if( disabled_ )
    {
        return;
    }

    // Publish the markers
    double epsilon = 0.05;

    // acceleration
    double ax,ay,atheta;
    ax = vel_x_actual - vx_last_;
    ay = vel_y_actual - vy_last_;
    atheta = vel_theta_actual - vtheta_last_;
    vx_last_ = vel_x_actual;
    vy_last_ = vel_y_actual;
    vtheta_last_ = vel_theta_actual;

    // for x-axis
    double x_vel_diff = fabs(vel_x_desired - vel_x_actual);
    if( x_vel_diff >= epsilon )
    {
//        double alpha = x_vel_diff * VELOCITY_COEFF;
        if (vel_x_desired >= 0.0 && ax <= 0.0)
        {
            x_pos_marker_.header.stamp = ros::Time::now();
            interpolateColor(x_vel_diff, x_pos_marker_.color);
//            x_pos_marker_.color.a = (alpha > 1.0) ? 1.0 : alpha;
        	marker_pub_.publish(x_pos_marker_);            
        }
        else if (vel_x_desired <= 0.0 && ax >= 0.0)
        {
            x_neg_marker_.header.stamp = ros::Time::now();
            interpolateColor(x_vel_diff, x_neg_marker_.color);
//            x_neg_marker_.color.a = (alpha > 1.0) ? 1.0 : alpha;
    	    marker_pub_.publish(x_neg_marker_);
        }
    }

    // for y-axis
    double y_vel_diff = fabs(vel_y_desired - vel_y_actual);
    if( y_vel_diff >= epsilon )
    {
//        double alpha = y_vel_diff * VELOCITY_COEFF;
        if (vel_y_desired >= 0.0 && ay <= 0.0)
        {
            y_pos_marker_.header.stamp = ros::Time::now();
            interpolateColor(y_vel_diff, y_pos_marker_.color);
//            y_pos_marker_.color.a = (alpha > 1.0) ? 1.0 : alpha;
        	marker_pub_.publish(y_pos_marker_);            
        }
        else if (vel_y_desired <= 0.0 && ay >= 0.0)
        {
            y_neg_marker_.header.stamp = ros::Time::now();
            interpolateColor(y_vel_diff, y_neg_marker_.color);
//            y_neg_marker_.color.a = (alpha > 1.0) ? 1.0 : alpha;
    	    marker_pub_.publish(y_neg_marker_);
        }
    }

    // for theta-axis
    double theta_vel_diff = fabs(vel_theta_desired - vel_theta_actual);
    if( theta_vel_diff >= epsilon )
    {
//        double alpha = theta_vel_diff * VELOCITY_COEFF;
        if (vel_theta_desired >= 0.0  && atheta <= 0.0)
        {
            theta_pos_marker_.header.stamp = ros::Time::now();
            interpolateColor(theta_vel_diff, theta_pos_marker_.color);
//            theta_pos_marker_.color.a = (alpha > 1.0) ? 1.0 : alpha;
        	marker_pub_.publish(theta_pos_marker_);            
        }
        else if (vel_theta_desired <= 0.0  && atheta >= 0.0)
        {
            theta_neg_marker_.header.stamp = ros::Time::now();
            interpolateColor(theta_vel_diff, theta_neg_marker_.color);
//            theta_neg_marker_.color.a = (alpha > 1.0) ? 1.0 : alpha;
    	    marker_pub_.publish(theta_neg_marker_);
        }
    }
}
void LogisticsSaveDialog::render()
{

	float xOffset = 0;
	float yOffset = 0 ;
	if ( enterAnim.isAnimating() )
	{
		xOffset = enterAnim.getXDelta();
		yOffset = enterAnim.getYDelta();
	}
	else if ( exitAnim.isAnimating() )
	{
		xOffset = exitAnim.getXDelta();
		yOffset = exitAnim.getYDelta();
	}

	float color = 0x7f000000;

	if ( enterAnim.isAnimating() && !enterAnim.isDone() )
	{
		float time = enterAnim.getCurrentTime();
		float endTime = enterAnim.getMaxTime();
		if ( endTime )
		{
			color = interpolateColor( 0x00000000, 0x7f000000, time/endTime );
			
		}
	}

	else if ( exitAnim.isAnimating() && !exitAnim.isDone() && !bLoad )
	{
		float time = exitAnim.getCurrentTime();
		float endTime = exitAnim.getMaxTime();
		if ( endTime )
		{
			color = interpolateColor( 0x7f000000, 0x00000000, time/endTime );
			
			
		}
	}

	if ( fadeOutTime )
		color = 0;

	
	GUI_RECT rect = { 0, 0, Environment.screenWidth, Environment.screenHeight };
	drawRect( rect, color );


	if ( xOffset || yOffset )
	{
		gameListBox.move( xOffset, yOffset );
		gameListBox.render();
		gameListBox.move( -xOffset, -yOffset );
	}
	else
	{
		gameListBox.render();
	}
	
	LogisticsScreen::render( (int)xOffset, (int)yOffset );
	
	if ( bPromptOverwrite || bDeletePrompt )
	{
		LogisticsOKDialog::instance()->render();
	}
		
}
Esempio n. 13
0
void MechBayScreen::drawWeightMeter(long xOffset, long yOffset)
{
		// there are 20 rays, each 9 degrees
	// they should be 50 pixels long
	float currentDropWeight = LogisticsData::instance->getCurrentDropWeight();
	float maxDropWeight = LogisticsData::instance->getMaxDropWeight();
	long numAddBars = 0;
	long numRemoveBars = 0;

	long addColor = 0;
	long removeColor = 0;		

	long numberOfBars = 20;
	if ( maxDropWeight != 0 )
	{
		float percent = currentDropWeight/maxDropWeight;
		percent *= 20.f;
		numberOfBars = percent + .5;
	}

	if ( addWeightAnim.isAnimating() && !addWeightAnim.isDone() )
	{
		addColor = addWeightAnim.getColor();
		float percent = (currentDropWeight - addWeightAmount) / maxDropWeight;
		percent *= 20.f;
		numAddBars = percent + .5;
		numAddBars = numberOfBars - numAddBars;
	}

	if ( removeWeightAnim.isAnimating() && !removeWeightAnim.isDone() )
	{
		addColor = removeWeightAnim.getColor();
		float percent = removeWeightAmount / maxDropWeight;
		percent *= 20.f;
		numRemoveBars = percent + .5;
	}

	gos_VERTEX v[3];
	for ( int i = 0; i <3; i++ )
	{
		v[i].u = 0.f;
		v[i].v = 0.f;
		v[i].rhw = .5;
		v[i].z = 0.f;
		v[i].argb = 0;
		v[i].frgb = 0;
		v[i].x = weightCenterX + xOffset;
		v[i].y = weightCenterY + yOffset;
	}
	 
	float curArc = 180.f;
	float curX = 50.f * cos( DEGREES_TO_RADS * curArc );
	float curY = 50.f * sin( DEGREES_TO_RADS * curArc );
	for ( i= 0; i < numberOfBars + numRemoveBars; i++ )
	{

		v[1].x = curX + weightCenterX + xOffset;
		v[1].y = curY + weightCenterY + yOffset;

		curArc += 9.f;
		curX = 50.f * cos( DEGREES_TO_RADS * curArc );
		curY = 50.f * sin( DEGREES_TO_RADS * curArc );

		v[2].x = curX + weightCenterX + xOffset;
		v[2].y = curY + weightCenterY + yOffset;

		if ( i >= numberOfBars - numAddBars )
			v[0].argb = v[1].argb = v[2].argb = addColor;
		else if ( i >= numberOfBars )
			v[0].argb = v[1].argb = v[2].argb = removeColor;
		else
			v[0].argb = v[1].argb = v[2].argb = interpolateColor( weightStartColor, weightEndColor, i * .05 );

		gos_DrawTriangles( v, 3 );
		

	}


	dropWeightMeter.render(xOffset, yOffset);
}
void PilotReadyScreen::render(int xOffset, int yOffset )
{
	pilotListBox.move( xOffset, yOffset );
	pilotListBox.render();
	pilotListBox.move( -xOffset, -yOffset );


	if ( !xOffset && !yOffset )
	{
		if ( !MPlayer && !LogisticsData::instance->isSingleMission() && LogisticsData::instance->newPilotsAvailable() )
		{
			soundSystem->playBettySample( BETTY_NEW_PILOTS );
			LogisticsData::instance->setNewPilotsAcknowledged();
		}
	}

	for ( int i = 0; i < 2; i++ )
	{
		attributeMeters[i].render( xOffset, yOffset );
	}


	if ( pCurPilot )
		rankIcons[pCurPilot->getRank()].render(xOffset, yOffset);


	for ( i = 0; i < 4; i++ )
		skillIcons[i].render(xOffset, yOffset);

	for ( i = 0; i < MAX_MEDAL; i++ )
		medalIcons[i].render(xOffset, yOffset);


	LogisticsScreen::render( xOffset, yOffset );
	for ( i = 0; i < ICON_COUNT; i++ )
	{
		pIcons[i].render( xOffset, yOffset );
	}


	if ( mechSelected )
	{
		// hack, cover up pilot stuff.
		GUI_RECT rect = { 77 + xOffset, 317 + yOffset, 720+ xOffset, 515 + yOffset };
		drawRect( rect, 0xff000000 );
		mechDisplay.render( xOffset, yOffset );
		// hack, cover up list box overrruns.
		statics[27].render( xOffset, yOffset );
		statics[28].render( xOffset, yOffset );
	}

	if ( launchFadeTime )
	{
		launchFadeTime += frameLength;
		long color = interpolateColor( 0x00000000, 0x7f000000, launchFadeTime/.5f );
		GUI_RECT rect = { 0, 0, Environment.screenWidth, Environment.screenHeight };
		drawRect( rect, color );
	}

	if ( MPlayer && ChatWindow::instance() )
		ChatWindow::instance()->render(xOffset, yOffset);

	if ( pDragPilot )
		dragIcon.render();

}
Esempio n. 15
0
void testApp :: updateBlobs ()
{
	//-- remove old blobs.

	contourBlobs.clear();
	contourBlobsScaled.clear();
	contourBlobsSimplified.clear();
	
	//-- copy blobs and scale.
	
	float scale;
	scale = largeRect.width / (float)noiseRect.width;
	
	float xoff;
	xoff = largeRect.x;
	
	float yoff;
	yoff = largeRect.y;

	for( int i=0; i<noiseBandsTotal; i++ )
	{
		ofxCvGrayscaleImage& image = noiseBands[ i ];
		
		int numOfBlobs;
		numOfBlobs = updateContours( image );
		
		if( numOfBlobs == 0 )
			continue;
		
		ofColor c0 = colorPicker0.getColor();
		ofColor c1 = colorPicker1.getColor();
		ofColor c2 = interpolateColor( c0, c1, noiseBandCutoffs[ i ] );
		
		for( int j=0; j<numOfBlobs; j++ )
		{
			ofxCvBlob& blob = contourFinder.blobs[ j ];
			
			contourBlobs.push_back( Blob() );
			contourBlobsScaled.push_back( Blob() );
			contourBlobsSimplified.push_back( Blob() );
			
			copyBlob( blob, contourBlobs.back() );
			copyBlob( blob, contourBlobsScaled.back(), xoff, yoff, scale );
			copyBlob( blob, contourBlobsSimplified.back(), xoff, yoff, scale );
			
			contourBlobs.back().color			= c2;
			contourBlobsScaled.back().color		= c2;
			contourBlobsSimplified.back().color	= c2;

			if( contourSmoothScale > 0 )
			{
				contourUtil.smooth( contourBlobsSimplified.back().pts, contourSmoothScale, 1.0 );
			}

			if( contourSimplifyScale > 0 )
			{
				contourUtil.simplify( contourBlobsSimplified.back().pts, contourSimplifyScale );
			}
			
			if( contourSimplifyTolerance > 0 )
			{
				float tolerance = contourSimplifyTolerance;
				tolerance *= ( 1 / (float)contourBlobsSimplified.back().pts.size() );
				tolerance *= 100;
				
				vector<ofPoint> ptsOut;
				contourSimplify.simplify( contourBlobsSimplified.back().pts, ptsOut, tolerance );
				contourBlobsSimplified.back().pts = ptsOut;
			}
		}
	}
}
Esempio n. 16
0
void SampleDisplay::draw(void)
{
	if(!isExposed())
		return;

	//
	// Border and background
	//
	//drawFullBox(0, 0, width, height, theme->col_dark_bg);
	u32 colcol = theme->col_dark_bg | theme->col_dark_bg << 16;
	for(int j=y;j<y+height;++j) dmaFillWordsDamnFast(colcol, *vram+256*j+x, width*2);

	if(active==false) {
		drawBorder();
	} else {
		drawBorder(RGB15(31,0,0)|BIT(15));
	}

	// Now comes sample-dependant stuff, so return if we have no sample
	if((smp==0)||(smp->getNSamples()==0)) return;

	//
	// Selection
	//
	s32 selleft = sampleToPixel(MIN(selstart, selend));
	s32 selwidth = sampleToPixel(MAX(selstart, selend)) - selleft;
	bool dontdraw = false;

	if( (selleft >= 0) && (selleft < width-2) && (selleft + selwidth > width - 2) ) {
		selwidth = (width-2) - selleft;
	} else if( (selleft < 0) && (selleft + selwidth > 0) && (selleft + selwidth < width-2) ) {
		selwidth += selleft;
		selleft = 0;
	} else if( (selleft < 0) && (selleft + selwidth > width-2) ) {
		selwidth = width-2;
		selleft = 0;
	} else if( (selleft + selwidth < 0) || (selleft > width-2) ) {
		dontdraw = true;
	}

	if(selection_exists && !dontdraw) {
		drawFullBox(selleft+1, 1, selwidth, DRAW_HEIGHT+1, RGB15(31,31,0)|BIT(15));
	}

	//
	// Scrollbar
	//

	// Right Button
	if(pen_on_scroll_right) {
		drawGradient(theme->col_dark_ctrl, theme->col_light_ctrl, width-9, height-SCROLLBAR_WIDTH+1, 8, 8);
	} else {
		drawGradient(theme->col_light_ctrl, theme->col_dark_ctrl, width-9, height-SCROLLBAR_WIDTH+1, 8, 8);
	}

	// This draws the right-arrow
	s8 j, p;
	for(j=0;j<3;j++) {
		for(p=-j;p<=j;++p) {
			*(*vram+SCREEN_WIDTH*(y+height-SCROLLBAR_WIDTH+4+p)+x+width-j-3) = RGB15(0,0,0) | BIT(15);
		}
	}

	drawBox(width-SCROLLBAR_WIDTH, height-SCROLLBUTTON_HEIGHT, 9, 9);

	// Left Button
	if(pen_on_scroll_left) {
		drawGradient(theme->col_dark_ctrl, theme->col_light_ctrl, 1, height-9, 8, 8);
	} else {
		drawGradient(theme->col_light_ctrl, theme->col_dark_ctrl, 1, height-9, 8, 8);
	}

	// This draws the down-arrow
	for(j=2;j>=0;j--) {
		for(p=-j;p<=j;++p) {
			*(*vram+SCREEN_WIDTH*(y+height-SCROLLBAR_WIDTH+4+p)+x+j+3) = theme->col_icon;
		}
	}

	drawBox(0, height-9, 9, 9);


	drawBox(0, height-SCROLLBAR_WIDTH, width, SCROLLBAR_WIDTH);

	// Clear Scrollbar
	drawGradient(theme->col_medium_bg, theme->col_light_bg, SCROLLBUTTON_HEIGHT, height-SCROLLBAR_WIDTH+1, width-2*SCROLLBUTTON_HEIGHT, SCROLLBAR_WIDTH-2);

	// The scroll thingy
	if(pen_on_scrollthingy) {
		drawFullBox(SCROLLBUTTON_HEIGHT+scrollthingypos, height-SCROLLBAR_WIDTH+1, scrollthingywidth-2, SCROLLBAR_WIDTH-2, theme->col_light_ctrl);
	} else {
		drawFullBox(SCROLLBUTTON_HEIGHT+scrollthingypos, height-SCROLLBAR_WIDTH+1, scrollthingywidth-2, SCROLLBAR_WIDTH-2, theme->col_dark_ctrl);
	}

	drawBox(SCROLLBUTTON_HEIGHT-1+scrollthingypos, height-SCROLLBAR_WIDTH, scrollthingywidth, SCROLLBAR_WIDTH);

	//
	// Sample
	//

	u16 colortable[DRAW_HEIGHT+2];
	for(u8 i=0; i<DRAW_HEIGHT+2; ++i)
		colortable[i] = interpolateColor(theme->col_light_ctrl, theme->col_dark_ctrl, i);

	// TODO; Eliminate floats here!!

	/*
	float step = (float)(smp->getNSamples() >> zoom_level) / (float)(width-2);
	float pos = 0.0f;

	u32 renderwindow = (u32)MAX(1, MIN(100, ceil(step)));
	*/

#define _fix(x) ((x)<<12)

	int step = divf32(_fix(smp->getNSamples() >> zoom_level), _fix(width-2));
	int pos = 0;

	int ceil_step = step;
	if (ceil_step & 0xFFF)
	{
		ceil_step &= ~0xFFF;
		ceil_step ++;
	}

	u32 renderwindow = MAX(1, MIN(100, ceil_step>>12));

	u16 middle = (DRAW_HEIGHT+2)/2;//-1;

	s32 lastmax=0, lastmin=0;
	if(smp->is16bit() == true) {

		s16 *data;
		s16 *base = (s16*)smp->getData() + pixelToSample(0);

		for(u32 i=1; i<u32(width-1); ++i)
		{
			data = &(base[pos>>12]);

			s32 maxsmp = -32767, minsmp = 32767;

			for(u32 j=0;j<renderwindow;++j) {
				if(*data > maxsmp) maxsmp = *data;
				if(*data < minsmp) minsmp = *data;
				data++;
			}

			s32 maxy = div32((DRAW_HEIGHT+2) * maxsmp, 2 * 32767);
			s32 miny = div32((DRAW_HEIGHT+2) * minsmp, 2 * 32767);

			if(i>1) {
				if(lastmin > maxy) maxy = lastmin;
				if(lastmax < miny) miny = lastmax;
			}

			for(s16 j=miny; j<=maxy; ++j) (*vram)[SCREEN_WIDTH*(y+middle-j)+x+i] = colortable[middle-j];

			lastmax = maxy;
			lastmin = miny;

			*(*vram+SCREEN_WIDTH*(y+middle)+x+i) = colortable[middle];

			pos += step;
		}

	} else {