STDMETHODIMP
CDirect2DRM::CreateImageFromWrappedTextExt(
				BSTR bstrText,
				IFont *pFont,
				BOOL bShadowed,
				DWORD width, 
				DWORD height,
				DWORD nPoint,
				LPDIRECT2DRMIMAGE *ppImage)
{
	MMASSERT(ppImage);
	if (m_pImageCache == NULL)
		return E_NOTINITIALIZED;

	HRESULT hr;
	LPD2DRMIMAGEPRIVATE pImagePriv = NULL;
	CMFImage *pmfi = NULL;
	SIZE size = {width, height };
	CString strText(bstrText);
	IFont *pIFont = NULL;
	CY ptsize = {nPoint*10000, 0};

	HFONT hFont = NULL;
	if ( pFont != NULL )
	{
		hr = pFont->get_hFont( &hFont);
		if (FAILED(hr))
			goto e_CreateImageFromText;
	} else {
		pIFont = GetDefaultFont();
		hr = pIFont->put_Size(ptsize);
		hr = pIFont->get_hFont( &hFont);
		
		if (FAILED(hr))
			goto e_CreateImageFromText;
	}
	
		// get a reference to the MFImage from the image cache
	if (FAILED(hr = m_pImageCache->GetImageFromText(strText, hFont, 0x00FFFFFF, bShadowed, 0, &size, &pmfi)) ||
		// CoCreate the D2DRMImage object
		FAILED(hr = CoCreateInstance(
						CLSID_CDirect2DRMImage,
						NULL,
						CLSCTX_INPROC_SERVER,
						IID_ID2DRMImagePrivate,
						(LPVOID *) &pImagePriv)) ||
		// initialize the D2DRMImage with the MFImage
		FAILED(hr = pImagePriv->InitFromMFImage(this, pmfi, 0)))
		goto e_CreateImageFromText;

	*ppImage = (LPDIRECT2DRMIMAGE) pImagePriv;

	// release the extra reference we had from the CreateImageFromText
	pmfi->Release();
	MMRELEASE(pIFont);
	return S_OK;

e_CreateImageFromText:
	MMRELEASE(pImagePriv);
	MMRELEASE(pmfi);
	MMRELEASE(pIFont);
	return hr;
}
Esempio n. 2
0
		void ScoreboardView::Draw() {
			SPADES_MARK_FUNCTION();
			
			world = client->GetWorld();
			if(!world){
				// no world
				return;
			}
			ctf = dynamic_cast<CTFGameMode *>(world->GetMode());
			tc = dynamic_cast<TCGameMode *>(world->GetMode());
			
			Handle<IImage>image;
			IFont *font;
			Vector2 pos, size;
			char buf[256];
			std::string str;
			float scrWidth = renderer->ScreenWidth();
			float scrHeight = renderer->ScreenHeight();
			const Vector4 whiteColor = {1,1,1,1};
			Handle<IImage> whiteImage = renderer->RegisterImage("Gfx/White.tga");
			
			float teamBarTop = 120.f;
			float teamBarHeight = 60.f;
			float contentsLeft = scrWidth * .5f - 400.f;
			float contentsRight = scrWidth * .5f + 400.f;
			float playersHeight = 300.f;
			float playersTop = teamBarTop + teamBarHeight;
			float playersBottom = playersTop + playersHeight;
			
			// draw shadow
			image = renderer->RegisterImage("Gfx/Scoreboard/TopShadow.tga");
			size.y = 32.f;
			renderer->SetColor(MakeVector4(0,0,0,0.2f));
			renderer->DrawImage(image, AABB2(0, teamBarTop-size.y,
											 scrWidth, size.y));
			renderer->SetColor(MakeVector4(0,0,0,0.2f));
			renderer->DrawImage(image, AABB2(0, playersBottom + size.y,
											 scrWidth, -size.y));
			
			// draw scores
			image = renderer->RegisterImage("Gfx/Scoreboard/ScoresBg.tga");
			size = MakeVector2(180.f, 32.f);
			pos = MakeVector2((scrWidth - size.x) * .5f,
							  teamBarTop - size.y);
			renderer->SetColor(MakeVector4(1.f, .45f, .2f, 1.f));
			renderer->DrawImage(image, AABB2(pos.x,pos.y,size.x,size.y));
			
			pos.y = pos.y + 5.f;
			font = client->designFont;
			
			sprintf(buf, "%d", GetTeamScore(0));
			size = font->Measure(buf);
			pos.x = scrWidth * .5f - size.x - 16.f;
			font->Draw(buf, pos + MakeVector2(0, 1), 1.f,
					   MakeVector4(0, 0, 0, 0.3));
			font->Draw(buf, pos, 1.f, whiteColor);
			
			sprintf(buf, "%d", GetTeamScore(1));
			size = font->Measure(buf);
			pos.x = scrWidth * .5f + 16.f;
			font->Draw(buf, pos + MakeVector2(0, 1), 1.f,
					   MakeVector4(0, 0, 0, 0.3));
			font->Draw(buf, pos, 1.f, whiteColor);
			
			sprintf(buf, "-");
			size = font->Measure(buf);
			pos.x = scrWidth * .5f  - size.x * .5f;
			font->Draw(buf, pos + MakeVector2(0, 1), 1.f,
					   MakeVector4(0, 0, 0, 0.3));
			font->Draw(buf, pos, 1.f, whiteColor);
			
			// draw team bar
			image = whiteImage;
			renderer->SetColor(AdjustColor(GetTeamColor(0), 0.8f, 0.3f));
			renderer->DrawImage(image,
								AABB2(0, teamBarTop,
									  scrWidth * .5f, teamBarHeight));
			renderer->SetColor(AdjustColor(GetTeamColor(1), 0.8f, 0.3f));
			renderer->DrawImage(image,
								AABB2(scrWidth * .5f, teamBarTop,
									  scrWidth * .5f, teamBarHeight));
			
			image = renderer->RegisterImage("Gfx/Scoreboard/Grunt.tga");
			size.x = 120.f; size.y = 60.f;
			renderer->DrawImage(image,
								AABB2(contentsLeft, teamBarTop + teamBarHeight - size.y,
									  size.x, size.y));
			renderer->DrawImage(image,
								AABB2(contentsRight, teamBarTop + teamBarHeight - size.y,
									  -size.x, size.y));
			
			font = client->bigTextFont;
			str = world->GetTeam(0).name;
			pos.x = contentsLeft + 110.f;
			pos.y = teamBarTop + 5.f;
			font->Draw(str, pos + MakeVector2(0, 2), 1.f,
					   MakeVector4(0, 0, 0, 0.5));
			font->Draw(str, pos, 1.f, whiteColor);
			
			str = world->GetTeam(1).name;
			size = font->Measure(str);
			pos.x = contentsRight - 110.f - size.x;
			pos.y = teamBarTop + 5.f;
			font->Draw(str, pos + MakeVector2(0, 2), 1.f,
					   MakeVector4(0, 0, 0, 0.5));
			font->Draw(str, pos, 1.f, whiteColor);
			
			// players background
			image = renderer->RegisterImage("Gfx/Scoreboard/PlayersBg.tga");
			renderer->SetColor(MakeVector4(0, 0, 0, 1.f));
			renderer->DrawImage(image,
								AABB2(0, playersTop,
									  scrWidth, playersHeight));
			
			// draw players
			DrawPlayers(0, contentsLeft, playersTop,
						(contentsRight - contentsLeft) * .5f,
						playersHeight);
			DrawPlayers(1, scrWidth * .5f, playersTop,
						(contentsRight - contentsLeft) * .5f,
						playersHeight);
		}
