Example #1
0
static
void fill_routine(int n, double *px, double *py, int tnr)
{
  PolyHandle poly;
  register int i;
  double x, y;
  int ix, iy;

  poly = OpenPoly();
  for (i = 0; i < n; i++)
  {
    WC_to_NDC(px[i], py[i], tnr, x, y);
    seg_xform(&x, &y);
    NDC_to_DC(x, y, ix, iy);

    if (i == 0)
      MoveTo(ix, iy);
    else
      LineTo(ix, iy);
  }
  ClosePoly();
  if (p->pat)
    FillPoly(poly, p->pat);
  else
    PaintPoly(poly);
  KillPoly(poly);
}
Example #2
0
void 
PF_FillPoly(PF_InData		*in_data,
			PF_ContextH		contextH,
			PolyHandle		poly)

{
#ifdef AE_OS_WIN
	HDC	hdc;
	HBRUSH Brush = GetStockObject(WHITE_BRUSH);
	PF_GET_CGRAF_DATA((*contextH)->cgrafptr, PF_CGrafData_HDC, &hdc);
	FillRgn(hdc, (HRGN)*poly, Brush);
#else
	FillPoly(poly, &in_data->qd_globals->gray);
#endif
}
Example #3
0
void DrawNoSectPolyRecursive (CMap *theMap, PolyObjectHdl MapPolyHdl, DrawSpecRecPtr drawSettings,Rect subRect)
{
	long			PointCount, PlotCount = 0, PointIndex;
	LongPoint		MatrixPt;
	Point			LastScrPt, ThisScrPt, FirstScrPt;
	LongPoint		**RgnPtsHdl;
	PolyHandle		PolyHdl = nil;
	
	////////////
	Boolean  alwaysIn123 = true;
	Boolean  alwaysIn174 = true;
	Boolean  alwaysIn456 = true;
	Boolean  alwaysIn386 = true;
	Boolean canSkipDrawingPolygon = false;
	//    1 7 4
	//    2 0 5
	//    3 8 6
	////////////////

	PointCount = GetPolyPointCount (MapPolyHdl);
	RgnPtsHdl = GetPolyPointsHdl (MapPolyHdl);
	Boolean bDrawBlackAndWhite = (sharedPrinting && settings.printMode != COLORMODE);

	#define MAXNUMSEGMENTS  8000 // JLM, It seems the limit is 32K not 64K at the documentation says
	short thisSectionOfPlane,prevSectionOfPlane;
	Boolean canSkipThisPt,skippedAPt,offQuickDrawPlane=false;
	Point lastSkippedPt;
	Rect  fuzzyRect = subRect;
	long lineWidth = 1, esiCode;
	long outsetPixels = 2*lineWidth+2; // needs to be wider that the line width
	//long penWidth = 3;
	long penWidth = 2;
	long halfPenWidth = 0;
	InsetRect(&fuzzyRect,-outsetPixels,-outsetPixels);

	if (RgnPtsHdl != nil)
	{

		// must clip to this rect in addtion to the original clip
		Rect clippingRect = subRect;
		RgnHandle saveClip = NewRgn(), addition = NewRgn() , newClip = NewRgn();

		GetClip(saveClip);
		GetClip(newClip);
		RectRgn(addition, &clippingRect);
		SectRgn(newClip, addition, newClip);
		SetClip(newClip);
		if(newClip) DisposeRgn(newClip);
		if(addition) DisposeRgn(addition);


		if (drawSettings -> fillCode != kNoFillCode)
			PolyHdl = OpenPoly ();
		else
		{
			PolyHdl = OpenPoly ();
			//Our_PmForeColor (gDrawBitmapInBlackAndWhite ? kBlackColorInd : drawSettings -> foreColorInd);
			Our_PmForeColor (drawSettings -> foreColorInd);
		}

		GetObjectESICode ((ObjectRecHdl) MapPolyHdl,&esiCode); 
		if (esiCode>0) 	// -500 is the default
		{
			//halfPenWidth = penWidth/2;
#ifdef MAC
			PenSize(penWidth,penWidth);
#else
			PenStyle(BLACK,penWidth);
#endif
		}
		for (PointIndex = 0,skippedAPt = false,prevSectionOfPlane = -1; PointIndex < PointCount; ++PointIndex)
		{
			MatrixPt = (*RgnPtsHdl) [PointIndex];
//			theMap -> GetScrPoint (&MatrixPt, &ThisScrPt);

			//ThisScrPt.h = SameDifferenceX(MatrixPt.h);
			//ThisScrPt.v = (gRect.bottom + gRect.top) - SameDifferenceY(MatrixPt.v);
			ThisScrPt = GetQuickDrawPt(MatrixPt.h, MatrixPt.v, &gRect, &offQuickDrawPlane);

			// code goes here, what to do when point is off quickdraw plane?
			//if (offQuickDrawPlane) break;
			
			ThisScrPt.h += drawSettings -> offsetDx;
			ThisScrPt.v += drawSettings -> offsetDy;
			
			if(PolyHdl)
			{  //// JLM 2/18/99
				// for points outside the drawing area, it is not necessary to move to the correct point,
				// as long as we preserve the winding.  This allows us to ignore many of the points outside 
				// the drawing rectangle gRect
				thisSectionOfPlane = SectionOfPlane(&fuzzyRect,ThisScrPt);
				if( 	thisSectionOfPlane > 0 // outside of the rectangle
						&& thisSectionOfPlane == prevSectionOfPlane // we have not changed sections of the plane
						&& PointIndex < PointCount -1) // not the last point
					canSkipThisPt = true;
				else canSkipThisPt = false;
				prevSectionOfPlane = thisSectionOfPlane;
				if(canSkipThisPt) 
				{
					skippedAPt = true;
					lastSkippedPt =ThisScrPt;
					continue;
				}
				/// JLM 3/6/01
				switch(thisSectionOfPlane) {
					case 1: 															alwaysIn456 = false; alwaysIn386 = false; break;
					case 2: 								alwaysIn174 = false; alwaysIn456 = false; alwaysIn386 = false; break;
					case 3: 								alwaysIn174 = false; alwaysIn456 = false; 							break;
					case 4:	alwaysIn123 = false; 														alwaysIn386 = false; break;
					case 5:	alwaysIn123 = false;	alwaysIn174 = false; 							alwaysIn386 = false; break;
					case 6:	alwaysIn123 = false;	alwaysIn174 = false; 														break;
					case 7:	alwaysIn123 = false;								alwaysIn456 = false; alwaysIn386 = false; break;
					case 8:	alwaysIn123 = false;	alwaysIn174 = false; alwaysIn456 = false; 							break;
					default: alwaysIn123 = false;	alwaysIn174 = false; alwaysIn456 = false; alwaysIn386 = false; break;
				}
				//////
				if(skippedAPt)
				{	// then we have to draw to the previous point 
					// before we draw to the current point 
					PointIndex--; //so we do the previous point below
					ThisScrPt = lastSkippedPt; // restore the coordinates of the previous point
					prevSectionOfPlane = -1; // force the next point to not be skipped
				}
				skippedAPt = false;
				if(PlotCount > MAXNUMSEGMENTS)
				{	// there is a bug on the max when the number of points gets too large
					// try recusion
					ClosePoly();
					KillPoly(PolyHdl);
					SetClip(saveClip);// JLM 8/4/99
					goto recursion;
				}
				//////////////
			}


			if (PointIndex == 0)
			{
				MyMoveTo (ThisScrPt.h-halfPenWidth, ThisScrPt.v-halfPenWidth);
				FirstScrPt = ThisScrPt;
				LastScrPt = ThisScrPt;
				PlotCount = 0;
			}
			else
			{
				if (LastScrPt.h != ThisScrPt.h || LastScrPt.v != ThisScrPt.v)
				{
					MyLineTo (ThisScrPt.h-halfPenWidth, ThisScrPt.v-halfPenWidth);
					LastScrPt = ThisScrPt;
					++PlotCount;
				}
			}
		}

		if (drawSettings -> bClosed)	/* draw a line from last point to first point if requested */
		{
			MyLineTo (FirstScrPt.h-halfPenWidth, FirstScrPt.v-halfPenWidth);
			++PlotCount;
		}

		if (PolyHdl != nil)
		{
			ClosePoly ();
			////////////// JLM 3/6/01
			if(alwaysIn123 || alwaysIn174 || alwaysIn456 || alwaysIn386)
				canSkipDrawingPolygon = true;
			if(canSkipDrawingPolygon) PlotCount = 0; // so that we skip the code below
			////////////
			if (PlotCount > 0)
			{
				if (PlotCount > 2)			/* polygon must contain more than 2 line-to points */
				{
					if (drawSettings -> bErase || (drawSettings -> fillCode == kNoFillCode && drawSettings -> backColorInd == kWaterColorInd))
						ErasePoly (PolyHdl);
	
					if (drawSettings -> fillCode == kPaintFillCode)
					{
						// this is the usual drawing code
						Our_PmForeColor (bDrawBlackAndWhite || gDrawBitmapInBlackAndWhite ? kBlackColorInd : drawSettings -> foreColorInd);//JLM
						if(bDrawBlackAndWhite) SetPenPat(UPSTRIPES);
						PaintPoly(PolyHdl);//JLM
						if(bDrawBlackAndWhite) SetPenPat(BLACK);
					}
					else if (drawSettings -> fillCode == kPatFillCode)
						FillPoly (PolyHdl, &(drawSettings -> backPattern));
				}

				if (drawSettings -> frameCode == kPaintFrameCode)
				{
					Our_PmForeColor (bDrawBlackAndWhite || gDrawBitmapInBlackAndWhite ? kBlackColorInd : drawSettings -> foreColorInd);
					FramePoly (PolyHdl);
				}
				else if (drawSettings -> frameCode == kPatFrameCode)
				{
					PenPat (&(drawSettings -> forePattern));
					FramePoly (PolyHdl);
				}
			}
			
			KillPoly (PolyHdl);
		}
		
		SetClip(saveClip);
		if(saveClip) DisposeRgn(saveClip);

	}

#ifdef MAC
	PenSize(1,1);
#else
	PenStyle(BLACK,1);
#endif
	return;
	
	////////////////////////////////
recursion:
	////////////////////////////////
	{
		#define MAXRECURSION 20 
		static short sRecursionValue = 0;
	
		if(sRecursionValue >= MAXRECURSION) 
		{
			printError("max recusion exceeded");
		}
		else
		{
			// use recursion
			Rect subBoundingRect;
			long middleH = (subRect.left+subRect.right)/2;
			long middleV = (subRect.top+subRect.bottom)/2;
			long index;
			
			sRecursionValue++;
		
			// divide the points up and Draw again
			for(index = 0; index < 4; index++)
			{
				subBoundingRect = subRect;
				switch(index)
				{
					case 0: 
						subBoundingRect.top  = middleV;
						subBoundingRect.left  = middleH;
						break;
					case 1: 
						subBoundingRect.top  = middleV;
						subBoundingRect.right  = middleH;
						break;
					case 2: 
						subBoundingRect.bottom  = middleV;
						subBoundingRect.left  = middleH;
						break;
					default: 
						subBoundingRect.bottom  = middleV;
						subBoundingRect.right  = middleH;
						break;
				}
				
				// the recursive call
				DrawNoSectPolyRecursive (theMap,MapPolyHdl,drawSettings,subBoundingRect);
				
			}
			// all done
			sRecursionValue--;
			return;
		}
	}
	
}
Example #4
0
OSErr DrawSectPoly (CMap* theMap, PolyObjectHdl MapPolyHdl, DrawSpecRecPtr drawSettings)
{
	long			SegCount, SegIndex, SegIndexPlus, PlotCount;
	LongPoint		MatrixPt;
	Point			ThisScrPt;
	OSErr			ErrCode = 0;
	Boolean			DrawFromSegFlag;
	PolyHandle		PolyHdl = nil;
	SegmentsHdl		SectSegHdl = nil;
	LongRect		sectLRect;
	Rect			ScrPolyRect;
	
	theMap -> GetMapDrawRect (&ScrPolyRect);
	InsetRect (&ScrPolyRect, -1, -1);
	theMap -> GetMatrixLRect (&ScrPolyRect, &sectLRect);

	SectSegHdl = MakeSectPoly (&sectLRect, MapPolyHdl);
	if (SectSegHdl != nil)
	{
		SegCount = _GetHandleSize ((Handle) SectSegHdl) / sizeof (Segment);

		PolyHdl = OpenPoly ();
			
		DrawFromSegFlag = true;
		PlotCount = 0;
		Boolean bDrawBlackAndWhite = (sharedPrinting && settings.printMode != COLORMODE);
		
		for (SegIndex = 0; SegIndex < SegCount; ++SegIndex)
		{
			if (DrawFromSegFlag)	/* start of new poly */
			{
				MatrixPt.h = (*SectSegHdl) [SegIndex].fromLong;
				MatrixPt.v = (*SectSegHdl) [SegIndex].fromLat;
				theMap -> GetScrPoint (&MatrixPt, &ThisScrPt);
				MyMoveTo (ThisScrPt.h, ThisScrPt.v);
				DrawFromSegFlag = false;
				PlotCount = 0;
			}
			
			MatrixPt.h = (*SectSegHdl) [SegIndex].toLong;
			MatrixPt.v = (*SectSegHdl) [SegIndex].toLat;
			theMap -> GetScrPoint (&MatrixPt, &ThisScrPt);
			MyLineTo (ThisScrPt.h, ThisScrPt.v);
			++PlotCount;

			SegIndexPlus = SegIndex + 1;
			if (SegIndexPlus == SegCount)
				SegIndexPlus = 0;
			
			/* check for end of current poly */
			if (((*SectSegHdl) [SegIndex].toLat  != (*SectSegHdl) [SegIndexPlus].fromLat ||
				 (*SectSegHdl) [SegIndex].toLong != (*SectSegHdl) [SegIndexPlus].fromLong))
			{
				ClosePoly ();
				
				if (PlotCount > 0)
				{
					if (PlotCount > 2)
					{
						if (drawSettings -> bErase)
							ErasePoly (PolyHdl);
		
						if (drawSettings -> fillCode == kPaintFillCode)
						{
							// this is the usual drawing code
							Our_PmForeColor (bDrawBlackAndWhite || gDrawBitmapInBlackAndWhite ? kBlackColorInd : drawSettings -> foreColorInd);//JLM
							if(bDrawBlackAndWhite) SetPenPat(UPSTRIPES);
							PaintPoly(PolyHdl);//JLM
							if(bDrawBlackAndWhite) SetPenPat(BLACK);
						}
						else if (drawSettings -> fillCode == kPatFillCode)
							FillPoly (PolyHdl, &(drawSettings -> backPattern));
					}
				
					if (drawSettings -> frameCode == kPaintFrameCode)
					{
						Our_PmForeColor (bDrawBlackAndWhite || gDrawBitmapInBlackAndWhite ? kBlackColorInd : drawSettings -> foreColorInd);
						FramePoly (PolyHdl);
					}
					else if (drawSettings -> frameCode == kPatFrameCode)
					{
						PenPat (&(drawSettings -> forePattern));
						FramePoly (PolyHdl);
					}
				}

				KillPoly (PolyHdl);

				/* now open a new poly for the next set of segments */
				PolyHdl = OpenPoly ();
				
				DrawFromSegFlag = true;
			}
		}

		ClosePoly ();

		if (PlotCount > 0)
		{
			if (PlotCount > 2)		/* must have at least 3 segments to fill-poly */
			{
				if (drawSettings -> bErase)
					ErasePoly (PolyHdl);

				if (drawSettings -> fillCode == kPaintFillCode)
				{
					Our_PmForeColor (drawSettings -> backColorInd);
					FillPoly (PolyHdl, &(drawSettings -> backPattern));
				}
				else if (drawSettings -> fillCode == kPatFillCode)
					FillPoly (PolyHdl, &(drawSettings -> backPattern));
			}

			if (drawSettings -> frameCode == kPaintFrameCode)
			{
				Our_PmForeColor (drawSettings -> foreColorInd);
				FramePoly (PolyHdl);
			}
			else if (drawSettings -> frameCode == kPatFrameCode)
			{
				PenPat (&(drawSettings -> forePattern));
				FramePoly (PolyHdl);
			}
		}

		KillPoly (PolyHdl);

		DisposeHandle ((Handle) SectSegHdl);
	}

	return (ErrCode);
}
void
ComboBox::Draw()
{
	int x = 0;
	int y = 0;
	int w = rect.w;
	int h = rect.h;

	if (w < 1 || h < 1 || !shown)
	return;

	Rect btn_rect(x,y,w,h);

	// draw the bevel:
	DrawRectSimple(btn_rect, button_state);

	// draw the border:
	if (border)
	DrawRect(0,0,w-1,h-1,border_color);

	// draw the arrow:
	POINT arrow[3];
	double h3 = (double)h/3.0;

	arrow[0].x = (int) (w-2*h3);
	arrow[0].y = (int) (h3);
	arrow[1].x = (int) (w-h3);
	arrow[1].y = (int) (h3);
	arrow[2].x = (int) ((arrow[1].x + arrow[0].x)/2);
	arrow[2].y = (int) (2*h3);

	FillPoly(3, arrow, border_color);

	// draw text here:
	Text caption = text;
	if (GetSelectedIndex() >= 0)
	caption = GetSelectedItem();

	if (font && caption.length()) {
		int border_size = 4;

		if (style & WIN_RAISED_FRAME && style & WIN_SUNK_FRAME)
		border_size = 8;

		Rect label_rect = CalcLabelRect();
		int  vert_space = label_rect.h;
		int  horz_space = label_rect.w;

		DrawText(caption.data(), 0, label_rect, DT_CALCRECT | DT_WORDBREAK | text_align);
		vert_space = (vert_space - label_rect.h)/2;
		
		label_rect.w = horz_space;

		if (vert_space > 0)
		label_rect.y += vert_space;

		if (animated && button_state > 0) {
			label_rect.x += button_state;
			label_rect.y += button_state;
		}

		font->SetColor(fore_color);
		DrawText(caption.data(), 0, label_rect, DT_WORDBREAK | text_align);
	}
}
void R004PseudoTexture::Render()
{
	m_viewport->Clear();
	MatrixStack mstackvertices;
	MatrixStack mstacknormals;

	// TODO: sort meshes

	mstackvertices.PushMatrix(m_camera->m_projectionmatrix);
	mstackvertices.PushMatrix(m_camera->m_viewmatrix);
	mstacknormals.PushMatrix(m_camera->m_viewmatrix);

	for (int i=0 ; i<m_scene->m_meshCount ; i++)
	{
		Mesh *mesh = m_scene->m_meshes[i];
		//mstackvertices.PushMatrix(mesh->m_worldmatrix);
		//mstacknormals.PushMatrix(mesh->m_worldmatrix);

		// Transforming vertices into screen coords
		Vec3f *vertices = new Vec3f[mesh->m_vertexcount];
		for (unsigned int v=0 ; v<mesh->m_vertexcount ; v++)
		{
			Vec3f vec = mesh->m_vertexbuffer[v];			
			vec = vec * mstackvertices.GetTopMatrix();
			vec.x = vec.x / ( (vec.z>0) ? (vec.z) : (-vec.z) );
			vec.y = vec.y / ( (vec.z>0) ? (vec.z) : (-vec.z) );
			vec = vec * m_viewport->m_viewportmatrix;
			vertices[v] = vec;
		}

		// Reading index buffer and drawing lines
		for (unsigned int s=0 ; s<mesh->m_stripcount ; s++)
		{
			Strip *strip = mesh->m_strips[s];
			Vec3f v0,v1,v2;
			v0 = vertices[strip->m_indexbuffer[0]];
			v1 = vertices[strip->m_indexbuffer[1]];
			for (unsigned i=2 ; i<strip->m_indexcount ; i++)
			{
				v2 = vertices[strip->m_indexbuffer[i]];
	
				// backface culling
				Vec3f cullingnormal = ((v1-v0).Cross((v2-v0)));
				if (cullingnormal.z < 0) // TODO dotproduct with camera ?
				{
					// Calculate flat shading
					Vec3f normal = (mesh->m_vertexbuffer[strip->m_indexbuffer[i]]-mesh->m_vertexbuffer[strip->m_indexbuffer[0]])
									.Cross(mesh->m_vertexbuffer[strip->m_indexbuffer[i-1]]-mesh->m_vertexbuffer[strip->m_indexbuffer[0]]);
					normal = normal.Mul3x3(mstacknormals.GetTopMatrix());
					normal.Normalize();
					Vec3f frontvec;
					frontvec.z = 1;
					float normaldotproduct = normal.Dot(frontvec);
					if (normaldotproduct > 0) normaldotproduct = 0;
					unsigned char shade = (unsigned char) ((normaldotproduct * (-200.0f)) + 55.0f);

					// Fill poly
					FillPoly(v0, v1, v2, shade);
				}

				v1 = v2;
			}
		}
		//mstack.PopMatrix(); // Remove world matrix (the mesh one)
		delete vertices;
	}
}