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

Author Topic: How to move window without title bar  (Read 4302 times)

0 Members and 1 Guest are viewing this topic.

reDo

  • Full Member
  • ***
  • Posts: 104
    • View Profile
How to move window without title bar
« on: August 14, 2011, 06:57:55 pm »
Hi, I am creating a little program and I am using window without titlebar, but I wanna move it, can you please tell me how can I do it? because this code doesnt work. It put window in the top of the left corner and near it but no elsewhere.  :roll:

Code: [Select]

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

int main()
{
    sf::RenderWindow App(sf::VideoMode(103,31),"Keygen",sf::Style::None);

    sf::Image images[4];
    images[0].LoadFromFile("keygen.png");
    images[1].LoadFromFile("textbox.png");
    images[2].LoadFromFile("generate.png");
    images[3].LoadFromFile("exit.png");
    sf::Sprite sprites[4];
    for(int i=0;i<4;i++)
    {
        images[i].SetSmooth(false);
        sprites[i].SetImage(images[i]);
    }
    sprites[1].SetPosition(6,6);
    sprites[2].SetPosition(31,16);
    sprites[3].SetPosition(75,16);

    bool move = false;
    while(App.IsOpened())
    {
        sf::Event Event;
        App.GetEvent(Event);

        if(!move)
            if(App.GetInput().IsMouseButtonDown(sf::Mouse::Left))
                move = true;

        if(move && App.GetInput().IsMouseButtonDown(sf::Mouse::Left))
            App.SetPosition(App.GetInput().GetMouseX()-51,App.GetInput().GetMouseY()-15);

        else
            move = false;

        App.Clear();
        App.Draw(sprites[0]);

        int mx = App.GetInput().GetMouseX();
        int my = App.GetInput().GetMouseY();
        if(mx >= 6 && mx <= 96 && my >= 6 && my <= 14)
            App.Draw(sprites[1]);
        else if(mx >= 31 && mx <= 73 && my >= 16 && my <= 24)
            App.Draw(sprites[2]);
        else if(mx >= 75 && mx <= 96 && my >= 16 && my <= 24)
        {
            App.Draw(sprites[3]);
            if((Event.Type == sf::Event::MouseButtonPressed) && (Event.MouseButton.Button == sf::Mouse::Left))
                App.Close();
        }

        App.Display();
        sf::Sleep(0.010);
    }

    return 0;
}

Haikarainen

  • Guest
How to move window without title bar
« Reply #1 on: August 15, 2011, 01:02:42 am »
You should wait until GetWindowPosition~ method is implemented.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
How to move window without title bar
« Reply #2 on: August 15, 2011, 10:35:36 am »
sf::Mouse::GetPosition(), which retrieves desktop mouse coordinates, should be enough to implement it. It is available in SFML 2.
Laurent Gomila - SFML developer

reDo

  • Full Member
  • ***
  • Posts: 104
    • View Profile
How to move window without title bar
« Reply #3 on: August 15, 2011, 12:33:56 pm »
Thanks Laurent  :D  I did it this way
Code: [Select]
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>

int main()
{
    sf::RenderWindow App(sf::VideoMode(103,31),"Keygen",sf::Style::None);

    sf::Texture images[4];
    images[0].LoadFromFile("keygen.png");
    images[1].LoadFromFile("textbox.png");
    images[2].LoadFromFile("generate.png");
    images[3].LoadFromFile("exit.png");
    sf::Sprite sprites[4];
    for(int i=0;i<4;i++)
    {
        sprites[i].SetTexture(images[i]);
    }
    sprites[1].SetPosition(6,6);
    sprites[2].SetPosition(31,16);
    sprites[3].SetPosition(75,16);

    bool move = false;
    bool button = false;
    while(App.IsOpened())
    {
        sf::Event Event;
        App.PollEvent(Event);

        App.Clear();
        App.Draw(sprites[0]);

        int mx = sf::Mouse::GetPosition(App).x;
        int my = sf::Mouse::GetPosition(App).y;

        if(mx >= 6 && mx <= 96 && my >= 6 && my <= 14)
            App.Draw(sprites[1]);
        else if(mx >= 31 && mx <= 73 && my >= 16 && my <= 24)
        {
            App.Draw(sprites[2]);
            button = true;
        }
        else if(mx >= 75 && mx <= 96 && my >= 16 && my <= 24)
        {
            App.Draw(sprites[3]);
            if((Event.Type == sf::Event::MouseButtonPressed) && (Event.MouseButton.Button == sf::Mouse::Left))
                App.Close();
            button = true;
        }

        else
            button = false;

        App.Display();

        if(move && button == false)
            App.SetPosition(sf::Mouse::GetPosition().x-51,sf::Mouse::GetPosition().y-10);

        if((Event.Type == sf::Event::MouseButtonPressed) && (Event.MouseButton.Button == sf::Mouse::Left))
            move = true;

        if((Event.Type == sf::Event::MouseButtonReleased) && (Event.MouseButton.Button == sf::Mouse::Left))
            move = false;

        sf::Sleep(0.010);
    }

    return 0;
}

 

anything