Beispiel #1
0
// For a given window, creates an array of the child windows, that can be used
// for resizing later on.
GADGETRESIZEHANDLE CreateGadgetResizeHandle(CWnd* pWnd)
	{
	CPtrArray* pArray = new CPtrArray;
	
	// 1st element of the array stores the client rectangle of the given window
	RECT_AND_HWND* pRectWnd = new RECT_AND_HWND;
	pWnd->GetClientRect(&(pRectWnd->m_rect));
	pRectWnd->m_hWnd = NULL;
	pArray->Add(pRectWnd);
	TCHAR szClassName[64];
	
	for (HWND hWndChild = ::GetTopWindow(pWnd->m_hWnd); hWndChild != NULL;
	hWndChild = ::GetNextWindow(hWndChild, GW_HWNDNEXT))
		{
		RECT_AND_HWND* pRectWnd = new RECT_AND_HWND;
		pRectWnd->m_hWnd = hWndChild;
		GetClassName(pRectWnd->m_hWnd, szClassName, 64); 
		::GetWindowRect(hWndChild, &(pRectWnd->m_rect));
		pWnd->ScreenToClient(&(pRectWnd->m_rect));

		// if it's a drop down combo box, then we set bottom -ve to indicate
		// we should keep the height fixed. Otherwise we might find that the drop
		// down size gets stupidly small.
		if (_tcscmp(szClassName, _T("ComboBox")) == 0 &&
			(GetWindowLong(hWndChild, GWL_STYLE) & (CBS_DROPDOWN | CBS_DROPDOWNLIST)) )
			{
			pRectWnd->m_rect.bottom = - (pRectWnd->m_rect.bottom - pRectWnd->m_rect.top);
			}

		pArray->Add(pRectWnd);
		}
	
	return (GADGETRESIZEHANDLE) pArray;
	}
