From e222771afa40c566911620e73b74122d886787b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Sun, 28 Aug 2022 01:05:25 -0300 Subject: [PATCH] Minor refactor: UI::Window: Window::setWinFlags is now Window::setWindowsFlags. Renderer: Added glVersionFromString, graphicsLibraryVersionToString, getDefaultGraphicsLibraryVersion, getAvailableGraphicsLibraryVersions. Defined Sizeu. Context and Window ini configurations are now lowercase. Display: Added getRefreshRate and getSize. UICodeEditor: hide color preview when mouse leaves the editor. ecode: Added Renderer options (vsync, msaa, max frame rate, renderer version). Added "bechmark-mode" option, to measure rendering performance. --- bin/assets/ee.ini | 34 ++-- include/eepp/graphics/renderer/renderer.hpp | 10 ++ include/eepp/math/size.hpp | 1 + include/eepp/ui/uiwindow.hpp | 2 +- include/eepp/window/displaymanager.hpp | 14 +- src/eepp/graphics/renderer/renderer.cpp | 84 +++++++-- src/eepp/maps/mapeditor/mapeditor.cpp | 10 +- .../maps/mapeditor/maplayerproperties.cpp | 2 +- .../maps/mapeditor/mapobjectproperties.cpp | 2 +- src/eepp/maps/mapeditor/tilemapproperties.cpp | 2 +- src/eepp/maps/mapeditor/uigotypenew.cpp | 2 +- src/eepp/maps/mapeditor/uimaplayernew.cpp | 2 +- src/eepp/maps/mapeditor/uimapnew.cpp | 2 +- src/eepp/ui/tools/textureatlaseditor.cpp | 2 +- src/eepp/ui/tools/textureatlasnew.cpp | 6 +- src/eepp/ui/uicodeeditor.cpp | 2 +- src/eepp/ui/uiwindow.cpp | 2 +- .../backend/SDL2/displaymanagersdl2.cpp | 19 +- .../backend/SDL2/displaymanagersdl2.hpp | 14 +- src/eepp/window/engine.cpp | 69 +++---- src/tests/test_all/test.cpp | 28 +-- src/tests/ui_perf_test/ui_perf_test.cpp | 2 +- src/tools/ecode/appconfig.cpp | 55 +++--- src/tools/ecode/appconfig.hpp | 5 +- src/tools/ecode/ecode.cpp | 170 ++++++++++++++---- src/tools/ecode/ecode.hpp | 12 +- src/tools/eterm/eterm.cpp | 20 ++- src/tools/uieditor/uieditor.cpp | 6 +- 28 files changed, 388 insertions(+), 191 deletions(-) diff --git a/bin/assets/ee.ini b/bin/assets/ee.ini index 1b7f1dcf0..5ace4a8cc 100755 --- a/bin/assets/ee.ini +++ b/bin/assets/ee.ini @@ -1,19 +1,19 @@ #You can set the initialization settings here. [EEPP] -Width = 1024 -Height = 768 -BitColor = 32 -Windowed = 1 -Resizeable = 1 -WinIcon = assets/icon/ee.png -VSync = 1 -GLVersion = Default -SharedGLContext = 1 -Backend = Default -JoystickEnabled = 0 -ParticlesNum = 1000 -UseShaders = 1 -Music = 0 -PixelDensity = auto -DebugUI = 0 -FrameRateLimit = 0 +width = 1024 +height = 768 +bitcolor = 32 +windowed = 1 +resizeable = 1 +winicon = assets/icon/ee.png +vsync = 1 +glversion = default +sharedglcontext = 1 +backend = default +joystickenabled = 0 +particlesnum = 1000 +useshaders = 1 +music = 0 +pixeldensity = auto +debugui = 0 +frameratelimit = 0 diff --git a/include/eepp/graphics/renderer/renderer.hpp b/include/eepp/graphics/renderer/renderer.hpp index fd26826b6..e15988885 100644 --- a/include/eepp/graphics/renderer/renderer.hpp +++ b/include/eepp/graphics/renderer/renderer.hpp @@ -27,6 +27,16 @@ class RendererGLES2; */ class EE_API Renderer { public: + /** @return The graphic library renderer version from a string. */ + static GraphicsLibraryVersion glVersionFromString( std::string glVersion ); + + /** @return Converts GralphicsLibraryVersion to a string */ + static std::string graphicsLibraryVersionToString( const GraphicsLibraryVersion& glVersion ); + + static GraphicsLibraryVersion getDefaultGraphicsLibraryVersion(); + + static std::vector getAvailableGraphicsLibraryVersions(); + static Renderer* createSingleton( GraphicsLibraryVersion ver ); static Renderer* createSingleton(); diff --git a/include/eepp/math/size.hpp b/include/eepp/math/size.hpp index d1aefff9c..154a0c1d1 100644 --- a/include/eepp/math/size.hpp +++ b/include/eepp/math/size.hpp @@ -68,6 +68,7 @@ template tSize& tSize::operator=( const tSize& right ) { } typedef tSize Sizei; +typedef tSize Sizeu; typedef tSize Sizef; }} // namespace EE::Math diff --git a/include/eepp/ui/uiwindow.hpp b/include/eepp/ui/uiwindow.hpp index bca925367..a98642221 100644 --- a/include/eepp/ui/uiwindow.hpp +++ b/include/eepp/ui/uiwindow.hpp @@ -126,7 +126,7 @@ class EE_API UIWindow : public UIWidget { Uint32 getWinFlags() const; - UIWindow* setWinFlags( const Uint32& winFlags ); + UIWindow* setWindowFlags( const Uint32& winFlags ); const StyleConfig& getStyleConfig() const; diff --git a/include/eepp/window/displaymanager.hpp b/include/eepp/window/displaymanager.hpp index 37274b93f..4b7ff3261 100644 --- a/include/eepp/window/displaymanager.hpp +++ b/include/eepp/window/displaymanager.hpp @@ -13,22 +13,26 @@ class EE_API Display { public: Display( int displayIndex ); - virtual std::string getName() = 0; + virtual std::string getName() const = 0; - virtual Rect getBounds() = 0; + virtual Rect getBounds() const = 0; - virtual Rect getUsableBounds() = 0; + virtual Rect getUsableBounds() const = 0; virtual Float getDPI() = 0; virtual const int& getIndex() const = 0; - virtual DisplayMode getCurrentMode() = 0; + virtual DisplayMode getCurrentMode() const = 0; - virtual DisplayMode getClosestDisplayMode( DisplayMode wantedMode ) = 0; + virtual DisplayMode getClosestDisplayMode( DisplayMode wantedMode ) const = 0; virtual const std::vector& getModes() const = 0; + virtual Uint32 getRefreshRate() const = 0; + + virtual Sizeu getSize() const = 0; + virtual ~Display(); PixelDensitySize getPixelDensitySize(); diff --git a/src/eepp/graphics/renderer/renderer.cpp b/src/eepp/graphics/renderer/renderer.cpp index e0fd54ee6..1315d6250 100644 --- a/src/eepp/graphics/renderer/renderer.cpp +++ b/src/eepp/graphics/renderer/renderer.cpp @@ -41,31 +41,93 @@ Renderer* GLi = NULL; Renderer* Renderer::sSingleton = NULL; -Renderer* Renderer::createSingleton( GraphicsLibraryVersion ver ) { +GraphicsLibraryVersion Renderer::glVersionFromString( std::string glVersion ) { + GraphicsLibraryVersion GLVer; + String::toLowerInPlace( glVersion ); + if ( "3" == glVersion || "opengl 3" == glVersion || "gl3" == glVersion || + "opengl3" == glVersion ) + GLVer = GLv_3; + else if ( "4" == glVersion || "opengl es 2" == glVersion || "gles2" == glVersion || + "opengles2" == glVersion || "es2" == glVersion ) + GLVer = GLv_ES2; + else if ( "5" == glVersion || "opengl 3 core profile" == glVersion || "gl3cp" == glVersion || + "opengl3cp" == glVersion || "opengl core profile" == glVersion || + "core profile" == glVersion || "cp" == glVersion ) + GLVer = GLv_3CP; + else if ( "opengl es 1" == glVersion || "gles1" == glVersion || "gl es 1" == glVersion || + "opengl es1" == glVersion || "opengles1" == glVersion || "es1" == glVersion || + "gles 1" == glVersion ) + GLVer = GLv_ES1; + else if ( "2" == glVersion || "opengl 2" == glVersion || "gl2" == glVersion || + "gl 2" == glVersion ) + GLVer = GLv_2; + else + GLVer = GLv_default; + return GLVer; +} + +std::string Renderer::graphicsLibraryVersionToString( const GraphicsLibraryVersion& glVersion ) { + switch ( glVersion ) { + case GLv_2: + return "OpenGL 2"; + case GLv_3: + return "OpenGL 3"; + case GLv_3CP: + return "OpenGL 3 Core Profile"; + case GLv_ES1: + return "OpenGL ES 1"; + case GLv_ES2: + return "OpenGL ES 2"; + case GLv_default: + default: + return graphicsLibraryVersionToString( getDefaultGraphicsLibraryVersion() ); + } +} + +GraphicsLibraryVersion Renderer::getDefaultGraphicsLibraryVersion() { + GraphicsLibraryVersion ver = GLv_2; #if !defined( EE_GLES1 ) && !defined( EE_GLES2 ) - if ( GLv_default == ver ) - ver = GLv_2; + ver = GLv_2; #else #if EE_PLATFORM != EE_PLATFORM_EMSCRIPTEN - if ( GLv_default == ver ) #ifdef EE_GLES2 - ver = GLv_ES2; + ver = GLv_ES2; #else - ver = GLv_ES1; + ver = GLv_ES1; #endif #else - if ( GLv_default == ver ) #ifndef EE_GLES1_DEFAULT #ifdef EE_GLES2 - ver = GLv_ES2; + ver = GLv_ES2; #else - ver = GLv_ES1; + ver = GLv_ES1; #endif #else - ver = GLv_ES1; + ver = GLv_ES1; #endif #endif #endif + return ver; +} + +std::vector Renderer::getAvailableGraphicsLibraryVersions() { + std::vector vers; +#if ( defined( EE_GLES1 ) && !defined( EE_GLES2 ) ) || defined( EE_GLES_BOTH ) + vers.emplace_back( GLv_ES1 ); +#else + vers.emplace_back( GLv_2 ); +#endif +#ifdef EE_GL3_ENABLED + vers.emplace_back( GLv_3 ); + vers.emplace_back( GLv_3CP ); + vers.emplace_back( GLv_ES2 ); +#endif + return vers; +} + +Renderer* Renderer::createSingleton( GraphicsLibraryVersion ver ) { + if ( ver == GLv_default ) + ver = getDefaultGraphicsLibraryVersion(); switch ( ver ) { case GLv_ES2: { @@ -325,7 +387,7 @@ std::string Renderer::getExtensions() { eeglGetStringiFunc = (pglGetStringiFunc)SOIL_GL_GetProcAddress( "glGetStringi" ); if ( NULL == eeglGetStringiFunc ) { - return 0; + return ""; } } diff --git a/src/eepp/maps/mapeditor/mapeditor.cpp b/src/eepp/maps/mapeditor/mapeditor.cpp index 26f21a742..f8ed229ce 100644 --- a/src/eepp/maps/mapeditor/mapeditor.cpp +++ b/src/eepp/maps/mapeditor/mapeditor.cpp @@ -1134,7 +1134,7 @@ void MapEditor::fileMenuClick( const Event* Event ) { createNewMap(); } else if ( "Open..." == txt ) { UIFileDialog* TGDialog = UIFileDialog::New( UIFileDialog::DefaultFlags, "*.eem" ); - TGDialog->setWinFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL ); + TGDialog->setWindowFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL ); TGDialog->setTitle( "Open Map" ); TGDialog->addEventListener( Event::OpenFile, cb::Make1( this, &MapEditor::mapOpen ) ); TGDialog->center(); @@ -1142,7 +1142,7 @@ void MapEditor::fileMenuClick( const Event* Event ) { } else if ( "Save As..." == txt ) { UIFileDialog* TGDialog = UIFileDialog::New( UIFileDialog::DefaultFlags | UIFileDialog::SaveDialog, "*.eem" ); - TGDialog->setWinFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL ); + TGDialog->setWindowFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL ); TGDialog->setTitle( "Save Map" ); TGDialog->addEventListener( Event::SaveFile, cb::Make1( this, &MapEditor::mapSave ) ); TGDialog->center(); @@ -1267,7 +1267,7 @@ void MapEditor::mapMenuClick( const Event* Event ) { if ( "New Texture Atlas..." == txt ) { UIWindow* tWin = UIWindow::New(); tWin->setSizeWithDecoration( 1024, 768 ); - tWin->setWinFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | + tWin->setWindowFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_DRAGABLE_CONTAINER ); tWin->setMinWindowSize( 1024, 768 ); @@ -1277,7 +1277,7 @@ void MapEditor::mapMenuClick( const Event* Event ) { } else if ( "Add External Texture Atlas..." == txt ) { UIFileDialog* TGDialog = UIFileDialog::New( UIFileDialog::DefaultFlags, std::string( "*" ) + EE_TEXTURE_ATLAS_EXTENSION ); - TGDialog->setWinFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL ); + TGDialog->setWindowFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL ); TGDialog->setTitle( "Load Texture Atlas..." ); TGDialog->addEventListener( Event::OpenFile, cb::Make1( this, &MapEditor::cextureAtlasOpen ) ); @@ -1328,7 +1328,7 @@ void MapEditor::layerMenuClick( const Event* Event ) { UIMessageBox* MapEditor::createAlert( const String& title, const String& text ) { UIMessageBox* MsgBox = UIMessageBox::New( UIMessageBox::OK, text ); - MsgBox->setWinFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_RESIZEABLE | UI_WIN_MODAL ); + MsgBox->setWindowFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_RESIZEABLE | UI_WIN_MODAL ); MsgBox->setTitle( title ); MsgBox->center(); MsgBox->show(); diff --git a/src/eepp/maps/mapeditor/maplayerproperties.cpp b/src/eepp/maps/mapeditor/maplayerproperties.cpp index 20d899e80..06f068875 100644 --- a/src/eepp/maps/mapeditor/maplayerproperties.cpp +++ b/src/eepp/maps/mapeditor/maplayerproperties.cpp @@ -24,7 +24,7 @@ MapLayerProperties::MapLayerProperties( MapLayer* Map, RefreshLayerListCb Cb ) : mUIWindow = UIWindow::New(); mUIWindow->setSizeWithDecoration( 500, 500 ) - ->setWinFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MODAL ) + ->setWindowFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MODAL ) ->setMinWindowSize( 500, 500 ); mUIWindow->addEventListener( Event::OnWindowClose, diff --git a/src/eepp/maps/mapeditor/mapobjectproperties.cpp b/src/eepp/maps/mapeditor/mapobjectproperties.cpp index c5b48c91c..3b4c1e6f2 100644 --- a/src/eepp/maps/mapeditor/mapobjectproperties.cpp +++ b/src/eepp/maps/mapeditor/mapobjectproperties.cpp @@ -39,7 +39,7 @@ MapObjectProperties::MapObjectProperties( GameObjectObject* Obj ) : mUIWindow = UIWindow::New(); mUIWindow->setSizeWithDecoration( 500, 500 ) - ->setWinFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MODAL ) + ->setWindowFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MODAL ) ->setMinWindowSize( 500, 500 ); mUIWindow->addEventListener( Event::OnWindowClose, diff --git a/src/eepp/maps/mapeditor/tilemapproperties.cpp b/src/eepp/maps/mapeditor/tilemapproperties.cpp index b70b36f30..ecffca18b 100644 --- a/src/eepp/maps/mapeditor/tilemapproperties.cpp +++ b/src/eepp/maps/mapeditor/tilemapproperties.cpp @@ -39,7 +39,7 @@ TileMapProperties::TileMapProperties( TileMap* Map ) : mUIWindow = UIWindow::New(); mUIWindow->setSizeWithDecoration( 500, 500 ) - ->setWinFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MODAL ) + ->setWindowFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MODAL ) ->setMinWindowSize( 500, 500 ); mUIWindow->addEventListener( Event::OnWindowClose, diff --git a/src/eepp/maps/mapeditor/uigotypenew.cpp b/src/eepp/maps/mapeditor/uigotypenew.cpp index 123aa6e2d..20d04f007 100644 --- a/src/eepp/maps/mapeditor/uigotypenew.cpp +++ b/src/eepp/maps/mapeditor/uigotypenew.cpp @@ -18,7 +18,7 @@ UIGOTypeNew::UIGOTypeNew( std::function Cb ) : mUIWindow = UIWindow::New(); mUIWindow->setSizeWithDecoration( 278, 114 ) - ->setWinFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MODAL ) + ->setWindowFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MODAL ) ->setMinWindowSize( 278, 114 ); mUIWindow->addEventListener( Event::OnWindowClose, diff --git a/src/eepp/maps/mapeditor/uimaplayernew.cpp b/src/eepp/maps/mapeditor/uimaplayernew.cpp index 7891a5a1e..e3e029ebe 100644 --- a/src/eepp/maps/mapeditor/uimaplayernew.cpp +++ b/src/eepp/maps/mapeditor/uimaplayernew.cpp @@ -23,7 +23,7 @@ UIMapLayerNew::UIMapLayerNew( UIMap* Map, EE_LAYER_TYPE Type, NewLayerCb newLaye mUIWindow = UIWindow::New(); mUIWindow->setSizeWithDecoration( 278, 114 ) - ->setWinFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MODAL ) + ->setWindowFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MODAL ) ->setMinWindowSize( 278, 114 ); mUIWindow->addEventListener( Event::OnWindowClose, diff --git a/src/eepp/maps/mapeditor/uimapnew.cpp b/src/eepp/maps/mapeditor/uimapnew.cpp index 128c5d238..b5155d4fa 100644 --- a/src/eepp/maps/mapeditor/uimapnew.cpp +++ b/src/eepp/maps/mapeditor/uimapnew.cpp @@ -38,7 +38,7 @@ UIMapNew::UIMapNew( UIMap* Map, std::function NewMapCb, bool ResizeMap ) mUIWindow = UIWindow::New(); mUIWindow->setSizeWithDecoration( 320, 380 ) - ->setWinFlags( UI_WIN_CLOSE_BUTTON | UI_WIN_USE_DEFAULT_BUTTONS_ACTIONS | + ->setWindowFlags( UI_WIN_CLOSE_BUTTON | UI_WIN_USE_DEFAULT_BUTTONS_ACTIONS | UI_WIN_SHARE_ALPHA_WITH_CHILDS | UI_WIN_MODAL ) ->setMinWindowSize( 320, 380 ); diff --git a/src/eepp/ui/tools/textureatlaseditor.cpp b/src/eepp/ui/tools/textureatlaseditor.cpp index 2c6f4eeb3..5ceb0b909 100644 --- a/src/eepp/ui/tools/textureatlaseditor.cpp +++ b/src/eepp/ui/tools/textureatlaseditor.cpp @@ -295,7 +295,7 @@ void TextureAtlasEditor::fileMenuClick( const Event* Event ) { } else if ( "Open..." == txt ) { UIFileDialog* TGDialog = UIFileDialog::New( UIFileDialog::DefaultFlags, std::string( "*" ) + EE_TEXTURE_ATLAS_EXTENSION ); - TGDialog->setWinFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL ); + TGDialog->setWindowFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL ); TGDialog->setTitle( "Open Texture Atlas" ); TGDialog->addEventListener( Event::OpenFile, cb::Make1( this, &TextureAtlasEditor::openTextureAtlas ) ); diff --git a/src/eepp/ui/tools/textureatlasnew.cpp b/src/eepp/ui/tools/textureatlasnew.cpp index 257c59fc6..8b8731536 100644 --- a/src/eepp/ui/tools/textureatlasnew.cpp +++ b/src/eepp/ui/tools/textureatlasnew.cpp @@ -11,7 +11,7 @@ namespace EE { namespace UI { namespace Tools { TextureAtlasNew::TextureAtlasNew( TGCreateCb NewTGCb ) : mUIWindow( NULL ), mNewTGCb( NewTGCb ) { mUIWindow = UIWindow::New(); - mUIWindow->setSizeWithDecoration( 378, 0 )->setMinWindowSize( 378, 0 )->setWinFlags( + mUIWindow->setSizeWithDecoration( 378, 0 )->setMinWindowSize( 378, 0 )->setWindowFlags( UI_WIN_CLOSE_BUTTON | UI_WIN_USE_DEFAULT_BUTTONS_ACTIONS | UI_WIN_SHARE_ALPHA_WITH_CHILDS | UI_WIN_MODAL ); @@ -130,7 +130,7 @@ void TextureAtlasNew::okClick( const Event* event ) { UIFileDialog* TGDialog = UIFileDialog::New( UIFileDialog::DefaultFlags | UIFileDialog::SaveDialog, "*." + ext ); - TGDialog->setWinFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL ); + TGDialog->setWindowFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL ); TGDialog->setTitle( "Save Texture Atlas" ); TGDialog->addEventListener( Event::SaveFile, cb::Make1( this, &TextureAtlasNew::textureAtlasSave ) ); @@ -208,7 +208,7 @@ void TextureAtlasNew::onDialogFolderSelect( const Event* event ) { if ( mouseEvent->getFlags() & EE_BUTTON_LMASK ) { UIFileDialog* TGDialog = UIFileDialog::New( UIFileDialog::DefaultFlags | UIFileDialog::AllowFolderSelect, "*" ); - TGDialog->setWinFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL ); + TGDialog->setWindowFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL ); TGDialog->setTitle( "Create Texture Atlas ( Select Folder Containing Textures )" ); TGDialog->addEventListener( Event::OpenFile, cb::Make1( this, &TextureAtlasNew::onSelectFolder ) ); diff --git a/src/eepp/ui/uicodeeditor.cpp b/src/eepp/ui/uicodeeditor.cpp index 7359bb166..c9397c1d6 100644 --- a/src/eepp/ui/uicodeeditor.cpp +++ b/src/eepp/ui/uicodeeditor.cpp @@ -290,7 +290,7 @@ void UICodeEditor::draw() { lineNumberDigits, charSize ); } - if ( mColorPreview && mPreviewColorRange.isValid() ) { + if ( mColorPreview && mPreviewColorRange.isValid() && isMouseOver() && !mMinimapHover ) { drawColorPreview( startScroll, lineHeight ); } diff --git a/src/eepp/ui/uiwindow.cpp b/src/eepp/ui/uiwindow.cpp index 16ff3ca8a..ff21fa7e0 100644 --- a/src/eepp/ui/uiwindow.cpp +++ b/src/eepp/ui/uiwindow.cpp @@ -1384,7 +1384,7 @@ Uint32 UIWindow::getWinFlags() const { return mStyleConfig.WinFlags; } -UIWindow* UIWindow::setWinFlags( const Uint32& winFlags ) { +UIWindow* UIWindow::setWindowFlags( const Uint32& winFlags ) { mStyleConfig.WinFlags = winFlags; updateWinFlags(); diff --git a/src/eepp/window/backend/SDL2/displaymanagersdl2.cpp b/src/eepp/window/backend/SDL2/displaymanagersdl2.cpp index 176da02c9..3f7f5029c 100644 --- a/src/eepp/window/backend/SDL2/displaymanagersdl2.cpp +++ b/src/eepp/window/backend/SDL2/displaymanagersdl2.cpp @@ -28,11 +28,11 @@ void DisplayManagerSDL2::setDPIAwareness() { DisplaySDL2::DisplaySDL2( int index ) : Display( index ) {} -std::string DisplaySDL2::getName() { +std::string DisplaySDL2::getName() const { return std::string( SDL_GetDisplayName( index ) ); } -Rect DisplaySDL2::getBounds() { +Rect DisplaySDL2::getBounds() const { SDL_Rect r; if ( SDL_GetDisplayBounds( index, &r ) == 0 ) return Rect( r.x, r.y, r.w, r.h ); @@ -76,7 +76,16 @@ const std::vector& DisplaySDL2::getModes() const { return displayModes; } -DisplayMode DisplaySDL2::getCurrentMode() { +Uint32 DisplaySDL2::getRefreshRate() const { + return getCurrentMode().RefreshRate; +} + +Sizeu DisplaySDL2::getSize() const { + DisplayMode mode( getCurrentMode() ); + return { mode.Width, mode.Height }; +} + +DisplayMode DisplaySDL2::getCurrentMode() const { SDL_DisplayMode mode; if ( SDL_GetCurrentDisplayMode( index, &mode ) == 0 ) { @@ -86,7 +95,7 @@ DisplayMode DisplaySDL2::getCurrentMode() { return DisplayMode( 0, 0, 0, 0 ); } -DisplayMode DisplaySDL2::getClosestDisplayMode( DisplayMode wantedMode ) { +DisplayMode DisplaySDL2::getClosestDisplayMode( DisplayMode wantedMode ) const { SDL_DisplayMode target, mode; target.w = wantedMode.Width; @@ -102,7 +111,7 @@ DisplayMode DisplaySDL2::getClosestDisplayMode( DisplayMode wantedMode ) { return DisplayMode( 0, 0, 0, 0 ); } -Rect DisplaySDL2::getUsableBounds() { +Rect DisplaySDL2::getUsableBounds() const { SDL_Rect r; if ( SDL_GetDisplayUsableBounds( index, &r ) == 0 ) return Rect( r.x, r.y, r.w, r.h ); diff --git a/src/eepp/window/backend/SDL2/displaymanagersdl2.hpp b/src/eepp/window/backend/SDL2/displaymanagersdl2.hpp index 171262aef..05abde64b 100644 --- a/src/eepp/window/backend/SDL2/displaymanagersdl2.hpp +++ b/src/eepp/window/backend/SDL2/displaymanagersdl2.hpp @@ -9,21 +9,25 @@ class EE_API DisplaySDL2 : public Display { public: DisplaySDL2( int index ); - std::string getName(); + std::string getName() const; - Rect getBounds(); + Rect getBounds() const; - Rect getUsableBounds(); + Rect getUsableBounds() const; Float getDPI(); const int& getIndex() const; - DisplayMode getCurrentMode(); + DisplayMode getCurrentMode() const; - DisplayMode getClosestDisplayMode( DisplayMode wantedMode ); + DisplayMode getClosestDisplayMode( DisplayMode wantedMode ) const; const std::vector& getModes() const; + + Uint32 getRefreshRate() const; + + Sizeu getSize() const; }; class EE_API DisplayManagerSDL2 : public DisplayManager { diff --git a/src/eepp/window/engine.cpp b/src/eepp/window/engine.cpp index 64ed329e1..2c7c32bb7 100644 --- a/src/eepp/window/engine.cpp +++ b/src/eepp/window/engine.cpp @@ -252,17 +252,17 @@ WindowSettings Engine::createWindowSettings( IniFile* ini, std::string iniKeyNam ini->readFile(); - int Width = ini->getValueI( iniKeyName, "Width", 800 ); - int Height = ini->getValueI( iniKeyName, "Height", 600 ); - int BitColor = ini->getValueI( iniKeyName, "BitColor", 32 ); - bool Windowed = ini->getValueB( iniKeyName, "Windowed", true ); - bool Resizeable = ini->getValueB( iniKeyName, "Resizeable", true ); - bool Borderless = ini->getValueB( iniKeyName, "Borderless", false ); - bool useDesktopResolution = ini->getValueB( iniKeyName, "UseDesktopResolution", false ); - std::string pixelDensityStr = ini->getValue( iniKeyName, "PixelDensity" ); + int Width = ini->getValueI( iniKeyName, "width", 800 ); + int Height = ini->getValueI( iniKeyName, "height", 600 ); + int BitColor = ini->getValueI( iniKeyName, "bitcolor", 32 ); + bool Windowed = ini->getValueB( iniKeyName, "windowed", true ); + bool Resizeable = ini->getValueB( iniKeyName, "resizeable", true ); + bool Borderless = ini->getValueB( iniKeyName, "borderless", false ); + bool useDesktopResolution = ini->getValueB( iniKeyName, "usedesktopresolution", false ); + std::string pixelDensityStr = ini->getValue( iniKeyName, "pixeldensity" ); float pixelDensity = PixelDensity::getPixelDensity(); bool useScreenKeyboard = - ini->getValueB( iniKeyName, "UseScreenKeyboard", EE_SCREEN_KEYBOARD_ENABLED ); + ini->getValueB( iniKeyName, "usescreenkeyboard", EE_SCREEN_KEYBOARD_ENABLED ); if ( !pixelDensityStr.empty() ) { if ( String::toLower( pixelDensityStr ) == "auto" ) { @@ -277,7 +277,7 @@ WindowSettings Engine::createWindowSettings( IniFile* ini, std::string iniKeyNam } } - std::string backend = ini->getValue( iniKeyName, "Backend", "" ); + std::string backend = ini->getValue( iniKeyName, "backend", "" ); WindowBackend winBackend = getDefaultBackend(); String::toLowerInPlace( backend ); @@ -299,8 +299,8 @@ WindowSettings Engine::createWindowSettings( IniFile* ini, std::string iniKeyNam if ( Resizeable ) Style |= WindowStyle::Resize; - std::string icon = ini->getValue( iniKeyName, "WinIcon", "" ); - std::string title = ini->getValue( iniKeyName, "WinTitle", "" ); + std::string icon = ini->getValue( iniKeyName, "winicon", "" ); + std::string title = ini->getValue( iniKeyName, "wintitle", "" ); WindowSettings WinSettings( Width, Height, title, Style, winBackend, BitColor, icon, pixelDensity, useScreenKeyboard ); @@ -319,41 +319,18 @@ ContextSettings Engine::createContextSettings( IniFile* ini, std::string iniKeyN ini->readFile(); - bool VSync = ini->getValueB( iniKeyName, "VSync", true ); - std::string GLVersion = ini->getValue( iniKeyName, "GLVersion", "0" ); + bool VSync = ini->getValueB( iniKeyName, "vsync", true ); + std::string GLVersion = ini->getValue( iniKeyName, "glversion", "0" ); + int depthBufferSize = ini->getValueI( iniKeyName, "depthbuffersize", 24 ); + int stencilBufferSize = ini->getValueI( iniKeyName, "stencilbuffersize", 1 ); + int multisamples = ini->getValueI( iniKeyName, "multisamples", 0 ); + int frameRateLimit = ini->getValueI( iniKeyName, "frameratelimit", 0 ); + bool doubleBuffering = ini->getValueB( iniKeyName, "doublebuffering", true ); + bool sharedGLContext = ini->getValueB( iniKeyName, "sharedglcontext", false ); - String::toLowerInPlace( GLVersion ); - - GraphicsLibraryVersion GLVer; - if ( "3" == GLVersion || "opengl 3" == GLVersion || "gl3" == GLVersion || - "opengl3" == GLVersion ) - GLVer = GLv_3; - else if ( "4" == GLVersion || "opengl es 2" == GLVersion || "gles2" == GLVersion || - "opengles2" == GLVersion || "es2" == GLVersion ) - GLVer = GLv_ES2; - else if ( "5" == GLVersion || "opengl 3 core profile" == GLVersion || "gl3cp" == GLVersion || - "opengl3cp" == GLVersion || "opengl core profile" == GLVersion || - "core profile" == GLVersion || "cp" == GLVersion ) - GLVer = GLv_3CP; - else if ( "opengl es 1" == GLVersion || "gles1" == GLVersion || "gl es 1" == GLVersion || - "opengl es1" == GLVersion || "opengles1" == GLVersion || "es1" == GLVersion || - "gles 1" == GLVersion ) - GLVer = GLv_ES1; - else if ( "2" == GLVersion || "opengl 2" == GLVersion || "gl2" == GLVersion || - "gl 2" == GLVersion ) - GLVer = GLv_2; - else - GLVer = GLv_default; - - int depthBufferSize = ini->getValueI( iniKeyName, "DepthBufferSize", 24 ); - int stencilBufferSize = ini->getValueI( iniKeyName, "StencilBufferSize", 1 ); - int multisamples = ini->getValueI( iniKeyName, "Multisamples", 0 ); - int frameRateLimit = ini->getValueI( iniKeyName, "FrameRateLimit", 0 ); - bool doubleBuffering = ini->getValueB( iniKeyName, "DoubleBuffering", true ); - bool sharedGLContext = ini->getValueB( iniKeyName, "SharedGLContext", false ); - - return ContextSettings( VSync, GLVer, doubleBuffering, depthBufferSize, stencilBufferSize, - multisamples, sharedGLContext, frameRateLimit ); + return ContextSettings( VSync, Renderer::glVersionFromString( GLVersion ), doubleBuffering, + depthBufferSize, stencilBufferSize, multisamples, sharedGLContext, + frameRateLimit ); } ContextSettings Engine::createContextSettings( std::string iniPath, std::string iniKeyName ) { diff --git a/src/tests/test_all/test.cpp b/src/tests/test_all/test.cpp index c7bbddc30..4631757f4 100644 --- a/src/tests/test_all/test.cpp +++ b/src/tests/test_all/test.cpp @@ -115,18 +115,18 @@ void EETest::init() { IniFile Ini( MyPath + "ee.ini" ); - PartsNum = Ini.getValueI( "EEPP", "ParticlesNum", 1000 ); - mUseShaders = Ini.getValueB( "EEPP", "UseShaders", false ); - mJoyEnabled = Ini.getValueB( "EEPP", "JoystickEnabled", false ); - mDebugUI = Ini.getValueB( "EEPP", "DebugUI", false ); + PartsNum = Ini.getValueI( "EEPP", "particlesnum", 1000 ); + mUseShaders = Ini.getValueB( "EEPP", "useshaders", false ); + mJoyEnabled = Ini.getValueB( "EEPP", "joystickenabled", false ); + mDebugUI = Ini.getValueB( "EEPP", "debugui", false ); #if defined( EE_PLATFORM_TOUCH ) mJoyEnabled = false; #endif - mMusEnabled = Ini.getValueB( "EEPP", "Music", false ); - mLastFPSLimit = Ini.getValueI( "EEPP", "FrameRateLimit", 0 ); - Int32 StartScreen = Ini.getValueI( "EEPP", "StartScreen", 5 ); + mMusEnabled = Ini.getValueB( "EEPP", "music", false ); + mLastFPSLimit = Ini.getValueI( "EEPP", "frameratelimit", 0 ); + Int32 StartScreen = Ini.getValueI( "EEPP", "startscreen", 5 ); WindowSettings WinSettings = EE->createWindowSettings( &Ini ); ContextSettings ConSettings = EE->createContextSettings( &Ini ); @@ -839,7 +839,7 @@ void EETest::createNewUI() { UIWindow* win = UIWindow::New(); win->setSize( 500, 500 ); - win->setWinFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_RESIZEABLE | UI_WIN_MAXIMIZE_BUTTON ); + win->setWindowFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_RESIZEABLE | UI_WIN_MAXIMIZE_BUTTON ); UILinearLayout* layWin = UILinearLayout::NewVertical(); layWin->setLayoutSizePolicy( SizePolicy::MatchParent, SizePolicy::MatchParent ); @@ -919,7 +919,7 @@ void EETest::createNewUI() { UIWindow* win2 = UIWindow::New(); win2->setSize( 500, 500 ); - win2->setWinFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_RESIZEABLE | UI_WIN_MAXIMIZE_BUTTON ); + win2->setWindowFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_RESIZEABLE | UI_WIN_MAXIMIZE_BUTTON ); UIRelativeLayout* rlay = UIRelativeLayout::New(); rlay->setParent( win2 ); @@ -1044,7 +1044,7 @@ void EETest::createColorPicker( Node* node ) { void EETest::createFileDialog() { UIFileDialog* CDialog = UIFileDialog::New(); - CDialog->setWinFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON ); + CDialog->setWindowFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON ); CDialog->addFilePattern( "*.hpp;*.cpp", true ); CDialog->center(); CDialog->show(); @@ -1069,8 +1069,8 @@ static void onWinDragStop( const Event* event ) { void EETest::createDecoratedWindow() { mUIWindow = UIBlurredWindow::New( mBlur ); mUIWindow - ->setWinFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_SHADOW | - UI_WIN_FRAME_BUFFER ) + ->setWindowFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_SHADOW | + UI_WIN_FRAME_BUFFER ) ->setMinWindowSize( 530, 350 ) ->setPosition( 200, 50 ); @@ -1112,10 +1112,10 @@ void EETest::createDecoratedWindow() { const String& txt = menuItem->getText(); if ( "Hide Border" == txt ) { - win->setWinFlags( win->getWinFlags() | UI_WIN_NO_DECORATION ); + win->setWindowFlags( win->getWinFlags() | UI_WIN_NO_DECORATION ); menuItem->setText( "Show Border" ); } else if ( "Show Border" == txt ) { - win->setWinFlags( win->getWinFlags() & ~UI_WIN_NO_DECORATION ); + win->setWindowFlags( win->getWinFlags() & ~UI_WIN_NO_DECORATION ); menuItem->setText( "Hide Border" ); } else if ( "Close" == txt ) { win->closeWindow(); diff --git a/src/tests/ui_perf_test/ui_perf_test.cpp b/src/tests/ui_perf_test/ui_perf_test.cpp index 70d898766..d60b03f5c 100644 --- a/src/tests/ui_perf_test/ui_perf_test.cpp +++ b/src/tests/ui_perf_test/ui_perf_test.cpp @@ -208,7 +208,7 @@ EE_MAIN_FUNC int main( int, char*[] ) { UIWindow* uiWin = UIWindow::NewOpt( UIWindow::LINEAR_LAYOUT ); uiWin->setMinWindowSize( 500, 400 ); - uiWin->setWinFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_RESIZEABLE | UI_WIN_MAXIMIZE_BUTTON ); + uiWin->setWindowFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_RESIZEABLE | UI_WIN_MAXIMIZE_BUTTON ); UITreeView* widgetTree = UITreeView::New(); widgetTree->setLayoutSizePolicy( SizePolicy::MatchParent, SizePolicy::MatchParent ); widgetTree->setParent( uiWin ); diff --git a/src/tools/ecode/appconfig.cpp b/src/tools/ecode/appconfig.cpp index 9aeaccb51..c152fd3cf 100644 --- a/src/tools/ecode/appconfig.cpp +++ b/src/tools/ecode/appconfig.cpp @@ -52,16 +52,17 @@ void AppConfig::load( const std::string& confPath, std::string& keybindingsPath, recentFolders = urlDecode( String::split( recentFol, ';' ) ); initColorScheme = editor.colorScheme = ini.getValue( "editor", "colorscheme", "eepp" ); editor.fontSize = ini.getValue( "editor", "font_size", "11dp" ); - window.size.setWidth( iniState.getValueI( "window", "width", displayDPI > 105 ? 1920 : 1280 ) ); - window.size.setHeight( + windowState.size.setWidth( + iniState.getValueI( "window", "width", displayDPI > 105 ? 1920 : 1280 ) ); + windowState.size.setHeight( iniState.getValueI( "window", "height", displayDPI > 105 ? 1080 : 720 ) ); - window.maximized = iniState.getValueB( "window", "maximized", false ); - window.pixelDensity = iniState.getValueF( "window", "pixeldensity" ); - window.winIcon = ini.getValue( "window", "winicon", resPath + "icon/ee.png" ); - window.panelPartition = iniState.getValue( "window", "panel_partition", "15%" ); - window.displayIndex = iniState.getValueI( "window", "display_index", 0 ); - window.position.x = iniState.getValueI( "window", "x", -1 ); - window.position.y = iniState.getValueI( "window", "y", -1 ); + windowState.maximized = iniState.getValueB( "window", "maximized", false ); + windowState.pixelDensity = iniState.getValueF( "window", "pixeldensity" ); + windowState.winIcon = ini.getValue( "window", "winicon", resPath + "icon/ee.png" ); + windowState.panelPartition = iniState.getValue( "window", "panel_partition", "15%" ); + windowState.displayIndex = iniState.getValueI( "window", "display_index", 0 ); + windowState.position.x = iniState.getValueI( "window", "x", -1 ); + windowState.position.y = iniState.getValueI( "window", "y", -1 ); editor.showLineNumbers = ini.getValueB( "editor", "show_line_numbers", true ); editor.showWhiteSpaces = ini.getValueB( "editor", "show_white_spaces", true ); editor.highlightMatchingBracket = @@ -136,23 +137,23 @@ void AppConfig::save( const std::vector& recentFiles, } editor.colorScheme = colorSchemeName; - window.size = win->getLastWindowedSize(); - window.maximized = win->isMaximized(); - window.displayIndex = win->getCurrentDisplayIndex(); - window.position = win->getPosition(); - if ( window.position.x < 0 ) - window.position.x = 0; - if ( window.position.y < 0 ) - window.position.y = 0; + windowState.size = win->getLastWindowedSize(); + windowState.maximized = win->isMaximized(); + windowState.displayIndex = win->getCurrentDisplayIndex(); + windowState.position = win->getPosition(); + if ( windowState.position.x < 0 ) + windowState.position.x = 0; + if ( windowState.position.y < 0 ) + windowState.position.y = 0; ini.setValue( "editor", "colorscheme", editor.colorScheme ); - iniState.setValueI( "window", "width", window.size.getWidth() ); - iniState.setValueI( "window", "height", window.size.getHeight() ); - iniState.setValueB( "window", "maximized", window.maximized ); - iniState.setValueF( "window", "pixeldensity", window.pixelDensity ); + iniState.setValueI( "window", "width", windowState.size.getWidth() ); + iniState.setValueI( "window", "height", windowState.size.getHeight() ); + iniState.setValueB( "window", "maximized", windowState.maximized ); + iniState.setValueF( "window", "pixeldensity", windowState.pixelDensity ); iniState.setValue( "window", "panel_partition", panelPartition ); - iniState.setValueI( "window", "display_index", window.displayIndex ); - iniState.setValueI( "window", "x", window.position.x ); - iniState.setValueI( "window", "y", window.position.y ); + iniState.setValueI( "window", "display_index", windowState.displayIndex ); + iniState.setValueI( "window", "x", windowState.position.x ); + iniState.setValueI( "window", "y", windowState.position.y ); iniState.setValue( "files", "recentfiles", String::join( urlEncode( recentFiles ), ';' ) ); iniState.setValue( "folders", "recentfolders", String::join( urlEncode( recentFolders ), ';' ) ); @@ -207,6 +208,12 @@ void AppConfig::save( const std::vector& recentFiles, ini.setValue( "terminal", "font_size", term.fontSize.toString() ); ini.setValue( "terminal", "colorscheme", term.colorScheme ); + ini.setValueB( "window", "vsync", context.VSync ); + ini.setValue( "window", "glversion", + Renderer::graphicsLibraryVersionToString( context.Version ) ); + ini.setValueI( "window", "multisamples", context.Multisamples ); + ini.setValueI( "window", "frameratelimit", context.FrameRateLimit ); + ini.writeFile(); iniState.writeFile(); } diff --git a/src/tools/ecode/appconfig.hpp b/src/tools/ecode/appconfig.hpp index d569c764f..e996276da 100644 --- a/src/tools/ecode/appconfig.hpp +++ b/src/tools/ecode/appconfig.hpp @@ -31,7 +31,7 @@ struct UIConfig { ColorSchemePreference colorScheme{ ColorSchemePreference::Dark }; }; -struct WindowConfig { +struct WindowStateConfig { Float pixelDensity{ 0 }; Sizei size{ 1280, 720 }; std::string winIcon; @@ -104,7 +104,8 @@ struct TerminalConfig { }; struct AppConfig { - WindowConfig window; + WindowStateConfig windowState; + ContextSettings context; CodeEditorConfig editor; DocumentConfig doc; TerminalConfig term; diff --git a/src/tools/ecode/ecode.cpp b/src/tools/ecode/ecode.cpp index 4f90b4210..c650211a9 100644 --- a/src/tools/ecode/ecode.cpp +++ b/src/tools/ecode/ecode.cpp @@ -130,6 +130,9 @@ void App::setAppTitle( const std::string& title ) { if ( !title.empty() ) fullTitle += " - " + title; + if ( mBenchmarkMode ) + fullTitle += " - " + String::toString( mWindow->getFPS() ) + " FPS"; + mWindow->setTitle( fullTitle ); } @@ -150,7 +153,7 @@ void App::onDocumentModified( UICodeEditor* editor, TextDocument& ) { void App::openFileDialog() { UIFileDialog* dialog = UIFileDialog::New( UIFileDialog::DefaultFlags, "*", mLastFileFolder.empty() ? "." : mLastFileFolder ); - dialog->setWinFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL ); + dialog->setWindowFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL ); dialog->setTitle( i18n( "open_file", "Open File" ) ); dialog->setCloseShortcut( KEY_ESCAPE ); dialog->addEventListener( Event::OpenFile, [&]( const Event* event ) { @@ -171,7 +174,7 @@ void App::openFolderDialog() { UIFileDialog::New( UIFileDialog::DefaultFlags | UIFileDialog::AllowFolderSelect | UIFileDialog::ShowOnlyFolders, "*", "." ); - dialog->setWinFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL ); + dialog->setWindowFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL ); dialog->setTitle( i18n( "open_folder", "Open Folder" ) ); dialog->setCloseShortcut( KEY_ESCAPE ); dialog->addEventListener( Event::OpenFile, [&]( const Event* event ) { @@ -199,7 +202,7 @@ void App::openFontDialog( std::string& fontPath, bool loadingMonoFont ) { if ( index.isValid() ) dialog->runOnMainThread( [&, dialog, index]() { dialog->getMultiView()->setSelection( index ); } ); - dialog->setWinFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL ); + dialog->setWindowFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL ); dialog->setTitle( i18n( "select_font_file", "Select Font File" ) ); dialog->setCloseShortcut( KEY_ESCAPE ); dialog->addEventListener( Event::OnWindowClose, [&]( const Event* ) { @@ -282,7 +285,7 @@ UIFileDialog* App::saveFileDialog( UICodeEditor* editor, bool focusOnClose ) { return nullptr; UIFileDialog* dialog = UIFileDialog::New( UIFileDialog::DefaultFlags | UIFileDialog::SaveDialog, "." ); - dialog->setWinFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL ); + dialog->setWindowFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL ); dialog->setTitle( i18n( "save_file_as", "Save File As" ) ); dialog->setCloseShortcut( KEY_ESCAPE ); std::string filename( editor->getDocument().getFilename() ); @@ -419,7 +422,7 @@ void App::mainLoop() { mWindow->getInput()->update(); SceneManager::instance()->update(); - if ( SceneManager::instance()->getUISceneNode()->invalidated() ) { + if ( SceneManager::instance()->getUISceneNode()->invalidated() || mBenchmarkMode ) { mWindow->clear(); SceneManager::instance()->draw(); mWindow->display(); @@ -430,6 +433,11 @@ void App::mainLoop() { } else { mWindow->getInput()->waitEvent( Milliseconds( mWindow->hasFocus() ? 16 : 100 ) ); } + + if ( mBenchmarkMode && mSecondsCounter.getElapsedTime() >= Seconds( 1 ) ) { + setAppTitle( mWindowTitle ); + mSecondsCounter.restart(); + } } void App::onFileDropped( String file ) { @@ -488,7 +496,7 @@ App::~App() { void App::createWidgetTreeView() { UIWindow* uiWin = UIWindow::NewOpt( UIWindow::LINEAR_LAYOUT ); uiWin->setMinWindowSize( 600, 400 ); - uiWin->setWinFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_RESIZEABLE | UI_WIN_MAXIMIZE_BUTTON ); + uiWin->setWindowFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_RESIZEABLE | UI_WIN_MAXIMIZE_BUTTON ); UITreeView* widgetTree = UITreeView::New(); widgetTree->setLayoutSizePolicy( SizePolicy::MatchParent, SizePolicy::MatchParent ); widgetTree->setParent( uiWin ); @@ -652,6 +660,8 @@ UIMenu* App::createWindowMenu() { } ); mWindowMenu->addSubMenu( i18n( "ui_prefes_color_scheme", "UI Prefers Color Scheme" ), findIcon( "color-scheme" ), colorsMenu ); + mWindowMenu->addSubMenu( i18n( "ui_renderer", "Renderer" ), findIcon( "renderer" ), + createRendererMenu() ); mWindowMenu ->add( i18n( "ui_scale_factor", "UI Scale Factor (Pixel Density)" ), findIcon( "pixel-density" ) ) @@ -755,7 +765,7 @@ UIMenu* App::createWindowMenu() { "1, and maximum 6. Requires restart." ) ); msgBox->setTitle( mWindowTitle ); msgBox->getTextInput()->setText( - String::format( "%.2f", mConfig.window.pixelDensity ) ); + String::format( "%.2f", mConfig.windowState.pixelDensity ) ); msgBox->setCloseShortcut( { KEY_ESCAPE, 0 } ); msgBox->showWhenReady(); msgBox->addEventListener( Event::MsgBoxConfirmClick, [&, msgBox]( const Event* ) { @@ -763,8 +773,8 @@ UIMenu* App::createWindowMenu() { Float val; if ( String::fromString( val, msgBox->getTextInput()->getText() ) && val >= 1 && val <= 6 ) { - if ( mConfig.window.pixelDensity != val ) { - mConfig.window.pixelDensity = val; + if ( mConfig.windowState.pixelDensity != val ) { + mConfig.windowState.pixelDensity = val; UIMessageBox* msg = UIMessageBox::New( UIMessageBox::OK, i18n( "new_ui_scale_factor", "New UI scale factor assigned.\nPlease " @@ -859,6 +869,93 @@ UIMenu* App::createWindowMenu() { return mWindowMenu; } +UIMenu* App::createRendererMenu() { + mRendererMenu = UIPopUpMenu::New(); + + mRendererMenu->addCheckBox( i18n( "vsync", "VSync" ), mConfig.context.VSync )->setId( "vsync" ); + mRendererMenu->add( i18n( "frame_rate_limit", "Frame Rate Limit" ), findIcon( "fps" ) ) + ->setId( "frame_rate_limit" ); + + mRendererMenu->addEventListener( Event::OnItemClicked, [&]( const Event* event ) { + if ( !event->getNode()->isType( UI_TYPE_MENUITEM ) ) + return; + UIMenuItem* item = event->getNode()->asType(); + if ( "vsync" == item->getId() ) { + mConfig.context.VSync = item->asType()->isActive(); + saveConfig(); + mNotificationCenter->addNotification( + i18n( "vsync_changed", + "Vsync configuration changed.\nRestart ecode to see the changes." ) + .unescape() ); + } else if ( "frame_rate_limit" == item->getId() ) { + UIMessageBox* msgBox = UIMessageBox::New( + UIMessageBox::INPUT, + i18n( "set_frame_rate_limit", "Set Frame Rate Limit:\nSet 0 to disable it.\n" ) + .unescape() ); + msgBox->setTitle( mWindowTitle ); + msgBox->setCloseShortcut( { KEY_ESCAPE, 0 } ); + msgBox->getTextInput()->setAllowOnlyNumbers( true, false ); + msgBox->getTextInput()->setText( String::toString( mConfig.context.FrameRateLimit ) ); + msgBox->showWhenReady(); + msgBox->addEventListener( Event::MsgBoxConfirmClick, [&, msgBox]( const Event* ) { + int val; + if ( String::fromString( val, msgBox->getTextInput()->getText() ) && val >= 0 ) { + mConfig.context.FrameRateLimit = val; + saveConfig(); + mWindow->setFrameRateLimit( val ); + mNotificationCenter->addNotification( + i18n( "frame_rate_limit_applied", "Frame Rate Limit Applied" ) ); + msgBox->closeWindow(); + } + } ); + setFocusEditorOnClose( msgBox ); + } + } ); + + UIPopUpMenu* glVersion = UIPopUpMenu::New(); + std::vector versions = Renderer::getAvailableGraphicsLibraryVersions(); + for ( const auto& ver : versions ) + glVersion + ->addRadioButton( Renderer::graphicsLibraryVersionToString( ver ), + GLi->version() == ver ) + ->setData( ver ); + glVersion->addEventListener( Event::OnItemClicked, [&]( const Event* event ) { + if ( !event->getNode()->isType( UI_TYPE_MENUITEM ) ) + return; + UIMenuItem* item = event->getNode()->asType(); + mConfig.context.Version = static_cast( item->getData() ); + saveConfig(); + mNotificationCenter->addNotification( + i18n( "glversion_changed", + "Renderer version changed.\nRestart ecode to see the changes." ) + .unescape() ); + } ); + mRendererMenu->addSubMenu( i18n( "ui_renderer_version", "Renderer Version" ), + findIcon( "renderer" ), glVersion ); + + UIPopUpMenu* multisampleLvl = UIPopUpMenu::New(); + const std::vector msaaVals = { 0, 2, 4, 8, 16 }; + for ( const auto& val : msaaVals ) + multisampleLvl + ->addRadioButton( String::toString( val ), mConfig.context.Multisamples == val ) + ->setData( val ); + mRendererMenu->addSubMenu( i18n( "ui_multisamples_level", "Multisample Anti-Aliasing Level" ), + findIcon( "multisamples" ), multisampleLvl ); + multisampleLvl->addEventListener( Event::OnItemClicked, [&]( const Event* event ) { + if ( !event->getNode()->isType( UI_TYPE_MENUITEM ) ) + return; + UIMenuItem* item = event->getNode()->asType(); + mConfig.context.Multisamples = item->getData(); + saveConfig(); + mNotificationCenter->addNotification( + i18n( "multisamples_changed", + "Multisample Anti-Aliasing Level applied.\nRestart ecode to see the changes." ) + .unescape() ); + } ); + + return mRendererMenu; +} + UIMenu* App::createViewMenu() { mViewMenu = UIPopUpMenu::New(); mViewMenu->addCheckBox( i18n( "show_line_numbers", "Show Line Numbers" ) ) @@ -3235,17 +3332,19 @@ FontTrueType* App::loadFont( const std::string& name, std::string fontPath, } void App::init( const LogLevel& logLevel, std::string file, const Float& pidelDensity, - const std::string& colorScheme, bool terminal, bool frameBuffer ) { + const std::string& colorScheme, bool terminal, bool frameBuffer, + bool benchmarkMode ) { DisplayManager* displayManager = Engine::instance()->getDisplayManager(); Display* currentDisplay = displayManager->getDisplayIndex( 0 ); mDisplayDPI = currentDisplay->getDPI(); mUseFrameBuffer = frameBuffer; + mBenchmarkMode = benchmarkMode; loadConfig( logLevel ); - currentDisplay = displayManager->getDisplayIndex( mConfig.window.displayIndex < + currentDisplay = displayManager->getDisplayIndex( mConfig.windowState.displayIndex < displayManager->getDisplayCount() - ? mConfig.window.displayIndex + ? mConfig.windowState.displayIndex : 0 ); mDisplayDPI = currentDisplay->getDPI(); mResPath = Sys::getProcessPath(); @@ -3267,10 +3366,11 @@ void App::init( const LogLevel& logLevel, std::string file, const Float& pidelDe mResPath += "assets"; FileSystem::dirAddSlashAtEnd( mResPath ); - mConfig.window.pixelDensity = - pidelDensity > 0 ? pidelDensity - : ( mConfig.window.pixelDensity > 0 ? mConfig.window.pixelDensity - : currentDisplay->getPixelDensity() ); + mConfig.windowState.pixelDensity = + pidelDensity > 0 + ? pidelDensity + : ( mConfig.windowState.pixelDensity > 0 ? mConfig.windowState.pixelDensity + : currentDisplay->getPixelDensity() ); displayManager->enableScreenSaver(); displayManager->enableMouseFocusClickThrough(); @@ -3280,37 +3380,40 @@ void App::init( const LogLevel& logLevel, std::string file, const Float& pidelDe WindowSettings winSettings = engine->createWindowSettings( &mConfig.iniState, "window" ); winSettings.PixelDensity = 1; - winSettings.Width = mConfig.window.size.getWidth(); - winSettings.Height = mConfig.window.size.getHeight(); + winSettings.Width = mConfig.windowState.size.getWidth(); + winSettings.Height = mConfig.windowState.size.getHeight(); if ( winSettings.Icon.empty() ) { - winSettings.Icon = mConfig.window.winIcon; + winSettings.Icon = mConfig.windowState.winIcon; if ( FileSystem::isRelativePath( winSettings.Icon ) ) winSettings.Icon = mResPath + winSettings.Icon; } - ContextSettings contextSettings = engine->createContextSettings( &mConfig.ini, "window" ); - contextSettings.SharedGLContext = true; - mWindow = engine->createWindow( winSettings, contextSettings ); + mConfig.context = engine->createContextSettings( &mConfig.ini, "window" ); + mConfig.context.SharedGLContext = true; + + mWindow = engine->createWindow( winSettings, mConfig.context ); Log::info( "%s (codename: \"%s\") initializing", ecode::Version::getVersionName().c_str(), ecode::Version::getCodename().c_str() ); if ( mWindow->isOpen() ) { + if ( mBenchmarkMode ) + mWindow->setFrameRateLimit( 0 ); #if EE_PLATFORM == EE_PLATFORM_MACOSX macOS_CreateApplicationMenus(); #endif Log::info( "Window creation took: %.2f ms", globalClock.getElapsedTime().asMilliseconds() ); - if ( mConfig.window.position != Vector2i( -1, -1 ) && - mConfig.window.displayIndex < displayManager->getDisplayCount() ) { - mWindow->setPosition( mConfig.window.position.x, mConfig.window.position.y ); + if ( mConfig.windowState.position != Vector2i( -1, -1 ) && + mConfig.windowState.displayIndex < displayManager->getDisplayCount() ) { + mWindow->setPosition( mConfig.windowState.position.x, mConfig.windowState.position.y ); } loadKeybindings(); - PixelDensity::setPixelDensity( mConfig.window.pixelDensity ); + PixelDensity::setPixelDensity( mConfig.windowState.pixelDensity ); - if ( mConfig.window.maximized ) + if ( mConfig.windowState.maximized ) mWindow->maximize(); mWindow->setCloseRequestCallback( @@ -3324,7 +3427,8 @@ void App::init( const LogLevel& logLevel, std::string file, const Float& pidelDe } } ); - PixelDensity::setPixelDensity( eemax( mWindow->getScale(), mConfig.window.pixelDensity ) ); + PixelDensity::setPixelDensity( + eemax( mWindow->getScale(), mConfig.windowState.pixelDensity ) ); mUISceneNode = UISceneNode::New(); mUIColorScheme = mConfig.ui.colorScheme; @@ -3728,7 +3832,8 @@ void App::init( const LogLevel& logLevel, std::string file, const Float& pidelDe } ); mDocInfo->setVisible( mConfig.editor.showDocInfo ); - mProjectSplitter->setSplitPartition( StyleSheetLength( mConfig.window.panelPartition ) ); + mProjectSplitter->setSplitPartition( + StyleSheetLength( mConfig.windowState.panelPartition ) ); if ( mConfig.ui.panelPosition == PanelPosition::Right ) mProjectSplitter->swap(); @@ -3852,6 +3957,9 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) { { 'l', "log-level" }, Log::getMapFlag(), Log::getDefaultLogLevel() ); args::Flag fb( parser, "framebuffer", "Use frame buffer (more memory usage, less CPU usage)", { "fb", "framebuffer" } ); + args::Flag benchmarkMode( parser, "benchmark-mode", + "Render as much as possible to measure the rendering performance.", + { "benchmark-mode" } ); try { #if EE_PLATFORM != EE_PLATFORM_EMSCRIPTEN @@ -3875,8 +3983,8 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) { appInstance = eeNew( App, () ); appInstance->init( logLevel.Get(), filePos ? filePos.Get() : file.Get(), pixelDenstiyConf ? pixelDenstiyConf.Get() : 0.f, - prefersColorScheme ? prefersColorScheme.Get() : "", terminal.Get(), - fb.Get() ); + prefersColorScheme ? prefersColorScheme.Get() : "", terminal.Get(), fb.Get(), + benchmarkMode.Get() ); eeSAFE_DELETE( appInstance ); Engine::destroySingleton(); diff --git a/src/tools/ecode/ecode.hpp b/src/tools/ecode/ecode.hpp index 025fbe3a7..04887537d 100644 --- a/src/tools/ecode/ecode.hpp +++ b/src/tools/ecode/ecode.hpp @@ -32,7 +32,8 @@ class App : public UICodeEditorSplitter::Client { void createWidgetTreeView(); void init( const LogLevel& logLevel, std::string file, const Float& pidelDensity, - const std::string& colorScheme, bool terminal, bool frameBuffer ); + const std::string& colorScheme, bool terminal, bool frameBuffer, + bool benchmarkMode ); void setAppTitle( const std::string& title ); @@ -163,6 +164,7 @@ class App : public UICodeEditorSplitter::Client { UIPopUpMenu* mDocMenu{ nullptr }; UIPopUpMenu* mViewMenu{ nullptr }; UIPopUpMenu* mWindowMenu{ nullptr }; + UIPopUpMenu* mRendererMenu{ nullptr }; UIPopUpMenu* mToolsMenu{ nullptr }; UIPopUpMenu* mProjectTreeMenu{ nullptr }; UIPopUpMenu* mProjectMenu{ nullptr }; @@ -178,8 +180,8 @@ class App : public UICodeEditorSplitter::Client { std::string mPluginsPath; std::string mColorSchemesPath; std::string mKeybindingsPath; - Float mDisplayDPI{ 96 }; std::string mResPath; + Float mDisplayDPI{ 96 }; AutoCompletePlugin* mAutoCompletePlugin{ nullptr }; LinterPlugin* mLinterPlugin{ nullptr }; FormatterPlugin* mFormatterPlugin{ nullptr }; @@ -191,6 +193,10 @@ class App : public UICodeEditorSplitter::Client { bool mDirTreeReady{ false }; bool mIsBundledApp{ false }; bool mUseFrameBuffer{ false }; + bool mBenchmarkMode{ false }; + Time mFrameTime{ Time::Zero }; + Clock mLastRender; + Clock mSecondsCounter; ProjectDocumentConfig mProjectDocConfig; std::unordered_set mTmpDocs; std::string mCurrentProject; @@ -262,6 +268,8 @@ class App : public UICodeEditorSplitter::Client { UIMenu* createWindowMenu(); + UIMenu* createRendererMenu(); + UIMenu* createHelpMenu(); void updateProjectSettingsMenu(); diff --git a/src/tools/eterm/eterm.cpp b/src/tools/eterm/eterm.cpp index 6f437f094..5c3d66b83 100644 --- a/src/tools/eterm/eterm.cpp +++ b/src/tools/eterm/eterm.cpp @@ -97,8 +97,11 @@ void mainLoop() { win->getInput()->waitEvent( Milliseconds( win->hasFocus() ? 16 : 100 ) ); } - if ( benchmarkMode && secondsCounter.getElapsedTime() >= Seconds( 1 ) ) - win->setTitle( "eterm - " + windowStringData + " - " + String::toString( win->getFPS() ) ); + if ( benchmarkMode && secondsCounter.getElapsedTime() >= Seconds( 1 ) ) { + win->setTitle( "eterm - " + windowStringData + " - " + String::toString( win->getFPS() ) + + " FPS" ); + secondsCounter.restart(); + } } EE_MAIN_FUNC int main( int argc, char* argv[] ) { @@ -130,10 +133,12 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) { parser, "execute-in-shell", "execute program in shell", { 'e', "execute" }, "" ); args::Flag vsync( parser, "vsync", "Enable vsync", { "vsync" } ); args::ValueFlag maxFPS( parser, "max-fps", - "Maximum rendering frames per second of the terminal", - { "max-fps" }, 60 ); - args::Flag benchmarkModeFlag( parser, "benchmark-mode", "Render as much as possible.", - { "benchmark-mode" } ); + "Maximum rendering frames per second of the terminal. Default " + "value will be the refresh rate of the screen.", + { "max-fps" }, 0 ); + args::Flag benchmarkModeFlag( + parser, "benchmark-mode", + "Render as much as possible to measure the rendering performance.", { "benchmark-mode" } ); try { parser.ParseCLI( argc, argv ); @@ -208,7 +213,8 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) { ->loadFromFile( resPath + "fonts/NotoEmoji-Regular.ttf" ); } - frameTime = benchmarkMode ? Time::Zero : Milliseconds( 1000.f / (Float)maxFPS.Get() ); + Float realMaxFPS = maxFPS.Get() ? maxFPS.Get() : currentDisplay->getRefreshRate(); + frameTime = benchmarkMode ? Time::Zero : Milliseconds( 1000.f / realMaxFPS ); if ( !terminal || terminal->hasTerminated() ) { FileInfo file( wd ? wd.Get() : FileSystem::getCurrentWorkingDirectory() ); diff --git a/src/tools/uieditor/uieditor.cpp b/src/tools/uieditor/uieditor.cpp index b500ec63c..e279c8298 100644 --- a/src/tools/uieditor/uieditor.cpp +++ b/src/tools/uieditor/uieditor.cpp @@ -170,7 +170,7 @@ void App::createWidgetTreeView() { UIWindow* uiWin = UIWindow::NewOpt( UIWindow::LINEAR_LAYOUT ); uiWin->setMinWindowSize( 600, 400 ); - uiWin->setWinFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_RESIZEABLE | UI_WIN_MAXIMIZE_BUTTON ); + uiWin->setWindowFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_RESIZEABLE | UI_WIN_MAXIMIZE_BUTTON ); UITreeView* widgetTree = UITreeView::New(); widgetTree->setLayoutSizePolicy( SizePolicy::MatchParent, SizePolicy::MatchParent ); widgetTree->setParent( uiWin ); @@ -962,7 +962,7 @@ void App::showFileDialog( const String& title, const std::functionsetTheme( mTheme ); - dialog->setWinFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL ); + dialog->setWindowFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL ); dialog->setTitle( title ); dialog->addEventListener( Event::OpenFile, cb ); dialog->setCloseShortcut( KEY_ESCAPE ); @@ -985,7 +985,7 @@ UIFileDialog* App::saveFileDialog( UICodeEditor* editor, bool focusOnClose ) { return nullptr; UIFileDialog* dialog = UIFileDialog::New( UIFileDialog::DefaultFlags | UIFileDialog::SaveDialog, "." ); - dialog->setWinFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL ); + dialog->setWindowFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL ); dialog->setTitle( i18n( "save_file_as", "Save File As" ) ); dialog->setCloseShortcut( KEY_ESCAPE ); std::string filename( editor->getDocument().getFilename() );