bool GameFactory::DestroyInstance(NetworkID id)
{
	FactoryObject reference = GetObject(id);
	DestroyInstance(reference);
	return true;
}
示例#2
0
//把HBITMAP保存成位图
BOOL SaveBmp(HBITMAP hBitmap, LPCWSTR FileName)
{
	HDC hDC;
	//当前分辨率下每象素所占字节数
	int iBits;
	//位图中每象素所占字节数
	WORD wBitCount;
	//定义调色板大小, 位图中像素字节大小 ,位图文件大小 , 写入文件字节数 
	DWORD dwPaletteSize=0, dwBmBitsSize=0, dwDIBSize=0, dwWritten=0; 
	//位图属性结构 
	BITMAP Bitmap; 
	//位图文件头结构
	BITMAPFILEHEADER bmfHdr; 
	//位图信息头结构 
	BITMAPINFOHEADER bi; 
	//指向位图信息头结构 
	LPBITMAPINFOHEADER lpbi; 
	//定义文件,分配内存句柄,调色板句柄 
	HANDLE fh, hDib, hPal,hOldPal=NULL; 

	//计算位图文件每个像素所占字节数 
	hDC = CreateDC( _T( "DISPLAY" ), NULL, NULL, NULL);
	iBits = GetDeviceCaps(hDC, BITSPIXEL) * GetDeviceCaps(hDC, PLANES); 
	DeleteDC(hDC); 
	if (iBits <= 1) wBitCount = 1; 
	else if (iBits <= 4) wBitCount = 4; 
	else if (iBits <= 8) wBitCount = 8; 
	else wBitCount = 24; 

	GetObject(hBitmap, sizeof(Bitmap), (LPSTR)&Bitmap);
	bi.biSize = sizeof(BITMAPINFOHEADER);
	bi.biWidth = Bitmap.bmWidth;
	bi.biHeight = Bitmap.bmHeight;
	bi.biPlanes = 1;
	bi.biBitCount = wBitCount;
	bi.biCompression = BI_RGB;
	bi.biSizeImage = 0;
	bi.biXPelsPerMeter = 0;
	bi.biYPelsPerMeter = 0;
	bi.biClrImportant = 0;
	bi.biClrUsed = 0;

	dwBmBitsSize = ((Bitmap.bmWidth * wBitCount + 31) / 32) * 4 * Bitmap.bmHeight;

	//为位图内容分配内存 
	hDib = GlobalAlloc(GHND,dwBmBitsSize + dwPaletteSize + sizeof(BITMAPINFOHEADER)); 
	lpbi = (LPBITMAPINFOHEADER)GlobalLock(hDib); 
	*lpbi = bi; 
	// 处理调色板 
	hPal = GetStockObject(DEFAULT_PALETTE); 
	if (hPal) 
	{ 
		hDC = ::GetDC(NULL); 
		hOldPal = ::SelectPalette(hDC, (HPALETTE)hPal, FALSE); 
		RealizePalette(hDC); 
	}
	// 获取该调色板下新的像素值 
	GetDIBits(hDC, hBitmap, 0, (UINT) Bitmap.bmHeight, (LPSTR)lpbi + sizeof(BITMAPINFOHEADER) 
		+dwPaletteSize, (BITMAPINFO *)lpbi, DIB_RGB_COLORS); 

	//恢复调色板 
	if (hOldPal) 
	{ 
		::SelectPalette(hDC, (HPALETTE)hOldPal, TRUE); 
		RealizePalette(hDC); 
		::ReleaseDC(NULL, hDC); 
	} 
	//创建位图文件 
	fh = CreateFile( FileName, GENERIC_WRITE,0, NULL, CREATE_ALWAYS, 
		FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL ); 

	if (fh == INVALID_HANDLE_VALUE) return FALSE; 

	// 设置位图文件头 
	bmfHdr.bfType = 0x4D42; // "BM" 
	dwDIBSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + dwPaletteSize + dwBmBitsSize; 
	bmfHdr.bfSize = dwDIBSize; 
	bmfHdr.bfReserved1 = 0; 
	bmfHdr.bfReserved2 = 0; 
	bmfHdr.bfOffBits = (DWORD)sizeof(BITMAPFILEHEADER) + (DWORD)sizeof(BITMAPINFOHEADER) + dwPaletteSize; 
	// 写入位图文件头 
	WriteFile(fh, (LPSTR)&bmfHdr, sizeof(BITMAPFILEHEADER), &dwWritten, NULL); 
	// 写入位图文件其余内容 
	WriteFile(fh, (LPSTR)lpbi, dwDIBSize, &dwWritten, NULL); 
	//清除 
	GlobalUnlock(hDib); 
	GlobalFree(hDib); 
	CloseHandle(fh); 
	return TRUE;
}
示例#3
0
int CxSkinButton::GetBitmapWidth (HBITMAP hBitmap)
{ BITMAP bm; GetObject(hBitmap,sizeof(BITMAP),(PSTR)&bm); return bm.bmWidth;}
const FFieldNetCache* FObjectReplicator::ReadField( const FClassNetCache* ClassCache, FInBunch& Bunch ) const
{
	if ( Connection->InternalAck )
	{
		// Replays use checksum rather than index
		uint32 Checksum = 0;
		Bunch << Checksum;

		if ( Bunch.IsError() )
		{
			UE_LOG(LogNet, Error, TEXT("ReadField: Error reading checksum: %s"), *GetObject()->GetFullName());
			return NULL;
		}

		if ( Checksum == 0 )
		{
			return NULL;	// We're done
		}

		const FFieldNetCache * FieldNetCache = ClassCache->GetFromChecksum( Checksum );

		if ( FieldNetCache == NULL )
		{
			UE_LOG(LogNet, Error, TEXT("ReadField: GetFromChecksum failed: %s"), *GetObject()->GetFullName());
			Bunch.SetError();
			return NULL;
		}

		return FieldNetCache;
	}

	const int32 RepIndex = Bunch.ReadInt( ClassCache->GetMaxIndex() + 1 );

	if ( Bunch.IsError() )
	{
		UE_LOG(LogRep, Error, TEXT("ReadField: Error reading RepIndex: %s"), *GetObject()->GetFullName());
		return NULL;
	}

	if ( RepIndex == ClassCache->GetMaxIndex() )
	{
		return NULL;	// We're done
	}

	if ( RepIndex > ClassCache->GetMaxIndex() )
	{
		// We shouldn't be receiving this bunch of this object has no properties or RPC functions to process
		UE_LOG(LogRep, Error, TEXT("ReadField: RepIndex too large: %s"), *GetObject()->GetFullName());
		Bunch.SetError();
		return NULL;
	}
	
	const FFieldNetCache * FieldNetCache = ClassCache->GetFromIndex( RepIndex );

	if ( FieldNetCache == NULL )
	{
		UE_LOG(LogNet, Error, TEXT("ReadField: GetFromIndex failed: %s"), *GetObject()->GetFullName());
		Bunch.SetError();
		return NULL;
	}

	return FieldNetCache;
}
void FObjectReplicator::ReplicateCustomDeltaProperties( FOutBunch & Bunch, FReplicationFlags RepFlags, bool & bContentBlockWritten )
{
	if ( LifetimeCustomDeltaProperties.Num() == 0 )
	{
		// No custom properties
		return;
	}

	UObject* Object = GetObject();

	check( Object );
	check( OwningChannel );

	UNetConnection * OwningChannelConnection = OwningChannel->Connection;

	// Initialize a map of which conditions are valid

	bool ConditionMap[COND_Max];
	const bool bIsInitial = RepFlags.bNetInitial ? true : false;
	const bool bIsOwner = RepFlags.bNetOwner ? true : false;
	const bool bIsSimulated = RepFlags.bNetSimulated ? true : false;
	const bool bIsPhysics = RepFlags.bRepPhysics ? true : false;

	ConditionMap[COND_None] = true;
	ConditionMap[COND_InitialOnly] = bIsInitial;
	ConditionMap[COND_OwnerOnly] = bIsOwner;
	ConditionMap[COND_SkipOwner] = !bIsOwner;
	ConditionMap[COND_SimulatedOnly] = bIsSimulated;
	ConditionMap[COND_AutonomousOnly] = !bIsSimulated;
	ConditionMap[COND_SimulatedOrPhysics] = bIsSimulated || bIsPhysics;
	ConditionMap[COND_InitialOrOwner] = bIsInitial || bIsOwner;
	ConditionMap[COND_Custom] = true;

	// Replicate those properties.
	for ( int32 i = 0; i < LifetimeCustomDeltaProperties.Num(); i++ )
	{
		// Get info.
		const int32				RetireIndex	= LifetimeCustomDeltaProperties[i];
		FPropertyRetirement &	Retire		= Retirement[RetireIndex];
		FRepRecord *			Rep			= &ObjectClass->ClassReps[RetireIndex];
		UProperty *				It			= Rep->Property;
		int32					Index		= Rep->Index;

		if (LifetimeCustomDeltaPropertyConditions.IsValidIndex(i))
		{
			// Check the replication condition here
			ELifetimeCondition RepCondition = LifetimeCustomDeltaPropertyConditions[i];

			check(RepCondition >= 0 && RepCondition < COND_Max);

			if (!ConditionMap[RepCondition])
			{
				// We didn't pass the condition so don't replicate us
				continue;
			}
		}

		const int32 BitsWrittenBeforeThis = Bunch.GetNumBits();

		// If this is a dynamic array, we do the delta here
		TSharedPtr<INetDeltaBaseState> & OldState = RecentCustomDeltaState.FindOrAdd( RetireIndex );
		TSharedPtr<INetDeltaBaseState> NewState;

		// Update Retirement records with this new state so we can handle packet drops.
		// LastNext will be pointer to the last "Next" pointer in the list (so pointer to a pointer)
		FPropertyRetirement ** LastNext = UpdateAckedRetirements( Retire, OwningChannelConnection->OutAckPacketId );

		check( LastNext != NULL );
		check( *LastNext == NULL );

		ValidateRetirementHistory( Retire );

		FNetBitWriter TempBitWriter( OwningChannel->Connection->PackageMap, 0 );

		//-----------------------------------------
		//	Do delta serialization on dynamic properties
		//-----------------------------------------
		const bool WroteSomething = SerializeCustomDeltaProperty( OwningChannelConnection, (void*)Object, It, Index, TempBitWriter, NewState, OldState );

		if ( !WroteSomething )
		{
			continue;
		}

		*LastNext = new FPropertyRetirement();

		// Remember what the old state was at this point in time.  If we get a nak, we will need to revert back to this.
		(*LastNext)->DynamicState = OldState;		

		// Save NewState into the RecentCustomDeltaState array (old state is a reference into our RecentCustomDeltaState map)
		OldState = NewState; 

		// Write header, and data to send to the actual bunch
		RepLayout->WritePropertyHeader( Object, ObjectClass, OwningChannel, It, Bunch, Index, bContentBlockWritten );

		const int NumStartingBits = Bunch.GetNumBits();

		// Send property.
		Bunch.SerializeBits( TempBitWriter.GetData(), TempBitWriter.GetNumBits() );

		NETWORK_PROFILER(GNetworkProfiler.TrackReplicateProperty(It, Bunch.GetNumBits() - NumStartingBits));
	}
}
EquivalenceScope::Object EquivalenceScope::GetObject(ASTContext &C, const Expr *E, VarDecl *Var, uint64_t Offset) {
  return Object(E, Offset, GetObject(C, Var));
}
void FObjectReplicator::UpdateUnmappedObjects( bool & bOutHasMoreUnmapped )
{
	UObject* Object = GetObject();

	if ( Object == NULL || Object->IsPendingKill() )
	{
		bOutHasMoreUnmapped = false;
		return;
	}

	if ( Connection->State == USOCK_Closed )
	{
		UE_LOG(LogNet, Warning, TEXT("FObjectReplicator::UpdateUnmappedObjects: Connection->State == USOCK_Closed"));
		return;
	}

	checkf( RepState->RepNotifies.Num() == 0, TEXT("Failed RepState RepNotifies check. Num=%d. Object=%s"), RepState->RepNotifies.Num(), *Object->GetFullName() );
	checkf( RepNotifies.Num() == 0, TEXT("Failed replicator RepNotifies check. Num=%d. Object=%s."), RepNotifies.Num(), *Object->GetFullName() );

	bool bSomeObjectsWereMapped = false;

	// Let the rep layout update any unmapped properties
	RepLayout->UpdateUnmappedObjects( RepState, Connection->PackageMap, Object, bSomeObjectsWereMapped, bOutHasMoreUnmapped );

	// Update unmapped objects for custom properties (currently just fast tarray)
	for ( auto It = UnmappedCustomProperties.CreateIterator(); It; ++It )
	{
		const int32			Offset			= It.Key();
		UStructProperty*	StructProperty	= It.Value();
		UScriptStruct*		InnerStruct		= StructProperty->Struct;

		check( InnerStruct->StructFlags & STRUCT_NetDeltaSerializeNative );

		UScriptStruct::ICppStructOps* CppStructOps = InnerStruct->GetCppStructOps();

		check( CppStructOps );
		check( !InnerStruct->InheritedCppStructOps() );

		FNetDeltaSerializeInfo Parms;

		FNetSerializeCB NetSerializeCB( OwningChannel->Connection->Driver );

		Parms.DebugName			= StructProperty->GetName();
		Parms.Struct			= InnerStruct;
		Parms.Map				= Connection->PackageMap;
		Parms.NetSerializeCB	= &NetSerializeCB;

		Parms.bUpdateUnmappedObjects	= true;
		Parms.bCalledPreNetReceive		= bSomeObjectsWereMapped;	// RepLayout used this to flag whether PreNetReceive was called
		Parms.Object					= Object;

		// Call the custom delta serialize function to handle it
		CppStructOps->NetDeltaSerialize( Parms, (uint8*)Object + Offset );

		// Merge in results
		bSomeObjectsWereMapped	|= Parms.bOutSomeObjectsWereMapped;
		bOutHasMoreUnmapped		|= Parms.bOutHasMoreUnmapped;

		if ( Parms.bOutSomeObjectsWereMapped )
		{
			// If we mapped a property, call the rep notify
			TArray<uint8> MetaData;
			QueuePropertyRepNotify( Object, StructProperty, 0, MetaData );
		}

		// If this property no longer has unmapped objects, we can stop checking it
		if ( !Parms.bOutHasMoreUnmapped )
		{
			It.RemoveCurrent();
		}
	}

	// Call any rep notifies that need to happen when object pointers change
	// Pass in false to override the check for queued bunches. Otherwise, if the owning channel has queued bunches,
	// the RepNotifies will remain in the list and the check for 0 RepNotifies above will fail next time.
	CallRepNotifies(false);

	if ( bSomeObjectsWereMapped )
	{
		// If we mapped some objects, make sure to call PostNetReceive (some game code will need to think this was actually replicated to work)
		PostNetReceive();
	}
}
示例#8
0
	cCustomBinaryData::cDataAndPos*cCustomBinaryData::GetDataByID(int e_iID)
	{
		return GetObject(e_iID);
	}
