示例#1
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);
}
void LogMessageWindow::addMessage(sf::Text msg){


	if (msg_queue.empty()){
		std::cout << "Msg queue is empty\n";
		//reposition the text to the boundaries of the message log window
		msg.setPosition(sf::Vector2f(this->message_window_background.getPosition().x + 10, 
			this->message_window_background.getPosition().y +  
			message_window_background.getSize().y - 14 ));

	}
	//When the number of messages in the queue reach the height of the message window, clear it.
	else if ( ((int)message_window_background.getSize().y / 14) == msg_queue.size()){//Division by constant, constant is the position of each message

		msg_queue.clear();
		msg.setPosition(sf::Vector2f(this->message_window_background.getPosition().x + 10,
			this->message_window_background.getPosition().y +
			message_window_background.getSize().y - 14));
	}
	else{

		std::cout << "Msg queue is NOT empty\n";
		msg.setPosition(sf::Vector2f(message_window_background.getPosition().x + 10, msg_queue.back().getPosition().y - 14.0f));
	}
	msg_queue.push_back(msg);
}
示例#3
0
sf::Vector2f getCenter(const sf::Text& text)
{
    sf::Vector2f center = text.getPosition();
    center.x += text.getLocalBounds().width  / 2.f;
    center.y += text.getLocalBounds().height / 2.f;
    return center;
}
示例#4
0
文件: Item.cpp 项目: Obscurs/genland
void Item::Draw(sf::RenderWindow& renderWindow, sf::Text &text)
{
	TextureManager *t = Resources::getTextureManager("tileMap");
		sf::Sprite s;
		sf::Vector2f item_pos = GetPosition();
		t->generateSprite(id, item_pos, s, sf::Vector2f(GetWidth(),GetHeight()));
		renderWindow.draw(s);



	sf::Vector2f test_pos = GetPosition();
	text.setPosition(test_pos.x, test_pos.y);
	text.setScale(sf::Vector2f(1.5,1.5));
	renderWindow.draw(text);
		//renderWindow.draw(_sprite);
		/*if(amount >0){
			char c[10];
			sprintf(c, "%i", amount);
			std::string string(c);
			sf::String str(string);
			text.setString(str);
			text.setPosition(GetPosition().x, GetPosition().y);
			renderWindow.draw(text);	
		}*/

}
示例#5
0
	//Enemy sprite render.
	void update(float deltaTime, char** levelMap, struct config* config) {

		if(mDirection == 0) {mMovement.x = 0;		mMovement.y = -mSpeed;}
		if(mDirection == 1) {mMovement.x = mSpeed;	mMovement.y = 0;}
		if(mDirection == 2) {mMovement.x = 0;		mMovement.y = mSpeed;}
		if(mDirection == 3) {mMovement.x = mSpeed;	mMovement.y = 0;}

		mRect.left += mMovement.x * deltaTime;
		collision(levelMap, config);
		mRect.top += mMovement.y * deltaTime;
		collision(levelMap, config);

		//Enemy animation.
		mCurrentFrame += mAnimationSpeed * deltaTime;
		if(mCurrentFrame > mFrameCount) mCurrentFrame -= mFrameCount;

		if(mMovement.x > 0) mSprite.setTextureRect(sf::IntRect(mRect.width * int(mCurrentFrame), 925, mRect.width, mRect.height));
		if(mMovement.x < 0) mSprite.setTextureRect(sf::IntRect(mRect.width * int(mCurrentFrame), 667, mRect.width, mRect.height));
		if(mMovement.y > 0) mSprite.setTextureRect(sf::IntRect(mRect.width * int(mCurrentFrame), 535, mRect.width, mRect.height));
		if(mMovement.y < 0) mSprite.setTextureRect(sf::IntRect(mRect.width * int(mCurrentFrame), 787, mRect.width, mRect.height));

		mSprite.setPosition(mRect.left - offsetX, mRect.top - offsetY);
		mTextName.setPosition(mRect.left - offsetX, mRect.top - mTextName.getCharacterSize() - offsetY);

	}
