Example #1
1
LRESULT CALLBACK WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
    switch (msg) {

        case WM_CREATE: {
            hdc = GetDC(hWnd);
            GetClientRect(hWnd,&rect);
            int ret = SetTimer(hWnd, TIMER_ID, 5, NULL);
            initFigures();
            break;
        }

        case WM_PAINT: {
            BeginPaint(hWnd, &ps);
            Paint(hWnd, &ps);
            EndPaint(hWnd, &ps);

        }
            break;


        case WM_LBUTTONDOWN: {
            Figure *figure;
            figure = new Figure(rand()%rect.right, rand()%rect.bottom, 100, 100);
            figure->setCircle(false);
            figure->setDir(rand()%4);
            figure->setVelocity(rand()%8 + 1);
            figure->setColor(rand()%250, rand()%250, rand()%250);
            vec.push_back(*figure);
            vectorSize++;
            break;
        }

        case WM_MOUSEWHEEL : {
            int deltaZ = (short) HIWORD(wParam);
            if(deltaZ > 0) {
                velocity += 2;
            }else {
                if(velocity > 0)
                    velocity -= 2;
            }
            break;
        }

        case WM_TIMER: {
            InvalidateRect(hWnd, &rect, FALSE);
        }
            break;

        case WM_DESTROY: {
            KillTimer(hWnd, TIMER_ID);
            PostQuitMessage(0);
            return 0;
        }

    }
    return DefWindowProc(hWnd, msg, wParam, lParam);
}
Example #2
0
void initFigures() {

    srand(time(NULL));
    Figure *figure;
    for(int i = 0; i < vectorSize; i++) {
        figure = new Figure(rand()%rect.right, rand()%rect.bottom, 50, 50);
        figure->setCircle(false);
        figure->setDir(rand()%4);
        figure->setVelocity(rand()%1 + 1);
        figure->setColor(rand()%250, rand()%250, rand()%250);
        figure->setCircle(true);
        vec.push_back(*figure);
    }
}
Example #3
0
void Group::SetLineColor(COLORREF color)
{
	//노드 데이터 변경
	POSITION posNode = NodeData.GetHeadPosition();
	while (posNode)
	{
		Figure* pGObj = (Figure*)NodeData.GetNext(posNode);
		pGObj->setColor(color);
	}
	//차일드 데이터 변경(recursion이 일어남)
	POSITION posChild = Child.GetHeadPosition();
	while (posChild)
	{
		Group* pGroup = (Group*)Child.GetNext(posChild);
		pGroup->SetLineColor(color);
	}
}
Example #4
0
void on_mouse(int event, int x, int y, int flags, void* param)
{
	
	
	switch(event)
	{
		case CV_EVENT_LBUTTONUP://evento del boton cuando se suelta
			window.followmousemove = 0;
			if(figure.task != '9')
			{
				figure.lp.x=x;
				figure.lp.y=y;
			}	
			else
			{
				window.refresh();
				figure.task = '?';
			}
			if(figure.drawtype != '?' )
				list.push_back(figure);
			drawList(window.image, list);
							
			break;
		case CV_EVENT_LBUTTONDOWN://evento del boton cuando se presiona
			xx = x;
			yy = y;
			
			window.followmousemove = 1;
			
			if(variable[3] != 9 && variable[3]<50)
			{
				figure = Figure(variable[0],variable[1],variable[2]);
				figure.fp.x=x;
				figure.fp.y=y;
				figure.drawtype=variable[3];
			}
			else
			{
				figure = find(x,y,list);
				if(variable[4]==50 || variable[4]==75 || variable[4]==125 || variable[4]==150)
				{
					figure.setZoom((float)variable[4]/100);
					figure.task = '9';
				}
				if(variable[0]!=-1 && variable[1]!=-1 && variable[2]!=-1)
				{
					figure.setColor(variable[0],variable[1],variable[2]);
					figure.task = '9';
				}

				if(variable[3]==9)
					figure.task = '9';
			}
			break;
	}
	if(CV_EVENT_MOUSEMOVE==event && window.followmousemove == 1)//evento del boton en movimiento
	{	

		window.refresh();
		if(figure.task == '9')
		{
			figure.move(x-xx,y-yy);
			xx=x;
			yy=y;
		}
		else
		{
			figure.lp.x = x;
			figure.lp.y = y;
		}
		
		figure.draw(window.image);
		drawList(window.image, list);	
	}
}