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

Author Topic: Creating a window in a window.  (Read 4485 times)

0 Members and 1 Guest are viewing this topic.

Lolilolight

  • Hero Member
  • *****
  • Posts: 1232
    • View Profile
Creating a window in a window.
« on: February 15, 2015, 09:34:03 am »
Hi!

I need to create a window in a window for my game. (Confirmation and message dialogs.)

So I've just created this class :

OptionPane::OptionPane(math::Vec3f position, math::Vec3f size, const Font* font, sf::String t, TYPE type) :
                LightComponent (position, size, size * 0.5f, false),
                rw (sf::VideoMode(size.x, size.y), "Option Pane", sf::Style::Default, sf::ContextSettings(0, 0, 4, 3, 0)),
                type(type) {
                rw.getView().move(size.x * 0.5f, size.y * 0.5f, size.z * 0.5f);
                if (type == CONFIRMATION_DIALOG) {
                    yes = new Button(math::Vec2f(size.x / 100 * 70, size.y - 100), math::Vec2f(100, 50), font, "Yes", rw);
                    no = new Button(math::Vec2f(size.x / 100 * 10, size.y - 100), math::Vec2f(100, 50), font, "No", rw);
                    core::FastDelegate<bool> trigger1(&Button::isMouseInButton, yes);
                    core::FastDelegate<bool> trigger2(&Button::isMouseInButton, no);
                    core::FastDelegate<void> slot1(&OptionPane::onYesOption, this);
                    core::FastDelegate<void> slot2(&OptionPane::onNoOption, this);
                    core::Action a (core::Action::MOUSE_BUTTON_PRESSED_ONCE,sf::Mouse::Left);
                    core::Command cmd1 (a, trigger1, slot1);
                    core::Command cmd2 (a, trigger2, slot2);
                    getListener().connect("YESOPTION", cmd1);
                    getListener().connect("NOOPTION", cmd2);
                } else {
                    yes = nullptr;
                    no = nullptr;
                    core::Action a (core::Action::KEY_PRESSED_ONCE, sf::Keyboard::Return);
                    core::FastDelegate<void> slot(&OptionPane::onEnter, this);
                    core::Command cmd (a, slot);
                    getListener().connect("ONENTER", cmd);
                }
                rw.setPosition(sf::Vector2i(position.x, position.y));
                option = UNDEFINED;
                text.setFont(*font);
                text.setString(t);
                text.setColor(sf::Color::Black);
                text.setPosition(math::Vec3f(10, 10, position.z));
                text.setSize(size);
                backgroundColor = sf::Color::White;
            }
            void OptionPane::onVisibilityChanged(bool visible) {
                rw.setVisible(visible);
            }
            OptionPane::OPTION OptionPane::getOption() {
                OPTION choosenOption = option;
                option = UNDEFINED;
                return choosenOption;
            }
            void OptionPane::clear() {
                rw.clear(backgroundColor);
            }
            void OptionPane::draw(RenderTarget& target, RenderStates states) {
                if (rw.isOpen()) {
                    rw.draw(text, states);
                    if (type == CONFIRMATION_DIALOG)  {
                        rw.draw(*yes, states);
                        rw.draw(*no, states);
                    }
                    rw.display();
                }
            }
            void OptionPane::update() {
                sf::Event event;
                while(rw.pollEvent(event)) {
                    if (event.type == sf::Event::Closed) {
                        rw.setVisible(false);
                    }
                    getListener().pushEvent(event);
                }
            }
            void OptionPane::onEnter() {
                setVisible(false);
                setEventContextActivated(false);
                rw.setVisible(false);
            }
            void OptionPane::onYesOption() {
                rw.setVisible(false);
                setEventContextActivated(false);            
                option = YES_OPTION;
            }
            void OptionPane::onNoOption() {
                rw.setVisible(false);
                setEventContextActivated(false);            
                option = NO_OPTION;
            }
            void OptionPane::setText(std::string t) {
                text.setString(sf::String(t.c_str()));
            }
            OptionPane::~OptionPane() {
                rw.close();
                if (CONFIRMATION_DIALOG) {
                    delete yes;
                    delete no;
                }
            }
 

It works fine except for one point, here, I want to create two sub-windows :

m_pseudoUsed = new gui::OptionPane(Vec2f(200, 200), Vec2f(200, 100), fm.getResourceByAlias("FreeSerif"),"Pseudo already used!",gui::OptionPane::TYPE::MESSAGE_DIALOG);
    m_pseudoUsed->setVisible(false);
    m_pseudoUsed->setEventContextActivated(false);
    m_confirmInvitation = new gui::OptionPane(Vec2f(200, 200), Vec2f(200, 100), fm.getResourceByAlias("FreeSerif"),"",gui::OptionPane::TYPE::CONFIRMATION_DIALOG);
    m_confirmInvitation->setVisible(false);
    m_confirmInvitation->setEventContextActivated(false);
 

