Skip to content

Commit

Permalink
Window size fixes on macOS.
Browse files Browse the repository at this point in the history
Changes for SpartanJ/ecode/#373
  • Loading branch information
SpartanJ committed Dec 22, 2024
1 parent fe63326 commit 60784d7
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 18 deletions.
18 changes: 13 additions & 5 deletions include/eepp/window/window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ class WindowSettings {
UseScreenKeyboard( EE_SCREEN_KEYBOARD_ENABLED ) {}

Uint32 Style;
Uint32 Width;
Uint32 Height;
Uint32 Width; //! In screen coordinates (pixels * scale)
Uint32 Height; //! In screen coordinates (pixels * scale)
Uint32 BitsPerPixel;
std::string Icon;
std::string Title;
Expand Down Expand Up @@ -246,9 +246,14 @@ class EE_API Window {
*/
virtual void setSize( Uint32 Width, Uint32 Height, bool isWindowed ) = 0;

/** @return The window size */
/** @return The window size in pixels */
virtual Sizei getSize();

/** @return The window size in screen coordinates (screen coordinates is size in pixels /
* scale).
*/
virtual Sizei getSizeInScreenCoordinates();

/** @return The window center point */
Vector2f getCenter();

Expand Down Expand Up @@ -306,7 +311,7 @@ class EE_API Window {
virtual Rect getBorderSize();

/** @return The size of the pixel in screen coordinates. This is the device scale factor. */
virtual Float getScale();
virtual Float getScale() const;

/** @return If the aplication is running returns true ( If you Init correctly the window and is
* running ). */
Expand Down Expand Up @@ -493,9 +498,12 @@ class EE_API Window {
* per second. */
const System::Time& getRenderTimePerSecond() const;

/** @return The last windowed size of the window */
/** @return The last windowed size of the window in pixels */
const Sizei& getLastWindowedSize() const;

/** @return The last windowed size of the window in screen coordinates */
Sizei getLastWindowedSizeInScreenCoordinates() const;

/** @return True if implements native message boxes */
virtual bool hasNativeMessageBox() const { return false; };

Expand Down
2 changes: 2 additions & 0 deletions projects/macos/ee.includes
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/opt/homebrew/Cellar/sdl2/2.30.8/include
../../src/
../../include/
../../src/thirdparty
Expand All @@ -14,3 +15,4 @@
../../src/modules/physics/include/
../../src/modules/physics/src/
../../src/tools/ecode
../../src/modules/languages-syntax-highlighting/src
2 changes: 1 addition & 1 deletion src/eepp/window/backend/SDL2/windowsdl2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ Rect WindowSDL::getBorderSize() {
return bordersSize;
}

Float WindowSDL::getScale() {
Float WindowSDL::getScale() const {
int realX, realY;
int scaledX, scaledY;
SDL_GL_GetDrawableSize( mSDLWindow, &realX, &realY );
Expand Down
2 changes: 1 addition & 1 deletion src/eepp/window/backend/SDL2/windowsdl2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class EE_API WindowSDL : public Window {

virtual Rect getBorderSize();

virtual Float getScale();
virtual Float getScale() const;

virtual bool hasNativeMessageBox() const;

Expand Down
18 changes: 15 additions & 3 deletions src/eepp/window/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ Sizei Window::getSize() {
return Sizei( mWindow.WindowConfig.Width, mWindow.WindowConfig.Height );
}

Sizei Window::getSizeInScreenCoordinates() {
Float scale = getScale();
return Sizei{ static_cast<int>( mWindow.WindowConfig.Width / scale ),
static_cast<int>( mWindow.WindowConfig.Height / scale ) };
}

Vector2f Window::getCenter() {
return Sizef( mWindow.WindowConfig.Width, mWindow.WindowConfig.Height ) * 0.5f;
}
Expand Down Expand Up @@ -346,6 +352,12 @@ const Sizei& Window::getLastWindowedSize() const {
return mLastWindowedSize;
}

Sizei Window::getLastWindowedSizeInScreenCoordinates() const {
Float scale = getScale();
return Sizei{ static_cast<int>( mLastWindowedSize.getWidth() / scale ),
static_cast<int>( mLastWindowedSize.getHeight() / scale ) };
}

bool Window::showMessageBox( const MessageBoxType&, const std::string&, const std::string& ) {
return false;
}
Expand Down Expand Up @@ -469,13 +481,13 @@ void Window::logSuccessfulInit( const std::string& BackendName ) {
"%s\n\tPlatform: %s\n\tOS: %s\n\tArch: %s\n\tCPU Cores: %d\n\tProcess Path: %s\n\tCurrent "
"Working Directory: %s\n\tHome Directory: %s\n\tDisk Free Space: %s\n\tWindow/Input "
"Backend: %s\n\tGL Backend: %s\n\tGL Vendor: %s\n\tGL Renderer: %s\n\tGL Version: "
"%s\n\tGL Shading Language Version: %s\n\tResolution: %dx%d",
"%s\n\tGL Shading Language Version: %s\n\tResolution: %dx%d\n\tWindow scale: %.2f",
Version::getVersionName(), Version::getCodename(), Version::getBuildTime(),
Sys::getPlatform(), Sys::getOSName( true ), Sys::getOSArchitecture(), Sys::getCPUCount(),
Sys::getProcessPath(), FileSystem::getCurrentWorkingDirectory(), Sys::getUserDirectory(),
FileSystem::sizeToString( FileSystem::getDiskFreeSpace( Sys::getProcessPath() ) ),
BackendName, GLi->versionStr(), GLi->getVendor(), GLi->getRenderer(), GLi->getVersion(),
GLi->getShadingLanguageVersion(), getWidth(), getHeight() ) );
GLi->getShadingLanguageVersion(), getWidth(), getHeight(), getScale() ) );

#ifndef EE_SILENT
Log::info( msg );
Expand Down Expand Up @@ -566,7 +578,7 @@ Rect Window::getBorderSize() {
return Rect();
}

Float Window::getScale() {
Float Window::getScale() const {
return 1.f;
}

Expand Down
4 changes: 3 additions & 1 deletion src/tools/ecode/appconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,9 @@ void AppConfig::save( const std::vector<std::string>& recentFiles,
}

editor.colorScheme = colorSchemeName;
windowState.size = win->getLastWindowedSize();
windowState.size = Sys::getPlatformType() == Sys::PlatformType::macOS
? win->getSizeInScreenCoordinates()
: win->getLastWindowedSizeInScreenCoordinates();
windowState.maximized = win->isMaximized();
windowState.displayIndex = win->getCurrentDisplayIndex();
windowState.position = win->getPosition();
Expand Down
14 changes: 7 additions & 7 deletions src/tools/ecode/ecode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -693,8 +693,6 @@ bool App::loadConfig( const LogLevel& logLevel, const Sizeu& displaySize, bool s
}

void App::saveConfig() {
if ( mIncognito )
return;
mConfig.save( mRecentFiles, mRecentFolders,
mProjectSplitter ? mProjectSplitter->getSplitPartition().toString() : "15%",
mMainSplitter ? mMainSplitter->getSplitPartition().toString() : "85%", mWindow,
Expand Down Expand Up @@ -1866,7 +1864,7 @@ bool App::isUnlockedCommand( const std::string& command ) {
}

void App::saveProject( bool onlyIfNeeded, bool sessionSnapshotEnabled ) {
if ( !mIncognito && !mCurrentProject.empty() ) {
if ( !mCurrentProject.empty() ) {
mConfig.saveProject(
mCurrentProject, mSplitter, mConfigPath, mProjectDocConfig,
mProjectBuildManager ? mProjectBuildManager->getConfig() : ProjectBuildConfiguration(),
Expand Down Expand Up @@ -3476,6 +3474,8 @@ void App::init( const LogLevel& logLevel, std::string file, const Float& pidelDe
if ( mConfig.windowState.maximized ) {
#if EE_PLATFORM == EE_PLATFORM_LINUX
mThreadPool->run( [this] { mWindow->maximize(); } );
#elif EE_PLATFORM == EE_PLATFORM_MACOS
// Do no maximize since the result is not exactly maximized
#else
mWindow->maximize();
#endif
Expand Down Expand Up @@ -3973,10 +3973,10 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) {
parser, "portable",
"Portable Mode (it will save the configuration files within the ecode main folder)",
{ 'p', "portable" } );
args::Flag incognito( parser, "incognito",
"Disables saving any settings from this session (opened files and "
"folders, folders/project settings and editor settings)",
{ 'i', "incognito" } );
args::Flag incognito(
parser, "incognito",
"It will stop keeping track of the opened files or folders during the session",
{ 'i', "incognito" } );
args::ValueFlag<size_t> jobs(
parser, "jobs",
"Sets the number of background jobs that the application will spawn "
Expand Down

0 comments on commit 60784d7

Please sign in to comment.