void CameraProperties::SetFovAngle( Float pAngle)
{
    Cast<Camera>(GetObject())->SetFovAngle(pAngle);
    FirePropertyChanged(&mFovAngle);
}
示例#10
0
/*!
\brief This function is responsible for drawing player, foods, background playing field and shows all the text in the game.
As it prescribe management in our game.
For control of the game and drawing the background playing field meets the code.
 \code
 switch (message)
	{
	case WM_CREATE: 

		hBitmap = (HBITMAP)LoadImage(hInst, L"1.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
		break;

	case WM_KEYDOWN:
		switch (wParam)
		{
			//Repeat game
			case 'O':
				pause= !pause;
				break;
			case 'P':
				if(GameOver == 1)
				{
					GameOver=0;
					ship.health = 20;
					RECT r = {0,0,700,500};
					for (int i=0;i<ASTEROID_COUNT;i++)
					{
						asteroids[i] = CreateAsteroid(r);
					}
				}
				break;
			}

	case WM_MOUSEMOVE:
		
		//Passing the coordinates of the mouse cursor.
			xPos = GET_X_LPARAM(lParam);
			targetx=xPos;
			yPos = GET_Y_LPARAM(lParam);
			targety=yPos;
		break;
	
		InvalidateRect(hWnd,NULL,1);
		break;
\endcode
This part of the code responsible for drawing player and foods. Drawing in WinApi performed using brushes and pens. With feathers, we draw the contours of our
player and foods. With a brush paints we figure our color.
 \code
case WM_PAINT:

        hdc = BeginPaint(hWnd, &ps);

        RECT rect;
		BITMAP 			bitmap;
		HDC 			hdcMem;
		HGDIOBJ 		oldBitmap;
        GetClientRect(hWnd, &rect);
        width=rect.right;
        height=rect.bottom;

		backbuffDC = CreateCompatibleDC(hdc);

        backbuffer = CreateCompatibleBitmap( hdc, width, height);

        savedDC = SaveDC(backbuffDC);

		SelectObject( backbuffDC, backbuffer );

		// Draw HERE
		
		//clear window
		hBrush = CreateSolidBrush(RGB(255,0,255));
        FillRect(backbuffDC,&rect,hBrush);
        DeleteObject(hBrush);
		hdcMem = CreateCompatibleDC(hdc);//!
		oldBitmap = SelectObject(hdcMem, hBitmap);//!
		//draw background
		GetObject(hBitmap, sizeof(bitmap), &bitmap);//!
		BitBlt(backbuffDC, 0, 0, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, SRCCOPY);//!
		//draw ball
		//Rectangle(backbuffDC,0, 0, 785, 663);
		//draw asteroids

		//Drawing food
		
		for (int i=0;i<ASTEROID_COUNT;i++)
		{
			hPen = CreatePen(PS_SOLID, 1, RGB(asteroids[i].dY, asteroids[i].dX, asteroids[i].dX+40));
			hOldPen = (HPEN)SelectObject(backbuffDC, hPen);
			Ellipse(backbuffDC,asteroids[i].X-asteroids[i].r, asteroids[i].Y-asteroids[i].r,asteroids[i].X+asteroids[i].r,asteroids[i].Y+asteroids[i].r);
			SelectObject(backbuffDC, hOldPen);
			DeleteObject(hPen);
			hPen = CreatePen(PS_SOLID, asteroids[i].r, RGB(asteroids[i].dY, asteroids[i].dX, asteroids[i].dX+40));
			hOldPen = (HPEN)SelectObject(backbuffDC, hPen);
			Ellipse(backbuffDC, asteroids[i].X - (asteroids[i].r/1.9), asteroids[i].Y - (asteroids[i].r/1.9),asteroids[i].X + (asteroids[i].r/1.9), asteroids[i].Y + (asteroids[i].r/1.9));
			Ellipse(backbuffDC, asteroids[i].X - (asteroids[i].r/2.1), asteroids[i].Y - (asteroids[i].r/2.1),asteroids[i].X + (asteroids[i].r/2.1), asteroids[i].Y + (asteroids[i].r/2.1));
			SelectObject(backbuffDC, hOldPen);
			DeleteObject(hPen);
		}

		//Drawing collor player
		hPen = CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
		hOldPen = (HPEN)SelectObject(backbuffDC, hPen);
		Ellipse(backbuffDC,ship.X-ship.health,ship.Y-ship.health,ship.X+ship.health,ship.Y+ship.health);	

		SelectObject(backbuffDC, hOldPen);
		DeleteObject(hPen);
\endcode
This part of the code responsible for entering text on a screen. To enter text on the screen creates an array of characters. Using this array, we can create the text. If the number of characters exceeds the specified number of the program will display an error. The text displayed on the screen at a certain place and under certain conditions. The implementation is shown below
 \code

		WCHAR s[30];
		if(GameOver == 1){
		wsprintf(s, _T("Game over!")); //Conclusion inscriptions "Game over!"
		TextOut(backbuffDC, 350, 250, s, wcslen(s));
		wsprintf(s, _T("Replay enter P"));
		TextOut(backbuffDC, 350, 270, s, wcslen(s));
		wsprintf(s,_T("score %d"),ship.health-20);// The conclusion points during the end game
		TextOut(backbuffDC,350,300,s,wcslen(s));
		}
		else {wsprintf(s,_T("score %d"),ship.health-20);// The conclusion points during the game
		TextOut(backbuffDC,20,630,s,wcslen(s));}

		if(pause){
		wsprintf(s, _T("Pause")); //Conclusion inscriptions "pause"
		TextOut(backbuffDC, 350, 250, s, wcslen(s));
		}
		wsprintf(s,_T("ver 1.2.5"));//ver game
		TextOut(backbuffDC,700,630,s,wcslen(s));
		wsprintf(s,_T("Replay enter P"));
		TextOut(backbuffDC,20,30,s,wcslen(s));
		wsprintf(s,_T("Pause enter O"));
		TextOut(backbuffDC,20,50,s,wcslen(s));
		\endcode
*/
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    PAINTSTRUCT ps;
    HDC hdc;
	int savedDC;
	HDC backbuffDC;
	int width, height;

	HBITMAP backbuffer;
	HBRUSH hBrush;
   
	int xPos, yPos;

	HPEN hPen, hOldPen;

    switch (message)
    {
		///Paint background
	case WM_CREATE: 

		hBitmap = (HBITMAP)LoadImage(hInst, L"1.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
		break;

	case WM_KEYDOWN:
		switch (wParam)
		{
			
			case 'O':
				pause= !pause;
				break;
			///Repeat game
			case 'P':
				if(GameOver == 1)
				{
					GameOver=0;
					ship.health = 20;
					RECT r = {0,0,700,500};
					for (int i=0;i<ASTEROID_COUNT;i++)
					{
						asteroids[i] = CreateAsteroid(r);
					}
				}
				break;
			}

		///Passing the coordinates of the mouse cursor.
		case WM_MOUSEMOVE:
			xPos = GET_X_LPARAM(lParam);
			targetx=xPos;
			yPos = GET_Y_LPARAM(lParam);
			targety=yPos;
		break;
	
		InvalidateRect(hWnd,NULL,1);
		break;
    case WM_PAINT:
        hdc = BeginPaint(hWnd, &ps);

        RECT rect;
		BITMAP 			bitmap;
		HDC 			hdcMem;
		HGDIOBJ 		oldBitmap;
        GetClientRect(hWnd, &rect);
        width=rect.right;
        height=rect.bottom;

		backbuffDC = CreateCompatibleDC(hdc);

        backbuffer = CreateCompatibleBitmap( hdc, width, height);

        savedDC = SaveDC(backbuffDC);

		SelectObject( backbuffDC, backbuffer );

		///clear window
		hBrush = CreateSolidBrush(RGB(255,0,255));
        FillRect(backbuffDC,&rect,hBrush);
        DeleteObject(hBrush);
		hdcMem = CreateCompatibleDC(hdc);//!
		oldBitmap = SelectObject(hdcMem, hBitmap);//!
		///draw background
		GetObject(hBitmap, sizeof(bitmap), &bitmap);//!
		BitBlt(backbuffDC, 0, 0, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, SRCCOPY);//!
		///draw ball
		///Rectangle(backbuffDC,0, 0, 785, 663);
		///draw asteroids

		//Drawing food
		
		for (int i=0;i<ASTEROID_COUNT;i++)
		{
			hPen = CreatePen(PS_SOLID, 1, RGB(asteroids[i].dY, asteroids[i].dX, asteroids[i].dX+40));
			hOldPen = (HPEN)SelectObject(backbuffDC, hPen);
			Ellipse(backbuffDC,asteroids[i].X-asteroids[i].r, asteroids[i].Y-asteroids[i].r,asteroids[i].X+asteroids[i].r,asteroids[i].Y+asteroids[i].r);
			SelectObject(backbuffDC, hOldPen);
			DeleteObject(hPen);
			hPen = CreatePen(PS_SOLID, asteroids[i].r, RGB(asteroids[i].dY, asteroids[i].dX, asteroids[i].dX+40));
			hOldPen = (HPEN)SelectObject(backbuffDC, hPen);
			Ellipse(backbuffDC, asteroids[i].X - (asteroids[i].r/1.9), asteroids[i].Y - (asteroids[i].r/1.9),asteroids[i].X + (asteroids[i].r/1.9), asteroids[i].Y + (asteroids[i].r/1.9));
			Ellipse(backbuffDC, asteroids[i].X - (asteroids[i].r/2.1), asteroids[i].Y - (asteroids[i].r/2.1),asteroids[i].X + (asteroids[i].r/2.1), asteroids[i].Y + (asteroids[i].r/2.1));
			SelectObject(backbuffDC, hOldPen);
			DeleteObject(hPen);
		}

		///Drawing collor player
		hPen = CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
		hOldPen = (HPEN)SelectObject(backbuffDC, hPen);
		Ellipse(backbuffDC,ship.X-ship.health,ship.Y-ship.health,ship.X+ship.health,ship.Y+ship.health);	

		SelectObject(backbuffDC, hOldPen);
		DeleteObject(hPen);

		WCHAR s[30];
		if(GameOver == 1){
			///Conclusion inscriptions "Game over!"
		wsprintf(s, _T("Game over!")); 
		TextOut(backbuffDC, 350, 250, s, wcslen(s));
		wsprintf(s, _T("Replay enter P"));
		TextOut(backbuffDC, 350, 270, s, wcslen(s));
		/// The conclusion points during the end game
		wsprintf(s,_T("score %d"),ship.health-20);
		TextOut(backbuffDC,350,300,s,wcslen(s));
		}
		/// The conclusion points during the game
		else {wsprintf(s,_T("score %d"),ship.health-20);
		TextOut(backbuffDC,20,630,s,wcslen(s));}

		///Conclusion inscriptions "pause"
		if(pause){
		wsprintf(s, _T("Pause")); 
		TextOut(backbuffDC, 350, 250, s, wcslen(s));
		}
		wsprintf(s,_T("ver 1.2.5"));
		TextOut(backbuffDC,700,630,s,wcslen(s));
		wsprintf(s,_T("Replay enter P"));
		TextOut(backbuffDC,20,30,s,wcslen(s));
		wsprintf(s,_T("Pause enter O"));
		TextOut(backbuffDC,20,50,s,wcslen(s));
		

		/// End application-specific layout section.

		BitBlt(hdc,0,0,width,height,backbuffDC,0,0,SRCCOPY);
        RestoreDC(backbuffDC,savedDC);

        DeleteObject(backbuffer);
        DeleteDC(backbuffDC);
		SelectObject(hdcMem, oldBitmap);
		DeleteDC(hdcMem);

		/// End drawing
        EndPaint(hWnd, &ps);
        break;

	/// Post Uninstall window background
	case WM_ERASEBKGND:
		return 1;
		
	/// The message about the destruction of the window
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hWnd, message, wParam, lParam);
        break;
    }

    return 0;
}
示例#11
0
static INT_PTR serviceBmpFilterResizeBitmap(WPARAM wParam,LPARAM lParam)
{
	BITMAP bminfo;
	int width, height;
	int xOrig, yOrig, widthOrig, heightOrig;
	ResizeBitmap *info = (ResizeBitmap *) wParam;

	if (info == NULL || info->size != sizeof(ResizeBitmap)
		|| info->hBmp == NULL
		|| info->max_width < 0 || info->max_height < 0
		|| (info->fit & ~RESIZEBITMAP_FLAG_DONT_GROW) < RESIZEBITMAP_STRETCH
		|| (info->fit & ~RESIZEBITMAP_FLAG_DONT_GROW) > RESIZEBITMAP_MAKE_SQUARE)
		return 0;

	// Well, lets do it

	// Calc final size
	GetObject(info->hBmp, sizeof(bminfo), &bminfo);

	width = info->max_width == 0 ? bminfo.bmWidth : info->max_width;
	height = info->max_height == 0 ? bminfo.bmHeight : info->max_height;

	xOrig = 0;
	yOrig = 0;
	widthOrig = bminfo.bmWidth;
	heightOrig = bminfo.bmHeight;

	if (widthOrig == 0 || heightOrig == 0)
		return 0;

	switch(info->fit & ~RESIZEBITMAP_FLAG_DONT_GROW)
	{
		case RESIZEBITMAP_STRETCH:
		{
			// Do nothing
			break;
		}
		case RESIZEBITMAP_KEEP_PROPORTIONS:
		{
			if (height * widthOrig / heightOrig <= width)
			{
				if (info->fit & RESIZEBITMAP_FLAG_DONT_GROW)
					height = min(height, bminfo.bmHeight);
				width = height * widthOrig / heightOrig;
			}
			else
			{
				if (info->fit & RESIZEBITMAP_FLAG_DONT_GROW)
					width = min(width, bminfo.bmWidth);
				height = width * heightOrig / widthOrig;
			}

			break;
		}
		case RESIZEBITMAP_MAKE_SQUARE:
		{
			if (info->fit & RESIZEBITMAP_FLAG_DONT_GROW)
			{
				width = min(width, bminfo.bmWidth);
				height = min(height, bminfo.bmHeight);
			}

			width = height = min(width, height);
			// Do not break. Use crop calcs to make size
		}
		case RESIZEBITMAP_CROP:
		{
			if (heightOrig * width / height >= widthOrig)
			{
				heightOrig = widthOrig * height / width;
				yOrig = (bminfo.bmHeight - heightOrig) / 2;
			}
			else
			{
				widthOrig = heightOrig * width / height;
				xOrig = (bminfo.bmWidth - widthOrig) / 2;
			}

			break;
		}
	}

	if ((width == bminfo.bmWidth && height == bminfo.bmHeight)
		|| ((info->fit & RESIZEBITMAP_FLAG_DONT_GROW)
			&& !(info->fit & RESIZEBITMAP_MAKE_SQUARE)
			&& width > bminfo.bmWidth && height > bminfo.bmHeight))
	{
		// Do nothing
		return (INT_PTR)info->hBmp;
	}
	else
	{
		FIBITMAP *dib = FreeImage_CreateDIBFromHBITMAP(info->hBmp);
		if (dib == NULL)
			return NULL;

		FIBITMAP *dib_tmp;
		if (xOrig > 0 || yOrig > 0)
			dib_tmp = FreeImage_Copy(dib, xOrig, yOrig, xOrig + widthOrig, yOrig + heightOrig);
		else
			dib_tmp = dib;

		if (dib_tmp == NULL)
		{
			FreeImage_Unload(dib);
			return NULL;
		}

		FIBITMAP *dib_new = FreeImage_Rescale(dib_tmp, width, height, FILTER_CATMULLROM);

		HBITMAP bitmap_new = FreeImage_CreateHBITMAPFromDIB(dib_new);

		if (dib_new != dib_tmp)
			FreeImage_Unload(dib_new);
		if (dib_tmp != dib)
			FreeImage_Unload(dib_tmp);
        FreeImage_Unload(dib);

		return (INT_PTR)bitmap_new;
	}
}
示例#12
0
文件: InfoPanel.cpp 项目: acml/cvsnt
void CInfoPanel::LoaderThread()
{
	m_news.clear();
	CHttpSocket sock;
	cvs::string xml;
	CXmlTree tree;
	size_t len;

	if(!sock.create("http://march-hare.com"))
	{
		xml="<?xml version=\"1.0\" encoding=\"windows-1252\"?>\n<messages>\n<message><subject>Need assistance?  Click here for our professional support options!</subject><author>&quot;March Hare Support&quot; &lt;[email protected]&gt;</author><url>http://store.march-hare.com/s.nl?sc=2&amp;category=2</url></message>\n</messages>";
		len=xml.length();
	}
	else if(!sock.request("GET","/cvspro/prods-pre.asp?register=advert"))
	{
		xml="<?xml version=\"1.0\" encoding=\"windows-1252\"?>\n<messages>\n<message><subject>Need help NOW?  Click here for our professional support options!</subject><author>&quot;March Hare Support&quot; &lt;[email protected]&gt;</author><url>http://store.march-hare.com/s.nl?sc=2&amp;category=2</url></message>\n</messages>";
		len=xml.length();
	}
	if(sock.responseCode()!=200)
	{
		xml="<?xml version=\"1.0\" encoding=\"windows-1252\"?>\n<messages>\n<message><subject>Need help? Need integration?  Need training?  Click here for our professional support options!</subject><author>&quot;March Hare Support&quot; &lt;[email protected]&gt;</author><url>http://store.march-hare.com/s.nl?sc=2&amp;category=2</url></message>\n</messages>";
		len=xml.length();
	}
	else
	{
		cvs::string xml = sock.responseData(len);
	}
	if(!tree.ParseXmlFromMemory(xml.c_str()))
		return;
	CXmlNodePtr node = tree.GetRoot();
	if(strcmp(node->GetName(),"messages"))
		return;
	if(!node->GetChild("message"))
		return;

	do
	{
		news_t n;
		n.subject = node->GetNodeValue("subject");
		n.author = node->GetNodeValue("author");
		n.url = node->GetNodeValue("url");
		m_news.push_back(n);
	} while(node->GetSibling("message"));

	if(!m_hItemFont)
	{
		HFONT hFont = (HFONT)SendMessage(m_hListWnd,WM_GETFONT,0,0);
		if(!hFont) hFont=GetStockFont(DEFAULT_GUI_FONT);

		LOGFONT lf = {0};
		GetObject(hFont,sizeof(lf),&lf);
		lf.lfUnderline=true;
		m_hItemFont = CreateFontIndirect(&lf);
	}

	ListView_DeleteAllItems(m_hListWnd);
	ListView_DeleteColumn(m_hListWnd,1);
	LVCOLUMN lvc={0};
	lvc.mask=LVCF_WIDTH|LVCF_TEXT;
	lvc.cx=500;
	lvc.pszText=_T("Title");
	ListView_InsertColumn(m_hListWnd,0,&lvc);
	lvc.mask=LVCF_WIDTH|LVCF_TEXT;
	lvc.cx=300;
	lvc.pszText=_T("Author");
	ListView_InsertColumn(m_hListWnd,1,&lvc);

	for(size_t n=0; n<m_news.size(); n++)
	{
		LVITEM lvi = {0};
		cvs::wide wnews(m_news[n].subject.c_str());
		cvs::wide wauth(m_news[n].author.c_str());
		lvi.mask=LVIF_TEXT|LVIF_PARAM;
		lvi.iItem=(int)n;
		lvi.pszText=(LPWSTR)(const wchar_t*)wnews;
		lvi.lParam=(LPARAM)&m_news[n];
		int iItem = ListView_InsertItem(m_hListWnd,&lvi);
		ListView_SetItemText(m_hListWnd,iItem,1,(LPWSTR)(const wchar_t*)wauth);
	}
	m_bLoaded = true;
}
/**
 * Splash screen thread entry function
 */