Beispiel #2
0
/*
============
Select_Ray

If the origin is inside a brush, that brush will be ignored.
============
*/
void Select_Ray( vec3_t origin, vec3_t dir, int flags )
{
	trace_t t;
	
	t = Test_Ray( origin, dir, flags );
	if ( !t.brush )
		return;
		
	if ( flags == SF_SINGLEFACE )
	{
		int nCount = g_SelectedFaces.GetSize();
		bool bOk = true;
		for ( int i = 0; i < nCount; i++ )
		{
			if ( t.face == reinterpret_cast<face_s*>( g_SelectedFaces.GetAt( i ) ) )
			{
				bOk = false;
				// need to move remove i'th entry
				g_SelectedFaces.RemoveAt( i, 1 );
				g_SelectedFaceBrushes.RemoveAt( i, 1 );
			}
		}
		if ( bOk )
		{
			g_SelectedFaces.Add( t.face );
			g_SelectedFaceBrushes.Add( t.brush );
		}
		//selected_face = t.face;
		//selected_face_brush = t.brush;
		Sys_UpdateWindows( W_ALL );
		clearSelection();
		// Texture_SetTexture requires a brushprimit_texdef fitted to the default width=2 height=2 texture
		brushprimit_texdef_s brushprimit_texdef;
		ConvertTexMatWithQTexture( &t.face->brushprimit_texdef, t.face->d_texture, &brushprimit_texdef, NULL );
		Texture_SetTexture( &t.face->texdef, &brushprimit_texdef, false, false );
		UpdateSurfaceDialog();
		return;
	}
	
	// move the brush to the other list
	
	clearSelection();
	
	if ( t.selected )
	{
		Brush_RemoveFromList( t.brush );
		Brush_AddToList( t.brush, &active_brushes );
		UpdatePatchInspector();
	}
	else
	{
		Select_Brush( t.brush, !( GetKeyState( VK_MENU ) & 0x8000 ) );
	}
	
	Sys_UpdateWindows( W_ALL );
}
Beispiel #3
0
BOOL CModuleWnd::GetSelectModuleData(LPSTGMEDIUM lpStgMedium)
{
	TCHAR buffer[MAX_PATH];
	CString strName;
	POSITION pos = GetListCtrl()->GetFirstSelectedItemPosition();
	int nItem;
	
	CPtrArray arrSubDoc;
	while (pos)
	{
		nItem = GetListCtrl()->GetNextSelectedItem(pos);
		GetListCtrl()->GetItemText(nItem, 0, buffer, MAX_PATH);
		strName = buffer;
		CDevDoc::CSubDoc* pSubDoc = m_pCurrentDocument->GetSubDocument(strName);
		arrSubDoc.Add(pSubDoc);
	}

	CDevDoc::GetSubDocumentData((CDevDoc::CSubDoc **)arrSubDoc.GetData(), arrSubDoc.GetSize(), lpStgMedium);
		
	for (int i = 0; i < arrSubDoc.GetSize(); i++)
		delete (CDevDoc::CSubDoc *)arrSubDoc[i];
	arrSubDoc.RemoveAll();
	
	return TRUE;
}
Beispiel #4
0
void PushPatch(patchMesh_t *patch)
{
	patchEntry_t *pEntry = new patchEntry_s;
	pEntry->p = patch;
	strcpy( pEntry->name, patch->pShader->getName() );
	PatchShaders.Add(pEntry);
}
CG2Neighbour* CNeighboursWithG2::GetRandomHub(CG2Neighbour* pExcept, GGUID* pGUID)
{
    CPtrArray pRandom;

    for ( POSITION pos = GetIterator() ; pos ; )
    {
        CG2Neighbour* pNeighbour = (CG2Neighbour*)GetNext( pos );

        if (	pNeighbour->m_nState == nrsConnected &&
                pNeighbour->m_nProtocol == PROTOCOL_G2 &&
                pNeighbour->m_nNodeType != ntLeaf &&
                pNeighbour != pExcept )
        {
            if ( pNeighbour->m_pGUIDCache->Lookup( pGUID ) == NULL )
            {
                pRandom.Add( pNeighbour );
            }
        }
    }

    int nSize = pRandom.GetSize();
    if ( ! nSize ) return NULL;

    nSize = rand() % nSize;

    return (CG2Neighbour*)pRandom.GetAt( nSize );
}
Beispiel #6
0
int CMqlx::ReadQuotes ( CString strFilename, CPtrArray &pArrayQuote )
{

	FILE *fpin ;
	QUOTE *pQuote ;

	fpin = fopen ( strFilename, "rt" ) ;

	if (fpin==NULL){
		cout<<"Open file "<<strFilename<<" Error."<<endl;
		return 1;
	}

	while ( ! feof ( fpin ) )
	{
		pQuote = new QUOTE() ;

		fscanf( fpin, "%s %f %f %f %f %lf %lf",
			pQuote->CurrentDate, /*pQuote->CurrentTime, */
			&pQuote->Open, &pQuote->High, &pQuote->Low, &pQuote->Close,
			&pQuote->Volume, &pQuote->Amount ) ;

		if (strcmp ("", pQuote->CurrentDate ) != 0)
		{
			//ChangeDateFormat ( pQuote ) ;
			pArrayQuote.Add ( pQuote ) ;
		}
	}

	fclose ( fpin ) ;
	return 0 ;
}
Beispiel #7
0
int CMqlx::ReadCvtDate( CString strFilename, CPtrArray &pCvt ) 
{
	FILE *fpcvtin = fopen ( strFilename, "rt" ) ;
	if (fpcvtin==NULL){
		cout<<"Open CVT file "<<m_strCvtFile<<" Error."<<endl;
		return 1;
	}

	CvtDate *pQuote ;

	while ( !feof( fpcvtin ) ) 

	{
		pQuote = new CvtDate() ;

		fscanf ( fpcvtin, "%s %s %s", pQuote->BeginDate,
			pQuote->EndDate, pQuote->ContractName ) ;

		if (strcmp (pQuote->EndDate, pQuote->BeginDate ) != 0)
		{
			//printf ( "%s %s %s \n", pQuote->BeginDate, pQuote->EndDate, pQuote->ContractName ) ;
			//ChangeDateFormat ( pQuote ) ;
			pCvt.Add ( pQuote ) ;
		}
	}
	return 0 ;
}
Beispiel #8
0
int CMqlx::GetQuotes(CvtDate *pCvtDate, CPtrArray &pArrayQuote )
{
	cout<<"BeginDate = "<<pCvtDate->BeginDate ; 
	cout<<" EndDate = "<<pCvtDate->EndDate <<endl; 
	//cout<<" Name = "<<pCvtDate->ContractName  ; 

	char (&n)[15]=pCvtDate->ContractName ;
	cout<<" Name = "<<n ; 
	map<CString,CPtrArray*> &b = CodeBook ;
	CPtrArray &pAQ=*(b[n]) ;

	INT_PTR nCount ;
	nCount = pAQ.GetCount ( ) ;
	cout<<" Count = "<< nCount<<endl ; 
	for ( int i=0; i<nCount; i++ )
	{
/*
		QUOTE* q=((QUOTE *)pAQ[i]);
		QUOTE* &q1=q;
		cout<<q1->CurrentDate <<endl;
*/
		char (&dt)[11]=((QUOTE *)pAQ[i])->CurrentDate ;
		if ((strcmp( dt, pCvtDate->BeginDate )>=0) &&
			(strcmp( dt, pCvtDate->EndDate )<0))
			pArrayQuote.Add (pAQ[i]);
		else if (strcmp( dt, pCvtDate->EndDate )>=0)
			break ;

	}

	return 0 ;
}
Beispiel #9
0
//查找用户
INT_PTR CGameUserManage::FindOnLineUser(BYTE bDeskIndex, CPtrArray & PlayPtrArray, CPtrArray & WatchPtrArray)
{
	INT_PTR uActiveCount=m_ActiveUserPtrArray.GetCount(),uFindCount=0;
	for (int i=0;i<uActiveCount;i++)
	{
		UserItemStruct * pFindUserItem=(UserItemStruct *)m_ActiveUserPtrArray.GetAt(i);
		if (pFindUserItem!=NULL)
		{
			if (pFindUserItem->GameUserInfo.bDeskNO==bDeskIndex)
			{
				uFindCount++;
				if (pFindUserItem->GameUserInfo.bUserState==USER_WATCH_GAME) WatchPtrArray.Add(pFindUserItem);
				else PlayPtrArray.Add(pFindUserItem);
			}
		}
	}
	return uFindCount;
}
Beispiel #10
0
void Select_Reselect()
{
	brush_s* b;
	CPtrArray holdArray;
	for ( b = selected_brushes.next ; b && b != &selected_brushes ; b = b->next )
	{
		holdArray.Add( reinterpret_cast<void*>( b ) );
	}
	
	int n = holdArray.GetSize();
	while ( n-- > 0 )
	{
		b = reinterpret_cast<brush_s*>( holdArray.GetAt( n ) );
		Select_Brush( b );
	}
	Sys_UpdateWindows( W_ALL );
}
Beispiel #11
0
void AddToMap(TCHAR* pszArg)
{
	ENSURE(pszArg != NULL);
	TCHAR* psz = _tcsdup(pszArg);
	if (psz == NULL)
	{
		AfxThrowMemoryException();
	}
	ASSERT(_tcschr(psz, _T(',')) != NULL);

	TCHAR* pszPrefixFrom;
	TCHAR* pszPrefixTo;
	TCHAR* pszAddTo;
	DWORD dwAddTo;
	CMapInfo* pInfo;
	TCHAR* pContext=NULL;

	// parse each field out of the argument.
	pszPrefixFrom = _tcstok_s(psz, _T(","), &pContext);
	pszPrefixTo = _tcstok_s(NULL, _T(","), &pContext);
	if (pszPrefixTo == NULL)
		goto ParmError;
	pszAddTo = _tcstok_s(NULL, _T(","), &pContext);
	if (pszAddTo == NULL)
		goto ParmError;

	// make sure they are valid symbols/values.
	if (!IsValidSymbol(pszPrefixFrom) || !IsValidSymbol(pszPrefixTo))
		goto ParmError;
	if (!IsValidValue(pszAddTo, dwAddTo))
		goto ParmError;

	// add them to the map.
	pInfo = new CMapInfo;
	ASSERT(pInfo);
	pInfo->pszPrefixFrom = pszPrefixFrom;
	pInfo->pszPrefixTo = pszPrefixTo;
	pInfo->dwAddTo = dwAddTo;
	aMap.Add(pInfo);
	return;

ParmError:
	UsageErr(_T("parameter \"%s\" not correctly formed."), pszArg);
	ASSERT(FALSE);
}
Beispiel #12
0
TEST_F(EngineTestParser,  findSubDirs_findAllSubDirectories)
{
	CPtrArray arr;
	CCodeDirectories* pDirs =  new CCodeDirectories;
	pDirs->m_strOriginalDir = m_parser.getCurrentPath();
	arr.Add(pDirs);
	int nRes = m_parser.findSubDirs(arr);
	if (nRes != 0)
	{
		for (int i = 0; i < nRes; i++)
		{
			pDirs = (CCodeDirectories*)arr.GetAt(i);
			delete pDirs;
		}
		arr.RemoveAll();
	}
	SetCurrentDirectory(g_strCurrentDir.c_str());
	ASSERT_NE(0, nRes); 
}
Beispiel #13
0
void CedExporter::CheckForExtraPoint(const CeLocation* loc, CMapPtrToPtr& locIndex, IdFactory& idf, CPtrArray& extraPoints)
{
	// Nothing to do if the location has already been noted
	void* x;
	if (locIndex.Lookup((void*)loc, x))
		return;

	CString msg;
	msg.Format("Recording extra point for %x", (int)loc);
	Log(msg);

	// Generate an extra point
	unsigned int entityId = 0;
	PointFeature_c* p = new PointFeature_c(idf, entityId, *loc);

	//msg.Format("Added point %d", p->Stub->InternalId);
	//Log(msg);

	extraPoints.Add(p);
	locIndex.SetAt((void*)loc, (void*)p->Stub->InternalId); // I don't think we really need the ID, but hold it just in case
}
Beispiel #14
0
//查找用户
INT_PTR CGameUserManage::FindOnLineUser(const TCHAR * szUserName, CPtrArray & ResultPtrArray)
{
	//查找用户指针
	CString strBuffer;
	INT_PTR uActiveCount=m_ActiveUserPtrArray.GetCount(),uFindCount=0;
	for (int i=0;i<uActiveCount;i++)
	{
		UserItemStruct * pFindUserItem=(UserItemStruct *)m_ActiveUserPtrArray.GetAt(i);
		if (pFindUserItem!=NULL)
		{
			strBuffer=pFindUserItem->GameUserInfo.nickName;
			strBuffer.MakeLower();
			if (strBuffer.Compare(szUserName)==0)
			{
				uFindCount++;
				ResultPtrArray.Add(pFindUserItem);
			}
		}
	}
	return uFindCount;
}
Beispiel #15
0
// static
void CedExporter::GetAllCoincidentLocations(const CeLocation* loc, CPtrArray& locs, FILE* log)
{
	//if (log != 0)
	//{
	//	fprintf(log, "before loop\n");
	//	fflush(log);
	//}

	if (loc == 0)
		return;
	
	const CeTileId& tileId = loc->GetTileID();
	const CeTile* t = tileId.GetpTile();

	for (const CeTileData* td = t->GetpTileData()->GetpTail(); td; td = td->GetpPrev())
	{
		int nLoc = (int)td->GetNumLoc();

		//if (log != 0)
		//{
		//	fprintf(log, "nLoc=%d\n", nLoc);
		//	fflush(log);
		//}

		const CeLocation** tLocs = td->GetpLocations();

		for (int i=0; i<nLoc; i++)
		{
			const CeLocation* tLoc = tLocs[i];
			if ((*loc) == (*tLoc))
				locs.Add((void*)tLoc);
		}
	}

	//if (log != 0)
	//{
	//	fprintf(log, "done loop nDup=%d\n", locs.GetSize());
	//	fflush(log);
	//}
}
Beispiel #16
0
TEST_F(EngineTestParser,  findCodesFiles_noCodesFiles)
{
	CPtrArray arr;
	CCodeDirectories* pDirs =  new CCodeDirectories;
	pDirs->m_strOriginalDir = m_strRootPath.c_str();
	arr.Add(pDirs);
	int nRes = m_parser.findSubDirs(arr);
	EXPECT_NE(0, nRes);
	bool bRes = m_parser.findCodesFiles(arr);
	nRes = arr.GetSize();
	if (nRes != 0)
	{
		for (int i = 0; i < nRes; i++)
		{
			CCodeDirectories* pDirs = (CCodeDirectories*)arr.GetAt(i);
			delete pDirs;
		}
		arr.RemoveAll();
	}
	SetCurrentDirectory(g_strCurrentDir.c_str());
	ASSERT_FALSE(bRes); 
}
bool
PokerTableWnd::AnimateStartHand(WinThread* pThread, DealSeatCardsAnimationInfo* pAnimationInfo){
	PokerHandStartedPacket*	p				= &pAnimationInfo->m_handStartedPacket;
	int 					nLoop			= 0;
	int 					nCt				= m_nMaxPlayerCt;
	int						nDealer			= -1;
	int						nFirstDealSeat	= 0;

	AutoSortedArray			arrHandCards;
	for(int i=0; i<p->m_handCards.GetCount(); i++){
		PokerHandCards* pHand = p->m_handCards.GetAt(i);
		if( !pHand ) continue;
		if( (int)p->m_cDealer == ((long)pHand->m_btSeat) )
			nDealer = ((long)pHand->m_btSeat);
		arrHandCards.Add(((long)pHand->m_btSeat), (long)pHand);
		}

	// Dealer seat is unavailable.
	if( nDealer == -1 ){
		nDealer = (int)p->m_cDealer;
		bool bExists = false;
		int nIndex = arrHandCards.FindValuePlace(nDealer + 1, bExists);
		if( bExists ){
			nFirstDealSeat = arrHandCards.Get(nIndex);
			}
		else{
			if( nIndex >= arrHandCards.GetCount() )
				nFirstDealSeat = arrHandCards.Get(0);
			else
				nFirstDealSeat = arrHandCards.Get(nIndex);
			}
		}
	else{
		int nIndex = arrHandCards.IndexOf(nDealer);
		if( (nIndex + 1) >= arrHandCards.GetCount() )
			nIndex = (nIndex + 1) - arrHandCards.GetCount();
		else
			nIndex ++;
		nFirstDealSeat = arrHandCards.Get(nIndex);
		}

	// Create flying cover control. {{
	CRect rcCover;
	rcCover.left	= m_pGUI->m_ptDealerCardPos.x;
	rcCover.top		= m_pGUI->m_ptDealerCardPos.y;
	rcCover.right	= rcCover.left + m_pGUI->m_szCardDimension.cx/2;
	rcCover.bottom	= rcCover.top + m_pGUI->m_szCardDimension.cy/2;

	ESChildControlFlyingCover* pCover = new ESChildControlFlyingCover();
	AddChildControlEx(pCover, CHILD_Table_FlyingCover, rcCover, GetChildControl(CHILD_PokerTable), m_pGUI->m_szDefWindowSize);
	// }}

	CPtrArray*	pArrRects	= NULL;
	nLoop = 0;
//	PokerGUI::GetInstance()->PlaySoundByType(SoundTypes::Sound_CardsDealt);
	while( nLoop < 4 ){
		int nIndexOffset = arrHandCards.IndexOf(nFirstDealSeat);
		for(int i=0; i<arrHandCards.GetCount(); i++){
			int nSeatIndex = i + nIndexOffset;
			if( nSeatIndex >= arrHandCards.GetCount() )
				nSeatIndex -= arrHandCards.GetCount();

			if( pThread->IsStopEventSignaled() ){
				goto quit_label;
				}

			PokerHandCards* pHand = (PokerHandCards*)arrHandCards.GetData(nSeatIndex);
			if( !pHand ) continue;
			int nSeat		= ((int)pHand->m_btSeat);
			int nCards[]	= {-1, -1, -1, -1};
			nCards[0]		= (nLoop >= 0) ? ((int)pHand->m_btCard1) : -1;
			nCards[1]		= (nLoop >= 1) ? ((int)pHand->m_btCard2) : -1;
			nCards[2]		= (nLoop >= 2) ? ((int)pHand->m_btCard3) : -1;
			nCards[3]		= (nLoop >= 3) ? ((int)pHand->m_btCard4) : -1;

			if( nCards[nLoop] == -1 )
				continue;
				
			// Flying cover animation.
			int			nFrame		= 0;
			int 		nFrameCtMin	= 3;
			int 		nFrameCt	= 4;
			int			nSpeed		= 40;
			bool		bCalcFrame	= true;

			while( nFrame <= nFrameCt ){
				CRect rcClient;
				GetClientRect(rcClient);

				float fStretchCX	= rcClient.Width() / ((float)m_pGUI->m_szDefWindowSize.cx);
				float fStretchCY	= rcClient.Height() / ((float)m_pGUI->m_szDefWindowSize.cy);

				CSize szFlyingCover(pCover->GetClientWidth(), pCover->GetClientHeight());

				CRect rcStartPos;
				rcStartPos.left		= m_pGUI->m_ptDealerCardPos.x*fStretchCX;
				rcStartPos.top		= m_pGUI->m_ptDealerCardPos.y*fStretchCY;
				rcStartPos.right	= rcStartPos.left + szFlyingCover.cx;
				rcStartPos.bottom	= rcStartPos.top + szFlyingCover.cy;

				CPoint	ptMiddle	(rcStartPos.left + rcStartPos.Width()/2, rcStartPos.top + rcStartPos.Height()/2);

				CRect rcSeat		= GetSeatRect(nSeat);
				CRect rcFinishPos;
				if( ptMiddle.x > rcSeat.right ){
					rcFinishPos.left	= rcSeat.right;
					rcFinishPos.top		= rcSeat.bottom - szFlyingCover.cy;
					rcFinishPos.right	= rcFinishPos.left + szFlyingCover.cx;
					rcFinishPos.bottom	= rcSeat.bottom;
					}
				else{
					rcFinishPos.left	= rcSeat.left - szFlyingCover.cx;
					rcFinishPos.top		= rcSeat.bottom - szFlyingCover.cy;
					rcFinishPos.right	= rcFinishPos.left + szFlyingCover.cx;
					rcFinishPos.bottom	= rcSeat.bottom;
					}

				CPoint	ptMiddleFly (rcFinishPos.left + rcFinishPos.Width()/2, rcFinishPos.top + rcFinishPos.Height()/2);
				int		nMoveCY		= ptMiddleFly.y - ptMiddle.y;
				int		nMoveCX		= ptMiddleFly.x - ptMiddle.x;

				if( bCalcFrame ){
					if( abs(nMoveCY) > abs(nMoveCX) )
						nFrameCt = ((abs(nMoveCY) / nSpeed*fStretchCY) + 1);
					else
						nFrameCt = ((abs(nMoveCX) / nSpeed*fStretchCX) + 1);
					nFrameCt	= min(nFrameCt, nFrameCtMin);
					bCalcFrame	= false;
					}

				int		nOffsetY	= rcStartPos.top + (nMoveCY / nFrameCt)*(nFrame);
				int		nOffsetX	= rcStartPos.left + (nMoveCX / nFrameCt)*(nFrame);

				CRect rcCoverFly;
				rcCoverFly.left		= m_pGUI->m_ptDealerCardPos.x*fStretchCX;
				rcCoverFly.top		= m_pGUI->m_ptDealerCardPos.y*fStretchCY;
				rcCoverFly.right	= rcCoverFly.left + szFlyingCover.cx;
				rcCoverFly.bottom	= rcCoverFly.top + szFlyingCover.cy;

				CRect rcCoverOld	= pCover->GetClientRect();

				float fY = (nOffsetY*1.0f) / ((float)rcClient.Height());
				float fX = (nOffsetX*1.0f) / ((float)rcClient.Width());
				pCover->SetLogicalPos			(fX, fY);
				pCover->OwnerWindowSizeChanged	(rcClient.Width(), rcClient.Height());

				pThread->Lock(); // Lock
				pArrRects = new CPtrArray();
				pArrRects->Add(new CRect(rcCoverOld));
				pArrRects->Add(new CRect(pCover->GetClientRect()));
				pThread->Unlock(); // Unlock
				::PostMessage(GetSafeHwnd(), WM_REDRAW_RECT, 1, (LPARAM)pArrRects);

				// Play deal card sound.
				PokerGUI::GetInstance()->PlaySoundByType(SoundTypes::Sound_CardsDealt);

				Sleep(25);

				nFrame		++;
				}
			// }}

			SetSeatCards(nSeat, nCards[0], nCards[1], nCards[2], nCards[3], false);
			// Redraw seat cards. {{
			pArrRects				= new CPtrArray();
			CRect* pRect			= new CRect();
			*pRect					= GetSeatCardsRect(nSeat);
			pArrRects->Add(pRect);
			::PostMessage(GetSafeHwnd(), WM_REDRAW_RECT, 1, (LPARAM)pArrRects);
			// }}
			}
		nLoop ++;
		}

quit_label:
	// Redraw cover control. {{
	pCover->SetVisible(false, false);
	pThread->Lock(); // Lock
	pArrRects = new CPtrArray();
	pArrRects->Add(new CRect(pCover->GetClientRect()));
	pThread->Unlock(); // Unlock
	::PostMessage(GetSafeHwnd(), WM_REDRAW_RECT, 1, (LPARAM)pArrRects);
	// }}

	RemoveChildControl(pCover, true);
	// Post finish message.
	PostMessage(WM_SEAT_CARDS_DEAL_FINISHED, 0, 0);
	return true;
	}
