示例#1
0
文件: scoring.cpp 项目: vsrz/VHH
void Scoring::Draw(unsigned int p_num, int score)
{
	std::stringstream pointsStream;
	pointsStream << score;
	points_graphics.setString(pointsStream.str());

	switch(p_num)
	{
	case 0:
		points_graphics.setPosition(5,5);
		break;

	case 1:
		points_graphics.setPosition(WindowManager::GetSize().x - points_graphics.getGlobalBounds().width - 5,5);
		break;

	case 2:
		points_graphics.setPosition(5,WindowManager::GetSize().y - points_graphics.getGlobalBounds().height - 5);
		break;

	case 3:
		points_graphics.setPosition(WindowManager::GetSize().x - points_graphics.getGlobalBounds().width - 5,WindowManager::GetSize().y - points_graphics.getGlobalBounds().height - 5);
		break;
	}

	WindowManager::Draw(points_graphics);
}
示例#2
0
void DropDown::arrange(sf::Text &text,sf::RectangleShape &shape)
{
	float ratiox = shape.getGlobalBounds().width/text.getGlobalBounds().width;
	float ratioy = (shape.getGlobalBounds().height/text.getGlobalBounds().height);
	ratioy*=0.5f;
	text.scale(ratiox,ratioy);
}
示例#3
0
文件: main.cpp 项目: knyazsergei/lab7
void drawNumbers(sf::RenderWindow & window,sf::Text & text, float bgHeight) {
	std::string textNum;
	sf::Vector2f position = getCenter(window);

	for (int i = 0; i < NUMBER_OF_DIGITS; i++) {
		position = polarToCartesianSys(bgHeight * 0.5f - text.getGlobalBounds().height * 2, 30.f * ( i + 1 ) - 90);
		text.setString(std::to_string( i + 1 ));
		text.setOrigin(text.getGlobalBounds().width * 0.5f, text.getGlobalBounds().height * 0.5f);
		text.setPosition(position.x + window.getSize().x * 0.5f, position.y + window.getSize().y * 0.5f);
		window.draw(text);
	}
}
示例#4
0
	virtual void init()
	
	
	{
		dt=0;
		
		
		if (!standard_font.loadFromFile("fonts/Unique.ttf"))
{
    // error...
}
		darken = sf::RectangleShape(sf::Vector2f(800,400));
		

		
		tit.setFont(standard_font); 
		score.setFont(standard_font); 

		std::stringstream ss;
		ss << your_score;
		std::string str = ss.str();
		
		
		tit.setString("Congrats! You beat the game\nIt took you:");
		
		score.setString(str + " seconds");


		tit.setCharacterSize(24);
		score.setCharacterSize(24);

		
		// dla centrowania obiektow
		
		sf::FloatRect tempt = tit.getGlobalBounds();
		sf::FloatRect tempr = score.getGlobalBounds();

		
		tit.setOrigin(sf::Vector2f(tempt.width/2,tempt.height/2));
		score.setOrigin(sf::Vector2f(tempr.width/2,tempr.height/2));

		
		tit.setPosition(400,150);
		score.setPosition(400,200);

		score.setColor(sf::Color(0,127,127));

		
		timer.restart();
		
		};
示例#5
0
文件: Cursor.cpp 项目: izissise/PFA
void		Cursor::setCursorPos(const sf::Text &text)
{
  sf::FloatRect	textSize = text.getGlobalBounds();
  sf::Vector2f	textPos = text.getPosition();

  _cursor.setPosition(textSize.width + textPos.x, textPos.y);
}
示例#6
0
    void initialize(sf::RenderWindow &mainWindow, sf::Font &mainFont)
    {
        titleText.setFont(mainFont);
        titleText.setString("Triangle Super");
        titleText.setCharacterSize(72);
        titleText.setPosition(mainWindow.getSize().x/2 - titleText.getGlobalBounds().width/2.f,
                              mainWindow.getSize().y/2 - titleText.getGlobalBounds().height/2.f);

        playText.setFont(mainFont);
        playText.setString("Play!");
        playText.setCharacterSize(30);
        playText.setPosition(mainWindow.getSize().x/3 - playText.getGlobalBounds().width/2.f,
                             mainWindow.getSize().y/3 *2 - playText.getGlobalBounds().height/2.f);

        quitText.setFont(mainFont);
        quitText.setString("Quit.");
        quitText.setCharacterSize(30);
        quitText.setPosition(mainWindow.getSize().x/3 *2 - quitText.getGlobalBounds().width/2.f,
                             mainWindow.getSize().y/3*2-quitText.getGlobalBounds().height/2.f);

        scoreText.setFont(mainFont);
        scoreText.setCharacterSize(30);
        scoreText.setPosition(mainWindow.getSize().x/2 - scoreText.getGlobalBounds().width/2.f,
                              mainWindow.getSize().y/3-scoreText.getGlobalBounds().height/2.f);
    }
