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 - xumepoc

Pages: [1] 2 3 4
1
Window / Re: MFC and SFML Window problem
« on: May 01, 2014, 11:08:54 pm »
Well what do you know, the latest beta worked :D Thanks Ixrec

2
Window / Re: MFC and SFML Window problem
« on: May 01, 2014, 10:36:03 pm »
Thanks will try compile the latest.

3
Window / Re: MFC and SFML Window problem
« on: May 01, 2014, 12:20:46 pm »
Well I overcome the problem for now, I delete the MyCanvas and recreate it again on end of resize. Not the best solution, but for now it works...

Now I have another problem. If I have a QDilaog or QWidget object in nonmodal on top of the SFML window I can't get back the focus of the mouse on that  object. The focus stays on the SFML. Interesting that the mouse wheel works at is should be, but the other functions (mouse move/click) are never send to the object. Always stay on the SFML.

Any solutions on that?

4
Window / Re: MFC and SFML Window problem
« on: April 21, 2014, 06:28:42 pm »
I can't make more minimal code then this in order to reproduce the problem. ??? :-[

5
Window / Re: MFC and SFML Window problem
« on: April 18, 2014, 08:47:24 am »
Bump ;D  ::)

6
Window / Re: MFC and SFML Window problem
« on: April 16, 2014, 05:18:21 pm »
Here is the code

sfmlcanvas.h
#ifndef QSFMLCANVAS_H
#define QSFMLCANVAS_H

#include <QWidget>
#include <SFML/Graphics.hpp>
#include <QTimer>

class QSFMLCanvas : public QWidget, public sf::RenderWindow
{
    //Q_OBJECT
public:
    explicit QSFMLCanvas(QWidget *parent, const QPoint& Position, const QSize& Size, unsigned int FrameTime = 1);
    virtual void showEvent(QShowEvent*);
    virtual QPaintEngine* paintEngine() const;
    virtual void paintEvent(QPaintEvent*);

    virtual ~QSFMLCanvas();
    virtual void OnInit();
    virtual void OnUpdate();
private:
    QTimer myTimer;
    bool myInitialized;
    HWND _hWND;

protected:
    virtual void resizeEvent(QResizeEvent * event );
};

#endif // QSFMLCANVAS_H
 

sfmlcanvas.cpp
void QSFMLCanvas::showEvent(QShowEvent*)
{
    if (!myInitialized)
    {
        // Under X11, we need to flush the commands sent to the server to ensure that
        // SFML will get an updated view of the windows
#ifdef Q_WS_X11
        //XFlush(QX11Info::display());
#endif
        // Create the SFML window with the widget handle
        _hWND = sf::WindowHandle( winId());
        RenderWindow::create(_hWND);

        // Let the derived class do its specific stuff
        OnInit();

        // Setup the timer to trigger a refresh at specified framerate
        connect(&myTimer, SIGNAL(timeout()), this, SLOT(repaint()));
        myTimer.start();
        myInitialized = true;
    }
}
QPaintEngine* QSFMLCanvas::paintEngine() const
{
    return 0;
}
void QSFMLCanvas::paintEvent(QPaintEvent*)
{
    // Let the derived class do its specific stuff
    OnUpdate();

    // Display on screen
    display();
}
void QSFMLCanvas::OnInit() {}
void QSFMLCanvas::OnUpdate() {}

void QSFMLCanvas::resizeEvent(QResizeEvent *event){}
 
mycanvas.h
#ifndef MYCANVAS_H
#define MYCANVAS_H

#include "qsfmlcanvas.h"
#include <SFML/Graphics.hpp>
class MyCanvas : public QSFMLCanvas
{
public :
    MyCanvas(QWidget* Parent, const QPoint& Position, const QSize& Size);
    void OnInit();
    void OnUpdate();
    void resizeEvent(QResizeEvent *event);
private :
    sf::Clock myClock;
    sf::RectangleShape rect;
    sf::Font font;
    sf::Text text;
};

#endif // MYCANVAS_H

mycanvas.cpp
#include "mycanvas.h"
#include <iostream>
#include <string>
#include <QDir>
#include <QWheelEvent>
#include <qdebug.h>

MyCanvas::MyCanvas(QWidget* Parent, const QPoint& Position, const QSize& Size) : QSFMLCanvas(Parent, Position, Size)
{
}
void MyCanvas::OnInit()
{
    myClock.restart();
}
void MyCanvas::OnUpdate()
{
    // Clear screen
    clear(sf::Color(69, 78, 83));

    sf::Font font;
    font.loadFromFile("arial.ttf");
    // Create a text
    sf::Text text("hello", font);
    text.setCharacterSize(30);
    text.setStyle(sf::Text::Bold);
    text.setColor(sf::Color::Red);
    text.setPosition(width() - 100,height()/2);

    // Draw it
    draw(text);
    myClock.restart();

}