bool	
PokerTableWnd::AnimateMoveChipsFromPot(WinThread* pThread, ChipsMovementAnimationInfo* pAnimationInfo){
	int 			nSecAnimate		= pAnimationInfo->m_nAnimationSec;
	int 			nFrameCt		= 15;
	int 			nLoop			= 0;
	int 			nCt				= m_nMaxPlayerCt;
	int*			pArrSeatAmounts	= pAnimationInfo->m_arrMoveChipsFromPotAmounts;

	float			fArrPosX[]		= {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f};
	float			fArrPosY[]		= {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f};
	CRect			rcChips	[]		= {CRect(0, 0, 0, 0), CRect(0, 0, 0, 0), CRect(0, 0, 0, 0), CRect(0, 0, 0, 0), CRect(0, 0, 0, 0),
									   CRect(0, 0, 0, 0), CRect(0, 0, 0, 0), CRect(0, 0, 0, 0), CRect(0, 0, 0, 0), CRect(0, 0, 0, 0)};
	// Collect chips controls.
	ESChildControlChips* pMainChips = GetMainChipsControl();
	ESChildControlChips* ppChips[]	= {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};

	while( nLoop < nCt ){
		PokerTableSeatInfo* pSeat = GetSeatInfo(nLoop);
		if( !pSeat || pArrSeatAmounts[nLoop] <= 0 ){
			nLoop ++;
			continue;
			}

		ppChips[nLoop] = GetChipsControl(nLoop);
		if( ppChips[nLoop] ){
			rcChips[nLoop] = ppChips[nLoop]->GetClientRect();
			ppChips[nLoop]->SetAmount(pArrSeatAmounts[nLoop], false);
			}
		
		if( ppChips[nLoop] ){
			fArrPosX[nLoop] = ppChips[nLoop]->GetLogicalPosX();
			fArrPosY[nLoop] = ppChips[nLoop]->GetLogicalPosY();
			}
		nLoop ++;
		}
	// }}

	// Animation movement(s)
	int		nFrame = 0;
	CRect	rcChipsBound;
	float	fDelay		= 1000.0f / ((float)(nFrameCt / ((float)nSecAnimate)));
	float   fAccelerate = 0.97f;

	while( nFrame < nFrameCt ){
		int nLoop1 = 0;
		rcChipsBound.SetRect(0, 0, 0, 0);

		CPtrArray* pArrRects = new CPtrArray();
		while( nLoop1 < nCt ){
			if( !ppChips[nLoop1] ){
				nLoop1 ++;
				continue;
				}

			if( pThread->IsStopEventSignaled() ){
				// Post finish message.
				::PostMessage(GetSafeHwnd(), WM_MOVE_CHIPS_FROM_POT_FINISHED, 0, 0);
				return true; // Stop animation.
				}

			CRect	rcMainChips	= pMainChips->GetClientRect();
			CPoint	ptMiddle(rcMainChips.left + rcMainChips.Width()/2, rcMainChips.top + rcMainChips.Height()/2);

			ESChildControlChips*	pChips		= ppChips[nLoop1];
			CRect					rcRectChips	= pChips->GetClientRect();
			CRect					rcChipOrig	= rcChips[nLoop1];
			CPoint					ptMiddleChips (rcChipOrig.left + rcChipOrig.Width()/2, rcChipOrig.top + rcChipOrig.Height()/2);
			int						nMoveCY		= ptMiddle.y - ptMiddleChips.y;
			int						nMoveCX		= ptMiddle.x - ptMiddleChips.x;
			int						nOffsetY	= rcChipOrig.top + (nMoveCY / nFrameCt)*(nFrameCt - (nFrame + 1));
			int						nOffsetX	= rcChipOrig.left + (nMoveCX / nFrameCt)*(nFrameCt - (nFrame + 1));

			CRect rcTableWnd;
			GetClientRect(rcTableWnd);

			float fY = (nOffsetY*1.0f) / ((float)rcTableWnd.Height());
			float fX = (nOffsetX*1.0f) / ((float)rcTableWnd.Width());

			pChips->SetLogicalPos			(fX, fY);
			pChips->OwnerWindowSizeChanged	(rcTableWnd.Width(), rcTableWnd.Height());
			
			rcRectChips |= pChips->GetClientRect();
			pThread->Lock(); // Lock
			pArrRects->Add(new CRect(rcRectChips.left, rcRectChips.top, rcRectChips.right, rcRectChips.bottom));
			pThread->Unlock(); // Unlock

			rcChipsBound |= pChips->GetClientRect();
			nLoop1 ++;
			}

		::PostMessage(GetSafeHwnd(), WM_REDRAW_RECT, 1, (LPARAM)pArrRects);
		int nSleep = (int)(fDelay*fAccelerate);
		Sleep(30);

		fAccelerate *= fAccelerate;
		nFrame		++;
		}

	// Post finish message.
	PostMessage(WM_MOVE_CHIPS_FROM_POT_FINISHED, 0, 0);
	return true;
	}
