diff --git a/include/eepp/ui/models/csspropertiesmodel.hpp b/include/eepp/ui/models/csspropertiesmodel.hpp index f43d1addb..1bd1eaf0b 100644 --- a/include/eepp/ui/models/csspropertiesmodel.hpp +++ b/include/eepp/ui/models/csspropertiesmodel.hpp @@ -70,7 +70,7 @@ class CSSPropertiesModel final : public Model { mProps[prop] = def; } if ( mWidget ) - mCloseCb = mWidget->addEventListener( Event::OnClose, [this]( const Event* ) { + mCloseCb = mWidget->on( Event::OnClose, [this]( const Event* ) { mWidget = nullptr; mCloseCb = 0; } ); diff --git a/include/eepp/ui/models/modeleditingdelegate.hpp b/include/eepp/ui/models/modeleditingdelegate.hpp index e518bb327..ec1a94dc2 100644 --- a/include/eepp/ui/models/modeleditingdelegate.hpp +++ b/include/eepp/ui/models/modeleditingdelegate.hpp @@ -114,13 +114,13 @@ class EE_API StringModelEditingDelegate : public ModelEditingDelegate { auto input = UITextInput::New(); input->addClass( "table_cell_edit" ); input->setLayoutSizePolicy( SizePolicy::Fixed, SizePolicy::Fixed ); - input->addEventListener( Event::OnPressEnter, [this]( auto ) { commit(); } ); - input->addEventListener( Event::OnFocusLoss, [this]( auto ) { rollback(); } ); - input->addEventListener( Event::KeyUp, [this]( const Event* event ) { + input->on( Event::OnPressEnter, [this]( auto ) { commit(); } ); + input->on( Event::OnFocusLoss, [this]( auto ) { rollback(); } ); + input->on( Event::KeyUp, [this]( const Event* event ) { if ( event->asKeyEvent()->getKeyCode() == KEY_ESCAPE ) rollback(); } ); - input->addEventListener( Event::OnValueChange, [this]( auto ) { change(); } ); + input->on( Event::OnValueChange, [this]( auto ) { change(); } ); return input; } }; diff --git a/include/eepp/ui/uidatabind.hpp b/include/eepp/ui/uidatabind.hpp index 1cc391169..bd03b2986 100644 --- a/include/eepp/ui/uidatabind.hpp +++ b/include/eepp/ui/uidatabind.hpp @@ -200,10 +200,10 @@ template class UIDataBind { Event::EventType eventType{ Event::OnValueChange }; void bindListeners( UIWidget* widget ) { - valueCbs[widget] = widget->addEventListener( eventType, [this]( const Event* event ) { + valueCbs[widget] = widget->on( eventType, [this]( const Event* event ) { processValueChange( event->getNode()->asType() ); } ); - closeCbs[widget] = widget->addEventListener( Event::OnClose, [this]( const Event* event ) { + closeCbs[widget] = widget->on( Event::OnClose, [this]( const Event* event ) { closeCbs.erase( event->getNode()->asType() ); this->widgets.erase( event->getNode()->asType() ); } ); diff --git a/include/eepp/ui/uidropdownlist.hpp b/include/eepp/ui/uidropdownlist.hpp index 8308dc42f..8f28f123e 100644 --- a/include/eepp/ui/uidropdownlist.hpp +++ b/include/eepp/ui/uidropdownlist.hpp @@ -85,6 +85,8 @@ class EE_API UIDropDownList : public UITextInput { virtual Uint32 onKeyDown( const KeyEvent& Event ); + virtual void onClassChange(); + virtual void onSizeChange(); virtual void onAutoSize(); diff --git a/src/eepp/ui/abstract/uiabstracttableview.cpp b/src/eepp/ui/abstract/uiabstracttableview.cpp index 4f2291fcd..b31fa830c 100644 --- a/src/eepp/ui/abstract/uiabstracttableview.cpp +++ b/src/eepp/ui/abstract/uiabstracttableview.cpp @@ -551,7 +551,7 @@ void UIAbstractTableView::onScrollChange() { void UIAbstractTableView::bindNavigationClick( UIWidget* widget ) { mWidgetsClickCbId[widget].push_back( - widget->addEventListener( Event::MouseDoubleClick, [this]( const Event* event ) { + widget->on( Event::MouseDoubleClick, [this]( const Event* event ) { auto mouseEvent = static_cast( event ); auto cellIdx = mouseEvent->getNode()->asType()->getCurIndex(); auto idx = mouseEvent->getNode()->getParent()->asType()->getCurIndex(); @@ -564,7 +564,7 @@ void UIAbstractTableView::bindNavigationClick( UIWidget* widget ) { } ) ); mWidgetsClickCbId[widget].push_back( - widget->addEventListener( Event::MouseClick, [this]( const Event* event ) { + widget->on( Event::MouseClick, [this]( const Event* event ) { auto mouseEvent = static_cast( event ); auto idx = mouseEvent->getNode()->getParent()->asType()->getCurIndex(); if ( mouseEvent->getFlags() & EE_BUTTON_RMASK ) { diff --git a/src/eepp/ui/abstract/uiabstractview.cpp b/src/eepp/ui/abstract/uiabstractview.cpp index 5e372ada7..b68c0f2ad 100644 --- a/src/eepp/ui/abstract/uiabstractview.cpp +++ b/src/eepp/ui/abstract/uiabstractview.cpp @@ -37,15 +37,14 @@ void UIAbstractView::setSelectionType( SelectionType selectionType ) { Uint32 UIAbstractView::onModelEvent( const std::function& callback, const Event::EventType& triggerEventType ) { - return addEventListener( - Event::OnModelEvent, [callback, triggerEventType]( const Event* event ) { - auto modelEvent = static_cast( event ); - if ( modelEvent->getModel() && modelEvent->getModelIndex().isValid() && - ( triggerEventType == Event::EventType::NoEvent || - modelEvent->getTriggerEvent()->getType() == triggerEventType ) ) { - callback( modelEvent ); - } - } ); + return on( Event::OnModelEvent, [callback, triggerEventType]( const Event* event ) { + auto modelEvent = static_cast( event ); + if ( modelEvent->getModel() && modelEvent->getModelIndex().isValid() && + ( triggerEventType == Event::EventType::NoEvent || + modelEvent->getTriggerEvent()->getType() == triggerEventType ) ) { + callback( modelEvent ); + } + } ); } std::vector UIAbstractView::getEditShortcuts() const { diff --git a/src/eepp/ui/doc/languages/cpp.cpp b/src/eepp/ui/doc/languages/cpp.cpp index cc612f06f..8f81c813d 100644 --- a/src/eepp/ui/doc/languages/cpp.cpp +++ b/src/eepp/ui/doc/languages/cpp.cpp @@ -21,7 +21,7 @@ void addCPP() { { { "/%*", "%*/" }, "comment" }, { { "\"", "[\"\n]", "\\" }, "string" }, { { "'", "'", "\\" }, "string" }, - { { "(#%s*include)%s+([<%\"][%w%d%.%\\%/%_%-]+[>%\"])" }, + { { "(#%s*include)%s+([<%\"][%w%d%.%\\%/%_%-%+]+[>%\"])" }, { "keyword", "keyword", "literal" } }, { { "cpp_number_parser" }, "number", "", SyntaxPatternMatchType::Parser }, { { "[%+%-=/%*%^%%<>!~|&]" }, "operator" }, diff --git a/src/eepp/ui/doc/languages/css.cpp b/src/eepp/ui/doc/languages/css.cpp index 399d9151e..adee86d4f 100644 --- a/src/eepp/ui/doc/languages/css.cpp +++ b/src/eepp/ui/doc/languages/css.cpp @@ -424,6 +424,7 @@ void addCSS() { { "Menu", "keyword" }, { "PopUpMenu", "keyword" }, { "ImageViewer", "keyword" }, + { "AudioPlayer", "keyword" }, }, "", diff --git a/src/eepp/ui/doc/languages/html.cpp b/src/eepp/ui/doc/languages/html.cpp index 70b524da2..d4d6396b2 100644 --- a/src/eepp/ui/doc/languages/html.cpp +++ b/src/eepp/ui/doc/languages/html.cpp @@ -38,7 +38,7 @@ void addHTML() { { { "%f[^<]![%a_][%w%_%-]*" }, "type" }, { { "%f[^<][%a_][%w%_%-]*" }, "function" }, { { "%f[^<]/[%a_][%w%_%-]*" }, "function" }, - { { "[%a_][%w_]*" }, "keyword" }, + { { "[%a_][%w_-]*" }, "keyword" }, { { "[/<>=]" }, "operator" }, }, diff --git a/src/eepp/ui/doc/languages/xml.cpp b/src/eepp/ui/doc/languages/xml.cpp index 226296b4f..31df8c520 100644 --- a/src/eepp/ui/doc/languages/xml.cpp +++ b/src/eepp/ui/doc/languages/xml.cpp @@ -25,7 +25,7 @@ void addXML() { { { "%f[^<]![%a_][%w%_%-]*" }, "type" }, { { "%f[^<][%a_][%w%_%-]*" }, "function" }, { { "%f[^<]/[%a_][%w%_%-]*" }, "function" }, - { { "[%a_][%w_]*" }, "keyword" }, + { { "[%a_][%w_-]*" }, "keyword" }, { { "[/<>=]" }, "operator" }, }, diff --git a/src/eepp/ui/iconmanager.cpp b/src/eepp/ui/iconmanager.cpp index 7a30fb703..7688dbc22 100644 --- a/src/eepp/ui/iconmanager.cpp +++ b/src/eepp/ui/iconmanager.cpp @@ -293,6 +293,7 @@ UIIconTheme* IconManager::init( const std::string& iconThemeName, FontTrueType* { "settings-alt", 0xeb52 }, { "attach", 0xec34 }, { "chat-sparkle", 0xEC4F }, + { "inspect", 0xEBD1 }, } ) { iconTheme->add( UIGlyphIcon::New( icon.first, codIconFont, icon.second ) ); diff --git a/src/eepp/ui/tools/textureatlaseditor.cpp b/src/eepp/ui/tools/textureatlaseditor.cpp index c8de421bc..5c2983544 100644 --- a/src/eepp/ui/tools/textureatlaseditor.cpp +++ b/src/eepp/ui/tools/textureatlaseditor.cpp @@ -124,54 +124,52 @@ TextureAtlasEditor::TextureAtlasEditor( UIWindow* attachTo, const TGEditorCloseC UIWidgetCreator::removeCustomWidgetCallback( "TextureAtlasTextureRegionEditor" ); mUIContainer->bind( "TextureRegionList", mTextureRegionList ); - mTextureRegionList->addEventListener( - Event::OnItemSelected, [this]( auto event ) { onTextureRegionChange( event ); } ); + mTextureRegionList->on( Event::OnItemSelected, + [this]( auto event ) { onTextureRegionChange( event ); } ); mUIContainer->bind( "gridlayout", mTextureRegionGrid ); mUIContainer->bind( "offX", mSpinOffX ); - mSpinOffX->addEventListener( Event::OnValueChange, - [this]( auto event ) { onOffXChange( event ); } ); + mSpinOffX->on( Event::OnValueChange, [this]( auto event ) { onOffXChange( event ); } ); mUIContainer->bind( "offY", mSpinOffY ); - mSpinOffY->addEventListener( Event::OnValueChange, - [this]( auto event ) { onOffYChange( event ); } ); + mSpinOffY->on( Event::OnValueChange, [this]( auto event ) { onOffYChange( event ); } ); mUIContainer->bind( "destW", mSpinDestW ); - mSpinDestW->addEventListener( Event::OnValueChange, - [this]( auto event ) { onDestWChange( event ); } ); + mSpinDestW->on( Event::OnValueChange, [this]( auto event ) { onDestWChange( event ); } ); mUIContainer->bind( "destH", mSpinDestH ); - mSpinDestH->addEventListener( Event::OnValueChange, - [this]( auto event ) { onDestHChange( event ); } ); + mSpinDestH->on( Event::OnValueChange, [this]( auto event ) { onDestHChange( event ); } ); mUIContainer->bind( "textureFilter", mTextureFilterList ); - mTextureFilterList->addEventListener( - Event::OnItemSelected, [this]( auto event ) { onTextureFilterChange( event ); } ); + mTextureFilterList->on( Event::OnItemSelected, + [this]( auto event ) { onTextureFilterChange( event ); } ); - mUIContainer->find( "resetDest" ) - ->addEventListener( Event::MouseClick, [this]( auto event ) { onResetDestSize( event ); } ); + mUIContainer->find( "resetDest" )->on( Event::MouseClick, [this]( auto event ) { + onResetDestSize( event ); + } ); - mUIContainer->find( "resetOff" ) - ->addEventListener( Event::MouseClick, [this]( auto event ) { onResetOffset( event ); } ); + mUIContainer->find( "resetOff" )->on( Event::MouseClick, [this]( auto event ) { + onResetOffset( event ); + } ); - mUIContainer->find( "centerOff" ) - ->addEventListener( Event::MouseClick, [this]( auto event ) { onCenterOffset( event ); } ); + mUIContainer->find( "centerOff" )->on( Event::MouseClick, [this]( auto event ) { + onCenterOffset( event ); + } ); - mUIContainer->find( "hbotOff" ) - ->addEventListener( Event::MouseClick, [this]( auto event ) { onHBOffset( event ); } ); + mUIContainer->find( "hbotOff" )->on( Event::MouseClick, [this]( auto event ) { + onHBOffset( event ); + } ); - mUIContainer->find( "fileMenu" ) - ->addEventListener( Event::OnItemClicked, - [this]( auto event ) { fileMenuClick( event ); } ); + mUIContainer->find( "fileMenu" )->on( Event::OnItemClicked, [this]( auto event ) { + fileMenuClick( event ); + } ); if ( NULL != mUIWindow ) { mUIWindow->setTitle( "Texture Atlas Editor" ); - mUIWindow->addEventListener( Event::OnWindowClose, - [this]( auto event ) { windowClose( event ); } ); + mUIWindow->on( Event::OnWindowClose, [this]( auto event ) { windowClose( event ); } ); } else { - mUIContainer->addEventListener( Event::OnClose, - [this]( auto event ) { windowClose( event ); } ); + mUIContainer->on( Event::OnClose, [this]( auto event ) { windowClose( event ); } ); mUIContainer->find( "texture_atlas_editor_root" ) ->setThemeSkin( mUIContainer->getSceneNode() ->asType() @@ -294,8 +292,7 @@ void TextureAtlasEditor::fileMenuClick( const Event* Event ) { UIFileDialog::DefaultFlags, std::string( "*" ) + EE_TEXTURE_ATLAS_EXTENSION ); TGDialog->setWindowFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL ); TGDialog->setTitle( "Open Texture Atlas" ); - TGDialog->addEventListener( Event::OpenFile, - [this]( auto event ) { openTextureAtlas( event ); } ); + TGDialog->on( Event::OpenFile, [this]( auto event ) { openTextureAtlas( event ); } ); TGDialog->center(); TGDialog->show(); } else if ( "Save" == txt ) { @@ -307,8 +304,7 @@ void TextureAtlasEditor::fileMenuClick( const Event* Event ) { UIMessageBox* MsgBox = UIMessageBox::New( UIMessageBox::OK_CANCEL, "Do you really want to close the current " "texture atlas?\nAll changes will be lost." ); - MsgBox->addEventListener( Event::OnConfirm, - [this]( auto event ) { onTextureAtlasClose( event ); } ); + MsgBox->on( Event::OnConfirm, [this]( auto event ) { onTextureAtlasClose( event ); } ); MsgBox->setTitle( "Close Texture Atlas?" ); MsgBox->center(); MsgBox->showWhenReady(); @@ -396,8 +392,7 @@ void TextureAtlasEditor::fillTextureRegionList() { ->setTooltipText( tr->getName() ) ->setGravity( UI_HALIGN_CENTER | UI_VALIGN_CENTER ) ->setParent( mTextureRegionGrid ) - ->addEventListener( Event::MouseClick, - [this]( auto event ) { onTextureRegionChange( event ); } ); + ->on( Event::MouseClick, [this]( auto event ) { onTextureRegionChange( event ); } ); ; } } diff --git a/src/eepp/ui/tools/textureatlasnew.cpp b/src/eepp/ui/tools/textureatlasnew.cpp index cb1711fc7..23d3e68e3 100644 --- a/src/eepp/ui/tools/textureatlasnew.cpp +++ b/src/eepp/ui/tools/textureatlasnew.cpp @@ -15,8 +15,7 @@ TextureAtlasNew::TextureAtlasNew( TGCreateCb NewTGCb ) : mUIWindow( NULL ), mNew UI_WIN_CLOSE_BUTTON | UI_WIN_USE_DEFAULT_BUTTONS_ACTIONS | UI_WIN_SHARE_ALPHA_WITH_CHILDREN | UI_WIN_MODAL ); - mUIWindow->addEventListener( Event::OnWindowClose, - [this]( auto event ) { windowClose( event ); } ); + mUIWindow->on( Event::OnWindowClose, [this]( auto event ) { windowClose( event ); } ); mUIWindow->setTitle( "New Texture Atlas" ); static const auto layout = R"xml( @@ -104,14 +103,16 @@ TextureAtlasNew::TextureAtlasNew( TGCreateCb NewTGCb ) : mUIWindow( NULL ), mNew mComboWidth->getListBox()->setSelected( "2048" ); mComboHeight->getListBox()->setSelected( "2048" ); - mSetPathButton->addEventListener( Event::MouseClick, - [this]( auto event ) { onDialogFolderSelect( event ); } ); - mUIWindow->find( "okButton" ) - ->addEventListener( Event::MouseClick, [this]( auto event ) { okClick( event ); } ); - mUIWindow->find( "cancelButton" ) - ->addEventListener( Event::MouseClick, [this]( auto event ) { cancelClick( event ); } ); + mSetPathButton->on( Event::MouseClick, + [this]( auto event ) { onDialogFolderSelect( event ); } ); + mUIWindow->find( "okButton" )->on( Event::MouseClick, [this]( auto event ) { + okClick( event ); + } ); + mUIWindow->find( "cancelButton" )->on( Event::MouseClick, [this]( auto event ) { + cancelClick( event ); + } ); - container->addEventListener( Event::OnLayoutUpdate, [this]( const Event* event ) { + container->on( Event::OnLayoutUpdate, [this]( const Event* event ) { mUIWindow->setMinWindowSize( event->getNode()->getSize() ); mUIWindow->center(); mUIWindow->show(); @@ -132,8 +133,7 @@ void TextureAtlasNew::okClick( const Event* event ) { UIFileDialog::New( UIFileDialog::DefaultFlags | UIFileDialog::SaveDialog, "*." + ext ); TGDialog->setWindowFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL ); TGDialog->setTitle( "Save Texture Atlas" ); - TGDialog->addEventListener( Event::SaveFile, - [this]( auto event ) { textureAtlasSave( event ); } ); + TGDialog->on( Event::SaveFile, [this]( auto event ) { textureAtlasSave( event ); } ); TGDialog->center(); TGDialog->show(); } @@ -211,8 +211,7 @@ void TextureAtlasNew::onDialogFolderSelect( const Event* event ) { UIFileDialog::New( UIFileDialog::DefaultFlags | UIFileDialog::AllowFolderSelect, "*" ); 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, - [this]( auto event ) { onSelectFolder( event ); } ); + TGDialog->on( Event::OpenFile, [this]( auto event ) { onSelectFolder( event ); } ); TGDialog->center(); TGDialog->show(); } diff --git a/src/eepp/ui/tools/textureatlastextureregioneditor.cpp b/src/eepp/ui/tools/textureatlastextureregioneditor.cpp index 3485c4c08..eaf71ba1e 100644 --- a/src/eepp/ui/tools/textureatlastextureregioneditor.cpp +++ b/src/eepp/ui/tools/textureatlastextureregioneditor.cpp @@ -28,7 +28,7 @@ TextureAtlasTextureRegionEditor::TextureAtlasTextureRegionEditor( TextureAtlasEd mDrag->center(); mDragPos = mDrag->getPixelsPosition(); - mDrag->addEventListener( Event::OnPositionChange, [this]( const Event* ) { + mDrag->on( Event::OnPositionChange, [this]( const Event* ) { if ( NULL != mGfx->getTextureRegion() ) { Vector2f Diff = -( mDragPos - mDrag->getPixelsPosition() ); diff --git a/src/eepp/ui/tools/uidocfindreplace.cpp b/src/eepp/ui/tools/uidocfindreplace.cpp index aba0007f6..21dde16ac 100644 --- a/src/eepp/ui/tools/uidocfindreplace.cpp +++ b/src/eepp/ui/tools/uidocfindreplace.cpp @@ -189,7 +189,7 @@ UIDocFindReplace::UIDocFindReplace( UIWidget* parent, const std::shared_ptraddEventListener( Event::MouseClick, [this]( const Event* event ) { + mToggle->on( Event::MouseClick, [this]( const Event* event ) { if ( event->asMouseEvent()->getFlags() & EE_BUTTON_LMASK ) { if ( mToggle->hasClass( "enabled" ) ) { mToggle->removeClass( "enabled" ); @@ -211,9 +211,9 @@ UIDocFindReplace::UIDocFindReplace( UIWidget* parent, const std::shared_ptrisType( UI_TYPE_CODEEDITOR ) ? getParent()->asType() : nullptr; - mFindInput->addEventListener( Event::OnTextChanged, - [this, editor]( const Event* ) { refreshHighlight( editor ); } ); - mFindInput->addEventListener( Event::OnTextPasted, [this]( const Event* ) { + mFindInput->on( Event::OnTextChanged, + [this, editor]( const Event* ) { refreshHighlight( editor ); } ); + mFindInput->on( Event::OnTextPasted, [this]( const Event* ) { if ( mFindInput->getUISceneNode()->getWindow()->getClipboard()->getText().find( '\n' ) != String::InvalidPos ) { if ( !mEscapeSequences->isSelected() ) @@ -281,15 +281,14 @@ UIDocFindReplace::UIDocFindReplace( UIWidget* parent, const std::shared_ptrsetTooltipText( getKeyBindings().getCommandKeybindString( cmd ) ); - widget->addEventListener( Event::MouseClick, [this, cmd]( const Event* event ) { + widget->on( Event::MouseClick, [this, cmd]( const Event* event ) { const MouseEvent* mouseEvent = static_cast( event ); if ( mouseEvent->getFlags() & EE_BUTTON_LMASK ) execute( cmd ); } ); }; auto addReturnListener = [this]( UIWidget* widget, std::string cmd ) { - widget->addEventListener( Event::OnPressEnter, - [this, cmd]( const Event* ) { execute( cmd ); } ); + widget->on( Event::OnPressEnter, [this, cmd]( const Event* ) { execute( cmd ); } ); }; addReturnListener( mFindInput, "repeat-find" ); addReturnListener( mReplaceInput, "find-and-replace" ); @@ -305,7 +304,7 @@ UIDocFindReplace::UIDocFindReplace( UIWidget* parent, const std::shared_ptrsetSelectAllDocOnTabNavigate( false ); mReplaceInput->setSelectAllDocOnTabNavigate( false ); - mFindInput->addEventListener( Event::OnTabNavigate, [this]( const Event* ) { + mFindInput->on( Event::OnTabNavigate, [this]( const Event* ) { if ( mReplaceDisabled ) return; if ( !mToggle->hasClass( "enabled" ) ) { @@ -315,8 +314,7 @@ UIDocFindReplace::UIDocFindReplace( UIWidget* parent, const std::shared_ptrsetFocus(); } ); - mReplaceInput->addEventListener( Event::OnTabNavigate, - [this]( const Event* ) { mFindInput->setFocus(); } ); + mReplaceInput->on( Event::OnTabNavigate, [this]( const Event* ) { mFindInput->setFocus(); } ); mDataBinds.emplace_back( UIDataBindBool::New( &mSearchState.caseSensitive, mCaseSensitive ) ); mDataBinds.emplace_back( UIDataBindBool::New( &mSearchState.wholeWord, mWholeWord ) ); @@ -352,7 +350,7 @@ UIDocFindReplace::UIDocFindReplace( UIWidget* parent, const std::shared_ptraddEventListener( Event::OnSizeChange, [this]( const Event* ) { + getParent()->on( Event::OnSizeChange, [this]( const Event* ) { Float startX = eemax( 0.f, getParent()->getSize().getWidth() - getSize().getWidth() ); setPosition( startX, getPosition().y ); } ); diff --git a/src/eepp/ui/tools/uiwidgetinspector.cpp b/src/eepp/ui/tools/uiwidgetinspector.cpp index a2386bfcd..213aa9fec 100644 --- a/src/eepp/ui/tools/uiwidgetinspector.cpp +++ b/src/eepp/ui/tools/uiwidgetinspector.cpp @@ -30,7 +30,7 @@ UIWindow* UIWidgetInspector::create( UISceneNode* sceneNode, const Float& menuIc static const auto WIDGET_LAYOUT = R"xml( - + " @@ -82,21 +82,29 @@ UIWindow* UIWidgetInspector::create( UISceneNode* sceneNode, const Float& menuIc } ); UIPushButton* button = cont->find( "pick_widget" ); - button->addEventListener( - Event::MouseClick, [sceneNode, widgetTree, tableView]( const Event* event ) { - if ( event->asMouseEvent()->getFlags() & EE_BUTTON_LMASK ) { - bool wasHighlightOver = sceneNode->getHighlightOver(); - sceneNode->setHighlightOver( true ); - sceneNode->getEventDispatcher()->setDisableMousePress( true ); - sceneNode->runOnMainThread( [sceneNode, widgetTree, tableView, wasHighlightOver]() { - checkWidgetPick( sceneNode, widgetTree, wasHighlightOver, tableView ); - } ); - } - } ); + + if ( button->getIcon() == nullptr ) { + Drawable* cursorPointer = button->getUISceneNode()->findIconDrawable( + "cursor-pointer", PixelDensity::dpToPx( 16 ) ); + + if ( cursorPointer ) + button->setIcon( cursorPointer, true ); + } + + button->on( Event::MouseClick, [sceneNode, widgetTree, tableView]( const Event* event ) { + if ( event->asMouseEvent()->getFlags() & EE_BUTTON_LMASK ) { + bool wasHighlightOver = sceneNode->getHighlightOver(); + sceneNode->setHighlightOver( true ); + sceneNode->getEventDispatcher()->setDisableMousePress( true ); + sceneNode->runOnMainThread( [sceneNode, widgetTree, tableView, wasHighlightOver]() { + checkWidgetPick( sceneNode, widgetTree, wasHighlightOver, tableView ); + } ); + } + } ); cont->find( "debug-draw-highlight" ) ->setChecked( sceneNode->getHighlightOver() ) - ->addEventListener( Event::OnValueChange, [sceneNode, highlightToggle]( const auto* ) { + ->on( Event::OnValueChange, [sceneNode, highlightToggle]( const auto* ) { if ( highlightToggle ) { highlightToggle(); } else { @@ -107,7 +115,7 @@ UIWindow* UIWidgetInspector::create( UISceneNode* sceneNode, const Float& menuIc cont->find( "debug-draw-boxes" ) ->setChecked( sceneNode->getDrawBoxes() ) - ->addEventListener( Event::OnValueChange, [sceneNode, drawBoxesToggle]( const auto* ) { + ->on( Event::OnValueChange, [sceneNode, drawBoxesToggle]( const auto* ) { if ( drawBoxesToggle ) { drawBoxesToggle(); } else { @@ -117,7 +125,7 @@ UIWindow* UIWidgetInspector::create( UISceneNode* sceneNode, const Float& menuIc cont->find( "debug-draw-debug-data" ) ->setChecked( sceneNode->getDrawDebugData() ) - ->addEventListener( Event::OnValueChange, [sceneNode, drawDebugDataToggle]( const auto* ) { + ->on( Event::OnValueChange, [sceneNode, drawDebugDataToggle]( const auto* ) { if ( drawDebugDataToggle ) { drawDebugDataToggle(); } else { @@ -126,14 +134,14 @@ UIWindow* UIWidgetInspector::create( UISceneNode* sceneNode, const Float& menuIc } ); cont->find( "widget-tree-search-collapse" ) - ->addEventListener( Event::MouseClick, [widgetTree]( const Event* event ) { + ->on( Event::MouseClick, [widgetTree]( const Event* event ) { if ( event->asMouseEvent()->getFlags() & EE_BUTTON_LMASK ) { widgetTree->collapseAll(); } } ); cont->find( "widget-tree-search-expand" ) - ->addEventListener( Event::MouseClick, [widgetTree]( const Event* event ) { + ->on( Event::MouseClick, [widgetTree]( const Event* event ) { if ( event->asMouseEvent()->getFlags() & EE_BUTTON_LMASK ) { widgetTree->expandAll(); } @@ -150,22 +158,20 @@ UIWindow* UIWidgetInspector::create( UISceneNode* sceneNode, const Float& menuIc uiWin->center(); - Uint32 winCb = sceneNode->addEventListener( Event::OnWindowAdded, [sceneNode, uiWin]( - const Event* event ) { + Uint32 winCb = sceneNode->on( Event::OnWindowAdded, [sceneNode, uiWin]( const Event* event ) { UIWindow* eWin = event->asWindowEvent()->getWindow()->asType(); if ( eWin != uiWin ) { - Uint32 winRdCb = - eWin->addEventListener( Event::OnWindowReady, [uiWin]( const Event* eWinEvent ) { - uiWin->toFront(); - eWinEvent->getNode()->removeEventListener( eWinEvent->getCallbackId() ); - } ); - uiWin->addEventListener( Event::OnWindowClose, [sceneNode, winRdCb]( const Event* ) { + Uint32 winRdCb = eWin->on( Event::OnWindowReady, [uiWin]( const Event* eWinEvent ) { + uiWin->toFront(); + eWinEvent->getNode()->removeEventListener( eWinEvent->getCallbackId() ); + } ); + uiWin->on( Event::OnWindowClose, [sceneNode, winRdCb]( const Event* ) { if ( !SceneManager::instance()->isShuttingDown() ) sceneNode->removeEventListener( winRdCb ); } ); } } ); - uiWin->addEventListener( Event::OnWindowClose, [sceneNode, winCb]( const Event* ) { + uiWin->on( Event::OnWindowClose, [sceneNode, winCb]( const Event* ) { if ( !SceneManager::instance()->isShuttingDown() ) sceneNode->removeEventListener( winCb ); } ); diff --git a/src/eepp/ui/uicheckbox.cpp b/src/eepp/ui/uicheckbox.cpp index f3d909ce8..a329acac3 100644 --- a/src/eepp/ui/uicheckbox.cpp +++ b/src/eepp/ui/uicheckbox.cpp @@ -25,7 +25,7 @@ UICheckBox::UICheckBox( const std::string& tag ) : mActiveButton->setParent( this ); mActiveButton->setPosition( 0, 0 ); mActiveButton->setSize( 8, 8 ); - mActiveButton->addEventListener( Event::OnSizeChange, cb ); + mActiveButton->on( Event::OnSizeChange, cb ); mActiveButton->unsetTabFocusable(); mInactiveButton = UIWidget::NewWithTag( tag + "::inactive" ); @@ -34,7 +34,7 @@ UICheckBox::UICheckBox( const std::string& tag ) : mInactiveButton->setParent( this ); mInactiveButton->setPosition( 0, 0 ); mInactiveButton->setSize( 8, 8 ); - mInactiveButton->addEventListener( Event::OnSizeChange, cb ); + mInactiveButton->on( Event::OnSizeChange, cb ); mInactiveButton->unsetTabFocusable(); onPaddingChange(); diff --git a/src/eepp/ui/uicodeeditor.cpp b/src/eepp/ui/uicodeeditor.cpp index a519eaaf0..21a32934e 100644 --- a/src/eepp/ui/uicodeeditor.cpp +++ b/src/eepp/ui/uicodeeditor.cpp @@ -152,17 +152,15 @@ UICodeEditor::UICodeEditor( const std::string& elementTag, const bool& autoRegis [this]( auto, auto ) { sendCommonEvent( Event::OnFoldUnfoldRange ); } ); mVScrollBar = UIScrollBar::NewVertical(); mVScrollBar->setParent( this ); - mVScrollBar->addEventListener( Event::OnSizeChange, - [this]( const Event* ) { updateScrollBar(); } ); - mVScrollBar->addEventListener( Event::OnValueChange, [this]( const Event* ) { + mVScrollBar->on( Event::OnSizeChange, [this]( const Event* ) { updateScrollBar(); } ); + mVScrollBar->on( Event::OnValueChange, [this]( const Event* ) { setScrollY( mVScrollBar->getValue() * getMaxScroll().y, false ); } ); mHScrollBar = UIScrollBar::NewHorizontal(); mHScrollBar->setParent( this ); - mHScrollBar->addEventListener( Event::OnSizeChange, - [this]( const Event* ) { updateScrollBar(); } ); - mHScrollBar->addEventListener( Event::OnValueChange, [this]( const Event* ) { + mHScrollBar->on( Event::OnSizeChange, [this]( const Event* ) { updateScrollBar(); } ); + mHScrollBar->on( Event::OnValueChange, [this]( const Event* ) { setScrollX( mHScrollBar->getValue() * getMaxScroll().x, false ); } ); @@ -1376,7 +1374,7 @@ void UICodeEditor::createDefaultContextMenuOptions( UIPopUpMenu* menu ) { if ( !mCreateDefaultContextMenuOptions ) return; - if ( mInteractiveLinks && !checkMouseOverLink( getInput()->getMousePos(), false ).empty() ){ + if ( mInteractiveLinks && !checkMouseOverLink( getInput()->getMousePos(), false ).empty() ) { menuAdd( menu, i18n( "uicodeeditor_open_url", "Open URL" ), "window", "open-hover-url" ); menu->addSeparator(); } @@ -1457,7 +1455,7 @@ bool UICodeEditor::onCreateContextMenu( const Vector2i& position, const Uint32& UICodeEditor* editor = this; const auto registerMenu = [editor, this]( UIMenu* menu ) { - menu->addEventListener( Event::OnItemClicked, [this, menu, editor]( const Event* event ) { + menu->on( Event::OnItemClicked, [this, menu, editor]( const Event* event ) { if ( !event->getNode()->isType( UI_TYPE_MENUITEM ) ) return; UIMenuItem* item = event->getNode()->asType(); @@ -1480,11 +1478,11 @@ bool UICodeEditor::onCreateContextMenu( const Vector2i& position, const Uint32& menu->show(); mCurrentMenu = menu; } ); - menu->addEventListener( Event::OnMenuHide, [this]( const Event* ) { + menu->on( Event::OnMenuHide, [this]( const Event* ) { if ( !isClosing() ) setFocus(); } ); - menu->addEventListener( Event::OnClose, [this]( const Event* ) { mCurrentMenu = nullptr; } ); + menu->on( Event::OnClose, [this]( const Event* ) { mCurrentMenu = nullptr; } ); return true; } @@ -1973,11 +1971,10 @@ void UICodeEditor::checkColorPickerAction() { } } if ( colorPicker ) - colorPicker->getUIWindow()->addEventListener( - Event::OnWindowClose, [this]( const Event* ) { - if ( !SceneManager::instance()->isShuttingDown() ) - setFocus(); - } ); + colorPicker->getUIWindow()->on( Event::OnWindowClose, [this]( const Event* ) { + if ( !SceneManager::instance()->isShuttingDown() ) + setFocus(); + } ); } } diff --git a/src/eepp/ui/uiconsole.cpp b/src/eepp/ui/uiconsole.cpp index 7a8039b36..60b8294ea 100644 --- a/src/eepp/ui/uiconsole.cpp +++ b/src/eepp/ui/uiconsole.cpp @@ -1251,7 +1251,7 @@ bool UIConsole::onCreateContextMenu( const Vector2i& position, const Uint32& fla } menu->setCloseOnHide( true ); - menu->addEventListener( Event::OnItemClicked, [this, menu]( const Event* event ) { + menu->on( Event::OnItemClicked, [this, menu]( const Event* event ) { if ( !event->getNode()->isType( UI_TYPE_MENUITEM ) ) return; UIMenuItem* item = event->getNode()->asType(); @@ -1270,11 +1270,11 @@ bool UIConsole::onCreateContextMenu( const Vector2i& position, const Uint32& fla menu->show(); mCurrentMenu = menu; } ); - menu->addEventListener( Event::OnMenuHide, [this]( const Event* ) { + menu->on( Event::OnMenuHide, [this]( const Event* ) { if ( !isClosing() ) setFocus(); } ); - menu->addEventListener( Event::OnClose, [this]( const Event* ) { mCurrentMenu = nullptr; } ); + menu->on( Event::OnClose, [this]( const Event* ) { mCurrentMenu = nullptr; } ); return true; } diff --git a/src/eepp/ui/uidropdownlist.cpp b/src/eepp/ui/uidropdownlist.cpp index 98bfceb31..875eb28a4 100644 --- a/src/eepp/ui/uidropdownlist.cpp +++ b/src/eepp/ui/uidropdownlist.cpp @@ -37,24 +37,20 @@ UIDropDownList::UIDropDownList( const std::string& tag ) : // This will force to change the parent when shown, and force the CSS style reload. mListBox->setParent( this ); - mListBox->addEventListener( Event::OnWidgetFocusLoss, - [this]( auto event ) { onListBoxFocusLoss( event ); } ); - mListBox->addEventListener( Event::OnItemSelected, - [this]( auto event ) { onItemSelected( event ); } ); - mListBox->addEventListener( Event::OnItemClicked, - [this]( auto event ) { onItemClicked( event ); } ); - mListBox->addEventListener( Event::OnItemKeyDown, - [this]( auto event ) { onItemKeyDown( event ); } ); - mListBox->addEventListener( Event::KeyDown, [this]( auto event ) { onItemKeyDown( event ); } ); - mListBox->addEventListener( Event::OnClear, [this]( auto event ) { onWidgetClear( event ); } ); - mListBoxCloseCb = mListBox->addEventListener( Event::OnClose, - [this]( const Event* ) { mListBox = nullptr; } ); - mListBox->addEventListener( Event::OnSelectionChanged, [this]( auto ) { + mListBox->on( Event::OnWidgetFocusLoss, [this]( auto event ) { onListBoxFocusLoss( event ); } ); + mListBox->on( Event::OnItemSelected, [this]( auto event ) { onItemSelected( event ); } ); + mListBox->on( Event::OnItemClicked, [this]( auto event ) { onItemClicked( event ); } ); + mListBox->on( Event::OnItemKeyDown, [this]( auto event ) { onItemKeyDown( event ); } ); + mListBox->on( Event::KeyDown, [this]( auto event ) { onItemKeyDown( event ); } ); + mListBox->on( Event::OnClear, [this]( auto event ) { onWidgetClear( event ); } ); + mListBoxCloseCb = + mListBox->on( Event::OnClose, [this]( const Event* ) { mListBox = nullptr; } ); + mListBox->on( Event::OnSelectionChanged, [this]( auto ) { if ( !mListBox->hasSelection() ) mListBox->setSelected( 0 ); sendCommonEvent( Event::OnSelectionChanged ); } ); - mListBox->addEventListener( Event::OnItemValueChange, [this]( const Event* event ) { + mListBox->on( Event::OnItemValueChange, [this]( const Event* event ) { if ( mListBox->getItemSelectedIndex() == event->asItemValueEvent()->getItemIndex() ) setText( mListBox->getItemSelectedText() ); } ); @@ -418,4 +414,9 @@ void UIDropDownList::loadFromXmlNode( const pugi::xml_node& node ) { endAttributesTransaction(); } +void UIDropDownList::onClassChange() { + if ( mListBox ) + mListBox->setClasses( getClasses() ); +} + }} // namespace EE::UI diff --git a/src/eepp/ui/uilistbox.cpp b/src/eepp/ui/uilistbox.cpp index 2de0aa031..b4c76265b 100644 --- a/src/eepp/ui/uilistbox.cpp +++ b/src/eepp/ui/uilistbox.cpp @@ -57,18 +57,17 @@ UIListBox::UIListBox( const std::string& tag ) : mVScrollBar->setPosition( getSize().getWidth() - 8, 0 ); mVScrollBar->setSize( 8, getSize().getHeight() ); mVScrollBar->setEnabled( false )->setVisible( false ); - mVScrollBar->addEventListener( Event::OnSizeChange, cb ); - mVScrollBar->addEventListener( Event::OnValueChange, - [this]( auto event ) { onScrollValueChange( event ); } ); + mVScrollBar->on( Event::OnSizeChange, cb ); + mVScrollBar->on( Event::OnValueChange, [this]( auto event ) { onScrollValueChange( event ); } ); mHScrollBar = UIScrollBar::NewHorizontal(); mHScrollBar->setParent( this ); mHScrollBar->setSize( getSize().getWidth() - mVScrollBar->getSize().getWidth(), 8 ); mHScrollBar->setPosition( 0, getSize().getHeight() - 8 ); mHScrollBar->setEnabled( false )->setVisible( false ); - mHScrollBar->addEventListener( Event::OnSizeChange, cb ); - mHScrollBar->addEventListener( Event::OnValueChange, - [this]( auto event ) { onHScrollValueChange( event ); } ); + mHScrollBar->on( Event::OnSizeChange, cb ); + mHScrollBar->on( Event::OnValueChange, + [this]( auto event ) { onHScrollValueChange( event ); } ); mDummyItem = createListBoxItem( "" ); mDummyItem->setSize( 0, 0 ); diff --git a/src/eepp/ui/uimenu.cpp b/src/eepp/ui/uimenu.cpp index 9cf2d7382..5ea269f22 100644 --- a/src/eepp/ui/uimenu.cpp +++ b/src/eepp/ui/uimenu.cpp @@ -169,8 +169,8 @@ UIWidget* UIMenu::add( UIWidget* widget ) { widgetsResize(); } }; - widget->addEventListener( Event::OnVisibleChange, cb ); - widget->addEventListener( Event::OnSizeChange, cb ); + widget->on( Event::OnVisibleChange, cb ); + widget->on( Event::OnSizeChange, cb ); resizeMe(); return widget; } @@ -190,7 +190,7 @@ UIMenuSeparator* UIMenu::addSeparator() { mNextPosY += separator->getPixelsSize().getHeight(); mItems.push_back( separator ); resizeMe(); - separator->addEventListener( Event::OnSizeChange, [this]( const Event* ) { + separator->on( Event::OnSizeChange, [this]( const Event* ) { if ( !mResizing ) { widgetsSetPos(); widgetsResize(); diff --git a/src/eepp/ui/uimenuitem.cpp b/src/eepp/ui/uimenuitem.cpp index d232c54eb..b27eaa743 100644 --- a/src/eepp/ui/uimenuitem.cpp +++ b/src/eepp/ui/uimenuitem.cpp @@ -103,9 +103,9 @@ void UIMenuItem::createShortcutView() { mShortcutView->setParent( this )->setVisible( true )->setEnabled( false ); mShortcutView->setFlags( UI_AUTO_SIZE | UI_HALIGN_RIGHT ); auto cb = [this]( const Event* ) { onSizeChange(); }; - mShortcutView->addEventListener( Event::OnPaddingChange, cb ); - mShortcutView->addEventListener( Event::OnMarginChange, cb ); - mShortcutView->addEventListener( Event::OnSizeChange, cb ); + mShortcutView->on( Event::OnPaddingChange, cb ); + mShortcutView->on( Event::OnMarginChange, cb ); + mShortcutView->on( Event::OnSizeChange, cb ); } void UIMenuItem::refreshShortcut() { diff --git a/src/eepp/ui/uimenusubmenu.cpp b/src/eepp/ui/uimenusubmenu.cpp index 367ff8f05..9e8be0ba3 100644 --- a/src/eepp/ui/uimenusubmenu.cpp +++ b/src/eepp/ui/uimenusubmenu.cpp @@ -19,8 +19,8 @@ UIMenuSubMenu::UIMenuSubMenu() : mArrow->setParent( this ); mArrow->setFlags( UI_AUTO_SIZE ); applyDefaultTheme(); - mArrow->addEventListener( Event::OnSizeChange, [this]( const Event* ) { onSizeChange(); } ); - mArrow->addEventListener( Event::OnMarginChange, [this]( const Event* ) { onSizeChange(); } ); + mArrow->on( Event::OnSizeChange, [this]( const Event* ) { onSizeChange(); } ); + mArrow->on( Event::OnMarginChange, [this]( const Event* ) { onSizeChange(); } ); mArrow->setVisible( true ); mArrow->setEnabled( false ); } diff --git a/src/eepp/ui/uimessagebox.cpp b/src/eepp/ui/uimessagebox.cpp index 2898c5dcd..444253374 100644 --- a/src/eepp/ui/uimessagebox.cpp +++ b/src/eepp/ui/uimessagebox.cpp @@ -46,8 +46,8 @@ UIMessageBox::UIMessageBox( const Type& type, const String& message, const Uint3 mTextInput->setLayoutSizePolicy( SizePolicy::MatchParent, SizePolicy::WrapContent ) ->setLayoutMargin( Rectf( 0, 4, 0, 4 ) ) ->setParent( vlay ) - ->addEventListener( Event::OnPressEnter, - [this]( const Event* ) { sendCommonEvent( Event::OnConfirm ); } ); + ->on( Event::OnPressEnter, + [this]( const Event* ) { sendCommonEvent( Event::OnConfirm ); } ); } else if ( mMsgBoxType == TEXT_EDIT ) { mTextEdit = UITextEdit::New(); mTextEdit->setLayoutSizePolicy( SizePolicy::Fixed, SizePolicy::Fixed ) @@ -92,7 +92,8 @@ UIMessageBox::UIMessageBox( const Type& type, const String& message, const Uint3 } ); } - on( Event::OnWindowCloseClick, [this]( const Event* ) { sendCommonEvent( Event::OnDiscard ); } ); + on( Event::OnWindowCloseClick, + [this]( const Event* ) { sendCommonEvent( Event::OnDiscard ); } ); UILinearLayout* hlay = UILinearLayout::NewHorizontal(); hlay->setLayoutMargin( Rectf( 0, 8, 0, 0 ) ) diff --git a/src/eepp/ui/uimultimodelview.cpp b/src/eepp/ui/uimultimodelview.cpp index 84cba8ede..c133e25f2 100644 --- a/src/eepp/ui/uimultimodelview.cpp +++ b/src/eepp/ui/uimultimodelview.cpp @@ -27,8 +27,8 @@ UIMultiModelView::UIMultiModelView( const std::string& tag ) : UIStackWidget( ta mTable = UITableView::New(); mList->setParent( this ); mTable->setParent( this ); - mList->addEventListener( Event::OnModelEvent, modelEvent ); - mTable->addEventListener( Event::OnModelEvent, modelEvent ); + mList->on( Event::OnModelEvent, modelEvent ); + mTable->on( Event::OnModelEvent, modelEvent ); mList->setOnSelectionChange( selectionChange ); mTable->setOnSelectionChange( selectionChange ); mList->setOnSelection( selection ); diff --git a/src/eepp/ui/uipushbutton.cpp b/src/eepp/ui/uipushbutton.cpp index 16decc716..9bf755652 100644 --- a/src/eepp/ui/uipushbutton.cpp +++ b/src/eepp/ui/uipushbutton.cpp @@ -73,10 +73,10 @@ UIPushButton::UIPushButton( const std::string& tag, ->setParent( this ) ->setVisible( true ) ->setEnabled( false ); - mTextBox->addEventListener( Event::OnFontChanged, cb ); - mTextBox->addEventListener( Event::OnFontStyleChanged, cb ); - mTextBox->addEventListener( Event::OnTextChanged, cb ); - mTextBox->addEventListener( Event::OnVisibleChange, cb ); + mTextBox->on( Event::OnFontChanged, cb ); + mTextBox->on( Event::OnFontStyleChanged, cb ); + mTextBox->on( Event::OnTextChanged, cb ); + mTextBox->on( Event::OnVisibleChange, cb ); applyDefaultTheme(); } @@ -388,10 +388,10 @@ UIImage* UIPushButton::getIcon() { ->setVisible( true ) ->setEnabled( false ); - mIcon->addEventListener( Event::OnPaddingChange, cb ); - mIcon->addEventListener( Event::OnMarginChange, cb ); - mIcon->addEventListener( Event::OnSizeChange, cb ); - mIcon->addEventListener( Event::OnVisibleChange, cb ); + mIcon->on( Event::OnPaddingChange, cb ); + mIcon->on( Event::OnMarginChange, cb ); + mIcon->on( Event::OnSizeChange, cb ); + mIcon->on( Event::OnVisibleChange, cb ); if ( mIconMinSize != Sizei::Zero ) { auto iconMinSize = mIconMinSize; diff --git a/src/eepp/ui/uiradiobutton.cpp b/src/eepp/ui/uiradiobutton.cpp index 7610ad481..3effc3bd1 100644 --- a/src/eepp/ui/uiradiobutton.cpp +++ b/src/eepp/ui/uiradiobutton.cpp @@ -23,7 +23,7 @@ UIRadioButton::UIRadioButton() : mActiveButton->setParent( this ); mActiveButton->setPosition( 0, 0 ); mActiveButton->setSize( 8, 8 ); - mActiveButton->addEventListener( Event::OnSizeChange, cb ); + mActiveButton->on( Event::OnSizeChange, cb ); mActiveButton->unsetTabFocusable(); mInactiveButton = UIWidget::NewWithTag( "radiobutton::inactive" ); @@ -32,7 +32,7 @@ UIRadioButton::UIRadioButton() : mInactiveButton->setParent( this ); mInactiveButton->setPosition( 0, 0 ); mInactiveButton->setSize( 9, 8 ); - mInactiveButton->addEventListener( Event::OnSizeChange, cb ); + mInactiveButton->on( Event::OnSizeChange, cb ); mInactiveButton->unsetTabFocusable(); onPaddingChange(); diff --git a/src/eepp/ui/uiscenenode.cpp b/src/eepp/ui/uiscenenode.cpp index 8df8213be..0c96dfbbc 100644 --- a/src/eepp/ui/uiscenenode.cpp +++ b/src/eepp/ui/uiscenenode.cpp @@ -147,13 +147,12 @@ void UISceneNode::onParentChange() { setDirty(); setPixelsSize( getParent()->getPixelsSize() ); - mCurOnSizeChangeListener = - getParent()->addEventListener( Event::OnSizeChange, [this]( const Event* ) { - setDirty(); - setPixelsSize( getParent()->getPixelsSize() ); - onMediaChanged(); - sendMsg( this, NodeMessage::WindowResize ); - } ); + mCurOnSizeChangeListener = getParent()->on( Event::OnSizeChange, [this]( const Event* ) { + setDirty(); + setPixelsSize( getParent()->getPixelsSize() ); + onMediaChanged(); + sendMsg( this, NodeMessage::WindowResize ); + } ); } void UISceneNode::setTranslator( Translator translator ) { diff --git a/src/eepp/ui/uiscrollablewidget.cpp b/src/eepp/ui/uiscrollablewidget.cpp index 9ea24893e..385f5c59f 100644 --- a/src/eepp/ui/uiscrollablewidget.cpp +++ b/src/eepp/ui/uiscrollablewidget.cpp @@ -18,10 +18,8 @@ UIScrollableWidget::UIScrollableWidget( const std::string& tag ) : mVScroll->setParent( this ); mHScroll->setParent( this ); - mVScroll->addEventListener( Event::OnValueChange, - [this]( auto event ) { onValueChangeCb( event ); } ); - mHScroll->addEventListener( Event::OnValueChange, - [this]( auto event ) { onValueChangeCb( event ); } ); + mVScroll->on( Event::OnValueChange, [this]( auto event ) { onValueChangeCb( event ); } ); + mHScroll->on( Event::OnValueChange, [this]( auto event ) { onValueChangeCb( event ); } ); applyDefaultTheme(); } diff --git a/src/eepp/ui/uiscrollbar.cpp b/src/eepp/ui/uiscrollbar.cpp index d1b94f825..9c6182af4 100644 --- a/src/eepp/ui/uiscrollbar.cpp +++ b/src/eepp/ui/uiscrollbar.cpp @@ -60,8 +60,7 @@ UIScrollBar::UIScrollBar( const std::string& tag, const UIOrientation& orientati mSlider->setParent( this ); mSlider->setAllowHalfSliderOut( false ); mSlider->setExpandBackground( false ); - mSlider->addEventListener( Event::OnValueChange, - [this] ( auto event ) { onValueChangeCb( event ); } ); + mSlider->on( Event::OnValueChange, [this]( auto event ) { onValueChangeCb( event ); } ); if ( orientation == UIOrientation::Vertical ) { mSlider->getSliderButton()->setElementTag( mTag + "::vbutton" ); mSlider->getBackSlider()->setElementTag( mTag + "::vback" ); diff --git a/src/eepp/ui/uiselectbutton.cpp b/src/eepp/ui/uiselectbutton.cpp index 7b4c65ca3..8c6385dff 100644 --- a/src/eepp/ui/uiselectbutton.cpp +++ b/src/eepp/ui/uiselectbutton.cpp @@ -131,8 +131,8 @@ void UISelectButton::setSelected( bool set ) { void UISelectButton::setSelectOnClick( bool set ) { if ( set ) { if ( mSelectOnClickCbId == 0 ) - mSelectOnClickCbId = addEventListener( Event::MouseClick, - [this]( const Event* ) { toggleSelection(); } ); + mSelectOnClickCbId = + on( Event::MouseClick, [this]( const Event* ) { toggleSelection(); } ); } else { if ( mSelectOnClickCbId != 0 ) removeEventListener( mSelectOnClickCbId ); diff --git a/src/eepp/ui/uislider.cpp b/src/eepp/ui/uislider.cpp index bf18c1bb8..3ca0b647a 100644 --- a/src/eepp/ui/uislider.cpp +++ b/src/eepp/ui/uislider.cpp @@ -71,7 +71,7 @@ UISlider::UISlider( const std::string& tag, const UIOrientation& orientation ) : mSlider->setDragEnabled( true ); mSlider->setSize( 4, 4 ); mSlider->setPosition( 0, 0 ); - mSlider->addEventListener( Event::OnPositionChange, [this]( const Event* ) { + mSlider->on( Event::OnPositionChange, [this]( const Event* ) { if ( !mUpdating && !mOnPosChange ) fixSliderPos(); } ); @@ -81,10 +81,10 @@ UISlider::UISlider( const std::string& tag, const UIOrientation& orientation ) : else mSlider->centerHorizontal(); - mBackSlider->addEventListener( Event::OnSizeChange, cb ); - mSlider->addEventListener( Event::OnSizeChange, cb ); - mBackSlider->addEventListener( Event::OnPaddingChange, cb ); - mSlider->addEventListener( Event::OnPaddingChange, cb ); + mBackSlider->on( Event::OnSizeChange, cb ); + mSlider->on( Event::OnSizeChange, cb ); + mBackSlider->on( Event::OnPaddingChange, cb ); + mSlider->on( Event::OnPaddingChange, cb ); applyDefaultTheme(); } diff --git a/src/eepp/ui/uispinbox.cpp b/src/eepp/ui/uispinbox.cpp index b6d05ef61..e920ba9ac 100644 --- a/src/eepp/ui/uispinbox.cpp +++ b/src/eepp/ui/uispinbox.cpp @@ -30,18 +30,17 @@ UISpinBox::UISpinBox() : mPushUp->setEnabled( true ); mPushUp->setParent( this ); mPushUp->setSize( 8, 8 ); - mPushUp->addEventListener( Event::OnSizeChange, cb ); + mPushUp->on( Event::OnSizeChange, cb ); mPushDown = UIWidget::NewWithTag( "spinbox::btndown" ); mPushDown->setVisible( true ); mPushDown->setEnabled( true ); mPushDown->setParent( this ); mPushDown->setSize( 8, 8 ); - mPushDown->addEventListener( Event::OnSizeChange, cb ); + mPushDown->on( Event::OnSizeChange, cb ); mInput->setAllowOnlyNumbers( true, false ); - mInput->addEventListener( Event::OnBufferChange, - [this]( auto event ) { onBufferChange( event ); } ); + mInput->on( Event::OnBufferChange, [this]( auto event ) { onBufferChange( event ); } ); double val = mValue; mValue += 1; setValue( val ); diff --git a/src/eepp/ui/uistacklayout.cpp b/src/eepp/ui/uistacklayout.cpp index 0e28c1b10..3cc35f1b0 100644 --- a/src/eepp/ui/uistacklayout.cpp +++ b/src/eepp/ui/uistacklayout.cpp @@ -119,16 +119,15 @@ void UIStackLayout::listenParent() { clearListeners(); mParentRef = getParent(); - mParentSizeChangeCb = - mParentRef->addEventListener( Event::OnSizeChange, [this]( const Event* ) { - if ( getLayoutWidthPolicy() == SizePolicy::WrapContent && - getUISceneNode()->isUpdatingLayouts() && - getParent()->getPixelsSize().getWidth() > 0 && mSize.x != getMatchParentWidth() ) { - runOnMainThread( [this]() { setLayoutDirty(); } ); - } - } ); - mParentCloseCb = mParentRef->addEventListener( - Event::OnClose, [this]( const Event* ) { mParentRef = nullptr; } ); + mParentSizeChangeCb = mParentRef->on( Event::OnSizeChange, [this]( const Event* ) { + if ( getLayoutWidthPolicy() == SizePolicy::WrapContent && + getUISceneNode()->isUpdatingLayouts() && getParent()->getPixelsSize().getWidth() > 0 && + mSize.x != getMatchParentWidth() ) { + runOnMainThread( [this]() { setLayoutDirty(); } ); + } + } ); + mParentCloseCb = + mParentRef->on( Event::OnClose, [this]( const Event* ) { mParentRef = nullptr; } ); } void UIStackLayout::onParentChange() { diff --git a/src/eepp/ui/uitab.cpp b/src/eepp/ui/uitab.cpp index da8df60e6..6edda009e 100644 --- a/src/eepp/ui/uitab.cpp +++ b/src/eepp/ui/uitab.cpp @@ -18,15 +18,15 @@ UITab::UITab() : UISelectButton( "tab" ), mOwnedWidget( NULL ), mDragTotalDiff( 0.f ), mTabWidget( NULL ) { mTextBox->setElementTag( mTag + "::text" ); auto cb = [this]( const Event* ) { onSizeChange(); }; - mTextBox->addEventListener( Event::OnSizeChange, cb ); + mTextBox->on( Event::OnSizeChange, cb ); mCloseButton = UIWidget::NewWithTag( mTag + "::close" ); mCloseButton->setParent( const_cast( this ) ); mCloseButton->setEnabled( false ); mCloseButton->setVisible( false ); - mCloseButton->addEventListener( Event::OnPaddingChange, cb ); - mCloseButton->addEventListener( Event::OnMarginChange, cb ); - mCloseButton->addEventListener( Event::OnSizeChange, cb ); - mCloseButton->addEventListener( Event::OnVisibleChange, cb ); + mCloseButton->on( Event::OnPaddingChange, cb ); + mCloseButton->on( Event::OnMarginChange, cb ); + mCloseButton->on( Event::OnSizeChange, cb ); + mCloseButton->on( Event::OnVisibleChange, cb ); applyDefaultTheme(); unsetFlags( UI_DRAG_VERTICAL ); } @@ -356,8 +356,7 @@ bool UITab::onCreateContextMenu( const Vector2i& position, const Uint32& flags ) UIMenu::findBestMenuPos( pos, menu ); menu->setPixelsPosition( pos ); menu->show(); - menu->addEventListener( Event::OnClose, - [tTabW]( const Event* ) { tTabW->mCurrentMenu = nullptr; } ); + menu->on( Event::OnClose, [tTabW]( const Event* ) { tTabW->mCurrentMenu = nullptr; } ); tTabW->mCurrentMenu = menu; return true; } diff --git a/src/eepp/ui/uitableheadercolumn.cpp b/src/eepp/ui/uitableheadercolumn.cpp index 07bf8940e..ed7256aa8 100644 --- a/src/eepp/ui/uitableheadercolumn.cpp +++ b/src/eepp/ui/uitableheadercolumn.cpp @@ -15,10 +15,10 @@ UITableHeaderColumn::UITableHeaderColumn( const std::string& parentTag, UIAbstra ->setFlags( UI_VALIGN_CENTER | UI_HALIGN_CENTER ) ->setParent( this ); mImage->setEnabled( false ); - mImage->addEventListener( Event::OnPaddingChange, cb ); - mImage->addEventListener( Event::OnMarginChange, cb ); - mImage->addEventListener( Event::OnSizeChange, cb ); - mImage->addEventListener( Event::OnVisibleChange, cb ); + mImage->on( Event::OnPaddingChange, cb ); + mImage->on( Event::OnMarginChange, cb ); + mImage->on( Event::OnSizeChange, cb ); + mImage->on( Event::OnVisibleChange, cb ); } Uint32 UITableHeaderColumn::onCalculateDrag( const Vector2f& position, const Uint32& flags ) { diff --git a/src/eepp/ui/uitextinput.cpp b/src/eepp/ui/uitextinput.cpp index 6714d186f..3e19f6c5b 100644 --- a/src/eepp/ui/uitextinput.cpp +++ b/src/eepp/ui/uitextinput.cpp @@ -917,7 +917,7 @@ bool UITextInput::onCreateContextMenu( const Vector2i& position, const Uint32& f } menu->setCloseOnHide( true ); - menu->addEventListener( Event::OnItemClicked, [this]( const Event* event ) { + menu->on( Event::OnItemClicked, [this]( const Event* event ) { if ( !event->getNode()->isType( UI_TYPE_MENUITEM ) ) return; UIMenuItem* item = event->getNode()->asType(); @@ -932,7 +932,7 @@ bool UITextInput::onCreateContextMenu( const Vector2i& position, const Uint32& f UIMenu::findBestMenuPos( pos, menu ); menu->setPixelsPosition( pos ); menu->show(); - menu->addEventListener( Event::OnClose, [this]( const Event* ) { mCurrentMenu = nullptr; } ); + menu->on( Event::OnClose, [this]( const Event* ) { mCurrentMenu = nullptr; } ); mCurrentMenu = menu; selCurInit( init ); selCurEnd( end ); diff --git a/src/eepp/ui/uitreeview.cpp b/src/eepp/ui/uitreeview.cpp index 89ec4089d..e787335a2 100644 --- a/src/eepp/ui/uitreeview.cpp +++ b/src/eepp/ui/uitreeview.cpp @@ -132,7 +132,7 @@ void UITreeView::bindNavigationClick( UIWidget* widget ) { }; mWidgetsClickCbId[widget].push_back( - widget->addEventListener( Event::MouseDoubleClick, [this, openTree]( const Event* event ) { + widget->on( Event::MouseDoubleClick, [this, openTree]( const Event* event ) { auto mouseEvent = static_cast( event ); auto cellIdx = mouseEvent->getNode()->asType()->getCurIndex(); auto idx = mouseEvent->getNode()->getParent()->asType()->getCurIndex(); @@ -145,7 +145,7 @@ void UITreeView::bindNavigationClick( UIWidget* widget ) { } ) ); mWidgetsClickCbId[widget].push_back( - widget->addEventListener( Event::MouseClick, [this, openTree]( const Event* event ) { + widget->on( Event::MouseClick, [this, openTree]( const Event* event ) { auto mouseEvent = static_cast( event ); auto idx = mouseEvent->getNode()->getParent()->asType()->getCurIndex(); if ( mouseEvent->getFlags() & EE_BUTTON_RMASK ) { @@ -949,10 +949,10 @@ UITreeViewCell::UITreeViewCell( const std::functionsetParent( const_cast( this ) ) ->setVisible( false ) ->setEnabled( false ); - mImage->addEventListener( Event::OnPaddingChange, cb ); - mImage->addEventListener( Event::OnMarginChange, cb ); - mImage->addEventListener( Event::OnSizeChange, cb ); - mImage->addEventListener( Event::OnVisibleChange, cb ); + mImage->on( Event::OnPaddingChange, cb ); + mImage->on( Event::OnMarginChange, cb ); + mImage->on( Event::OnSizeChange, cb ); + mImage->on( Event::OnVisibleChange, cb ); } UIWidget* UITreeViewCell::getExtraInnerWidget() const { diff --git a/src/eepp/ui/uiwidgettable.cpp b/src/eepp/ui/uiwidgettable.cpp index 63c5a6312..7bb9b8f13 100644 --- a/src/eepp/ui/uiwidgettable.cpp +++ b/src/eepp/ui/uiwidgettable.cpp @@ -57,13 +57,11 @@ UIWidgetTable::UIWidgetTable() : mVScrollBar->setVisible( ScrollBarMode::AlwaysOn == mVScrollMode ); mVScrollBar->setEnabled( ScrollBarMode::AlwaysOn == mVScrollMode ); - mVScrollBar->addEventListener( Event::OnValueChange, - [this] ( auto event ) { onScrollValueChange( event ); } ); - mHScrollBar->addEventListener( Event::OnValueChange, - [this] ( auto event ) { onScrollValueChange( event ); } ); + mVScrollBar->on( Event::OnValueChange, [this]( auto event ) { onScrollValueChange( event ); } ); + mHScrollBar->on( Event::OnValueChange, [this]( auto event ) { onScrollValueChange( event ); } ); - mVScrollBar->addEventListener( Event::OnSizeChange, cb ); - mHScrollBar->addEventListener( Event::OnSizeChange, cb ); + mVScrollBar->on( Event::OnSizeChange, cb ); + mHScrollBar->on( Event::OnSizeChange, cb ); applyDefaultTheme(); } diff --git a/src/eepp/ui/uiwindow.cpp b/src/eepp/ui/uiwindow.cpp index 69643b790..753453b52 100644 --- a/src/eepp/ui/uiwindow.cpp +++ b/src/eepp/ui/uiwindow.cpp @@ -100,8 +100,8 @@ UIWindow::UIWindow( UIWindow::WindowBaseContainerType type, const StyleConfig& w mContainer->setParent( this ); mContainer->setClipType( ClipType::ContentBox ); mContainer->enableReportSizeChangeToChildren(); - mContainer->addEventListener( Event::OnPositionChange, - [this]( auto event ) { onContainerPositionChange( event ); } ); + mContainer->on( Event::OnPositionChange, + [this]( auto event ) { onContainerPositionChange( event ); } ); updateWinFlags(); @@ -215,7 +215,7 @@ void UIWindow::updateWinFlags() { if ( NULL == mButtonClose ) { mButtonClose = UIWidget::NewWithTag( "window::close" ); mButtonClose->writeNodeFlag( NODE_FLAG_OWNED_BY_NODE, 1 ); - mButtonClose->addEventListener( Event::OnSizeChange, cb ); + mButtonClose->on( Event::OnSizeChange, cb ); needsUpdate = true; } @@ -231,7 +231,7 @@ void UIWindow::updateWinFlags() { if ( NULL == mButtonMaximize ) { mButtonMaximize = UIWidget::NewWithTag( "window::maximize" ); mButtonMaximize->writeNodeFlag( NODE_FLAG_OWNED_BY_NODE, 1 ); - mButtonMaximize->addEventListener( Event::OnSizeChange, cb ); + mButtonMaximize->on( Event::OnSizeChange, cb ); needsUpdate = true; } @@ -247,7 +247,7 @@ void UIWindow::updateWinFlags() { if ( NULL == mButtonMinimize ) { mButtonMinimize = UIWidget::NewWithTag( "window::minimize" ); mButtonMinimize->writeNodeFlag( NODE_FLAG_OWNED_BY_NODE, 1 ); - mButtonMinimize->addEventListener( Event::OnSizeChange, cb ); + mButtonMinimize->on( Event::OnSizeChange, cb ); needsUpdate = true; } diff --git a/src/modules/eterm/src/eterm/ui/uiterminal.cpp b/src/modules/eterm/src/eterm/ui/uiterminal.cpp index b7cb6d3e8..cb9bc08d4 100644 --- a/src/modules/eterm/src/eterm/ui/uiterminal.cpp +++ b/src/modules/eterm/src/eterm/ui/uiterminal.cpp @@ -79,7 +79,7 @@ UITerminal::UITerminal( const std::shared_ptr& terminalDisplay } ); mVScroll->setParent( this ); - mVScroll->addEventListener( Event::OnValueChange, [this]( const Event* ) { updateScroll(); } ); + mVScroll->on( Event::OnValueChange, [this]( const Event* ) { updateScroll(); } ); setCommand( "terminal-scroll-up-screen", [this] { mTerm->action( TerminalShortcutAction::SCROLLUP_SCREEN ); } ); @@ -581,7 +581,7 @@ bool UITerminal::onCreateContextMenu( const Vector2i& position, const Uint32& fl } menu->setCloseOnHide( true ); - menu->addEventListener( Event::OnItemClicked, [this]( const Event* event ) { + menu->on( Event::OnItemClicked, [this]( const Event* event ) { if ( !event->getNode()->isType( UI_TYPE_MENUITEM ) ) return; UIMenuItem* item = event->getNode()->asType(); @@ -594,7 +594,7 @@ bool UITerminal::onCreateContextMenu( const Vector2i& position, const Uint32& fl UIMenu::findBestMenuPos( pos, menu ); menu->setPixelsPosition( pos ); menu->show(); - menu->addEventListener( Event::OnClose, [this]( const Event* ) { mCurrentMenu = nullptr; } ); + menu->on( Event::OnClose, [this]( const Event* ) { mCurrentMenu = nullptr; } ); mCurrentMenu = menu; return true; } diff --git a/src/modules/maps/src/eepp/maps/mapeditor/mapeditor.cpp b/src/modules/maps/src/eepp/maps/mapeditor/mapeditor.cpp index 8f4cacb21..3d0ce79a3 100644 --- a/src/modules/maps/src/eepp/maps/mapeditor/mapeditor.cpp +++ b/src/modules/maps/src/eepp/maps/mapeditor/mapeditor.cpp @@ -72,12 +72,10 @@ MapEditor::MapEditor( UIWindow* AttachTo, const MapEditorCloseCb& callback ) : if ( NULL != mUIWindow ) { mUIContainer = mUIWindow->getContainer(); mUIWindow->setTitle( "Map Editor" ); - mUIWindow->addEventListener( Event::OnWindowClose, - [this]( auto event ) { windowClose( event ); } ); + mUIWindow->on( Event::OnWindowClose, [this]( auto event ) { windowClose( event ); } ); } else { mUIContainer = SceneManager::instance()->getUISceneNode(); - mUIContainer->addEventListener( Event::OnClose, - [this]( auto event ) { windowClose( event ); } ); + mUIContainer->on( Event::OnClose, [this]( auto event ) { windowClose( event ); } ); } createME(); @@ -139,7 +137,7 @@ void MapEditor::createMenuBar() { PU1->add( "Quit", PU1->getUISceneNode()->findIconDrawable( "quit", PixelDensity::dpToPxI( 16 ) ) ); - PU1->addEventListener( Event::OnItemClicked, [this]( auto event ) { fileMenuClick( event ); } ); + PU1->on( Event::OnItemClicked, [this]( auto event ) { fileMenuClick( event ); } ); MenuBar->addMenuButton( "File", PU1 ); UIPopUpMenu* PU3 = UIPopUpMenu::New(); @@ -166,7 +164,7 @@ void MapEditor::createMenuBar() { PU3->addSeparator(); - PU3->addEventListener( Event::OnItemClicked, [this]( auto event ) { viewMenuClick( event ); } ); + PU3->on( Event::OnItemClicked, [this]( auto event ) { viewMenuClick( event ); } ); MenuBar->addMenuButton( "View", PU3 ); UIPopUpMenu* PU4 = UIPopUpMenu::New(); @@ -174,7 +172,7 @@ void MapEditor::createMenuBar() { PU4->add( "Properties..." ); PU4->add( "Resize..." ); - PU4->addEventListener( Event::OnItemClicked, [this]( auto event ) { mapMenuClick( event ); } ); + PU4->on( Event::OnItemClicked, [this]( auto event ) { mapMenuClick( event ); } ); MenuBar->addMenuButton( "Map", PU4 ); UIPopUpMenu* PU5 = UIPopUpMenu::New(); @@ -196,8 +194,7 @@ void MapEditor::createMenuBar() { mLayerChkVisible = PU5->addCheckBox( "Visible" ); - PU5->addEventListener( Event::OnItemClicked, - [this]( auto event ) { layerMenuClick( event ); } ); + PU5->on( Event::OnItemClicked, [this]( auto event ) { layerMenuClick( event ); } ); MenuBar->addMenuButton( "Layer", PU5 ); UIPopUpMenu* PU6 = UIPopUpMenu::New(); @@ -205,7 +202,7 @@ void MapEditor::createMenuBar() { PU6->add( "New Texture Atlas..." ); PU6->add( "Add External Texture Atlas..." ); MenuBar->addMenuButton( "Atlases", PU6 ); - PU6->addEventListener( Event::OnItemClicked, [this]( auto event ) { mapMenuClick( event ); } ); + PU6->on( Event::OnItemClicked, [this]( auto event ) { mapMenuClick( event ); } ); mWinContainer = UIWidget::New(); mWinContainer->enableReportSizeChangeToChildren(); @@ -249,8 +246,7 @@ void MapEditor::createETGMenu() { ->setSize( Width + DistToBorder, mWinContainer->getSize().getHeight() - DistFromTopMenu ) ->setPosition( ContPosX, DistFromTopMenu ); - mTabWidget->addEventListener( Event::OnTabSelected, - [this]( auto event ) { onTabSelected( event ); } ); + mTabWidget->on( Event::OnTabSelected, [this]( auto event ) { onTabSelected( event ); } ); createTabs(); @@ -313,8 +309,7 @@ void MapEditor::createTextureRegionContainer( Int32 Width ) { ->setSize( Width - 30, 0 ) ->setPosition( TAB_CONT_X_DIST, Txt->getPosition().y + Txt->getSize().getHeight() + 4 ); - mGOTypeList->addEventListener( Event::OnItemSelected, - [this]( auto event ) { onTypeChange( event ); } ); + mGOTypeList->on( Event::OnItemSelected, [this]( auto event ) { onTypeChange( event ); } ); fillGotyList(); mBtnGOTypeAdd = UIPushButton::New(); @@ -327,8 +322,7 @@ void MapEditor::createTextureRegionContainer( Int32 Width ) { "add", PixelDensity::dpToPxI( 16 ) ) ) ->setAnchors( UI_ANCHOR_RIGHT | UI_ANCHOR_TOP ); mBtnGOTypeAdd->setTooltipText( "Adds a new game object type\nunknown by the map editor." ); - mBtnGOTypeAdd->addEventListener( Event::MouseClick, - [this]( auto event ) { addNewGOType( event ); } ); + mBtnGOTypeAdd->on( Event::MouseClick, [this]( auto event ) { addNewGOType( event ); } ); if ( NULL == mBtnGOTypeAdd->getIcon()->getDrawable() ) mBtnGOTypeAdd->setText( "..." ); @@ -344,8 +338,7 @@ void MapEditor::createTextureRegionContainer( Int32 Width ) { ->setSize( Width, 0 ) ->setPosition( TAB_CONT_X_DIST, Txt->getPosition().y + Txt->getSize().getHeight() + 4 ); - mLayerList->addEventListener( Event::OnItemSelected, - [this]( auto event ) { onLayerSelect( event ); } ); + mLayerList->on( Event::OnItemSelected, [this]( auto event ) { onLayerSelect( event ); } ); Txt = createTextBox( "Game Object Flags:", mTextureRegionCont, Sizef( Width, 16 ), Vector2f( TAB_CONT_X_DIST, mLayerList->getPosition().y + @@ -360,8 +353,7 @@ void MapEditor::createTextureRegionContainer( Int32 Width ) { ->setParent( mTextureRegionCont ) ->setPosition( TAB_CONT_X_DIST, Txt->getPosition().y + Txt->getSize().getHeight() + 4 ); mChkMirrored->setText( "Mirrored" ); - mChkMirrored->addEventListener( Event::OnValueChange, - [this]( auto event ) { chkClickMirrored( event ); } ); + mChkMirrored->on( Event::OnValueChange, [this]( auto event ) { chkClickMirrored( event ); } ); mChkFlipped = UICheckBox::New(); mChkFlipped->setFontStyle( Text::Shadow ) @@ -370,8 +362,7 @@ void MapEditor::createTextureRegionContainer( Int32 Width ) { ->setPosition( mChkMirrored->getPosition().x + mChkMirrored->getSize().getWidth() + 32, mChkMirrored->getPosition().y ); mChkFlipped->setText( "Flipped" ); - mChkFlipped->addEventListener( Event::OnValueChange, - [this]( auto event ) { chkClickFlipped( event ); } ); + mChkFlipped->on( Event::OnValueChange, [this]( auto event ) { chkClickFlipped( event ); } ); mChkBlocked = UICheckBox::New(); mChkBlocked->setFontStyle( Text::Shadow ) @@ -381,8 +372,7 @@ void MapEditor::createTextureRegionContainer( Int32 Width ) { mChkMirrored->getPosition().y + mChkMirrored->getSize().getHeight() + 4 ); mChkBlocked->setText( "Blocked" ); mChkBlocked->setTooltipText( "Blocks the tile occupied by the sprite." ); - mChkBlocked->addEventListener( Event::OnValueChange, - [this]( auto event ) { chkClickBlocked( event ); } ); + mChkBlocked->on( Event::OnValueChange, [this]( auto event ) { chkClickBlocked( event ); } ); mChkAnim = UICheckBox::New(); mChkAnim->setFontStyle( Text::Shadow ) @@ -392,8 +382,7 @@ void MapEditor::createTextureRegionContainer( Int32 Width ) { mChkFlipped->getPosition().y + mChkFlipped->getSize().getHeight() + 4 ); mChkAnim->setText( "Animated" ); mChkAnim->setTooltipText( "Indicates if the Sprite is animated." ); - mChkAnim->addEventListener( Event::OnValueChange, - [this]( auto event ) { chkClickAnimated( event ); } ); + mChkAnim->on( Event::OnValueChange, [this]( auto event ) { chkClickAnimated( event ); } ); mChkRot90 = UICheckBox::New(); mChkRot90->setFontStyle( Text::Shadow ) @@ -402,8 +391,7 @@ void MapEditor::createTextureRegionContainer( Int32 Width ) { ->setPosition( mChkBlocked->getPosition().x, mChkBlocked->getPosition().y + mChkBlocked->getSize().getHeight() + 4 ); mChkRot90->setText( String::fromUtf8( std::string_view{ "Rotate 90º" } ) ); - mChkRot90->addEventListener( Event::OnValueChange, - [this]( auto event ) { chkClickRot90( event ); } ); + mChkRot90->on( Event::OnValueChange, [this]( auto event ) { chkClickRot90( event ); } ); mChkAutoFix = UICheckBox::New(); mChkAutoFix->setFontStyle( Text::Shadow ) @@ -414,8 +402,7 @@ void MapEditor::createTextureRegionContainer( Int32 Width ) { mChkAutoFix->setText( "AutoFix TilePos" ); mChkAutoFix->setTooltipText( "In a tiled layer if the sprite is moved,\nit will update the " "current tile position automatically." ); - mChkAutoFix->addEventListener( Event::OnValueChange, - [this]( auto event ) { chkClickAutoFix( event ); } ); + mChkAutoFix->on( Event::OnValueChange, [this]( auto event ) { chkClickAutoFix( event ); } ); mChkBlendAdd = UICheckBox::New(); mChkBlendAdd->setFontStyle( Text::Shadow ) @@ -425,8 +412,7 @@ void MapEditor::createTextureRegionContainer( Int32 Width ) { mChkRot90->getPosition().y + mChkRot90->getSize().getHeight() + 4 ); mChkBlendAdd->setText( "Additive Blend" ); mChkBlendAdd->setTooltipText( "Use additive blend mode." ); - mChkBlendAdd->addEventListener( Event::OnValueChange, - [this]( auto event ) { chkClickAutoFix( event ); } ); + mChkBlendAdd->on( Event::OnValueChange, [this]( auto event ) { chkClickAutoFix( event ); } ); Txt = createTextBox( "Game Object Data:", mTextureRegionCont, Sizef( Width, 16 ), Vector2f( TAB_CONT_X_DIST, mChkBlendAdd->getPosition().y + @@ -441,7 +427,7 @@ void MapEditor::createTextureRegionContainer( Int32 Width ) { mChkDI->setText( "Add as DataId" ); mChkDI->setTooltipText( "If the resource it's not a sprite,\nyou can reference it with a data id" ); - mChkDI->addEventListener( Event::OnValueChange, [this]( auto event ) { chkClickDI( event ); } ); + mChkDI->on( Event::OnValueChange, [this]( auto event ) { chkClickDI( event ); } ); mSGCont = UIWidget::New(); mSGCont->setParent( mTextureRegionCont ) @@ -460,8 +446,8 @@ void MapEditor::createTextureRegionContainer( Int32 Width ) { ->setParent( mSGCont ) ->setSize( Width, 0 ) ->setPosition( 0, Txt->getPosition().y + Txt->getSize().getHeight() + 4 ); - mTextureAtlasesList->addEventListener( - Event::OnItemSelected, [this]( auto event ) { onTextureAtlasChange( event ); } ); + mTextureAtlasesList->on( Event::OnItemSelected, + [this]( auto event ) { onTextureAtlasChange( event ); } ); mTextureRegionList = UIListBox::New(); mTextureRegionList->setParent( mSGCont ) @@ -471,8 +457,8 @@ void MapEditor::createTextureRegionContainer( Int32 Width ) { mTextureRegionList->getContainerPadding().Top + mTextureRegionList->getContainerPadding().Bottom ); mTextureRegionList->setAnchors( UI_ANCHOR_RIGHT | UI_ANCHOR_TOP ); - mTextureRegionList->addEventListener( - Event::OnItemSelected, [this]( auto event ) { onTextureRegionChange( event ); } ); + mTextureRegionList->on( Event::OnItemSelected, + [this]( auto event ) { onTextureRegionChange( event ); } ); mGfxPreview = UITextureRegion::New(); mGfxPreview->setScaleType( UIScaleType::FitInside ) @@ -511,8 +497,7 @@ void MapEditor::createLightContainer() { ->setSize( mLightCont->getSize().getWidth() - TAB_CONT_X_DIST * 2, 0 ) ->setPosition( TAB_CONT_X_DIST, 0 ); NewLightBut->setText( "New Light" ); - NewLightBut->addEventListener( Event::MouseClick, - [this]( auto event ) { onNewLight( event ); } ); + NewLightBut->on( Event::MouseClick, [this]( auto event ) { onNewLight( event ); } ); UITextView* Txt = createTextBox( "Light Color:", mLightCont, Sizef(), Vector2f( TAB_CONT_X_DIST, 32 ), @@ -540,8 +525,7 @@ void MapEditor::createLightContainer() { ->setPosition( Txt->getPosition().x + Txt->getSize().getWidth(), Txt->getPosition().y ); mUIRedSlider->setMaxValue( 255 ); mUIRedSlider->setValue( 255 ); - mUIRedSlider->addEventListener( Event::OnValueChange, - [this]( auto event ) { onRedChange( event ); } ); + mUIRedSlider->on( Event::OnValueChange, [this]( auto event ) { onRedChange( event ); } ); mUIRedTxt = createTextBox( String::toString( (Uint32)255 ), mLightCont, Sizef(), @@ -560,8 +544,7 @@ void MapEditor::createLightContainer() { ->setPosition( mUIRedSlider->getPosition().x, Txt->getPosition().y ); mUIGreenSlider->setMaxValue( 255 ); mUIGreenSlider->setValue( 255 ); - mUIGreenSlider->addEventListener( Event::OnValueChange, - [this]( auto event ) { onGreenChange( event ); } ); + mUIGreenSlider->on( Event::OnValueChange, [this]( auto event ) { onGreenChange( event ); } ); mUIGreenTxt = createTextBox( String::toString( (Uint32)255 ), mLightCont, Sizef(), @@ -580,8 +563,7 @@ void MapEditor::createLightContainer() { ->setPosition( mUIRedSlider->getPosition().x, Txt->getPosition().y ); mUIBlueSlider->setMaxValue( 255 ); mUIBlueSlider->setValue( 255 ); - mUIBlueSlider->addEventListener( Event::OnValueChange, - [this]( auto event ) { onBlueChange( event ); } ); + mUIBlueSlider->on( Event::OnValueChange, [this]( auto event ) { onBlueChange( event ); } ); mUIBlueTxt = createTextBox( String::toString( (Uint32)255 ), mLightCont, Sizef(), @@ -600,8 +582,8 @@ void MapEditor::createLightContainer() { ->setPosition( Txt->getPosition().x, Txt->getPosition().y + Txt->getSize().getHeight() + 8 ); mLightRadius->setMaxValue( 2000 ); - mLightRadius->addEventListener( Event::OnValueChange, - [this]( auto event ) { onLightRadiusChangeVal( event ); } ); + mLightRadius->on( Event::OnValueChange, + [this]( auto event ) { onLightRadiusChangeVal( event ); } ); mLightTypeChk = UICheckBox::New(); mLightTypeChk->setFlags( UI_AUTO_SIZE ) @@ -610,8 +592,7 @@ void MapEditor::createLightContainer() { mLightRadius->getPosition().y + mLightRadius->getSize().getHeight() + 8 ); mLightTypeChk->setText( "Isometric Light" ); mLightTypeChk->setChecked( false ); - mLightTypeChk->addEventListener( Event::OnValueChange, - [this]( auto event ) { onLightTypeChange( event ); } ); + mLightTypeChk->on( Event::OnValueChange, [this]( auto event ) { onLightTypeChange( event ); } ); } UISelectButton* MapEditor::addObjContButton( String text, Uint32 mode ) { @@ -622,8 +603,7 @@ UISelectButton* MapEditor::addObjContButton( String text, Uint32 mode ) { Button->setText( text ); Button->setData( mode ); - Button->addEventListener( Event::MouseClick, - [this]( auto event ) { onObjectModeSel( event ); } ); + Button->on( Event::MouseClick, [this]( auto event ) { onObjectModeSel( event ); } ); mLastSelButtonY += Button->getSize().getHeight() + 4; @@ -646,8 +626,8 @@ void MapEditor::createObjectsContainer() { mChkClampToTile = UICheckBox::New(); mChkClampToTile->resetFlags( ChkFlags )->setParent( mObjectCont )->setPosition( 12, nextY ); mChkClampToTile->setText( "Clamp Position to Tile" ); - mChkClampToTile->addEventListener( Event::OnValueChange, - [this]( auto event ) { chkClickClampToTile( event ); } ); + mChkClampToTile->on( Event::OnValueChange, + [this]( auto event ) { chkClickClampToTile( event ); } ); mChkClampToTile->setChecked( true ); } @@ -690,11 +670,9 @@ void MapEditor::createUIMap() { mUIMap->setVisible( true ); mUIMap->setEnabled( true ); createNewEmptyMap(); - mUIMap->addEventListener( Event::OnSizeChange, - [this]( auto event ) { onMapSizeChange( event ); } ); - mUIMap->addEventListener( Event::MouseDown, [this]( auto event ) { onMapMouseDown( event ); } ); - mUIMap->addEventListener( Event::MouseClick, - [this]( auto event ) { onMapMouseClick( event ); } ); + mUIMap->on( Event::OnSizeChange, [this]( auto event ) { onMapSizeChange( event ); } ); + mUIMap->on( Event::MouseDown, [this]( auto event ) { onMapMouseDown( event ); } ); + mUIMap->on( Event::MouseClick, [this]( auto event ) { onMapMouseClick( event ); } ); mUIMap->setLightSelectCb( [this]( auto event ) { onLightSelect( event ); } ); mUIMap->setLightRadiusChangeCb( [this]( auto event ) { onLightRadiusChange( event ); } ); mUIMap->setAddObjectCallback( @@ -710,16 +688,14 @@ void MapEditor::createUIMap() { ->setSize( mWinContainer->getSize().getWidth() - 225 - ScrollV, ScrollH ) ->setPosition( 0, mWinContainer->getSize().getHeight() - ScrollH ); mMapHScroll->setAnchors( UI_ANCHOR_LEFT | UI_ANCHOR_RIGHT | UI_ANCHOR_BOTTOM ); - mMapHScroll->addEventListener( Event::OnValueChange, - [this]( auto event ) { onScrollMapH( event ); } ); + mMapHScroll->on( Event::OnValueChange, [this]( auto event ) { onScrollMapH( event ); } ); mMapVScroll = UIScrollBar::New(); mMapVScroll->setParent( mWinContainer ) ->setSize( ScrollV, mWinContainer->getSize().getHeight() - ScrollH ) ->setPosition( mWinContainer->getSize().getWidth() - 225 - ScrollV, 0 ); mMapVScroll->setAnchors( UI_ANCHOR_TOP | UI_ANCHOR_BOTTOM ); - mMapVScroll->addEventListener( Event::OnValueChange, - [this]( auto event ) { onScrollMapV( event ); } ); + mMapVScroll->on( Event::OnValueChange, [this]( auto event ) { onScrollMapV( event ); } ); mapCreated(); } @@ -1145,7 +1121,7 @@ void MapEditor::fileMenuClick( const Event* Event ) { UIFileDialog* TGDialog = UIFileDialog::New( UIFileDialog::DefaultFlags, "*.eem" ); TGDialog->setWindowFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL ); TGDialog->setTitle( "Open Map" ); - TGDialog->addEventListener( Event::OpenFile, [this]( auto event ) { mapOpen( event ); } ); + TGDialog->on( Event::OpenFile, [this]( auto event ) { mapOpen( event ); } ); TGDialog->center(); TGDialog->show(); } else if ( "Save As..." == txt ) { @@ -1153,7 +1129,7 @@ void MapEditor::fileMenuClick( const Event* Event ) { UIFileDialog::New( UIFileDialog::DefaultFlags | UIFileDialog::SaveDialog, "*.eem" ); TGDialog->setWindowFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL ); TGDialog->setTitle( "Save Map" ); - TGDialog->addEventListener( Event::SaveFile, [this]( auto event ) { mapSave( event ); } ); + TGDialog->on( Event::SaveFile, [this]( auto event ) { mapSave( event ); } ); TGDialog->center(); TGDialog->show(); } else if ( "Save" == txt ) { @@ -1164,7 +1140,7 @@ void MapEditor::fileMenuClick( const Event* Event ) { UIMessageBox* MsgBox = UIMessageBox::New( UIMessageBox::OK_CANCEL, "Do you really want to close the current map?\nAll changes will be lost." ); - MsgBox->addEventListener( Event::OnConfirm, [this]( auto event ) { onMapClose( event ); } ); + MsgBox->on( Event::OnConfirm, [this]( auto event ) { onMapClose( event ); } ); MsgBox->setTitle( "Close Map?" ); MsgBox->center(); MsgBox->showWhenReady(); @@ -1287,15 +1263,13 @@ void MapEditor::mapMenuClick( const Event* Event ) { UIFileDialog::DefaultFlags, std::string( "*" ) + EE_TEXTURE_ATLAS_EXTENSION ); TGDialog->setWindowFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL ); TGDialog->setTitle( "Load Texture Atlas..." ); - TGDialog->addEventListener( Event::OpenFile, - [this]( auto event ) { cextureAtlasOpen( event ); } ); + TGDialog->on( Event::OpenFile, [this]( auto event ) { cextureAtlasOpen( event ); } ); TGDialog->center(); TGDialog->show(); } else if ( "Properties..." == txt ) { eeNew( TileMapProperties, ( mUIMap->Map() ) ); } else if ( "Resize..." ) { - eeNew( UIMapNew, ( - mUIMap, [this] { onMapLoad(); }, true ) ); + eeNew( UIMapNew, ( mUIMap, [this] { onMapLoad(); }, true ) ); } } diff --git a/src/modules/maps/src/eepp/maps/mapeditor/maplayerproperties.cpp b/src/modules/maps/src/eepp/maps/mapeditor/maplayerproperties.cpp index 1a61d719d..428d55235 100644 --- a/src/modules/maps/src/eepp/maps/mapeditor/maplayerproperties.cpp +++ b/src/modules/maps/src/eepp/maps/mapeditor/maplayerproperties.cpp @@ -27,8 +27,7 @@ MapLayerProperties::MapLayerProperties( MapLayer* Map, RefreshLayerListCb Cb ) : ->setWindowFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MODAL ) ->setMinWindowSize( 500, 500 ); - mUIWindow->addEventListener( Event::OnWindowClose, - [this] ( auto event ) { onWindowClose( event ); } ); + mUIWindow->on( Event::OnWindowClose, [this]( auto event ) { onWindowClose( event ); } ); mUIWindow->setTitle( "Layer Properties" ); Int32 InitialY = 16; @@ -46,8 +45,7 @@ MapLayerProperties::MapLayerProperties( MapLayer* Map, RefreshLayerListCb Cb ) : ->setParent( mUIWindow->getContainer() ) ->setPosition( Txt->getPosition().x + DistFromTitle, Txt->getPosition().y + DistFromTitle ); mUIInput->setText( mLayer->getName() ); - mUIInput->addEventListener( Event::OnPressEnter, - [this] ( auto event ) { onOKClick( event ); } ); + mUIInput->on( Event::OnPressEnter, [this]( auto event ) { onOKClick( event ); } ); UITextView* TxtBox = UITextView::New(); TxtBox->setFontStyle( Text::Shadow ) @@ -71,8 +69,7 @@ MapLayerProperties::MapLayerProperties( MapLayer* Map, RefreshLayerListCb Cb ) : OKButton->setPosition( mUIWindow->getContainer()->getSize().getWidth() - OKButton->getSize().getWidth() - 4, mUIWindow->getContainer()->getSize().getHeight() - OKButton->getSize().getHeight() - 4 ); - OKButton->addEventListener( Event::MouseClick, - [this] ( auto event ) { onOKClick( event ); } ); + OKButton->on( Event::MouseClick, [this]( auto event ) { onOKClick( event ); } ); OKButton->setText( "OK" ); OKButton->setAnchors( UI_ANCHOR_RIGHT | UI_ANCHOR_BOTTOM ); @@ -82,8 +79,7 @@ MapLayerProperties::MapLayerProperties( MapLayer* Map, RefreshLayerListCb Cb ) : ->setPosition( OKButton->getPosition().x - OKButton->getSize().getWidth() - 4, OKButton->getPosition().y ); CancelButton->setIcon( sceneNode->findIconDrawable( "cancel", PixelDensity::dpToPxI( 16 ) ) ); - CancelButton->addEventListener( Event::MouseClick, - [this] ( auto event ) { onCancelClick( event ); } ); + CancelButton->on( Event::MouseClick, [this]( auto event ) { onCancelClick( event ); } ); CancelButton->setText( "Cancel" ); CancelButton->setAnchors( UI_ANCHOR_RIGHT | UI_ANCHOR_BOTTOM ); @@ -106,8 +102,7 @@ MapLayerProperties::MapLayerProperties( MapLayer* Map, RefreshLayerListCb Cb ) : AddButton->setParent( mUIWindow->getContainer() )->setSize( 24, 0 )->setPosition( Pos ); AddButton->setIcon( sceneNode->findIconDrawable( "add", PixelDensity::dpToPxI( 16 ) ) ); AddButton->setAnchors( UI_ANCHOR_RIGHT | UI_ANCHOR_TOP ); - AddButton->addEventListener( Event::MouseClick, - [this] ( auto event ) { onAddCellClick( event ); } ); + AddButton->on( Event::MouseClick, [this]( auto event ) { onAddCellClick( event ); } ); if ( NULL == AddButton->getIcon()->getDrawable() ) AddButton->setText( "+" ); @@ -118,8 +113,7 @@ MapLayerProperties::MapLayerProperties( MapLayer* Map, RefreshLayerListCb Cb ) : RemoveButton->setParent( mUIWindow->getContainer() )->setSize( 24, 0 )->setPosition( Pos ); RemoveButton->setIcon( sceneNode->findIconDrawable( "remove", PixelDensity::dpToPxI( 16 ) ) ); RemoveButton->setAnchors( UI_ANCHOR_RIGHT | UI_ANCHOR_TOP ); - RemoveButton->addEventListener( Event::MouseClick, - [this] ( auto event ) { onRemoveCellClick( event ); } ); + RemoveButton->on( Event::MouseClick, [this]( auto event ) { onRemoveCellClick( event ); } ); if ( NULL == RemoveButton->getIcon()->getDrawable() ) RemoveButton->setText( "-" ); diff --git a/src/modules/maps/src/eepp/maps/mapeditor/mapobjectproperties.cpp b/src/modules/maps/src/eepp/maps/mapeditor/mapobjectproperties.cpp index 9b54a93c4..ba1e04c02 100644 --- a/src/modules/maps/src/eepp/maps/mapeditor/mapobjectproperties.cpp +++ b/src/modules/maps/src/eepp/maps/mapeditor/mapobjectproperties.cpp @@ -42,8 +42,7 @@ MapObjectProperties::MapObjectProperties( GameObjectObject* Obj ) : ->setWindowFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MODAL ) ->setMinWindowSize( 500, 500 ); - mUIWindow->addEventListener( Event::OnWindowClose, - [this] ( auto event ) { onWindowClose( event ); } ); + mUIWindow->on( Event::OnWindowClose, [this]( auto event ) { onWindowClose( event ); } ); mUIWindow->setTitle( "Object Properties" ); Int32 InitialY = 16; @@ -58,8 +57,7 @@ MapObjectProperties::MapObjectProperties( GameObjectObject* Obj ) : ->setPosition( Txt->getPosition().x + DistFromTitle, Txt->getPosition().y + DistFromTitle ); mUIInput->setMaxLength( 64 ); mUIInput->setText( mObj->getName() ); - mUIInput->addEventListener( Event::OnPressEnter, - [this] ( auto event ) { onOKClick( event ); } ); + mUIInput->on( Event::OnPressEnter, [this]( auto event ) { onOKClick( event ); } ); UITextView* Txt2 = createTextBox( "Object type:", mUIWindow->getContainer(), Sizef(), Vector2f( 50 + 192, InitialY ), @@ -71,8 +69,7 @@ MapObjectProperties::MapObjectProperties( GameObjectObject* Obj ) : Txt2->getPosition().y + DistFromTitle ); mUIInput2->setMaxLength( 64 ); mUIInput2->setText( mObj->getTypeName() ); - mUIInput2->addEventListener( Event::OnPressEnter, - [this] ( auto event ) { onOKClick( event ); } ); + mUIInput2->on( Event::OnPressEnter, [this]( auto event ) { onOKClick( event ); } ); Uint32 TxtBoxFlags = UI_NODE_DEFAULT_FLAGS | UI_HALIGN_CENTER | UI_VALIGN_CENTER; createTextBox( "Property Name", mUIWindow->getContainer(), Sizef( 192, 24 ), @@ -89,8 +86,7 @@ MapObjectProperties::MapObjectProperties( GameObjectObject* Obj ) : OKButton->setPosition( mUIWindow->getContainer()->getSize().getWidth() - OKButton->getSize().getWidth() - 4, mUIWindow->getContainer()->getSize().getHeight() - OKButton->getSize().getHeight() - 4 ); - OKButton->addEventListener( Event::MouseClick, - [this] ( auto event ) { onOKClick( event ); } ); + OKButton->on( Event::MouseClick, [this]( auto event ) { onOKClick( event ); } ); OKButton->setText( "OK" ); OKButton->setAnchors( UI_ANCHOR_RIGHT | UI_ANCHOR_BOTTOM ); @@ -100,8 +96,7 @@ MapObjectProperties::MapObjectProperties( GameObjectObject* Obj ) : ->setPosition( OKButton->getPosition().x - OKButton->getSize().getWidth() - 4, OKButton->getPosition().y ); CancelButton->setIcon( sceneNode->findIconDrawable( "cancel", PixelDensity::dpToPxI( 16 ) ) ); - CancelButton->addEventListener( Event::MouseClick, - [this] ( auto event ) { onCancelClick( event ); } ); + CancelButton->on( Event::MouseClick, [this]( auto event ) { onCancelClick( event ); } ); CancelButton->setText( "Cancel" ); CancelButton->setAnchors( UI_ANCHOR_RIGHT | UI_ANCHOR_BOTTOM ); @@ -124,8 +119,7 @@ MapObjectProperties::MapObjectProperties( GameObjectObject* Obj ) : AddButton->setParent( mUIWindow->getContainer() )->setSize( 24, 0 )->setPosition( Pos ); AddButton->setIcon( sceneNode->findIconDrawable( "add", PixelDensity::dpToPxI( 16 ) ) ); AddButton->setAnchors( UI_ANCHOR_RIGHT | UI_ANCHOR_TOP ); - AddButton->addEventListener( Event::MouseClick, - [this] ( auto event ) { onAddCellClick( event ); } ); + AddButton->on( Event::MouseClick, [this]( auto event ) { onAddCellClick( event ); } ); if ( NULL == AddButton->getIcon()->getDrawable() ) AddButton->setText( "+" ); @@ -136,8 +130,7 @@ MapObjectProperties::MapObjectProperties( GameObjectObject* Obj ) : RemoveButton->setParent( mUIWindow->getContainer() )->setSize( 24, 0 )->setPosition( Pos ); RemoveButton->setIcon( sceneNode->findIconDrawable( "remove", PixelDensity::dpToPxI( 16 ) ) ); RemoveButton->setAnchors( UI_ANCHOR_RIGHT | UI_ANCHOR_TOP ); - RemoveButton->addEventListener( Event::MouseClick, - [this] ( auto event ) { onRemoveCellClick( event ); } ); + RemoveButton->on( Event::MouseClick, [this]( auto event ) { onRemoveCellClick( event ); } ); if ( NULL == RemoveButton->getIcon()->getDrawable() ) RemoveButton->setText( "-" ); diff --git a/src/modules/maps/src/eepp/maps/mapeditor/tilemapproperties.cpp b/src/modules/maps/src/eepp/maps/mapeditor/tilemapproperties.cpp index bd2b4a321..36eb0012f 100644 --- a/src/modules/maps/src/eepp/maps/mapeditor/tilemapproperties.cpp +++ b/src/modules/maps/src/eepp/maps/mapeditor/tilemapproperties.cpp @@ -43,8 +43,7 @@ TileMapProperties::TileMapProperties( TileMap* Map ) : ->setWindowFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MODAL ) ->setMinWindowSize( 500, 500 ); - mUIWindow->addEventListener( Event::OnWindowClose, - [this] ( auto event ) { onWindowClose( event ); } ); + mUIWindow->on( Event::OnWindowClose, [this]( auto event ) { onWindowClose( event ); } ); mUIWindow->setTitle( "Map Properties" ); Uint32 DiffIfLights = 0; @@ -77,8 +76,7 @@ TileMapProperties::TileMapProperties( TileMap* Map ) : Txt->getPosition().y ); mUIRedSlider->setMaxValue( 255 ); mUIRedSlider->setValue( mMap->getBaseColor().r ); - mUIRedSlider->addEventListener( Event::OnValueChange, - [this] ( auto event ) { onRedChange( event ); } ); + mUIRedSlider->on( Event::OnValueChange, [this]( auto event ) { onRedChange( event ); } ); mUIRedTxt = createTextBox( String::toString( (Uint32)mMap->getBaseColor().r ), mUIWindow->getContainer(), Sizef(), @@ -98,8 +96,8 @@ TileMapProperties::TileMapProperties( TileMap* Map ) : ->setPosition( mUIRedSlider->getPosition().x, Txt->getPosition().y ); mUIGreenSlider->setMaxValue( 255 ); mUIGreenSlider->setValue( mMap->getBaseColor().g ); - mUIGreenSlider->addEventListener( Event::OnValueChange, - [this] ( auto event ) { onGreenChange( event ); } ); + mUIGreenSlider->on( Event::OnValueChange, + [this]( auto event ) { onGreenChange( event ); } ); mUIGreenTxt = createTextBox( String::toString( (Uint32)mMap->getBaseColor().g ), mUIWindow->getContainer(), Sizef(), @@ -118,8 +116,7 @@ TileMapProperties::TileMapProperties( TileMap* Map ) : ->setPosition( mUIRedSlider->getPosition().x, Txt->getPosition().y ); mUIBlueSlider->setMaxValue( 255 ); mUIBlueSlider->setValue( mMap->getBaseColor().b ); - mUIBlueSlider->addEventListener( Event::OnValueChange, - [this] ( auto event ) { onBlueChange( event ); } ); + mUIBlueSlider->on( Event::OnValueChange, [this]( auto event ) { onBlueChange( event ); } ); mUIBlueTxt = createTextBox( String::toString( (Uint32)mMap->getBaseColor().b ), mUIWindow->getContainer(), Sizef(), @@ -141,8 +138,7 @@ TileMapProperties::TileMapProperties( TileMap* Map ) : OKButton->setPosition( mUIWindow->getContainer()->getSize().getWidth() - OKButton->getSize().getWidth() - 4, mUIWindow->getContainer()->getSize().getHeight() - OKButton->getSize().getHeight() - 4 ); - OKButton->addEventListener( Event::MouseClick, - [this] ( auto event ) { onOKClick( event ); } ); + OKButton->on( Event::MouseClick, [this]( auto event ) { onOKClick( event ); } ); OKButton->setText( "OK" ); OKButton->setAnchors( UI_ANCHOR_RIGHT | UI_ANCHOR_BOTTOM ); @@ -152,8 +148,7 @@ TileMapProperties::TileMapProperties( TileMap* Map ) : ->setPosition( OKButton->getPosition().x - OKButton->getSize().getWidth() - 4, OKButton->getPosition().y ); CancelButton->setIcon( sceneNode->findIconDrawable( "cancel", PixelDensity::dpToPxI( 16 ) ) ); - CancelButton->addEventListener( Event::MouseClick, - [this] ( auto event ) { onCancelClick( event ); } ); + CancelButton->on( Event::MouseClick, [this]( auto event ) { onCancelClick( event ); } ); CancelButton->setText( "Cancel" ); CancelButton->setAnchors( UI_ANCHOR_RIGHT | UI_ANCHOR_BOTTOM ); @@ -176,8 +171,7 @@ TileMapProperties::TileMapProperties( TileMap* Map ) : AddButton->setSize( 24, 0 )->setParent( mUIWindow->getContainer() )->setPosition( Pos ); AddButton->setIcon( sceneNode->findIconDrawable( "add", PixelDensity::dpToPxI( 16 ) ) ); AddButton->setAnchors( UI_ANCHOR_RIGHT | UI_ANCHOR_TOP ); - AddButton->addEventListener( Event::MouseClick, - [this] ( auto event ) { onAddCellClick( event ); } ); + AddButton->on( Event::MouseClick, [this]( auto event ) { onAddCellClick( event ); } ); if ( NULL == AddButton->getIcon()->getDrawable() ) AddButton->setText( "+" ); @@ -188,8 +182,7 @@ TileMapProperties::TileMapProperties( TileMap* Map ) : RemoveButton->setSize( 24, 0 )->setParent( mUIWindow->getContainer() )->setPosition( Pos ); RemoveButton->setIcon( sceneNode->findIconDrawable( "remove", PixelDensity::dpToPxI( 16 ) ) ); RemoveButton->setAnchors( UI_ANCHOR_RIGHT | UI_ANCHOR_TOP ); - RemoveButton->addEventListener( Event::MouseClick, - [this] ( auto event ) { onRemoveCellClick( event ); } ); + RemoveButton->on( Event::MouseClick, [this]( auto event ) { onRemoveCellClick( event ); } ); if ( NULL == RemoveButton->getIcon()->getDrawable() ) RemoveButton->setText( "-" ); diff --git a/src/modules/maps/src/eepp/maps/mapeditor/uigotypenew.cpp b/src/modules/maps/src/eepp/maps/mapeditor/uigotypenew.cpp index cba453cb4..7199a15bb 100644 --- a/src/modules/maps/src/eepp/maps/mapeditor/uigotypenew.cpp +++ b/src/modules/maps/src/eepp/maps/mapeditor/uigotypenew.cpp @@ -22,8 +22,7 @@ UIGOTypeNew::UIGOTypeNew( std::function Cb ) : ->setWindowFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MODAL ) ->setMinWindowSize( 278, 114 ); - mUIWindow->addEventListener( Event::OnWindowClose, - [this] ( auto event ) { onWindowClose( event ); } ); + mUIWindow->on( Event::OnWindowClose, [this]( auto event ) { onWindowClose( event ); } ); mUIWindow->setTitle( "Add GameObject Type" ); Int32 InitialY = 16; @@ -47,8 +46,8 @@ UIGOTypeNew::UIGOTypeNew( std::function Cb ) : OKButton->setPosition( mUIWindow->getContainer()->getSize().getWidth() - OKButton->getSize().getWidth() - 4, mUIWindow->getContainer()->getSize().getHeight() - OKButton->getSize().getHeight() - 4 ); - OKButton->addEventListener( Event::MouseClick, [this] ( auto event ) { onOKClick( event ); } ); - mUIInput->addEventListener( Event::OnPressEnter, [this] ( auto event ) { onOKClick( event ); } ); + OKButton->on( Event::MouseClick, [this]( auto event ) { onOKClick( event ); } ); + mUIInput->on( Event::OnPressEnter, [this]( auto event ) { onOKClick( event ); } ); OKButton->setText( "Add" ); @@ -58,8 +57,7 @@ UIGOTypeNew::UIGOTypeNew( std::function Cb ) : ->setPosition( OKButton->getPosition().x - OKButton->getSize().getWidth() - 4, OKButton->getPosition().y ); CancelButton->setIcon( sceneNode->findIconDrawable( "cancel", PixelDensity::dpToPxI( 16 ) ) ); - CancelButton->addEventListener( Event::MouseClick, - [this] ( auto event ) { onCancelClick( event ); } ); + CancelButton->on( Event::MouseClick, [this]( auto event ) { onCancelClick( event ); } ); CancelButton->setText( "Cancel" ); mUIWindow->center(); diff --git a/src/modules/maps/src/eepp/maps/mapeditor/uimap.cpp b/src/modules/maps/src/eepp/maps/mapeditor/uimap.cpp index 5f120e476..469a6ea79 100644 --- a/src/modules/maps/src/eepp/maps/mapeditor/uimap.cpp +++ b/src/modules/maps/src/eepp/maps/mapeditor/uimap.cpp @@ -586,7 +586,7 @@ void UIMap::createObjPopUpMenu() { Menu->add( "Remove Object" ); Menu->addSeparator(); Menu->add( "Object Properties..." ); - Menu->addEventListener( Event::OnItemClicked, [this] ( auto event ) { objItemClick( event ); } ); + Menu->on( Event::OnItemClicked, [this]( auto event ) { objItemClick( event ); } ); if ( Menu->show() ) { Vector2f Pos = getEventDispatcher()->getMousePosf(); diff --git a/src/modules/maps/src/eepp/maps/mapeditor/uimaplayernew.cpp b/src/modules/maps/src/eepp/maps/mapeditor/uimaplayernew.cpp index 9bc97c16c..454363ef9 100644 --- a/src/modules/maps/src/eepp/maps/mapeditor/uimaplayernew.cpp +++ b/src/modules/maps/src/eepp/maps/mapeditor/uimaplayernew.cpp @@ -27,8 +27,7 @@ UIMapLayerNew::UIMapLayerNew( UIMap* Map, EE_LAYER_TYPE Type, NewLayerCb newLaye ->setWindowFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MODAL ) ->setMinWindowSize( 278, 114 ); - mUIWindow->addEventListener( Event::OnWindowClose, - [this] ( auto event ) { onWindowClose( event ); } ); + mUIWindow->on( Event::OnWindowClose, [this]( auto event ) { onWindowClose( event ); } ); if ( MAP_LAYER_TILED == mType ) mUIWindow->setTitle( "New Tile Layer" ); @@ -57,9 +56,8 @@ UIMapLayerNew::UIMapLayerNew( UIMap* Map, EE_LAYER_TYPE Type, NewLayerCb newLaye OKButton->setPosition( mUIWindow->getContainer()->getSize().getWidth() - OKButton->getSize().getWidth() - 4, mUIWindow->getContainer()->getSize().getHeight() - OKButton->getSize().getHeight() - 4 ); - OKButton->addEventListener( Event::MouseClick, [this] ( auto event ) { onOKClick( event ); } ); - mUILayerName->addEventListener( Event::OnPressEnter, - [this] ( auto event ) { onOKClick( event ); } ); + OKButton->on( Event::MouseClick, [this]( auto event ) { onOKClick( event ); } ); + mUILayerName->on( Event::OnPressEnter, [this]( auto event ) { onOKClick( event ); } ); OKButton->setText( "Add" ); @@ -69,11 +67,10 @@ UIMapLayerNew::UIMapLayerNew( UIMap* Map, EE_LAYER_TYPE Type, NewLayerCb newLaye ->setPosition( OKButton->getPosition().x - OKButton->getSize().getWidth() - 4, OKButton->getPosition().y ); CancelButton->setIcon( sceneNode->findIconDrawable( "cancel", PixelDensity::dpToPxI( 16 ) ) ); - CancelButton->addEventListener( Event::MouseClick, - [this] ( auto event ) { onCancelClick( event ); } ); + CancelButton->on( Event::MouseClick, [this]( auto event ) { onCancelClick( event ); } ); CancelButton->setText( "Cancel" ); - mUIWindow->addEventListener( Event::KeyUp, [this] ( auto event ) { onOnKeyUp( event ); } ); + mUIWindow->on( Event::KeyUp, [this]( auto event ) { onOnKeyUp( event ); } ); mUIWindow->center(); mUIWindow->show(); diff --git a/src/modules/maps/src/eepp/maps/mapeditor/uimapnew.cpp b/src/modules/maps/src/eepp/maps/mapeditor/uimapnew.cpp index 3f774bc75..d01010935 100644 --- a/src/modules/maps/src/eepp/maps/mapeditor/uimapnew.cpp +++ b/src/modules/maps/src/eepp/maps/mapeditor/uimapnew.cpp @@ -39,11 +39,10 @@ UIMapNew::UIMapNew( UIMap* Map, std::function NewMapCb, bool ResizeMap ) mUIWindow = UIWindow::New(); mUIWindow->setSizeWithDecoration( 320, 380 ) ->setWindowFlags( UI_WIN_CLOSE_BUTTON | UI_WIN_USE_DEFAULT_BUTTONS_ACTIONS | - UI_WIN_SHARE_ALPHA_WITH_CHILDREN | UI_WIN_MODAL ) + UI_WIN_SHARE_ALPHA_WITH_CHILDREN | UI_WIN_MODAL ) ->setMinWindowSize( 320, 380 ); - mUIWindow->addEventListener( Event::OnWindowClose, - [this] ( auto event ) { onWindowClose( event ); } ); + mUIWindow->on( Event::OnWindowClose, [this]( auto event ) { onWindowClose( event ); } ); if ( !mResizeMap ) { mUIWindow->setTitle( "New Map" ); @@ -216,8 +215,7 @@ UIMapNew::UIMapNew( UIMap* Map, std::function NewMapCb, bool ResizeMap ) Txt->getPosition().y ); mUIRedSlider->setMaxValue( 255 ); mUIRedSlider->setValue( 255 ); - mUIRedSlider->addEventListener( Event::OnValueChange, - [this] ( auto event ) { onRedChange( event ); } ); + mUIRedSlider->on( Event::OnValueChange, [this]( auto event ) { onRedChange( event ); } ); mUIRedTxt = createTextBox( String::toString( 255 ), mUIWindow->getContainer(), Sizef(), @@ -241,8 +239,7 @@ UIMapNew::UIMapNew( UIMap* Map, std::function NewMapCb, bool ResizeMap ) ->setPosition( mUIRedSlider->getPosition().x, Txt->getPosition().y ); mUIGreenSlider->setMaxValue( 255 ); mUIGreenSlider->setValue( 255 ); - mUIGreenSlider->addEventListener( Event::OnValueChange, - [this] ( auto event ) { onGreenChange( event ); } ); + mUIGreenSlider->on( Event::OnValueChange, [this]( auto event ) { onGreenChange( event ); } ); mUIGreenTxt = createTextBox( String::toString( 255 ), mUIWindow->getContainer(), Sizef(), @@ -266,8 +263,7 @@ UIMapNew::UIMapNew( UIMap* Map, std::function NewMapCb, bool ResizeMap ) ->setPosition( mUIRedSlider->getPosition().x, Txt->getPosition().y ); mUIBlueSlider->setMaxValue( 255 ); mUIBlueSlider->setValue( 255 ); - mUIBlueSlider->addEventListener( Event::OnValueChange, - [this] ( auto event ) { onBlueChange( event ); } ); + mUIBlueSlider->on( Event::OnValueChange, [this]( auto event ) { onBlueChange( event ); } ); mUIBlueTxt = createTextBox( String::toString( 255 ), mUIWindow->getContainer(), Sizef(), @@ -285,7 +281,7 @@ UIMapNew::UIMapNew( UIMap* Map, std::function NewMapCb, bool ResizeMap ) OKButton->setPosition( mUIWindow->getContainer()->getSize().getWidth() - OKButton->getSize().getWidth() - 4, mUIWindow->getContainer()->getSize().getHeight() - OKButton->getSize().getHeight() - 4 ); - OKButton->addEventListener( Event::MouseClick, [this] ( auto event ) { onOKClick( event ); } ); + OKButton->on( Event::MouseClick, [this]( auto event ) { onOKClick( event ); } ); OKButton->setText( "OK" ); UIPushButton* CancelButton = UIPushButton::New(); @@ -294,8 +290,7 @@ UIMapNew::UIMapNew( UIMap* Map, std::function NewMapCb, bool ResizeMap ) ->setPosition( OKButton->getPosition().x - OKButton->getSize().getWidth() - 4, OKButton->getPosition().y ); CancelButton->setIcon( sceneNode->findIconDrawable( "cancel", PixelDensity::dpToPxI( 16 ) ) ); - CancelButton->addEventListener( Event::MouseClick, - [this] ( auto event ) { onCancelClick( event ); } ); + CancelButton->on( Event::MouseClick, [this]( auto event ) { onCancelClick( event ); } ); CancelButton->setText( "Cancel" ); mUIWindow->center(); diff --git a/src/tests/test_all/test.cpp b/src/tests/test_all/test.cpp index e8682ba20..d4beb10ee 100644 --- a/src/tests/test_all/test.cpp +++ b/src/tests/test_all/test.cpp @@ -372,8 +372,8 @@ void EETest::createBaseUI() { tWin->setTitle( "Widgets Test" ); - tWin->addEventListener( Event::MouseUp, [this]( auto event ) { onWinMouseUp( event ); } ); - C->addEventListener( Event::MouseUp, [this]( auto event ) { onWinMouseUp( event ); } ); + tWin->on( Event::MouseUp, [this]( auto event ) { onWinMouseUp( event ); } ); + C->on( Event::MouseUp, [this]( auto event ) { onWinMouseUp( event ); } ); UISprite* sprite = UISprite::New(); sprite->setFlags( UI_AUTO_SIZE ); @@ -397,7 +397,7 @@ void EETest::createBaseUI() { Button->setParent( C )->setPosition( 225, 215 )->setSize( 90, 0 ); Button->setIcon( mSceneNode->findIconDrawable( "ok", PixelDensity::dpToPxI( 16 ) ) ); Button->setText( "Click Me" ); - Button->addEventListener( Event::MouseClick, [this]( auto event ) { onButtonClick( event ); } ); + Button->on( Event::MouseClick, [this]( auto event ) { onButtonClick( event ); } ); Button->setTooltipText( "Click and see what happens..." ); UICheckBox* Checkbox = UICheckBox::New(); @@ -417,8 +417,7 @@ void EETest::createBaseUI() { ->setParent( C ) ->setPosition( 220, 80 ) ->setSize( 80, 24 ); - mSlider->addEventListener( Event::OnValueChange, - [this]( auto event ) { onSliderValueChange( event ); } ); + mSlider->on( Event::OnValueChange, [this]( auto event ) { onSliderValueChange( event ); } ); UISlider::New() ->setOrientation( UIOrientation::Vertical ) @@ -437,8 +436,7 @@ void EETest::createBaseUI() { mScrollBar = UIScrollBar::New(); mScrollBar->setParent( C )->setSize( 0, 240 ); - mScrollBar->addEventListener( Event::OnValueChange, - [this]( auto event ) { onValueChange( event ); } ); + mScrollBar->on( Event::OnValueChange, [this]( auto event ) { onValueChange( event ); } ); mProgressBar = UIProgressBar::New(); mProgressBar->setParent( C )->setSize( 200, 24 )->setPosition( 20, 190 ); @@ -560,11 +558,10 @@ void EETest::createBaseUI() { Menu->addSeparator(); Menu->add( "Quit" ); - Menu->addEventListener( Event::OnItemClicked, [this]( auto event ) { onItemClick( event ); } ); - Menu->getItem( "Quit" )->addEventListener( Event::MouseUp, - [this]( auto event ) { onQuitClick( event ); } ); + Menu->on( Event::OnItemClicked, [this]( auto event ) { onItemClick( event ); } ); + Menu->getItem( "Quit" )->on( Event::MouseUp, [this]( auto event ) { onQuitClick( event ); } ); - SceneManager::instance()->getUISceneNode()->getRoot()->addEventListener( + SceneManager::instance()->getUISceneNode()->getRoot()->on( Event::MouseClick, [this]( auto event ) { onMainClick( event ); } ); #ifdef EE_PLATFORM_TOUCH @@ -583,7 +580,7 @@ void EETest::createBaseUI() { mShowMenu->setPosition( screenSize.getWidth() - mShowMenu->getSize().getWidth() - 32, screenSize.getHeight() - mShowMenu->getSize().getHeight() - 9 ); mShowMenu->setAnchors( UI_ANCHOR_RIGHT | UI_ANCHOR_BOTTOM ); - mShowMenu->addEventListener( Event::MouseClick, [this]( auto event ) { onShowMenu( event ); } ); + mShowMenu->on( Event::MouseClick, [this]( auto event ) { onShowMenu( event ); } ); #endif } @@ -657,11 +654,10 @@ void EETest::createNewUI() { scrollView->setTouchDragEnabled( true ); scrollView->setLayoutSizePolicy( SizePolicy::MatchParent, SizePolicy::MatchParent ) ->setParent( relLay ); - scrollView->getContainer()->addEventListener( Event::MouseClick, - [this]( auto event ) { onMainClick( event ); } ); + scrollView->getContainer()->on( Event::MouseClick, + [this]( auto event ) { onMainClick( event ); } ); container->setParent( scrollView ); - container->addEventListener( Event::MouseClick, - [this]( auto event ) { onMainClick( event ); } ); + container->on( Event::MouseClick, [this]( auto event ) { onMainClick( event ); } ); UILoader* loader = UILoader::New(); loader->setOutlineThickness( 4 ) @@ -738,7 +734,7 @@ void EETest::createNewUI() { pushButton->setPosition( 50, 560 )->setSize( 200, 0 )->setParent( container ); pushButton->setText( "PushButton" ); pushButton->setIcon( mSceneNode->findIconDrawable( "ok", PixelDensity::dpToPxI( 16 ) ) ); - pushButton->addEventListener( Event::MouseClick, [this, pushButton]( const Event* event ) { + pushButton->on( Event::MouseClick, [this, pushButton]( const Event* event ) { if ( static_cast( event )->getFlags() & EE_BUTTON_LMASK ) createColorPicker( pushButton ); } ); @@ -1076,11 +1072,10 @@ void EETest::createDecoratedWindow() { ->setMinWindowSize( 530, 350 ) ->setPosition( 200, 50 ); - mUIWindow->addEventListener( Event::OnWindowClose, - [this]( auto event ) { onCloseClick( event ); } ); + mUIWindow->on( Event::OnWindowClose, [this]( auto event ) { onCloseClick( event ); } ); mUIWindow->setTitle( "Test Window" ); - mUIWindow->addEventListener( Event::OnDragStart, onWinDragStart ); - mUIWindow->addEventListener( Event::OnDragStop, onWinDragStop ); + mUIWindow->on( Event::OnDragStart, onWinDragStart ); + mUIWindow->on( Event::OnDragStop, onWinDragStop ); UILinearLayout* lay = UILinearLayout::NewVertical(); lay->setLayoutSizePolicy( SizePolicy::MatchParent, SizePolicy::MatchParent ); @@ -1093,7 +1088,7 @@ void EETest::createDecoratedWindow() { UIPopUpMenu* PopMenu = UIPopUpMenu::New(); PopMenu->add( "Hide Border" ); PopMenu->add( "Close" ); - PopMenu->addEventListener( Event::OnItemClicked, []( const Event* Event ) { + PopMenu->on( Event::OnItemClicked, []( const Event* Event ) { if ( !Event->getNode()->isType( UI_TYPE_MENUITEM ) ) return; @@ -1139,7 +1134,7 @@ void EETest::createDecoratedWindow() { Button->setText( "Click Me" ); Button->setLayoutSizePolicy( SizePolicy::MatchParent, SizePolicy::WrapContent ) ->setParent( lay ); - Button->addEventListener( Event::MouseClick, [this]( auto event ) { onButtonClick( event ); } ); + Button->on( Event::MouseClick, [this]( auto event ) { onButtonClick( event ); } ); mUIWindow->setKeyBindingCommand( "button-click", [this] { addFlyingIcon(); } ); mUIWindow->addKeyBinding( { KEY_C, KEYMOD_LALT }, "button-click" ); @@ -1154,8 +1149,7 @@ void EETest::createDecoratedWindow() { UITextEdit* TEdit = UITextEdit::New(); TEdit->setFlags( UI_WORD_WRAP ); TEdit->setParent( TabWidget ); - TEdit->addEventListener( Event::OnSizeChange, - [this, TEdit]( const Event* ) { TEdit->setText( mBuddha ); } ); + TEdit->on( Event::OnSizeChange, [this, TEdit]( const Event* ) { TEdit->setText( mBuddha ); } ); TabWidget->add( "TextEdit", TEdit ); UITextInput* Txt = UITextInput::New(); diff --git a/src/tools/ecode/ecode.cpp b/src/tools/ecode/ecode.cpp index 414cd8182..2dbd6bf18 100644 --- a/src/tools/ecode/ecode.cpp +++ b/src/tools/ecode/ecode.cpp @@ -1574,7 +1574,7 @@ void App::onTabCreated( UITab* tab, UIWidget* ) { "clone-document-buffer" ); } - menu->addEventListener( Event::OnItemClicked, [tab, this]( const Event* event ) { + menu->on( Event::OnItemClicked, [tab, this]( const Event* event ) { if ( !event->getNode()->isType( UI_TYPE_MENUITEM ) ) return; UIMenuItem* item = event->getNode()->asType(); diff --git a/src/tools/ecode/plugins/autocomplete/autocompleteplugin.cpp b/src/tools/ecode/plugins/autocomplete/autocompleteplugin.cpp index 685c8379f..e950b36b7 100644 --- a/src/tools/ecode/plugins/autocomplete/autocompleteplugin.cpp +++ b/src/tools/ecode/plugins/autocomplete/autocompleteplugin.cpp @@ -243,49 +243,45 @@ void AutoCompletePlugin::load( PluginManager* pluginManager ) { void AutoCompletePlugin::onRegister( UICodeEditor* editor ) { Lock l( mDocMutex ); std::vector listeners; - listeners.push_back( - editor->addEventListener( Event::OnDocumentLoaded, [this, editor]( const Event* ) { - mDirty = true; - mDocs.insert( editor->getDocumentRef().get() ); - mEditorDocs[editor] = editor->getDocumentRef().get(); - tryRequestCapabilities( editor ); - } ) ); + listeners.push_back( editor->on( Event::OnDocumentLoaded, [this, editor]( const Event* ) { + mDirty = true; + mDocs.insert( editor->getDocumentRef().get() ); + mEditorDocs[editor] = editor->getDocumentRef().get(); + tryRequestCapabilities( editor ); + } ) ); - listeners.push_back( - editor->addEventListener( Event::OnDocumentClosed, [this]( const Event* event ) { - const DocEvent* docEvent = static_cast( event ); - TextDocument* doc = docEvent->getDoc(); + listeners.push_back( editor->on( Event::OnDocumentClosed, [this]( const Event* event ) { + const DocEvent* docEvent = static_cast( event ); + TextDocument* doc = docEvent->getDoc(); - { - Lock ls( mDocUsesOwnSymbolsMutex ); - mDocUsesOwnSymbols.erase( doc ); - } + { + Lock ls( mDocUsesOwnSymbolsMutex ); + mDocUsesOwnSymbols.erase( doc ); + } - Lock l( mDocMutex ); - mDocs.erase( doc ); - mDocCache.erase( doc ); - mDirty = true; - } ) ); + Lock l( mDocMutex ); + mDocs.erase( doc ); + mDocCache.erase( doc ); + mDirty = true; + } ) ); - listeners.push_back( - editor->addEventListener( Event::OnDocumentChanged, [this, editor]( const Event* ) { - TextDocument* oldDoc = mEditorDocs[editor]; - TextDocument* newDoc = editor->getDocumentRef().get(); + listeners.push_back( editor->on( Event::OnDocumentChanged, [this, editor]( const Event* ) { + TextDocument* oldDoc = mEditorDocs[editor]; + TextDocument* newDoc = editor->getDocumentRef().get(); - { - Lock ls( mDocUsesOwnSymbolsMutex ); - mDocUsesOwnSymbols.erase( oldDoc ); - } + { + Lock ls( mDocUsesOwnSymbolsMutex ); + mDocUsesOwnSymbols.erase( oldDoc ); + } - Lock l( mDocMutex ); - mDocs.erase( oldDoc ); - mDocCache.erase( oldDoc ); - mEditorDocs[editor] = newDoc; - mDirty = true; - } ) ); + Lock l( mDocMutex ); + mDocs.erase( oldDoc ); + mDocCache.erase( oldDoc ); + mEditorDocs[editor] = newDoc; + mDirty = true; + } ) ); - listeners.push_back( editor->addEventListener( Event::OnCursorPosChange, [this, editor]( - const Event* ) { + listeners.push_back( editor->on( Event::OnCursorPosChange, [this, editor]( const Event* ) { if ( !mReplacing ) resetSuggestions( editor ); @@ -296,14 +292,14 @@ void AutoCompletePlugin::onRegister( UICodeEditor* editor ) { } } ) ); - listeners.push_back( editor->addEventListener( - Event::OnFocusLoss, [this]( const Event* ) { resetSignatureHelp(); } ) ); + listeners.push_back( + editor->on( Event::OnFocusLoss, [this]( const Event* ) { resetSignatureHelp(); } ) ); - listeners.push_back( editor->addEventListener( - Event::OnDocumentUndoRedo, [this]( const Event* ) { resetSignatureHelp(); } ) ); + listeners.push_back( + editor->on( Event::OnDocumentUndoRedo, [this]( const Event* ) { resetSignatureHelp(); } ) ); - listeners.push_back( editor->addEventListener( - Event::OnDocumentSyntaxDefinitionChange, [this]( const Event* ev ) { + listeners.push_back( + editor->on( Event::OnDocumentSyntaxDefinitionChange, [this]( const Event* ev ) { const DocSyntaxDefEvent* event = static_cast( ev ); std::string oldLang = event->getOldLang(); std::string newLang = event->getNewLang(); diff --git a/src/tools/ecode/plugins/formatter/formatterplugin.cpp b/src/tools/ecode/plugins/formatter/formatterplugin.cpp index 40841e260..5ad6fb67e 100644 --- a/src/tools/ecode/plugins/formatter/formatterplugin.cpp +++ b/src/tools/ecode/plugins/formatter/formatterplugin.cpp @@ -70,30 +70,27 @@ void FormatterPlugin::onRegister( UICodeEditor* editor ) { } ); } - listeners.push_back( - editor->addEventListener( Event::OnDocumentLoaded, [this, editor]( const Event* ) { - tryRequestCapabilities( editor->getDocumentRef() ); - } ) ); + listeners.push_back( editor->on( Event::OnDocumentLoaded, [this, editor]( const Event* ) { + tryRequestCapabilities( editor->getDocumentRef() ); + } ) ); - listeners.push_back( - editor->addEventListener( Event::OnDocumentChanged, [this, editor]( const Event* ) { - TextDocument* newDoc = editor->getDocumentRef().get(); - mEditorDocs[editor] = newDoc; - } ) ); + listeners.push_back( editor->on( Event::OnDocumentChanged, [this, editor]( const Event* ) { + TextDocument* newDoc = editor->getDocumentRef().get(); + mEditorDocs[editor] = newDoc; + } ) ); - listeners.push_back( - editor->addEventListener( Event::OnDocumentSave, [this]( const Event* event ) { - if ( mAutoFormatOnSave && event->getNode()->isType( UI_TYPE_CODEEDITOR ) ) { - UICodeEditor* editor = event->getNode()->asType(); - auto isAutoFormatting = mIsAutoFormatting.find( &editor->getDocument() ); - if ( ( isAutoFormatting == mIsAutoFormatting.end() || - isAutoFormatting->second == false ) && - mPluginManager && - !String::startsWith( editor->getDocument().getFilePath(), - mPluginManager->getPluginsPath() ) ) - formatDocAsync( editor ); - } - } ) ); + listeners.push_back( editor->on( Event::OnDocumentSave, [this]( const Event* event ) { + if ( mAutoFormatOnSave && event->getNode()->isType( UI_TYPE_CODEEDITOR ) ) { + UICodeEditor* editor = event->getNode()->asType(); + auto isAutoFormatting = mIsAutoFormatting.find( &editor->getDocument() ); + if ( ( isAutoFormatting == mIsAutoFormatting.end() || + isAutoFormatting->second == false ) && + mPluginManager && + !String::startsWith( editor->getDocument().getFilePath(), + mPluginManager->getPluginsPath() ) ) + formatDocAsync( editor ); + } + } ) ); mEditors.insert( { editor, listeners } ); mEditorDocs[editor] = editor->getDocumentRef().get(); diff --git a/src/tools/ecode/plugins/git/gitplugin.cpp b/src/tools/ecode/plugins/git/gitplugin.cpp index 21b89ff24..f996dd452 100644 --- a/src/tools/ecode/plugins/git/gitplugin.cpp +++ b/src/tools/ecode/plugins/git/gitplugin.cpp @@ -639,11 +639,10 @@ std::string GitPlugin::gitBranch() { } void GitPlugin::onRegisterListeners( UICodeEditor* editor, std::vector& listeners ) { - listeners.push_back( - editor->addEventListener( Event::OnCursorPosChange, [this, editor]( const Event* ) { - if ( mTooltipInfoShowing ) - hideTooltip( editor ); - } ) ); + listeners.push_back( editor->on( Event::OnCursorPosChange, [this, editor]( const Event* ) { + if ( mTooltipInfoShowing ) + hideTooltip( editor ); + } ) ); } Color GitPlugin::getVarColor( const std::string& var ) { diff --git a/src/tools/ecode/plugins/linter/linterplugin.cpp b/src/tools/ecode/plugins/linter/linterplugin.cpp index 6f78676e3..1a17061cd 100644 --- a/src/tools/ecode/plugins/linter/linterplugin.cpp +++ b/src/tools/ecode/plugins/linter/linterplugin.cpp @@ -606,41 +606,38 @@ void LinterPlugin::onRegister( UICodeEditor* editor ) { std::vector listeners; - listeners.push_back( - editor->addEventListener( Event::OnDocumentLoaded, [this, editor]( const Event* event ) { - Lock l( mDocMutex ); - const DocEvent* docEvent = static_cast( event ); - mDocs.insert( docEvent->getDoc() ); - mEditorDocs[editor] = docEvent->getDoc(); - setDocDirty( docEvent->getDoc() ); - } ) ); + listeners.push_back( editor->on( Event::OnDocumentLoaded, [this, editor]( const Event* event ) { + Lock l( mDocMutex ); + const DocEvent* docEvent = static_cast( event ); + mDocs.insert( docEvent->getDoc() ); + mEditorDocs[editor] = docEvent->getDoc(); + setDocDirty( docEvent->getDoc() ); + } ) ); - listeners.push_back( - editor->addEventListener( Event::OnDocumentClosed, [this]( const Event* event ) { - Lock l( mDocMutex ); - const DocEvent* docEvent = static_cast( event ); - TextDocument* doc = docEvent->getDoc(); - mDocs.erase( doc ); - mDirtyDoc.erase( doc ); - Lock matchesLock( mMatchesMutex ); - mMatches.erase( doc ); - } ) ); + listeners.push_back( editor->on( Event::OnDocumentClosed, [this]( const Event* event ) { + Lock l( mDocMutex ); + const DocEvent* docEvent = static_cast( event ); + TextDocument* doc = docEvent->getDoc(); + mDocs.erase( doc ); + mDirtyDoc.erase( doc ); + Lock matchesLock( mMatchesMutex ); + mMatches.erase( doc ); + } ) ); - listeners.push_back( - editor->addEventListener( Event::OnDocumentChanged, [this, editor]( const Event* ) { - TextDocument* oldDoc = mEditorDocs[editor]; - TextDocument* newDoc = editor->getDocumentRef().get(); - Lock l( mDocMutex ); - mDocs.erase( oldDoc ); - mDirtyDoc.erase( oldDoc ); - mEditorDocs[editor] = newDoc; - mDocs.insert( newDoc ); - Lock matchesLock( mMatchesMutex ); - mMatches.erase( oldDoc ); - } ) ); + listeners.push_back( editor->on( Event::OnDocumentChanged, [this, editor]( const Event* ) { + TextDocument* oldDoc = mEditorDocs[editor]; + TextDocument* newDoc = editor->getDocumentRef().get(); + Lock l( mDocMutex ); + mDocs.erase( oldDoc ); + mDirtyDoc.erase( oldDoc ); + mEditorDocs[editor] = newDoc; + mDocs.insert( newDoc ); + Lock matchesLock( mMatchesMutex ); + mMatches.erase( oldDoc ); + } ) ); - listeners.push_back( editor->addEventListener( - Event::OnTextChanged, [this, editor]( const Event* ) { setDocDirty( editor ); } ) ); + listeners.push_back( editor->on( Event::OnTextChanged, + [this, editor]( const Event* ) { setDocDirty( editor ); } ) ); for ( auto& kb : mKeyBindings ) { if ( !kb.second.empty() ) diff --git a/src/tools/ecode/plugins/lsp/lspclientplugin.cpp b/src/tools/ecode/plugins/lsp/lspclientplugin.cpp index d66f3171d..deaf9b47c 100644 --- a/src/tools/ecode/plugins/lsp/lspclientplugin.cpp +++ b/src/tools/ecode/plugins/lsp/lspclientplugin.cpp @@ -1351,12 +1351,12 @@ void LSPClientPlugin::renameSymbol( UICodeEditor* editor ) { selection.hasSelection() ? selection.end() : selStart ) ); msgBox->getTextInput()->getDocument().selectAll(); msgBox->showWhenReady(); - msgBox->addEventListener( Event::OnConfirm, [this, selStart, editor, msgBox]( const Event* ) { + msgBox->on( Event::OnConfirm, [this, selStart, editor, msgBox]( const Event* ) { String newName( msgBox->getTextInput()->getText() ); mClientManager.renameSymbol( editor->getDocumentRef()->getURI(), selStart, newName ); msgBox->closeWindow(); } ); - msgBox->addEventListener( Event::OnClose, [this]( const Event* ) { + msgBox->on( Event::OnClose, [this]( const Event* ) { if ( mManager->getSplitter() && mManager->getSplitter()->getCurWidget() ) mManager->getSplitter()->getCurWidget()->setFocus(); } ); @@ -1437,22 +1437,20 @@ void LSPClientPlugin::onRegister( UICodeEditor* editor ) { std::vector listeners; - listeners.push_back( - editor->addEventListener( Event::OnDocumentLoaded, [this, editor]( const Event* ) { - mEditorDocs[editor] = editor->getDocumentRef().get(); - mClientManager.run( editor->getDocumentRef() ); - updateCurrentSymbol( editor->getDocument() ); - } ) ); + listeners.push_back( editor->on( Event::OnDocumentLoaded, [this, editor]( const Event* ) { + mEditorDocs[editor] = editor->getDocumentRef().get(); + mClientManager.run( editor->getDocumentRef() ); + updateCurrentSymbol( editor->getDocument() ); + } ) ); + + listeners.push_back( editor->on( Event::OnCursorPosChange, [this, editor]( const Event* ) { + if ( mSymbolInfoShowing ) + hideTooltip( editor ); + updateCurrentSymbol( editor->getDocument() ); + } ) ); listeners.push_back( - editor->addEventListener( Event::OnCursorPosChange, [this, editor]( const Event* ) { - if ( mSymbolInfoShowing ) - hideTooltip( editor ); - updateCurrentSymbol( editor->getDocument() ); - } ) ); - - listeners.push_back( - editor->addEventListener( Event::OnDocumentChanged, [this, editor]( const Event* event ) { + editor->on( Event::OnDocumentChanged, [this, editor]( const Event* event ) { const DocChangedEvent* docChangedEvent = static_cast( event ); TextDocument* oldDoc = mEditorDocs[editor]; TextDocument* newDoc = editor->getDocumentRef().get(); diff --git a/src/tools/ecode/plugins/plugin.cpp b/src/tools/ecode/plugins/plugin.cpp index b762ca29e..5f4055392 100644 --- a/src/tools/ecode/plugins/plugin.cpp +++ b/src/tools/ecode/plugins/plugin.cpp @@ -210,37 +210,34 @@ void PluginBase::onRegister( UICodeEditor* editor ) { std::vector listeners; - listeners.push_back( - editor->addEventListener( Event::OnDocumentLoaded, [this, editor]( const Event* event ) { + listeners.push_back( editor->on( Event::OnDocumentLoaded, [this, editor]( const Event* event ) { + Lock l( mMutex ); + const DocEvent* docEvent = static_cast( event ); + mDocs.insert( docEvent->getDoc() ); + mEditorDocs[editor] = docEvent->getDoc(); + onDocumentLoaded( docEvent->getDoc() ); + } ) ); + + listeners.push_back( editor->on( Event::OnDocumentClosed, [this]( const Event* event ) { + { Lock l( mMutex ); const DocEvent* docEvent = static_cast( event ); - mDocs.insert( docEvent->getDoc() ); - mEditorDocs[editor] = docEvent->getDoc(); - onDocumentLoaded( docEvent->getDoc() ); - } ) ); + TextDocument* doc = docEvent->getDoc(); + onDocumentClosed( doc ); + onUnregisterDocument( doc ); + mDocs.erase( doc ); + } + } ) ); - listeners.push_back( - editor->addEventListener( Event::OnDocumentClosed, [this]( const Event* event ) { - { - Lock l( mMutex ); - const DocEvent* docEvent = static_cast( event ); - TextDocument* doc = docEvent->getDoc(); - onDocumentClosed( doc ); - onUnregisterDocument( doc ); - mDocs.erase( doc ); - } - } ) ); - - listeners.push_back( - editor->addEventListener( Event::OnDocumentChanged, [this, editor]( const Event* ) { - TextDocument* oldDoc = mEditorDocs[editor]; - TextDocument* newDoc = editor->getDocumentRef().get(); - Lock l( mMutex ); - mDocs.erase( oldDoc ); - mDocs.insert( newDoc ); - mEditorDocs[editor] = newDoc; - onDocumentChanged( editor, oldDoc ); - } ) ); + listeners.push_back( editor->on( Event::OnDocumentChanged, [this, editor]( const Event* ) { + TextDocument* oldDoc = mEditorDocs[editor]; + TextDocument* newDoc = editor->getDocumentRef().get(); + Lock l( mMutex ); + mDocs.erase( oldDoc ); + mDocs.insert( newDoc ); + mEditorDocs[editor] = newDoc; + onDocumentChanged( editor, oldDoc ); + } ) ); onRegisterListeners( editor, listeners ); diff --git a/src/tools/ecode/plugins/pluginmanager.cpp b/src/tools/ecode/plugins/pluginmanager.cpp index 952de4e1f..13078117b 100644 --- a/src/tools/ecode/plugins/pluginmanager.cpp +++ b/src/tools/ecode/plugins/pluginmanager.cpp @@ -530,7 +530,7 @@ UIWindow* UIPluginManager::New( UISceneNode* sceneNode, PluginManager* manager, prefs->setEnabled( enabled && plugin->hasFileConfig() ); } }; - tv->addEventListener( Event::OnClose, [manager, tv]( const Event* ) { + tv->on( Event::OnClose, [manager, tv]( const Event* ) { if ( tv->readyCbs.empty() ) return; for ( const auto& cb : tv->readyCbs ) { diff --git a/src/tools/ecode/plugins/spellchecker/spellcheckerplugin.cpp b/src/tools/ecode/plugins/spellchecker/spellcheckerplugin.cpp index 77011a817..c27eab15e 100644 --- a/src/tools/ecode/plugins/spellchecker/spellcheckerplugin.cpp +++ b/src/tools/ecode/plugins/spellchecker/spellcheckerplugin.cpp @@ -225,8 +225,8 @@ void SpellCheckerPlugin::onDocumentChanged( UICodeEditor*, TextDocument* oldDoc void SpellCheckerPlugin::onRegisterListeners( UICodeEditor* editor, std::vector& listeners ) { - listeners.push_back( editor->addEventListener( - Event::OnTextChanged, [this, editor]( const Event* ) { setDocDirty( editor ); } ) ); + listeners.push_back( editor->on( Event::OnTextChanged, + [this, editor]( const Event* ) { setDocDirty( editor ); } ) ); } void SpellCheckerPlugin::setDocDirty( TextDocument* doc ) { @@ -249,7 +249,8 @@ void SpellCheckerPlugin::update( UICodeEditor* editor ) { void SpellCheckerPlugin::spellCheckDoc( std::shared_ptr doc ) { if ( ( !mLanguagesDisabled.empty() && mLanguagesDisabled.find( doc->getSyntaxDefinition().getLSPName() ) != - mLanguagesDisabled.end() ) || doc->isHuge() ) + mLanguagesDisabled.end() ) || + doc->isHuge() ) return; ScopedOp op( diff --git a/src/tools/ecode/terminalmanager.cpp b/src/tools/ecode/terminalmanager.cpp index 140eda5b6..66d3c83a4 100644 --- a/src/tools/ecode/terminalmanager.cpp +++ b/src/tools/ecode/terminalmanager.cpp @@ -261,7 +261,7 @@ UIMenu* TerminalManager::createColorSchemeMenu( bool emptyMenu ) { }; UIPopUpMenu* menu = UIPopUpMenu::New(); - menu->addEventListener( Event::OnItemClicked, cb ); + menu->on( Event::OnItemClicked, cb ); mColorSchemeMenus.push_back( menu ); size_t total = 0; const auto& colorSchemes = mTerminalColorSchemes; @@ -284,7 +284,7 @@ UIMenu* TerminalManager::createColorSchemeMenu( bool emptyMenu ) { if ( menu->getCount() == maxItems && colorSchemes.size() - total > 1 ) { UIPopUpMenu* newMenu = UIPopUpMenu::New(); menu->addSubMenu( mApp->i18n( "more_ellipsis", "More..." ), nullptr, newMenu ); - newMenu->addEventListener( Event::OnItemClicked, cb ); + newMenu->on( Event::OnItemClicked, cb ); mColorSchemeMenus.push_back( newMenu ); menu = newMenu; } @@ -537,7 +537,7 @@ UITerminal* TerminalManager::createNewTerminal( term->setColorScheme( csIt != mTerminalColorSchemes.end() ? mTerminalColorSchemes.at( mTerminalCurrentColorScheme ) : TerminalColorScheme::getDefault() ); - term->addEventListener( Event::OnTitleChange, [this]( const Event* event ) { + term->on( Event::OnTitleChange, [this]( const Event* event ) { if ( event->getNode() != mApp->getSplitter()->getCurWidget() ) return; mApp->setAppTitle( event->getNode()->asType()->getTitle() ); @@ -550,7 +550,7 @@ UITerminal* TerminalManager::createNewTerminal( msgBox->getTextInput()->setHint( mApp->i18n( "any_name_ellipsis", "Any name..." ) ); msgBox->setCloseShortcut( { KEY_ESCAPE, KEYMOD_NONE } ); msgBox->showWhenReady(); - msgBox->addEventListener( Event::OnConfirm, [msgBox, term]( const Event* ) { + msgBox->on( Event::OnConfirm, [msgBox, term]( const Event* ) { std::string title( msgBox->getTextInput()->getText().toUtf8() ); term->setTitle( title ); msgBox->close(); diff --git a/src/tools/ecode/uibuildsettings.cpp b/src/tools/ecode/uibuildsettings.cpp index 5ffeb69ea..e14d325c8 100644 --- a/src/tools/ecode/uibuildsettings.cpp +++ b/src/tools/ecode/uibuildsettings.cpp @@ -593,7 +593,7 @@ UIBuildSettings::UIBuildSettings( msgBox->setTitle( i18n( "build_settings", "Build Settings" ) ); msgBox->setCloseShortcut( { KEY_ESCAPE, KEYMOD_NONE } ); msgBox->showWhenReady(); - msgBox->addEventListener( Event::OnConfirm, [this, msgBox]( const Event* ) { + msgBox->on( Event::OnConfirm, [this, msgBox]( const Event* ) { mCanceled = true; sendTextEvent( Event::OnClear, mBuild.getName() ); msgBox->closeWindow(); @@ -612,7 +612,7 @@ UIBuildSettings::UIBuildSettings( msgBox->getTextInput()->setText( mBuild.getName() ); msgBox->getTextInput()->getDocument().selectAll(); } ); - msgBox->addEventListener( Event::OnConfirm, [msgBox, this]( const Event* ) { + msgBox->on( Event::OnConfirm, [msgBox, this]( const Event* ) { const auto& newBuildName = msgBox->getTextInput()->getText(); sendTextEvent( Event::OnCopy, newBuildName ); msgBox->closeWindow(); @@ -625,19 +625,19 @@ UIBuildSettings::UIBuildSettings( msgBox->setTitle( i18n( "build_settings", "Build Settings" ) ); msgBox->setCloseShortcut( { KEY_ESCAPE, KEYMOD_NONE } ); msgBox->showWhenReady(); - msgBox->addEventListener( - Event::OnConfirm, [this, msgBox, buildTypeDropDown, panelBuildTypeDDL]( const Event* ) { - const auto& buildType = msgBox->getTextInput()->getText(); - mBuild.mBuildTypes.insert( buildType.toUtf8() ); - buildTypeDropDown->getListBox()->addListBoxItem( buildType ); - buildTypeDropDown->getListBox()->setSelected( buildType ); - if ( panelBuildTypeDDL ) { - panelBuildTypeDDL->getListBox()->addListBoxItem( buildType ); - panelBuildTypeDDL->getListBox()->setSelected( buildType ); - panelBuildTypeDDL->setEnabled( true ); - } - msgBox->closeWindow(); - } ); + msgBox->on( Event::OnConfirm, + [this, msgBox, buildTypeDropDown, panelBuildTypeDDL]( const Event* ) { + const auto& buildType = msgBox->getTextInput()->getText(); + mBuild.mBuildTypes.insert( buildType.toUtf8() ); + buildTypeDropDown->getListBox()->addListBoxItem( buildType ); + buildTypeDropDown->getListBox()->setSelected( buildType ); + if ( panelBuildTypeDDL ) { + panelBuildTypeDDL->getListBox()->addListBoxItem( buildType ); + panelBuildTypeDDL->getListBox()->setSelected( buildType ); + panelBuildTypeDDL->setEnabled( true ); + } + msgBox->closeWindow(); + } ); } ); find( "build_type_del" )->onClick( [this, buildTypeDropDown, panelBuildTypeDDL]( auto ) { @@ -650,17 +650,17 @@ UIBuildSettings::UIBuildSettings( msgBox->setTitle( i18n( "build_settings", "Build Settings" ) ); msgBox->setCloseShortcut( { KEY_ESCAPE, KEYMOD_NONE } ); msgBox->showWhenReady(); - msgBox->addEventListener( Event::OnConfirm, [this, msgBox, buildTypeDropDown, - panelBuildTypeDDL, txt]( const Event* ) { - mBuild.mBuildTypes.erase( txt.toUtf8() ); - buildTypeDropDown->getListBox()->removeListBoxItem( txt ); - if ( panelBuildTypeDDL ) { - panelBuildTypeDDL->getListBox()->removeListBoxItem( txt ); - if ( panelBuildTypeDDL->getListBox()->isEmpty() ) - panelBuildTypeDDL->setEnabled( false ); - } - msgBox->closeWindow(); - } ); + msgBox->on( Event::OnConfirm, + [this, msgBox, buildTypeDropDown, panelBuildTypeDDL, txt]( const Event* ) { + mBuild.mBuildTypes.erase( txt.toUtf8() ); + buildTypeDropDown->getListBox()->removeListBoxItem( txt ); + if ( panelBuildTypeDDL ) { + panelBuildTypeDDL->getListBox()->removeListBoxItem( txt ); + if ( panelBuildTypeDDL->getListBox()->isEmpty() ) + panelBuildTypeDDL->setEnabled( false ); + } + msgBox->closeWindow(); + } ); } ); if ( isNew && mBuild.mOutputParser.getPreset().empty() && diff --git a/src/tools/ecode/uitreeviewglobalsearch.cpp b/src/tools/ecode/uitreeviewglobalsearch.cpp index 6c9974887..e31cde5dc 100644 --- a/src/tools/ecode/uitreeviewglobalsearch.cpp +++ b/src/tools/ecode/uitreeviewglobalsearch.cpp @@ -81,7 +81,7 @@ void UITreeViewCellGlobalSearch::toggleSelected() { std::function UITreeViewCellGlobalSearch::getCheckBoxFn() { return [this]( UIPushButton* ) -> UITextView* { UICheckBox* chk = UICheckBox::New(); - addEventListener( Event::MouseClick, [this, chk]( const Event* event ) { + on( Event::MouseClick, [this, chk]( const Event* event ) { const MouseEvent* mouseEvent = static_cast( event ); if ( !( mouseEvent->getFlags() & EE_BUTTON_LMASK ) ) return 1; @@ -155,8 +155,7 @@ UIPushButton* UITreeViewCellGlobalSearch::updateText( const std::string& text ) ProjectSearch::ResultData* res = (ProjectSearch::ResultData*)getCurIndex().parent().internalData(); - const auto& styleDef = - SyntaxDefinitionManager::instance()->getByExtension( res->file ); + const auto& styleDef = SyntaxDefinitionManager::instance()->getByExtension( res->file ); Uint32 from = text.find_first_not_of( ' ' ); Uint32 to = from; diff --git a/src/tools/mapeditor/mapeditor.cpp b/src/tools/mapeditor/mapeditor.cpp index 4123775d6..571d775cd 100644 --- a/src/tools/mapeditor/mapeditor.cpp +++ b/src/tools/mapeditor/mapeditor.cpp @@ -26,8 +26,8 @@ bool onCloseRequestCallback( EE::Window::Window* ) { MsgBox = UIMessageBox::New( UIMessageBox::OK_CANCEL, "Do you really want to close the current map?\nAll changes will be lost." ); - MsgBox->addEventListener( Event::OnConfirm, []( const Event* ) { win->close(); } ); - MsgBox->addEventListener( Event::OnClose, []( const Event* ) { MsgBox = NULL; } ); + MsgBox->on( Event::OnConfirm, []( const Event* ) { win->close(); } ); + MsgBox->on( Event::OnClose, []( const Event* ) { MsgBox = NULL; } ); MsgBox->setTitle( "Close Map?" ); MsgBox->center(); MsgBox->showWhenReady(); diff --git a/src/tools/textureatlaseditor/textureatlaseditor.cpp b/src/tools/textureatlaseditor/textureatlaseditor.cpp index bcd6337b8..726df495b 100644 --- a/src/tools/textureatlaseditor/textureatlaseditor.cpp +++ b/src/tools/textureatlaseditor/textureatlaseditor.cpp @@ -26,8 +26,8 @@ bool onCloseRequestCallback( EE::Window::Window* ) { MsgBox = UIMessageBox::New( UIMessageBox::OK_CANCEL, "Do you really want to close the texture atlas editor?\nAll changes will be lost." ); - MsgBox->addEventListener( Event::OnConfirm, []( const Event* ) { win->close(); } ); - MsgBox->addEventListener( Event::OnClose, []( const Event* ) { MsgBox = NULL; } ); + MsgBox->on( Event::OnConfirm, []( const Event* ) { win->close(); } ); + MsgBox->on( Event::OnClose, []( const Event* ) { MsgBox = NULL; } ); MsgBox->setTitle( "Close Texture Atlas Editor?" ); MsgBox->center(); MsgBox->showWhenReady(); diff --git a/src/tools/uieditor/uieditor.cpp b/src/tools/uieditor/uieditor.cpp index ea4a64a94..37fc7a865 100644 --- a/src/tools/uieditor/uieditor.cpp +++ b/src/tools/uieditor/uieditor.cpp @@ -491,7 +491,7 @@ void App::updateRecentFiles() { if ( 0xFFFFFFFF != mRecentFilesEventClickId ) menu->removeEventListener( mRecentFilesEventClickId ); - mRecentFilesEventClickId = menu->addEventListener( + mRecentFilesEventClickId = menu->on( Event::OnItemClicked, [this]( const Event* event ) { onRecentFilesClick( event ); } ); } @@ -520,7 +520,7 @@ void App::updateRecentProjects() { if ( 0xFFFFFFFF != mRecentProjectEventClickId ) menu->removeEventListener( mRecentProjectEventClickId ); - mRecentProjectEventClickId = menu->addEventListener( + mRecentProjectEventClickId = menu->on( Event::OnItemClicked, [this]( const Event* event ) { onRecentProjectClick( event ); } ); } @@ -633,8 +633,8 @@ void App::refreshLayoutList() { mUIMenuBar->addMenuButton( "Layouts", uiLayoutsMenu ); - uiLayoutsMenu->addEventListener( - Event::OnItemClicked, [this]( const Event* event ) { onLayoutSelected( event ); } ); + uiLayoutsMenu->on( Event::OnItemClicked, + [this]( const Event* event ) { onLayoutSelected( event ); } ); } else { uiLayoutsMenu = mUIMenuBar->getPopUpMenu( "Layouts" ); } @@ -874,8 +874,8 @@ bool App::onCloseRequestCallback( EE::Window::Window* ) { UIMessageBox::OK_CANCEL, "Do you really want to close the current file?\nAll changes will be lost." ); mMsgBox->setTheme( mTheme ); - mMsgBox->addEventListener( Event::OnConfirm, [this]( const Event* ) { mWindow->close(); } ); - mMsgBox->addEventListener( Event::OnWindowClose, [this]( const Event* ) { mMsgBox = NULL; } ); + mMsgBox->on( Event::OnConfirm, [this]( const Event* ) { mWindow->close(); } ); + mMsgBox->on( Event::OnWindowClose, [this]( const Event* ) { mMsgBox = NULL; } ); mMsgBox->setTitle( "Close Editor?" ); mMsgBox->center(); mMsgBox->showWhenReady(); @@ -970,7 +970,7 @@ void App::showFileDialog( const String& title, const std::functionsetTheme( mTheme ); dialog->setWindowFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL ); dialog->setTitle( title ); - dialog->addEventListener( Event::OpenFile, cb ); + dialog->on( Event::OpenFile, cb ); dialog->setCloseShortcut( KEY_ESCAPE ); dialog->center(); dialog->show(); @@ -998,7 +998,7 @@ UIFileDialog* App::saveFileDialog( UICodeEditor* editor, bool focusOnClose ) { if ( FileSystem::fileExtension( editor->getDocument().getFilename() ).empty() ) filename += editor->getSyntaxDefinition().getFileExtension(); dialog->setFileName( filename ); - dialog->addEventListener( Event::SaveFile, [this, editor]( const Event* event ) { + dialog->on( Event::SaveFile, [this, editor]( const Event* event ) { if ( editor ) { std::string path( event->getNode()->asType()->getFullPath() ); if ( !path.empty() && !FileSystem::isDirectory( path ) && @@ -1031,7 +1031,7 @@ UIFileDialog* App::saveFileDialog( UICodeEditor* editor, bool focusOnClose ) { } } ); if ( focusOnClose ) { - dialog->addEventListener( Event::OnWindowClose, [editor]( const Event* ) { + dialog->on( Event::OnWindowClose, [editor]( const Event* ) { if ( editor && !SceneManager::instance()->isShuttingDown() ) editor->setFocus(); } ); @@ -1140,8 +1140,7 @@ void App::createAppMenu() { uiPopMenu->add( "Quit", findIcon( "quit" ) )->setId( "quit" ); mUIMenuBar->addMenuButton( "File", uiPopMenu ); - uiPopMenu->addEventListener( Event::OnItemClicked, - [this]( const Event* event ) { fileMenuClick( event ); } ); + uiPopMenu->on( Event::OnItemClicked, [this]( const Event* event ) { fileMenuClick( event ); } ); UIPopUpMenu* uiResourceMenu = UIPopUpMenu::New(); uiResourceMenu->add( "Load images from path...", findIcon( "document-open" ) ) @@ -1153,8 +1152,8 @@ void App::createAppMenu() { uiResourceMenu->add( "Load style sheet from path...", findIcon( "document-open" ) ) ->setId( "load-css-from-path" ); mUIMenuBar->addMenuButton( "Resources", uiResourceMenu ); - uiResourceMenu->addEventListener( Event::OnItemClicked, - [this]( const Event* event ) { fileMenuClick( event ); } ); + uiResourceMenu->on( Event::OnItemClicked, + [this]( const Event* event ) { fileMenuClick( event ); } ); UIPopUpMenu* colorsMenu = UIPopUpMenu::New(); colorsMenu @@ -1185,8 +1184,7 @@ void App::createAppMenu() { viewMenu->add( "Toggle Console", findIcon( "terminal" ), "F3" )->setId( "toggle-console" ); viewMenu->add( "Toggle Editor", findIcon( "editor" ), "F9" )->setId( "toggle-editor" ); mUIMenuBar->addMenuButton( "View", viewMenu ); - viewMenu->addEventListener( Event::OnItemClicked, - [this]( const Event* event ) { fileMenuClick( event ); } ); + viewMenu->on( Event::OnItemClicked, [this]( const Event* event ) { fileMenuClick( event ); } ); mConsole = UIConsole::New(); mConsole->setQuakeMode( true ); mConsole->setVisible( false ); @@ -1324,7 +1322,7 @@ void App::init( const Float& pixelDensityConf, const bool& useAppTheme, const st mUIContainer = UIWindow::NewOpt( UIWindow::SIMPLE_LAYOUT, winStyle ); mUIContainer->setId( "appContainer" )->setSize( mUISceneNode->getSize() ); mUIContainer->setParent( mUISceneNode->getRoot() ); - mUISceneNode->addEventListener( Event::OnSizeChange, [this]( const Event* ) { + mUISceneNode->on( Event::OnSizeChange, [this]( const Event* ) { mUIContainer->setPixelsSize( mUISceneNode->getPixelsSize() ); } ); @@ -1372,8 +1370,7 @@ void App::init( const Float& pixelDensityConf, const bool& useAppTheme, const st resizeCb(); - mUISceneNode->addEventListener( Event::OnSizeChange, - [this]( const Event* ) { resizeCb(); } ); + mUISceneNode->on( Event::OnSizeChange, [this]( const Event* ) { resizeCb(); } ); mUseDefaultTheme = useAppTheme; @@ -1477,12 +1474,12 @@ void App::saveAllProcess() { mTmpDocs.erase( &editor->getDocument() ); } else { UIFileDialog* dialog = saveFileDialog( editor, false ); - dialog->addEventListener( Event::SaveFile, [this, editor]( const Event* ) { + dialog->on( Event::SaveFile, [this, editor]( const Event* ) { updateEditorTabTitle( editor ); if ( mSplitter->getCurEditor() == editor ) updateEditorTitle( editor ); } ); - dialog->addEventListener( Event::OnWindowClose, [this, editor]( const Event* ) { + dialog->on( Event::OnWindowClose, [this, editor]( const Event* ) { mTmpDocs.erase( &editor->getDocument() ); if ( !SceneManager::instance()->isShuttingDown() && !mTmpDocs.empty() ) saveAllProcess();