Beispiel #1
0
void CFlarePainter::PaintFlare (CG32bitImage &Dest, int x, int y, int iRadius, CG32bitPixel rgbColor, bool bSpikes, SViewportPaintCtx &Ctx)

//	PaintFlare
//
//	Paints a flare

{
    int i;

    if (iRadius > 0)
    {
        //	Paint each of the spikes first

        if (bSpikes)
        {
            int iAngle = 360 / MAIN_SPIKE_COUNT;
            for (i = 0; i < MAIN_SPIKE_COUNT; i++)
            {
                SPoint Spike[4];
                m_pCreator->CreateFlareSpike(i * iAngle, iRadius, iRadius / MAIN_SPIKE_WIDTH_RATIO, Spike);

                CG16bitBinaryRegion Region;
                Region.CreateFromSimplePolygon(4, Spike);
                Region.Fill(Dest, x, y, CG32bitPixel(rgbColor, MAIN_SPIKE_OPACITY));
            }
        }

        //	Paint the extended glow

        CGDraw::CircleGradient(Dest, x, y, iRadius, rgbColor);
    }
}
Beispiel #2
0
void CAniSolidFill::Fill (SAniPaintCtx &Ctx, int x, int y, const CG16bitBinaryRegion &Region)

//	Fill
//
//	Fills the region

	{
	Region.Fill(Ctx.Dest, x, y, CG32bitPixel(m_rgbColor, (BYTE)m_dwOpacity));
	}
Beispiel #3
0
void CPolyflashPainter::Paint (CG32bitImage &Dest, int x, int y, SViewportPaintCtx &Ctx)

//	Paint
//
//	Paints the flash

	{
	CG16bitBinaryRegion Region;
	SPoint Poly[6];

	//	Create the broad outer flame

	CreateFlame(Ctx.iRotation, 40, Poly);
	Region.CreateFromConvexPolygon(6, Poly);
	Region.Fill(Dest, x, y, CG32bitPixel(0xff, 0x80, 0x40, 0x80));

	//	Create the central bright area

	CreateFlame(Ctx.iRotation, 30, Poly);
	Region.CreateFromConvexPolygon(6, Poly);
	Region.Fill(Dest, x, y, CG32bitPixel(0xff, 0xff, 0xa0));
	}
