Exemplo n.º 1
0
void Square::Render()
{
	DrawSquare();
}
Exemplo n.º 2
0
//
//  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  PURPOSE:  Processes messages for the main window.
//
//  WM_COMMAND  - process the application menu
//  WM_PAINT    - Paint the main window
//  WM_DESTROY  - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	PAINTSTRUCT ps;
	HDC hdc = GetDC(hWnd);
	switch (mode)
	{
	case 0:
		FreeDrawProc(hWnd, message, wParam, lParam);
		break;
	case 1:
		DrawLineProc(hWnd, message, wParam, lParam);
	case 2:
		DrawEllipseProc(hWnd, message, wParam, lParam);
	case 3:
		DrawRoundProc(hWnd, message, wParam, lParam);
	case 4:
		DrawSquareProc(hWnd, message, wParam, lParam);
	case 5:
		DrawRectangleProc(hWnd, message, wParam, lParam);
	}
	
	switch (message)
    {
	case WM_CREATE:
	{
		p1.x = p1.y = 0;
		p2 = p1;
		mode = 1;
		enTrainDessin = FALSE;

		//Tạo bitmap
	
		RECT rect;
		GetClientRect(hWnd, &rect);
		//Tạo ra một bitmap tương thích với DC màn hình
		hBitmap = CreateCompatibleBitmap(hdc, rect.right - rect.left, rect.bottom - rect.top);
		
		//Tô background cho bitmap
		//Tạo memory dc để tương tác với Bitmap
		HDC memDC = CreateCompatibleDC(hdc);
		SelectObject(memDC, hBitmap);
		HBRUSH hBrush = CreateSolidBrush(GetSysColor(COLOR_WINDOW));
		FillRect(memDC, &rect, hBrush);
		DeleteObject(hBrush);
		DeleteDC(memDC);
		ReleaseDC(hWnd, hdc);
		break;
	}
    case WM_COMMAND:
        {
			
            int wmId = LOWORD(wParam);
            // Parse the menu selections:
            switch (wmId)
            {
			case ID_LINE_STRAIGHTLINE:
				mode = 1;
			break;
			case ID_LINE_FREESTYLE:
				mode = 0;
				break;
			
			case ID_SHAPE_ELLIPSE:
				mode = 2;
				break;
			
			case ID_SHAPE_ROUND:
				mode = 3;
				break;
			
			case ID_SHAPE_SQUARE:
				mode = 4;
				break;
			
			case ID_SHAPE_RECTANGLE:
				mode = 5;
				break;

			case ID_DRAW_WIDTH:
				DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_DIALOG2), hWnd, AboutBox);
				break;

			case ID_COLOR_RED:
				R = 255;
				G = 0;
				B = 0;
					break;

			case ID_COLOR_GREEN:
				R = 0;
				G = 255;
				B = 0;
					break;


			case ID_COLOR_BLUE:
				R = 0;
				G = 0;
				B = 255;
					break;

			case ID_FORMAT_COLOR:
				doChooseColor(hEdit);

				break;
            
			case ID_FILE_OPEN:

				OPENFILENAME ofn;
				TCHAR szFile[260];
				ZeroMemory(&ofn, sizeof(ofn));
				ofn.lStructSize = sizeof(ofn);
				ofn.hwndOwner = hWnd;
				ofn.lpstrFile = szFile;
				ofn.lpstrFile[0] = '\0';
				ofn.nMaxFile = sizeof(szFile);
				ofn.lpstrFilter = _T("All Files *.*\0*.*\0Text Files *.txt\0*.TXT\0 Doc Files\0*.TXT;*.DOC;*.BAK\0");
				ofn.nFilterIndex = 1;
				ofn.lpstrInitialDir = _T("C:\\");
				ofn.lpstrTitle = _T("My Application - Open file");
				ofn.lpstrDefExt = _T("txt");
				ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;

				// Display the Open dialog box. 
				if (GetOpenFileName(&ofn) == TRUE) {
					PAINTSTRUCT ps;
					HDC hdc = GetDC(hWnd);
					//			HDC hdcDestination;
					HBITMAP hbitmap = (HBITMAP)::LoadImage(NULL, ofn.lpstrFile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
					//	MessageBox(NULL, ofn.lpstrFile, _T("Selected file"), MB_OK);
					//hdc = getOb
					HDC memDC = CreateCompatibleDC(hdc);
					SelectObject(memDC, hbitmap);
					RECT rect;
					GetClientRect(hWnd, &rect);
					BitBlt(hdc, 0, 0, rect.right - rect.left, rect.bottom - rect.top, memDC, 0, 0, SRCCOPY);
				}

				break;
			case ID_FILE_SAVE:
			{
				OPENFILENAME ofn;
				ZeroMemory(&ofn, sizeof(ofn));
				char szFileName[MAX_LOADSTRING];
				ZeroMemory(szFileName, MAX_LOADSTRING);
				ofn.lStructSize = sizeof(ofn);
				ofn.hwndOwner = NULL;
				ofn.lpstrFilter = _T("All Files(*.*)\0 * .*\0Bmp Files(*.bmp)\0 * .bmp\0Text Files(*.txt)\0 * .txt\0");
				ofn.lpstrFile = (LPWSTR)szFileName;
				ofn.nMaxFile = MAX_LOADSTRING;
				ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
				ofn.lpstrDefExt = (LPCWSTR)L"bmp";
				GetSaveFileName(&ofn);
				PBITMAPINFO PBi = CreateBitmapInfoStruct(hWnd, hBitmap);
				CreateBMPFile(hWnd, ofn.lpstrFile, PBi, hBitmap, hdc);
				/*save = 1;*/
			}
				break;
			case ID_FILE_EXIT:
				DestroyWindow(hWnd);
				break;
			default:
				return DefWindowProc(hWnd, message, wParam, lParam);
            }
        }
        break;


    case WM_PAINT:
        {
            PAINTSTRUCT ps;
            
            // TODO: Add any drawing code that uses hdc here...
			HDC hdc = BeginPaint(hWnd, &ps);
			//Vẽ bitmap ra màn hình trước
			HDC memDC = CreateCompatibleDC(hdc);
			SelectObject(memDC, hBitmap);
			RECT rect;
			GetClientRect(hWnd, &rect);
			BitBlt(hdc, 0, 0, rect.right - rect.left, rect.bottom - rect.top, memDC, 0, 0, SRCCOPY);
				switch (mode)
				{
				case 0:
					//Vẽ tự do thì ta vẽ luôn trên màn hình và bitmap
					FreeDraw(memDC);
					FreeDraw(hdc);
					break;
				case 1:
					//Vẽ đường thẳng thì ta chỉ vẽ lên màn hình
					DrawLine(hdc);
					break;
				case 2:
					
					DrawEllipse(hdc);
					break;
				case 3:

					DrawRound(hdc);
					break;
				case 4:

					DrawSquare(hdc);
					break;
				case 5:
					//DrawRectangle(memDC);
					DrawRectangle(hdc);
					break;
				}
				
				DeleteObject(memDC);
			//SelectObject(hdc, oldPen);
			
            EndPaint(hWnd, &ps);
        }
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
}
Exemplo n.º 3
0
void PictureBox::Render()
{
	DrawSquare();
}
Exemplo n.º 4
0
int Dungeon::DrawMap_c(unsigned char(*map_data)[10], int x_max, int z_max)
{

	for (int z = 0; z < z_max; z++)
	{
		for (int x = 0; x < x_max; x++)
		{
			DrawSquare(x * 100, 0, (z + 1) * 100, (x + 1) * 100, 0, z * 100); //床
			DrawSquare(x * 100, 100, (z + 1) * 100, (x + 1) * 100, 100, z * 100); //天井
		}
	}

	for (int z = 0; z < z_max; z++)
	{
		for (int x = 0; x < x_max; x++)
		{
			if ((map_data[z][x] & 1))
			{
				if (z >= z_max - 1) //配列の外にアクセスしないように
				{
					goto sugusoko1;
				}
				else if (pos_z > z && !(map_data[z + 1][x] & 4)) //一方通行を考慮
				{
				}
				else
				{
				sugusoko1:;
					DrawSquare(x * 100, 100, (z + 1) * 100, (x + 1) * 100, 0, (z + 1) * 100);
				}
			}
			if ((map_data[z][x] & 2))
			{
				if (x >= x_max - 1) //配列の外にアクセスしないように
				{
					goto sugusoko2;
				}
				else if (pos_x > x &&!(map_data[z][x + 1] & 8)) //一方通行を考慮
				{
				}
				else
				{
				sugusoko2:;
					DrawSquare((x + 1) * 100, 100, z * 100, (x + 1) * 100, 0, (z + 1) * 100);
				}
			}
			if ((map_data[z][x] & 4))
			{
				if (!z) //配列の外にアクセスしないように
				{
					goto sugusoko4;
				}
				else if (pos_z < z && !(map_data[z - 1][x] & 1)) //一方通行を考慮
				{
				}
				else
				{
				sugusoko4:;
					DrawSquare(x * 100, 100, z * 100, (x + 1) * 100, 0, z * 100);
				}
			}
			if ((map_data[z][x] & 8))
			{
				if (!x) //配列の外にアクセスしないように
				{
					goto sugusoko8;
				}
				else if (pos_x < x && !(map_data[z][x - 1] & 2)) //一方通行を考慮
				{
				}
				else
				{
				sugusoko8:;
					DrawSquare(x * 100, 100, (z + 1) * 100, x * 100, 0, z * 100);
				}
			}
		}
	}

	DrawFormatString(0, 0, GetColor(255, 0, 0), "x:%d,z:%d,%d", pos_x, pos_z, muki);
	if (1) //デバッグ用コード
	{
		for (int z = z_max - 1; z >= 0; --z)
		{
			for (int x = x_max - 1; x >= 0; --x)
			{
				DrawFormatString(20 * (x), 20 + 20 * (z_max + 1 - z), GetColor(255, 0, 0), "%d", savedata->map_open_flag[floors - 1][z][x]);
			}
		}
	}

	DrawFormatString(0, 100, GetColor(0, 0, 255), "t_x:%d,t_z:%d,p_x:%d,p_z:%d", (int)target_camera.x, (int)target_camera.z, (int)player_camera.x, (int)player_camera.z);

	return 0;
}
Exemplo n.º 5
0
void Dungeon::DrawExcra(int posx, int posy, int posz)
{
	DrawSquare(posx*100+50, 0, posz+50, posx*100+50, 100, posz+50);
}
void CGLBase::Draw(double rot, int x,int y,int pattern)
{
	//Rotate = Rotate + rot;
	//Image.x = Image.x + x;
	//Image.y = Image.y + y;

	//int ObjNum;
	CPoint touch;

	glClearColor(1.0, 1.0, 1.0, 1.0);
	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); 


	//L字型になった時の描画処理
	if(IsLshape)
	{
		//2枚目の下部
		if(2760 < currentTouchPos.x && currentTouchPos.x < 3840 && 1010 < currentTouchPos.y)
		{
			GhostTouchPos.x = currentTouchPos.y + 2760;
			GhostTouchPos.y = 3840 - currentTouchPos.x;
		//3枚目の左
		}else if(3830 <= currentTouchPos.x && currentTouchPos.x < 3910)
		{
			GhostTouchPos.x = 3840 - currentTouchPos.y;
			GhostTouchPos.y = currentTouchPos.x - 2760;
			if(1080 < GhostTouchPos.y)
			{
				Elaser.x = GhostTouchPos.x;
				Elaser.y = GhostTouchPos.y - 140;
				GhostTouchPos.y = 1079;
				//glColor3d(1.0,1.0,1.0);
				//DrawSquare(Elaser);
			}
		}else{
			GhostTouchPos.x = -100;
			GhostTouchPos.y = -100;
		}

	}
	if(!IsLshape)
		GhostTouchPos = CPoint(-100,-100);


	if(m_CreateGoalFlag)
		DrawGoal(TargetPos[m_correct]);


	if(IsStandby && m_Moving == false)
	{
		if(IsLshape)
		{
			glClearColor(1.0, 1.0, 1.0, 1.0);
			glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
			glPushMatrix();
			glBegin(GL_QUADS);
			glColor3d(0.0,0.0,0.0);
			glVertex2d(-0.52,  0.1);
			glVertex2d(-0.52, -0.1);
			glVertex2d(-0.48, -0.1);
			glVertex2d(-0.48,  0.1);
			glEnd();
			glPopMatrix();
		}else{
			glClearColor(1.0, 1.0, 1.0, 1.0);
			glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
			glPushMatrix();
			glBegin(GL_QUADS);
			glColor3d(0.0,0.0,0.0);
			glVertex2d(-0.02,  0.1);
			glVertex2d(-0.02, -0.1);
			glVertex2d( 0.02, -0.1);
			glVertex2d( 0.02,  0.1);
			glEnd();
			glPopMatrix();
		}
		//Sleep(3000);
		
		m_CreateGoalFlag = false;
		//IsStandby = false;
		IsFirstTouch = true;
		IsTasking = false;
		GhostObjectPos[m_correct] = ObjectPos[m_correct];

	}else if(m_Moving == true){
		glClearColor(1.0, 1.0, 1.0, 1.0);
		glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);	
	}else{

		if(IsTaskFinish == true){			//タッチしていない状態
			glColor3d(1.0,0.0,0.0);
			DrawSquare(ObjectPos[m_correct]);
			tmpObjectPos[m_correct] = ObjectPos[m_correct];
			IsTaskFinish = false;
			//TRACE("スタート\n");
		}else if(IsTasking == true && IsCorrectTouch == true)		//ドラッグしている状態
		{
			glColor3d(0.0,1.0,0.0);
			//if(1930 < currentTouchPos.x && currentTouchPos.y < 1080 && IsLined)
			//	glColor3d(1.0,1.0,1.0);
//			if(!IsLshape)
//				glColor3d(1.0,1.0,1.0);
			DrawSquare(GhostTouchPos);
		
			//glColor3d(0.0,1.0,0.0);
			DrawSquare(currentTouchPos);
		}else if(IsTasking == false && IsCorrectTouch == true){			//手を放した状態
			glColor3d(0.0,0.0,1.0);
			if(1930 < currentTouchPos.x && currentTouchPos.y < 1080 && IsLined)
				glColor3d(1.0,1.0,1.0);
//			if(!IsLshape)
//				glColor3d(1.0,1.0,1.0);
			DrawSquare(GhostTouchPos);
			glColor3d(0.0,0.0,1.0);
			DrawSquare(tmpObjectPos[m_correct]);
		}else{
			//TRACE("ハズレ\n");
			glColor3d(1.0,0.0,0.0);
//			if(!IsLshape)
//				glColor3d(1.0,1.0,1.0);
			DrawSquare(GhostTouchPos);
			glColor3d(1.0,0.0,0.0);
			DrawSquare(tmpObjectPos[m_correct]);
			//TRACE("(%d,%d)\n",currentTouchPos.x, currentTouchPos.y);
		}
	}	


	if(IsLshape)
	{	
		
		if(3830 <= currentTouchPos.x && currentTouchPos.x < 3910)
		{
			glColor3d(1.0,1.0,1.0);
			GhostTouchPos.y = 1080 + (currentTouchPos.x - 3980);
			DrawSquare(GhostTouchPos);
			Elaser.x = 3770;
			Elaser.y = currentTouchPos.y;
			DrawSquare(Elaser);
		}

		if(2760 < currentTouchPos.x && currentTouchPos.x < 3840 && 1010 < currentTouchPos.y)
		{
			Elaser.x = 3770;
			Elaser.y = 3840 - currentTouchPos.x;
			glColor3d(1.0,1.0,1.0);
			DrawSquare(Elaser);
		}
	}


}