bool	
PokerTableWnd::AnimateCollectChips(WinThread* pThread, CollectChipsAnimationInfo* pAnimationInfo){
	int 			nSecAnimate	= pAnimationInfo->m_nAnimationSec;
	int 			nFrameCt	= 15;
	int				nSkipFrames	= 0;
	int 			nLoop		= 0;
	int 			nCt			= m_nMaxPlayerCt;
	int 			nMainChips	= pAnimationInfo->m_nMainChipsAmount;
	int				nChipsCt	= 0;

	float			fArrPosX[]	= {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f};
	float			fArrPosY[]	= {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f};
	CRect			rcChips	[]	= {CRect(0, 0, 0, 0), CRect(0, 0, 0, 0), CRect(0, 0, 0, 0), CRect(0, 0, 0, 0), CRect(0, 0, 0, 0),
								   CRect(0, 0, 0, 0), CRect(0, 0, 0, 0), CRect(0, 0, 0, 0), CRect(0, 0, 0, 0), CRect(0, 0, 0, 0)};

	// Collect chips controls.
	ESChildControlChips* pMainChips = GetMainChipsControl();
	ESChildControlChips* ppChips[]	= {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};

// Crush
//	pMainChips = NULL;

	while( nLoop < nCt ){
		PokerTableSeatInfo* pSeat = GetSeatInfo(nLoop);
		if( !pSeat || pSeat->GetPotAmount() <= 0 ){
			nLoop ++;
			continue;
			}

		ppChips[nLoop] = GetChipsControl(nLoop);
		if( ppChips[nLoop] ){
			if( ppChips[nLoop]->GetAmount() <= 0 ){
				ppChips[nLoop] = NULL;
				}
			else{
				rcChips[nLoop]	= ppChips[nLoop]->GetClientRect();
				fArrPosX[nLoop] = ppChips[nLoop]->GetLogicalPosX();
				fArrPosY[nLoop] = ppChips[nLoop]->GetLogicalPosY();
				nChipsCt		++;
				}
			}
		
		nLoop ++;
		}
	// }}

	if( !nChipsCt ){
		PostMessage(WM_COLLECT_CHIPS_FINISHED, 0, 0);
		return true; // Stop animation.
		}

	// Collect chips sound.
	PokerGUI::GetInstance()->PlaySoundByType(SoundTypes::Sound_ChipsMovedToPot, 1, 0);

	// Animation movement(s)
	int		nFrame = 0;
	CRect	rcChipsBound;
	float	fDelay		= 1000.0f / ((float)(nFrameCt / ((float)nSecAnimate)));
	float   fAccelerate = 0.97f;

	while( nFrame < nFrameCt ){
		int nLoop1 = 0;
		if( (nFrame + nSkipFrames) == nFrameCt )
			break;

		rcChipsBound.SetRect(MAXINT,MAXINT,MAXINT,MAXINT);

		CPtrArray* pArrRects = new CPtrArray();
		while( nLoop1 < nCt ){
			if( !ppChips[nLoop1] ){
				nLoop1 ++;
				continue;
				}

			if( pThread->IsStopEventSignaled() ){
				// Finished.
				PostMessage(WM_COLLECT_CHIPS_FINISHED, 0, 0);
				return true; // Stop animation.
				}

			CRect	rcMainChips	= pMainChips->GetClientRect();
			CPoint	ptMiddle(rcMainChips.left + rcMainChips.Width()/2, rcMainChips.top + rcMainChips.Height()/2);

			ESChildControlChips*	pChips		= ppChips[nLoop1];
			CRect					rcRectChips	= pChips->GetClientRect();
			CRect					rcChipOrig	= rcChips[nLoop1];
			CPoint					ptMiddleChips (rcChipOrig.left + rcChipOrig.Width()/2, rcChipOrig.top + rcChipOrig.Height()/2);
			int						nMoveCY		= ptMiddle.y - ptMiddleChips.y;
			int						nMoveCX		= ptMiddle.x - ptMiddleChips.x;
			int						nOffsetY	= rcChipOrig.top + (nMoveCY / nFrameCt)*(nFrame + 1);
			int						nOffsetX	= rcChipOrig.left + (nMoveCX / nFrameCt)*(nFrame + 1);

			CRect rcTableWnd;
			GetClientRect(rcTableWnd);

			float fY = (nOffsetY*1.0f) / ((float)rcTableWnd.Height());
			float fX = (nOffsetX*1.0f) / ((float)rcTableWnd.Width());

			pChips->SetLogicalPos			(fX, fY);
			pChips->OwnerWindowSizeChanged	(rcTableWnd.Width(), rcTableWnd.Height());
			
			rcRectChips |= pChips->GetClientRect();
			pThread->Lock(); // Lock
			pArrRects->Add(new CRect(rcRectChips.left, rcRectChips.top, rcRectChips.right, rcRectChips.bottom));
			pThread->Unlock(); // Unlock

			rcChipsBound |= rcRectChips;
			nLoop1 ++;
			}

		if( rcChipsBound.Width() < 300 ){
			for(int i=0; i<pArrRects->GetCount(); i++){
				CRect* pRect = (CRect*)pArrRects->GetAt(i);
				delete pRect;
				}
			pArrRects->RemoveAll();
			CRect* pRectBound = new CRect(rcChipsBound);
			pArrRects->Add(pRectBound);
			::PostMessage(GetSafeHwnd(), WM_REDRAW_RECT, 1, (LPARAM)pArrRects);
			}
		else{
			::PostMessage(GetSafeHwnd(), WM_REDRAW_RECT, 1, (LPARAM)pArrRects);
			}
		
//		int nSleep = (int)(fDelay*fAccelerate);
		Sleep(30);
//		fAccelerate *= fAccelerate;
		nFrame		++;
		}

	// Wait
	Sleep(10);

	// Clear seat pot amounts.
	int nLoop1 = 0;
	while( nLoop1 < nCt ){
		if( !ppChips[nLoop1] ){
			nLoop1 ++;
			continue;
			}

		ESChildControlChips*	pChips		= ppChips[nLoop1];
		CRect					rcRectChips	= pChips->GetClientRect();

		CRect rcTableWnd;
		GetClientRect(rcTableWnd);
		
		pChips->SetAmount				(0, false);
		pChips->SetLogicalPos			(fArrPosX[nLoop1], fArrPosY[nLoop1]);
		pChips->OwnerWindowSizeChanged	(rcTableWnd.Width(), rcTableWnd.Height());
		nLoop1 ++;
		}

	if( pThread->IsStopEventSignaled() ){
		PostMessage(WM_COLLECT_CHIPS_FINISHED, 0, 0);
		return true; // Stop animation.
		}

	pThread->Lock(); // Lock
	// Redraw all chips area at once.
	CPtrArray* pArrRects = new CPtrArray();
	pArrRects->Add(new CRect(rcChipsBound.left, rcChipsBound.top, rcChipsBound.right, rcChipsBound.bottom));
	CRect	rcMainChips	= pMainChips->GetClientRect();
	pArrRects->Add(new CRect(rcMainChips.left, rcMainChips.top, rcMainChips.right, rcMainChips.bottom));
	SetMainPotAmount	(nMainChips, false);
	::PostMessage(GetSafeHwnd(), WM_REDRAW_RECT, 1, (LPARAM)pArrRects);
	pThread->Unlock(); // Unlock

	Sleep(100);

	PostMessage(WM_COLLECT_CHIPS_FINISHED, 0, 0);
	return true;
	}
