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

Author Topic: SFML : trying to open a WxFrame  (Read 6959 times)

0 Members and 1 Guest are viewing this topic.

GabrielS

  • Newbie
  • *
  • Posts: 25
    • View Profile
SFML : trying to open a WxFrame
« on: July 10, 2013, 06:00:10 pm »
Hello community,

For some reasons ( I need to display curves that I have generated ), I need to merge WxWidget and SFML.
I don't want to put SFML in a wxFrame, I just want to be able to create a new window ( a wxFrame ) from SFML.

To be precise, I got my all GUI made with SFML (super easy to use this library, this is awesome :D), and I got a button on this GUI called "create Curve". When the user clicks on this button, I would like to open a WxFrame (using wxMathPlot) to display some curves generated.
Any one has an idea how to do this ? I've been able to draw a wxFrame + my SFML GUI but the wxFrame is "dead".
I do not know if it is possible tho, but I feel that it is ;) .
Any ideas are welcome ;)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: SFML : trying to open a WxFrame
« Reply #1 on: July 10, 2013, 06:15:22 pm »
I don't know if this is possible. But why don't you draw the curves with SFML?
Laurent Gomila - SFML developer

GabrielS

  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: SFML : trying to open a WxFrame
« Reply #2 on: July 10, 2013, 06:20:18 pm »
Well, i have drawn the curve using a class Curve I've created (a vector of sf::Vertex) with this method
void Curve::drawIn(sf::RenderWindow& window)
{
        sf::VertexArray copyCurveInArray(sf::PrimitiveType::LinesStrip,mPoints.size()); // draw the curve as a line in SFML
        for (int i = 0; i < mPoints.size(); i++)
        {
                copyCurveInArray[i].position.x = mPoints.at(i).position.x;
                copyCurveInArray[i].position.y = -mPoints.at(i).position.y + 200;
                copyCurveInArray[i].color = sf::Color::Black;
        }
        window.draw(copyCurveInArray);
}

but I wanted to use http://wxmathplot.sourceforge.net/screenshot.shtml library (that allows you to "move" in the window, zoomin, zoomout "super easily" (it wasn't easy to have the samples of this library working, but now that I managed to have the samples working, that would be awesome if I was able to draw the curves in this window)
If you have an idea using only SFML but having zoomin/zoomout/wheel motion/ display/hide grid ..., I would like to ,)
« Last Edit: July 10, 2013, 06:24:46 pm by GabrielS »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: SFML : trying to open a WxFrame
« Reply #3 on: July 10, 2013, 06:56:40 pm »
Moving and zooming is easy with views.
Display/hide grid is just a boolean and a vertex array of lines.

Only straight-forward stuff.
Laurent Gomila - SFML developer

GabrielS

  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: SFML : trying to open a WxFrame
« Reply #4 on: July 10, 2013, 07:28:52 pm »
hm,

yes sure, but I do not think I am able to re-create an existing library (even small) in (not even) one month or two, that's why I wanted to use the library I linked, it's just "easy-to-use" but using a wxWidget.