Esempio n. 3
0
		void LimboView::Draw() {
			Handle<IImage> menuItemImage = renderer->RegisterImage("Gfx/Limbo/MenuItem.tga");
			Handle<IImage> menuItemBigImage = renderer->RegisterImage("Gfx/Limbo/BigMenuItem.tga");
			//Handle<IImage> menuItemRingImage = renderer->RegisterImage("Gfx/Limbo/MenuItemRing.tga");
			IFont *font = client->textFont;
			
			float left = (renderer->ScreenWidth() - contentsWidth) * .5f;
			float top = renderer->ScreenHeight() - 150.f;
			{
				std::string msg = "Select Team:";
				Vector2 pos;
				pos.x = left + 10.f;
				pos.y = top + 10.f;
				font->Draw(msg, pos + MakeVector2(0, 1), 1.f, MakeVector4(0,0,0,0.4f));
				font->Draw(msg, pos, 1.f, MakeVector4(1, 1, 1, 1));
			}
			if(selectedTeam != 2){
				std::string msg = "Select Weapon:";
				Vector2 pos;
				pos.x = left + 260.f;
				pos.y = top + 10.f;
				font->Draw(msg, pos + MakeVector2(0, 1), 1.f, MakeVector4(0,0,0,0.4f));
				font->Draw(msg, pos, 1.f, MakeVector4(1, 1, 1, 1));
			}
			
			for(size_t i = 0; i < items.size(); i++){
				MenuItem& item = items[i];
				bool selected = false;
				
				if(!item.visible)
					continue;
				
				switch(item.type){
					case MenuTeam1: selected = selectedTeam == 0; break;
					case MenuTeam2: selected = selectedTeam == 1; break;
					case MenuTeamSpectator: selected = selectedTeam == 2; break;
					case MenuWeaponRifle:
						selected = selectedWeapon == RIFLE_WEAPON; break;
					case MenuWeaponSMG:
						selected = selectedWeapon == SMG_WEAPON; break;
					case MenuWeaponShotgun:
						selected = selectedWeapon == SHOTGUN_WEAPON; break;
					default:
						selected = false;
				}
				
				Vector4 fillColor = {0.2f, 0.2f, 0.2f, 0.5f};
				Vector4 ringColor = {0, 0, 0, 0};
				
				if(item.hover){
					fillColor = MakeVector4(.4f, .4f, .4f, .7f);
					ringColor = MakeVector4(.8f, .8f, .8f, .7f);
				}
				if(selected){
					fillColor = MakeVector4(.7f, .7f, .7f, .9f);
				}
				
				renderer->SetColor(fillColor);
				if(item.type == MenuSpawn){
					renderer->DrawImage(menuItemBigImage, item.rect);
					
					std::string msg = item.text;
					IFont *bFont = client->textFont;
					Vector2 size = bFont->Measure(msg);
					Vector2 pos;
					pos.x = item.rect.GetMinX() + (item.rect.GetWidth() - size.x) / 2.f + 2.f;
					pos.y = item.rect.GetMinY() + (item.rect.GetHeight() - size.y) / 2.f + 2.f;
					bFont->Draw(msg, pos + MakeVector2(0, 2), 1.f, MakeVector4(0,0,0,0.4f));
					bFont->Draw(msg, pos, 1.f, MakeVector4(1, 1, 1, 1));
				}else{
					renderer->DrawImage(menuItemImage, item.rect);
					
					std::string msg = item.text;
					if(item.type == MenuTeam1)
						msg = client->GetWorld()->GetTeam(0).name;
					if(item.type == MenuTeam2)
						msg = client->GetWorld()->GetTeam(1).name;
					Vector2 size = font->Measure(msg);
					Vector2 pos;
					pos.x = item.rect.GetMinX() + 5.f;
					pos.y = item.rect.GetMinY() + (item.rect.GetHeight() - size.y) / 2.f + 2.f;
					font->Draw(msg, pos + MakeVector2(0, 1), 1.f, MakeVector4(0,0,0,0.4f));
					font->Draw(msg, pos, 1.f, MakeVector4(1, 1, 1, 1));
				}
			}
			
			Handle<IImage> cursor = renderer->RegisterImage("Gfx/Limbo/Cursor.tga");
			
			renderer->SetColor(MakeVector4(1, 1, 1, 1));
			renderer->DrawImage(cursor, AABB2(cursorPos.x - 8,
											  cursorPos.y - 8,
											  32, 32));
		}
