eterm clean up.

This commit is contained in:
Martín Lucas Golini
2024-03-15 20:22:15 -03:00
parent 4cc7201876
commit 8991a089fc
6 changed files with 73 additions and 66 deletions
+5 -5
View File
@@ -52,18 +52,18 @@ void InputSDL::waitEvent( const Time& timeout ) {
} }
bool InputSDL::grabInput() { bool InputSDL::grabInput() {
return ( SDL_GetWindowGrab( static_cast<WindowSDL*>( mWindow )->GetSDLWindow() ) == SDL_TRUE ) return ( SDL_GetWindowGrab( static_cast<WindowSDL*>( mWindow )->getSDLWindow() ) == SDL_TRUE )
? true ? true
: false; : false;
} }
void InputSDL::grabInput( const bool& Grab ) { void InputSDL::grabInput( const bool& Grab ) {
SDL_SetWindowGrab( static_cast<WindowSDL*>( mWindow )->GetSDLWindow(), SDL_SetWindowGrab( static_cast<WindowSDL*>( mWindow )->getSDLWindow(),
Grab ? SDL_TRUE : SDL_FALSE ); Grab ? SDL_TRUE : SDL_FALSE );
} }
void InputSDL::injectMousePos( const Uint16& x, const Uint16& y ) { void InputSDL::injectMousePos( const Uint16& x, const Uint16& y ) {
SDL_WarpMouseInWindow( reinterpret_cast<WindowSDL*>( mWindow )->GetSDLWindow(), x, y ); SDL_WarpMouseInWindow( reinterpret_cast<WindowSDL*>( mWindow )->getSDLWindow(), x, y );
} }
Vector2i InputSDL::queryMousePos() { Vector2i InputSDL::queryMousePos() {
@@ -71,7 +71,7 @@ Vector2i InputSDL::queryMousePos() {
Vector2i tempMouse; Vector2i tempMouse;
Vector2i tempWinPos; Vector2i tempWinPos;
Rect bordersSize; Rect bordersSize;
SDL_Window* sdlw = reinterpret_cast<WindowSDL*>( mWindow )->GetSDLWindow(); SDL_Window* sdlw = reinterpret_cast<WindowSDL*>( mWindow )->getSDLWindow();
SDL_GetGlobalMouseState( &tempMouse.x, &tempMouse.y ); SDL_GetGlobalMouseState( &tempMouse.x, &tempMouse.y );
SDL_GetWindowPosition( sdlw, &tempWinPos.x, &tempWinPos.y ); SDL_GetWindowPosition( sdlw, &tempWinPos.x, &tempWinPos.y );
// Since an unknown version the window position includes the margin from the border size. // Since an unknown version the window position includes the margin from the border size.
@@ -88,7 +88,7 @@ void InputSDL::captureMouse( const bool& capture ) {
} }
bool InputSDL::isMouseCaptured() const { bool InputSDL::isMouseCaptured() const {
return SDL_GetWindowFlags( reinterpret_cast<WindowSDL*>( mWindow )->GetSDLWindow() ) & return SDL_GetWindowFlags( reinterpret_cast<WindowSDL*>( mWindow )->getSDLWindow() ) &
SDL_WINDOW_MOUSE_CAPTURE; SDL_WINDOW_MOUSE_CAPTURE;
} }
+1 -1
View File
@@ -861,7 +861,7 @@ bool WindowSDL::showMessageBox( const MessageBoxType& type, const std::string& t
mSDLWindow ); mSDLWindow );
} }
SDL_Window* WindowSDL::GetSDLWindow() const { SDL_Window* WindowSDL::getSDLWindow() const {
return mSDLWindow; return mSDLWindow;
} }
+1 -1
View File
@@ -86,7 +86,7 @@ class EE_API WindowSDL : public Window {
virtual bool showMessageBox( const MessageBoxType& type, const std::string& title, virtual bool showMessageBox( const MessageBoxType& type, const std::string& title,
const std::string& message ); const std::string& message );
SDL_Window* GetSDLWindow() const; SDL_Window* getSDLWindow() const;
void startOnScreenKeyboard(); void startOnScreenKeyboard();
+3 -3
View File
@@ -45,7 +45,7 @@ void Cell::setData( std::string&& data ) {
calc(); calc();
bool circular = !subscribeToObservers(); bool circular = !subscribeToObservers();
if ( circular ) { if ( circular ) {
displayValue = "!CIRCULAR"; displayValue = "#REF!";
formulaContainsErrors = true; formulaContainsErrors = true;
} else { } else {
setChanged(); setChanged();
@@ -72,7 +72,7 @@ void Cell::calc() {
auto oldDisplayValue = displayValue; auto oldDisplayValue = displayValue;
if ( !hasFormula() && !value.empty() && value[0] == '=' ) { if ( !hasFormula() && !value.empty() && value[0] == '=' ) {
displayValue = "!ERR"; displayValue = "#ERR!";
formulaContainsErrors = true; formulaContainsErrors = true;
return; return;
} else if ( !hasFormula() ) { } else if ( !hasFormula() ) {
@@ -85,7 +85,7 @@ void Cell::calc() {
if ( res ) if ( res )
displayValue = String::fromDouble( *res ); displayValue = String::fromDouble( *res );
else else
displayValue = "!ERR"; displayValue = "#ERR!";
formulaContainsErrors = res ? false : true; formulaContainsErrors = res ? false : true;
@@ -1385,7 +1385,7 @@ void TerminalDisplay::drawGrid( const Vector2f& pos ) {
} }
void TerminalDisplay::draw( const Vector2f& pos ) { void TerminalDisplay::draw( const Vector2f& pos ) {
if ( !mEmulator ) if ( !mEmulator || !mTerminal )
return; return;
mDrawing = true; mDrawing = true;
+62 -55
View File
@@ -98,30 +98,6 @@ void inputCallback( InputEvent* event ) {
} }
} }
void mainLoop() {
bool termNeedsUpdate = false;
win->getInput()->update();
if ( terminal )
termNeedsUpdate = !terminal->update();
if ( terminal && ( benchmarkMode || terminal->isDirty() ) &&
( !termNeedsUpdate || lastRender.getElapsedTime() >= frameTime ) ) {
lastRender.restart();
win->clear();
terminal->draw();
win->display();
} else if ( !benchmarkMode && !termNeedsUpdate ) {
win->getInput()->waitEvent( Milliseconds( win->hasFocus() ? 16 : 100 ) );
}
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[] ) { EE_MAIN_FUNC int main( int argc, char* argv[] ) {
#ifdef EE_DEBUG #ifdef EE_DEBUG
Log::instance()->setLogToStdOut( true ); Log::instance()->setLogToStdOut( true );
@@ -263,42 +239,73 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) {
Float realMaxFPS = maxFPS.Get() ? maxFPS.Get() : currentDisplay->getRefreshRate(); Float realMaxFPS = maxFPS.Get() ? maxFPS.Get() : currentDisplay->getRefreshRate();
frameTime = benchmarkMode ? Time::Zero : Milliseconds( 1000.f / realMaxFPS ); frameTime = benchmarkMode ? Time::Zero : Milliseconds( 1000.f / realMaxFPS );
if ( !terminal || terminal->hasTerminated() ) { FileInfo file( wd ? wd.Get() : FileSystem::getCurrentWorkingDirectory() );
FileInfo file( wd ? wd.Get() : FileSystem::getCurrentWorkingDirectory() ); terminal = TerminalDisplay::create(
terminal = TerminalDisplay::create( win, fontMono, PixelDensity::dpToPx( fontSize.Get() ), win->getSize().asFloat(),
win, fontMono, PixelDensity::dpToPx( fontSize.Get() ), win->getSize().asFloat(), file.isRegularFile() && file.isExecutable() ? file.getFilepath() : shell.Get(),
file.isRegularFile() && file.isExecutable() ? file.getFilepath() : shell.Get(), shellArgs ? String::split( shellArgs.Get() ) : std::vector<std::string>(),
shellArgs ? String::split( shellArgs.Get() ) : std::vector<std::string>(), file.getDirectoryPath(), historySize.Get(), nullptr, fb.Get(),
file.getDirectoryPath(), historySize.Get(), nullptr, fb.Get(), !( file.isRegularFile() && file.isExecutable() ) );
!( file.isRegularFile() && file.isExecutable() ) );
terminal->getTerminal()->setAllowMemoryTrimnming( true );
terminal->pushEventCallback( [&closeOnExit]( const TerminalDisplay::Event& event ) {
if ( event.type == TerminalDisplay::EventType::TITLE ) {
windowStringData = event.eventData;
win->setTitle( "eterm - " + windowStringData );
} else if ( event.type == TerminalDisplay::EventType::PROCESS_EXIT &&
closeOnExit.Get() ) {
win->close();
}
} );
if ( shell )
terminal->setKeepAlive( false );
if ( colorScheme ) { if ( terminal->getTerminal() == nullptr ) {
auto selColorScheme = terminalColorSchemes.find( colorScheme.Get() ); win->close();
if ( selColorScheme != terminalColorSchemes.end() ) win->showMessageBox( EE::Window::Window::MessageBoxType::Error, "eterm",
terminal->setColorScheme( selColorScheme->second ); "Operating System not supported." );
} terminal.reset();
Engine::destroySingleton();
if ( !executeInShell.Get().empty() ) MemoryManager::showResults();
terminal->executeFile( executeInShell.Get() ); return EXIT_FAILURE;
win->startTextInput();
} }
terminal->getTerminal()->setAllowMemoryTrimnming( true );
terminal->pushEventCallback( [&closeOnExit]( const TerminalDisplay::Event& event ) {
if ( event.type == TerminalDisplay::EventType::TITLE ) {
windowStringData = event.eventData;
win->setTitle( "eterm - " + windowStringData );
} else if ( event.type == TerminalDisplay::EventType::PROCESS_EXIT &&
closeOnExit.Get() ) {
win->close();
}
} );
if ( shell )
terminal->setKeepAlive( false );
if ( colorScheme ) {
auto selColorScheme = terminalColorSchemes.find( colorScheme.Get() );
if ( selColorScheme != terminalColorSchemes.end() )
terminal->setColorScheme( selColorScheme->second );
}
if ( !executeInShell.Get().empty() )
terminal->executeFile( executeInShell.Get() );
win->startTextInput();
win->getInput()->pushCallback( &inputCallback ); win->getInput()->pushCallback( &inputCallback );
win->runMainLoop( &mainLoop ); win->runMainLoop( [] {
bool termNeedsUpdate = false;
win->getInput()->update();
if ( terminal )
termNeedsUpdate = !terminal->update();
if ( terminal && ( benchmarkMode || terminal->isDirty() ) &&
( !termNeedsUpdate || lastRender.getElapsedTime() >= frameTime ) ) {
lastRender.restart();
win->clear();
terminal->draw();
win->display();
} else if ( !benchmarkMode && !termNeedsUpdate ) {
win->getInput()->waitEvent( Milliseconds( win->hasFocus() ? 16 : 100 ) );
}
if ( benchmarkMode && secondsCounter.getElapsedTime() >= Seconds( 1 ) ) {
win->setTitle( "eterm - " + windowStringData + " - " +
String::toString( win->getFPS() ) + " FPS" );
secondsCounter.restart();
}
} );
} }
terminal.reset(); terminal.reset();