diff --git a/include/eepp/ui/tools/uicolorpicker.hpp b/include/eepp/ui/tools/uicolorpicker.hpp index 7d5352321..8506fee23 100644 --- a/include/eepp/ui/tools/uicolorpicker.hpp +++ b/include/eepp/ui/tools/uicolorpicker.hpp @@ -11,11 +11,6 @@ #include #include -namespace EE { namespace Graphics { -class Texture; -class DrawableGroup; -}} - namespace EE { namespace UI { namespace Tools { class EE_API UIColorPicker { @@ -29,8 +24,6 @@ class EE_API UIColorPicker { UIColorPicker( UIWindow * attach = NULL, const ColorPickedCb& colorPickedCb = ColorPickedCb(), const ColorPickerCloseCb& closeCb = ColorPickerCloseCb() ); - virtual ~UIColorPicker(); - void setColor( const Color& color ); const Color& getColor() const; @@ -46,8 +39,6 @@ class EE_API UIColorPicker { UIWidget * mRoot; ColorPickedCb mPickedCb; ColorPickerCloseCb mCloseCb; - Texture * mHueTexture; - DrawableGroup * mColorRectangle; UIImage * mColorPicker; UIImage * mHuePicker; UIWidget * mVerticalLine; @@ -68,6 +59,8 @@ class EE_API UIColorPicker { Texture * createHueTexture( const Sizef& size ); + Texture * createGridTexture(); + void updateColorPicker(); void updateGuideLines(); diff --git a/include/eepp/ui/uiimage.hpp b/include/eepp/ui/uiimage.hpp index 47343adb6..9d66decac 100644 --- a/include/eepp/ui/uiimage.hpp +++ b/include/eepp/ui/uiimage.hpp @@ -27,7 +27,7 @@ class EE_API UIImage : public UIWidget { Drawable * getDrawable() const; - UIImage * setDrawable( Drawable * drawable ); + UIImage * setDrawable( Drawable * drawable, bool ownIt = false ); const Color& getColor() const; diff --git a/include/eepp/ui/uislider.hpp b/include/eepp/ui/uislider.hpp index ef54c6f59..b36f71d72 100644 --- a/include/eepp/ui/uislider.hpp +++ b/include/eepp/ui/uislider.hpp @@ -2,7 +2,6 @@ #define EE_UIUISlider_HPP #include -#include namespace EE { namespace UI { @@ -70,13 +69,11 @@ class EE_API UISlider : public UIWidget { Sizef getMinimumSize(); protected: - friend class Private::UISliderButton; - UI_ORIENTATION mOrientation; bool mAllowHalfSliderOut; bool mExpandBackground; - UINode * mBackSlider; - Private::UISliderButton * mSlider; + UINode * mBackSlider; + UIWidget * mSlider; Float mMinValue; Float mMaxValue; Float mValue; @@ -95,13 +92,13 @@ class EE_API UISlider : public UIWidget { void fixSliderPos(); + void adjustSliderPos(); + virtual Uint32 onKeyDown( const KeyEvent &Event ); virtual void onAlphaChange(); virtual Uint32 onMessage( const NodeMessage * Msg ); - - void updateSliderPosition(); }; }} diff --git a/include/eepp/ui/uisliderbutton.hpp b/include/eepp/ui/uisliderbutton.hpp deleted file mode 100644 index c41247a4a..000000000 --- a/include/eepp/ui/uisliderbutton.hpp +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef EE_UICUISLIDERBUTTON_HPP -#define EE_UICUISLIDERBUTTON_HPP - -#include - -namespace EE { namespace UI { namespace Private { - -class EE_API UISliderButton : public UIWidget { - public: - static UISliderButton * New(); - - UISliderButton(); - - virtual ~UISliderButton(); - protected: - virtual void onPositionChange(); -}; - -}}} - -#endif diff --git a/projects/linux/ee.files b/projects/linux/ee.files index d9c106046..d9df990f4 100644 --- a/projects/linux/ee.files +++ b/projects/linux/ee.files @@ -335,7 +335,6 @@ ../../include/eepp/ui/uiselectbutton.hpp ../../include/eepp/ui/uiskin.hpp ../../include/eepp/ui/uiskinstate.hpp -../../include/eepp/ui/uisliderbutton.hpp ../../include/eepp/ui/uislider.hpp ../../include/eepp/ui/uispinbox.hpp ../../include/eepp/ui/uisprite.hpp @@ -754,7 +753,6 @@ ../../src/eepp/ui/uiselectbutton.cpp ../../src/eepp/ui/uiskin.cpp ../../src/eepp/ui/uiskinstate.cpp -../../src/eepp/ui/uisliderbutton.cpp ../../src/eepp/ui/uislider.cpp ../../src/eepp/ui/uispinbox.cpp ../../src/eepp/ui/uisprite.cpp diff --git a/src/eepp/graphics/statelistdrawable.cpp b/src/eepp/graphics/statelistdrawable.cpp index e42b1980e..809638915 100644 --- a/src/eepp/graphics/statelistdrawable.cpp +++ b/src/eepp/graphics/statelistdrawable.cpp @@ -26,11 +26,19 @@ StateListDrawable::~StateListDrawable() { } void StateListDrawable::clearDrawables() { + std::vector removeOwnershipState; + for ( auto it = mDrawables.begin(); it != mDrawables.end(); ++it ) { Drawable * drawable = it->second; - if ( mDrawablesOwnership[ drawable ] ) + if ( mDrawablesOwnership[ drawable ] ) { + removeOwnershipState.push_back( drawable ); eeSAFE_DELETE( drawable ); + } + } + + for ( auto& removeOwnership : removeOwnershipState ) { + mDrawablesOwnership.erase( removeOwnership ); } mDrawables.clear(); diff --git a/src/eepp/ui/tools/uicolorpicker.cpp b/src/eepp/ui/tools/uicolorpicker.cpp index 5dedb9044..22559e016 100644 --- a/src/eepp/ui/tools/uicolorpicker.cpp +++ b/src/eepp/ui/tools/uicolorpicker.cpp @@ -34,8 +34,6 @@ UIColorPicker::UIColorPicker( UIWindow* attachTo, const UIColorPicker::ColorPick mRoot( NULL ), mPickedCb( colorPickedCb ), mCloseCb( closeCb ), - mHueTexture( NULL ), - mColorRectangle( NULL ), mColorPicker( NULL ), mHuePicker( NULL ), mVerticalLine( NULL ), @@ -68,7 +66,6 @@ UIColorPicker::UIColorPicker( UIWindow* attachTo, const UIColorPicker::ColorPick margin-bottom: 4dp; } #color_picker > .header > .current_color { - background-color: white; } #color_picker > .header > .picker_icon { icon: color-picker-white; @@ -192,20 +189,14 @@ UIColorPicker::UIColorPicker( UIWindow* attachTo, const UIColorPicker::ColorPick updateAll(); } ); - mHueTexture = createHueTexture( mHuePicker->getPixelsSize() ); - mHuePicker->setDrawable( mHueTexture ); + mHuePicker->setDrawable( createHueTexture( mHuePicker->getPixelsSize() ), true ); + mCurrentColor->setBackgroundDrawable( createGridTexture(), true ); updateAll(); registerEvents(); } -UIColorPicker::~UIColorPicker() { - TextureFactory::instance()->remove( mHueTexture->getTextureId() ); - mColorPicker->setDrawable( NULL ); - eeSAFE_DELETE( mColorRectangle ); -} - void UIColorPicker::setColor( const Color& color ) { if ( color != mRgb ) { mRgb = color; @@ -232,8 +223,7 @@ const Colorf& UIColorPicker::getHsvColor() const { return mHsv; } -UIWindow* UIColorPicker::getUIWindow() const -{ +UIWindow* UIColorPicker::getUIWindow() const { return mUIWindow; } @@ -262,9 +252,28 @@ Texture * UIColorPicker::createHueTexture( const Sizef& size ) { return TF->getTexture( texId ); } +Texture * UIColorPicker::createGridTexture() { + Sizef size( PixelDensity::dpToPx( Sizef( 26, 24 ) ) ); + Image image( size.getWidth(), size.getHeight(), 3, Color( 128, 128, 128, 255 ) ); + Color highlightColor( 204, 204, 204, 255 ); + int hWidth = size.getWidth() / 2; + int hHeight = size.getHeight() / 2; + for ( int y = 0; y < hHeight; y++ ) { + for ( int x = 0; x < hWidth; x++ ) { + image.setPixel( x, y, highlightColor ); + image.setPixel( hWidth + x, hHeight + y, highlightColor ); + } + } + + TextureFactory * TF = TextureFactory::instance(); + Uint32 texId = TF->loadFromPixels( image.getPixelsPtr(), image.getWidth(), image.getHeight(), + image.getChannels(), false, Texture::ClampMode::ClampRepeat ); + + return TF->getTexture( texId ); +} + void UIColorPicker::updateColorPicker() { - Drawable * oldDrawable = mColorRectangle; - mColorRectangle = DrawableGroup::New(); + DrawableGroup * colorRectangle = DrawableGroup::New(); RectangleDrawable * rectDrawable = RectangleDrawable::New(); @@ -275,7 +284,7 @@ void UIColorPicker::updateColorPicker() { rectColors.BottomRight = Color::fromHsv( Colorf( mHsv.hsv.h, 1, 1, 1 ) ); rectColors.TopRight = Color::fromHsv( Colorf( mHsv.hsv.h, 1, 1, 1 ) ); rectDrawable->setRectColors( rectColors ); - mColorRectangle->addDrawable( rectDrawable ); + colorRectangle->addDrawable( rectDrawable ); rectDrawable = RectangleDrawable::New(); rectDrawable->setSize( mColorPicker->getPixelsSize() ); @@ -284,10 +293,9 @@ void UIColorPicker::updateColorPicker() { rectColors.BottomRight = Color::Black; rectColors.TopRight = Color::Transparent; rectDrawable->setRectColors( rectColors ); - mColorRectangle->addDrawable( rectDrawable ); + colorRectangle->addDrawable( rectDrawable ); - mColorPicker->setDrawable( mColorRectangle ); - eeSAFE_DELETE( oldDrawable ); + mColorPicker->setDrawable( colorRectangle, true ); } void UIColorPicker::updateGuideLines() { diff --git a/src/eepp/ui/uiimage.cpp b/src/eepp/ui/uiimage.cpp index 68441f8b6..51bb07149 100644 --- a/src/eepp/ui/uiimage.cpp +++ b/src/eepp/ui/uiimage.cpp @@ -46,10 +46,11 @@ bool UIImage::isType( const Uint32& type ) const { return UIImage::getType() == type ? true : UIWidget::isType( type ); } -UIImage * UIImage::setDrawable( Drawable * drawable ) { +UIImage * UIImage::setDrawable(Drawable * drawable , bool ownIt ) { safeDeleteDrawable(); mDrawable = drawable; + mDrawableOwner = ownIt; if ( NULL != mDrawable && mDrawable->isDrawableResource() ) { mResourceChangeCb = static_cast( mDrawable )->pushResourceChangeCallback( cb::Make2( this, &UIImage::onDrawableResourceEvent ) ); @@ -178,10 +179,7 @@ void UIImage::safeDeleteDrawable() { } if ( NULL != mDrawable && mDrawableOwner ) { - if ( mDrawable->getDrawableType() == Drawable::SPRITE ) { - Sprite * spr = reinterpret_cast( mDrawable ); - eeSAFE_DELETE( spr ); - } + eeSAFE_DELETE( mDrawable ); mDrawableOwner = false; } diff --git a/src/eepp/ui/uislider.cpp b/src/eepp/ui/uislider.cpp index 6b8cab79e..1a6fa6a7b 100644 --- a/src/eepp/ui/uislider.cpp +++ b/src/eepp/ui/uislider.cpp @@ -44,13 +44,16 @@ UISlider::UISlider( const UI_ORIENTATION& orientation ) : mBackSlider->setSize( bgSize ); mBackSlider->center(); - mSlider = Private::UISliderButton::New(); + mSlider = UIWidget::NewWithTag( "slider::button" ); mSlider->setParent( this ); mSlider->setEnabled( true ); mSlider->setVisible( true ); mSlider->setDragEnabled( true ); mSlider->setSize( 16, 16 ); mSlider->setPosition( 0, 0 ); + mSlider->addEventListener( Event::OnPositionChange, [&] ( const Event* event ) { + fixSliderPos(); + } ); if ( UI_HORIZONTAL == mOrientation ) mSlider->centerVertical(); @@ -162,7 +165,7 @@ void UISlider::adjustChilds() { mBackSlider->center(); } - fixSliderPos(); + adjustSliderPos(); } void UISlider::fixSliderPos() { @@ -184,6 +187,11 @@ void UISlider::fixSliderPos() { } mSlider->centerVertical(); + + if ( mAllowHalfSliderOut ) + setValue( mMinValue + ( mSlider->getPosition().x - mPadding.Left ) * ( mMaxValue - mMinValue ) / (Float)mBackSlider->getSize().getWidth() ); + else + setValue( mMinValue + ( mSlider->getPosition().x - mPadding.Left ) * ( mMaxValue - mMinValue ) / ( (Float)mDpSize.getWidth() - mSlider->getSize().getWidth() ) ); } else { mSlider->setPosition( 0, mSlider->getPosition().y ); @@ -200,16 +208,20 @@ void UISlider::fixSliderPos() { } mSlider->centerHorizontal(); - } - updateSliderPosition(); + if ( mAllowHalfSliderOut ) + setValue( mMinValue + ( mSlider->getPosition().y - mPadding.Top ) * ( mMaxValue - mMinValue ) / (Float)mBackSlider->getSize().getHeight() ); + else + setValue( mMinValue + ( mSlider->getPosition().y - mPadding.Top ) * ( mMaxValue - mMinValue ) / ( (Float)mDpSize.getHeight() - mSlider->getSize().getHeight() ) ); + } mOnPosChange = false; } } -void UISlider::updateSliderPosition() { +void UISlider::adjustSliderPos() { Float Percent = ( mValue - mMinValue ) / ( mMaxValue - mMinValue ); + mOnPosChange = true; if ( UI_HORIZONTAL == mOrientation ) { if ( mAllowHalfSliderOut ) @@ -223,6 +235,7 @@ void UISlider::updateSliderPosition() { mSlider->setPosition( mSlider->getPosition().x, mPadding.Top + (Int32)( ( (Float)mDpSize.getHeight() - mPadding.Top - mPadding.Bottom - mSlider->getSize().getHeight() ) * Percent ) ); } + mOnPosChange = false; } void UISlider::setValue( Float Val ) { @@ -237,7 +250,9 @@ void UISlider::setValue( Float Val ) { if ( !mOnPosChange ) { mOnPosChange = true; - updateSliderPosition(); + + adjustSliderPos(); + mOnPosChange = false; } diff --git a/src/eepp/ui/uisliderbutton.cpp b/src/eepp/ui/uisliderbutton.cpp deleted file mode 100644 index 435edaf73..000000000 --- a/src/eepp/ui/uisliderbutton.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include -#include - -namespace EE { namespace UI { namespace Private { - -UISliderButton *UISliderButton::New() { - return eeNew( UISliderButton, () ); -} - -UISliderButton::UISliderButton() : - UIWidget( "slider::button" ) -{ - applyDefaultTheme(); -} - -UISliderButton::~UISliderButton() { -} - -void UISliderButton::onPositionChange() { - UIWidget::onPositionChange(); - - mParentCtrl->asType()->fixSliderPos(); -} - -}}}