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

Author Topic: sf::RenderWindow only has tiny drawable area despite bigger size  (Read 1671 times)

0 Members and 1 Guest are viewing this topic.

codecodecode

  • Newbie
  • *
  • Posts: 26
    • View Profile
So I cobbled up an integration to wxWidgets from various internet sources, the end result is only partially successful and I'm at loss what's missing.

My custom class inherits sf::RenderWindow:
class foondabar : public wxWindow, public sf::RenderWindow
its constructor looks like this:
foondabar::foondabar(wxFrame* parent, wxString text) :
 wxWindow(parent, wxID_ANY)
{
    SetMinSize( wxSize(320, 240) );
    #ifdef __WXGTK__
        //on linux, so this part gets executed
        gtk_widget_realize(m_wxwindow);
        gtk_widget_set_double_buffered(m_wxwindow, false);
        GdkWindow* Win = gtk_widget_get_window(m_wxwindow);
        XFlush(GDK_WINDOW_XDISPLAY(Win));
        sf::RenderWindow::create(GDK_WINDOW_XWINDOW(Win));

    #else

        // Tested under Windows XP only (should work with X11
        // and other Windows versions - no idea about MacOS)
        sf::RenderWindow::Create(GetHandle());
    #endif
}
and finally, paint and render function:
void foondabar::render(wxDC&  dc)
{

    clear(sf::Color(0,0,0,2));

    sf::RectangleShape sheip(sf::Vector2f(3000, 3000));
    sheip.setFillColor(sf::Color(250, 250, 50));
    sheip.setPosition(-1000,-1000);
    draw(sheip);

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

    draw(sheip);

    // Display on screen
    display();
}

And the end result looks like this:


What is missing? Why isn't the whole area being drawn in, despite being cleared in the background colour?

I've tried all kinds of variations in the constructor, including this->create(GDK_WINDOW_XWINDOW(Win));, setting size and position and creating with video mode, and many many combinations of those; in the case of a video mode a separate window is created, which I don't want; otherwise it either doesn't show any canvas, just a blank window, or there's no visible difference to the screenshot above.

codecodecode

  • Newbie
  • *
  • Posts: 26
    • View Profile
Re: sf::RenderWindow only has tiny drawable area despite bigger size
« Reply #1 on: January 14, 2017, 02:54:21 pm »
Apparently the size of the drawable area is set automatically to the one of the control and this is only done once, at the initialisaiton. Calling this function from the resize event function, passing it the width and height of the window, solved the issue:
void foondabar::udt(int a, int b)
{
    #ifdef __WXGTK__
    //uncommenting the line below will make the drawable area go outside the control, if that's ever needed
    //sf::RenderWindow::setSize(sf::Vector2u(a-50,b-50));
    GdkWindow* Win = gtk_widget_get_window( (GtkWidget *) GetHandle() );
    XFlush(GDK_WINDOW_XDISPLAY(Win));
    sf::RenderWindow::create(GDK_WINDOW_XWINDOW(Win));
    #endif
}

 

anything