コード例 #1
0
void quadrupedClass::Draw(HDC hdc)const{
	
	/*//DEBUGGING CODE: draw the redraw box. 
	//note: the box is not erased due to how this works (drawing what it would be the previous frame...), 
	//but it's a decent indicator of where the erasing will happen, to be sure it works properly
	HBRUSH brushRed = CreateHatchBrush(HS_DIAGCROSS, RGB(255, 0, 0));
	FillRect(hdc, &RedrawArea(true), brushRed);
	//END debugging*/


	HPEN penFront = CreatePen(PS_SOLID, 2, RGB(0, 0, 255));
	HPEN penBack = CreatePen(PS_SOLID, 2, RGB(255, 0, 0));//different colors for the legs
	HPEN pen = CreatePen(PS_SOLID, 2, RGB(0, 0, 0));//basic pen is black
	HPEN oldPen = (HPEN)SelectObject(hdc, pen);//store the original pen

	//head
	Ellipse(hdc, Head.left, Head.top, Head.right, Head.bottom);
	//back
	DrawLine(hdc, Back.Start, Back.End);
	//legs
		//back
	SelectObject(hdc, penBack);//change the pen
	DrawLine(hdc, LegBB.Start, LegBB.End);
	DrawLine(hdc, LegFB.Start, LegFB.End);
		//front
	SelectObject(hdc, penFront);//change the pen
	DrawLine(hdc, LegFF.Start, LegFF.End);
	DrawLine(hdc, LegBF.Start, LegBF.End);


	//reset hdc
	SelectObject(hdc, oldPen);
	DeleteObject(pen);
	DeleteObject(penFront);
	DeleteObject(penBack);

}
コード例 #2
0
ファイル: heavysidefunction.cpp プロジェクト: TrojanXu/feelpp
heavysideFunction::value_type
heavysideFunction::operator()( node_type const& pointHat ) const
{
    node_type Ellipse( pbeqspace_type::Dim );
    node_type point( pbeqspace_type::Dim );

    point = element_prod( *M_stretch,pointHat ) + ( *M_translation );

    molecule_type::atoms_const_iterator_type atom( M_molecule->begin() );

    for ( ; atom != M_molecule->end(); ++atom )
    {
        Ellipse =  point  - atom->center();

        //if ( norm_inf(Ellipse) >  atom->radius() ) continue;

        if  ( norm_2( Ellipse ) < atom->radius2() )
        {
            return 0;
        }
    }

    return 1;
}
コード例 #3
0
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    PAINTSTRUCT ps;
    static RECT rect,oldRect,invalidationRect;                                //The oldRect is used for window resizing handling , the invalidationRect for invalidating only the drawing area
    static BOOL drawing_circle=FALSE,drawing_square=TRUE,drawing_bezier=FALSE,//Checks what is being drawn at the moment
                first_point=TRUE,                                                         //Checks if the first point of the bezier is being drawn
                button_pressed_in_area=FALSE,                                             //Checks if the button was pressed and if it happened inside the drawing area
                mouse_moving=FALSE;                                                       //Checks if the mouse is moving in order to paint the tracing of the object

    static HDC hdc,
           hdcMem;
    static HBITMAP hBitmap;
    BITMAP bitmap;

    static int figureCount=0;                                                  //Counts the number of figures in the drawing area
    static POINT arrayPoints[100][5];                                          //The array that holds the data of the figures

    static float xDisp,yDisp,slope,displacement;                               //Used to move and resize the pictures drawn . The last two variables are used to calculate the function
    //that the points will move on when resizing (the resize is a convergence towards the center)
    static int xFin=0,yFin=0,xFinSecond=0,yFinSecond=0;                        //Used to draw the tracing of elemens with the last two needed for Bezier only
    static int resizeCount;                                                    //Used to limit the resize to a certain number of times


    switch (message)                  /* handle the messages */
    {
    case WM_CREATE:

        GetClientRect(hwnd,&rect);
        //oldRect gets the same value as current rect as to avoid division by 0 and unintended resizing at the beginning
        oldRect=rect;
        //Creates the needed switches
        CreateButtons(hwnd,rect);
        // Loads the bitmap from resources
        hBitmap = LoadBitmap(hInst,MAKEINTRESOURCE(LOGO));
        GetObject(hBitmap,sizeof(BITMAP),&bitmap);
        break;

    case WM_SIZE:

        GetClientRect(hwnd,&rect);
        //Resizes all buttons based on the window size
        MoveWindow(hwndSquareButton,rect.right*3/4,rect.bottom/32,rect.right/8,30,TRUE);
        MoveWindow(hwndCircleButton,rect.right*7/8,rect.bottom/32,rect.right/8,30,TRUE);
        MoveWindow(hwndBezierButton,rect.right*3/4,rect.bottom/8,rect.right/8,30,TRUE);
        //Set the displacement of the drawings inside the window to new , moved coordinates
        xDisp=(float)rect.right/oldRect.right;
        yDisp=(float)rect.bottom/oldRect.bottom;

        oldRect.bottom=rect.bottom;
        oldRect.right=rect.right;

        for(int i=0; i<figureCount; i++) {
            for(int j=0; j<4; j++) {
                arrayPoints[i][j].x*=xDisp;
                arrayPoints[i][j].y*=yDisp;
            }
        }

        InvalidateRect(hwnd,NULL,TRUE);
        break;

    case WM_COMMAND:
        //Sets the buttons to active and puts the flags in the needed positions
        switch(wParam)
        {
        case ID_SWITCH_CIRCLE:
            SendMessage(hwndCircleButton,BM_SETCHECK,1,0);
            SendMessage(hwndBezierButton,BM_SETCHECK,0,0);
            SendMessage(hwndSquareButton,BM_SETCHECK,0,0);
            drawing_bezier=drawing_square=FALSE;
            drawing_circle=TRUE;
            break;

        case ID_SWITCH_SQUARE:
            SendMessage(hwndCircleButton,BM_SETCHECK,0,0);
            SendMessage(hwndBezierButton,BM_SETCHECK,0,0);
            SendMessage(hwndSquareButton,BM_SETCHECK,1,0);
            drawing_bezier=drawing_circle=FALSE;
            drawing_square=TRUE;
            break;

        case ID_SWITCH_BEZIER:
            SendMessage(hwndCircleButton,BM_SETCHECK,0,0);
            SendMessage(hwndBezierButton,BM_SETCHECK,1,0);
            SendMessage(hwndSquareButton,BM_SETCHECK,0,0);
            drawing_square=drawing_circle=FALSE;
            drawing_bezier=TRUE;
            break;

        }
        break;

    case WM_RBUTTONDOWN:
        //The setting up of invalidation region
        GetClientRect(hwnd,&rect);
        invalidationRect.right=rect.right*3/4-16;
        invalidationRect.top=rect.top+130;
        invalidationRect.bottom=rect.bottom-5;
        invalidationRect.left=rect.right*1/4+16;
        //The deletion a figure and refreshing the picture
        figureCount--;
        if(figureCount<0) figureCount=0;
        InvalidateRect(hwnd,&invalidationRect,TRUE);
        break;

    case WM_MOUSEMOVE:
        //Exits case in case the mouse is out of the needed area
        if(!button_pressed_in_area) break;
        mouse_moving=TRUE;
        //invalidation
        GetClientRect(hwnd,&rect);
        invalidationRect.right=rect.right*3/4-16;
        invalidationRect.top=rect.top+130;
        invalidationRect.bottom=rect.bottom-5;
        invalidationRect.left=rect.right*1/4+16;
        //Checks if the moving is being done in the drawing area and ends drawing in case it isn't
        if ((LOWORD(lParam)<rect.right/4+20) || (LOWORD(lParam)>rect.right*3/4-20) ||
                (HIWORD(lParam)<135) || (HIWORD(lParam)>rect.bottom-6)) {
            SendMessage(hwnd,WM_LBUTTONUP,NULL,lParam) ;
            break;
        }

        hdc=GetDC(hwnd);
        //Depending on the selected drawing sets the points for the tracing of figures
        if (drawing_circle) {
            xFin=LOWORD(lParam);
            yFin=HIWORD(lParam);
        }

        if (drawing_square) {
            xFin=LOWORD(lParam);
            yFin=HIWORD(lParam);
        }

        if (drawing_bezier && !first_point) {
            xFin=LOWORD(lParam);
            yFin=HIWORD(lParam);
        } else if (drawing_bezier) {
            xFinSecond=LOWORD(lParam);
            yFinSecond=HIWORD(lParam);
        }
        //Send message to repaint drawing area
        InvalidateRect(hwnd,&invalidationRect,TRUE);
        ReleaseDC(hwnd,hdc);

        break;

    case WM_LBUTTONDOWN:
        //Checks if the button clicking is being done in the drawing area and sets focus to main window
        SetFocus(hwnd);
        GetClientRect(hwnd,&rect);
        if ((LOWORD(lParam)<rect.right/4+14) || (LOWORD(lParam)>rect.right*3/4-14) ||
                (HIWORD(lParam)<125) || (HIWORD(lParam)>rect.bottom-6)) break;

        button_pressed_in_area=TRUE;
        hdc=GetDC(hwnd);
        //Gets initial points for the figure being drawn and sets a information value in order to read the right thing from the array afterwards
        if (drawing_square) {
            arrayPoints[figureCount][4].x=ID_SWITCH_SQUARE;
            arrayPoints[figureCount][0].x=LOWORD(lParam);
            arrayPoints[figureCount][0].y=HIWORD(lParam);
        }

        if (drawing_bezier && first_point) {
            arrayPoints[figureCount][4].x=ID_SWITCH_BEZIER;
            arrayPoints[figureCount][0].x=LOWORD(lParam);
            arrayPoints[figureCount][0].y=HIWORD(lParam);
            first_point=FALSE;
        } else if (drawing_bezier) {
            first_point=TRUE;
            figureCount--;
            arrayPoints[figureCount][2].x=LOWORD(lParam);
            arrayPoints[figureCount][2].y=HIWORD(lParam);
        }

        if (drawing_circle) {
            arrayPoints[figureCount][4].x=ID_SWITCH_CIRCLE;
            arrayPoints[figureCount][0].x=LOWORD(lParam);
            arrayPoints[figureCount][0].y=HIWORD(lParam);
        }
        ReleaseDC(hwnd,hdc);
        break;

    case WM_LBUTTONUP:
        //Makes sure the drawing started inside the canvas
        if(!button_pressed_in_area) break;
        mouse_moving=FALSE;
        //invalidation
        GetClientRect(hwnd,&rect);
        invalidationRect.right=rect.right*3/4-16;
        invalidationRect.top=rect.top+130;
        invalidationRect.bottom=rect.bottom-5;
        invalidationRect.left=rect.right*1/4+16;

        hdc=GetDC(hwnd);
        //Gets the end points of the figures
        if (drawing_square) {
            arrayPoints[figureCount][1].x=LOWORD(lParam);
            arrayPoints[figureCount][1].y=HIWORD(lParam);
        }

        if (drawing_bezier && !first_point) {
            arrayPoints[figureCount][1].x=LOWORD(lParam);
            arrayPoints[figureCount][1].y=HIWORD(lParam);

        } else if (drawing_bezier) {
            arrayPoints[figureCount][3].x=LOWORD(lParam);
            arrayPoints[figureCount][3].y=HIWORD(lParam);
            InvalidateRect(hwnd,&invalidationRect,TRUE);
        }

        if (drawing_circle) {
            arrayPoints[figureCount][1].x=LOWORD(lParam);
            arrayPoints[figureCount][1].y=HIWORD(lParam);
        }
        //Increments nr of figures
        figureCount++;
        button_pressed_in_area=FALSE;
        //The bezier uses 4 points instead of 2 like the others so different actions when invalidating
        if (!drawing_bezier) {
            InvalidateRect(hwnd,&invalidationRect,TRUE);
        }

        ReleaseDC(hwnd,hdc);

        break;

    case WM_KEYDOWN:
        //invalidation
        GetClientRect(hwnd,&rect);
        invalidationRect.right=rect.right*3/4-16;
        invalidationRect.top=rect.top+130;
        invalidationRect.bottom=rect.bottom-5;
        invalidationRect.left=rect.right*1/4+16;
        //Resizes canvas based on convergence on the line formed by the center point of the canvas and a point of the figure
        switch(wParam) {
        case VK_UP:

            if (resizeCount<0) break;
            for(int i=0; i<figureCount; i++) {
                for(int j=0; j<4; j++) {

                    slope=(arrayPoints[i][j].y-(rect.bottom-126)/2)/(float)(arrayPoints[i][j].x-rect.right/2);
                    displacement=arrayPoints[i][j].y-slope*arrayPoints[i][j].x;

                    arrayPoints[i][j].x=(rect.right/2)-(rect.right/2-arrayPoints[i][j].x)*1.1;
                    arrayPoints[i][j].y=roundf(arrayPoints[i][j].x*slope+displacement);
                }
            }
            resizeCount--;
            break;

        case VK_DOWN:

            if(resizeCount>10) break;
            for(int i=0; i<figureCount; i++) {
                for(int j=0; j<4; j++) {

                    slope=(arrayPoints[i][j].y-(rect.bottom-126)/2)/(float)(arrayPoints[i][j].x-rect.right/2);
                    displacement=arrayPoints[i][j].y-slope*arrayPoints[i][j].x;

                    arrayPoints[i][j].x=(rect.right/2)-(rect.right/2-arrayPoints[i][j].x)*0.9;
                    arrayPoints[i][j].y=roundf(arrayPoints[i][j].x*slope+displacement);


                }
            }
            resizeCount++;
            break;
        }
        InvalidateRect(hwnd,&invalidationRect,TRUE);
        break;

    case WM_PAINT:
        hdc=BeginPaint(hwnd,&ps);
        GetClientRect(hwnd,&rect);
        //Create figures
        SelectObject(hdc,GetStockObject(NULL_BRUSH));
        for (int i=0; i<figureCount; i++) {
            switch(arrayPoints[i][4].x) {
            case ID_SWITCH_SQUARE:
                Rectangle(hdc,arrayPoints[i][0].x,arrayPoints[i][0].y,arrayPoints[i][1].x,arrayPoints[i][1].y);
                break;
            case ID_SWITCH_CIRCLE:
                Ellipse(hdc,arrayPoints[i][0].x,arrayPoints[i][0].y,arrayPoints[i][1].x,arrayPoints[i][1].y);
                break;
            case ID_SWITCH_BEZIER:
                PolyBezier(hdc,arrayPoints[i],4);
                break;
            }
        }
        //Create traces
        if (mouse_moving) {

            if (drawing_circle) {
                Ellipse(hdc,arrayPoints[figureCount][0].x,arrayPoints[figureCount][0].y,xFin,yFin);
            }

            if (drawing_bezier && !first_point) {
                MoveToEx(hdc,arrayPoints[figureCount][0].x,arrayPoints[figureCount][0].y,NULL);
                LineTo(hdc,xFin,yFin);
            } else if (drawing_bezier) {
                MoveToEx(hdc,arrayPoints[figureCount][0].x,arrayPoints[figureCount][0].y,NULL);
                LineTo(hdc,xFin,yFin);

                MoveToEx(hdc,arrayPoints[figureCount][2].x,arrayPoints[figureCount][2].y,NULL);
                LineTo(hdc,xFinSecond,yFinSecond);
            }

            if (drawing_square) {
                Rectangle(hdc,arrayPoints[figureCount][0].x,arrayPoints[figureCount][0].y,xFin,yFin);
            }

        }

        SelectObject(hdc,GetStockObject(WHITE_BRUSH));
        //Create the gradients
        CreateGradient(hdc,0,0,rect.right/4+10,rect.bottom+1);
        CreateGradient(hdc,rect.right*3/4-10,0,rect.right+1,rect.bottom+1);
        //Creates the background for drawing
        DrawTheWorkingArea(hdc,rect);
        //Adds the lines to the drawing
        DrawTheLines(hdc,rect);
        //Adds figures to the mix
        DrawGeometry(hdc,rect);
        //Make bmp
        hdcMem = CreateCompatibleDC(hdc);
        SelectObject(hdcMem,hBitmap);
        BitBlt(hdc,rect.right/4+16,6,185,120,hdcMem,0,0,SRCCOPY);
        DeleteDC(hdcMem);
        EndPaint(hwnd,&ps);
        break;

    case WM_CTLCOLORSTATIC:
        SetBkMode((HDC)wParam,TRANSPARENT);
        return (LRESULT)GetStockObject(NULL_BRUSH);

    case WM_GETMINMAXINFO:
        //Setting the minimal size for the window
        MINMAXINFO *ptMinMax;
        ptMinMax=(MINMAXINFO*)lParam;

        ptMinMax->ptMinTrackSize.x=450;
        ptMinMax->ptMinTrackSize.y=300;
        break;

    case WM_DESTROY:

        PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
        break;
    default:                      /* for messages that we don't deal with */
        return DefWindowProc (hwnd, message, wParam, lParam);
    }

    return 0;
}
コード例 #4
0
ファイル: acllib.c プロジェクト: Gnnng/LaserTank
void ellipse(int left,int top,int right, int bottom)
{
	ACL_ASSERT_BEGIN_PAINT;
	Ellipse(g_hmemdc,left,top,right,bottom);
}
コード例 #5
0
ファイル: plotWin32.c プロジェクト: jpflori/pari
static void DrawPoint(void *data, long x, long y)
{
  Ellipse((HDC)data,x-1,y-1,x+1,y+1);
}
コード例 #6
0
ファイル: GDI1.cpp プロジェクト: wolkat/grk-cwiczenia
// funkcja okna zawieraj¹ca obs³ugê meldunków przesy³anych do okna
LRESULT CALLBACK WndProc (HWND Okno, UINT KodMeldunku, WPARAM wParam, LPARAM lParam)
{
	// deklaracja zmiennych
	HMENU mGlowne, mPlik, mInfo;
    	
	// obs³uga meldunku w zale¿noœci od kodu meldunku
	switch (KodMeldunku) 
	{ case WM_CREATE:  // obs³uga utworzenia okna - stworzenie menu
		mPlik = CreateMenu();
		AppendMenu(mPlik, MF_STRING, 100, "&Gong...");
		AppendMenu(mPlik, MF_SEPARATOR, 0, "");
		AppendMenu(mPlik, MF_STRING, 101, "&Koniec");
		mInfo = CreateMenu();
		AppendMenu(mInfo, MF_STRING, 102, "&Autor...");
		mGlowne = CreateMenu();
		AppendMenu(mGlowne, MF_POPUP, (UINT_PTR) mPlik, "&Plik");
		AppendMenu(mGlowne, MF_POPUP, (UINT_PTR) mInfo, "&Info");
		SetMenu(Okno, mGlowne);
		DrawMenuBar(Okno);
		return 0;

	  case WM_COMMAND: // obs³uga wyboru opcji z menu
		switch (wParam)
		{
		case 100: if(MessageBox(Okno, "Czy wygenerowaæ gong?", "Gong", MB_YESNO) == IDYES)
					MessageBeep(0);
                  break;
		case 101: DestroyWindow(Okno); // wymuszenie meldunku WM_DESTROY
        		  break;
		case 102: MessageBox(Okno, "imiê i nazwisko:\nnumer indeksu: ", "Student PJWSTK", MB_OK);
		}
		return 0;
	
	  case WM_PAINT: // obs³uga odœwie¿enia okna
		{	PAINTSTRUCT Paint;
			HDC Kontekst = BeginPaint(Okno, &Paint);
			HPEN Pioro = CreatePen(PS_SOLID, 15, RGB(255,0,0)); // czerwone pióro o gruboœci 15
			HBRUSH Pedzel = CreateSolidBrush(RGB(255,0,0)); // czerwony pêdzel

			SelectObject(Kontekst, Pioro);
			// SelectObject(Kontekst, GetStockObject(WHITE_BRUSH)); // standardowy bia³y pêdzel
			Ellipse(Kontekst, 100, 100, 300, 300);	// narysowanie okrêgu za pomoc¹ aktywnych pióra i pêdzla

			SelectObject(Kontekst, Pedzel);
			POINT wielokat[] = {{106, 200}, {118, 248}, {152, 282}, {200, 294}, {248, 282}, {282, 248}, {294, 200}};
			Polygon(Kontekst, wielokat, 7);  // narysowanie wielok¹ta wype³niaj¹cego doln¹ po³owê okrêgu na czerwono

			SetBkMode(Kontekst, TRANSPARENT); // wypisanie tekstu
			SetTextAlign(Kontekst, TA_CENTER | TA_BOTTOM);
			// SetTextColor(Kontekst, RGB(0,0,0));
			TextOut(Kontekst, 200, 200, "P J W S T K", 11);

			DeleteObject(Pioro); // usuniêcie niepotrzebnych przyborów graficznych
			DeleteObject(Pedzel);
			EndPaint(Okno, &Paint);
		}
		return 0;
  	
	  case WM_DESTROY: // obs³uga zamkniêcia okna - wygenerowanie meldunku WM_QUIT
		PostQuitMessage (0) ;
		return 0;
    
	  default: // standardowa obs³uga wszystkich pozosta³ych meldunków
		return DefWindowProc(Okno, KodMeldunku, wParam, lParam);
	}
}
コード例 #7
0
void RenderOffscreen(HDC hDestDC)
{
	HDC hdc				= hDestDC; // CreateCompatibleDC(hWndMain);
	int err=GetLastError();
	HBITMAP hOldBitmap	= SelectObject(hdc, hbmpOffscreen);
	RECT rect;
	HPEN hPen;
	double dx, dy, px, py,  AngRad, dDeltaAng;
	int pos, p1;
	long CenterX, CenterY;

	hPen = SelectObject(hdc, CreatePen(PS_SOLID, 3, 0L));

	GetClientRect(hWndMain, &rect);

	/* Draw the table */
	CenterX = (rect.right - rect.left)/2;
	CenterY = (rect.bottom - rect.top)/2;
	Ellipse(hdc, CenterX - 100, CenterY - 100, CenterX + 100, CenterY + 100);

	/* Draw the chopsticks */
	dDeltaAng = 360 / PHILOSOPHERS;
	for (pos = 0; pos < PHILOSOPHERS; pos++)	//FIXIT
	{
		/* Draw the chopsticks */
		AngRad = (pos * dDeltaAng)/57.29577951;
		dx = CenterX + (sin(AngRad)*60);
		dy = CenterY - (cos(AngRad)*60);
		MoveToEx(hdc, (int)dx, (int)dy, NULL);
		dx = CenterX + (sin(AngRad)*85);
		dy = CenterY - (cos(AngRad)*85);
		LineTo(hdc, (int)dx, (int)dy);

		//Draw the plate
		AngRad = ((pos * dDeltaAng+dDeltaAng / 2))/57.29577951;
		dx = CenterX + (sin(AngRad) * 72);
		dy = CenterY - (cos(AngRad) * 72);
		Ellipse(hdc, (int)dx-12, (int)dy-12, (int)dx+12, (int)dy+12);
	}

	/* delete the black pen */
	DeleteObject(SelectObject(hdc, hPen));

	/* Draw the philosophers */
	for(pos = 0; pos < PHILOSOPHERS; pos++)
	{
		/* select a pen for each philosopher */
		switch (gDinerState[pos])
		{
		case RESTING:
			hPen = SelectObject(hdc, CreatePen(PS_SOLID, 3, RGB(0, 255, 0)));
			break;

		case WAITING:
		case EATING:
			hPen = SelectObject(hdc, CreatePen(PS_SOLID, 3, RGB(255, 0, 0)));
			break;

		default:
			hPen = SelectObject(hdc, CreatePen(PS_SOLID, 3, 0L));
		}

		AngRad = ((pos * dDeltaAng) + dDeltaAng / 2)/57.29577951;
		px = CenterX + (sin(AngRad)*150);
		py = CenterY - (cos(AngRad)*150);

		/* Draw the Philosopher */
		Ellipse(hdc, (int)px-25, (int)py-25, (int)px+25, (int)py+25);

		//Draw the left arm
		if (gChopstickState[pos] == pos)
		{
			MoveToEx(hdc, (int)px, (int)py, NULL);
			AngRad = (pos * dDeltaAng)/57.29577951;
			dx = CenterX + (sin(AngRad)*85);
			dy = CenterY - (cos(AngRad)*85);
			LineTo(hdc, (int)dx, (int)dy);
		}

		//Draw the right arm
		p1 = pos + 1;
		if (p1 == PHILOSOPHERS)
			p1 = 0;
		if (gChopstickState[p1] == pos)
		{
			MoveToEx(hdc, (int)px, (int)py, NULL);
			AngRad = (p1 * dDeltaAng)/57.29577951;
			dx = CenterX + (sin(AngRad)*85);
			dy = CenterY - (cos(AngRad)*85);
			LineTo(hdc, (int)dx, (int)dy);
		}

		/* Delete the pen */
		DeleteObject(SelectObject(hdc, hPen));			
	}	//for pos

	BitBlt( hDestDC,
				rect.left,
				rect.top,
				rect.right - rect.left,
				rect.bottom-rect.top,
				hdc,
				rect.left,
				rect.top,
				SRCCOPY
			);
	GetLastError();

	SelectObject(hdc, hOldBitmap);

//	DeleteDC(hWndMain, hdc);
}
コード例 #8
0
ファイル: draw.cpp プロジェクト: hedane/HHCARobot
//绘制实验统计数据图表
void draw_stat_chart(PHISTORY history, RECT &rect, int max_round, int min_round, double max_value, double min_value, int type)
{
	int x = type == 0 ? rect.left : rect.right;
	if(type < 2)
	{
		draw_line(x, rect.top, x, rect.bottom);
	}

	int h = (rect.bottom - rect.top) / DRAW_STAT_TAG_NUM;
	x += type == 0 ? -DRAW_STAT_TAG_LEN : DRAW_STAT_TAG_LEN;
	int y = rect.bottom;
	double value = (max_value - min_value) / DRAW_STAT_TAG_NUM;
	char buf[MAX_LOADSTRING];
	for(int i=0;i<=DRAW_STAT_TAG_NUM;i++)
	{
		if(type < 2)
		{
			draw_line(x, y, type == 0 ? rect.left : rect.right, y);
		}
		sprintf_s(buf, sizeof(buf), "%.1f", min_value +  value * i);
		switch(type)
		{
		case 0:
			{
				RECT r = {gDrawClientRect.left, y - h, x, y};
				DrawText(gDrawBmpMemDC, buf, (int)strlen(buf), &r, DT_RIGHT | DT_BOTTOM | DT_SINGLELINE);
			}
			break;
		case 1:
			{
				RECT r = {x, y - h, gDrawClientRect.right, y};
				DrawText(gDrawBmpMemDC, buf, (int)strlen(buf), &r, DT_LEFT | DT_BOTTOM | DT_SINGLELINE);
			}
			break;
		default:
			if(i > 0)
			{
				RECT r = {x, y, gDrawClientRect.right, y + h};
				DrawText(gDrawBmpMemDC, buf, (int)strlen(buf), &r, DT_LEFT | DT_TOP | DT_SINGLELINE);
			}
			break;
		}
		y -= h;
	}

	PHISTORYITEM p = history->head;
	int height = rect.bottom - rect.top;
	int width = rect.right - rect.left;
	const int cr = type == 0 ? 4 : 3;
	int i = 0;
	while(p != NULL)
	{
		x = rect.left + width * (p->round - min_round) / (max_round - min_round);
		switch(type)
		{
		case 0:
			y = rect.bottom - (int)(height * (p->top[0].generation - min_value) / (max_value - min_value));
			break;
		case 1:
			value = (double)p->round / p->top[0].generation;
			y = rect.bottom - (int)(height * (value - min_value) / (max_value - min_value));
			break;
		default:
			value = (double)p->top[0].score / gConfig.lab_more_count;
			y = rect.bottom - (int)(height * (value - min_value) / (max_value - min_value));
			break;
		}
		if(i > 0)
		{
			LineTo(gDrawBmpMemDC, x, y);
		}
		else
		{
			MoveToEx(gDrawBmpMemDC, x, y, NULL);
			Ellipse(gDrawBmpMemDC, x-cr, y-cr, x+cr, y+cr);
		}

		i++;
		p = p->next;
	}
	if(i > 1)
	{
		Ellipse(gDrawBmpMemDC, x-cr, y-cr, x+cr, y+cr);
	}

	switch(type)
	{
	case 0:
		{
			RECT r = {rect.left, gDrawClientRect.top, rect.right/3, rect.top};
			sprintf_s(buf, sizeof(buf), "%s", "—— 子代");
			DrawText(gDrawBmpMemDC, buf, (int)strlen(buf), &r, DT_RIGHT | DT_VCENTER | DT_SINGLELINE);
		}
		break;
	case 1:
		{
			RECT r = {rect.right/3, gDrawClientRect.top, rect.right*2/3, rect.top};
			sprintf_s(buf, sizeof(buf), "%s", "—— 代比");
			DrawText(gDrawBmpMemDC, buf, (int)strlen(buf), &r, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
		}
		break;
	default:
		{
			RECT r = {rect.right*2/3, gDrawClientRect.top, rect.right, rect.top};
			sprintf_s(buf, sizeof(buf), "%s", "—— 平均分");
			DrawText(gDrawBmpMemDC, buf, (int)strlen(buf), &r, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
		}
		break;
	}
}
コード例 #9
0
ファイル: MainWindow.cpp プロジェクト: MishaGubsky/studies
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	UINT code;      // код уведомления
	UINT idCtrl;     // идентификатор дочернего окна
	HWND hChild;
	HDC hdc;
	HBRUSH hBrush;
	switch (msg)
	{

	case WM_PAINT:
		HDC hdc;
		PAINTSTRUCT ps;
		RECT rc;

		// Перерисовываем внутреннюю область окна
		hdc = BeginPaint(hWnd, &ps);
		GetClientRect(hWnd, &rc);
		EndPaint(hWnd, &ps);
		break;
	case WM_COPYDATA:
		szBuf =(int*) ((PCOPYDATASTRUCT)lParam)->lpData;
		i = szBuf[0];
		j = szBuf[1];
		k = szBuf[2];
		break;
	case WM_RBUTTONDOWN:
	case WM_LBUTTONDOWN:
	{
		if (k == 1)
		{
			hdc = GetDC(hWnd);
			hBrush = CreateSolidBrush(RGB(255, 0, 0));
			switch (i)
			{
			case 1:
				hBrush = CreateSolidBrush(RGB(255, 0, 0));
				break;
			case 2:
				hBrush = CreateSolidBrush(RGB(0, 0, 255));
				break;
			case 3:
				hBrush = CreateSolidBrush(RGB(0, 255, 0));
				break;
			}
			SelectObject(hdc, hBrush);

			switch (j)
			{
			case 1:
				POINT poly[5];

				poly[0].x = LOWORD(lParam);
				poly[0].y = HIWORD(lParam)-50;

				poly[1].x = LOWORD(lParam) - 40;
				poly[1].y = HIWORD(lParam) ;

				poly[2].x = LOWORD(lParam);
				poly[2].y = HIWORD(lParam) + 50;

				poly[3].x = LOWORD(lParam) + 40;
				poly[3].y = HIWORD(lParam) ;

				poly[4].x = LOWORD(lParam);
				poly[4].y = HIWORD(lParam)-50;

				Polyline(hdc, poly, 5);
				FloodFill(hdc, LOWORD(lParam), HIWORD(lParam), 0);
				break;
			case 2:
				Rectangle(hdc, LOWORD(lParam)-50, HIWORD(lParam)-50, LOWORD(lParam) + 50, HIWORD(lParam) + 50);
				break;
			case 3:
				Ellipse(hdc, LOWORD(lParam)-50, HIWORD(lParam)-50, LOWORD(lParam) + 50, HIWORD(lParam) + 50);
				break;
			case 4:
				POINT poly1[11];

				poly1[0].x = LOWORD(lParam);
				poly1[0].y = HIWORD(lParam)-90;

				poly1[1].x = LOWORD(lParam) - 30;
				poly1[1].y = HIWORD(lParam) - 30;

				poly1[2].x = LOWORD(lParam) - 90;
				poly1[2].y = HIWORD(lParam) - 20;

				poly1[3].x = LOWORD(lParam) - 50;
				poly1[3].y = HIWORD(lParam) + 30;

				poly1[4].x = LOWORD(lParam) - 60;
				poly1[4].y = HIWORD(lParam) + 90;




				poly1[5].x = LOWORD(lParam);
				poly1[5].y = HIWORD(lParam) + 70;

				poly1[6].x = LOWORD(lParam) + 60;
				poly1[6].y = HIWORD(lParam) + 90;

				poly1[7].x = LOWORD(lParam) + 50;
				poly1[7].y = HIWORD(lParam) + 30;

				poly1[8].x = LOWORD(lParam) + 90;
				poly1[8].y = HIWORD(lParam) - 20;

				poly1[9].x = LOWORD(lParam) + 30;
				poly1[9].y = HIWORD(lParam) - 30;

				poly1[10].x = LOWORD(lParam);
				poly1[10].y = HIWORD(lParam)-90;

				Polyline(hdc, poly1, 11);
				FloodFill(hdc, LOWORD(lParam), HIWORD(lParam), 0);
				break;
			}


			ReleaseDC(hWnd, hdc);
		}
	}break;
	case WM_DESTROY:
	{
		PostQuitMessage(0);
	} break;
	default: return DefWindowProc(hWnd, msg, wParam, lParam);
	}
	return 0;
}
コード例 #10
0
ファイル: Selection.cpp プロジェクト: jimmccurdy/ArchiveGit
void CSelection::InvertSelection(HWND hWnd, HDC hDC, RECT* pRect, int fFlags)
{
	short OldROP;
	bool fNeedDC;
	RECT SelectRect;
	static RECT LastSelectRect;
	static int LastFlags;
	bool fDoc = false;
	int type;

	if (pRect->right - pRect->left > 50)
		int i = 0;

	if (fFlags && pRect)
	{ // Saved for the display hook
		LastSelectRect = *pRect;
		LastFlags = fFlags;
	}
	else
	{ // Called from the display hook
		fFlags = LastFlags;
	}

	type = fFlags & SL_TYPE;
	SelectRect = LastSelectRect;
	if (fDoc)
	{
//j		if (type == SL_LINE)
//j		{
//j			File2DisplayEx(hWnd, (LPINT)&SelectRect.left, (LPINT)&SelectRect.top, true);
//j			File2DisplayEx(hWnd, (LPINT)&SelectRect.right, (LPINT)&SelectRect.bottom, true);
//j		}
//j		else
//j		{
//j			OrderRect(&SelectRect, &SelectRect);
//j			File2DispRectExact(hWnd, &SelectRect, &SelectRect); 
//j		}
	}

	if (fNeedDC = (!hDC))
		hDC = GetDC(hWnd);

	switch (type)
	{
		case SL_BOX:
		{
			OldROP = SetROP2(hDC, R2_NOT);
			MoveToEx(hDC, SelectRect.left, SelectRect.top, NULL);
			LineTo(hDC, SelectRect.right, SelectRect.top);
			LineTo(hDC, SelectRect.right, SelectRect.bottom);
			LineTo(hDC, SelectRect.left, SelectRect.bottom);
			LineTo(hDC, SelectRect.left, SelectRect.top);
			SetROP2(hDC, OldROP);
			break;
		}

		case SL_BOXHANDLES:
		{
			OldROP = SetROP2(hDC, R2_NOT);
			MoveToEx(hDC, SelectRect.left, SelectRect.top, NULL);
			LineTo(hDC, SelectRect.right, SelectRect.top);
			LineTo(hDC, SelectRect.right, SelectRect.bottom);
			LineTo(hDC, SelectRect.left, SelectRect.bottom);
			LineTo(hDC, SelectRect.left, SelectRect.top);
			SetROP2(hDC, OldROP);
			DrawHandles(hDC, &SelectRect);
			break;
		}

	#ifdef NOTUSED //j
		case SL_GRID:
		{
			RECT ClientRect;
			int x, y, dx, dy, cx, cy;

			OldROP = SetROP2(hDC, R2_NOT);
			GetClientRect(hWnd, &ClientRect);
			dx = abs(RectWidth(&SelectRect));
			dy = abs(RectHeight(&SelectRect));
			if (dx > CLOSENESS && dy > CLOSENESS)
			{
				x = min(SelectRect.left, SelectRect.right);
				cx = x;
				Image2Control(&cx, &cy);
				while (cx >= ClientRect.left)
				{
					MoveToEx(hDC, cx, ClientRect.top, NULL);
					LineTo(hDC, cx, ClientRect.bottom);
					x -= dx;
					cx = x;
					Image2Control(&cx, &cy);
				}
				x = max(SelectRect.left, SelectRect.right);
				cx = x;
				Image2Control(&cx, &cy);
				while (cx <= ClientRect.right)
				{
					MoveToEx(hDC, cx, ClientRect.top, NULL);
					LineTo(hDC, cx, ClientRect.bottom);
					x += dx;
					cx = x;
					Image2Control(&cx, &cy);
				}
				y = min(SelectRect.top, SelectRect.bottom);
				cy = y;
				Image2Control(&cx, &cy);
				while (cy >= ClientRect.top)
				{
					MoveToEx(hDC, ClientRect.left, cy, NULL);
					LineTo(hDC, ClientRect.right, cy);
					y -= dy;
					cy = y;
					Image2Control(&cx, &cy);
				}
				y = max(SelectRect.top, SelectRect.bottom);
				cy = y;
				Image2Control(&cx, &cy);
				while (cy <= ClientRect.bottom)
				{
					MoveToEx(hDC, ClientRect.left, cy, NULL);
					LineTo(hDC, ClientRect.right, cy);
					y += dy;
					cy = y;
					Image2Control(&cx, &cy);
				}
			}
			else
			{
				Image2Control((LPINT)&SelectRect.left, (LPINT)&SelectRect.top);
				Image2Control((LPINT)&SelectRect.right, (LPINT)&SelectRect.bottom);
				MoveToEx(hDC, SelectRect.left, SelectRect.top, NULL);
				LineTo(hDC, SelectRect.right, SelectRect.top);
				LineTo(hDC, SelectRect.right, SelectRect.bottom);
				LineTo(hDC, SelectRect.left, SelectRect.bottom);
				LineTo(hDC, SelectRect.left, SelectRect.top);
			}
			SetROP2(hDC, OldROP);
			break;
		}
	#endif NOTUSED //j

		case SL_LINE:
		{
			OldROP = SetROP2(hDC, R2_NOT);
			MoveToEx(hDC, SelectRect.left, SelectRect.top, NULL);
			LineTo(hDC, SelectRect.right, SelectRect.bottom);
			SetROP2(hDC, OldROP);
			break;
		}

		case SL_ELLIPSE:
		{
			OldROP = SetROP2(hDC, R2_NOT);
			HBRUSH hOldBrush = (HBRUSH)SelectObject(hDC, GetStockObject(NULL_BRUSH));
			Ellipse(hDC, SelectRect.left, SelectRect.top,
				SelectRect.right, SelectRect.bottom);
			SetROP2(hDC, OldROP);
			SelectObject(hDC, hOldBrush);
			break;
		}

		case SL_BLOCK:
		{
			PatBlt(hDC, SelectRect.left, SelectRect.top,
				SelectRect.right - SelectRect.left,
				SelectRect.bottom - SelectRect.top, DSTINVERT);
			break;
		}
	}

	if (fNeedDC)
		ReleaseDC(hWnd, hDC);
}
コード例 #11
0
LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
   switch( uMsg )
   {
      case WM_COMMAND :
              switch( LOWORD( wParam ) )
              {
                 case IDM_TEST :
                        {
                           BITMAPINFOHEADER  bi;
                           BITMAPINFOHEADER* lpbi;
                           HBITMAP           hBitmap;
                           HDC               hDC, hMemDC;
                           HANDLE            hDIB;

                           // Initialize the BITMAPINFOHEADER structure.
                           //...........................................
                           bi.biSize     = sizeof( BITMAPINFOHEADER );
                           bi.biWidth    = 50;
                           bi.biHeight   = 50;
                           bi.biPlanes   = 1;
                           bi.biBitCount = 4;
                           bi.biCompression   = BI_RGB;
                           bi.biSizeImage     = 0;
                           bi.biXPelsPerMeter = 0;
                           bi.biYPelsPerMeter = 0;
                           bi.biClrUsed       = 0;
                           bi.biClrImportant  = 0;

                           hDC = GetDC( hWnd );

                           // Create DIB.
                           //............
                           hBitmap = CreateDIBitmap( hDC, &bi, 0L, NULL, 
                                                     NULL, 0 );

                           // Allocate memory for BITMAPINFO structure.
                           //..........................................
                           hDIB    = GlobalAlloc( GHND, 
                                                  sizeof( BITMAPINFOHEADER )+
                                                  16 * sizeof( RGBQUAD ) );

                           lpbi = (BITMAPINFOHEADER*)GlobalLock( hDIB );

                           // Copy bi to top of BITMAPINFO structure.
                           //........................................
                           *lpbi = bi;

                           // Use GetDIBits() to init bi struct data.
                           //........................................
                           GetDIBits( hDC, hBitmap, 0, 50, NULL, 
                                      (LPBITMAPINFO)lpbi, DIB_RGB_COLORS );
                           GlobalUnlock( hDIB );

                           // Create a memory device context 
                           // and select the DIB into it.
                           //...............................
                           hMemDC = CreateCompatibleDC( hDC );
                           SelectObject( hMemDC, hBitmap );

                           // Paint on memory device context.
                           //................................
                           SelectObject( hMemDC, GetStockObject(BLACK_BRUSH));
                           Rectangle( hMemDC, 0, 0, 50, 50 );

                           SelectObject( hMemDC, GetStockObject(WHITE_BRUSH));
                           Ellipse( hMemDC, 0, 0, 50, 50 );
                           Ellipse( hMemDC, 10, 0, 40, 50 );
                           Ellipse( hMemDC, 20, 0, 30, 50 );

                           // Paint the bitmap on the display.
                           //.................................
                           BitBlt( hDC, 0, 0, 50, 50,
                                   hMemDC, 0, 0, SRCCOPY );

                           DeleteDC( hMemDC );
                           GlobalFree( hDIB );
                           ReleaseDC( hWnd, hDC );
                        }
                        break;

                 case IDM_ABOUT :
                        DialogBox( hInst, "AboutBox", hWnd, (DLGPROC)About );
                        break;

                 case IDM_EXIT :
                        DestroyWindow( hWnd );
                        break;
              }
              break;
      
      case WM_DESTROY :
              PostQuitMessage(0);
              break;

      default :
            return( DefWindowProc( hWnd, uMsg, wParam, lParam ) );
   }

   return( 0L );
}
コード例 #12
0
ファイル: mylaba.cpp プロジェクト: hrumil/laby-AYA
LRESULT CALLBACK WinFun(HWND hwnd, UINT message, 
						WPARAM wParam, LPARAM lParam)
{
	HDC hdc;
	PAINTSTRUCT ps;
	HPEN Pen=CreatePen(PS_DASHDOTDOT, 1, RGB(130,10,130));		// Стиль и цвет границы
	HBRUSH br=CreateHatchBrush(HS_DIAGCROSS, RGB(255,255,0));	// Стиль и цвет штриховки
			
	switch(message)
	{
	case WM_RBUTTONDOWN:
		x2=x1=LOWORD(lParam);
		y2=y1=HIWORD(lParam);
		break;
	case WM_MOUSEMOVE:
		if (wParam & MK_RBUTTON)								// Определяем нажатие правой кнопки мыши
		{
			x2=LOWORD(lParam);
			y2=HIWORD(lParam);
		}
		break;
	case WM_RBUTTONUP:											// Отпускаем правую кнопку мыши
		hdc=GetDC(hwnd);
		SelectObject(hdc, Pen);									// Делаем перо активным
		Ellipse(hdc, x1, y1, x2, y2);							// Определяем размеры эллипса
		SelectObject(hdc, br);									// Делаем кисть активной
		Ellipse(hdc, x1, y1, x2, y2);							// Определяем размеры заштрихованной части
		DeleteObject(Pen);										// Удаляем перо
		DeleteObject(br);										// Удаляем кисть
		ReleaseDC(hwnd, hdc);
		
		p=new EllipsList;
		p->L.x1=x1; p->L.x2=x2;
		p->L.y1=y1; p->L.y2=y2;
		add(pFirst, p);
		break;

	//case WM_ERASEBKGND:										// Не стирает рисунок
	case WM_PAINT:												// Перерисовка
		hdc=BeginPaint(hwnd, &ps);
		p=pFirst;
		while(p)												// Просматриваем список и рисуем эллипс
		{
		SelectObject(hdc, Pen);									// Делаем перо активным
		Ellipse(hdc, p->L.x1, p->L.y1, p->L.x2, p->L.y2);		// Определяем размеры эллипса
		SelectObject(hdc, br);									// Делаем кисть активной
		Ellipse(hdc, p->L.x1, p->L.y1, p->L.x2, p->L.y2);		// Определяем размеры заштрихованной части
		p=p->pNext;
		}
		
		EndPaint(hwnd, &ps);
		break;
	
	case WM_DESTROY:											// Завершение программы
		PostQuitMessage(0);
		break;


	default:
// Позволяет Windows обрабатывать любые сообщения, неуказанные в предыдущем случае
		return DefWindowProc(hwnd, message, wParam, lParam);
	}
	return 0;
}
コード例 #13
0
BOOL TabletBase::ProcessMessage(UINT msg, WPARAM wParam, LPARAM lParam) 
{
	PACKET          pkt;             /* the current packet */
	HDC             hDC;             /* handle for Device Context */
	PAINTSTRUCT     psPaint;         /* the paint structure */

	//渡された message から、イベントの種類を解析する
	switch(msg){

	case WM_PAINT: { /* Paint the window */
		int ZAngle;         /* Raw Altitude */
		UINT Thata;         /* Raw Azimuth */
		double ZAngle2;     /* Adjusted Altitude */
		double Thata2;      /* Adjusted Azimuth */

		char szOutput[128]; /* String for outputs */

		if (m_TiltSupport) {                             
			/* 
			wintab.h defines .orAltitude 
			as a UINT but documents .orAltitude 
			as positive for upward angles 
			and negative for downward angles.
			WACOM uses negative altitude values to 
			show that the pen is inverted; 
			therefore we cast .orAltitude as an 
			(int) and then use the absolute value. 
			*/
			ZAngle  = (int)m_ortNew.orAltitude;
			ZAngle2 = m_altAdjust - (double)abs(ZAngle)/m_altFactor;
			/* adjust azimuth */
			Thata  = m_ortNew.orAzimuth;
			Thata2 = (double)Thata/m_aziFactor;
			/* get the length of the diagnal to draw */  
			m_Z1Angle.x = (int)(ZAngle2*sin(Thata2));
			m_Z1Angle.y = (int)(ZAngle2*cos(Thata2));
		}
		else {
			m_Z1Angle.x = 0;
			m_Z1Angle.y = 0;
		}

		if (hDC = BeginPaint(m_hWnd, &psPaint)) {

			/* write raw tilt info */ 
			if (m_TiltSupport) {                             
				wsprintf((LPSTR)szOutput,"Tilt: %03i, Thata: %04u\0",
					ZAngle,Thata);
			}
			else {
				strcpy(szOutput,"Tilt not supported.");
			}
			DrawText(hDC,szOutput,strlen(szOutput),&m_rcInfoTilt,DT_LEFT);

			/* write current cursor name */ 
			gpWTInfoA(WTI_CURSORS + m_curNew, CSR_NAME, szOutput);
			DrawText(hDC,szOutput,strlen(szOutput),&m_rcInfoName,DT_LEFT);

			/* write tablet name */
			gpWTInfoA(WTI_DEVICES, DVC_NAME, szOutput);
			DrawText(hDC,szOutput,strlen(szOutput),&m_rcInfoGen,DT_LEFT);

			/* draw circle based on tablet pressure */
			Ellipse(hDC, m_ptNew.x - m_prsNew, m_ptNew.y - m_prsNew,
				m_ptNew.x + m_prsNew, m_ptNew.y + m_prsNew);

			/* draw a line based on tablet tilt */
			MoveTo(hDC, m_ptNew.x, m_ptNew.y);
			LineTo(hDC, m_ptNew.x + m_Z1Angle.x, m_ptNew.y - m_Z1Angle.y);

			/* draw CROSS based on tablet position */ 
			MoveTo(hDC, m_ptNew.x - 20, m_ptNew.y     );
			LineTo(hDC, m_ptNew.x + 20, m_ptNew.y     );
			MoveTo(hDC, m_ptNew.x     , m_ptNew.y - 20);
			LineTo(hDC, m_ptNew.x     , m_ptNew.y + 20);
			EndPaint(m_hWnd, &psPaint);
		}
		break;
				   }

	case WT_PACKET: /* A packet is waiting from WINTAB */
		if (gpWTPacket((HCTX)lParam, wParam, &pkt)) {

			/* old co-ordinates used for comparisons */
			POINT 		ptOld = m_ptNew; 
			UINT  		prsOld = m_prsNew;
			UINT  		curOld = m_curNew;
			ORIENTATION ortOld = m_ortNew;

			/* save new co-ordinates */
			m_ptNew.x = (UINT)pkt.pkX;
			m_ptNew.y = (UINT)pkt.pkY;
			m_curNew = pkt.pkCursor;
			m_prsNew = pkt.pkNormalPressure;
			m_ortNew = pkt.pkOrientation;

			/* If the visual changes update the main graphic */
			if (m_ptNew.x != ptOld.x ||
				m_ptNew.y != ptOld.y ||
				m_prsNew != prsOld ||
				m_ortNew.orAzimuth != ortOld.orAzimuth ||
				m_ortNew.orAltitude != ortOld.orAltitude ||
				m_ortNew.orTwist != ortOld.orTwist) {                                     
					InvalidateRect(m_hWnd, &m_rcDraw, TRUE);
			}
			/* if the displayed data changes update the text */
			if (m_ortNew.orAzimuth != ortOld.orAzimuth ||
				m_ortNew.orAltitude != ortOld.orAltitude ||
				m_ortNew.orTwist != ortOld.orTwist) {
					InvalidateRect(m_hWnd, &m_rcInfoTilt, TRUE);
			}
			/* if the cursor changes update the cursor name */
			if (m_curNew != curOld) {
				InvalidateRect(m_hWnd, &m_rcInfoName, TRUE);
			}
		}
		break;

		//----終了処理----
	case WM_DESTROY:
		UnloadWintab( );
		PostQuitMessage(0);
		break;

		//----デフォルトの処理----
	default :
		return DefWindowProc(m_hWnd,msg,wParam,lParam);
	}

	return 0L;
}
コード例 #14
0
ファイル: main.cpp プロジェクト: wetosc/LabWP
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)                  /* handle the messages */
    {
    case WM_CREATE:
    {
        HWND radioButton_1 = CreateWindowEx(0, "Button", "Rectangle", WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON, 4, 10, 100, 20, hwnd, (HMENU)1, NULL, NULL);
        HWND radioButton_2 = CreateWindowEx(0, "Button", "Ellipse", WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON, 4, 30, 100, 20, hwnd, (HMENU)2, NULL, NULL);
        HWND radioButton_3 = CreateWindowEx(0, "Button", "Pie", WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON, 4, 50, 100, 20, hwnd, (HMENU)3, NULL, NULL);
        HWND checkBox_1 = CreateWindowEx(0,"Button","Red",WS_VISIBLE | WS_CHILD | BS_AUTOCHECKBOX,4,70,100,20,hwnd,(HMENU)4,NULL,NULL);
        HWND checkBox_2 = CreateWindowEx(0,"Button","Green",WS_VISIBLE | WS_CHILD | BS_AUTOCHECKBOX,4,90,100,20,hwnd,(HMENU)5,NULL,NULL);
        HWND checkBox_3 = CreateWindowEx(0,"Button","Blue",WS_VISIBLE | WS_CHILD | BS_AUTOCHECKBOX,4,110,100,20,hwnd,(HMENU)6,NULL,NULL);
        HWND pushButton_1 = CreateWindow( "Button", "Play", WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,4,130,50,20,hwnd,(HMENU)7,NULL,NULL);
        HWND pushButton_2 = CreateWindow( "Button", "Pause", WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,54,130,50,20,hwnd,(HMENU)8,NULL,NULL);
        checks[0] = checkBox_1;
        checks[1] = checkBox_2;
        checks[2] = checkBox_3;
        break;
    }
    case WM_COMMAND:
    {
        switch (wParam)
        {
        case 1:
            figure = 0;
            break;
        case 2:
            figure = 1;
            break;
        case 3:
            figure = 2;
            break;
        case 4:
            color = 0;
            if (SendMessage(checks[0], BM_GETCHECK,0,0 ) == BST_CHECKED)
            {
                EnableWindow(checks[1], false);
                EnableWindow(checks[2], false);
            }
            else
            {
                EnableWindow(checks[1], true);
                EnableWindow(checks[2], true);
            }
            break;
        case 5:
            if (SendMessage(checks[1], BM_GETCHECK,0,0 ) == BST_CHECKED)
            {
                EnableWindow(checks[0], false);
                EnableWindow(checks[2], false);
            }
            else
            {
                EnableWindow(checks[0], true);
                EnableWindow(checks[2], true);
            }
            color = 1;
            break;
        case 6:
            if (SendMessage(checks[2], BM_GETCHECK,0,0 ) == BST_CHECKED)
            {
                EnableWindow(checks[0], false);
                EnableWindow(checks[1], false);
            }
            else
            {
                EnableWindow(checks[0], true);
                EnableWindow(checks[1], true);
            }
            color = 2;
            break;
        case 7:
            SetTimer(hwnd, 7, 100, NULL);
            break;
        case 8:
            KillTimer(hwnd, 7);
            break;
        default:
            break;
        }
        InvalidateRect(hwnd, NULL, FALSE);
        break;
    }
    case WM_PAINT:
    {
        PAINTSTRUCT ps;
        RECT rc;
        GetClientRect(hwnd, &rc);
        HDC hdc = BeginPaint (hwnd, &ps) ;
        FillRect(hdc, &rc, CreateSolidBrush(RGB(255,255,255)));

        switch (color)
        {
        case 0:
            SelectObject(hdc, CreateSolidBrush(RGB(255,0,0)));
            break;
        case 1:
            SelectObject(hdc, CreateSolidBrush(RGB(0,255,0)));
            break;
        case 2:
            SelectObject(hdc, CreateSolidBrush(RGB(0,0,255)));
            break;
        }
        int x= 300 + cos(angle)*100;
        int y= 150 + sin(angle)*100;
        switch (figure)
        {
        case 0:
            Rectangle(hdc, x-10, y-10, x+10, y+10);
            break;
        case 1:
            Ellipse(hdc, x-15, y-10, x+15, y+10);
            break;
        case 2:
            Pie(hdc, x-10, y-10, x+10, y+10, x-5,y-10,x+10,y+5);
            break;
        }
        EndPaint (hwnd, &ps) ;
        break;
    }

    case WM_TIMER:
    {
        angle+=3.14*5/180;
        InvalidateRect(hwnd, NULL, FALSE);
        break;
    }
    case WM_DESTROY:
        PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
        break;
    default:                      /* for messages that we don't deal with */
        return DefWindowProc (hwnd, message, wParam, lParam);
    }

    return 0;
}
コード例 #15
0
ファイル: OSiSP1.cpp プロジェクト: LisP94/OSiSP
LRESULT CALLBACK WndclProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	static HDC hdcch,hdcch1;
	int width=200, height=200;
	static HPEN pens, penm, penh;
	COLORREF clr;
	PAINTSTRUCT ps;
	TIME time;
	LPARAM param;
	RECT rect;
	static int timer,min,hour,xs,ys,xm,ym,xh,yh;
	HBITMAP hbmp;
	switch (message)
	{
	case WM_CREATE:
		hdcch = GetDC(hWnd);
		hdcch1 = CreateCompatibleDC(hdcch);
		hbmp = CreateCompatibleBitmap(hdcch, width, height);
		pens = CreatePen(PS_SOLID, 1,RGB(0,0,0));
		penm = CreatePen(PS_SOLID, 2, RGB(0, 0, 0));
		penh = CreatePen(PS_SOLID, 3, RGB(0, 0, 0));
		SelectObject(hdcch1, hbmp);
		rect.left = 0;
		rect.top = 0;
		rect.right = width;
		rect.bottom = height;
		FillRect(hdcch1, &rect, (HBRUSH)CreateSolidBrush(RGB(255, 255, 255)));
		SelectObject(hdcch1, penh);
		Ellipse(hdcch1, 30, 20, 160, 150);
		TextOut(hdcch1, 88, 25, L"12", 2);
		TextOut(hdcch1, 145, 75, L"3", 1);
		TextOut(hdcch1, 90, 130, L"6", 1);
		TextOut(hdcch1, 35, 75, L"9", 1);
		ReleaseDC(hWnd, hdcch);
		timer = SetTimer(hWnd, 1, 1000, NULL);
		time.xs = 0;
		time.ys = -60;
		time.xm = 0;
		time.ym = -50;
		time.xh = 0;
		time.yh = -30;
		time.min = 0;
		time.hour = 0;
		SetTime(time);
		xs=time.xs;
		ys=time.ys;
		xm=time.xm;
		ym=time.ym;
		xh=time.xh;
		yh=time.yh;
		min=time.min;
		hour=time.hour;
		break;
	case WM_TIMER:
		hdcch = GetDC(hWnd);
		min++;
		if (min== 60)
		{
			NewHand(xm, ym);
			min = 0;
			xs = 0;
			ys = -60;
			hour++;
		}
		if (hour == 12)
		{
			NewHand(xh, yh);
			hour = 0;
		}
		NewHand(xs, ys);
		BitBlt(hdcch, 0, 0, 200, 200, hdcch1, 0, 0, SRCCOPY);
		MoveToEx(hdcch, 95, 85, NULL);
		SelectObject(hdcch, pens);
		LineTo(hdcch, xs+95, ys+85);
		MoveToEx(hdcch, 95, 85, NULL);
		SelectObject(hdcch, penm);
		LineTo(hdcch, xm+95, ym+85);
		MoveToEx(hdcch, 95, 85, NULL);
		SelectObject(hdcch, penh);
		LineTo(hdcch, xh+95, yh+85);
		ReleaseDC(hWnd, hdcch);
		break;
	case WM_PAINT:
		hdcch = BeginPaint(hWnd, &ps);
		BitBlt(hdcch, 0, 0, 200,200 , hdcch1, 0, 0, SRCCOPY);
		MoveToEx(hdcch, 95, 85, NULL);
		SelectObject(hdcch, pens);
		LineTo(hdcch, xs+95, ys+85);
		MoveToEx(hdcch, 95, 85, NULL);
		SelectObject(hdcch, penm);
		LineTo(hdcch, xm+95, ym+85);
		MoveToEx(hdcch, 95, 85, NULL);
		SelectObject(hdcch, penh);
		LineTo(hdcch, xh+95, yh+85);
		EndPaint(hWnd, &ps);
		break;
	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
	}
	return 0;
}
コード例 #16
0
ファイル: libshapes.c プロジェクト: ajstarks/openvg
// Circle makes a circle at the specified location and dimensions
void Circle(VGfloat x, VGfloat y, VGfloat r) {
	Ellipse(x, y, r, r);
}
コード例 #17
0
ファイル: Bounce.c プロジェクト: AaronFae/VimProject
LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
     static HBITMAP hBitmap ;
     static int     cxClient, cyClient, xCenter, yCenter, cxTotal, cyTotal,
                    cxRadius, cyRadius, cxMove, cyMove, xPixel, yPixel ;
     HBRUSH         hBrush ;
     HDC            hdc, hdcMem ;
     int            iScale ;
     
     switch (iMsg)
     {
     case WM_CREATE:
          hdc = GetDC (hwnd) ;
          xPixel = GetDeviceCaps (hdc, ASPECTX) ;
          yPixel = GetDeviceCaps (hdc, ASPECTY) ;
          ReleaseDC (hwnd, hdc) ;
          
          SetTimer (hwnd, ID_TIMER, 50, NULL) ;
          return 0 ;
          
     case WM_SIZE:
          xCenter = (cxClient = LOWORD (lParam)) / 2 ;
          yCenter = (cyClient = HIWORD (lParam)) / 2 ;
          
          iScale = min (cxClient * xPixel, cyClient * yPixel) / 16 ;
          
          cxRadius = iScale / xPixel ;
          cyRadius = iScale / yPixel ;
          
          cxMove = max (1, cxRadius / 2) ;
          cyMove = max (1, cyRadius / 2) ;
          
          cxTotal = 2 * (cxRadius + cxMove) ;
          cyTotal = 2 * (cyRadius + cyMove) ;
          
          if (hBitmap)
               DeleteObject (hBitmap) ;
          
          hdc = GetDC (hwnd) ;
          hdcMem = CreateCompatibleDC (hdc) ;
          hBitmap = CreateCompatibleBitmap (hdc, cxTotal, cyTotal) ;
          ReleaseDC (hwnd, hdc) ;
          
          SelectObject (hdcMem, hBitmap) ;
          Rectangle (hdcMem, -1, -1, cxTotal + 1, cyTotal + 1) ;
          
          hBrush = CreateHatchBrush (HS_DIAGCROSS, 0L) ;
          SelectObject (hdcMem, hBrush) ;
          SetBkColor (hdcMem, RGB (255, 0, 255)) ;
          Ellipse (hdcMem, cxMove, cyMove, cxTotal - cxMove, cyTotal - cyMove) ;
          DeleteDC (hdcMem) ;
          DeleteObject (hBrush) ;
          return 0 ;
          
     case WM_TIMER:
          if (!hBitmap)
               break ;
          
          hdc = GetDC (hwnd) ;
          hdcMem = CreateCompatibleDC (hdc) ;
          SelectObject (hdcMem, hBitmap) ;
          
          BitBlt (hdc, xCenter - cxTotal / 2,
                       yCenter - cyTotal / 2, cxTotal, cyTotal,
                  hdcMem, 0, 0, SRCCOPY) ;
          
          ReleaseDC (hwnd, hdc) ;
          DeleteDC (hdcMem) ;
          
          xCenter += cxMove ;
          yCenter += cyMove ;
          
          if ((xCenter + cxRadius >= cxClient) || (xCenter - cxRadius <= 0))
               cxMove = -cxMove ;
          
          if ((yCenter + cyRadius >= cyClient) || (yCenter - cyRadius <= 0))
               cyMove = -cyMove ;
          
          return 0 ;
          
     case WM_DESTROY:
          if (hBitmap)
               DeleteObject (hBitmap) ;
          
          KillTimer (hwnd, ID_TIMER) ;
          PostQuitMessage (0) ;
          return 0 ;
     }
     return DefWindowProc (hwnd, iMsg, wParam, lParam) ;
}
コード例 #18
0
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    static HWND hPencil, hLine, hBezier, hRectangle, hEllipse, hEraser, hFill, hBorderW, hEraserW, hClear;

    RECT rect ;
    PAINTSTRUCT ps;
    HDC hdc = GetDC(hwnd);

    int screenW, screenH;
    int xMouse, yMouse;

    int xFillPreview = 200;
    int yFillPreview = 515;
    int xStrokePreview = 310;
    int yStrokePreview = 515;

    HDC hdcMem;
    BITMAP bitmap;
    HBITMAP hbit;

    static RECT drawingArea = {25, 55, 750, 500};
    static RECT fillColorRect = {xFillPreview, yFillPreview, xFillPreview + 25, yFillPreview + 20};
    static RECT borderColorRect = {xStrokePreview, yStrokePreview, xStrokePreview + 25, yStrokePreview + 20};

    static RECT tempRect;

    HBRUSH hBrush;
    static POINT pointPen;
    POINT point;
    HPEN linePen;
    int width;

    static BOOL lineStarted, rectangleStarted, ellipseStarted;
    static RECT rectangle, ellipse;
    static int bezierStage = 0;
    static POINT line;
    static POINT bezierPoints[4];

    HPEN borderPen;
    HBRUSH fillBrush;

    switch (message)
    {

    case WM_CREATE:
        hImageBttn = LoadBitmap(GetModuleHandle(0), MAKEINTRESOURCE(IDB_PENCIL));

        screenW = GetSystemMetrics(SM_CXSCREEN);
        screenH = GetSystemMetrics(SM_CYSCREEN);
        GetWindowRect(hwnd, &rect);
        SetWindowPos(hwnd, 0, (screenW - rect.right)/2, (screenH - rect.bottom)/2, 0, 0, SWP_NOZORDER|SWP_NOSIZE);
        hPencil = CreateWindowEx(
                      0,
                      "Button",
                      NULL,
                      WS_VISIBLE| WS_CHILD|BS_AUTORADIOBUTTON | BS_PUSHLIKE | BS_BITMAP ,
                      25, 15,
                      32, 32,
                      hwnd,
                      (HMENU)IDB_pencil,
                      hInst,
                      NULL);
        SendMessage(hPencil, BM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hImageBttn);

        hImageBttn = LoadBitmap(GetModuleHandle(0), MAKEINTRESOURCE(IDB_LINE));
        hLine = CreateWindowEx(
                    0,
                    "Button",
                    NULL,
                    WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON | BS_PUSHLIKE | BS_BITMAP,
                    65, 15,
                    32, 32,
                    hwnd,
                    (HMENU)IDB_line,
                    hInst,
                    NULL);
        SendMessage(hLine, BM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hImageBttn);

        hImageBttn = LoadBitmap(GetModuleHandle(0), MAKEINTRESOURCE(IDB_BEZIER));
        hBezier = CreateWindowEx(
                      0,
                      "Button",
                      NULL,
                      WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON | BS_PUSHLIKE | BS_BITMAP,
                      105, 15,
                      32, 32,
                      hwnd,
                      (HMENU)IDB_bezier,
                      hInst,
                      NULL);
        SendMessage(hBezier, BM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hImageBttn);

        hImageBttn = LoadBitmap(GetModuleHandle(0), MAKEINTRESOURCE(IDB_RECTANGLE));
        hRectangle = CreateWindowEx(
                         0,
                         "Button",
                         NULL,
                         WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON | BS_PUSHLIKE | BS_BITMAP,
                         145, 15,
                         32, 32,
                         hwnd,
                         (HMENU)IDB_rectangle,
                         hInst,
                         NULL);
        SendMessage(hRectangle, BM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hImageBttn);

        hImageBttn = LoadBitmap(GetModuleHandle(0), MAKEINTRESOURCE(IDB_ELLIPSE));
        hEllipse = CreateWindowEx(
                       0,
                       "Button",
                       NULL,
                       WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON | BS_PUSHLIKE | BS_BITMAP,
                       185, 15,
                       32, 32,
                       hwnd,
                       (HMENU)IDB_ellipse,
                       hInst,
                       NULL);
        SendMessage(hEllipse, BM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hImageBttn);

        hImageBttn = LoadBitmap(GetModuleHandle(0), MAKEINTRESOURCE(IDB_ERASER));
        hEraser = CreateWindowEx(
                      0,
                      "Button",
                      NULL,
                      WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON | BS_PUSHLIKE | BS_BITMAP,
                      225, 15,
                      32, 32,
                      hwnd,
                      (HMENU)IDB_eraser,
                      hInst,
                      NULL);
        SendMessage(hEraser, BM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hImageBttn);

        hFill = CreateWindowEx(
                    0,
                    "Button",
                    "Fill object",
                    WS_VISIBLE | WS_CHILD | BS_AUTOCHECKBOX,
                    10, 515,
                    100, 20,
                    hwnd,
                    (HMENU)IDB_fill,
                    hInst,
                    NULL);

        CreateWindowEx(
            0,
            "Static",
            "Fill color",
            WS_VISIBLE | WS_CHILD | SS_LEFT,
            120, 515,
            75, 20,
            hwnd,
            (HMENU)0,
            hInst,
            NULL);

        CreateWindowEx(
            0,
            "Static",
            "Line color",
            WS_VISIBLE | WS_CHILD | SS_LEFT,
            230, 515,
            70, 20,
            hwnd,
            (HMENU)0,
            hInst,
            NULL);

        CreateWindowEx(
            0,
            "Static",
            "Border width",
            WS_VISIBLE | WS_CHILD | SS_LEFT,
            350, 515,
            100, 20,
            hwnd,
            (HMENU)0,
            hInst,
            NULL);

        hBorderW = CreateWindowEx(
                       0,
                       "Edit",
                       "1",
                       WS_VISIBLE | WS_CHILD | WS_BORDER | SS_CENTER,
                       460, 515,
                       40, 20,
                       hwnd,
                       (HMENU)0,
                       hInst,
                       NULL);

        CreateWindowEx(
            0,
            "Static",
            "Eraser width",
            WS_VISIBLE | WS_CHILD | SS_LEFT,
            515, 515,
            100, 20,
            hwnd,
            (HMENU)0,
            hInst,
            NULL);

        hEraserW = CreateWindowEx(
                       0,
                       "Edit",
                       "1",
                       WS_VISIBLE | WS_CHILD | WS_BORDER | SS_CENTER,
                       620, 515,
                       40, 20,
                       hwnd,
                       (HMENU)0,
                       hInst,
                       NULL);

        hClear = CreateWindowEx(
                     NULL,
                     "Button",
                     "Clear",
                     WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,
                     680, 515,
                     100, 20,
                     hwnd,
                     (HMENU)IDB_clear,
                     GetModuleHandle(NULL),
                     NULL);

        RegisterHotKey(hwnd, HK_dellipse, MOD_CONTROL, 0x45);
        RegisterHotKey(hwnd, HK_dblue, MOD_CONTROL, 0x43);
        break;

    case WM_PAINT:
        hdc = BeginPaint(hwnd, &ps);
        updateColorControls(hdc, fillColor, xFillPreview, yFillPreview);
        updateColorControls(hdc, borderColor, xStrokePreview, yStrokePreview);

        SelectObject(hdc, CreatePen(PS_SOLID, 1, RGB(0,0,0)));
        SelectObject(hdc, (HBRUSH)GetStockObject(WHITE_BRUSH));
        Rectangle(hdc, drawingArea.left, drawingArea.top, drawingArea.right, drawingArea.bottom);

        EndPaint(hwnd, &ps);
        break;

    case WM_COMMAND:
        switch (LOWORD(wParam))
        {
        case IDB_clear:
            Button_SetCheck(hPencil, BST_UNCHECKED);
            Button_SetCheck(hLine, BST_UNCHECKED);
            Button_SetCheck(hBezier, BST_UNCHECKED);
            Button_SetCheck(hRectangle, BST_UNCHECKED);
            Button_SetCheck(hEllipse, BST_UNCHECKED);
            Button_SetCheck(hEraser, BST_UNCHECKED);

            InvalidateRect(hwnd, &drawingArea, FALSE);
            InvalidateRect(hwnd, &drawingArea, TRUE);
            break;
        default:
            DefWindowProc(hwnd, WM_COMMAND, wParam, lParam);
            break;
        }
        break;

    case WM_GETMINMAXINFO:
    {
        LPMINMAXINFO mmi = (LPMINMAXINFO)lParam;
        mmi->ptMinTrackSize.x = 800;
        mmi->ptMinTrackSize.y = 550;
        mmi->ptMaxTrackSize.x = 850;
        mmi->ptMaxTrackSize.y = 600;
        break;
    }
    case WM_LBUTTONDOWN:
        xMouse = GET_X_LPARAM(lParam);
        yMouse = GET_Y_LPARAM(lParam);

        if(xMouse >= fillColorRect.left && xMouse <= fillColorRect.right)
        {
            if(yMouse >= fillColorRect.top && yMouse <= fillColorRect.bottom)
            {
                fillColor = colorSelect(hwnd, fillColor);
                updateColorControls(hdc, fillColor, xFillPreview, yFillPreview);
            }
            else if(yMouse >= borderColorRect.top && yMouse <= borderColorRect.bottom)
            {
                borderColor = colorSelect(hwnd, borderColor);
                updateColorControls(hdc, borderColor, xStrokePreview, yStrokePreview);
            }
            return 0;
        }

        if( (xMouse > drawingArea.left) && (xMouse < drawingArea.right) &&
                (yMouse > drawingArea.top) && (yMouse < drawingArea.bottom) )
        {
            width = getFromInput(hBorderW);
            point = getCurrentPointPosition(xMouse, yMouse, drawingArea, width);
            xMouse = point.x;
            yMouse = point.y;

            if((wParam == MK_LBUTTON) && (Button_GetCheck(hPencil) == BST_CHECKED))
            {
                pointPen.x = xMouse;
                pointPen.y = yMouse;
            }

            if((wParam == MK_LBUTTON) && (Button_GetCheck(hLine) == BST_CHECKED))
            {
                line.x = xMouse;
                line.y = yMouse;
                lineStarted = true;
            }

            if((wParam == MK_LBUTTON) && (Button_GetCheck(hRectangle) == BST_CHECKED))
            {
                rectangle.left = xMouse;
                rectangle.top = yMouse;
                rectangleStarted = true;
            }

            if((wParam == MK_LBUTTON) && (Button_GetCheck(hEllipse) == BST_CHECKED))
            {
                ellipse.left = xMouse;
                ellipse.top = yMouse;
                ellipseStarted = true;
            }

            if((wParam == MK_LBUTTON) && (Button_GetCheck(hBezier) == BST_CHECKED))
            {
                if(bezierStage == 0)
                {
                    bezierPoints[0] = point;
                    bezierStage = 1;
                }
                else
                {
                    bezierPoints[2] = point;
                    bezierStage = 3;
                }
            }
        }
        break;

    case WM_LBUTTONUP:
        xMouse = GET_X_LPARAM(lParam);
        yMouse = GET_Y_LPARAM(lParam);
        width = getFromInput(hBorderW);
        point = getCurrentPointPosition(xMouse, yMouse, drawingArea, width);
        xMouse = point.x;
        yMouse = point.y;

        borderPen = CreatePen(PS_SOLID, width, borderColor);
        if(Button_GetCheck(hFill) == BST_CHECKED)
            fillBrush = CreateSolidBrush(fillColor);
        else
            fillBrush = (HBRUSH)GetStockObject(NULL_BRUSH);

        if(lineStarted)
        {
            SelectObject(hdc, borderPen);
            MoveToEx(hdc, xMouse, yMouse, NULL);
            LineTo(hdc, line.x, line.y);
            DeleteObject(borderPen);
            lineStarted = false;
        }

        if(rectangleStarted)
        {
            SelectObject(hdc, borderPen);
            SelectObject(hdc, fillBrush);
            Rectangle(hdc, rectangle.left, rectangle.top, xMouse, yMouse);

            DeleteObject(borderPen);
            DeleteObject(fillBrush);

            rectangleStarted = false;
        }

        if(ellipseStarted)
        {
            SelectObject(hdc, borderPen);
            SelectObject(hdc, fillBrush);

            Ellipse(hdc, ellipse.left, ellipse.top, xMouse, yMouse);
            DeleteObject(borderPen);
            DeleteObject(fillBrush);

            ellipseStarted = false;
        }

        if(bezierStage == 1)
        {
            bezierPoints[1] = point;
            bezierStage = 2;
        }

        if(bezierStage == 3)
        {
            bezierPoints[3] = point;
            bezierStage = 0;
            SelectObject(hdc, borderPen);
            PolyBezier(hdc, bezierPoints, 4);
            DeleteObject(borderPen);
        }
        break;

    case WM_MOUSEMOVE:
        xMouse = GET_X_LPARAM(lParam);
        yMouse = GET_Y_LPARAM(lParam);
        if( (xMouse > drawingArea.left) && (xMouse < drawingArea.right) &&
                (yMouse > drawingArea.top) && (yMouse < drawingArea.bottom) )
        {
            if((wParam == MK_LBUTTON) && (Button_GetCheck(hPencil) == BST_CHECKED))
            {
                width = getFromInput(hBorderW);
                point = getCurrentPointPosition(xMouse, yMouse, drawingArea, width);
                xMouse = point.x;
                yMouse = point.y;
                linePen = CreatePen(PS_SOLID, width, borderColor);
                SelectObject(hdc, linePen);
                MoveToEx(hdc, xMouse, yMouse, NULL);
                LineTo(hdc, pointPen.x, pointPen.y);
                DeleteObject(linePen);
                pointPen.x = xMouse;
                pointPen.y = yMouse;
            }

            if((wParam == MK_LBUTTON) && (Button_GetCheck(hEraser) == BST_CHECKED))
            {
                width = getFromInput(hEraserW);
                point = getCurrentPointPosition(xMouse, yMouse, drawingArea, width);
                xMouse = point.x;
                yMouse = point.y;
                rect.left = point.x - (width / 2);
                rect.right = point.x + (width / 2);
                rect.top = point.y - (width / 2);
                rect.bottom = point.y + (width / 2);
                InvalidateRect(hwnd, &rect, FALSE);
                SendMessage(hwnd, WM_PAINT, 0, 0);
            }
        }
        break;

    case WM_CTLCOLORSTATIC:
    {
        HDC hDC = (HDC)wParam;
        SetBkColor(hDC, GetSysColor(COLOR_WINDOW));
        SetTextColor(hDC, RGB(255,69,0));
        SetBkMode(hDC, TRANSPARENT);
        return (INT_PTR)CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
    }
    break;

    case WM_HOTKEY:
    {
        switch(wParam)
        {
        case HK_dellipse:

            Button_SetCheck(hPencil, BST_UNCHECKED);
            Button_SetCheck(hLine, BST_UNCHECKED);
            Button_SetCheck(hBezier, BST_UNCHECKED);
            Button_SetCheck(hRectangle, BST_UNCHECKED);
            Button_SetCheck(hEraser, BST_UNCHECKED);
            Button_SetCheck(hEllipse, BST_CHECKED);
            break;

        case HK_dblue:
            Button_SetCheck(hFill, BST_CHECKED);
            fillColor = RGB(0,0,255);
            updateColorControls(hdc, fillColor, xFillPreview, yFillPreview);
            break;
        default:
            break;
        }
        break;
    }

    case WM_CLOSE:
        if(MessageBox(hwnd, "Close application?", "Quit", MB_YESNO) == IDYES) DestroyWindow(hwnd);
        break;

    case WM_DESTROY:
        PostQuitMessage (0);
        break;
    default:
        return DefWindowProc (hwnd, message, wParam, lParam);
    }
    return 0;
}
コード例 #19
0
ファイル: twl.cpp プロジェクト: Artorios/rootkit.com
void TDC::ellipse(const Rect& rt)
//---------------------------------
{  Ellipse(m_hdc, rt.left,rt.top,rt.right,rt.bottom); }
コード例 #20
0
void roadmap_canvas_native_draw_multiple_lines (int count, int *lines,
				RoadMapGuiPoint *points, int r, int g, int b, int thickness)
{
	int i;
	int count_of_points;

	POINT winpoints[1024];

   static int init;

   select_native_color (RGB(r, g, b), thickness);

	for (i = 0; i < count; ++i) {

      RoadMapGuiPoint end_points[2];
      int first = 1;
		
		count_of_points = *lines;
		
      if (count_of_points < 2) continue;

		while (count_of_points > 1024) {

         if (first) {
            first = 0;
            end_points[0] = *points;
         }
			roadmap_canvas_convert_points (winpoints, points, 1024);
			Polyline(RoadMapDrawingBuffer, winpoints, 1024);
			/* We shift by 1023 only, because we must link the lines. */
			points += 1023;
			count_of_points -= 1023;
		}

      if (first) {
         first = 0;
         end_points[0] = *points;
      }

      end_points[1] = points[count_of_points - 1];
		roadmap_canvas_convert_points (winpoints, points, count_of_points);
		Polyline(RoadMapDrawingBuffer, winpoints, count_of_points);

#if 0
      if (CurrentPen->thinkness > 5) {

         HPEN oldPen = SelectObject(RoadMapDrawingBuffer,
            GetStockObject(NULL_PEN));

         int radius = CurrentPen->thinkness / 2;

         Ellipse(RoadMapDrawingBuffer,
			   end_points[0].x - radius, end_points[0].y - radius,
			   radius + end_points[0].x + 1,
			   radius + end_points[0].y + 1);

         Ellipse(RoadMapDrawingBuffer,
			   end_points[1].x - radius, end_points[1].y - radius,
			   radius + end_points[1].x + 1,
			   radius + end_points[1].y + 1);

         SelectObject(RoadMapDrawingBuffer, oldPen);
	   }
#endif

		points += count_of_points;
		lines += 1;
	}

//   DeleteObject(SelectObject(RoadMapDrawingBuffer, oldPen));
//   DeleteObject(SelectObject(RoadMapDrawingBuffer, oldBrush));
}
コード例 #21
0
//*************************************************************************
// DoPaint -- this is the WM_PAINT action routine for the main window.
// It places the TrueType logo in the upper left corner of the window, draws
// a "fan hub" around it, and draws "fan leaves" of text out from the hub.
// These leaves are scaled to reach the bottom and the right edge of the
// window, by defining an ellipse centered on the TrueType logo which just
// touches those two edges.  The text strings span the distance from the
// hub to the ellipse along radial lines, and are both scaled and rotated.
//     Depending on user-set state variables, the ellipse and baselines
// for the text fan may be shown (ShowAlignmentMarks), and/or the text may
// be shadowed (ShadowAll).  Other attributes, such as bolding or
// italicization, may be selected from the font dialog box.
//*************************************************************************
void DoPaint()
{
    PAINTSTRUCT       PaintInfo;
    HDC               hDC;
    LOGFONT           FontRec;
    OUTLINETEXTMETRIC FontMetric;
    int               FontHeight, x, y, j, k;
    WORD              BaseWidth, DesiredExtent, FanTextLen;
    float             Theta;
    LPCSTR            P;
    RECT              R;
    long              TE;
    int               d;

    BeginPaint(hwnd, &PaintInfo);

    hDC = PaintInfo.hdc;
    P = ArcText;
    FanTextLen = strlen(FanText);

    // save device context; easiest way to preserve current state
    SaveDC(hDC);

    // set initial font data (for TrueType logo)
    FontRec = CornerFontRec;
    SetBkMode(hDC, TRANSPARENT);
    SetTextColor(hDC, RGB(128,128,128));
    FontRec.lfHeight = FontRec.lfHeight * 2;
    FontRec.lfWidth = floor(FontRec.lfWidth * 2.1);

    // create the TrueType logo
    SelectObject(hDC, CreateFontIndirect(&FontRec));
    TextOut(hDC, 18, 5, "T", 1);
    SetTextColor(hDC, RGB(0,0,0));
    TextOut(hDC, 32, 13,"T", 1);

    // determine window dimensions & set up fan text parameters
    GetClientRect(hwnd, &R);
    FontRec = MainFontRec;
    DeleteObject(SelectObject(hDC, CreateFontIndirect(&FontRec)));
    GetOutlineTextMetrics(hDC, sizeof(FontMetric), &FontMetric);
    FontHeight = FontMetric.otmTextMetrics.tmHeight;
    SetViewportOrg(hDC, FontHeight+2, 0);
    R.right -= FontHeight+2;
    BaseWidth = LOWORD(GetTextExtent(hDC, FanText, FanTextLen));

    // get a "black brush" for drawing operations
    SelectObject(hDC, GetStockObject(NULL_BRUSH));

    // if we want to show the alignment marks, draw the bounding ellipse
    if (ShowAlignmentMarks)
    {
        Ellipse(hDC, -R.right, -R.bottom, R.right, R.bottom);
    }

    // draw the "hub" of the fan
    Ellipse(hDC, -(Radius-5), -(Radius-5), (Radius-5), Radius-5);
    Ellipse(hDC, -(Radius-10), -(Radius-10), (Radius-10), Radius-10);

    SetTextColor(hDC, FanColor[0]);

    // loop over the "fan leaves"
    for ( d = 27; d <= 36; d++)
    {
        x = ROUND(Radius * cos(d * Deg2Rad));
        y = ROUND(Radius * sin(-d * Deg2Rad)); // -d because y axis is inverted

        Theta = -d * Deg2Rad;
        if (x)
        {
            Theta = atan((R.right / (R.bottom * 1.0)) * (y / (x * 1.0)));
        }

        j = ROUND(R.right * cos(Theta));
        k = ROUND(R.bottom * sin(Theta));

        if (ShowAlignmentMarks)
        {
            MoveTo(hDC, x,y);
            LineTo(hDC, j,k);
        }

        DesiredExtent = ROUND(sqrt(SQR(x*1.0 - j) + SQR(y*1.0 - k))) - 5;
        FontRec = MainFontRec;
        FontRec.lfEscapement = d * 100;
        FontRec.lfWidth = floor((FontMetric.otmTextMetrics.tmAveCharWidth) *
                                (DesiredExtent / (BaseWidth * 1.0)));
        DeleteObject(SelectObject(hDC, CreateFontIndirect(&FontRec)));
        TE = GetTextExtent(hDC, FanText, FanTextLen);

        for ( ;(LOWORD(TE) > DesiredExtent) && (FontRec.lfWidth);
             FontRec.lfWidth-- )
        {
            // Shave off some character width until the string fits 
            DeleteObject(SelectObject(hDC, CreateFontIndirect(&FontRec)));
            TE = GetTextExtent(hDC, FanText, FanTextLen);
        }

        // Expand the string if necessary to make it fit the desired extent 
        if (LOWORD(TE) < DesiredExtent)
          { SetTextJustification(hDC,DesiredExtent - LOWORD(TE), 3); }
        if (ShadowAll)
        {
            SetTextColor(hDC, RGB(0,0,0));
            TextOut(hDC, x+2, y+1, FanText, FanTextLen);
        }
        SetTextColor(hDC, FanColor[d - 27]);
        TextOut(hDC, x, y, FanText, FanTextLen);
        // clear justifier's internal error accumulator 
        SetTextJustification(hDC,0,0);

        if (P[0])
        {
            FontRec = CornerFontRec;
            FontRec.lfEscapement = (d+10) * 100;
            FontRec.lfWidth = 0;
            DeleteObject(SelectObject(hDC, CreateFontIndirect(&FontRec)));
            SetTextColor(hDC, 0);
            x = floor((Radius - FontHeight - 5) * cos(d * Deg2Rad));
            y = floor((Radius - FontHeight - 5) * sin(-d * Deg2Rad));
            TextOut(hDC, x, y, P, 1);
            P++;
        } // if
    } // for d

    // lose the fan font, selecting in the Borland text font
    DeleteObject(SelectObject(hDC, CreateFontIndirect(&BorlandFontRec)));
    TE = GetTextExtent(hDC, BorlandText, strlen(BorlandText));
    SetTextColor(hDC, RGB(0,0,0));
    // write the Borland text in the lower right corner, with a shadow effect
    TextOut(hDC, R.right - LOWORD(TE), R.bottom - HIWORD(TE), BorlandText,
            strlen(BorlandText));
    SetTextColor(hDC, RGB(255,0,0));
    TextOut(hDC, R.right - LOWORD(TE) - 5, R.bottom - HIWORD(TE), BorlandText,
            strlen(BorlandText));

    DeleteObject(SelectObject(hDC, GetStockObject(SYSTEM_FONT)));
    // restore the saved DC; easiest way to reset to entry state
    RestoreDC(hDC, -1);
    EndPaint(hwnd, &PaintInfo);
} // end of DoPaint()
コード例 #22
0
ファイル: ellipse.hpp プロジェクト: wallix/redemption
 static Ellipse since_center(int centerx, int centery, uint16_t radiusx, uint16_t radiusy) {
     return Ellipse(centerx - radiusx, centery - radiusy, centerx + radiusx, centery + radiusy);
 }
