Пример #1
0
int ClustMod::Display(
		TimeValue t, INode* inode, ViewExp *vpt, 
		int flags, ModContext *mc)
	{
	// Transform the gizmo with the node.
	#ifdef DESIGN_VER
	TimeValue rt = GetCOREInterface()->GetTime();
	Matrix3 obtm = inode->GetObjectTM(rt);
	#else
	Matrix3 obtm = inode->GetObjectTM(t);
    #endif

	GraphicsWindow *gw = vpt->getGW();
	gw->setTransform(obtm);

	Matrix3 ptm(1), ctm(1);
	if (posControl) posControl->GetValue(t,&ptm,FOREVER,CTRL_RELATIVE);
	if (tmControl) tmControl->GetValue(t,&ctm,FOREVER,CTRL_RELATIVE);	
	//Matrix3 tm = DEFORMER_TM;
	Matrix3 tm = CompTM(ptm,ctm,mc->tm,1);	

	ClustDeformer deformer(tm);	
	if (ip && ip->GetSubObjectLevel() == 1) {
		//gw->setColor( LINE_COLOR, (float)1.0, (float)1.0, (float)0.0);		
		gw->setColor(LINE_COLOR,GetUIColor(COLOR_SEL_GIZMOS));
	} else {
		//gw->setColor( LINE_COLOR, (float).85, (float).5, (float)0.0);
		gw->setColor(LINE_COLOR,GetUIColor(COLOR_GIZMOS));
		}
	if (mc->box->pmin==mc->box->pmax) {
		Point3 pt = mc->box->pmin * tm;
		gw->marker(&pt,ASTERISK_MRKR);		
	} else {
		DoModifiedBox(MakeBoxNotEmpty(*mc->box),deformer,DrawLineProc(gw));
		}

	//obtm = ctm * obtm;
	if (mc->tm) obtm = ctm * Inverse(*mc->tm) * obtm;
	else obtm = ctm * obtm;
	
	gw->setTransform(obtm);
	if ( ip && (ip->GetSubObjectLevel() == 1 ||
	            ip->GetSubObjectLevel() == 2) ) {		
		//gw->setColor( LINE_COLOR, (float)1.0, (float)1.0, (float)0.0);
		gw->setColor(LINE_COLOR,GetUIColor(COLOR_SEL_GIZMOS));
	} else {
		//gw->setColor( LINE_COLOR, (float).85, (float).5, (float)0.0);
		gw->setColor(LINE_COLOR,GetUIColor(COLOR_GIZMOS));
		}	
	DrawCenterMark(DrawLineProc(gw),MakeBoxNotEmpty(*mc->box));	
	return 0;
	}
Пример #2
0
int ClustMod::HitTest(
		TimeValue t, INode* inode, int type, int crossing, 
		int flags, IPoint2 *p, ViewExp *vpt, ModContext* mc)
	{	
	int savedLimits;
	Matrix3 obtm = inode->GetObjectTM(t);
	GraphicsWindow *gw = vpt->getGW();
	HitRegion hr;
	MakeHitRegion(hr,type, crossing,4,p);
	gw->setHitRegion(&hr);
	gw->setRndLimits(((savedLimits = gw->getRndLimits()) | GW_PICK) & ~GW_ILLUM);
	gw->clearHitCode();	
	gw->setTransform(obtm);

	Matrix3 ptm(1), ctm(1);
	if (posControl) posControl->GetValue(t,&ptm,FOREVER,CTRL_RELATIVE);
	if (tmControl) tmControl->GetValue(t,&ctm,FOREVER,CTRL_RELATIVE);	

	if (ip && ip->GetSubObjectLevel() == 1) {		
		//Matrix3 tm = DEFORMER_TM;
		Matrix3 tm = CompTM(ptm,ctm,mc->tm,1);

		ClustDeformer deformer(tm);
		if (mc->box->pmin==mc->box->pmax) {
			Point3 pt = mc->box->pmin * tm;
			gw->marker(&pt,ASTERISK_MRKR);
		} else {
			DoModifiedBox(MakeBoxNotEmpty(*mc->box),deformer,DrawLineProc(gw));
			}
		}

	if (ip && (ip->GetSubObjectLevel() == 1 ||
	           ip->GetSubObjectLevel() == 2)) {		
		//obtm = ctm * obtm;
		if (mc->tm) obtm = ctm * Inverse(*mc->tm) * obtm;
		else obtm = ctm * obtm;

		gw->setTransform(obtm);
		DrawCenterMark(DrawLineProc(gw),MakeBoxNotEmpty(*mc->box));
		}

	gw->setRndLimits(savedLimits);	
	if (gw->checkHitCode()) {
		vpt->LogHit(inode, mc, gw->getHitDistance(), 0, NULL); 
		return 1;
		}
	return 0;
	}
Пример #3
0
int BendManip::Display(TimeValue t, INode* pNode, ViewExp *pVpt, int flags)
{

	ModContext* mc = FindModContext( pNode, modifier );
	if( mc==NULL ) return 0;


	Interval valid;
	GraphicsWindow *gw = pVpt->getGW();
	Matrix3 modmat, ntm = pNode->GetObjTMBeforeWSM(t), off, invoff;

	if (mc->box->IsEmpty()) return 0;

	//Lets get the Modifier do all the work here
	modmat = modifier->CompMatrix(t,*mc,ntm,valid,FALSE);
	modifier->CompOffset(t,off,invoff);
	gw->setTransform(modmat);
	if(mouseWithin)
		gw->setColor( LINE_COLOR, (float)1.0, (float)0.0, (float)0.0);
	else
		gw->setColor( LINE_COLOR, (float)0.0, (float)1.0, (float)0.0);

	DoModifiedBox(*mc->box,modifier->GetDeformer(t,*mc,invoff,off),DrawLineProc(gw));

	
	return 1;
	
}
Пример #4
0
int BendManip::HitTest(TimeValue t, INode* pNode, int type, int crossing,
			int flags, IPoint2 *p, ViewExp *pVpt)
{
	ModContext* mc = FindModContext( pNode, modifier );
	if( mc==NULL ) return 0;

// From SimpleMod - Removed the centre drawing section
	Interval valid;
	int savedLimits;	
	GraphicsWindow *gw = pVpt->getGW();
	HitRegion hr;
	MakeHitRegion(hr,type, crossing,4,p);
	gw->setHitRegion(&hr);
	Matrix3 modmat, ntm = pNode->GetObjTMBeforeWSM(t);

	if (mc->box->IsEmpty()) return 0;

	gw->setRndLimits(((savedLimits = gw->getRndLimits()) | GW_PICK) & ~GW_ILLUM);
	gw->clearHitCode();

	//Lets get the Modifier do all the work here

	Matrix3 off, invoff;
	modmat = modifier->CompMatrix(t,*mc,ntm,valid,FALSE);
	modifier->CompOffset(t,off,invoff);
	gw->setTransform(modmat);		
	DoModifiedBox(*mc->box,modifier->GetDeformer(t,*mc,invoff,off),DrawLineProc(gw));
	

	gw->setRndLimits(savedLimits);	

	if (gw->checkHitCode()) {
		pVpt->LogHit(pNode, mc, gw->getHitDistance(), 0, NULL); 

	}

// Setup the Hit data from the Manipulator system into the HitRecord
	if(  pVpt->NumSubObjHits() ) {
		ManipHitData* pHitData = new ManipHitData(this);
		HitRecord* hit = pVpt->GetSubObjHitList().First();

		hit->hitData = pHitData; //Add the manip hit data
		return TRUE;
	}

	else 
	{
		return FALSE;
	}
}
Пример #5
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;
}