Beispiel #20
0
void WINAPI QERApp_HookWindow( IWindowListener* pListen ){
	l_WindowListeners.Add( pListen );
	pListen->IncRef();
}
Beispiel #21
0
int CTradeStatistic2::Statistic(CString day,bool show)
{
	CStringArray list;
	list.Add("序号,合约,日期,开仓时,数量,价格,方向,开平,盈亏,手续费,权益,");
	CStringArray arDirection;
	arDirection.Add("买");
	arDirection.Add("卖");
	CStringArray arOpenClose;
	arOpenClose.Add("开");
	arOpenClose.Add("平");

	
	CStringArray arTempPrice;
	CStringArray arTempCount;
	
	double maxquanyi=0;
	double maxhuiche=0;
	//CString strMaxHuicheTime;
	CString str;

	int yearbegin=0;
	CTradeStaYear * pStaYear=0;
	double beginQuanyi=0;
	CPtrArray arYear;
	double sum_yk=0;

	int countyingli = 0;
	int countkuisun=0;
	double allyingli=0;
	double allkuisun=0;
	double HuicheMax=0;
	CString HuicheTime;
	double HuicheMaxAll=0;
	CString HuicheTimeAll;

	m_nTradeCount = m_arListTrade.GetSize();

	for(int i=0;i<m_arListTrade.GetSize();i++)
	{
		double yingkui=0;
		double shouxufei= 0;
		CTradeRecord2 * pt = (CTradeRecord2 *)m_arListTrade[i];

		CString time(pt->day);
		int year = atoi(time.Mid(0,4));

		shouxufei = pt->price * pt->count * m_jiazhi * m_feilv;
		CString row;

		if( pt->openorclose == 0 )
		{
			m_beginquanyi = m_beginquanyi - shouxufei;
			row.Format("%d,%s,%s,%s,%d,%.2f,%s,%s,%.2f,%.2f,%.2f,",i,pt->heyue, pt->day,pt->time1,pt->count,pt->price,arDirection[pt->direction],arOpenClose[pt->openorclose],yingkui,shouxufei,m_beginquanyi);
			list.Add(row);
			
			str.Format("%.2f",pt->price);
			arTempPrice.Add(str);

			str.Format("%d",pt->count);
			arTempCount.Add(str);
		}
		else
		{
			yingkui = 0;
			for(int j=0;j<arTempPrice.GetSize();j++)
			{
				if( pt->direction ==0 )//BP
				{
					yingkui += atoi(arTempCount[j]) * (atof(arTempPrice[j])-pt->price) *m_jiazhi ;
				}
				else
				{
					yingkui += atoi(arTempCount[j]) * ( pt->price -atof(arTempPrice[j])  ) *m_jiazhi ;
				}
			}
			arTempPrice.RemoveAll();
			arTempCount.RemoveAll();

			m_beginquanyi += yingkui - shouxufei;

			if( m_beginquanyi > maxquanyi )
				maxquanyi = m_beginquanyi;

			pt->huiche =  maxquanyi - m_beginquanyi ;

			if( pt->huiche > HuicheMaxAll )
			{
				HuicheMaxAll = pt->huiche;
				HuicheTimeAll.Format("%s %s",pt->day, pt->time1);
			}

			//统计平均盈利和亏损
			if( yingkui > 0 )
			{
				allyingli += yingkui ;
				countyingli++;
			}
			else
			{
				allkuisun += yingkui;
				countkuisun++;
			}


			row.Format("%d,%s,%s,%s,%d,%.2f,%s,%s,%.2f,%.2f,%.2f,",i,pt->heyue,pt->day,pt->time1,pt->count,pt->price,arDirection[pt->direction],arOpenClose[pt->openorclose],yingkui,shouxufei,m_beginquanyi);
			list.Add(row);

			

			sum_yk += yingkui- shouxufei * 2;
			if( sum_yk>m_sum_max)
			{
				m_sum_max = sum_yk;			
			}
			pt->huiche = m_sum_max-sum_yk;
			if( pt->huiche > HuicheMax )
			{
				HuicheMax = pt->huiche;
				HuicheTime.Format("%s %s",pt->day,pt->time1);
			}
		}

		//分年统计
		if(yearbegin==0  )
		{			
			pStaYear = new CTradeStaYear;
			arYear.Add(pStaYear);
			yearbegin = year;
			pStaYear->year = yearbegin;

			beginQuanyi = m_beginquanyi;
		}
		else if (pStaYear && year != pStaYear->year)
		{
			//对前一年进行统计
			pStaYear->shouyi = m_beginquanyi-beginQuanyi;
			pStaYear->maxhuiche = HuicheMax;
			strcpy_s(pStaYear->szMaxHuicheTime,HuicheTime);
			
			sum_yk = 0;
			m_sum_max = 0;
			HuicheMax = 0;

			pStaYear = new CTradeStaYear;
			arYear.Add(pStaYear);
			yearbegin = year;
			pStaYear->year = yearbegin;

			beginQuanyi = m_beginquanyi;
		}	

	}

	//对前一年进行统计
	if( pStaYear)
	{
		pStaYear->shouyi = m_beginquanyi-beginQuanyi;
		pStaYear->maxhuiche = HuicheMax;
		strcpy_s(pStaYear->szMaxHuicheTime,HuicheTime);
	}


	double avgYingli = allyingli /countyingli;
	double avgKuisun = allkuisun/countkuisun;
	double shenglv = 1.0* countyingli /(countyingli+countkuisun);
	double avgYingli2 = (allyingli+allkuisun)/(countyingli+countkuisun);


	CString row;
	row = ",,,,,,";
	list.Add(row);
	row = "测试统计,,,,,,";
	list.Add(row);
	row.Format("最大回撤,%.2f,",HuicheMaxAll);
	list.Add(row);
	row.Format("最大回撤时间,%s,",HuicheTimeAll);
	list.Add(row);
	row.Format("平均盈利,%.2f,",avgYingli);
	list.Add(row);
	row.Format("平均亏损,%.2f,",avgKuisun);
	list.Add(row);
	row.Format("胜率,%.2f,",shenglv);
	list.Add(row);
	row.Format("每手平均盈利,%.2f,",avgYingli2);
	list.Add(row);

	m_shenglv = shenglv;
	m_HuicheMax = HuicheMaxAll;
	m_avgYingli2 = avgYingli2;
	m_avgYingli = avgYingli;
	m_avgKuisun = avgKuisun;

	list.Add(",,,,,,,,");
	list.Add("分年统计,");
	list.Add("年份,收益,最大回撤,回撤时间,交易次数,平均盈利,平均亏损,每手盈利,胜率,");
	for(int i=0;i<arYear.GetSize();i++)
	{
		CTradeStaYear * pYear = (CTradeStaYear *)arYear[i];
		CString row;
		row.Format("%d,%.2f,%.2f,%s,",pYear->year,pYear->shouyi,pYear->maxhuiche,pYear->szMaxHuicheTime);
		list.Add(row);
	}

	row.Format("耗时,%s", CalculateElapseTime());
	list.Add(row);

	list.InsertAt(0,day);
	if( show )
	{
		::SendMessage(m_hMsgWnd,WM_MODEL_RESULT_MSG,0,(long)&list);
		StatisticEquity();
	}
	return 0;
}
Beispiel #22
0
// Do the download.
BOOL CDownloadManager::DoDownload(CDownloadCollectionArray& Collections, LPCSTR pszDirectory)
{
	//
	// Build an array containing just the collections we want to download.
	//

	CPtrArray cpaDownloadCollections;

	for (int n = 0; n < Collections.GetSize(); n++)
	{
		CDownloadCollection& Collection = Collections.ElementAt(n);
		if (Collection.m_fDownload)
		{
			// Add this collection to the list.
			cpaDownloadCollections.Add(&Collection);
		}
	}

	//
	// Now, do the download.
	//

	int nCollections = cpaDownloadCollections.GetSize();
	if (nCollections == 0)
	{
		// Should not even be here.
		ASSERT(FALSE);
		return FALSE;
	}

	// Setup the progress dialog.
	CCollectionProgressDialog Dialog;
	Dialog.Create(CCollectionProgressDialog::IDD, CWnd::GetSafeOwner(NULL));
	Dialog.Show();

	// Create the connection callback.
	CCollectionConnectionCallback ConnectionCallback(&Dialog);

	int nStatus = CSSTATUS_Success;
	int nCollectionsDownloaded = 0;
	for (int nCollection = 0; nCollection < nCollections; nCollection++)
	{
		// Get the collection to download.
		CDownloadCollection* pCollection = (CDownloadCollection*)cpaDownloadCollections.GetAt(nCollection);

		// Update the dialog text.
		Dialog.SetCollectionsLeft(nCollections-nCollection);
		Dialog.SetCurrentCollection(pCollection->m_Info.m_csDescription);
		Dialog.SetFilesLeft(-1);		// Getting DIR file.

		// Download the DIR file.
		// Build the source name of the DIR file.
		CString csDirSourceName;
		csDirSourceName = pCollection->m_Info.m_csFileName;
		// Sometimes these files end in '.'. Get rid of it if so.
		int nLength = csDirSourceName.GetLength();
		if (nLength > 0 && csDirSourceName[nLength-1] == '.')
		{
			csDirSourceName = csDirSourceName.Left(nLength-1);
		}

		// Stick the DIR extension on.
		csDirSourceName += ".dir";

		// Build the destination name of the DIR file.
		CString csDirFileName;
		Util::ConstructPath(csDirFileName, pszDirectory, pCollection->m_Info.m_csName + ".dir");

		if ((nStatus = DownloadFile(csDirSourceName, csDirFileName, ConnectionCallback)) == CSSTATUS_Success)
		{
			// We have the DIR file.
			if (pCollection->m_Dir.Read(csDirFileName))
			{
				// We have the directory.
				const CDownloadFileArray& Files = pCollection->m_Dir.GetFiles();
				int nFiles = Files.GetSize();
				for (int nFile = 0; nFile < nFiles; nFile++)
				{
					// Set how many files are left.
					Dialog.SetFilesLeft(nFiles-nFile);

					// Get the file to download.
					const CDownloadFile& File = Files.GetAt(nFile);

					//if (!File.CheckDownloadState(pszDirectory))
					//{
						// We need to download it.
						// Construct the name of the file.
						CString csDestName;
						Util::ConstructPath(csDestName, pszDirectory, File.m_csFileName);
						if ((nStatus = DownloadFile(File.m_csSourceName, csDestName, ConnectionCallback)) != CSSTATUS_Success)
						{
							// The file was not downloaded.
							if (nStatus != CSSTATUS_UserAbort)
							{
								// See if the user wants to continue downloading files.
								if (AfxMessageBox(IDS_CantDownloadCollection, MB_YESNO) == IDNO)
								{
									nStatus = CSSTATUS_UserAbort;
								}
							}
						}
					//}

					// If the user says abort, abort!
					if (nStatus == CSSTATUS_UserAbort)
					{
						break;
					}
				}
				if (nStatus == CSSTATUS_Success)
				{
					nCollectionsDownloaded++;
				}
			}
			else
			{
				// We could not read the DIR file.
				// See if the user wants to continue downloading files.
				if (AfxMessageBox(IDS_CantReadDirFile, MB_YESNO) == IDNO)
				{
					nStatus = CSSTATUS_UserAbort;
				}
			}
		}
		else
		{
			// We did not download the DIR file.
			if (nStatus != CSSTATUS_UserAbort)
			{
				// See if the user wants to continue downloading files.
				if (AfxMessageBox(IDS_CantDownloadDirFile, MB_YESNO) == IDNO)
				{
					nStatus = CSSTATUS_UserAbort;
				}
			}
		}

		// If the user says abort, abort!
		if (nStatus == CSSTATUS_UserAbort)
		{
			break;
		}
	}

	// Get of the dialog.
	Dialog.Hide();

	// If we successfully downloaded any collections...
	if (nCollectionsDownloaded > 0)
	{
		// ...inform any interested party that the content has changed.
		::PostMessage(HWND_BROADCAST, m_uContentChangedMessage, 0, 0);
	}

	return (nStatus == CSSTATUS_Success);
}
bool
PokerTableWnd::AnimateDealTableCards(WinThread* pThread, DealTableCardsAnimationInfo* pAnimationInfo){
	PokerRoundStartedPacket*	p			= &pAnimationInfo->m_roundStartedPacket;
	ESChildControlTableCards*	pTableCards	= GetTableCardsControl();
	int							nFrameCt	= 15;

	int nCard1			= (int)p->m_btTableCard1;
	int nCard2			= (int)p->m_btTableCard2;
	int nCard3			= (int)p->m_btTableCard3;
	int nCard4			= (int)p->m_btTableCard4;
	int nCard5			= (int)p->m_btTableCard5;

	if( p->m_cRoundType == PokerRoundType::Flop ){
		int nOffsetXCard1	= -1;
		int nOffsetXCard2	= -1;
		int nOffsetXCard3	= -1;

		SetTableCards(nCard1, nCard2, nCard3, -1, -1, false);
		for(int nFrame=0; nFrame<nFrameCt; nFrame++){
			CRect	rcTableCards	= pTableCards->GetClientRect();
			CRect	rcCard			= pTableCards->GetCard1Rect();
			CRect	rcCard1			= pTableCards->GetCard1Rect();
			CRect	rcCard2			= pTableCards->GetCard2Rect();
			CRect	rcCard3			= pTableCards->GetCard3Rect();
			float	f				= (float)((rcCard3.right - rcCard1.left) / ((float)nFrameCt));
			float	fOffsetX		= f * (nFrame + 1);

			nOffsetXCard1	= ((int)fOffsetX) - rcCard.Width();
			if( nOffsetXCard1 <= 0 )
				pTableCards->SetCard1OffsetX(nOffsetXCard1);
			else
				pTableCards->SetCard1OffsetX(0);

			nOffsetXCard2	= (rcCard1.left - rcCard2.right) + (int)(f*2) + (int)(fOffsetX);
			if( nOffsetXCard2 <= 0 )
				pTableCards->SetCard2OffsetX(nOffsetXCard2);
			else
				pTableCards->SetCard2OffsetX(0);

			nOffsetXCard3	= (rcCard1.left - rcCard3.right) + (int)(f*4) + (int)(fOffsetX);
			if( nOffsetXCard3 <= 0 )
				pTableCards->SetCard3OffsetX(nOffsetXCard3);
			else
				pTableCards->SetCard3OffsetX(0);

			if( pThread->IsStopEventSignaled() ){
				// Post finish message.
				PostMessage(WM_TABLE_CARDS_DEAL_FINISHED, 0, 0);
				return true;
				}

			// Redraw seat cards. {{
			CPtrArray* pArrRects	= new CPtrArray();
			CRect* pRect			= new CRect();
			*pRect					= pTableCards->GetClientRect();
			pArrRects->Add(pRect);
			::PostMessage(GetSafeHwnd(), WM_REDRAW_RECT, 1, (LPARAM)pArrRects);
			// }}

			Sleep(40);
			}
		}
	else
	if( p->m_cRoundType == PokerRoundType::Turn ){
		int nOffsetXCard4	= -1;
		SetTableCards(nCard1, nCard2, nCard3, nCard4, -1, false);

		for(int nFrame=0; nFrame<nFrameCt; nFrame++){
			CRect	rcTableCards	= pTableCards->GetClientRect();
			CRect	rcCard			= pTableCards->GetCard4Rect();
			float	f				= (float)(rcCard.Width() / ((float)nFrameCt));
			float	fOffsetX		= f * (nFrame + 1);

			nOffsetXCard4	= ((int)fOffsetX) - rcCard.Width();
			if( nOffsetXCard4 <= 0 )
				pTableCards->SetCard4OffsetX(nOffsetXCard4);
			else
				pTableCards->SetCard4OffsetX(0);

			if( pThread->IsStopEventSignaled() ){
				// Post finish message.
				PostMessage(WM_TABLE_CARDS_DEAL_FINISHED, 0, 0);
				return true;
				}

			// Redraw seat cards. {{
			CPtrArray* pArrRects	= new CPtrArray();
			CRect* pRect			= new CRect();
			*pRect					= pTableCards->GetClientRect();
			pArrRects->Add(pRect);
			::PostMessage(GetSafeHwnd(), WM_REDRAW_RECT, 1, (LPARAM)pArrRects);
			// }}

			Sleep(30);
			}
		}
	else
	if( p->m_cRoundType == PokerRoundType::River ){
		int nOffsetXCard5	= -1;
		SetTableCards(nCard1, nCard2, nCard3, nCard4, nCard5, false);

		for(int nFrame=0; nFrame<nFrameCt; nFrame++){
			CRect	rcTableCards	= pTableCards->GetClientRect();
			CRect	rcCard			= pTableCards->GetCard5Rect();
			float	f				= (float)(rcCard.Width() / ((float)nFrameCt));
			float	fOffsetX		= f * (nFrame + 1);

			nOffsetXCard5	= ((int)fOffsetX) - rcCard.Width();
			if( nOffsetXCard5 <= 0 )
				pTableCards->SetCard5OffsetX(nOffsetXCard5);
			else
				pTableCards->SetCard5OffsetX(0);

			if( pThread->IsStopEventSignaled() ){
				// Post finish message.
				PostMessage(WM_TABLE_CARDS_DEAL_FINISHED, 0, 0);
				return true;
				}

			// Redraw seat cards. {{
			CPtrArray* pArrRects	= new CPtrArray();
			CRect* pRect			= new CRect();
			*pRect					= pTableCards->GetClientRect();
			pArrRects->Add(pRect);
			::PostMessage(GetSafeHwnd(), WM_REDRAW_RECT, 1, (LPARAM)pArrRects);
			// }}

			Sleep(30);
			}
		}
	
	// Post finish message.
	PostMessage(WM_TABLE_CARDS_DEAL_FINISHED, 0, 0);
	return 0L;
	}
