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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - DevBug

Pages: [1]
1
Graphics / [Solved] Text Coords and Shape Coords
« on: December 21, 2010, 11:43:00 am »
Quote from: "Laurent"
Yes... but you need to find the code that doesn't produce the expected results. It doesn't help to know that SetPosition and GetPosition work, I already knew that ;)

...


Explain how this works:

Code: [Select]

void SFMLRenderer::DrawText(std::string& text, Point& position) {
    Gum::Base::Size size = MeasureText(text);
    Gum::Base::Rect rect = Gum::Base::Rect(position.x, position.y, 0, 0);
   
    sf::Text sfText = sf::Text(text, sf::Font::GetDefaultFont(), 10);
    sfText.SetColor(m_Color);
    sfText.SetPosition(sf::Vector2f(rect.Left, rect.Top));
    m_pTarget->Draw(sfText);
}


Edit:

I'm starting to think my compiler is messing things up because, this draws perfectly centered text.

Code: [Select]

    Gum::Base::Size size = GetRenderer()->MeasureText(GetCaption());
   
    Gum::Base::Point position;
    position.x = GetGlobalPos().x;
    position.y = GetGlobalPos().y;
   
    position.y += (GetSize().w - size.w) / 2;
    position.x += (GetSize().h - size.h) / 2;
   
    if(m_Pressed) {
        position.x++;
        position.y++;
    }    

2
Graphics / [Solved] Text Coords and Shape Coords
« on: December 21, 2010, 10:37:12 am »
Quote from: "Laurent"
Quote
Here's the problem: sfText.GetPosition() != sf::Vector2f((int)position.x, (int)position.y) always returns false. I'm also using the same position for the rectangle.

:?:
Why is it a problem that the position of the text is equal to what you assigned it?


Because it's drawing in a different position.

3
Graphics / [Solved] Text Coords and Shape Coords
« on: December 21, 2010, 09:59:06 am »
Quote from: "Laurent"
So what's the point of showing me a working piece of code? :P

At least now you have a code that works, that you can compare to yours and see what's different.


Here's the problem: sfText.GetPosition() != sf::Vector2f((int)position.x, (int)position.y) always returns false.  I'm also using the same position for the rectangle.

4
Graphics / [Solved] Text Coords and Shape Coords
« 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

5
Graphics / [Solved] Text Coords and Shape Coords
« 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.

6
Graphics / [Solved] Text Coords and Shape Coords
« on: December 21, 2010, 06:25:01 am »
Wait for Laurent?

7
Graphics / [Solved] Text Coords and Shape Coords
« 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.

8
Graphics / [Solved] Text Coords and Shape Coords
« 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.

9
Graphics / [Solved] Text Coords and Shape Coords
« 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.

10
Graphics / calss not drawing a sprite properly
« on: December 21, 2010, 05:55:06 am »
Are you sure the image is being loaded?

Try this.

Code: [Select]

class Cursor {
public:
Cursor() {
m_Sprite = sf::Sprite(m_Image);
}

Cursor(std::string& path) {
if(!m_Image.LoadFromFile(path)) {
// Exit or do whatever
}

m_Sprite = sf::Sprite(m_Image);
}

virtual ~Cursor() { }

virtual void Draw(sf::Window& Window) {
Window.Draw(m_Sprite);
}

virtual void Update(sf::Window& Window) {
m_Position.x = Window.GetInput().GetMouseX();
m_Position.y = Window.GetInput().GetMouseY();
m_Pressed = Window.GetInput().IsMouseButtonDown(sf::Mouse::Left);

m_Sprite.SetPosition(m_Position);
}

virtual sf::Vector2f GetCursorPosition() { return m_Position; }
virtual float GetCursorX() { m_Position.x }
virtual float GetCursorY() { m_Position.y }
protected:
sf::Image m_Image;
sf::Sprite m_Sprite;
sf::Vector2f m_Position;
bool m_Pressed;
};

class MyCursor : public Cursor {
public:
MyCursor() {
Cursor::Cursor("cursor.png");
}
};


Edit:

Call it like this:

Code: [Select]

int main(int argc, char** argv) {
// Create video mode, window, etc.
MyCursor myCursor = MyCursor();

// Inside the loop
myCursor.Update(myWindow);
myCursor.Draw(myWindow);
}

11
Graphics / [Solved] Text Coords and Shape Coords
« on: December 21, 2010, 05:40:51 am »
Ah, it seems that you and me have the same problem: My thread.

12
Graphics / sf::Text positioning is off?
« on: December 20, 2010, 11:58:17 pm »
I'm having problems with SFML 2.0's sf::Text class.  It seems that the text position is off. It seems to be a problem with the sf::Text class because the rectangle (where the text should be) draws fine.  The positioning error only shows up when my position (x, y) are not a 1:1 ratio.



Code: [Select]

// Inside my gui component
GetRenderer()->DrawText(GetCaption(), Gum::Base::Point(GetGlobalPos().x, GetGlobalPos().y));

// My renderer
void SFMLRenderer::DrawText(std::string& text, Point& position) {
    Gum::Base::Size size = MeasureText(text);
    sf::Text sfText = sf::Text(text, m_Font, 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);
}

Pages: [1]