Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Strikethrough text style #352

Closed
wants to merge 1 commit into from

4 participants

@Foaly

Added a strikethrough text style to sf::Text. Fix for issue #243

@kimci86

The diff is awful.
Pay attention to the end of line character.
https://help.github.com/articles/dealing-with-line-endings

@MarioLiebisch
Collaborator

I'd blame the Github application for Windows (at least that's the reason I think). I've seen this behaviour before, when trying to commit something. At first the changes are shown properly, only the changed lines. But one you committed, the whole file is shown as changed. Using command line git since then without such issues.

@Foaly

Yes you are right! I did use GitHub for Windows and in the client it showed up correctly, but when committing it to GitHub the line endings where wrong. I'll see if I can fix it. Unfortunately my computer crashed shortly afterwards and does bios beeps now... so it might take a little.

@Foaly Foaly Added a strikethrough text style.
Added a strikethrough test style to sf::Text. Fixes issue #243.
06fd036
@Foaly

Ok I think I finally got it! It took quiet some time, but i think everything is right now.

@pdinklag

Looking good!

@Foaly

As I said earlier I had trouble with my computer. In the process of fix it my repositories got messed up bad. I had to delete my fork and start with a fresh copy. I noticed that this commit has a error (comma missing in the enum). I'm now not able to fix that anymore. I was able to set up everything correct and organize things a little better in branches.
So I'm going to close this pull request and open a new clean one. I am sorry about any inconvenience and confusion.

@Foaly Foaly closed this
@Foaly Foaly referenced this pull request
Closed

Strikethrough text style #362

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 17, 2013
  1. @Foaly

    Added a strikethrough text style.

    Foaly authored
    Added a strikethrough test style to sf::Text. Fixes issue #243.
This page is out of date. Refresh to see the latest.
Showing with 59 additions and 28 deletions.
  1. +7 −6 include/SFML/Graphics/Text.hpp
  2. +52 −22 src/SFML/Graphics/Text.cpp
