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

Author Topic: [Solved] Text Coords and Shape Coords  (Read 10193 times)

0 Members and 1 Guest are viewing this topic.

Wander

  • Full Member
  • ***
  • Posts: 170
    • View Profile
    • Email
[Solved] Text Coords and Shape Coords
« on: December 21, 2010, 05:11:55 am »
I am making a class that creates buttons in SFML. I have been having a problem for about a month now. The problem is that the text won't position inside of the outlining box.

After much trial and error I have figured out why it won't match up.
It seems to me that the sf::Shape class and the sf::String class are positioned on separate coordinate planes or move at different interval factor per one coordinate (e.g. 1 sf::Shape coordinate = 0.5 sf::String coordinates).

If anyone knows how to fix this I would love some help. I'm about ready to pull my hair out at this. Thank you. :)[/b]
-Wander

DevBug

  • Newbie
  • *
  • Posts: 12
    • View Profile
[Solved] Text Coords and Shape Coords
« Reply #1 on: December 21, 2010, 05:40:51 am »
Ah, it seems that you and me have the same problem: My thread.

Wander

  • Full Member
  • ***
  • Posts: 170
    • View Profile
    • Email
[Solved] Text Coords and Shape Coords
« Reply #2 on: December 21, 2010, 05:48:22 am »
Okay, but how do I fix it?
-Wander

DevBug

  • Newbie
  • *
  • Posts: 12
    • View Profile
[Solved] Text Coords and Shape Coords
« Reply #3 on: December 21, 2010, 06:00:30 am »
What version of SFML are you using? Maybe a new revision changed something. I take that you're using 1.6, I'm using 2.0 and it has the same problem.

Wander

  • Full Member
  • ***
  • Posts: 170
    • View Profile
    • Email
[Solved] Text Coords and Shape Coords
« Reply #4 on: December 21, 2010, 06:01:14 am »
1.6
-Wander

DevBug

  • Newbie
  • *
  • Posts: 12
    • View Profile
[Solved] Text Coords and Shape Coords
« Reply #5 on: December 21, 2010, 06:08:04 am »
I saw no obvious errors in a run through.  However, I've got suspicions of Glyphs though.

Wander

  • Full Member
  • ***
  • Posts: 170
    • View Profile
    • Email
[Solved] Text Coords and Shape Coords
« Reply #6 on: December 21, 2010, 06:15:36 am »
whats that?
-Wander

DevBug

  • Newbie
  • *
  • Posts: 12
    • View Profile
[Solved] Text Coords and Shape Coords
« Reply #7 on: December 21, 2010, 06:19:23 am »
A single character from a font.  I've found something intriguing: It seems like the text is rendered at 0; I can't find any references to the current position of the text.

Edit:

It seems that everything is translated with the matrix (makes sense, SFML uses OpenGL).

Edit:

There is no derived GetMatrix so I don't know.

Wander

  • Full Member
  • ***
  • Posts: 170
    • View Profile
    • Email
[Solved] Text Coords and Shape Coords
« Reply #8 on: December 21, 2010, 06:22:42 am »
so do you have any ideas on how to fix this? :/
-Wander

DevBug

  • Newbie
  • *
  • Posts: 12
    • View Profile
[Solved] Text Coords and Shape Coords
« Reply #9 on: December 21, 2010, 06:25:01 am »
Wait for Laurent?

Wander

  • Full Member
  • ***
  • Posts: 170
    • View Profile
    • Email
[Solved] Text Coords and Shape Coords
« Reply #10 on: December 21, 2010, 06:28:23 am »
hahaha im confused
-Wander

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
[Solved] Text Coords and Shape Coords
« Reply #11 on: December 21, 2010, 07:38:28 am »
I need a minimal and complete code that I can test please.

Be careful with SFML 1.6, if you use scales things might be offseted.
Laurent Gomila - SFML developer

DevBug

  • Newbie
  • *
  • Posts: 12
    • View Profile
[Solved] Text Coords and Shape Coords
« Reply #12 on: December 21, 2010, 09:10:32 am »
This is quite odd, we are both getting the same problem. Yet when I try to produce the error with minimal code it doesn't show up.  Compiler error maybe? It might have to do with the way I'm drawing text: I'm creating my sf::Text inside a loop (which is called through multiple functions).

Here's the minimal code:
Code: [Select]

#include <string>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>

int main() {
    sf::RenderWindow Window(sf::VideoMode(800, 600), "SFML");
   
    sf::Event Event;
    while(Window.IsOpened()) {
        while(Window.GetEvent(Event)) {
            if(Event.Type == sf::Event::Closed) {
                Window.Close();
                break;
            }
        }
       
        Window.Clear();
       
        sf::Shape rTest = sf::Shape::Rectangle(10, 235, 32, 32, sf::Color(255, 255, 255, 255));
        sf::Text tTest = sf::Text("My First Button", sf::Font::GetDefaultFont(), 10);
        tTest.SetColor(sf::Color(172, 172, 172, 255));
        tTest.SetPosition(sf::Vector2f(10, 235));

        Window.Draw(rTest);
        Window.Draw(tTest);
       
        Window.Display();
    }
   
    return EXIT_SUCCESS;
}


Here is what I'm doing to draw text and debug, etc.

Code: [Select]

void SFMLRenderer::DrawRectangle(Rect& rect) {
    sf::Shape sfRect = sf::Shape::Rectangle(rect.Left, rect.Top, rect.Width, rect.Height, m_Color);
    m_pTarget->Draw(sfRect);
}

void SFMLRenderer::DrawText(std::string& text, Point& position) {
    Gum::Base::Size size = MeasureText(text);
    sf::Text sfText = sf::Text(text, sf::Font::GetDefaultFont(), 10);
    sfText.SetPosition(sf::Vector2f((int)position.x, (int)position.y));

    DrawRectangle(Gum::Base::Rect(position.x, position.y, size.w, size.h));
    m_pTarget->Draw(sfText);
}


Edit I've added this in my DrawText:

Code: [Select]

if(sfText.GetPosition() != sf::Vector2f((int)position.x, (int)position.y)) {
        printf("!=\n");
}


Nothing in the console.  This is really weird.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
[Solved] Text Coords and Shape Coords
« Reply #13 on: December 21, 2010, 09:17:42 am »
Quote
Yet when I try to produce the error with minimal code it doesn't show up
[...]
Here's the minimal code

So to be clear, does this minimal code produce the bug or not?
Laurent Gomila - SFML developer

DevBug

  • Newbie
  • *
  • Posts: 12
    • View Profile
[Solved] Text Coords and Shape Coords
« Reply #14 on: December 21, 2010, 09:18:55 am »
Sadly no, but I don't understand how my code is producing the error (if the rectangle is drawing in the correct position).

Edit:

Here's my project that I'm working on (it has the error).

https://github.com/mtwilliams/World-of-Mana