I set the visibility of my sub-windows to false, so the windows shouldn't be shown, but it's not what I see.

I see a transparent window on the main window, and the title is not always the title of my sub-windows..., this is really strange. :/
« Last Edit: February 15, 2015, 09:40:25 am by Lolilolight »

Lolilolight

  • Hero Member
  • *****
  • Posts: 1232
    • View Profile
[SFML 2.2] Re: Creating a window in a window. (On ubuntu 14.4)
« Reply #1 on: February 15, 2015, 09:47:31 am »
And here is a code which repoduce the bug :

int main()
{  
    RenderWindow window(sf::VideoMode(800, 600), "OpenGL");  
    RenderWindow window1(sf::VideoMode(200, 100), "test");
    window1.setVisible(false);
    RenderWindow window2(sf::VideoMode(200, 100), "test2");
    window2.setVisible(false);
    while (window.isOpen())
    {
        sf::Event event;
        while(window.pollEvent(event)) {
              if (event.type == sf::Event::Closed)
                    window.close();
        }
        window.clear();
        window.display();
    }
    return 0;
 

The second window is visible. :/ (The window which the title "test2")

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: Creating a window in a window.
« Reply #2 on: February 15, 2015, 11:52:46 am »
does this works ?

#include <SFML/Graphics.hpp>
using namespace sf;

int main()
{
    RenderWindow window(sf::VideoMode(800, 600), "OpenGL");
    RenderWindow window1(sf::VideoMode(500, 100), "test");
    RenderWindow window2(sf::VideoMode(500, 100), "test2");

    bool once = true;

    while (window.isOpen())
    {
        sf::Event event;
        while(window.pollEvent(event)) {
            if (event.type == sf::Event::Closed)
                window.close();
        }
        while(window1.pollEvent(event)) {
            if (event.type == sf::Event::Closed)
                window1.close();
        }
        while(window2.pollEvent(event)) {
            if (event.type == sf::Event::Closed)
                window2.close();
        }

        if (once) {
            window1.setVisible(false);
            window2.setVisible(false);
            once = false;
        }

        window.clear();
        window.display();
    }
    return 0;
}
 
SFML / OS X developer

Lolilolight

  • Hero Member
  • *****
  • Posts: 1232
    • View Profile
Re: Creating a window in a window.
« Reply #3 on: February 16, 2015, 09:40:07 am »
Quote
does this works ?

No.  :'(
« Last Edit: February 16, 2015, 09:42:44 am by Lolilolight »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Creating a window in a window.
« Reply #4 on: February 16, 2015, 10:16:41 am »
OS? Version of SFML?
Laurent Gomila - SFML developer

Lolilolight

  • Hero Member
  • *****
  • Posts: 1232
    • View Profile
Re: Creating a window in a window.
« Reply #5 on: February 16, 2015, 02:54:27 pm »
OS version : Ubuntu LTS 14.4 (64 bits)

SFML version : SFML-master (the one from the git repository)

I've also tried with the last stable version but same problem.

Mr_Blame

  • Full Member
  • ***
  • Posts: 192
    • View Profile
    • Email
Re: Creating a window in a window.
« Reply #6 on: February 24, 2015, 07:21:54 pm »
Most easy way (if your using win32 and sfml 2.x) you can handle sf::RenderWindow to a HWND window and call message boxes for HWND window and make parent windows and in the same window draw sfml! Cool!
« Last Edit: February 24, 2015, 07:23:52 pm by Mr_Blame »

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Creating a window in a window.
« Reply #7 on: February 24, 2015, 09:46:17 pm »
Most easy way (if your using win32 and sfml 2.x) you can handle sf::RenderWindow to a HWND window and call message boxes for HWND window and make parent windows and in the same window draw sfml! Cool!
How is that helpful? He is not using win32 - he explicitly states that he's using  Ubuntu LTS 14.4  ...

Lolilolight

  • Hero Member
  • *****
  • Posts: 1232
    • View Profile
Re: Creating a window in a window.
« Reply #8 on: March 13, 2015, 04:52:53 pm »
Arf..., linux doesn't seems to be very appropriate to create more complex api. :/ (Or is  it SFML fault ?)

Now, I receive a keyreleased event even if I don't release a key, this is very annoying, I think this is related to the first bug because I don't have this problem with a single window.

And when I want to put the code to render into a thread (because the rendering time is too long with mesa opensource driver) I get the this non-sense error that I haven't called XinitThread but I've done it.

I think I'll use SDL instead of SFML to get rid of this bugs with the SFML window module but I don't know if it's possible to use opengl function manually after creating an SDL window, last time I tried the opengl function wheren't not executed.








 

anything