From abc47067a45dcd85569dc7aa4402e9822a26fac1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Tue, 16 Jun 2020 17:39:49 -0300 Subject: [PATCH] Minor code editor fixes. Improved touch dragging. Minor API change in UIMenu::add*. Updated the README.md. Added TODO.md (to keep track on the things I want to improve/implement). --- README.md | 69 +++++++++-- TODO.md | 61 ++++++++++ bin/assets/ui/breeze.css | 8 ++ include/eepp/ui/doc/syntaxdefinition.hpp | 1 + include/eepp/ui/uicodeeditor.hpp | 2 + include/eepp/ui/uimenu.hpp | 10 +- include/eepp/ui/uimenucheckbox.hpp | 2 - include/eepp/ui/uitouchdraggablewidget.hpp | 2 + src/eepp/maps/mapeditor/mapeditor.cpp | 24 ++-- src/eepp/ui/doc/syntaxdefinitionmanager.cpp | 14 ++- src/eepp/ui/uicodeeditor.cpp | 10 ++ src/eepp/ui/uimenu.cpp | 26 ++-- src/eepp/ui/uimenucheckbox.cpp | 8 +- src/eepp/ui/uiscrollview.cpp | 3 +- src/eepp/ui/uitab.cpp | 3 +- src/eepp/ui/uitouchdraggablewidget.cpp | 125 ++++++++++---------- src/tools/codeeditor/codeeditor.cpp | 11 +- src/tools/uieditor/uieditor.cpp | 5 +- 18 files changed, 257 insertions(+), 127 deletions(-) create mode 100644 TODO.md diff --git a/README.md b/README.md index f62aa68ee..8ebb01241 100644 --- a/README.md +++ b/README.md @@ -184,12 +184,33 @@ its submodules, in order to achieve this easily you can simply clone with: ## UI Screenshots +### ecode - Text Editor + +Text editor inspired in [lite](https://github.com/rxi/lite) (in development, already fully functional). +It's using the newest pure CSS theme based on the default [Plasma](https://kde.org/plasma-desktop) +dark theme: Breeze Dark. + +![ecode - Text Editor](https://web.ensoft.dev/eepp/screenshots/ecode.png) + +### UI Editor + +Editor that displays in real-time the changes on any layout and CSS to help speed up the development +of user interfaces. In the screenshot is displaying some of the default widgets available in eepp. + +![UI Editor](https://web.ensoft.dev/eepp/screenshots/uieditor.png) + +### Texture Atlas Editor + +Small tool, used to create and edit texture atlases. + +![Texture Atlas Editor with 1.5x pixel density](https://web.ensoft.dev/eepp/screenshots/taeditor.png) + +### Map Editor + +2D map editor using the default skinned theme (using a single texture atlas with 9-patch images). + ![Map Editor](https://web.ensoft.dev/eepp/screenshots/eepp1.png) -![UI Elements with 2x pixel density](https://web.ensoft.dev/eepp/screenshots/eepp2.png) - -![Texture Atlas Editor with 1.5x pixel density](https://web.ensoft.dev/eepp/screenshots/eepp3.png) - ## UI Layout XML example It should look really familiar to any Android developer. This is a window with @@ -215,6 +236,8 @@ the most basic controls in a vertical linear layout display. ``` +**UI introduction can be found [here](https://eepp.ensoft.dev/page_uiintroduction.html)**. + ## UI Widgets with C++ example How does it look with real code? @@ -311,6 +334,36 @@ Here is a small example on how the CSS looks like: } ``` +**The complete CSS specification can be found in the docs: [here](https://eepp.ensoft.dev/page_cssspecification.html).** + +**You can also check how a pure CSS theme looks like in eepp: [here](https://github.com/SpartanJ/eepp/blob/develop/bin/assets/ui/breeze.css).** + +## Live demos (using emscripten) + +Since eepp supports emscripten you can take a quick look on some of the examples, demos and tools that +the library currently provides. Please be aware that you'll find some differences based on the limitations +that emscripten have at the moment (no threads, no access to the file system, no custom cursors, etc). +Note: please wait some seconds until the resources are loaded, currently there is no loading indicator. +Also please use a modern browser with WebGL and WASM support. + +* **[ecode - Text Editor](https://web.ensoft.dev/eepp/demo-fs.html?run=eepp-CodeEditor-debug.js)** + +* **[Texture Atlas Editor](https://web.ensoft.dev/eepp/demo-fs.html?run=eepp-TextureAtlasEditor-debug.js)** + +* **[Map Editor](https://web.ensoft.dev/eepp/demo-fs.html?run=eepp-MapEditor-debug.js)** + +* **[UI Hello World](https://web.ensoft.dev/eepp/demo-fs.html?run=eepp-ui-hello-world-debug.js)** + +* **[UI Editor running some tests](https://web.ensoft.dev/eepp/demo-fs.html?run=eepp-UIEditor-debug.js)** + +* **[Fonts example](http://localhost/eepp/emscripten-fs.html?run=eepp-fonts-debug.js)** + +* **[Physics module demo](https://web.ensoft.dev/eepp/demo-fs.html?run=eepp-physics-debug.js)** + +* **[Sprites example](https://web.ensoft.dev/eepp/demo-fs.html?run=eepp-sprites-debug.js)** + +* **[Full Test](https://web.ensoft.dev/eepp/demo-fs.html?run=eepp-test-debug.js)** + ## How to build it The library has very few external dependencies. Most of the time you will only @@ -517,7 +570,7 @@ oriented to desktop apps. Audio and Network modules were based the modules in SFML with several important differences mentioned above. -I like to use what's well done and fit my needs, but since I have my personal +I like to use what's well done and fits my needs, but since I have my personal views on how to implement some things I prefer to take the code, to have full control over it. @@ -547,9 +600,9 @@ of similar alternatives. Regarding the code quality: this project started very long time ago and suffered many modifications over time. A good chunk of the code base still uses old C++ practices (for example: raw pointers, own implementation of thread, mutex, etc). -Some of these things can be "modernized" others don't make much sense or +Some of these things can be "modernized", but, others don't make much sense or overhauling them would take too much time to justify the effort. I'm working on -"modernizing" some parts of the code, and new code usually tend to look more +"modernizing" some parts of the code, and new code usually tends to look more modern. ### Plans/ideas for the future @@ -562,7 +615,7 @@ Improve/create documentation for the UI module. Add more examples and some tools. -Add Scripting support ( first I would like to stabilize the library, but I'm getting there ). +Add scripting support, but first I would like to stabilize the library, but I'm getting there. Add 2D skeletal animations support ( probably Spine2D, shouldn't be much work to implement ). diff --git a/TODO.md b/TODO.md new file mode 100644 index 000000000..d3f9641d5 --- /dev/null +++ b/TODO.md @@ -0,0 +1,61 @@ + +# TODO - Short and mid term plans. + +## UIMenuRadioButton + +Implement support for radio buttons in menues. + +## UIMenuItem + +* Support displaying the keyboard shortcuts for the menu items. + +## UIWidget + +* Add onDrop( UIWidget* ) API. In order to be able to drop widgets onto other widgets. + +## UITabWidget + +* Add support to move Tabs from one UITabWidget to another using the onDrop API. + +## UIIconTheme and UIIconThemeManager + +Implement icon themes separated from the UITheme and customizable from a CSS file. + +## UICodeEditor + +* Add show white spaces. + +## TextDocument + +* Add indentation type auto-detection. + +* Add multi-line search and replace. + +* Add auto-close brackets. + +* Add XML tags auto-close. + +* Add command to comment selected lines. + +* On Save: trim white spaces. + +* On Save: Ensure new line at end of file option. + +* On Save: Allow to select line endings type. + +## GlyphDrawable + +Implement a `GlyphDrawable`. This should render any glyph as a drawable type. +It should be very useful to use font icons in buttons and menues. + +## UITreeView + +Implement a simple tree view widget, to at least cover the most common use cases. + +## Code Editor + +Keep improving it: + +* Add more menues ( Edit, Window ). + +* Save user configuration. \ No newline at end of file diff --git a/bin/assets/ui/breeze.css b/bin/assets/ui/breeze.css index 35a9b6cda..8575a0d3f 100644 --- a/bin/assets/ui/breeze.css +++ b/bin/assets/ui/breeze.css @@ -4,6 +4,7 @@ --back: #31363b; --font: #eff0f1; --font-hint: #898b8d; + --menu-font-disabled: #6e7275; --button-back: #30353a; --button-border: #6b6f73; --button-radius: 2dp; @@ -624,6 +625,13 @@ Menu::SubMenu::text { color: var(--menu-font); } + +Menu::Item:disabled > Menu::Item::text, +Menu::CheckBox:disabled > Menu::CheckBox::text, +Menu::SubMenu:disabled > Menu::SubMenu::text { + color: var(--menu-font-disabled); +} + Menu::SubMenu::arrow { margin-right: 1dp; } diff --git a/include/eepp/ui/doc/syntaxdefinition.hpp b/include/eepp/ui/doc/syntaxdefinition.hpp index 4c359eb48..e76d4c1c3 100644 --- a/include/eepp/ui/doc/syntaxdefinition.hpp +++ b/include/eepp/ui/doc/syntaxdefinition.hpp @@ -2,6 +2,7 @@ #define EE_UI_DOC_DEFINITION_HPP #include +#include #include #include diff --git a/include/eepp/ui/uicodeeditor.hpp b/include/eepp/ui/uicodeeditor.hpp index 154216fad..d81e27587 100644 --- a/include/eepp/ui/uicodeeditor.hpp +++ b/include/eepp/ui/uicodeeditor.hpp @@ -428,6 +428,8 @@ class EE_API UICodeEditor : public UIWidget, public TextDocument::Client { virtual void onFontChanged(); + virtual Uint32 onMessage( const NodeMessage* msg ); + void disableEditorFeatures(); Float getViewportWidth( const bool& forceVScroll = false ) const; diff --git a/include/eepp/ui/uimenu.hpp b/include/eepp/ui/uimenu.hpp index 9d163543a..8af32227f 100644 --- a/include/eepp/ui/uimenu.hpp +++ b/include/eepp/ui/uimenu.hpp @@ -25,15 +25,15 @@ class EE_API UIMenu : public UIWidget { virtual bool isType( const Uint32& type ) const; - Uint32 add( const String& Text, Drawable* Icon = NULL ); + UIMenuItem* add( const String& Text, Drawable* Icon = NULL ); - Uint32 add( UIWidget* widget ); + UIWidget* add( UIWidget* widget ); - Uint32 addSeparator(); + UIMenuSeparator* addSeparator(); - Uint32 addCheckBox( const String& Text, const bool& Active = false ); + UIMenuCheckBox* addCheckBox( const String& Text, const bool& Active = false ); - Uint32 addSubMenu( const String& Text, Drawable* Icon = NULL, UIMenu* SubMenu = NULL ); + UIMenuSubMenu* addSubMenu( const String& Text, Drawable* Icon = NULL, UIMenu* SubMenu = NULL ); UIWidget* getItem( const Uint32& Index ); diff --git a/include/eepp/ui/uimenucheckbox.hpp b/include/eepp/ui/uimenucheckbox.hpp index 775613b76..71cb3e676 100644 --- a/include/eepp/ui/uimenucheckbox.hpp +++ b/include/eepp/ui/uimenucheckbox.hpp @@ -25,8 +25,6 @@ class EE_API UIMenuCheckBox : public UIMenuItem { void switchActive(); - virtual bool inheritsFrom( const Uint32 getType ); - protected: bool mActive; UISkin* mSkinActive; diff --git a/include/eepp/ui/uitouchdraggablewidget.hpp b/include/eepp/ui/uitouchdraggablewidget.hpp index 165e02a27..9a308dd16 100644 --- a/include/eepp/ui/uitouchdraggablewidget.hpp +++ b/include/eepp/ui/uitouchdraggablewidget.hpp @@ -46,6 +46,8 @@ class EE_API UITouchDraggableWidget : public UIWidget { virtual bool isTouchOverAllowedChilds(); virtual void scheduledUpdate( const Time& time ); + + virtual Uint32 onMessage( const NodeMessage* msg ); }; }} // namespace EE::UI diff --git a/src/eepp/maps/mapeditor/mapeditor.cpp b/src/eepp/maps/mapeditor/mapeditor.cpp index 78c8941a9..0aefa4353 100644 --- a/src/eepp/maps/mapeditor/mapeditor.cpp +++ b/src/eepp/maps/mapeditor/mapeditor.cpp @@ -133,26 +133,20 @@ void MapEditor::createMenuBar() { UIPopUpMenu* PU3 = UIPopUpMenu::New(); PU3->setParent( mUIContainer ); - mChkShowGrid = PU3->getItem( PU3->addCheckBox( "Show Grid" ) )->asType(); + mChkShowGrid = PU3->addCheckBox( "Show Grid" ); mChkShowGrid->setActive( true ); - - mChkMarkTileOver = - PU3->getItem( PU3->addCheckBox( "Mark Tile Over" ) )->asType(); - - mChkShowBlocked = PU3->getItem( PU3->addCheckBox( "Show Blocked" ) )->asType(); + mChkMarkTileOver = PU3->addCheckBox( "Mark Tile Over" ); + mChkShowBlocked = PU3->addCheckBox( "Show Blocked" ); PU3->addSeparator(); addShortcut( KEY_KP_PLUS, KEYMOD_CTRL, - PU3->getItem( PU3->add( "Zoom In", mTheme->getIconByName( "zoom-in" ) ) ) - ->asType() ); + PU3->add( "Zoom In", mTheme->getIconByName( "zoom-in" ) ) ); addShortcut( KEY_KP_MINUS, KEYMOD_CTRL, - PU3->getItem( PU3->add( "Zoom Out", mTheme->getIconByName( "zoom-out" ) ) ) - ->asType() ); + PU3->add( "Zoom Out", mTheme->getIconByName( "zoom-out" ) ) ); addShortcut( KEY_0, KEYMOD_CTRL, - PU3->getItem( PU3->add( "Normal Size", mTheme->getIconByName( "zoom-original" ) ) ) - ->asType() ); + PU3->add( "Normal Size", mTheme->getIconByName( "zoom-original" ) ) ); PU3->addSeparator(); PU3->addEventListener( Event::OnItemClicked, cb::Make1( this, &MapEditor::viewMenuClick ) ); @@ -179,13 +173,11 @@ void MapEditor::createMenuBar() { PU5->add( "Layer Properties..." ); PU5->addSeparator(); - Uint32 LayerChkBoxIndex = PU5->addCheckBox( "Lights Enabled" ); - mLayerChkLights = PU5->getItem( LayerChkBoxIndex )->asType(); + mLayerChkLights = PU5->addCheckBox( "Lights Enabled" ); PU5->addSeparator(); - LayerChkBoxIndex = PU5->addCheckBox( "Visible" ); - mLayerChkVisible = PU5->getItem( LayerChkBoxIndex )->asType(); + mLayerChkVisible = PU5->addCheckBox( "Visible" ); PU5->addEventListener( Event::OnItemClicked, cb::Make1( this, &MapEditor::layerMenuClick ) ); MenuBar->addMenuButton( "Layer", PU5 ); diff --git a/src/eepp/ui/doc/syntaxdefinitionmanager.cpp b/src/eepp/ui/doc/syntaxdefinitionmanager.cpp index d20f67740..3fbb83b35 100644 --- a/src/eepp/ui/doc/syntaxdefinitionmanager.cpp +++ b/src/eepp/ui/doc/syntaxdefinitionmanager.cpp @@ -69,8 +69,8 @@ SyntaxDefinitionManager::SyntaxDefinitionManager() { {{"\\."}, "normal"}, {{""}, "comment"}, {{"```", "```"}, "string"}, - {{"``", "``", "\\"}, "string"}, - {{"`", "`", "\\"}, "string"}, + {{"``", "``"}, "string"}, + {{"`", "`"}, "string"}, {{"~~", "~~", "\\"}, "keyword2"}, {{"%-%-%-+"}, "comment"}, {{"%*%s+"}, "operator"}, @@ -858,10 +858,10 @@ SyntaxDefinitionManager::SyntaxDefinitionManager() { // ini / conf add( {"Config File", - {"%.ini$", "%.conf$", "%.desktop$"}, + {"%.ini$", "%.conf$", "%.desktop$", "Doxyfile"}, { {{"#[%da-fA-F]+"}, "literal"}, - {{"#", "\n"}, "comment"}, + {{"#.-\n"}, "comment"}, {{"\"", "\"", "\\"}, "string"}, {{"'", "'", "\\"}, "string"}, {{"%[", "%]"}, "keyword2"}, @@ -1713,6 +1713,12 @@ std::vector SyntaxDefinitionManager::getLanguageNames() const { const SyntaxDefinition& SyntaxDefinitionManager::getStyleByExtension( const std::string& filePath ) const { std::string extension( FileSystem::fileExtension( filePath ) ); + + // Use the filename instead + if ( extension.empty() ) { + extension = FileSystem::fileNameFromPath( filePath ); + } + if ( !extension.empty() ) { for ( auto style = mStyles.rbegin(); style != mStyles.rend(); ++style ) { for ( auto ext : style->getFiles() ) { diff --git a/src/eepp/ui/uicodeeditor.cpp b/src/eepp/ui/uicodeeditor.cpp index 58cf3d5bb..523442224 100644 --- a/src/eepp/ui/uicodeeditor.cpp +++ b/src/eepp/ui/uicodeeditor.cpp @@ -262,6 +262,12 @@ UICodeEditor* UICodeEditor::setFont( Font* font ) { void UICodeEditor::onFontChanged() {} +Uint32 UICodeEditor::onMessage( const NodeMessage* msg ) { + if ( msg->getMsg() == NodeMessage::MouseDown ) + return 1; + return UIWidget::onMessage( msg ); +} + void UICodeEditor::disableEditorFeatures() { mShowLineNumber = false; mShowIndentationGuide = false; @@ -1586,6 +1592,10 @@ void UICodeEditor::registerKeybindings() { {{KEY_DELETE, 0}, "delete-to-next-char"}, {{KEY_KP_ENTER, KEYMOD_CTRL | KEYMOD_SHIFT}, "new-line-above"}, {{KEY_RETURN, KEYMOD_CTRL | KEYMOD_SHIFT}, "new-line-above"}, + {{KEY_KP_ENTER, KEYMOD_CTRL}, "new-line"}, + {{KEY_RETURN, KEYMOD_CTRL}, "new-line"}, + {{KEY_KP_ENTER, KEYMOD_SHIFT}, "new-line"}, + {{KEY_RETURN, KEYMOD_SHIFT}, "new-line"}, {{KEY_KP_ENTER, 0}, "new-line"}, {{KEY_RETURN, 0}, "new-line"}, {{KEY_UP, KEYMOD_CTRL | KEYMOD_SHIFT}, "move-lines-up"}, diff --git a/src/eepp/ui/uimenu.cpp b/src/eepp/ui/uimenu.cpp index 59e355619..0524ab479 100644 --- a/src/eepp/ui/uimenu.cpp +++ b/src/eepp/ui/uimenu.cpp @@ -71,8 +71,10 @@ UIMenuItem* UIMenu::createMenuItem( const String& Text, Drawable* Icon ) { return tCtrl; } -Uint32 UIMenu::add( const String& Text, Drawable* Icon ) { - return add( createMenuItem( Text, Icon ) ); +UIMenuItem* UIMenu::add( const String& Text, Drawable* Icon ) { + UIMenuItem* menuItem = createMenuItem( Text, Icon ); + add( menuItem ); + return menuItem; } UIMenuCheckBox* UIMenu::createMenuCheckBox( const String& Text, const bool& Active ) { @@ -88,8 +90,10 @@ UIMenuCheckBox* UIMenu::createMenuCheckBox( const String& Text, const bool& Acti return tCtrl; } -Uint32 UIMenu::addCheckBox( const String& Text, const bool& Active ) { - return add( createMenuCheckBox( Text, Active ) ); +UIMenuCheckBox* UIMenu::addCheckBox( const String& Text, const bool& Active ) { + UIMenuCheckBox* chkBox = createMenuCheckBox( Text, Active ); + add( chkBox ); + return chkBox; } UIMenuSubMenu* UIMenu::createSubMenu( const String& Text, Drawable* Icon, UIMenu* SubMenu ) { @@ -104,8 +108,10 @@ UIMenuSubMenu* UIMenu::createSubMenu( const String& Text, Drawable* Icon, UIMenu return tCtrl; } -Uint32 UIMenu::addSubMenu( const String& Text, Drawable* Icon, UIMenu* SubMenu ) { - return add( createSubMenu( Text, Icon, SubMenu ) ); +UIMenuSubMenu* UIMenu::addSubMenu( const String& Text, Drawable* Icon, UIMenu* SubMenu ) { + UIMenuSubMenu* subMenu = createSubMenu( Text, Icon, SubMenu ); + add( subMenu ); + return subMenu; } bool UIMenu::widgetCheckSize( UIWidget* widget, const bool& Resize ) { @@ -137,7 +143,7 @@ bool UIMenu::widgetCheckSize( UIWidget* widget, const bool& Resize ) { return false; } -Uint32 UIMenu::add( UIWidget* widget ) { +UIWidget* UIMenu::add( UIWidget* widget ) { if ( this != widget->getParent() ) widget->setParent( this ); @@ -160,7 +166,7 @@ Uint32 UIMenu::add( UIWidget* widget ) { resizeMe(); - return mItems.size() - 1; + return widget; } void UIMenu::setWidgetSize( UIWidget* widget ) { @@ -169,7 +175,7 @@ void UIMenu::setWidgetSize( UIWidget* widget ) { mResizing = false; } -Uint32 UIMenu::addSeparator() { +UIMenuSeparator* UIMenu::addSeparator() { UIMenuSeparator* separator = UIMenuSeparator::New(); separator->setParent( this ); separator->setPixelsPosition( mRealPadding.Left, mRealPadding.Top + mNextPosY ); @@ -189,7 +195,7 @@ Uint32 UIMenu::addSeparator() { } } ); - return mItems.size() - 1; + return separator; } UIWidget* UIMenu::getItem( const Uint32& Index ) { diff --git a/src/eepp/ui/uimenucheckbox.cpp b/src/eepp/ui/uimenucheckbox.cpp index b712f8a3d..b8efbfad2 100644 --- a/src/eepp/ui/uimenucheckbox.cpp +++ b/src/eepp/ui/uimenucheckbox.cpp @@ -11,6 +11,7 @@ UIMenuCheckBox* UIMenuCheckBox::New() { UIMenuCheckBox::UIMenuCheckBox() : UIMenuItem( "menu::checkbox" ), mActive( false ), mSkinActive( NULL ), mSkinInactive( NULL ) { mIcon->setElementTag( mTag + "::icon" ); + mTextBox->setElementTag( mTag + "::text" ); applyDefaultTheme(); mIcon->setFlags( UI_SKIN_KEEP_SIZE_ON_DRAW ); } @@ -117,11 +118,4 @@ void UIMenuCheckBox::onStateChange() { setActive( mActive ); } -bool UIMenuCheckBox::inheritsFrom( const Uint32 Type ) { - if ( Type == UI_TYPE_MENUITEM ) - return true; - - return false; -} - }} // namespace EE::UI diff --git a/src/eepp/ui/uiscrollview.cpp b/src/eepp/ui/uiscrollview.cpp index 44a510389..da3b944a7 100644 --- a/src/eepp/ui/uiscrollview.cpp +++ b/src/eepp/ui/uiscrollview.cpp @@ -349,8 +349,7 @@ Uint32 UIScrollView::onMessage( const NodeMessage* Msg ) { } } } - - return 0; + return UITouchDraggableWidget::onMessage( Msg ); } }} // namespace EE::UI diff --git a/src/eepp/ui/uitab.cpp b/src/eepp/ui/uitab.cpp index 701d9a59d..05d83a1c4 100644 --- a/src/eepp/ui/uitab.cpp +++ b/src/eepp/ui/uitab.cpp @@ -255,7 +255,8 @@ Uint32 UITab::onMessage( const NodeMessage* message ) { switch ( message->getMsg() ) { case NodeMessage::MouseDown: { - if ( flags & EE_BUTTON_LMASK && message->getSender() != mCloseButton ) { + if ( flags & EE_BUTTON_LMASK && message->getSender() != mCloseButton && + getEventDispatcher()->getMouseDownNode() == this ) { tTabW->setTabSelected( this ); } break; diff --git a/src/eepp/ui/uitouchdraggablewidget.cpp b/src/eepp/ui/uitouchdraggablewidget.cpp index d43b86695..84e7bb055 100644 --- a/src/eepp/ui/uitouchdraggablewidget.cpp +++ b/src/eepp/ui/uitouchdraggablewidget.cpp @@ -63,88 +63,85 @@ bool UITouchDraggableWidget::isTouchOverAllowedChilds() { } void UITouchDraggableWidget::scheduledUpdate( const Time& time ) { - if ( mEnabled && mVisible && NULL != getEventDispatcher() ) { - if ( isTouchDragEnabled() ) { - EventDispatcher* eventDispatcher = getEventDispatcher(); - Uint32 Press = eventDispatcher->getPressTrigger(); + if ( mEnabled && mVisible && isTouchDragEnabled() && NULL != getEventDispatcher() ) { + if ( isTouchDragging() ) { + // Mouse Not Down + if ( !( getEventDispatcher()->getPressTrigger() & EE_BUTTON_LMASK ) ) { + setTouchDragging( false ); + getEventDispatcher()->setNodeDragging( NULL ); + return; + } - if ( isTouchDragging() ) { - // Mouse Not Down - if ( !( Press & EE_BUTTON_LMASK ) ) { - setTouchDragging( false ); - eventDispatcher->setNodeDragging( NULL ); - return; - } + Float ms = time.asSeconds(); + Vector2f elapsed( ms, ms ); + Vector2f Pos( getEventDispatcher()->getMousePosf() ); - Float ms = time.asSeconds(); - Vector2f elapsed( ms, ms ); - Vector2f Pos( eventDispatcher->getMousePosf() ); + if ( mTouchDragPoint != Pos ) { + Vector2f diff = -( mTouchDragPoint - Pos ); - if ( mTouchDragPoint != Pos ) { - Vector2f diff = -( mTouchDragPoint - Pos ); + onTouchDragValueChange( diff ); - onTouchDragValueChange( diff ); + mTouchDragAcceleration += elapsed * diff; - mTouchDragAcceleration += elapsed * diff; + mTouchDragPoint = Pos; - mTouchDragPoint = Pos; - - eventDispatcher->setNodeDragging( this ); - } else { - mTouchDragAcceleration -= elapsed * mTouchDragDeceleration; - } + getEventDispatcher()->setNodeDragging( this ); } else { - // Mouse Down - if ( Press & EE_BUTTON_LMASK ) { - if ( isTouchOverAllowedChilds() && !eventDispatcher->isNodeDragging() ) { - setTouchDragging( true ); - eventDispatcher->setNodeDragging( this ); + mTouchDragAcceleration -= elapsed * mTouchDragDeceleration; + } + } else { + // Deaccelerate + if ( mTouchDragAcceleration.x != 0 || mTouchDragAcceleration.y != 0 ) { + Float ms = getEventDispatcher()->getLastFrameTime().asSeconds(); - mTouchDragPoint = Vector2f( eventDispatcher->getMousePos().x, - eventDispatcher->getMousePos().y ); - mTouchDragAcceleration = Vector2f( 0, 0 ); - } + if ( 0 != mTouchDragAcceleration.x ) { + bool wasPositiveX = mTouchDragAcceleration.x >= 0; + + if ( mTouchDragAcceleration.x > 0 ) + mTouchDragAcceleration.x -= mTouchDragDeceleration.x * ms; + else + mTouchDragAcceleration.x += mTouchDragDeceleration.x * ms; + + if ( wasPositiveX && mTouchDragAcceleration.x < 0 ) + mTouchDragAcceleration.x = 0; + else if ( !wasPositiveX && mTouchDragAcceleration.x > 0 ) + mTouchDragAcceleration.x = 0; } - // Deaccelerate - if ( mTouchDragAcceleration.x != 0 || mTouchDragAcceleration.y != 0 ) { - Float ms = eventDispatcher->getLastFrameTime().asSeconds(); + if ( 0 != mTouchDragAcceleration.y ) { + bool wasPositiveY = mTouchDragAcceleration.y >= 0; - if ( 0 != mTouchDragAcceleration.x ) { - bool wasPositiveX = mTouchDragAcceleration.x >= 0; + if ( mTouchDragAcceleration.y > 0 ) + mTouchDragAcceleration.y -= mTouchDragDeceleration.y * ms; + else + mTouchDragAcceleration.y += mTouchDragDeceleration.y * ms; - if ( mTouchDragAcceleration.x > 0 ) - mTouchDragAcceleration.x -= mTouchDragDeceleration.x * ms; - else - mTouchDragAcceleration.x += mTouchDragDeceleration.x * ms; - - if ( wasPositiveX && mTouchDragAcceleration.x < 0 ) - mTouchDragAcceleration.x = 0; - else if ( !wasPositiveX && mTouchDragAcceleration.x > 0 ) - mTouchDragAcceleration.x = 0; - } - - if ( 0 != mTouchDragAcceleration.y ) { - bool wasPositiveY = mTouchDragAcceleration.y >= 0; - - if ( mTouchDragAcceleration.y > 0 ) - mTouchDragAcceleration.y -= mTouchDragDeceleration.y * ms; - else - mTouchDragAcceleration.y += mTouchDragDeceleration.y * ms; - - if ( wasPositiveY && mTouchDragAcceleration.y < 0 ) - mTouchDragAcceleration.y = 0; - else if ( !wasPositiveY && mTouchDragAcceleration.y > 0 ) - mTouchDragAcceleration.y = 0; - } - - onTouchDragValueChange( mTouchDragAcceleration ); + if ( wasPositiveY && mTouchDragAcceleration.y < 0 ) + mTouchDragAcceleration.y = 0; + else if ( !wasPositiveY && mTouchDragAcceleration.y > 0 ) + mTouchDragAcceleration.y = 0; } + + onTouchDragValueChange( mTouchDragAcceleration ); } } } } +Uint32 UITouchDraggableWidget::onMessage( const NodeMessage* msg ) { + if ( msg->getMsg() == NodeMessage::MouseDown && ( msg->getFlags() & EE_BUTTON_LMASK ) && + !isTouchDragging() && isTouchOverAllowedChilds() && + !getEventDispatcher()->isNodeDragging() ) { + setTouchDragging( true ); + getEventDispatcher()->setNodeDragging( this ); + mTouchDragPoint = Vector2f( getEventDispatcher()->getMousePos().x, + getEventDispatcher()->getMousePos().y ); + mTouchDragAcceleration = Vector2f( 0, 0 ); + return 1; + } + return 0; +} + std::string UITouchDraggableWidget::getPropertyString( const PropertyDefinition* propertyDef, const Uint32& propertyIndex ) { if ( NULL == propertyDef ) diff --git a/src/tools/codeeditor/codeeditor.cpp b/src/tools/codeeditor/codeeditor.cpp index 16831f7bf..3e053f5bd 100644 --- a/src/tools/codeeditor/codeeditor.cpp +++ b/src/tools/codeeditor/codeeditor.cpp @@ -663,15 +663,18 @@ void App::initSearchBar() { UITextInput* findInput = mSearchBarLayout->find( "search_find" ); UITextInput* replaceInput = mSearchBarLayout->find( "search_replace" ); UICheckBox* caseSensitiveChk = mSearchBarLayout->find( "case_sensitive" ); - findInput->addEventListener( - Event::OnTextChanged, [&, findInput, caseSensitiveChk]( const Event* ) { + findInput->addEventListener( Event::OnTextChanged, [&, findInput, + caseSensitiveChk]( const Event* ) { + if ( mCurEditor ) { if ( !findInput->getText().empty() ) { + mCurEditor->getDocument().setSelection( mCurEditor->getDocument().startOfDoc() ); findNextText( findInput->getText(), caseSensitiveChk->isChecked() ); - } else if ( mCurEditor ) { + } else { mCurEditor->getDocument().setSelection( mCurEditor->getDocument().getSelection().start() ); } - } ); + } + } ); mSearchBarLayout->addCommand( "close-searchbar", [&] { mSearchBarLayout->setEnabled( false )->setVisible( false ); mCurEditor->setFocus(); diff --git a/src/tools/uieditor/uieditor.cpp b/src/tools/uieditor/uieditor.cpp index 60b24370e..1b8a329eb 100644 --- a/src/tools/uieditor/uieditor.cpp +++ b/src/tools/uieditor/uieditor.cpp @@ -496,10 +496,7 @@ void refreshLayoutList() { uiLayoutsMenu->removeAll(); for ( auto it = layouts.begin(); it != layouts.end(); ++it ) { - Uint32 idx = uiLayoutsMenu->addCheckBox( it->first ); - UIMenuCheckBox* chk = static_cast( uiLayoutsMenu->getItem( idx ) ); - - chk->setActive( currentLayout == it->second ); + uiLayoutsMenu->addCheckBox( it->first )->setActive( currentLayout == it->second ); } } else if ( uiMenuBar->getButton( "Layouts" ) != NULL ) { uiMenuBar->removeMenuButton( "Layouts" );