Exemplo n.º 1
0
void ArrangeAlignment::RedrawDiagram(ReDrawInfoType* ExtraInfo)
{
	// objects drawn in the render region must be relatively large in the given coord space
	// else Gavin's curve flattening results in visible straight lines
	// so every dimension is scaled by scale
	INT32 scale=1000;

	// make a render region
	DocRect VirtRendRect;
	VirtRendRect.lo.x=-1*scale;
	VirtRendRect.lo.y=-2*scale;
	VirtRendRect.hi.x=(DiagWidth +1)*scale;
	VirtRendRect.hi.y=(DiagHeight+2)*scale;
	RenderRegion* pRender=CreateGRenderRegion(&VirtRendRect,ExtraInfo);

	if (pRender!=NULL)
	{
		pRender->SaveContext();

		// currently this must be set here before any colour tables calculated
		Quality             AntiAliasQuality(Quality::QualityMax);
		QualityAttribute    AntiAliasQualityAttr(AntiAliasQuality);
		pRender->SetQuality(&AntiAliasQualityAttr,FALSE);

		// Render the background rectangle
		DialogColourInfo RedrawColours;
		pRender->SetLineColour(RedrawColours.DialogBack());
		pRender->SetFillColour(RedrawColours.DialogBack());
		pRender->DrawRect(&VirtRendRect);

		// declared at this scope else RestoreContext() dies!
		RadialFillAttribute Fill;		

		// set up some defaults used by all objects
		Fill.MakeElliptical();
		Fill.Colour=DocColour(255,255,255);
		pRender->SetLineColour(BLACK);
		pRender->SetLineWidth(0);

		for (INT32 i=0; i<DiagRects; i++)
		{
			// reverse order in which objets are rendered (now filled!)
			INT32 j=DiagRects-1-i;

			// set fill colour of each object
			switch (j)
			{
				case  0: Fill.EndColour=DocColour(255,255,0); break;
				case  1: Fill.EndColour=DocColour(0,0,255);   break;
				case  2: Fill.EndColour=DocColour(255,0,0);   break;
				case  3: Fill.EndColour=DocColour(0,160,0);   break;
				default: Fill.EndColour=DocColour(0,0,0);     break;
			}

			// get bound rect of object to be drawn
			INT32 x=DiagRectX[Align.h][j].lo*scale;
			INT32 w=DiagRectX[Align.h][j].hi*scale-x;
			INT32 y=DiagRectY[Align.v][j].lo*scale;
			INT32 h=DiagRectY[Align.v][j].hi*scale-y;

			// create shape and fill geometries
			Path shape;
			shape.Initialise(16,8);
			shape.IsFilled=TRUE;
			shape.FindStartOfPath();
			switch (j)
			{
				case 0:
				{
					// create a rectangle
					shape.InsertMoveTo(DocCoord(x,y));
					shape.InsertLineTo(DocCoord(x,y+h));
					shape.InsertLineTo(DocCoord(x+w,y+h));
					shape.InsertLineTo(DocCoord(x+w,y));
					shape.InsertLineTo(DocCoord(x,y));

//					// create a radial fill
//					Fill.StartPoint=DocCoord(x+w*3/16,y+h*3/4);
//					Fill.EndPoint  =DocCoord(x+w*3/8,y+h/2);
//					Fill.EndPoint2 =DocCoord(x+w*3/8,y+h);
					break;
				}

				case 1:
				{
					// create a pseudo ellipse
					shape.InsertMoveTo( DocCoord(x,y+h/2));
					shape.InsertCurveTo(DocCoord(x,y+h*3/4),  DocCoord(x+w/4,y+h),  DocCoord(x+w/2,y+h));
					shape.InsertCurveTo(DocCoord(x+w*3/4,y+h),DocCoord(x+w,y+h*3/4),DocCoord(x+w,y+h/2));
					shape.InsertCurveTo(DocCoord(x+w,y+h/4),  DocCoord(x+w*3/4,y),  DocCoord(x+w/2,y));
					shape.InsertCurveTo(DocCoord(x+w/4,y),    DocCoord(x,y+h/4),    DocCoord(x,y+h/2));

// 					// create a radial fill
//					Fill.StartPoint=DocCoord(x+w*3/8,y+h*5/8);
//					Fill.EndPoint  =DocCoord(x+w*6/8,y+h/4);
//					Fill.EndPoint2 =DocCoord(x+w*6/8,y+h);
					break;
				}

				default:
				{
					// create a rounded rectangle
					shape.InsertMoveTo( DocCoord(x,y+h/2));
					shape.InsertCurveTo(DocCoord(x,y+h),  DocCoord(x,y+h),  DocCoord(x+w/2,y+h));
					shape.InsertCurveTo(DocCoord(x+w,y+h),DocCoord(x+w,y+h),DocCoord(x+w,y+h/2));
					shape.InsertCurveTo(DocCoord(x+w,y),  DocCoord(x+w,y),  DocCoord(x+w/2,y));
					shape.InsertCurveTo(DocCoord(x,y),    DocCoord(x,y),    DocCoord(x,y+h/2));

// 					// create a radial fill
//					Fill.StartPoint=DocCoord(x+w*3/16,y+h*3/4);
//					Fill.EndPoint  =DocCoord(x+w*3/8,y+h/2);
//					Fill.EndPoint2 =DocCoord(x+w*3/8,y+h);
					break;
				}

			}
//			pRender->SetFillGeometry(&Fill,FALSE);
			pRender->SetFillColour(Fill.EndColour);
			pRender->DrawPath(&shape);
		}

		pRender->RestoreContext();
		DestroyGRenderRegion(pRender);	// also blt's to screen
	}
}
Exemplo n.º 2
0
BOOL ArrowRec::CreateStockArrow(StockArrow ArrowType)
{
	if (ArrowShape != NULL)
	{
		delete ArrowShape;
		ArrowShape = NULL;
	}

	BOOL ok;
	Path* pPath;

	const INT32 Size  = 3;
	const INT32 Width = (72000/2)*3;

	if (ArrowType >= NUM_STOCK_ARROWS)
		ArrowType = SA_STRAIGHTARROW;

	// Set the ArrowID
	ArrowID = ArrowType;

	switch (ArrowType)
	{
		case SA_STRAIGHTARROW:

			/*
			STRAIGHT
			-9 54 m
			-9 0 l
			-9 -54 l
			117 0 l
			-9 54 l
			-9 54 l
			*/

			pPath = new Path();
			if (pPath == NULL)
				return FALSE;

			ok = pPath->Initialise(4);
			if (ok) 	 pPath->FindStartOfPath();
			if (ok) ok = pPath->InsertMoveTo(DocCoord( -9000,  54000));
			if (ok) ok = pPath->InsertLineTo(DocCoord( -9000, -54000));
			if (ok) ok = pPath->InsertLineTo(DocCoord(117000,      0));
			if (ok) ok = pPath->CloseSubPath();

			if (!ok)
			{
				delete pPath;
				return FALSE;
			}

			pPath->IsFilled  = TRUE;
			pPath->IsStroked = FALSE;

			ArrowShape 	= pPath;
			Centre 		= DocCoord(0,0);
			LineWidth 	= Width;
			ArrowWidth 	= INT32(Size);
			ArrowHeight = INT32(Size);
 			IsNull 		= FALSE;

			StartArrow = FALSE;

			break;

		case SA_ANGLEDARROW:

			/*
			ANGLED
			-26.999 53.999 m
			-9 0 l
			-26.999 -54.001 l
			135 0 l
			-26.999 53.999 l
			*/

			pPath = new Path();
			if (pPath == NULL)
				return FALSE;

			ok = pPath->Initialise(5);
			if (ok) 	 pPath->FindStartOfPath();
			if (ok) ok = pPath->InsertMoveTo(DocCoord(-27000,  54000));
			if (ok) ok = pPath->InsertLineTo(DocCoord( -9000,      0));
			if (ok) ok = pPath->InsertLineTo(DocCoord(-27000, -54000));
			if (ok) ok = pPath->InsertLineTo(DocCoord(135000,      0));
			if (ok) ok = pPath->CloseSubPath();

			if (!ok)
			{
				delete pPath;
				return FALSE;
			}

			pPath->IsFilled  = TRUE;
			pPath->IsStroked = FALSE;

			ArrowShape 	= pPath;
			Centre 		= DocCoord(0,0);
			LineWidth 	= Width;
			ArrowWidth 	= INT32(Size);
			ArrowHeight = INT32(Size);
 			IsNull 		= FALSE;

			StartArrow = FALSE;

			break;


		case SA_ROUNDEDARROW:

			/*
			ROUND
			-9 0 m
			-9 -45 l
			-9 -51.708 2.808 -56.580 9 -54 c
			117 -9 l
			120.916 -7.369 126 -4.242 126 0 c
			126 4.242 120.916 7.369 117 9 c
			9 54 l
			2.808 56.580 -9 51.708 -9 45 c
			-9 0 l
			*/

			pPath = new Path();
			if (pPath == NULL)
				return FALSE;

			ok = pPath->Initialise(17);
			if (ok) 	 pPath->FindStartOfPath();
			if (ok) ok = pPath->InsertMoveTo( DocCoord(  -9000,      0));
			if (ok) ok = pPath->InsertLineTo( DocCoord(  -9000, -45000));
			if (ok) ok = pPath->InsertCurveTo(DocCoord(  -9000, -51708),
											  DocCoord(   2808, -56580),
											  DocCoord(   9000, -54000));
			if (ok) ok = pPath->InsertLineTo( DocCoord( 117000,  -9000));
			if (ok) ok = pPath->InsertCurveTo(DocCoord( 120916,  -7369),
											  DocCoord( 126000,  -4242),
											  DocCoord( 126000,      0));
			if (ok) ok = pPath->InsertCurveTo(DocCoord( 126000,   4242),
											  DocCoord( 120916,   7369),
											  DocCoord( 117000,   9000));
			if (ok) ok = pPath->InsertLineTo( DocCoord(   9000,  54000));
			if (ok) ok = pPath->InsertCurveTo(DocCoord(   2808,  56580),
											  DocCoord(  -9000,  51708),
											  DocCoord(  -9000,  45000));
			if (ok) ok = pPath->CloseSubPath();

			if (!ok)
			{
				delete pPath;
				return FALSE;
			}

			pPath->IsFilled  = TRUE;
			pPath->IsStroked = FALSE;

			ArrowShape 	= pPath;
			Centre 		= DocCoord(0,0);
			LineWidth 	= Width;
			ArrowWidth 	= INT32(Size);
			ArrowHeight = INT32(Size);
 			IsNull 		= FALSE;

			StartArrow = FALSE;

			break;
	

		case SA_SPOT:

			/*
			BLOB
			-54 0 m
			-54 29.807 -29.807 54 0 54 c
			29.807 54 54 29.807 54 0 c
			54 -29.807 29.807 -54 0 -54 c
			-29.807 -54 -54 -29.807 -54 0 c
			*/

			pPath = new Path();
			if (pPath == NULL)
				return FALSE;

			ok = pPath->Initialise(14);
			if (ok) 	 pPath->FindStartOfPath();
			if (ok) ok = pPath->InsertMoveTo( DocCoord( -54000,      0));
			if (ok) ok = pPath->InsertCurveTo(DocCoord( -54000,  29807),
											  DocCoord( -29807,  54000),
											  DocCoord(      0,  54000));
			if (ok) ok = pPath->InsertCurveTo(DocCoord(  29807,  54000),
											  DocCoord(  54000,  29807),
											  DocCoord(  54000,      0));
			if (ok) ok = pPath->InsertCurveTo(DocCoord(  54000, -29807),
											  DocCoord(  29807, -54000),
											  DocCoord(      0, -54000));
			if (ok) ok = pPath->InsertCurveTo(DocCoord( -29807, -54000),
											  DocCoord( -54000, -29807),
											  DocCoord( -54000,      0));
			if (ok) ok = pPath->CloseSubPath();

			if (!ok)
			{
				delete pPath;
				return FALSE;
			}

			pPath->IsFilled  = TRUE;
			pPath->IsStroked = FALSE;

			ArrowShape 	= pPath;
			Centre 		= DocCoord(0,0);
			LineWidth 	= Width;
			ArrowWidth 	= INT32(Size);
			ArrowHeight = INT32(Size);
 			IsNull 		= FALSE;

			StartArrow = TRUE;

			break;
	

		case SA_DIAMOND:

			/*
			DIAMOND
			-63 0 m
			0 63 l
			63 0 l
			0 -63 l
			-63 0 l
			*/

			pPath = new Path();
			if (pPath == NULL)
				return FALSE;

			ok = pPath->Initialise(5);
			if (ok) 	 pPath->FindStartOfPath();
			if (ok) ok = pPath->InsertMoveTo(DocCoord(-63000,      0));
			if (ok) ok = pPath->InsertLineTo(DocCoord(     0,  63000));
			if (ok) ok = pPath->InsertLineTo(DocCoord( 63000,      0));
			if (ok) ok = pPath->InsertLineTo(DocCoord(     0, -63000));
			if (ok) ok = pPath->CloseSubPath();

			if (!ok)
			{
				delete pPath;
				return FALSE;
			}

			pPath->IsFilled  = TRUE;
			pPath->IsStroked = FALSE;

			ArrowShape 	= pPath;
			Centre 		= DocCoord(0,0);
			LineWidth 	= Width;
			ArrowWidth 	= INT32(Size);
			ArrowHeight = INT32(Size);
 			IsNull 		= FALSE;

			StartArrow = TRUE;

			break;
	
		case SA_ARROWFEATHER:

			/*
			FEATHER
			18 -54 m
			108 -54 l
			63 0 l
			108 54 l
			18 54 l
			-36 0 l
			18 -54 l
			*/

			pPath = new Path();
			if (pPath == NULL)
				return FALSE;

			ok = pPath->Initialise(7);
			if (ok) 	 pPath->FindStartOfPath();
			if (ok) ok = pPath->InsertMoveTo(DocCoord( 18000, -54000));
			if (ok) ok = pPath->InsertLineTo(DocCoord(108000, -54000));
			if (ok) ok = pPath->InsertLineTo(DocCoord( 63000,      0));
			if (ok) ok = pPath->InsertLineTo(DocCoord(108000,  54000));
			if (ok) ok = pPath->InsertLineTo(DocCoord( 18000,  54000));
			if (ok) ok = pPath->InsertLineTo(DocCoord(-36000,      0));
			if (ok) ok = pPath->CloseSubPath();

			if (!ok)
			{
				delete pPath;
				return FALSE;
			}

			pPath->IsFilled  = TRUE;
			pPath->IsStroked = FALSE;

			ArrowShape 	= pPath;
			Centre 		= DocCoord(0,0);
			LineWidth 	= Width;
			ArrowWidth 	= INT32(Size);
			ArrowHeight = INT32(Size);
 			IsNull 		= FALSE;

			StartArrow = TRUE;

			break;
	
		case SA_ARROWFEATHER2:

			/*
			FEATHER3
			-35.998 0 m
			18 -54 l
			54 -54 l
			18 -18 l
			27 -18 l
			63 -54 l
			99 -54 l
			63 -18 l
			72 -18 l
			108 -54 l
			144 -54 l
			90 0 l
			144 54 l
			108 54 l
			72 18 l
			63 18 l
			99 54 l
			63 54 l
			27 18 l
			18 18 l
			54 54 l
			18 54 l
			-35.998 0 l
			*/

			pPath = new Path();
			if (pPath == NULL)
				return FALSE;

			ok = pPath->Initialise(23);
			if (ok) 	 pPath->FindStartOfPath();
			if (ok) ok = pPath->InsertMoveTo(DocCoord( -36000,      0));
			if (ok) ok = pPath->InsertLineTo(DocCoord(  18000, -54000));
			if (ok) ok = pPath->InsertLineTo(DocCoord(  54000, -54000));
			if (ok) ok = pPath->InsertLineTo(DocCoord(  18000, -18000));
			if (ok) ok = pPath->InsertLineTo(DocCoord(  27000, -18000));
			if (ok) ok = pPath->InsertLineTo(DocCoord(  63000, -54000));
			if (ok) ok = pPath->InsertLineTo(DocCoord(  99000, -54000));
			if (ok) ok = pPath->InsertLineTo(DocCoord(  63000, -18000));
			if (ok) ok = pPath->InsertLineTo(DocCoord(  72000, -18000));
			if (ok) ok = pPath->InsertLineTo(DocCoord( 108000, -54000));
			if (ok) ok = pPath->InsertLineTo(DocCoord( 144000, -54000));
			if (ok) ok = pPath->InsertLineTo(DocCoord(  90000,      0));
			if (ok) ok = pPath->InsertLineTo(DocCoord( 144000,  54000));
			if (ok) ok = pPath->InsertLineTo(DocCoord( 108000,  54000));
			if (ok) ok = pPath->InsertLineTo(DocCoord(  72000,  18000));
			if (ok) ok = pPath->InsertLineTo(DocCoord(  63000,  18000));
			if (ok) ok = pPath->InsertLineTo(DocCoord(  99000,  54000));
			if (ok) ok = pPath->InsertLineTo(DocCoord(  63000,  54000));
			if (ok) ok = pPath->InsertLineTo(DocCoord(  27000,  18000));
			if (ok) ok = pPath->InsertLineTo(DocCoord(  18000,  18000));
			if (ok) ok = pPath->InsertLineTo(DocCoord(  54000,  54000));
			if (ok) ok = pPath->InsertLineTo(DocCoord(  18000,  54000));
			if (ok) ok = pPath->CloseSubPath();

			if (!ok)
			{
				delete pPath;
				return FALSE;
			}

			pPath->IsFilled  = TRUE;
			pPath->IsStroked = FALSE;

			ArrowShape 	= pPath;
			Centre 		= DocCoord(0,0);
			LineWidth 	= Width;
			ArrowWidth 	= INT32(Size);
			ArrowHeight = INT32(Size);
 			IsNull 		= FALSE;

			StartArrow = TRUE;

			break;
	
		case SA_HOLLOWDIAMOND:

			/*
			HOLLOW
			0 45 m
			-45 0 l
			0 -45 l
			45 0 l
			0 45 l
			0 63 m
			-63 0 l
			0 -63 l
			63 0 l
			0 63 l
			*/

			pPath = new Path();
			if (pPath == NULL)
				return FALSE;

			ok = pPath->Initialise(10);
			if (ok) 	 pPath->FindStartOfPath();
			if (ok) ok = pPath->InsertMoveTo(DocCoord(     0,  45000));
			if (ok) ok = pPath->InsertLineTo(DocCoord(-45000,      0));
			if (ok) ok = pPath->InsertLineTo(DocCoord(     0, -45000));
			if (ok) ok = pPath->InsertLineTo(DocCoord( 45000,      0));
			if (ok) ok = pPath->CloseSubPath();
			if (ok) ok = pPath->InsertMoveTo(DocCoord(     0,  63000));
			if (ok) ok = pPath->InsertLineTo(DocCoord(-63000,      0));
			if (ok) ok = pPath->InsertLineTo(DocCoord(     0, -63000));
			if (ok) ok = pPath->InsertLineTo(DocCoord( 63000,      0));
			if (ok) ok = pPath->CloseSubPath();

			if (!ok)
			{
				delete pPath;
				return FALSE;
			}

			pPath->IsFilled  = TRUE;
			pPath->IsStroked = FALSE;

			ArrowShape 	= pPath;
			Centre 		= DocCoord(-45000,0);
			LineWidth 	= Width;
			ArrowWidth 	= INT32(Size);
			ArrowHeight = INT32(Size);
 			IsNull 		= FALSE;

			StartArrow = TRUE;

			break;

		default:
			ArrowShape 	= NULL;
			Centre 		= DocCoord(0,0);

			LineWidth	= DEFAULT_ARROW_LINEWIDTH;
			ArrowWidth	= 3;
			ArrowHeight	= 3;

			StartArrow 			= FALSE;
			ScaleWithLineWidth 	= TRUE;
			ArrowID 			= SA_NULLARROW;
 			IsNull 				= TRUE;
			break;
	}

	return TRUE;
}
Exemplo n.º 3
0
void RenderDemoDlg::RenderControl(ReDrawInfoType* ExtraInfo)
{
	// Go get a render region
	DocRect VirtualSize(-ExtraInfo->dx/2, -ExtraInfo->dy/2, ExtraInfo->dx/2, ExtraInfo->dy/2);
	RenderRegion* pRender = CreateGRenderRegion(&VirtualSize, ExtraInfo);
	if (pRender!=NULL)
	{
		DialogColourInfo RedrawColours;		// Get a supplier for default dlg colours

		// Render stuff in here
		// Build a Linear fill attribute
		LinearFillAttribute MyGradFill;
		MyGradFill.Colour = DocColour(255, 255, 0);
		MyGradFill.EndColour = DocColour(0, 255, 255);
		MyGradFill.StartPoint = DocCoord(0, ExtraInfo->dy);
		MyGradFill.EndPoint = DocCoord(ExtraInfo->dx, 0);

		// Build a path
		Path InkPath;
		InkPath.Initialise(12,12);
		InkPath.FindStartOfPath();

		// Get the coords used to build a shape
		INT32 dx = ExtraInfo->dx / 2;
		INT32 dy = ExtraInfo->dy / 2;
		INT32 Midx = ExtraInfo->dx / 4;
		INT32 Midy = ExtraInfo->dy / 4;

		// build a circle in the middle of the control
		InkPath.InsertMoveTo(DocCoord(Midx, dy));
		InkPath.InsertCurveTo(DocCoord(Midx+Midx/2, dy), DocCoord(dx, Midy+Midy/2), DocCoord(dx, Midy));
		InkPath.InsertCurveTo(DocCoord(dx, Midy-Midy/2), DocCoord(Midx+Midx/2, 0), DocCoord(Midx, 0));
		InkPath.InsertCurveTo(DocCoord(Midx-Midx/2, 0), DocCoord(0, Midy-Midy/2), DocCoord(0, Midy));
		InkPath.InsertCurveTo(DocCoord(0, Midy+Midy/2), DocCoord(Midx-Midx/2, dy), DocCoord(Midx, dy));
		InkPath.IsFilled = TRUE;
		
		// A Grey colour [...hmmm, it's not a very grey grey any more... oragnge more like]
		DocColour Grey(255,200,0);

		// Render the attributes and the a rectangle
		pRender->SaveContext();
		pRender->SetLineColour(Grey);

		// Draw a rectangle to fill in the background - Fill with Dialogue Background colour
		DocRect DrawMe(0, 0, ExtraInfo->dx, ExtraInfo->dy);
		pRender->SetFillColour(RedrawColours.DialogBack());
		pRender->DrawRect(&VirtualSize);

		// Draw some shapes and stuff
		pRender->SetFillGeometry(&MyGradFill, FALSE);
		pRender->DrawPath(&InkPath);

		// Build a path
		Path TriPath;
		TriPath.Initialise(12,12);
		TriPath.FindStartOfPath();

		// build a circle in the middle of the control
		TriPath.InsertMoveTo(VirtualSize.lo);
		TriPath.InsertLineTo(DocCoord(VirtualSize.hi.x, VirtualSize.lo.y));
		TriPath.InsertLineTo(DocCoord(0, VirtualSize.hi.y));
		TriPath.InsertLineTo(VirtualSize.lo);
		TriPath.IsFilled = TRUE;

		LinearFillAttribute MyTriFill;
		MyTriFill.Colour = ShowFirst ? First : Second;
		MyTriFill.EndColour = DocColour(0,0,0);
		MyTriFill.StartPoint = DocCoord(ExtraInfo->dx, 0);
		MyTriFill.EndPoint = DocCoord(0, ExtraInfo->dy);

		pRender->SetFillGeometry(&MyTriFill, FALSE);
		pRender->DrawPath(&TriPath);

		pRender->RestoreContext();

		// Get rid of the render region
		DestroyGRenderRegion(pRender);
	}

	// and animate it!
	if (ShowFirst)
	{
		INT32 Red, Green, Blue;
		First.GetRGBValue(&Red, &Green, &Blue);

		if (Blue>0)
		{
			// Set the colour back again
			Blue -= 10;
			First.SetRGBValue(Red, Green, Blue);

			// redraw it
			InvalidateGadget(_R(IDC_REDRAW_ME));
		}
	}
	else
	{
		// Set the colour back to how it was
		First.SetRGBValue(255, 0, 250);
	}
}