mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-08-13 04:42:12 +03:00
Added UIGridLayout.
Also some fixes for the UI layouts and ScrollView. --HG-- branch : dev
This commit is contained in:
@@ -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<Texture*> getTextures();
|
||||
|
||||
/** Set the texture enviroment
|
||||
* @param Param The texture param
|
||||
|
||||
@@ -225,7 +225,7 @@ class EE_API Color : public tColor<Uint8>
|
||||
/** 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 );
|
||||
|
||||
|
||||
@@ -53,6 +53,7 @@
|
||||
#include <eepp/ui/uirelativelayout.hpp>
|
||||
#include <eepp/ui/uiloader.hpp>
|
||||
#include <eepp/ui/uiscrollview.hpp>
|
||||
#include <eepp/ui/uigridlayout.hpp>
|
||||
#include <eepp/ui/tools/textureatlaseditor.hpp>
|
||||
|
||||
#include <eepp/ui/uithemedefault.hpp>
|
||||
|
||||
@@ -219,7 +219,7 @@ class EE_API UIControl {
|
||||
|
||||
Sizei getSkinSize();
|
||||
|
||||
UIControl * getNextComplexControl();
|
||||
UIControl * getNextWidget();
|
||||
|
||||
void applyDefaultTheme();
|
||||
|
||||
|
||||
82
include/eepp/ui/uigridlayout.hpp
Normal file
82
include/eepp/ui/uigridlayout.hpp
Normal file
@@ -0,0 +1,82 @@
|
||||
#ifndef EE_UI_UIGRIDLAYOUT
|
||||
#define EE_UI_UIGRIDLAYOUT
|
||||
|
||||
#include <eepp/ui/uiwidget.hpp>
|
||||
|
||||
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
|
||||
@@ -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
|
||||
};
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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 );
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -179,6 +179,19 @@ void TextureFactory::setCurrentTexture( const int& TexId, const Uint32& TextureU
|
||||
mCurrentTexture[ TextureUnit ] = TexId;
|
||||
}
|
||||
|
||||
std::vector<Texture*> TextureFactory::getTextures() {
|
||||
std::vector<Texture*> 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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
239
src/eepp/ui/uigridlayout.cpp
Normal file
239
src/eepp/ui/uigridlayout.cpp
Normal file
@@ -0,0 +1,239 @@
|
||||
#include <eepp/ui/uigridlayout.hpp>
|
||||
#include <eepp/helper/pugixml/pugixml.hpp>
|
||||
|
||||
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<UIWidget*>( 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() ) ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}}
|
||||
@@ -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() {
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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<String> items;
|
||||
for ( pugi::xml_node item = node.child("item"); item; item = item.next_sibling("item") ) {
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <eepp/ui/uitouchdragablewidget.hpp>
|
||||
#include <eepp/ui/uimanager.hpp>
|
||||
#include <eepp/helper/pugixml/pugixml.hpp>
|
||||
|
||||
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() ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <eepp/ui/uiscrollview.hpp>
|
||||
#include <eepp/ui/uiimage.hpp>
|
||||
#include <eepp/ui/uitouchdragablewidget.hpp>
|
||||
#include <eepp/ui/uigridlayout.hpp>
|
||||
|
||||
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 );
|
||||
|
||||
@@ -749,6 +749,36 @@ void EETest::createNewUI() {
|
||||
" </LinearLayout>"
|
||||
"</window>"
|
||||
);
|
||||
|
||||
/*
|
||||
UIManager::instance()->loadLayoutFromString(
|
||||
"<window layout_width='800dp' layout_height='600dp' winflags='default|maximize'>"
|
||||
" <LinearLayout layout_width='match_parent' layout_height='match_parent'>"
|
||||
" <ScrollView layout_width='match_parent' layout_height='match_parent' layout_weight='1' touchdrag='true'>"
|
||||
" <GridLayout columnMode='size' rowMode='size' columnWidth='200dp' rowHeight='200dp' layout_width='match_parent' layout_height='wrap_content' id='gridlayout' />"
|
||||
" </ScrollView>"
|
||||
" </LinearLayout>"
|
||||
"</window>"
|
||||
);
|
||||
|
||||
UIGridLayout * gridLayout = NULL;
|
||||
UIManager::instance()->getMainControl()->bind( "gridlayout", gridLayout );
|
||||
|
||||
if ( NULL != gridLayout ) {
|
||||
std::vector<Texture*> 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() {
|
||||
|
||||
Reference in New Issue
Block a user