示例#6
0
void pauseMenu()
{
	pause.setFont(myFont);
	pause.setCharacterSize(WIDTH / 16);
	pause.setStyle(sf::Text::Bold);
	pause.setColor(sf::Color::Black);
	pause.setString("PAUSE");
	pause.setOrigin(pause.getLocalBounds().width / 2, pause.getLocalBounds().height / 2);
	pause.setPosition(WIDTH / 2, 3 * HEIGHT / 16);

	sf::Vector2f menuRectSize(3 * WIDTH / 16, HEIGHT / 8);

	for (int i = 0; i < pauseMenuRect.size(); i++)
	{
		pauseMenuRect[i].setSize(menuRectSize);
		pauseMenuRect[i].setFillColor(grey);
		pauseMenuRect[i].setOrigin(menuRectSize.x / 2, menuRectSize.y / 2);
		pauseMenuRect[i].setPosition(WIDTH / 2, 6 * HEIGHT / 16 + i * (5 * HEIGHT / 32));

		pauseMenuText[i].setFont(myFont);
		pauseMenuText[i].setCharacterSize(2 * pause.getCharacterSize() / 5);
		pauseMenuText[i].setStyle(sf::Text::Bold);
		pauseMenuText[i].setColor(sf::Color::Black);
		pauseMenuText[i].setString(pauseMenuCommands[i]);
		pauseMenuText[i].setOrigin(pauseMenuText[i].getLocalBounds().width / 2, pauseMenuText[i].getLocalBounds().height / 2);
		pauseMenuText[i].setPosition(pauseMenuRect[i].getPosition().x, pauseMenuRect[i].getPosition().y);
	}

	BILLIARDS.draw(pause);
	for (int i = 0; i < pauseMenuRect.size(); i++)
	{
		BILLIARDS.draw(pauseMenuRect[i]);
		BILLIARDS.draw(pauseMenuText[i]);
	}
}
示例#7
0
 void showMsg(std::wstring msg, sf::Color foreground) {
     if ( (msg.size() * style.fontsize ) > width ) {
         msg = linebreak(msg, int(width / style.tilesize));
     }
     textbox->setString(msg);
     textbox->setColor(foreground);
 }
示例#8
0
void CustomMenu::onEvent(const sf::Event& event) {
	Component* triggered = nullptr;

	while((triggered = popEvent(event))) {
		math::u_id id = triggered->getID();

		if(id == save->getID()) {

		} else if(id == load->getID()) {

		} else if(id == random->getID()) {
			conv << (Utility::Random::getUnsignedRandom()%1001);

			name_f->setText(SentenceGenerator::getWord(SentenceGenerator::Noun) +
					SentenceGenerator::getWord(SentenceGenerator::Noun));
			age_f->setText(conv.str());

			gender->randomize();
			//palette->randomize();

			conv.str("");
		} else if(id == back->getID())
			MenuUtils::mainMenu();
		else if(id == name_f->getID())
			name.setColor(name_f->getColor());
		else if(id == age_f->getID())
			age.setColor(age_f->getColor());
		else
			std::cerr << "Auto-destruction sequence activated. Nooooo!!!" << std::endl;
	}
}
示例#9
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);
}
示例#10
0
	void wordwrap(){
		//divide the sentence into words
		vector< string > words = explode( ' ', log_text );
		vector< bool > newline( words.size() );

		int limit_right = log_x + log_background -> width() - log_padding_x * 2;

		for( unsigned index = 0; index < words.size(); ++index ){

			log_text.clear();

			for( unsigned i = 0; i <= index; i++ ){
				log_text += words[i] + ( newline[ i ] ? '\n' : ' ' );
			}

			log_text_display.setString( log_text );

			if( log_text_display.findCharacterPos( log_text.size() ).x >= limit_right ){
				newline[ index - 1 ] = true;
			}
		}

		log_text.clear();

		for( unsigned i = 0; i < words.size(); i++ ){
			log_text += words[i] + ( newline[ i ] ? '\n' : ' ' );
		}
	}
示例#11
0
	//Player constructor.
	Player(sf::Texture& texture, sf::Texture& hpImage, int x, int y, sf::Font& font) {

		mSprite.setTexture(texture);
		mRect = sf::FloatRect(x, y, 120, 110);					//Character x, y, width, height.
		
		mName = "Player 1";
		mTextName.setString(mName);
		mTextName.setFont(font);
		mTextName.setCharacterSize(30);
		mTextName.setStyle(sf::Text::Bold);
		mTextName.setColor(sf::Color::Red);
		
		mHpSprite.setTexture(hpImage);
		mHpSprite.setTextureRect(sf::IntRect(0, 0, 100, 10));

		mSprite.setTextureRect(sf::IntRect(0, 15, 120, 110));
	
		mSpeed = 0.1;
		mMovement.x = 0;
		mMovement.y = 0;

		mCurrentFrame = 0;
		mAnimationSpeed = 0.005;

		mIsAlive = true;
		mHP = 100;
		mMaxHp = 100;
		mMP = 100;
	}