Esempio n. 4
0
		void ScoreboardView::DrawPlayers(int team, float left, float top,
										 float width, float height){
			IFont *font = client->textFont;
			float rowHeight = 24.f;
			char buf[256];
			Vector2 size;
			Vector4 white = { 1,1,1,1 };
			int maxRows = (int)floorf(height / rowHeight);
			int numPlayers = 0;
			int cols;
			std::vector<ScoreboardEntry> entries;
			
			for(int i = 0; i < world->GetNumPlayerSlots(); i++){
				Player *p = world->GetPlayer(i);
				if(!p) continue;
				if(p->GetTeamId() != team)
					continue;
					
				ScoreboardEntry ent;
				ent.name = p->GetName();
				ent.score = world->GetPlayerPersistent(i).kills;
				ent.id = i;
				entries.push_back(ent);
				
				numPlayers++;
			}
			
			std::sort(entries.begin(), entries.end());
			
			cols = (numPlayers + maxRows - 1) / maxRows;
			if(cols == 0)cols = 1;
			maxRows = (numPlayers + cols - 1) / cols;
			
			int row = 0, col = 0;
			float colWidth = (float)width / (float)cols;
			
			for(int i = 0; i < numPlayers; i++){
				ScoreboardEntry& ent = entries[i];
				
				float rowY = top + 6.f + row * rowHeight;
				float colX = left + width / (float)cols * (float)col;
				Vector4 color = white;
				if(ent.id == world->GetLocalPlayerIndex())
					color = GetTeamColor(team);
				
				sprintf(buf, "#%d", ent.id); // FIXME: 1-base?
				size = font->Measure(buf);
				font->Draw(buf, MakeVector2(colX + 35.f - size.x,
											rowY),
						   1.f, color);
				
				font->Draw(ent.name, MakeVector2(colX + 45.f,
											rowY),
						   1.f, color);
				
				sprintf(buf, "%d", ent.score);
				size = font->Measure(buf);
				font->Draw(buf, MakeVector2(colX + colWidth - 10.f - size.x,
											rowY),
						   1.f, color);
				
				row++;
				if(row >= maxRows){
					col++;
					row = 0;
				}
			}
		}