Started working on removing the CreateParams and supporting different pixel densities.

--HG--
branch : dev
This commit is contained in:
Martí­n Lucas Golini
2017-02-21 23:18:15 -03:00
parent c9dbf5f6e5
commit cab7e5cda1
40 changed files with 562 additions and 99 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 305 B

After

Width:  |  Height:  |  Size: 280 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 295 B

After

Width:  |  Height:  |  Size: 270 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 272 B

After

Width:  |  Height:  |  Size: 256 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 259 B

After

Width:  |  Height:  |  Size: 235 B

View File

@@ -106,31 +106,49 @@ tRECT<T>& operator -=(tRECT<T>& R, T X) {
return R;
}
template <typename T>
tRECT<T> operator *(const tRECT<T>& R, T X) {
return tRECT<T>(R.Left * X, R.Top * X, R.Right * X, R.Bottom * X);
template <typename T, typename Y>
tRECT<T> operator *(const tRECT<T>& R, Y X) {
return tRECT<T>((T)((Y)R.Left * X), (T)((Y)R.Top * X), (T)((Y)R.Right * X), (T)((Y)R.Bottom * X));
}
template <typename T>
tRECT<T>& operator *=(tRECT<T>& R, T X) {
R.Left *= X;
R.Top *= X;
R.Right *= X;
R.Bottom *= X;
template <typename T, typename Y>
tRECT<T>& operator *=(tRECT<T>& R, Y X) {
R.Left = (T)((Y)R.Left * X );
R.Top = (T)((Y)R.Top * X );
R.Right = (T)((Y)R.Right * X );
R.Bottom = (T)((Y)R.Bottom * X );
return R;
}
template <typename T>
tRECT<T> operator /(const tRECT<T>& R, T X) {
return tRECT<T>(R.Left / X, R.Top / X, R.Right / X, R.Bottom / X);
template <typename T, typename Y>
tRECT<T>& operator *(tRECT<T>& R, Y X) {
R.Left = (T)((Y)R.Left * X );
R.Top = (T)((Y)R.Top * X );
R.Right = (T)((Y)R.Right * X );
R.Bottom = (T)((Y)R.Bottom * X );
return R;
}
template <typename T>
tRECT<T>& operator /=(tRECT<T>& R, T X) {
R.Left /= X;
R.Top /= X;
R.Right /= X;
R.Bottom /= X;
template <typename T, typename Y>
tRECT<T> operator /(const tRECT<T>& R, Y X) {
return tRECT<T>((T)((Y)R.Left / X), (T)((Y)R.Top / X), (T)((Y)R.Right / X), (T)((Y)R.Bottom / X));
}
template <typename T, typename Y>
tRECT<T>& operator /=(tRECT<T>& R, Y X) {
R.Left = (T)((Y)R.Left / X );
R.Top = (T)((Y)R.Top / X );
R.Right = (T)((Y)R.Right / X );
R.Bottom = (T)((Y)R.Bottom / X );
return R;
}
template <typename T, typename Y>
tRECT<T>& operator /(tRECT<T>& R, Y X) {
R.Left = (T)((Y)R.Left / X );
R.Top = (T)((Y)R.Top / X );
R.Right = (T)((Y)R.Right / X );
R.Bottom = (T)((Y)R.Bottom / X );
return R;
}

View File

@@ -10,6 +10,8 @@ class EE_API UICheckBox : public UITextBox {
public:
UICheckBox( const UITextBox::CreateParams& Params );
UICheckBox();
virtual ~UICheckBox();
virtual Uint32 getType() const;
@@ -27,11 +29,16 @@ class EE_API UICheckBox : public UITextBox {
UIControlAnim * getActiveButton() const;
UIControlAnim * getInactiveButton() const;
Int32 getTextSeparation() const;
void setTextSeparation(const Int32 & textSeparation);
protected:
UIControlAnim * mActiveButton;
UIControlAnim * mInactiveButton;
bool mActive;
Uint32 mLastTick;
Int32 mTextSeparation;
virtual void onSizeChange();

View File

@@ -39,6 +39,8 @@ class EE_API UIComplexControl : public UIControlAnim {
UIComplexControl( const UIComplexControl::CreateParams& Params );
UIComplexControl();
virtual ~UIComplexControl();
virtual Uint32 getType() const;

View File

@@ -22,6 +22,8 @@ class UIManager;
class EE_API UIControl {
public:
static Float PixelDensity;
typedef cb::Callback1<void, const UIEvent*> UIEventCallback;
class CreateParams {
@@ -72,6 +74,8 @@ class EE_API UIControl {
UIControl( const CreateParams& Params );
UIControl();
virtual ~UIControl();
void screenToControl( Vector2i& position ) const;
@@ -96,12 +100,16 @@ class EE_API UIControl {
const Vector2i& getPosition() const;
const Vector2i& getRealPosition() const;
virtual void setSize( const Sizei& size );
void setSize( const Int32& Width, const Int32& Height );
const Sizei& getSize();
const Sizei& getRealSize();
Recti getRect() const;
void setVisible( const bool& visible );
@@ -140,9 +148,9 @@ class EE_API UIControl {
void setVerticalAlign( Uint32 valign );
void setBackgroundFillEnabled( bool enabled );
UIBackground * setBackgroundFillEnabled( bool enabled );
void setBorderEnabled( bool enabled );
UIBorder * setBorderEnabled( bool enabled );
UIControl * getNextControl() const;
@@ -246,17 +254,19 @@ class EE_API UIControl {
friend class UIWindow;
Vector2i mPos;
Vector2i mRealPos;
Vector2i mScreenPos;
Vector2f mScreenPosf;
Sizei mSize;
Sizei mRealSize;
Uint32 mFlags;
UintPtr mData;
UIControl * mParentCtrl;
UIControl * mChild; //! Pointer to the first child of the control
UIControl * mParentCtrl;
UIControl * mChild; //! Pointer to the first child of the control
UIControl * mChildLast; //! Pointer to the last child added
UIControl * mNext; //! Pointer to the next child of the father
UIControl * mNext; //! Pointer to the next child of the father
UIControl * mPrev; //! Pointer to the prev child of the father
UISkinState * mSkinState;
@@ -267,7 +277,7 @@ class EE_API UIControl {
Uint16 mBlend;
Uint16 mNumCallBacks;
Polygon2f mPoly;
Polygon2f mPoly;
Vector2f mCenter;
UIEventsMap mEvents;
@@ -386,6 +396,42 @@ class EE_API UIControl {
Sizei getSkinSize( UISkin * Skin, const Uint32& State = UISkinState::StateNormal );
Rectf getRectf();
void setInternalPosition( const Vector2i& Pos );
void setInternalSize( const Sizei& size );
void setInternalWidth( const Int32& width );
void setInternalHeight( const Int32& height );
void setInternalPosX( const Int32& x );
void setInternalPosY( const Int32& y );
Float pxToDp( Float px );
Int32 pxToDpI( Float px );
Float dpToPx( Float dp );
Int32 dpToPxI( Float dp );
Sizei dpToPxI(Sizei size);
Sizei pxToDpI( Sizei size );
Recti dpToPxI( Recti size);
Recti pxToDpI( Recti size );
Sizef dpToPx( Sizef size);
Sizef pxToDp( Sizef size );
Sizei dpToPxI( Sizef size);
Sizei pxToDpI( Sizef size );
};
}}

View File

@@ -11,6 +11,8 @@ class EE_API UIControlAnim : public UIDragable {
public:
UIControlAnim( const CreateParams& Params );
UIControlAnim();
virtual ~UIControlAnim();
virtual Uint32 getType() const;

View File

@@ -9,6 +9,8 @@ class EE_API UIDragable : public UIControl {
public:
UIDragable( const UIControl::CreateParams& Params );
UIDragable();
virtual Uint32 getType() const;
virtual bool isType( const Uint32& type ) const;

View File

@@ -26,6 +26,8 @@ class EE_API UIGfx : public UIComplexControl {
UIGfx( const UIGfx::CreateParams& Params );
UIGfx();
virtual ~UIGfx();
virtual Uint32 getType() const;
@@ -42,7 +44,7 @@ class EE_API UIGfx : public UIComplexControl {
const ColorA& getColor() const;
void serColor( const ColorA& col );
void setColor( const ColorA& col );
const EE_RENDER_MODE& getRenderMode() const;

View File

@@ -10,6 +10,8 @@ class EE_API UIRadioButton : public UITextBox {
public:
UIRadioButton( const UITextBox::CreateParams& Params );
UIRadioButton();
virtual ~UIRadioButton();
virtual Uint32 getType() const;
@@ -27,11 +29,16 @@ class EE_API UIRadioButton : public UITextBox {
UIControlAnim * getActiveButton() const;
UIControlAnim * getInactiveButton() const;
Int32 getTextSeparation() const;
void setTextSeparation(const Int32 & textSeparation);
protected:
UIControlAnim * mActiveButton;
UIControlAnim * mInactiveButton;
bool mActive;
Uint32 mLastTick;
Int32 mTextSeparation;
virtual void onSizeChange();

View File

@@ -27,6 +27,8 @@ class EE_API UISlider : public UIComplexControl {
UISlider( const UISlider::CreateParams& Params );
UISlider();
virtual ~UISlider();
virtual Uint32 getType() const;
@@ -73,7 +75,7 @@ class EE_API UISlider : public UIComplexControl {
bool mAllowHalfSliderOut;
bool mExpandBackground;
UIControlAnim * mBackSlider;
UIControlAnim * mSlider;
Private::UISliderButton * mSlider;
Float mMinValue;
Float mMaxValue;
Float mValue;

View File

@@ -9,6 +9,8 @@ class EE_API UISliderButton : public UIControlAnim {
public:
UISliderButton( const UIControlAnim::CreateParams& Params );
UISliderButton();
virtual ~UISliderButton();
protected:
virtual void onPositionChange();

View File

@@ -38,6 +38,8 @@ class EE_API UITextBox : public UIComplexControl {
UITextBox( const UITextBox::CreateParams& Params );
UITextBox();
virtual ~UITextBox();
virtual Uint32 getType() const;
@@ -56,13 +58,13 @@ class EE_API UITextBox : public UIComplexControl {
virtual void setText( const String& text );
const ColorA& getColor() const;
const ColorA& getFontColor() const;
void setColor( const ColorA& color );
void setFontColor( const ColorA& color );
const ColorA& getShadowColor() const;
const ColorA& getFontShadowColor() const;
void setShadowColor( const ColorA& color );
void setFontShadowColor( const ColorA& color );
const ColorA& getSelectionBackColor() const;
@@ -95,6 +97,7 @@ class EE_API UITextBox : public UIComplexControl {
ColorA mFontSelectionBackColor;
Vector2f mAlignOffset;
Recti mPadding;
Recti mRealPadding;
Int32 mSelCurInit;
Int32 mSelCurEnd;

View File

@@ -28,6 +28,8 @@ class EE_API UITextInput : public UITextBox {
UITextInput( const UITextInput::CreateParams& Params );
UITextInput();
virtual ~UITextInput();
virtual Uint32 getType() const;

View File

@@ -60,7 +60,7 @@ class EE_API UITheme : protected ResourceManager<UISkin> {
void addThemeIcon( const std::string& Icon );
UITheme( const std::string& getName, const std::string& abbr, Graphics::Font * defaultFont = NULL );
UITheme( const std::string& name, const std::string& abbr, Graphics::Font * defaultFont = NULL );
virtual ~UITheme();

View File

@@ -7,7 +7,8 @@ namespace EE { namespace UI {
UICheckBox::UICheckBox( const UITextBox::CreateParams& Params ) :
UITextBox( Params ),
mActive( false )
mActive( false ),
mTextSeparation( 4 )
{
UIControlAnim::CreateParams ButtonParams( Params );
@@ -28,6 +29,31 @@ UICheckBox::UICheckBox( const UITextBox::CreateParams& Params ) :
applyDefaultTheme();
}
UICheckBox::UICheckBox() :
UITextBox(),
mActive( false ),
mTextSeparation( dpToPxI( 4 ) )
{
mActiveButton = eeNew( UIControlAnim, () );
mActiveButton->setVisible( false );
mActiveButton->setEnabled( true );
mActiveButton->setParent( this );
mActiveButton->setPosition( 0, 0 );
mActiveButton->setSize( dpToPxI( 16 ), dpToPxI( 16 ) );
mInactiveButton = eeNew( UIControlAnim, () );
mInactiveButton->setVisible( true );
mInactiveButton->setEnabled( true );
mInactiveButton->setParent( this );
mInactiveButton->setPosition( 0, 0 );
mInactiveButton->setSize( dpToPxI( 16 ), dpToPxI( 16 ) );
setPadding( Recti(0,0,0,0) );
applyDefaultTheme();
}
UICheckBox::~UICheckBox() {
}
@@ -56,7 +82,7 @@ void UICheckBox::doAftersetTheme() {
tSubTexture = tSkin->getSubTexture( UISkinState::StateNormal );
if ( NULL != tSubTexture ) {
mActiveButton->setSize( tSubTexture->getRealSize() );
mActiveButton->setSize( dpToPxI( tSubTexture->getRealSize() ) );
mActiveButton->centerVertical();
}
}
@@ -67,7 +93,7 @@ void UICheckBox::doAftersetTheme() {
tSubTexture = tSkin->getSubTexture( UISkinState::StateNormal );
if ( NULL != tSubTexture ) {
mInactiveButton->setSize( tSubTexture->getRealSize() );
mInactiveButton->setSize( dpToPxI( tSubTexture->getRealSize() ) );
mInactiveButton->centerVertical();
}
}
@@ -82,7 +108,7 @@ void UICheckBox::autoSize() {
mActiveButton->centerVertical();
mInactiveButton->centerVertical();
mSize.setWidth( (int)mTextCache->getTextWidth() + mActiveButton->getSize().getWidth() );
setInternalWidth( (int)mTextCache->getTextWidth() + mActiveButton->getSize().getWidth() );
}
}
@@ -136,8 +162,12 @@ const bool& UICheckBox::isActive() const {
}
void UICheckBox::setPadding( const Recti& padding ) {
mPadding = padding;
mPadding.Left = mPadding.Left + mActiveButton->getSize().getWidth();
UITextBox::setPadding( padding );
mActiveButton->setPosition( mPadding.Left, mActiveButton->getPosition().y );
mInactiveButton->setPosition( mPadding.Left, mInactiveButton->getPosition().y );
mRealPadding.Left = mActiveButton->getPosition().x + mActiveButton->getSize().getWidth() + dpToPxI( mTextSeparation );
}
UIControlAnim * UICheckBox::getActiveButton() const {
@@ -148,6 +178,16 @@ UIControlAnim * UICheckBox::getInactiveButton() const {
return mInactiveButton;
}
Int32 UICheckBox::getTextSeparation() const {
return mTextSeparation;
}
void UICheckBox::setTextSeparation(const Int32 & textSeparation) {
mTextSeparation = textSeparation;
setPadding( getPadding() );
}
Uint32 UICheckBox::onKeyDown( const UIEventKey& Event ) {
UITextBox::onKeyDown( Event );

View File

@@ -15,6 +15,16 @@ UIComplexControl::UIComplexControl( const UIComplexControl::CreateParams& Params
setTooltipText( Params.TooltipText );
}
UIComplexControl::UIComplexControl() :
UIControlAnim(),
mTooltip( NULL ),
mMinControlSize()
{
mControlFlags |= UI_CTRL_FLAG_COMPLEX;
updateAnchorsDistances();
}
UIComplexControl::~UIComplexControl() {
eeSAFE_DELETE( mTooltip );
}
@@ -29,7 +39,7 @@ bool UIComplexControl::isType( const Uint32& type ) const {
void UIComplexControl::updateAnchorsDistances() {
if ( NULL != mParentCtrl ) {
mDistToBorder = Recti( mPos.x, mPos.y, mParentCtrl->getSize().x - ( mPos.x + mSize.x ), mParentCtrl->getSize().y - ( mPos.y + mSize.y ) );
mDistToBorder = Recti( mPos.x, mPos.y, mParentCtrl->getRealSize().x - ( mPos.x + mSize.x ), mParentCtrl->getRealSize().y - ( mPos.y + mSize.y ) );
}
}

View File

@@ -7,6 +7,8 @@
namespace EE { namespace UI {
Float UIControl::PixelDensity = 1;
UIControl::UIControl( const CreateParams& Params ) :
mPos( Params.Pos ),
mSize( Params.Size ),
@@ -43,6 +45,33 @@ UIControl::UIControl( const CreateParams& Params ) :
updateQuad();
}
UIControl::UIControl() :
mPos(),
mSize(),
mFlags( UI_CONTROL_DEFAULT_FLAGS ),
mData( 0 ),
mParentCtrl( NULL ),
mChild( NULL ),
mChildLast( NULL ),
mNext( NULL ),
mPrev( NULL ),
mSkinState( NULL ),
mBackground( NULL ),
mBorder( NULL ),
mControlFlags( 0 ),
mBlend( ALPHA_NORMAL ),
mNumCallBacks( 0 ),
mVisible( false ),
mEnabled( false )
{
if ( NULL == mParentCtrl && NULL != UIManager::instance()->getMainControl() ) {
mParentCtrl = UIManager::instance()->getMainControl();
}
if ( NULL != mParentCtrl )
mParentCtrl->childAdd( this );
}
UIControl::~UIControl() {
safeDeleteSkinState();
eeSAFE_DELETE( mBackground );
@@ -118,27 +147,38 @@ bool UIControl::isInside( const Vector2i& Pos ) const {
return ( Pos.x >= 0 && Pos.y >= 0 && Pos.x < mSize.getWidth() && Pos.y < mSize.getHeight() );
}
void UIControl::setPosition( const Vector2i& Pos ) {
void UIControl::setInternalPosition( const Vector2i& Pos ) {
mPos = Pos;
mRealPos = Vector2i( Pos.x * PixelDensity, Pos.y * PixelDensity );
}
void UIControl::setPosition( const Vector2i& Pos ) {
setInternalPosition( Pos );
onPositionChange();
}
void UIControl::setPosition( const Int32& x, const Int32& y ) {
mPos = Vector2i( x, y );
onPositionChange();
setPosition( Vector2i( x, y ) );
}
const Vector2i& UIControl::getPosition() const {
return mPos;
}
const Vector2i &UIControl::getRealPosition() const {
return mRealPos;
}
void UIControl::setInternalSize( const Sizei& size ) {
mSize = size;
mRealSize = Sizei( size.x * PixelDensity, size.y * PixelDensity );
}
void UIControl::setSize( const Sizei& Size ) {
if ( Size != mSize ) {
Vector2i sizeChange( Size.x - mSize.x, Size.y - mSize.y );
mSize = Size;
setInternalSize( Size );
onSizeChange();
@@ -160,6 +200,26 @@ const Sizei& UIControl::getSize() {
return mSize;
}
const Sizei& UIControl::getRealSize() {
return mRealSize;
}
void UIControl::setInternalWidth( const Int32& width ) {
setInternalSize( Sizei( width, mSize.y ) );
}
void UIControl::setInternalHeight( const Int32& height ) {
setInternalSize( Sizei( mSize.x, height ) );
}
void UIControl::setInternalPosX( const Int32& x ) {
setInternalPosition( Vector2i( x, mPos.y ) );
}
void UIControl::setInternalPosY( const Int32& y ) {
setInternalPosition( Vector2i( mPos.x, y ) );
}
void UIControl::setVisible( const bool& visible ) {
mVisible = visible;
onVisibleChange();
@@ -415,15 +475,17 @@ void UIControl::setVerticalAlign( Uint32 valign ) {
mFlags |= valign & UI_VALIGN_MASK;
}
void UIControl::setBackgroundFillEnabled( bool enabled ) {
UIBackground * UIControl::setBackgroundFillEnabled( bool enabled ) {
writeFlag( UI_FILL_BACKGROUND, enabled ? 1 : 0 );
if ( enabled && NULL == mBackground ) {
mBackground = eeNew( UIBackground, () );
}
return mBackground;
}
void UIControl::setBorderEnabled( bool enabled ) {
UIBorder * UIControl::setBorderEnabled( bool enabled ) {
writeFlag( UI_BORDER, enabled ? 1 : 0 );
if ( enabled && NULL == mBorder ) {
@@ -433,6 +495,8 @@ void UIControl::setBorderEnabled( bool enabled ) {
mBackground = eeNew( UIBackground, () );
}
}
return mBorder;
}
UIControl * UIControl::getNextControl() const {
@@ -464,6 +528,13 @@ const Uint32& UIControl::getFlags() const {
void UIControl::setFlags( const Uint32& flags ) {
mFlags |= flags;
if ( NULL == mBackground && ( mFlags & UI_FILL_BACKGROUND ) )
mBackground = eeNew( UIBackground, () );
if ( NULL == mBorder && ( mFlags & UI_BORDER ) )
mBorder = eeNew( UIBorder, () );
}
void UIControl::setBlendMode( const EE_BLEND_MODE& blend ) {
@@ -525,6 +596,54 @@ Rectf UIControl::getRectf() {
return Rectf( mScreenPosf, Sizef( (Float)mSize.getWidth(), (Float)mSize.getHeight() ) );
}
Float UIControl::dpToPx( Float dp ) {
return dp * 1;
}
Int32 UIControl::dpToPxI( Float dp ) {
return (Int32)dpToPx( dp );
}
Float UIControl::pxToDp( Float px ) {
return px / 1;
}
Int32 UIControl::pxToDpI( Float px ) {
return (Int32)pxToDp( px );
}
Sizei UIControl::dpToPxI( Sizei size ) {
return Sizei( dpToPxI( size.x ), dpToPxI( size.y ) );
}
Sizei UIControl::pxToDpI( Sizei size ) {
return Sizei( pxToDpI( size.x ), pxToDpI( size.y ) );
}
Recti UIControl::dpToPxI( Recti rect ) {
return rect * 1;
}
Recti UIControl::pxToDpI( Recti rect ) {
return rect / 1;
}
Sizef UIControl::dpToPx( Sizef size ) {
return size * 1.f;
}
Sizef UIControl::pxToDp( Sizef size ) {
return size * 1.f;
}
Sizei UIControl::dpToPxI( Sizef size ) {
return Sizei( dpToPxI( size.x ), dpToPxI( size.y ) );
}
Sizei UIControl::pxToDpI( Sizef size ) {
return Sizei( pxToDpI( size.x ), pxToDpI( size.y ) );
}
void UIControl::backgroundDraw() {
Primitives P;
Rectf R = getRectf();

View File

@@ -21,6 +21,21 @@ UIControlAnim::UIControlAnim( const CreateParams& Params ) :
updateOriginPoint();
}
UIControlAnim::UIControlAnim() :
UIDragable(),
mAngle(0.f),
mScale(1.f,1.f),
mAlpha(255.f),
mAngleAnim(NULL),
mScaleAnim(NULL),
mAlphaAnim(NULL),
mMoveAnim(NULL)
{
mControlFlags |= UI_CTRL_FLAG_ANIM;
updateOriginPoint();
}
UIControlAnim::~UIControlAnim() {
eeSAFE_DELETE( mAlphaAnim );
eeSAFE_DELETE( mAngleAnim );

View File

@@ -11,6 +11,13 @@ UIDragable::UIDragable( const UIControl::CreateParams& Params ) :
mControlFlags |= UI_CTRL_FLAG_DRAGABLE;
}
UIDragable::UIDragable() :
UIControl(),
mDragButton( EE_BUTTON_LMASK )
{
mControlFlags |= UI_CTRL_FLAG_DRAGABLE;
}
UIDragable::~UIDragable() {
}

View File

@@ -18,6 +18,16 @@ UIGfx::UIGfx( const UIGfx::CreateParams& Params ) :
autoSize();
}
UIGfx::UIGfx() :
UIComplexControl(),
mSubTexture( NULL ),
mColor(),
mRender( RN_NORMAL ),
mAlignOffset(0,0)
{
mFlags |= UI_FIT_TO_CONTROL;
}
UIGfx::~UIGfx() {
}
@@ -33,6 +43,11 @@ void UIGfx::setSubTexture( Graphics::SubTexture * subTexture ) {
mSubTexture = subTexture;
autoSize();
if ( NULL != mSubTexture && mSize.x == 0 && mSize.y == 0 ) {
setSize( dpToPxI( mSubTexture->getDestSize() ) );
}
autoAlign();
}
@@ -112,7 +127,7 @@ const ColorA& UIGfx::getColor() const {
return mColor;
}
void UIGfx::serColor( const ColorA& col ) {
void UIGfx::setColor( const ColorA& col ) {
mColor = col;
setAlpha( col.a() );
}
@@ -130,17 +145,17 @@ void UIGfx::autoAlign() {
return;
if ( HAlignGet( mFlags ) == UI_HALIGN_CENTER ) {
mAlignOffset.x = mSize.getWidth() / 2 - mSubTexture->getDestSize().x / 2;
mAlignOffset.x = mSize.getWidth() / 2 - dpToPxI( mSubTexture->getDestSize().x ) / 2;
} else if ( fontHAlignGet( mFlags ) == UI_HALIGN_RIGHT ) {
mAlignOffset.x = mSize.getWidth() - mSubTexture->getDestSize().x;
mAlignOffset.x = mSize.getWidth() - dpToPxI( mSubTexture->getDestSize().x );
} else {
mAlignOffset.x = 0;
}
if ( VAlignGet( mFlags ) == UI_VALIGN_CENTER ) {
mAlignOffset.y = mSize.getHeight() / 2 - mSubTexture->getDestSize().y / 2;
mAlignOffset.y = mSize.getHeight() / 2 - dpToPxI( mSubTexture->getDestSize().y ) / 2;
} else if ( fontVAlignGet( mFlags ) == UI_VALIGN_BOTTOM ) {
mAlignOffset.y = mSize.getHeight() - mSubTexture->getDestSize().y;
mAlignOffset.y = mSize.getHeight() - dpToPxI( mSubTexture->getDestSize().y );
} else {
mAlignOffset.y = 0;
}

View File

@@ -673,7 +673,7 @@ void UIListBox::setFontColor( const ColorA& Color ) {
mFontColor = Color;
for ( Uint32 i = 0; i < mItems.size(); i++ )
mItems[i]->setColor( mFontColor );
mItems[i]->setFontColor( mFontColor );
}
const ColorA& UIListBox::getFontColor() const {

View File

@@ -116,11 +116,11 @@ void UIListBoxItem::onStateChange() {
}
if ( mSkinState->getState() == UISkinState::StateSelected ) {
setColor( LBParent->getFontSelectedColor() );
setFontColor( LBParent->getFontSelectedColor() );
} else if ( mSkinState->getState() == UISkinState::StateMouseEnter ) {
setColor( LBParent->getFontOverColor() );
setFontColor( LBParent->getFontOverColor() );
} else {
setColor( LBParent->getFontColor() );
setFontColor( LBParent->getFontColor() );
}
}

View File

@@ -37,11 +37,11 @@ void UIMenuItem::onStateChange() {
UIMenu * tMenu = reinterpret_cast<UIMenu*> ( getParent() );
if ( mSkinState->getState() == UISkinState::StateSelected ) {
mTextBox->setColor( tMenu->mFontSelectedColor );
mTextBox->setFontColor( tMenu->mFontSelectedColor );
} else if ( mSkinState->getState() == UISkinState::StateMouseEnter ) {
mTextBox->setColor( tMenu->mFontOverColor );
mTextBox->setFontColor( tMenu->mFontOverColor );
} else {
mTextBox->setColor( tMenu->mFontColor );
mTextBox->setFontColor( tMenu->mFontColor );
}
}

View File

@@ -100,17 +100,17 @@ void UIPushButton::onSizeChange() {
if ( NULL != mTextBox ) {
Recti P = makePadding();
mSize.setHeight( mIcon->getSize().getHeight() + P.Top + P.Bottom );
setInternalHeight( mIcon->getSize().getHeight() + P.Top + P.Bottom );
if ( 0 == mTextBox->getText().size() ) {
mSize.setWidth ( mIcon->getSize().getWidth() + P.Left + P.Right );
setInternalWidth( mIcon->getSize().getWidth() + P.Left + P.Right );
mIcon->center();
} else {
mSize.setWidth( mIconSpace + mIcon->setPosition(.x + mIcon->getSize().getWidth() + mTextBox->getSize().getWidth() );
setInternalWidth( mIconSpace + mIcon->setPosition(.x + mIcon->getSize().getWidth() + mTextBox->getSize().getWidth() );
if ( mSize.getHeight() < P.Top + P.Bottom + mTextBox->getTextHeight() )
mSize.setHeight( P.Top + P.Bottom + mTextBox->getTextHeight() );
setInternalHeight( P.Top + P.Bottom + mTextBox->getTextHeight() );
}
}
} else {
@@ -137,7 +137,7 @@ void UIPushButton::doAftersetTheme() {
}
if ( mFlags & UI_AUTO_SIZE ) {
mSize.setHeight( getSkinSize().getHeight() );
setInternalHeight( getSkinSize().getHeight() );
}
autoPadding();
@@ -199,9 +199,9 @@ void UIPushButton::onAlphaChange() {
void UIPushButton::onStateChange() {
if ( mSkinState->getState() == UISkinState::StateMouseEnter ) {
mTextBox->setColor( mFontOverColor );
mTextBox->setFontColor( mFontOverColor );
} else {
mTextBox->setColor( mFontColor );
mTextBox->setFontColor( mFontColor );
}
mTextBox->setAlpha( mAlpha );

View File

@@ -9,7 +9,8 @@ UIRadioButton::UIRadioButton( const UITextBox::CreateParams& Params ) :
UITextBox( Params ),
mActiveButton(NULL),
mInactiveButton(NULL),
mActive( false )
mActive( false ),
mTextSeparation( 4 )
{
UIControlAnim::CreateParams ButtonParams( Params );
@@ -32,6 +33,32 @@ UIRadioButton::UIRadioButton( const UITextBox::CreateParams& Params ) :
applyDefaultTheme();
}
UIRadioButton::UIRadioButton() :
UITextBox(),
mActiveButton(NULL),
mInactiveButton(NULL),
mActive( false ),
mTextSeparation( dpToPxI( 4 ) )
{
mActiveButton = eeNew( UIControlAnim, () );
mActiveButton->setVisible( false );
mActiveButton->setEnabled( true );
mActiveButton->setParent( this );
mActiveButton->setPosition( 0, 0 );
mActiveButton->setSize( dpToPxI( 16 ), dpToPxI( 16 ) );
mInactiveButton = eeNew( UIControlAnim, () );
mInactiveButton->setVisible( true );
mInactiveButton->setEnabled( true );
mInactiveButton->setParent( this );
mInactiveButton->setPosition( 0, 0 );
mInactiveButton->setSize( dpToPxI( 16 ), dpToPxI( 16 ) );
setPadding( Recti(0,0,0,0) );
applyDefaultTheme();
}
UIRadioButton::~UIRadioButton() {
}
@@ -56,7 +83,7 @@ void UIRadioButton::setTheme( UITheme * Theme ) {
tSubTexture = tSkin->getSubTexture( UISkinState::StateNormal );
if ( NULL != tSubTexture ) {
mActiveButton->setSize( tSubTexture->getRealSize() );
mActiveButton->setSize( dpToPxI( tSubTexture->getRealSize() ) );
mActiveButton->centerVertical();
}
}
@@ -67,7 +94,7 @@ void UIRadioButton::setTheme( UITheme * Theme ) {
tSubTexture = tSkin->getSubTexture( UISkinState::StateNormal );
if ( NULL != tSubTexture ) {
mInactiveButton->setSize( tSubTexture->getRealSize() );
mInactiveButton->setSize( dpToPxI( tSubTexture->getRealSize() ) );
mInactiveButton->centerVertical();
}
}
@@ -82,7 +109,7 @@ void UIRadioButton::autoSize() {
mActiveButton->centerVertical();
mInactiveButton->centerVertical();
mSize.setWidth( (int)mTextCache->getTextWidth() + mActiveButton->getSize().getWidth() );
setInternalWidth( (int)mTextCache->getTextWidth() + mActiveButton->getSize().getWidth() );
}
}
@@ -202,8 +229,12 @@ const bool& UIRadioButton::isActive() const {
}
void UIRadioButton::setPadding( const Recti& padding ) {
mPadding = padding;
mPadding.Left = mPadding.Left + mActiveButton->getSize().getWidth();
UITextBox::setPadding( padding );
mActiveButton->setPosition( mPadding.Left, mActiveButton->getPosition().y );
mInactiveButton->setPosition( mPadding.Left, mInactiveButton->getPosition().y );
mRealPadding.Left = mActiveButton->getPosition().x + mActiveButton->getSize().getWidth() + dpToPxI( mTextSeparation );
}
UIControlAnim * UIRadioButton::getActiveButton() const {
@@ -214,6 +245,16 @@ UIControlAnim * UIRadioButton::getInactiveButton() const {
return mInactiveButton;
}
Int32 UIRadioButton::getTextSeparation() const {
return mTextSeparation;
}
void UIRadioButton::setTextSeparation(const Int32 & textSeparation) {
mTextSeparation = textSeparation;
setPadding( getPadding() );
}
Uint32 UIRadioButton::onKeyDown( const UIEventKey& Event ) {
if ( Event.getKeyCode() == KEY_SPACE ) {
if ( Sys::getTicks() - mLastTick > 250 ) {

View File

@@ -54,11 +54,11 @@ void UISelectButton::onStateChange() {
UIWinMenu * Menu = reinterpret_cast<UIWinMenu*> ( getParent() );
if ( mSkinState->getState() == UISkinState::StateSelected ) {
getTextBox()->setColor( Menu->getFontSelectedColor() );
getTextBox()->setFontColor( Menu->getFontSelectedColor() );
} else if ( mSkinState->getState() == UISkinState::StateMouseEnter ) {
getTextBox()->setColor( Menu->getFontOverColor() );
getTextBox()->setFontColor( Menu->getFontOverColor() );
} else {
getTextBox()->setColor( Menu->getFontColor() );
getTextBox()->setFontColor( Menu->getFontColor() );
}
}
}

View File

@@ -48,6 +48,49 @@ UISlider::UISlider( const UISlider::CreateParams& Params ) :
applyDefaultTheme();
}
UISlider::UISlider() :
UIComplexControl(),
mVertical( true ),
mAllowHalfSliderOut( false ),
mExpandBackground( false ),
mBackSlider( NULL ),
mSlider( NULL ),
mMinValue( 0.f ),
mMaxValue( 1.f ),
mValue( 0.f ),
mClickStep( 0.1f ),
mOnPosChange( false )
{
Sizei bgSize;
if ( !mVertical )
bgSize = dpToPxI( Sizei( mSize.getWidth() - 16, 8 ) );
else
bgSize = dpToPxI( Sizei( 8, mSize.getWidth() - 16 ) );
mBackSlider = eeNew( UIControlAnim, () );
mBackSlider->setParent( this );
mBackSlider->setVisible( true );
mBackSlider->setEnabled( true );
mBackSlider->setSize( bgSize );
mBackSlider->center();
mSlider = eeNew( Private::UISliderButton, () );
mSlider->setParent( this );
mSlider->setEnabled( true );
mSlider->setVisible( true );
mSlider->setDragEnabled( true );
mSlider->setSize( dpToPxI( 16 ), dpToPxI( 16 ) );
mSlider->setPosition( 0, 0 );
if ( !mVertical )
mSlider->centerVertical();
else
mSlider->centerHorizontal();
applyDefaultTheme();
}
UISlider::~UISlider() {
}
@@ -134,6 +177,8 @@ void UISlider::adjustChilds() {
}
mBackSlider->center();
fixSliderPos();
}
}
}
@@ -172,8 +217,9 @@ void UISlider::fixSliderPos() {
if ( mSlider->getPosition().y > mBackSlider->getSize().getHeight() )
mSlider->setPosition( 0, mBackSlider->getSize().getHeight() );
} else {
if ( mSlider->getPosition().y > mBackSlider->getSize().getHeight() - mSlider->getSize().getHeight() )
if ( mSlider->getPosition().y > mBackSlider->getSize().getHeight() - mSlider->getSize().getHeight() ) {
mSlider->setPosition( 0, mBackSlider->getSize().getHeight() - mSlider->getSize().getHeight() );
}
}
mSlider->centerHorizontal();

View File

@@ -9,6 +9,12 @@ UISliderButton::UISliderButton( const UIControlAnim::CreateParams& Params ) :
applyDefaultTheme();
}
UISliderButton::UISliderButton() :
UIControlAnim()
{
applyDefaultTheme();
}
UISliderButton::~UISliderButton() {
}

View File

@@ -92,7 +92,7 @@ void UISpinBox::setTheme( UITheme * Theme ) {
}
if ( mFlags & UI_AUTO_SIZE ) {
mSize.setHeight( mInput->getSkinSize().getHeight() );
setInternalHeight( mInput->getSkinSize().getHeight() );
}
adjustChilds();

View File

@@ -73,11 +73,11 @@ void UITab::onStateChange() {
setSize( mSize.getWidth(), getSkinSize( getSkin(), mSkinState->getState() ).getHeight() );
if ( mSkinState->getState() == UISkinState::StateSelected ) {
mTextBox->setColor( tTabW->mFontSelectedColor );
mTextBox->setFontColor( tTabW->mFontSelectedColor );
} else if ( mSkinState->getState() == UISkinState::StateMouseEnter ) {
mTextBox->setColor( tTabW->mFontOverColor );
mTextBox->setFontColor( tTabW->mFontOverColor );
} else {
mTextBox->setColor( tTabW->mFontColor );
mTextBox->setFontColor( tTabW->mFontColor );
}
}
}

View File

@@ -32,6 +32,31 @@ UITextBox::UITextBox( const UITextBox::CreateParams& Params ) :
autoAlign();
}
UITextBox::UITextBox() :
UIComplexControl(),
mFontColor(),
mFontShadowColor(),
mFontSelectionBackColor(),
mAlignOffset( 0.f, 0.f ),
mSelCurInit( -1 ),
mSelCurEnd( -1 )
{
mTextCache = eeNew( TextCache, () );
if ( NULL != UIThemeManager::instance()->getDefaultFont() ) {
mTextCache->setFont( UIThemeManager::instance()->getDefaultFont() );
} else {
eePRINTL( "UITextBox::UITextBox : Created a UI TextBox without a defined font." );
}
if ( NULL != UIThemeManager::instance()->getDefaultTheme() ) {
mTextCache->setColor( UIThemeManager::instance()->getDefaultTheme()->getFontColor() );
mTextCache->setShadowColor( UIThemeManager::instance()->getDefaultTheme()->getFontShadowColor() );
}
autoAlign();
}
UITextBox::~UITextBox() {
eeSAFE_DELETE( mTextCache );
}
@@ -53,15 +78,15 @@ void UITextBox::draw() {
if ( mTextCache->getTextWidth() ) {
if ( mFlags & UI_CLIP_ENABLE ) {
UIManager::instance()->clipEnable(
mScreenPos.x + mPadding.Left,
mScreenPos.y + mPadding.Top,
mSize.getWidth() - mPadding.Left - mPadding.Right,
mSize.getHeight() - mPadding.Top - mPadding.Bottom
mScreenPos.x + mRealPadding.Left,
mScreenPos.y + mRealPadding.Top,
mSize.getWidth() - mRealPadding.Left - mRealPadding.Right,
mSize.getHeight() - mRealPadding.Top - mRealPadding.Bottom
);
}
mTextCache->setFlags( getFlags() );
mTextCache->draw( (Float)mScreenPos.x + mAlignOffset.x + (Float)mPadding.Left, (Float)mScreenPos.y + mAlignOffset.y + (Float)mPadding.Top, Vector2f::One, 0.f, getBlendMode() );
mTextCache->draw( (Float)mScreenPos.x + mAlignOffset.x + (Float)mRealPadding.Left, (Float)mScreenPos.y + mAlignOffset.y + (Float)mRealPadding.Top, Vector2f::One, 0.f, getBlendMode() );
if ( mFlags & UI_CLIP_ENABLE ) {
UIManager::instance()->clipDisable();
@@ -105,22 +130,22 @@ void UITextBox::setText( const String& text ) {
onTextChanged();
}
const ColorA& UITextBox::getColor() const {
const ColorA& UITextBox::getFontColor() const {
return mFontColor;
}
void UITextBox::setColor( const ColorA& color ) {
void UITextBox::setFontColor( const ColorA& color ) {
mFontColor = color;
mTextCache->setColor( color );
setAlpha( color.a() );
}
const ColorA& UITextBox::getShadowColor() const {
const ColorA& UITextBox::getFontShadowColor() const {
return mFontShadowColor;
}
void UITextBox::setShadowColor( const ColorA& color ) {
void UITextBox::setFontShadowColor( const ColorA& color ) {
mFontShadowColor = color;
mTextCache->setShadowColor( mFontColor );
}
@@ -157,8 +182,8 @@ void UITextBox::shrinkText( const Uint32& MaxWidth ) {
void UITextBox::autoSize() {
if ( mFlags & UI_AUTO_SIZE ) {
mSize.setWidth( (int)mTextCache->getTextWidth() );
mSize.setHeight( (int)mTextCache->getTextHeight() );
setInternalWidth( (int)mTextCache->getTextWidth() );
setInternalHeight( (int)mTextCache->getTextHeight() );
}
}
@@ -215,6 +240,7 @@ void UITextBox::onFontChanged() {
void UITextBox::setPadding( const Recti& padding ) {
mPadding = padding;
mRealPadding = dpToPxI( padding );
}
const Recti& UITextBox::getPadding() const {
@@ -333,10 +359,10 @@ void UITextBox::drawSelection() {
lastEnd = end;
}
P.drawRectangle( Rectf( mScreenPos.x + initPos.x + mAlignOffset.x + mPadding.Left,
mScreenPos.y + initPos.y - mTextCache->getFont()->getFontHeight() + mAlignOffset.y + mPadding.Top,
mScreenPos.x + endPos.x + mAlignOffset.x + mPadding.Left,
mScreenPos.y + endPos.y + mAlignOffset.y + mPadding.Top )
P.drawRectangle( Rectf( mScreenPos.x + initPos.x + mAlignOffset.x + mRealPadding.Left,
mScreenPos.y + initPos.y - mTextCache->getFont()->getFontHeight() + mAlignOffset.y + mRealPadding.Top,
mScreenPos.x + endPos.x + mAlignOffset.x + mRealPadding.Left,
mScreenPos.y + endPos.y + mAlignOffset.y + mRealPadding.Top )
);
} while ( end != lastEnd );
}

View File

@@ -24,6 +24,21 @@ UITextInput::UITextInput( const UITextInput::CreateParams& Params ) :
applyDefaultTheme();
}
UITextInput::UITextInput() :
UITextBox(),
mCursorPos(0),
mAllowEditing( true ),
mShowingWait( true )
{
mTextBuffer.start();
mTextBuffer.setActive( false );
mTextBuffer.setFreeEditing( true );
mTextBuffer.setTextSelectionEnabled( isTextSelectionEnabled() );
mTextBuffer.setReturnCallback( cb::Make0( this, &UITextInput::privOnPressEnter ) );
applyDefaultTheme();
}
UITextInput::~UITextInput() {
}

View File

@@ -319,9 +319,9 @@ bool UITheme::searchFilesOfElement( Graphics::TextureAtlas * SG, const std::stri
return Found;
}
UITheme::UITheme( const std::string& Name, const std::string& Abbr, Graphics::Font * defaultFont ) :
UITheme::UITheme(const std::string& name, const std::string& Abbr, Graphics::Font * defaultFont ) :
ResourceManager<UISkin> ( false ),
mName( Name ),
mName( name ),
mNameHash( String::hash( mName ) ),
mAbbr( Abbr ),
mTextureAtlas( NULL ),

View File

@@ -154,8 +154,8 @@ void UITooltip::setAlpha( const Float& alpha ) {
void UITooltip::autoSize() {
if ( mFlags & UI_AUTO_SIZE ) {
mSize.setWidth( (int)mTextCache->getTextWidth() + mPadding.Left + mPadding.Right );
mSize.setHeight( (int)mTextCache->getTextHeight() + mPadding.Top + mPadding.Bottom );
setInternalWidth( (int)mTextCache->getTextWidth() + mPadding.Left + mPadding.Right );
setInternalHeight( (int)mTextCache->getTextHeight() + mPadding.Top + mPadding.Bottom );
}
}

View File

@@ -58,7 +58,9 @@ void UIWinMenu::addMenuButton( const String& ButtonText, UIPopUpMenu * Menu ) {
Button->setText( ButtonText );
Button->setVisible( true );
Button->setEnabled( true );
Button->setThemeControl( mSkinState->getSkin()->getTheme(), "winmenubutton" );
if ( NULL != mSkinState && NULL != mSkinState->getSkin() )
Button->setThemeControl( mSkinState->getSkin()->getTheme(), "winmenubutton" );
Menu->setVisible( false );
Menu->setEnabled( false );

View File

@@ -254,6 +254,8 @@ void EETest::createUI() {
eePRINTL( "Texture Atlas Loading Time: %4.3f ms.", TE.getElapsed().asMilliseconds() );
UIControl::PixelDensity = 1;
UIManager::instance()->init(); //UI_MANAGER_HIGHLIGHT_FOCUS | UI_MANAGER_HIGHLIGHT_OVER
//mTheme = UITheme::LoadFromPath( eeNew( UIdefaultTheme, ( "uitheme", "uitheme" ) ), MyPath + "uitheme/" );
@@ -266,7 +268,7 @@ void EETest::createUI() {
UIThemeManager::instance()->setDefaultEffectsEnabled( true );
UIThemeManager::instance()->setDefaultFont( TTF );
UIThemeManager::instance()->setDefaultTheme( "uitheme" );
/**/
UIControl::CreateParams Params( UIManager::instance()->getMainControl(), Vector2i(0,0), Sizei( 530, 380 ), UI_FILL_BACKGROUND | UI_CLIP_ENABLE | UI_BORDER );
Params.Border.setWidth( 2 );
@@ -574,6 +576,30 @@ void EETest::createUI() {
C = reinterpret_cast<UIControlAnim*> ( C->getParent() );
eePRINTL( "CreateUI time: %4.3f ms.", TE.getElapsed().asMilliseconds() );
/**/
UIRadioButton * ctrl = eeNew( UIRadioButton, () );
ctrl->setPosition( 100, 100 );
ctrl->setSize( 320, 32 );
ctrl->setBackgroundFillEnabled( true )->setColor( 0x33333333 );
ctrl->setBorderEnabled( true )->setColor( 0x66666666 );
ctrl->setVisible( true );
ctrl->setEnabled( true );
ctrl->setText( "Happy TextBox :)" );
ctrl->setFontColor( 0x000000FF );
UIGfx * gfx = eeNew( UIGfx, () );
gfx->setPosition( 100, 132 );
gfx->setBackgroundFillEnabled( true )->setColor( 0x33333333 );
gfx->setSubTexture( mTheme->getIconByName( "ok" ) );
gfx->setVisible( true );
gfx->setEnabled( true );
UISlider * slider = eeNew( UISlider, () );
slider->setPosition( 50, 100 );
slider->setSize( 32, 100 );
slider->setVisible( true );
slider->setEnabled( true );
}
void EETest::createMapEditor() {