示例#7
0
//will update the string of the text if needed and color and will keep the text centered if specified
void FontManager::UpdateText(sf::Text& text, const char* txt, sf::Color color, bool setOrigin)
{
	if (txt != NULL)
		text.setString(txt);

	if (setOrigin)
		text.setOrigin(text.getGlobalBounds().width / 2.0f, text.getLocalBounds().height / 2.0f);

	text.setColor(color);
}
示例#8
0
文件: GameEnd.hpp 项目: mangannn/flux
	virtual void draw(RenderWindow *window) {

		sf::RectangleShape box(window->getView().getSize());
		box.setFillColor(color);

		text.setPosition((window->getView().getSize() - Vector2f(text.getGlobalBounds().width, text.getGlobalBounds().height)) * 0.5f);

		window->draw(text);
		window->draw(box);
	}
bool isTextClicked(sf::Text text, sf::RenderWindow& window)
{
  // check if mouse is currently intersecting with text
  if(text.getGlobalBounds().intersects(sf::Rect<float> ((float)sf::Mouse::getPosition(window).x,
    (float)sf::Mouse::getPosition(window).y, 8, 8)))
  {
    return true; // if so return true, text has been clicked
  }

  else return false; // else return false, text has NOT been clicked
}
示例#10
0
void MenuScreen::generateGameModeButton(sf::Text& button, const string& modeName, 
	short position, const sf::Font *font,
	const sf::Vector2u& screenSize )
{
	button = sf::Text( modeName, *font );
	button.setColor( sf::Color::Blue );
	button.setStyle( sf::Text::Regular );
	sf::FloatRect textRect = button.getGlobalBounds();
	button.setOrigin( textRect.left + textRect.width / 2.0f,
		textRect.top + textRect.height / 2.0f );
	button.setPosition( screenSize.x / 2, screenSize.y * 0.2 + position * Constants::LENGTH_BUTTON_SEPERATION );
}
示例#11
0
	virtual void init()
	
	
	{
		dt=0;
		
		
		if (!standard_font.loadFromFile("fonts/Unique.ttf"))
{
    // error...
}
		darken = sf::RectangleShape(sf::Vector2f(800,400));
		

		
		tit.setFont(standard_font); 


		tit.setString("Made by");

		explain.setFont(standard_font);
		explain.setString("Just a bored slacker");
		explain.setCharacterSize(36);
		explain.setPosition(260,320);

		tit.setCharacterSize(24);

		
		// dla centrowania obiektow
		
		sf::FloatRect tempt = tit.getGlobalBounds();

		
		tit.setOrigin(sf::Vector2f(tempt.width/2,tempt.height/2));

		
		tit.setPosition(400,120);


if (!tex.loadFromFile("gfx/jabslogo.png"))
	
	{
		std::cout<<"Fuckup"<<std::endl;
		}

		spr.setTexture(tex);
		spr.setPosition(334,144);

		
		timer.restart();
		
		};
示例#12
0
	virtual void init()
	
	
	{
		dt=0;
		
		
		if (!standard_font.loadFromFile("fonts/Unique.ttf"))
{
    // error...
}
		darken = sf::RectangleShape(sf::Vector2f(800,400));
		

		
		tit.setFont(standard_font); 
		subtit.setFont(standard_font); 


		tit.setString(title);
		subtit.setString(subtitle);

		tit.setCharacterSize(24);
		subtit.setCharacterSize(18);
		
		// dla centrowania obiektow
		
		sf::FloatRect tempt = tit.getGlobalBounds();
		sf::FloatRect temps = subtit.getGlobalBounds();
		
		tit.setOrigin(sf::Vector2f(tempt.width/2,tempt.height/2));
		subtit.setOrigin(sf::Vector2f(temps.width/2,temps.height/2));
		
		tit.setPosition(400,150);
		subtit.setPosition(400,180);
		
		timer.restart();
		
		};
