Added support for skin fill color.

Added movement transition support for x and y properties.
Some fixes.

--HG--
branch : dev
This commit is contained in:
Martín Lucas Golini
2019-01-09 00:42:13 -03:00
parent fa57c2393e
commit b16f4b8421
13 changed files with 236 additions and 63 deletions

View File

@@ -68,17 +68,19 @@ Tooltip {
}
#tpad {
/* scale: 1;*/
/* rotation: 0;*/
borderWidth: 2dp;
/* borderColor: #66666666;*/
transition: scale 0.25s, rotation 0.25s 0.25s, borderColor 0.25;
borderColor: #66666666;
backgroundColor: #33FF3333;
backgroundCorners: 12;
transition: scale 0.25s, rotation 0.25s 0.25s, borderColor 0.25s, backgroundColor 0.25s;
}
#tpad:hover {
scale: 1.1;
rotation: -3;
backgroundColor: #FF333333;
borderColor: #99999999;
backgroundCorners: 12;
}
#tpad2 {
@@ -106,3 +108,11 @@ Tooltip {
width: 128dp;
height: 48dp;
}
#pbut {
transition: all 0.25s;
}
#pbut:hover {
skinColor: #66ff44;
}

View File

@@ -2,7 +2,7 @@
<TabWidget layout_width="match_parent" layout_height="match_parent" paddingLeft="8dp" paddingRight="8dp" paddingBottom="8dp" paddingTop="20dp" backgroundColor="#656565">
<hbox id="test_1" layout_width="match_parent" layout_height="match_parent">
<vbox id="lvbox" layout_width="match_parent" layout_weight="0.5" layout_height="match_parent" backgroundColor="#222" padding="12dp">
<TextView id="tpad" layout_width="wrap_content" layout_height="wrap_content" text="testing padding" textSize="24dp" padding="12dp" backgroundColor="#333" backgroundCorners="12" borderColor="#66666666" borderWidth="2dp" />
<TextView id="tpad" layout_width="wrap_content" layout_height="wrap_content" text="testing padding" textSize="24dp" padding="12dp" />
<TextView id="tpad2" layout_width="wrap_content" layout_height="wrap_content" layout_marginTop="8dp" text="testing padding" textSize="24dp" backgroundColor="#333" gravity="center" />
<CheckBox layout_width="wrap_content" layout_height="wrap_content" layout_marginTop="8dp" text="testing padding" textSize="24dp" padding="12dp" backgroundColor="#333" />
<RadioButton layout_width="wrap_content" layout_height="wrap_content" layout_marginTop="8dp" text="testing padding" textSize="24dp" padding="12dp" backgroundColor="#333" />
@@ -33,7 +33,7 @@
<TextureRegion layout_width="96dp" layout_height="96dp" src="bn01" padding="8dp" backgroundColor="#787" gravity="center" layout_marginTop="162dp" gravity="right|bottom" />
<PushButton layout_width="wrap_content" layout_height="wrap_content" text="testing padding" layout_gravity="bottom|right" gravity="center" padding="8dp" layout_to_top_of="tmp" />
<PushButton text="OK!" textSize="16dp" icon="ok" layout_gravity="left|bottom" gravity="center" layout_width="wrap_content" layout_height="wrap_content" layout_marginBottom="8dp" padding="8dp" layout_to_top_of="tm" />
<PushButton id="pbut" text="OK!" textSize="16dp" icon="ok" layout_gravity="left|bottom" gravity="center" layout_width="wrap_content" layout_height="wrap_content" layout_marginBottom="8dp" padding="8dp" layout_to_top_of="tm" />
<Slider id="slider" orientation="horizontal" halfslider="true" layout_width="200dp" layout_height="wrap_content" padding="32dp" background="#555" layout_to_bottom_of="el1" />

View File

