예제 #1
0
_MEMBER_FUNCTION_IMPL(GUIFont, getTextExtent)
{
	const char * text;
	sq_getstring(pVM, -1, (const char **)&text);
	CEGUI::Font * pFont = sq_getinstance<CEGUI::Font *>(pVM);

	if(!pFont)
	{
		sq_pushbool(pVM, false);
		return 1;
	}

	sq_pushfloat(pVM, pFont->getTextExtent(g_pClient->GetGUI()->AnsiToCeguiFriendlyString(text)));
	return 1;
}
예제 #2
0
	void Console::appendTextRow(const CeGuiString& text, const colour color)
	{
		const float MIN_SPACE_POS = 0.5;

		CeGuiString textLeft = CeGuiString(text);
        CEGUI::Font* font = const_cast<CEGUI::Font*>(mDisplay->getFont());
        unsigned int width = mDisplay->getPixelSize().d_width * 0.95f;

		while (textLeft.length() > 0)
		{
			CeGuiString textLine;

			if (font->getTextExtent(textLeft) > width)
			{
				unsigned int numLastChar = font->getCharAtPixel(textLeft, width);
				unsigned int numSpace = textLeft.find_last_of(" \t\n", numLastChar);

				if (numSpace == CeGuiString::npos || numSpace < MIN_SPACE_POS*numLastChar)
				{
					textLine = textLeft.substr(0, numLastChar);
					textLeft = textLeft.substr(numLastChar);
				}
				else
				{
					textLine = textLeft.substr(0, numSpace);
					textLeft = textLeft.substr(numSpace+1);
				}
			}
			else
			{
				textLine = textLeft;
				textLeft = "";
			}

			ListboxTextItem* item = new ListboxTextItem(textLine);
			item->setTextColours(color);
			mDisplay->addItem(item);
			mDisplay->ensureItemIsVisible(item); // scroll to bottom;
		}
		//ListboxWrappedTextItem* item = new ListboxWrappedTextItem(text);
		//item->setTextColours(color);
		//item->setTextFormatting(CEGUI::WordWrapLeftAligned);
		//mDisplay->addItem(item);
		//mDisplay->ensureItemIsVisible(item); // scroll to bottom;*/
	}
