Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - Xafi

Pages: [1]
1
Window / [sf::Event] problem with mouseMove
« on: June 20, 2014, 01:15:02 pm »
I Have a sf::event named event, then if i do a click  event.mouseMove.x = 0, how do i can get coordinates without problems?

2
SFML website / One subforum for SFML contributions?
« on: November 29, 2013, 01:00:06 pm »
Why not to do One subforum for SFML contributions?

3
SFML projects / [Resource] Little RichText
« on: November 29, 2013, 03:15:17 am »
HI today i did a class to handle sf::text.



I wait tips to optimize

RichText.hpp
/* AUTHOR: XAFI */
#ifndef RICHTEXT_H
#define RICHTEXT_H
#include <SFML/Graphics.hpp>
#include <string>
#include <vector>
class RichText : public sf::Drawable,public sf::Transformable
{
public:
        RichText();
        RichText & operator << (const std::string&);
        RichText & operator << (const sf::Color&);
        RichText & operator << (const sf::Uint32);

        void setFont(const sf::Font &);
        void setCharacterSize(int);
        void setColor(int, sf::Color);
        void setString(int, std::string);
        void Clear();
       
        sf::Vector2f getSize() const;
        const std::string getString();
        int getCharacterSize();

private:
        void draw(sf::RenderTarget& target, sf::RenderStates states) const;
        void UpdatePos() const;
        mutable std::vector<sf::Text> Text;
        sf::Color LastColor;
        sf::Uint32 LastStyle;
        mutable sf::Vector2f Size;



};

#endif //RICHTECT_H
 
RichText.cpp
/* AUTHOR: XAFI */

#include "RichText.h"

RichText::RichText() :
        LastColor(sf::Color::White),
        LastStyle(sf::Text::Style::Regular)


{
}

RichText & RichText::operator << (const std::string& string)
{
        sf::Text t;
        t.setString(string);
        t.setColor(LastColor);
        t.setStyle(LastStyle);
        Text.push_back( t );
        return *this;
}
RichText & RichText::operator << (const sf::Color &color)
{
        LastColor = color;
        return *this;
}

RichText & RichText::operator << (const sf::Uint32 style)
{
        LastStyle = style;
        return *this;
}

void RichText::setFont(const sf::Font& font)
{
        for (std::vector<sf::Text>::iterator it = Text.begin(); it != Text.end(); ++it)
        {
                it->setFont(font);
        }
}

void RichText::draw(sf::RenderTarget &target, sf::RenderStates states) const
{
        UpdatePos();
        states.transform *= getTransform();
        for (std::vector<sf::Text>::const_iterator it = Text.begin(); it != Text.end(); ++it)
        {
                target.draw(*it, states);
        }
}
void RichText::setCharacterSize(int size)
{
        for (std::vector<sf::Text>::iterator it = Text.begin(); it != Text.end(); ++it)
        {
                it->setCharacterSize(size);
        }
}
const std::string RichText::getString()
{
        std::string tmp;
        for (std::vector<sf::Text>::iterator it = Text.begin(); it != Text.end(); ++it)
        {
                tmp += it->getString().toAnsiString();
        }
        return tmp;
}
void RichText::UpdatePos() const
{
        int x = 0;
        for (std::vector<sf::Text>::iterator it = Text.begin(); it != Text.end(); ++it)
        {
                x += it->getLocalBounds().width;
                it->setPosition(x - it->getLocalBounds().width, 0);
        }
        Size.x = x;
}
void RichText::setColor(int index, sf::Color color)
{
        Text[index].setColor(color);
}
void RichText::setString(int index, std::string string)
{
Text[index].setString(string);
}
void RichText::Clear()
{
        LastColor = sf::Color::White;
        LastStyle = sf::Text::Style::Regular;
        Text.erase(Text.begin(), Text.end());
}
sf::Vector2f RichText::getSize() const
{
        return Size;
}

int RichText::getCharacterSize()
{
        return Text[0].getCharacterSize();
}
 


4
Graphics / RenderWindow low graphics quality (Help please)
« on: February 04, 2012, 12:51:18 am »
Hi. i have a problem. The graphics of my window are low quality. why is this?
look at this
http://imageshack.us/photo/my-images/848/77830113.png/

Bye i wait a answer :)

Pages: [1]