uint32 WINAPI StartSplashScreenThread( LPVOID unused )
{
	WNDCLASS wc;
	wc.style       = CS_HREDRAW | CS_VREDRAW; 
	wc.lpfnWndProc = (WNDPROC) SplashScreenWindowProc; 
	wc.cbClsExtra  = 0; 
	wc.cbWndExtra  = 0; 
	wc.hInstance   = hInstance; 

	wc.hIcon       = LoadIcon(hInstance, MAKEINTRESOURCE(FWindowsPlatformMisc::GetAppIcon()));
	if(wc.hIcon == NULL)
	{
		wc.hIcon   = LoadIcon((HINSTANCE) NULL, IDI_APPLICATION); 
	}

	wc.hCursor     = LoadCursor((HINSTANCE) NULL, IDC_ARROW); 
	wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
	wc.lpszMenuName  = NULL;
	wc.lpszClassName = TEXT("SplashScreenClass"); 
 
	if(!RegisterClass(&wc)) 
	{
		return 0; 
	} 

	// Load splash screen image, display it and handle all window's messages
	GSplashScreenBitmap = (HBITMAP) LoadImage(hInstance, (LPCTSTR)*GSplashScreenFileName, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
	if(GSplashScreenBitmap)
	{
		BITMAP bm;
		GetObject(GSplashScreenBitmap, sizeof(bm), &bm);

		const int32 BorderWidth = GetSystemMetrics(SM_CXBORDER);
		const int32 BorderHeight = GetSystemMetrics(SM_CYBORDER);
		const int32 WindowWidth = bm.bmWidth + BorderWidth;
		const int32 WindowHeight = bm.bmHeight + BorderHeight;
		int32 ScreenPosX = (GetSystemMetrics(SM_CXSCREEN) - WindowWidth) / 2;
		int32 ScreenPosY = (GetSystemMetrics(SM_CYSCREEN) - WindowHeight) / 2;

		const bool bAllowFading = true;

		// Force the editor splash screen to show up in the taskbar and alt-tab lists
		uint32 dwWindowStyle = (GIsEditor ? WS_EX_APPWINDOW : 0) | WS_EX_TOOLWINDOW;
		if( bAllowFading )
		{
			dwWindowStyle |= WS_EX_LAYERED;
		}

		GSplashScreenWnd = CreateWindowEx(
			dwWindowStyle,
			wc.lpszClassName, 
			TEXT("SplashScreen"),
			WS_BORDER|WS_POPUP,
			ScreenPosX,
			ScreenPosY,
			WindowWidth,
			WindowHeight,
			(HWND) NULL,
			(HMENU) NULL,
			hInstance,
			(LPVOID) NULL); 

		if( bAllowFading )
		{
			// Set window to fully transparent to start out
			SetLayeredWindowAttributes( GSplashScreenWnd, 0, 0, LWA_ALPHA );
		}


		// Setup font
		{
			HFONT SystemFontHandle = ( HFONT )GetStockObject( DEFAULT_GUI_FONT );

			// Create small font
			{
				LOGFONT MyFont;
				FMemory::Memzero( &MyFont, sizeof( MyFont ) );
				GetObject( SystemFontHandle, sizeof( MyFont ), &MyFont );
				MyFont.lfHeight = 10;
				// MyFont.lfQuality = ANTIALIASED_QUALITY;
				GSplashScreenSmallTextFontHandle = CreateFontIndirect( &MyFont );
				if( GSplashScreenSmallTextFontHandle == NULL )
				{
					// Couldn't create font, so just use a system font
					GSplashScreenSmallTextFontHandle = SystemFontHandle;
				}
			}

			// Create normal font
			{
				LOGFONT MyFont;
				FMemory::Memzero( &MyFont, sizeof( MyFont ) );
				GetObject( SystemFontHandle, sizeof( MyFont ), &MyFont );
				MyFont.lfHeight = 12;
				// MyFont.lfQuality = ANTIALIASED_QUALITY;
				GSplashScreenNormalTextFontHandle = CreateFontIndirect( &MyFont );
				if( GSplashScreenNormalTextFontHandle == NULL )
				{
					// Couldn't create font, so just use a system font
					GSplashScreenNormalTextFontHandle = SystemFontHandle;
				}
			}
		}
		
		// Setup bounds for version info text 1
		GSplashScreenTextRects[ SplashTextType::VersionInfo1 ].top = bm.bmHeight - 60;
		GSplashScreenTextRects[ SplashTextType::VersionInfo1 ].bottom = bm.bmHeight - 40;
		GSplashScreenTextRects[ SplashTextType::VersionInfo1 ].left = 10;
		GSplashScreenTextRects[ SplashTextType::VersionInfo1 ].right = bm.bmWidth - 20;

		// Setup bounds for copyright info text
		if( GIsEditor )
		{
			GSplashScreenTextRects[ SplashTextType::CopyrightInfo ].top = bm.bmHeight - 44;
			GSplashScreenTextRects[ SplashTextType::CopyrightInfo ].bottom = bm.bmHeight - 34;
		}
		else
		{
			GSplashScreenTextRects[ SplashTextType::CopyrightInfo ].top = bm.bmHeight - 16;
			GSplashScreenTextRects[ SplashTextType::CopyrightInfo ].bottom = bm.bmHeight - 6;
		}
		GSplashScreenTextRects[ SplashTextType::CopyrightInfo ].left = 10;
		GSplashScreenTextRects[ SplashTextType::CopyrightInfo ].right = bm.bmWidth - 20;

		// Setup bounds for startup progress text
		GSplashScreenTextRects[ SplashTextType::StartupProgress ].top = bm.bmHeight - 20;
		GSplashScreenTextRects[ SplashTextType::StartupProgress ].bottom = bm.bmHeight;
		GSplashScreenTextRects[ SplashTextType::StartupProgress ].left = 10;
		GSplashScreenTextRects[ SplashTextType::StartupProgress ].right = bm.bmWidth - 20;

		if (GSplashScreenWnd)
		{
			SetWindowText(GSplashScreenWnd, *GSplashScreenAppName.ToString());
			ShowWindow(GSplashScreenWnd, SW_SHOW); 
			UpdateWindow(GSplashScreenWnd); 
		 
			const double FadeStartTime = FPlatformTime::Seconds();
			const float FadeDuration = 0.2f;
			int32 CurrentOpacityByte = 0;

			MSG message;
			bool bIsSplashFinished = false;
			while( !bIsSplashFinished )
			{
				if( PeekMessage(&message, NULL, 0, 0, PM_REMOVE) )
				{
					TranslateMessage(&message);
					DispatchMessage(&message);

					if( message.message == WM_QUIT )
					{
						bIsSplashFinished = true;
					}
				}

				// Update window opacity
				if( bAllowFading && CurrentOpacityByte < 255 )
				{
					// Set window to fully transparent to start out
					const float TimeSinceFadeStart = (float)( FPlatformTime::Seconds() - FadeStartTime );
					const float FadeAmount = FMath::Clamp( TimeSinceFadeStart / FadeDuration, 0.0f, 1.0f );
					const int32 NewOpacityByte = 255 * FadeAmount;
					if( NewOpacityByte != CurrentOpacityByte )
					{
						CurrentOpacityByte = NewOpacityByte;
						SetLayeredWindowAttributes( GSplashScreenWnd, 0, CurrentOpacityByte, LWA_ALPHA );
					}

					// We're still fading, but still yield a timeslice
					FPlatformProcess::Sleep( 0.0f );
				}
				else
				{
					// Give up some time
					FPlatformProcess::Sleep( 1.0f / 60.0f );
				}
			}
		}

		DeleteObject(GSplashScreenBitmap);
		GSplashScreenBitmap = NULL;
	}

	UnregisterClass(wc.lpszClassName, hInstance);
	return 0; 
}
		  LRESULT CALLBACK WindowProc(HWND _hwnd,
		  UINT _msg,
		  WPARAM _wparam,
		  LPARAM _lparam)
{
	// This is the main message handler of the system.
	PAINTSTRUCT ps; // Used in WM_PAINT.
	HDC hdc; // Handle to a device context.
	// What is the message?
	switch (_msg)
	{
	case WM_CREATE:
	{
		_iNumThreads = std::thread::hardware_concurrency();				
		// Do initialization stuff here.
		// Return Success.
		return (0);
	}
		break;
	case WM_PAINT:
	{
		// Simply validate the window.
		hdc = BeginPaint(_hwnd, &ps);
		if (!bitmapsToDraw.empty())
		{
			//Starting coordinates
			int x = 0;
			int y = 0;
			
			//Used to nicely arrange the images
			int _iNum = int(ceil(sqrt(bitmapsToDraw.size())));
			int _iWidth = (1000 / _iNum);
			int _iHeight = _iWidth;

			//Drawing the images
			for (unsigned int i = 0; i < bitmapsToDraw.size(); i++)
			{
				BITMAP bitmap;
				GetObject(bitmapsToDraw[i], sizeof(BITMAP), &bitmap);
				HDC hdcMem = CreateCompatibleDC(hdc);
				HBITMAP oldBitmap = static_cast<HBITMAP>(SelectObject(hdcMem, bitmapsToDraw[i]));
				SetStretchBltMode(hdc, _iStretchColor);
				StretchBlt(hdc, x, y, _iWidth, _iHeight, hdcMem, 0, 0, bitmap.bmWidth, bitmap.bmHeight, SRCCOPY);
				SelectObject(hdcMem, oldBitmap);
				DeleteDC(hdcMem);
				x += _iWidth;
				//Adding new row
				if (x >= 1000)
				{
					y += _iWidth;
					x = 0;
				}
			}
		}	
		EndPaint(_hwnd, &ps);
		// Return Success.
		return (0);
	}
		break;
	case WM_COMMAND:
	{
		switch (LOWORD(_wparam))
		{
		case ID_FILE_LOADIMAGES:
		{
			LoadBitmaps();
			InvalidateRect(_hwnd, NULL, TRUE);
			break;
		}
		case ID_FILE_LOADSOUNDS:
		{
			LoadSounds();
			break;
		}
		case ID_COLORTYPE_HALFTONE:
		{
			_iStretchColor = HALFTONE;
			InvalidateRect(_hwnd, NULL, TRUE);
			break;
		}
		case ID_COLORTYPE_BLACKONWHITE:
		{
			_iStretchColor = BLACKONWHITE;
			InvalidateRect(_hwnd, NULL, TRUE);
			break;
		}
		case ID_COLORTYPE_COLORONCOLOR:
		{
			_iStretchColor = COLORONCOLOR;
			InvalidateRect(_hwnd, NULL, TRUE);
			break;
		}
		case ID_COLORTYPE_WHITEONBLACK:
		{
			_iStretchColor = STRETCH_ORSCANS;
			InvalidateRect(_hwnd, NULL, TRUE);
			break;
		}
		case ID_EXIT:
		{
			//Deleting bitmaps upon exiting
			for (unsigned int i = 0; i < bitmapsToDraw.size(); i++)
			{
				DeleteObject(bitmapsToDraw[i]);
			}
			PostQuitMessage(0);
			// Return success.
			return (0);
			break;
		}

		default:
			break;
		}
		return(0);
	
	}
	
		
	case WM_DESTROY:
	{	//Delete all bitmaps here
		// Kill the application, this sends a WM_QUIT message.
		for (unsigned int i = 0; i < bitmapsToDraw.size(); i++)
		{
			DeleteObject(bitmapsToDraw[i]);
		}
		
		PostQuitMessage(0);
		// Return success.
		return (0);
	}
		break;
	default:break;
	} // End switch.
	// Process any messages that we did not take care of...
	return (DefWindowProc(_hwnd, _msg, _wparam, _lparam));
}
void CameraProperties::PanUpDown(Float pMovement)
{
	Cast<Camera>(GetObject())->PanUpDown(pMovement);
    FirePropertyChanged(&mPosition);
}
Float CameraProperties::GetFovAngle() const
{
    return Cast<Camera>(GetObject())->GetFovAngle();
}
示例#17
0
文件: bitmap.cpp 项目: jakwuh/bsu
PBITMAPINFO CreateBitmapInfoStruct(HWND hwnd, HBITMAP hBmp)
{
	BITMAP bmp;
	PBITMAPINFO pbmi;
	WORD    cClrBits;

	// Retrieve the bitmap color format, width, and height.  
	if (!GetObject(hBmp, sizeof(BITMAP), (LPSTR)&bmp))
		errhandler("GetObject", hwnd);

	// Convert the color format to a count of bits.  
	cClrBits = (WORD)(bmp.bmPlanes * bmp.bmBitsPixel);
	if (cClrBits == 1)
		cClrBits = 1;
	else if (cClrBits <= 4)
		cClrBits = 4;
	else if (cClrBits <= 8)
		cClrBits = 8;
	else if (cClrBits <= 16)
		cClrBits = 16;
	else if (cClrBits <= 24)
		cClrBits = 24;
	else cClrBits = 32;

	// Allocate memory for the BITMAPINFO structure. (This structure  
	// contains a BITMAPINFOHEADER structure and an array of RGBQUAD  
	// data structures.)  

	if (cClrBits < 24)
		pbmi = (PBITMAPINFO)LocalAlloc(LPTR,
		sizeof(BITMAPINFOHEADER) +
		sizeof(RGBQUAD) * (1 << cClrBits));

	// There is no RGBQUAD array for these formats: 24-bit-per-pixel or 32-bit-per-pixel 

	else
		pbmi = (PBITMAPINFO)LocalAlloc(LPTR, sizeof(BITMAPINFOHEADER));

	// Initialize the fields in the BITMAPINFO structure.  

	pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
	pbmi->bmiHeader.biWidth = bmp.bmWidth;
	pbmi->bmiHeader.biHeight = bmp.bmHeight;
	pbmi->bmiHeader.biPlanes = bmp.bmPlanes;
	pbmi->bmiHeader.biBitCount = bmp.bmBitsPixel;
	if (cClrBits < 24)
		pbmi->bmiHeader.biClrUsed = (1 << cClrBits);

	// If the bitmap is not compressed, set the BI_RGB flag.  
	pbmi->bmiHeader.biCompression = BI_RGB;

	// Compute the number of bytes in the array of color  
	// indices and store the result in biSizeImage.  
	// The width must be DWORD aligned unless the bitmap is RLE 
	// compressed. 
	pbmi->bmiHeader.biSizeImage = ((pbmi->bmiHeader.biWidth * cClrBits + 31) & ~31) / 8
		* pbmi->bmiHeader.biHeight;
	// Set biClrImportant to 0, indicating that all of the  
	// device colors are important.  
	pbmi->bmiHeader.biClrImportant = 0;
	return pbmi;
}
void CameraProperties::SetNearView(Float pNearView)
{
	Cast<Camera>(GetObject())->SetNearView(pNearView);
    FirePropertyChanged(&mNearView);
}
示例#19
0
void FObjectReplicator::CallRepNotifies(bool bSkipIfChannelHasQueuedBunches)
{
	UObject* Object = GetObject();

	if ( Object == NULL || Object->IsPendingKill() )
	{
		return;
	}

	if ( Connection != NULL && Connection->Driver != NULL && Connection->Driver->ShouldSkipRepNotifies() )
	{
		return;
	}

	if ( bSkipIfChannelHasQueuedBunches && ( OwningChannel != NULL && OwningChannel->QueuedBunches.Num() > 0 ) )
	{
		return;
	}

	RepLayout->CallRepNotifies( RepState, Object );

	if ( RepNotifies.Num() > 0 )
	{
		for (int32 RepNotifyIdx = 0; RepNotifyIdx < RepNotifies.Num(); RepNotifyIdx++)
		{
			//UE_LOG(LogRep, Log,  TEXT("Calling Object->%s with %s"), *RepNotifies(RepNotifyIdx)->RepNotifyFunc.ToString(), *RepNotifies(RepNotifyIdx)->GetName()); 						
			UProperty* RepProperty = RepNotifies[RepNotifyIdx];
			UFunction* RepNotifyFunc = Object->FindFunctionChecked(RepProperty->RepNotifyFunc);

			if (RepNotifyFunc->NumParms == 0)
			{
				Object->ProcessEvent(RepNotifyFunc, NULL);
			}
			else if (RepNotifyFunc->NumParms == 1)
			{
				Object->ProcessEvent(RepNotifyFunc, RepProperty->ContainerPtrToValuePtr<uint8>(RepState->StaticBuffer.GetData()) );
			}
			else if (RepNotifyFunc->NumParms == 2)
			{
				// Fixme: this isn't as safe as it could be. Right now we have two types of parameters: MetaData (a TArray<uint8>)
				// and the last local value (pointer into the Recent[] array).
				//
				// Arrays always expect MetaData. Everything else, including structs, expect last value.
				// This is enforced with UHT only. If a ::NetSerialize function ever starts producing a MetaData array thats not in UArrayProperty,
				// we have no static way of catching this and the replication system could pass the wrong thing into ProcessEvent here.
				//
				// But this is all sort of an edge case feature anyways, so its not worth tearing things up too much over.

				FMemMark Mark(FMemStack::Get());
				uint8* Parms = new(FMemStack::Get(),MEM_Zeroed,RepNotifyFunc->ParmsSize)uint8;

				TFieldIterator<UProperty> Itr(RepNotifyFunc);
				check(Itr);

				Itr->CopyCompleteValue( Itr->ContainerPtrToValuePtr<void>(Parms), RepProperty->ContainerPtrToValuePtr<uint8>(RepState->StaticBuffer.GetData()) );
				++Itr;
				check(Itr);

				TArray<uint8> *NotifyMetaData = RepNotifyMetaData.Find(RepNotifies[RepNotifyIdx]);
				check(NotifyMetaData);
				Itr->CopyCompleteValue( Itr->ContainerPtrToValuePtr<void>(Parms), NotifyMetaData );

				Object->ProcessEvent(RepNotifyFunc, Parms );

				Mark.Pop();
			}

			if (Object == NULL || Object->IsPendingKill())
			{
				// script event destroyed Object
				break;
			}
		}
	}

	RepNotifies.Reset();
	RepNotifyMetaData.Empty();
}
Float CameraProperties::GetNearView() const
{
	return Cast<Camera>(GetObject())->GetNearView();
}
示例#21
0
void FObjectReplicator::ReceivedNak( int32 NakPacketId )
{
	UObject* Object = GetObject();

	if ( Object == NULL )
	{
		UE_LOG(LogNet, Verbose, TEXT("ReceivedNak: Object == NULL"));
		return;
	}

	if ( Object != NULL && ObjectClass != NULL )
	{
		RepLayout->ReceivedNak( RepState, NakPacketId );

		for ( int32 i = Retirement.Num() - 1; i >= 0; i-- )
		{
			ValidateRetirementHistory( Retirement[i] );

			// If this is a dynamic array property, we have to look through the list of retirement records to see if we need to reset the base state
			FPropertyRetirement * Rec = Retirement[i].Next; // Retirement[i] is head and not actually used in this case
			while ( Rec != NULL )
			{
				if ( NakPacketId > Rec->OutPacketIdRange.Last )
				{
					// We can assume this means this record's packet was ack'd, so we can get rid of the old state
					check( Retirement[i].Next == Rec );
					Retirement[i].Next = Rec->Next;
					delete Rec;
					Rec = Retirement[i].Next;
					continue;
				}
				else if ( NakPacketId >= Rec->OutPacketIdRange.First && NakPacketId <= Rec->OutPacketIdRange.Last )
				{
					UE_LOG(LogNet, Verbose, TEXT("Restoring Previous Base State of dynamic property Channel %d. NakId: %d  (%d -%d)"), OwningChannel->ChIndex, NakPacketId, Rec->OutPacketIdRange.First, Rec->OutPacketIdRange.Last);

					// The Nack'd packet did update this property, so we need to replace the buffer in RecentDynamic
					// with the buffer we used to create this update (which was dropped), so that the update will be recreated on the next replicate actor
					if ( Rec->DynamicState.IsValid() )
					{
						TSharedPtr<INetDeltaBaseState> & RecentState = RecentCustomDeltaState.FindChecked( i );
						
						RecentState.Reset();
						RecentState = Rec->DynamicState;
					}

					// We can get rid of the rest of the saved off base states since we will be regenerating these updates on the next replicate actor
					while ( Rec != NULL )
					{
						FPropertyRetirement * DeleteNext = Rec->Next;
						delete Rec;
						Rec = DeleteNext;
					}

					// Finished
					Retirement[i].Next = NULL;
					break;				
				}
				Rec = Rec->Next;
			}
				
			ValidateRetirementHistory( Retirement[i] );
		}
	}
}
void CameraProperties::LookAt( const Vector3f& pLookAtPos )
{
    Cast<Camera>(GetObject())->LookAt( pLookAtPos );
}
示例#23
0
bool FObjectReplicator::ReceivedBunch( FInBunch& Bunch, const FReplicationFlags& RepFlags, bool& bOutHasUnmapped )
{
	UObject* Object = GetObject();

	if ( Object == NULL )
	{
		UE_LOG(LogNet, Verbose, TEXT("ReceivedBunch: Object == NULL"));
		return false;
	}

	UPackageMap * PackageMap = OwningChannel->Connection->PackageMap;

	const bool bIsServer = ( OwningChannel->Connection->Driver->ServerConnection == NULL );

	const FClassNetCache * ClassCache = OwningChannel->Connection->Driver->NetCache->GetClassNetCache( ObjectClass );

	if ( ClassCache == NULL )
	{
		UE_LOG(LogNet, Error, TEXT("ReceivedBunch: ClassCache == NULL: %s"), *Object->GetFullName());
		return false;
	}

	bool bThisBunchReplicatedProperties = false;

	// Read first field
	const FFieldNetCache * FieldCache = ReadField( ClassCache, Bunch );

	if ( Bunch.IsError() )
	{
		UE_LOG(LogNet, Error, TEXT("ReceivedBunch: Error reading field 1: %s"), *Object->GetFullName());
		return false;
	}

	if ( FieldCache == NULL )
	{
		// There are no actual replicated properties or functions in this bunch. That is ok - we may have gotten this
		// actor/sub-object because we want the client to spawn one (but we aren't actually replicating properties on it)
		return true;
	}

	while ( FieldCache )
	{
		// Receive properties from the net.
		UProperty* ReplicatedProp = NULL;

		while ( FieldCache && ( ReplicatedProp = Cast< UProperty >( FieldCache->Field ) ) != NULL )
		{
			NET_CHECKSUM( Bunch );

			// Server shouldn't receive properties.
			if ( bIsServer )
			{
				UE_LOG(LogNet, Error, TEXT("Server received unwanted property value %s in %s"), *ReplicatedProp->GetName(), *Object->GetFullName());
				return false;
			}
		
			bThisBunchReplicatedProperties = true;

			if ( !bHasReplicatedProperties )
			{
				bHasReplicatedProperties = true;		// Persistent, not reset until PostNetReceive is called
				PreNetReceive();
			}

			bool DebugProperty = false;
#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
			{
				static IConsoleVariable* CVar = IConsoleManager::Get().FindConsoleVariable(TEXT("net.Replication.DebugProperty"));
				if (CVar && !CVar->GetString().IsEmpty() && ReplicatedProp->GetName().Contains(CVar->GetString()) )
				{
					UE_LOG(LogRep, Log, TEXT("Replicating Property[%d] %s on %s"), ReplicatedProp->RepIndex, *ReplicatedProp->GetName(), *Object->GetName());
					DebugProperty = true;
				}
			}
#endif
			if ( !Retirement[ ReplicatedProp->RepIndex ].CustomDelta )
			{
				bool bLocalHasUnmapped = false;
				// We hijack a non custom delta property to signify we are using FRepLayout to read the entire property block
				if ( !RepLayout->ReceiveProperties( ObjectClass, RepState, (void*)Object, Bunch, bLocalHasUnmapped ) )
				{
					UE_LOG(LogRep, Error, TEXT("ReceiveProperties FAILED %s in %s"), *ReplicatedProp->GetName(), *Object->GetFullName());
					return false;
				}

				if ( bLocalHasUnmapped )
				{
					bOutHasUnmapped = true;
				}
			}
			else
			{
				// Receive array index.
				uint32 Element = 0;
				if ( ReplicatedProp->ArrayDim != 1 )
				{
					check( ReplicatedProp->ArrayDim >= 2 );

					Bunch.SerializeIntPacked( Element );

					if ( Element >= (uint32)ReplicatedProp->ArrayDim )
					{
						UE_LOG(LogRep, Error, TEXT("Element index too large %s in %s"), *ReplicatedProp->GetName(), *Object->GetFullName());
						return false;
					}
				}

				// Pointer to destination.
				uint8* Data = ReplicatedProp->ContainerPtrToValuePtr<uint8>((uint8*)Object, Element);
				TArray<uint8>	MetaData;
				const PTRINT DataOffset = Data - (uint8*)Object;

				// Receive custom delta property.
				UStructProperty * StructProperty = Cast< UStructProperty >( ReplicatedProp );

				if ( StructProperty == NULL )
				{
					// This property isn't custom delta
					UE_LOG(LogRepTraffic, Error, TEXT("Property isn't custom delta %s"), *ReplicatedProp->GetName());
					return false;
				}

				UScriptStruct * InnerStruct = StructProperty->Struct;

				if ( !( InnerStruct->StructFlags & STRUCT_NetDeltaSerializeNative ) )
				{
					// This property isn't custom delta
					UE_LOG(LogRepTraffic, Error, TEXT("Property isn't custom delta %s"), *ReplicatedProp->GetName());
					return false;
				}

				UScriptStruct::ICppStructOps * CppStructOps = InnerStruct->GetCppStructOps();

				check( CppStructOps );
				check( !InnerStruct->InheritedCppStructOps() );

				FNetDeltaSerializeInfo Parms;

				FNetSerializeCB NetSerializeCB( OwningChannel->Connection->Driver );

				Parms.DebugName			= StructProperty->GetName();
				Parms.Struct			= InnerStruct;
				Parms.Map				= PackageMap;
				Parms.Reader			= &Bunch;
				Parms.NetSerializeCB	= &NetSerializeCB;

				// Call the custom delta serialize function to handle it
				CppStructOps->NetDeltaSerialize( Parms, Data );

				if ( Bunch.IsError() )
				{
					UE_LOG(LogNet, Error, TEXT("ReceivedBunch: NetDeltaSerialize - Bunch.IsError() == true: %s"), *Object->GetFullName());
					return false;
				}

				if ( Parms.bOutHasMoreUnmapped )
				{
					UnmappedCustomProperties.Add( DataOffset, StructProperty );
					bOutHasUnmapped = true;
				}

				// Successfully received it.
				UE_LOG(LogRepTraffic, Log, TEXT(" %s - %s"), *Object->GetName(), *ReplicatedProp->GetName());

				// Notify the Object if this var is RepNotify
				QueuePropertyRepNotify( Object, ReplicatedProp, Element, MetaData );
			}	
			
			// Read next field
			FieldCache = ReadField( ClassCache, Bunch );

			if ( Bunch.IsError() )
			{
				UE_LOG(LogNet, Error, TEXT("ReceivedBunch: Error reading field 2: %s"), *Object->GetFullName());
				return false;
			}
		}

		// Handle function calls.
		if ( FieldCache && Cast< UFunction >( FieldCache->Field ) )
		{
			FName Message = FieldCache->Field->GetFName();
			UFunction * Function = Object->FindFunction( Message );

			if ( Function == NULL )
			{
				UE_LOG(LogNet, Error, TEXT("ReceivedBunch: Function == NULL: %s"), *Object->GetFullName());
				return false;
			}

			if ( ( Function->FunctionFlags & FUNC_Net ) == 0 )
			{
				UE_LOG(LogRep, Error, TEXT("Rejected non RPC function %s in %s"), *Message.ToString(), *Object->GetFullName());
				return false;
			}

			if ( ( Function->FunctionFlags & ( bIsServer ? FUNC_NetServer : ( FUNC_NetClient | FUNC_NetMulticast ) ) ) == 0 )
			{
				UE_LOG(LogRep, Error, TEXT("Rejected RPC function due to access rights %s in %s"), *Message.ToString(), *Object->GetFullName());
				return false;
			}

			UE_LOG(LogRepTraffic, Log, TEXT("      Received RPC: %s"), *Message.ToString());

			// Get the parameters.
			FMemMark Mark(FMemStack::Get());
			uint8* Parms = new(FMemStack::Get(),MEM_Zeroed,Function->ParmsSize)uint8;

			// Use the replication layout to receive the rpc parameter values
			TSharedPtr<FRepLayout> FuncRepLayout = OwningChannel->Connection->Driver->GetFunctionRepLayout( Function );

			FuncRepLayout->ReceivePropertiesForRPC( Object, Function, OwningChannel, Bunch, Parms );

			if ( Bunch.IsError() )
			{
				UE_LOG(LogRep, Error, TEXT("ReceivedBunch: ReceivePropertiesForRPC - Bunch.IsError() == true: Function: %s, Object: %s"), *Message.ToString(), *Object->GetFullName());
				return false;
			}

			// validate that the function is callable here
			const bool bCanExecute = ( !bIsServer || RepFlags.bNetOwner );		// we are client or net owner

			if ( bCanExecute )
			{
				// Call the function.
				RPC_ResetLastFailedReason();

				Object->ProcessEvent( Function, Parms );

				if ( RPC_GetLastFailedReason() != NULL )
				{
					UE_LOG(LogRep, Error, TEXT("ReceivedBunch: RPC_GetLastFailedReason: %s"), RPC_GetLastFailedReason());
					return false;
				}
			}
			else
			{
				UE_LOG(LogRep, Verbose, TEXT("Rejected unwanted function %s in %s"), *Message.ToString(), *Object->GetFullName());

				if ( !OwningChannel->Connection->TrackLogsPerSecond() )	// This will disconnect the client if we get here too often
				{
					UE_LOG(LogRep, Error, TEXT("Rejected too many unwanted functions %s in %s"), *Message.ToString(), *Object->GetFullName());
					return false;
				}
			}

			// Destroy the parameters.
			//warning: highly dependent on UObject::ProcessEvent freeing of parms!
			for ( UProperty * Destruct=Function->DestructorLink; Destruct; Destruct=Destruct->DestructorLinkNext )
			{
				if( Destruct->IsInContainer(Function->ParmsSize) )
				{
					Destruct->DestroyValue_InContainer(Parms);
				}
			}

			Mark.Pop();

			if ( Object == NULL || Object->IsPendingKill() )
			{
				// replicated function destroyed Object
				return true;		// FIXME: Should this return false to kick connection?  Seems we'll cause a read misalignment here if we don't
			}

			// Next.
			FieldCache = ReadField( ClassCache, Bunch );

			if ( Bunch.IsError() )
			{
				UE_LOG(LogNet, Error, TEXT("ReceivedBunch: Error reading field 3: %s"), *Object->GetFullName());
				return false;
			}
		}
		else if ( FieldCache )
		{
			UE_LOG(LogRep, Error, TEXT("ReceivedBunch: Invalid replicated field %i in %s"), FieldCache->FieldNetIndex, *Object->GetFullName());
			return false;
		}
	}

	return true;
}
void CameraProperties::Pitch(Float pAngle)
{
	Cast<Camera>(GetObject())->Pitch(pAngle);
}
示例#25
0
/** Replicates properties to the Bunch. Returns true if it wrote anything */
bool FObjectReplicator::ReplicateProperties( FOutBunch & Bunch, FReplicationFlags RepFlags )
{
	UObject* Object = GetObject();

	if ( Object == NULL )
	{
		UE_LOG(LogRep, Verbose, TEXT("ReplicateProperties: Object == NULL"));
		return false;
	}

	check( Object );
	check( OwningChannel );
	check( RepLayout.IsValid() );
	check( RepState )
	check( RepState->StaticBuffer.Num() );

	UNetConnection* OwningChannelConnection = OwningChannel->Connection;

	const int32 StartingBitNum = Bunch.GetNumBits();

	bool bContentBlockWritten = false;

	// Replicate all the custom delta properties (fast arrays, etc)
	ReplicateCustomDeltaProperties( Bunch, RepFlags, bContentBlockWritten );

	// Replicate properties in the layout
	RepLayout->ReplicateProperties( RepState, (uint8*)Object, ObjectClass, OwningChannel, Bunch, RepFlags, bContentBlockWritten );

	// LastUpdateEmpty - this is done before dequeing the multicasted unreliable functions on purpose as they should not prevent
	// an actor channel from going dormant.
	bLastUpdateEmpty = ( Bunch.GetNumBits() == StartingBitNum );

	// Replicate Queued (unreliable functions)
	if ( RemoteFunctions != NULL && RemoteFunctions->GetNumBits() > 0 )
	{
		static const auto* CVar = IConsoleManager::Get().FindTConsoleVariableDataInt( TEXT( "net.RPC.Debug" ) );

		if ( CVar && CVar->GetValueOnGameThread() == 1 )
		{
			UE_LOG( LogRepTraffic, Warning,	TEXT("      Sending queued RPCs: %s. Channel[%d] [%.1f bytes]"), *Object->GetName(), OwningChannel->ChIndex, RemoteFunctions->GetNumBits() / 8.f );
		}

		if ( !bContentBlockWritten )
		{
			OwningChannel->BeginContentBlock( Object, Bunch );
			bContentBlockWritten = true;
		}

		Bunch.SerializeBits( RemoteFunctions->GetData(), RemoteFunctions->GetNumBits() );
		RemoteFunctions->Reset();
		RemoteFuncInfo.Empty();

		NETWORK_PROFILER(GNetworkProfiler.FlushQueuedRPCs(OwningChannelConnection, Object));
	}

	// See if we wrote something important (anything but the 'end' int below).
	// Note that queued unreliable functions are considered important (WroteImportantData) but not for bLastUpdateEmpty. LastUpdateEmpty
	// is used for dormancy purposes. WroteImportantData is for determining if we should not include a component in replication.
	const bool WroteImportantData = ( Bunch.GetNumBits() != StartingBitNum );

	if ( WroteImportantData )
	{
		OwningChannel->EndContentBlock( Object, Bunch, OwningChannelConnection->Driver->NetCache->GetClassNetCache( ObjectClass ) );
	}

	return WroteImportantData;
}
void CameraProperties::Yaw(Float pAngle)
{
    Cast<Camera>(GetObject())->Yaw(pAngle);
}
示例#27
0
INT_PTR CALLBACK ChangeInfoDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	ChangeInfoData* dat = (ChangeInfoData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);

	switch(msg) {
	case WM_INITDIALOG:
		TranslateDialogDefault(hwndDlg);

		dat = new ChangeInfoData();
		SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat);

		dat->hwndDlg = hwndDlg;
		dat->ppro = (CIcqProto*)lParam;
		dat->hwndList = GetDlgItem(hwndDlg, IDC_LIST);

		ListView_SetExtendedListViewStyle(dat->hwndList, LVS_EX_FULLROWSELECT);
		dat->iEditItem = -1;
		{
			HFONT hFont;
			LOGFONT lf;

			dat->hListFont = (HFONT)SendMessage(dat->hwndList, WM_GETFONT, 0, 0);
			GetObject(dat->hListFont, sizeof(lf), &lf);
			lf.lfHeight -= 5;
			hFont = CreateFontIndirect(&lf);
			SendMessage(dat->hwndList, WM_SETFONT, (WPARAM)hFont, 0);
		}
		{ // Prepare ListView Columns
			LV_COLUMN lvc = {0};
			RECT rc;

			GetClientRect(dat->hwndList, &rc);
			rc.right -= GetSystemMetrics(SM_CXVSCROLL);
			lvc.mask = LVCF_WIDTH;
			lvc.cx = rc.right / 3;
			ListView_InsertColumn(dat->hwndList, 0, &lvc);
			lvc.cx = rc.right - lvc.cx;
			ListView_InsertColumn(dat->hwndList, 1, &lvc);
		}
		{ // Prepare Setting Items
			LV_ITEM lvi = {0};
			lvi.mask = LVIF_PARAM | LVIF_TEXT;

			for (lvi.iItem = 0; lvi.iItem < settingCount; lvi.iItem++) 
			{
				TCHAR text[MAX_PATH];

				lvi.lParam = lvi.iItem;
				lvi.pszText = text;
				utf8_to_tchar_static(setting[lvi.iItem].szDescription, text, SIZEOF(text));
				ListView_InsertItem(dat->hwndList, &lvi);
			}
		}

		SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
		return TRUE;

	case WM_NOTIFY:
		switch (((LPNMHDR)lParam)->idFrom) {
		case 0:
			switch (((LPNMHDR)lParam)->code) {
			case PSN_PARAMCHANGED:
				dat->ppro = (CIcqProto*)((PSHNOTIFY*)lParam)->lParam;
				dat->LoadSettingsFromDb(0);
				{
					char *pwd = dat->ppro->GetUserPassword(TRUE);
					strcpy(dat->Password, (pwd) ? pwd : "" ); /// FIXME
				}
				break;

			case PSN_INFOCHANGED:
				dat->LoadSettingsFromDb(1);
				break;

			case PSN_KILLACTIVE:
				dat->EndStringEdit(1);
				dat->EndListEdit(1);
				break;

			case PSN_APPLY:
				if (dat->ChangesMade()) 
				{
					if (MessageBox(hwndDlg, TranslateT("You've made some changes to your ICQ details but it has not been saved to the server. Are you sure you want to close this dialog?"), TranslateT("Change ICQ Details"), MB_YESNOCANCEL) != IDYES)
					{
						SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE);
						return TRUE;
					}
				}
				break;
			}
			break;

		case IDC_LIST:
			switch (((LPNMHDR)lParam)->code) {
			case LVN_GETDISPINFO:
				if (dat->iEditItem != -1) 
				{
					if (dat->editTopIndex != ListView_GetTopIndex(dat->hwndList)) 
					{
						dat->EndStringEdit(1);
						dat->EndListEdit(1);
					}
				}
				break;

			case NM_CUSTOMDRAW:
				{
					LPNMLVCUSTOMDRAW cd=(LPNMLVCUSTOMDRAW)lParam;

					switch(cd->nmcd.dwDrawStage) {
					case CDDS_PREPAINT:
						SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, CDRF_NOTIFYITEMDRAW);
						return TRUE;

					case CDDS_ITEMPREPAINT:
						{
							RECT rcItem;

							if (dat->iEditItem != -1) 
							{
								if (dat->editTopIndex != ListView_GetTopIndex(dat->hwndList)) 
								{
									dat->EndStringEdit(1);
									dat->EndListEdit(1);
								}
							}

							ListView_GetItemRect(dat->hwndList, cd->nmcd.dwItemSpec, &rcItem, LVIR_BOUNDS);

							if (GetWindowLongPtr(dat->hwndList, GWL_STYLE) & WS_DISABLED)
							{  // Disabled List
								SetTextColor(cd->nmcd.hdc, cd->clrText);
								FillRect(cd->nmcd.hdc, &rcItem, GetSysColorBrush(COLOR_3DFACE));
							}
							else if ((cd->nmcd.uItemState & CDIS_SELECTED || dat->iEditItem == (int)cd->nmcd.dwItemSpec)
								&& setting[cd->nmcd.lItemlParam].displayType != LI_DIVIDER)
							{  // Selected item
								SetTextColor(cd->nmcd.hdc, GetSysColor(COLOR_HIGHLIGHTTEXT));
								FillRect(cd->nmcd.hdc, &rcItem, GetSysColorBrush(COLOR_HIGHLIGHT));
							}
							else
							{ // Unselected item
								SetTextColor(cd->nmcd.hdc, GetSysColor(COLOR_WINDOWTEXT));
								FillRect(cd->nmcd.hdc, &rcItem, GetSysColorBrush(COLOR_WINDOW));
							}

							HFONT hoFont = (HFONT)SelectObject(cd->nmcd.hdc, dat->hListFont);

							if (setting[cd->nmcd.lItemlParam].displayType == LI_DIVIDER)
							{
								RECT rcLine;
								SIZE textSize;
								char str[MAX_PATH];
								char *szText = ICQTranslateUtfStatic(setting[cd->nmcd.lItemlParam].szDescription, str, MAX_PATH);

								SetTextColor(cd->nmcd.hdc, GetSysColor(COLOR_3DSHADOW));
								DrawTextUtf(cd->nmcd.hdc, szText, &rcItem, DT_CENTER|DT_NOCLIP|DT_NOPREFIX|DT_SINGLELINE|DT_VCENTER, &textSize);
								rcLine.top = (rcItem.top + rcItem.bottom) / 2 - 1;
								rcLine.bottom = rcLine.top + 2;
								rcLine.left = rcItem.left + 3;
								rcLine.right = (rcItem.left + rcItem.right - textSize.cx) / 2 - 3;
								DrawEdge(cd->nmcd.hdc, &rcLine, BDR_SUNKENOUTER, BF_RECT);
								rcLine.left = (rcItem.left + rcItem.right + textSize.cx) / 2 + 3;
								rcLine.right = rcItem.right - 3;
								DrawEdge(cd->nmcd.hdc, &rcLine, BDR_SUNKENOUTER, BF_RECT);
							}
							else
							{
								RECT rcItemDescr, rcItemValue;
								char str[MAX_PATH];

								ListView_GetSubItemRect(dat->hwndList, cd->nmcd.dwItemSpec, 0, LVIR_BOUNDS, &rcItemDescr);
								ListView_GetSubItemRect(dat->hwndList, cd->nmcd.dwItemSpec, 1, LVIR_BOUNDS, &rcItemValue);

								rcItemDescr.right = rcItemValue.left;
								rcItemDescr.left += 2;
								DrawTextUtf(cd->nmcd.hdc, ICQTranslateUtfStatic(setting[cd->nmcd.lItemlParam].szDescription, str, MAX_PATH), &rcItemDescr, DT_END_ELLIPSIS|DT_LEFT|DT_NOCLIP|DT_NOPREFIX|DT_SINGLELINE|DT_VCENTER, NULL);

								dat->PaintItemSetting(cd->nmcd.hdc, &rcItemValue, cd->nmcd.lItemlParam, cd->nmcd.uItemState);
							}
							SelectObject(cd->nmcd.hdc, hoFont);

							SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, CDRF_SKIPDEFAULT);

							return TRUE;
						}
					}
					break;
				}
			case NM_CLICK:
				{  
					LPNMLISTVIEW nm=(LPNMLISTVIEW)lParam;
					LV_ITEM lvi;
					RECT rc;

					dat->EndStringEdit(1);
					dat->EndListEdit(1);
					if (nm->iSubItem != 1) break;
					lvi.mask = LVIF_PARAM|LVIF_STATE;
					lvi.stateMask = 0xFFFFFFFF;
					lvi.iItem = nm->iItem; lvi.iSubItem = nm->iSubItem;
					ListView_GetItem(dat->hwndList, &lvi);
					if (!(lvi.state & LVIS_SELECTED)) break;
					ListView_EnsureVisible(dat->hwndList, lvi.iItem, FALSE);
					ListView_GetSubItemRect(dat->hwndList, lvi.iItem, lvi.iSubItem, LVIR_BOUNDS, &rc);
					dat->editTopIndex = ListView_GetTopIndex(dat->hwndList);
					switch (setting[lvi.lParam].displayType & LIM_TYPE) {
					case LI_STRING:
					case LI_LONGSTRING:
					case LI_NUMBER:
						dat->BeginStringEdit(nm->iItem, &rc, lvi. lParam, 0);
						break;
					case LI_LIST:
						dat->BeginListEdit(nm->iItem, &rc, lvi. lParam, 0);
						break;
					}
					break;
				}
			case LVN_KEYDOWN:
				{  
					LPNMLVKEYDOWN nm=(LPNMLVKEYDOWN)lParam;
					LV_ITEM lvi;
					RECT rc;

					dat->EndStringEdit(1);
					dat->EndListEdit(1);
					if(nm->wVKey==VK_SPACE || nm->wVKey==VK_RETURN || nm->wVKey==VK_F2) nm->wVKey=0;
					if(nm->wVKey && (nm->wVKey<'0' || (nm->wVKey>'9' && nm->wVKey<'A') || (nm->wVKey>'Z' && nm->wVKey<VK_NUMPAD0) || nm->wVKey>=VK_F1))
						break;
					lvi.mask=LVIF_PARAM|LVIF_STATE;
					lvi.stateMask=0xFFFFFFFF;
					lvi.iItem = ListView_GetNextItem(dat->hwndList, -1, LVNI_ALL|LVNI_SELECTED);
					if (lvi.iItem==-1) break;
					lvi.iSubItem=1;
					ListView_GetItem(dat->hwndList,&lvi);
					ListView_EnsureVisible(dat->hwndList,lvi.iItem,FALSE);
					ListView_GetSubItemRect(dat->hwndList,lvi.iItem,lvi.iSubItem,LVIR_BOUNDS,&rc);
					dat->editTopIndex = ListView_GetTopIndex(dat->hwndList);
					switch(setting[lvi.lParam].displayType & LIM_TYPE) {
					case LI_STRING:
					case LI_LONGSTRING:
					case LI_NUMBER:
						dat->BeginStringEdit(lvi.iItem,&rc,lvi.lParam,nm->wVKey);
						break;
					case LI_LIST:
						dat->BeginListEdit(lvi.iItem,&rc,lvi.lParam,nm->wVKey);
						break;
					}
					SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, TRUE);
					return TRUE;
				}
			case NM_KILLFOCUS:
				if (!IsStringEditWindow(GetFocus())) dat->EndStringEdit(1);
				if (!IsListEditWindow(GetFocus())) dat->EndListEdit(1);
				break;
			}
			break;
		}
		break;
	case WM_KILLFOCUS:
		dat->EndStringEdit(1);
		dat->EndListEdit(1);
		break;
	case WM_COMMAND:
		switch(LOWORD(wParam)) {
		case IDCANCEL:
			SendMessage(GetParent(hwndDlg), msg, wParam, lParam);
			break;

		case IDC_SAVE:
			if (!dat->SaveSettingsToDb(hwndDlg))
				break;

			EnableDlgItem(hwndDlg, IDC_SAVE, FALSE);
			EnableDlgItem(hwndDlg, IDC_LIST, FALSE);
			SetDlgItemText(hwndDlg, IDC_UPLOADING, TranslateT("Upload in progress..."));
			EnableDlgItem(hwndDlg, IDC_UPLOADING, TRUE);
			ShowDlgItem(hwndDlg, IDC_UPLOADING, SW_SHOW);
			dat->hAckHook = HookEventMessage(ME_PROTO_ACK, hwndDlg, DM_PROTOACK);

			if (!dat->UploadSettings()) 
			{
				EnableDlgItem(hwndDlg, IDC_SAVE, TRUE);
				EnableDlgItem(hwndDlg, IDC_LIST, TRUE);
				ShowDlgItem(hwndDlg, IDC_UPLOADING, SW_HIDE);
				UnhookEvent(dat->hAckHook); 
				dat->hAckHook = NULL;
			}
			break;
		}
		break;

	case WM_SIZE:
		{ // make the dlg resizeable
			UTILRESIZEDIALOG urd = {0};

			if (IsIconic(hwndDlg)) break;
			urd.cbSize = sizeof(urd);
			urd.hInstance = hInst;
			urd.hwndDlg = hwndDlg;
			urd.lParam = 0; // user-defined
			urd.lpTemplate = MAKEINTRESOURCEA(IDD_INFO_CHANGEINFO);
			urd.pfnResizer = ChangeInfoDlg_Resize;
			CallService(MS_UTILS_RESIZEDIALOG, 0, (LPARAM) &urd);

			{ // update listview column widths
				RECT rc;

				GetClientRect(dat->hwndList, &rc);
				rc.right -= GetSystemMetrics(SM_CXVSCROLL);
				ListView_SetColumnWidth(dat->hwndList, 0, rc.right / 3);
				ListView_SetColumnWidth(dat->hwndList, 1, rc.right - rc.right / 3);
			}
			break;
		}

	case DM_PROTOACK:
		{
			ACKDATA *ack=(ACKDATA*)lParam;
			int i,done;

			if (ack->type != ACKTYPE_SETINFO) break;
			if (ack->result == ACKRESULT_SUCCESS)
			{
				for (i=0; i < SIZEOF(dat->hUpload); i++)
					if (dat->hUpload[i] && ack->hProcess == dat->hUpload[i]) break;

				if (i == SIZEOF(dat->hUpload)) break;
				dat->hUpload[i] = NULL;
				for (done = 0, i = 0; i < SIZEOF(dat->hUpload); i++)
					done += dat->hUpload[i] == NULL;
				TCHAR buf[MAX_PATH];
				mir_sntprintf(buf, sizeof(buf), TranslateT("Upload in progress...%d%%"), 100*done/(SIZEOF(dat->hUpload)));
				SetDlgItemText(hwndDlg, IDC_UPLOADING, buf);
				if (done < SIZEOF(dat->hUpload)) break;

				dat->ClearChangeFlags();
				UnhookEvent(dat->hAckHook); 
				dat->hAckHook = NULL;
				EnableDlgItem(hwndDlg, IDC_LIST, TRUE);
				EnableDlgItem(hwndDlg, IDC_UPLOADING, FALSE);
				SetDlgItemText(hwndDlg, IDC_UPLOADING, TranslateT("Upload complete"));
				SendMessage(GetParent(hwndDlg), PSM_FORCECHANGED, 0, 0);
			}
			else if (ack->result==ACKRESULT_FAILED)
			{
				UnhookEvent(dat->hAckHook); 
				dat->hAckHook = NULL;
				EnableDlgItem(hwndDlg, IDC_LIST, TRUE);
				EnableDlgItem(hwndDlg, IDC_UPLOADING, FALSE);
				SetDlgItemText(hwndDlg, IDC_UPLOADING, TranslateT("Upload FAILED"));
				SendMessage(GetParent(hwndDlg), PSM_FORCECHANGED, 0, 0);
				EnableDlgItem(hwndDlg, IDC_SAVE, TRUE);
			}
			break;
		}
	case WM_DESTROY:
		if (dat->hAckHook) 
		{
			UnhookEvent(dat->hAckHook);
			dat->hAckHook = NULL;
		}
		{
			HFONT hFont = (HFONT)SendMessage(dat->hwndList, WM_GETFONT, 0, 0);
			DeleteObject(hFont);
		}
		dat->FreeStoredDbSettings();
		SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 0);
		delete dat;
		break;
	}
	return FALSE;
}
void CameraProperties::Roll(Float pAngle)
{
    Cast<Camera>(GetObject())->Roll(pAngle);
}
示例#29
0
int CxSkinButton::GetBitmapHeight (HBITMAP hBitmap)
{ BITMAP bm; GetObject(hBitmap,sizeof(BITMAP),(PSTR)&bm); return bm.bmHeight;}
示例#30
0
void _DrawTransparentBitmap(HDC hdc, HBITMAP hBitmap, short xStart, short yStart, COLORREF cTransparentColor)
{
	BITMAP     bm;
	COLORREF   cColor;
	HBITMAP    bmAndBack, bmAndObject, bmAndMem, bmSave;
	HBITMAP    bmBackOld, bmObjectOld, bmMemOld, bmSaveOld;
	HDC        hdcMem, hdcBack, hdcObject, hdcTemp, hdcSave;
	POINT      ptSize;

	hdcTemp = CreateCompatibleDC(hdc);
	SelectObject(hdcTemp, hBitmap);   // Select the bitmap

	GetObject(hBitmap, sizeof(BITMAP), &bm);
	ptSize.x = bm.bmWidth;            // Get width of bitmap
	ptSize.y = bm.bmHeight;           // Get height of bitmap
	DPtoLP(hdcTemp, &ptSize, 1);      // Convert from device

	// to logical points

	// Create some DCs to hold temporary data.
	hdcBack   = CreateCompatibleDC(hdc);
	hdcObject = CreateCompatibleDC(hdc);
	hdcMem    = CreateCompatibleDC(hdc);
	hdcSave   = CreateCompatibleDC(hdc);

	// Create a bitmap for each DC. DCs are required for a number of
	// GDI functions.

	// Monochrome DC
	bmAndBack   = CreateBitmap(ptSize.x, ptSize.y, 1, 1, NULL);

	// Monochrome DC
	bmAndObject = CreateBitmap(ptSize.x, ptSize.y, 1, 1, NULL);

	bmAndMem    = CreateCompatibleBitmap(hdc, ptSize.x, ptSize.y);
	bmSave      = CreateCompatibleBitmap(hdc, ptSize.x, ptSize.y);

	// Each DC must select a bitmap object to store pixel data.
	bmBackOld   = (HBITMAP)SelectObject(hdcBack, bmAndBack);
	bmObjectOld = (HBITMAP)SelectObject(hdcObject, bmAndObject);
	bmMemOld    = (HBITMAP)SelectObject(hdcMem, bmAndMem);
	bmSaveOld   = (HBITMAP)SelectObject(hdcSave, bmSave);

	// Set proper mapping mode.
	SetMapMode(hdcTemp, GetMapMode(hdc));

	// Save the bitmap sent here, because it will be overwritten.
	BitBlt(hdcSave, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCCOPY);

	// Set the background color of the source DC to the color.
	// contained in the parts of the bitmap that should be transparent
	cColor = SetBkColor(hdcTemp, cTransparentColor);

	// Create the object mask for the bitmap by performing a BitBlt
	// from the source bitmap to a monochrome bitmap.
	BitBlt(hdcObject, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0,
		SRCCOPY);

	// Set the background color of the source DC back to the original
	// color.
	SetBkColor(hdcTemp, cColor);

	// Create the inverse of the object mask.
	BitBlt(hdcBack, 0, 0, ptSize.x, ptSize.y, hdcObject, 0, 0,
		NOTSRCCOPY);

	// Copy the background of the main DC to the destination.
	BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdc, xStart, yStart,
		SRCCOPY);

	// Mask out the places where the bitmap will be placed.
	BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdcObject, 0, 0, SRCAND);

	// Mask out the transparent colored pixels on the bitmap.
	BitBlt(hdcTemp, 0, 0, ptSize.x, ptSize.y, hdcBack, 0, 0, SRCAND);

	// XOR the bitmap with the background on the destination DC.
	BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCPAINT);

	// Copy the destination to the screen.
	BitBlt(hdc, xStart, yStart, ptSize.x, ptSize.y, hdcMem, 0, 0,
		SRCCOPY);

	// Place the original bitmap back into the bitmap sent here.
	BitBlt(hdcTemp, 0, 0, ptSize.x, ptSize.y, hdcSave, 0, 0, SRCCOPY);

	// Delete the memory bitmaps.
	DeleteObject(SelectObject(hdcBack, bmBackOld));
	DeleteObject(SelectObject(hdcObject, bmObjectOld));
	DeleteObject(SelectObject(hdcMem, bmMemOld));
	DeleteObject(SelectObject(hdcSave, bmSaveOld));

	// Delete the memory DCs.
	DeleteDC(hdcMem);
	DeleteDC(hdcBack);
	DeleteDC(hdcObject);
	DeleteDC(hdcSave);
	DeleteDC(hdcTemp);
}