@@ -2,6 +2,7 @@
#define EE_SCENE_ACTION_MOVE_HPP
#include <eepp/scene/action.hpp>
#include <eepp/scene/actions/actioninterpolation1d.hpp>
#include <eepp/scene/actions/actioninterpolation2d.hpp>
namespace EE { namespace Scene { namespace Actions {
@@ -23,6 +24,30 @@ class EE_API Move : public ActionInterpolation2d {
Move();
};
class EE_API MoveCoordinate : public ActionInterpolation1d {
public:
enum CoordinateType {
CoordinateX,
CoordinateY
};
static MoveCoordinate * New( const Float& start, const Float& end, const Time& duration, const Ease::Interpolation& type = Ease::Linear, const CoordinateType& coordinateType = CoordinateX );
Action * clone() const override;
Action * reverse() const override;
protected:
MoveCoordinate( const Float& start, const Float& end, const Time& duration, const Ease::Interpolation& type, const CoordinateType& coordinateType );
void onStart() override;
void onUpdate( const Time& time ) override;
private:
CoordinateType mCoordinateType;
MoveCoordinate();
};
}}}
#endif

View File

@@ -219,7 +219,7 @@ class EE_API Color : public tColor<Uint8>
Colorf toHsl();
std::string toHexString();
std::string toHexString() const;
static Color fromHsl( const Colorf& hsl );

View File

@@ -165,6 +165,14 @@ class EE_API UINode : public Node {
UINode * setSkin( UISkin * skin );
UINode * setSkinColor( const Uint32& state, const Color& color );
UINode * setSkinColor( const Color& color );
Color getSkinColor( const Uint32& state );
Color getSkinColor();
void removeSkin();
virtual void pushState( const Uint32& State, bool emitEvent = true );

View File

@@ -20,10 +20,20 @@ class EE_API UISkinState : public UIState {
void draw( const Float& X, const Float& Y, const Float& Width, const Float& Height, const Uint32& Alpha );
bool stateExists( const Uint32& State ) const;
void setStateColor( const Uint32& state, const Color& color );
Color getStateColor( const Uint32& state ) const;
bool hasStateColor( const Uint32& state ) const;
protected:
UISkin * mSkin;
std::map<Uint32,Color> mColors;
Color mCurrentColor;
void updateState();
void onStateChange();
};
}}

View File

@@ -26,9 +26,11 @@ const Uint8& Drawable::getAlpha() {
}
void Drawable::setColor(const Color & color) {
mColor = color;
onColorFilterChange();
onAlphaChange();
if ( mColor != color ) {
mColor = color;
onColorFilterChange();
onAlphaChange();
}
}
Color Drawable::getColor() const {

View File

@@ -15,12 +15,10 @@ Move::Move( const Vector2f & start, const Vector2f & end, const Time& duration,
}
void Move::onStart() {
if ( NULL != mNode ) {
mNode->setPosition( mInterpolation.getPosition() );
}
onUpdate( Time::Zero );
}
void Move::onUpdate( const Time& time ) {
void Move::onUpdate( const Time& ) {
if ( NULL != mNode ) {
mNode->setPosition( mInterpolation.getPosition() );
}
@@ -38,4 +36,42 @@ Action * Move::reverse() const {
return action;
}
MoveCoordinate * MoveCoordinate::New( const Float& start, const Float& end, const Time& duration, const Ease::Interpolation& type, const MoveCoordinate::CoordinateType& coordinateType ) {
return eeNew( MoveCoordinate, ( start, end, duration, type, coordinateType ) );
}
Action * MoveCoordinate::clone() const {
MoveCoordinate * action = eeNew( MoveCoordinate, () );
action->setInterpolation( mInterpolation );
return action;
}
Action * MoveCoordinate::reverse() const {
MoveCoordinate * action = eeNew( MoveCoordinate, () );
action->setInterpolation( Interpolation1d( mInterpolation.getReversePoints() ) );
return action;
}
MoveCoordinate::MoveCoordinate( const Float& start, const Float& end, const Time& duration, const Ease::Interpolation& type, const MoveCoordinate::CoordinateType& coordinateType ) :
mCoordinateType( coordinateType )
{
mInterpolation.clear().add( start, duration ).add( end ).setType( type );
}
void MoveCoordinate::onStart() {
onUpdate( Time::Zero );
}
void MoveCoordinate::onUpdate( const Time& ) {
if ( NULL != mNode ) {
if ( mCoordinateType == CoordinateX )
mNode->setPosition( mInterpolation.getPosition(), mNode->getPosition().y );
else if ( mCoordinateType == CoordinateY )
mNode->setPosition( mNode->getPosition().x, mInterpolation.getPosition() );
}
}
MoveCoordinate::MoveCoordinate()
{}
}}}