void MyCanvas::resizeEvent(QResizeEvent *event)
{
    qDebug() << "RESIZED SFML";

   // setSize(sf::Vector2u(event->size().width(),event->size().height()));
    QWidget::resizeEvent(event);
}
 

mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QWidget>
#include "MyCanvas.h"


class MainWindow : public QWidget
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

    MyCanvas Canvas;
private:

protected:
    void resizeEvent( QResizeEvent * event);
    void paintEvent(QPaintEvent *event);
};

#endif // MAINWINDOW_H
 

mainwindow.cpp
#include "mainwindow.h"
#include <QPainter>
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QWidget(parent),
    Canvas(this,QPoint(5,20),QSize(width() - 20,height() - 40))

{
    //setWindowFlags ( Qt :: FramelessWindowHint);
}

MainWindow::~MainWindow()
{

}
void MainWindow::resizeEvent(QResizeEvent *event)
{
    Canvas.move( 5, 22);
    Canvas.resize(width() - 10,height() - 44);
}
void MainWindow::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);
}

 

main.cpp
#include "mainwindow.h"
#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    return a.exec();
}
 

Just resize the window and you will see how the text disappear to the right.

7
Window / Re: MFC and SFML Window problem
« on: April 15, 2014, 11:09:13 pm »
I think this is exactly the same issue http://en.sfml-dev.org/forums/index.php?topic=12952.15. So how to change the videomode after the window has been created?

8
Window / Re: MFC and SFML Window problem
« on: April 15, 2014, 10:35:07 pm »
Well I spoke too soon. It seems that the SFML windows IS NOT resized after all
I did to test it this time
void MyCanvas::resizeEvent(QResizeEvent *event)
{
    qDebug() << "RESIZED Widget" << event->size().width() << event->size().height();


    setSize(sf::Vector2u(event->size().width(),event->size().height()));
    qDebug() << "RESIZED SFML" << getSize().x << getSize().y;
}

which is resulting in this

RESIZED QWidget 502 470
RESIZED SFML 502 470
RESIZED QWidget 504 471
RESIZED SFML 502 470
RESIZED QWidget 504 471
RESIZED SFML 502 470
RESIZED QWidget 521 481
RESIZED SFML 502 470
RESIZED QWidget 521 481
RESIZED SFML 502 470
RESIZED QWidget 535 487
RESIZED SFML 502 470
RESIZED QWidget 535 487
RESIZED SFML 502 470
RESIZED QWidget 546 492
RESIZED SFML 502 470

So where would the problem be?

9
Window / Re: MFC and SFML Window problem
« on: April 15, 2014, 09:59:21 pm »
Well I am now sure that the SFML window is resing along with the Qt widget, so the problem is somewhere else. When I check the viewport size I get 1000/1000, is this value real pixels or just indicating 100% from the SFML window. Because it stays constant during the resize

10
Window / Re: MFC and SFML Window problem
« on: April 15, 2014, 08:56:02 am »
Sorry but can you explain a bit more in details. Because I am resizing the MyCanvas manually when I resize the main window. So basically I am resizing the SFMLCanvas widget. Does that means the RenderWindow also gets that event?

11
Window / Re: MFC and SFML Window problem
« on: April 15, 2014, 08:24:23 am »
Then I am out of ideas :D

12
Window / Re: MFC and SFML Window problem
« on: April 15, 2014, 06:04:13 am »
OK, maybe there is something wrong in the implementation that I did.

I am receiving the resize event in the MyCanvas, but how can I be sure that I am also resizing QSFMLCanvas which is the base class of MyCanvas? Because what I am thinking is that MyCanvas is resizing, but the event is not send to QSFMLCanvas too, so it stays the same size.

13
Window / Re: MFC and SFML Window problem
« on: April 14, 2014, 10:09:46 pm »
I will make a small demo and will post it here (yes minimal and complete code  ::) :P ;) ;D) so you can test and if possible find the solution for it.

14
Window / Re: MFC and SFML Window problem
« on: April 14, 2014, 06:17:24 pm »
Well I am implementing this tutorial http://sfml-dev.org/tutorials/1.6/graphics-qt.php,
and I am getting the resize event in the MyCanvas class.

I have to say that the MyCanvas is itself called as variable in a Qt Widget, thus embedding the MyCanvas (SFML).

15
Window / Re: MFC and SFML Window problem
« on: April 14, 2014, 05:13:57 pm »
So what could the problem be? I can see that the window itself is resizing (the clear color is resized OK) but for some reason all is cropped if outside of the original size of the window.

Pages: [1] 2 3 4