Пример #1
0
ThreeDimension::ThreeDimension(){
	frontside = Polygon();
	backside = Polygon();
}
Пример #2
0
void Triangle (HDC hdc, POINT pt[])
{
     SelectObject (hdc, GetStockObject (BLACK_BRUSH)) ;
     Polygon (hdc, pt, 3) ;
     SelectObject (hdc, GetStockObject (WHITE_BRUSH)) ;
}
Пример #3
0
static LRESULT APIENTRY LevelControlWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
	LevelControlData *lcd = (LevelControlData *)GetWindowLongPtr(hwnd, 0);

	switch(msg) {

	case WM_NCCREATE:
		if (!(lcd = new LevelControlData))
			return FALSE;
		memset(lcd,0,sizeof(LevelControlData));

		lcd->nTabs		= 3;
		lcd->iPos[0]	= 0;
		lcd->rgbTab[0]	= 0xFFFFFF;
		lcd->rgbLow		= 0x000000;
		lcd->rgbHigh	= 0xFFFFFF;
		lcd->iMovingTab	= -1;

		SetWindowLongPtr(hwnd, 0, (LONG_PTR)lcd);
		return TRUE;

	case WM_CREATE:
	case WM_SIZE:
		LevelControlResize(hwnd, lcd);
		break;

	case WM_DESTROY:
		delete lcd;
		SetWindowLongPtr(hwnd, 0, 0);
		break;

	case WM_PAINT:
		{
			PAINTSTRUCT ps;
			HDC hdc;
			int i, x, w, h;
			RECT r;

			hdc = BeginPaint(hwnd, &ps);

			w = lcd->w;
			h = lcd->rColorBand.bottom - lcd->rColorBand.top;

			if (RectVisible(hdc, &lcd->rColorBand)) {
				int dr, dg, db;
				int xlo, xhi;
				RECT rClip;

				dr = (signed long)(lcd->rgbHigh&0xff) - (signed long)(lcd->rgbLow&0xff);
				dg = ((signed long)(lcd->rgbHigh&0xff00) - (signed long)(lcd->rgbLow&0xff00))>>8;
				db = ((signed long)(lcd->rgbHigh&0xff0000) - (signed long)(lcd->rgbLow&0xff0000))>>16;

				r = lcd->rColorBand;
				xlo = 0;
				xhi = w;

				i = GetClipBox(hdc, &rClip);

				if (i!=ERROR && i!=NULLREGION) {
					RECT rClip2;

					IntersectRect(&rClip2, &r, &rClip);

					xlo = rClip2.left - r.left;
					xhi = rClip2.right - r.left;
				}

				for(x=xlo; x<xhi; x++) {
					HBRUSH hbr;
					COLORREF cr;

					r.left = lcd->rColorBand.left + x;
					r.right = r.left+1;

					cr	= lcd->rgbLow
						+  ((dr*x + w/2)/w)
						+ (((dg*x + w/2)/w) << 8)
						+ (((db*x + w/2)/w) << 16);

					if (hbr = CreateSolidBrush(cr)) {
						FillRect(hdc, &r, hbr);
						DeleteObject(hbr);
					}
				}
			}

			for(i=0; i<lcd->nTabs; i++) {
				POINT pt[3];
				HBRUSH hbr;
				HGDIOBJ hgoOld;

				pt[0].x = lcd->iPixPos[i];
				pt[1].x = lcd->iPixPos[i]+lcd->iTabW;
				pt[2].x = lcd->iPixPos[i]+2*lcd->iTabW;
				pt[0].y = pt[2].y = lcd->rColorBand.bottom+lcd->iTabH-1;
				pt[1].y = lcd->rColorBand.bottom;

				if (hbr = CreateSolidBrush(lcd->rgbTab[i]))
					hgoOld = SelectObject(hdc, hbr);

				Polygon(hdc, pt, 3);

				if (hbr)
					DeleteObject(SelectObject(hdc, hgoOld));
			}

			EndPaint(hwnd, &ps);
		}
		break;

	case WM_LBUTTONDOWN:
		{
			int x = LOWORD(lParam);
			int y = HIWORD(lParam);

			if (y >= lcd->rColorBand.bottom && y<lcd->rColorBand.bottom+lcd->iTabH) {
				int i;
				int best_tab = -1, best_dx = 100;

				for(i=0; i<lcd->nTabs; i++) {
					int dx = (x-lcd->iTabW) - lcd->iPixPos[i];
					int adx = abs(dx);

					// Pick the closest tab to cursor; if tabs are on the same
					// position, pick the lowest tab if mouse is to the left and
					// the highest tab if mouse is to the right

					if (adx < 8 && (best_tab == -1 || adx < best_dx ||
						(adx == best_dx && dx>0))) {

						best_dx = adx;
						best_tab = i;
					}

				}
				if (best_tab >= 0) {
					SetCapture(hwnd);
					lcd->iMovingTab = best_tab;
					lcd->iMovingOffset = x - lcd->iPixPos[best_tab];
				}
			}
		}
		break;

	case WM_LBUTTONUP:
		if (lcd->iMovingTab>=0) {
			ReleaseCapture();
			lcd->iMovingTab = -1;
		}
		break;

	case WM_MOUSEMOVE:
		if (lcd->iMovingTab>=0) {
			int pos, pixpos;
			RECT r;

			pixpos = (int)(signed short)LOWORD(lParam) - lcd->iMovingOffset;
			pos = LevelPixelToRatio(pixpos, lcd->w);

			// clip position against spectrum

			if (pixpos<0) {
				pos = 0;
				pixpos = 0;
			} else if (pixpos >= lcd->rColorBand.right - lcd->rColorBand.left) {
				pixpos = lcd->rColorBand.right - lcd->rColorBand.left - 1;
				pos = 0xFFFF;
			}

			// don't let tabs pass each other

			if (lcd->iMovingTab>0 && pos < lcd->iPos[lcd->iMovingTab-1]) {
				pos = lcd->iPos[lcd->iMovingTab-1];
				pixpos = lcd->iPixPos[lcd->iMovingTab-1];
			} else if (lcd->iMovingTab < lcd->nTabs-1 && pos > lcd->iPos[lcd->iMovingTab+1]) {
				pos = lcd->iPos[lcd->iMovingTab+1];
				pixpos = lcd->iPixPos[lcd->iMovingTab+1];
			}

			// render changes

			r.left = lcd->iPixPos[lcd->iMovingTab];
			r.right = lcd->iPixPos[lcd->iMovingTab]+2*lcd->iTabW+1;
			r.top = lcd->rColorBand.bottom;
			r.bottom = r.top + lcd->iTabH;

			InvalidateRect(hwnd, &r, TRUE);

			lcd->iPos[lcd->iMovingTab] = pos;
			lcd->iPixPos[lcd->iMovingTab] = pixpos;

			r.left = pixpos;
			r.right = pixpos+2*lcd->iTabW+1;

			InvalidateRect(hwnd, &r, TRUE);

			UpdateWindow(hwnd);

			// send notification message to parent window

			NMVLTABCHANGE nmvltc;

			nmvltc.hdr.code		= VLCN_TABCHANGE;
			nmvltc.hdr.hwndFrom	= hwnd;
			nmvltc.hdr.idFrom	= GetWindowLong(hwnd, GWL_ID);
			nmvltc.iTab			= lcd->iMovingTab;
			nmvltc.iNewPos		= pos;

			SendMessage(GetParent(hwnd), WM_NOTIFY, nmvltc.hdr.idFrom, (LPARAM)&nmvltc);
		}
		break;

	case VLCM_SETTABCOUNT:
		lcd->nTabs = lParam;
		if (wParam)
			InvalidateRect(hwnd, &lcd->rTabBand, TRUE);
		break;

	case VLCM_SETTABCOLOR:
		lcd->rgbTab[LOWORD(wParam)] = lParam;
		if (HIWORD(wParam))
			InvalidateRect(hwnd, &lcd->rTabBand, TRUE);
		break;

	case VLCM_MOVETABPOS:
	case VLCM_SETTABPOS:
		lcd->iPos[LOWORD(wParam)] = lParam;
		lcd->iPixPos[LOWORD(wParam)] = LevelRatioToPixel(lParam, lcd->w);
		if (HIWORD(wParam))
			InvalidateRect(hwnd, &lcd->rTabBand, TRUE);

		if (msg == VLCM_MOVETABPOS) {
			NMVLTABCHANGE nmvltc;

			nmvltc.hdr.code		= VLCN_TABCHANGE;
			nmvltc.hdr.hwndFrom	= hwnd;
			nmvltc.hdr.idFrom	= GetWindowLong(hwnd, GWL_ID);
			nmvltc.iTab			= LOWORD(wParam);
			nmvltc.iNewPos		= lParam;

			SendMessage(GetParent(hwnd), WM_NOTIFY, nmvltc.hdr.idFrom, (LPARAM)&nmvltc);
		}
		break;

	case VLCM_SETGRADIENT:
		lcd->rgbLow = wParam;
		lcd->rgbHigh = lParam;
		InvalidateRect(hwnd, &lcd->rColorBand, FALSE);
		break;

	default:
		return DefWindowProc(hwnd, msg, wParam, lParam);
	}
