SFML community forums
Help => Graphics => Topic started by: didito on October 14, 2009, 04:52:21 pm
-
hello,
i was wondering why some of my instanced sf::Strings were not working,
because i ran into some unexpected behavior.
*) what i want to do:
i want to copy a sf::string
*) this is what i was doing (should work IMHO, but does NOT)
sf::Font font;
//font gets loaded ... OK
sf::String label1;
label1.SetFont(font);
//rest of setup (color, style, size) and transformation ... OK
sf::String label2 = label1; //assuming all attributes get copied - NOT WORKING!
//just setup unique attributes of label2 ...
sf::String label3(label1); //assuming the same - NOT WORKING!
//setup unique attributes of label3 here ...
*) this is how i should do it in order to get it working
sf::Font font;
//font gets loaded ... OK
sf::String label1;
label1.SetFont(font);
//rest of setup (color, style, size) and transformation ... OK
//A - WORKS OK
sf::String label2;
label2.SetFont(font);
label2.SetSize(size);
//B - WORKS OK
sf::String label3("", font, size);
ok, i could use A and B, but wouldn't it be more natural to just copy it?
it seems like a problem with the copy ctor or copy assignment operator.
and i don't see a problem why this should not be working.
the font reference should be a shallow copy, the content a deep copy
and all the POD-like attributes can be copied easily anyway.
btw, as a kind of little request - what about a TextFormat class?
you can assign font, style, size, etc and assign it to different sf::Strings (which only hold the string content and a reference to this format).
this would save us a lot of typing and nice OO design :)
cheers, didi
-
Copying a sf::String works like a charm. Can you show a complete code that reproduces your problem?
btw, as a kind of little request - what about a TextFormat class?
you can assign font, style, size, etc and assign it to different sf::Strings (which only hold the string content and a reference to this format).
this would save us a lot of typing and nice OO design
Copying from another string will have the same effect as assigning a Textformat (except that the text would be copied as well).
-
believe me, it does not work here. i am sitting in front of the code.
and what do you mean, i already have posted the code?!?
maybe it has something to do with the problem of not being able to create/load a font before the opengl-context (i ran into that one before).
should i create SFML objects in any specific order?
btw, i am using a revision of SFML 1.5 (or 1.6?) on mac.
-
believe me, it does not work here. i am sitting in front of the code.
I believe you, but I'm not sure it is as simple as the copy constructor failing. All the members are directly copyable, and I let the compiler generate the copy constructor for me. So I think it might be a side effect of another error in your program.
and what do you mean, i already have posted the code?!?
I saw your code, but I want a complete one that I can copy, paste, compile and test directly ;)
maybe it has something to do with the problem of not being able to create/load a font before the opengl-context (i ran into that one before).
should i create SFML objects in any specific order?
No, there's no constraint about the order of initialization in SFML.
btw, i am using a revision of SFML 1.5 (or 1.6?) on mac.
Which revision?