diff --git a/include/eepp/system/functionstring.hpp b/include/eepp/system/functionstring.hpp index 55168379e..c135f6ab6 100644 --- a/include/eepp/system/functionstring.hpp +++ b/include/eepp/system/functionstring.hpp @@ -1,12 +1,13 @@ #ifndef EE_SYSTEM_FUNCTIONSTRING_HPP #define EE_SYSTEM_FUNCTIONSTRING_HPP +#include #include #include namespace EE { namespace System { -class FunctionString { +class EE_API FunctionString { public: static FunctionString parse( const std::string& function ); diff --git a/include/eepp/ui.hpp b/include/eepp/ui.hpp index fd4cea410..94fccb8a3 100644 --- a/include/eepp/ui.hpp +++ b/include/eepp/ui.hpp @@ -45,6 +45,7 @@ #include #include #include +#include #include diff --git a/include/eepp/ui/tools/textureatlaseditor.hpp b/include/eepp/ui/tools/textureatlaseditor.hpp index 3d009a322..52d288c06 100644 --- a/include/eepp/ui/tools/textureatlaseditor.hpp +++ b/include/eepp/ui/tools/textureatlaseditor.hpp @@ -21,9 +21,9 @@ class EE_API TextureAtlasEditor { public: typedef std::function TGEditorCloseCb; - static TextureAtlasEditor * New( UIWindow * AttatchTo = NULL, const TGEditorCloseCb& callback = TGEditorCloseCb() ); + static TextureAtlasEditor * New( UIWindow * attachTo = NULL, const TGEditorCloseCb& callback = TGEditorCloseCb() ); - TextureAtlasEditor( UIWindow * AttatchTo = NULL, const TGEditorCloseCb& callback = TGEditorCloseCb() ); + TextureAtlasEditor( UIWindow * attachTo = NULL, const TGEditorCloseCb& callback = TGEditorCloseCb() ); virtual ~TextureAtlasEditor(); diff --git a/include/eepp/ui/tools/uicolorpicker.hpp b/include/eepp/ui/tools/uicolorpicker.hpp new file mode 100644 index 000000000..c9c487a97 --- /dev/null +++ b/include/eepp/ui/tools/uicolorpicker.hpp @@ -0,0 +1,51 @@ +#ifndef EE_UI_TOOLS_UICOLORPICKER_HPP +#define EE_UI_TOOLS_UICOLORPICKER_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace EE { namespace Graphics { +class Texture; +}} + +namespace EE { namespace UI { namespace Tools { + +class EE_API UIColorPicker { + public: + typedef std::function ColorPickedCb; + typedef std::function ColorPickerCloseCb; + + static UIColorPicker * New( UIWindow * attach = NULL, const ColorPickedCb& colorPickedCb = ColorPickedCb(), const ColorPickerCloseCb& closeCb = ColorPickerCloseCb() ); + + UIColorPicker( UIWindow * attach = NULL, const ColorPickedCb& colorPickedCb = ColorPickedCb(), const ColorPickerCloseCb& closeCb = ColorPickerCloseCb() ); + + virtual ~UIColorPicker(); + protected: + UIWindow * mUIWindow; + Node * mUIContainer; + ColorPickedCb mPickedCb; + ColorPickerCloseCb mCloseCb; + Texture * mHueTexture; + RectangleDrawable * mColorRectangle; + UIImage * mColorPicker; + UIImage * mHuePicker; + Colorf mHsv; + Color mRgb; + + void windowClose( const Event * Event ); + + Texture * createHueTexture( const Sizef& size ); + + void updateColorPicker(); +}; + +}}} + +#endif diff --git a/projects/linux/ee.files b/projects/linux/ee.files index 21aaf3a57..d9c106046 100644 --- a/projects/linux/ee.files +++ b/projects/linux/ee.files @@ -300,6 +300,7 @@ ../../include/eepp/ui/css/stylesheetstyle.hpp ../../include/eepp/ui/marginmove/scale.hpp ../../include/eepp/ui/tools/textureatlaseditor.hpp +../../include/eepp/ui/tools/uicolorpicker.hpp ../../include/eepp/ui/uicheckbox.hpp ../../include/eepp/ui/uicombobox.hpp ../../include/eepp/ui/uicommondialog.hpp @@ -721,6 +722,7 @@ ../../src/eepp/ui/tools/textureatlasnew.hpp ../../src/eepp/ui/tools/textureatlastextureregioneditor.cpp ../../src/eepp/ui/tools/textureatlastextureregioneditor.hpp +../../src/eepp/ui/tools/uicolorpicker.cpp ../../src/eepp/ui/uicheckbox.cpp ../../src/eepp/ui/uicombobox.cpp ../../src/eepp/ui/uicommondialog.cpp diff --git a/src/eepp/graphics/drawablegroup.cpp b/src/eepp/graphics/drawablegroup.cpp index 7fca9c5cb..fec1ffd82 100644 --- a/src/eepp/graphics/drawablegroup.cpp +++ b/src/eepp/graphics/drawablegroup.cpp @@ -124,4 +124,4 @@ void DrawableGroup::update() { mNeedsUpdate = false; } -}} +}} diff --git a/src/eepp/system/color.cpp b/src/eepp/system/color.cpp index 2f51c6bfe..ed7b255d2 100644 --- a/src/eepp/system/color.cpp +++ b/src/eepp/system/color.cpp @@ -172,13 +172,14 @@ Color Color::fromHsv(const Colorf& hsv) { Color rgba(Color::Transparent); Float remainder, p, q, t; int region; + Uint8 brightness = static_cast( hsv.hsv.v * 255.f + 0.5f ); rgba.a = static_cast( hsv.hsv.a * 255.f + 0.5f ); if (hsv.hsv.s == 0) { - rgba.r = hsv.hsv.v; - rgba.g = hsv.hsv.v; - rgba.b = hsv.hsv.v; + rgba.r = brightness; + rgba.g = brightness; + rgba.b = brightness; return rgba; } @@ -189,7 +190,7 @@ Color Color::fromHsv(const Colorf& hsv) { q = hsv.hsv.v * (1 - hsv.hsv.s * remainder); t = hsv.hsv.v * (1 - (hsv.hsv.s * (1 - remainder))); - Uint8 brightness = static_cast( hsv.hsv.v * 255.f + 0.5f ); + p = static_cast( p * 255.f + 0.5f ); q = static_cast( q * 255.f + 0.5f ); t = static_cast( t * 255.f + 0.5f ); diff --git a/src/eepp/ui/tools/textureatlaseditor.cpp b/src/eepp/ui/tools/textureatlaseditor.cpp index d3ba5648d..8b5100165 100644 --- a/src/eepp/ui/tools/textureatlaseditor.cpp +++ b/src/eepp/ui/tools/textureatlaseditor.cpp @@ -19,12 +19,12 @@ UIWidget * TextureAtlasEditor::createTextureAtlasTextureRegionEditor( std::strin return mTextureRegionEditor; } -TextureAtlasEditor *TextureAtlasEditor::New(UIWindow * AttatchTo, const TextureAtlasEditor::TGEditorCloseCb & callback) { - return eeNew( TextureAtlasEditor, ( AttatchTo, callback ) ); +TextureAtlasEditor *TextureAtlasEditor::New(UIWindow * attachTo, const TextureAtlasEditor::TGEditorCloseCb & callback) { + return eeNew( TextureAtlasEditor, ( attachTo, callback ) ); } -TextureAtlasEditor::TextureAtlasEditor( UIWindow * AttatchTo, const TGEditorCloseCb& callback ) : - mUIWindow( AttatchTo ), +TextureAtlasEditor::TextureAtlasEditor( UIWindow * attachTo, const TGEditorCloseCb& callback ) : + mUIWindow( attachTo ), mCloseCb( callback ), mTexturePacker( NULL ), mTextureAtlasLoader( NULL ), diff --git a/src/eepp/ui/tools/uicolorpicker.cpp b/src/eepp/ui/tools/uicolorpicker.cpp new file mode 100644 index 000000000..0b44ada09 --- /dev/null +++ b/src/eepp/ui/tools/uicolorpicker.cpp @@ -0,0 +1,210 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace EE { namespace UI { namespace Tools { + +UIColorPicker* UIColorPicker::New( UIWindow* attachTo, const UIColorPicker::ColorPickedCb& colorPickedCb, const UIColorPicker::ColorPickerCloseCb& closeCb ) { + return eeNew( UIColorPicker, ( attachTo, colorPickedCb, closeCb ) ); +} + +UIColorPicker::UIColorPicker( UIWindow* attachTo, const UIColorPicker::ColorPickedCb& colorPickedCb, const UIColorPicker::ColorPickerCloseCb& closeCb ) : + mUIWindow( attachTo ), + mPickedCb( colorPickedCb ), + mCloseCb( closeCb ), + mHueTexture( NULL ), + mColorRectangle( NULL ), + mColorPicker( NULL ), + mHuePicker( NULL ), + mHsv(0, 1, 1, 1), + mRgb(Color::fromHsv(mHsv)) +{ + if ( NULL == mUIWindow ) { + mUIContainer = SceneManager::instance()->getUISceneNode(); + } else { + mUIContainer = mUIWindow->getContainer(); + } + + std::string layout = R"xml( + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + )xml"; + + UIWidget * root = NULL; + if ( NULL != mUIContainer->getSceneNode() && mUIContainer->getSceneNode()->isUISceneNode() ) + root = mUIContainer->getSceneNode()->asType()->loadLayoutFromString( layout, mUIContainer ); + + if ( NULL != mUIWindow ) { + mUIWindow->setTitle( "Color Picker" ); + mUIWindow->addEventListener( Event::OnWindowClose, cb::Make1( this, &UIColorPicker::windowClose ) ); + } else { + mUIContainer->addEventListener( Event::OnClose, cb::Make1( this, &UIColorPicker::windowClose ) ); + } + + root->bind( "color_picker_rect", mColorPicker ); + root->bind( "hue_picker", mHuePicker ); + mHueTexture = createHueTexture( mHuePicker->getPixelsSize() ); + mHuePicker->setDrawable( mHueTexture ); + updateColorPicker(); +} + +UIColorPicker::~UIColorPicker() { + TextureFactory::instance()->remove( mHueTexture->getTextureId() ); + mColorPicker->setDrawable( NULL ); + eeSAFE_DELETE( mColorRectangle ); +} + +void UIColorPicker::windowClose( const Event * ) { + if ( mCloseCb ) + mCloseCb(); + + eeDelete( this ); +} + +Texture * UIColorPicker::createHueTexture( const Sizef& size ) { + Image image( 1, (Uint32)size.getHeight(), 3 ); + + for ( Uint32 y = 0; y < image.getHeight(); y++ ) { + Colorf hsva; + hsva.hsv.h = 360.f * y / image.getHeight(); + hsva.hsv.s = 1.f; + hsva.hsv.v = 1.f; + image.setPixel( 0, y, Color::fromHsv( hsva ) ); + } + + 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 = RectangleDrawable::New(); + + RectColors rectColors; + rectColors.TopLeft = Color::fromHsv( Colorf( mHsv.hsv.h, 0, 1, 1 ) ); + rectColors.BottomLeft = Color::fromHsv( Colorf( mHsv.hsv.h, 0, 0, 1 ) ); + rectColors.BottomRight = Color::fromHsv( Colorf( mHsv.hsv.h, 1, 0, 1 ) ); + rectColors.TopRight = Color::fromHsv( Colorf( mHsv.hsv.h, 1, 1, 1 ) ); + mColorRectangle->setRectColors( rectColors ); + + mColorPicker->setDrawable( mColorRectangle ); + eeSAFE_DELETE( oldDrawable ); +} + +}}} diff --git a/src/test/eetest.cpp b/src/test/eetest.cpp index 9ec146a93..381c4e24d 100644 --- a/src/test/eetest.cpp +++ b/src/test/eetest.cpp @@ -113,6 +113,7 @@ void EETest::init() { mCurDemo = eeINDEX_NOT_FOUND; mMapEditor = NULL; mETGEditor = NULL; + mColorPicker = NULL; Mus = NULL; mUIWindow = NULL; mTerrainBut = NULL; @@ -500,6 +501,7 @@ void EETest::createBaseUI() { Menu->addSeparator(); Menu->add( "Map Editor" ); Menu->add( "Texture Atlas Editor" ); + Menu->add( "Color Picker" ); Menu->addSeparator(); Menu->add( "Show Screen 1" ); Menu->add( "Show Screen 2" ); @@ -925,13 +927,22 @@ void EETest::createETGEditor() { windowStyleConfig.MinWindowSize = Sizef( 1024, 768 ); tWin->setStyleConfig( windowStyleConfig ); - mETGEditor = Tools::TextureAtlasEditor::New( tWin, cb::Make0( this, &EETest::onETGEditorClose ) ); + mETGEditor = Tools::TextureAtlasEditor::New( tWin, [&] { mETGEditor = NULL; } ); tWin->center(); tWin->show(); } -void EETest::onETGEditorClose() { - mETGEditor = NULL; +void EETest::createColorPicker() { + UIWindow * tWin = UIWindow::New(); + tWin->setSize( 320, 478 )->setPosition( 0, 0 ); + UIWindow::StyleConfig windowStyleConfig = tWin->getStyleConfig(); + windowStyleConfig.WinFlags = UI_WIN_DEFAULT_FLAGS | UI_WIN_SHADOW | UI_WIN_FRAME_BUFFER; + windowStyleConfig.MinWindowSize = Sizef( 320, 478 ); + tWin->setStyleConfig( windowStyleConfig ); + + mColorPicker = Tools::UIColorPicker::New( tWin, [&](Color color) {}, [&] { mColorPicker = NULL; } ); + tWin->center(); + tWin->show(); } void EETest::createCommonDialog() { @@ -1114,6 +1125,8 @@ void EETest::onItemClick( const Event * Event ) { createMapEditor(); } else if ( "Texture Atlas Editor" == txt ) { createETGEditor(); + } else if ( "Color Picker" == txt ) { + createColorPicker(); } else if ( "Multi Viewport" == txt ) { MultiViewportMode = !MultiViewportMode; } else if ( "Open..." == txt ) { diff --git a/src/test/eetest.hpp b/src/test/eetest.hpp index 4aa793909..674228ff8 100644 --- a/src/test/eetest.hpp +++ b/src/test/eetest.hpp @@ -168,6 +168,7 @@ class EETest : private Thread { UIWindow * mUIWindow; MapEditor * mMapEditor; TextureAtlasEditor * mETGEditor; + UIColorPicker * mColorPicker; Text mEEText; Text mFBOText; @@ -236,9 +237,9 @@ class EETest : private Thread { void createMapEditor(); - void onMapEditorClose(); + void createColorPicker(); - void onETGEditorClose(); + void onMapEditorClose(); void createETGEditor();