CSS support WIP.

--HG--
branch : dev
This commit is contained in:
Martín Lucas Golini
2018-12-29 20:27:31 -03:00
parent cfcc01ad8b
commit 8094b26310
89 changed files with 530 additions and 189 deletions

View File

@@ -0,0 +1,12 @@
PushButton {
foregroundColor: #66666666;
}
PushButton:hover {
foregroundColor: #66FF6666;
}
PushButton:pressed {
foregroundColor: #FF666666;
}

View File

@@ -47,7 +47,15 @@
#include <eepp/ui/tools/textureatlaseditor.hpp>
#include <eepp/ui/uithemedefault.hpp>
#include <eepp/ui/uiwidgetcreator.hpp>
#include <eepp/ui/css/stylesheet.hpp>
#include <eepp/ui/css/stylesheetelement.hpp>
#include <eepp/ui/css/stylesheetnode.hpp>
#include <eepp/ui/css/stylesheetparser.hpp>
#include <eepp/ui/css/stylesheetselector.hpp>
#include <eepp/ui/css/stylesheetproperty.hpp>
#include <eepp/ui/css/stylesheetselectorparser.hpp>
#include <eepp/ui/css/stylesheetpropertiesparser.hpp>
#endif

View File

@@ -5,13 +5,17 @@
namespace EE { namespace UI { namespace CSS {
class StyleSheet {
class StyleSheetElement;
class EE_API StyleSheet {
public:
StyleSheet();
void addNode( StyleSheetNode node );
StyleSheetProperties find( const std::string& tagName = "", const std::string& id = "", const std::vector<std::string>& classes = {}, const std::string& pseudoClass = "" );
bool isEmpty() const;
StyleSheetProperties getElementProperties( StyleSheetElement * element, const std::string& pseudoClass = "" );
std::vector<StyleSheetNode> nodes;
};

View File

@@ -3,16 +3,17 @@
#include <string>
#include <vector>
#include <eepp/config.hpp>
namespace EE { namespace UI { namespace CSS {
class StyleSheetElement {
class EE_API StyleSheetElement {
public:
virtual std::string getStyleSheetTag() const = 0;
virtual const std::string& getStyleSheetTag() const = 0;
virtual const std::string& getStyleSheetId() const;
virtual const std::string& getStyleSheetId() const = 0;
virtual const std::vector<std::string>& getStyleSheetClasses() = 0;
virtual const std::vector<std::string>& getStyleSheetClasses() const = 0;
virtual StyleSheetElement * getStyleSheetParentElement() = 0;
};

View File

@@ -6,7 +6,7 @@
namespace EE { namespace UI { namespace CSS {
class StyleSheetNode {
class EE_API StyleSheetNode {
public:
explicit StyleSheetNode( const std::string& selector, const StyleSheetProperties& properties );

View File

@@ -13,9 +13,13 @@
using namespace EE;
using namespace EE::System;
namespace EE { namespace System {
class Pack;
}}
namespace EE { namespace UI { namespace CSS {
class StyleSheetParser {
class EE_API StyleSheetParser {
public:
StyleSheetParser();
@@ -23,6 +27,10 @@ class StyleSheetParser {
bool loadFromFile( const std::string& file );
bool loadFromMemory( const Uint8* RAWData, const Uint32& size );
bool loadFromPack( Pack * pack, std::string filePackPath );
void print();
StyleSheet& getStyleSheet();

View File

@@ -8,7 +8,7 @@
namespace EE { namespace UI { namespace CSS {
class StyleSheetPropertiesParser {
class EE_API StyleSheetPropertiesParser {
public:
StyleSheetPropertiesParser();

View File

@@ -3,10 +3,11 @@
#include <string>
#include <map>
#include <eepp/config.hpp>
namespace EE { namespace UI { namespace CSS {
class StyleSheetProperty {
class EE_API StyleSheetProperty {
public:
StyleSheetProperty();
@@ -14,6 +15,7 @@ class StyleSheetProperty {
std::string name;
std::string value;
Uint32 specificity;
};
typedef std::map<std::string, StyleSheetProperty> StyleSheetProperties;

View File

@@ -5,7 +5,7 @@
namespace EE { namespace UI { namespace CSS {
class StyleSheetSelector {
class EE_API StyleSheetSelector {
public:
enum SelectorType {
TagName = 1 << 0,
@@ -18,7 +18,7 @@ class StyleSheetSelector {
SpecificityId = 1000000,
SpecificityClass = 100000,
SpecificityTag = 10000,
SpecificityPseudoClass = 0
SpecificityPseudoClass = 100
};
explicit StyleSheetSelector( const std::string& selectorName );

View File

@@ -5,7 +5,7 @@
namespace EE { namespace UI { namespace CSS {
class StyleSheetSelectorParser {
class EE_API StyleSheetSelectorParser {
public:
StyleSheetSelectorParser();

View File

@@ -32,7 +32,7 @@ class EE_API UICheckBox : public UITextView {
void setTextSeparation(const Int32 & textSeparation);
virtual bool setAttribute( const NodeAttribute& attribute );
virtual bool setAttribute( const NodeAttribute& attribute, const Uint32& state = UIState::StateFlagNormal );
protected:
UINode * mActiveButton;
UINode * mInactiveButton;

View File

@@ -36,7 +36,7 @@ class EE_API UIDropDownList : public UITextInput {
void setStyleConfig(const UIDropDownListStyleConfig & styleConfig);
virtual bool setAttribute( const NodeAttribute& attribute );
virtual bool setAttribute( const NodeAttribute& attribute, const Uint32& state = UIState::StateFlagNormal );
virtual void loadFromXmlNode(const pugi::xml_node & node);
protected:

View File

@@ -49,7 +49,7 @@ class EE_API UIGridLayout : public UILayout {
UIGridLayout * setRowWeight(const Float & rowWeight);
virtual bool setAttribute( const NodeAttribute& attribute );
virtual bool setAttribute( const NodeAttribute& attribute, const Uint32& state = UIState::StateFlagNormal );
protected:
Sizei mSpan;
ElementMode mColumnMode;

View File

@@ -31,7 +31,7 @@ class EE_API UIImage : public UIWidget {
const Vector2f& getAlignOffset() const;
virtual bool setAttribute( const NodeAttribute& attribute );
virtual bool setAttribute( const NodeAttribute& attribute, const Uint32& state = UIState::StateFlagNormal );
Uint32 getScaleType() const;

View File

@@ -14,6 +14,9 @@ class EE_API UILayout : public UIWidget {
virtual Uint32 getType() const;
virtual bool isType( const Uint32& type ) const;
protected:
UILayout( const std::string& tag );
};
}}

View File

@@ -25,7 +25,7 @@ class EE_API UILinearLayout : public UILayout {
UILinearLayout * add( UIWidget * widget );
virtual bool setAttribute( const NodeAttribute& attribute );
virtual bool setAttribute( const NodeAttribute& attribute, const Uint32& state = UIState::StateFlagNormal );
protected:
UI_ORIENTATION mOrientation;

View File

@@ -113,7 +113,7 @@ class EE_API UIListBox : public UITouchDragableWidget {
void loadItemsFromXmlNode(const pugi::xml_node & node);
virtual bool setAttribute( const NodeAttribute& attribute );
virtual bool setAttribute( const NodeAttribute& attribute, const Uint32& state = UIState::StateFlagNormal );
protected:
friend class UIListBoxItem;
friend class UIItemContainer<UIListBox>;

View File

@@ -49,7 +49,7 @@ class EE_API UILoader : public UIWidget {
UILoader * setAnimationSpeed( const Float& animationSpeed );
virtual bool setAttribute( const NodeAttribute& attribute );
virtual bool setAttribute( const NodeAttribute& attribute, const Uint32& state = UIState::StateFlagNormal );
Float getArcStartAngle() const;

View File

@@ -19,6 +19,8 @@ class EE_API UIMenuItem : public UIPushButton {
virtual void setTheme( UITheme * Theme );
protected:
UIMenuItem( const std::string& tag );
virtual Uint32 onMouseEnter( const Vector2i &position, const Uint32 flags );
virtual void onStateChange();

View File

@@ -159,9 +159,9 @@ class EE_API UINode : public Node {
void removeSkin();
void pushState( const Uint32& State, bool emitEvent = true );
virtual void pushState( const Uint32& State, bool emitEvent = true );
void popState( const Uint32& State, bool emitEvent = true );
virtual void popState( const Uint32& State, bool emitEvent = true );
Sizef getSkinSize();

View File

@@ -51,7 +51,7 @@ class EE_API UIProgressBar : public UIWidget {
UITextView * getTextBox() const;
virtual bool setAttribute( const NodeAttribute& attribute );
virtual bool setAttribute( const NodeAttribute& attribute, const Uint32& state = UIState::StateFlagNormal );
protected:
UIProgressBarStyleConfig mStyleConfig;
Float mProgress;

View File

@@ -71,12 +71,14 @@ class EE_API UIPushButton : public UIWidget {
void setStyleConfig(const UIPushButtonStyleConfig & styleConfig);
virtual bool setAttribute( const NodeAttribute& attribute );
virtual bool setAttribute( const NodeAttribute& attribute, const Uint32& state = UIState::StateFlagNormal );
protected:
UIPushButtonStyleConfig mStyleConfig;
UIImage * mIcon;
UITextView * mTextBox;
UIPushButton( const std::string& tag );
virtual void onSizeChange();
virtual void onAlphaChange();

View File

@@ -32,7 +32,7 @@ class EE_API UIRadioButton : public UITextView {
void setTextSeparation(const Int32 & textSeparation);
virtual bool setAttribute( const NodeAttribute& attribute );
virtual bool setAttribute( const NodeAttribute& attribute, const Uint32& state = UIState::StateFlagNormal );
protected:
UINode * mActiveButton;
UINode * mInactiveButton;

View File

@@ -3,6 +3,7 @@
#include <eepp/scene/scenenode.hpp>
#include <eepp/system/translator.hpp>
#include <eepp/ui/css/stylesheet.hpp>
namespace EE { namespace UI {
@@ -13,7 +14,7 @@ class EE_API UISceneNode : public SceneNode {
public:
static UISceneNode * New( EE::Window::Window * window = NULL );
UISceneNode( EE::Window::Window * window = NULL );
explicit UISceneNode( EE::Window::Window * window = NULL );
virtual Node * setSize( const Sizef& size );
@@ -41,12 +42,18 @@ class EE_API UISceneNode : public SceneNode {
UIWidget * loadLayoutNodes( pugi::xml_node node, Node * parent );
void setStyleSheet( CSS::StyleSheet styleSheet );
CSS::StyleSheet& getStyleSheet();
bool hasStyleSheet();
protected:
friend class EE::UI::UIWindow;
Sizef mDpSize;
Uint32 mFlags;
Translator mTranslator;
std::list<UIWindow*> mWindowsList;
CSS::StyleSheet mStyleSheet;
virtual void resizeControl( EE::Window::Window * win );
@@ -60,9 +67,7 @@ class EE_API UISceneNode : public SceneNode {
bool windowExists( UIWindow * win );
virtual void setInternalSize(const Sizef& size );
};
}}

View File

@@ -69,7 +69,7 @@ class EE_API UIScrollBar : public UIWidget {
void setExpandBackground( bool expandBackground );
virtual bool setAttribute( const NodeAttribute& attribute );
virtual bool setAttribute( const NodeAttribute& attribute, const Uint32& state = UIState::StateFlagNormal );
protected:
ScrollBarType mScrollBarType;
UISlider * mSlider;

View File

@@ -40,7 +40,7 @@ class EE_API UIScrollView : public UITouchDragableWidget {
UINode * getContainer() const;
virtual bool setAttribute( const NodeAttribute& attribute );
virtual bool setAttribute( const NodeAttribute& attribute, const Uint32& state = UIState::StateFlagNormal );
protected:
ScrollViewType mViewType;
UI_SCROLLBAR_MODE mVScrollMode;

View File

@@ -27,8 +27,10 @@ class EE_API UISelectButton : public UIPushButton {
const Color& getFontSelectedColor() const;
virtual bool setAttribute( const NodeAttribute& attribute );
virtual bool setAttribute( const NodeAttribute& attribute, const Uint32& state = UIState::StateFlagNormal );
protected:
UISelectButton( const std::string& tag );
virtual void onStateChange();
};

View File

@@ -66,7 +66,7 @@ class EE_API UISlider : public UIWidget {
void setPageStep( const Float & pageStep );
virtual bool setAttribute( const NodeAttribute& attribute );
virtual bool setAttribute( const NodeAttribute& attribute, const Uint32& state = UIState::StateFlagNormal );
Sizef getMinimumSize();
protected:

View File

@@ -56,7 +56,7 @@ class EE_API UISpinBox : public UIWidget {
bool dotsInNumbersAllowed();
virtual bool setAttribute( const NodeAttribute& attribute );
virtual bool setAttribute( const NodeAttribute& attribute, const Uint32& state = UIState::StateFlagNormal );
protected:
UITextInput * mInput;
UINode * mPushUp;

View File

@@ -46,7 +46,7 @@ class EE_API UISprite : public UIWidget {
bool getDeallocSprite();
virtual bool setAttribute( const NodeAttribute& attribute );
virtual bool setAttribute( const NodeAttribute& attribute, const Uint32& state = UIState::StateFlagNormal );
protected:
Graphics::Sprite * mSprite;
RenderMode mRender;

View File

@@ -33,7 +33,7 @@ class EE_API UIState {
StateFlagCount = StateCount
};
static const char * getSkinStateName( const Uint32& State );
static const char * getStateName( const Uint32& State );
static int getStateNumber(const std::string & State);
@@ -59,6 +59,8 @@ class EE_API UIState {
Uint32 mCurrentState;
void updateState();
virtual void onStateChange();
};
}}

View File

@@ -3,26 +3,36 @@
#include <eepp/ui/uistate.hpp>
#include <eepp/scene/nodeattribute.hpp>
#include <eepp/ui/css/stylesheetproperty.hpp>
using namespace EE::Scene;
namespace EE { namespace UI {
class UIWidget;
class EE_API UIStyle : public UIState {
public:
static UIStyle * New();
static UIStyle * New( UIWidget * widget );
explicit UIStyle();
explicit UIStyle( UIWidget * widget );
virtual ~UIStyle();
bool stateExists( const Uint32& state );
void addAttribute( int state, NodeAttribute attribute );
void load();
protected:
typedef std::map<std::string, NodeAttribute> AttributesMap;
UIWidget * mWidget;
std::map<int, AttributesMap> mStates;
void addStyleSheetProperties( int state, const CSS::StyleSheetProperties& properties );
void onStateChange();
};
}}

View File

@@ -29,7 +29,7 @@ class EE_API UITab : public UISelectButton {
virtual UIPushButton * setText( const String& text );
virtual bool setAttribute( const NodeAttribute& attribute );
virtual bool setAttribute( const NodeAttribute& attribute, const Uint32& state = UIState::StateFlagNormal );
protected:
Node * mControlOwned;
std::string mOwnedName;

View File

@@ -77,7 +77,7 @@ class EE_API UITable : public UITouchDragableWidget {
Rectf getContainerPadding() const;
virtual bool setAttribute( const NodeAttribute& attribute );
virtual bool setAttribute( const NodeAttribute& attribute, const Uint32& state = UIState::StateFlagNormal );
protected:
friend class UIItemContainer<UITable>;
friend class UITableCell;

View File

@@ -135,7 +135,7 @@ class EE_API UITabWidget : public UIWidget {
void setStyleConfig(const UITabWidgetStyleConfig & styleConfig);
virtual bool setAttribute( const NodeAttribute& attribute );
virtual bool setAttribute( const NodeAttribute& attribute, const Uint32& state = UIState::StateFlagNormal );
protected:
friend class UITab;

View File

@@ -47,7 +47,7 @@ class EE_API UITextEdit : public UIWidget {
void setFontStyleConfig(const UIFontStyleConfig & fontStyleConfig);
virtual bool setAttribute( const NodeAttribute& attribute );
virtual bool setAttribute( const NodeAttribute& attribute, const Uint32& state = UIState::StateFlagNormal );
protected:
UITextInput * mTextInput;
UIScrollBar * mHScrollBar;

View File

@@ -47,7 +47,7 @@ class EE_API UITextInput : public UITextView {
bool isFreeEditingEnabled();
virtual bool setAttribute( const NodeAttribute& attribute );
virtual bool setAttribute( const NodeAttribute& attribute, const Uint32& state = UIState::StateFlagNormal );
virtual UIWidget * setPadding(const Rectf& padding);
protected:
@@ -58,6 +58,8 @@ class EE_API UITextInput : public UITextView {
bool mAllowEditing;
bool mShowingWait;
UITextInput( const std::string& tag );
void resetWaitCursor();
virtual void alignFix();

View File

@@ -43,7 +43,7 @@ class EE_API UITextureRegion : public UIWidget {
UITextureRegion * setScaleType(const Uint32 & scaleType);
virtual bool setAttribute( const NodeAttribute& attribute );
virtual bool setAttribute( const NodeAttribute& attribute, const Uint32& state = UIState::StateFlagNormal );
protected:
Uint32 mScaleType;
Graphics::TextureRegion * mTextureRegion;

View File

@@ -76,7 +76,7 @@ class EE_API UITextView : public UIWidget {
UITooltipStyleConfig getFontStyleConfig() const;
virtual bool setAttribute( const NodeAttribute& attribute );
virtual bool setAttribute( const NodeAttribute& attribute, const Uint32& state = UIState::StateFlagNormal );
protected:
Text * mTextCache;
String mString;
@@ -101,6 +101,8 @@ class EE_API UITextView : public UIWidget {
Int32 mFontLineCenter;
bool mSelecting;
UITextView( const std::string& tag );
virtual void drawSelection(Text * textCache);
virtual void onSizeChange();

View File

@@ -29,12 +29,14 @@ class EE_API UITouchDragableWidget : public UIWidget {
UITouchDragableWidget * setTouchDragDeceleration( const Vector2f& touchDragDeceleration );
virtual bool setAttribute( const NodeAttribute& attribute );
virtual bool setAttribute( const NodeAttribute& attribute, const Uint32& state = UIState::StateFlagNormal );
protected:
Vector2f mTouchDragPoint;
Vector2f mTouchDragAcceleration;
Vector2f mTouchDragDeceleration;
UITouchDragableWidget( const std::string& tag );
virtual void onTouchDragValueChange( Vector2f diff );
virtual bool isTouchOverAllowedChilds();

View File

@@ -4,6 +4,7 @@
#include <eepp/scene/nodeattribute.hpp>
#include <eepp/ui/uinode.hpp>
#include <eepp/ui/uitooltip.hpp>
#include <eepp/ui/css/stylesheetelement.hpp>
namespace pugi {
class xml_node;
@@ -11,7 +12,9 @@ class xml_node;
namespace EE { namespace UI {
class EE_API UIWidget : public UINode {
class UIStyle;
class EE_API UIWidget : public UINode, public CSS::StyleSheetElement {
public:
static UIWidget * New();
@@ -85,18 +88,44 @@ class EE_API UIWidget : public UINode {
void notifyLayoutAttrChangeParent();
bool setAttribute( const std::string& name, const std::string& value );
bool setAttribute( const std::string& name, const std::string& value, const Uint32& state = UIState::StateFlagNormal );
virtual bool setAttribute( const NodeAttribute& attribute );
virtual bool setAttribute( const NodeAttribute& attribute, const Uint32& state = UIState::StateFlagNormal );
const Rectf& getPadding() const;
UIWidget * setPadding(const Rectf& padding);
const std::string& getStyleSheetTag() const;
const std::string& getStyleSheetId() const;
const std::vector<std::string>& getStyleSheetClasses() const;
StyleSheetElement * getStyleSheetParentElement();
void addClass( const std::string& cls );
void removeClass( const std::string& cls );
bool containsClass( const std::string& cls );
void setElementTag( const std::string& tag );
const std::string& getElementTag() const;
virtual void pushState( const Uint32& State, bool emitEvent = true );
virtual void popState( const Uint32& State, bool emitEvent = true );
void reloadStyle();
protected:
friend class UIManager;
friend class UISceneNode;
std::string mTag;
UITheme * mTheme;
UIStyle * mStyle;
UITooltip * mTooltip;
Sizef mMinControlSize;
Rect mDistToBorder;
@@ -111,6 +140,9 @@ class EE_API UIWidget : public UINode {
UIWidget * mLayoutPositionRuleWidget;
int mAttributesTransactionCount;
std::string mSkinName;
std::vector<std::string> mClasses;
explicit UIWidget( const std::string& tag );
void createTooltip();

View File

@@ -109,7 +109,7 @@ class EE_API UIWindow : public UIWidget {
virtual void loadFromXmlNode( const pugi::xml_node& node );
virtual bool setAttribute( const NodeAttribute& attribute );
virtual bool setAttribute( const NodeAttribute& attribute, const Uint32& state = UIState::StateFlagNormal );
virtual void internalDraw();

View File

@@ -1,6 +1,7 @@
#include <eepp/ui/css/stylesheet.hpp>
#include <eepp/ui/css/stylesheetselector.hpp>
#include <eepp/ui/css/stylesheetproperty.hpp>
#include <eepp/ui/css/stylesheetelement.hpp>
namespace EE { namespace UI { namespace CSS {
@@ -10,9 +11,13 @@ void StyleSheet::addNode( StyleSheetNode node ) {
nodes.push_back( node );
}
StyleSheetProperties StyleSheet::find( const std::string& tagName, const std::string& id, const std::vector<std::string>& classes, const std::string& pseudoClass ) {
bool StyleSheet::isEmpty() const {
return nodes.empty();
}
StyleSheetProperties StyleSheet::getElementProperties( StyleSheetElement * element, const std::string& pseudoClass ) {
StyleSheetProperties propertiesSelected;
Uint32 lastSpecificity = -1;
Uint32 lastSpecificity = 0;
for ( auto it = nodes.begin(); it != nodes.end(); ++it ) {
StyleSheetNode& node = *it;
@@ -20,17 +25,17 @@ StyleSheetProperties StyleSheet::find( const std::string& tagName, const std::st
Uint32 flags = 0;
if ( selector.hasTagName() && !tagName.empty() && selector.getTagName() == tagName ) {
if ( selector.hasTagName() && !element->getStyleSheetTag().empty() && selector.getTagName() == element->getStyleSheetTag() ) {
flags |= StyleSheetSelector::TagName;
}
if ( selector.hasId() && !id.empty() && selector.getId() == id ) {
if ( selector.hasId() && !element->getStyleSheetId().empty() && selector.getId() == element->getStyleSheetId() ) {
flags |= StyleSheetSelector::Id;
}
if ( selector.hasClasses() && !classes.empty() ) {
if ( selector.hasClasses() && !element->getStyleSheetClasses().empty() ) {
bool hasClasses = true;
for ( auto cit = classes.begin(); cit != classes.end(); ++cit ) {
for ( auto cit = element->getStyleSheetClasses().begin(); cit != element->getStyleSheetClasses().end(); ++cit ) {
if ( !selector.hasClass( *cit ) ) {
hasClasses = false;
break;
@@ -47,7 +52,9 @@ StyleSheetProperties StyleSheet::find( const std::string& tagName, const std::st
}
if ( flags == selector.getRequiredFlags() && selector.getSpecificity() > lastSpecificity ) {
propertiesSelected = node.properties;
for ( auto pit = node.properties.begin(); pit != node.properties.end(); ++pit )
propertiesSelected[ pit->second.name ] = pit->second;
lastSpecificity = selector.getSpecificity();
}
}

View File

@@ -2,14 +2,57 @@
#include <eepp/ui/css/stylesheetselectorparser.hpp>
#include <eepp/ui/css/stylesheetpropertiesparser.hpp>
#include <eepp/system/iostreamfile.hpp>
#include <eepp/system/iostreammemory.hpp>
#include <eepp/system/pack.hpp>
#include <eepp/system/packmanager.hpp>
#include <eepp/system/filesystem.hpp>
using namespace EE::System;
namespace EE { namespace UI { namespace CSS {
StyleSheetParser::StyleSheetParser() {
}
bool StyleSheetParser::loadFromFile( const std::string& file ) {
IOStreamFile stream( file );
bool StyleSheetParser::loadFromStream( IOStream& stream ) {
mCSS.resize( stream.getSize(), '\0' );
stream.read( &mCSS[0], stream.getSize() );
return parse();
}
bool StyleSheetParser::loadFromFile( const std::string& filename ) {
if ( !FileSystem::fileExists( filename ) && PackManager::instance()->isFallbackToPacksActive() ) {
std::string path( filename );
Pack * pack = PackManager::instance()->exists( path );
if ( NULL != pack ) {
return loadFromPack( pack, path );
}
return false;
}
IOStreamFile stream( filename );
return loadFromStream( stream );
}
bool StyleSheetParser::loadFromPack( Pack * pack, std::string filePackPath ) {
if ( NULL == pack )
return false;
bool Ret = false;
SafeDataPointer PData;
if ( pack->isOpen() && pack->extractFileToMemory( filePackPath, PData ) ) {
Ret = loadFromMemory( PData.data, PData.size );
}
return Ret;
}
bool StyleSheetParser::loadFromMemory( const Uint8* RAWData, const Uint32& size ) {
IOStreamMemory stream( (const char*)RAWData, size );
return loadFromStream( stream );
}
@@ -143,10 +186,4 @@ int StyleSheetParser::readProperty( ReadState& rs, std::size_t pos, std::string&
return pos;
}
bool StyleSheetParser::loadFromStream( IOStream& stream ) {
mCSS.resize( stream.getSize(), '\0' );
stream.read( &mCSS[0], stream.getSize() );
return parse();
}
}}}

View File

@@ -7,7 +7,7 @@ StyleSheetProperty::StyleSheetProperty()
{}
StyleSheetProperty::StyleSheetProperty( const std::string& name, const std::string& value ) :
name( String::trim( name ) ),
name( String::toLower( String::trim( name ) ) ),
value( String::trim( value ) )
{}

View File

@@ -5,7 +5,7 @@ namespace EE { namespace UI { namespace CSS {
StyleSheetSelector::StyleSheetSelector( const std::string& selectorName ) :
name( selectorName ),
name( String::toLower( selectorName ) ),
specificity(0)
{
auto parts = String::split( name, ' ' );

View File

@@ -10,7 +10,7 @@ UICheckBox * UICheckBox::New() {
}
UICheckBox::UICheckBox() :
UITextView(),
UITextView( "checkbox" ),
mActive( false ),
mTextSeparation( 4 )
{
@@ -185,13 +185,13 @@ void UICheckBox::setTextSeparation(const Int32 & textSeparation) {
setPadding( getPadding() );
}
bool UICheckBox::setAttribute( const NodeAttribute& attribute ) {
bool UICheckBox::setAttribute( const NodeAttribute& attribute, const Uint32& state ) {
const std::string& name = attribute.getName();
if ( "selected" == name || "active" == name ) {
setActive( attribute.asBool() );
} else {
return UITextView::setAttribute( attribute );
return UITextView::setAttribute( attribute, state );
}
return true;

View File

@@ -8,7 +8,7 @@ UIComboBox * UIComboBox::New() {
}
UIComboBox::UIComboBox() :
UIWidget(),
UIWidget( "combobox" ),
mDropDownList( NULL ),
mButton( NULL )
{

View File

@@ -12,7 +12,7 @@ UIDropDownList * UIDropDownList::New() {
}
UIDropDownList::UIDropDownList() :
UITextInput(),
UITextInput( "dropdownlist" ),
mListBox( NULL ),
mFriendCtrl( NULL )
{
@@ -274,7 +274,7 @@ void UIDropDownList::destroyListBox() {
}
}
bool UIDropDownList::setAttribute( const NodeAttribute& attribute ) {
bool UIDropDownList::setAttribute( const NodeAttribute& attribute, const Uint32& state ) {
const std::string& name = attribute.getName();
if ( "popuptomaincontrol" == name ) {
@@ -282,7 +282,7 @@ bool UIDropDownList::setAttribute( const NodeAttribute& attribute ) {
} else if ( "maxnumvisibleitems" == name ) {
setMaxNumVisibleItems( attribute.asUint() );
} else {
return UITextInput::setAttribute( attribute );
return UITextInput::setAttribute( attribute, state );
}
return true;

View File

@@ -8,7 +8,7 @@ UIGridLayout * UIGridLayout::New() {
}
UIGridLayout::UIGridLayout() :
UILayout(),
UILayout( "gridlayout" ),
mColumnMode( Weight ),
mRowMode( Weight ),
mColumnWeight( 0.25f ),
@@ -204,7 +204,7 @@ Sizef UIGridLayout::getTargetElementSize() {
mRowMode == Size ? mRowHeight : ( ( getLayoutHeightRules() == WRAP_CONTENT ? getParent()->getSize().getHeight() : mDpSize.getHeight() ) - mPadding.Top - mPadding.Bottom ) * mRowWeight );
}
bool UIGridLayout::setAttribute( const NodeAttribute &attribute ) {
bool UIGridLayout::setAttribute( const NodeAttribute& attribute, const Uint32& state ) {
const std::string& name = attribute.getName();
if ( "columnspan" == name ) {
@@ -232,7 +232,7 @@ bool UIGridLayout::setAttribute( const NodeAttribute &attribute ) {
} else if ( "reversedraw" == name ) {
setReverseDraw( attribute.asBool() );
} else {
return UILayout::setAttribute( attribute );
return UILayout::setAttribute( attribute, state );
}
return true;

View File

@@ -11,7 +11,7 @@ UIImage * UIImage::New() {
}
UIImage::UIImage() :
UIWidget(),
UIWidget( "image" ),
mScaleType( UIScaleType::None ),
mDrawable( NULL ),
mColor(),
@@ -183,7 +183,7 @@ const Vector2f& UIImage::getAlignOffset() const {
return mAlignOffset;
}
bool UIImage::setAttribute( const NodeAttribute& attribute ) {
bool UIImage::setAttribute( const NodeAttribute& attribute, const Uint32& state ) {
const std::string& name = attribute.getName();
if ( "src" == name ) {
@@ -209,7 +209,7 @@ bool UIImage::setAttribute( const NodeAttribute& attribute ) {
} else if ( "tint" == name ) {
setColor( attribute.asColor() );
} else {
return UIWidget::setAttribute( attribute );
return UIWidget::setAttribute( attribute, state );
}
return true;

View File

@@ -7,7 +7,12 @@ UILayout * UILayout::New() {
}
UILayout::UILayout() :
UIWidget()
UIWidget( "layout" )
{
}
UILayout::UILayout( const std::string& tag ) :
UIWidget( tag )
{
}

View File

@@ -16,7 +16,7 @@ UILinearLayout * UILinearLayout::NewHorizontal() {
}
UILinearLayout::UILinearLayout() :
UILayout(),
UILayout( "linearlayout" ),
mOrientation( UI_VERTICAL )
{
clipEnable();
@@ -336,7 +336,7 @@ Sizei UILinearLayout::getTotalUsedSize() {
return size;
}
bool UILinearLayout::setAttribute( const NodeAttribute& attribute ) {
bool UILinearLayout::setAttribute( const NodeAttribute& attribute, const Uint32& state ) {
const std::string& name = attribute.getName();
if ( "orientation" == name ) {
@@ -348,7 +348,7 @@ bool UILinearLayout::setAttribute( const NodeAttribute& attribute ) {
else if ( "vertical" == val )
setOrientation( UI_VERTICAL );
} else {
return UILayout::setAttribute( attribute );
return UILayout::setAttribute( attribute, state );
}
return true;

View File

@@ -16,7 +16,7 @@ UIListBox * UIListBox::New() {
}
UIListBox::UIListBox() :
UITouchDragableWidget(),
UITouchDragableWidget( "listbox" ),
mRowHeight(0),
mVScrollMode( UI_SCROLLBAR_AUTO ),
mHScrollMode( UI_SCROLLBAR_AUTO ),
@@ -983,7 +983,7 @@ void UIListBox::setFontStyleConfig(const UIFontStyleConfig & fontStyleConfig) {
setFontColor( mFontStyleConfig.FontColor );
}
bool UIListBox::setAttribute( const NodeAttribute& attribute ) {
bool UIListBox::setAttribute( const NodeAttribute& attribute, const Uint32& state ) {
const std::string& name = attribute.getName();
if ( "rowheight" == name ) {
@@ -1029,7 +1029,7 @@ bool UIListBox::setAttribute( const NodeAttribute& attribute ) {
mHScrollBar->setScrollBarType( UIScrollBar::NoButtons );
}
} else {
return UITouchDragableWidget::setAttribute( attribute );
return UITouchDragableWidget::setAttribute( attribute, state );
}
return true;

View File

@@ -8,7 +8,7 @@ UIListBoxItem * UIListBoxItem::New() {
}
UIListBoxItem::UIListBoxItem() :
UITextView()
UITextView( "listboxitem" )
{
setLayoutSizeRules( FIXED, FIXED );
applyDefaultTheme();

View File

@@ -9,7 +9,7 @@ UILoader * UILoader::New() {
}
UILoader::UILoader() :
UIWidget(),
UIWidget( "loader" ),
mRadius(0),
mOutlineThickness( PixelDensity::dpToPx(8) ),
mColor( Color::Green ),
@@ -184,7 +184,7 @@ UILoader * UILoader::setAnimationSpeed( const Float& animationSpeed ) {
return this;
}
bool UILoader::setAttribute( const NodeAttribute& attribute ) {
bool UILoader::setAttribute( const NodeAttribute& attribute, const Uint32& state ) {
std::string name = attribute.getName();
if ( "indeterminate" == name ) {
@@ -204,7 +204,7 @@ bool UILoader::setAttribute( const NodeAttribute& attribute ) {
} else if ( "arcstartangle" == name ) {
setArcStartAngle( attribute.asFloat() );
} else {
return UIWidget::setAttribute( attribute );
return UIWidget::setAttribute( attribute, state );
}
return true;

View File

@@ -13,7 +13,7 @@ UIMenu *UIMenu::New() {
}
UIMenu::UIMenu() :
UIWidget(),
UIWidget( "menu" ),
mMaxWidth( 0 ),
mNextPosY( 0 ),
mBiggestIcon( 0 ),

View File

@@ -9,7 +9,7 @@ UIMenuCheckBox * UIMenuCheckBox::New() {
}
UIMenuCheckBox::UIMenuCheckBox() :
UIMenuItem(),
UIMenuItem( "menucheckbox" ),
mActive( false ),
mSkinActive( NULL ),
mSkinInactive( NULL )

View File

@@ -7,12 +7,16 @@ UIMenuItem * UIMenuItem::New() {
return eeNew( UIMenuItem, () );
}
UIMenuItem::UIMenuItem() :
UIPushButton()
UIMenuItem::UIMenuItem( const std::string& tag ) :
UIPushButton( tag )
{
applyDefaultTheme();
}
UIMenuItem::UIMenuItem() :
UIMenuItem( "menuitem" )
{}
UIMenuItem::~UIMenuItem() {
}

View File

@@ -8,7 +8,7 @@ UIMenuSeparator * UIMenuSeparator::New() {
}
UIMenuSeparator::UIMenuSeparator() :
UIWidget()
UIWidget( "menuseparator" )
{
applyDefaultTheme();
}

View File

@@ -9,7 +9,7 @@ UIMenuSubMenu * UIMenuSubMenu::New() {
}
UIMenuSubMenu::UIMenuSubMenu() :
UIMenuItem(),
UIMenuItem( "menusubmenu" ),
mSubMenu( NULL ),
mArrow( NULL ),
mTimeOver( 0.f ),

View File

@@ -12,6 +12,7 @@ UIPopUpMenu * UIPopUpMenu::New() {
UIPopUpMenu::UIPopUpMenu() :
UIMenu()
{
setElementTag( "popupmenu" );
setVisible( false );
setEnabled( false );
applyDefaultTheme();

View File

@@ -10,7 +10,7 @@ UIProgressBar *UIProgressBar::New() {
}
UIProgressBar::UIProgressBar() :
UIWidget(),
UIWidget( "progressbar" ),
mProgress( 0.f ),
mTotalSteps( 100.f ),
mFillerSkin( NULL )
@@ -213,7 +213,7 @@ UITextView * UIProgressBar::getTextBox() const {
return mTextBox;
}
bool UIProgressBar::setAttribute( const NodeAttribute& attribute ) {
bool UIProgressBar::setAttribute( const NodeAttribute& attribute, const Uint32& state ) {
const std::string& name = attribute.getName();
if ( "totalsteps" == name ) {
@@ -236,7 +236,7 @@ bool UIProgressBar::setAttribute( const NodeAttribute& attribute ) {
} else if ( "fillerpaddingbottom" == name ) {
setFillerPadding( Rectf( mStyleConfig.FillerPadding.Left, mStyleConfig.FillerPadding.Top, mStyleConfig.FillerPadding.Right, attribute.asDpDimension() ) );
} else {
return UIWidget::setAttribute( attribute );
return UIWidget::setAttribute( attribute, state );
}
return true;

View File

@@ -11,8 +11,8 @@ UIPushButton * UIPushButton::New() {
return eeNew( UIPushButton, () );
}
UIPushButton::UIPushButton() :
UIWidget(),
UIPushButton::UIPushButton( const std::string& tag ) :
UIWidget( tag ),
mIcon( NULL ),
mTextBox( NULL )
{
@@ -61,6 +61,10 @@ UIPushButton::UIPushButton() :
applyDefaultTheme();
}
UIPushButton::UIPushButton() :
UIPushButton( "pushbutton" )
{}
UIPushButton::~UIPushButton() {
}
@@ -367,7 +371,7 @@ void UIPushButton::setStyleConfig(const UIPushButtonStyleConfig & styleConfig) {
onStateChange();
}
bool UIPushButton::setAttribute( const NodeAttribute& attribute ) {
bool UIPushButton::setAttribute( const NodeAttribute& attribute, const Uint32& state ) {
const std::string& name = attribute.getName();
bool attributeSet = true;
@@ -387,7 +391,7 @@ bool UIPushButton::setAttribute( const NodeAttribute& attribute ) {
setIcon( icon );
}
} else {
attributeSet = UIWidget::setAttribute( attribute );
attributeSet = UIWidget::setAttribute( attribute, state );
}
if ( !attributeSet && ( String::startsWith( name, "text" ) || String::startsWith( name, "font" ) ) )

View File

@@ -10,7 +10,7 @@ UIRadioButton * UIRadioButton::New() {
}
UIRadioButton::UIRadioButton() :
UITextView(),
UITextView( "radiobutton" ),
mActiveButton(NULL),
mInactiveButton(NULL),
mActive( false ),
@@ -252,13 +252,13 @@ void UIRadioButton::setTextSeparation(const Int32 & textSeparation) {
setPadding( getPadding() );
}
bool UIRadioButton::setAttribute( const NodeAttribute& attribute ) {
bool UIRadioButton::setAttribute( const NodeAttribute& attribute, const Uint32& state ) {
const std::string& name = attribute.getName();
if ( "selected" == name || "active" == name ) {
setActive( attribute.asBool() );
} else {
return UITextView::setAttribute( attribute );
return UITextView::setAttribute( attribute, state );
}
return true;

View File

@@ -7,7 +7,7 @@ UIRelativeLayout * UIRelativeLayout::New() {
}
UIRelativeLayout::UIRelativeLayout() :
UILayout()
UILayout( "relativelayout" )
{
}

View File

@@ -24,7 +24,7 @@ UISceneNode::UISceneNode( EE::Window::Window * window ) :
resizeControl( mWindow );
}
void UISceneNode::resizeControl( EE::Window::Window * win ) {
void UISceneNode::resizeControl( EE::Window::Window * ) {
setSize( (Float)mWindow->getWidth() / PixelDensity::getPixelDensity(), (Float)mWindow->getHeight() / PixelDensity::getPixelDensity() );
sendMsg( this, NodeMessage::WindowResize );
}
@@ -98,6 +98,29 @@ UIWidget * UISceneNode::loadLayoutNodes( pugi::xml_node node, Node * parent ) {
return firstWidget;
}
void UISceneNode::setStyleSheet(CSS::StyleSheet styleSheet) {
mStyleSheet = styleSheet;
if ( NULL != mChild ) {
Node * ChildLoop = mChild;
while ( NULL != ChildLoop ) {
if ( ChildLoop->isWidget() )
static_cast<UIWidget*>( ChildLoop )->reloadStyle();
ChildLoop = ChildLoop->getNextNode();
}
}
}
CSS::StyleSheet& UISceneNode::getStyleSheet() {
return mStyleSheet;
}
bool UISceneNode::hasStyleSheet() {
return !mStyleSheet.isEmpty();
}
UIWidget * UISceneNode::loadLayoutFromFile( const std::string& layoutPath, Node * parent ) {
if ( FileSystem::fileExists( layoutPath ) ) {
pugi::xml_document doc;

View File

@@ -16,7 +16,7 @@ UIScrollBar * UIScrollBar::NewVertical() {
}
UIScrollBar::UIScrollBar( const UI_ORIENTATION& orientation ) :
UIWidget(),
UIWidget( "scrollbar" ),
#ifdef EE_PLATFORM_TOUCH
mScrollBarType( NoButtons )
#else
@@ -296,7 +296,7 @@ void UIScrollBar::setExpandBackground( bool expandBackground ) {
adjustChilds();
}
bool UIScrollBar::setAttribute( const NodeAttribute & attribute ) {
bool UIScrollBar::setAttribute( const NodeAttribute& attribute, const Uint32& state ) {
const std::string& name = attribute.getName();
if ( "orientation" == name ) {
@@ -327,7 +327,7 @@ bool UIScrollBar::setAttribute( const NodeAttribute & attribute ) {
setScrollBarType( TwoButtons );
}
} else {
return UIWidget::setAttribute( attribute );
return UIWidget::setAttribute( attribute, state );
}
return true;

View File

@@ -9,7 +9,7 @@ UIScrollView * UIScrollView::New() {
}
UIScrollView::UIScrollView() :
UITouchDragableWidget(),
UITouchDragableWidget( "scrollview" ),
mViewType( Exclusive ),
mVScrollMode( UI_SCROLLBAR_AUTO ),
mHScrollMode( UI_SCROLLBAR_AUTO ),
@@ -228,7 +228,7 @@ bool UIScrollView::isTouchOverAllowedChilds() {
return isMouseOverMeOrChilds() && mScrollView->isMouseOverMeOrChilds() && ret;
}
bool UIScrollView::setAttribute( const NodeAttribute& attribute ) {
bool UIScrollView::setAttribute( const NodeAttribute& attribute, const Uint32& state ) {
const std::string& name = attribute.getName();
if ( "type" == name ) {
@@ -263,7 +263,7 @@ bool UIScrollView::setAttribute( const NodeAttribute& attribute ) {
mHScroll->setScrollBarType( UIScrollBar::NoButtons );
}
} else {
return UITouchDragableWidget::setAttribute( attribute );
return UITouchDragableWidget::setAttribute( attribute, state );
}
return true;

View File

@@ -4,14 +4,17 @@
namespace EE { namespace UI {
UISelectButton *UISelectButton::New() {
UISelectButton * UISelectButton::New() {
return eeNew( UISelectButton, () );
}
UISelectButton::UISelectButton( const std::string& tag ) :
UIPushButton( tag )
{}
UISelectButton::UISelectButton() :
UIPushButton()
{
}
UISelectButton( "selectbutton" )
{}
UISelectButton::~UISelectButton() {
}
@@ -89,13 +92,13 @@ const Color &UISelectButton::getFontSelectedColor() const {
return mStyleConfig.FontSelectedColor;
}
bool UISelectButton::setAttribute( const NodeAttribute& attribute ) {
bool UISelectButton::setAttribute( const NodeAttribute& attribute, const Uint32& state ) {
const std::string& name = attribute.getName();
if ( "textselectedcolor" == name ) {
setFontSelectedColor( attribute.asColor() );
} else {
return UIPushButton::setAttribute( attribute );
return UIPushButton::setAttribute( attribute, state );
}
return true;

View File

@@ -18,7 +18,7 @@ UISlider * UISlider::NewHorizontal() {
}
UISlider::UISlider( const UI_ORIENTATION& orientation ) :
UIWidget(),
UIWidget( "slider" ),
mOrientation( orientation ),
mBackSlider( NULL ),
mSlider( NULL ),
@@ -419,7 +419,7 @@ Uint32 UISlider::onMessage(const NodeMessage * Msg) {
return 0;
}
bool UISlider::setAttribute( const NodeAttribute& attribute ) {
bool UISlider::setAttribute( const NodeAttribute& attribute, const Uint32& state ) {
const std::string& name = attribute.getName();
if ( "orientation" == name ) {
@@ -443,7 +443,7 @@ bool UISlider::setAttribute( const NodeAttribute& attribute ) {
} else if ( "halfslider" == name ) {
setAllowHalfSliderOut( attribute.asBool() );
} else {
return UIWidget::setAttribute( attribute );
return UIWidget::setAttribute( attribute, state );
}
return true;

View File

@@ -8,7 +8,7 @@ UISliderButton *UISliderButton::New() {
}
UISliderButton::UISliderButton() :
UIWidget()
UIWidget( "sliderbutton" )
{
applyDefaultTheme();
}

View File

@@ -9,7 +9,7 @@ UISpinBox * UISpinBox::New() {
}
UISpinBox::UISpinBox() :
UIWidget(),
UIWidget( "spinbox" ),
mMinValue( 0.f ),
mMaxValue( 1024.f ),
mValue( 0 ),
@@ -273,7 +273,7 @@ void UISpinBox::onPaddingChange() {
UIWidget::onPaddingChange();
}
bool UISpinBox::setAttribute( const NodeAttribute& attribute ) {
bool UISpinBox::setAttribute( const NodeAttribute& attribute, const Uint32& state ) {
const std::string& name = attribute.getName();
bool attributeSet = true;
@@ -287,7 +287,7 @@ bool UISpinBox::setAttribute( const NodeAttribute& attribute ) {
} else if ( "clickstep" == name ) {
setClickStep(attribute.asFloat() );
} else {
attributeSet = UIWidget::setAttribute( attribute );
attributeSet = UIWidget::setAttribute( attribute, state );
}
mInput->setAttribute( attribute );

View File

@@ -10,7 +10,7 @@ UISprite * UISprite::New() {
}
UISprite::UISprite() :
UIWidget(),
UIWidget( "sprite" ),
mSprite( NULL ),
mRender( RENDER_NORMAL ),
mAlignOffset(0,0),
@@ -185,7 +185,7 @@ void UISprite::onSizeChange() {
UIWidget::onSizeChange();
}
bool UISprite::setAttribute( const NodeAttribute& attribute ) {
bool UISprite::setAttribute( const NodeAttribute& attribute, const Uint32& state ) {
const std::string& name = attribute.getName();
if ( "src" == name ) {
@@ -196,7 +196,7 @@ bool UISprite::setAttribute( const NodeAttribute& attribute ) {
setSprite( Sprite::New( val ) );
}
} else {
return UIWidget::setAttribute( attribute );
return UIWidget::setAttribute( attribute, state );
}
return true;

View File

@@ -25,7 +25,7 @@ static const Uint32 UIStateFlags[] = {
UIState::StateFlagDisabled
};
const char * UIState::getSkinStateName( const Uint32& State ) {
const char * UIState::getStateName( const Uint32& State ) {
return UIStatesNames[ State ];
}
@@ -95,12 +95,22 @@ void UIState::updateState() {
if ( ( mState & UIStateFlags[i] ) == UIStateFlags[i] ) {
if ( stateExists( UIStateFlags[i] ) ) {
mCurrentState = UIStateFlags[i];
onStateChange();
return;
}
}
}
Uint32 currentState = mCurrentState;
mCurrentState = StateFlagNormal;
if ( currentState != StateFlagNormal ) {
onStateChange();
}
}
void UIState::onStateChange() {
}
}}

View File

@@ -1,25 +1,71 @@
#include <eepp/ui/uistyle.hpp>
#include <eepp/ui/uiwidget.hpp>
#include <eepp/ui/uiscenenode.hpp>
namespace EE { namespace UI {
UIStyle * EE::UI::UIStyle::New() {
return eeNew( UIStyle, () );
UIStyle * EE::UI::UIStyle::New( UIWidget * widget ) {
return eeNew( UIStyle, ( widget ) );
}
UIStyle::UIStyle()
UIStyle::UIStyle( UIWidget * widget ) :
mWidget( widget )
{
load();
}
UIStyle::~UIStyle()
{
{}
bool UIStyle::stateExists( const EE::Uint32 & state ) {
return mStates.find( state ) != mStates.end();
}
bool UIStyle::stateExists( const EE::Uint32 & ) {
return false;
}
void UIStyle::addAttribute(int state, NodeAttribute attribute) {
void UIStyle::addAttribute( int state, NodeAttribute attribute ) {
mStates[ state ][ attribute.getName() ] = attribute;
}
void UIStyle::load() {
UISceneNode * uiSceneNode = mWidget->getSceneNode()->isUISceneNode() ? static_cast<UISceneNode*>( mWidget->getSceneNode() ) : NULL;
if ( NULL != uiSceneNode ) {
CSS::StyleSheet& styleSheet = uiSceneNode->getStyleSheet();
if ( !styleSheet.isEmpty() ) {
addStyleSheetProperties( StateFlagNormal, styleSheet.getElementProperties( mWidget, "" ) );
addStyleSheetProperties( StateFlagFocus, styleSheet.getElementProperties( mWidget, "focus" ) );
addStyleSheetProperties( StateFlagSelected, styleSheet.getElementProperties( mWidget, "selected" ) );
addStyleSheetProperties( StateFlagHover, styleSheet.getElementProperties( mWidget, "hover" ) );
addStyleSheetProperties( StateFlagPressed, styleSheet.getElementProperties( mWidget, "pressed" ) );
addStyleSheetProperties( StateFlagSelectedHover, styleSheet.getElementProperties( mWidget, "selectedhover" ) );
addStyleSheetProperties( StateFlagSelectedPressed, styleSheet.getElementProperties( mWidget, "selectedpressed" ) );
addStyleSheetProperties( StateFlagDisabled, styleSheet.getElementProperties( mWidget, "disabled" ) );
onStateChange();
}
}
}
void UIStyle::addStyleSheetProperties( int state, const CSS::StyleSheetProperties& properties ) {
if ( !properties.empty() ) {
for ( auto it = properties.begin(); it != properties.end(); ++it ) {
CSS::StyleSheetProperty property = it->second;
addAttribute( state, NodeAttribute( property.name, property.value ) );
}
}
}
void UIStyle::onStateChange() {
if ( NULL != mWidget && stateExists( mCurrentState ) ) {
AttributesMap& attrs = mStates[ mCurrentState ];
for ( auto it = attrs.begin(); it != attrs.end(); ++it ) {
NodeAttribute& nodeAttr = it->second;
mWidget->setAttribute( nodeAttr );
}
}
}
}}

View File

@@ -10,7 +10,7 @@ UITab *UITab::New() {
}
UITab::UITab() :
UISelectButton(),
UISelectButton( "tab" ),
mControlOwned( NULL )
{
applyDefaultTheme();
@@ -148,7 +148,7 @@ void UITab::onAutoSize() {
}
}
bool UITab::setAttribute( const NodeAttribute& attribute ) {
bool UITab::setAttribute( const NodeAttribute& attribute, const Uint32& state ) {
std::string name = attribute.getName();
if ( "name" == name || "text" == name ) {
@@ -158,7 +158,7 @@ bool UITab::setAttribute( const NodeAttribute& attribute ) {
mOwnedName = attribute.asString();
setOwnedControl();
} else {
return UISelectButton::setAttribute( attribute );
return UISelectButton::setAttribute( attribute, state );
}
return true;

View File

@@ -8,7 +8,7 @@ UITable * UITable::New() {
}
UITable::UITable() :
UITouchDragableWidget(),
UITouchDragableWidget( "table" ),
mContainerPadding(),
mContainer( NULL ),
mVScrollBar( NULL ),
@@ -617,7 +617,7 @@ bool UITable::isTouchOverAllowedChilds() {
return isMouseOverMeOrChilds() && !mVScrollBar->isMouseOverMeOrChilds() && !mHScrollBar->isMouseOverMeOrChilds();
}
bool UITable::setAttribute( const NodeAttribute& attribute ) {
bool UITable::setAttribute( const NodeAttribute& attribute, const Uint32& state ) {
const std::string& name = attribute.getName();
if ( "rowheight" == name ) {
@@ -644,7 +644,7 @@ bool UITable::setAttribute( const NodeAttribute& attribute ) {
mHScrollBar->setScrollBarType( UIScrollBar::NoButtons );
}
} else {
return UITouchDragableWidget::setAttribute( attribute );
return UITouchDragableWidget::setAttribute( attribute, state );
}
return true;

View File

@@ -8,7 +8,7 @@ UITableCell * UITableCell::New() {
}
UITableCell::UITableCell() :
UIWidget()
UIWidget( "tablecell" )
{
applyDefaultTheme();
}

View File

@@ -12,7 +12,7 @@ UITabWidget * UITabWidget::New() {
}
UITabWidget::UITabWidget() :
UIWidget(),
UIWidget( "tabwidget" ),
mTabSelected( NULL ),
mTabSelectedIndex( eeINDEX_NOT_FOUND )
{
@@ -186,7 +186,7 @@ void UITabWidget::setStyleConfig(const UITabWidgetStyleConfig & styleConfig) {
orderTabs();
}
bool UITabWidget::setAttribute( const NodeAttribute& attribute ) {
bool UITabWidget::setAttribute( const NodeAttribute& attribute, const Uint32& state ) {
const std::string& name = attribute.getName();
if ( "textcolor" == name ) {
@@ -250,7 +250,7 @@ bool UITabWidget::setAttribute( const NodeAttribute& attribute ) {
} else if ( "linebelowtabsyoffset" == name ) {
setLineBelowTabsYOffset( attribute.asInt() );
} else {
return UIWidget::setAttribute( attribute );
return UIWidget::setAttribute( attribute, state );
}
return true;

View File

@@ -11,7 +11,7 @@ UITextEdit * UITextEdit::New() {
}
UITextEdit::UITextEdit() :
UIWidget(),
UIWidget( "textedit" ),
mTextInput( NULL ),
mHScrollBar( NULL ),
mVScrollBar( NULL ),
@@ -463,7 +463,7 @@ void UITextEdit::setFontStyleConfig(const UIFontStyleConfig & fontStyleConfig) {
}
}
bool UITextEdit::setAttribute( const NodeAttribute &attribute ) {
bool UITextEdit::setAttribute( const NodeAttribute& attribute, const Uint32& state ) {
const std::string& name = attribute.getName();
bool attributeSet = true;
@@ -485,11 +485,11 @@ bool UITextEdit::setAttribute( const NodeAttribute &attribute ) {
else if ( "on" == val ) setHorizontalScrollMode( UI_SCROLLBAR_ALWAYS_ON );
else if ( "off" == val ) setHorizontalScrollMode( UI_SCROLLBAR_ALWAYS_OFF );
} else {
attributeSet = UIWidget::setAttribute( attribute );
attributeSet = UIWidget::setAttribute( attribute, state );
}
if ( !attributeSet && ( String::startsWith( name, "text" ) || String::startsWith( name, "font" ) ) )
mTextInput->setAttribute( attribute );
mTextInput->setAttribute( attribute, state );
return attributeSet;
}

View File

@@ -13,8 +13,8 @@ UITextInput * UITextInput::New() {
return eeNew( UITextInput, () );
}
UITextInput::UITextInput() :
UITextView(),
UITextInput::UITextInput( const std::string& tag ) :
UITextView( tag ),
mCursorPos(0),
mAllowEditing( true ),
mShowingWait( true )
@@ -31,6 +31,10 @@ UITextInput::UITextInput() :
applyDefaultTheme();
}
UITextInput::UITextInput() :
UITextInput( "textinput" )
{}
UITextInput::~UITextInput() {
}
@@ -344,7 +348,7 @@ bool UITextInput::isFreeEditingEnabled() {
return mTextBuffer.isFreeEditingEnabled();
}
bool UITextInput::setAttribute( const NodeAttribute& attribute ) {
bool UITextInput::setAttribute( const NodeAttribute& attribute, const Uint32& state ) {
const std::string& name = attribute.getName();
if ( "text" == name ) {
@@ -362,7 +366,7 @@ bool UITextInput::setAttribute( const NodeAttribute& attribute ) {
} else if ( "allowdot" == name ) {
getInputTextBuffer()->setAllowOnlyNumbers( getInputTextBuffer()->onlyNumbersAllowed(), attribute.asBool() );
} else {
return UITextView::setAttribute( attribute );
return UITextView::setAttribute( attribute, state );
}
return true;

View File

@@ -11,7 +11,7 @@ UITextureRegion * UITextureRegion::New() {
}
UITextureRegion::UITextureRegion() :
UIWidget(),
UIWidget( "textureregion" ),
mTextureRegion( NULL ),
mColor(),
mRender( RENDER_NORMAL ),
@@ -192,7 +192,7 @@ const Vector2f& UITextureRegion::getAlignOffset() const {
return mAlignOffset;
}
bool UITextureRegion::setAttribute( const NodeAttribute& attribute ) {
bool UITextureRegion::setAttribute( const NodeAttribute& attribute, const Uint32& state ) {
const std::string& name = attribute.getName();
if ( "src" == name || "textureregion" == name ) {
@@ -215,7 +215,7 @@ bool UITextureRegion::setAttribute( const NodeAttribute& attribute ) {
} else if ( "tint" == name ) {
setColor( attribute.asColor() );
} else {
return UIWidget::setAttribute( attribute );
return UIWidget::setAttribute( attribute, state );
}
return true;

View File

@@ -13,8 +13,8 @@ UITextView * UITextView::New() {
return eeNew( UITextView, () );
}
UITextView::UITextView() :
UIWidget(),
UITextView::UITextView( const std::string& tag ) :
UIWidget( tag ),
mRealAlignOffset( 0.f, 0.f ),
mSelCurInit( -1 ),
mSelCurEnd( -1 ),
@@ -37,6 +37,10 @@ UITextView::UITextView() :
alignFix();
}
UITextView::UITextView() :
UITextView( "textview" )
{}
UITextView::~UITextView() {
eeSAFE_DELETE( mTextCache );
}
@@ -532,7 +536,7 @@ void UITextView::setFontStyleConfig( const UITooltipStyleConfig& fontStyleConfig
setOutlineColor( mFontStyleConfig.getOutlineColor() );
}
bool UITextView::setAttribute( const NodeAttribute& attribute ) {
bool UITextView::setAttribute( const NodeAttribute& attribute, const Uint32& state ) {
const std::string& name = attribute.getName();
if ( "text" == name ) {
@@ -591,7 +595,7 @@ bool UITextView::setAttribute( const NodeAttribute& attribute ) {
} else if ( "textselection" == name ) {
mFlags|= UI_TEXT_SELECTION_ENABLED;
} else {
return UIWidget::setAttribute( attribute );
return UIWidget::setAttribute( attribute, state );
}
return true;

View File

@@ -7,11 +7,15 @@ UITouchDragableWidget * UITouchDragableWidget::New() {
return eeNew( UITouchDragableWidget, () );
}
UITouchDragableWidget::UITouchDragableWidget() :
UIWidget(),
UITouchDragableWidget::UITouchDragableWidget( const std::string& tag ) :
UIWidget( tag ),
mTouchDragDeceleration( 5.f, 5.f )
{}
UITouchDragableWidget::UITouchDragableWidget() :
UITouchDragableWidget( "touchdragablewidget" )
{}
Uint32 UITouchDragableWidget::getType() const {
return UI_TYPE_TOUCH_DRAGABLE_WIDGET;
}
@@ -136,7 +140,7 @@ bool UITouchDragableWidget::isTouchOverAllowedChilds() {
return isMouseOverMeOrChilds();
}
bool UITouchDragableWidget::setAttribute( const NodeAttribute& attribute ) {
bool UITouchDragableWidget::setAttribute( const NodeAttribute& attribute, const Uint32& state ) {
const std::string& name = attribute.getName();
if ( "touchdrag" == name ) {
@@ -144,7 +148,7 @@ bool UITouchDragableWidget::setAttribute( const NodeAttribute& attribute ) {
} else if ( "touchdragdeceleration" == name ) {
setTouchDragDeceleration( Vector2f( attribute.asFloat(), attribute.asFloat() ) );
} else {
return UIWidget::setAttribute( attribute );
return UIWidget::setAttribute( attribute, state );
}
return true;

View File

@@ -1,8 +1,10 @@
#include <eepp/ui/uiwidget.hpp>
#include <eepp/ui/uithememanager.hpp>
#include <eepp/ui/uistyle.hpp>
#include <eepp/graphics/drawablesearcher.hpp>
#include <eepp/scene/scenenode.hpp>
#include <eepp/ui/uiscenenode.hpp>
#include <pugixml/pugixml.hpp>
#include <algorithm>
namespace EE { namespace UI {
@@ -10,9 +12,11 @@ UIWidget * UIWidget::New() {
return eeNew( UIWidget, () );
}
UIWidget::UIWidget() :
UIWidget::UIWidget( const std::string & tag ) :
UINode(),
mTag( tag ),
mTheme( NULL ),
mStyle( NULL ),
mTooltip( NULL ),
mMinControlSize(),
mLayoutWeight(0),
@@ -26,9 +30,18 @@ UIWidget::UIWidget() :
mNodeFlags |= NODE_FLAG_WIDGET;
updateAnchorsDistances();
if ( getSceneNode()->isUISceneNode() && static_cast<UISceneNode*>( getSceneNode() )->hasStyleSheet() )
mStyle = UIStyle::New( this );
}
UIWidget::UIWidget() :
UIWidget( "widget" )
{
}
UIWidget::~UIWidget() {
eeSAFE_DELETE( mStyle );
eeSAFE_DELETE( mTooltip );
}
@@ -417,6 +430,77 @@ UIWidget * UIWidget::setPadding(const Rectf& padding) {
return this;
}
const std::string &UIWidget::getStyleSheetId() const {
return mId;
}
const std::string& UIWidget::getStyleSheetTag() const {
return mTag;
}
const std::vector<std::string> &UIWidget::getStyleSheetClasses() const {
return mClasses;
}
CSS::StyleSheetElement * UIWidget::getStyleSheetParentElement() {
return NULL != mParentCtrl && mParentCtrl->isWidget() ? reinterpret_cast<CSS::StyleSheetElement*>( mParentCtrl ) : NULL;
}
void UIWidget::addClass( const std::string& cls ) {
if ( !containsClass( cls ) )
mClasses.push_back( cls );
}
void UIWidget::removeClass( const std::string& cls ) {
mClasses.erase( std::find( mClasses.begin(), mClasses.end(), cls ) );
}
bool UIWidget::containsClass( const std::string& cls ) {
return std::find( mClasses.begin(), mClasses.end(), cls ) != mClasses.end();
}
void UIWidget::setElementTag( const std::string& tag ) {
mTag = tag;
}
const std::string& UIWidget::getElementTag() const {
return mTag;
}
void UIWidget::pushState( const Uint32& State, bool emitEvent ) {
if ( NULL != mStyle )
mStyle->pushState( State );
UINode::pushState( State, emitEvent );
}
void UIWidget::popState( const Uint32& State, bool emitEvent ) {
if ( NULL != mStyle )
mStyle->popState( State );
UINode::popState( State, emitEvent );
}
void UIWidget::reloadStyle() {
if ( NULL == mStyle && getSceneNode()->isUISceneNode() && static_cast<UISceneNode*>( getSceneNode() )->hasStyleSheet() )
mStyle = UIStyle::New( this );
if ( NULL != mStyle ) {
mStyle->load();
if ( NULL != mChild ) {
Node * ChildLoop = mChild;
while ( NULL != ChildLoop ) {
if ( ChildLoop->isWidget() )
static_cast<UIWidget*>( ChildLoop )->reloadStyle();
ChildLoop = ChildLoop->getNextNode();
}
}
}
}
void UIWidget::onPaddingChange() {
invalidateDraw();
}
@@ -433,11 +517,11 @@ void UIWidget::endAttributesTransaction() {
}
}
bool UIWidget::setAttribute( const std::string& name, const std::string& value ) {
return setAttribute( NodeAttribute( name, value ) );
bool UIWidget::setAttribute( const std::string& name, const std::string& value, const Uint32& state ) {
return setAttribute( NodeAttribute( name, value ), state );
}
bool UIWidget::setAttribute(const NodeAttribute & attribute) {
bool UIWidget::setAttribute( const NodeAttribute& attribute, const Uint32& state ) {
std::string name = attribute.getName();
bool attributeSet = true;
@@ -460,32 +544,32 @@ bool UIWidget::setAttribute(const NodeAttribute & attribute) {
const std::string attributeName( attribute.asString() );
if ( String::startsWith( attributeName, "#" ) ) {
setBackgroundColor( attribute.asColor() );
setBackgroundColor( state, attribute.asColor() );
} else if ( NULL != ( res = DrawableSearcher::searchByName( attributeName ) ) ) {
setBackgroundDrawable( res, res->getDrawableType() == Drawable::SPRITE );
setBackgroundDrawable( state, res, res->getDrawableType() == Drawable::SPRITE );
}
} else if ( "backgroundcolor" == name ) {
setBackgroundColor( attribute.asColor() );
setBackgroundColor( state, attribute.asColor() );
} else if ( "foreground" == name ) {
Drawable * res = NULL;
const std::string attributeName( attribute.asString() );
if ( String::startsWith( attributeName, "#" ) ) {
setForegroundColor( attribute.asColor() );
setForegroundColor( state, attribute.asColor() );
} else if ( NULL != ( res = DrawableSearcher::searchByName( attributeName ) ) ) {
setForegroundDrawable( res, res->getDrawableType() == Drawable::SPRITE );
setForegroundDrawable( state, res, res->getDrawableType() == Drawable::SPRITE );
}
} else if ( "foregroundcolor" == name ) {
setForegroundColor( attribute.asColor() );
setForegroundColor( state, attribute.asColor() );
} else if ( "foregroundcorners" == name ) {
setForegroundCorners( attribute.asUint() );
setForegroundCorners( state, attribute.asUint() );
} else if ( "bordercolor" == name ) {
setBorderColor( attribute.asColor() );
setBorderColor( state, attribute.asColor() );
} else if ( "borderwidth" == name ) {
setBorderWidth( attribute.asDpDimensionI("1") );
setBorderWidth( state, attribute.asDpDimensionI("1") );
} else if ( "bordercorners" == name || "backgroundcorners" == name ) {
setBackgroundCorners( attribute.asUint() );
setBackgroundCorners( state, attribute.asUint() );
} else if ( "visible" == name ) {
setVisible( attribute.asBool() );
} else if ( "enabled" == name ) {

View File

@@ -29,7 +29,7 @@ UIWindow::UIWindow( UIWindow::WindowBaseContainerType type ) :
{}
UIWindow::UIWindow( UIWindow::WindowBaseContainerType type, const UIWindowStyleConfig& windowStyleConfig ) :
UIWidget(),
UIWidget( "window" ),
mFrameBuffer( NULL ),
mStyleConfig( windowStyleConfig ),
mWindowDecoration( NULL ),
@@ -1412,7 +1412,7 @@ void UIWindow::resizeCursor() {
}
}
bool UIWindow::setAttribute( const NodeAttribute& attribute ) {
bool UIWindow::setAttribute( const NodeAttribute& attribute, const Uint32& state ) {
const std::string& name = attribute.getName();
if ( "width" == name ) {
@@ -1453,7 +1453,7 @@ bool UIWindow::setAttribute( const NodeAttribute& attribute ) {
setWinFlags( winflags );
}
} else {
return UIWidget::setAttribute( attribute );
return UIWidget::setAttribute( attribute, state );
}
return true;

View File

@@ -12,7 +12,7 @@ UIWinMenu * UIWinMenu::New() {
}
UIWinMenu::UIWinMenu() :
UIWidget(),
UIWidget( "winmenu" ),
mCurrentMenu( NULL )
{
if ( !(mFlags & UI_ANCHOR_RIGHT) )

View File

@@ -599,6 +599,12 @@ void EETest::createUI() {
sceneNode->setTranslator( mTranslator );
CSS::StyleSheetParser styleSheetParser;
if ( styleSheetParser.loadFromFile( MyPath + "ui/css/style.css" ) ) {
sceneNode->setStyleSheet( styleSheetParser.getStyleSheet() );
}
SceneManager::instance()->add( sceneNode );
eePRINTL("Node size: %d", sizeof(Node));