Click here to Skip to main content
15,896,915 members
Articles / Desktop Programming / MFC

Basic Curves And Surfaces Modeler

Rate me:
Please Sign up or sign in to vote.
4.17/5 (40 votes)
18 Apr 2012CPOL3 min read 249K   16.4K   117  
A basic demo of modeling curves and surfaces in OpenGL.
// SplitterWndEx.cpp : implementation file
//

#include "stdafx.h"
#include "CadSurf.h"
#include "SplitterWndEx.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CSplitterWndEx

CSplitterWndEx::CSplitterWndEx()
{
	m_bIsAutomaticSplit = false;
	m_bSplittingDone = false;
}

CSplitterWndEx::~CSplitterWndEx()
{
}


BEGIN_MESSAGE_MAP(CSplitterWndEx, CSplitterWnd)
	//{{AFX_MSG_MAP(CSplitterWndEx)
	ON_WM_MOUSEMOVE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CSplitterWndEx message handlers
void CSplitterWndEx::OnDrawSplitter(CDC* pDC, ESplitType nType, const CRect& rectArg)
{
	int x_ActivePane, y_ActivePane; 
	COLORREF hilightcolor = 
	 RGB(255,255,0);
	
	GetActivePane(x_ActivePane, y_ActivePane);
	if( ((GetRowCount()>1) ||(GetColumnCount()>1)) && (nType == splitBorder))
	{
		int pRow = 0;
		int pCol = 0;
		if(rectArg.top)
		{
			pRow = 1;	
		}
		if(rectArg.left)
		{
			pCol = 1;
		}
		if((pCol == y_ActivePane) && (pRow == x_ActivePane)) 
		{
			if (pDC == NULL)
			{
				RedrawWindow(rectArg, NULL, RDW_INVALIDATE|RDW_NOCHILDREN);
				return; 		
			}
			ASSERT_VALID(pDC);	
			CRect rect = 
			rectArg;pDC->Draw3dRect(rect, hilightcolor, hilightcolor);
			int dx = -GetSystemMetrics(SM_CXBORDER);
			int dy = 
			-GetSystemMetrics(SM_CYBORDER);
			rect.InflateRect(dx,dy);pDC->Draw3dRect(rect, hilightcolor, hilightcolor);
			return;
		}
	}
	CSplitterWnd::OnDrawSplitter(pDC,nType,rectArg);
}

//This Method draw an extra Rectangle around the ActivePane with the color <hilighcolor>. 

//Note: you can set 2 colors (see help for Draw3dRect). 

void CSplitterWndEx::RefreshSplitBars(void)
{
	CRect rectInside;
	GetInsideRect(rectInside);
	DrawAllSplitBars(NULL, rectInside.right, rectInside.bottom);
}

void CSplitterWndEx::StartTracking(int ht)
{
	//save the current cursor ...
	HCURSOR theCurrentCursor = GetCursor();

	CSplitterWnd::StartTracking(ht); 

	if ( m_bIsAutomaticSplit )
	{
		//...and restore it immediatelly if in AutomaticSplit mode
		SetCursor(theCurrentCursor);
	}
}

void CSplitterWndEx::StopTracking(BOOL bAccept)
{
	CSplitterWnd::StopTracking(bAccept);

	//now the is splitting done
	m_bIsAutomaticSplit = false;
	m_bSplittingDone = true;
}

BOOL CSplitterWndEx::DoAutomaticSplit()
{
	//save the current mouse position
	POINT theInitialMousePosition;
	GetCursorPos(&theInitialMousePosition);

	//set the splitting done to false ( of course )
	m_bSplittingDone = false;

	//and automaitic to true 
	m_bIsAutomaticSplit = true;
	
	//do the split
	BOOL RetVal = CSplitterWnd::DoKeyboardSplit();

	//restore immediatelly the old mouse poition
	SetCursorPos(theInitialMousePosition.x,theInitialMousePosition.y);
	return RetVal;
}

BOOL CSplitterWndEx::DoKeyboardSplit()
{
	m_bSplittingDone = false;
	m_bIsAutomaticSplit = false;
	return CSplitterWnd::DoKeyboardSplit();
}

void CSplitterWndEx::OnMouseMove(UINT nFlags, CPoint point) 
{
	if ( m_bIsAutomaticSplit )
	{
		//if AutomaticSplit mode : We are not able to choose the position of the splitters
		// -> Exiting to next step
		StopTracking(TRUE);
		return;
	}
	CSplitterWnd::OnMouseMove(nFlags, point);
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Product Manager Mahindra & Mahindra
India India
Sharjith is a Mechanical Engineer with strong passion for Automobiles, Aircrafts and Software development.

Comments and Discussions