Пример #4
0
void Scene::GouraudFacet (Facet& f)
//
// Draws a facet using Gourauds's color interpolation model.
// A scan line approach is taken for drawing this facet.
//
// Uses the global intermediate storage array pix.
//
// If outline == True then the facet ist outlined using the 
// current line drawing color.
//
{
    float rstep,gstep,bstep,rr,gg,bb;
    long /*previous_color,*/ color;
    int maxy,miny,maxx,minx,k,mono;    
    Pixel2D p;
 
    // number of vertices
    int n = f.GetNumVertices();
    
    // facet is degenerate or has too many facets
    if (n < 3 || n > MaxVertices) return;

    Material *Mp;
    static Material M;
    if (coloring == PerVertex) {
        if (f.material) {
	    M.ambient = f.material->ambient;
	    M.specular = f.material->specular;
	    M.exponent = f.material->exponent;
	} else {
	    M.ambient = mat.ambient;
	    M.specular = mat.specular;
	    M.exponent = mat.exponent;
	}
	Mp = &M;
    } else if (coloring == Global) {
	Mp = f.GetMaterial();
    } else /* (coloring == PerFacet) */ {
	M.color   = f.front;
	if (f.material) {
	    M.ambient = f.material->ambient;
	    M.specular = f.material->specular;
	    M.exponent = f.material->exponent;
	} else {
	    M.ambient = mat.ambient;
	    M.specular = mat.specular;
	    M.exponent = mat.exponent;
	}
	Mp = &M;
    } 


    // remember previous line color
    //previous_color = linecolor;
    ColorF previous_color = foreground_color;

    maxy = miny = f[0].p.py;
    for (int i = 0; i < n; i++) {
	const Vertex& Vi = f[i];
      
        // copy projected vertex coordinates to polygon array
        pix[i] = Vi.p;

        // find minimum and maximum y-value
	if (pix[i].py > maxy) 
	    maxy = pix[i].py;
        else if (pix[i].py < miny) 
	    miny = pix[i].py;

        // get color at each vertex (vertex color + illumination effect)
	if (coloring == PerVertex) {
	    M.color.red   = float(Vi.red) / 255;
	    M.color.green = float(Vi.green) / 255;
	    M.color.blue  = float(Vi.blue) / 255;
	}
	PhongColor(Vi.x,Vi.y,Vi.z, Vi.nx,Vi.ny,Vi.nz,
		   Mp,r[i],g[i],b[i]);
    }
    
    // special case of a black/and white display
    if (displaymono) {        
	Polygon(n,pix,White,Fill);	// draw a white background polyogon
	SetColor(Black);	// set foreground color to black for the dots
    }
 
    // fill facet using a scan line approach  
    // loop through the scanlines
    // --------------------------

    for ( p.py = miny; p.py <= maxy; (p.py)++ ) {
	
        // polygon is wider than 30000 pixel
	minx =  30000; maxx = -30000;

	int imin = 0, imax = 0;
	for (int i = 0, j = n-1; i < n; j = i++) {
	    
	    int pjy = pix[j].py,
		piy = pix[i].py;
 
	    if ((pjy != piy) && 
	        (pjy >= p.py || piy >= p.py) &&
	        (pjy <= p.py || piy <= p.py)) { 
		
		float mu = float(p.py-pjy)/float(piy-pjy),
		      mu1 = 1.0-mu;
		k = int(mu1*pix[j].px+mu*pix[i].px+0.5);
		if (k < minx) {
		    minx = k; // minimum x
		    imin = i;
		} 
		if (k > maxx) {
		    maxx = k; // maximum x
		    imax = i;
		}
	    }
	}
   
	{
	    int i = imin, j = i ? i-1 : n-1, 
	        dpy = pix[i].py-pix[j].py;
	    float mu = dpy ? float(p.py-pix[j].py)/float(dpy) : 0,
	          mu1 = 1.0-mu;
	    // minimum values
	    rr = mu1 * r[j] + mu * r[i];
	    gg = mu1 * g[j] + mu * g[i];
	    bb = mu1 * b[j] + mu * b[i];
	}

	if (minx < maxx) {    
	    int i = imax, j = i ? i-1 : n-1, 
	        dpy = pix[i].py-pix[j].py;
	    float mu = dpy ? float(p.py-pix[j].py)/float(dpy) : 0, 
	          mu1 = 1.0-mu;
	    // steps
	    float dx = float(maxx-minx);
	    rstep = (mu1 * r[j] + mu * r[i] - rr)/dx;
	    gstep = (mu1 * g[j] + mu * g[i] - gg)/dx;
	    bstep = (mu1 * b[j] + mu * b[i] - bb)/dx;

	} else 
	    rstep = gstep = bstep = 0;


	if (displaymono) {           // for a monochrome display - ditherized

	    for (p.px = minx; p.px <= maxx; ++(p.px)) {
		
		// compute the monochrome intensity - scale from 0..255 to 0..63
		// and diherize using Bayer's algorithm
		mono = (int)(0.30*rr+0.59*gg+0.11*bb) >> 2;
		if (mono < Bayer_Dithering_8x8 [p.px & 7][p.py & 7]) Dot(p);
		
		rr += rstep;
		gg += gstep;
		bb += bstep;
	    }

	} else if (colordither) {    // for a color display - ditherized

	    for (p.px = minx; p.px <= maxx; ++(p.px)) {
		
		// scale from 0..255 to 0..15
		// and ditherize using Bayer's algorithm
		int red,green,blue;
		red   = (int)rr >> 4;
		green = (int)gg >> 4;
		blue  = (int)bb >> 4;
		
		// map to color table (fixed entries 0..8)
		color = 
		  ((blue > Bayer_Dithering_4x4 [p.px & 3][p.py & 3])?1:0) |  
		    ((green > Bayer_Dithering_4x4 [p.px & 3][p.py & 3]?1:0)<<1) |
		      ((red > Bayer_Dithering_4x4 [p.px & 3][p.py & 3]?1:0)<<2);
		
		Dot(p,color); // color is a color table index
		
		rr += rstep;
		gg += gstep;
		bb += bstep;
	    }
	    
	} else {                     // for a color display - non-ditherized

	    for (p.px = minx; p.px <= maxx; ++(p.px)) {
Пример #5
0
void WinErasePolygon (OSPictContext context)
{
	StartErasing (context);
	Polygon (context->hDC, thePolygon, thePolygonIndex);
}	/* WinErasePolygon */
Пример #6
0
void fnRelateSegments(int iDigit, int iPlace, HWND hWnd)
{
    int iTranslate, iIdx;
    BOOL bOnIndex[7];

    POINT PT1[6];
    POINT PT2[6];
    POINT PT3[6];
    POINT PT4[6];
    POINT PT5[6];
    POINT PT6[6];
    POINT PT7[6];
    POINT CN1[4];
    POINT CN2[4];

    POINT *PT[7];

    HDC hDC;
    HBRUSH hDigitBrush[7], hColonBrush;
    HANDLE hDigitPen[7], hColonPen;
    HFONT hfAMPM;

    hDC = 0;

    for(iIdx = 0; iIdx < 7; iIdx++)
        bOnIndex[iIdx] = FALSE;

    switch (iDigit)
    {
    case 0:
        if (iPlace != 3)
        {
            bOnIndex[0] = TRUE;
            bOnIndex[1] = TRUE;
            bOnIndex[2] = TRUE;
            bOnIndex[3] = TRUE;
            bOnIndex[4] = TRUE;
            bOnIndex[5] = TRUE;
        }
        break;
    case 1:
        bOnIndex[0] = TRUE;
        bOnIndex[1] = TRUE;
        break;
    case 2:
        bOnIndex[0] = TRUE;
        bOnIndex[2] = TRUE;
        bOnIndex[3] = TRUE;
        bOnIndex[5] = TRUE;
        bOnIndex[6] = TRUE;
        break;
    case 3:
        bOnIndex[0] = TRUE;
        bOnIndex[1] = TRUE;
        bOnIndex[2] = TRUE;
        bOnIndex[5] = TRUE;
        bOnIndex[6] = TRUE;
        break;
    case 4:
        bOnIndex[0] = TRUE;
        bOnIndex[1] = TRUE;
        bOnIndex[4] = TRUE;
        bOnIndex[6] = TRUE;
        break;
    case 5:
        bOnIndex[1] = TRUE;
        bOnIndex[2] = TRUE;
        bOnIndex[4] = TRUE;
        bOnIndex[5] = TRUE;
        bOnIndex[6] = TRUE;
        break;
    case 6:
        bOnIndex[1] = TRUE;
        bOnIndex[2] = TRUE;
        bOnIndex[3] = TRUE;
        bOnIndex[4] = TRUE;
        bOnIndex[5] = TRUE;
        bOnIndex[6] = TRUE;
        break;
    case 7:
        bOnIndex[0] = TRUE;
        bOnIndex[1] = TRUE;
        bOnIndex[5] = TRUE;
        break;
    case 8:
        bOnIndex[0] = TRUE;
        bOnIndex[1] = TRUE;
        bOnIndex[2] = TRUE;
        bOnIndex[3] = TRUE;
        bOnIndex[4] = TRUE;
        bOnIndex[5] = TRUE;
        bOnIndex[6] = TRUE;
        break;
    case 9:
        bOnIndex[0] = TRUE;
        bOnIndex[1] = TRUE;
        bOnIndex[2] = TRUE;
        bOnIndex[4] = TRUE;
        bOnIndex[5] = TRUE;
        bOnIndex[6] = TRUE;
        break;
    }

    for(iIdx = 0; iIdx < 7; iIdx++)
    {
        if(bOnIndex[iIdx])
        {
            hDigitBrush[iIdx] = CreateSolidBrush(crDigitColor);
            hDigitPen[iIdx] = CreatePen(PS_SOLID, 0, crDigitColor);
        }
        else
        {
            hDigitBrush[iIdx] = CreateSolidBrush(crWndColor);
            hDigitPen[iIdx] = CreatePen(PS_SOLID, 0, crWndColor);
        }
    }
    hDC = GetDC(hWnd);

    PT[0] = PT1;
    PT[1] = PT2;
    PT[2] = PT3;
    PT[3] = PT4;
    PT[4] = PT5;
    PT[5] = PT6;
    PT[6] = PT7;


    switch (iPlace)
    {
    case 0:
        iTranslate = 260;
        break;
    case 1:
        iTranslate = 185;
        break;
    case 2:
        iTranslate = 75;
        break;
    case 3:
        iTranslate = 0;
        break;
    }
    PT1[0].x = iTranslate + 64;
    PT1[0].y = 13;
    PT1[1].x = iTranslate + 69;
    PT1[1].y = 18;
    PT1[2].x = iTranslate + 69;
    PT1[2].y = 58;
    PT1[3].x = iTranslate + 64;
    PT1[3].y = 63;
    PT1[4].x = iTranslate + 59;
    PT1[4].y = 58;
    PT1[5].x = iTranslate + 59;
    PT1[5].y = 18;

    PT2[0].x = iTranslate + 64;
    PT2[0].y = 67;
    PT2[1].x = iTranslate + 69;
    PT2[1].y = 72;
    PT2[2].x = iTranslate + 69;
    PT2[2].y = 112;
    PT2[3].x = iTranslate + 64;
    PT2[3].y = 117;
    PT2[4].x = iTranslate + 59;
    PT2[4].y = 112;
    PT2[5].x = iTranslate + 59;
    PT2[5].y = 72;

    PT3[0].x = iTranslate + 62;
    PT3[0].y = 119;
    PT3[1].x = iTranslate + 57;
    PT3[1].y = 124;
    PT3[2].x = iTranslate + 17;
    PT3[2].y = 124;
    PT3[3].x = iTranslate + 12;
    PT3[3].y = 119;
    PT3[4].x = iTranslate + 17;
    PT3[4].y = 114;
    PT3[5].x = iTranslate + 57;
    PT3[5].y = 114;

    PT4[0].x = iTranslate + 10;
    PT4[0].y = 67;
    PT4[1].x = iTranslate + 15;
    PT4[1].y = 72;
    PT4[2].x = iTranslate + 15;
    PT4[2].y = 112;
    PT4[3].x = iTranslate + 10;
    PT4[3].y = 117;
    PT4[4].x = iTranslate + 05;
    PT4[4].y = 112;
    PT4[5].x = iTranslate + 05;
    PT4[5].y = 72;

    PT5[0].x = iTranslate + 10;
    PT5[0].y = 13;
    PT5[1].x = iTranslate + 15;
    PT5[1].y = 18;
    PT5[2].x = iTranslate + 15;
    PT5[2].y = 58;
    PT5[3].x = iTranslate + 10;
    PT5[3].y = 63;
    PT5[4].x = iTranslate + 05;
    PT5[4].y = 58;
    PT5[5].x = iTranslate + 05;
    PT5[5].y = 18;

    PT6[0].x = iTranslate + 62;
    PT6[0].y = 11;
    PT6[1].x = iTranslate + 57;
    PT6[1].y = 16;
    PT6[2].x = iTranslate + 17;
    PT6[2].y = 16;
    PT6[3].x = iTranslate + 12;
    PT6[3].y = 11;
    PT6[4].x = iTranslate + 17;
    PT6[4].y = 06;
    PT6[5].x = iTranslate + 57;
    PT6[5].y = 06;

    PT7[0].x = iTranslate + 62;
    PT7[0].y = 65;
    PT7[1].x = iTranslate + 57;
    PT7[1].y = 70;
    PT7[2].x = iTranslate + 17;
    PT7[2].y = 70;
    PT7[3].x = iTranslate + 12;
    PT7[3].y = 65;
    PT7[4].x = iTranslate + 17;
    PT7[4].y = 60;
    PT7[5].x = iTranslate + 57;
    PT7[5].y = 60;

    CN1[0].x = 170;
    CN1[0].y = 26;
    CN1[1].x = 180;
    CN1[1].y = 36;
    CN1[2].x = 170;
    CN1[2].y = 46;
    CN1[3].x = 160;
    CN1[3].y = 36;

    CN2[0].x = 170;
    CN2[0].y = 90;
    CN2[1].x = 180;
    CN2[1].y = 100;
    CN2[2].x = 170;
    CN2[2].y = 110;
    CN2[3].x = 160;
    CN2[3].y = 100;

    for(iIdx = 0; iIdx < 7; iIdx++)
    {
        SelectObject(hDC, hDigitBrush[iIdx]);
        SelectObject(hDC, hDigitPen[iIdx]);
        Polygon(hDC, PT[iIdx], 6);
    }

    hColonBrush = CreateSolidBrush(crColonColor);
    hColonPen = CreatePen(PS_SOLID, 0, crColonColor);
    hfAMPM = CreateFont(0, 15, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
                        ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
                        DEFAULT_QUALITY, DEFAULT_PITCH, "Tahoma");
    SelectObject(hDC, hColonBrush);
    SelectObject(hDC, hColonPen);
    SelectObject(hDC, hfAMPM);

    Polygon(hDC, CN1, 4);
    Polygon(hDC, CN2, 4);

    SetBkColor(hDC, crWndColor);
    SetTextColor(hDC, crColonColor);
    if(cAMPM == 'A')
        TextOut(hDC, 370, 20, "AM", 2);
    else
        TextOut(hDC, 370, 20, "PM", 2);

    DeleteObject(hfAMPM);
    DeleteObject(hColonBrush);
    CloseHandle(hColonPen);
    DeleteObject(hColonPen);

    for(iIdx = 0; iIdx < 7; iIdx++)
    {
        DeleteObject(hDigitBrush[iIdx]);
        CloseHandle(hDigitPen[iIdx]);
        DeleteObject(hDigitPen[iIdx]);
    }

    ReleaseDC(hWnd, hDC);
    return;
}
Пример #7
0
// WINMAIN ////////////////////////////////////////////////
int WINAPI WinMain(	HINSTANCE hinstance,
					HINSTANCE hprevinstance,
					LPSTR lpcmdline,
					int ncmdshow)
{

WNDCLASSEX winclass; // this will hold the class we create
HWND	   hwnd;	 // generic window handle
MSG		   msg;		 // generic message
HDC        hdc;      // graphics device context

// first fill in the window class stucture
winclass.cbSize         = sizeof(WNDCLASSEX);
winclass.style			= CS_DBLCLKS | CS_OWNDC | 
                          CS_HREDRAW | CS_VREDRAW;
winclass.lpfnWndProc	= WindowProc;
winclass.cbClsExtra		= 0;
winclass.cbWndExtra		= 0;
winclass.hInstance		= hinstance;
winclass.hIcon			= LoadIcon(NULL, IDI_APPLICATION);
winclass.hCursor		= LoadCursor(NULL, IDC_ARROW); 
winclass.hbrBackground	= (HBRUSH)GetStockObject(BLACK_BRUSH);
winclass.lpszMenuName	= NULL;
winclass.lpszClassName	= WINDOW_CLASS_NAME;
winclass.hIconSm        = LoadIcon(NULL, IDI_APPLICATION);

// save hinstance in global
hinstance_app = hinstance;

// register the window class
if (!RegisterClassEx(&winclass))
	return(0);

// create the window
if (!(hwnd = CreateWindowEx(NULL,                // extended style
                            WINDOW_CLASS_NAME,   // class
						    "Polygon Drawing Demo", // title
						    WS_OVERLAPPEDWINDOW | WS_VISIBLE,
					 	    0,0,	  // initial x,y
						    WINDOW_WIDTH, // initial width
                            WINDOW_HEIGHT,// initial height
						    NULL,	  // handle to parent 
						    NULL,	  // handle to menu
						    hinstance,// instance of this application
						    NULL)))	// extra creation parms
return(0);

// save main window handle
main_window_handle = hwnd;

// get the graphics device context 
hdc = GetDC(hwnd);


// enter main event loop, but this time we use PeekMessage()
// instead of GetMessage() to retrieve messages
while(TRUE)
	{
    // test if there is a message in queue, if so get it
	if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
	   { 
	   // test if this is a quit
       if (msg.message == WM_QUIT)
           break;
	
	   // translate any accelerator keys
	   TranslateMessage(&msg);

	   // send the message to the window proc
	   DispatchMessage(&msg);
	   } // end if

    // select random colors for polygon 
    HPEN   pen_color   = CreatePen(PS_SOLID, 1, RGB(rand()%256,rand()%256,rand()%256));
    HBRUSH brush_color = CreateSolidBrush(RGB(rand()%256,rand()%256,rand()%256));

    // select them into dc
    SelectObject(hdc,pen_color);
    SelectObject(hdc,brush_color);

    // now create list of random points for polygon
    int num_points = 3+rand()%8;

    // this will hold the point list
    POINT point_list[10];
 
    // create array of points
    for (int index = 0; index < num_points; index++)
        {
        // set next random point in list
        point_list[index].x = rand()%WINDOW_WIDTH;
        point_list[index].y = rand()%WINDOW_HEIGHT;
        } // end for index
    
    // draw the polygon
    Polygon(hdc, point_list, num_points);

    // let user see it
    Sleep(500);

    // main game processing goes here
    if (KEYDOWN(VK_ESCAPE))
       SendMessage(hwnd, WM_CLOSE, 0,0);
       
	} // end while


// release the device context
ReleaseDC(hwnd,hdc);

// return to Windows like this
return(msg.wParam);

} // end WinMain
Пример #8
0
void Navigation2D::_navpoly_link(int p_id) {

	ERR_FAIL_COND(!navpoly_map.has(p_id));
	NavMesh &nm = navpoly_map[p_id];
	ERR_FAIL_COND(nm.linked);

	PoolVector<Vector2> vertices = nm.navpoly->get_vertices();
	int len = vertices.size();
	if (len == 0)
		return;

	PoolVector<Vector2>::Read r = vertices.read();

	for (int i = 0; i < nm.navpoly->get_polygon_count(); i++) {

		//build

		List<Polygon>::Element *P = nm.polygons.push_back(Polygon());
		Polygon &p = P->get();
		p.owner = &nm;

		Vector<int> poly = nm.navpoly->get_polygon(i);
		int plen = poly.size();
		const int *indices = poly.ptr();
		bool valid = true;
		p.edges.resize(plen);

		Vector2 center;
		float sum = 0;

		for (int j = 0; j < plen; j++) {

			int idx = indices[j];
			if (idx < 0 || idx >= len) {
				valid = false;
				break;
			}

			Polygon::Edge e;
			Vector2 ep = nm.xform.xform(r[idx]);
			center += ep;
			e.point = _get_point(ep);
			p.edges[j] = e;

			int idxn = indices[(j + 1) % plen];
			if (idxn < 0 || idxn >= len) {
				valid = false;
				break;
			}

			Vector2 epn = nm.xform.xform(r[idxn]);

			sum += (epn.x - ep.x) * (epn.y + ep.y);
		}

		p.clockwise = sum > 0;

		if (!valid) {
			nm.polygons.pop_back();
			ERR_CONTINUE(!valid);
			continue;
		}

		p.center = center / plen;

		//connect

		for (int j = 0; j < plen; j++) {

			int next = (j + 1) % plen;
			EdgeKey ek(p.edges[j].point, p.edges[next].point);

			Map<EdgeKey, Connection>::Element *C = connections.find(ek);
			if (!C) {

				Connection c;
				c.A = &p;
				c.A_edge = j;
				c.B = NULL;
				c.B_edge = -1;
				connections[ek] = c;
			} else {

				if (C->get().B != NULL) {
					ConnectionPending pending;
					pending.polygon = &p;
					pending.edge = j;
					p.edges[j].P = C->get().pending.push_back(pending);
					continue;
					//print_line(String()+_get_vertex(ek.a)+" -> "+_get_vertex(ek.b));
				}

				C->get().B = &p;
				C->get().B_edge = j;
				C->get().A->edges[C->get().A_edge].C = &p;
				C->get().A->edges[C->get().A_edge].C_edge = j;
				p.edges[j].C = C->get().A;
				p.edges[j].C_edge = C->get().A_edge;
				//connection successful.
			}
		}
	}

	nm.linked = true;
}
Пример #9
0
void
Brush(HDC hdc, LONG x1, LONG y1, LONG x2, LONG y2, COLORREF color, LONG style)
{
    HPEN oldPen = SelectObject(hdc, CreatePen(PS_SOLID, 1, color));
    HBRUSH oldBrush = SelectObject(hdc, CreateSolidBrush(color));
    LONG a, b;
    b = max(1, max(abs(x2 - x1), abs(y2 - y1)));
    switch (style)
    {
        case 0:
            for(a = 0; a <= b; a++)
                Ellipse(hdc, (x1 * (b - a) + x2 * a) / b - 3, (y1 * (b - a) + y2 * a) / b - 3,
                        (x1 * (b - a) + x2 * a) / b + 4, (y1 * (b - a) + y2 * a) / b + 4);
            break;
        case 1:
            for(a = 0; a <= b; a++)
                Ellipse(hdc, (x1 * (b - a) + x2 * a) / b - 1, (y1 * (b - a) + y2 * a) / b - 1,
                        (x1 * (b - a) + x2 * a) / b + 3, (y1 * (b - a) + y2 * a) / b + 3);
            break;
        case 2:
            MoveToEx(hdc, x1, y1, NULL);
            LineTo(hdc, x2, y2);
            SetPixel(hdc, x2, y2, color);
            break;
        case 3:
            for(a = 0; a <= b; a++)
                Rectangle(hdc, (x1 * (b - a) + x2 * a) / b - 3, (y1 * (b - a) + y2 * a) / b - 3,
                          (x1 * (b - a) + x2 * a) / b + 5, (y1 * (b - a) + y2 * a) / b + 5);
            break;
        case 4:
            for(a = 0; a <= b; a++)
                Rectangle(hdc, (x1 * (b - a) + x2 * a) / b - 2, (y1 * (b - a) + y2 * a) / b - 2,
                          (x1 * (b - a) + x2 * a) / b + 3, (y1 * (b - a) + y2 * a) / b + 3);
            break;
        case 5:
            for(a = 0; a <= b; a++)
                Rectangle(hdc, (x1 * (b - a) + x2 * a) / b - 1, (y1 * (b - a) + y2 * a) / b - 1,
                          (x1 * (b - a) + x2 * a) / b + 1, (y1 * (b - a) + y2 * a) / b + 1);
            break;
        case 6:
        case 7:
        case 8:
        case 9:
        case 10:
        case 11:
        {
            POINT offsTop[] = {{4, -3}, {2, -2}, {0, 0}, 
                               {-3, -3}, {-2, -2}, {-1, 0}};
            POINT offsBtm[] = {{-3, 4}, {-2, 2}, {-1, 1},
                               {4, 4}, {2, 2}, {0, 1}};
            LONG idx = style - 6;
            POINT pts[4];
            pts[0].x = x1 + offsTop[idx].x;
            pts[0].y = y1 + offsTop[idx].y;
            pts[1].x = x1 + offsBtm[idx].x;
            pts[1].y = y1 + offsBtm[idx].y;
            pts[2].x = x2 + offsBtm[idx].x;
            pts[2].y = y2 + offsBtm[idx].y;
            pts[3].x = x2 + offsTop[idx].x;
            pts[3].y = y2 + offsTop[idx].y;
            Polygon(hdc, pts, 4);
            break;
        }
    }
    DeleteObject(SelectObject(hdc, oldBrush));
    DeleteObject(SelectObject(hdc, oldPen));
}
Пример #10
0
void ViewPort::DrawActiveDomain( double pixel_size, double offset_x, double offset_y )
{
	Transform *transform;								// render all transforms in section
	HPEN pen, oldpen;
	HBRUSH brush, oldbrush;
	LOGBRUSH lbrush;
	int oldmode, i, x, y, numpts;
	Contour *contour, *c;
	Point *p;
	POINT *lpPoints;

	if ( section && viewDC )							// need a drawing surface for domain contour
	  if ( section->active )							// do only if have an active transform
		{
		transform = section->active;
		if ( transform->domain )						// do only if have domain
			{
			contour = transform->domain;
			if ( contour->points )
				{
				c = new Contour( *contour );					// copy the contour
																// if image, then contour is in pixels
				if ( transform->image ) c->Scale( transform->image->mag );
				c->InvNform( transform->nform );				// transform into section
				c->Shift( -offset_x, -offset_y );				// shift into view
				c->Scale( 1.0/pixel_size );						// scale to view's pixels
					
				numpts = c->points->Number();
				lpPoints = new POINT[ numpts ];					// create Window POINT array for drawing

				i = 0;
				p = c->points->first;
				while ( p != NULL )
					{
					lpPoints[i].x = (int)floor(p->x);
					lpPoints[i].y = height - (int)floor(p->y);
					i++;
					p = p->next;
					}
																// create pen for border of object
				pen = CreatePen( PS_SOLID, 1, c->border.ref() );
				oldpen = (HPEN)SelectObject( viewDC, pen );		// set pen into device context

				if ( c->mode < 0 )
					{
					brush = CreateSolidBrush( c->fill.ref() );	// interior will be filled
					oldbrush = (HBRUSH)SelectObject( viewDC, brush );
					SetROP2( viewDC, abs(c->mode) );			// using contour fill mode and color
					Polygon( viewDC, lpPoints, numpts );
					SelectObject( viewDC, oldbrush );			// clean up fill brush
					DeleteObject(brush);
					}

				SelectObject( viewDC, (HBRUSH)GetStockObject(NULL_BRUSH) );	// without coloring interior
				SetROP2( viewDC, R2_COPYPEN );								// draw contour border with pen
				if ( c->closed ) Polygon( viewDC, lpPoints, numpts );
				else Polyline( viewDC, lpPoints, numpts );
				
				SelectObject( viewDC, oldpen );					// clean up pen
				DeleteObject(pen);
				delete[] lpPoints;								// and dynamic memory
				delete c;
				}
			}
		}

}
Пример #11
0
// draw aircraft
void RenderPlaneSideview(HDC hdc, double fDist, double fAltitude,double brg, DiagrammStruct* psDia )
{
//BOOL bInvCol = true ; //INVERTCOLORS
  #define NO_AP_PTS 17
  int deg = DEG_TO_INT(AngleLimit360(brg));
  double fCos = COSTABLE[deg];
  double fSin = SINETABLE[deg];

  int TAIL   = 6;
  int PROFIL = 1;
  int FINB   = 3;
  int BODY   = 2;
  int NOSE   = 7;
  int WING   = (int) (22.0 );
  int TUBE   = (int) (14.0  ) ;
  int FINH   = 6+BODY;

  POINT Start;
  int HEAD = TUBE / 2;
  TUBE =  3 * TUBE/ 2;
  POINT AircraftSide
  [8] = {
      {(int)(fSin * (HEAD+0   )    ), -BODY-1},  // 1
      {(int)(fSin * (HEAD+NOSE)    ),  0},       // 2
      {(int)(fSin * (HEAD+0   )    ),  BODY+1},  // 3
      {(int)(fSin * (-TUBE)        ),  BODY},    // 4   -1
      {(int)(fSin * -TUBE          ), -FINH},    // 5
      {(int)(fSin * (-TUBE+FINB)   ), -FINH},    // 6
      {(int)(fSin * (-TUBE+FINB+3) ), -BODY+1},  // 7  +1
      {(int)(fSin * (HEAD+0)       ), -BODY-1}     // 8
  };

  #define  FACT 2

  BODY = (int)((double)(BODY+1) * fCos * fCos);

  int DIA = (BODY + PROFIL);

  /* both wings */
  POINT AircraftWing
  [13] = {
      {(int)(fCos * BODY              ) ,  -DIA},    // 1
      {(int)(fCos * (int)( FACT*BODY) ), -PROFIL},    // 2
      {(int)(fCos * WING              ) ,  -PROFIL},    // 3
      {(int)(fCos * WING              ), 0* PROFIL},    // 4
      {(int)(fCos * (int)( FACT*BODY) ) , PROFIL},    // 5
      {(int)(fCos *  BODY             ), DIA},    // 6
      {(int)(fCos * -BODY             ) , DIA},    // 7
      {(int)(fCos * (int)( -FACT*BODY)), PROFIL},    // 8
      {(int)(fCos * -WING             ), 0* PROFIL  },    // 9
      {(int)(fCos * -WING             ) , -PROFIL}  ,    // 10
      {(int)(fCos * (int)( -FACT*BODY)), -PROFIL},    // 11
      {(int)(fCos * -BODY             ) , -DIA},    // 12
      {(int)(fCos *  BODY             ), -DIA}    // 13
  };


  POINT AircraftWingL
  [7] = {

      {(int)(0 * -BODY                ),  DIA       },    // 1
      {(int)(fCos * (int)( -FACT*BODY)),  PROFIL    },    // 2
      {(int)(fCos * -WING             ),  0* PROFIL },    // 3
      {(int)(fCos * -WING             ), -PROFIL    },    // 4
      {(int)(fCos * (int)( -FACT*BODY)), -PROFIL    },    // 5
      {(int)(0 * -BODY                ), -DIA       },    // 6
      {(int)(0 * -BODY                ),  DIA       }     // 7
  };


  POINT AircraftWingR
  [7] = {
      {(int)(0 * BODY                 ) ,  -DIA    },   // 1
      {(int)(fCos * (int)( FACT*BODY) ) , -PROFIL  },   // 2
      {(int)(fCos * WING              ) ,  -PROFIL },   // 3
      {(int)(fCos * WING              ) , 0* PROFIL},   // 4
      {(int)(fCos * (int)( FACT*BODY) ) , PROFIL   },   // 5
      {(int)(0 *  BODY                ) , DIA      },   // 6
      {(int)(0 *  BODY                ) , -DIA     }    // 7
  };



  POINT AircraftTail
  [5] = {
      {(int)(fCos *  TAIL - fSin*TUBE), -FINH},            // 1
      {(int)(fCos *  TAIL - fSin*TUBE), -FINH +PROFIL},    // 2
      {(int)(fCos * -TAIL - fSin*TUBE), -FINH +PROFIL},    // 3
      {(int)(fCos * -TAIL - fSin*TUBE), -FINH },           // 4
      {(int)(fCos *  TAIL - fSin*TUBE), -FINH},            // 5

  };

  Start.x = CalcDistanceCoordinat(fDist,  psDia);
  Start.y = CalcHeightCoordinat(fAltitude, psDia);
  HBRUSH oldBrush;
  HPEN   oldPen;
/*
  if(bInvCol)
  {
    oldPen   = (HPEN)SelectObject(hdc, GetStockObject(WHITE_PEN));
    oldBrush = (HBRUSH)SelectObject(hdc, GetStockObject(BLACK_BRUSH));
  }
  else
*/
  {
    oldPen   = (HPEN) SelectObject(hdc, GetStockObject(BLACK_PEN));
    oldBrush = (HBRUSH)SelectObject(hdc, GetStockObject(WHITE_BRUSH));
  }

  //SelectObject(hdc, GetStockObject(BLACK_PEN));
  PolygonRotateShift(AircraftWing, 13,  Start.x, Start.y,  0);
  PolygonRotateShift(AircraftSide, 8,   Start.x, Start.y,  0);
  PolygonRotateShift(AircraftTail, 5,   Start.x, Start.y,  0);
  PolygonRotateShift(AircraftWingL, 7,   Start.x, Start.y,  0);
  PolygonRotateShift(AircraftWingR, 7,   Start.x, Start.y,  0);

  HBRUSH GreenBrush = CreateSolidBrush(COLORREF RGB_GREEN);
  HBRUSH RedBrush = CreateSolidBrush(COLORREF RGB_RED);
  if((brg < 180))
  {
    SelectObject(hdc, RedBrush);
    Polygon(hdc,AircraftWingL ,7 );

    SelectObject(hdc, GetStockObject(WHITE_BRUSH));
    Polygon(hdc,AircraftSide  ,8 );

    SelectObject(hdc, GreenBrush);
    Polygon(hdc,AircraftWingR ,7 );

    SelectObject(hdc, oldBrush);
  }
  else
  {
    SelectObject(hdc, GreenBrush);
    Polygon(hdc,AircraftWingR ,7 );

    SelectObject(hdc, GetStockObject(WHITE_BRUSH));
    Polygon(hdc,AircraftSide  ,8 );

    SelectObject(hdc, RedBrush);
    Polygon(hdc,AircraftWingL ,7 );

    SelectObject(hdc, oldBrush);
   //Polygon(hdc,AircraftWing  ,13);
  }
  if((brg < 90)|| (brg > 270)) {
    Polygon(hdc,AircraftTail  ,5 );
  }

  SelectObject(hdc, oldPen);
  SelectObject(hdc, oldBrush);
  DeleteObject(RedBrush);
  DeleteObject(GreenBrush);

} //else !asp_heading_task
Пример #12
0
void ViewPort::DrawContours( double pixel_size, double offset_x, double offset_y )
{
	Transform *transform;								// render all transforms in section
	HPEN pen, oldpen;
	HBRUSH brush, oldbrush;
	LOGBRUSH lbrush;
	int oldmode, i, x, y, numpts;
	Contour *contour, *c;
	Point *p;
	POINT *lpPoints;

//startTime3 = GetTickCount();

	if ( section && viewDC )							// do only if section and drawing surface are defined
	  if ( section->transforms )							// render all contours in all transforms
		{
		transform = section->transforms->first;
		while ( transform )									// render all contours in this transform
			{	
			if ( transform->contours )						// do only if have contours
				{
				contour = transform->contours->first;
															// do each contour in list
				while ( contour )
					{
					if ( contour->points && !contour->hidden )		// don't draw hidden contours
						{
						c = new Contour( *contour );					// copy the contour
						c->InvNform( transform->nform );				// transform into section
						c->Shift( -offset_x, -offset_y );				// shift into view
						c->Scale( 1.0/pixel_size );						// scale to view's pixels

						numpts = c->points->Number();
						lpPoints = new POINT[ numpts ];					// create Window POINT array for drawing

						i = 0;
						p = c->points->first;
						while ( p != NULL )
							{
							lpPoints[i].x = (int)floor(p->x);
							lpPoints[i].y = height - (int)floor(p->y);
							i++;
							p = p->next;
							}
																		// create pen for border of object
						if ( transform->isActive ) pen = CreatePen( PS_DOT, 1, c->border.ref() );
						else pen = CreatePen( PS_SOLID, 1, c->border.ref() );
						oldpen = (HPEN)SelectObject( viewDC, pen );		// set pen into device context

						if ( c->closed && ((transform->isActive && (c->mode > 0))
												|| (!transform->isActive && (c->mode < 0))) )
							{
							brush = CreateSolidBrush( c->fill.ref() );	// interior will be filled
							oldbrush = (HBRUSH)SelectObject( viewDC, brush );
							SetROP2( viewDC, abs(c->mode) );			// using contour fill mode and color
							Polygon( viewDC, lpPoints, numpts );
							SelectObject( viewDC, oldbrush );			// clean up fill brush
							DeleteObject(brush);
							}

						SelectObject( viewDC, (HBRUSH)GetStockObject(NULL_BRUSH) );	// without coloring interior
						SetROP2( viewDC, R2_COPYPEN );								// draw contour border with pen
						if ( c->closed ) Polygon( viewDC, lpPoints, numpts );
						else Polyline( viewDC, lpPoints, numpts );
						
						SelectObject( viewDC, oldpen );					// clean up pen
						DeleteObject(pen);
						delete[] lpPoints;								// and dynamic memory
						delete c;
						}
					contour = contour->next;					// do next contour in list
					}
				}

			transform = transform->next;					// do next transform in list
			}
		}		// end if ( section->transforms )

//totalTime3 += GetTickCount() - startTime3;			// debugging
//nTime3++;

}
Пример #13
0
// Step 4: the Window Procedure
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	HDC hDC;			// handle to the device context (permission to draw)
	PAINTSTRUCT Ps;		// a variable that you need
	HPEN hRectPen;		// the handle to the red pen
	HPEN hCirPen;
	HPEN hTriPen;
	static POINT triPoint[3];
	static int triBase = 100;
	triPoint[0].x = 445;
	triPoint[0].y = 225 - (triBase / 2);
	triPoint[1].x = 470 - (triBase / 2);
	triPoint[1].y = 170 + (triBase / 2);
	triPoint[2].x = 420 + (triBase / 2);
	triPoint[2].y = 170 + (triBase / 2);

	HBRUSH rectBrush;
	HBRUSH cirBrush;
	HBRUSH triBrush;

	static int rectRed = 255;
	static int rectBlue = 0;
	static int rectGreen = 0;

	static int rectBrushRed = 128;
	static int rectBrushBlue = 128;
	static int rectBrushGreen = 128;

	static int cirRed = 155;
	static int cirBlue = 0;
	static int cirGreen = 10;

	static int cirBrushRed = 108;
	static int cirBrushBlue = 228;
	static int cirBrushGreen = 024;

	static int triRed = 0;
	static int triBlue = 50;
	static int triGreen = 10;

	static int triBrushRed = 208;
	static int triBrushBlue = 155;
	static int triBrushGreen = 124;

	static int rectX = 325;
	static int rectY = 200;
	static int cirX = 225;
	static int cirY = 200;

	POINT test[1];
	test[0].x = 123;
	static int penSize = 5;

	switch (msg)
	{
	case WM_PAINT:
		hDC = BeginPaint(hwnd, &Ps);
		hRectPen = CreatePen(PS_SOLID, penSize, RGB(rectRed, rectGreen, rectBlue));
		SelectObject(hDC, hRectPen);

		rectBrush = CreateSolidBrush(RGB(rectBrushRed, rectBrushGreen, rectBrushBlue));
		SelectObject(hDC, rectBrush);
		Rectangle(hDC, rectX + 25, rectY - 25, rectX - 25, rectY + 25);

		hCirPen = CreatePen(PS_SOLID, penSize, RGB(cirRed, cirGreen, cirBlue));
		SelectObject(hDC, hCirPen);

		cirBrush = CreateSolidBrush(RGB(cirBrushRed, cirBrushGreen, cirBrushBlue));
		SelectObject(hDC, cirBrush);
		Ellipse(hDC, cirX + 25, cirY - 25, cirX - 25, cirY + 25);

		hTriPen = CreatePen(PS_SOLID, penSize, RGB(triRed, triGreen, triBlue));
		SelectObject(hDC, hTriPen);

		triBrush = CreateSolidBrush(RGB(triBrushRed, triBrushGreen, triBrushBlue));
		SelectObject(hDC, triBrush);

		Polygon(hDC, triPoint, 3);

		DeleteObject(hRectPen);
		DeleteObject(rectBrush);
		DeleteObject(hCirPen);

		DeleteObject(cirBrush);
		DeleteObject(hTriPen);
		DeleteObject(triBrush);
		EndPaint(hwnd, &Ps);
		break;
	case WM_KEYDOWN:
		if (wParam == VK_SPACE)
		{
			rectRed = rand() % 256;
			rectGreen = rand() % 256;
			rectBlue = rand() % 256;
			rectBrushRed = rand() % 256;
			rectBrushBlue = rand() % 256;
			rectBrushGreen = rand() % 256;

			cirRed = rand() % 256;
			cirGreen = rand() % 256;
			cirBlue = rand() % 256;
			cirBrushRed = rand() % 256;
			cirBrushBlue = rand() % 256;
			cirBrushGreen = rand() % 256;

			triRed = rand() % 256;
			triGreen = rand() % 256;
			triBlue = rand() % 256;
			triBrushRed = rand() % 256;
			triBrushBlue = rand() % 256;
			triBrushGreen = rand() % 256;
		}
		else if (wParam == VK_NEXT)
		{
			triBase -= 5;
		}
		else if (wParam == VK_PRIOR)
		{
			triBase += 5;
		}
		else if (wParam == VK_RIGHT)
		{
			rectX += 3;
		}
		else if (wParam == VK_LEFT)
		{
			rectX -= 3;
		}
		else if (wParam == VK_UP)
		{
			rectY -= 3;
		}
		else if (wParam == VK_DOWN)
		{
			rectY += 3;
		}

		InvalidateRect(hwnd, NULL, true);
		break;

	case WM_CLOSE:
		DestroyWindow(hwnd);
		break;
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	default:
		return DefWindowProc(hwnd, msg, wParam, lParam);
	}
	return 0;
}
Пример #14
0
Tetragon::Tetragon():TetragonBase(Polygon(),Texgon()){
  
}
Пример #15
0
LRESULT CALLBACK WindowProc (HWND   hwnd,
                             UINT   msg,
                             WPARAM wParam,
                             LPARAM lParam)
{
    //create some pens to use for drawing
    static HPEN BluePen  = CreatePen(PS_SOLID, 1, RGB(0, 0, 255));
    static HPEN OldPen   = NULL;

    //create a solid brush
    static HBRUSH RedBrush = CreateSolidBrush(RGB(255, 0, 0));
    static HBRUSH OldBrush = NULL;
  
    //these hold the dimensions of the client window area
	  static int cxClient, cyClient;

    //this will hold the vertices of the polygons we create
    static POINT verts[NUM_VERTS];

    static int iNumVerts = NUM_VERTS;
    
    switch (msg)
    {
	
		//A WM_CREATE msg is sent when your application window is first
		//created
    case WM_CREATE:
      {
         //to get get the size of the client window first we need  to create
         //a RECT and then ask Windows to fill in our RECT structure with
         //the client window size. Then we assign to cxClient and cyClient 
         //accordingly
			   RECT rect;

			   GetClientRect(hwnd, &rect);

			   cxClient = rect.right;
			   cyClient = rect.bottom;

         //seed random number generator
         srand((unsigned) time(NULL));

         //now lets create some random vertices
         for (int v=0; v<iNumVerts; ++v)
         {
           verts[v].x = RandInt(0, cxClient);
           verts[v].y = RandInt(0, cyClient);
         }

      }

      break;

    case WM_KEYUP:
      {
        switch(wParam)
        {
        case VK_SPACE:
          {
            //create some new points for our polygon
            //now lets create some random vertices
            for (int v=0; v<iNumVerts; ++v)
            {
              verts[v].x = RandInt(0, cxClient);
              verts[v].y = RandInt(0, cyClient);
            }

             //refresh the display so we can see our
              //new polygon
              InvalidateRect(hwnd, NULL, TRUE);
              UpdateWindow(hwnd);
          }
          
          break;

        case VK_ESCAPE:
          {
            PostQuitMessage(0);
          }
          
          break;
        }
      }
    
    case WM_PAINT:
      {
 				 //create some random vertices for the polygon
         for (int v=0; v<iNumVerts; ++v)
         {
           verts[v].x = RandInt(0, cxClient);
           verts[v].y = RandInt(0, cyClient);
         } 
        
         PAINTSTRUCT ps;
          
         BeginPaint (hwnd, &ps);
          
         //first select a pen to draw with and store a copy
         //of the pen we are swapping it with
         OldPen = (HPEN)SelectObject(ps.hdc, BluePen);

         //do the same for our brush
         OldBrush = (HBRUSH)SelectObject(ps.hdc, RedBrush);

         //draw the polygon
         Polygon(ps.hdc, verts, iNumVerts);
         
         //replace the original pen
         SelectObject(ps.hdc, OldPen);
         //and brush
         SelectObject(ps.hdc, OldBrush);
          
         EndPaint (hwnd, &ps);

         //use this as a simple delay so we can see the 
         //polygons
         Sleep(100);
      }

      break;

    //has the user resized the client area?
		case WM_SIZE:
		  {
        //if so we need to update our variables so that any drawing
        //we do using cxClient and cyClient is scaled accordingly
			  cxClient = LOWORD(lParam);
			  cyClient = HIWORD(lParam);

        //create a new polygon
        for (int v=0; v<iNumVerts; ++v)
        {
           verts[v].x = RandInt(0, cxClient);
           verts[v].y = RandInt(0, cyClient);
        }
      }

      break;
          
		 case WM_DESTROY:
			 {
				 //delete the pens        
         DeleteObject(BluePen);
         DeleteObject(OldPen);

         //and the brushes
         DeleteObject(RedBrush);
         DeleteObject(OldBrush);
         
         // kill the application, this sends a WM_QUIT message  
				 PostQuitMessage (0);
			 }

       break;

     }//end switch

     //this is where all the messages not specifically handled by our 
		 //winproc are sent to be processed
		 return DefWindowProc (hwnd, msg, wParam, lParam);
}
Пример #16
0
void
MwPaintScrollbars(HWND hwnd, HDC hdc, DWORD style)
{
	BOOL	vertbar = (style==SBS_VERT);
        BOOL	horzbar = (style==SBS_HORZ);
	BOOL	fGotDC = FALSE;
	RECT	rc,rc2;

	POINT	p3[3];
	int	shrink=2;

        int start = 0;
        RECT rcHBar, rcVBar;

	int cx,cy;
    	MWSCROLLBARINFO* pData;
	
        pData = (MWSCROLLBARINFO *)hwnd->userdata;
	rc = hwnd->winrect;
	cx=rc.right-rc.left;
	cy=rc.bottom-rc.top;

	if (!hdc && (horzbar || vertbar)) {
		hdc = GetWindowDC(hwnd);
		fGotDC = TRUE;
	}

	if (vertbar) {

#if 1
		/* bkgnd */
		rc2.left=rc.left; rc2.right=rc2.left+ cx;
		rc2.top=rc.top;
		rc2.bottom=rc2.top+ cx;
		FillRect(hdc, &rc2, (HBRUSH)(COLOR_BTNFACE+1));
		rc2.top=rc.bottom- cx;
		rc2.bottom=rc2.top+ cx;
		FillRect(hdc, &rc2, (HBRUSH)(COLOR_BTNFACE+1));
#endif
		/* up */
		Draw3dUpDownState(hdc, rc.left, rc.top,
			cx, cx,
			pData->status & SBS_UPARROW);
		/* down */
		Draw3dUpDownState(hdc, rc.left,rc.bottom-cx,
			cx, cx,
			pData->status & SBS_DOWNARROW);
/* jmt: draw arrows */
		SelectObject(hdc,GetStockObject(BLACK_BRUSH));
		/* up */
		p3[0].x= rc.left + (cx/2) - 1;
		p3[0].y= rc.top + 2 + shrink;
		p3[1].x= rc.left + 2 + shrink - 1;
		p3[1].y= rc.top + (cx-4) - shrink;
		p3[2].x= rc.left + (cx-4) - shrink;
		p3[2].y= rc.top + (cx-4) - shrink;
		Polygon(hdc,p3,3);
		/* down */
		p3[0].x= rc.left + (cx/2) - 1;
		p3[0].y= rc.bottom - 4 - shrink;
		p3[1].x= rc.left + 2 + shrink - 1;
		p3[1].y= rc.bottom-cx + 2 + shrink;
		p3[2].x= rc.left + (cx-4) - shrink;
		p3[2].y= rc.bottom-cx + 2 + shrink;
		Polygon(hdc,p3,3);

        	/* draw moving bar */

    		wndGetVScrollBarRect (hwnd, &rcVBar);
    		rcVBar.left -- ;
    		/*rcVBar.right -- ;*/

        	start = rcVBar.top + cx + pData->barStart;
                    
        	if (start + pData->barLen > rcVBar.bottom)
            		start = rcVBar.bottom - pData->barLen;
		
		if (pData->barLen == 0)
			pData->barLen=rc.bottom-rc.top-(cx*2); 

		/* bkgnd */
		rc2.left=rc.left; rc2.right=rc.right/*-1*/;
		rc2.top=rc.top+cx;
		rc2.bottom=start;
		if (rc2.bottom>rc2.top)
			FillRect(hdc, &rc2, (HBRUSH)GetStockObject(DKGRAY_BRUSH));   

		rc2.top=start+pData->barLen;
		rc2.bottom=rc.bottom-cx;
		if (rc2.bottom>rc2.top)
			FillRect(hdc, &rc2, (HBRUSH)GetStockObject(DKGRAY_BRUSH));   

        	Draw3dUpFrame (hdc, rcVBar.left, start, rcVBar.right,
	    		start + pData->barLen);
		/*printf("barv:(l,t,r,b):(%d,%d,%d,%d)\n",
        		rcVBar.left, start, rcVBar.right,
	    		start + pData->barLen);*/

	}
	if (horzbar) {
#if 1
		/* bkgnd */
		rc2.top=rc.top; rc2.bottom=rc2.top+ cy;
		rc2.left=rc.left;
		rc2.right=rc2.left+ cy;
		FillRect(hdc, &rc2, (HBRUSH)(COLOR_BTNFACE+1));
		rc2.left=rc.right- cy;
		rc2.right=rc2.left+ cy;
		FillRect(hdc, &rc2, (HBRUSH)(COLOR_BTNFACE+1));
#endif
		/* left */
		Draw3dUpDownState(hdc, rc.left, rc.top,
			cy, cy,
			pData->status & SBS_LEFTARROW);
		/* right */
		Draw3dUpDownState(hdc, rc.right-cy, rc.top,
			cy, cy,
			pData->status & SBS_RIGHTARROW);
/* jmt: draw arrows */
		SelectObject(hdc,GetStockObject(BLACK_BRUSH));
		/* left */
		p3[0].x= rc.left + 2 + shrink;
		p3[0].y= rc.top + (cy/2) ;
		p3[1].x= rc.left + (cy-4) - shrink ;
		p3[1].y= rc.top + 2 + shrink;
		p3[2].x= rc.left + (cy-4) - shrink;
		p3[2].y= rc.bottom - 4 - shrink + 1;
		Polygon(hdc,p3,3);
		/* right */
		p3[0].x= rc.right - 4 - shrink;
		p3[0].y= rc.top + (cy/2) ;
		p3[1].x= rc.right-cy + 2 + shrink ;
		p3[1].y= rc.top + 2 + shrink;
		p3[2].x= rc.right-cy + 2 + shrink;
		p3[2].y= rc.bottom - 4 - shrink + 1;
		Polygon(hdc,p3,3);

        	/* draw moving bar. */

    		wndGetHScrollBarRect (hwnd, &rcHBar);
    		rcHBar.top -- ;
    		/*rcHBar.bottom -- ;*/

        	start = rcHBar.left + cy + pData->barStart;

        	if (start + pData->barLen > rcHBar.right)
            		start = rcHBar.right - pData->barLen;

		if (pData->barLen == 0)
			pData->barLen=rc.right-rc.left-(cy*2); 

		/* bkgnd */
		rc2.top=rc.top; rc2.bottom=rc.bottom/*-1*/;
		rc2.left=rc.left+cy;
		rc2.right=start;
		if (rc2.right>rc2.left)
			FillRect(hdc, &rc2, (HBRUSH)GetStockObject(DKGRAY_BRUSH));   

		rc2.left=start+pData->barLen;
		rc2.right=rc.right-cy;
		if (rc2.right>rc2.left)
			FillRect(hdc, &rc2, (HBRUSH)GetStockObject(DKGRAY_BRUSH));   

        	Draw3dUpFrame (hdc, start, rcHBar.top, start + pData->barLen,
	    		rcHBar.bottom);
		/*printf("barh:(l,t,r,b):(%d,%d,%d,%d)\n",
        		start, rcHBar.top, start + pData->barLen,
	    		rcHBar.bottom);*/
	}

	if (fGotDC)
		ReleaseDC(hwnd, hdc);
}
Пример #17
0
void MapWindow::DrawRunway(HDC hdc,WAYPOINT* wp, RECT rc, double fScaleFact, BOOL picto)
{
  int solid= false;
  HPEN    oldPen  ;
  HBRUSH  oldBrush ;
  bool bGlider = false;
  bool bOutland = false;
  bool bRunway = false;
   double rwl = 5.33;
   double rwb = 1.0;
   double cir = 4.0;
  static double scale_drawradio=0;
  static double scale_bigfont=0;
  static double scale_fullinfos=0;
  int Center_x = wp->Screen.x;
  int Center_y = wp->Screen.y;
  if(picto)
  {
	  Center_x = rc.left+ (rc.right- rc.left)/2;
	  Center_y = rc.bottom +(rc.top-rc.bottom)/2;
  }
  int l,p,b;

  switch(ScreenSize) {
	case ss240x320:
	case ss320x240:
	case ss480x272:
	case ss272x480:
 	  	fScaleFact /= 800; // (*=1.6 after /= 1600 is equale to /1000)
		break;
	default:
		fScaleFact /=1600;
		break;
  }

  if (DoInit[MDI_MAPWPVECTORS])
  {
    // All values <=
    switch(ScreenSize)
    {

	case ss480x272:
		if (ScreenSizeX==854) {
			scale_drawradio=3.6;
			scale_bigfont=1.5;
			scale_fullinfos=1.5;

		} else {
			scale_drawradio=2.6;
			scale_bigfont=1.1;
			scale_fullinfos=0.8;
		}
		break;
	case ss800x480:
		scale_drawradio=2.6;
		scale_bigfont=1.5;
		scale_fullinfos=1.5;
		break;
	case ss640x480:
		scale_drawradio=3.6;
		scale_bigfont=1.5;
		scale_fullinfos=1.5;
		break;

	default:
		scale_drawradio=2.6;
		scale_bigfont=1.5;
		scale_fullinfos=1.5;
		break;
    }
    DoInit[MDI_MAPWPVECTORS]=false;
  }

  if( wp->RunwayLen > 100) /* square if no runway defined */
  {
    l = (int) (rwl * (1.0+ ((double)wp->RunwayLen/800.0-1.0)/4.0));
  } else
  {
    l = (int)( rwl*0.5);
    rwb = l ;
  }

  l = (int)(l * fScaleFact*1.1); if(l==0) l=1;
  b = (int)(rwb * fScaleFact); if(b==0) b=1;
  p = (int)(cir * (double)ScreenScale * fScaleFact); if(p==0) p=1;

  switch(wp->Style) {
	case STYLE_AIRFIELDSOLID: solid = true;  bRunway  = true;  bOutland = false;  bGlider  = false;	break;
	case STYLE_AIRFIELDGRASS: solid = false; bRunway  = true;  bOutland = false;  bGlider  = false;	break;
	case STYLE_OUTLANDING	: solid = false; bRunway  = true;  bOutland = true;   bGlider  = false; b*=2; break;
	case STYLE_GLIDERSITE	: solid = false; bRunway  = true;  bOutland = false;  bGlider  = true;	break;
	default: return; break;
  }

  oldPen   = (HPEN) SelectObject(hdc, GetStockObject(BLACK_PEN));
  oldBrush = (HBRUSH)SelectObject(hdc, LKBrush_Red);

  if( wp->Reachable == TRUE)
    SelectObject(hdc, LKBrush_Green);


  if(!bOutland)
  {
	Circle( hdc,Center_x, Center_y, p,  rc,false, true);
  }

  if(bRunway)
  {
	POINT Runway[5] = {
		  { b, l },  // 1
		  {-b, l },  // 2
		  {-b,-l },  // 3
		  { b,-l },  // 4
		  { b,l  }   // 5
	};
	if(!bOutland)
	{
	    if(solid)
	  	  SelectObject(hdc, LKBrush_DarkGrey );
	    else
		  SelectObject(hdc, LKBrush_White);
	}
	PolygonRotateShift(Runway, 5,  Center_x, Center_y,  wp->RunwayDir- (int)MapWindow::GetDisplayAngle());
	Polygon(hdc,Runway ,5 );

  } // bRunway


  if(fScaleFact >= 1.2) {
    if(bGlider)
    {
	    double fFact = 0.04*fScaleFact/1.5;
	    POINT WhiteWing [17]  = {
		  { (long)(-228  * fFact ) , (long)(13  * fFact)}, //1
		  { (long) (-221 * fFact ) , (long)(-5  * fFact)}, //2
		  { (long) (-102 * fFact ) , (long)(-50 * fFact)}, //3
		  { (long) (8	 * fFact ) , (long)( 5  * fFact)}, //4
		  { (long) (149  * fFact ) , (long)(-55 * fFact)}, //5
		  { (long) (270  * fFact ) , (long)(-12 * fFact)}, //6
		  { (long) (280  * fFact ) , (long)( 5  * fFact)}, //7
		  { (long) (152  * fFact ) , (long)(-30 * fFact)}, //8
		  { (long) (48	 * fFact ) , (long)( 27 * fFact)}, //9
		  { (long) (37	 * fFact ) , (long)( 44 * fFact)}, //10
		  { (long)(-20	 * fFact ) , (long)( 65 * fFact)}, //11
		  { (long)(-29	 * fFact ) , (long)( 80 * fFact)}, //12
		  { (long)(-56	 * fFact ) , (long)( 83 * fFact)}, //13
		  { (long)(-50	 * fFact ) , (long)( 40 * fFact)}, //14
		  { (long)(-30	 * fFact ) , (long)( 27 * fFact)}, //15
		  { (long)(-103  * fFact ) , (long)(-26 * fFact)}, //16
		  { (long)(-228  * fFact ) , (long)( 13 * fFact)}  //17
	    };
	    PolygonRotateShift(WhiteWing, 17,  Center_x, Center_y,  0/*+ wp->RunwayDir-Brg*/);
	    Polygon(hdc,WhiteWing ,17 );
    }
  }

  // StartupStore(_T(".......fscale=%f *1600=%f realscale = %f\n"), fScaleFact, fScaleFact*1600, MapWindow::zoom.RealScale());


  if( MapWindow::zoom.RealScale() <= scale_drawradio ) 
  {

	HFONT hfOld;

	if (MapWindow::zoom.RealScale() <= scale_bigfont) 
		hfOld = (HFONT)SelectObject(hdc, LK8PanelUnitFont);
	else
		hfOld = (HFONT)SelectObject(hdc, LK8UnitFont);

	if (INVERTCOLORS)
		SelectObject(hdc,LKBrush_Petrol);
	else
		SelectObject(hdc,LKBrush_LightCyan);

	unsigned int offset = p + NIBLSCALE(1) ;
	if( !picto)
	{
		if ( _tcslen(wp->Freq)>0 ) {
			MapWindow::LKWriteBoxedText(hdc,&DrawRect,wp->Freq, Center_x- offset, Center_y -offset, 0, WTALIGN_RIGHT, RGB_WHITE, RGB_BLACK);
		}

		//
		// Full infos! 1.5km scale
		//
		if (MapWindow::zoom.RealScale() <=scale_fullinfos) {
			if ( _tcslen(wp->Code)==4 ) {
				MapWindow::LKWriteBoxedText(hdc,&DrawRect,wp->Code,Center_x + offset, Center_y - offset, 0, WTALIGN_LEFT, RGB_WHITE,RGB_BLACK);
			}

			if (wp->Altitude >0) {
				TCHAR tAlt[20];
				_stprintf(tAlt,_T("%.0f %s"),wp->Altitude*ALTITUDEMODIFY,Units::GetUnitName(Units::GetUserAltitudeUnit()));
				MapWindow::LKWriteBoxedText(hdc,&DrawRect,tAlt, Center_x + offset, Center_y + offset, 0, WTALIGN_LEFT, RGB_WHITE, RGB_BLACK);
			}

		}
	}
	SelectObject(hdc, hfOld);

  }



  SelectObject(hdc, oldPen);
  SelectObject(hdc, oldBrush);

}
Пример #18
0
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
	HDC hdc;
	PAINTSTRUCT ps;
	RECT rect;
	HBRUSH hBrush;

	int i;
	static POINT pts[4]={120,150,170,150,170,200,120,200};
	HWND hwndChild;
	static POINT center,rectangleCenter;
	static int timerOn,figure,color; //figure =1 -square, =2 triangle, =3 circle; similar to color

	switch(message)
	{
	case WM_CREATE:

		center.x=320;
		center.y=200;

	
		for (i=0; i<4; i++)
		{
			rectangleCenter.x+=pts[i].x;
			rectangleCenter.y+=pts[i].y;
		}
		rectangleCenter.x/=4;
		rectangleCenter.y/=4;

		distance=computeDistance(rectangleCenter,center);

		timerOn=0;
		figure=0;
		color=0;
		CreateWindow(TEXT("button"),
			TEXT("Rotate"),
			WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
			10,
			10,
			100,
			40,
			hwnd,
			(HMENU)0,
			((LPCREATESTRUCT)lParam)->hInstance,
			NULL);

		CreateWindow(TEXT("button"),
			TEXT("Stop"),
			WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
			10,
			60,
			100,
			40,
			hwnd,
			(HMENU)1,
			((LPCREATESTRUCT)lParam)->hInstance,
			NULL);

		CreateWindow(TEXT("button"),
			TEXT("Sqare"),
			WS_CHILD|WS_VISIBLE|BS_RADIOBUTTON,
			10,
			110,
			100,
			40,
			hwnd,
			(HMENU)2,
			((LPCREATESTRUCT)lParam)->hInstance,
			NULL);

		CreateWindow(TEXT("button"),
			TEXT("Triangle"),
			WS_CHILD|WS_VISIBLE|BS_RADIOBUTTON,
			10,
			150,
			100,
			40,
			hwnd,
			(HMENU)3,
			((LPCREATESTRUCT)lParam)->hInstance,
			NULL);

		CreateWindow(TEXT("button"),
			TEXT("Circle"),
			WS_CHILD|WS_VISIBLE|BS_RADIOBUTTON,
			10,
			190,
			100,
			40,
			hwnd,
			(HMENU)4,
			((LPCREATESTRUCT)lParam)->hInstance,
			NULL);

		CreateWindow(TEXT("button"),
			TEXT("Red"),
			WS_CHILD|WS_VISIBLE|BS_CHECKBOX|BS_AUTOCHECKBOX,
			10,
			250,
			100,
			40,
			hwnd,
			(HMENU)5,
			((LPCREATESTRUCT)lParam)->hInstance,
			NULL);

		CreateWindow(TEXT("button"),
			TEXT("Green"),
			WS_CHILD|WS_VISIBLE|BS_CHECKBOX|BS_AUTOCHECKBOX,
			10,
			290,
			100,
			40,
			hwnd,
			(HMENU)6,
			((LPCREATESTRUCT)lParam)->hInstance,
			NULL);

		CreateWindow(TEXT("button"),
			TEXT("Blue"),
			WS_CHILD|WS_VISIBLE|BS_CHECKBOX|BS_AUTOCHECKBOX,
			10,
			330,
			100,
			40,
			hwnd,
			(HMENU)7,
			((LPCREATESTRUCT)lParam)->hInstance,
			NULL);

		return 0;

	case WM_COMMAND:
		switch(LOWORD(wParam))
		{
		case 0: //Rotate
			timerOn=1;
			SetTimer(hwnd,1,100,NULL);
			//MessageBox(hwnd,TEXT("0"),NULL,NULL);
			break;

		case 1: //Stop
			
			if (timerOn) KillTimer(hwnd,1);
			timerOn=0;
			//MessageBox(hwnd,TEXT("1"),NULL,NULL);
			break;

		case 2: //Sqare
			figure=1;
			hwndChild=GetDlgItem(hwnd,3);
			SendMessage(hwndChild,BM_SETCHECK,0,0);

			hwndChild=GetDlgItem(hwnd,4);
			SendMessage(hwndChild,BM_SETCHECK,0,0);

			SendMessage((HWND)lParam,BM_SETCHECK,1,0);
			break;

		case 3: //Triangle
			figure=2;
			hwndChild=GetDlgItem(hwnd,2);
			SendMessage(hwndChild,BM_SETCHECK,0,0);

			hwndChild=GetDlgItem(hwnd,4);
			SendMessage(hwndChild,BM_SETCHECK,0,0);

			SendMessage((HWND)lParam,BM_SETCHECK,1,0);
			break;

		case 4://Circle
			figure=3;
			hwndChild=GetDlgItem(hwnd,3);
			SendMessage(hwndChild,BM_SETCHECK,0,0);

			hwndChild=GetDlgItem(hwnd,2);
			SendMessage(hwndChild,BM_SETCHECK,0,0);

			SendMessage((HWND)lParam,BM_SETCHECK,1,0);
			break;
		
		case 5://Red
			if (SendMessage((HWND)lParam,BM_GETCHECK,0,0))
			{
				color=1;
				hwndChild=GetDlgItem(hwnd,6);
				EnableWindow(hwndChild,FALSE);

				hwndChild=GetDlgItem(hwnd,7);
				EnableWindow(hwndChild,FALSE);
			}
			else
			{
				color=0;
				hwndChild=GetDlgItem(hwnd,6);
				EnableWindow(hwndChild,TRUE);

				hwndChild=GetDlgItem(hwnd,7);
				EnableWindow(hwndChild,TRUE);
			}

		break;
		
		case 6://Green
			if (SendMessage((HWND)lParam,BM_GETCHECK,0,0))
			{
				color=2;
				hwndChild=GetDlgItem(hwnd,5);
				EnableWindow(hwndChild,FALSE);

				hwndChild=GetDlgItem(hwnd,7);
				EnableWindow(hwndChild,FALSE);
			}
			else
			{
				color=0;
				hwndChild=GetDlgItem(hwnd,5);
				EnableWindow(hwndChild,TRUE);

				hwndChild=GetDlgItem(hwnd,7);
				EnableWindow(hwndChild,TRUE);
			}

		break;

		case 7://blue
			if (SendMessage((HWND)lParam,BM_GETCHECK,0,0))
			{
				color=3;
				hwndChild=GetDlgItem(hwnd,6);
				EnableWindow(hwndChild,FALSE);

				hwndChild=GetDlgItem(hwnd,5);
				EnableWindow(hwndChild,FALSE);
			}
			else
			{
				color=0;
				hwndChild=GetDlgItem(hwnd,6);
				EnableWindow(hwndChild,TRUE);

				hwndChild=GetDlgItem(hwnd,5);
				EnableWindow(hwndChild,TRUE);
			}


		break;
		}
		SetRect(&rect,120,0,520,400);
		InvalidateRect(hwnd,&rect,TRUE);
		return 0;

	case WM_TIMER:
		rotatePoint(&rectangleCenter,0.15,center);
		pts[0].x=rectangleCenter.x-25;
		pts[0].y=rectangleCenter.y-25;
		pts[1].x=rectangleCenter.x+25;
		pts[1].y=pts[0].y;
		pts[2].x=pts[1].x;
		pts[2].y=rectangleCenter.y+25;
		pts[3].x=pts[0].x;
		pts[3].y=pts[2].y;
		SetRect(&rect,120,0,520,400);
		InvalidateRect(hwnd,&rect,TRUE);
		return 0;

	case WM_PAINT:
		hdc=BeginPaint(hwnd,&ps);
		hBrush=NULL;
		if (color==1)
		{
			hBrush=CreateSolidBrush(RGB(255,0,0));
		}
		else if (color==2)
		{
			hBrush=CreateSolidBrush(RGB(0,255,0));
		}
		else if (color==3)
		{
			hBrush=CreateSolidBrush(RGB(0,0,255));
		}
		if (figure==1)
		{
			SelectObject(hdc,hBrush);
			Polygon(hdc,pts,4);
		}
		else if (figure==2)
		{
			POINT pts1[3];
			pts1[0].x=(pts[0].x+pts[1].x)/2;
			pts1[0].y=pts[0].y;
			pts1[1]=pts[2];
			pts1[2]=pts[3];

			SelectObject(hdc,hBrush);
			Polygon(hdc,pts1,3);
		}
		else if(figure==3)
		{
			SelectObject(hdc,hBrush);
			Ellipse(hdc,pts[0].x,pts[0].y,pts[2].x,pts[2].y);
		}

		if (color!=0) DeleteObject(hBrush);
		EndPaint(hwnd,&ps);
		return 0;

	case WM_DESTROY:
		PostQuitMessage(0);
		return 0;
	}

	return DefWindowProc(hwnd,message,wParam,lParam);
	
}
Пример #19
0
void fnSeconds(int iDigit, int iPlace, HWND hWnd)
{
    int iTranslate, iIdx;
    BOOL bOnIndex[7];

    POINT PT1[6];
    POINT PT2[6];
    POINT PT3[6];
    POINT PT4[6];
    POINT PT5[6];
    POINT PT6[6];
    POINT PT7[6];
    POINT CN1[4];
    POINT CN2[4];

    POINT *PT[7];

    HDC hDC;
    HBRUSH hDigitBrush[7];
    HANDLE hDigitPen[7];

    hDC = 0;

    for(iIdx = 0; iIdx < 7; iIdx++)
        bOnIndex[iIdx] = FALSE;

    switch (iDigit)
    {
    case 0:
        bOnIndex[0] = TRUE;
        bOnIndex[1] = TRUE;
        bOnIndex[2] = TRUE;
        bOnIndex[3] = TRUE;
        bOnIndex[4] = TRUE;
        bOnIndex[5] = TRUE;
        break;
    case 1:
        bOnIndex[0] = TRUE;
        bOnIndex[1] = TRUE;
        break;
    case 2:
        bOnIndex[0] = TRUE;
        bOnIndex[2] = TRUE;
        bOnIndex[3] = TRUE;
        bOnIndex[5] = TRUE;
        bOnIndex[6] = TRUE;
        break;
    case 3:
        bOnIndex[0] = TRUE;
        bOnIndex[1] = TRUE;
        bOnIndex[2] = TRUE;
        bOnIndex[5] = TRUE;
        bOnIndex[6] = TRUE;
        break;
    case 4:
        bOnIndex[0] = TRUE;
        bOnIndex[1] = TRUE;
        bOnIndex[4] = TRUE;
        bOnIndex[6] = TRUE;
        break;
    case 5:
        bOnIndex[1] = TRUE;
        bOnIndex[2] = TRUE;
        bOnIndex[4] = TRUE;
        bOnIndex[5] = TRUE;
        bOnIndex[6] = TRUE;
        break;
    case 6:
        bOnIndex[1] = TRUE;
        bOnIndex[2] = TRUE;
        bOnIndex[3] = TRUE;
        bOnIndex[4] = TRUE;
        bOnIndex[5] = TRUE;
        bOnIndex[6] = TRUE;
        break;
    case 7:
        bOnIndex[0] = TRUE;
        bOnIndex[1] = TRUE;
        bOnIndex[5] = TRUE;
        break;
    case 8:
        bOnIndex[0] = TRUE;
        bOnIndex[1] = TRUE;
        bOnIndex[2] = TRUE;
        bOnIndex[3] = TRUE;
        bOnIndex[4] = TRUE;
        bOnIndex[5] = TRUE;
        bOnIndex[6] = TRUE;
        break;
    case 9:
        bOnIndex[0] = TRUE;
        bOnIndex[1] = TRUE;
        bOnIndex[2] = TRUE;
        bOnIndex[4] = TRUE;
        bOnIndex[5] = TRUE;
        bOnIndex[6] = TRUE;
        break;
    }

    for(iIdx = 0; iIdx < 7; iIdx++)
    {
        if(bOnIndex[iIdx])
        {
            hDigitBrush[iIdx] = CreateSolidBrush(crDigitColor);
            hDigitPen[iIdx] = CreatePen(PS_SOLID, 0, crDigitColor);
        }
        else
        {
            hDigitBrush[iIdx] = CreateSolidBrush(crWndColor);
            hDigitPen[iIdx] = CreatePen(PS_SOLID, 0, crWndColor);
        }
    }
    hDC = GetDC(hWnd);

    PT[0] = PT1;
    PT[1] = PT2;
    PT[2] = PT3;
    PT[3] = PT4;
    PT[4] = PT5;
    PT[5] = PT6;
    PT[6] = PT7;


    switch (iPlace)
    {
    case 0:
        iTranslate = 400;
        break;
    case 1:
        iTranslate = 350;
        break;
    }
    PT1[0].x = iTranslate + 28;
    PT1[0].y = 73;
    PT1[1].x = iTranslate + 31;
    PT1[1].y = 76;
    PT1[2].x = iTranslate + 31;
    PT1[2].y = 91;
    PT1[3].x = iTranslate + 28;
    PT1[3].y = 94;
    PT1[4].x = iTranslate + 25;
    PT1[4].y = 91;
    PT1[5].x = iTranslate + 25;
    PT1[5].y = 76;

    PT2[0].x = iTranslate + 28;
    PT2[0].y = 98;
    PT2[1].x = iTranslate + 31;
    PT2[1].y = 101;
    PT2[2].x = iTranslate + 31;
    PT2[2].y = 116;
    PT2[3].x = iTranslate + 28;
    PT2[3].y = 119;
    PT2[4].x = iTranslate + 25;
    PT2[4].y = 116;
    PT2[5].x = iTranslate + 25;
    PT2[5].y = 101;

    PT3[0].x = iTranslate + 26;
    PT3[0].y = 121;
    PT3[1].x = iTranslate + 23;
    PT3[1].y = 124;
    PT3[2].x = iTranslate + 8;
    PT3[2].y = 124;
    PT3[3].x = iTranslate + 5;
    PT3[3].y = 121;
    PT3[4].x = iTranslate + 8;
    PT3[4].y = 118;
    PT3[5].x = iTranslate + 23;
    PT3[5].y = 118;

    PT4[0].x = iTranslate + 3;
    PT4[0].y = 98;
    PT4[1].x = iTranslate + 6;
    PT4[1].y = 101;
    PT4[2].x = iTranslate + 6;
    PT4[2].y = 116;
    PT4[3].x = iTranslate + 3;
    PT4[3].y = 119;
    PT4[4].x = iTranslate + 0;
    PT4[4].y = 116;
    PT4[5].x = iTranslate + 0;
    PT4[5].y = 101;

    PT5[0].x = iTranslate + 3;
    PT5[0].y = 73;
    PT5[1].x = iTranslate + 6;
    PT5[1].y = 76;
    PT5[2].x = iTranslate + 6;
    PT5[2].y = 91;
    PT5[3].x = iTranslate + 3;
    PT5[3].y = 94;
    PT5[4].x = iTranslate + 0;
    PT5[4].y = 91;
    PT5[5].x = iTranslate + 0;
    PT5[5].y = 76;

    PT6[0].x = iTranslate + 26;
    PT6[0].y = 71;
    PT6[1].x = iTranslate + 23;
    PT6[1].y = 74;
    PT6[2].x = iTranslate + 8;
    PT6[2].y = 74;
    PT6[3].x = iTranslate + 5;
    PT6[3].y = 71;
    PT6[4].x = iTranslate + 8;
    PT6[4].y = 68;
    PT6[5].x = iTranslate + 23;
    PT6[5].y = 68;

    PT7[0].x = iTranslate + 26;
    PT7[0].y = 96;
    PT7[1].x = iTranslate + 23;
    PT7[1].y = 99;
    PT7[2].x = iTranslate + 8;
    PT7[2].y = 99;
    PT7[3].x = iTranslate + 5;
    PT7[3].y = 96;
    PT7[4].x = iTranslate + 8;
    PT7[4].y = 93;
    PT7[5].x = iTranslate + 23;
    PT7[5].y = 93;

    for(iIdx = 0; iIdx < 7; iIdx++)
    {
        SelectObject(hDC, hDigitBrush[iIdx]);
        SelectObject(hDC, hDigitPen[iIdx]);
        Polygon(hDC, PT[iIdx], 6);
    }

    for(iIdx = 0; iIdx < 7; iIdx++)
    {
        DeleteObject(hDigitBrush[iIdx]);
        CloseHandle(hDigitPen[iIdx]);
        DeleteObject(hDigitPen[iIdx]);
    }

    ReleaseDC(hWnd, hDC);
    return;
}
Пример #20
0
VOID
DrawCpuBarGraph(
    HDC             hDC,
    PDISPLAY_ITEM   DisplayItem,
    UINT            Item

)
/*++

Routine Description:

    Draw a 3-d like CPU bar graph into the perf window

Arguments:

    hDC         - Device Context for window
    DisplayItem - Data structure with all perf window info

Return Value:

   status of operation


Revision History:

      03-21-91      Initial code

--*/

{
    RECT    GraphRect,DrawRect;
    ULONG   i,GraphWidth,GraphHeight,CpuGraphHeight;
    ULONG   BarWidth,BarHeight,tHeight,kHeight,uHeight,dHeight,iHeight;
    POINT   PolyPoint[4];
    HPEN    hOldPen;
    UINT    FontSize;
    UCHAR   TextStr[100];
    ULONG   nItems,UserBase, KerBase, DPCbase, TotBase, IntBase;


    nItems = 5;

    GraphRect.left   = DisplayItem->GraphBorder.left   + 1;
    GraphRect.right  = DisplayItem->GraphBorder.right  - 1;
    GraphRect.top    = DisplayItem->GraphBorder.top    + 1;
    GraphRect.bottom = DisplayItem->GraphBorder.bottom - 1;

    GraphWidth  = GraphRect.right  - GraphRect.left;
    GraphHeight = GraphRect.bottom - GraphRect.top;


    BarWidth   = GraphWidth/((nItems*4)+4);
    BarHeight  = GraphHeight/((nItems*4)+4);

    CpuGraphHeight = GraphHeight - 2 * BarHeight;

    //
    // Jump Out if window is too small
    //

    if (BarWidth == 0) {
        return;
    }

    //
    // Calculate Heights
    //

    uHeight = (DisplayItem->UserTime[0] * CpuGraphHeight)/ DisplayItem->Max;
    UserBase = 2;
    kHeight = (DisplayItem->KernelTime[0] * CpuGraphHeight)/ DisplayItem->Max;
    KerBase = 6;
    dHeight = (DisplayItem->DpcTime[0] * CpuGraphHeight)/ DisplayItem->Max;
    DPCbase = 10;
    iHeight = (DisplayItem->InterruptTime[0] * CpuGraphHeight)/ DisplayItem->Max;
    IntBase = 14;
    tHeight = (DisplayItem->TotalTime[0] * CpuGraphHeight)/ DisplayItem->Max;
    TotBase = 18;

    DrawRect.left   = 0;
    DrawRect.right  = GraphWidth;
    DrawRect.top    = 0;
    DrawRect.bottom = GraphHeight;

    FillRect(DisplayItem->MemoryDC,&DrawRect,WinperfInfo.hBackground);
    SelectObject(DisplayItem->MemoryDC,GetStockObject(GRAY_BRUSH));

    //
    // Draw Background, face 1 (left side)
    //

    PolyPoint[0].x = DrawRect.left + BarWidth;
    PolyPoint[0].y = DrawRect.bottom    - (BarHeight/2);

    PolyPoint[1].x = DrawRect.left + BOX_DEPTH*BarWidth;
    PolyPoint[1].y = DrawRect.bottom    - (BOX_DEPTH*BarHeight/2);

    PolyPoint[2].x = DrawRect.left + BOX_DEPTH*BarWidth;
    PolyPoint[2].y = DrawRect.bottom    - (GraphHeight - BarHeight/2);

    PolyPoint[3].x = DrawRect.left + BarWidth;
    PolyPoint[3].y = DrawRect.bottom    - (GraphHeight - BOX_DEPTH*BarHeight/2);

    Polygon(DisplayItem->MemoryDC,&PolyPoint[0],4);

    //
    // Draw Background, face 2 (bottom)
    //

    PolyPoint[0].x = DrawRect.left + BarWidth;
    PolyPoint[0].y = DrawRect.bottom    - (BarHeight/2);

    //  Left line
    PolyPoint[1].x = DrawRect.left + BOX_DEPTH*BarWidth;
    PolyPoint[1].y = DrawRect.bottom    - (BOX_DEPTH*BarHeight/2);

    //  Back line
    PolyPoint[2].x = DrawRect.left + (nItems*4+2)*BarWidth;
    PolyPoint[2].y = DrawRect.bottom    - (BOX_DEPTH*BarHeight/2);

    //	Bottom line.
    PolyPoint[3].x = DrawRect.left + (nItems*4)*BarWidth;
    PolyPoint[3].y = DrawRect.bottom    - (BarHeight/2);

    Polygon(DisplayItem->MemoryDC,&PolyPoint[0],4);

    //
    // Draw Background, face 3 (Back Side)
    //

    PolyPoint[0].x = DrawRect.left + BOX_DEPTH*BarWidth;
    PolyPoint[0].y = DrawRect.bottom    - (BOX_DEPTH*BarHeight/2);

    PolyPoint[1].x = DrawRect.left + BOX_DEPTH*BarWidth;
    PolyPoint[1].y = DrawRect.bottom   - (GraphHeight - BarHeight/2);

    PolyPoint[2].x = DrawRect.left + (nItems*4+2)*BarWidth;
    PolyPoint[2].y = DrawRect.bottom    - (GraphHeight - BarHeight/2);

    PolyPoint[3].x = DrawRect.left + (nItems*4+2)*BarWidth;
    PolyPoint[3].y = DrawRect.bottom    - ((BOX_DEPTH*BarHeight)/2);

    Polygon(DisplayItem->MemoryDC,&PolyPoint[0],4);

    //
    // Draw Scale Lines if the window height is large ( > 200)
    //


    if ((DrawRect.bottom - DrawRect.top) > 200) {

        hOldPen = SelectObject(DisplayItem->MemoryDC,WinperfInfo.hDotPen);
        SetBkMode(DisplayItem->MemoryDC,TRANSPARENT);

        //
        //	Back
        //

        for (i=1; i<10; i++) {
            MoveToEx(DisplayItem->MemoryDC,
                     BOX_DEPTH*BarWidth,
                     DrawRect.bottom  - (BOX_DEPTH*BarHeight/2 + (i*CpuGraphHeight/10)),
                     NULL
                    );

            LineTo(DisplayItem->MemoryDC,
                   (nItems*4+2)*BarWidth,
                   DrawRect.bottom  - (BOX_DEPTH*BarHeight/2 + (i*CpuGraphHeight/10))
                  );
        }

        //
        //	Left Side
        //

        for (i=1; i<10; i++) {
            MoveToEx(DisplayItem->MemoryDC,
                     BarWidth,
                     DrawRect.bottom  - (BarHeight/2 + (i*CpuGraphHeight/10)),
                     NULL
                    );

            LineTo(DisplayItem->MemoryDC,
                   BOX_DEPTH*BarWidth,
                   DrawRect.bottom  - (BOX_DEPTH*BarHeight/2 + (i*CpuGraphHeight/10))
                  );
        }


        SelectObject(DisplayItem->MemoryDC,hOldPen);
    }

    //
    //  Draw CPU User time BOX, face
    //

    SelectObject(DisplayItem->MemoryDC,WinperfInfo.hGreenBrush);

    PolyPoint[0].x = DrawRect.left + (UserBase)*BarWidth;
    PolyPoint[0].y = DrawRect.bottom    - (BarHeight);

    PolyPoint[1].x = DrawRect.left + (UserBase+2)*BarWidth;
    PolyPoint[1].y = DrawRect.bottom   - (BarHeight);

    PolyPoint[2].x = DrawRect.left + (UserBase+2)*BarWidth;
    PolyPoint[2].y = DrawRect.bottom  - (uHeight + BarHeight);

    PolyPoint[3].x = DrawRect.left + (UserBase)*BarWidth;
    PolyPoint[3].y = DrawRect.bottom  - (uHeight + BarHeight);

    Polygon(DisplayItem->MemoryDC,&PolyPoint[0],4);

    //
    // Draw User Box Side
    //

    PolyPoint[0].x = DrawRect.left + (UserBase+2)*BarWidth;
    PolyPoint[0].y = DrawRect.bottom    - (BarHeight);

    PolyPoint[1].x = DrawRect.left + (UserBase+BOX_DEPTH)*BarWidth;
    PolyPoint[1].y = DrawRect.bottom   - (3*BarHeight/2);

    PolyPoint[2].x = DrawRect.left + (UserBase+BOX_DEPTH)*BarWidth;
    PolyPoint[2].y = DrawRect.bottom  - (3*BarHeight/2 + uHeight);

    PolyPoint[3].x = DrawRect.left + (UserBase+2)*BarWidth;
    PolyPoint[3].y = DrawRect.bottom  - (BarHeight + uHeight);

    Polygon(DisplayItem->MemoryDC,&PolyPoint[0],4);

    //
    // Draw User Box Top
    //

    PolyPoint[0].x = DrawRect.left + (UserBase)*BarWidth;
    PolyPoint[0].y = DrawRect.bottom - (uHeight +  BarHeight);

    PolyPoint[1].x = DrawRect.left + (UserBase+2)*BarWidth;
    PolyPoint[1].y = DrawRect.bottom - (uHeight + BarHeight);

    PolyPoint[2].x = DrawRect.left + (UserBase+BOX_DEPTH)*BarWidth;
    PolyPoint[2].y = DrawRect.bottom  - (uHeight + 3*BarHeight/2);

    PolyPoint[3].x = DrawRect.left + (UserBase+1)*BarWidth;
    PolyPoint[3].y = DrawRect.bottom  - (uHeight + 3*BarHeight/2);

    Polygon(DisplayItem->MemoryDC,&PolyPoint[0],4);

    //
    //  Draw CPU Kernel time BOX, face
    //

    SelectObject(DisplayItem->MemoryDC,WinperfInfo.hRedBrush);

    PolyPoint[0].x = DrawRect.left + (KerBase)*BarWidth;
    PolyPoint[0].y = DrawRect.bottom    - (BarHeight);

    PolyPoint[1].x = DrawRect.left + (KerBase+2)*BarWidth;
    PolyPoint[1].y = DrawRect.bottom   - (BarHeight);

    PolyPoint[2].x = DrawRect.left + (KerBase+2)*BarWidth;
    PolyPoint[2].y = DrawRect.bottom  - ( kHeight + BarHeight);

    PolyPoint[3].x = DrawRect.left + (KerBase)*BarWidth;
    PolyPoint[3].y = DrawRect.bottom  - (kHeight + BarHeight);

    Polygon(DisplayItem->MemoryDC,&PolyPoint[0],4);

    //
    // Draw Kernel Box Side
    //

    PolyPoint[0].x = DrawRect.left + (KerBase+2)*BarWidth;
    PolyPoint[0].y = DrawRect.bottom    - (BarHeight);

    PolyPoint[1].x = DrawRect.left + (KerBase+3)*BarWidth;
    PolyPoint[1].y = DrawRect.bottom   - (3*BarHeight/2);

    PolyPoint[2].x = DrawRect.left + (KerBase+3)*BarWidth;
    PolyPoint[2].y = DrawRect.bottom  - (3*BarHeight/2 +kHeight);

    PolyPoint[3].x = DrawRect.left + (KerBase+2)*BarWidth;
    PolyPoint[3].y = DrawRect.bottom  - (kHeight + BarHeight);

    Polygon(DisplayItem->MemoryDC,&PolyPoint[0],4);

    //
    // Draw Kernel Box Top
    //

    PolyPoint[0].x = DrawRect.left + (KerBase)*BarWidth;
    PolyPoint[0].y = DrawRect.bottom - (kHeight + BarHeight);

    PolyPoint[1].x = DrawRect.left + (KerBase+2)*BarWidth;
    PolyPoint[1].y = DrawRect.bottom - (kHeight + BarHeight);

    PolyPoint[2].x = DrawRect.left + (KerBase+3)*BarWidth;
    PolyPoint[2].y = DrawRect.bottom  - (kHeight + 3*BarHeight/2);

    PolyPoint[3].x = DrawRect.left + (KerBase+1)*BarWidth;
    PolyPoint[3].y = DrawRect.bottom  - (kHeight + 3*BarHeight/2);

    Polygon(DisplayItem->MemoryDC,&PolyPoint[0],4);

    //
    //  Draw CPU DPC time BOX, face
    //

    SelectObject(DisplayItem->MemoryDC,WinperfInfo.hYellowBrush);

    PolyPoint[0].x = DrawRect.left + (DPCbase)*BarWidth;
    PolyPoint[0].y = DrawRect.bottom    - (BarHeight);

    PolyPoint[1].x = DrawRect.left + (DPCbase+2)*BarWidth;
    PolyPoint[1].y = DrawRect.bottom   - (BarHeight);

    PolyPoint[2].x = DrawRect.left + (DPCbase+2)*BarWidth;
    PolyPoint[2].y = DrawRect.bottom  - ( dHeight + BarHeight);

    PolyPoint[3].x = DrawRect.left + (DPCbase)*BarWidth;
    PolyPoint[3].y = DrawRect.bottom  - (dHeight + BarHeight);

    Polygon(DisplayItem->MemoryDC,&PolyPoint[0],4);

    //
    // Draw DPC Box Side
    //

    PolyPoint[0].x = DrawRect.left + (DPCbase+2)*BarWidth;
    PolyPoint[0].y = DrawRect.bottom    - (BarHeight);

    PolyPoint[1].x = DrawRect.left + (DPCbase+3)*BarWidth;
    PolyPoint[1].y = DrawRect.bottom   - (3*BarHeight/2);

    PolyPoint[2].x = DrawRect.left + (DPCbase+3)*BarWidth;
    PolyPoint[2].y = DrawRect.bottom  - (3*BarHeight/2 +dHeight);

    PolyPoint[3].x = DrawRect.left + (DPCbase+2)*BarWidth;
    PolyPoint[3].y = DrawRect.bottom  - (dHeight + BarHeight);

    Polygon(DisplayItem->MemoryDC,&PolyPoint[0],4);

    //
    // Draw DPC Box Top
    //

    PolyPoint[0].x = DrawRect.left + (DPCbase)*BarWidth;
    PolyPoint[0].y = DrawRect.bottom - (dHeight + BarHeight);

    PolyPoint[1].x = DrawRect.left + (DPCbase+2)*BarWidth;
    PolyPoint[1].y = DrawRect.bottom - (dHeight + BarHeight);

    PolyPoint[2].x = DrawRect.left + (DPCbase+3)*BarWidth;
    PolyPoint[2].y = DrawRect.bottom  - (dHeight + 3*BarHeight/2);

    PolyPoint[3].x = DrawRect.left + (DPCbase+1)*BarWidth;
    PolyPoint[3].y = DrawRect.bottom  - (dHeight + 3*BarHeight/2);

    Polygon(DisplayItem->MemoryDC,&PolyPoint[0],4);

    //
    //  Draw CPU Interrupt time BOX, face
    //

    SelectObject(DisplayItem->MemoryDC,WinperfInfo.hMagentaBrush);

    PolyPoint[0].x = DrawRect.left + (IntBase)*BarWidth;
    PolyPoint[0].y = DrawRect.bottom    - (BarHeight);

    PolyPoint[1].x = DrawRect.left + (IntBase+2)*BarWidth;
    PolyPoint[1].y = DrawRect.bottom   - (BarHeight);

    PolyPoint[2].x = DrawRect.left + (IntBase+2)*BarWidth;
    PolyPoint[2].y = DrawRect.bottom  - ( iHeight + BarHeight);

    PolyPoint[3].x = DrawRect.left + (IntBase)*BarWidth;
    PolyPoint[3].y = DrawRect.bottom  - (iHeight + BarHeight);

    Polygon(DisplayItem->MemoryDC,&PolyPoint[0],4);

    //
    // Draw Interrupt Box Side
    //

    PolyPoint[0].x = DrawRect.left + (IntBase+2)*BarWidth;
    PolyPoint[0].y = DrawRect.bottom    - (BarHeight);

    PolyPoint[1].x = DrawRect.left + (IntBase+3)*BarWidth;
    PolyPoint[1].y = DrawRect.bottom   - (3*BarHeight/2);

    PolyPoint[2].x = DrawRect.left + (IntBase+3)*BarWidth;
    PolyPoint[2].y = DrawRect.bottom  - (3*BarHeight/2 +iHeight);

    PolyPoint[3].x = DrawRect.left + (IntBase+2)*BarWidth;
    PolyPoint[3].y = DrawRect.bottom  - (iHeight + BarHeight);

    Polygon(DisplayItem->MemoryDC,&PolyPoint[0],4);

    //
    // Draw Interrupt Box Top
    //

    PolyPoint[0].x = DrawRect.left + (IntBase)*BarWidth;
    PolyPoint[0].y = DrawRect.bottom - (iHeight + BarHeight);

    PolyPoint[1].x = DrawRect.left + (IntBase+2)*BarWidth;
    PolyPoint[1].y = DrawRect.bottom - (iHeight + BarHeight);

    PolyPoint[2].x = DrawRect.left + (IntBase+3)*BarWidth;
    PolyPoint[2].y = DrawRect.bottom  - (iHeight + 3*BarHeight/2);

    PolyPoint[3].x = DrawRect.left + (IntBase+1)*BarWidth;
    PolyPoint[3].y = DrawRect.bottom  - (iHeight + 3*BarHeight/2);

    Polygon(DisplayItem->MemoryDC,&PolyPoint[0],4);

    //
    //  Draw CPU Total time BOX, face
    //

    SelectObject(DisplayItem->MemoryDC,WinperfInfo.hBlueBrush);

    PolyPoint[0].x = DrawRect.left + (TotBase)*BarWidth;
    PolyPoint[0].y = DrawRect.bottom    - (BarHeight);

    PolyPoint[1].x = DrawRect.left + (TotBase+2)*BarWidth;
    PolyPoint[1].y = DrawRect.bottom   - (BarHeight);

    PolyPoint[2].x = DrawRect.left + (TotBase+2)*BarWidth;
    PolyPoint[2].y = DrawRect.bottom  - ( tHeight + BarHeight);

    PolyPoint[3].x = DrawRect.left + (TotBase)*BarWidth;
    PolyPoint[3].y = DrawRect.bottom  - (tHeight + BarHeight);

    Polygon(DisplayItem->MemoryDC,&PolyPoint[0],4);

    //
    // Draw CPU Total Box Side
    //

    PolyPoint[0].x = DrawRect.left + (TotBase+2)*BarWidth;
    PolyPoint[0].y = DrawRect.bottom    - (BarHeight);

    PolyPoint[1].x = DrawRect.left + (TotBase+3)*BarWidth;
    PolyPoint[1].y = DrawRect.bottom   - (3*BarHeight/2);

    PolyPoint[2].x = DrawRect.left + (TotBase+3)*BarWidth;
    PolyPoint[2].y = DrawRect.bottom  - (3*BarHeight/2 + tHeight);

    PolyPoint[3].x = DrawRect.left + (TotBase+2)*BarWidth;
    PolyPoint[3].y = DrawRect.bottom  - (tHeight + BarHeight);

    Polygon(DisplayItem->MemoryDC,&PolyPoint[0],4);

    //
    // Draw Kernel Box Top
    //

    PolyPoint[0].x = DrawRect.left + (TotBase)*BarWidth;
    PolyPoint[0].y = DrawRect.bottom - (tHeight + BarHeight);

    PolyPoint[1].x = DrawRect.left + (TotBase+2)*BarWidth;
    PolyPoint[1].y = DrawRect.bottom - (tHeight + BarHeight);

    PolyPoint[2].x = DrawRect.left + (TotBase+3)*BarWidth;
    PolyPoint[2].y = DrawRect.bottom  - (tHeight + 3*BarHeight/2);

    PolyPoint[3].x = DrawRect.left + (TotBase+1)*BarWidth;
    PolyPoint[3].y = DrawRect.bottom  - (tHeight + 3*BarHeight/2);

    Polygon(DisplayItem->MemoryDC,&PolyPoint[0],4);

    //
    // Update screen with memory image
    //

    BitBlt(
        hDC,
        GraphRect.left,
        GraphRect.top,
        GraphWidth,
        GraphHeight,
        DisplayItem->MemoryDC,
        0,
        0,
        SRCCOPY);

    //
    // Draw Text output for CPU bar-graph window
    //


    DrawRect.left = DisplayItem->TextBorder.left +2;
    DrawRect.right = DisplayItem->TextBorder.right -2;
    DrawRect.top = DisplayItem->TextBorder.top +1;
    DrawRect.bottom = DisplayItem->TextBorder.bottom -1;

    FillRect(hDC,&DrawRect,WinperfInfo.hBackground);

    SetBkColor(hDC,RGB(192,192,192));

    //
    //  Decide which font to draw with
    //

    FontSize =  DrawRect.bottom - DrawRect.top;

    if (FontSize >= 15) {
        WinperfInfo.hOldFont = SelectObject(hDC,WinperfInfo.LargeFont);
    } else if (FontSize > 10) {
        WinperfInfo.hOldFont = SelectObject(hDC,WinperfInfo.MediumFont);
    } else {
        WinperfInfo.hOldFont = SelectObject(hDC,WinperfInfo.SmallFont);

    }

    strcpy(TextStr,PerfNames[Item]);

    if ((DrawRect.right - DrawRect.left) > 120) {
        strcat(TextStr," User,Kernel,Dpc,Int,Total");
    } else {
        strcat(TextStr," U K D I T");
    }

    DrawText(
        hDC,
        TextStr,
        strlen(TextStr),
        &DrawRect,
        DT_LEFT | DT_VCENTER | DT_SINGLELINE
    );



}
Пример #21
0
void Scene::FlatFacet (Facet& f)
//
// If shading is 'Flat' the facet is drawn using flat shading, otherwise
// if shading is 'false' it will be filled with the background color. 
//
// Uses the global intermediate storage array pix.
//
{
    int i,j;
    float cx,cy,cz,nx,ny,nz,nk;
    short r,g,b;
    long color;
    
    // number of vertices
    int n = f.GetNumVertices();
    
    // facet is degenerate (a line) ----- CURRENTLY DEGENERATE NOT ALLOWED
    if (n == 2) {
	Line(f[0].p,f[1].p);
	return;
    }

    // can't happen !
    if (n < 2 || n > MaxVertices) {
	Warn("Scene::FlatFacet: number of vertices out of range");
	return;
    }

    static Material M;
    Material *Mp;
    if (coloring == Global) {
	Mp = f.GetMaterial();
    } else {
        M.color = f.front;
	if (f.material) {
	    M.ambient  = f.material->ambient;
	    M.specular = f.material->specular;
	    M.exponent = f.material->exponent;
	} else {
	    M.ambient = mat.ambient;
	    M.specular = mat.specular;
	    M.exponent = mat.exponent;
	}
	Mp = &M;
    } 
     
    // copy projected vertex coordinates to polygon array
    for (i = 0; i < n; i++) pix[i] = f[i].p;
     
    // compute color of facet from reflection properties
    if (shading == Facet::Flat) { 
	
	f.Normal(nx,ny,nz,nk);
	f.Center(cx,cy,cz);

	PhongColor(cx,cy,cz,nx,ny,nz,Mp,r,g,b);

	// find color in colormap
	//color = LookupColor(r,g,b,f.GetMaterial());
	color = LookupColor(r,g,b,&mat);

    // else if (shading == false) then use the background color
    } else
        color = backcolor;

    // =======================================================
    // testing: fog for edgelines to get a depth cueing effect
    // =======================================================
    ColorF previous_color;
    if (fog_opacity) {
      previous_color = foreground_color;
      SetColor( ColorF_Weighted(0.5*(1-tanh((6/fog_opacity)
			        *(hypot(cx,cy,cz)-fog_distance-1))),
				previous_color,fog_color) );
    }

    // draw outlines if requested
    if (edgelines == 1) 
        Polygon(n,pix,color,Outline|Fill);
    else if (edgelines == 0)
        Polygon(n,pix,color,Fill);
    else if (edgelines == Facet::Individual ) {
	if (f.edgelines == 1)
	    Polygon(n,pix,color,Outline|Fill); 
	else if (f.edgelines == 0)
	    Polygon(n,pix,color,Fill);
	else if (f.edgelines == Facet::Individual) {
	    Polygon(n,pix,color,Fill);
	    for (i = 0, j = n-1; i < n; j = i++) 
	      if ( f.GetEdgeLine(j) ) Line(pix[j],pix[i]);
	}	
    }

    if (fog_opacity) SetColor(previous_color);
}
Пример #22
0
void CRadar::Update()
{
	HDC dc;
	if (SUCCEEDED(lpSurface->GetDC(&dc)))
	{
		HBRUSH oldbrush;
		{	// Löschen / Auf Farbe setzen
			PatBlt(dc,0,0,size,size,BLACKNESS);
			SelectObject(dc,GetStockObject(WHITE_PEN));
			const HBRUSH green=CreateSolidBrush(RGB(0,64,0));
			oldbrush=(HBRUSH)SelectObject(dc,green);
			Ellipse(dc,0,0,size,size);
			SelectObject(dc,oldbrush);
			DeleteObject(green);
		}

		const float sx=parent->pos.x,sy=parent->pos.z;
		const float mx=size/2.0f,my=size/2.0f;

		const float InvRation=1.0f/((0.4f)*(256.0f/float(size)));

		D3DMATRIX m;
		if (parent->IsType(IDChicken))
			D3DUtil_SetRotateYMatrix(m,-parent->ang.y);
		else D3DUtil_SetRotateYMatrix(m,parent->ang.y);
	
		D3DVECTOR v;
		const HRGN rgn=CreateEllipticRgn(1,1,size-1,size-1);
		SelectClipRgn(dc,rgn);

		{	// Begrenzung rendern
			D3DVECTOR b[4]={
				D3DVECTOR(world->minx(),0,world->minz())-parent->pos,
				D3DVECTOR(world->maxx(),0,world->minz())-parent->pos,
				D3DVECTOR(world->maxx(),0,world->maxz())-parent->pos,
				D3DVECTOR(world->minx(),0,world->maxz())-parent->pos};

			POINT p[4];
			for (int i=0;i<4;i++)
			{
				D3DMath_VectorMatrixMultiply(b[i],b[i],m);

				b[i].x=b[i].x*InvRation+mx;
				b[i].z=-b[i].z*InvRation+my;
				p[i].x=(int)b[i].x;
				p[i].y=(int)b[i].z;
			}

			SelectObject(dc,GetStockObject(WHITE_PEN));
			const HBRUSH green=CreateSolidBrush(RGB(0,128,0));
			oldbrush=(HBRUSH)SelectObject(dc,green);

			Polygon(dc,&p[0],4);
			SelectObject(dc,oldbrush);
			DeleteObject(green);
		}

//	Grid rendern

		{
			D3DVECTOR v2;
			const HPEN pen1=CreatePen(PS_SOLID,1,RGB(0,192,0)),pen2=CreatePen(PS_SOLID,1,RGB(128,128,0)),pen3=CreatePen(PS_SOLID,1,RGB(0,128,128)),oldpen=(HPEN)SelectObject(dc,pen1);

#define Grid 20

			int ox=0,oy=0,oz=0,x,z;
			int num=int((size)/(Grid*InvRation))/2;

			if (parent->pos.x>0)
				while (ox<parent->pos.x)ox+=Grid;

			if (parent->pos.x<0)
				while (ox>parent->pos.x)ox-=Grid;

			if (parent->pos.z>0)
				while (oz<parent->pos.z)oz+=Grid;

			if (parent->pos.z<0)
				while (oz>parent->pos.z)oz-=Grid;


			if (TRUE)
			{	// x/z
				SelectObject(dc,pen1);
				for (x=-num-1;x<=num+1;x++)	// x-Achse
				{
					v.x=float(x*(Grid*InvRation))-(parent->pos.x*InvRation)+(ox*InvRation);
					v.y=0;
					v.z=size*0.5f;

					v2.x=float(x*(Grid*InvRation))-(parent->pos.x*InvRation)+(ox*InvRation);
					v2.y=0;
					v2.z=-int(size)*0.5f;
					D3DMath_VectorMatrixMultiply(v,v,m);
					D3DMath_VectorMatrixMultiply(v2,v2,m);
					MoveToEx(dc,int(mx+(v.x)),int(my+(-v.z)),NULL);
					LineTo(dc,int(mx+(v2.x)),int(my+(-v2.z)));
				}
	
				for (z=-num-1;z<=num+1;z++)	// z-Achse
				{
					v.x=size*0.5f;
					v.y=0;
					v.z=float(z*(Grid*InvRation))-(parent->pos.z*InvRation)+(oz*InvRation);
		
					v2.x=-int(size)*0.5f;
					v2.y=0;
					v2.z=float(z*(Grid*InvRation))-(parent->pos.z*InvRation)+(oz*InvRation);
					D3DMath_VectorMatrixMultiply(v,v,m);
					D3DMath_VectorMatrixMultiply(v2,v2,m);
					MoveToEx(dc,int(mx+(v.x)),int(my+(-v.z)),NULL);
					LineTo(dc,int(mx+(v2.x)),int(my+(-v2.z)));
				}
			}
	
	
	
			SelectObject(dc,oldpen);
			::DeleteObject(pen1);
			::DeleteObject(pen2);
			::DeleteObject(pen3);
		}

//	---


		COLORREF c;
		float s,x,y;
		D3DVECTOR p;
		HBRUSH brush;

		// Objekte rendern

		CObject* akt=game->chain->GetFirst();
		while (akt)
		{
			c=RGB(255,0,0);
			s=3;
			switch(GetType(akt->id))
			{
			case IDChicken:
				if (((CChicken*)akt)->dead!=0.0f)goto weiter;
				p=((CChicken*)akt)->pos;
				c=RGB(255,255,255);
				s=3;
				break;
			case IDBauer:
				if (((CBauer*)akt)->dead!=0.0f)goto weiter;
				if (((CBauer*)akt)->HasObject(IDDrescher))goto weiter;
				p=((CBauer*)akt)->pos;
				c=RGB(192,128,0);
				s=5;
				break;
			case IDStall:
				p=((CStall*)akt)->pos;
				c=RGB(214,160,32);
				s=7;
				break;
			case IDTree:
				p=((CTree*)akt)->pos;
				c=RGB(0,230,0);
				s=4;
				break;
			case IDGartenkralle:
				p=((CGartenkralle*)akt)->pos;
				c=RGB(255,214,0);
				s=2;
				break;
			case IDDrescher:
				p=((CDrescher*)akt)->pos;
				c=RGB(255,0,0);
				s=7;
				break;
			case IDGolfer:
				p=((CGolfer*)akt)->pos;
				c=RGB(192,192,192);
				s=2;
				break;
			case IDPlasmaCannon:
				p=((CPlasmaCannon*)akt)->pos;
				c=RGB(255,255,0);
				s=3;
				break;



			default:goto weiter;
			}
	
			p=p-parent->pos;
			D3DMath_VectorMatrixMultiply(p,p,m);
			x=p.x*InvRation;
			y=-p.z*InvRation;

			if ((x)*(x)+(y)*(y)<((size*0.5f)*(size*0.5f))-(4.0f*4.0f*4.0f*4.0f))
			{
				x+=mx;
				y+=my;

				SelectObject(dc,brush=CreateSolidBrush(c));

				SelectObject(dc,GetStockObject(NULL_PEN));
				Ellipse(dc,int(x-s),int(y-s),int(x+s),int(y+s));
	
				SelectObject(dc,oldbrush);
				::DeleteObject(brush);
			}	


weiter:
			akt=akt->next;
		}

		SelectObject(dc,GetStockObject(WHITE_PEN));
		Line(dc,size/2,(size*10)/18,size/2,(size*8)/18);
		Line(dc,(size*10)/18,size/2,(size*8)/18,size/2);

		SelectClipRgn(dc,NULL);
		::DeleteObject(rgn);

		lpSurface->ReleaseDC(dc);
	}

	MakeTransparent(lpSurface,FALSE);
}
Пример #23
0
void WinFillPolygon (OSPictContext context)
{
	StartFilling (context);
	Polygon (context->hDC, thePolygon, thePolygonIndex);
}	/* WinFillPolygon */
Пример #24
0
// ======================================= 
// 정의 : CGraphicManager::Poly(POINT* pPt, int n)
// 동작 : 다각형 그리기
void CGraphicManager::Poly(POINT* pPt, int n)
{
	Polygon(MemoryDC, pPt, n);
}
Пример #25
0
void WinInvertPolygon (OSPictContext context)
{
	StartInverting (context);
	Polygon (context->hDC, thePolygon, thePolygonIndex);
}	/* WinInvertPolygon */
Пример #26
0
END_TEST


START_TEST ( test_Polygon_read )
{
  std::string s = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
                  "<polygon xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" >\n"
                  "  <listOfElements>\n"
                  "    <element xsi:type=\"RenderPoint\" x=\"0\" y=\"0\"/>\n"
                  "    <element xsi:type=\"RenderPoint\" x=\"100%\" y=\"50%\"/>\n"
                  "    <element xsi:type=\"RenderPoint\" x=\"100%\" y=\"50%\"/>\n"
                  "    <element xsi:type=\"RenderPoint\" x=\"0\" y=\"100%\"/>\n"
                  "  </listOfElements>\n"
                  "</polygon>\n"
                ;

  XMLInputStream* pStream= new XMLInputStream(s.c_str(),false);
  XMLNode* pNode = new XMLNode(*pStream);

  // no attributes
  Polygon c(*pNode);
  fail_unless(c.getNumElements() == 4);
  fail_unless(!c.isSetMatrix());
  fail_unless(!c.isSetStroke());
  fail_unless(!c.isSetStrokeWidth());
  fail_unless(!c.isSetDashArray());
  fail_unless(!c.isSetFillColor());
  fail_unless(!c.isSetFillRule());

  delete pNode;
  delete pStream;

  // 2D transformation attributes  
  s = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
      "<polygon xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" transform=\"0.984808,0.173648,-0.173648,0.984808,0,0\">\n"
      "  <listOfElements>\n"
      "    <element xsi:type=\"RenderPoint\" x=\"0\" y=\"0\"/>\n"
      "    <element xsi:type=\"RenderPoint\" x=\"100%\" y=\"50%\"/>\n"
      "    <element xsi:type=\"RenderPoint\" x=\"100%\" y=\"50%\"/>\n"
      "    <element xsi:type=\"RenderPoint\" x=\"0\" y=\"100%\"/>\n"
      "  </listOfElements>\n"
      "</polygon>\n"
    ;

  pStream= new XMLInputStream(s.c_str(),false);
  pNode = new XMLNode(*pStream);

  c = Polygon(*pNode);
  fail_unless(c.getNumElements() == 4);
  fail_unless(c.isSetMatrix());
  const double* pMatrix=c.getMatrix2D();
  fail_unless(pMatrix != NULL);
  fail_unless(fabs((pMatrix[0] - 0.984808) / 0.984808) < 1e-9);   
  fail_unless(fabs((pMatrix[1] - 0.173648) / 0.173648) < 1e-9);   
  fail_unless(fabs((pMatrix[2] - -0.173648) / -0.173648) < 1e-9);   
  fail_unless(fabs((pMatrix[3] - 0.984808) / 0.984808) < 1e-9);   
  fail_unless(pMatrix[4] < 1e-9);
  fail_unless(pMatrix[5] < 1e-9);
  fail_unless(!c.isSetStroke());
  fail_unless(!c.isSetStrokeWidth());
  fail_unless(!c.isSetDashArray());
  fail_unless(!c.isSetFillColor());
  fail_unless(!c.isSetFillRule());
  delete pNode;
  delete pStream;

  // 1D attributes (stroke, stroke_width, stroke-dasharray  

  s = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
      "<polygon xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" stroke=\"#00FF00\" stroke-width=\"3\" stroke-dasharray=\"32 , 20\">\n"
      "  <listOfElements>\n"
      "    <element xsi:type=\"RenderPoint\" x=\"0\" y=\"0\"/>\n"
      "    <element xsi:type=\"RenderPoint\" x=\"100%\" y=\"50%\"/>\n"
      "    <element xsi:type=\"RenderPoint\" x=\"100%\" y=\"50%\"/>\n"
      "    <element xsi:type=\"RenderPoint\" x=\"0\" y=\"100%\"/>\n"
      "  </listOfElements>\n"
      "</polygon>\n"
    ;

  pStream= new XMLInputStream(s.c_str(),false);
  pNode = new XMLNode(*pStream);

  c = Polygon(*pNode);
  fail_unless(c.getNumElements() == 4);
  fail_unless(!c.isSetMatrix());
  fail_unless(c.isSetStroke());
  fail_unless(c.getStroke() == "#00FF00");
  fail_unless(c.isSetStrokeWidth());
  fail_unless(fabs((c.getStrokeWidth() - 3.0) / 3.0) < 1e-9);
  fail_unless(c.isSetDashArray());
  const std::vector<unsigned int>& array = c.getDashArray();
  fail_unless(array.size() == 2);
  fail_unless(array[0] == 32);
  fail_unless(array[1] == 20);
  fail_unless(!c.isSetFillColor());
  fail_unless(!c.isSetFillRule());

  delete pNode;
  delete pStream;

  // 2d attributes (fill, fill-rule)

  s = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
      "<polygon xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" fill=\"#DDFF00\" fill-rule=\"evenodd\">\n"
      "  <listOfElements>\n"
      "    <element xsi:type=\"RenderPoint\" x=\"0\" y=\"0\"/>\n"
      "    <element xsi:type=\"RenderPoint\" x=\"100%\" y=\"50%\"/>\n"
      "    <element xsi:type=\"RenderPoint\" x=\"100%\" y=\"50%\"/>\n"
      "    <element xsi:type=\"RenderPoint\" x=\"0\" y=\"100%\"/>\n"
      "  </listOfElements>\n"
      "</polygon>\n"
    ;

  pStream= new XMLInputStream(s.c_str(),false);
  pNode = new XMLNode(*pStream);

  c = Polygon(*pNode);
  fail_unless(c.getNumElements() == 4);
  fail_unless(!c.isSetMatrix());
  fail_unless(!c.isSetStroke());
  fail_unless(!c.isSetStrokeWidth());
  fail_unless(!c.isSetDashArray());
  fail_unless(c.isSetFillColor());
  fail_unless(c.getFillColor() == "#DDFF00");
  fail_unless(c.isSetFillRule());
  fail_unless(c.getFillRule() == GraphicalPrimitive2D::EVENODD);

  delete pNode;
  delete pStream;
}
Пример #27
0
 Polygon::pointer Polygon::create ( const Glib::ustring& id, const Vertices& vertices, Fill::pointer fill, Stroke::pointer stroke )
 {
   PAPYRUS_CREATE ( Polygon ( id, vertices, fill, stroke ) );
 }
Пример #28
0
END_TEST

START_TEST ( test_Polygon_read_old_style )
{
  std::string s = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
                  "<polygon xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n"
                  "  <listOfCurveSegments>\n"
                  "    <curveSegment xsi:type=\"LineSegment\">\n"
                  "      <start x=\"0\" y=\"0\" />\n"
                  "      <end x=\"10\" y=\"3\" />\n"
                  "    </curveSegment>\n"
                  "    <curveSegment xsi:type=\"LineSegment\">\n"
                  "      <start x=\"10\" y=\"3\" />\n"
                  "      <end x=\"0\" y=\"6\" />\n"
                  "    </curveSegment>\n"
                  "  </listOfCurveSegments>\n"
                  "</polygon>\n"
                ;
      
  XMLInputStream* pStream= new XMLInputStream(s.c_str(),false);
  XMLNode* pNode = new XMLNode(*pStream);

  Polygon c = Polygon(*pNode);
  fail_unless(!c.isSetMatrix());
  fail_unless(!c.isSetStroke());
  fail_unless(!c.isSetStrokeWidth());
  fail_unless(!c.isSetDashArray());
  fail_unless(!c.isSetFillColor());
  fail_unless(!c.isSetFillRule());
  fail_unless(c.getNumElements() == 3);
  const RenderPoint* pP=c.getElement(0);
  fail_unless( pP != NULL );
  if (pP == NULL) return;
  fail_unless( pP->getTypeCode() == SBML_RENDER_POINT );
  fail_unless( dynamic_cast<const RenderCubicBezier*>(pP) == NULL);
  fail_unless( pP->x().getAbsoluteValue() < 1e-9);
  fail_unless( pP->x().getRelativeValue() < 1e-9);
  fail_unless( pP->y().getAbsoluteValue() < 1e-9);
  fail_unless( pP->y().getRelativeValue() < 1e-9);
  fail_unless( pP->z().getAbsoluteValue() < 1e-9);
  fail_unless( pP->z().getRelativeValue() < 1e-9);
  pP=c.getElement(1);
  fail_unless( pP != NULL );
  fail_unless( pP->getTypeCode() == SBML_RENDER_POINT );
  fail_unless( dynamic_cast<const RenderCubicBezier*>(pP) == NULL);
  fail_unless( fabs((pP->x().getAbsoluteValue() - 10.0 ) / 10.0) < 1e-9);
  fail_unless( pP->x().getRelativeValue() < 1e-9);
  fail_unless( fabs((pP->y().getAbsoluteValue() - 3.0) / 3.0) < 1e-9);
  fail_unless( pP->y().getRelativeValue() < 1e-9);
  fail_unless( pP->z().getAbsoluteValue() < 1e-9);
  fail_unless( pP->z().getRelativeValue() < 1e-9);
  pP=c.getElement(2);
  fail_unless( pP != NULL );
  fail_unless( pP->getTypeCode() == SBML_RENDER_POINT );
  fail_unless( dynamic_cast<const RenderCubicBezier*>(pP) == NULL);
  fail_unless( pP->x().getAbsoluteValue() < 1e-9);
  fail_unless( pP->x().getRelativeValue() < 1e-9);
  fail_unless( fabs((pP->y().getAbsoluteValue() - 6.0) / 6.0) < 1e-9);
  fail_unless( pP->y().getRelativeValue() < 1e-9);
  fail_unless( pP->z().getAbsoluteValue() < 1e-9);
  fail_unless( pP->z().getRelativeValue() < 1e-9);
  delete pNode;
  delete pStream;
      
      
  s = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
      "<polygon xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n"
      "  <listOfCurveSegments>\n"
      "    <curveSegment xsi:type=\"CubicBezier\">\n"
      "      <start x=\"2.0\" y=\"7.71428\"/>\n"
      "      <basePoint1 x=\"10.21428\" y=\"12.0\"/>\n"
      "      <basePoint2 x=\"15.21428\" y=\"17.04464\"/>\n"
      "      <end x=\"24.05357\" y=\"15.83928\"/>\n"
      "    </curveSegment>\n"
      "    <curveSegment xsi:type=\"CubicBezier\">\n"
      "      <start x=\"24.05357\" y=\"15.83928\"/>\n"
      "      <basePoint1 x=\"32.89285\" y=\"14.63392\"/>\n"
      "      <basePoint2 x=\"45.57142\" y=\"7.17856\"/>\n"
      "      <end x=\"45.57142\" y=\"7.17856\"/>\n"
      "    </curveSegment>\n"
      "    <curveSegment xsi:type=\"LineSegment\">\n"
      "      <start x=\"45.57142\" y=\"7.17856\"/>\n"
      "      <end x=\"41.46427\" y=\"2.0\"/>\n"
      "    </curveSegment>\n"
      "    <curveSegment xsi:type=\"CubicBezier\">\n"
      "      <start x=\"41.46427\" y=\"2.0\"/>\n"
      "      <basePoint1 x=\"41.46427\" y=\"2.0\"/>\n"
      "      <basePoint2 x=\"31.9107\" y=\"9.14285\"/>\n"
      "      <end x=\"23.42856\" y=\"9.32142\"/>\n"
      "    </curveSegment>\n"
      "    <curveSegment xsi:type=\"CubicBezier\">\n"
      "      <start x=\"23.42856\" y=\"9.32142\"/>\n"
      "      <basePoint1 x=\"14.94642\" y=\"9.49999\"/>\n"
      "      <basePoint2 x=\"7.5357\" y=\"2.71428\"/>\n"
      "      <end x=\"7.5357\" y=\"2.71428\"/>\n"
      "    </curveSegment>\n"
      "    <curveSegment xsi:type=\"LineSegment\">\n"
      "      <start x=\"7.5357\" y=\"2.71428\"/>\n"
      "      <end x=\"2.0\" y=\"7.71428\"/>\n"
      "    </curveSegment>\n"
      "  </listOfCurveSegments>\n"
      "</polygon>\n"
    ;

  pStream= new XMLInputStream(s.c_str(),false);
  pNode = new XMLNode(*pStream);
  
  c = Polygon(*pNode);
  fail_unless(!c.isSetMatrix());
  fail_unless(!c.isSetStroke());
  fail_unless(!c.isSetStrokeWidth());
  fail_unless(!c.isSetDashArray());
  fail_unless(!c.isSetFillColor());
  fail_unless(!c.isSetFillRule());
  fail_unless(c.getNumElements() == 7);
  pP=c.getElement(0);
  fail_unless( pP != NULL );
  fail_unless( pP->getTypeCode() == SBML_RENDER_POINT );
  fail_unless( dynamic_cast<const RenderCubicBezier*>(pP) == NULL);
  fail_unless( fabs((pP->x().getAbsoluteValue() - 2.0) / 2.0) < 1e-9);
  fail_unless( pP->x().getRelativeValue() < 1e-9);
  fail_unless( fabs((pP->y().getAbsoluteValue() - 7.71428) / 7.71428) < 1e-9);
  fail_unless( pP->y().getRelativeValue() < 1e-9);
  fail_unless( pP->z().getAbsoluteValue() < 1e-9);
  fail_unless( pP->z().getRelativeValue() < 1e-9);
  pP=c.getElement(1);
  fail_unless( pP != NULL );
  fail_unless( pP->getTypeCode() == SBML_RENDER_POINT );
  fail_unless( dynamic_cast<const RenderCubicBezier*>(pP) == NULL);
  fail_unless( fabs((pP->x().getAbsoluteValue() - 24.05357) / 24.05357) < 1e-9);
  fail_unless( pP->x().getRelativeValue() < 1e-9);
  fail_unless( fabs((pP->y().getAbsoluteValue() - 15.83928) / 15.83928) < 1e-9);
  fail_unless( pP->y().getRelativeValue() < 1e-9);
  fail_unless( pP->z().getAbsoluteValue() < 1e-9);
  fail_unless( pP->z().getRelativeValue() < 1e-9);
  pP=c.getElement(2);
  fail_unless( pP != NULL );
  fail_unless( pP->getTypeCode() == SBML_RENDER_POINT );
  fail_unless( dynamic_cast<const RenderCubicBezier*>(pP) == NULL);
  fail_unless( fabs((pP->x().getAbsoluteValue() - 45.57142) / 45.57142) < 1e-9);
  fail_unless( pP->x().getRelativeValue() < 1e-9);
  fail_unless( fabs((pP->y().getAbsoluteValue() - 7.17856) / 7.17856) < 1e-9);
  fail_unless( pP->y().getRelativeValue() < 1e-9);
  fail_unless( pP->z().getAbsoluteValue() < 1e-9);
  fail_unless( pP->z().getRelativeValue() < 1e-9);
  pP=c.getElement(3);
  fail_unless( pP != NULL );
  fail_unless( pP->getTypeCode() == SBML_RENDER_POINT );
  fail_unless( dynamic_cast<const RenderCubicBezier*>(pP) == NULL);
  fail_unless( fabs((pP->x().getAbsoluteValue() - 41.46427) / 41.46427) < 1e-9);
  fail_unless( pP->x().getRelativeValue() < 1e-9);
  fail_unless( fabs((pP->y().getAbsoluteValue() - 2.0) / 2.0) < 1e-9);
  fail_unless( pP->y().getRelativeValue() < 1e-9);
  fail_unless( pP->z().getAbsoluteValue() < 1e-9);
  fail_unless( pP->z().getRelativeValue() < 1e-9);
  pP=c.getElement(4);
  fail_unless( pP != NULL );
  fail_unless( pP->getTypeCode() == SBML_RENDER_POINT );
  fail_unless( dynamic_cast<const RenderCubicBezier*>(pP) == NULL);
  fail_unless( fabs((pP->x().getAbsoluteValue() - 23.42856) / 23.42856) < 1e-9);
  fail_unless( pP->x().getRelativeValue() < 1e-9);
  fail_unless( fabs((pP->y().getAbsoluteValue() - 9.32142) / 9.32142) < 1e-9);
  fail_unless( pP->y().getRelativeValue() < 1e-9);
  fail_unless( pP->z().getAbsoluteValue() < 1e-9);
  fail_unless( pP->z().getRelativeValue() < 1e-9);
  pP=c.getElement(5);
  fail_unless( pP != NULL );
  fail_unless( pP->getTypeCode() == SBML_RENDER_POINT );
  fail_unless( dynamic_cast<const RenderCubicBezier*>(pP) == NULL);
  fail_unless( fabs((pP->x().getAbsoluteValue() - 7.5357) / 7.5357) < 1e-9);
  fail_unless( pP->x().getRelativeValue() < 1e-9);
  fail_unless( fabs((pP->y().getAbsoluteValue() - 2.71428) / 2.71428) < 1e-9);
  fail_unless( pP->y().getRelativeValue() < 1e-9);
  fail_unless( pP->z().getAbsoluteValue() < 1e-9);
  fail_unless( pP->z().getRelativeValue() < 1e-9);
  pP=c.getElement(6);
  fail_unless( pP != NULL );
  fail_unless( pP->getTypeCode() == SBML_RENDER_POINT );
  fail_unless( dynamic_cast<const RenderCubicBezier*>(pP) == NULL);
  fail_unless( fabs((pP->x().getAbsoluteValue() - 2.0) / 2.0) < 1e-9);
  fail_unless( pP->x().getRelativeValue() < 1e-9);
  fail_unless( fabs((pP->y().getAbsoluteValue() - 7.71428) / 7.71428) < 1e-9);
  fail_unless( pP->y().getRelativeValue() < 1e-9);
  fail_unless( pP->z().getAbsoluteValue() < 1e-9);
  fail_unless( pP->z().getRelativeValue() < 1e-9);
  delete pNode;
  delete pStream;
} 
Пример #29
0
bool Zone::ParsePolygonString(const char *poly_string, Polygon &polygon) {
  Debug(3, "Parsing polygon string '%s'", poly_string);

  char *str_ptr = new char[strlen(poly_string)+1];
  char *str = str_ptr;
  strcpy(str, poly_string);

  char *ws;
  int n_coords = 0;
  int max_n_coords = strlen(str)/4;
  Coord *coords = new Coord[max_n_coords];
  while( true ) {
    if ( *str == '\0' ) {
      break;
    }
    ws = strchr(str, ' ');
    if ( ws ) {
      *ws = '\0';
    }
    char *cp = strchr(str, ',');
    if ( !cp ) {
      Error("Bogus coordinate %s found in polygon string", str);
      delete[] coords;
      delete[] str_ptr;
      return false;
    } else {
      *cp = '\0';
      char *xp = str;
      char *yp = cp+1;

      int x = atoi(xp);
      int y = atoi(yp);

      Debug(3, "Got coordinate %d,%d from polygon string", x, y);
#if 0
			if ( x < 0 )
				x = 0;
			else if ( x >= width )
				x = width-1;
			if ( y < 0 )
				y = 0;
			else if ( y >= height )
				y = height-1;
#endif
			coords[n_coords++] = Coord( x, y );
		}
		if ( ws )
			str = ws+1;
		else
			break;
	}
	polygon = Polygon(n_coords, coords);

	Debug(3, "Successfully parsed polygon string");
	//printf( "Area: %d\n", pg.Area() );
	//printf( "Centre: %d,%d\n", pg.Centre().X(), pg.Centre().Y() );

	delete[] coords;
	delete[] str_ptr;

	return true;
}
Пример #30
0
void Draw(HWND hwnd, POINT p1)
{
	PAINTSTRUCT ps;
	HPEN hPen;
	HBRUSH hBrush;
	HDC hdc = GetDC(hwnd);

	hPen = CreatePen(PS_SOLID, 1, RGB(221, 243, 20)); SelectObject(hdc, hPen);
	hBrush = CreateSolidBrush(RGB(221, 243, 20)); SelectObject(hdc, hBrush);
	// head
	int headRadius = 50;
	int xOffset = 100;
	int yOffset = 50;
	POINT headCenter = { (int)p1.x + xOffset + headRadius, (int)p1.y + yOffset + headRadius };
	Ellipse(hdc, headCenter.x - headRadius, headCenter.y - headRadius, headCenter.x + headRadius, headCenter.y + headRadius);
		// hair 
	const int hairsCount = 15;
	int hairRectWidth = headRadius * 0.1;
	int hairRectHeight = headRadius * 0.4;
	POINT pointsHair[hairsCount];
	pointsHair[0] = { (int)(double)headCenter.x - (double)headRadius * 0.65, (int)(double)headCenter.y - (double)headRadius * 0.4 };
	pointsHair[1] = { (int)pointsHair[0].x + hairRectWidth, (int) pointsHair[0].y - hairRectHeight};
	for (int i = 2; i < hairsCount; i++)
	{
		pointsHair[i] = { (int)pointsHair[i - 2].x + 2 * hairRectWidth, (int)pointsHair[i - 2].y };
	}
	hPen = CreatePen(PS_SOLID, 2, RGB(129, 90, 22)); SelectObject(hdc, hPen);
	Polyline(hdc, pointsHair, hairsCount);
		// ----
		// eyes
	int eyeHeight = 10;
	int eyeWidth = 20;
	POINT eyeCenter = { (int)headCenter.x - headRadius / 2, (int)headCenter.y - eyeHeight / 2 };
	hPen = CreatePen(PS_SOLID, 1, RGB(0, 0, 0)); SelectObject(hdc, hPen);
	Arc(hdc, eyeCenter.x - eyeWidth / 2, eyeCenter.y - eyeHeight / 2, eyeCenter.x + eyeWidth / 2, eyeCenter.y + eyeHeight / 2, eyeCenter.x - eyeWidth / 2, eyeCenter.y, eyeCenter.x + eyeWidth / 2, eyeCenter.y);
	Arc(hdc, eyeCenter.x - eyeWidth / 2, eyeCenter.y - eyeHeight / 2, eyeCenter.x + eyeWidth / 2, eyeCenter.y + eyeHeight / 2, eyeCenter.x + eyeWidth / 2, eyeCenter.y, eyeCenter.x - eyeWidth / 2, eyeCenter.y);
	eyeCenter = { headCenter.x + headRadius / 2, headCenter.y - eyeHeight / 2 };
	Arc(hdc, eyeCenter.x - eyeWidth / 2, eyeCenter.y - eyeHeight / 2, eyeCenter.x + eyeWidth / 2, eyeCenter.y + eyeHeight / 2, eyeCenter.x - eyeWidth / 2, eyeCenter.y, eyeCenter.x + eyeWidth / 2, eyeCenter.y);
	Arc(hdc, eyeCenter.x - eyeWidth / 2, eyeCenter.y - eyeHeight / 2, eyeCenter.x + eyeWidth / 2, eyeCenter.y + eyeHeight / 2, eyeCenter.x + eyeWidth / 2, eyeCenter.y, eyeCenter.x - eyeWidth / 2, eyeCenter.y);
		// ----
		// nose
	int noseOffset = 5;
	POINT pointsNose[3] = { 
		{ (int) p1.x + xOffset + headRadius, (int) p1.y + yOffset + headRadius},
		{ (int)p1.x + xOffset + headRadius - noseOffset, (int)p1.y + yOffset + headRadius + 2 * noseOffset },
		{ (int)p1.x + xOffset + headRadius + noseOffset, (int)p1.y + yOffset + headRadius + 2 * noseOffset }
	};
	Polyline(hdc, pointsNose, 3);
		// ----
		// mouth
	int mouthRadius = (int)(double)headRadius * 0.45;
	POINT mouthCenter = headCenter;
	int NOTUSED = 5;
	Arc(hdc, (int)(double) mouthCenter.x - (double) mouthRadius * 1.42, (int)(double) mouthCenter.y - (double) mouthRadius * 1.42,
		(int)mouthCenter.x + mouthRadius * 1.42, (int)mouthCenter.y + mouthRadius * 1.42,
		(int)headCenter.x - 5, (int)headCenter.y + 5,
		(int)headCenter.x + 5, (int)headCenter.y + 5);
		// ----
	// ----
	// neck
	hPen = CreatePen(PS_SOLID, 1, RGB(221, 243, 20)); SelectObject(hdc, hPen);
	hBrush = CreateSolidBrush(RGB(221, 243, 20)); SelectObject(hdc, hBrush);
	int neckWidth = 15;
	int neckHeight = 20;
	// 4!!!
	Rectangle(hdc, (int)headCenter.x - neckWidth / 2, (int)headCenter.y + headRadius - 4,
		(int)headCenter.x + neckWidth / 2, (int)headCenter.y + headRadius + neckHeight);
	// ----
	// body
	int bodyWidth = 100;
	int bodyHeight = 160;
	// 4!!!!
	POINT bodyCenter = { (int)headCenter.x, (int)headCenter.y + headRadius + neckHeight + bodyHeight / 2 - 4 };
	Ellipse(hdc, (int)bodyCenter.x - bodyWidth / 2, (int)bodyCenter.y - bodyHeight / 2,
		(int)bodyCenter.x + bodyWidth / 2, (int)bodyCenter.y + bodyHeight / 2);
		// hands
	hPen = CreatePen(PS_SOLID, 15, RGB(221, 243, 20)); SelectObject(hdc, hPen);
	POINT handsCenter = { (int)bodyCenter.x, (int)(double)bodyCenter.y - (double)bodyHeight / 2 * 0.7 };
	int handRectWidth = 100;
	int handRectHeight = 50;
	MoveToEx(hdc, (int)handsCenter.x, (int)handsCenter.y, NULL);
	LineTo(hdc, (int)handsCenter.x - handRectWidth, (int)handsCenter.y + handRectHeight);
	MoveToEx(hdc, (int)handsCenter.x, (int)handsCenter.y, NULL);
	LineTo(hdc, (int)handsCenter.x + handRectWidth, (int)handsCenter.y + handRectHeight);
			// flagpole
	int flagpoleWidth = 8;
	int flagpoleHeight = 100;
	POINT flagCenter = { (int)handsCenter.x + handRectWidth, (int)handsCenter.y + handRectHeight - flagpoleHeight / 2 };
	hPen = CreatePen(PS_SOLID, 2, RGB(21, 54, 183)); SelectObject(hdc, hPen);
	hBrush = CreateSolidBrush(RGB(21, 54, 183)); SelectObject(hdc, hBrush);
	Rectangle(hdc, (int) flagCenter.x - flagpoleWidth / 2, (int) flagCenter.y - flagpoleHeight / 2, (int) flagCenter.x + flagpoleWidth / 2, (int) flagCenter.y + flagpoleHeight / 2);
				// flag
	int flagWidth = 60;
	int flagHeight = flagpoleHeight * 0.4;
	POINT pointsFlag[3] = {
		{ (int)flagCenter.x - flagpoleWidth / 2, (int)flagCenter.y - flagpoleHeight / 2 },
		{ (int)flagCenter.x - flagpoleWidth / 2 + flagWidth, (int)flagCenter.y - flagpoleHeight / 2 + flagHeight / 2 },
		{ (int)flagCenter.x - flagpoleWidth / 2, (int)flagCenter.y - flagpoleHeight / 2 + flagHeight }
	};
	hPen = CreatePen(PS_SOLID, 2, RGB(255, 0, 0)); SelectObject(hdc, hPen);
	hBrush = CreateSolidBrush(RGB(255, 0, 0)); SelectObject(hdc, hBrush);
	Polygon(hdc, pointsFlag, 3);
				// ---------
			// ----
		// -----
		// legs
	POINT legsCenter = { (int)bodyCenter.x, (int)bodyCenter.y + bodyHeight / 2 * 0.5 };
	int legRectWidth = 50;
	int legRectHeight = 80;
	hPen = CreatePen(PS_SOLID, 15, RGB(221, 243, 20)); SelectObject(hdc, hPen);
	MoveToEx(hdc, (int)legsCenter.x, (int)legsCenter.y, NULL);
	LineTo(hdc, (int)legsCenter.x - legRectWidth, (int)legsCenter.y + legRectHeight);
	MoveToEx(hdc, (int)legsCenter.x, (int)legsCenter.y, NULL);
	LineTo(hdc, (int)legsCenter.x + legRectWidth, (int)legsCenter.y + legRectHeight);
		// ----
	// ----

	DeleteObject(hPen);
	DeleteObject(hBrush);
	//EndPaint(hwnd, &ps);
}