예제 #3
0
_MEMBER_FUNCTION_IMPL(GUIElement, setFont)
{
	CGUIFrameWindow * pWindow = sq_getinstance<CGUIFrameWindow *>(pVM);
	CEGUI::Font * pFont = sq_getinstance<CEGUI::Font *>(pVM, 2);

	if(!pWindow || !pFont)
	{
		sq_pushbool(pVM, false);
		return 1;
	}

	// Adjust the size of the element when the font is changed
	float fTextWidth = pFont->getTextExtent(pWindow->getText());
	float fTextHeight = pFont->getFontHeight();
	pWindow->setSize(CEGUI::UVector2(CEGUI::UDim(0, fTextWidth), CEGUI::UDim(0, fTextHeight)));

	pWindow->setFont(pFont);
	return 1;
}
예제 #4
0
_MEMBER_FUNCTION_IMPL(GUIText, setText)
{
	const char * text;
	sq_getstring(pVM, -1, (const char **)&text);
	CGUIFrameWindow * pWindow = sq_getinstance<CGUIFrameWindow *>(pVM);

	if(!pWindow)
	{
		sq_pushbool(pVM, false);
		return 1;
	}

	CClientScriptManager * pClientScriptManager = g_pClient->GetClientScriptManager();
	pClientScriptManager->GetGUIManager()->Add(pWindow, pClientScriptManager->GetScriptingManager()->Get(pVM));

	// We have to use the element's font to get the real extent 
	CEGUI::Font * pFont = pWindow->getFont (true);
	float fTextWidth = pFont->getTextExtent(text);
	float fTextHeight = pFont->getFontHeight();
	pWindow->setSize(CEGUI::UVector2(CEGUI::UDim(0, fTextWidth), CEGUI::UDim(0, fTextHeight)));
	pWindow->setText(CGUI::AnsiToCeguiFriendlyString(text, strlen(text)));
	sq_pushbool(pVM, true);
	return 1;
}
예제 #5
0
// Direct3DDevice9::Reset
void Direct3DReset()
{
	// If our GUI instance does not exist create it
	if(!g_pGUI)
	{
		g_pGUI = new CGUI(g_pDevice);

		if(g_pGUI->Initialize())
		{
			// Version identifier text
			g_pVersionIdentifier = g_pGUI->CreateGUIStaticText();
			g_pVersionIdentifier->setText(VERSION_IDENTIFIER);
			CEGUI::Font * pFont = g_pGUI->GetFont("tahoma-bold");
			float fTextWidth = pFont->getTextExtent(VERSION_IDENTIFIER);
			float fTextHeight = pFont->getFontHeight();
			g_pVersionIdentifier->setSize(CEGUI::UVector2(CEGUI::UDim(0, fTextWidth), CEGUI::UDim(0, fTextHeight)));
			float fTextX = pFont->getTextExtent("_");
			float fTextY = -(fTextX + fTextHeight);
			g_pVersionIdentifier->setPosition(CEGUI::UVector2(CEGUI::UDim(0, fTextX), CEGUI::UDim(1, fTextY)));
			g_pVersionIdentifier->setProperty("FrameEnabled", "false");
			g_pVersionIdentifier->setProperty("BackgroundEnabled", "false");
			g_pVersionIdentifier->setFont(pFont);
			g_pVersionIdentifier->setProperty("TextColours", "tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
			g_pVersionIdentifier->setAlpha(0.6f);
			g_pVersionIdentifier->setVisible(true);

			/*#ifdef IVMP_WEBKIT
				g_pWebkit = new CD3D9WebKit();
			#endif
			*/

			// TODO: Make the default stuff (Chat window, main menu, e.t.c) a xml layout so it
			// can be edited by users
			// TODO: Also load the font from an xml layout so it can be edited by users
			// TODO: Ability to output all server messages to the client console?
			// TODO: A script console when client side scripts are implemented

			CLogFile::Printf("GUI initialized");
		}
		else
			CLogFile::Printf("GUI initialization failed");
	}
	else
	{
		// If our GUI class does exist inform it of the device reset
		g_pGUI->OnResetDevice();
	}

	// If our graphics instance does not exist create it
	if(!g_pGraphics && g_pDevice)
		g_pGraphics = new CGraphics(g_pDevice);
	else
		g_pGraphics->OnResetDevice();

	// If our main menu class does not exist create it
	if(!g_pMainMenu)
		g_pMainMenu = new CMainMenu();
	else
		g_pMainMenu->OnResetDevice();

	//// Show loading screen
	//if(!CGame::IsGameLoaded() && !CGame::IsMenuActive())
	//	g_pMainMenu->ShowLoadingScreen();

	// If our credits class does not exist create it
	if(!g_pCredits)
		g_pCredits = new CCredits(g_pGUI);

	// If our fps counter class does not exist create it
	if(!g_pFPSCounter)
		g_pFPSCounter = new CFPSCounter();

	// If our fps counter class does not exist create it
	if(!g_pChatWindow)
		g_pChatWindow = new CChatWindow();

	// If our input window class does not exist create it
	if(!g_pInputWindow)
	{
		g_pInputWindow = new CInputWindow();
		RegisterCommands();
	}

	// If our name tags class does not exist create it
	if(!g_pNameTags)
		g_pNameTags = new CNameTags();
}
예제 #6
0
void CSpawnSelection::ProcessLocalPlayer(CLocalPlayer *pLocalPlayer)
{
	CCamera *pGameCamera;
	CPlayerPed *pGamePlayer;
	DWORD dwTicksSinceLastSelection;
	Vector3 vPlayerPos;
	float fDrawX=25.0f;
	float fDrawY=250.0f;
	char szMsg[256];

	if(FALSE == pLocalPlayer->IsActive() && !pLocalPlayer->IsWasted() && m_bClearedToSpawn)
	{
		// DONT ALLOW ANY ACTIONS IF WE'RE STILL FADING OR WAITING.
		if((GetTickCount() - m_dwInitialSelectionTick) < 2000) return;
		pGame->ToggleKeyInputsDisabled(TRUE);
		
		if(GetKeyState(VK_SHIFT)&0x8000) // SHIFT PRESSED SO SPAWN
		{		
			pGameCamera = pGame->GetCamera();
			pGamePlayer = pGame->FindPlayerPed();
			pGameCamera->Restore();
			pLocalPlayer->SpawnPlayer();
			pGame->DisplayHud(TRUE);
			pGame->ToggleHud(TRUE);
			pGame->HideRadar(FALSE);
			pGameCamera->SetBehindPlayer();
			pGamePlayer->GetPosition(&vPlayerPos);		
			pGame->PlaySound(10, vPlayerPos);
			pGame->ToggleKeyInputsDisabled(FALSE);
			pGamePlayer->TogglePlayerControllable(TRUE);
			m_pGUIText->setVisible(false);
			return;
		}
		else if(m_bClearedToSpawn) // WE ARE CLEARED TO SPAWN OR SELECT ANOTHER CLASS
		{
			pGame->ToggleHud(FALSE);
			pGame->HideRadar(TRUE);

			// SHOW INFO ABOUT THE SELECTED CLASS..
			szMsg[0] = '\0';
			strcat(szMsg, "> Use Left and Right arrow keys to select a class.\n");
			strcat(szMsg, "> Press Shift button when ready to spawn.\n");

			if(!m_pGUIText)
			{
				m_pGUIText = pGUI->CreateGUIStaticText();
				m_pGUIText->setText(szMsg);
				CEGUI::Font * pFont = pGUI->GetTahomaBold10Font();
				float fTextWidth = pFont->getTextExtent(szMsg);
				float fTextHeight = pFont->getFontHeight();
				m_pGUIText->setSize(CEGUI::UVector2(CEGUI::UDim(0, fTextWidth*3), CEGUI::UDim(0, fTextHeight*3)));
				float fTextX = pFont->getTextExtent("_");
				float fTextY = -(fTextX + fTextHeight);
				m_pGUIText->setPosition(CEGUI::UVector2(CEGUI::UDim(0, fTextX), CEGUI::UDim(0.8, fTextY)));
				m_pGUIText->setProperty("BackgroundEnabled", "false");
				m_pGUIText->setProperty("FrameEnabled", "false");
				m_pGUIText->setProperty("Font", "Tahoma-Bold-10");
				m_pGUIText->setProperty("TextColours", "tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF");
				m_pGUIText->setAlpha(155);
				m_pGUIText->setVisible(true);
			}

			CD3DFont *pD3DFont = pChatWindow->m_pD3DFont;
			//pD3DFont->DrawText(fDrawX,fDrawY,0xFFFFFFFF,szMsg);

			// GRAB PLAYER MATRIX FOR SOUND POSITION
			pGamePlayer = pGame->FindPlayerPed();
			pGamePlayer->GetPosition(&vPlayerPos);

			pGame->DisplayHud(FALSE);
			pGamePlayer->ClearAllWeapons();
			pGamePlayer->TogglePlayerControllable(FALSE);
			dwTicksSinceLastSelection = GetTickCount() - m_dwLastSpawnSelectionTick; // used to delay reselection.

			// ALLOW ANOTHER SELECTION WITH LEFT KEY
			if( (GetKeyState(VK_LEFT)&0x8000) && (dwTicksSinceLastSelection > 250)) { // LEFT ARROW
				m_bClearedToSpawn = FALSE;
				m_dwLastSpawnSelectionTick = GetTickCount();
				m_iSelectedClass--;
		
				pGame->PlaySound(14, vPlayerPos);
				pLocalPlayer->RequestClass(m_iSelectedClass);
				return;
			}

			// ALLOW ANOTHER SELECTION WITH RIGHT KEY
			if( (GetKeyState(VK_RIGHT)&0x8000) && (dwTicksSinceLastSelection > 250)) { // RIGHT ARROW
	
				m_bClearedToSpawn = FALSE;
				m_dwLastSpawnSelectionTick = GetTickCount();
				m_iSelectedClass++;

				pGame->PlaySound(13, vPlayerPos);
				pLocalPlayer->RequestClass(m_iSelectedClass);
				return;
			}	
		}
	}
}
예제 #7
0
void Draw_Static_Text( const std::string &text, const Color *color_text /* = &white */, const Color *color_bg /* = NULL */, bool wait_for_input /* = 1 */ )
{
	// fixme : Can't handle multiple lines of text. Change to MultiLineEditbox or use HorzFormatting=WordWrapLeftAligned property.
	bool draw = 1;

	// Statictext window
	CEGUI::Window *window_statictext = CEGUI::WindowManager::getSingleton().loadWindowLayout( "statictext.layout" );
	pGuiSystem->getGUISheet()->addChildWindow( window_statictext );
	// get default text
	CEGUI::Window *text_default = static_cast<CEGUI::Window *>(CEGUI::WindowManager::getSingleton().getWindow( "text_default" ));

	// set text
	text_default->setProperty( "TextColours", CEGUI::PropertyHelper::colourToString( CEGUI::colour( static_cast<float>(color_text->red) / 255, static_cast<float>(color_text->green) / 255, static_cast<float>(color_text->blue) / 255, 1 ) ) );
	CEGUI::String gui_text = reinterpret_cast<const CEGUI::utf8*>(text.c_str());
	text_default->setText( gui_text );

	// align text
	CEGUI::Font *font = &CEGUI::FontManager::getSingleton().get( "bluebold_medium" );
	float text_width = font->getTextExtent( gui_text ) * global_downscalex;

	text_default->setWidth( CEGUI::UDim( 0, ( text_width + 15 ) * global_upscalex ) );
	text_default->setXPosition( CEGUI::UDim( 0, ( game_res_w * 0.5f - text_width * 0.5f ) * global_upscalex ) );
	text_default->moveToFront();

	float text_height = font->getLineSpacing();
	text_height *= 1 + std::count(text.begin(), text.end(), '\n');
	// set window height
	text_default->setHeight( CEGUI::UDim( 0, text_height + ( 12 * global_upscaley ) ) );

	while( draw )
	{
		Draw_Game();

		// draw background
		if( color_bg )
		{
			// create request
			cRect_Request *request = new cRect_Request();

			pVideo->Draw_Rect( NULL, 0.9f, color_bg, request );
			request->m_render_count = wait_for_input ? 4 : 1;

			// add request
			pRenderer->Add( request );
		}

		pVideo->Render();

		if( wait_for_input )
		{
			while( SDL_PollEvent( &input_event ) )
			{
				if( input_event.type == SDL_KEYDOWN || input_event.type == SDL_JOYBUTTONDOWN || input_event.type == SDL_MOUSEBUTTONDOWN )
				{
					draw = 0;
				}
			}

			// if vsync is disabled then limit the fps to reduce the CPU usage
			if( !pPreferences->m_video_vsync )
			{
				Correct_Frame_Time( 100 );
			}
		}
		else
		{
			draw = 0;
		}

		pFramerate->Update();
	}

	// Clear possible active input
	if( wait_for_input )
	{
		Clear_Input_Events();
	}

	pGuiSystem->getGUISheet()->removeChildWindow( window_statictext );
	CEGUI::WindowManager::getSingleton().destroyWindow( window_statictext );
}
예제 #8
0
int cDialogBox_Question :: Enter( std::string text, bool with_cancel /* = 0 */ )
{
	Init( with_cancel );

	// get text
	CEGUI::Editbox *box_text = static_cast<CEGUI::Editbox *>(CEGUI::WindowManager::getSingleton().getWindow( "box_question_text" ));
	box_text->setText( reinterpret_cast<const CEGUI::utf8*>(text.c_str()) );


	// align text
	CEGUI::Font *font = &CEGUI::FontManager::getSingleton().get( "bluebold_medium" );
	// fixme : Can't handle multiple lines of text
	float text_width = font->getTextExtent( text ) * global_downscalex;

	if( text_width > 250 )
	{
		box_window->setWidth( CEGUI::UDim( 0, ( text_width + 15 ) * global_upscalex ) );
		box_window->setXPosition( CEGUI::UDim( 0, ( game_res_w * 0.5f - text_width * 0.5f ) * global_upscalex ) );
	}

	// Button Yes
	CEGUI::PushButton *button_yes = static_cast<CEGUI::PushButton *>(CEGUI::WindowManager::getSingleton().getWindow( "box_question_button_yes" ));
	// Button No
	CEGUI::PushButton *button_no = static_cast<CEGUI::PushButton *>(CEGUI::WindowManager::getSingleton().getWindow( "box_question_button_no" ));
	// Button Cancel
	CEGUI::PushButton *button_cancel = static_cast<CEGUI::PushButton *>(CEGUI::WindowManager::getSingleton().getWindow( "box_question_button_cancel" ));

	// if without cancel
	if( !with_cancel )
	{
		button_cancel->hide();
	}

	// events
	button_yes->subscribeEvent( CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber( &cDialogBox_Question::Button_yes_clicked, this ) );
	button_no->subscribeEvent( CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber( &cDialogBox_Question::Button_no_clicked, this ) );
	button_cancel->subscribeEvent( CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber( &cDialogBox_Question::Button_cancel_clicked, this ) );

	finished = 0;

	while( !finished )
	{
		Draw();

		while( SDL_PollEvent( &input_event ) )
		{
			if( input_event.type == SDL_KEYDOWN )
			{
				if( input_event.key.keysym.sym == SDLK_ESCAPE )
				{
					if( with_cancel )
					{
						return_value = -1;
					}
					else
					{
						return_value = 0;
					}

					finished = 1;
				}
				else if( input_event.key.keysym.sym == SDLK_RETURN || input_event.key.keysym.sym == SDLK_KP_ENTER )
				{
					return_value = 1;
					finished = 1;
				}
				else
				{
					pKeyboard->CEGUI_Handle_Key_Down( input_event.key.keysym.sym );
				}
			}
			else if( input_event.type == SDL_KEYUP )
			{
				pKeyboard->CEGUI_Handle_Key_Up( input_event.key.keysym.sym );
			}
			else
			{
				pMouseCursor->Handle_Event( &input_event );
			}
		}

		Update();
	}

	Exit();

	return return_value;
}