Got it!
This may not be minimal, but it may be short enough: (Compile with SFML 2.0)
#include <Windows.h>
#include <SFML/Graphics.hpp>
class style
{
public:
sf::Font Font;
int fs;
sf::Vector2f pos;
style()
: Font(sf::Font::GetDefaultFont()),fs(30),pos(sf::Vector2f(0.f,0.f))
{
}
};
class btn
{
public:
btn(std::string txt)
{
MyValue = sf::Text(txt,st.Font,st.fs);
}
void up()
{
MyValue.SetFont(st.Font);
MyValue.SetCharacterSize(st.fs);
MyValue.SetPosition(st.pos);
}
void add(std::string txt,int at)
{
std::string t=MyValue.GetString();
t.insert(at,txt);
MyValue.SetString(t);
}
void render(sf::RenderTarget* rt)
{
rt->Draw(MyValue);
}
style st;
private:
sf::Text MyValue;
};
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nShowCommand)
{
sf::RenderWindow App(sf::VideoMode(800,600),"Text Bug");
btn b1("Btn1");
b1.st.fs = 35;
b1.st.pos.x = 100;
b1.up();
btn b2("Btn2");
b2.st.fs = 25;
b2.st.pos.x = 400;
b2.up();
btn b3("Btn3");
b3.st.fs = 20;
b3.st.pos.x = 700;
b3.up();
while(App.IsOpened())
{
sf::Event e;
while (App.GetEvent(e))
{
std::string txt = " ";
switch(e.Type)
{
case sf::Event::Closed:
App.Close();
break;
case sf::Event::TextEntered:
txt[0] = (char)e.Text.Unicode;
b2.add(txt,2);
}
}
App.Clear();
b1.render(&App);b2.render(&App);b3.render(&App);
App.Display();
}
return 0;
}
bye,
CBenni::O