diff --git a/include/eepp/system/colors.hpp b/include/eepp/system/colors.hpp index 4722fe572..4e57f3474 100755 --- a/include/eepp/system/colors.hpp +++ b/include/eepp/system/colors.hpp @@ -191,8 +191,62 @@ const tColorA tColorA::Transparent = tColorA(0,0,0,0); template const tColorA tColorA::Black = tColorA(0,0,0,255); +class tColorAI : public tColorA +{ + public: + tColorAI() : + tColorA() + {} + + tColorAI(Uint8 r, Uint8 g, Uint8 b, Uint8 a) : + tColorA(r,g,b,a) + {} + + tColorAI( const tColor& Col ) : + tColorA( Col ) + {} + + tColorAI( const tColor& Col, Uint8 a ) : + tColorA( Col, a ) + {} + + tColorAI( const tColorA& Col ) : + tColorA( Col.Value ) + {} + + tColorAI( const Uint32& Col ) : + tColorA( Col ) + {} + + static inline tColorAI colorFromPointer(void *ptr) { + unsigned long val = (long)ptr; + + // hash the pointer up nicely + val = (val+0x7ed55d16) + (val<<12); + val = (val^0xc761c23c) ^ (val>>19); + val = (val+0x165667b1) + (val<<5); + val = (val+0xd3a2646c) ^ (val<<9); + val = (val+0xfd7046c5) + (val<<3); + val = (val^0xb55a4f09) ^ (val>>16); + + unsigned char r = (val>>0) & 0xFF; + unsigned char g = (val>>8) & 0xFF; + unsigned char b = (val>>16) & 0xFF; + + unsigned char max = r>g ? (r>b ? r : b) : (g>b ? g : b); + + const int mult = 127; + const int add = 63; + r = (r*mult)/max + add; + g = (g*mult)/max + add; + b = (b*mult)/max + add; + + return tColorAI(r, g, b, 255); + } +}; + typedef tColor Colorf; -typedef tColorA ColorA; +typedef tColorAI ColorA; typedef tColorA ColorAf; typedef tColorA ColorAff; diff --git a/include/eepp/ui/uicontrol.hpp b/include/eepp/ui/uicontrol.hpp index e44a80eec..5de5de175 100644 --- a/include/eepp/ui/uicontrol.hpp +++ b/include/eepp/ui/uicontrol.hpp @@ -415,6 +415,8 @@ class EE_API UIControl { void drawDebugData(); + void drawBox(); + void setInternalPosition( const Vector2i& Pos ); void setInternalSize( const Sizei& size ); diff --git a/include/eepp/ui/uihelper.hpp b/include/eepp/ui/uihelper.hpp index 4830b2e97..2b515f9be 100644 --- a/include/eepp/ui/uihelper.hpp +++ b/include/eepp/ui/uihelper.hpp @@ -113,7 +113,8 @@ enum UI_SCROLLBAR_MODE { enum UI_MANAGER_FLAGS { UI_MANAGER_HIGHLIGHT_FOCUS = ( 1 << 0 ), UI_MANAGER_HIGHLIGHT_OVER = ( 1 << 1 ), - UI_MANAGER_DRAW_DEBUG_DATA = ( 1 << 2 ) + UI_MANAGER_DRAW_DEBUG_DATA = ( 1 << 2 ), + UI_MANAGER_DRAW_BOXES = ( 1 << 3 ) }; enum UI_WINDOW_FLAGS { diff --git a/include/eepp/ui/uimanager.hpp b/include/eepp/ui/uimanager.hpp index d9be2ad17..aa1cbff20 100644 --- a/include/eepp/ui/uimanager.hpp +++ b/include/eepp/ui/uimanager.hpp @@ -71,6 +71,10 @@ class EE_API UIManager { bool getDrawDebugData() const; + void setDrawBoxes( bool draw ); + + bool getDrawBoxes() const; + void setHighlightFocusColor( const ColorA& Color ); const ColorA& getHighlightFocusColor() const; diff --git a/include/eepp/ui/uiscrollbar.hpp b/include/eepp/ui/uiscrollbar.hpp index 6a5890136..2c88ba1df 100644 --- a/include/eepp/ui/uiscrollbar.hpp +++ b/include/eepp/ui/uiscrollbar.hpp @@ -47,6 +47,10 @@ class EE_API UIScrollBar : public UIComplexControl { const Float& getClickStep() const; + Float getPageStep() const; + + void setPageStep( const Float& pageStep ); + virtual void setTheme( UITheme * Theme ); bool isVertical() const; @@ -58,13 +62,23 @@ class EE_API UIScrollBar : public UIComplexControl { UIControlAnim * getButtonUp() const; UIControlAnim * getButtonDown() const; + + UI_ORIENTATION getOrientation() const; + + void setOrientation( const UI_ORIENTATION & orientation ); + + bool getExpandBackground() const; + + void setExpandBackground( bool expandBackground ); protected: UISlider * mSlider; UIControlAnim * mBtnUp; - UIControlAnim * mBtnDown; + UIControlAnim * mBtnDown; virtual void onSizeChange(); + void autoSize(); + void adjustChilds(); void onValueChangeCb( const UIEvent * Event ); diff --git a/include/eepp/ui/uislider.hpp b/include/eepp/ui/uislider.hpp index 57c69be83..d9ea7940a 100644 --- a/include/eepp/ui/uislider.hpp +++ b/include/eepp/ui/uislider.hpp @@ -63,10 +63,6 @@ class EE_API UISlider : public UIComplexControl { void adjustChilds(); - const bool& isHalfSliderOutAllowed() const; - - const bool& isBackgroundExpanded() const; - void manageClick( const Uint32& flags ); UI_ORIENTATION getOrientation() const; @@ -80,6 +76,10 @@ class EE_API UISlider : public UIComplexControl { bool getExpandBackground() const; void setExpandBackground( bool expandBackground ); + + Float getPageStep() const; + + void setPageStep( const Float & pageStep ); protected: friend class Private::UISliderButton; @@ -92,6 +92,7 @@ class EE_API UISlider : public UIComplexControl { Float mMaxValue; Float mValue; Float mClickStep; + Float mPageStep; bool mOnPosChange; diff --git a/include/eepp/ui/uithememanager.hpp b/include/eepp/ui/uithememanager.hpp index b024d7c7a..0fe0789ff 100644 --- a/include/eepp/ui/uithememanager.hpp +++ b/include/eepp/ui/uithememanager.hpp @@ -60,7 +60,7 @@ class EE_API UIThemeManager : public ResourceManager { protected: Font * mFont; UITheme * mThemeDefault; - bool mautoApplyDefaultTheme; + bool mAutoApplyDefaultTheme; bool mEnableDefaultEffects; Time mFadeInTime; diff --git a/src/eepp/ui/uicontrol.cpp b/src/eepp/ui/uicontrol.cpp index 5a0c4ff03..596da6034 100644 --- a/src/eepp/ui/uicontrol.cpp +++ b/src/eepp/ui/uicontrol.cpp @@ -361,6 +361,17 @@ void UIControl::drawDebugData() { } } +void UIControl::drawBox() { + if ( UIManager::instance()->getDrawBoxes() ) { + Primitives P; + P.setFillMode( DRAW_LINE ); + P.setBlendMode( getBlendMode() ); + P.setColor( ColorA::colorFromPointer( this ) ); + P.setLineWidth( dpToPxI( 1 ) ); + P.drawRectangle( getRectf() ); + } +} + void UIControl::draw() { if ( mVisible ) { if ( mFlags & UI_FILL_BACKGROUND ) @@ -372,11 +383,13 @@ void UIControl::draw() { if ( NULL != mSkinState ) mSkinState->draw( mScreenPosf.x, mScreenPosf.y, (Float)mRealSize.getWidth(), (Float)mRealSize.getHeight(), 255 ); + drawDebugData(); + + drawBox(); + drawHighlightFocus(); drawOverControl(); - - drawDebugData(); } } diff --git a/src/eepp/ui/uicontrolanim.cpp b/src/eepp/ui/uicontrolanim.cpp index 8980e5fa9..a261e23a5 100644 --- a/src/eepp/ui/uicontrolanim.cpp +++ b/src/eepp/ui/uicontrolanim.cpp @@ -67,6 +67,8 @@ void UIControlAnim::draw() { drawOverControl(); drawDebugData(); + + drawBox(); } } diff --git a/src/eepp/ui/uilistbox.cpp b/src/eepp/ui/uilistbox.cpp index 832d6ddbd..7a7ac92d5 100644 --- a/src/eepp/ui/uilistbox.cpp +++ b/src/eepp/ui/uilistbox.cpp @@ -81,6 +81,13 @@ UIListBox::UIListBox( UIListBox::CreateParams& Params ) : UIListBox::UIListBox() : UIComplexControl(), + mRowHeight(0), + mVScrollMode( UI_SCROLLBAR_AUTO ), + mHScrollMode( UI_SCROLLBAR_AUTO ), + mSmoothScroll( true ), + mPaddingContainer(), + mHScrollPadding(), + mVScrollPadding(), mContainer( NULL ), mVScrollBar( NULL ), mHScrollBar( NULL ), @@ -197,7 +204,6 @@ Uint32 UIListBox::addListBoxItem( UIListBoxItem * Item ) { if ( Item->getParent() != mContainer ) Item->setParent( mContainer ); - updateScroll(); Uint32 tMaxTextWidth = mMaxTextWidth; @@ -209,6 +215,8 @@ Uint32 UIListBox::addListBoxItem( UIListBoxItem * Item ) { updateScroll(); } + mVScrollBar->setPageStep( ( (Float)mContainer->getSize().getHeight() /(Float) mRowHeight ) / (Float)mItems.size() ); + return (Uint32)(mItems.size() - 1); } @@ -219,13 +227,15 @@ Uint32 UIListBox::addListBoxItem( const String& Text ) { if ( NULL != mFont ) { Uint32 twidth = mFont->getTextWidth( Text ); - if ( twidth > mMaxTextWidth ) { + if ( twidth > (Uint32)dpToPxI( mMaxTextWidth ) ) { mMaxTextWidth = (Uint32)pxToDpI( twidth ); updateListBoxItemsSize(); } } + mVScrollBar->setPageStep( ( (Float)mContainer->getSize().getHeight() /(Float) mRowHeight ) / (Float)mItems.size() ); + updateScroll(); return (Uint32)(mItems.size() - 1); @@ -399,7 +409,7 @@ void UIListBox::findMaxWidth() { else width = mFont->getTextWidth( mTexts[i] ); - if ( width > (Int32)mMaxTextWidth ) + if ( width > dpToPxI( mMaxTextWidth ) ) mMaxTextWidth = (Uint32)pxToDpI( width ); } } @@ -415,7 +425,7 @@ void UIListBox::itemUpdateSize( UIListBoxItem * Item ) { if ( NULL != Item ) { Int32 width = (Int32)Item->getTextWidth(); - if ( width > (Int32)mMaxTextWidth ) + if ( width > dpToPxI( mMaxTextWidth ) ) mMaxTextWidth = (Uint32)pxToDpI( width ); if ( !mHScrollBar->isVisible() ) { diff --git a/src/eepp/ui/uimanager.cpp b/src/eepp/ui/uimanager.cpp index 5e88d3b12..35759c8a1 100644 --- a/src/eepp/ui/uimanager.cpp +++ b/src/eepp/ui/uimanager.cpp @@ -333,6 +333,14 @@ bool UIManager::getDrawDebugData() const { return 0 != ( mFlags & UI_MANAGER_DRAW_DEBUG_DATA ); } +void UIManager::setDrawBoxes( bool draw ) { + BitOp::setBitFlagValue( &mFlags, UI_MANAGER_DRAW_BOXES, draw ? 1 : 0 ); +} + +bool UIManager::getDrawBoxes() const { + return 0 != ( mFlags & UI_MANAGER_DRAW_BOXES ); +} + void UIManager::setHighlightFocusColor( const ColorA& Color ) { mHighlightFocusColor = Color; } diff --git a/src/eepp/ui/uiscrollbar.cpp b/src/eepp/ui/uiscrollbar.cpp index 0d4adafbb..5b55e29d7 100644 --- a/src/eepp/ui/uiscrollbar.cpp +++ b/src/eepp/ui/uiscrollbar.cpp @@ -110,41 +110,47 @@ void UIScrollBar::setTheme( UITheme * Theme ) { mBtnDown->setPixelsSize( tSkin->getSize() ); } - if ( mFlags & UI_AUTO_SIZE ) { - tSkin = mSlider->getBackSlider()->getSkin(); - - if ( NULL != tSkin ) { - Sizei size = tSkin->getSize(); - - if ( mSlider->isVertical() ) { - mSlider->setPixelsSize( size.getWidth() , mRealSize.getHeight() ); - setPixelsSize( size.getWidth() , mRealSize.getHeight() ); - mMinControlSize.x = mSize.getWidth(); - } else { - mSlider->setPixelsSize( mRealSize.getWidth(), size.getHeight() ); - setPixelsSize( mRealSize.getWidth(), size.getHeight() ); - mMinControlSize.y = mSize.getHeight(); - } - } - } - adjustChilds(); mSlider->adjustChilds(); } +void UIScrollBar::autoSize() { + UISkin * tSkin = mSlider->getBackSlider()->getSkin(); + + if ( NULL != tSkin ) { + Sizei size = tSkin->getSize(); + + mMinControlSize = pxToDpI( size ); + + if ( mFlags & UI_AUTO_SIZE ) { + if ( mSlider->isVertical() ) { + mSlider->setPixelsSize( size.getWidth() , mRealSize.getHeight() ); + setPixelsSize( size.getWidth(), mRealSize.getHeight() ); + } else { + mSlider->setPixelsSize( mRealSize.getWidth(), size.getHeight() ); + setPixelsSize( mRealSize.getWidth(), size.getHeight() ); + } + } + } +} + void UIScrollBar::onSizeChange() { adjustChilds(); + mSlider->adjustChilds(); + UIComplexControl::onSizeChange(); } void UIScrollBar::adjustChilds() { + autoSize(); + mBtnUp->setPosition( 0, 0 ); if ( !isVertical() ) { mBtnDown->setPosition( mSize.getWidth() - mBtnDown->getSize().getWidth(), 0 ); - mSlider->setSize( mSize.getWidth() - mBtnDown->getSize().getWidth() - mBtnUp->getSize().getWidth(), mSlider->getSize().getHeight() ); + mSlider->setSize( mSize.getWidth() - mBtnDown->getSize().getWidth() - mBtnUp->getSize().getWidth(), mSize.getHeight() ); mSlider->setPosition( mBtnUp->getSize().getWidth(), 0 ); mBtnDown->centerVertical(); @@ -152,7 +158,7 @@ void UIScrollBar::adjustChilds() { mSlider->centerVertical(); } else { mBtnDown->setPosition( 0, mSize.getHeight() - mBtnDown->getSize().getHeight() ); - mSlider->setSize( mSlider->getSize().getWidth(), mSize.getHeight() - mBtnDown->getSize().getHeight() - mBtnUp->getSize().getHeight() ); + mSlider->setSize( mSize.getWidth(), mSize.getHeight() - mBtnDown->getSize().getHeight() - mBtnUp->getSize().getHeight() ); mSlider->setPosition( 0, mBtnUp->getSize().getHeight() ); mBtnDown->centerHorizontal(); @@ -229,6 +235,14 @@ const Float& UIScrollBar::getClickStep() const { return mSlider->getClickStep(); } +Float UIScrollBar::getPageStep() const { + return mSlider->getPageStep(); +} + +void UIScrollBar::setPageStep(const Float& pageStep) { + mSlider->setPageStep( pageStep ); +} + bool UIScrollBar::isVertical() const { return mSlider->isVertical(); } @@ -249,6 +263,27 @@ UIControlAnim * UIScrollBar::getButtonDown() const { return mBtnDown; } +bool UIScrollBar::getExpandBackground() const { + return mSlider->getExpandBackground(); +} + +void UIScrollBar::setExpandBackground( bool expandBackground ) { + mSlider->setExpandBackground( expandBackground ); + + adjustChilds(); +} + +UI_ORIENTATION UIScrollBar::getOrientation() const { + return mSlider->getOrientation(); +} + +void UIScrollBar::setOrientation( const UI_ORIENTATION & orientation ) { + mSlider->setOrientation( orientation ); + + applyDefaultTheme(); +} + + void UIScrollBar::onAlphaChange() { UIControlAnim::onAlphaChange(); diff --git a/src/eepp/ui/uislider.cpp b/src/eepp/ui/uislider.cpp index 37d9404c9..f6dfe05ad 100644 --- a/src/eepp/ui/uislider.cpp +++ b/src/eepp/ui/uislider.cpp @@ -15,6 +15,7 @@ UISlider::UISlider( const UISlider::CreateParams& Params ) : mMaxValue( 1.f ), mValue( 0.f ), mClickStep( 0.1f ), + mPageStep(0), mOnPosChange( false ) { UIControl::CreateParams BgParams; @@ -59,6 +60,7 @@ UISlider::UISlider() : mMaxValue( 1.f ), mValue( 0.f ), mClickStep( 0.1f ), + mPageStep(0), mOnPosChange( false ) { Sizei bgSize; @@ -131,12 +133,27 @@ void UISlider::adjustChilds() { tSkin = mSlider->getSkin(); if ( NULL != tSkin ) { - mSlider->setPixelsSize( tSkin->getSize() ); + if ( mPageStep == 0 ) { + mSlider->setPixelsSize( tSkin->getSize() ); + } else { + Float percent = ( mPageStep / ( mMaxValue - mMinValue ) ); - if ( UI_HORIZONTAL == mOrientation ) + if ( UI_HORIZONTAL == mOrientation ) { + Int32 size = eemax( (Int32)( (Float)mRealSize.getWidth() * percent ), tSkin->getSize().getWidth() ); + + mSlider->setPixelsSize( size, tSkin->getSize().getHeight() ); + } else { + Int32 size = eemax( (Int32)( (Float)mRealSize.getHeight() * percent ), tSkin->getSize().getHeight() ); + + mSlider->setPixelsSize( tSkin->getSize().getWidth(), size ); + } + } + + if ( UI_HORIZONTAL == mOrientation ) { mSlider->centerVertical(); - else + } else { mSlider->centerHorizontal(); + } } tSkin = mBackSlider->getSkin(); @@ -363,25 +380,14 @@ UI_ORIENTATION UISlider::getOrientation() const { void UISlider::setOrientation( const UI_ORIENTATION & orientation ) { mOrientation = orientation; - Sizei bgSize; - - if ( UI_HORIZONTAL == mOrientation ) - bgSize = dpToPxI( Sizei( mSize.getWidth() - 16, 8 ) ); - else - bgSize = dpToPxI( Sizei( 8, mSize.getHeight() - 16 ) ); - - mBackSlider->setSize( bgSize ); - applyDefaultTheme(); } -bool UISlider::getAllowHalfSliderOut() const -{ +bool UISlider::getAllowHalfSliderOut() const { return mAllowHalfSliderOut; } -void UISlider::setAllowHalfSliderOut( bool allowHalfSliderOut ) -{ +void UISlider::setAllowHalfSliderOut( bool allowHalfSliderOut ) { mAllowHalfSliderOut = allowHalfSliderOut; adjustChilds(); @@ -389,13 +395,11 @@ void UISlider::setAllowHalfSliderOut( bool allowHalfSliderOut ) setValue( mValue ); } -bool UISlider::getExpandBackground() const -{ +bool UISlider::getExpandBackground() const { return mExpandBackground; } -void UISlider::setExpandBackground( bool expandBackground ) -{ +void UISlider::setExpandBackground( bool expandBackground ) { mExpandBackground = expandBackground; adjustChilds(); @@ -403,6 +407,18 @@ void UISlider::setExpandBackground( bool expandBackground ) setValue( mValue ); } +Float UISlider::getPageStep() const { + return mPageStep; +} + +void UISlider::setPageStep(const Float & pageStep) { + mPageStep = eemin( eemax( pageStep, mMinValue ), mMaxValue ); + + adjustChilds(); + + setValue( mValue ); +} + UIControl * UISlider::getBackSlider() const { return mBackSlider; } @@ -411,14 +427,6 @@ UIDragable * UISlider::getSliderButton() const { return mSlider; } -const bool& UISlider::isHalfSliderOutAllowed() const { - return mAllowHalfSliderOut; -} - -const bool& UISlider::isBackgroundExpanded() const { - return mExpandBackground; -} - void UISlider::onAlphaChange() { UIControlAnim::onAlphaChange(); diff --git a/src/eepp/ui/uithememanager.cpp b/src/eepp/ui/uithememanager.cpp index 2136b77db..41427ee5a 100644 --- a/src/eepp/ui/uithememanager.cpp +++ b/src/eepp/ui/uithememanager.cpp @@ -10,7 +10,7 @@ UIThemeManager::UIThemeManager() : ResourceManager( true ), mFont( NULL ), mThemeDefault( NULL ), - mautoApplyDefaultTheme( true ), + mAutoApplyDefaultTheme( true ), mEnableDefaultEffects( false ), mFadeInTime( Milliseconds( 100.f ) ), mFadeOutTime( Milliseconds ( 100.f ) ), @@ -57,16 +57,16 @@ UITheme * UIThemeManager::getDefaultTheme() const { } void UIThemeManager::applyDefaultTheme( UIControl * Control ) { - if ( mautoApplyDefaultTheme && NULL != mThemeDefault && NULL != Control ) + if ( mAutoApplyDefaultTheme && NULL != mThemeDefault && NULL != Control ) Control->setTheme( mThemeDefault ); } void UIThemeManager::setAutoApplyDefaultTheme( const bool& apply ) { - mautoApplyDefaultTheme = apply; + mAutoApplyDefaultTheme = apply; } const bool& UIThemeManager::getAutoApplyDefaultTheme() const { - return mautoApplyDefaultTheme; + return mAutoApplyDefaultTheme; } void UIThemeManager::setDefaultEffectsEnabled( const bool& Enabled ) { diff --git a/src/test/eetest.cpp b/src/test/eetest.cpp index 1f9972dec..5169fac2a 100644 --- a/src/test/eetest.cpp +++ b/src/test/eetest.cpp @@ -278,7 +278,7 @@ void EETest::createUI() { UIThemeManager::instance()->setDefaultFont( TTF ); UIThemeManager::instance()->setDefaultTheme( mThemeName ); - Int32 wsize = 100; + Int32 wsize = 15; std::vector str(wsize); if ( wsize ) { @@ -286,7 +286,7 @@ void EETest::createUI() { str[i-1] = "Test ListBox " + String::toStr(i) + " testing it right now!"; } - /**/ + /* UIControl::CreateParams Params( UIManager::instance()->getMainControl(), Vector2i(0,0), Sizei( 530, 380 ), UI_FILL_BACKGROUND | UI_CLIP_ENABLE | UI_BORDER ); Params.Border.setWidth( 2 ); @@ -662,6 +662,20 @@ void EETest::createUI() { listBox->setVisible( true ); listBox->setEnabled( true ); listBox->addListBoxItems( str ); + + UIScrollBar * scrollBar = eeNew( UIScrollBar, () ); + scrollBar->setOrientation( UI_HORIZONTAL ); + scrollBar->setPosition( 200, 150 ); + scrollBar->setSize( 100, 0 ); + scrollBar->setVisible( true ); + scrollBar->setEnabled( true ); + + UIScrollBar * scrollBar2 = eeNew( UIScrollBar, () ); + scrollBar2->setOrientation( UI_VERTICAL ); + scrollBar2->setPosition( 200, 25 ); + scrollBar2->setSize( 0, 100 ); + scrollBar2->setVisible( true ); + scrollBar2->setEnabled( true ); } void EETest::createMapEditor() {