diff --git a/bin/assets/layouts/test.css b/bin/assets/layouts/test.css index 331697e2c..a9c8ea8ef 100644 --- a/bin/assets/layouts/test.css +++ b/bin/assets/layouts/test.css @@ -309,18 +309,17 @@ CheckBox:checked { } #test_4 > RelativeLayout > TextView { - transition: all 10s; + transition: all 0.2s; } #test_4 > RelativeLayout:hover > TextView { - margin-left: 800dp; + margin-left: 24dp; } TabWidget { padding-left: 8dp; padding-right: 8dp; padding-bottom: 8dp; - padding-top: 20dp; background-color: #656565; } diff --git a/bin/assets/ui/breeze.css b/bin/assets/ui/breeze.css index e8f2a40c2..c86964b9a 100644 --- a/bin/assets/ui/breeze.css +++ b/bin/assets/ui/breeze.css @@ -673,6 +673,7 @@ SpinBox::btnup:hover { MenuBar { height: 24dp; + background-color: var(--back); } Menu, diff --git a/include/eepp/network/http.hpp b/include/eepp/network/http.hpp index d85d713be..8589a7859 100644 --- a/include/eepp/network/http.hpp +++ b/include/eepp/network/http.hpp @@ -174,7 +174,7 @@ class EE_API Http : NonCopyable { ///< target resource. Patch, ///< The PATCH method is used to apply partial modifications to a resource. Connect ///< The CONNECT method starts two-way communications with the requested - ///< resource. It can be used to open a tunnel. + ///< resource. It can be used to open a tunnel. }; /** @brief Enumerate the available states for a request */ @@ -335,6 +335,12 @@ class EE_API Http : NonCopyable { // Types typedef std::map FieldTable; + /** @return True if request is verbose logging */ + bool isVerbose() const; + + /** Set verbose logging */ + void setVerbose( bool verbose ); + private: friend class Http; @@ -360,6 +366,7 @@ class EE_API Http : NonCopyable { bool mCompressedResponse; ///< Request comrpessed response bool mContinue; ///< Resume download mutable bool mCancel; ///< Cancel state of current request + bool mVerbose{ false }; ///< Enable/Disable verbosity ProgressCallback mProgressCallback; ///< Progress callback unsigned int mMaxRedirections; ///< Maximun number of redirections allowed mutable unsigned int mRedirectionCount; ///< Number of redirections followed by the request diff --git a/include/eepp/ui/uifiledialog.hpp b/include/eepp/ui/uifiledialog.hpp index bb6b8f1c1..a291de002 100644 --- a/include/eepp/ui/uifiledialog.hpp +++ b/include/eepp/ui/uifiledialog.hpp @@ -26,15 +26,14 @@ class EE_API UIFileDialog : public UIWindow { ShowHidden = ( 1 << 5 ) }; - static const Uint32 DefaultFlags = FoldersFirst | SortAlphabetically | UIFileDialog::ShowHidden; + static const Uint32 DefaultFlags = UIFileDialog::Flags::FoldersFirst | + UIFileDialog::Flags::SortAlphabetically | + UIFileDialog::Flags::ShowHidden; - static UIFileDialog* New( Uint32 dialogFlags = DefaultFlags, + static UIFileDialog* New( Uint32 dialogFlags = UIFileDialog::DefaultFlags, const std::string& defaultFilePattern = "*", const std::string& defaultDirectory = Sys::getProcessPath() ); - UIFileDialog( Uint32 dialogFlags = DefaultFlags, const std::string& defaultFilePattern = "*", - const std::string& defaultDirectory = Sys::getProcessPath() ); - virtual ~UIFileDialog(); virtual Uint32 getType() const; @@ -138,6 +137,10 @@ class EE_API UIFileDialog : public UIWindow { KeyBindings::Shortcut mOpenShortut{ KEY_RETURN, KeyMod::getDefaultModifier() }; std::shared_ptr mModel; + UIFileDialog( Uint32 dialogFlags = UIFileDialog::DefaultFlags, + const std::string& defaultFilePattern = "*", + const std::string& defaultDirectory = Sys::getProcessPath() ); + virtual void onWindowReady(); virtual Uint32 onKeyUp( const KeyEvent& event ); diff --git a/projects/linux/ee.creator.user b/projects/linux/ee.creator.user index 089b05520..b6ac24ce3 100644 --- a/projects/linux/ee.creator.user +++ b/projects/linux/ee.creator.user @@ -1,6 +1,6 @@ - + EnvironmentId @@ -107,9 +107,9 @@ Desktop Desktop {388e5431-b31b-42b3-b9ad-9002d279d75d} - 12 + 10 0 - 19 + 15 ../../make/linux @@ -1105,7 +1105,7 @@ eepp-UIEditor-debug ProjectExplorer.CustomExecutableRunConfiguration - -x assets/layouts/test_widgets.xml -c assets/ui/breeze.css + --css=assets/layouts/test.css --xml=assets/layouts/test.xml -u true false false diff --git a/src/eepp/network/http.cpp b/src/eepp/network/http.cpp index 22e610986..14fef16ed 100644 --- a/src/eepp/network/http.cpp +++ b/src/eepp/network/http.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -194,6 +195,14 @@ std::string Http::Request::prepareTunnel( const Http& http ) { return out.str(); } +bool Http::Request::isVerbose() const { + return mVerbose; +} + +void Http::Request::setVerbose( bool verbose ) { + mVerbose = verbose; +} + void Http::Request::setContinue( const bool& resume ) { mContinue = resume; } @@ -848,7 +857,10 @@ Http::Response Http::downloadRequest( const Http::Request& request, IOStream& wr // Convert the request to string and send it through the connected socket std::string requestStr = toSend.prepare( *this ); - eePRINTL( "%s", requestStr.c_str() ); + if ( request.isVerbose() ) { + std::cout << "Request:" << std::endl; + std::cout << requestStr << std::endl; + } if ( !requestStr.empty() ) { Socket::Status status; diff --git a/src/eepp/ui/doc/textdocument.cpp b/src/eepp/ui/doc/textdocument.cpp index d3706158c..2d5ac3f3f 100644 --- a/src/eepp/ui/doc/textdocument.cpp +++ b/src/eepp/ui/doc/textdocument.cpp @@ -1127,15 +1127,10 @@ void TextDocument::deleteCurrentLine() { deleteSelection(); return; } - if ( getSelection().start().line() + 1 >= (Int64)linesCount() ) { - remove( { startOfLine( getSelection().start() ), - startOfLine( { getSelection().start().line() - 1, 0 } ) } ); - setSelection( startOfLine( getSelection().start() ) ); - } else { - remove( { startOfLine( getSelection().start() ), - startOfLine( { getSelection().start().line() + 1, 0 } ) } ); - setSelection( startOfLine( getSelection().start() ) ); - } + auto start = startOfLine( getSelection().start() ); + auto end = positionOffset( endOfLine( getSelection().start() ), 1 ); + remove( { start, end } ); + setSelection( start ); } void TextDocument::selectToPreviousChar() { diff --git a/src/eepp/ui/uistyle.cpp b/src/eepp/ui/uistyle.cpp index e3543067c..ec720e5ca 100644 --- a/src/eepp/ui/uistyle.cpp +++ b/src/eepp/ui/uistyle.cpp @@ -161,7 +161,7 @@ bool UIStyle::isStructurallyVolatile() const { } void UIStyle::reloadFontFamily() { - if ( mDefinition->getPropertyIds().contains( (Uint32)PropertyId::FontFamily ) ) { + if ( mDefinition && mDefinition->getPropertyIds().contains( (Uint32)PropertyId::FontFamily ) ) { auto propIt = mDefinition->getProperties().find( (Uint32)PropertyId::FontFamily ); if ( propIt != mDefinition->getProperties().end() ) { applyStyleSheetProperty( propIt->second, nullptr ); diff --git a/src/eepp/ui/uitabwidget.cpp b/src/eepp/ui/uitabwidget.cpp index 890b1bd19..50640b2c4 100644 --- a/src/eepp/ui/uitabwidget.cpp +++ b/src/eepp/ui/uitabwidget.cpp @@ -388,6 +388,11 @@ void UITabWidget::posTabs() { } x += mTabs[i]->getPixelsSize().getWidth() + mStyleConfig.TabSeparation; + + if ( mStyleConfig.TabHeight != 0 && mTabs[i]->getPixelsSize().getHeight() == 0 ) { + mTabs[i]->setPixelsSize( mTabs[i]->getPixelsSize().getWidth(), + PixelDensity::dpToPx( mStyleConfig.TabHeight ) ); + } } updateScrollBar(); diff --git a/src/examples/http_request/http_request.cpp b/src/examples/http_request/http_request.cpp index 70e0f864b..4d7521a0a 100644 --- a/src/examples/http_request/http_request.cpp +++ b/src/examples/http_request/http_request.cpp @@ -5,6 +5,7 @@ void printResponseHeaders( Http::Response& response ) { Http::Response::FieldTable headers = response.getHeaders(); + std::cout << "Response:" << std::endl; std::cout << "HTTP/" << response.getMajorHttpVersion() << "." << response.getMinorHttpVersion() << " " << response.getStatus() << " " << Http::Response::statusToString( response.getStatus() ) << std::endl; @@ -18,31 +19,32 @@ void printResponseHeaders( Http::Response& response ) { EE_MAIN_FUNC int main( int argc, char* argv[] ) { args::ArgumentParser parser( "HTTP request program example" ); - args::HelpFlag help( parser, "help", "Display this help menu", {'h', "help"} ); + args::HelpFlag help( parser, "help", "Display this help menu", { 'h', "help" } ); args::Flag resume( parser, "continue", "Resume getting a partially-downloaded file", - {'c', "continue"} ); - args::Flag compressed( parser, "compressed", "Request compressed response", {"compressed"} ); - args::ValueFlag postData( parser, "data", "HTTP POST data", {'d', "data"} ); - args::ValueFlagList multipartData( parser, "multipart-data", - "Specify multipart MIME data", {'F', "form"} ); + { 'c', "continue" } ); + args::Flag compressed( parser, "compressed", "Request compressed response", { "compressed" } ); + args::ValueFlag postData( parser, "data", "HTTP POST data", { 'd', "data" } ); + args::ValueFlagList multipartData( + parser, "multipart-data", "Specify multipart MIME data", { 'F', "form" } ); args::ValueFlagList headers( parser, "header", "Pass custom header(s) to server", - {'H', "header"} ); + { 'H', "header" } ); args::Flag includeHead( parser, "include", "Include protocol response headers in the output", - {'i', "include"} ); + { 'i', "include" } ); args::Flag insecure( parser, "insecure", "Allow insecure server connections when using SSL", - {'k', "insecure"} ); - args::Flag location( parser, "location", "Follow redirects", {'L', "location"} ); + { 'k', "insecure" } ); + args::Flag location( parser, "location", "Follow redirects", { 'L', "location" } ); args::ValueFlag maxRedirs( - parser, "max-redirs", "Maximum number of redirects allowed", {"max-redirs"} ); + parser, "max-redirs", "Maximum number of redirects allowed", { "max-redirs" } ); args::ValueFlag output( parser, "file", "Write to file instead of stdout", - {'o', "output"} ); + { 'o', "output" } ); args::ValueFlag proxy( parser, "proxy", "[protocol://]host[:port] Use this proxy", - {'x', "proxy"} ); + { 'x', "proxy" } ); args::Flag progress( parser, "progress", "Show current progress of a download", - {'p', "progress"} ); - args::Flag verbose( parser, "verbose", "Make the operation more talkative", {'v', "verbose"} ); + { 'p', "progress" } ); + args::Flag verbose( parser, "verbose", "Make the operation more talkative", + { 'v', "verbose" } ); args::ValueFlag requestMethod( parser, "request", "Specify request command to use", - {'X', "request"} ); + { 'X', "request" } ); args::Positional url( parser, "URL", "The URL to request" ); try { @@ -69,6 +71,8 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) { std::cout << parser; return EXIT_SUCCESS; } else { + request.setVerbose( verbose ); + // If the user provided the URL, creates an instance of URI to parse it. URI uri( url.Get() ); @@ -218,14 +222,16 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) { // Check the status code and display the result Http::Response::Status status = response.getStatus(); - if ( includeHead ) + if ( includeHead || verbose ) printResponseHeaders( response ); if ( status == Http::Response::Ok ) { std::cout << response.getBody(); } else { - std::cout << "Error " << status << std::endl - << response.getStatusDescription() << std::endl; + if ( verbose ) { + std::cout << "Error " << status << std::endl + << response.getStatusDescription() << std::endl; + } std::cout << response.getBody(); } } else { @@ -257,7 +263,7 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) { // Download the request response into a file Http::Response response = http.downloadRequest( request, path, Seconds( 5 ) ); - if ( includeHead ) + if ( includeHead || verbose ) printResponseHeaders( response ); } } diff --git a/src/tools/ecode/ecode.cpp b/src/tools/ecode/ecode.cpp index 0d7c2e36b..e37b23d87 100644 --- a/src/tools/ecode/ecode.cpp +++ b/src/tools/ecode/ecode.cpp @@ -343,6 +343,8 @@ void App::loadConfig( const LogLevel& logLevel ) { mTerminalManager = std::make_unique( this ); mTerminalManager->setTerminalColorSchemesPath( mConfigPath + "terminal" + FileSystem::getOSSlash() + "colorschemes" ); + mTerminalManager->setUseFrameBuffer( mUseFrameBuffer ); + if ( !FileSystem::fileExists( mPluginsPath ) ) FileSystem::makeDir( mPluginsPath ); FileSystem::dirAddSlashAtEnd( mPluginsPath ); @@ -3222,10 +3224,11 @@ 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 ) { + const std::string& colorScheme, bool terminal, bool frameBuffer ) { DisplayManager* displayManager = Engine::instance()->getDisplayManager(); Display* currentDisplay = displayManager->getDisplayIndex( 0 ); mDisplayDPI = currentDisplay->getDPI(); + mUseFrameBuffer = frameBuffer; loadConfig( logLevel ); @@ -3794,6 +3797,8 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) { args::MapFlag logLevel( parser, "log-level", "The level of details that the application will emmit logs.", { 'l', "log-level" }, Log::getMapFlag(), Log::getDefaultLogLevel() ); + args::Flag fb( parser, "framebuffer", "Use frame buffer (more memory usage, less CPU usage)", + { "fb", "framebuffer" } ); try { #if EE_PLATFORM != EE_PLATFORM_EMSCRIPTEN @@ -3817,7 +3822,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() ); + prefersColorScheme ? prefersColorScheme.Get() : "", terminal.Get(), + fb.Get() ); eeSAFE_DELETE( appInstance ); Engine::destroySingleton(); diff --git a/src/tools/ecode/ecode.hpp b/src/tools/ecode/ecode.hpp index 9422b2595..ed7c67770 100644 --- a/src/tools/ecode/ecode.hpp +++ b/src/tools/ecode/ecode.hpp @@ -35,7 +35,7 @@ class App : public UICodeEditorSplitter::Client { void createWidgetTreeView(); void init( const LogLevel& logLevel, std::string file, const Float& pidelDensity, - const std::string& colorScheme, bool terminal ); + const std::string& colorScheme, bool terminal, bool frameBuffer ); void setAppTitle( const std::string& title ); @@ -193,6 +193,7 @@ class App : public UICodeEditorSplitter::Client { size_t mMenuIconSize; bool mDirTreeReady{ false }; bool mIsBundledApp{ false }; + bool mUseFrameBuffer{ false }; ProjectDocumentConfig mProjectDocConfig; std::unordered_set mTmpDocs; std::string mCurrentProject; diff --git a/src/tools/ecode/terminalmanager.cpp b/src/tools/ecode/terminalmanager.cpp index c4ec2eaca..d7c192ff1 100644 --- a/src/tools/ecode/terminalmanager.cpp +++ b/src/tools/ecode/terminalmanager.cpp @@ -78,6 +78,14 @@ void TerminalManager::updateColorSchemeMenu() { } } +bool TerminalManager::getUseFrameBuffer() const { + return mUseFrameBuffer; +} + +void TerminalManager::setUseFrameBuffer( bool useFrameBuffer ) { + mUseFrameBuffer = useFrameBuffer; +} + UIMenu* TerminalManager::createColorSchemeMenu() { mColorSchemeMenuesCreatedWithHeight = mApp->uiSceneNode()->getPixelsSize().getHeight(); size_t maxItems = 19; @@ -162,7 +170,8 @@ UITerminal* TerminalManager::createNewTerminal( const std::string& title, UITabW "", {}, !workingDir.empty() ? workingDir - : ( !mApp->getCurrentProject().empty() ? mApp->getCurrentProject() : "" ) ); + : ( !mApp->getCurrentProject().empty() ? mApp->getCurrentProject() : "" ), + 10000, nullptr, mUseFrameBuffer ); auto ret = mApp->getSplitter()->createWidgetInTabWidget( tabWidget, term, title.empty() ? mApp->i18n( "shell", "Shell" ).toUtf8() : title, true ); mApp->getSplitter()->removeUnusedTab( tabWidget ); diff --git a/src/tools/ecode/terminalmanager.hpp b/src/tools/ecode/terminalmanager.hpp index 1782a5764..2c001989e 100644 --- a/src/tools/ecode/terminalmanager.hpp +++ b/src/tools/ecode/terminalmanager.hpp @@ -41,6 +41,10 @@ class TerminalManager { void updateColorSchemeMenu(); + bool getUseFrameBuffer() const; + + void setUseFrameBuffer( bool useFrameBuffer ); + protected: App* mApp; std::string mTerminalColorSchemesPath; @@ -49,6 +53,7 @@ class TerminalManager { Float mColorSchemeMenuesCreatedWithHeight{ 0 }; std::vector mColorSchemeMenues; + bool mUseFrameBuffer{ false }; }; } // namespace ecode diff --git a/src/tools/eterm/eterm.cpp b/src/tools/eterm/eterm.cpp index ee2fe861e..3aa065917 100644 --- a/src/tools/eterm/eterm.cpp +++ b/src/tools/eterm/eterm.cpp @@ -101,7 +101,7 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) { args::ValueFlag historySize( parser, "scrollback", "Maximum history size (lines)", { 'l', "scrollback" }, 10000 ); args::Flag fb( parser, "framebuffer", "Use frame buffer (more memory usage, less CPU usage)", - { "framebuffer" } ); + { "fb", "framebuffer" } ); args::ValueFlag fontPath( parser, "fontpath", "Font path", { 'f', "font" } ); args::ValueFlag fontSize( parser, "fontsize", "Font size (in dp)", { 's', "fontsize" }, 11 ); @@ -111,6 +111,8 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) { args::ValueFlag pixelDenstiyConf( parser, "pixel-density", "Set default application pixel density", { 'd', "pixel-density" } ); + args::Positional wd( parser, "wording-dir", "Working Directory" ); + try { parser.ParseCLI( argc, argv ); } catch ( const args::Help& ) { @@ -185,8 +187,8 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) { if ( !terminal || terminal->hasTerminated() ) { terminal = TerminalDisplay::create( win, fontMono, PixelDensity::dpToPx( fontSize.Get() ), win->getSize().asFloat(), - shell.Get(), {}, FileSystem::getCurrentWorkingDirectory(), historySize.Get(), - nullptr, fb.Get() ); + shell.Get(), {}, wd ? wd.Get() : FileSystem::getCurrentWorkingDirectory(), + historySize.Get(), nullptr, fb.Get() ); terminal->pushEventCallback( [&]( const TerminalDisplay::Event& event ) { if ( event.type == TerminalDisplay::EventType::TITLE ) win->setTitle( "eterm - " + event.eventData ); diff --git a/src/tools/uieditor/uieditor.cpp b/src/tools/uieditor/uieditor.cpp index bcbf82797..002851344 100644 --- a/src/tools/uieditor/uieditor.cpp +++ b/src/tools/uieditor/uieditor.cpp @@ -7,7 +7,7 @@ This is a real time visual editor for the UI module. The layout files can be edited with any editor, and the layout changes can be seen live with this editor. So this is a layout preview app. The layout is updated every time the layout file is -modified by the user. So you'll need to save the file in your editor to see the changes. This was +modified by the user. You'll need to save the file in your editor to see the changes. This was done in a rush for a personal project ( hence the horrendous code ), but it's quite useful and functional. Project files are created by hand for the moment, and they shuld look like this one: @@ -29,8 +29,8 @@ functional. Project files are created by hand for the moment, and they shuld loo -basepath is optional, otherwise it will take the base path from the xml file itself ( it xml is in -/home/project.xml, basepath it going to be /home ) +basepath is optional, otherwise it will take the base path from the xml file itself ( if the xml is +in /home/project.xml, basepath it going to be /home ) Layout width and height are the default/target window size for the project. @@ -128,15 +128,12 @@ void unloadImages() { GlobalTextureAtlas::instance()->remove( it->second ); TextureFactory::instance()->remove( it->first ); } - imagesLoaded.clear(); } void unloadFonts() { - for ( auto it = fontsLoaded.begin(); it != fontsLoaded.end(); ++it ) { + for ( auto it = fontsLoaded.begin(); it != fontsLoaded.end(); ++it ) FontManager::instance()->remove( it->first ); - } - fontsLoaded.clear(); } @@ -155,20 +152,15 @@ static bool isCSS( const std::string& path ) { static void loadImage( std::string path ) { std::string filename( FileSystem::fileRemoveExtension( FileSystem::fileNameFromPath( path ) ) ); - Uint32 texId = TextureFactory::instance()->loadFromFile( path ); - TextureRegion* texRegion = GlobalTextureAtlas::instance()->add( texId, filename ); - imagesLoaded[texId] = texRegion; } static void loadFont( std::string path ) { std::string filename( FileSystem::fileRemoveExtension( FileSystem::fileNameFromPath( path ) ) ); FontTrueType* font = FontTrueType::New( filename ); - font->loadFromFile( path ); - fontsLoaded[font] = filename; } @@ -177,11 +169,9 @@ static void loadImagesFromFolder( std::string folderPath ) { FileSystem::dirAddSlashAtEnd( folderPath ); - for ( auto it = files.begin(); it != files.end(); ++it ) { - if ( Image::isImageExtension( *it ) ) { + for ( auto it = files.begin(); it != files.end(); ++it ) + if ( Image::isImageExtension( *it ) ) loadImage( folderPath + ( *it ) ); - } - } } static void loadFontsFromFolder( std::string folderPath ) { @@ -189,11 +179,9 @@ static void loadFontsFromFolder( std::string folderPath ) { FileSystem::dirAddSlashAtEnd( folderPath ); - for ( auto it = files.begin(); it != files.end(); ++it ) { - if ( isFont( *it ) ) { + for ( auto it = files.begin(); it != files.end(); ++it ) + if ( isFont( *it ) ) loadFont( folderPath + ( *it ) ); - } - } } static void loadLayoutsFromFolder( std::string folderPath ) { @@ -201,18 +189,27 @@ static void loadLayoutsFromFolder( std::string folderPath ) { FileSystem::dirAddSlashAtEnd( folderPath ); - for ( auto it = files.begin(); it != files.end(); ++it ) { - if ( isXML( *it ) ) { + for ( auto it = files.begin(); it != files.end(); ++it ) + if ( isXML( *it ) ) layouts[FileSystem::fileRemoveExtension( ( *it ) )] = ( folderPath + ( *it ) ); - } - } +} + +static void setUserDefaultTheme() { + useDefaultTheme = true; + uiSceneNode->getUIThemeManager()->setDefaultTheme( theme ); + uiSceneNode->setStyleSheet( theme->getStyleSheet() ); } static void loadStyleSheet( std::string cssPath ) { CSS::StyleSheetParser parser; if ( NULL != uiSceneNode && parser.loadFromFile( cssPath ) ) { - uiSceneNode->setStyleSheet( parser.getStyleSheet() ); + if ( useDefaultTheme ) { + setUserDefaultTheme(); + uiSceneNode->combineStyleSheet( parser.getStyleSheet() ); + } else { + uiSceneNode->setStyleSheet( parser.getStyleSheet() ); + } currentStyleSheet = cssPath; @@ -242,16 +239,13 @@ static void loadLayout( std::string file ) { bool keepWatch = false; for ( auto& directory : fileWatcher->directories() ) { - if ( directory == folder ) { + if ( directory == folder ) keepWatch = true; - } } if ( !keepWatch ) { - if ( watch != 0 ) { + if ( watch != 0 ) fileWatcher->removeWatch( watch ); - } - watch = fileWatcher->addWatch( folder, listener ); } @@ -267,9 +261,8 @@ static void refreshLayout() { if ( !currentLayout.empty() && FileSystem::fileExists( currentLayout ) && uiContainer != NULL ) { if ( !currentStyleSheet.empty() && FileSystem::fileExists( currentStyleSheet ) && - uiContainer != NULL ) { + uiContainer != NULL ) loadStyleSheet( currentStyleSheet ); - } loadLayout( currentLayout ); } @@ -310,9 +303,8 @@ void onRecentFilesClick( const Event* event ) { const String& txt = event->getNode()->asType()->getText(); std::string path( txt.toUtf8() ); - if ( FileSystem::fileExists( path ) && !FileSystem::isDirectory( path ) ) { + if ( FileSystem::fileExists( path ) && !FileSystem::isDirectory( path ) ) loadLayoutFile( path ); - } } void updateRecentFiles() { @@ -331,16 +323,14 @@ void updateRecentFiles() { menu->removeAll(); - for ( size_t i = 0; i < recentFiles.size(); i++ ) { + for ( size_t i = 0; i < recentFiles.size(); i++ ) menu->add( recentFiles[i] ); - } - if ( 0xFFFFFFFF != recentFilesEventClickId ) { + if ( 0xFFFFFFFF != recentFilesEventClickId ) menu->removeEventListener( recentFilesEventClickId ); - } recentFilesEventClickId = - menu->addEventListener( Event::OnItemClicked, cb::Make1( &onRecentFilesClick ) ); + menu->addEventListener( Event::OnItemClicked, &onRecentFilesClick ); } SceneManager::instance()->setCurrentUISceneNode( uiSceneNode ); @@ -362,29 +352,28 @@ void updateRecentProjects() { menu->removeAll(); - for ( size_t i = 0; i < recentProjects.size(); i++ ) { + for ( size_t i = 0; i < recentProjects.size(); i++ ) menu->add( recentProjects[i] ); - } - if ( 0xFFFFFFFF != recentProjectEventClickId ) { + if ( 0xFFFFFFFF != recentProjectEventClickId ) menu->removeEventListener( recentProjectEventClickId ); - } recentProjectEventClickId = - menu->addEventListener( Event::OnItemClicked, cb::Make1( &onRecentProjectClick ) ); + menu->addEventListener( Event::OnItemClicked, &onRecentProjectClick ); } SceneManager::instance()->setCurrentUISceneNode( uiSceneNode ); } void resizeCb( EE::Window::Window* window ) { + uiContainer->setPadding( Rectf( 0, uiMenuBar ? uiMenuBar->getSize().getHeight() : 0.f, 0, 0 ) ); if ( layoutExpanded ) { uiContainer->setSize( uiSceneNode->getSize() ); } else if ( !preserveContainerSize ) { Float scaleW = (Float)uiSceneNode->getSize().getWidth() / (Float)uiContainer->getSize().getWidth(); - Float scaleH = - (Float)uiSceneNode->getSize().getHeight() / (Float)uiContainer->getSize().getHeight(); + Float scaleH = (Float)uiSceneNode->getSize().getHeight() / + ( (Float)uiContainer->getSize().getHeight() ); uiContainer->setScale( scaleW < scaleH ? scaleW : scaleH ); uiContainer->center(); @@ -454,10 +443,8 @@ void onLayoutSelected( const Event* event ) { if ( ( uiLayoutsMenu = uiMenuBar->getPopUpMenu( "Layouts" ) ) && uiLayoutsMenu->getCount() > 0 ) { - for ( size_t i = 0; i < uiLayoutsMenu->getCount(); i++ ) { - UIMenuCheckBox* menuItem = static_cast( uiLayoutsMenu->getItem( i ) ); - menuItem->setActive( false ); - } + for ( size_t i = 0; i < uiLayoutsMenu->getCount(); i++ ) + uiLayoutsMenu->getItem( i )->asType()->setActive( false ); } UIMenuCheckBox* chk = static_cast( event->getNode() ); @@ -465,9 +452,8 @@ void onLayoutSelected( const Event* event ) { std::map::iterator it; - if ( ( it = layouts.find( txt.toUtf8() ) ) != layouts.end() ) { + if ( ( it = layouts.find( txt.toUtf8() ) ) != layouts.end() ) loadLayout( it->second ); - } } void refreshLayoutList() { @@ -484,16 +470,15 @@ void refreshLayoutList() { uiMenuBar->addMenuButton( "Layouts", uiLayoutsMenu ); - uiLayoutsMenu->addEventListener( Event::OnItemClicked, cb::Make1( &onLayoutSelected ) ); + uiLayoutsMenu->addEventListener( Event::OnItemClicked, &onLayoutSelected ); } else { uiLayoutsMenu = uiMenuBar->getPopUpMenu( "Layouts" ); } uiLayoutsMenu->removeAll(); - for ( auto it = layouts.begin(); it != layouts.end(); ++it ) { + for ( auto it = layouts.begin(); it != layouts.end(); ++it ) uiLayoutsMenu->addCheckBox( it->first )->setActive( currentLayout == it->second ); - } } else if ( uiMenuBar->getButton( "Layouts" ) != NULL ) { uiMenuBar->removeMenuButton( "Layouts" ); } @@ -510,9 +495,8 @@ static void loadProjectNodes( pugi::xml_node node ) { if ( name == "uiproject" ) { pugi::xml_node basePathNode = resources.child( "basepath" ); - if ( !basePathNode.empty() ) { + if ( !basePathNode.empty() ) basePath = basePathNode.text().as_string(); - } pugi::xml_node fontNode = resources.child( "font" ); @@ -555,10 +539,8 @@ static void loadProjectNodes( pugi::xml_node node ) { } for ( auto it = widgetRegistered.begin(); it != widgetRegistered.end(); ++it ) { - if ( !UIWidgetCreator::existsCustomWidgetCallback( it->first ) ) { - UIWidgetCreator::addCustomWidgetCallback( it->first, - cb::Make1( createWidget ) ); - } + if ( !UIWidgetCreator::existsCustomWidgetCallback( it->first ) ) + UIWidgetCreator::addCustomWidgetCallback( it->first, &createWidget ); } } @@ -578,9 +560,8 @@ static void loadProjectNodes( pugi::xml_node node ) { if ( !styleSheetNode.empty() ) { std::string cssPath( styleSheetNode.attribute( "path" ).as_string() ); - if ( isCSS( cssPath ) && FileSystem::fileExists( basePath + cssPath ) ) { + if ( isCSS( cssPath ) && FileSystem::fileExists( basePath + cssPath ) ) loadStyleSheet( basePath + cssPath ); - } } pugi::xml_node layoutNode = resources.child( "layout" ); @@ -618,23 +599,20 @@ static void loadProjectNodes( pugi::xml_node node ) { loaded = true; } - if ( width != 0 && height != 0 ) { + if ( width != 0 && height != 0 ) loadedSizedLayout = true; - } } } if ( layouts.size() > 0 && !loaded ) { loadLayout( layouts.begin()->second ); - if ( width != 0 && height != 0 ) { + if ( width != 0 && height != 0 ) loadedSizedLayout = true; - } } - if ( loadedSizedLayout ) { + if ( loadedSizedLayout ) resizeWindowToLayout(); - } } refreshLayoutList(); @@ -655,9 +633,8 @@ void loadLayoutFile( std::string layoutPath ) { recentFiles.insert( recentFiles.begin(), layoutPath ); - if ( recentFiles.size() > 10 ) { + if ( recentFiles.size() > 10 ) recentFiles.resize( 10 ); - } updateRecentFiles(); } @@ -686,9 +663,8 @@ void loadProject( std::string projectPath ) { recentProjects.insert( recentProjects.begin(), projectPath ); - if ( recentProjects.size() > 10 ) { + if ( recentProjects.size() > 10 ) recentProjects.resize( 10 ); - } updateRecentProjects(); } else { @@ -735,30 +711,25 @@ void mainLoop() { window->getInput()->update(); if ( window->getInput()->isKeyUp( KEY_ESCAPE ) && NULL == MsgBox && - onCloseRequestCallback( window ) ) { + onCloseRequestCallback( window ) ) window->close(); - } - if ( window->getInput()->isKeyUp( KEY_F3 ) || window->getInput()->isKeyUp( KEY_BACKSLASH ) ) { + if ( window->getInput()->isKeyUp( KEY_F3 ) || window->getInput()->isKeyUp( KEY_BACKSLASH ) ) console->toggle(); - } - if ( NULL != uiContainer && window->getInput()->isKeyUp( KEY_F1 ) ) { + if ( NULL != uiContainer && window->getInput()->isKeyUp( KEY_F1 ) ) resizeWindowToLayout(); - } if ( window->getInput()->isKeyUp( KEY_F6 ) ) { uiSceneNode->setHighlightFocus( !uiSceneNode->getHighlightFocus() ); uiSceneNode->setHighlightOver( !uiSceneNode->getHighlightOver() ); } - if ( window->getInput()->isKeyUp( KEY_F7 ) ) { + if ( window->getInput()->isKeyUp( KEY_F7 ) ) uiSceneNode->setDrawBoxes( !uiSceneNode->getDrawBoxes() ); - } - if ( window->getInput()->isKeyUp( KEY_F8 ) ) { + if ( window->getInput()->isKeyUp( KEY_F8 ) ) uiSceneNode->setDrawDebugData( !uiSceneNode->getDrawDebugData() ); - } if ( window->getInput()->isKeyUp( KEY_F9 ) ) { Clock clock; @@ -767,27 +738,11 @@ void mainLoop() { clock.getElapsedTime().asMilliseconds() ); } - if ( mousePos != window->getInput()->getMousePos() ) { - mousePos = window->getInput()->getMousePos(); - mouseClock.restart(); - - if ( uiMenuBar->getAlpha() != 255 && uiMenuBar->getActionManager()->isEmpty() ) { - uiMenuBar->runAction( - Actions::Fade::New( uiMenuBar->getAlpha(), 255, Milliseconds( 250 ) ) ); - } - } else if ( mouseClock.getElapsedTime() > Seconds( 1 ) ) { - if ( uiMenuBar->getAlpha() == 255 && uiMenuBar->getActionManager()->isEmpty() ) { - uiMenuBar->runAction( Actions::Fade::New( 255, 0, Milliseconds( 250 ) ) ); - } - } - - if ( updateLayout && waitClock.getElapsedTime().asMilliseconds() > 250.f ) { + if ( updateLayout && waitClock.getElapsedTime().asMilliseconds() > 250.f ) refreshLayout(); - } - if ( updateStyleSheet && cssWaitClock.getElapsedTime().asMilliseconds() > 250.f ) { + if ( updateStyleSheet && cssWaitClock.getElapsedTime().asMilliseconds() > 250.f ) refreshStyleSheet(); - } SceneManager::instance()->update(); @@ -822,60 +777,44 @@ void projectOpen( const Event* event ) { loadProject( event->getNode()->asType()->getFullPath() ); } +static void showFileDialog( const String& title, const std::function& cb, + const std::string& filePattern = "*", + const Uint32& dialogFlags = UIFileDialog::Flags::FoldersFirst | + UIFileDialog::Flags::SortAlphabetically | + UIFileDialog::Flags::ShowHidden ) { + UIFileDialog* TGDialog = UIFileDialog::New( dialogFlags, filePattern ); + TGDialog->setTheme( theme ); + TGDialog->setWinFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL ); + TGDialog->setTitle( title ); + TGDialog->addEventListener( Event::OpenFile, cb ); + TGDialog->center(); + TGDialog->show(); +} + void fileMenuClick( const Event* event ) { if ( !event->getNode()->isType( UI_TYPE_MENUITEM ) ) return; - const String& txt = event->getNode()->asType()->getText(); + const String& id = event->getNode()->asType()->getId(); SceneManager::instance()->setCurrentUISceneNode( appUiSceneNode ); - if ( "Open project..." == txt ) { - UIFileDialog* TGDialog = UIFileDialog::New( UIFileDialog::DefaultFlags, "*.xml" ); - TGDialog->setTheme( theme ); - TGDialog->setWinFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL ); - TGDialog->setTitle( "Open layout..." ); - TGDialog->addEventListener( Event::OpenFile, cb::Make1( projectOpen ) ); - TGDialog->center(); - TGDialog->show(); - } else if ( "Open layout..." == txt ) { - UIFileDialog* TGDialog = UIFileDialog::New( UIFileDialog::DefaultFlags, "*.xml" ); - TGDialog->setTheme( theme ); - TGDialog->setWinFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL ); - TGDialog->setTitle( "Open layout..." ); - TGDialog->addEventListener( Event::OpenFile, cb::Make1( layoutOpen ) ); - TGDialog->center(); - TGDialog->show(); - } else if ( "Close" == txt ) { + if ( "open-project" == id ) { + showFileDialog( "Open project...", &projectOpen, "*.xml" ); + } else if ( "open-layout" == id ) { + showFileDialog( "Open layout...", &layoutOpen, "*.xml" ); + } else if ( "close" == id ) { closeProject(); - } else if ( "Quit" == txt ) { + } else if ( "quit" == id ) { onCloseRequestCallback( window ); - } else if ( "Load images from path..." == txt ) { - UIFileDialog* TGDialog = - UIFileDialog::New( UIFileDialog::DefaultFlags | UIFileDialog::AllowFolderSelect ); - TGDialog->setTheme( theme ); - TGDialog->setWinFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL ); - TGDialog->setTitle( "Open images from folder..." ); - TGDialog->addEventListener( Event::OpenFile, cb::Make1( imagePathOpen ) ); - TGDialog->center(); - TGDialog->show(); - } else if ( "Load fonts from path..." == txt ) { - UIFileDialog* TGDialog = - UIFileDialog::New( UIFileDialog::DefaultFlags | UIFileDialog::AllowFolderSelect ); - TGDialog->setTheme( theme ); - TGDialog->setWinFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL ); - TGDialog->setTitle( "Open fonts from folder..." ); - TGDialog->addEventListener( Event::OpenFile, cb::Make1( fontPathOpen ) ); - TGDialog->center(); - TGDialog->show(); - } else if ( "Load style sheet from path..." == txt ) { - UIFileDialog* TGDialog = UIFileDialog::New( UIFileDialog::DefaultFlags, "*.css" ); - TGDialog->setTheme( theme ); - TGDialog->setWinFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL ); - TGDialog->setTitle( "Open style sheet from path..." ); - TGDialog->addEventListener( Event::OpenFile, cb::Make1( styleSheetPathOpen ) ); - TGDialog->center(); - TGDialog->show(); + } else if ( "load-images-from-path" == id ) { + showFileDialog( "Open images from folder...", &imagePathOpen, "*", + UIFileDialog::DefaultFlags | UIFileDialog::AllowFolderSelect ); + } else if ( "load-fonts-from-path" == id ) { + showFileDialog( "Open fonts from folder...", &fontPathOpen, "*", + UIFileDialog::DefaultFlags | UIFileDialog::AllowFolderSelect ); + } else if ( "load-css-from-path" == id ) { + showFileDialog( "Open style sheet from path...", &styleSheetPathOpen, "*.css" ); } SceneManager::instance()->setCurrentUISceneNode( uiSceneNode ); @@ -888,32 +827,42 @@ void createAppMenu() { size_t iconSize = PixelDensity::dpToPxI( 16 ); UIPopUpMenu* uiPopMenu = UIPopUpMenu::New(); - uiPopMenu->add( "Open project...", - appUiSceneNode->findIconDrawable( "document-open", iconSize ) ); + uiPopMenu + ->add( "Open project...", appUiSceneNode->findIconDrawable( "document-open", iconSize ) ) + ->setId( "open-project" ); uiPopMenu->addSeparator(); - uiPopMenu->add( "Open layout...", - appUiSceneNode->findIconDrawable( "document-open", iconSize ) ); + uiPopMenu + ->add( "Open layout...", appUiSceneNode->findIconDrawable( "document-open", iconSize ) ) + ->setId( "open-layout" ); uiPopMenu->addSeparator(); - uiPopMenu->addSubMenu( "Recent files", NULL, UIPopUpMenu::New() ); - uiPopMenu->addSubMenu( "Recent projects", NULL, UIPopUpMenu::New() ); + uiPopMenu->addSubMenu( "Recent files", NULL, UIPopUpMenu::New() )->setId( "recent-files" ); + uiPopMenu->addSubMenu( "Recent projects", NULL, UIPopUpMenu::New() ) + ->setId( "recent-projects" ); uiPopMenu->addSeparator(); - uiPopMenu->add( "Close", appUiSceneNode->findIconDrawable( "document-close", iconSize ) ); + uiPopMenu->add( "Close", appUiSceneNode->findIconDrawable( "document-close", iconSize ) ) + ->setId( "close" ); uiPopMenu->addSeparator(); - uiPopMenu->add( "Quit", appUiSceneNode->findIconDrawable( "quit", iconSize ) ); + uiPopMenu->add( "Quit", appUiSceneNode->findIconDrawable( "quit", iconSize ) )->setId( "quit" ); uiMenuBar->addMenuButton( "File", uiPopMenu ); - uiPopMenu->addEventListener( Event::OnItemClicked, cb::Make1( fileMenuClick ) ); + uiPopMenu->addEventListener( Event::OnItemClicked, &fileMenuClick ); UIPopUpMenu* uiResourceMenu = UIPopUpMenu::New(); - uiResourceMenu->add( "Load images from path...", - appUiSceneNode->findIconDrawable( "document-open", iconSize ) ); + uiResourceMenu + ->add( "Load images from path...", + appUiSceneNode->findIconDrawable( "document-open", iconSize ) ) + ->setId( "load-images-from-path" ); uiResourceMenu->addSeparator(); - uiResourceMenu->add( "Load fonts from path...", - appUiSceneNode->findIconDrawable( "document-open", iconSize ) ); + uiResourceMenu + ->add( "Load fonts from path...", + appUiSceneNode->findIconDrawable( "document-open", iconSize ) ) + ->setId( "load-fonts-from-path" ); uiResourceMenu->addSeparator(); - uiResourceMenu->add( "Load style sheet from path...", - appUiSceneNode->findIconDrawable( "document-open", iconSize ) ); + uiResourceMenu + ->add( "Load style sheet from path...", + appUiSceneNode->findIconDrawable( "document-open", iconSize ) ) + ->setId( "load-css-from-path" ); uiMenuBar->addMenuButton( "Resources", uiResourceMenu ); - uiResourceMenu->addEventListener( Event::OnItemClicked, cb::Make1( fileMenuClick ) ); + uiResourceMenu->addEventListener( Event::OnItemClicked, &fileMenuClick ); console = UIConsole::New(); console->setQuakeMode( true ); @@ -922,12 +871,6 @@ void createAppMenu() { SceneManager::instance()->setCurrentUISceneNode( uiSceneNode ); } -void setUserDefaultTheme() { - useDefaultTheme = true; - uiSceneNode->getUIThemeManager()->setDefaultTheme( theme ); - uiSceneNode->combineStyleSheet( theme->getStyleSheet() ); -} - #if EE_PLATFORM == EE_PLATFORM_EMSCRIPTEN std::vector parseEmscriptenArgs( int argc, char* argv[] ) { if ( argc < 1 ) @@ -996,13 +939,11 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) { Display* currentDisplay = displayManager->getDisplayIndex( 0 ); Float pixelDensity = currentDisplay->getPixelDensity(); - if ( pixelDenstiyConf ) { + if ( pixelDenstiyConf ) pixelDensity = pixelDenstiyConf.Get(); - } - if ( preserveContainerSizeFlag ) { + if ( preserveContainerSizeFlag ) preserveContainerSize = true; - } Log::instance()->setLiveWrite( true ); Log::instance()->setConsoleOutput( true ); @@ -1017,23 +958,13 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) { if ( window->isOpen() ) { PixelDensity::setPixelDensity( eemax( window->getScale(), pixelDensity ) ); - window->setCloseRequestCallback( cb::Make1( onCloseRequestCallback ) ); - - std::string pd; - if ( PixelDensity::getPixelDensity() >= 1.5f ) - pd = "1.5x"; - else if ( PixelDensity::getPixelDensity() >= 2.f ) - pd = "2x"; + window->setCloseRequestCallback( &onCloseRequestCallback ); FontTrueType* font = FontTrueType::New( "NotoSans-Regular", resPath + "assets/fonts/NotoSans-Regular.ttf" ); FontTrueType::New( "monospace", resPath + "assets/fonts/DejaVuSansMono.ttf" ); - theme = UITheme::load( "uitheme" + pd, "uitheme" + pd, - resPath + "assets/ui/uitheme" + pd + ".eta", font, - resPath + "assets/ui/uitheme.css" ); - /*theme = UITheme::load( "uitheme", "uitheme", "", font, resPath + "assets/ui/breeze.css" - * );*/ + theme = UITheme::load( "uitheme", "uitheme", "", font, resPath + "assets/ui/breeze.css" ); uiSceneNode = UISceneNode::New(); uiSceneNode->setId( "uiSceneNode" ); @@ -1056,10 +987,6 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) { uiSceneNode->getUIThemeManager()->setDefaultFont( font )->setDefaultEffectsEnabled( true ); - if ( useAppTheme.Get() ) { - setUserDefaultTheme(); - } - loadConfig(); createAppMenu(); @@ -1073,19 +1000,22 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) { resizeCb( window ); - window->pushResizeCallback( cb::Make1( resizeCb ) ); + uiMenuBar->addEventListener( Event::OnSizeChange, + [&]( const Event* ) { resizeCb( window ); } ); - if ( cssFile ) { + window->pushResizeCallback( &resizeCb ); + + if ( useAppTheme.Get() ) + useDefaultTheme = true; + + if ( cssFile ) loadStyleSheet( cssFile.Get() ); - } - if ( xmlFile ) { + if ( xmlFile ) loadLayoutFile( xmlFile.Get() ); - } - if ( projectFile ) { + if ( projectFile ) loadProject( projectFile.Get() ); - } #if EE_PLATFORM == EE_PLATFORM_EMSCRIPTEN if ( !xmlFile && !cssFile ) @@ -1098,8 +1028,6 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) { saveConfig(); - eeSAFE_DELETE( console ); - Engine::destroySingleton(); MemoryManager::showResults();