diff --git a/Makefile b/Makefile index 5cb650058..47af3b978 100644 --- a/Makefile +++ b/Makefile @@ -187,7 +187,7 @@ SRCGAMING = $(wildcard ./src/gaming/*.cpp) $(wildcard ./src/gaming/mapeditor/* SRCGRAPHICS = $(wildcard ./src/graphics/*.cpp) $(wildcard ./src/graphics/renderer/*.cpp) SRCMATH = $(wildcard ./src/math/*.cpp) SRCSYSTEM = $(wildcard ./src/system/*.cpp) -SRCUI = $(wildcard ./src/ui/*.cpp) +SRCUI = $(wildcard ./src/ui/*.cpp) $(wildcard ./src/ui/tools/*.cpp) SRCUTILS = $(wildcard ./src/utils/*.cpp) SRCWINDOW = $(wildcard ./src/window/*.cpp) $(wildcard ./src/window/backend/null/*.cpp) $(wildcard ./src/window/platform/null/*.cpp) $(SDL_BACKEND_SRC) $(ALLEGRO_BACKEND_SRC) $(PLATFORMSRC) SRCPHYSICS = $(wildcard ./src/physics/*.cpp) $(wildcard ./src/physics/constraints/*.cpp) @@ -261,6 +261,7 @@ dirs: @mkdir -p $(OBJDIR)/src/math @mkdir -p $(OBJDIR)/src/system @mkdir -p $(OBJDIR)/src/ui + @mkdir -p $(OBJDIR)/src/ui/tools @mkdir -p $(OBJDIR)/src/utils @mkdir -p $(OBJDIR)/src/window @mkdir -p $(OBJDIR)/src/window/backend/SDL diff --git a/ee.files b/ee.files index f85c520a8..038ccc7c3 100644 --- a/ee.files +++ b/ee.files @@ -791,3 +791,9 @@ src/helper/chipmunk/constraints/cpDampedRotarySpring.c src/helper/chipmunk/constraints/cpConstraint.c src/ui/cuimessagebox.hpp src/ui/cuimessagebox.cpp +src/ui/tools/ctexturegroupeditor.hpp +src/ui/tools/ctexturegroupeditor.cpp +src/ui/tools/ctexturegroupnew.hpp +src/ui/tools/ctexturegroupnew.cpp +src/ui/tools/ctexturegroupshapeeditor.hpp +src/ui/tools/ctexturegroupshapeeditor.cpp diff --git a/src/base.hpp b/src/base.hpp index bcfff9eb8..9768e2823 100644 --- a/src/base.hpp +++ b/src/base.hpp @@ -150,6 +150,7 @@ #define eeSAFE_DELETE(p) { if(p) { eeDelete (p); (p)=NULL; } } #define eeSAFE_FREE(p) { if(p) { eeFree ( (void*)p ); (p)=NULL; } } #define eeSAFE_DELETE_ARRAY(p) { if(p) { eeDeleteArray(p); (p)=NULL; } } +#define eeINDEX_NOT_FOUND 0xFFFFFFFF namespace EE { #if 1 == EE_USE_DOUBLES diff --git a/src/ee.h b/src/ee.h index 112bffaec..a23a45528 100755 --- a/src/ee.h +++ b/src/ee.h @@ -191,6 +191,9 @@ #include "ui/cuiaquatheme.hpp" using namespace EE::UI; + #include "ui/tools/ctexturegroupeditor.hpp" + using namespace EE::UI::Tools; + // Gaming #include "gaming/clight.hpp" #include "gaming/cisomap.hpp" @@ -204,6 +207,9 @@ #include "gaming/cmap.hpp" using namespace EE::Gaming; + #include "gaming/mapeditor/cmapeditor.hpp" + using namespace EE::Gaming::MapEditor; + #include "physics/cphysicsmanager.hpp" #include "physics/cshape.hpp" #include "physics/cshapecircle.hpp" diff --git a/src/gaming/cmap.cpp b/src/gaming/cmap.cpp index 331c0bf84..30f9217c1 100644 --- a/src/gaming/cmap.cpp +++ b/src/gaming/cmap.cpp @@ -202,11 +202,13 @@ void cMap::MouseOverDraw() { } void cMap::GridDraw() { - cPrimitives P; + if ( DrawBackground() ) { + cPrimitives P; - P.SetColor( eeColorA( 0, 0, 0, 50 ) ); - P.DrawRectangle( mScreenPos.x, mScreenPos.y, mViewSize.x, mViewSize.y, 0.f, 1.f ); - P.SetColor( eeColorA( 255, 255, 255, 255 ) ); + P.SetColor( eeColorA( 0, 0, 0, 50 ) ); + P.DrawRectangle( mScreenPos.x, mScreenPos.y, mViewSize.x, mViewSize.y, 0.f, 1.f ); + P.SetColor( eeColorA( 255, 255, 255, 255 ) ); + } if ( !DrawGrid() ) return; @@ -387,6 +389,14 @@ Uint32 cMap::DrawGrid() const { return mFlags & MAP_FLAG_DRAW_GRID; } +void cMap::DrawBackground( const bool& draw ) { + SetFlagValue( &mFlags, MAP_FLAG_DRAW_BACKGROUND, draw ? 1 : 0 ); +} + +Uint32 cMap::DrawBackground() const { + return mFlags & MAP_FLAG_DRAW_BACKGROUND; +} + Uint32 cMap::ClipedArea() const { return mFlags & MAP_FLAG_CLIP_AREA; } diff --git a/src/gaming/cmap.hpp b/src/gaming/cmap.hpp index f96aaead5..eaff108e7 100644 --- a/src/gaming/cmap.hpp +++ b/src/gaming/cmap.hpp @@ -92,6 +92,10 @@ class cMap { Uint32 DrawGrid() const; + void DrawBackground( const bool& draw ); + + Uint32 DrawBackground() const; + Uint32 DrawTileOver() const; void DrawTileOver( const bool& draw ); diff --git a/src/gaming/mapeditor/clayerproperties.cpp b/src/gaming/mapeditor/clayerproperties.cpp index b210490e0..cf9400ea0 100644 --- a/src/gaming/mapeditor/clayerproperties.cpp +++ b/src/gaming/mapeditor/clayerproperties.cpp @@ -127,7 +127,7 @@ void cLayerProperties::AddCellClick( const cUIEvent * Event ) { Uint32 Index = mGenGrid->GetItemSelectedIndex(); - if ( 0xFFFFFFFF == Index ) { + if ( eeINDEX_NOT_FOUND == Index ) { mGenGrid->GetCell( 0 )->Select(); } } @@ -135,7 +135,7 @@ void cLayerProperties::AddCellClick( const cUIEvent * Event ) { void cLayerProperties::RemoveCellClick( const cUIEvent * Event ) { Uint32 Index = mGenGrid->GetItemSelectedIndex(); - if ( 0xFFFFFFFF != Index ) { + if ( eeINDEX_NOT_FOUND != Index ) { mGenGrid->Remove( Index ); if ( Index < mGenGrid->Count() ) { diff --git a/src/gaming/mapeditor/cmapeditor.cpp b/src/gaming/mapeditor/cmapeditor.cpp index 1b4761bc1..d098110d5 100644 --- a/src/gaming/mapeditor/cmapeditor.cpp +++ b/src/gaming/mapeditor/cmapeditor.cpp @@ -19,6 +19,7 @@ #include "../../ui/cuicheckbox.hpp" #include "../../ui/cuicommondialog.hpp" #include "../../ui/cuimessagebox.hpp" +#include "../../ui/tools/ctexturegroupeditor.hpp" #include "../../graphics/cshapegroupmanager.hpp" #include "../../graphics/cglobalshapegroup.hpp" #include "../../graphics/ctexturegrouploader.hpp" @@ -41,10 +42,9 @@ cMapEditor::cMapEditor( cUIWindow * AttatchTo, const MapEditorCloseCb& callback mTheme = cUIThemeManager::instance()->DefaultTheme(); - if ( NULL == mUIWindow ) + if ( NULL == mUIWindow ) { mUIWindow = cUIManager::instance()->MainControl(); - - + } if ( cUIManager::instance()->MainControl() == mUIWindow ) { mUIContainer = mUIWindow; @@ -423,7 +423,7 @@ void cMapEditor::CreateUIMap() { mUIMap = eeNew( cUIMap, ( Params ) ); mUIMap->Visible( true ); mUIMap->Enabled( true ); - mUIMap->Map()->Create( eeSize( 100, 100 ), 16, eeSize( 32, 32 ), MAP_FLAG_DRAW_GRID | MAP_FLAG_CLAMP_BODERS | MAP_FLAG_CLIP_AREA, Params.Size ); + mUIMap->Map()->Create( eeSize( 100, 100 ), 16, eeSize( 32, 32 ), MAP_FLAG_DRAW_GRID | MAP_FLAG_DRAW_BACKGROUND | MAP_FLAG_CLAMP_BODERS | MAP_FLAG_CLIP_AREA, Params.Size ); mUIMap->AddEventListener( cUIEvent::EventOnSizeChange, cb::Make1( this, &cMapEditor::OnMapSizeChange ) ); mUIMap->AddEventListener( cUIEvent::EventMouseDown, cb::Make1( this, &cMapEditor::OnMapMouseDown ) ); mUIMap->AddEventListener( cUIEvent::EventMouseClick, cb::Make1( this, &cMapEditor::OnMapMouseClick ) ); @@ -528,7 +528,7 @@ void cMapEditor::FileMenuClick( const cUIEvent * Event ) { } void cMapEditor::OnMapClose( const cUIEvent * Event ) { - mUIMap->Map()->Create( eeSize( 100, 100 ), 16, eeSize( 32, 32 ), MAP_FLAG_DRAW_GRID | MAP_FLAG_CLAMP_BODERS | MAP_FLAG_CLIP_AREA, mUIMap->Size() ); + mUIMap->Map()->Create( eeSize( 100, 100 ), 16, eeSize( 32, 32 ), MAP_FLAG_DRAW_GRID | MAP_FLAG_DRAW_BACKGROUND | MAP_FLAG_CLAMP_BODERS | MAP_FLAG_CLIP_AREA, mUIMap->Size() ); MapCreated(); @@ -555,7 +555,12 @@ void cMapEditor::MapMenuClick( const cUIEvent * Event ) { const String& txt = reinterpret_cast ( Event->Ctrl() )->Text(); - if ( "Add External Texture Group..." == txt ) { + if ( "New Texture Group..." == txt ) { + cUIWindow * tWin = mTheme->CreateWindow( NULL, eeSize( 1024, 768 ), eeVector2i(), UI_CONTROL_DEFAULT_FLAGS_CENTERED, UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON, eeSize( 1024, 768 ) ); + eeNew ( Tools::cTextureGroupEditor, ( tWin ) ); + tWin->Center(); + tWin->Show(); + } else if ( "Add External Texture Group..." == txt ) { cUICommonDialog * TGDialog = mTheme->CreateCommonDialog( NULL, eeSize(), eeVector2i(), UI_CONTROL_DEFAULT_FLAGS_CENTERED, UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL, eeSize(), 255, UI_CDL_DEFAULT_FLAGS, "*.etg" ); TGDialog->Title( "Load texture group..." ); @@ -646,12 +651,18 @@ void cMapEditor::TextureGroupOpen( const cUIEvent * Event ) { std::string sgname = FileRemoveExtension( FileNameFromPath( CDL->GetFullPath() ) ); - if ( NULL == cShapeGroupManager::instance()->GetByName( sgname ) ) { + cShapeGroup * SG = cShapeGroupManager::instance()->GetByName( sgname ); + + if ( NULL == SG ) { cTextureGroupLoader tgl( CDL->GetFullPath() ); if ( tgl.IsLoaded() ) { mShapeGroupsList->ListBox()->AddListBoxItem( sgname ); } + } else { + if ( eeINDEX_NOT_FOUND == mShapeGroupsList->ListBox()->GetItemIndex( sgname ) ) { + mShapeGroupsList->ListBox()->AddListBoxItem( sgname ); + } } } diff --git a/src/gaming/mapeditor/cmapeditor.hpp b/src/gaming/mapeditor/cmapeditor.hpp index bd65b632b..734eadca9 100644 --- a/src/gaming/mapeditor/cmapeditor.hpp +++ b/src/gaming/mapeditor/cmapeditor.hpp @@ -12,15 +12,13 @@ namespace EE { namespace Gaming { namespace MapEditor { class cUILayerNew; -class cMapEditor { +class EE_API cMapEditor { public: typedef cb::Callback0 MapEditorCloseCb; cMapEditor( cUIWindow * AttatchTo = NULL, const MapEditorCloseCb& callback = MapEditorCloseCb() ); ~cMapEditor(); - - void CloseCallback( const MapEditorCloseCb& callback ); protected: cUIWindow * mUIWindow; cUIControl * mUIContainer; diff --git a/src/gaming/mapeditor/cmapproperties.cpp b/src/gaming/mapeditor/cmapproperties.cpp index 88cdc964c..ac1794ead 100644 --- a/src/gaming/mapeditor/cmapproperties.cpp +++ b/src/gaming/mapeditor/cmapproperties.cpp @@ -127,7 +127,7 @@ void cMapProperties::AddCellClick( const cUIEvent * Event ) { Uint32 Index = mGenGrid->GetItemSelectedIndex(); - if ( 0xFFFFFFFF == Index ) { + if ( eeINDEX_NOT_FOUND == Index ) { mGenGrid->GetCell( 0 )->Select(); } } @@ -135,7 +135,7 @@ void cMapProperties::AddCellClick( const cUIEvent * Event ) { void cMapProperties::RemoveCellClick( const cUIEvent * Event ) { Uint32 Index = mGenGrid->GetItemSelectedIndex(); - if ( 0xFFFFFFFF != Index ) { + if ( eeINDEX_NOT_FOUND != Index ) { mGenGrid->Remove( Index ); if ( Index < mGenGrid->Count() ) { diff --git a/src/gaming/mapeditor/cuimapnew.cpp b/src/gaming/mapeditor/cuimapnew.cpp index 38c87a8d4..f3bf0d73a 100644 --- a/src/gaming/mapeditor/cuimapnew.cpp +++ b/src/gaming/mapeditor/cuimapnew.cpp @@ -80,7 +80,7 @@ void cUIMapNew::OKClick( const cUIEvent * Event ) { Int32 ml = static_cast( mUIMapMaxLayers->Value() ); if ( w > 0 && h > 0 && tw > 0 && th > 0 && ml > 0 ) { - mUIMap->Map()->Create( eeSize( w, h ), ml, eeSize( tw, th ), MAP_FLAG_CLAMP_BODERS | MAP_FLAG_CLIP_AREA | MAP_FLAG_DRAW_GRID, mUIMap->Map()->ViewSize() ); + mUIMap->Map()->Create( eeSize( w, h ), ml, eeSize( tw, th ), MAP_FLAG_CLAMP_BODERS | MAP_FLAG_CLIP_AREA | MAP_FLAG_DRAW_GRID | MAP_FLAG_DRAW_BACKGROUND, mUIMap->Map()->ViewSize() ); if ( mNewMapCb.IsSet() ) mNewMapCb(); diff --git a/src/gaming/maphelper.hpp b/src/gaming/maphelper.hpp index a1ae7a0aa..d2691fdb6 100644 --- a/src/gaming/maphelper.hpp +++ b/src/gaming/maphelper.hpp @@ -86,7 +86,8 @@ enum EE_MAP_FLAGS { MAP_FLAG_CLAMP_BODERS = ( 1 << 0 ), MAP_FLAG_CLIP_AREA = ( 1 << 1 ), MAP_FLAG_DRAW_GRID = ( 1 << 2 ), - MAP_FLAG_DRAW_TILE_OVER = ( 1 << 3 ) + MAP_FLAG_DRAW_TILE_OVER = ( 1 << 3 ), + MAP_FLAG_DRAW_BACKGROUND= ( 1 << 4 ) }; enum EE_LAYER_FLAGS { diff --git a/src/graphics/cfont.cpp b/src/graphics/cfont.cpp index 0e1f8e891..8c973da36 100644 --- a/src/graphics/cfont.cpp +++ b/src/graphics/cfont.cpp @@ -6,7 +6,7 @@ namespace EE { namespace Graphics { cFont::cFont( const Uint32& Type, const std::string& Name ) : mType( Type ), mCacheData(true), - mColor(0xFFFFFFFF), + mColor(255,255,255,255), mShadowColor(0xFF000000), mNumLines(1), mTexId(0), diff --git a/src/graphics/cscrollparallax.cpp b/src/graphics/cscrollparallax.cpp index a20e555a1..98519d229 100755 --- a/src/graphics/cscrollparallax.cpp +++ b/src/graphics/cscrollparallax.cpp @@ -5,7 +5,7 @@ namespace EE { namespace Graphics { cScrollParallax::cScrollParallax() : mShape( NULL ), mBlend( ALPHA_NORMAL ), - mColor( 0xFFFFFFFF ) + mColor( 255, 255, 255, 255 ) { } diff --git a/src/graphics/ctextcache.cpp b/src/graphics/ctextcache.cpp index 7153d279b..7c4091baa 100644 --- a/src/graphics/ctextcache.cpp +++ b/src/graphics/ctextcache.cpp @@ -7,8 +7,8 @@ cTextCache::cTextCache() : mFont(NULL), mCachedWidth(0.f), mNumLines(1), - mFontColor(0xFFFFFFFF), - mFontShadowColor(0xFF000000), + mFontColor(255,255,255,255), + mFontShadowColor(0,0,0,255), mCachedCoords(false), mFlags(0) { diff --git a/src/graphics/ctextcache.hpp b/src/graphics/ctextcache.hpp index a9c6849d6..d63a6a862 100644 --- a/src/graphics/ctextcache.hpp +++ b/src/graphics/ctextcache.hpp @@ -12,13 +12,13 @@ class cFont; /** @brief Cached text for a fast font rendering. */ class EE_API cTextCache { public: - cTextCache( cFont * font, const String& text = "", eeColorA FontColor = eeColorA(0xFFFFFFFF), eeColorA FontShadowColor = eeColorA(0xFF000000) ); + cTextCache( cFont * font, const String& text = "", eeColorA FontColor = eeColorA(255,255,255,255), eeColorA FontShadowColor = eeColorA(0,0,0,255) ); cTextCache(); ~cTextCache(); - void Create( cFont * font, const String& text = "", eeColorA FontColor = eeColorA(0xFFFFFFFF), eeColorA FontShadowColor = eeColorA(0xFF000000) ); + void Create( cFont * font, const String& text = "", eeColorA FontColor = eeColorA(255,255,255,255), eeColorA FontShadowColor = eeColorA(0,0,0,255) ); cFont * Font() const; diff --git a/src/graphics/ctexturepacker.cpp b/src/graphics/ctexturepacker.cpp index b860968a7..9c3d4ea8e 100644 --- a/src/graphics/ctexturepacker.cpp +++ b/src/graphics/ctexturepacker.cpp @@ -722,4 +722,12 @@ const Int32& cTexturePacker::GetPlacedCount() const { return mPlacedCount; } +const Int32& cTexturePacker::Width() const { + return mWidth; +} + +const Int32& cTexturePacker::Height() const { + return mHeight; +} + }} diff --git a/src/graphics/ctexturepacker.hpp b/src/graphics/ctexturepacker.hpp index 660b05a18..9a77213ad 100644 --- a/src/graphics/ctexturepacker.hpp +++ b/src/graphics/ctexturepacker.hpp @@ -48,22 +48,24 @@ class EE_API cTexturePacker { ~cTexturePacker(); - bool AddTexture( const std::string& TexturePath ); + bool AddTexture( const std::string& TexturePath ); - bool AddTexturesPath( std::string TexturesPath ); + bool AddTexturesPath( std::string TexturesPath ); - Int32 PackTextures(); + Int32 PackTextures(); - void Save( const std::string& Filepath, const EE_SAVE_TYPE& Format = EE_SAVE_TYPE_DDS, const bool& SaveExtensions = false ); + void Save( const std::string& Filepath, const EE_SAVE_TYPE& Format = EE_SAVE_TYPE_DDS, const bool& SaveExtensions = false ); - void Close(); + void Close(); /** First of all you need to set at least the max dimensions of the texture atlas. */ - void SetOptions( const Uint32& MaxWidth, const Uint32& MaxHeight, const bool& ForcePowOfTwo = true, const Uint32& PixelBorder = 0, const bool& AllowFlipping = false ); + void SetOptions( const Uint32& MaxWidth, const Uint32& MaxHeight, const bool& ForcePowOfTwo = true, const Uint32& PixelBorder = 0, const bool& AllowFlipping = false ); - inline const Int32& Width() const { return mWidth; } + const Int32& Width() const; - inline const Int32& Height() const { return mHeight; } + const Int32& Height() const; + + const std::string& GetFilepath() const; protected: enum PackStrategy { PackBig, @@ -89,7 +91,7 @@ class EE_API cTexturePacker { bool mForcePowOfTwo; Int32 mPixelBorder; bool mSaveExtensions; - EE_SAVE_TYPE mFormat; + EE_SAVE_TYPE mFormat; cTexturePacker * GetChild() const; @@ -97,8 +99,6 @@ class EE_API cTexturePacker { std::list * GetTexturePackPtr(); - const std::string& GetFilepath() const; - void ChildSave( const EE_SAVE_TYPE& Format ); void SaveShapes(); diff --git a/src/helper/SOIL/stb_image.c b/src/helper/SOIL/stb_image.c index 5258afa19..666671d40 100644 --- a/src/helper/SOIL/stb_image.c +++ b/src/helper/SOIL/stb_image.c @@ -1665,8 +1665,10 @@ static int stbi_jpeg_test(stbi *s) static int stbi_jpeg_info_raw(jpeg *j, int *x, int *y, int *comp) { - if (!decode_jpeg_header(j, SCAN_header)) + if (!decode_jpeg_header(j, SCAN_header)) { + stbi_rewind( j->s ); return 0; + } if (x) *x = j->s->img_x; if (y) *y = j->s->img_y; if (comp) *comp = j->s->img_n; @@ -2606,8 +2608,10 @@ static int stbi_png_test(stbi *s) static int stbi_png_info_raw(png *p, int *x, int *y, int *comp) { - if (!parse_png_file(p, SCAN_header, 0)) + if (!parse_png_file(p, SCAN_header, 0)) { + stbi_rewind( p->s ); return 0; + } if (x) *x = p->s->img_x; if (y) *y = p->s->img_y; if (comp) *comp = p->s->img_n; @@ -2925,18 +2929,33 @@ static int tga_test(stbi *s) int sz; get8u(s); // discard Offset sz = get8u(s); // color type - if ( sz > 1 ) return 0; // only RGB or indexed allowed + if ( sz > 1 ) { + stbi_rewind( s ); + return 0; + } // only RGB or indexed allowed sz = get8u(s); // image type - if ( (sz != 1) && (sz != 2) && (sz != 3) && (sz != 9) && (sz != 10) && (sz != 11) ) return 0; // only RGB or grey allowed, +/- RLE + if ( (sz != 1) && (sz != 2) && (sz != 3) && (sz != 9) && (sz != 10) && (sz != 11) ) { + stbi_rewind( s ); + return 0; + } // only RGB or grey allowed, +/- RLE get16(s); // discard palette start get16(s); // discard palette length get8(s); // discard bits per palette color entry get16(s); // discard x origin get16(s); // discard y origin - if ( get16(s) < 1 ) return 0; // test width - if ( get16(s) < 1 ) return 0; // test height + if ( get16(s) < 1 ) { + stbi_rewind( s ); + return 0; + } // test width + if ( get16(s) < 1 ) { + stbi_rewind( s ); + return 0; + } // test height sz = get8(s); // bits per pixel - if ( (sz != 8) && (sz != 16) && (sz != 24) && (sz != 32) ) return 0; // only RGB or RGBA or grey allowed + if ( (sz != 8) && (sz != 16) && (sz != 24) && (sz != 32) ) { + stbi_rewind( s ); + return 0; + } // only RGB or RGBA or grey allowed return 1; // seems to have passed everything } @@ -3659,7 +3678,10 @@ static int stbi_gif_header(stbi *s, stbi_gif *g, int *comp, int is_info) static int stbi_gif_info_raw(stbi *s, int *x, int *y, int *comp) { stbi_gif g; - if (!stbi_gif_header(s, &g, comp, 1)) return 0; + if (!stbi_gif_header(s, &g, comp, 1)) { + stbi_rewind( s ); + return 0; + } if (x) *x = g.w; if (y) *y = g.h; return 1; @@ -4107,7 +4129,10 @@ static int stbi_hdr_info(stbi *s, int *x, int *y, int *comp) char *token; int valid = 0; - if (strcmp(hdr_gettoken(s,buffer), "#?RADIANCE") != 0) return 0; + if (strcmp(hdr_gettoken(s,buffer), "#?RADIANCE") != 0) { + stbi_rewind( s ); + return 0; + } for(;;) { token = hdr_gettoken(s,buffer); @@ -4115,13 +4140,22 @@ static int stbi_hdr_info(stbi *s, int *x, int *y, int *comp) if (strcmp(token, "FORMAT=32-bit_rle_rgbe") == 0) valid = 1; } - if (!valid) return 0; + if (!valid) { + stbi_rewind( s ); + return 0; + } token = hdr_gettoken(s,buffer); - if (strncmp(token, "-Y ", 3)) return 0; + if (strncmp(token, "-Y ", 3)) { + stbi_rewind( s ); + return 0; + } token += 3; *y = strtol(token, &token, 10); while (*token == ' ') ++token; - if (strncmp(token, "+X ", 3)) return 0; + if (strncmp(token, "+X ", 3)) { + stbi_rewind( s ); + return 0; + } token += 3; *x = strtol(token, NULL, 10); *comp = 3; @@ -4137,10 +4171,16 @@ static int stbi_hdr_info(stbi *s, int *x, int *y, int *comp) static int stbi_bmp_info(stbi *s, int *x, int *y, int *comp) { int hsz; - if (get8(s) != 'B' || get8(s) != 'M') return 0; + if (get8(s) != 'B' || get8(s) != 'M') { + stbi_rewind( s ); + return 0; + } skip(s,12); hsz = get32le(s); - if (hsz != 12 && hsz != 40 && hsz != 56 && hsz != 108) return 0; + if (hsz != 12 && hsz != 40 && hsz != 56 && hsz != 108) { + stbi_rewind( s ); + return 0; + } if (hsz == 12) { *x = get16le(s); *y = get16le(s); @@ -4148,7 +4188,10 @@ static int stbi_bmp_info(stbi *s, int *x, int *y, int *comp) *x = get32le(s); *y = get32le(s); } - if (get16le(s) != 1) return 0; + if (get16le(s) != 1) { + stbi_rewind( s ); + return 0; + } *comp = get16le(s) / 8; return 1; } @@ -4156,15 +4199,30 @@ static int stbi_bmp_info(stbi *s, int *x, int *y, int *comp) static int stbi_psd_info(stbi *s, int *x, int *y, int *comp) { int channelCount; - if (get32(s) != 0x38425053) return 0; - if (get16(s) != 1) return 0; + if (get32(s) != 0x38425053) { + stbi_rewind( s ); + return 0; + } + if (get16(s) != 1) { + stbi_rewind( s ); + return 0; + } skip(s, 6); channelCount = get16(s); - if (channelCount < 0 || channelCount > 16) return 0; + if (channelCount < 0 || channelCount > 16) { + stbi_rewind( s ); + return 0; + } *y = get32(s); *x = get32(s); - if (get16(s) != 8) return 0; - if (get16(s) != 3) return 0; + if (get16(s) != 8) { + stbi_rewind( s ); + return 0; + } + if (get16(s) != 3) { + stbi_rewind( s ); + return 0; + } *comp = 4; return 1; } @@ -4179,7 +4237,10 @@ static int stbi_pic_info(stbi *s, int *x, int *y, int *comp) *x = get16(s); *y = get16(s); if (at_eof(s)) return 0; - if ( (*x) != 0 && (1 << 28) / (*x) < (*y)) return 0; + if ( (*x) != 0 && (1 << 28) / (*x) < (*y)) { + stbi_rewind( s ); + return 0; + } skip(s, 8); @@ -4196,8 +4257,14 @@ static int stbi_pic_info(stbi *s, int *x, int *y, int *comp) packet->channel = get8u(s); act_comp |= packet->channel; - if (at_eof(s)) return 0; - if (packet->size != 8) return 0; + if (at_eof(s)) { + stbi_rewind( s ); + return 0; + } + if (packet->size != 8) { + stbi_rewind( s ); + return 0; + } } while (chained); *comp = (act_comp & 0x10 ? 4 : 3); @@ -4208,9 +4275,9 @@ static int stbi_pic_info(stbi *s, int *x, int *y, int *comp) static int stbi_info_main(stbi *s, int *x, int *y, int *comp) { if (stbi_jpeg_info(s, x, y, comp)) - return 1; + return 1; if (stbi_png_info(s, x, y, comp)) - return 1; + return 1; if (stbi_gif_info(s, x, y, comp)) return 1; if (stbi_bmp_info(s, x, y, comp)) diff --git a/src/helper/SOIL/stbi_DDS_c.h b/src/helper/SOIL/stbi_DDS_c.h index c05eb49aa..35ae36594 100755 --- a/src/helper/SOIL/stbi_DDS_c.h +++ b/src/helper/SOIL/stbi_DDS_c.h @@ -288,14 +288,32 @@ static int stbi_dds_info( stbi *s, int *x, int *y, int *comp, int *iscompressed getn( s, (stbi_uc*)(&header), 128 ); - if( header.dwMagic != (('D' << 0) | ('D' << 8) | ('S' << 16) | (' ' << 24)) ) return 0; - if( header.dwSize != 124 ) return 0; + if( header.dwMagic != (('D' << 0) | ('D' << 8) | ('S' << 16) | (' ' << 24)) ) { + stbi_rewind( s ); + return 0; + } + if( header.dwSize != 124 ) { + stbi_rewind( s ); + return 0; + } flags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT; - if( (header.dwFlags & flags) != flags ) return 0; - if( header.sPixelFormat.dwSize != 32 ) return 0; + if( (header.dwFlags & flags) != flags ) { + stbi_rewind( s ); + return 0; + } + if( header.sPixelFormat.dwSize != 32 ) { + stbi_rewind( s ); + return 0; + } flags = DDPF_FOURCC | DDPF_RGB; - if( (header.sPixelFormat.dwFlags & flags) == 0 ) return 0; - if( (header.sCaps.dwCaps1 & DDSCAPS_TEXTURE) == 0 ) return 0; + if( (header.sPixelFormat.dwFlags & flags) == 0 ) { + stbi_rewind( s ); + return 0; + } + if( (header.sCaps.dwCaps1 & DDSCAPS_TEXTURE) == 0 ) { + stbi_rewind( s ); + return 0; + } is_compressed = (header.sPixelFormat.dwFlags & DDPF_FOURCC) / DDPF_FOURCC; has_alpha = (header.sPixelFormat.dwFlags & DDPF_ALPHAPIXELS) / DDPF_ALPHAPIXELS; diff --git a/src/test/eetest.cpp b/src/test/eetest.cpp index 24e31ef56..392cc0a20 100644 --- a/src/test/eetest.cpp +++ b/src/test/eetest.cpp @@ -1771,9 +1771,13 @@ void cEETest::PhysicsDestroy() { } #if EE_PLATFORM == EE_PLATFORM_MACOSX +#ifdef EE_BACKEND_SDL_ACTIVE #include +#endif +#ifdef EE_BACKEND_ALLEGRO_ACTIVE #include #endif +#endif int main (int argc, char * argv []) { cEETest * Test = eeNew( cEETest, () ); diff --git a/src/ui/cuicommondialog.hpp b/src/ui/cuicommondialog.hpp index 950b29cbe..7d43ed204 100644 --- a/src/ui/cuicommondialog.hpp +++ b/src/ui/cuicommondialog.hpp @@ -11,7 +11,7 @@ namespace EE { namespace UI { -class cUICommonDialog : public cUIWindow { +class EE_API cUICommonDialog : public cUIWindow { public: class CreateParams : public cUIWindow::CreateParams { public: diff --git a/src/ui/cuigenericgrid.cpp b/src/ui/cuigenericgrid.cpp index 965010366..317de88e7 100644 --- a/src/ui/cuigenericgrid.cpp +++ b/src/ui/cuigenericgrid.cpp @@ -15,7 +15,7 @@ cUIGenericGrid::cUIGenericGrid( const cUIGenericGrid::CreateParams& Params ) : mCollumnsCount( Params.CollumnsCount ), mRowHeight( Params.RowHeight ), mTotalWidth( Params.GridWidth ), - mLastPos( 0xFFFFFFFF ), + mLastPos( eeINDEX_NOT_FOUND ), mVisibleFirst(0), mVisibleLast(0), mHScrollInit(0), @@ -229,7 +229,7 @@ void cUIGenericGrid::UpdateScroll( bool FromScrollChange ) { RelPosMax = RelPos + mContainer->Size().Height() + mRowHeight; - if ( ( FromScrollChange && 0xFFFFFFFF != mLastPos && mLastPos == RelPos ) && ( tHLastScroll == mHScrollInit ) ) + if ( ( FromScrollChange && eeINDEX_NOT_FOUND != mLastPos && mLastPos == RelPos ) && ( tHLastScroll == mHScrollInit ) ) return; mLastPos = RelPos; @@ -263,7 +263,7 @@ void cUIGenericGrid::UpdateScroll( bool FromScrollChange ) { RelPosMax = RelPos + VisibleItems; } - if ( ( FromScrollChange && 0xFFFFFFFF != mLastPos && mLastPos == RelPos ) && ( !Clipped || tHLastScroll == mHScrollInit ) ) + if ( ( FromScrollChange && eeINDEX_NOT_FOUND != mLastPos && mLastPos == RelPos ) && ( !Clipped || tHLastScroll == mHScrollInit ) ) return; mLastPos = RelPos; @@ -329,7 +329,7 @@ void cUIGenericGrid::Remove( cUIGridCell * Cell ) { } void cUIGenericGrid::Remove( std::vector ItemsIndex ) { - if ( ItemsIndex.size() && 0xFFFFFFFF != ItemsIndex[0] ) { + if ( ItemsIndex.size() && eeINDEX_NOT_FOUND != ItemsIndex[0] ) { std::vector ItemsCpy; bool erase; @@ -493,7 +493,7 @@ Uint32 cUIGenericGrid::GetItemIndex( cUIGridCell * Item ) { return i; } - return 0xFFFFFFFF; + return eeINDEX_NOT_FOUND; } Uint32 cUIGenericGrid::OnSelected() { diff --git a/src/ui/cuilistbox.cpp b/src/ui/cuilistbox.cpp index 470386af5..0ea205f47 100644 --- a/src/ui/cuilistbox.cpp +++ b/src/ui/cuilistbox.cpp @@ -19,7 +19,7 @@ cUIListBox::cUIListBox( cUIListBox::CreateParams& Params ) : mFontColor( Params.FontColor ), mFontOverColor( Params.FontOverColor ), mFontSelectedColor( Params.FontSelectedColor ), - mLastPos( 0xFFFFFFFF ), + mLastPos( eeINDEX_NOT_FOUND ), mMaxTextWidth(0), mHScrollInit(0), mItemsNotVisible(0), @@ -176,7 +176,7 @@ Uint32 cUIListBox::RemoveListBoxItem( cUIListBoxItem * Item ) { } void cUIListBox::RemoveListBoxItems( std::vector ItemsIndex ) { - if ( ItemsIndex.size() && 0xFFFFFFFF != ItemsIndex[0] ) { + if ( ItemsIndex.size() && eeINDEX_NOT_FOUND != ItemsIndex[0] ) { std::vector ItemsCpy; bool erase; mTexts.clear(); @@ -245,7 +245,7 @@ Uint32 cUIListBox::GetListBoxItemIndex( const String& Name ) { return i; } - return 0xFFFFFFFF; + return eeINDEX_NOT_FOUND; } Uint32 cUIListBox::GetListBoxItemIndex( cUIListBoxItem * Item ) { @@ -256,7 +256,7 @@ Uint32 cUIListBox::GetListBoxItemIndex( cUIListBoxItem * Item ) { return i; } - return 0xFFFFFFFF; + return eeINDEX_NOT_FOUND; } void cUIListBox::OnScrollValueChange( const cUIEvent * Event ) { @@ -461,7 +461,7 @@ void cUIListBox::UpdateScroll( bool FromScrollChange ) { RelPosMax = RelPos + mContainer->Size().Height() + mRowHeight; - if ( ( FromScrollChange && 0xFFFFFFFF != mLastPos && mLastPos == RelPos ) && ( tHLastScroll == mHScrollInit ) ) + if ( ( FromScrollChange && eeINDEX_NOT_FOUND != mLastPos && mLastPos == RelPos ) && ( tHLastScroll == mHScrollInit ) ) return; mLastPos = RelPos; @@ -505,7 +505,7 @@ void cUIListBox::UpdateScroll( bool FromScrollChange ) { RelPosMax = RelPos + VisibleItems; } - if ( ( FromScrollChange && 0xFFFFFFFF != mLastPos && mLastPos == RelPos ) && ( !Clipped || tHLastScroll == mHScrollInit ) ) + if ( ( FromScrollChange && eeINDEX_NOT_FOUND != mLastPos && mLastPos == RelPos ) && ( !Clipped || tHLastScroll == mHScrollInit ) ) return; mLastPos = RelPos; @@ -610,7 +610,7 @@ Uint32 cUIListBox::GetItemSelectedIndex() const { if ( mSelected.size() ) return mSelected.front(); - return 0xFFFFFFFF; + return eeINDEX_NOT_FOUND; } String cUIListBox::GetItemSelectedText() const { @@ -646,7 +646,7 @@ Uint32 cUIListBox::GetItemIndex( cUIListBoxItem * Item ) { return i; } - return 0xFFFFFFFF; + return eeINDEX_NOT_FOUND; } Uint32 cUIListBox::GetItemIndex( const String& Text ) { @@ -655,7 +655,7 @@ Uint32 cUIListBox::GetItemIndex( const String& Text ) { return i; } - return 0xFFFFFFFF; + return eeINDEX_NOT_FOUND; } void cUIListBox::FontColor( const eeColorA& Color ) { diff --git a/src/ui/cuimenu.cpp b/src/ui/cuimenu.cpp index 4dcd31be4..93fd93569 100644 --- a/src/ui/cuimenu.cpp +++ b/src/ui/cuimenu.cpp @@ -19,7 +19,7 @@ cUIMenu::cUIMenu( cUIMenu::CreateParams& Params ) : mNextPosY( 0 ), mBiggestIcon( mMinSpaceForIcons ), mItemSelected( NULL ), - mItemSelectedIndex( 0xFFFFFFFF ), + mItemSelectedIndex( eeINDEX_NOT_FOUND ), mClickHide( false ), mLastTickMove( 0 ) { @@ -254,7 +254,7 @@ Uint32 cUIMenu::GetItemIndex( cUIControl * Item ) { return i; } - return 0xFFFFFFFF; + return eeINDEX_NOT_FOUND; } Uint32 cUIMenu::Count() const { @@ -413,7 +413,7 @@ bool cUIMenu::Hide() { mItemSelected->SetSkinState( cUISkinState::StateNormal ); mItemSelected = NULL; - mItemSelectedIndex = 0xFFFFFFFF; + mItemSelectedIndex = eeINDEX_NOT_FOUND; return true; } @@ -446,7 +446,7 @@ void cUIMenu::TrySelect( cUIControl * Ctrl, bool Up ) { } else { Uint32 Index = GetItemIndex( Ctrl ); - if ( Index != 0xFFFFFFFF ) { + if ( Index != eeINDEX_NOT_FOUND ) { if ( Up ) { if ( Index > 0 ) { for ( Int32 i = (Int32)Index - 1; i >= 0; i-- ) { @@ -475,7 +475,7 @@ void cUIMenu::TrySelect( cUIControl * Ctrl, bool Up ) { void cUIMenu::NextSel() { if ( mItems.size() ) { - if ( mItemSelectedIndex != 0xFFFFFFFF ) { + if ( mItemSelectedIndex != eeINDEX_NOT_FOUND ) { if ( mItemSelectedIndex + 1 < mItems.size() ) { TrySelect( mItems[ mItemSelectedIndex + 1 ], false ); } else { @@ -489,7 +489,7 @@ void cUIMenu::NextSel() { void cUIMenu::PrevSel() { if ( mItems.size() ) { - if ( mItemSelectedIndex != 0xFFFFFFFF ) { + if ( mItemSelectedIndex != eeINDEX_NOT_FOUND ) { if ( mItemSelectedIndex >= 1 ) { TrySelect( mItems[ mItemSelectedIndex - 1 ], true ); } else { @@ -532,9 +532,9 @@ Uint32 cUIMenu::OnKeyDown( const cUIEventKey& Event ) { break; case KEY_RETURN: if ( NULL != mItemSelected ) { - mItemSelected->SendMouseEvent(cUIEvent::EventMouseClick, cUIManager::instance()->GetMousePos(), 0xFFFFFFFF ); + mItemSelected->SendMouseEvent(cUIEvent::EventMouseClick, cUIManager::instance()->GetMousePos(), EE_BUTTONS_ALL ); - cUIMessage Msg( mItemSelected, cUIMessage::MsgMouseUp, 0xFFFFFFFF ); + cUIMessage Msg( mItemSelected, cUIMessage::MsgMouseUp, EE_BUTTONS_ALL ); mItemSelected->MessagePost( &Msg ); } diff --git a/src/ui/cuimessagebox.hpp b/src/ui/cuimessagebox.hpp index 4f1899a9c..3c27c0b0c 100644 --- a/src/ui/cuimessagebox.hpp +++ b/src/ui/cuimessagebox.hpp @@ -7,7 +7,7 @@ namespace EE { namespace UI { -class cUIMessageBox : public cUIWindow { +class EE_API cUIMessageBox : public cUIWindow { public: class CreateParams : public cUIWindow::CreateParams { public: diff --git a/src/ui/cuipopupmenu.cpp b/src/ui/cuipopupmenu.cpp index 7614b06b0..c0acedb4c 100644 --- a/src/ui/cuipopupmenu.cpp +++ b/src/ui/cuipopupmenu.cpp @@ -48,7 +48,7 @@ bool cUIPopUpMenu::Hide() { mItemSelected->SetSkinState( cUISkinState::StateNormal ); mItemSelected = NULL; - mItemSelectedIndex = 0xFFFFFFFF; + mItemSelectedIndex = eeINDEX_NOT_FOUND; if ( cUIThemeManager::instance()->DefaultEffectsEnabled() ) { DisableFadeOut( cUIThemeManager::instance()->ControlsFadeOutTime() ); diff --git a/src/ui/cuiskin.cpp b/src/ui/cuiskin.cpp index a9e3bfcc3..c5128dfd6 100644 --- a/src/ui/cuiskin.cpp +++ b/src/ui/cuiskin.cpp @@ -24,7 +24,7 @@ cUISkin::cUISkin( const std::string& Name, const Uint32& Type ) : mColorDefault = 0xFFFFFFFF; for ( Int32 i = 0; i < cUISkinState::StateCount; i++ ) - mColor[ i ] = eeColorA( 0xFFFFFFFF ); + mColor[ i ] = eeColorA( 255, 255, 255, 255 ); } cUISkin::~cUISkin() { diff --git a/src/ui/cuispinbox.cpp b/src/ui/cuispinbox.cpp index bc217cb83..8956fa1f6 100644 --- a/src/ui/cuispinbox.cpp +++ b/src/ui/cuispinbox.cpp @@ -156,8 +156,6 @@ void cUISpinBox::InternalValue( const eeFloat& Val, const bool& Force ) { mValue = Val; - mInput->GetInputTextBuffer()->ChangedSinceLastUpdate( false ); - OnValueChange(); } } @@ -194,9 +192,11 @@ const eeFloat& cUISpinBox::MaxValue() const { } void cUISpinBox::Update() { + bool Changed = mInput->GetInputTextBuffer()->ChangedSinceLastUpdate(); + cUIControlAnim::Update(); - if ( mInput->GetInputTextBuffer()->ChangedSinceLastUpdate() ) { + if ( Changed ) { if ( !mInput->Text().size() ) { Value( 0 ); } else { diff --git a/src/ui/tools/ctexturegroupeditor.cpp b/src/ui/tools/ctexturegroupeditor.cpp new file mode 100644 index 000000000..e2ba2a86f --- /dev/null +++ b/src/ui/tools/ctexturegroupeditor.cpp @@ -0,0 +1,351 @@ +#include "ctexturegroupeditor.hpp" +#include "ctexturegroupnew.hpp" +#include "../cuimanager.hpp" +#include "../cuipopupmenu.hpp" +#include "../cuimenuitem.hpp" +#include "../cuicommondialog.hpp" +#include "../cuimessagebox.hpp" + +namespace EE { namespace UI { namespace Tools { + +cTextureGroupEditor::cTextureGroupEditor( cUIWindow * AttatchTo, const TGEditorCloseCb& callback ) : + mUIWindow( AttatchTo ), + mCloseCb( callback ), + mTexturePacker( NULL ), + mTextureGroupLoader( NULL ), + mCurShape( NULL ) +{ + if ( NULL == cUIThemeManager::instance()->DefaultTheme() ) { + eePRINT( "cTextureGroupEditor needs a default theme seted to work." ); + return; + } + + mTheme = cUIThemeManager::instance()->DefaultTheme(); + + if ( NULL == mUIWindow ) { + mUIWindow = cUIManager::instance()->MainControl(); + } + + if ( cUIManager::instance()->MainControl() == mUIWindow ) { + mUIContainer = mUIWindow; + } else { + mUIContainer = mUIWindow->Container(); + } + + cUITextBox * TxtBox; + Uint32 Flags = UI_CONTROL_DEFAULT_ALIGN | UI_ANCHOR_TOP | UI_ANCHOR_RIGHT | UI_CLIP_ENABLE | UI_AUTO_SIZE; + Uint32 InitY = 230; + + CreateTxtBox( eeVector2i( mUIContainer->Size().Width() - 205, 30 ), "Shape List:" ); + + mShapeList = mTheme->CreateListBox( mUIContainer, eeSize( 200, 156 ), eeVector2i( mUIContainer->Size().Width() - 205, 50 ), UI_CONTROL_DEFAULT_ALIGN | UI_CLIP_ENABLE | UI_AUTO_PADDING | UI_ANCHOR_RIGHT | UI_ANCHOR_TOP ); + mShapeList->Size( mShapeList->Size().Width(), mShapeList->RowHeight() * 9 + mShapeList->PaddingContainer().Top + mShapeList->PaddingContainer().Bottom ); + mShapeList->AddEventListener( cUIEvent::EventOnItemSelected, cb::Make1( this, &cTextureGroupEditor::OnShapeChange ) ); + + CreateTxtBox( eeVector2i( mUIContainer->Size().Width() - 205, InitY ), "Current Shape:" ); + + InitY +=30; + + mSpinOffX = mTheme->CreateSpinBox( mUIContainer, eeSize( 100, 22 ), eeVector2i(), Flags, 0, false ); + mSpinOffX->MinValue( -32000 ); + mSpinOffX->MaxValue( 32000 ); + mSpinOffX->Pos( mUIContainer->Size().Width() - mSpinOffX->Size().Width() - 10, InitY ); + mSpinOffX->AddEventListener( cUIEvent::EventOnValueChange, cb::Make1( this, &cTextureGroupEditor::OnOffXChange ) ); + + TxtBox = CreateTxtBox( eeVector2i(), "Offset X:" ); + TxtBox->Pos( mSpinOffX->Pos().x - 10 - TxtBox->Size().Width(), InitY ); + + InitY +=30; + + mSpinOffY = mTheme->CreateSpinBox( mUIContainer, eeSize( 100, 22 ), eeVector2i(), Flags, 0, false ); + mSpinOffY->MinValue( -32000 ); + mSpinOffY->MaxValue( 32000 ); + mSpinOffY->Pos( mUIContainer->Size().Width() - mSpinOffY->Size().Width() - 10, InitY ); + mSpinOffY->AddEventListener( cUIEvent::EventOnValueChange, cb::Make1( this, &cTextureGroupEditor::OnOffYChange ) ); + TxtBox = CreateTxtBox( eeVector2i(), "Offset Y:" ); + TxtBox->Pos( mSpinOffY->Pos().x - 10 - TxtBox->Size().Width(), InitY ); + + InitY +=30; + + mSpinDestW = mTheme->CreateSpinBox( mUIContainer, eeSize( 100, 22 ), eeVector2i(), Flags, 0, false ); + mSpinDestW->MaxValue( 32000 ); + mSpinDestW->Pos( mUIContainer->Size().Width() - mSpinDestW->Size().Width() - 10, InitY ); + mSpinDestW->AddEventListener( cUIEvent::EventOnValueChange, cb::Make1( this, &cTextureGroupEditor::OnDestWChange ) ); + TxtBox = CreateTxtBox( eeVector2i(), "Dest. Width:" ); + TxtBox->Pos( mSpinDestW->Pos().x - 10 - TxtBox->Size().Width(), InitY ); + + InitY +=30; + + mSpinDestH = mTheme->CreateSpinBox( mUIContainer, eeSize( 100, 22 ), eeVector2i(), Flags, 0, false ); + mSpinDestH->MaxValue( 32000 ); + mSpinDestH->Pos( mUIContainer->Size().Width() - mSpinDestH->Size().Width() - 10, InitY ); + mSpinDestH->AddEventListener( cUIEvent::EventOnValueChange, cb::Make1( this, &cTextureGroupEditor::OnDestHChange ) ); + TxtBox = CreateTxtBox( eeVector2i(), "Dest. Height:" ); + TxtBox->Pos( mSpinDestH->Pos().x - 10 - TxtBox->Size().Width(), InitY ); + + Uint32 ButFlags = UI_CONTROL_ALIGN_CENTER | UI_ANCHOR_TOP | UI_ANCHOR_RIGHT | UI_AUTO_SIZE; + + cUIPushButton * ResetButton = mTheme->CreatePushButton( mUIContainer, eeSize( 120, 22 ), eeVector2i( mUIContainer->Size().Width() - 120 - 5 , mSpinDestH->Pos().y + mSpinDestH->Size().Height() + 8 ), ButFlags ); + ResetButton->Text( "Reset Dest. Size" ); + ResetButton->AddEventListener( cUIEvent::EventMouseClick, cb::Make1( this, &cTextureGroupEditor::OnResetDestSize ) ); + + cUIPushButton * ResetOffsetButton = mTheme->CreatePushButton( mUIContainer, eeSize( 120, 22 ), eeVector2i( ResetButton->Pos().x, ResetButton->Pos().y + ResetButton->Size().Height() + 8 ), ButFlags ); + ResetOffsetButton->AddEventListener( cUIEvent::EventMouseClick, cb::Make1( this, &cTextureGroupEditor::OnResetOffset ) ); + ResetOffsetButton->Text( "Reset Offset" ); + + cUIPushButton * CenterOffsetButton = mTheme->CreatePushButton( mUIContainer, eeSize( 120, 22 ), eeVector2i( ResetOffsetButton->Pos().x, ResetOffsetButton->Pos().y + ResetOffsetButton->Size().Height() + 8 ), ButFlags ); + CenterOffsetButton->AddEventListener( cUIEvent::EventMouseClick, cb::Make1( this, &cTextureGroupEditor::OnCenterOffset ) ); + CenterOffsetButton->Text( "Centered Offset" ); + + cUIPushButton * HBOffsetButton = mTheme->CreatePushButton( mUIContainer, eeSize( 120, 22 ), eeVector2i( CenterOffsetButton->Pos().x, CenterOffsetButton->Pos().y + CenterOffsetButton->Size().Height() + 8 ), ButFlags ); + HBOffsetButton->AddEventListener( cUIEvent::EventMouseClick, cb::Make1( this, &cTextureGroupEditor::OnHBOffset ) ); + HBOffsetButton->Text( "Half-Bottom Offset" ); + + mUIWindow->Title( "Texture Group Editor" ); + mUIWindow->AddEventListener( cUIEvent::EventOnWindowClose, cb::Make1( this, &cTextureGroupEditor::WindowClose ) ); + + CreateTGEditor(); + + cUIComplexControl::CreateParams Params; + Params.Parent( mUIContainer ); + Params.PosSet( 0, mWinMenu->Size().Height() ); + Params.SizeSet( 800, 600 ); + Params.Background.Color( eeColorA( 0, 0, 0, 50 ) ); + Params.Flags |= UI_ANCHOR_BOTTOM | UI_ANCHOR_RIGHT | UI_CLIP_ENABLE | UI_BORDER | UI_FILL_BACKGROUND; + mShapeEditor = eeNew( cTextureGroupShapeEditor, ( Params, this ) ); + mShapeEditor->Visible( true ); + mShapeEditor->Enabled( true ); +} + +cTextureGroupEditor::~cTextureGroupEditor() { + eeSAFE_DELETE( mTexturePacker ); + eeSAFE_DELETE( mTextureGroupLoader ); +} + + +void cTextureGroupEditor::OnResetDestSize( const cUIEvent * Event ) { + const cUIEventMouse * MouseEvent = reinterpret_cast ( Event ); + + if ( NULL != mCurShape && MouseEvent->Flags() & EE_BUTTON_LMASK ) { + eeSize RealSize = mCurShape->RealSize(); + + mCurShape->DestWidth( RealSize.Width() ); + mCurShape->DestHeight( RealSize.Height() ); + mSpinDestW->Value( RealSize.Width() ); + mSpinDestH->Value( RealSize.Height() ); + } +} + +void cTextureGroupEditor::OnResetOffset( const cUIEvent * Event ) { + const cUIEventMouse * MouseEvent = reinterpret_cast ( Event ); + + if ( NULL != mCurShape && MouseEvent->Flags() & EE_BUTTON_LMASK ) { + mSpinOffX->Value( 0 ); + mSpinOffY->Value( 0 ); + } +} + +void cTextureGroupEditor::OnCenterOffset( const cUIEvent * Event ) { + const cUIEventMouse * MouseEvent = reinterpret_cast ( Event ); + + if ( NULL != mCurShape && MouseEvent->Flags() & EE_BUTTON_LMASK ) { + eeSize NSize( -( (Int32)mCurShape->DestWidth() / 2 ), -( (Int32)mCurShape->DestHeight() / 2 ) ); + + mSpinOffX->Value( NSize.x ); + mSpinOffY->Value( NSize.y ); + } +} + +void cTextureGroupEditor::OnHBOffset( const cUIEvent * Event ) { + const cUIEventMouse * MouseEvent = reinterpret_cast ( Event ); + + if ( NULL != mCurShape && MouseEvent->Flags() & EE_BUTTON_LMASK ) { + eeSize NSize( -( (Int32)mCurShape->DestWidth() / 2 ), -(Int32)mCurShape->DestHeight() ); + + mSpinOffX->Value( NSize.x ); + mSpinOffY->Value( NSize.y ); + } +} + +void cTextureGroupEditor::OnOffXChange( const cUIEvent * Event ) { + if ( NULL != mCurShape ) { + mCurShape->OffsetX( (Int32)mSpinOffX->Value() ); + } +} + +void cTextureGroupEditor::OnOffYChange( const cUIEvent * Event ) { + if ( NULL != mCurShape ) { + mCurShape->OffsetY( (Int32)mSpinOffY->Value() ); + } +} + +void cTextureGroupEditor::OnDestWChange( const cUIEvent * Event ) { + if ( NULL != mCurShape ) { + mCurShape->DestWidth( (Int32)mSpinDestW->Value() ); + } +} + +void cTextureGroupEditor::OnDestHChange( const cUIEvent * Event ) { + if ( NULL != mCurShape ) { + mCurShape->DestHeight( (Int32)mSpinDestH->Value() ); + } +} + +cUITextBox * cTextureGroupEditor::CreateTxtBox( eeVector2i Pos, const String& Text ) { + cUITextBox * TxtBox = mTheme->CreateTextBox( mUIContainer, eeSize(), Pos, UI_CONTROL_DEFAULT_ALIGN | UI_ANCHOR_TOP | UI_ANCHOR_RIGHT | UI_DRAW_SHADOW | UI_AUTO_SIZE ); + TxtBox->Text( Text ); + return TxtBox; +} + +void cTextureGroupEditor::WindowClose( const cUIEvent * Event ) { + if ( mCloseCb.IsSet() ) + mCloseCb(); + + eeDelete( this ); +} + +void cTextureGroupEditor::CreateTGEditor() { + CreateWinMenu(); +} + +void cTextureGroupEditor::CreateWinMenu() { + mWinMenu = mTheme->CreateWinMenu( mUIContainer ); + + cUIPopUpMenu * PU = mTheme->CreatePopUpMenu(); + PU->Add( "New...", mTheme->GetIconByName( "document-new" ) ); + PU->Add( "Open...", mTheme->GetIconByName( "document-open" ) ); + PU->AddSeparator(); + PU->Add( "Save", mTheme->GetIconByName( "document-save" ) ); + PU->AddSeparator(); + PU->Add( "Close", mTheme->GetIconByName( "document-close" ) ); + PU->AddSeparator(); + PU->Add( "Quit", mTheme->GetIconByName( "quit" ) ); + + PU->AddEventListener( cUIEvent::EventOnItemClicked, cb::Make1( this, &cTextureGroupEditor::FileMenuClick ) ); + mWinMenu->AddMenuButton( "File", PU ); +} + +void cTextureGroupEditor::FileMenuClick( const cUIEvent * Event ) { + if ( !Event->Ctrl()->IsTypeOrInheritsFrom( UI_TYPE_MENUITEM ) ) + return; + + const String& txt = reinterpret_cast ( Event->Ctrl() )->Text(); + + if ( "New..." == txt ) { + eeNew( cTextureGroupNew, ( cb::Make1( this, &cTextureGroupEditor::OnTextureGroupCreate ) ) ); + } else if ( "Open..." == txt ) { + cUICommonDialog * TGDialog = mTheme->CreateCommonDialog( NULL, eeSize(), eeVector2i(), UI_CONTROL_DEFAULT_FLAGS_CENTERED, UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL, eeSize(), 255, UI_CDL_DEFAULT_FLAGS, "*.etg" ); + + TGDialog->Title( "Open Texture Group" ); + TGDialog->AddEventListener( cUIEvent::EventOpenFile, cb::Make1( this, &cTextureGroupEditor::OpenTextureGroup ) ); + TGDialog->Center(); + TGDialog->Show(); + } else if ( "Save" == txt ) { + if ( NULL != mTextureGroupLoader ) { + mTextureGroupLoader->UpdateTextureAtlas(); + } + } else if ( "Close" == txt ) { + if ( NULL != mTextureGroupLoader ) { + cUIMessageBox * MsgBox = mTheme->CreateMessageBox( MSGBOX_OKCANCEL, "Do you really want to close the current texture group?\nAll changes will be lost." ); + MsgBox->AddEventListener( cUIEvent::EventMsgBoxConfirmClick, cb::Make1( this, &cTextureGroupEditor::OnTextureGroupClose ) ); + MsgBox->Title( "Close Texture Group?" ); + MsgBox->Center(); + MsgBox->Show(); + } else { + OnTextureGroupClose( NULL ); + } + } else if ( "Quit" == txt ) { + if ( mUIWindow == cUIManager::instance()->MainControl() ) { + cUIManager::instance()->GetWindow()->Close(); + } else { + mUIWindow->CloseWindow(); + } + } +} + +void cTextureGroupEditor::OnTextureGroupCreate( cTexturePacker * TexPacker ) { + eeSAFE_DELETE( mTexturePacker ); + mTexturePacker = TexPacker; + + eeSAFE_DELETE( mTextureGroupLoader ); + + std::string FPath( FileRemoveExtension( mTexturePacker->GetFilepath() ) + ".etg" ); + + mTextureGroupLoader = eeNew( cTextureGroupLoader, ( FPath ) ); + + UpdateControls(); +} + +void cTextureGroupEditor::UpdateControls() { + if ( NULL != mTextureGroupLoader ) { + FillShapeList(); + } +} + +void cTextureGroupEditor::FillShapeList() { + if ( NULL == mTextureGroupLoader || NULL == mTextureGroupLoader->GetShapeGroup() ) + return; + + std::list& Res = mTextureGroupLoader->GetShapeGroup()->GetResources(); + + mShapeList->Clear(); + + std::vector items; + + for ( std::list::iterator it = Res.begin(); it != Res.end(); it++ ) { + items.push_back( (*it)->Name() ); + } + + if ( items.size() ) { + std::sort( items.begin(), items.end() ); + + mShapeList->AddListBoxItems( items ); + mShapeList->SetSelected( 0 ); + } + + mShapeList->VerticalScrollBar()->ClickStep( 8.f / (eeFloat)mShapeList->Count() ); +} + +void cTextureGroupEditor::OnShapeChange( const cUIEvent * Event ) { + if ( NULL != mTextureGroupLoader && NULL != mTextureGroupLoader->GetShapeGroup() ) { + mCurShape = mTextureGroupLoader->GetShapeGroup()->GetByName( mShapeList->GetItemSelectedText() ); + + if ( NULL != mCurShape ) { + mShapeEditor->Shape( mCurShape ); + mSpinOffX->Value( mCurShape->OffsetX() ); + mSpinOffY->Value( mCurShape->OffsetY() ); + mSpinDestW->Value( mCurShape->DestWidth() ); + mSpinDestH->Value( mCurShape->DestHeight() ); + } + } +} + +void cTextureGroupEditor::OpenTextureGroup( const cUIEvent * Event ) { + cUICommonDialog * CDL = reinterpret_cast ( Event->Ctrl() ); + + eeSAFE_DELETE( mTextureGroupLoader ); + mTextureGroupLoader = eeNew( cTextureGroupLoader, ( CDL->GetFullPath() ) ); + + if ( mTextureGroupLoader->IsLoaded() ) { + UpdateControls(); + } +} + +void cTextureGroupEditor::SaveTextureGroup( const cUIEvent * Event ) { + if ( NULL != mTextureGroupLoader ) { + mTextureGroupLoader->UpdateTextureAtlas(); + } +} + +void cTextureGroupEditor::OnTextureGroupClose( const cUIEvent * Event ) { + eeSAFE_DELETE( mTextureGroupLoader ); + mShapeList->Clear(); + mSpinOffX->Value( 0 ); + mSpinOffY->Value( 0 ); + mSpinDestW->Value( 0 ); + mSpinDestH->Value( 0 ); + mShapeEditor->Shape( NULL ); + mCurShape = NULL; +} + +}}} diff --git a/src/ui/tools/ctexturegroupeditor.hpp b/src/ui/tools/ctexturegroupeditor.hpp new file mode 100644 index 000000000..5e7b4ff97 --- /dev/null +++ b/src/ui/tools/ctexturegroupeditor.hpp @@ -0,0 +1,86 @@ +#ifndef EE_UITOOLSCTEXTUREGROUPEDITOR_HPP +#define EE_UITOOLSCTEXTUREGROUPEDITOR_HPP + +#include "../base.hpp" +#include "ctexturegroupshapeeditor.hpp" +#include "../cuiwindow.hpp" +#include "../cuispinbox.hpp" +#include "../cuilistbox.hpp" +#include "../cuiwinmenu.hpp" +#include "../../graphics/ctexturepacker.hpp" +#include "../../graphics/ctexturegrouploader.hpp" +#include "../../graphics/cshapegroupmanager.hpp" + +namespace EE { namespace UI { namespace Tools { + +class EE_API cTextureGroupEditor { + public: + typedef cb::Callback0 TGEditorCloseCb; + + cTextureGroupEditor( cUIWindow * AttatchTo = NULL, const TGEditorCloseCb& callback = TGEditorCloseCb() ); + + virtual ~cTextureGroupEditor(); + + cUISpinBox * SpinOffX() const { return mSpinOffX; } + + cUISpinBox * SpinOffY() const { return mSpinOffY; } + protected: + cUIWindow * mUIWindow; + cUIControl * mUIContainer; + cUITheme * mTheme; + TGEditorCloseCb mCloseCb; + cTexturePacker * mTexturePacker; + cTextureGroupLoader * mTextureGroupLoader; + cShape * mCurShape; + cUISpinBox * mSpinOffX; + cUISpinBox * mSpinOffY; + cUISpinBox * mSpinDestW; + cUISpinBox * mSpinDestH; + cUIListBox * mShapeList; + cUIWinMenu * mWinMenu; + cTextureGroupShapeEditor * mShapeEditor; + + void WindowClose( const cUIEvent * Event ); + + void CreateTGEditor(); + + void CreateWinMenu(); + + void FileMenuClick( const cUIEvent * Event ); + + void OnTextureGroupCreate( cTexturePacker * TexPacker ); + + void OpenTextureGroup( const cUIEvent * Event ); + + void SaveTextureGroup( const cUIEvent * Event ); + + void OnTextureGroupClose( const cUIEvent * Event ); + + void OnShapeChange( const cUIEvent * Event ); + + cUITextBox * CreateTxtBox( eeVector2i Pos, const String& Text ); + + void UpdateControls(); + + void FillShapeList(); + + void OnOffXChange( const cUIEvent * Event ); + + void OnOffYChange( const cUIEvent * Event ); + + void OnDestWChange( const cUIEvent * Event ); + + void OnDestHChange( const cUIEvent * Event ); + + void OnResetDestSize( const cUIEvent * Event ); + + void OnResetOffset( const cUIEvent * Event ); + + void OnCenterOffset( const cUIEvent * Event ); + + void OnHBOffset( const cUIEvent * Event ); +}; + +}}} + +#endif diff --git a/src/ui/tools/ctexturegroupnew.cpp b/src/ui/tools/ctexturegroupnew.cpp new file mode 100644 index 000000000..4146c4cb1 --- /dev/null +++ b/src/ui/tools/ctexturegroupnew.cpp @@ -0,0 +1,203 @@ +#include "ctexturegroupnew.hpp" +#include "../cuicommondialog.hpp" +#include "../cuimessagebox.hpp" + +namespace EE { namespace UI { namespace Tools { + +cTextureGroupNew::cTextureGroupNew( TGCreateCb NewTGCb ) : + mTheme( NULL ), + mUIWindow( NULL ), + mNewTGCb( NewTGCb ) +{ + mTheme = cUIThemeManager::instance()->DefaultTheme(); + + if ( NULL == mTheme ) + return; + + mUIWindow = mTheme->CreateWindow( NULL, eeSize( 378, 244 ), eeVector2i(), UI_CONTROL_DEFAULT_FLAGS_CENTERED, UI_WIN_DEFAULT_FLAGS | UI_WIN_MODAL ); + mUIWindow->AddEventListener( cUIEvent::EventOnWindowClose, cb::Make1( this, &cTextureGroupNew::WindowClose ) ); + mUIWindow->Title( "New Texture Group" ); + + Int32 PosX = mUIWindow->Container()->Size().Width() - 110; + + CreateTxtBox( eeVector2i( 10, 20 ), "Save File Format:" ); + mSaveFileType = mTheme->CreateDropDownList( mUIWindow->Container(), eeSize( 100, 22 ), eeVector2i( PosX, 20 ), UI_CONTROL_DEFAULT_FLAGS | UI_CLIP_ENABLE | UI_AUTO_PADDING | UI_AUTO_SIZE ); + + std::vector FileTypes; + FileTypes.push_back( "TGA" ); + FileTypes.push_back( "BMP" ); + FileTypes.push_back( "PNG" ); + FileTypes.push_back( "DDS" ); + + mSaveFileType->ListBox()->AddListBoxItems( FileTypes ); + mSaveFileType->ListBox()->SetSelected( "PNG" ); + + CreateTxtBox( eeVector2i( 10, 50 ), "Max. Texture Atlas Width:" ); + mComboWidth = mTheme->CreateComboBox( mUIWindow->Container(), eeSize( 100, 22 ), eeVector2i( PosX, 50 ), UI_CONTROL_DEFAULT_FLAGS | UI_CLIP_ENABLE | UI_AUTO_PADDING | UI_AUTO_SIZE ); + + CreateTxtBox( eeVector2i( 10, 80 ), "Max. Texture Atlas Height:" ); + mComboHeight = mTheme->CreateComboBox( mUIWindow->Container(), eeSize( 100, 22 ), eeVector2i( PosX, 80 ), UI_CONTROL_DEFAULT_FLAGS | UI_CLIP_ENABLE | UI_AUTO_PADDING | UI_AUTO_SIZE ); + + std::vector Sizes; + + for ( Uint32 i = 6; i < 14; i++ ) { + Sizes.push_back( toStr( 1 << i ) ); + } + + mComboWidth->ListBox()->AddListBoxItems( Sizes ); + mComboHeight->ListBox()->AddListBoxItems( Sizes ); + mComboWidth->GetInputTextBuffer()->AllowOnlyNumbers( true ); + mComboHeight->GetInputTextBuffer()->AllowOnlyNumbers( true ); + mComboWidth->Text( "512" ); + mComboHeight->Text( "512" ); + + CreateTxtBox( eeVector2i( 10, 110 ), "Space between shapes (pixels):" ); + mPixelSpace = mTheme->CreateSpinBox( mUIWindow->Container(), eeSize( 100, 22 ), eeVector2i( PosX, 110 ), UI_CONTROL_DEFAULT_FLAGS | UI_CLIP_ENABLE | UI_AUTO_SIZE, 0, false ); + + CreateTxtBox( eeVector2i( 10, 140 ), "Texture Group Folder Path:" ); + mTGPath = mTheme->CreateTextInput( mUIWindow->Container(), eeSize( mUIWindow->Container()->Size().Width() - 60, 22 ), eeVector2i( 10, 160 ), UI_CONTROL_DEFAULT_FLAGS | UI_CLIP_ENABLE | UI_AUTO_PADDING | UI_AUTO_SIZE , false, 512 ); + mTGPath->AllowEditing( false ); + + mSetPathButton = mTheme->CreatePushButton( mUIWindow->Container(), eeSize( 32, 32 ), eeVector2i( mUIWindow->Container()->Size().Width() - 10 - 32, 160 ) ); + mSetPathButton->Text( "..." ); + mSetPathButton->AddEventListener( cUIEvent::EventMouseClick, cb::Make1( this, &cTextureGroupNew::OnDialogFolderSelect ) ); + + cUIPushButton * OKButton = mTheme->CreatePushButton( mUIWindow->Container(), eeSize( 80, 22 ), eeVector2i(), UI_CONTROL_DEFAULT_FLAGS_CENTERED | UI_AUTO_SIZE, mTheme->GetIconByName( "ok" ) ); + OKButton->Pos( mUIWindow->Container()->Size().Width() - OKButton->Size().Width() - 4, mUIWindow->Container()->Size().Height() - OKButton->Size().Height() - 4 ); + OKButton->AddEventListener( cUIEvent::EventMouseClick, cb::Make1( this, &cTextureGroupNew::OKClick ) ); + OKButton->Text( "OK" ); + + cUIPushButton * CancelButton = mTheme->CreatePushButton( mUIWindow->Container(), OKButton->Size(), eeVector2i( OKButton->Pos().x - OKButton->Size().Width() - 4, OKButton->Pos().y ), UI_CONTROL_DEFAULT_FLAGS_CENTERED | UI_AUTO_SIZE, mTheme->GetIconByName( "cancel" ) ); + CancelButton->AddEventListener( cUIEvent::EventMouseClick, cb::Make1( this, &cTextureGroupNew::CancelClick ) ); + CancelButton->Text( "Cancel" ); + + mUIWindow->Center(); + mUIWindow->Show(); +} + +cTextureGroupNew::~cTextureGroupNew() { +} + +cUITextBox * cTextureGroupNew::CreateTxtBox( eeVector2i Pos, const String& Text ) { + cUITextBox * TxtBox = mTheme->CreateTextBox( mUIWindow->Container(), eeSize(), Pos, UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW | UI_AUTO_SIZE ); + TxtBox->Text( Text ); + return TxtBox; +} + +void cTextureGroupNew::OKClick( const cUIEvent * Event ) { + std::string ext( mSaveFileType->Text() ); + toLower( ext ); + + cUICommonDialog * TGDialog = mTheme->CreateCommonDialog( NULL, eeSize(), eeVector2i(), UI_CONTROL_DEFAULT_FLAGS_CENTERED, UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL, eeSize(), 255, UI_CDL_DEFAULT_FLAGS | CDL_FLAG_SAVE_DIALOG, "*." + ext ); + + TGDialog->Title( "Save Texture Group" ); + TGDialog->AddEventListener( cUIEvent::EventSaveFile, cb::Make1( this, &cTextureGroupNew::TextureGroupSave ) ); + TGDialog->Center(); + TGDialog->Show(); +} + +void cTextureGroupNew::CancelClick( const cUIEvent * Event ) { + mUIWindow->CloseWindow(); +} + +void cTextureGroupNew::WindowClose( const cUIEvent * Event ) { + eeDelete( this ); +} + +static bool IsValidExtension( const std::string& ext ) { + return ext == "png" || ext == "bmp" || ext == "dds" || ext == "dds"; +} + +void cTextureGroupNew::TextureGroupSave( const cUIEvent * Event ) { + cUICommonDialog * CDL = reinterpret_cast ( Event->Ctrl() ); + std::string FPath( CDL->GetFullPath() ); + + if ( !IsDirectory( FPath ) ) { + Int32 w,h,b; + bool Res1 = fromString( w, mComboWidth->Text() ); + bool Res2 = fromString( h, mComboHeight->Text() ); + b = static_cast( mPixelSpace->Value() ); + + if ( Res1 && Res2 ) { + cTexturePacker * TexturePacker = eeNew( cTexturePacker, ( w, h, false, b ) ); + + TexturePacker->AddTexturesPath( mTGPath->Text() ); + + TexturePacker->PackTextures(); + + std::string ext = FileExtension( FPath, true ); + + if ( !IsValidExtension( ext ) ) { + FPath = FileRemoveExtension( FPath ); + + ext = mSaveFileType->Text(); + + toLower( ext ); + + FPath += "." + ext; + } + + TexturePacker->Save( FPath, static_cast ( mSaveFileType->ListBox()->GetItemSelectedIndex() ) ); + + if ( mNewTGCb.IsSet() ) + mNewTGCb( TexturePacker ); + + mUIWindow->CloseWindow(); + } + } +} + +void cTextureGroupNew::OnDialogFolderSelect( const cUIEvent * Event ) { + const cUIEventMouse * MouseEvent = reinterpret_cast( Event ); + + if ( MouseEvent->Flags() & EE_BUTTON_LMASK ) { + cUICommonDialog * TGDialog = mTheme->CreateCommonDialog( NULL, eeSize(), eeVector2i(), UI_CONTROL_DEFAULT_FLAGS_CENTERED, UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL, eeSize(), 255, UI_CDL_DEFAULT_FLAGS | CDL_FLAG_ALLOW_FOLDER_SELECT, "*" ); + + TGDialog->Title( "Create Texture Group ( Select Folder Containing Textures )" ); + TGDialog->AddEventListener( cUIEvent::EventOpenFile, cb::Make1( this, &cTextureGroupNew::OnSelectFolder ) ); + TGDialog->Center(); + TGDialog->Show(); + } +} + +void cTextureGroupNew::OnSelectFolder( const cUIEvent * Event ) { + cUICommonDialog * CDL = reinterpret_cast ( Event->Ctrl() ); + cUIMessageBox * MsgBox; + std::string FPath( CDL->GetFullPath() ); + DirPathAddSlashAtEnd( FPath ); + + if ( IsDirectory( FPath ) ) { + std::vector files = FilesGetInPath( FPath ); + + int x,y,c, count = 0; + for ( Uint32 i = 0; i < files.size(); i++ ) { + std::string ImgPath( FPath + files[i] ); + + if ( !IsDirectory( ImgPath ) ) { + int res = stbi_info( ImgPath.c_str(), &x, &y, &c ); + + if ( res ) { + count++; + break; + } + } + } + + //! All OK + if ( count ) { + mTGPath->Text( FPath ); + } else { + MsgBox = mTheme->CreateMessageBox( MSGBOX_OK, "The folder must contain at least one image!" ); + MsgBox->Title( "Error" ); + MsgBox->Center(); + MsgBox->Show(); + } + } else { + MsgBox = mTheme->CreateMessageBox( MSGBOX_OK, "You must select a folder!" ); + MsgBox->Title( "Error" ); + MsgBox->Center(); + MsgBox->Show(); + } +} + +}}} diff --git a/src/ui/tools/ctexturegroupnew.hpp b/src/ui/tools/ctexturegroupnew.hpp new file mode 100644 index 000000000..91f840a5f --- /dev/null +++ b/src/ui/tools/ctexturegroupnew.hpp @@ -0,0 +1,48 @@ +#ifndef EE_UITOOLSCTEXTUREGROUPNEW_HPP +#define EE_UITOOLSCTEXTUREGROUPNEW_HPP + +#include "../base.hpp" +#include "../cuiwindow.hpp" +#include "../cuicombobox.hpp" +#include "../cuispinbox.hpp" +#include "../cuipushbutton.hpp" +#include "../../graphics/ctexturepacker.hpp" + +namespace EE { namespace UI { namespace Tools { + +class cTextureGroupNew { + public: + typedef cb::Callback1 TGCreateCb; + + cTextureGroupNew( TGCreateCb NewTGCb = TGCreateCb() ); + + virtual ~cTextureGroupNew(); + protected: + cUITheme * mTheme; + cUIWindow * mUIWindow; + TGCreateCb mNewTGCb; + cUIComboBox * mComboWidth; + cUIComboBox * mComboHeight; + cUISpinBox * mPixelSpace; + cUITextInput * mTGPath; + cUIPushButton * mSetPathButton; + cUIDropDownList * mSaveFileType; + + void WindowClose( const cUIEvent * Event ); + + void CancelClick( const cUIEvent * Event ); + + void OKClick( const cUIEvent * Event ); + + cUITextBox * CreateTxtBox( eeVector2i Pos, const String& Text ); + + void OnDialogFolderSelect( const cUIEvent * Event ); + + void OnSelectFolder( const cUIEvent * Event ); + + void TextureGroupSave( const cUIEvent * Event ); +}; + +}}} + +#endif diff --git a/src/ui/tools/ctexturegroupshapeeditor.cpp b/src/ui/tools/ctexturegroupshapeeditor.cpp new file mode 100644 index 000000000..6641b84f3 --- /dev/null +++ b/src/ui/tools/ctexturegroupshapeeditor.cpp @@ -0,0 +1,82 @@ +#include "ctexturegroupshapeeditor.hpp" +#include "ctexturegroupeditor.hpp" +#include "../../graphics/cprimitives.hpp" +#include "../cuimanager.hpp" + +namespace EE { namespace UI { namespace Tools { + +cTextureGroupShapeEditor::cTextureGroupShapeEditor( const cUIComplexControl::CreateParams& Params, cTextureGroupEditor * Editor ) : + cUIComplexControl( Params ), + mGfx( NULL ), + mEditor( Editor ) +{ + if ( NULL == cUIThemeManager::instance()->DefaultTheme() ) { + return; + } + + mTheme = cUIThemeManager::instance()->DefaultTheme(); + + mGfx = mTheme->CreateGfx( NULL, this ); + + cUIDragable::CreateParams DragParams; + DragParams.Parent( this ); + DragParams.SizeSet( 500000, 500000 ); + mDrag = eeNew( cUIDragable, ( DragParams ) ); + mDrag->Enabled( true ); + mDrag->Visible( true ); + mDrag->DragEnable( true ); + + GetCenter(); +} + +cTextureGroupShapeEditor::~cTextureGroupShapeEditor() { +} + +void cTextureGroupShapeEditor::Draw() { + cPrimitives P; + P.SetColor( eeColorA( 255, 0, 0, mAlpha ) ); + P.DrawLine( mScreenPos.x, mScreenPos.y + mUICenter.y, mScreenPos.x + mSize.Width(), mScreenPos.y + mUICenter.y ); + P.DrawLine( mScreenPos.x + mUICenter.x, mScreenPos.y, mScreenPos.x + mUICenter.x, mScreenPos.y + mSize.Height() ); + + cUIComplexControl::Draw(); +} + +void cTextureGroupShapeEditor::Update() { + eeVector2i Pos = mDrag->Pos(); + + cUIComplexControl::Update(); + + if ( NULL != mGfx->Shape() && mDrag->DragEnable() && mDrag->Dragging() && Pos != mDrag->Pos() ) { + eeVector2i Diff = -( Pos - mDrag->Pos() ); + + mGfx->Shape()->OffsetX( mGfx->Shape()->OffsetX() + Diff.x ); + mGfx->Shape()->OffsetY( mGfx->Shape()->OffsetY() + Diff.y ); + + mEditor->SpinOffX()->Value( mGfx->Shape()->OffsetX() ); + mEditor->SpinOffY()->Value( mGfx->Shape()->OffsetY() ); + } + + mGfx->Pos( mUICenter ); +} + +void cTextureGroupShapeEditor::OnSizeChange() { + GetCenter(); +} + +cShape * cTextureGroupShapeEditor::Shape() const { + return mGfx->Shape(); +} + +void cTextureGroupShapeEditor::Shape( cShape * shape ) { + mGfx->Shape( shape ); +} + +cUIGfx * cTextureGroupShapeEditor::Gfx() const { + return mGfx; +} + +void cTextureGroupShapeEditor::GetCenter() { + mUICenter = eeVector2i( mSize.Width() / 2, mSize.Height() / 2 ); +} + +}}} diff --git a/src/ui/tools/ctexturegroupshapeeditor.hpp b/src/ui/tools/ctexturegroupshapeeditor.hpp new file mode 100644 index 000000000..5868730c8 --- /dev/null +++ b/src/ui/tools/ctexturegroupshapeeditor.hpp @@ -0,0 +1,42 @@ +#ifndef EE_UITOOLSCTEXTUREGROUPSHAPEEDITOR_HPP +#define EE_UITOOLSCTEXTUREGROUPSHAPEEDITOR_HPP + +#include "../base.hpp" +#include "../cuicomplexcontrol.hpp" +#include "../../graphics/cshape.hpp" +#include "../cuigfx.hpp" + +namespace EE { namespace UI { namespace Tools { + +class cTextureGroupEditor; + +class cTextureGroupShapeEditor : public cUIComplexControl { + public: + cTextureGroupShapeEditor( const cUIComplexControl::CreateParams& Params, cTextureGroupEditor * Editor ); + + virtual ~cTextureGroupShapeEditor(); + + virtual void Draw(); + + virtual void Update(); + + cShape * Shape() const; + + void Shape( cShape * shape ); + + cUIGfx * Gfx() const; + protected: + cUITheme * mTheme; + cUIGfx * mGfx; + cUIDragable * mDrag; + eeVector2i mUICenter; + cTextureGroupEditor * mEditor; + + virtual void OnSizeChange(); + + void GetCenter(); +}; + +}}} + +#endif diff --git a/src/utils/utils.hpp b/src/utils/utils.hpp index d6e40b65d..6e01f8d68 100755 --- a/src/utils/utils.hpp +++ b/src/utils/utils.hpp @@ -127,10 +127,10 @@ namespace EE { namespace Utils { void EE_API SetFlagValue( Uint32 * Key, Uint32 Val, Uint32 BitWrite ); /** @return The OS Name */ - std::string GetOSName(); + std::string EE_API GetOSName(); /** @return The OS Architecture */ - std::string GetOSArchitecture(); + std::string EE_API GetOSArchitecture(); } } diff --git a/src/window/cinputtextbuffer.cpp b/src/window/cinputtextbuffer.cpp index 2f1c3b20c..f34f8fef5 100755 --- a/src/window/cinputtextbuffer.cpp +++ b/src/window/cinputtextbuffer.cpp @@ -9,7 +9,7 @@ cInputTextBuffer::cInputTextBuffer( const bool& active, const bool& supportNewLi mFlags(0), mCallback(0), mPromptPos(0), - mMaxLenght(0xFFFFFFFF) + mMaxLenght(INPUT_LENGHT_MAX) { if ( NULL == mWindow ) { mWindow = cEngine::instance()->GetCurrentWindow(); @@ -33,7 +33,7 @@ cInputTextBuffer::cInputTextBuffer( cWindow * window ) : mFlags(0), mCallback(0), mPromptPos(0), - mMaxLenght(0xFFFFFFFF) + mMaxLenght(INPUT_LENGHT_MAX) { if ( NULL == mWindow ) { mWindow = cEngine::instance()->GetCurrentWindow(); diff --git a/src/window/cinputtextbuffer.hpp b/src/window/cinputtextbuffer.hpp index 069aa5b23..16c55e40d 100755 --- a/src/window/cinputtextbuffer.hpp +++ b/src/window/cinputtextbuffer.hpp @@ -18,11 +18,13 @@ enum INPUT_TEXTBUFFER_FLAGS { INPUT_TB_SUPPORT_COPY_PASTE = 7 }; +#define INPUT_LENGHT_MAX 0xFFFFFFFF + class EE_API cInputTextBuffer { public: typedef cb::Callback0 EnterCallback; - cInputTextBuffer( const bool& active, const bool& supportNewLine, const bool& supportFreeEditing, Window::cWindow * window = NULL, const Uint32& maxLenght = 0xFFFFFFFF ); + cInputTextBuffer( const bool& active, const bool& supportNewLine, const bool& supportFreeEditing, Window::cWindow * window = NULL, const Uint32& maxLenght = INPUT_LENGHT_MAX ); cInputTextBuffer( Window::cWindow * window = NULL );