View
13 include/SFML/Graphics/Text.hpp
@@ -55,10 +55,11 @@ public :
////////////////////////////////////////////////////////////
enum Style
{
- Regular = 0, ///< Regular characters, no style
- Bold = 1 << 0, ///< Bold characters
- Italic = 1 << 1, ///< Italic characters
- Underlined = 1 << 2 ///< Underlined characters
+ Regular = 0, ///< Regular characters, no style
+ Bold = 1 << 0, ///< Bold characters
+ Italic = 1 << 1, ///< Italic characters
+ Underlined = 1 << 2 ///< Underlined characters
+ Strikethrough = 1 << 3 ///< Strikethough characters
};
////////////////////////////////////////////////////////////
@@ -308,8 +309,8 @@ private :
/// It inherits all the functions from sf::Transformable:
/// position, rotation, scale, origin. It also adds text-specific
/// properties such as the font to use, the character size,
-/// the font style (bold, italic, underlined), the global color
-/// and the text to display of course.
+/// the font style (bold, italic, underlined or strikethrough), the
+/// global color and the text to display of course.
/// It also provides convenience functions to calculate the
/// graphical size of the text, or to get the global position
/// of a given character.
View
74 src/SFML/Graphics/Text.cpp
@@ -238,11 +238,13 @@ void Text::updateGeometry()
return;
// Compute values related to the text style
- bool bold = (m_style & Bold) != 0;
- bool underlined = (m_style & Underlined) != 0;
- float italic = (m_style & Italic) ? 0.208f : 0.f; // 12 degrees
- float underlineOffset = m_characterSize * 0.1f;
- float underlineThickness = m_characterSize * (bold ? 0.1f : 0.07f);
+ bool bold = (m_style & Bold) != 0;
+ bool underlined = (m_style & Underlined) != 0;
+ bool strikethrough = (m_style & Strikethrough) != 0;
+ float italic = (m_style & Italic) ? 0.209f : 0.f; // 12 degrees
+ float lineThickness = m_characterSize * (bold ? 0.1f : 0.07f);
+ float underlineOffset = m_characterSize * 0.1f;
+ float strikethroughOffset = m_characterSize * 0.4f ;
// Precompute the variables needed by the algorithm
float hspace = static_cast<float>(m_font->getGlyph(L' ', m_characterSize, bold).advance);
@@ -260,24 +262,40 @@ void Text::updateGeometry()
x += static_cast<float>(m_font->getKerning(prevChar, curChar, m_characterSize));
prevChar = curChar;
- // If we're using the underlined style and there's a new line, draw a line
- if (underlined && (curChar == L'\n'))
- {
- float top = y + underlineOffset;
- float bottom = top + underlineThickness;
-
- m_vertices.append(Vertex(Vector2f(0, top), m_color, Vector2f(1, 1)));
- m_vertices.append(Vertex(Vector2f(x, top), m_color, Vector2f(1, 1)));
- m_vertices.append(Vertex(Vector2f(x, bottom), m_color, Vector2f(1, 1)));
- m_vertices.append(Vertex(Vector2f(0, bottom), m_color, Vector2f(1, 1)));
- }
-
// Handle special characters
switch (curChar)
{
- case L' ' : x += hspace; continue;
- case L'\t' : x += hspace * 4; continue;
- case L'\n' : y += vspace; x = 0; continue;
+ case L' ' : x += hspace; continue;
+ case L'\t' : x += hspace * 4; continue;
+ case L'\n' :
+ // If we're using the underlined style and there's a new line, draw a line
+ if(underlined)
+ {
+ float top = y + underlineOffset;
+ float bottom = top + lineThickness;
+
+ m_vertices.append(Vertex(sf::Vector2f(0, top), m_color, Vector2f(1, 1)));
+ m_vertices.append(Vertex(sf::Vector2f(x, top), m_color, Vector2f(1, 1)));
+ m_vertices.append(Vertex(sf::Vector2f(x, bottom), m_color, Vector2f(1, 1)));
+ m_vertices.append(Vertex(sf::Vector2f(0, bottom), m_color, Vector2f(1, 1)));
+ }
+
+ // If we're using the strikethrough style and there's a new line, draw a line across all charcters
+ if (strikethrough)
+ {
+ float top = y - strikethroughOffset;
+ float bottom = top + lineThickness;
+
+ m_vertices.append(Vertex(sf::Vector2f(0, top), m_color, Vector2f(1, 1)));
+ m_vertices.append(Vertex(sf::Vector2f(x, top), m_color, Vector2f(1, 1)));
+ m_vertices.append(Vertex(sf::Vector2f(x, bottom), m_color, Vector2f(1, 1)));
+ m_vertices.append(Vertex(sf::Vector2f(0, bottom), m_color, Vector2f(1, 1)));
+ }
+
+ y += vspace;
+ x = 0;
+ continue;
+
case L'\v' : y += vspace * 4; continue;
}
@@ -307,8 +325,20 @@ void Text::updateGeometry()
// If we're using the underlined style, add the last line
if (underlined)
{
- float top = y + underlineOffset;
- float bottom = top + underlineThickness;
+ float top = y + underlineOffset;
+ float bottom = top + lineThickness;
+
+ m_vertices.append(Vertex(sf::Vector2f(0, top), m_color, Vector2f(1, 1)));
+ m_vertices.append(Vertex(sf::Vector2f(x, top), m_color, Vector2f(1, 1)));
+ m_vertices.append(Vertex(sf::Vector2f(x, bottom), m_color, Vector2f(1, 1)));
+ m_vertices.append(Vertex(sf::Vector2f(0, bottom), m_color, Vector2f(1, 1)));
+ }
+
+ // If we're using the strikethrough style, add the a line across all charcters
+ if (strikethrough)
+ {
+ float top = y - strikethroughOffset;
+ float bottom = top + lineThickness;
m_vertices.append(Vertex(Vector2f(0, top), m_color, Vector2f(1, 1)));
m_vertices.append(Vertex(Vector2f(x, top), m_color, Vector2f(1, 1)));
Something went wrong with that request. Please try again.