示例#12
0
文件: scoring.cpp 项目: vsrz/VHH
void Scoring::Initialize()
{
	font.loadFromFile("./Resources/Fonts/jokerman.ttf");
	points_graphics.setFont(font);
	points_graphics.setCharacterSize(24);
	points_graphics.setString("0");
}
//private function to initialize the text easier
//precondition: the Font must have opened correctly
void RoundEndScreen::initializeText(sf::Font &font, sf::Text &text, float x_position, float y_position, int size)
{
	text.setFont(font);
	text.setCharacterSize(size);
	text.setPosition(x_position, y_position);
	text.setColor(sf::Color::White);
}
示例#14
0
	Pong() : gameWindow(sf::VideoMode(600, 480), "Pong")
	{
		ball.setFillColor(sf::Color::Cyan);
		ball.setPosition(100.0, 100.0);
		ball.setRadius(10.f);

		p1Paddle.setFillColor(sf::Color::Green);
		p1Paddle.setPosition(10.0, 100.0);
		p1Paddle.setSize(sf::Vector2f(10.0, 100.0));

		p2Paddle.setFillColor(sf::Color::Red);
		p2Paddle.setPosition(580.0, 100.0);
		p2Paddle.setSize(sf::Vector2f(10.0, 100.0));

		p1MovingUp = false;
		p1MovingDown = false;
		p2MovingUp = false;
		p2MovingDown = false;

		ballMovement = sf::Vector2f(ballSpeed, ballSpeed);
		font.loadFromFile("arial.ttf");

		p1ScoreText.setPosition(150, 10);
		p1ScoreText.setFont(font);
		p1ScoreText.setString(std::to_string(p1Score));
		p1ScoreText.setColor(sf::Color::Red);
		p1ScoreText.setCharacterSize(24);

		p2ScoreText.setPosition(450, 10);
		p2ScoreText.setFont(font);
		p2ScoreText.setString(std::to_string(p2Score));
		p2ScoreText.setColor(sf::Color::Red);
		p2ScoreText.setCharacterSize(24);
	}
示例#15
0
文件: sfUtil.cpp 项目: Oberon00/jd
void breakTextLines(sf::Text& t, float maxX)
{
    sf::String s = t.getString();
    std::size_t lastBreakCharIdx = s.getSize();
    static sf::String const breakBeforeChars("([{\"'`'");
    static auto const isBreakBeforeChar = [] (sf::Uint32 c) {
        return breakBeforeChars.find(c) != sf::String::InvalidPos;
    };
    for (std::size_t i = 0; i < s.getSize(); ++i) {
        if (t.findCharacterPos(i).x > maxX) {
            if (lastBreakCharIdx > i)
                lastBreakCharIdx = i;
            if (s.getSize() > lastBreakCharIdx &&
                !std::iswgraph(static_cast<std::wint_t>(s[lastBreakCharIdx + 1]))
            ) {
                s[lastBreakCharIdx + 1] = '\n';
            } else {
                s.insert(lastBreakCharIdx + 1, '\n');
            }
            t.setString(s);
            i += 1;
        }
        if (!std::iswalnum(static_cast<std::wint_t>(s[i]))) {
            lastBreakCharIdx = i;
            if (i > 0 && isBreakBeforeChar(s[i]))
                lastBreakCharIdx -= 1;
        }
    }
}
示例#16
0
void origin_from_text(sf::Text text)
{
	
	const sf::FloatRect rectangle{text.getLocalBounds()};
	
	text.setOrigin(0.5f*rectangle.width, 0.95f*rectangle.height);
	
}
	void set_origin()
	{
		
		const sf::FloatRect rectangle{m_text.getLocalBounds()};
		
		m_text.setOrigin(0.5f*rectangle.width, 0.95f*rectangle.height);
		
	}