View File

@@ -148,14 +148,13 @@ void Tint::onUpdate( const Time& ) {
}
case Skin:
{
/*
widget->setSkinColor( widget->getStyleState(),
Color( mInterpolationR.getPosition(),
mInterpolationG.getPosition(),
mInterpolationB.getPosition(),
mInterpolateAlpha ? mInterpolationA.getPosition() : 255
) );
*/
break;
}
case Border:

View File

@@ -226,7 +226,7 @@ Colorf Color::toHsl() {
return hsl;
}
std::string Color::toHexString() {
std::string Color::toHexString() const {
std::stringstream stream;
stream << "#" << std::setfill ('0') << std::setw(sizeof(Color)*2) << std::hex << getValue();
return stream.str();

View File

@@ -408,15 +408,11 @@ UINode * UINode::setBackgroundColor( const Uint32 & state, const Color& color )
Drawable * stateDrawable = background->getStateDrawable( state );
if ( NULL == stateDrawable ) {
RectangleDrawable * colorDrawable = RectangleDrawable::New();
if ( NULL == stateDrawable )
setBackgroundDrawable( state, RectangleDrawable::New(), true );
colorDrawable->setColor( color );
setBackgroundDrawable( state, colorDrawable, true );
} else {
stateDrawable->setColor( color );
}
if ( NULL != mBackgroundState )
mBackgroundState->setStateColor( state, color );
return this;
}
@@ -426,17 +422,10 @@ Color UINode::getBackgroundColor() {
}
Color UINode::getBackgroundColor( const Uint32 & state ) {
UISkin * background = setBackgroundFillEnabled( true );
if ( NULL != mBackgroundState )
return mBackgroundState->getStateColor( state );
Drawable * stateDrawable = background->getStateDrawable( state );
if ( NULL == stateDrawable ) {
RectangleDrawable * colorDrawable = RectangleDrawable::New();
return colorDrawable->getColor();
} else {
return stateDrawable->getColor();
}
return Color::White;
}
UINode * UINode::setBackgroundColor( const Color& color ) {
@@ -493,17 +482,10 @@ Color UINode::getForegroundColor() {
}
Color UINode::getForegroundColor( const Uint32 & state ) {
UISkin * foreground = setForegroundFillEnabled( true );
if ( NULL != mForegroundState )
return mForegroundState->getStateColor( state );
Drawable * stateDrawable = foreground->getStateDrawable( state );
if ( NULL == stateDrawable ) {
RectangleDrawable * colorDrawable = RectangleDrawable::New();
return colorDrawable->getColor();
} else {
return stateDrawable->getColor();
}
return Color::White;
}
UINode * UINode::setForegroundColor( const Uint32 & state, const Color& color ) {
@@ -511,15 +493,11 @@ UINode * UINode::setForegroundColor( const Uint32 & state, const Color& color )
Drawable * stateDrawable = foreground->getStateDrawable( state );
if ( NULL == stateDrawable ) {
RectangleDrawable * colorDrawable = RectangleDrawable::New();
if ( NULL == stateDrawable )
setForegroundDrawable( state, RectangleDrawable::New(), true );
colorDrawable->setColor( color );
setForegroundDrawable( state, colorDrawable, true );
} else {
stateDrawable->setColor( color );
}
if ( NULL != mForegroundState )
mForegroundState->setStateColor( state, color );
return this;
}
@@ -763,6 +741,28 @@ UINode * UINode::setSkin( UISkin * skin ) {
return this;
}
UINode * UINode::setSkinColor( const Uint32& state, const Color& color ) {
if ( NULL != mSkinState )
mSkinState->setStateColor( state, color );
return this;
}
UINode * UINode::setSkinColor( const Color& color ) {
return setSkinColor( UIState::StateFlagNormal, color );
}
Color UINode::getSkinColor( const Uint32& state ) {
if ( NULL != mSkinState )
return mSkinState->getStateColor( state );
return Color::White;
}
Color UINode::getSkinColor() {
return getSkinColor( UIState::StateFlagNormal );
}
void UINode::removeSkin() {
if ( NULL != mSkinState && ( mNodeFlags & NODE_FLAG_SKIN_OWNER ) ) {
UISkin * tSkin = mSkinState->getSkin();

View File

@@ -8,7 +8,8 @@ UISkinState * UISkinState::New( UISkin * skin ) {
}
UISkinState::UISkinState( UISkin * Skin ) :
mSkin( Skin )
mSkin( Skin ),
mCurrentColor( Color::White )
{
eeASSERT( NULL != mSkin );
}
@@ -25,11 +26,37 @@ bool UISkinState::stateExists( const Uint32& State ) const {
return mSkin->hasDrawableState( State );
}
void UISkinState::setStateColor(const Uint32 & state, const Color & color) {
mColors[ state ] = color;
if ( mCurrentState == state )
mCurrentColor = color;
}
Color UISkinState::getStateColor( const Uint32& state ) const {
auto it = mColors.find( state );
if ( it != mColors.end() )
return it->second;
return mSkin->getColor();
}
bool UISkinState::hasStateColor(const Uint32 & state) const {
return mColors.find( state ) != mColors.end();
}
void UISkinState::draw( const Float& X, const Float& Y, const Float& Width, const Float& Height, const Uint32& Alpha ) {
if ( NULL != mSkin ) {
Color color = mSkin->getColor();
mSkin->setState( mCurrentState );
mSkin->setAlpha( Alpha );
mSkin->setColor( mCurrentColor );
if ( Alpha != 255 )
mSkin->setAlpha( Alpha * mCurrentColor.a / 255 );
mSkin->draw( Vector2f( X, Y ), Sizef( Width, Height ) );
mSkin->setColor( color );
}
}
@@ -54,4 +81,8 @@ void UISkinState::updateState() {
}
}
void UISkinState::onStateChange() {
mCurrentColor = getStateColor( mCurrentState );
}
}}

View File

@@ -601,9 +601,45 @@ bool UIWidget::setAttribute( const NodeAttribute& attribute, const Uint32& state
if ( "id" == name ) {
setId( attribute.value() );
} else if ( "x" == name ) {
setInternalPosition( Vector2f( attribute.asDpDimension(), mDpPos.y ) );
setLayoutWidthRules( FIXED );
Float newX = attribute.asDpDimensionI();
if ( !isSceneNodeLoading() && NULL != mStyle && mStyle->hasTransition( state, attribute.getName() ) ) {
UIStyle::TransitionInfo transitionInfo( mStyle->getTransition( state, attribute.getName() ) );
SAVE_NORMAL_STATE_ATTR( String::strFormated( "%.2f", mDpSize.getWidth() ) );
Action * action = Actions::MoveCoordinate::New( getPosition().x, newX, transitionInfo.duration, transitionInfo.timingFunction, Actions::MoveCoordinate::CoordinateX );
if ( Time::Zero != transitionInfo.delay )
action = Actions::Sequence::New( Actions::Delay::New( transitionInfo.delay ), action );
runAction( action );
} else {
setInternalPosition( Vector2f( newX, mDpPos.y ) );
notifyLayoutAttrChange();
}
} else if ( "y" == name ) {
setInternalPosition( Vector2f( mDpPos.x, attribute.asDpDimension() ) );
setLayoutWidthRules( FIXED );
Float newY = attribute.asDpDimensionI();
if ( !isSceneNodeLoading() && NULL != mStyle && mStyle->hasTransition( state, attribute.getName() ) ) {
UIStyle::TransitionInfo transitionInfo( mStyle->getTransition( state, attribute.getName() ) );
SAVE_NORMAL_STATE_ATTR( String::strFormated( "%.2f", mDpSize.getWidth() ) );
Action * action = Actions::MoveCoordinate::New( getPosition().y, newY, transitionInfo.duration, transitionInfo.timingFunction, Actions::MoveCoordinate::CoordinateY );
if ( Time::Zero != transitionInfo.delay )
action = Actions::Sequence::New( Actions::Delay::New( transitionInfo.delay ), action );
runAction( action );
} else {
setInternalPosition( Vector2f( mDpPos.x, newY ) );
notifyLayoutAttrChange();
}
} else if ( "width" == name ) {
setLayoutWidthRules( FIXED );
@@ -611,11 +647,10 @@ bool UIWidget::setAttribute( const NodeAttribute& attribute, const Uint32& state
if ( !isSceneNodeLoading() && NULL != mStyle && mStyle->hasTransition( state, attribute.getName() ) ) {
UIStyle::TransitionInfo transitionInfo( mStyle->getTransition( state, attribute.getName() ) );
Float start( getSize().getWidth() );
SAVE_NORMAL_STATE_ATTR( String::strFormated( "%.2f", mDpSize.getWidth() ) );
Action * action = Actions::ResizeWidth::New( start, newWidth, transitionInfo.duration, transitionInfo.timingFunction );
Action * action = Actions::ResizeWidth::New( getSize().getWidth(), newWidth, transitionInfo.duration, transitionInfo.timingFunction );
if ( Time::Zero != transitionInfo.delay )
action = Actions::Sequence::New( Actions::Delay::New( transitionInfo.delay ), action );
@@ -632,11 +667,10 @@ bool UIWidget::setAttribute( const NodeAttribute& attribute, const Uint32& state
if ( !isSceneNodeLoading() && NULL != mStyle && mStyle->hasTransition( state, attribute.getName() ) ) {
UIStyle::TransitionInfo transitionInfo( mStyle->getTransition( state, attribute.getName() ) );
Float start( getSize().getHeight() );
SAVE_NORMAL_STATE_ATTR( String::strFormated( "%.2f", mDpSize.getHeight() ) );
Action * action = Actions::ResizeHeight::New( start, newHeight, transitionInfo.duration, transitionInfo.timingFunction );
Action * action = Actions::ResizeHeight::New( getSize().getHeight(), newHeight, transitionInfo.duration, transitionInfo.timingFunction );
if ( Time::Zero != transitionInfo.delay )
action = Actions::Sequence::New( Actions::Delay::New( transitionInfo.delay ), action );
@@ -663,7 +697,7 @@ bool UIWidget::setAttribute( const NodeAttribute& attribute, const Uint32& state
UIStyle::TransitionInfo transitionInfo( mStyle->getTransition( state, attribute.getName() ) );
Color start( getBackgroundColor( getStylePreviousState() ) );
Action * action = Actions::Tint::New( start, color, false, transitionInfo.duration, transitionInfo.timingFunction, Actions::Tint::Background );
Action * action = Actions::Tint::New( start, color, true, transitionInfo.duration, transitionInfo.timingFunction, Actions::Tint::Background );
if ( Time::Zero != transitionInfo.delay )
action = Actions::Sequence::New( Actions::Delay::New( transitionInfo.delay ), action );
@@ -689,7 +723,7 @@ bool UIWidget::setAttribute( const NodeAttribute& attribute, const Uint32& state
UIStyle::TransitionInfo transitionInfo( mStyle->getTransition( state, attribute.getName() ) );
Color start( getForegroundColor( getStylePreviousState() ) );
Action * action = Actions::Tint::New( start, color, false, transitionInfo.duration, transitionInfo.timingFunction, Actions::Tint::Foreground );
Action * action = Actions::Tint::New( start, color, true, transitionInfo.duration, transitionInfo.timingFunction, Actions::Tint::Foreground );
if ( Time::Zero != transitionInfo.delay )
action = Actions::Sequence::New( Actions::Delay::New( transitionInfo.delay ), action );
@@ -734,6 +768,24 @@ bool UIWidget::setAttribute( const NodeAttribute& attribute, const Uint32& state
} else if ( "skin" == name ) {
mSkinName = attribute.asString();
setThemeSkin( mSkinName );
} else if ( "skincolor" == name ) {
Color color = attribute.asColor();
if ( !isSceneNodeLoading() && NULL != mStyle && mStyle->hasTransition( state, attribute.getName() ) ) {
UIStyle::TransitionInfo transitionInfo( mStyle->getTransition( state, attribute.getName() ) );
Color start( getSkinColor( getStylePreviousState() ) );
SAVE_NORMAL_STATE_ATTR( start.toHexString() )
Action * action = Actions::Tint::New( start, color, true, transitionInfo.duration, transitionInfo.timingFunction, Actions::Tint::Skin );
if ( Time::Zero != transitionInfo.delay )
action = Actions::Sequence::New( Actions::Delay::New( transitionInfo.delay ), action );
runAction( action );
} else {
setSkinColor( state, color );
}
} else if ( "gravity" == name ) {
std::string gravity = attribute.asString();
String::toLowerInPlace( gravity );