void TestPolygons (CUniverse &Universe, CXMLElement *pCmdLine)
{
    int i;

    const int FRAME_WIDTH = 256;
    const int FRAME_HEIGHT = 256;
    const int OUTPUT_WIDTH = FRAME_WIDTH * 2;
    const int OUTPUT_HEIGHT = FRAME_HEIGHT;

    //	Options

    int iCount = pCmdLine->GetAttributeInteger(CONSTLIT("count"));
    if (iCount == 0)
        iCount = 1000;

    int iBltCount = Max(1, iCount / 10);

    //	Create the output image

    CG32bitImage Output;
    Output.Create(OUTPUT_WIDTH, OUTPUT_HEIGHT, CG32bitImage::alpha8);

    //	Create a regular polygon

    const int iSides = 17;
    const Metric rRadius = 100.0;
    const Metric rAngleStep = (TAU / iSides);

    TArray<CVector> Shape1;
    Shape1.InsertEmpty(iSides);
    for (i = 0; i < iSides; i++)
        Shape1[i] = CVector::FromPolar(i * rAngleStep, rRadius);

    //	Create a point array, which we'll use for the binary region

    SPoint Shape1Points[iSides];
    for (i = 0; i < iSides; i++)
    {
        Shape1Points[i].x = (int)Shape1[i].GetX();
        Shape1Points[i].y = (int)Shape1[i].GetY();
    }

    //	Create a path

    CGPath Shape1Path;
    Shape1Path.Init(Shape1);

    //	We do timing tests first

    TNumberSeries<Metric> Timing;

    //	Time rasterization of a binary region

    const int CALLS_PER_SAMPLE = 1000;
    const int BLTS_PER_SAMPLE = 100;
    DWORD dwStart = ::GetTickCount();
    for (i = 0; i < iCount; i++)
    {
        CG16bitBinaryRegion Region;
        Region.CreateFromPolygon(iSides, Shape1Points);

        if (((i + 1) % CALLS_PER_SAMPLE) == 0)
            Timing.Insert((Metric)::sysGetTicksElapsed(dwStart, &dwStart));
    }

    printf("CG16bitBinaryRegion::CreateFromPolygon: %s ms per %d\n", (LPSTR)strFromDouble(Timing.GetMean()), CALLS_PER_SAMPLE);

    //	Time rasterization of path

    Timing.DeleteAll();
    dwStart = ::GetTickCount();
    for (i = 0; i < iCount; i++)
    {

        CGRegion Region;
        Shape1Path.Rasterize(&Region, 1);

        if (((i + 1) % CALLS_PER_SAMPLE) == 0)
            Timing.Insert((Metric)::sysGetTicksElapsed(dwStart, &dwStart));
    }

    printf("CGPath::Rasterize: %s ms per %d\n", (LPSTR)strFromDouble(Timing.GetMean()), CALLS_PER_SAMPLE);

    //	Create the regions

    CG16bitBinaryRegion Shape1BinaryRegion;
    Shape1BinaryRegion.CreateFromPolygon(iSides, Shape1Points);

    CGRegion Shape1Region;
    Shape1Path.Rasterize(&Shape1Region, 4);

    //	Time to blt

    Timing.DeleteAll();
    dwStart = ::GetTickCount();
    for (i = 0; i < iBltCount; i++)
    {
        CGDraw::Region(Output, (FRAME_WIDTH / 2), (FRAME_HEIGHT / 2), Shape1BinaryRegion, CG32bitPixel(255, 255, 255));

        if (((i + 1) % BLTS_PER_SAMPLE) == 0)
            Timing.Insert((Metric)::sysGetTicksElapsed(dwStart, &dwStart));
    }

    printf("CGDraw::Region (CG16bitBinaryRegion): %s ms per %d\n", (LPSTR)strFromDouble(Timing.GetMean()), BLTS_PER_SAMPLE);

    Timing.DeleteAll();
    dwStart = ::GetTickCount();
    for (i = 0; i < iBltCount; i++)
    {
        CGDraw::Region(Output, (FRAME_WIDTH / 2), (FRAME_HEIGHT / 2), Shape1Region, CG32bitPixel(255, 255, 255));

        if (((i + 1) % BLTS_PER_SAMPLE) == 0)
            Timing.Insert((Metric)::sysGetTicksElapsed(dwStart, &dwStart));
    }

    printf("CGDraw::Region (CGRegion): %s ms per %d\n", (LPSTR)strFromDouble(Timing.GetMean()), BLTS_PER_SAMPLE);

    //	Clear

    Output.Fill(CG32bitPixel(0, 0, 0));

    //	Blt result

    int x = 0;
    int y = 0;
    CGDraw::Region(Output, x + (FRAME_WIDTH / 2), y + (FRAME_HEIGHT / 2), Shape1BinaryRegion, CG32bitPixel(255, 255, 255));

    x = FRAME_WIDTH;
    CGDraw::Region(Output, x + (FRAME_WIDTH / 2), y + (FRAME_HEIGHT / 2), Shape1Region, CG32bitPixel(255, 255, 255));

    //	Copy to clipboard

    OutputImage(Output, NULL_STR);
}
Beispiel #5
0
void CFlarePainter::Paint (CG16bitImage &Dest, int x, int y, SViewportPaintCtx &Ctx)

//	Paint
//
//	Paint

	{
	int i;
	
	//	Safety checks

	int iTotalLifetime = m_pCreator->GetLifetime();
	if (iTotalLifetime <= 0)
		return;

	switch (m_pCreator->GetStyle())
		{
		case CFlareEffectCreator::styleFadingBlast:
			{

			//	Radius shrinks proportionally each tick

			int iRadius;
			if (m_iTick < m_pCreator->GetLifetime())
				iRadius = (int)(m_pCreator->GetRadius() * ((Metric)(m_pCreator->GetLifetime() - m_iTick) / (Metric)iTotalLifetime));
			else
				iRadius = 0;

			//	Color moves from primary to secondary

			WORD wColor;
			if (m_pCreator->GetPrimaryColor() != m_pCreator->GetSecondaryColor())
				wColor = CG16bitImage::FadeColor(m_pCreator->GetPrimaryColor(), m_pCreator->GetSecondaryColor(), 100 * m_iTick / iTotalLifetime);
			else
				wColor = m_pCreator->GetPrimaryColor();

			//	Paint

			if (iRadius)
				{
				//	Paint each of the spikes first

				int iAngle = 360 / MAIN_SPIKE_COUNT;
				for (i = 0; i < MAIN_SPIKE_COUNT; i++)
					{
					SPoint Spike[4];
					m_pCreator->CreateFlareSpike(i * iAngle, iRadius, iRadius / MAIN_SPIKE_WIDTH_RATIO, Spike);

					CG16bitBinaryRegion Region;
					Region.CreateFromSimplePolygon(4, Spike);
					Region.FillTrans(Dest, x, y, wColor, MAIN_SPIKE_OPACITY);
					}

				//	Paint the extended glow

				DrawAlphaGradientCircle(Dest,
						x,
						y,
						iRadius,
						wColor);
				}

			break;
			}
		}
	}