Beispiel #24
0
void CedExporter::AppendExportItems(const CTime& when, const CeOperation& op, IdFactory& idf, CPtrArray& exportItems)
{
	switch (op.GetType())
	{
	case CEOP_DATA_IMPORT:
		exportItems.Add(new ImportOperation_c(idf, when, (const CeImport&)op));
		return;

	case CEOP_ARC_SUBDIVISION:
	{
		const CeArcSubdivision& sub = (const CeArcSubdivision&)op;
		LineSubdivisionOperation_c* face1 = new LineSubdivisionOperation_c(idf, when, sub, 0);
		exportItems.Add(face1);

		if (sub.IsMultiFace())
			exportItems.Add(new LineSubdivisionOperation_c(idf, when, sub, face1->Sequence));

		return;
	}

	case CEOP_DIR_INTERSECT:
		exportItems.Add(new IntersectTwoDirectionsOperation_c(idf, when, (const CeIntersectDir&)op));
		return;

	case CEOP_DIST_INTERSECT:
		exportItems.Add(new IntersectTwoDistancesOperation_c(idf, when, (const CeIntersectDist&)op));
		return;

	case CEOP_DIRDIST_INTERSECT:
		exportItems.Add(new IntersectDirectionAndDistanceOperation_c(idf, when, (const CeIntersectDirDist&)op));
		return;

	case CEOP_LINE_INTERSECT:
		exportItems.Add(new IntersectTwoLinesOperation_c(idf, when, (const CeIntersectLine&)op));
		return;

	case CEOP_NEW_POINT:
		exportItems.Add(new NewPointOperation_c(idf, when, (const CeNewPoint&)op));
		return;

	case CEOP_NEW_LABEL:
		exportItems.Add(new NewTextOperation_c(idf, when, (const CeNewLabel&)op));
		return;

	case CEOP_MOVE_LABEL:
		exportItems.Add(new MoveTextOperation_c(idf, when, (const CeMoveLabel&)op));
		return;

	case CEOP_DELETION:
	{
		DeletionOperation_c* dop = new DeletionOperation_c(idf, when, (const CeDeletion&)op);
		if (dop->Deletions.GetSize() > 0)
			exportItems.Add(dop);
		return;
	}

	case CEOP_NEW_ARC:
		exportItems.Add(new NewLineOperation_c(idf, when, (const CeNewArc&)op));
		return;

	case CEOP_PATH:
	{
		PathOperation_c* pop = new PathOperation_c(idf, when, (const CePath&)op);
		exportItems.Add(pop);

		// If CEdit produced a spurious point right at the end of the path, treat it
		// as an additional NewPointOperation.
		if (pop->FalseEndPoint)
			exportItems.Add(new NewPointOperation_c(idf, when, *(pop->FalseEndPoint)));

		return;
	}

	case CEOP_AREA_SUBDIVISION:
		exportItems.Add(new PolygonSubdivisionOperation_c(idf, when, (const CeAreaSubdivision&)op));
		return;

	case CEOP_SET_LABEL_ROTATION:
		exportItems.Add(new TextRotationOperation_c(idf, when, (const CeSetLabelRotation&)op));
		return;

	case CEOP_GET_BACKGROUND:
		exportItems.Add(new ImportOperation_c(idf, when, (const CeGetBackground&)op));
		return;

	case CEOP_GET_CONTROL:
		exportItems.Add(new GetControlOperation_c(idf, when, (const CeGetControl&)op));
		return;

	case CEOP_NEW_CIRCLE:
		exportItems.Add(new NewCircleOperation_c(idf, when, (const CeNewCircle&)op));
		return;

	case CEOP_DIRLINE_INTERSECT:
		exportItems.Add(new IntersectDirectionAndLineOperation_c(idf, when, (const CeIntersectDirLine&)op));
		return;

	case CEOP_ARC_EXTEND:
		exportItems.Add(new LineExtensionOperation_c(idf, when, (const CeArcExtension&)op));
		return;

	case CEOP_RADIAL:
		exportItems.Add(new RadialOperation_c(idf, when, (const CeRadial&)op));
		return;

	case CEOP_SET_THEME:
		AfxMessageBox("Cannot process set theme command");
		assert(1==0);
		return;

	case CEOP_SET_TOPOLOGY:
		exportItems.Add(new SetTopologyOperation_c(idf, when, (const CeSetTopology&)op));
		return;

	case CEOP_POINT_ON_LINE:
		exportItems.Add(new SimpleLineSubdivisionOperation_c(idf, when, (const CePointOnLine&)op));
		return;

	case CEOP_PARALLEL:
		exportItems.Add(new ParallelLineOperation_c(idf, when, (const CeArcParallel&)op));
		return;

	case CEOP_TRIM:
		exportItems.Add(new TrimLineOperation_c(idf, when, (const CeArcTrim&)op));
		return;

	case CEOP_ATTACH_POINT:
		exportItems.Add(new AttachPointOperation_c(idf, when, (const CeAttachPoint&)op));
		return;
	}
}
Beispiel #25
0
//------------------------------------------------------------------------
void CMRCFrameWndSizeDock::SaveBarSizes(LPCTSTR pszSection, BOOL bSave)
// Saves all the sizeable bars info
// uses the "ID" of the bar as a key. The bar will already exist on a 
// load, so this seems safe enough
//------------------------------------------------------------------------
{
	
	struct BarSizeSaveInfo BSI;
	CMRCSizeControlBar* pBar;
	char szBarId[20] = "BarSize_";

	CPtrArray arrFloatingBars;
	
	POSITION pos = m_listControlBars.GetHeadPosition();
	while (pos != NULL)
	{
		pBar = (CMRCSizeControlBar *) m_listControlBars.GetNext(pos);
		ASSERT(pBar != NULL);
		if (pBar->IsKindOf(RUNTIME_CLASS(CMRCSizeControlBar)))
		{
			UINT nID = pBar->GetDlgCtrlID();
			_itoa(nID, szBarId + 8, 10);

			if (bSave)
			{
				BSI.VertDockSize 	= pBar->m_VertDockSize;
				BSI.HorzDockSize	= pBar->m_HorzDockSize;
				BSI.FloatSize 		= pBar->m_FloatSize;
				BSI.bMDIFloating = FALSE;
				// if floating in a MDI Float window.
				CFrameWnd * pBarFrame = pBar->GetDockingFrame();
				if (pBarFrame != NULL && pBarFrame->IsKindOf(RUNTIME_CLASS(CMRCMDIFloatWnd)))
				{
					ASSERT(pBar->IsFloating());
					BSI.bMDIFloating = TRUE;
				}
				
				MRCWriteProfileBinary (pszSection, szBarId, &BSI, sizeof BSI);
			}
			else
			{
				if (MRCGetProfileBinary (pszSection, szBarId, &BSI, sizeof BSI))
				{
					pBar->m_VertDockSize	= BSI.VertDockSize;
					pBar->m_HorzDockSize	= BSI.HorzDockSize;
					pBar->m_FloatSize 		= BSI.FloatSize;
					
					// Now have to set the actual window size. The reason for this is
					// that the Adjustment algorithm looks at actual window rect sizes, so
					// it doesn't have to worry about borders etc.
					CSize NewSize = pBar->CalcFixedLayout(FALSE, (pBar->m_dwStyle & CBRS_ORIENT_HORZ));
					pBar->SetWindowPos(0, 0, 0, NewSize.cx, NewSize.cy, 
								SWP_NOACTIVATE | SWP_NOREDRAW | SWP_NOZORDER | SWP_NOMOVE);
					if (pBar->IsFloating())
					{
						if (BSI.bMDIFloating)	// floating in an MDI frame - do the float
						{
							// have to cast to CMRCMDIFrameWndSizeDock - as this is a CFrameWnd function
							ASSERT(this->IsKindOf(RUNTIME_CLASS(CMRCMDIFrameWndSizeDock)));
							arrFloatingBars.Add(pBar);
						}
						else
						{
							CFrameWnd * pFrame = pBar->GetParentFrame();
							if (pFrame != NULL)
								pFrame->RecalcLayout();
						}
					}
				}
#ifdef _VERBOSE_TRACE
				TRACE("Bar ID=%d, Floating(%d,%d), HorzDocked(%d,%d), VertDocked(%d.%d)\n",
						nID,
						BSI.FloatSize.cx,	BSI.FloatSize.cy,
						BSI.VertDockSize.cx, BSI.VertDockSize.cy,
						BSI.HorzDockSize.cx, BSI.HorzDockSize.cy);
#endif
			
			}

#ifdef _VERBOSE_TRACE
			CString strTitle;
			pBar->GetWindowText(strTitle);
			TRACE("%s '%s' ID=%d Float(%d,%d) Horz(%d,%d) Vert(%d,%d)\n",
					LPCTSTR(pBar->GetRuntimeClass()->m_lpszClassName),
					LPCTSTR(strTitle), nID,
					pBar->m_FloatSize.cx, pBar->m_FloatSize.cy,
					pBar->m_HorzDockSize.cx,  pBar->m_HorzDockSize.cy,
					pBar->m_VertDockSize.cx,  pBar->m_VertDockSize.cy);
#endif
		}
	}

	RecalcLayout();			// recalc the layout - so we end up with a meaningful set of bars
	if (!bSave)
	{
		for (int i = 0; i < arrFloatingBars.GetSize(); i++)
		{
			pBar = (CMRCSizeControlBar *) arrFloatingBars[i];
			ASSERT(pBar->m_pDockContext != NULL);
			((CMRCMDIFrameWndSizeDock *)this)->FloatControlBarInMDIChild(pBar,
											pBar->m_pDockContext->m_ptMRUFloatPos);
		}
	}
}
/***********************************************************
*	作用:马赛克特效
************************************************************/
void EffectDisplay::MosaicDisplay(CDC* pDC, CDC* pMemDC)
{
    #define SAFE_DELETE(p) { if(p) { delete (p); (p)=NULL; } }

	int nTileSize = 24;	//马赛克小方块大小
	int nRw = 0;
	int nRh = 0;

	if (s_nPicWidth % nTileSize != 0)
		nRw = 1;
	if (s_nPicHeight % nTileSize != 0)
		nRh = 1;

	//计算小方块的个数
	int nTileCount = (s_nPicWidth / nTileSize + nRw)*
		(s_nPicHeight / nTileSize + nRh);

	CPtrArray points;	//保存所有小方块的左上坐标
	long lx = 0;
	long ly = 0;

	for (int k = 0; k < nTileCount; k++)
	{
		CPoint* point = new CPoint;
		point->x = lx;
		point->y = ly;
		lx = lx + nTileSize;
		if (lx >= s_nPicWidth)
		{
			lx = 0;
			ly = ly + nTileSize;
		}
		points.Add(point);
	}

	//根据图像大小确定时间间隔
	int nDelayTime = 2;
	if (s_nPicHeight * s_nPicWidth > 600 * 500)
		nDelayTime = 1;

	LARGE_INTEGER seed;
	QueryPerformanceFrequency(&seed);
	QueryPerformanceCounter(&seed);

	//初始化一个以微秒为单位的时间种子
	srand((int)seed.QuadPart);

	for (int i = nTileCount - 1; i >= 0; i--)
	{
		int n = rand() % (i + 1);
		CPoint* point = (CPoint*)points[n];

		lx = point->x;
		ly = point->y;

		pDC->BitBlt(lx + s_nOffsetX, ly + s_nOffsetY, nTileSize, nTileSize,
			pMemDC, lx + s_nOffsetX, ly + s_nOffsetY, SRCCOPY);

		SAFE_DELETE(point);
		points.RemoveAt(n);

		DelayTime(nDelayTime);
	}
}
Beispiel #27
0
void CedExporter::CreateExport(CeMap* cedFile)
{
	//CleanObjectLists(cedFile);
	//return;

	// Ensure root folders exist (methods will quietly fail if folders are already there)
	CreateDirectory("C:\\Backsight", 0);
	CreateDirectory("C:\\Backsight\\index", 0);

	// Ensure the export has not been done already by looking for an existing index entry
	LPCTSTR mapName = cedFile->GetFileName();
	CString indexFileName;
	indexFileName.Format("C:\\Backsight\\index\\%s.txt", mapName);
	CFileStatus fileStatus;
	if (CFile::GetStatus((LPCTSTR)indexFileName, fileStatus))
	{
		AfxMessageBox("Map has been exported previously");
		return;
	}

	IdFactory idFactory;
	CPtrArray items;

	// Generate a GUID for the project
	CString guid;
	FillGuidString(guid);

	// Record the current computer name
	CString machineName;
	FillComputerName(machineName);

	// Create the new project event (assuming UTM zone 14 on NAD83)
	CTime now = CTime::GetCurrentTime();
	int layerId = 10; // Survey layer
	items.Add(new NewProjectEvent_c(idFactory, now, (LPCTSTR)guid, mapName, layerId, "UTM83-14", "CEdit", (LPCTSTR)machineName));

	// Invent a pseudo-session to enclose all ID allocations (and any other stuff)
	items.Add(new NewSessionEvent_c(idFactory, now, "CEdit", ""));

	CeIdManager* idMan = CeIdHandle::GetIdManager();
	unsigned int nGroup = idMan->GetNumGroup();

	for (unsigned int i=0; i<nGroup; i++)
	{
		const CeIdGroup* group = idMan->GetpGroup(i);
		int groupId = idFactory.GetGroupId(group->GetGroupName());
		const CPtrList& ranges = group->GetIdRanges();

		POSITION pos = ranges.GetHeadPosition();
		while ( pos )
		{
			CeIdRange* range = (CeIdRange*)ranges.GetNext(pos);
			items.Add(new IdAllocation_c(idFactory, now, groupId, range->GetMin(), range->GetMax()));
		}
	}

	// Produce a definitive (correct) list of the features created
	// be each edit. This aims to overcome a defect in the lists associated
	// with CeImport edits (and perhaps other edits).
	idFactory.GenerateOperationFeatureLists(cedFile);
	
	// Generate any points that will be needed for line ends (whereas CEdit would let you have lines without
	// an end point, Backsight requires them)
	ImportOperation_c* extra = new ImportOperation_c(idFactory, now);
	GenerateExtraPoints(cedFile, idFactory, extra->Features);
	//AfxMessageBox("done extra points");

	// Represent the points as an import operation
	if (extra->Features.GetSize() == 0)
		delete extra;
	else
		items.Add(extra);

	items.Add(new EndSessionEvent_c(idFactory, now));

	// Now loop through each session (but ignore empty sessions).
	CPSEPtrList& sessions = cedFile->GetSessions();
	POSITION spos = sessions.GetHeadPosition();
	int totop = 0;

	while (spos != 0)
	{
		CeSession* session = (CeSession*)sessions.GetNext(spos);
		const CPSEPtrList& ops = session->GetOperations();
		int nop = ops.GetCount();
		totop += nop;

		if (nop > 0)
		{
			// Append the NewSessionEvent
			CTime startTime(session->GetStart().GetTimeValue());
			CTime endTime(session->GetEnd().GetTimeValue());
			items.Add(new NewSessionEvent_c(idFactory, startTime, (LPCTSTR)session->GetpWho()->GetpWho(), ""));

			// Figure out the average time between successive edits (treat the end session event as an "edit")
			LONG sessionSecs = (endTime - startTime).GetTotalSeconds();
			LONG secsPerEdit = sessionSecs / (nop + 2);

			POSITION opos = ops.GetHeadPosition();
			for (int i=0; i<nop; i++)
			{
				CeOperation* op = (CeOperation*)ops.GetNext(opos);
				LONG secs = (i+1) * secsPerEdit;
				CTimeSpan delta(0,0,0, secs);
				CTime when = startTime + delta;
				AppendExportItems(when, *op, idFactory, items);
			}

			// Append the end session event
			items.Add(new EndSessionEvent_c(idFactory, endTime));
		}
	}

	// Clear the lists of features associated with each edit
	idFactory.ClearOperationFeatureLists();

	// test
	CString t;
	t.Format("Number of edits=%d", totop);
	AfxMessageBox(t);
	//return;

	// Create the project folder
	CString projectFolder;
	projectFolder.Format("C:\\Backsight\\%s", (LPCTSTR)guid);
	CreateDirectory((LPCTSTR)projectFolder, 0);

	// Produce the output file
	unsigned int maxId = idFactory.GetNextId();
	CString fileName;
	fileName.Format("%s\\%u.txt", (LPCTSTR)projectFolder, maxId);

	FILE* fp = fopen((LPCTSTR)fileName, "w");
	TextEditWriter* tw = new TextEditWriter(fp);
	EditSerializer* es = new EditSerializer(idFactory, *tw);

	for (int ix=0; ix<items.GetSize(); ix++)
	{
		Persistent_c* p = (Persistent_c*)items.GetAt(ix);
		es->WritePersistent(DataField_Edit, *p);
	}

	delete es;
	delete tw;
	fclose(fp);

	// Write the index entry file
	fp = fopen((LPCTSTR)indexFileName, "w");
	fprintf(fp, "%s", (LPCTSTR)guid);
	fclose(fp);
	
	// Write point positions file
	CString ptsFileName;
	ptsFileName.Format("%s\\%s.pts", (LPCTSTR)projectFolder, mapName);
	idFactory.WritePointsFile((LPCTSTR)ptsFileName);

	// Remove the export objects
	for (int ip=0; ip<items.GetSize(); ip++)
	{
		Persistent_c* p = (Persistent_c*)items.GetAt(ip);
		delete p;
	}

	// Dump out attributes...

	// Obtain the mapping from schema to output file extension (for consistency with
	// current data distributions done by GeoManitoba).
	CeExportTypeUtil xt;
	int rcode = xt.Load();
	if ( rcode < 0 )
	{
		CString msg;
		xt.GetLoadMessage(msg,rcode);
		AfxMessageBox(msg);
		return;
	}

	// Collect the IDs
	CPtrList ids;
	cedFile->GetIds(ids);

	// Collect the rows attached to the IDs
	CPtrList rows;
	CeTableEx::CollectRows(rows, ids);

	// Group by table. Then dispense with the list of pointers to rows.
	CPtrList tables;
	CeTableEx::BinRows(tables, rows);
	rows.RemoveAll();

	// Go through each bin, exporting the info to an output text file.	
	POSITION pos = tables.GetHeadPosition();
	CString tableFileName;

	while ( pos )
	{
		CeTableEx* pTable = (CeTableEx*)tables.GetNext(pos);

		// Determine the name of the output file (based on the name of the schema)
		const CeSchema& schema = pTable->GetSchema();
		tableFileName.Format("%s\\%s-%s.txt", (LPCTSTR)projectFolder, mapName, xt.GetFileType(schema));

		// Write out the attributes
		pTable->Export((LPCTSTR)tableFileName);
		delete pTable;
	}

	// Remove pointers to the tables (now deleted).
	tables.RemoveAll();
}
Beispiel #28
0
//
// =======================================================================================================================
//    Map_ImportFile Timo 09/01/99:: called by CXYWnd::Paste & Map_ImportFile if Map_ImportFile ( prefab ), the buffer
//    may contain brushes in old format ( conversion needed )
// =======================================================================================================================
//
void Map_ImportBuffer(char *buf, bool renameEntities) {
	entity_t	*ent;
	brush_t		*b = NULL;
	CPtrArray	ptrs;

	Select_Deselect();

	Undo_Start("import buffer");

	g_qeglobals.d_parsed_brushes = 0;
	if (buf) {
		CMapStringToString	mapStr;
		StartTokenParsing(buf);
		g_qeglobals.d_num_entities = 0;

		//
		// Timo will be used in Entity_Parse to detect if a conversion between brush
		// formats is needed
		//
		g_qeglobals.bNeedConvert = false;
		g_qeglobals.bOldBrushes = false;
		g_qeglobals.bPrimitBrushes = false;
		g_qeglobals.mapVersion = 1.0;

		if (GetToken(true)) {
			if (stricmp(token, "Version") == 0) {
				GetToken(false);
				g_qeglobals.mapVersion = atof(token);
				common->Printf("Map version: %1.2f\n", g_qeglobals.mapVersion);
			} else {
				UngetToken();
			}
		}

		idDict RemappedNames;	// since I can't use "map <string, string>"... sigh. So much for STL...

		while (1) {
			//
			// use the selected brushes list as it's handy ent = Entity_Parse (false,
			// &selected_brushes);
			//
			ent = Entity_Parse(false, &active_brushes);
			if (!ent) {
				break;
			}

			// end entity for undo
			Undo_EndEntity(ent);

			// end brushes for undo
			for (b = ent->brushes.onext; b && b != &ent->brushes; b = b->onext) {
				Undo_EndBrush(b);
			}

			if (!strcmp(ValueForKey(ent, "classname"), "worldspawn")) {
				// world brushes need to be added to the current world entity
				b = ent->brushes.onext;
				while (b && b != &ent->brushes) {
					brush_t *bNext = b->onext;
					Entity_UnlinkBrush(b);
					Entity_LinkBrush(world_entity, b);
					ptrs.Add(b);
					b = bNext;
				}
			}
			else {
				// the following bit remaps conflicting target/targetname key/value pairs
				CString str = ValueForKey(ent, "target");
				CString strKey;
				CString strTarget("");
				if (str.GetLength() > 0) {
					if (FindEntity("target", str.GetBuffer(0))) {
						if (!mapStr.Lookup(str, strKey)) {
							idStr key;
							UniqueTargetName(key);
							strKey = key;
							mapStr.SetAt(str, strKey);
						}

						strTarget = strKey;
						SetKeyValue(ent, "target", strTarget.GetBuffer(0));
					}
				}

				/*
				 * str = ValueForKey(ent, "name"); if (str.GetLength() > 0) { if
				 * (FindEntity("name", str.GetBuffer(0))) { if (!mapStr.Lookup(str, strKey)) {
				 * UniqueTargetName(strKey); mapStr.SetAt(str, strKey); } Entity_SetName(ent,
				 * strKey.GetBuffer(0)); } }
				 */
				CString cstrNameOld = ValueForKey(ent, "name");
				Entity_Name(ent, renameEntities);
				CString cstrNameNew = ValueForKey(ent, "name");
				if (cstrNameOld != cstrNameNew)
				{
					RemappedNames.Set(cstrNameOld, cstrNameNew);
				}
				//
				// if (strTarget.GetLength() > 0) SetKeyValue(ent, "target",
				// strTarget.GetBuffer(0));
				// add the entity to the end of the entity list
				//
				ent->next = &entities;
				ent->prev = entities.prev;
				entities.prev->next = ent;
				entities.prev = ent;
				g_qeglobals.d_num_entities++;

				for (b = ent->brushes.onext; b != &ent->brushes; b = b->onext) {
					ptrs.Add(b);
				}
			}
		}

		// now iterate through the remapped names, and see if there are any target-connections that need remaking...
		//
		// (I could probably write this in half the size with STL, but WTF, work with what we have...)
		//
		int iNumKeyVals = RemappedNames.GetNumKeyVals();
		for (int iKeyVal=0; iKeyVal < iNumKeyVals; iKeyVal++)
		{
			const idKeyValue *pKeyVal = RemappedNames.GetKeyVal( iKeyVal );

			LPCSTR psOldName = pKeyVal->GetKey().c_str();
			LPCSTR psNewName = pKeyVal->GetValue().c_str();

			entity_t *pEntOld = FindEntity("name", psOldName);	// original ent we cloned from
			entity_t *pEntNew = FindEntity("name", psNewName);	// cloned ent

			if (pEntOld && pEntNew)
			{
				CString cstrTargetNameOld = ValueForKey(pEntOld, "target");
				if (!cstrTargetNameOld.IsEmpty())
				{
					// ok, this ent was targeted at another ent, so it's clone needs updating to point to
					//	the clone of that target, so...
					//
					entity_t *pEntOldTarget = FindEntity("name", cstrTargetNameOld);
					if ( pEntOldTarget )
					{
						LPCSTR psNewTargetName = RemappedNames.GetString( cstrTargetNameOld );
						if (psNewTargetName && psNewTargetName[0])
						{
							SetKeyValue(pEntNew, "target", psNewTargetName);
						}
					}
				}
			}
		}
	}

	//
	// ::ShowWindow(g_qeglobals.d_hwndEntity, FALSE);
	// ::LockWindowUpdate(g_qeglobals.d_hwndEntity);
	//
	g_bScreenUpdates = false;
	for (int i = 0; i < ptrs.GetSize(); i++) {
		Brush_Build(reinterpret_cast < brush_t * > (ptrs[i]), true, false);
		Select_Brush(reinterpret_cast < brush_t * > (ptrs[i]), true, false);
	}

	// ::LockWindowUpdate(NULL);
	g_bScreenUpdates = true;

	ptrs.RemoveAll();

	//
	// reset the "need conversion" flag conversion to the good format done in
	// Map_BuildBrushData
	//
	g_qeglobals.bNeedConvert = false;

	Sys_UpdateWindows(W_ALL);

	// Sys_MarkMapModified();
	mapModified = 1;

	Undo_End();
}
Beispiel #29
0
    // 
    // open the file and grab all the includes.
    //
    void ProcessFile(){
        FILE *f;
		CString fullName;
        BOOL bSystem;
		DWORD lineCntr = 0;
		char *a = new char[2048];
        memset(a, 0, 2048);
		char srcPath[_MAX_PATH];

		// construct the full path
		if (!_AfxFullPath(srcPath, m_pathName)) {
			strcpy(srcPath, m_pathName);
		}

		// strip off the source filename to end up with just the path
		LPSTR pTemp = strrchr(srcPath, '\\');
		if (pTemp) {
			*(pTemp + 1) = 0;
		}

        f = fopen(m_pathName, "r");
        if(f != NULL && f != (FILE *)-1)  {
			setvbuf(f, NULL, _IOFBF, 32768);		// use a large file buffer
            while(fgets(a, 2047, f)) {
				// if the string "//{{NO_DEPENDENCIES}}" is at the start of one of the 
				// first 10 lines of a file, don't build dependencies on it or any
				// of the files it includes
				if (lineCntr < 10) {
					static char* pDependStr = "//{{NO_DEPENDENCIES}}";
					if (strncmp(a, pDependStr, strlen(pDependStr)) == 0) {
						noDependMap[m_pathName] = 0;	// add it to the noDependMap
						break;							// no need for further processing of this file
					}
				}
				++lineCntr;
				// have to handle a variety of legal syntaxes that we find in our source files:
				//    #include
				// #   include
                // #include
				// if the first non-whitespace char is a '#', consider this line
				pTemp = a;
				pTemp += strspn(pTemp, " \t");			// skip whitespace
				if (*pTemp == '#') {
					++pTemp;							// skip the '#'
					pTemp += strspn(pTemp, " \t");		// skip more whitespace
					if( !strncmp(pTemp, "include", 7) ){
						pTemp += 7;						// skip the "include"
						pTemp += strspn(pTemp, " \t");	// skip more whitespace
						bSystem = (*pTemp == '<');		// mark if it's a system include or not
                        // forget system files -- we just have to search all the paths
                        // every time and never find them! This change alone speeds a full
                        // depend run on my system from 5 minutes to 3:15
						// if (bSystem || (*pTemp == '"')) {
                        if (*pTemp == '"') {
							LPSTR pStart = pTemp + 1;	// mark the start of the string
							pTemp = pStart + strcspn(pStart, ">\" ");	// find the end of the string
							*pTemp = 0;					// terminate the string

							// construct the full pathname from the path part of the 
							// source file and the name listed here
							fullName = srcPath;
							fullName += pStart;
							CFileRecord *pAddMe = AddFile( pStart, fullName, bSystem );
							if (pAddMe) {
								m_includes.Add(pAddMe);
							}
						}
					}
				}
            }
            fclose(f);
        }
        delete [] a;
    }