I was thinking of another solution tho :
do you think it is possible to include my SFML work (SFML GUI) into a wxWidget (I've seen there was a tutorial on SFML1.6) and to create new SFML window from here ?
As a result, I will be able (instead of having one SFML window opening a WxFrame) to have one WxFrame with 2 tabs, one including my GUI SFML (which should allow the user to open SMFL window) and the other tab with the curves using wxMathplot ?
Do you think this is possible to implement ?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: SFML : trying to open a WxFrame
« Reply #5 on: July 10, 2013, 08:49:06 pm »
Sure, should be easy. The 1.6 tutorial should still be valid, you just have to adapt it to the SFML 2 syntax.
Laurent Gomila - SFML developer

GabrielS

  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: SFML : trying to open a WxFrame
« Reply #6 on: July 10, 2013, 09:15:37 pm »
Ok, thanks, i'll keep you in touch with my work ;)

GabrielS

  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: SFML : trying to open a WxFrame
« Reply #7 on: July 11, 2013, 04:10:36 pm »
hm.. I tried to adapt (just a little the tutorial from SFML1.6) : here is the code I used :
#include "wx/wx.h"
#include <SFML/Graphics.hpp>

class wxSFMLCanvas : public wxControl, public sf::RenderWindow
{
public :

        wxSFMLCanvas(wxWindow* Parent = NULL, wxWindowID Id = -1, const wxPoint& Position = wxDefaultPosition,
                                 const wxSize& Size = wxDefaultSize, long Style = 0);

        virtual ~wxSFMLCanvas();

private :

        DECLARE_EVENT_TABLE()

        virtual void OnUpdate();

        void OnIdle(wxIdleEvent&);

        void OnPaint(wxPaintEvent&);

        void OnEraseBackground(wxEraseEvent&);
};

void wxSFMLCanvas::OnIdle(wxIdleEvent&)
{
        Refresh();
}

void wxSFMLCanvas::OnPaint(wxPaintEvent&)
{
        wxPaintDC Dc(this);

        OnUpdate();

        display();
}

#ifdef __WXGTK__
        #include <gdk/gdkx.h>
        #include <gtk/gtk.h>
        #include <wx/gtk/win_gtk.h>
#endif

wxSFMLCanvas::wxSFMLCanvas(wxWindow* Parent, wxWindowID Id, const wxPoint& Position, const wxSize& Size, long Style) :
wxControl(Parent, Id, Position, Size, Style)
{
        #ifdef __WXGTK__

                gtk_widget_realize(m_wxwindow);
                gtk_widget_set_double_buffered(m_wxwindow, false);
                GdkWindow* Win = GTK_PIZZA(m_wxwindow)->bin_window;
                XFlush(GDK_WINDOW_XDISPLAY(Win));
                sf::RenderWindow::create(GDK_WINDOW_XWINDOW(Win));
        #else
                sf::RenderWindow::create(GetHandle());

        #endif
}

class MyCanvas : public wxSFMLCanvas
{
public :

        MyCanvas(wxWindow*  Parent,
                         wxWindowID Id,
                         wxPoint&   Position,
                         wxSize&    Size,
                         long       Style = 0) :
        wxSFMLCanvas(Parent, Id, Position, Size, Style)
        {
                mySprite.setColor(sf::Color::Cyan);
                //mySprite.SetImage(myImage);
        }

private :

        virtual void OnUpdate()
        {
                clear(sf::Color(0, 128, 128));
                draw(mySprite);
        }

        //sf::Image  myImage;
        sf::Sprite mySprite;
};

class MyFrame : public wxFrame
{
public :

        MyFrame() :
        wxFrame(NULL, wxID_ANY, "SFML wxWidgets", wxDefaultPosition, wxSize(800, 600))
        {
                new MyCanvas(this, wxID_ANY, wxPoint(50, 50), wxSize(700, 500));
        }
};

class MyApplication : public wxApp
{
private :

        virtual bool OnInit()
        {
                MyFrame* MainFrame = new MyFrame;
                MainFrame->Show();

                return true;
        }
};

IMPLEMENT_APP(MyApplication);

& i get this error :
1>minimal.obj : error LNK2001: unresolved external symbol "protected: virtual struct wxEventTable const * __thiscall wxSFMLCanvas::GetEventTable(void)const " (?GetEventTable@wxSFMLCanvas@@MBEPBUwxEventTable@@XZ)
1>minimal.obj : error LNK2001: unresolved external symbol "protected: virtual class wxEventHashTable & __thiscall wxSFMLCanvas::GetEventHashTable(void)const " (?GetEventHashTable@wxSFMLCanvas@@MBEAAVwxEventHashTable@@XZ)
1>minimal.obj : error LNK2001: unresolved external symbol "protected: virtual void __thiscall wxSFMLCanvas::OnUpdate(void)" (?OnUpdate@wxSFMLCanvas@@MAEXXZ)
1>minimal.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall wxSFMLCanvas::~wxSFMLCanvas(void)" (??1wxSFMLCanvas@@UAE@XZ) referenced in function "public: virtual void * __thiscall wxSFMLCanvas::`scalar deleting destructor'(unsigned int)" (??_GwxSFMLCanvas@@UAEPAXI@Z)
1>vc_mswud\minimal.exe : fatal error LNK1120: 4 unresolved externals

NB : I implemented the code on the minimal sample from wxWidget ( so that I didnt have to add wxWidget dependancies) and I have added the lib/include SFML dependancies :
(linker/General, Linker/Input and c/c++/General)
I'm sure I' doing a mistake so;ewhere ( i do believe that its a problem of linking libraries ) but as I'm completely new to wxWidget, I just tried what I thought was the easier : comes from their sample to add SFML2.0 inside. I hope you can help me here,

Thanks,

gabriel
« Last Edit: July 11, 2013, 04:12:10 pm by GabrielS »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: SFML : trying to open a WxFrame
« Reply #8 on: July 11, 2013, 05:57:37 pm »
Just implement the event table and the functions that you declare but don't define.
Laurent Gomila - SFML developer

GabrielS

  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: SFML : trying to open a WxFrame
« Reply #9 on: July 11, 2013, 07:44:11 pm »
hm, I don't understand... Can you clarify please :) ?
I've just followed the tutorial from SFML1.6 ....

Quote
Just implement the event table and the functions that you declare but don't define.

I don't understand what I did wrong.. please help, I've just done the same thing error and getting same mistake

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: SFML : trying to open a WxFrame
« Reply #10 on: July 11, 2013, 08:20:21 pm »
Quote
unresolved external symbol "protected: virtual struct wxEventTable const * __thiscall wxSFMLCanvas::GetEventTable(void)const
unresolved external symbol "protected: virtual class wxEventHashTable & __thiscall wxSFMLCanvas::GetEventHashTable(void)const
You've declared an event table (DECLARE_EVENT_TABLE) but you don't define it.

Quote
unresolved external symbol "protected: virtual void __thiscall wxSFMLCanvas::OnUpdate(void)"
It is declared in the header but never implemented.

Quote
unresolved external symbol "public: virtual __thiscall wxSFMLCanvas::~wxSFMLCanvas(void)"
It is declared in the header but never implemented.

The pieces of code of the tutorial don't make a complete source, you can't just copy and paste them and expect it to work magically. You must know at least the basics of wxWidgets and C++. I don't see the point of using code that you don't understand ;)
Laurent Gomila - SFML developer

GabrielS

  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: SFML : trying to open a WxFrame
« Reply #11 on: July 11, 2013, 08:23:47 pm »
well yes, I am completely new to wxWidget, but I tought I could be able to consider it as a "blackbox" and working on SFML more than wxWidget. My applicationin "pure SFML" works well, I just wanted to add this in a larger wxFrame to be able to use wxMathplot ;).
Omw to wxWidget tutorials so.. I'll try to figure out what I'm missing,

Thanks

 

anything