示例#13
0
void Renderer::draw(sf::Text const& text, ZIndex_t zindex, sf::RenderStates const& states)
{
    auto bounds = text.getGlobalBounds();
    if(isInScreen(bounds))
    {
        m_drawCallbacks.push_back({
            zindex,
            [&text, states] (sf::RenderTarget& renderer)
            {
                renderer.draw(text, states);
            }
        });
    }
}
示例#14
0
void assetHandle::trimTextToRectangleWidth(sf::Text &text, sf::RectangleShape &rect)
{

    while(true)
    {
        sf::FloatRect floatRect = text.getGlobalBounds();
        if ((floatRect.left + floatRect.width) > rect.getSize().x)
        {
            std::string newString = text.getString();
            newString = newString.substr(0, newString.size()-1);
            text.setString(newString);
        }
        else
            break;
    }
}
示例#15
0
void centerHonrizontally(sf::Text& text, unsigned int total_width)
{
  const sf::FloatRect bounds = text.getGlobalBounds();
  text.setPosition( (total_width - bounds.width) / 2, text.getPosition().y );
}
示例#16
0
        Player () {
            PlayerNumber = totalPlayers;
            Sprite = loadSpriteData("Player " + intToString(PlayerNumber + 1));
            //Get Global width, seperate to rotation
            CharacterWidth = Sprite.getGlobalBounds().width;
            nameSpacing = 30;
            healthBarSpacing = nameSpacing + 15;

            Sprite.setOrigin(Sprite.getGlobalBounds().width/2, Sprite.getGlobalBounds().height/2);
            Sprite.setPosition((App.getSize().x/2) - (Sprite.getGlobalBounds().width/2), (App.getSize().y/2) - (Sprite.getGlobalBounds().height/2));

            //PlayerName.setFont(sf::Font::getDefaultFont());
            PlayerName.setCharacterSize(15);
            PlayerName.setString("Player: " + intToString(PlayerNumber + 1));
            PlayerName.setOrigin(PlayerName.getGlobalBounds().width/2, PlayerName.getGlobalBounds().height/2);
            PlayerName.setPosition(Sprite.getPosition().x, Sprite.getPosition().y + nameSpacing);

            NameOutline.setSize(sf::Vector2f(PlayerName.getGlobalBounds().width, PlayerName.getGlobalBounds().height));
            NameOutline.setOutlineThickness(2);
            NameOutline.setFillColor(sf::Color(0, 0, 0, 120));
            NameOutline.setOutlineColor(sf::Color::Black);
            NameOutline.setOrigin(NameOutline.getGlobalBounds().width/2, NameOutline.getGlobalBounds().height/2);
            NameOutline.setPosition(Sprite.getPosition().x + 1.5, Sprite.getPosition().y + nameSpacing + 4);

            MaxHealth = Health = 100;
            HealthBarSize = 50;

            HealthBarRed.setSize(sf::Vector2f(HealthBarSize, 5));
            HealthBarRed.setOutlineThickness(1);
            HealthBarRed.setFillColor(sf::Color::Red);
            HealthBarRed.setOutlineColor(sf::Color::Black);
            HealthBarRed.setPosition(Sprite.getPosition().x - (CharacterWidth/2) - 5, Sprite.getPosition().y + healthBarSpacing);

            HealthBarGreen.setSize(sf::Vector2f(HealthBarSize, 5));
            HealthBarGreen.setOutlineThickness(1);
            HealthBarGreen.setFillColor(sf::Color::Green);
            HealthBarGreen.setOutlineColor(sf::Color::Black);
            HealthBarGreen.setPosition(Sprite.getPosition().x - (CharacterWidth/2) - 5, Sprite.getPosition().y + healthBarSpacing);

            if (controllerConnected) {
                ControlScheme = ControlSchemes::Joystick;
                Key k;
                k.InputType = Input::JoystickMovedNeg;
                k.KeyCode = sf::Joystick::Axis::Y;
                Bindings["Up"] = k;

                k.InputType = Input::JoystickMovedPos;
                k.KeyCode = sf::Joystick::Axis::Y;
                Bindings["Down"] = k;

                k.InputType = Input::JoystickMovedNeg;
                k.KeyCode = sf::Joystick::Axis::X;
                Bindings["Left"] = k;

                k.InputType = Input::JoystickMovedPos;
                k.KeyCode = sf::Joystick::Axis::X;
                Bindings["Right"] = k;
                } else {
                    ControlScheme = ControlSchemes::KeyboardMouse;
                    Key k;
                    k.InputType = Input::KeyboardInput;
                    k.KeyCode = sf::Keyboard::W;
                    Bindings["Up"] = k;

                    k.InputType = Input::KeyboardInput;
                    k.KeyCode = sf::Keyboard::S;
                    Bindings["Down"] = k;

                    k.InputType = Input::KeyboardInput;
                    k.KeyCode = sf::Keyboard::A;
                    Bindings["Left"] = k;

                    k.InputType = Input::KeyboardInput;
                    k.KeyCode = sf::Keyboard::D;
                    Bindings["Right"] = k;
                    }

            totalPlayers++;
            }
