From f66f6c9d1fe79df997e95fe75c3304d8ee132689 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=AD=C2=ADn=20Lucas=20Golini?= Date: Tue, 18 Apr 2017 04:41:38 -0300 Subject: [PATCH] Added UIGridLayout. Also some fixes for the UI layouts and ScrollView. --HG-- branch : dev --- include/eepp/graphics/texturefactory.hpp | 5 +- include/eepp/system/color.hpp | 2 +- include/eepp/ui.hpp | 1 + include/eepp/ui/uicontrol.hpp | 2 +- include/eepp/ui/uigridlayout.hpp | 82 ++++++++ include/eepp/ui/uihelper.hpp | 1 + include/eepp/ui/uiimage.hpp | 8 +- include/eepp/ui/uilinearlayout.hpp | 1 + include/eepp/ui/uiscrollview.hpp | 3 + include/eepp/ui/uitouchdragablewidget.hpp | 2 + projects/linux/ee.files | 2 + src/eepp/graphics/texturefactory.cpp | 13 ++ src/eepp/system/color.cpp | 2 +- src/eepp/ui/uicontrol.cpp | 10 +- src/eepp/ui/uigridlayout.cpp | 239 ++++++++++++++++++++++ src/eepp/ui/uiimage.cpp | 8 +- src/eepp/ui/uilinearlayout.cpp | 20 +- src/eepp/ui/uilistbox.cpp | 2 +- src/eepp/ui/uimanager.cpp | 2 +- src/eepp/ui/uirelativelayout.cpp | 4 +- src/eepp/ui/uiscrollview.cpp | 20 +- src/eepp/ui/uitouchdragablewidget.cpp | 16 ++ src/eepp/ui/uiwidgetcreator.cpp | 2 + src/test/eetest.cpp | 30 +++ 24 files changed, 452 insertions(+), 25 deletions(-) create mode 100644 include/eepp/ui/uigridlayout.hpp create mode 100644 src/eepp/ui/uigridlayout.cpp diff --git a/include/eepp/graphics/texturefactory.hpp b/include/eepp/graphics/texturefactory.hpp index 12f25dc3a..2f29719b9 100755 --- a/include/eepp/graphics/texturefactory.hpp +++ b/include/eepp/graphics/texturefactory.hpp @@ -122,7 +122,10 @@ class EE_API TextureFactory : protected Mutex { void setCurrentTexture( const int& TexId, const Uint32& TextureUnit ); /** Returns the number of textures loaded */ - Uint32 getNumTextures() const { return (Uint32)mTextures.size(); } + Uint32 getTextureCount() const { return (Uint32)mTextures.size(); } + + /** @return All the active textures */ + std::vector getTextures(); /** Set the texture enviroment * @param Param The texture param diff --git a/include/eepp/system/color.hpp b/include/eepp/system/color.hpp index b76858c34..e1ffb66a7 100755 --- a/include/eepp/system/color.hpp +++ b/include/eepp/system/color.hpp @@ -225,7 +225,7 @@ class EE_API Color : public tColor /** Blend a source color to destination color */ static Color blend( Color src, Color dst ); - static Color colorFromPointer( void *ptr ); + static Color fromPointer( void *ptr ); static Color fromString( const char * str ); diff --git a/include/eepp/ui.hpp b/include/eepp/ui.hpp index 98a7fc073..f983832b0 100644 --- a/include/eepp/ui.hpp +++ b/include/eepp/ui.hpp @@ -53,6 +53,7 @@ #include #include #include +#include #include #include diff --git a/include/eepp/ui/uicontrol.hpp b/include/eepp/ui/uicontrol.hpp index d6763a855..ba88cf9ce 100644 --- a/include/eepp/ui/uicontrol.hpp +++ b/include/eepp/ui/uicontrol.hpp @@ -219,7 +219,7 @@ class EE_API UIControl { Sizei getSkinSize(); - UIControl * getNextComplexControl(); + UIControl * getNextWidget(); void applyDefaultTheme(); diff --git a/include/eepp/ui/uigridlayout.hpp b/include/eepp/ui/uigridlayout.hpp new file mode 100644 index 000000000..62b8905fa --- /dev/null +++ b/include/eepp/ui/uigridlayout.hpp @@ -0,0 +1,82 @@ +#ifndef EE_UI_UIGRIDLAYOUT +#define EE_UI_UIGRIDLAYOUT + +#include + +namespace EE { namespace UI { + +class EE_API UIGridLayout : public UIWidget { + public: + enum ElementMode + { + Size, + Weight + }; + + static UIGridLayout * New(); + + UIGridLayout(); + + virtual Uint32 getType() const; + + virtual bool isType( const Uint32& type ) const; + + Sizei getSpan() const; + + UIGridLayout * setSpan(const Sizei& span); + + ElementMode getColumnMode() const; + + UIGridLayout * setColumnMode( const ElementMode& mode ); + + ElementMode getRowMode() const; + + UIGridLayout * setRowMode( const ElementMode& mode ); + + Float getColumnWeight() const; + + UIGridLayout * setColumnWeight(const Float & columnWeight); + + int getColumnWidth() const; + + UIGridLayout * setColumnWidth(int columnWidth); + + int getRowHeight() const; + + UIGridLayout * setRowHeight(int rowHeight); + + Float getRowWeight() const; + + UIGridLayout * setRowWeight(const Float & rowWeight); + + Rect getPadding() const; + + void setPadding(const Rect & padding); + + virtual void loadFromXmlNode( const pugi::xml_node& node ); + protected: + Rect mPadding; + Sizei mSpan; + ElementMode mColumnMode; + ElementMode mRowMode; + Float mColumnWeight; + int mColumnWidth; + Float mRowWeight; + int mRowHeight; + + virtual void onSizeChange(); + + virtual void onChildCountChange(); + + virtual void onParentSizeChange( const Vector2i& SizeChange ); + + virtual Uint32 onMessage( const UIMessage * Msg ); + + Sizei getTargetElementSize(); + + void pack(); +}; + +}} + +#endif diff --git a/include/eepp/ui/uihelper.hpp b/include/eepp/ui/uihelper.hpp index 14c88db3c..d7364bc1e 100644 --- a/include/eepp/ui/uihelper.hpp +++ b/include/eepp/ui/uihelper.hpp @@ -106,6 +106,7 @@ enum UI_CONTROL_TYPES { UI_TYPE_LINEAR_LAYOUT, UI_TYPE_RELATIVE_LAYOUT, UI_TYPE_TOUCH_DRAGABLE_WIDGET, + UI_TYPE_GRID_LAYOUT, UI_TYPE_USER = 10000 }; diff --git a/include/eepp/ui/uiimage.hpp b/include/eepp/ui/uiimage.hpp index 1492c1295..4ff434d69 100644 --- a/include/eepp/ui/uiimage.hpp +++ b/include/eepp/ui/uiimage.hpp @@ -23,15 +23,11 @@ class EE_API UIImage : public UIWidget { Drawable * getDrawable() const; - void setDrawable( Drawable * drawable ); + UIImage * setDrawable( Drawable * drawable ); const Color& getColor() const; - void setColor( const Color& col ); - - const EE_RENDER_MODE& getRenderMode() const; - - void setRenderMode( const EE_RENDER_MODE& render ); + UIImage * setColor( const Color& col ); const Vector2i& getAlignOffset() const; diff --git a/include/eepp/ui/uilinearlayout.hpp b/include/eepp/ui/uilinearlayout.hpp index 89e9a02a0..a5495bd52 100644 --- a/include/eepp/ui/uilinearlayout.hpp +++ b/include/eepp/ui/uilinearlayout.hpp @@ -28,6 +28,7 @@ class EE_API UILinearLayout : public UIWidget { virtual void loadFromXmlNode( const pugi::xml_node& node ); protected: UI_ORIENTATION mOrientation; + bool mAttrChangeReceive; virtual Uint32 onMessage( const UIMessage * Msg ); diff --git a/include/eepp/ui/uiscrollview.hpp b/include/eepp/ui/uiscrollview.hpp index 0e7099239..22b2fc26b 100644 --- a/include/eepp/ui/uiscrollview.hpp +++ b/include/eepp/ui/uiscrollview.hpp @@ -49,6 +49,7 @@ class EE_API UIScrollView : public UITouchDragableWidget { UIScrollBar * mHScroll; UIControlAnim * mContainer; UIControl * mScrollView; + Uint32 mSizeChangeCb; virtual void onSizeChange(); @@ -58,6 +59,8 @@ class EE_API UIScrollView : public UITouchDragableWidget { void onValueChangeCb( const UIEvent * Event ); + void onScrollViewSizeChange( const UIEvent * Event ); + void containerUpdate(); void updateScroll(); diff --git a/include/eepp/ui/uitouchdragablewidget.hpp b/include/eepp/ui/uitouchdragablewidget.hpp index da7558956..4a4724e91 100644 --- a/include/eepp/ui/uitouchdragablewidget.hpp +++ b/include/eepp/ui/uitouchdragablewidget.hpp @@ -28,6 +28,8 @@ class EE_API UITouchDragableWidget : public UIWidget { Vector2f getTouchDragDeceleration() const; UITouchDragableWidget * setTouchDragDeceleration( const Vector2f& touchDragDeceleration ); + + virtual void loadFromXmlNode( const pugi::xml_node& node ); protected: Vector2f mTouchDragPoint; Vector2f mTouchDragAcceleration; diff --git a/projects/linux/ee.files b/projects/linux/ee.files index 0bb6eeaf1..9aa112d27 100644 --- a/projects/linux/ee.files +++ b/projects/linux/ee.files @@ -29,6 +29,7 @@ ../../include/eepp/system/translator.hpp ../../include/eepp/ui/uidragablecontrol.hpp ../../include/eepp/ui/uieventmouse.hpp +../../include/eepp/ui/uigridlayout.hpp ../../include/eepp/ui/uiimage.hpp ../../include/eepp/ui/uilinearlayout.hpp ../../include/eepp/ui/uimenuseparator.hpp @@ -73,6 +74,7 @@ ../../src/eepp/system/color.cpp ../../src/eepp/system/translator.cpp ../../src/eepp/ui/uidragablecontrol.cpp +../../src/eepp/ui/uigridlayout.cpp ../../src/eepp/ui/uiimage.cpp ../../src/eepp/ui/uilinearlayout.cpp ../../src/eepp/ui/uiloader.cpp diff --git a/src/eepp/graphics/texturefactory.cpp b/src/eepp/graphics/texturefactory.cpp index fb3d2db45..064962733 100755 --- a/src/eepp/graphics/texturefactory.cpp +++ b/src/eepp/graphics/texturefactory.cpp @@ -179,6 +179,19 @@ void TextureFactory::setCurrentTexture( const int& TexId, const Uint32& TextureU mCurrentTexture[ TextureUnit ] = TexId; } +std::vector TextureFactory::getTextures() { + std::vector textures; + + for ( Uint32 i = 1; i < mTextures.size(); i++ ) { + Texture* Tex = getTexture(i); + + if ( Tex ) + textures.push_back( Tex ); + } + + return textures; +} + void TextureFactory::reloadAllTextures() { for ( Uint32 i = 1; i < mTextures.size(); i++ ) { Texture* Tex = getTexture(i); diff --git a/src/eepp/system/color.cpp b/src/eepp/system/color.cpp index dc7b47aa9..db31ea24c 100644 --- a/src/eepp/system/color.cpp +++ b/src/eepp/system/color.cpp @@ -244,7 +244,7 @@ Color Color::fromHsl( const Colorf& hsl ) { return Color( (Uint8)Math::round(rgba.r * 255.f), (Uint8)Math::round(rgba.g * 255.f), (Uint8)Math::round(rgba.b * 255.f), Math::round( hsl.hsl.a * 255.f ) ); } -Color Color::colorFromPointer( void *ptr ) { +Color Color::fromPointer( void *ptr ) { unsigned long val = (long)ptr; // hash the pointer up nicely diff --git a/src/eepp/ui/uicontrol.cpp b/src/eepp/ui/uicontrol.cpp index 59f3a9203..d144426f4 100644 --- a/src/eepp/ui/uicontrol.cpp +++ b/src/eepp/ui/uicontrol.cpp @@ -369,7 +369,7 @@ void UIControl::drawBox() { Primitives P; P.setFillMode( DRAW_LINE ); P.setBlendMode( getBlendMode() ); - P.setColor( Color::colorFromPointer( this ) ); + P.setColor( Color::fromPointer( this ) ); P.setLineWidth( PixelDensity::dpToPxI( 1 ) ); P.drawRectangle( getRectf() ); } @@ -1449,7 +1449,7 @@ Sizei UIControl::getSkinSize() { return Sizei::Zero; } -UIControl * UIControl::getNextComplexControl() { +UIControl * UIControl::getNextWidget() { UIControl * Found = NULL; UIControl * ChildLoop = mChild; @@ -1458,7 +1458,7 @@ UIControl * UIControl::getNextComplexControl() { if ( ChildLoop->isWidget() ) { return ChildLoop; } else { - Found = ChildLoop->getNextComplexControl(); + Found = ChildLoop->getNextWidget(); if ( NULL != Found ) { return Found; @@ -1473,7 +1473,7 @@ UIControl * UIControl::getNextComplexControl() { if ( mNext->isVisible() && mNext->isEnabled() && mNext->isWidget() ) { return mNext; } else { - return mNext->getNextComplexControl(); + return mNext->getNextWidget(); } } else { ChildLoop = mParentCtrl; @@ -1483,7 +1483,7 @@ UIControl * UIControl::getNextComplexControl() { if ( ChildLoop->mNext->isVisible() && ChildLoop->mNext->isEnabled() && ChildLoop->mNext->isWidget() ) { return ChildLoop->mNext; } else { - return ChildLoop->mNext->getNextComplexControl(); + return ChildLoop->mNext->getNextWidget(); } } diff --git a/src/eepp/ui/uigridlayout.cpp b/src/eepp/ui/uigridlayout.cpp new file mode 100644 index 000000000..2a562e5d9 --- /dev/null +++ b/src/eepp/ui/uigridlayout.cpp @@ -0,0 +1,239 @@ +#include +#include + +namespace EE { namespace UI { + +UIGridLayout * UIGridLayout::New() { + return eeNew( UIGridLayout, () ); +} + +UIGridLayout::UIGridLayout() : + UIWidget(), + mColumnMode( Weight ), + mRowMode( Weight ), + mColumnWeight( 0.25f ), + mColumnWidth( 0 ), + mRowWeight( 0.25f ), + mRowHeight( 0 ) +{ +} + +Uint32 UIGridLayout::getType() const { + return UI_TYPE_GRID_LAYOUT; +} + +bool UIGridLayout::isType( const Uint32& type ) const { + return UIGridLayout::getType() == type ? true : UIWidget::isType( type ); +} + +Sizei UIGridLayout::getSpan() const { + return mSpan; +} + +UIGridLayout * UIGridLayout::setSpan(const Sizei & span) { + mSpan = span; + return this; +} + +UIGridLayout::ElementMode UIGridLayout::getColumnMode() const { + return mColumnMode; +} + +UIGridLayout * UIGridLayout::setColumnMode(const UIGridLayout::ElementMode & mode) { + mColumnMode = mode; + pack(); + return this; +} + +UIGridLayout::ElementMode UIGridLayout::getRowMode() const { + return mRowMode; +} + +UIGridLayout *UIGridLayout::setRowMode(const UIGridLayout::ElementMode & mode) { + mRowMode = mode; + pack(); + return this; +} + +Float UIGridLayout::getColumnWeight() const { + return mColumnWeight; +} + +UIGridLayout * UIGridLayout::setColumnWeight(const Float & columnWeight) { + mColumnWeight = columnWeight; + if ( mColumnMode == Weight ) + pack(); + return this; +} + +int UIGridLayout::getColumnWidth() const { + return mColumnWidth; +} + +UIGridLayout * UIGridLayout::setColumnWidth(int columnWidth) { + mColumnWidth = columnWidth; + if ( mColumnMode == Size ) + pack(); + return this; +} + +int UIGridLayout::getRowHeight() const { + return mRowHeight; +} + +UIGridLayout * UIGridLayout::setRowHeight(int rowHeight) { + mRowHeight = rowHeight; + if ( mRowMode == Size ) + pack(); + return this; +} + +Float UIGridLayout::getRowWeight() const { + return mRowWeight; +} + +UIGridLayout * UIGridLayout::setRowWeight(const Float & rowWeight) { + mRowWeight = rowWeight; + if ( mRowMode == Weight ) + pack(); + return this; +} + +Rect UIGridLayout::getPadding() const { + return mPadding; +} + +void UIGridLayout::setPadding(const Rect & padding) +{ + mPadding = padding; +} + +void UIGridLayout::onSizeChange() { + pack(); + UIWidget::onSizeChange(); +} + +void UIGridLayout::onChildCountChange() { + pack(); + UIWidget::onChildCountChange(); +} + +void UIGridLayout::onParentSizeChange(const Vector2i & SizeChange) { + pack(); + UIWidget::onParentSizeChange( SizeChange ); +} + +void UIGridLayout::pack() { + setInternalPosition( Vector2i( mLayoutMargin.Left, mPos.y ) ); + setInternalPosition( Vector2i( mPos.x, mLayoutMargin.Top ) ); + + if ( getLayoutWidthRules() == MATCH_PARENT ) { + setInternalWidth( getParent()->getSize().getWidth() - mLayoutMargin.Left - mLayoutMargin.Right ); + sendCommonEvent( UIEvent::EventOnSizeChange ); + } + + if ( getLayoutHeightRules() == MATCH_PARENT ) { + setInternalHeight( getParent()->getSize().getHeight() - mLayoutMargin.Top - mLayoutMargin.Bottom ); + sendCommonEvent( UIEvent::EventOnSizeChange ); + } + + UIControl * ChildLoop = mChild; + + Vector2i pos(mPadding.Left,mPadding.Top); + Sizei targetSize( getTargetElementSize() ); + + if ( getHorizontalAlign() == UI_HALIGN_RIGHT ) + pos.x = mSize.getWidth() - mPadding.Right; + + while ( NULL != ChildLoop ) { + if ( ChildLoop->isWidget() && ChildLoop->isVisible() ) { + UIWidget * widget = static_cast( ChildLoop ); + + if ( widget->getLayoutWeight() != 0.f ) + targetSize.x = widget->getLayoutWeight() * ( mSize.getWidth() - mPadding.Left - mPadding.Right ); + + widget->setSize( targetSize ); + widget->setPosition( pos ); + + pos.x += getHorizontalAlign() == UI_HALIGN_RIGHT ? -targetSize.getWidth() : targetSize.getWidth(); + + if ( pos.x < mPadding.Left || pos.x + targetSize.x > mSize.getWidth() - mPadding.Right ) { + pos.x = getHorizontalAlign() == UI_HALIGN_RIGHT ? mSize.getWidth() - mPadding.Right : mPadding.Left; + + pos.y += targetSize.getHeight() + mSpan.y; + } else { + pos.x += getHorizontalAlign() == UI_HALIGN_RIGHT ? -mSpan.x : mSpan.x; + } + } + + ChildLoop = ChildLoop->getNextControl(); + } + + if ( getLayoutHeightRules() == WRAP_CONTENT ) { + setInternalHeight( pos.y + targetSize.getHeight() ); + sendCommonEvent( UIEvent::EventOnSizeChange ); + } +} + +Uint32 UIGridLayout::onMessage(const UIMessage * Msg) { + switch( Msg->getMsg() ) { + case UIMessage::MsgLayoutAttributeChange: + { + pack(); + break; + } + } + + return 0; +} + +Sizei UIGridLayout::getTargetElementSize() { + return Sizei( mColumnMode == Size ? mColumnWidth : ( ( getLayoutHeightRules() == WRAP_CONTENT ? getParent()->getSize().getWidth() : mSize.getWidth() ) - mPadding.Left - mPadding.Right ) * mColumnWeight, + mRowMode == Size ? mRowHeight : ( ( getLayoutHeightRules() == WRAP_CONTENT ? getParent()->getSize().getHeight() : mSize.getHeight() ) - mPadding.Top - mPadding.Bottom ) * mRowWeight ); +} + +void UIGridLayout::loadFromXmlNode(const pugi::xml_node & node) { + UIWidget::loadFromXmlNode( node ); + + for (pugi::xml_attribute_iterator ait = node.attributes_begin(); ait != node.attributes_end(); ++ait) { + std::string name = ait->name(); + String::toLowerInPlace( name ); + + if ( "columnspan" == name ) { + setSpan( Sizei( mSpan.x, ait->as_int() ) ); + } else if ( "rowspan" == name ) { + setSpan( Sizei( ait->as_int(), mSpan.y ) ); + } else if ( "span" == name ) { + setSpan( Sizei( ait->as_int(), ait->as_int() ) ); + } else if ( "columnmode" == name ) { + std::string val( ait->as_string() ); + String::toLowerInPlace( val ); + setColumnMode( "size" == val ? Size : Weight ); + } else if ( "rowmode" == name ) { + std::string val( ait->as_string() ); + String::toLowerInPlace( val ); + setRowMode( "size" == val ? Size : Weight ); + } else if ( "columnweight" == name ) { + setColumnWeight( ait->as_float() ); + } else if ( "columnwidth" == name ) { + setColumnWidth( ait->as_int() ); + } else if ( "rowweight" == name ) { + setRowWeight( ait->as_float() ); + } else if ( "rowheight" == name ) { + setRowHeight( ait->as_int() ); + } else if ( "padding" == name ) { + int val = PixelDensity::toDpFromStringI( ait->as_string() ); + setPadding( Rect( val, val, val, val ) ); + } else if ( "paddingleft" == name ) { + setPadding( Rect( PixelDensity::toDpFromStringI( ait->as_string() ), mPadding.Top, mPadding.Right, mPadding.Bottom ) ); + } else if ( "paddingright" == name ) { + setPadding( Rect( mPadding.Left, mPadding.Top, PixelDensity::toDpFromStringI( ait->as_string() ), mPadding.Bottom ) ); + } else if ( "paddingtop" == name ) { + setPadding( Rect( mPadding.Left, PixelDensity::toDpFromStringI( ait->as_string() ), mPadding.Right, mPadding.Bottom ) ); + } else if ( "paddingbottom" == name ) { + setPadding( Rect( mPadding.Left, mPadding.Top, mPadding.Right, PixelDensity::toDpFromStringI( ait->as_string() ) ) ); + } + } +} + +}} diff --git a/src/eepp/ui/uiimage.cpp b/src/eepp/ui/uiimage.cpp index 126b07987..0caa1a7a2 100644 --- a/src/eepp/ui/uiimage.cpp +++ b/src/eepp/ui/uiimage.cpp @@ -12,6 +12,7 @@ UIImage * UIImage::New() { UIImage::UIImage() : UIWidget(), + mScaleType( 0 ), mDrawable( NULL ), mColor(), mAlignOffset(0,0) @@ -33,7 +34,7 @@ bool UIImage::isType( const Uint32& type ) const { return UIImage::getType() == type ? true : UIWidget::isType( type ); } -void UIImage::setDrawable( Drawable * drawable ) { +UIImage * UIImage::setDrawable( Drawable * drawable ) { safeDeleteDrawable(); mDrawable = drawable; @@ -47,6 +48,8 @@ void UIImage::setDrawable( Drawable * drawable ) { autoAlign(); notifyLayoutAttrChange(); + + return this; } void UIImage::onAutoSize() { @@ -113,9 +116,10 @@ const Color& UIImage::getColor() const { return mColor; } -void UIImage::setColor( const Color& col ) { +UIImage * UIImage::setColor( const Color& col ) { mColor = col; setAlpha( col.a ); + return this; } void UIImage::autoAlign() { diff --git a/src/eepp/ui/uilinearlayout.cpp b/src/eepp/ui/uilinearlayout.cpp index 598d5f50c..d6ff0e717 100644 --- a/src/eepp/ui/uilinearlayout.cpp +++ b/src/eepp/ui/uilinearlayout.cpp @@ -17,7 +17,8 @@ UILinearLayout * UILinearLayout::NewHorizontal() { UILinearLayout::UILinearLayout() : UIWidget(), - mOrientation( UI_VERTICAL ) + mOrientation( UI_VERTICAL ), + mAttrChangeReceive( true ) { setFlags( UI_CLIP_ENABLE ); } @@ -69,10 +70,12 @@ void UILinearLayout::pack() { void UILinearLayout::packVertical() { if ( getLayoutWidthRules() == MATCH_PARENT && 0 == mLayoutWeight ) { setInternalWidth( getParent()->getSize().getWidth() - mLayoutMargin.Left - mLayoutMargin.Right ); + sendCommonEvent( UIEvent::EventOnSizeChange ); } if ( getLayoutHeightRules() == MATCH_PARENT ) { setInternalHeight( getParent()->getSize().getHeight() - mLayoutMargin.Top - mLayoutMargin.Bottom ); + sendCommonEvent( UIEvent::EventOnSizeChange ); } UIControl * ChildLoop = mChild; @@ -101,6 +104,10 @@ void UILinearLayout::packVertical() { { } } + + if ( widget->getLayoutHeightRules() == MATCH_PARENT && widget->getSize().getHeight() != mSize.getHeight() ) { + //widget->setSize( widget->getSize().getWidth(), mSize.getHeight() ); + } } ChildLoop = ChildLoop->getNextControl(); @@ -154,6 +161,7 @@ void UILinearLayout::packVertical() { if ( getLayoutHeightRules() == WRAP_CONTENT ) { setInternalHeight( curY ); notifyLayoutAttrChangeParent(); + sendCommonEvent( UIEvent::EventOnSizeChange ); } else if ( getLayoutHeightRules() == MATCH_PARENT ) { setInternalHeight( getParent()->getSize().getHeight() - mLayoutMargin.Top - mLayoutMargin.Bottom ); } @@ -162,6 +170,7 @@ void UILinearLayout::packVertical() { setInternalWidth( maxX ); packVertical(); notifyLayoutAttrChangeParent(); + sendCommonEvent( UIEvent::EventOnSizeChange ); } alignAgainstLayout(); @@ -170,10 +179,12 @@ void UILinearLayout::packVertical() { void UILinearLayout::packHorizontal() { if ( getLayoutWidthRules() == MATCH_PARENT ) { setInternalWidth( getParent()->getSize().getWidth() - mLayoutMargin.Left - mLayoutMargin.Right ); + sendCommonEvent( UIEvent::EventOnSizeChange ); } if ( getLayoutHeightRules() == MATCH_PARENT && 0 == mLayoutWeight ) { setInternalHeight( getParent()->getSize().getHeight() - mLayoutMargin.Top - mLayoutMargin.Bottom ); + sendCommonEvent( UIEvent::EventOnSizeChange ); } UIControl * ChildLoop = mChild; @@ -202,6 +213,10 @@ void UILinearLayout::packHorizontal() { { } } + + if ( widget->getLayoutWidthRules() == MATCH_PARENT && widget->getSize().getWidth() != mSize.getWidth() ) { + //widget->setSize( mSize.getWidth(), widget->getSize().getWidth() ); + } } ChildLoop = ChildLoop->getNextControl(); @@ -255,14 +270,17 @@ void UILinearLayout::packHorizontal() { if ( getLayoutWidthRules() == WRAP_CONTENT ) { setInternalWidth( curX ); notifyLayoutAttrChangeParent(); + sendCommonEvent( UIEvent::EventOnSizeChange ); } else if ( getLayoutWidthRules() == MATCH_PARENT ) { setInternalWidth( getParent()->getSize().getWidth() - mLayoutMargin.Left - mLayoutMargin.Right ); + sendCommonEvent( UIEvent::EventOnSizeChange ); } if ( getLayoutHeightRules() == WRAP_CONTENT && mSize.getHeight() != maxY ) { setInternalHeight( maxY ); packHorizontal(); notifyLayoutAttrChangeParent(); + sendCommonEvent( UIEvent::EventOnSizeChange ); } alignAgainstLayout(); diff --git a/src/eepp/ui/uilistbox.cpp b/src/eepp/ui/uilistbox.cpp index 9559afd92..cf1fce01c 100644 --- a/src/eepp/ui/uilistbox.cpp +++ b/src/eepp/ui/uilistbox.cpp @@ -971,7 +971,7 @@ void UIListBox::setFontStyleConfig(const UIFontStyleConfig & fontStyleConfig) { } void UIListBox::loadFromXmlNode(const pugi::xml_node & node) { - UIWidget::loadFromXmlNode( node ); + UITouchDragableWidget::loadFromXmlNode( node ); std::vector items; for ( pugi::xml_node item = node.child("item"); item; item = item.next_sibling("item") ) { diff --git a/src/eepp/ui/uimanager.cpp b/src/eepp/ui/uimanager.cpp index 12597ffda..d12b0ce6e 100644 --- a/src/eepp/ui/uimanager.cpp +++ b/src/eepp/ui/uimanager.cpp @@ -355,7 +355,7 @@ void UIManager::checkTabPress( const Uint32& KeyCode ) { eeASSERT( NULL != mFocusControl ); if ( KeyCode == KEY_TAB ) { - UIControl * Ctrl = mFocusControl->getNextComplexControl(); + UIControl * Ctrl = mFocusControl->getNextWidget(); if ( NULL != Ctrl ) Ctrl->setFocus(); diff --git a/src/eepp/ui/uirelativelayout.cpp b/src/eepp/ui/uirelativelayout.cpp index 089b28d42..84ffc38cc 100644 --- a/src/eepp/ui/uirelativelayout.cpp +++ b/src/eepp/ui/uirelativelayout.cpp @@ -16,7 +16,7 @@ Uint32 UIRelativeLayout::getType() const { } bool UIRelativeLayout::isType( const Uint32& type ) const { - return UIWidget::getType() == type ? true : UIWidget::isType( type ); + return UIRelativeLayout::getType() == type ? true : UIWidget::isType( type ); } UIRelativeLayout * UIRelativeLayout::add(UIWidget * widget) { @@ -42,10 +42,12 @@ void UIRelativeLayout::fixChilds() { if ( getLayoutWidthRules() == MATCH_PARENT ) { setInternalWidth( getParent()->getSize().getWidth() - mLayoutMargin.Left - mLayoutMargin.Right ); + sendCommonEvent( UIEvent::EventOnSizeChange ); } if ( getLayoutHeightRules() == MATCH_PARENT ) { setInternalHeight( getParent()->getSize().getHeight() - mLayoutMargin.Top - mLayoutMargin.Bottom ); + sendCommonEvent( UIEvent::EventOnSizeChange ); } UIControl * child = mChild; diff --git a/src/eepp/ui/uiscrollview.cpp b/src/eepp/ui/uiscrollview.cpp index 336938a4e..d01b83bef 100644 --- a/src/eepp/ui/uiscrollview.cpp +++ b/src/eepp/ui/uiscrollview.cpp @@ -16,12 +16,15 @@ UIScrollView::UIScrollView() : mVScroll( UIScrollBar::New( UI_VERTICAL ) ), mHScroll( UIScrollBar::New( UI_HORIZONTAL ) ), mContainer( UIControlAnim::New() ), - mScrollView( NULL ) + mScrollView( NULL ), + mSizeChangeCb( 0 ) { + setFlags( UI_REPORT_SIZE_CHANGE_TO_CHILDS ); + mVScroll->setParent( this ); mHScroll->setParent( this ); mContainer->setParent( this ); - mContainer->setFlags( UI_CLIP_ENABLE ); + mContainer->setFlags( UI_CLIP_ENABLE | UI_REPORT_SIZE_CHANGE_TO_CHILDS ); mVScroll->addEventListener( UIEvent::EventOnValueChange, cb::Make1( this, &UIScrollView::onValueChangeCb ) ); mHScroll->addEventListener( UIEvent::EventOnValueChange, cb::Make1( this, &UIScrollView::onValueChangeCb ) ); @@ -66,11 +69,16 @@ void UIScrollView::onChildCountChange() { } if ( found ) { - if ( NULL != mScrollView ) + if ( NULL != mScrollView ) { + if ( 0 != mSizeChangeCb ) + mScrollView->removeEventListener( mSizeChangeCb ); + mScrollView->close(); + } child->setParent( mContainer ); mScrollView = child; + mSizeChangeCb = mScrollView->addEventListener( UIEvent::EventOnSizeChange, cb::Make1( this, &UIScrollView::onScrollViewSizeChange ) ); containerUpdate(); } @@ -186,6 +194,10 @@ void UIScrollView::onValueChangeCb( const UIEvent * Event ) { updateScroll(); } +void UIScrollView::onScrollViewSizeChange(const UIEvent * Event) { + containerUpdate(); +} + void UIScrollView::onTouchDragValueChange( Vector2f diff ) { if ( mVScroll->isEnabled() ) mVScroll->setValue( mVScroll->getValue() + ( -diff.y / (Float)( mScrollView->getSize().getHeight() ) ) ); @@ -200,7 +212,7 @@ bool UIScrollView::isTouchOverAllowedChilds() { } void UIScrollView::loadFromXmlNode( const pugi::xml_node& node ) { - UIWidget::loadFromXmlNode( node ); + UITouchDragableWidget::loadFromXmlNode( node ); for (pugi::xml_attribute_iterator ait = node.attributes_begin(); ait != node.attributes_end(); ++ait) { std::string name = ait->name(); diff --git a/src/eepp/ui/uitouchdragablewidget.cpp b/src/eepp/ui/uitouchdragablewidget.cpp index 10cd0f9b7..11cf4b5f4 100644 --- a/src/eepp/ui/uitouchdragablewidget.cpp +++ b/src/eepp/ui/uitouchdragablewidget.cpp @@ -1,5 +1,6 @@ #include #include +#include namespace EE { namespace UI { @@ -119,4 +120,19 @@ bool UITouchDragableWidget::isTouchOverAllowedChilds() { return isMouseOverMeOrChilds(); } +void UITouchDragableWidget::loadFromXmlNode(const pugi::xml_node & node) { + UIWidget::loadFromXmlNode( node ); + + for (pugi::xml_attribute_iterator ait = node.attributes_begin(); ait != node.attributes_end(); ++ait) { + std::string name = ait->name(); + String::toLowerInPlace( name ); + + if ( "touchdrag" == name ) { + setTouchDragEnabled( ait->as_bool() ); + } else if ( "touchdragdeceleration" == name ) { + setTouchDragDeceleration( Vector2f( ait->as_float(), ait->as_float() ) ); + } + } +} + }} diff --git a/src/eepp/ui/uiwidgetcreator.cpp b/src/eepp/ui/uiwidgetcreator.cpp index 0a3bc7e8c..13d0350e6 100644 --- a/src/eepp/ui/uiwidgetcreator.cpp +++ b/src/eepp/ui/uiwidgetcreator.cpp @@ -28,6 +28,7 @@ #include #include #include +#include namespace EE { namespace UI { @@ -69,6 +70,7 @@ UIWidget * UIWidgetCreator::createFromName( std::string widgetName ) { else if ( widgetName == "scrollview" ) return UIScrollView::New(); else if ( widgetName == "subtexture" ) return UISubTexture::New(); else if ( widgetName == "touchdragable" ) return UITouchDragableWidget::New(); + else if ( widgetName == "gridlayout" ) return UIGridLayout::New(); if ( widgetCallback.find( widgetName ) != widgetCallback.end() ) { return widgetCallback[ widgetName ].Call( widgetName ); diff --git a/src/test/eetest.cpp b/src/test/eetest.cpp index cc71c5944..c7ad02a60 100644 --- a/src/test/eetest.cpp +++ b/src/test/eetest.cpp @@ -749,6 +749,36 @@ void EETest::createNewUI() { " " "" ); + + /* + UIManager::instance()->loadLayoutFromString( + "" + " " + " " + " " + " " + " " + "" + ); + + UIGridLayout * gridLayout = NULL; + UIManager::instance()->getMainControl()->bind( "gridlayout", gridLayout ); + + if ( NULL != gridLayout ) { + std::vector textures = TextureFactory::instance()->getTextures(); + + if ( textures.size() > 0 ) { + for ( std::size_t i = 0; i < textures.size(); i++ ) { + UIImage::New()->setDrawable( textures[i] ) + ->setScaleType( UIScaleType::FitInside ) + ->setGravity( UI_HALIGN_CENTER | UI_VALIGN_CENTER ) + ->setEnabled( false ) + ->setParent( gridLayout )->setBackgroundFillEnabled( true ) + ->setColor( Color::fromPointer( textures[i] ) ); + } + } + } + */ } void EETest::createMapEditor() {