mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-08-18 06:55:48 +03:00
Basic css linear-gradient support.
--HG-- branch : dev
This commit is contained in:
@@ -76,6 +76,7 @@ Tooltip {
|
||||
borderWidth: 2dp;
|
||||
borderColor: #66666666;
|
||||
backgroundColor: #33FF3333;
|
||||
backgroundImage: linear-gradient( #8c8886, #585857 );
|
||||
borderRadius: 12;
|
||||
transition: scale 0.25s, rotation 0.25s 0.25s, borderColor 0.25s, backgroundColor 0.25s, borderRadius 0.25s;
|
||||
}
|
||||
@@ -104,6 +105,26 @@ Tooltip {
|
||||
backgroundColor: #656;
|
||||
}
|
||||
|
||||
#tpad3 {
|
||||
borderWidth: 2dp;
|
||||
borderColor: #1e2021d7;
|
||||
backgroundImage: linear-gradient( #797a79, #585857 );
|
||||
borderRadius: 3;
|
||||
padding: 12dp;
|
||||
transition: all 0.25;
|
||||
}
|
||||
|
||||
#tpad3:hover {
|
||||
backgroundImage: linear-gradient( #9c9d9b, #5b5b5a );
|
||||
borderColor: #1d1f1fd7;
|
||||
borderRadius: 3;
|
||||
}
|
||||
|
||||
#tpad3:pressed {
|
||||
backgroundImage: linear-gradient( #4e4f4d, #414141 );
|
||||
borderColor: #222320d7;
|
||||
}
|
||||
|
||||
#tres {
|
||||
/* width: 32dp;
|
||||
height: 32dp;*/
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
<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" />
|
||||
<TextView id="tpad2" layout_width="wrap_content" layout_height="wrap_content" text="testing padding" textSize="24dp" backgroundColor="#333" gravity="center" />
|
||||
<TextView id="tpad3" layout_width="wrap_content" layout_height="wrap_content" text="testing things" />
|
||||
<CheckBox layout_width="wrap_content" layout_height="wrap_content" text="testing padding" textSize="24dp" padding="12dp" backgroundColor="#333" />
|
||||
<RadioButton layout_width="wrap_content" layout_height="wrap_content" text="testing padding" textSize="24dp" padding="12dp" backgroundColor="#333" />
|
||||
<TextInput layout_width="300dp" layout_height="wrap_content" text="testing padding" textSize="24dp" padding="24dp" />
|
||||
|
||||
@@ -44,9 +44,9 @@ class EE_API StateListDrawable : public StatefulDrawable {
|
||||
|
||||
virtual Uint8 getStateAlpha( const Uint32& state );
|
||||
|
||||
bool hasDrawableState( Uint32 state );
|
||||
bool hasDrawableState(const Uint32 & state ) const;
|
||||
|
||||
bool hasDrawableStateColor( Uint32 state );
|
||||
bool hasDrawableStateColor(const Uint32 & state ) const;
|
||||
|
||||
void clearDrawables();
|
||||
protected:
|
||||
|
||||
@@ -37,8 +37,7 @@ class NodeAttribute {
|
||||
TypeRectf
|
||||
};
|
||||
|
||||
class Info
|
||||
{
|
||||
class Info {
|
||||
public:
|
||||
Info( AttributeType type, const std::string& name );
|
||||
|
||||
@@ -55,6 +54,23 @@ class NodeAttribute {
|
||||
std::vector<std::string> names;
|
||||
};
|
||||
|
||||
class FunctionType {
|
||||
public:
|
||||
static FunctionType parse( const std::string& function );
|
||||
|
||||
FunctionType( const std::string& name, const std::vector<std::string>& parameters );
|
||||
|
||||
const std::string& getName() const;
|
||||
|
||||
const std::vector<std::string> getParameters() const;
|
||||
|
||||
bool isEmpty() const;
|
||||
protected:
|
||||
std::string name;
|
||||
|
||||
std::vector<std::string> parameters;
|
||||
};
|
||||
|
||||
NodeAttribute();
|
||||
|
||||
NodeAttribute( std::string name, std::string value );
|
||||
|
||||
@@ -235,6 +235,8 @@ class EE_API Color : public tColor<Uint8>
|
||||
|
||||
static Color fromString( std::string str );
|
||||
|
||||
static bool isColorString( std::string str );
|
||||
|
||||
static const Color Transparent;
|
||||
static const Color White;
|
||||
static const Color Black;
|
||||
@@ -276,8 +278,29 @@ public:
|
||||
Color toColor();
|
||||
};
|
||||
|
||||
class RectColors {
|
||||
class EE_API RectColors {
|
||||
public:
|
||||
RectColors() :
|
||||
TopLeft( Color::White ),
|
||||
TopRight( Color::White ),
|
||||
BottomLeft( Color::White ),
|
||||
BottomRight( Color::White )
|
||||
{}
|
||||
|
||||
RectColors( const Color& color ) :
|
||||
TopLeft( color ),
|
||||
TopRight( color ),
|
||||
BottomLeft( color ),
|
||||
BottomRight( color )
|
||||
{}
|
||||
|
||||
RectColors( const Color& topLeft, const Color& topRight, const Color& bottomLeft, const Color& bottomRight ) :
|
||||
TopLeft( topLeft ),
|
||||
TopRight( topRight ),
|
||||
BottomLeft( bottomLeft ),
|
||||
BottomRight( bottomRight )
|
||||
{}
|
||||
|
||||
Color TopLeft;
|
||||
Color TopRight;
|
||||
Color BottomLeft;
|
||||
|
||||
@@ -108,6 +108,15 @@ Drawable * StateListDrawable::getStateDrawable( const Uint32& state ) {
|
||||
|
||||
StateListDrawable * StateListDrawable::setStateDrawable( const Uint32 & state, Drawable * drawable, bool ownIt ) {
|
||||
if ( NULL != drawable ) {
|
||||
if ( hasDrawableState( state ) && mDrawablesOwnership[ mDrawables[ state ] ] ) {
|
||||
|
||||
if ( mCurrentDrawable == mDrawables[ state ] )
|
||||
mCurrentDrawable = NULL;
|
||||
|
||||
mDrawablesOwnership.erase( mDrawables[ state ] );
|
||||
eeDelete( mDrawables[ state ] );
|
||||
}
|
||||
|
||||
mDrawables[ state ] = drawable;
|
||||
mDrawablesOwnership[ drawable ] = ownIt;
|
||||
|
||||
@@ -159,11 +168,11 @@ Uint8 StateListDrawable::getStateAlpha( const Uint32& state ) {
|
||||
return 255;
|
||||
}
|
||||
|
||||
bool StateListDrawable::hasDrawableState(Uint32 state ) {
|
||||
bool StateListDrawable::hasDrawableState( const Uint32& state ) const {
|
||||
return mDrawables.find( state ) != mDrawables.end();
|
||||
}
|
||||
|
||||
bool StateListDrawable::hasDrawableStateColor(Uint32 state ) {
|
||||
bool StateListDrawable::hasDrawableStateColor( const Uint32& state ) const {
|
||||
return mDrawableColors.find( state ) != mDrawableColors.end();
|
||||
}
|
||||
|
||||
|
||||
@@ -321,4 +321,81 @@ Ease::Interpolation NodeAttribute::asInterpolation( const Ease::Interpolation& d
|
||||
return Ease::fromName( mValue, defaultInterpolation );
|
||||
}
|
||||
|
||||
NodeAttribute::FunctionType NodeAttribute::FunctionType::parse( const std::string& function ) {
|
||||
size_t posFuncStart = function.find_first_of( '(' );
|
||||
size_t posFuncEnd = function.find_last_of( ')' );
|
||||
std::string funcName;
|
||||
std::vector<std::string> parameters;
|
||||
|
||||
if ( std::string::npos != posFuncStart && std::string::npos != posFuncEnd && posFuncStart > 1 && posFuncStart + 1 < function.size() ) {
|
||||
funcName = function.substr( 0, posFuncStart );
|
||||
|
||||
if ( !funcName.empty() ) {
|
||||
std::string funcParameters = function.substr( posFuncStart + 1, posFuncEnd - posFuncStart - 1 );
|
||||
std::string curParameter = "";
|
||||
bool parsingString = false;
|
||||
bool lastWasBackslash = false;
|
||||
|
||||
funcParameters = String::trim( funcParameters );
|
||||
|
||||
for ( size_t i = 0; i < funcParameters.size(); i++ ) {
|
||||
const char& curChar = funcParameters.at(i);
|
||||
|
||||
if ( !parsingString ) {
|
||||
if ( ',' == curChar ) {
|
||||
curParameter = String::trim( curParameter );
|
||||
|
||||
if ( !curParameter.empty() ) {
|
||||
parameters.push_back( curParameter );
|
||||
curParameter = "";
|
||||
}
|
||||
} else if ( '"' == curChar ) {
|
||||
parsingString = true;
|
||||
} else {
|
||||
curParameter += curChar;
|
||||
}
|
||||
} else {
|
||||
if ( '"' == curChar && !lastWasBackslash ) {
|
||||
parsingString = false;
|
||||
|
||||
if ( !curParameter.empty() ) {
|
||||
parameters.push_back( curParameter );
|
||||
curParameter = "";
|
||||
}
|
||||
} else {
|
||||
if ( '\\' == curChar )
|
||||
lastWasBackslash = !lastWasBackslash;
|
||||
|
||||
curParameter += curChar;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
curParameter = String::trim( curParameter );
|
||||
|
||||
if ( !curParameter.empty() )
|
||||
parameters.push_back( curParameter );
|
||||
}
|
||||
}
|
||||
|
||||
return NodeAttribute::FunctionType( funcName, parameters );
|
||||
}
|
||||
|
||||
NodeAttribute::FunctionType::FunctionType( const std::string& name, const std::vector<std::string>& parameters ) :
|
||||
name( name ),
|
||||
parameters( parameters )
|
||||
{}
|
||||
|
||||
const std::string& NodeAttribute::FunctionType::getName() const {
|
||||
return name;
|
||||
}
|
||||
|
||||
const std::vector<std::string> NodeAttribute::FunctionType::getParameters() const {
|
||||
return parameters;
|
||||
}
|
||||
|
||||
bool NodeAttribute::FunctionType::isEmpty() const {
|
||||
return name.empty();
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
@@ -316,7 +316,7 @@ Color Color::fromString( std::string str ) {
|
||||
else if ( "maroon" == str ) return Color::Maroon;
|
||||
else if ( "olive" == str ) return Color::Olive;
|
||||
else if ( "officegreen" == str ) return Color::OfficeGreen;
|
||||
else if ( "purple" == str ) return Color::Purple;
|
||||
else if ( "purple" == str ) return Color::Purple;
|
||||
else if ( "teal" == str ) return Color::Teal;
|
||||
else if ( "navy" == str ) return Color::Navy;
|
||||
}
|
||||
@@ -334,4 +334,33 @@ Color Color::fromString( std::string str ) {
|
||||
return Color( std::strtoul( str.c_str(), NULL, 16 ) );
|
||||
}
|
||||
|
||||
bool Color::isColorString( std::string str ) {
|
||||
if ( str.empty() )
|
||||
return false;
|
||||
|
||||
if ( str[0] == '#' )
|
||||
return true;
|
||||
|
||||
String::toLowerInPlace( str );
|
||||
if ( "transparent" == str ) return true;
|
||||
else if ( "white" == str ) return true;
|
||||
else if ( "black" == str ) return true;
|
||||
else if ( "red" == str ) return true;
|
||||
else if ( "green" == str ) return true;
|
||||
else if ( "blue" == str ) return true;
|
||||
else if ( "yellow" == str ) return true;
|
||||
else if ( "cyan" == str ) return true;
|
||||
else if ( "magenta" == str ) return true;
|
||||
else if ( "silver" == str ) return true;
|
||||
else if ( "gray" == str ) return true;
|
||||
else if ( "maroon" == str ) return true;
|
||||
else if ( "olive" == str ) return true;
|
||||
else if ( "officegreen" == str ) return true;
|
||||
else if ( "purple" == str ) return true;
|
||||
else if ( "teal" == str ) return true;
|
||||
else if ( "navy" == str ) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <eepp/ui/uistyle.hpp>
|
||||
#include <eepp/ui/uitooltip.hpp>
|
||||
#include <eepp/graphics/drawablesearcher.hpp>
|
||||
#include <eepp/graphics/rectangledrawable.hpp>
|
||||
#include <eepp/ui/uiscenenode.hpp>
|
||||
#include <eepp/scene/actions/actions.hpp>
|
||||
#include <pugixml/pugixml.hpp>
|
||||
@@ -720,6 +721,46 @@ bool UIWidget::setAttribute( const NodeAttribute& attribute, const Uint32& state
|
||||
} else {
|
||||
setBackgroundColor( state, color );
|
||||
}
|
||||
} else if ( "backgroundimage" == name ) {
|
||||
NodeAttribute::FunctionType functionType = NodeAttribute::FunctionType::parse( attribute.getValue() );
|
||||
|
||||
if ( !functionType.isEmpty() ) {
|
||||
if ( functionType.getName() == "linear-gradient" && functionType.getParameters().size() >= 2 ) {
|
||||
RectangleDrawable * drawable = RectangleDrawable::New();
|
||||
RectColors rectColors;
|
||||
|
||||
if ( Color::isColorString( functionType.getParameters().at(0) ) ) {
|
||||
rectColors.TopLeft = rectColors.TopRight = Color::fromString( functionType.getParameters().at(0) );
|
||||
rectColors.BottomLeft = rectColors.BottomRight = Color::fromString( functionType.getParameters().at(1) );
|
||||
} else if ( functionType.getParameters().size() >= 3 ) {
|
||||
std::string direction = functionType.getParameters().at(0);
|
||||
String::toLowerInPlace( direction );
|
||||
|
||||
if ( direction == "to bottom" ) {
|
||||
rectColors.TopLeft = rectColors.TopRight = Color::fromString( functionType.getParameters().at(1) );
|
||||
rectColors.BottomLeft = rectColors.BottomRight = Color::fromString( functionType.getParameters().at(2) );
|
||||
} else if ( direction == "to left" ) {
|
||||
rectColors.TopLeft = rectColors.BottomLeft = Color::fromString( functionType.getParameters().at(2) );
|
||||
rectColors.TopRight = rectColors.BottomRight = Color::fromString( functionType.getParameters().at(1) );
|
||||
} else if ( direction == "to right" ) {
|
||||
rectColors.TopLeft = rectColors.BottomLeft = Color::fromString( functionType.getParameters().at(1) );
|
||||
rectColors.TopRight = rectColors.BottomRight = Color::fromString( functionType.getParameters().at(2) );
|
||||
} else if ( direction == "to top" ) {
|
||||
rectColors.TopLeft = rectColors.TopRight = Color::fromString( functionType.getParameters().at(2) );
|
||||
rectColors.BottomLeft = rectColors.BottomRight = Color::fromString( functionType.getParameters().at(1) );
|
||||
} else {
|
||||
rectColors.TopLeft = rectColors.TopRight = Color::fromString( functionType.getParameters().at(1) );
|
||||
rectColors.BottomLeft = rectColors.BottomRight = Color::fromString( functionType.getParameters().at(2) );
|
||||
}
|
||||
} else {
|
||||
return setAttribute( "backgroundcolor", functionType.getParameters().at(0) );
|
||||
}
|
||||
|
||||
drawable->setRectColors( rectColors );
|
||||
|
||||
setBackgroundDrawable( state, drawable, true );
|
||||
}
|
||||
}
|
||||
} else if ( "foreground" == name ) {
|
||||
Drawable * res = NULL;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user