Fixed UISlider (again).

UIImage now can own Drawables.
UIColorPicker improvements.
Removed UISliderButton (not used anymore).

--HG--
branch : dev
This commit is contained in:
Martín Lucas Golini
2019-11-11 00:51:24 -03:00
parent cb14426b6d
commit 87c80a0872
10 changed files with 67 additions and 96 deletions

View File

@@ -11,11 +11,6 @@
#include <eepp/ui/uislider.hpp>
#include <eepp/ui/uispinbox.hpp>
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();

View File

@@ -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;

View File

@@ -2,7 +2,6 @@
#define EE_UIUISlider_HPP
#include <eepp/ui/uiwidget.hpp>
#include <eepp/ui/uisliderbutton.hpp>
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();
};
}}

View File

@@ -1,21 +0,0 @@
#ifndef EE_UICUISLIDERBUTTON_HPP
#define EE_UICUISLIDERBUTTON_HPP
#include <eepp/ui/uiwidget.hpp>
namespace EE { namespace UI { namespace Private {
class EE_API UISliderButton : public UIWidget {
public:
static UISliderButton * New();
UISliderButton();
virtual ~UISliderButton();
protected:
virtual void onPositionChange();
};
}}}
#endif

View File

@@ -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

View File

@@ -26,11 +26,19 @@ StateListDrawable::~StateListDrawable() {
}
void StateListDrawable::clearDrawables() {
std::vector<Drawable*> 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();

View File

@@ -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() {

View File

@@ -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<DrawableResource*>( 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<Sprite*>( mDrawable );
eeSAFE_DELETE( spr );
}
eeSAFE_DELETE( mDrawable );
mDrawableOwner = false;
}

View File

@@ -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;
}

View File

@@ -1,25 +0,0 @@
#include <eepp/ui/uisliderbutton.hpp>
#include <eepp/ui/uislider.hpp>
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<UISlider>()->fixSliderPos();
}
}}}