示例#18
0
文件: Menu.cpp 项目: Coguar/Field964
void _choose_color(sf::Text & text, sf::Vector2f pos, FloatRect & rect){
	if (_select_button(pos, rect)){
		text.setColor(Color::Yellow);
	}
	else {
		text.setColor(Color::Red);
	}
}
示例#19
0
文件: Game.cpp 项目: clavery63/tetris
void Game::prepareText(sf::Text &text, int height)
{
    text.setFont(font);
    text.setCharacterSize(Game::characterSize);
    text.setStyle(sf::Text::Bold);
    text.setColor(sf::Color::White);
    text.setPosition(420, height);
}
示例#20
0
文件: main.cpp 项目: bobrusha/my_game
void getText(sf::Text & txt, sf::Font & font,char* str, int x, int y, int size)
{
	txt.setFont(font); 
	txt.setString(str);
	txt.setColor(sf::Color::Black);
	txt.setPosition(x,y);
	txt.setCharacterSize(size);
}
示例#21
0
void resize(sf::Text& text, float width, float height)
{
    int local_width  = text.getLocalBounds().width;
    int local_height = text.getLocalBounds().height;

    if ((local_width > 0) && (local_height > 0))
        text.setScale(width / local_width, height / local_height);
}
示例#22
0
文件: hud.hpp 项目: K0teu/Squares-War
 void rysuj_tekst( sf::RenderWindow & okno, sf::String _tresc, float x, float y )
 {
     double kamera_xHud = kamera.getCenter().x - kamera.getSize().x/2;
     double kamera_yHud = kamera.getCenter().y - kamera.getSize().y/2;
     tekst.setString( _tresc );
     tekst.setPosition( kamera_xHud + x, kamera_yHud + y );
     okno.draw( tekst );
 }
示例#23
0
文件: hud.hpp 项目: K0teu/Squares-War
 void rysuj_tekst( sf::RenderWindow & okno, sf::Color kolor, sf::String _tresc, float x, float y )
 {
     tekst.setString( _tresc );
     tekst.setColor( kolor );
     tekst.setPosition( x, y );
     okno.draw( tekst );
     tekst.setColor( sf::Color::White );
 }
/**
Text drawing for buttons.
*/
void SpriteManager::draw (sf::Text button_text, int x, int y, int width, int height, sf::RenderWindow &window) {


    button_text.setFont (font);
    sf::FloatRect text_rect = button_text.getLocalBounds ();
    button_text.setPosition ((x + (width / 2)) - (button_text.getLocalBounds ().width / 2), (y + (height / 2)) - (button_text.getLocalBounds ().height));//Centers text to button.

    window.draw (button_text);
}
示例#25
0
void ColorPalette::refresh(void) {
	selected.setFillColor(color);
	label.setColor(color);

	label.setString(ColorPalette::interpret(color, str));

	rgb_c.setOutlineColor(Utility::Color::getInverseColor(color));
	bw_c.setOutlineColor(Utility::Color::getInverseColor(color));
}
示例#26
0
void Menupoint::update(sf::Window& window)
{
	if	(_pos.x <= sf::Mouse::getPosition(window).x &&
	   	 _pos.x + _text.getLocalBounds().width >= sf::Mouse::getPosition(window).x &&
	   	 _pos.y <= sf::Mouse::getPosition(window).y &&
	   	 _pos.y + _text.getLocalBounds().height >= sf::Mouse::getPosition(window).y)
		_text.setColor(sf::Color::Blue);
	else
		_text.setColor(sf::Color::White);
}
示例#27
0
文件: main.cpp 项目: bobrusha/my_game
void youWin (sf::Text & txt, sf::Font & font)
{
	txt.setFont(font); // font is a sf::Font

				// set the string to display
	txt.setString("You win !!!");
	txt.setColor(sf::Color::Black);
	txt.setPosition(100,100);
	txt.setCharacterSize(72);
}
示例#28
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);
}
示例#29
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);
	}
示例#30
0
文件: Menu.cpp 项目: Coguar/Field964
void showMission(Game1 & game, MissionText & mission_text, sf::Text & text, Hero & hero, MenuImg & fon, menuBools & bools)
{
	if (!bools.first_play) {
		switch (hero.player->quest)
		{
		case Player::quest_status::start: text.setString(mission_text.start); break;
		case Player::quest_status::find_car: text.setString(mission_text.find_car); break;
		case Player::quest_status::find_gaz: text.setString(mission_text.find_gaz); break;
		case Player::quest_status::find_busket: text.setString(mission_text.find_buscket); break;
		case Player::quest_status::find_colon: text.setString(mission_text.find_colon); break;
		case Player::quest_status::go_to_car: text.setString(mission_text.go_to_car); break;
		}
		text.setOrigin(text.getLocalBounds().width / 2, 0);
		text.setPosition(fon.sprite->getPosition().x + 220, fon.sprite->getPosition().y - 250);
		text.setColor(Color::Red);
		game.window->draw(text);
	}
	else {
		fon.hand_sprite->setPosition(fon.sprite->getPosition().x + 200, fon.sprite->getPosition().y);
		game.window->draw(*fon.hand_sprite);

	}
	game.aim_sprite->setPosition(game.pos);
	game.window->draw(*game.aim_sprite);
	game.window->display();
}