From 2541dccfc99d45552c43e98769019e592d8b9222 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Thu, 8 Feb 2024 22:25:18 -0300 Subject: [PATCH] 7GUIs circle drawer WIP. UILoader rendering glitch fix. Git create branch fix checkout in subrepos. UIMessageBox don't focus on any disabled input by default. --- include/eepp/ui/uinode.hpp | 4 +- include/eepp/window/window.hpp | 4 +- premake4.lua | 6 ++ premake5.lua | 6 ++ projects/linux/ee.creator.user | 25 +++++- projects/linux/ee.files | 1 + src/eepp/ui/uiloader.cpp | 6 ++ src/eepp/ui/uimessagebox.cpp | 6 +- src/eepp/ui/uinode.cpp | 6 +- src/eepp/window/window.cpp | 8 +- .../7guis/circle_drawer/circle_drawer.cpp | 85 +++++++++++++++++++ src/tools/ecode/plugins/git/git.cpp | 2 +- 12 files changed, 144 insertions(+), 15 deletions(-) create mode 100644 src/examples/7guis/circle_drawer/circle_drawer.cpp diff --git a/include/eepp/ui/uinode.hpp b/include/eepp/ui/uinode.hpp index 55dc7d235..8f590b1c7 100644 --- a/include/eepp/ui/uinode.hpp +++ b/include/eepp/ui/uinode.hpp @@ -59,9 +59,9 @@ class EE_API UINode : public Node { virtual Node* setPosition( const Float& x, const Float& y ); - void setPixelsPosition( const Vector2f& position ); + Node* setPixelsPosition( const Vector2f& position ); - void setPixelsPosition( const Float& x, const Float& y ); + Node* setPixelsPosition( const Float& x, const Float& y ); const Vector2f& getPosition() const; diff --git a/include/eepp/window/window.hpp b/include/eepp/window/window.hpp index e922afc00..1ff8d2653 100644 --- a/include/eepp/window/window.hpp +++ b/include/eepp/window/window.hpp @@ -461,8 +461,8 @@ class EE_API Window { /** Runs the main loop function passed as parameter ** @param func The main loop function - ** @param fps The desired FPS ( 0 = infinite ) */ - void runMainLoop( std::function func, int fps = 0 ); + ** @param fps The desired FPS ( 0 = infinite, < 0 keep current setting ) */ + void runMainLoop( std::function func, int fps = -1 ); /** @return The current display index. */ virtual int getCurrentDisplayIndex(); diff --git a/premake4.lua b/premake4.lua index 0495c1cb0..41e2288e5 100644 --- a/premake4.lua +++ b/premake4.lua @@ -1374,6 +1374,12 @@ solution "eepp" files { "src/examples/7guis/crud/*.cpp" } build_link_configuration( "eepp-7guis-crud", true ) + project "eepp-7guis-circle-drawer" + set_kind() + language "C++" + files { "src/examples/7guis/circle_drawer/*.cpp" } + build_link_configuration( "eepp-7guis-circle-drawer", true ) + -- Tools project "eepp-textureatlaseditor" set_kind() diff --git a/premake5.lua b/premake5.lua index 38052d152..e9c1ebd1d 100644 --- a/premake5.lua +++ b/premake5.lua @@ -1139,6 +1139,12 @@ workspace "eepp" files { "src/examples/7guis/crud/*.cpp" } build_link_configuration( "eepp-7guis-crud", true ) + project "eepp-7guis-circle-drawer" + set_kind() + language "C++" + files { "src/examples/7guis/circle_drawer/*.cpp" } + build_link_configuration( "eepp-7guis-circle-drawer", true ) + -- Tools project "eepp-textureatlaseditor" set_kind() diff --git a/projects/linux/ee.creator.user b/projects/linux/ee.creator.user index 1cc1d9ba5..415e63431 100644 --- a/projects/linux/ee.creator.user +++ b/projects/linux/ee.creator.user @@ -1,6 +1,6 @@ - + EnvironmentId @@ -1328,6 +1328,27 @@ false %{buildDir}/../../bin + + true + 0 + true + true + + 2 + + false + %{buildDir}/../../bin/eepp-7guis-circle-drawer-debug + eepp-7guis-circle-drawer + ProjectExplorer.CustomExecutableRunConfiguration + + true + 0 + false + 1 + false + false + %{buildDir}/../../bin + true 0 @@ -1470,7 +1491,7 @@ false %{buildDir}../../../bin/ - 26 + 27 diff --git a/projects/linux/ee.files b/projects/linux/ee.files index f220c1d17..8e9509cc5 100644 --- a/projects/linux/ee.files +++ b/projects/linux/ee.files @@ -1130,6 +1130,7 @@ ../../src/eepp/window/keycodes.cpp ../../src/eepp/window/platformhelper.hpp ../../src/eepp/window/window.cpp +../../src/examples/7guis/circle_drawer/circle_drawer.cpp ../../src/examples/7guis/counter/counter.cpp ../../src/examples/7guis/crud/crud.cpp ../../src/examples/7guis/flight_booker/flight_booker.cpp diff --git a/src/eepp/ui/uiloader.cpp b/src/eepp/ui/uiloader.cpp index 1a3ffd19b..3226e999d 100644 --- a/src/eepp/ui/uiloader.cpp +++ b/src/eepp/ui/uiloader.cpp @@ -62,6 +62,9 @@ void UILoader::draw() { } void UILoader::scheduledUpdate( const Time& time ) { + if ( !mVisible ) + return; + if ( mVisible && isMeOrParentTreeVisible() && mAnimationSpeed != 0.f ) invalidateDraw(); @@ -77,6 +80,9 @@ void UILoader::scheduledUpdate( const Time& time ) { mArcAngle = 20; } + if ( mArcStartAngle > 360 ) + mArcStartAngle = fmod( mArcStartAngle, 360 ); + mArc.setArcAngle( mArcAngle ); mArc.setArcStartAngle( mArcStartAngle ); } else { diff --git a/src/eepp/ui/uimessagebox.cpp b/src/eepp/ui/uimessagebox.cpp index f766ec77a..66d551f94 100644 --- a/src/eepp/ui/uimessagebox.cpp +++ b/src/eepp/ui/uimessagebox.cpp @@ -176,11 +176,11 @@ Uint32 UIMessageBox::onKeyUp( const KeyEvent& event ) { bool UIMessageBox::show() { bool b = UIWindow::show(); - if ( NULL != mTextInput ) { + if ( NULL != mTextInput && mTextInput->isEnabled() ) { mTextInput->setFocus(); - } else if ( NULL != mTextEdit ) { + } else if ( NULL != mTextEdit && mTextEdit->isEnabled() ) { mTextEdit->setFocus(); - } else { + } else if ( mButtonOK->isEnabled() ) { mButtonOK->setFocus(); } return b; diff --git a/src/eepp/ui/uinode.cpp b/src/eepp/ui/uinode.cpp index 846cafe15..d86b4abba 100644 --- a/src/eepp/ui/uinode.cpp +++ b/src/eepp/ui/uinode.cpp @@ -114,17 +114,19 @@ Node* UINode::setPosition( const Float& x, const Float& y ) { return this; } -void UINode::setPixelsPosition( const Vector2f& Pos ) { +Node* UINode::setPixelsPosition( const Vector2f& Pos ) { if ( mPosition != Pos ) { mDpPos = PixelDensity::pxToDp( Pos ); Transformable::setPosition( Pos ); setDirty(); onPositionChange(); } + return this; } -void UINode::setPixelsPosition( const Float& x, const Float& y ) { +Node* UINode::setPixelsPosition( const Float& x, const Float& y ) { setPixelsPosition( Vector2f( x, y ) ); + return this; } const Vector2f& UINode::getPosition() const { diff --git a/src/eepp/window/window.cpp b/src/eepp/window/window.cpp index 2d6374a41..cd62da872 100644 --- a/src/eepp/window/window.cpp +++ b/src/eepp/window/window.cpp @@ -602,12 +602,14 @@ static void eepp_mainloop() { #endif void Window::runMainLoop( std::function func, int fps ) { - mMainLoop = std::move(func); + mMainLoop = std::move( func ); #if EE_PLATFORM == EE_PLATFORM_EMSCRIPTEN - emscripten_set_main_loop( eepp_mainloop, fps, 1 ); + emscripten_set_main_loop( eepp_mainloop, std::max( mFrameData.FPS.Limit, std::max( 0, fps ) ), + 1 ); #else - setFrameRateLimit( fps ); + if ( fps >= 0 ) + setFrameRateLimit( fps ); while ( isRunning() ) { mMainLoop(); diff --git a/src/examples/7guis/circle_drawer/circle_drawer.cpp b/src/examples/7guis/circle_drawer/circle_drawer.cpp new file mode 100644 index 000000000..8d62f379e --- /dev/null +++ b/src/examples/7guis/circle_drawer/circle_drawer.cpp @@ -0,0 +1,85 @@ +#include + +// Reference https://eugenkiss.github.io/7guis/tasks#circle +// This is a work in progress, undo redo stack is pending +EE_MAIN_FUNC int main( int, char** ) { + UIApplication app( { 800, 600, "eepp - 7GUIs - Circle Drawer" } ); + UIWidget* cont = app.getUI()->loadLayoutFromString( R"xml( + + + + + + + + + )xml" ); + UIWidget* canvas = cont->find( "canvas" ); + canvas->onClick( [&]( const MouseEvent* event ) { + Float size = Math::randi( 20, 80 ); + Vector2f mousePos( event->getPosition().asFloat() - size / 2 ); + canvas->worldToNodeTranslation( mousePos ); + UIWidget* circle = UIWidget::New(); + circle->addClass( "circle" )->setParent( canvas ); + circle->setLayoutSizePolicy( SizePolicy::Fixed, SizePolicy::Fixed ) + ->setPixelsSize( { size, size } ) + ->setBorderRadius( size / 2 ) + ->setPixelsPosition( mousePos ); + // undoRedoStack->insert( circle ); + circle->onClick( + [circle]( auto ) { + auto adjustMsgBox = UIMessageBox::New( UIMessageBox::OK, "Adjust diameter..." ); + adjustMsgBox->on( Event::OnConfirm, [circle]( auto ) { + auto pos( circle->getPixelsPosition().asInt() ); + auto msgBox = UIMessageBox::New( + UIMessageBox::OK, + String::format( "Adjust diameter of circle at (%d, %d)", pos.x, pos.y ) ); + msgBox->getButtonOK()->setVisible( false )->setEnabled( false ); + auto slider = UISlider::NewHorizontal(); + slider->setLayoutSizePolicy( SizePolicy::MatchParent, SizePolicy::WrapContent ) + ->setLayoutMargin( Rectf( 8, 8, 8, 8 ) ) + ->setParent( msgBox->getLayoutCont()->getFirstChild() ) + ->setFocus() + ->toPosition( 1 ); + slider->setMinValue( 20 ); + slider->setMaxValue( 80 ); + slider->setValue( circle->getPixelsSize().x ); + slider->on( Event::OnValueChange, [slider, circle]( auto ) { + Float size = std::floor( slider->getValue() ); + Sizef newSize = { size, size }; + circle->setPixelsPosition( + ( circle->getPixelsPosition() + ( circle->getPixelsSize() / 2.f ) ) - + newSize / 2.f ); + circle->setPixelsSize( newSize )->setBorderRadius( size / 2 ); + } ); + msgBox->on( Event::OnWindowClose, [/*circle*/]( auto ) { + // undoRedoStack->changeSize( circle ); + } ); + msgBox->showWhenReady(); + } ); + adjustMsgBox->showWhenReady(); + }, + MouseButton::EE_BUTTON_RIGHT ); + } ); + cont->find( "undo" )->onClick( []( auto ) { + // undoRedoStack->undo(); + } ); + cont->find( "redo" )->onClick( []( auto ) { + // undoRedoStack->redo(); + } ); + return app.run(); +} diff --git a/src/tools/ecode/plugins/git/git.cpp b/src/tools/ecode/plugins/git/git.cpp index c08ef8802..580e87cc6 100644 --- a/src/tools/ecode/plugins/git/git.cpp +++ b/src/tools/ecode/plugins/git/git.cpp @@ -250,7 +250,7 @@ Git::Result Git::createBranch( const std::string& branchName, bool _checkout, const std::string& projectDir ) { auto res = gitSimple( String::format( "branch --no-track %s", branchName ), projectDir ); if ( _checkout ) - checkout( branchName ); + checkout( branchName, projectDir ); return res; }