示例#17
0
int PlayerConnection::Run(sf::RenderWindow &mainWin, int screen)
{
	
	if (!this->font.loadFromFile("resources/fonts/" + DEFAULT_FONT))
	{
		std::cerr << "Error loading the font " + DEFAULT_FONT << std::endl;
		system("pause");
		return (-1);
	}

	this->initializeItems();
	
	sf::Event Event;

	//Boucler tant que la fenêtre n'est pas fermée
    while (true)
    {
		bool usernameIsValid = username.size() > 3;

        //Vérifier les événements
        while (mainWin.pollEvent(Event))
        {
            if (Event.type == sf::Event::Closed)
            {
                return (-1);
            }

			if (Event.type == sf::Event::TextEntered) //On veut seulement les caracteres ASCII
			{	
				bool isANumber = (Event.text.unicode >= 48 && Event.text.unicode <= 57);
				bool isALetter = (Event.text.unicode >= 65 && Event.text.unicode <= 90) || (Event.text.unicode >= 97 && Event.text.unicode <= 122);

				if (username.size() < 13 && (isANumber || isALetter))
				{
					username += static_cast<char>(Event.text.unicode);
				}
			}

			if (Event.type == sf::Event::KeyReleased && Event.key.code == sf::Keyboard::BackSpace)
			{
				username = "";
			}

            if (Event.type == sf::Event::MouseButtonReleased)
            {
				sf::Vector2f mouse_coords = sf::Vector2f(Event.mouseButton.x, Event.mouseButton.y);

				if (intersects(mouse_coords, start.getGlobalBounds()) && usernameIsValid)
				{
					return (MENU);        
				}
				else if	(intersects(mouse_coords, nameContainer.getGlobalBounds()))
				{
					username = "";
				}
			}

            if (Event.type == sf::Event::MouseMoved)
            {
				sf::Vector2f mouse_coords = sf::Vector2f(Event.mouseMove.x, Event.mouseMove.y);
				if (intersects(mouse_coords, start.getGlobalBounds()))
				{
					start.setColor(sf::Color::Red);
					start.setScale(1.05, 1.05);
				}
				else
				{
					start.setColor(sf::Color::White);
					start.setScale(1,1);
				}
			}

			nameDisplay.setString(username);
        }

        mainWin.clear();

		mainWin.draw(spriteLogo);

		mainWin.draw(text);

		if (!usernameIsValid)
		{
			nameContainer.setOutlineColor(sf::Color::Red);
		}
		else
		{
			nameContainer.setOutlineColor(sf::Color::White);
		}

		mainWin.draw(nameContainer);

		mainWin.draw(nameDisplay);

		mainWin.draw(start);

        mainWin.display();
    }

    //On ne devrait jamais se rendre jusqu'à ce point, mais juste au cas, on ferme l'application.
    return (-1);
}
示例#18
0
	// Render text with gaussian blur drop shadow
	void ShadowTextRenderer::DrawDropShadowText(sf::RenderTarget& target, sf::Text& text, bool highQuality = true)
	{
		sf::View oldView = Utilities::SetDefaultView(target);

		sf::RenderStates states = sf::RenderStates();
		states.blendMode = sf::BlendMode::BlendAlpha;

		if (gaussianShader && highQuality)
		{
			sf::FloatRect bounds = text.getGlobalBounds();
			sf::Vector2u size = sf::Vector2u(bounds.width * 2.0f, bounds.height * 4.0f);

			auto ptr = findFromTextureCache(size);
			sf::RenderTexture* base;
			if (ptr != 0)
				base = ptr;
			else
			{
				base = new sf::RenderTexture();
				base->create(size.x, size.y);
				base->setSmooth(true);
			}

			sf::View view = base->getView();
			view.setCenter(text.getPosition().x + bounds.width / 2.0f, text.getPosition().y + bounds.height / 2.0f);
			base->setView(view);

			base->clear(sf::Color::Transparent);

			sf::Color oldColor = text.getColor();
			text.setColor(sf::Color::Black);
			base->draw(text, states);
			text.setColor(oldColor);

			base->display();

			ptr = findFromTextureCache(size);
			sf::RenderTexture* shadow;
			if (ptr != 0)
				shadow = ptr;
			else
			{
				shadow = new sf::RenderTexture();
				shadow->create(size.x, size.y);
				shadow->setSmooth(true);
			}

			view = shadow->getView();
			view.setCenter(shadow->getSize().x / 2.0f, shadow->getSize().y / 2.0f);
			shadow->setView(view);

			shadow->clear(sf::Color::Transparent);

			gaussianShader->setParameter("texture", base->getTexture());
			gaussianShader->setParameter("resolution", bounds.width);
			gaussianShader->setParameter("blurScale", 0.4f);
			gaussianShader->setParameter("blurStrength", 0.5f);
			gaussianShader->setParameter("blurAmount", 6.0f);
			gaussianShader->setParameter("dir", sf::Vector2f(1.0f, 0.0f));

			states.shader = gaussianShader;

			shadow->draw(sf::Sprite(base->getTexture()), states);
			shadow->display();

			addToTextureCache(base);

			sf::Texture shadowTex = shadow->getTexture();
			shadow->clear(sf::Color::Transparent);

			gaussianShader->setParameter("texture", shadowTex);
			gaussianShader->setParameter("resolution", bounds.height);
			gaussianShader->setParameter("dir", sf::Vector2f(0.0f, 1.0f));

			states.shader = gaussianShader;

			shadow->draw(sf::Sprite(shadowTex), states);
			shadow->display();

			states.shader = 0;

			sf::Sprite shadowSpr = sf::Sprite(shadow->getTexture());
			shadowSpr.setPosition(text.getPosition() - sf::Vector2f(shadow->getSize().x / 2.0f , shadow->getSize().y / 2.0f) + sf::Vector2f(bounds.width / 2.0f, bounds.height / 2.0f));
			target.draw(shadowSpr, states);

			addToTextureCache(shadow);

			//sf::Sprite baseSpr = sf::Sprite(base.getTexture());
			//baseSpr.setPosition(text.getPosition() + (text.getPosition() - view.getCenter()));
		}
		else
		{
			sf::Vector2f oldPos = text.getPosition();
			text.setPosition(oldPos - sf::Vector2f(2.0f, 2.0f));

			sf::Color oldColor = text.getColor();
			text.setColor(sf::Color::Black);

			target.draw(text, states);

			text.setPosition(oldPos);
			text.setColor(oldColor);
		}

		target.draw(text, states);

		target.setView(oldView);
	}
示例#19
0
void centerPosition(sf::Text& text, unsigned int total_width, unsigned int total_height)
{
  const sf::FloatRect bounds = text.getGlobalBounds();
  text.setPosition( (total_width - bounds.width) / 2, (total_height - bounds.height) / 2 );
}
示例#20
0
void MainMenu::centerTextOnxAxis(sf::Text &txt, float y)
{
    txt.setPosition((window.getSize().x-txt.getGlobalBounds().width)/2.f,y);
}