From ab04f9b06eef86fd2173d31e29b2c8aac4a6dbf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Sun, 2 Apr 2023 19:37:31 -0300 Subject: [PATCH] eepp: Added Window::showMessageBox. ecode: Closes SpartanJ/ecode#93 (ecode does not properly warn the user of the lack of GPU acceleration). Minor refactor. --- include/eepp/ui/doc/textdocument.hpp | 5 ++--- include/eepp/window/window.hpp | 13 +++++++++++ src/eepp/ui/doc/textdocument.cpp | 8 +++---- src/eepp/window/backend/SDL2/windowsdl2.cpp | 22 +++++++++++++++++++ src/eepp/window/backend/SDL2/windowsdl2.hpp | 5 +++++ src/eepp/window/window.cpp | 4 ++++ src/tools/ecode/ecode.cpp | 13 +++++++++++ .../ecode/plugins/lsp/lspdocumentclient.cpp | 2 +- .../ecode/plugins/lsp/lspdocumentclient.hpp | 2 +- 9 files changed, 65 insertions(+), 9 deletions(-) diff --git a/include/eepp/ui/doc/textdocument.hpp b/include/eepp/ui/doc/textdocument.hpp index ef738793e..edb6859ac 100644 --- a/include/eepp/ui/doc/textdocument.hpp +++ b/include/eepp/ui/doc/textdocument.hpp @@ -87,8 +87,7 @@ class EE_API TextDocument { onDocumentLoaded( doc ); } virtual void onDocumentSyntaxDefinitionChange( const SyntaxDefinition& ) {} - virtual void onDocumentMoveHighlight( const Int64& /*fromLine*/, - const Int64& /*numLines*/ ){}; + virtual void onDocumentLineMove( const Int64& /*fromLine*/, const Int64& /*numLines*/ ){}; }; TextDocument( bool verbose = true ); @@ -634,7 +633,7 @@ class EE_API TextDocument { void notifySyntaxDefinitionChange(); - void notifiyDocumentMoveHighlight( const Int64& fromLine, const Int64& numLines ); + void notifiyDocumenLineMove( const Int64& fromLine, const Int64& numLines ); void insertAtStartOfSelectedLines( const String& text, bool skipEmpty ); diff --git a/include/eepp/window/window.hpp b/include/eepp/window/window.hpp index 3520a943c..1bc49231a 100644 --- a/include/eepp/window/window.hpp +++ b/include/eepp/window/window.hpp @@ -463,8 +463,21 @@ class EE_API Window { * per second. */ const System::Time& getRenderTimePerSecond() const; + /** @return The last windowed size of the window */ const Sizei& getLastWindowedSize() const; + /** @return True if implements native message boxes */ + virtual bool hasNativeMessageBox() const { return false; }; + + /** Native message box types */ + enum class MessageBoxType { Error, Warning, Information }; + + /** Shows a native message box. + * @return True if message box was shown + */ + virtual bool showMessageBox( const MessageBoxType& type, const std::string& title, + const std::string& message ); + protected: friend class Engine; friend class Input; diff --git a/src/eepp/ui/doc/textdocument.cpp b/src/eepp/ui/doc/textdocument.cpp index ec2bbdff8..2c2e08532 100644 --- a/src/eepp/ui/doc/textdocument.cpp +++ b/src/eepp/ui/doc/textdocument.cpp @@ -917,7 +917,7 @@ TextPosition TextDocument::insert( const size_t& cursorIdx, TextPosition positio if ( linesAdd > 0 ) { mHighlighter->moveHighlight( position.line(), linesAdd ); - notifiyDocumentMoveHighlight( position.line(), linesAdd ); + notifiyDocumenLineMove( position.line(), linesAdd ); } notifyTextChanged( { { position, position }, text } ); @@ -1062,7 +1062,7 @@ size_t TextDocument::remove( const size_t& cursorIdx, TextRange range, if ( linesRemoved > 0 ) { mHighlighter->moveHighlight( range.start().line(), -linesRemoved ); - notifiyDocumentMoveHighlight( range.start().line(), -linesRemoved ); + notifiyDocumenLineMove( range.start().line(), -linesRemoved ); } notifyTextChanged( { originalRange, "" } ); @@ -2598,10 +2598,10 @@ void TextDocument::notifySyntaxDefinitionChange() { } } -void TextDocument::notifiyDocumentMoveHighlight( const Int64& fromLine, const Int64& numLines ) { +void TextDocument::notifiyDocumenLineMove( const Int64& fromLine, const Int64& numLines ) { Lock l( mClientsMutex ); for ( auto& client : mClients ) { - client->onDocumentMoveHighlight( fromLine, numLines ); + client->onDocumentLineMove( fromLine, numLines ); } } diff --git a/src/eepp/window/backend/SDL2/windowsdl2.cpp b/src/eepp/window/backend/SDL2/windowsdl2.cpp index c2b5e2817..2cfdab3cd 100644 --- a/src/eepp/window/backend/SDL2/windowsdl2.cpp +++ b/src/eepp/window/backend/SDL2/windowsdl2.cpp @@ -828,6 +828,28 @@ Float WindowSDL::getScale() { return (Float)realX / (Float)scaledX; } +bool WindowSDL::hasNativeMessageBox() const { + return true; +} + +Uint32 toSDLMsgBoxType( const Window::MessageBoxType& type ) { + switch ( type ) { + case Window::MessageBoxType::Error: + return SDL_MESSAGEBOX_ERROR; + case Window::MessageBoxType::Warning: + return SDL_MESSAGEBOX_WARNING; + case Window::MessageBoxType::Information: + return SDL_MESSAGEBOX_INFORMATION; + } + return SDL_MESSAGEBOX_INFORMATION; +} + +bool WindowSDL::showMessageBox( const MessageBoxType& type, const std::string& title, + const std::string& message ) { + return 0 == SDL_ShowSimpleMessageBox( toSDLMsgBoxType( type ), title.c_str(), message.c_str(), + mSDLWindow ); +} + SDL_Window* WindowSDL::GetSDLWindow() const { return mSDLWindow; } diff --git a/src/eepp/window/backend/SDL2/windowsdl2.hpp b/src/eepp/window/backend/SDL2/windowsdl2.hpp index 56d76aca6..12e77dd60 100644 --- a/src/eepp/window/backend/SDL2/windowsdl2.hpp +++ b/src/eepp/window/backend/SDL2/windowsdl2.hpp @@ -79,6 +79,11 @@ class EE_API WindowSDL : public Window { virtual Float getScale(); + virtual bool hasNativeMessageBox() const; + + virtual bool showMessageBox( const MessageBoxType& type, const std::string& title, + const std::string& message ); + SDL_Window* GetSDLWindow() const; void startTextInput(); diff --git a/src/eepp/window/window.cpp b/src/eepp/window/window.cpp index 0aa771655..58727e5bd 100644 --- a/src/eepp/window/window.cpp +++ b/src/eepp/window/window.cpp @@ -341,6 +341,10 @@ const Sizei& Window::getLastWindowedSize() const { return mLastWindowedSize; } +bool Window::showMessageBox( const MessageBoxType&, const std::string&, const std::string& ) { + return false; +} + void Window::calculateFps() { if ( mFrameData.FPS.LastCheck.getElapsedTime().asSeconds() >= 1.f ) { mFrameData.FPS.Current = mFrameData.FPS.Count; diff --git a/src/tools/ecode/ecode.cpp b/src/tools/ecode/ecode.cpp index 2a0de16b7..418dafa28 100644 --- a/src/tools/ecode/ecode.cpp +++ b/src/tools/ecode/ecode.cpp @@ -2929,6 +2929,19 @@ void App::init( const LogLevel& logLevel, std::string file, const Float& pidelDe ecode::Version::getCodename().c_str() ); if ( mWindow->isOpen() ) { + // Only verify GPU driver availability on Windows. + // macOS will have at least a fallback renderer + // Linux will have at least Mesa drivers with LLVM Pipe +#if EE_PLATFORM == EE_PLATFORM_WIN + if ( !GLi->shadersSupported() ) { + mWindow->showMessageBox( + EE::Window::Window::MessageBoxType::Error, "ecode", + "ecode detected that there are no GPU drivers available or that the GPU does not " + "support shaders.\nThis will prevent ecode to properly function.\nPlease check " + "that your GPU drivers are installed." ); + return; + } +#endif #if EE_PLATFORM == EE_PLATFORM_MACOSX macOS_CreateApplicationMenus(); #endif diff --git a/src/tools/ecode/plugins/lsp/lspdocumentclient.cpp b/src/tools/ecode/plugins/lsp/lspdocumentclient.cpp index 95b0d838e..61eddce5d 100644 --- a/src/tools/ecode/plugins/lsp/lspdocumentclient.cpp +++ b/src/tools/ecode/plugins/lsp/lspdocumentclient.cpp @@ -233,7 +233,7 @@ void LSPDocumentClient::processTokens( const LSPSemanticTokensDelta& tokens ) { mRunningSemanticTokens = false; } -void LSPDocumentClient::onDocumentMoveHighlight( const Int64& fromLine, const Int64& numLines ) { +void LSPDocumentClient::onDocumentLineMove( const Int64& fromLine, const Int64& numLines ) { Int64 linesCount = mDoc->linesCount(); if ( numLines > 0 ) { for ( Int64 i = linesCount - 1; i >= fromLine; --i ) { diff --git a/src/tools/ecode/plugins/lsp/lspdocumentclient.hpp b/src/tools/ecode/plugins/lsp/lspdocumentclient.hpp index e7ab596b8..adc780a21 100644 --- a/src/tools/ecode/plugins/lsp/lspdocumentclient.hpp +++ b/src/tools/ecode/plugins/lsp/lspdocumentclient.hpp @@ -37,7 +37,7 @@ class LSPDocumentClient : public TextDocument::Client { virtual void onDocumentDirtyOnFileSystem( TextDocument* ); virtual void onDocumentMoved( TextDocument* ); virtual void onDocumentReloaded( TextDocument* ); - virtual void onDocumentMoveHighlight( const Int64& fromLine, const Int64& numLines ); + virtual void onDocumentLineMove( const Int64& fromLine, const Int64& numLines ); void notifyOpen();