Cross platform issues...

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
Post Reply
User avatar
kepeter
In need of some credit
In need of some credit
Posts: 3
Joined: Wed Jun 29, 2022 7:29 am

Cross platform issues...

Post by kepeter »

In the attached - very simple - project I use SDL2 and wxWidgets together.
It is a perfectly working code on Windows (10 and 11), but has two major issues (and one minor) on Linux (Fedora 35 and Ubuntu 20.04.4 LTS (Focal Fossa) in my case).
I'm using wxWidgets 3.0.5 and SDL2 2.0.22 on all platforms.
On Linux I use gcc 11.2
On Windows I use cl 19.33
In both case I compile for x64
I'm using CMake 3.8 to build and C++17 as language version

GetSize problem

Code: Select all

MainFrame* frame = new MainFrame("wxWidgets/SDL2");

frame->Maximize(true);
frame->Show(true);

wxSize size = frame->GetSize();
int multiplier = std::min(size.x / 320, size.y / 200);

frame->SDLPanel->SetSize(multiplier * 320, multiplier * 200);
frame->SDLPanel->CenterOnParent();
On Linux the GetSize returns the design time (or default?) size despite the Maximize. It messes with all the calculations and the centering. On Windows it works perfectly...

Event loop
Both wxWidgets and SDL2 part of the code runs an event loop. On Windows they work both perfectly, but on Linux SDL2 never gets a single event.
It seems that on Linux the events are all consumed by wxWidgets. To test it I made a version (not included here) where I use SDL_PumpEvents from within wxWidgets' event loop to force the event reaching SDL2. While this works fairly good I still wondering about the differences of platforms...
Attachments
app.h
(680 Bytes) Downloaded 38 times
main.cpp
(230 Bytes) Downloaded 39 times
app.cpp
(2.5 KiB) Downloaded 38 times
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Cross platform issues...

Post by ONEEYEMAN »

Hi,
For the first problem - you need to understand that GTK has a different concept of working.
On GTK the window size and position is not known until the window is actually realizing on screen.
Now the trick question is - are you using sizers or absolute positioning? I think you use the latter since you calculate the position of SDL window.
You should look into using sizers for layout - it will eliminate a lot of issues for you.

Thank you.
User avatar
kepeter
In need of some credit
In need of some credit
Posts: 3
Joined: Wed Jun 29, 2022 7:29 am

Re: Cross platform issues...

Post by kepeter »

Thank you - I will check sizers as a solution for that...
Last edited by kepeter on Wed Jun 29, 2022 1:20 pm, edited 1 time in total.
User avatar
kepeter
In need of some credit
In need of some credit
Posts: 3
Joined: Wed Jun 29, 2022 7:29 am

Re: Cross platform issues...

Post by kepeter »

I created a version using sizers. It works same on both platforms, but rises an another problem...
Even using two sizers (horizontal and vertical) I am able to center the panel only in one direction...

Code: Select all

int multiplier = 3;

SDLPanel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(multiplier * 320, multiplier * 200));
wxBoxSizer* sizerV = new wxBoxSizer( wxVERTICAL );
wxBoxSizer* sizerH = new wxBoxSizer( wxHORIZONTAL );

sizerH->Add(SDLPanel, wxSizerFlags(0).Center());
sizerV->Add(sizerH, wxSizerFlags(0).Center());

SetSizerAndFit(sizerV);
Visually sizerH changes nothing, I can remove it from the code and still see the very same result...
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Cross platform issues...

Post by doublemax »

In order to center an item horizontally in a horizontal sizer, you need to add a stretch spacer before and after it.
Use the source, Luke!
User avatar
kepeter
In need of some credit
In need of some credit
Posts: 3
Joined: Wed Jun 29, 2022 7:29 am

Re: Cross platform issues...

Post by kepeter »

Thank you!
That did the trick...
Post Reply