skyrpex / richtext Goto Github PK
View Code? Open in Web Editor NEWRich text class for SFML2. Allows the user to draw lines of text with different styles and colors.
License: Other
Rich text class for SFML2. Allows the user to draw lines of text with different styles and colors.
License: Other
With one of the newer SFML 2.x version (iirc 2.4) the sf::Text
class received outline support. Would be nice if RichText could make use of this. Additionally, setColor
has been deprecated in favor of setFillColor
in order to differentiate between fill and outline coloring.
Such a change would bumped the minimum required SFML version to something like 2.4.
This is more of a question to the developer than an issue per say:
From my current understanding, a RichText is a matrix, two dimensional vector, of Texts. If my belief is true, which it could certainly be false, I should in theory be able to print individual vectors separately. Is there any way to do this?
Say I want all r's to be red, and all b's to be blue, and c's indicate carriage returns. Could I do the following:
rbbbbbrc
rrbbrrrrc
bbbbbbc
... and so on.
I figure since there's a .setCharacterColor, each character must be it's own Text?
Also, since you have a class for each line, I should be able to print lines individually?
Thank you for your time!
Here's my error:
Unhandled exception at 0x0FAA49EF (sfml-graphics-d-2.dll) in SFMLGameStates2.exe: 0xC0000005: Access violation reading location 0xCCCCCCD0. occurred
It occurs in RichText.hpp in RichText::Line::draw()
, so I don't know what I'm doing wrong.
Hi, excellent work.
I am writing a textbox for my program and all works smoothly except now I want to be able to add a line break to the text when I press the return key. I've tried doing: enteredRaw.push_back("\\n");
when return key is pressed, all elements from enteredRaw get put into a string s and used like thus:
sfe::RichText text(font);
text << sf::Text::Regular << sf::Color::Black << s;
however the rendered string is on the same line
When checking the output of the string and even what is rendered on screen, both have "\n" in them, so what am I doing wrong?
Use typedef to define de collection type, so it's easy to change, as Hiura suggested here.
Wouldn't vector be more efficient here (instead of list) ? (Insertion is only at the end so it's should be O(1) most of the time, and > iteration is quite frequent in this class so it should be faster with continuous memory.) I know that at this scale it doesn't really > matter which collection you use but it's a good programming practice.
On the style level, using a typedef std::somecollectionsf::Text CollectionType; would allow changing the collection in one line editing.
There is a graphic problem with the '\n' character. The logic doesn't handle new lines.
The following code shows an unexpected behavior with spaces : text2
is printed as "ab" instead of "a b". (Well, it seems that GitHub has also a bug with spaces... See picture below to get the idea).
#include "RichText.hpp"
#include <SFML/Graphics.hpp>
int main()
{
sfe::RichText text;
text << "a b";
sfe::RichText text2;
text2 << "a " << "b";
text.setCharacterSize(25);
text.setPosition(100, 100);
text2.setCharacterSize(25);
text2.setPosition(100, 125);
sf::RenderWindow window;
window.create(sf::VideoMode(400, 300), "Rich text");
while(window.isOpen())
{
sf::Event event;
while(window.pollEvent(event))
{
if(event.type == sf::Event::Closed || (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape))
window.close();
}
window.clear();
window.draw(text);
window.draw(text2);
window.display();
}
}
Both lines (i.e., both text
and text2
) should display the same.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.