Beispiel #30
0
trace_t Test_Ray( vec3_t origin, vec3_t dir, int flags )
{
	brush_s*    brush;
	face_s* face;
	float   dist;
	trace_t t;
	
	memset( &t, 0, sizeof( t ) );
	t.dist = DIST_START;
	
	if ( flags & SF_CYCLE )
	{
		CPtrArray array;
		brush_s* pToSelect = ( selected_brushes.next != &selected_brushes ) ? selected_brushes.next : NULL;
		Select_Deselect();
		
		// go through active brushes and accumulate all "hit" brushes
		for ( brush = active_brushes.next ; brush != &active_brushes ; brush = brush->next )
		{
			//if ( (flags & SF_ENTITIES_FIRST) && brush->owner == world_entity)
			//  continue;
			
			if ( FilterBrush( brush ) )
				continue;
				
			if ( !g_PrefsDlg.m_bSelectCurves && brush->patchBrush )
				continue;
				
			if ( !g_PrefsDlg.m_bSelectTerrain && brush->terrainBrush )
				continue;
				
			//if (!g_bShowPatchBounds && brush->patchBrush)
			//  continue;
			
			face = Brush_Ray( origin, dir, brush, &dist );
			
			if ( face )
			{
				array.Add( brush );
			}
		}
		
		int nSize = array.GetSize();
		if ( nSize > 0 )
		{
			bool bFound = false;
			for ( int i = 0; i < nSize; i++ )
			{
				brush_s* b = reinterpret_cast<brush_s*>( array.GetAt( i ) );
				// did we hit the last one selected yet ?
				if ( b == pToSelect )
				{
					// yes we want to select the next one in the list
					int n = ( i > 0 ) ? i - 1 : nSize - 1;
					pToSelect = reinterpret_cast<brush_s*>( array.GetAt( n ) );
					bFound = true;
					break;
				}
			}
			if ( !bFound )
				pToSelect = reinterpret_cast<brush_s*>( array.GetAt( 0 ) );
		}
		if ( pToSelect )
		{
			face = Brush_Ray( origin, dir, pToSelect, &dist );
			
			t.dist = dist;
			t.brush = pToSelect;
			t.face = face;
			t.selected = false;
			return t;
		}
	}
	
	if ( !( flags & SF_SELECTED_ONLY ) )
	{
		for ( brush = active_brushes.next ; brush != &active_brushes ; brush = brush->next )
		{
			if ( ( flags & SF_ENTITIES_FIRST ) && brush->owner == world_entity )
				continue;
				
			if ( FilterBrush( brush ) )
				continue;
				
			if ( !g_PrefsDlg.m_bSelectCurves && brush->patchBrush )
				continue;
				
			if ( !g_PrefsDlg.m_bSelectTerrain && brush->terrainBrush )
				continue;
				
			//if (!g_bShowPatchBounds && brush->patchBrush)
			//  continue;
			
			face = Brush_Ray( origin, dir, brush, &dist );
			if ( dist > 0 && dist < t.dist )
			{
				t.dist = dist;
				t.brush = brush;
				t.face = face;
				t.selected = false;
			}
		}
	}
	
	
	for ( brush = selected_brushes.next ; brush != 0 && brush != &selected_brushes ; brush = brush->next )
	{
		if ( ( flags & SF_ENTITIES_FIRST ) && brush->owner == world_entity )
			continue;
			
		if ( FilterBrush( brush ) )
			continue;
			
		if ( !g_PrefsDlg.m_bSelectCurves && brush->patchBrush )
			continue;
			
		if ( !g_PrefsDlg.m_bSelectTerrain && brush->terrainBrush )
			continue;
			
		face = Brush_Ray( origin, dir, brush, &dist );
		if ( dist > 0 && dist < t.dist )
		{
			t.dist = dist;
			t.brush = brush;
			t.face = face;
			t.selected = true;
		}
	}
	
	// if entites first, but didn't find any, check regular
	
	if ( ( flags & SF_ENTITIES_FIRST ) && t.brush == NULL )
		return Test_Ray( origin, dir, flags - SF_ENTITIES_FIRST );
		
	return t;
	
}