コード例 #23
0
void CmEscapeCurrentTool( void )				// abort tool operation when press escape key
{
	switch ( CurrentTool )
		{
		case ZOOM_TOOL:							// return to view position at start of drag
			if ( LToolActive )
				if ( BlendView ) BlendView->Pan( appDC, 0, 0 );
				else FrontView->Pan( appDC, 0, 0 );
			if ( RToolActive )
				if ( BlendView ) BlendView->Zoom( appDC, 1.0, 0, 0 );
				else FrontView->Zoom( appDC, 1.0, 0, 0 );
			EndDrag();							// release DC and cursor captured by BeginDrag()
			LToolActive = false;
			RToolActive = false;
			break;

		case DOMAIN_TOOL:						// just undo shift, no R2_NOT lines on screen
			if ( LToolActive && DomainView ) DomainView->Pan( appDC, 0, 0 );
			LToolActive = false;
			EndDrag();							// release DC and cursor
			break;

		case PENCIL_TOOL:
			if ( LToolActive )
				{
				EndDrag();						// release DC and cursor
				LToolActive = false;
				if ( ToolContour ) delete ToolContour;
				ToolContour = NULL;
				InvalidateRect( appWnd, NULL, FALSE );	// cleanup ROP2_NOT drawing
				}
			if ( RToolActive )
				{
				EndDrag();
				RToolActive = false;
				}
			break;

		case GRID_TOOL:
		case POINT_TOOL:
			if ( RToolActive )
				{
				EndDrag();
				RToolActive = false;
				}
			break;

		case ELLIPSE_TOOL:
			if ( LToolActive )					// erase temporary ellipse drag drawing
				{
				if ( !ScrollOccurred )
					Ellipse( appDC, LToolRect.left, LToolRect.top, LToolRect.right, LToolRect.bottom );	// erase
				EndDrag();						// release DC and cursor
				LToolActive = false;
				}
			break;

		case LINE_TOOL:
			if ( LToolActive )					// erase temporary drag line drawing if active
				{
				if ( !ScrollOccurred )
					{
					MoveToEx( appDC, LToolRect.left, LToolRect.top, NULL );
					LineTo( appDC, LToolRect.right, LToolRect.bottom );
					}
				EndDrag();						// release DC and cursor
				LToolActive = false;
				}
			break;

		case ZLINE_TOOL:
		case MULTILINE_TOOL:
		case CULTILINE_TOOL:
			if ( LToolActive )					// erase temporary drawing if active
				{
				EndDrag();								// release DC and cursor
				if ( EditContour ) delete EditContour;
				EditContour = NULL;						// stop editing contour
				FrontView->needsDrawing = true;			// erase EditContour
				if ( BackView )
					BackView->needsDrawing = true;		// erase back trace which may exist
				InvalidateRect( appWnd, NULL, FALSE );	// cleanup drawing
				LToolActive = false;
				}
			break;

		case ARROW_TOOL:
		case MAGNIFY_TOOL:
		case RECTANGLE_TOOL:					// both tools need drag rectangle erase
			if ( LToolActive )
				{
				if ( !ScrollOccurred )
					Rectangle( appDC, LToolRect.left, LToolRect.top, LToolRect.right, LToolRect.bottom );
				EndDrag();						// release DC and cursor
				LToolActive = false;
				}
			break;

		case WILDFIRE_TOOL:
			if ( RToolActive )					// cleanup fire break contour
				{
				if ( ToolContour ) delete ToolContour;
				ToolContour = NULL;
				}
			EndDrag();								// release DC and cursor
			RToolActive = false;
			LToolActive = false;
			InvalidateRect( appWnd, NULL, FALSE );	// cleanup any ROP2_NOT drawing
			break;

		case SCALPEL_TOOL:
			if ( LToolActive )					// if using tool left button, abort drag+draw
				{
				EndDrag();						// release DC and cursor
				LToolActive = false;
				if ( ToolContour ) delete ToolContour;
				ToolContour = NULL;
				InvalidateRect( appWnd, NULL, FALSE );	// cleanup ROP2_NOT drawing
				}
			if ( RToolActive )
				{
				EndDrag();
				RToolActive = false;			// if right button, just inactivate
				}
			break;

		default:								// other tools have nothing to cleanup!
			break;
		}
		
	KillTimer( appWnd, SCROLL_TIMER );			// in case section is scrolling, stop it
	Scrolling = false;
}
コード例 #24
0
ファイル: main.cpp プロジェクト: korleinster/gamebusdriver
// 윈도우 프로시저
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {

	// 그리기 위한 변수 - WM_PAINT
	HDC hdc;
	PAINTSTRUCT ps;
	// ------------------------------

	switch (uMsg)
	{
	case WM_CREATE:
		return 0;
		break;
	case WM_SIZE:
		return 0;
		break;
	case WM_DESTROY:
		PostQuitMessage(0);
		return 0;
		break;

	case WM_KEYDOWN:
		switch (wParam)
		{
		case VK_ESCAPE:
			PostQuitMessage(0);
			return 0;
			break;
		case VK_RIGHT:
			g_client.getPlayerData()->pos.x += value;
			break;
		case VK_LEFT:
			g_client.getPlayerData()->pos.x -= value;
			break;
		case VK_DOWN:
			g_client.getPlayerData()->pos.y += value;
			break;
		case VK_UP:
			g_client.getPlayerData()->pos.y -= value;
			break;

		default:
#ifdef _DEBUG
			// 디버깅 모드에서 예외되는 키를 입력할 경우, 서버와 기본 연결 테스트 통신을 하게 된다.
			//g_client.sendPacket_TEST();
#endif // _DEBUG
			return 0;
			break;
		}
		InvalidateRect(hWnd, NULL, TRUE);

		// 1. 작업해야 하는 것들, 맨 처음 클라이언트 통신 후 주고받아야 하는 데이터들 주고 받기
		// 2. 다른 플레이어 데이터 벡터에 저장하기
		// 3. 시야 범위 내에 있는 플레이어 노출시키기
		{
			player_data temp;
			temp = *(g_client.getPlayerData());
			g_client.sendPacket(sizeof(player_data), KEYINPUT, reinterpret_cast<BYTE*>(&temp));
		}
		break;

	case WM_PAINT:
		hdc = BeginPaint(hWnd, &ps);
		
		Ellipse(hdc, g_client.getPlayerData()->pos.x - view_range, g_client.getPlayerData()->pos.y - view_range, g_client.getPlayerData()->pos.x + view_range, g_client.getPlayerData()->pos.y + view_range);
		Ellipse(hdc, g_client.getPlayerData()->pos.x - value, g_client.getPlayerData()->pos.y - value, g_client.getPlayerData()->pos.x + value, g_client.getPlayerData()->pos.y + value);

		for (auto players : *(g_client.getOtherPlayers())) {
			Ellipse(hdc, players.second.pos.x - value, players.second.pos.y - value, players.second.pos.x + value, players.second.pos.y + value);
		}

		EndPaint(hWnd, &ps);
		break;

	case WM_SOCKET:
		g_client.ProcessWinMessage(hWnd, uMsg, wParam, lParam);
		return 0;
		break;

	}
	return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
コード例 #25
0
ファイル: main.c プロジェクト: timpeskett/museum
LRESULT CALLBACK WndProc( HWND wnd, DWORD msg, WPARAM wParam, LPARAM lParam )
{
    int i;
    int s;
    int j;
    HDC dc;
    PAINTSTRUCT ps;
    HBRUSH brush;
    char scorebuffer[20];
    RECT textrect;

    switch( msg )
    {
        case WM_CREATE:
            ShowCursor( 0 );
            SetTimer( wnd, TIMER_ID, 30, NULL );

            textrect.left = 0;
            textrect.right = WIDTH;
            textrect.top = 0;
            textrect.bottom = HEIGHT / 5;

            srand( time(0) );

            SendMessage( wnd, JM_RESET, 0, 0 );
            break;
        case JM_RESET:
            paddle.left = (WIDTH - PWIDTH) / 2;
            paddle.right = paddle.left + PWIDTH;
            paddle.bottom = HEIGHT - SPACE;
            paddle.top = paddle.bottom - PHEIGHT;

            starting = 1;
            reload = 2500 / numballs / 30;
            countdown = reload;

            for( i = 0; i < numballs; i++ )
            {
                ball[i].left = paddle.left + (PWIDTH - BDIAMETER) / 2;
                ball[i].right = ball[i].left + BDIAMETER;
                ball[i].bottom = paddle.top;
                ball[i].top = ball[i].bottom - BDIAMETER;

                ballp[i].vx = 0.0f;
                ballp[i].vy = 0.0f;
                ballp[i].active = 0;
            }
            break;
        case JM_LOSE:
            score = (numballs - 3) * 200;
            SendMessage( wnd, JM_RESET, 0, 0 );
            break;
        case WM_TIMER:
            if( wParam != TIMER_ID )
            {
                break;
            }
            if( starting )
            {
                if( !countdown )
                {
                    for( s = 0; s < numballs; s++ )
                    {
                        if( !ballp[s].active )
                        {
                            break;
                        }
                    }
                    if( s == numballs )
                    {
                        starting = 0;
                    }
                    else
                    {
                        ballp[s].active = 1;
                        ballp[s].vy = startvel;
                        ballp[s].vx = (float)(rand() % 15) - 15 / 2;
                    }
                    countdown = reload;
                }
                countdown--;
            }

            for( s = 0; s < numballs; s++ )
            {
                if( ballp[s].active )
                {
                    ball[s].top -= (int)ballp[s].vy;
                    ball[s].bottom = ball[s].top + BDIAMETER;
                    ball[s].left += (int)ballp[s].vx;
                    ball[s].right = ball[s].left + BDIAMETER;
                    ballp[s].vy -= gravity;
                    if( ball[s].bottom >= paddle.top)
                    {
                        if(  paddle.left <= ball[s].left + (BDIAMETER / 2) && paddle.right >= ball[s].right - (BDIAMETER / 2) )
                        {
                            ballp[s].vy = startvel;
                            ballp[s].vx = (ball[s].left - paddle.left + (BDIAMETER / 2) - (PWIDTH / 2)) / 2;
                            score += 10;
                            if( score >= (numballs - 2) * 200 )
                            {
                                if( numballs >= 10 )
                                {
                                    dc = GetDC( wnd );
                                    TextOut( dc, WIDTH / 3, HEIGHT / 2, "You Won!", 8 );
                                    ReleaseDC( wnd, dc );
                                    Sleep(2000);
                                    SendMessage( wnd, WM_CLOSE, 0, 0 );
                                }
                                else
                                {
                                    numballs++;
                                    SendMessage( wnd, JM_RESET, 0, 0 );
                                }
                            }
                        }
                        if( ball[s].bottom >= HEIGHT )
                        {
                            SendMessage( wnd, JM_LOSE, 0, 0 );
                            break;
                        }
                    }
                    if( ball[s].left <= (0 - (int)ballp[s].vx) || ball[s].right >= (WIDTH - (int)ballp[s].vx) )
                    {
                        ballp[s].vx = -(ballp[s].vx);
                    }
                    if( ball[s].top <= 0 )
                    {
                        ballp[s].vy = ((int)ballp[s].vy < 0 ) ? ballp[s].vy : -(ballp[s].vy);
                    }
                }
            }

            InvalidateRgn( wnd, NULL, 1 );
            break;
        case WM_MOUSEMOVE:
            paddle.left = LOWORD(lParam) - PWIDTH / 2;
            paddle.right = paddle.left + PWIDTH;
            break;
        case WM_PAINT:
            dc = BeginPaint( wnd, &ps );

            sprintf( scorebuffer, "Score: %d", score );
            TextOut( dc, 0, 0, scorebuffer, strlen( scorebuffer) );


            brush = CreateSolidBrush( 0 );

            SelectObject( dc, brush );

            RoundRect( dc, paddle.left, paddle.top, paddle.right, paddle.bottom, PWIDTH / 4, PHEIGHT );

            DeleteObject( brush );

            for( j = 0; j < numballs; j++ )
            {
                brush = CreateSolidBrush( colours[j] );
                SelectObject( dc, brush );
                Ellipse( dc, ball[j].left, ball[j].top, ball[j].right, ball[j].bottom );
                DeleteObject( brush );
            }

            EndPaint( wnd, &ps );
            break;
        case WM_DESTROY:
            KillTimer( wnd, TIMER_ID );
            ShowCursor( 1 );
            PostQuitMessage( 0 );
            break;
        default:
            return DefWindowProc( wnd, msg, wParam, lParam );
            break;
    }

    return 0;
}
コード例 #26
0
LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {

    static HWND hwndEraserWeight;
    static HWND hwndStrokeWeight;
    static HWND hwndPenTool;
    static HWND hwndLineTool;
    static HWND hwndPolygonTool;
    static HWND hwndEllipseTool;
    static HWND hwndBezierTool;
    static HWND hwndEraserTool;
    static HWND hwndFillCheck;

    static POINT pen;
    static BOOL firstLine;
    static POINT newLine;
    static BOOL firstPolygon;
    static RECT newPolygon;
    static BOOL firstEllipse;
    static RECT newEllipse;
    static BOOL firstBezier;
    static BOOL secondBezier;
    static BOOL thirdBezier;
    static POINT pointsforBezier[4];
    static HRGN lastRegion;
    static BOOL regionDeleted;

    int xMouse, yMouse;

    static RECT drawingArea = {15, 180, 580, 640};

    RECT rectRED     = {255, 100, 375, 115};
    RECT rectGREEN   = {255, 120, 375, 135};
    RECT rectBLUE    = {255, 140, 375, 155};
    RECT rectTemp;

    HDC hdc = GetDC(hwnd);
    COLORREF strokeRGB;
    int strokeWeight;
    COLORREF fillRGB;
    HBRUSH fillBrush;
    PAINTSTRUCT ps;
    HPEN strokePen;
    POINT point;
    RECT rect;

    HBRUSH hBrush;
    int xFillPreview =240 ;
    int yFillPreview = 50;
    int xStrokePreview = 320;
    int yStrokePreview = 50;
    UINT fillRED      = 255;
    UINT fillGREEN    = 255;
    UINT fillBLUE     = 255;
    UINT strokeRED    = 0;
    UINT strokeGREEN  = 0;
    UINT strokeBLUE   = 0;

    HDC hdcMem;
    BITMAP bitmap;
    HBITMAP hbmpimage = NULL;
    hbmpimage = (HBITMAP)LoadImage(hInstance, "aesthetic1.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
    GetObject(hbmpimage, sizeof(bitmap), &bitmap);

    switch(message) {

        case WM_CREATE:

            CreateWindowEx(
                0,
                "Button",
                "Tools",
                WS_VISIBLE | WS_CHILD | BS_GROUPBOX,
                5, 5,
                100, 160,
                hwnd,
                0,
                hInstance,
                NULL);

            CreateWindowEx(
                0,
                "Button",
                "Style",
                WS_VISIBLE | WS_CHILD | BS_GROUPBOX,
                520, 5,
                135, 120,
                hwnd,
                0,
                hInstance,
                NULL);

            CreateWindowEx(
                0,
                "Button",
                "Color",
                WS_VISIBLE | WS_CHILD | BS_GROUPBOX,
                220, 5,
                180, 160,
                hwnd,
                0,
                hInstance,
                NULL);

            CreateWindowEx(
                0,
                "Static",
                "Fill",
                WS_VISIBLE | WS_CHILD | SS_CENTER,
                240, 25,
                45, 20,
                hwnd,
                (HMENU)0,
                hInstance,
                NULL);

            CreateWindowEx(
                0,
                "Static",
                "Stroke",
                WS_VISIBLE | WS_CHILD | SS_CENTER,
                320, 25,
                45, 20,
                hwnd,
                (HMENU)0,
                hInstance,
                NULL);

            CreateWindowEx(
                0,
                "Static",
                "R",
                WS_VISIBLE | WS_CHILD | SS_LEFT,
                240, 100,
                10, 15,
                hwnd,
                (HMENU)0,
                hInstance,
                NULL);

            CreateWindowEx(
                0,
                "Static",
                "G",
                WS_VISIBLE | WS_CHILD | SS_LEFT,
                240, 120,
                10, 15,
                hwnd,
                (HMENU)0,
                hInstance,
                NULL);

            CreateWindowEx(
                0,
                "Static",
                "B",
                WS_VISIBLE | WS_CHILD | SS_LEFT,
                240, 140,
                10, 15,
                hwnd,
                (HMENU)0,
                hInstance,
                NULL);

            hwndPenTool = CreateWindowEx(
                0,
                "Button",
                "Pen",
                WS_VISIBLE | WS_CHILD | WS_GROUP | BS_AUTORADIOBUTTON,
                15, 30,
                80, 18,
                hwnd,
                (HMENU)IDB_PEN,
                hInstance,
                NULL);

            Button_SetCheck(hwndPenTool, BST_CHECKED);

            hwndLineTool = CreateWindowEx(
                0,
                "Button",
                "Line",
                WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON,
                15, 55,
                80, 18,
                hwnd,
                (HMENU)IDB_LINE,
                hInstance,
                NULL);

            hwndPolygonTool = CreateWindowEx(
                0,
                "Button",
                "Polygon",
                WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON,
                15, 80,
                80, 18,
                hwnd,
                (HMENU)IDB_POLYGON,
                hInstance,
                NULL);

            hwndEllipseTool = CreateWindowEx(
                0,
                "Button",
                "Ellipse",
                WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON,
                15, 105,
                80, 18,
                hwnd,
                (HMENU)IDB_ELLIPSE,
                hInstance,
                NULL);

            hwndBezierTool = CreateWindowEx(
                0,
                "Button",
                "Bezier",
                WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON,
                15, 130,
                80, 18,
                hwnd,
                (HMENU)IDB_BEZIER,
                hInstance,
                NULL);

            hwndFillCheck = CreateWindowEx(
                0,
                "Button",
                "Fill",
                WS_VISIBLE | WS_CHILD | BS_AUTOCHECKBOX,
                530, 30,
                80, 18,
                hwnd,
                (HMENU)0,
                hInstance,
                NULL);

            CreateWindowEx(
                0,
                "Static",
                "Stroke",
                WS_VISIBLE | WS_CHILD,
                530, 60,
                80, 20,
                hwnd,
                (HMENU)0,
                hInstance,
                NULL);

            hwndStrokeWeight = CreateWindowEx(
                0,
                "Edit",
                "1",
                WS_VISIBLE | WS_CHILD | WS_BORDER | SS_CENTER,
                620, 60,
                20, 20,
                hwnd,
                (HMENU)0,
                hInstance,
                NULL);

            hwndEraserTool = CreateWindowEx(
                0,
                "Button",
                "Eraser",
                WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON,
                530, 90,
                80, 20,
                hwnd,
                (HMENU)IDB_ERASER,
                hInstance,
                NULL);

            hwndEraserWeight = CreateWindowEx(
                0,
                "Edit",
                "1",
                WS_VISIBLE | WS_CHILD | WS_BORDER | SS_CENTER,
                620, 90,
                20, 20,
                hwnd, (HMENU)0,
                hInstance,
                NULL);
            return 0;

        case WM_COMMAND:
            switch (LOWORD(wParam)) {
                default:
                    DefWindowProc(hwnd, WM_COMMAND, wParam, lParam);
                    break;
            }
            return 0;

        case WM_LBUTTONDOWN:
            xMouse = GET_X_LPARAM(lParam);
            yMouse = GET_Y_LPARAM(lParam);

            if((xMouse > rectRED.left)&&(xMouse <= rectRED.right)) {
                strokeRGB = GetPixel(hdc, xStrokePreview + 20, yStrokePreview + 20);

                if((yMouse > rectRED.top)&&(yMouse <= rectRED.bottom)) {
                    strokeRED = (xMouse - rectRED.left) * 255 / (rectRED.right - rectRED.left);
                    strokeGREEN = GetGValue(strokeRGB);
                    strokeBLUE = GetBValue(strokeRGB);
                    updateColorPreview(hdc, RGB(strokeRED, strokeGREEN, strokeBLUE), xStrokePreview, yStrokePreview);
                }

                else if((yMouse > rectGREEN.top)&&(yMouse <= rectGREEN.bottom)) {
                    strokeRED = GetRValue(strokeRGB);
                    strokeGREEN = (xMouse - rectGREEN.left) * 255 / (rectGREEN.right - rectGREEN.left);
                    strokeBLUE = GetBValue(strokeRGB);
                    updateColorPreview(hdc, RGB(strokeRED, strokeGREEN, strokeBLUE), xStrokePreview, yStrokePreview);
                }

                else if((yMouse > rectBLUE.top)&&(yMouse <= rectBLUE.bottom)) {
                    strokeRED = GetRValue(strokeRGB);
                    strokeGREEN = GetGValue(strokeRGB);
                    strokeBLUE = (xMouse - rectBLUE.left) * 255 / (rectBLUE.right - rectBLUE.left);
                    updateColorPreview(hdc, RGB(strokeRED, strokeGREEN, strokeBLUE), xStrokePreview, yStrokePreview);
                }
                return 0;
            }

                if((xMouse > drawingArea.left)&&(xMouse < drawingArea.right)&&(yMouse > drawingArea.top)&&(yMouse < drawingArea.bottom)) {
                strokeWeight = getWeight(hwndStrokeWeight);
                point = drawingLimits(xMouse, yMouse, drawingArea, strokeWeight);
                xMouse = point.x;
                yMouse = point.y;

                if((wParam == MK_LBUTTON)&&(Button_GetCheck(hwndPenTool) == BST_CHECKED)) {
                    pen.x = xMouse;
                    pen.y = yMouse;
                }

                if((wParam == MK_LBUTTON)&&(Button_GetCheck(hwndLineTool) == BST_CHECKED)) {
                    newLine.x = xMouse;
                    newLine.y = yMouse;
                    firstLine = true;
                }

                if((wParam == MK_LBUTTON)&&(Button_GetCheck(hwndPolygonTool) == BST_CHECKED)) {
                    newPolygon.left = xMouse;
                    newPolygon.top = yMouse;
                    firstPolygon = true;
                }

                if((wParam == MK_LBUTTON)&&(Button_GetCheck(hwndEllipseTool) == BST_CHECKED)) {
                    newEllipse.left = xMouse;
                    newEllipse.top = yMouse;
                    firstEllipse = true;
                }

                if((wParam == MK_LBUTTON)&&(Button_GetCheck(hwndBezierTool) == BST_CHECKED)) {
                    pointsforBezier[0] = point;
                    firstBezier  = true;
                    secondBezier = false;
                    thirdBezier  = false;
                }
            }
            return 0;

        case WM_LBUTTONUP:

            xMouse = GET_X_LPARAM(lParam);
            yMouse = GET_Y_LPARAM(lParam);

            strokeRGB = GetPixel(hdc, xStrokePreview + 20, yStrokePreview + 20);
            fillRGB = GetPixel(hdc, xFillPreview + 20, yFillPreview + 20);
            strokeWeight = getWeight(hwndStrokeWeight);

            if(firstLine) {
                point = drawingLimits(xMouse, yMouse, drawingArea, strokeWeight);
                xMouse = point.x;
                yMouse = point.y;

                strokePen = CreatePen(PS_SOLID, strokeWeight, strokeRGB);
                SelectObject(hdc, strokePen);
                MoveToEx(hdc, xMouse, yMouse, NULL);
                LineTo(hdc, newLine.x, newLine.y);
                DeleteObject(strokePen);

                firstLine = false;
            }

            if(firstPolygon) {
                point = drawingLimits(xMouse, yMouse, drawingArea, strokeWeight);
                newPolygon.right = point.x;
                newPolygon.bottom = point.y;

                strokePen = CreatePen(PS_SOLID, strokeWeight, strokeRGB);
                fillBrush = (Button_GetCheck(hwndFillCheck) == BST_CHECKED)? CreateSolidBrush(fillRGB) : (HBRUSH)GetStockObject(NULL_BRUSH);
                SelectObject(hdc, strokePen);
                SelectObject(hdc, fillBrush);
                Rectangle(hdc, newPolygon.left, newPolygon.top, newPolygon.right, newPolygon.bottom);
                DeleteObject(strokePen);
                DeleteObject(fillBrush);

                lastRegion = getLastRectRegion(newPolygon, strokeWeight, &regionDeleted);

                firstPolygon = false;
            }

            if(firstEllipse) {
                point = drawingLimits(xMouse, yMouse, drawingArea, strokeWeight);
                newEllipse.right = point.x;
                newEllipse.bottom = point.y;

                strokePen = CreatePen(PS_SOLID, strokeWeight, strokeRGB);
                fillBrush = (Button_GetCheck(hwndFillCheck) == BST_CHECKED)? CreateSolidBrush(fillRGB) : (HBRUSH)GetStockObject(NULL_BRUSH);
                SelectObject(hdc, strokePen);
                SelectObject(hdc, fillBrush);
                Ellipse(hdc, newEllipse.left, newEllipse.top, newEllipse.right, newEllipse.bottom);
                DeleteObject(strokePen);
                DeleteObject(fillBrush);

                lastRegion = getLastEllipticRegion(newEllipse, strokeWeight, &regionDeleted);

                firstEllipse = false;
            }

            if(firstBezier) {
                point = drawingLimits(xMouse, yMouse, drawingArea, strokeWeight);
                pointsforBezier[1] = point;
                firstBezier  = false;
                secondBezier = true;
                thirdBezier  = false;
            }
            return 0;

        case WM_RBUTTONDOWN:
            xMouse = GET_X_LPARAM(lParam);
            yMouse = GET_Y_LPARAM(lParam);

            if((xMouse > rectRED.left)&&(xMouse <= rectRED.right)) {
                fillRGB = GetPixel(hdc, xFillPreview + 20, yFillPreview + 20);

                if((yMouse > rectRED.top)&&(yMouse <= rectRED.bottom)) {
                    fillRED = (xMouse - rectRED.left) * 255 / (rectRED.right - rectRED.left);
                    fillGREEN = GetGValue(fillRGB);
                    fillBLUE = GetBValue(fillRGB);
                    updateColorPreview(hdc, RGB(fillRED, fillGREEN, fillBLUE), xFillPreview, yFillPreview);
                }

                else if((yMouse > rectGREEN.top)&&(yMouse <= rectGREEN.bottom)) {
                    fillRED = GetRValue(fillRGB);
                    fillGREEN = (xMouse - rectGREEN.left) * 255 / (rectGREEN.right - rectGREEN.left);
                    fillBLUE = GetBValue(fillRGB);
                    updateColorPreview(hdc, RGB(fillRED, fillGREEN, fillBLUE), xFillPreview, yFillPreview);
                }

                else if((yMouse > rectBLUE.top)&&(yMouse <= rectBLUE.bottom)) {
                    fillRED = GetRValue(fillRGB);
                    fillGREEN = GetGValue(fillRGB);
                    fillBLUE = (xMouse - rectBLUE.left) * 255 / (rectBLUE.right - rectBLUE.left);
                    updateColorPreview(hdc, RGB(fillRED, fillGREEN, fillBLUE), xFillPreview, yFillPreview);
                }
                return 0;
            }

            if((xMouse > drawingArea.left)&&(xMouse < drawingArea.right)&&(yMouse > drawingArea.top)&&(yMouse < drawingArea.bottom)) {
                strokeWeight = getWeight(hwndStrokeWeight);
                point = drawingLimits(xMouse, yMouse, drawingArea, strokeWeight);
                xMouse = point.x;
                yMouse = point.y;

                if((wParam == MK_RBUTTON)&&(Button_GetCheck(hwndBezierTool) == BST_CHECKED)&&(secondBezier)) {
                    pointsforBezier[2] = point;
                    firstBezier  = false;
                    secondBezier = false;
                    thirdBezier  = true;
                }
            }
            if(regionDeleted) {
                InvalidateRgn(hwnd, lastRegion, TRUE);
                DeleteObject(lastRegion);
                regionDeleted = false;
            }
            return 0;

        case WM_RBUTTONUP:
            xMouse = GET_X_LPARAM(lParam);
            yMouse = GET_Y_LPARAM(lParam);
            strokeRGB = GetPixel(hdc, xStrokePreview + 20, yStrokePreview + 20);
            fillRGB = GetPixel(hdc, xFillPreview + 20, yFillPreview + 20);
            strokeWeight = getWeight(hwndStrokeWeight);
            point = drawingLimits(xMouse, yMouse, drawingArea, strokeWeight);
            xMouse = point.x;
            yMouse = point.y;

            if(thirdBezier) {
                pointsforBezier[3] = point;
                strokePen = CreatePen(PS_SOLID, strokeWeight, strokeRGB);
                SelectObject(hdc, strokePen);
                PolyBezier(hdc, pointsforBezier, 4);
                DeleteObject(strokePen);
                firstBezier  = false;
                secondBezier = false;
                thirdBezier  = false;
            }
            return 0;

        case WM_MOUSEMOVE:
            xMouse = GET_X_LPARAM(lParam);
            yMouse = GET_Y_LPARAM(lParam);

            if((xMouse > drawingArea.left)&&(xMouse < drawingArea.right)
                &&(yMouse > drawingArea.top)&&(yMouse < drawingArea.bottom)) {
                strokeRGB = GetPixel(hdc, xStrokePreview + 20, yStrokePreview + 20);
                fillRGB   = GetPixel(hdc, xStrokePreview + 20, yStrokePreview + 20);

                if((wParam == MK_LBUTTON)&&(Button_GetCheck(hwndPenTool) == BST_CHECKED)) {
                    strokePen = CreatePen(PS_SOLID, 1, strokeRGB);
                    SelectObject(hdc, strokePen);
                    MoveToEx(hdc, xMouse, yMouse, NULL);
                    LineTo(hdc, pen.x, pen.y);
                    DeleteObject(strokePen);
                    pen.x = xMouse;
                    pen.y = yMouse;
                }

                if((wParam == MK_LBUTTON)&&(Button_GetCheck(hwndEraserTool) == BST_CHECKED)) {
                    strokeWeight = getWeight(hwndEraserWeight);
                    point = drawingLimits(xMouse, yMouse, drawingArea, strokeWeight);
                    xMouse = point.x;
                    yMouse = point.y;
                    rect.left = point.x - (strokeWeight/2);
                    rect.right = point.x + (strokeWeight/2);
                    rect.top = point.y - (strokeWeight/2);
                    rect.bottom = point.y + (strokeWeight/2);
                    InvalidateRect(hwnd, &rect, FALSE);
                    SendMessage(hwnd, WM_PAINT, 0, 0);
                    ValidateRect(hwnd, &rect);
                }
            }
            return 0;

        case WM_PAINT:
            hdc = BeginPaint(hwnd, &ps);

            updateColorPreview(hdc, RGB(255, 255, 255), xFillPreview, yFillPreview);

            updateColorPreview(hdc, RGB(0, 0, 0), xStrokePreview, yStrokePreview);

            hdcMem = CreateCompatibleDC(hdc);
            SelectObject(hdcMem, hbmpimage);
            BitBlt(hdc, 600, 40, 280, 600, hdcMem, 0, 0, SRCCOPY);
            DeleteDC(hdcMem);

            rectTemp.top = rectRED.top;
            rectTemp.bottom = rectRED.bottom;
            for(int i = 0; i < (rectRED.right - rectRED.left); i++) {
                int r;
                r = i * 255 / (rectRED.right - rectRED.left);
                rectTemp.left  = rectRED.left  + i;
                rectTemp.right = rectRED.left + i + 1;
                hBrush = CreateSolidBrush(RGB(r, 0, 0));
                FillRect(hdc, &rectTemp, hBrush);
                DeleteObject(hBrush);
            }

            rectTemp.top = rectGREEN.top;
            rectTemp.bottom = rectGREEN.bottom;
            for(int i = 0; i < (rectGREEN.right - rectGREEN.left); i++) {
                int g;
                g = i * 255 / (rectGREEN.right - rectGREEN.left);
                rectTemp.left  = rectGREEN.left  + i;
                rectTemp.right = rectGREEN.left + i + 1;
                hBrush = CreateSolidBrush(RGB(0, g, 0));
                FillRect(hdc, &rectTemp, hBrush);
                DeleteObject(hBrush);
            }

            rectTemp.top = rectBLUE.top;
            rectTemp.bottom = rectBLUE.bottom;
            for(int i = 0; i < (rectBLUE.right - rectBLUE.left); i++) {
                int b;
                b = i * 255 / (rectBLUE.right - rectBLUE.left);
                rectTemp.left  = rectBLUE.left  + i;
                rectTemp.right = rectBLUE.left + i + 1;
                hBrush = CreateSolidBrush(RGB(0, 0, b));
                FillRect(hdc, &rectTemp, hBrush);
                DeleteObject(hBrush);
            }

            SelectObject(hdc, CreatePen(PS_SOLID, 1, RGB(0,0,0)));
            SelectObject(hdc, (HBRUSH)GetStockObject(WHITE_BRUSH));
            Rectangle(hdc, drawingArea.left, drawingArea.top, drawingArea.right, drawingArea.bottom);

            EndPaint(hwnd, &ps);
            return 0;

        case WM_DESTROY:
            PostQuitMessage (0);
            return 0;

        default:
            return DefWindowProc (hwnd, message, wParam, lParam);
    }

    return 0;
}
コード例 #27
0
ファイル: shape.cpp プロジェクト: RISK46kaf/Practise
Ellipse Rect::toEllipse()
{
    return Ellipse(_coordinates);
}
コード例 #28
0
int WINAPI WinMain(	HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int ncmdshow)
{

	WNDCLASS winclass;	// this will hold the class created
	HWND	 hwnd;		// generic window handle
	MSG		 msg;		// generic message
	HDC      hdc;       // generic dc
	RECT rect;
	float velocity[15];
	int ball_y[15],
		ball_x[15],
		iEndPos[15],
		index=0;
	LARGE_INTEGER a;
	__int64 b=0,c=0, diffrenceC_B=0;

	//fill in the window class stucture
	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; //MAKEINTRESOURCE(IDR_MENU1);
	winclass.lpszClassName	= WINDOW_CLASS_NAME;

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

	// create the window
	if (!(hwnd = CreateWindow(WINDOW_CLASS_NAME, // class
							  "Bouncing on the desktop",	 // title
							  WS_OVERLAPPEDWINDOW | WS_VISIBLE,
						 	  0,600,	   // x,y
							  WINDOW_WIDTH,  // width
						      WINDOW_HEIGHT, // height
							  NULL,	   // handle to parent 
							  NULL,	   // handle to menu
							  hinstance,// instance
							  NULL)))	// creation parms
	{
		MessageBox(hwnd, "Window Could not be Created", NULL, MB_OK); //NULL is default for Error
		return(0);
	}

	// save the window handle and instance in a global
	main_window_handle = hwnd;
	main_instance      = hinstance;

	for(index=0; index<=14; index++) //start balls at random positions, set velocity = 0
	{
		ball_y[index]= -10;
		ball_x[index]= rand()%1000;
		iEndPos[index]= rand()%900;
		velocity[index]= 0;
	}
	
	index=0; //reset index

	// enter main event loop
	while(1)
	{
		//check messages
		if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
		{ 
			// test if this is a quit message
			if (msg.message == WM_QUIT)
				break;
	
			// translate any accelerator keys
			TranslateMessage(&msg);

			// send the message to the window proc
			DispatchMessage(&msg);
		} // end if
		if(KEY_DOWN(VK_ESCAPE)) //if hit the Esc key quit the program
			PostQuitMessage(0);
		
		if(!QueryPerformanceCounter(&a))
		{
			MessageBox(hwnd, "Error on QueryPerformanceCounter()", NULL, MB_OK); //NULL is default for Error
			return(0);
		}
		else
		{
			b = c = a.QuadPart;
		}	

	   	hdc= GetDC(hwnd);
		
		//--------Begin Text Info---------------------
		SetBkMode(hdc, TRANSPARENT); //set background color
		//first create the eraser string for variable text
		SetTextColor(hdc,RGB(0,255,0)); //set text color black
		TextOut(hdc, 30, 60, buffer, strlen(buffer)); //print text
		TextOut(hdc, 30, 75, buffer2, strlen(buffer2)); //print text
		
		//unvarieing text
		SetTextColor(hdc,RGB(0,255,0)); //set text color black
		TextOut(hdc, 30, 15,"Keys 0-6 set the delay time", strlen("Keys 0-6 set the delay time")); //print text
		TextOut(hdc, 30, 30,"Left and right arrows change gravity", strlen("Left and right arrows change gravity")); //print text
		TextOut(hdc, 30, 45,"Up and down arrows change friction", strlen("Up and down arrows change friction")); //print text
		TextOut(hdc, 30, 90,"S key starts over", strlen("S key starts over")); //print text
		
		//variable text
		sprintf(buffer,"Friction= ", friction);
		sprintf(buffer2,"Gravity= ", gravity);
		TextOut(hdc, 30, 60, buffer, strlen(buffer)); //print text
		TextOut(hdc, 30, 75, buffer2, strlen(buffer2)); //print text
		//--------End Text Info-------------------------

		ReleaseDC(hwnd, hdc);
		
		
		hdc= GetWindowDC(GetDesktopWindow());
		
		//-------------Erasing ball----------------
		//fill in rect struct for erasing ball
		rect.left = ball_x[index] - BALL_RADIUS5;
		rect.right = ball_x[index] + BALL_RADIUS5;
		rect.top = ball_y[index] - BALL_RADIUS5;
		rect.bottom = ball_y[index] + BALL_RADIUS5;
		
		//Draw erasing ball in the old position
		SelectObject(hdc, red_pen5);
		SelectObject(hdc, red_brush5);
		Ellipse(hdc,rect.left, rect.top, rect.right, rect.bottom);
		
		//------------End Erasing ball----------------

		//-------------Test to see whats going on-----------
		//if the ball hits the ground, bounce back. The reason its here is because the erasing ball
		//needs the old position to erase the drawing ball.
		if(ball_y[index] >= iEndPos[index]) 
		{
			//velocity[index] = -velocity[index];
			ball_y[index] = iEndPos[index]; //need to rest the y position because of >=, the y could be > 370
		}
		
		//allows user to restart balls in a new possition if they want to
		//the reason its put here is so that if the user decides to restart, the erasing ball
		//will erase the drawing ball, and won't leave ball marks all over.
		if(startOver) 
		{
			for(index=0; index<=14; index++) //start balls at random positions, set velocity = 0
			{
				ball_y[index]= -10;
				ball_x[index]= rand()%2000;
				iEndPos[index]= rand()%900;
				velocity[index]= 0;
			}//end for loop on index
			
			startOver= false; //reset startOver back to false 
		}//end if on startOver

		//--------------End Test to see whats going on
		
		//-------------- Move the ball--------------
		velocity[index]+= gravity* ( (diffrenceC_B*0.0009)*0.02);
		velocity[index]*= friction;
		ball_y[index]+= (int) velocity[index];
		//-------------End Move the ball------------

		//---------------Draw the Ball------------------
		//Redraw the ball in its new position
	
		//fill in rect struct for drawing ball
		//ball 5
		rect.left = ball_x[index] - BALL_RADIUS5;
		rect.right = ball_x[index] + BALL_RADIUS5;
		rect.top = ball_y [index] - BALL_RADIUS5;
		rect.bottom = ball_y[index] + BALL_RADIUS5;
		
		//Draw the ball in its new spot
		SelectObject(hdc, red_pen5);
		SelectObject(hdc, red_brush5);
		Ellipse(hdc,rect.left, rect.top, rect.right, rect.bottom);
		//end ball 5

		//ball 4
		rect.left = ball_x[index] - BALL_RADIUS4;
		rect.right = ball_x[index] + BALL_RADIUS4;
		rect.top = ball_y [index] - BALL_RADIUS4;
		rect.bottom = ball_y[index] + BALL_RADIUS4;
		
		//Draw the ball in its new spot
		SelectObject(hdc, red_pen4);
		SelectObject(hdc, red_brush4);
		Ellipse(hdc,rect.left, rect.top, rect.right, rect.bottom);
		//end ball 4

		//ball 3
		rect.left = ball_x[index] - BALL_RADIUS3;
		rect.right = ball_x[index] + BALL_RADIUS3;
		rect.top = ball_y [index] - BALL_RADIUS3;
		rect.bottom = ball_y[index] + BALL_RADIUS3;
		
		//Draw the ball in its new spot
		SelectObject(hdc, red_pen3);
		SelectObject(hdc, red_brush3);
		Ellipse(hdc,rect.left, rect.top, rect.right, rect.bottom);
		//end ball 3

		//ball 2
		rect.left = ball_x[index] - BALL_RADIUS2;
		rect.right = ball_x[index] + BALL_RADIUS2;
		rect.top = ball_y [index] - BALL_RADIUS2;
		rect.bottom = ball_y[index] + BALL_RADIUS2;
		
		//Draw the ball in its new spot
		SelectObject(hdc, red_pen2);
		SelectObject(hdc, red_brush2);
		Ellipse(hdc,rect.left, rect.top, rect.right, rect.bottom);
		//end ball 2

		//ball 1
		rect.left = ball_x[index] - BALL_RADIUS1;
		rect.right = ball_x[index] + BALL_RADIUS1;
		rect.top = ball_y [index] - BALL_RADIUS1;
		rect.bottom = ball_y[index] + BALL_RADIUS1;
		
		//Draw the ball in its new spot
		SelectObject(hdc, red_pen1);
		SelectObject(hdc, red_brush1);
		Ellipse(hdc,rect.left, rect.top, rect.right, rect.bottom);
		//end ball 1
		//----------------End draw the ball---------------s

		//if index increments to 14 (or last ball) start drawing from the
		//begining again over again (meaning draw ball b0, b1,...b14 start back at b1)
		index++;
		if(index >=14)
			index=0;
		
		if(!QueryPerformanceCounter(&a))
		{
			MessageBox(hwnd, "Error on QueryPerformanceCounter()", NULL, MB_OK); //NULL is default for Error
			return(0);
		}
		else
		{
			c = a.QuadPart;
			diffrenceC_B= c-b;
		}	
		
		//slow things down a bit
		//Sleep(delay);
				
		//Release device context
		ReleaseDC(GetDesktopWindow(), hdc);
		
	} // end while

	

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

} // end WinMain
コード例 #29
0
ファイル: legend.c プロジェクト: mingpen/OpenNT
void DrawColorCol (PLEGEND pLegend,
                   PLINE pLine,
                   int iCol,
                   HDC hDC,
                   int yPos)
/*
   Effect:        Draw the "color" column of a legend entry. The color 
                  column displays a small sample of the line drawing.

                  For charts, the sample is a line of the correct style,
                  color, and width.  Since we are using wide lines, 
                  the round endcaps of the lines will breach the column.
                  Therefore we need to set the clip region. We could
                  remove this clipping if we find a way to change the
                  end cap design.  

                  For alerts, the sample is a small circle which echos
                  the design in the alert log itself.
*/      
   {  // DrawColorCol
   HBRUSH         hBrush, hBrushPrevious ;
   RECT           rect ;
   int            yMiddle ;
   int            iCircle ;



   rect.left = pLegend->aCols[iCol].xPos - LegendLeftMargin () + 2 ;
   rect.top = yPos + 1 ;
   rect.right = rect.left + pLegend->aCols[iCol].xWidth - LegendHorzMargin () ;
   rect.bottom = yPos + pLegend->yItemHeight - 1 ;

   yMiddle = rect.top + (rect.bottom - rect.top) / 2 ;
   iCircle = rect.bottom - rect.top - 2 ;
 
  switch (pLegend->iLineType)
      {  // switch
      case LineTypeChart:
   
         if (pLine->Visual.iWidth == 1)
            {
            // simple case with thin pen
//            hBrush = SelectBrush (hDC, hbLightGray) ;
            hBrush = SelectBrush (hDC, hBrushFace) ;
            Rectangle (hDC, rect.left, rect.top, rect.right, rect.bottom) ;
   
            HLine (hDC, pLine->hPen, 
                   rect.left + 1, rect.right - 1, yMiddle) ;
            SelectBrush (hDC, hBrush) ;
            }
         else
            {
            // thicker pen width, have to set ClipRect so
            // it will not draw otherside the rect.
            SaveDC (hDC) ;
//            hBrush = SelectBrush (hDC, hbLightGray) ;
            hBrush = SelectBrush (hDC, hBrushFace) ;
            Rectangle (hDC, rect.left, rect.top, rect.right, rect.bottom) ;
   
            IntersectClipRect (hDC, 
                               rect.left + 1,
                               rect.top + 1,
                               rect.right - 1,
                               rect.bottom - 1) ;
            HLine (hDC, pLine->hPen, 
                   rect.left + 1, rect.right - 1, yMiddle) ;
            SelectBrush (hDC, hBrush) ;
            RestoreDC (hDC, -1) ;
            }
         break ;


      case LineTypeAlert:
         hBrushPrevious = SelectBrush (hDC, pLine->hBrush) ;

         Ellipse (hDC,
                  rect.left + 2,
                  rect.top + 2,
                  rect.left + 2 + iCircle,
                  rect.top + 2 + iCircle) ;

         SelectBrush (hDC, hBrushPrevious) ;
         break ;
      }  // switch

   }  // DrawColorCol
コード例 #30
0
ファイル: Graphics.cpp プロジェクト: kaseya/tightvnc2
void Graphics::ellipse(int l, int t, int r, int b)
{
  Ellipse(m_dc->m_dc, l, t, r, b);
}